2006-11-28 18:35:01 -07:00
|
|
|
/*
|
|
|
|
* connection tracking event cache.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NF_CONNTRACK_ECACHE_H
|
|
|
|
#define _NF_CONNTRACK_ECACHE_H
|
|
|
|
#include <net/netfilter/nf_conntrack.h>
|
|
|
|
|
2008-10-08 03:35:07 -06:00
|
|
|
#include <net/net_namespace.h>
|
2006-11-28 18:35:01 -07:00
|
|
|
#include <net/netfilter/nf_conntrack_expect.h>
|
2009-06-13 04:26:29 -06:00
|
|
|
#include <linux/netfilter/nf_conntrack_common.h>
|
|
|
|
#include <linux/netfilter/nf_conntrack_tuple_common.h>
|
|
|
|
#include <net/netfilter/nf_conntrack_extend.h>
|
2006-11-28 18:35:01 -07:00
|
|
|
|
2009-06-13 04:26:29 -06:00
|
|
|
/* Connection tracking event types */
|
2009-06-02 12:08:44 -06:00
|
|
|
enum ip_conntrack_events
|
|
|
|
{
|
2009-06-13 04:26:29 -06:00
|
|
|
IPCT_NEW = 0, /* new conntrack */
|
|
|
|
IPCT_RELATED = 1, /* related conntrack */
|
|
|
|
IPCT_DESTROY = 2, /* destroyed conntrack */
|
|
|
|
IPCT_STATUS = 3, /* status has changed */
|
|
|
|
IPCT_PROTOINFO = 4, /* protocol information has changed */
|
|
|
|
IPCT_HELPER = 5, /* new helper has been set */
|
|
|
|
IPCT_MARK = 6, /* new mark has been set */
|
|
|
|
IPCT_NATSEQADJ = 7, /* NAT is doing sequence adjustment */
|
|
|
|
IPCT_SECMARK = 8, /* new security mark has been set */
|
|
|
|
};
|
2009-06-02 12:08:44 -06:00
|
|
|
|
2009-06-13 04:26:29 -06:00
|
|
|
enum ip_conntrack_expect_events {
|
|
|
|
IPEXP_NEW = 0, /* new expectation */
|
|
|
|
};
|
2009-06-02 12:08:44 -06:00
|
|
|
|
2009-06-13 04:26:29 -06:00
|
|
|
struct nf_conntrack_ecache {
|
|
|
|
unsigned long cache; /* bitops want long */
|
|
|
|
};
|
2009-06-02 12:08:44 -06:00
|
|
|
|
2009-06-13 04:26:29 -06:00
|
|
|
static inline struct nf_conntrack_ecache *
|
|
|
|
nf_ct_ecache_find(const struct nf_conn *ct)
|
|
|
|
{
|
|
|
|
return nf_ct_ext_find(ct, NF_CT_EXT_ECACHE);
|
|
|
|
}
|
2009-06-02 12:08:44 -06:00
|
|
|
|
2009-06-13 04:26:29 -06:00
|
|
|
static inline struct nf_conntrack_ecache *
|
|
|
|
nf_ct_ecache_ext_add(struct nf_conn *ct, gfp_t gfp)
|
|
|
|
{
|
|
|
|
struct net *net = nf_ct_net(ct);
|
2009-06-02 12:08:44 -06:00
|
|
|
|
2009-06-13 04:26:29 -06:00
|
|
|
if (!net->ct.sysctl_events)
|
|
|
|
return NULL;
|
2009-06-02 12:08:44 -06:00
|
|
|
|
2009-06-13 04:26:29 -06:00
|
|
|
return nf_ct_ext_add(ct, NF_CT_EXT_ECACHE, gfp);
|
2009-06-02 12:08:44 -06:00
|
|
|
};
|
|
|
|
|
2006-11-28 18:35:01 -07:00
|
|
|
#ifdef CONFIG_NF_CONNTRACK_EVENTS
|
2008-11-18 03:56:20 -07:00
|
|
|
/* This structure is passed to event handler */
|
|
|
|
struct nf_ct_event {
|
|
|
|
struct nf_conn *ct;
|
|
|
|
u32 pid;
|
|
|
|
int report;
|
|
|
|
};
|
|
|
|
|
2009-06-03 02:32:06 -06:00
|
|
|
struct nf_ct_event_notifier {
|
|
|
|
int (*fcn)(unsigned int events, struct nf_ct_event *item);
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct nf_ct_event_notifier *nf_conntrack_event_cb;
|
|
|
|
extern int nf_conntrack_register_notifier(struct nf_ct_event_notifier *nb);
|
|
|
|
extern void nf_conntrack_unregister_notifier(struct nf_ct_event_notifier *nb);
|
2006-11-28 18:35:01 -07:00
|
|
|
|
2009-06-13 04:26:29 -06:00
|
|
|
extern void nf_ct_deliver_cached_events(struct nf_conn *ct);
|
2006-11-28 18:35:01 -07:00
|
|
|
|
|
|
|
static inline void
|
2008-10-08 03:35:07 -06:00
|
|
|
nf_conntrack_event_cache(enum ip_conntrack_events event, struct nf_conn *ct)
|
2006-11-28 18:35:01 -07:00
|
|
|
{
|
2009-06-13 04:26:29 -06:00
|
|
|
struct nf_conntrack_ecache *e;
|
|
|
|
|
|
|
|
if (nf_conntrack_event_cb == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
e = nf_ct_ecache_find(ct);
|
|
|
|
if (e == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
set_bit(event, &e->cache);
|
2006-11-28 18:35:01 -07:00
|
|
|
}
|
|
|
|
|
2008-11-18 03:56:20 -07:00
|
|
|
static inline void
|
2009-06-13 04:26:29 -06:00
|
|
|
nf_conntrack_eventmask_report(unsigned int eventmask,
|
|
|
|
struct nf_conn *ct,
|
|
|
|
u32 pid,
|
|
|
|
int report)
|
2006-11-28 18:35:01 -07:00
|
|
|
{
|
2009-06-13 04:26:29 -06:00
|
|
|
struct net *net = nf_ct_net(ct);
|
2009-06-03 02:32:06 -06:00
|
|
|
struct nf_ct_event_notifier *notify;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
notify = rcu_dereference(nf_conntrack_event_cb);
|
|
|
|
if (notify == NULL)
|
|
|
|
goto out_unlock;
|
|
|
|
|
2009-06-13 04:26:29 -06:00
|
|
|
if (!net->ct.sysctl_events)
|
|
|
|
goto out_unlock;
|
|
|
|
|
2009-06-03 02:32:06 -06:00
|
|
|
if (nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct)) {
|
|
|
|
struct nf_ct_event item = {
|
|
|
|
.ct = ct,
|
|
|
|
.pid = pid,
|
|
|
|
.report = report
|
|
|
|
};
|
2009-06-13 04:26:29 -06:00
|
|
|
notify->fcn(eventmask, &item);
|
2009-06-03 02:32:06 -06:00
|
|
|
}
|
|
|
|
out_unlock:
|
|
|
|
rcu_read_unlock();
|
2006-11-28 18:35:01 -07:00
|
|
|
}
|
|
|
|
|
2009-06-13 04:26:29 -06:00
|
|
|
static inline void
|
|
|
|
nf_conntrack_event_report(enum ip_conntrack_events event, struct nf_conn *ct,
|
|
|
|
u32 pid, int report)
|
|
|
|
{
|
|
|
|
nf_conntrack_eventmask_report(1 << event, ct, pid, report);
|
|
|
|
}
|
|
|
|
|
2008-11-18 03:56:20 -07:00
|
|
|
static inline void
|
|
|
|
nf_conntrack_event(enum ip_conntrack_events event, struct nf_conn *ct)
|
|
|
|
{
|
2009-06-13 04:26:29 -06:00
|
|
|
nf_conntrack_eventmask_report(1 << event, ct, 0, 0);
|
2008-11-18 03:56:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct nf_exp_event {
|
|
|
|
struct nf_conntrack_expect *exp;
|
|
|
|
u32 pid;
|
|
|
|
int report;
|
|
|
|
};
|
|
|
|
|
2009-06-03 02:32:06 -06:00
|
|
|
struct nf_exp_event_notifier {
|
|
|
|
int (*fcn)(unsigned int events, struct nf_exp_event *item);
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct nf_exp_event_notifier *nf_expect_event_cb;
|
|
|
|
extern int nf_ct_expect_register_notifier(struct nf_exp_event_notifier *nb);
|
|
|
|
extern void nf_ct_expect_unregister_notifier(struct nf_exp_event_notifier *nb);
|
2007-03-14 17:40:10 -06:00
|
|
|
|
2008-11-18 03:56:20 -07:00
|
|
|
static inline void
|
|
|
|
nf_ct_expect_event_report(enum ip_conntrack_expect_events event,
|
|
|
|
struct nf_conntrack_expect *exp,
|
|
|
|
u32 pid,
|
|
|
|
int report)
|
|
|
|
{
|
2009-06-13 04:26:29 -06:00
|
|
|
struct net *net = nf_ct_exp_net(exp);
|
2009-06-03 02:32:06 -06:00
|
|
|
struct nf_exp_event_notifier *notify;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
notify = rcu_dereference(nf_expect_event_cb);
|
|
|
|
if (notify == NULL)
|
|
|
|
goto out_unlock;
|
|
|
|
|
2009-06-13 04:26:29 -06:00
|
|
|
if (!net->ct.sysctl_events)
|
|
|
|
goto out_unlock;
|
|
|
|
|
2009-06-03 02:32:06 -06:00
|
|
|
{
|
|
|
|
struct nf_exp_event item = {
|
|
|
|
.exp = exp,
|
|
|
|
.pid = pid,
|
|
|
|
.report = report
|
|
|
|
};
|
2009-06-13 04:26:29 -06:00
|
|
|
notify->fcn(1 << event, &item);
|
2009-06-03 02:32:06 -06:00
|
|
|
}
|
|
|
|
out_unlock:
|
|
|
|
rcu_read_unlock();
|
2008-11-18 03:56:20 -07:00
|
|
|
}
|
|
|
|
|
2006-11-28 18:35:01 -07:00
|
|
|
static inline void
|
2007-07-07 23:30:49 -06:00
|
|
|
nf_ct_expect_event(enum ip_conntrack_expect_events event,
|
|
|
|
struct nf_conntrack_expect *exp)
|
2006-11-28 18:35:01 -07:00
|
|
|
{
|
2008-11-18 03:56:20 -07:00
|
|
|
nf_ct_expect_event_report(event, exp, 0, 0);
|
2006-11-28 18:35:01 -07:00
|
|
|
}
|
|
|
|
|
2008-10-08 03:35:07 -06:00
|
|
|
extern int nf_conntrack_ecache_init(struct net *net);
|
|
|
|
extern void nf_conntrack_ecache_fini(struct net *net);
|
|
|
|
|
2006-11-28 18:35:01 -07:00
|
|
|
#else /* CONFIG_NF_CONNTRACK_EVENTS */
|
|
|
|
|
|
|
|
static inline void nf_conntrack_event_cache(enum ip_conntrack_events event,
|
2008-10-11 10:46:24 -06:00
|
|
|
struct nf_conn *ct) {}
|
2009-06-13 04:26:29 -06:00
|
|
|
static inline void nf_conntrack_eventmask_report(unsigned int eventmask,
|
|
|
|
struct nf_conn *ct,
|
|
|
|
u32 pid,
|
|
|
|
int report) {}
|
2006-11-28 18:35:01 -07:00
|
|
|
static inline void nf_conntrack_event(enum ip_conntrack_events event,
|
|
|
|
struct nf_conn *ct) {}
|
2008-11-18 03:56:20 -07:00
|
|
|
static inline void nf_conntrack_event_report(enum ip_conntrack_events event,
|
|
|
|
struct nf_conn *ct,
|
|
|
|
u32 pid,
|
|
|
|
int report) {}
|
2006-11-28 18:35:01 -07:00
|
|
|
static inline void nf_ct_deliver_cached_events(const struct nf_conn *ct) {}
|
2007-07-07 23:30:49 -06:00
|
|
|
static inline void nf_ct_expect_event(enum ip_conntrack_expect_events event,
|
|
|
|
struct nf_conntrack_expect *exp) {}
|
2008-11-18 03:56:20 -07:00
|
|
|
static inline void nf_ct_expect_event_report(enum ip_conntrack_expect_events e,
|
|
|
|
struct nf_conntrack_expect *exp,
|
|
|
|
u32 pid,
|
|
|
|
int report) {}
|
2008-10-08 03:35:07 -06:00
|
|
|
|
|
|
|
static inline int nf_conntrack_ecache_init(struct net *net)
|
|
|
|
{
|
|
|
|
return 0;
|
2008-10-09 22:10:36 -06:00
|
|
|
}
|
2008-10-08 03:35:07 -06:00
|
|
|
|
|
|
|
static inline void nf_conntrack_ecache_fini(struct net *net)
|
|
|
|
{
|
|
|
|
}
|
2006-11-28 18:35:01 -07:00
|
|
|
#endif /* CONFIG_NF_CONNTRACK_EVENTS */
|
|
|
|
|
|
|
|
#endif /*_NF_CONNTRACK_ECACHE_H*/
|
|
|
|
|