~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/net/netfilter/nf_conntrack_ecache.h

Version: ~ [ linux-5.7 ] ~ [ linux-5.6.15 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.43 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.125 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.182 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.225 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.225 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.84 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*
  3  * connection tracking event cache.
  4  */
  5 
  6 #ifndef _NF_CONNTRACK_ECACHE_H
  7 #define _NF_CONNTRACK_ECACHE_H
  8 #include <net/netfilter/nf_conntrack.h>
  9 
 10 #include <net/net_namespace.h>
 11 #include <net/netfilter/nf_conntrack_expect.h>
 12 #include <linux/netfilter/nf_conntrack_common.h>
 13 #include <linux/netfilter/nf_conntrack_tuple_common.h>
 14 #include <net/netfilter/nf_conntrack_extend.h>
 15 
 16 enum nf_ct_ecache_state {
 17         NFCT_ECACHE_UNKNOWN,            /* destroy event not sent */
 18         NFCT_ECACHE_DESTROY_FAIL,       /* tried but failed to send destroy event */
 19         NFCT_ECACHE_DESTROY_SENT,       /* sent destroy event after failure */
 20 };
 21 
 22 struct nf_conntrack_ecache {
 23         unsigned long cache;            /* bitops want long */
 24         u16 missed;                     /* missed events */
 25         u16 ctmask;                     /* bitmask of ct events to be delivered */
 26         u16 expmask;                    /* bitmask of expect events to be delivered */
 27         enum nf_ct_ecache_state state:8;/* ecache state */
 28         u32 portid;                     /* netlink portid of destroyer */
 29 };
 30 
 31 static inline struct nf_conntrack_ecache *
 32 nf_ct_ecache_find(const struct nf_conn *ct)
 33 {
 34 #ifdef CONFIG_NF_CONNTRACK_EVENTS
 35         return nf_ct_ext_find(ct, NF_CT_EXT_ECACHE);
 36 #else
 37         return NULL;
 38 #endif
 39 }
 40 
 41 static inline struct nf_conntrack_ecache *
 42 nf_ct_ecache_ext_add(struct nf_conn *ct, u16 ctmask, u16 expmask, gfp_t gfp)
 43 {
 44 #ifdef CONFIG_NF_CONNTRACK_EVENTS
 45         struct net *net = nf_ct_net(ct);
 46         struct nf_conntrack_ecache *e;
 47 
 48         if (!ctmask && !expmask && net->ct.sysctl_events) {
 49                 ctmask = ~0;
 50                 expmask = ~0;
 51         }
 52         if (!ctmask && !expmask)
 53                 return NULL;
 54 
 55         e = nf_ct_ext_add(ct, NF_CT_EXT_ECACHE, gfp);
 56         if (e) {
 57                 e->ctmask  = ctmask;
 58                 e->expmask = expmask;
 59         }
 60         return e;
 61 #else
 62         return NULL;
 63 #endif
 64 };
 65 
 66 #ifdef CONFIG_NF_CONNTRACK_EVENTS
 67 /* This structure is passed to event handler */
 68 struct nf_ct_event {
 69         struct nf_conn *ct;
 70         u32 portid;
 71         int report;
 72 };
 73 
 74 struct nf_ct_event_notifier {
 75         int (*fcn)(unsigned int events, struct nf_ct_event *item);
 76 };
 77 
 78 int nf_conntrack_register_notifier(struct net *net,
 79                                    struct nf_ct_event_notifier *nb);
 80 void nf_conntrack_unregister_notifier(struct net *net,
 81                                       struct nf_ct_event_notifier *nb);
 82 
 83 void nf_ct_deliver_cached_events(struct nf_conn *ct);
 84 int nf_conntrack_eventmask_report(unsigned int eventmask, struct nf_conn *ct,
 85                                   u32 portid, int report);
 86 
 87 static inline void
 88 nf_conntrack_event_cache(enum ip_conntrack_events event, struct nf_conn *ct)
 89 {
 90         struct net *net = nf_ct_net(ct);
 91         struct nf_conntrack_ecache *e;
 92 
 93         if (!rcu_access_pointer(net->ct.nf_conntrack_event_cb))
 94                 return;
 95 
 96         e = nf_ct_ecache_find(ct);
 97         if (e == NULL)
 98                 return;
 99 
100         set_bit(event, &e->cache);
101 }
102 
103 static inline int
104 nf_conntrack_event_report(enum ip_conntrack_events event, struct nf_conn *ct,
105                           u32 portid, int report)
106 {
107         const struct net *net = nf_ct_net(ct);
108 
109         if (!rcu_access_pointer(net->ct.nf_conntrack_event_cb))
110                 return 0;
111 
112         return nf_conntrack_eventmask_report(1 << event, ct, portid, report);
113 }
114 
115 static inline int
116 nf_conntrack_event(enum ip_conntrack_events event, struct nf_conn *ct)
117 {
118         const struct net *net = nf_ct_net(ct);
119 
120         if (!rcu_access_pointer(net->ct.nf_conntrack_event_cb))
121                 return 0;
122 
123         return nf_conntrack_eventmask_report(1 << event, ct, 0, 0);
124 }
125 
126 struct nf_exp_event {
127         struct nf_conntrack_expect *exp;
128         u32 portid;
129         int report;
130 };
131 
132 struct nf_exp_event_notifier {
133         int (*fcn)(unsigned int events, struct nf_exp_event *item);
134 };
135 
136 int nf_ct_expect_register_notifier(struct net *net,
137                                    struct nf_exp_event_notifier *nb);
138 void nf_ct_expect_unregister_notifier(struct net *net,
139                                       struct nf_exp_event_notifier *nb);
140 
141 void nf_ct_expect_event_report(enum ip_conntrack_expect_events event,
142                                struct nf_conntrack_expect *exp,
143                                u32 portid, int report);
144 
145 void nf_conntrack_ecache_pernet_init(struct net *net);
146 void nf_conntrack_ecache_pernet_fini(struct net *net);
147 
148 int nf_conntrack_ecache_init(void);
149 void nf_conntrack_ecache_fini(void);
150 
151 static inline void nf_conntrack_ecache_delayed_work(struct net *net)
152 {
153         if (!delayed_work_pending(&net->ct.ecache_dwork)) {
154                 schedule_delayed_work(&net->ct.ecache_dwork, HZ);
155                 net->ct.ecache_dwork_pending = true;
156         }
157 }
158 
159 static inline void nf_conntrack_ecache_work(struct net *net)
160 {
161         if (net->ct.ecache_dwork_pending) {
162                 net->ct.ecache_dwork_pending = false;
163                 mod_delayed_work(system_wq, &net->ct.ecache_dwork, 0);
164         }
165 }
166 #else /* CONFIG_NF_CONNTRACK_EVENTS */
167 static inline void nf_conntrack_event_cache(enum ip_conntrack_events event,
168                                             struct nf_conn *ct) {}
169 static inline int nf_conntrack_eventmask_report(unsigned int eventmask,
170                                                 struct nf_conn *ct,
171                                                 u32 portid,
172                                                 int report) { return 0; }
173 static inline int nf_conntrack_event(enum ip_conntrack_events event,
174                                      struct nf_conn *ct) { return 0; }
175 static inline int nf_conntrack_event_report(enum ip_conntrack_events event,
176                                             struct nf_conn *ct,
177                                             u32 portid,
178                                             int report) { return 0; }
179 static inline void nf_ct_deliver_cached_events(const struct nf_conn *ct) {}
180 static inline void nf_ct_expect_event_report(enum ip_conntrack_expect_events e,
181                                              struct nf_conntrack_expect *exp,
182                                              u32 portid,
183                                              int report) {}
184 
185 static inline void nf_conntrack_ecache_pernet_init(struct net *net) {}
186 
187 static inline void nf_conntrack_ecache_pernet_fini(struct net *net)
188 {
189 }
190 
191 static inline int nf_conntrack_ecache_init(void)
192 {
193         return 0;
194 }
195 
196 static inline void nf_conntrack_ecache_fini(void)
197 {
198 }
199 
200 static inline void nf_conntrack_ecache_delayed_work(struct net *net)
201 {
202 }
203 
204 static inline void nf_conntrack_ecache_work(struct net *net)
205 {
206 }
207 #endif /* CONFIG_NF_CONNTRACK_EVENTS */
208 
209 #endif /*_NF_CONNTRACK_ECACHE_H*/
210 
211 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp