History

netfilter: xt_CT: merge common code of revision 0 and 1

This patch merges the common code for revision 0 and 1.

Pablo Neira Ayuso committed 13 years ago

Commit d52ed431 parent d1beadd1 file · +56 −89Browse files

Unified · Split

net/netfilter/xt_CT.c+56−89
@@ -20,12 +20,8 @@ · 19 unmodified lines
2020 #include <net/netfilter/nf_conntrack_timeout.h>
2121 #include <net/netfilter/nf_conntrack_zones.h>
2222
23−static unsigned int xt_ct_target_v0(struct sk_buff *skb,
24− const struct xt_action_param *par)
23+static inline int xt_ct_target(struct sk_buff *skb, struct nf_conn *ct)
2524 {
26− const struct xt_ct_target_info *info = par->targinfo;
27− struct nf_conn *ct = info->ct;
28−
2925 /* Previously seen (loopback)? Ignore. */
3026 if (skb->nfct != NULL)
3127 return XT_CONTINUE;
@@ -37,21 +33,22 @@ static unsigned int xt_ct_target_v0(struct sk_buff *skb, · 5 unmodified lines
3733 return XT_CONTINUE;
3834 }
3935
40−static unsigned int xt_ct_target_v1(struct sk_buff *skb,
36+static unsigned int xt_ct_target_v0(struct sk_buff *skb,
4137 const struct xt_action_param *par)
4238 {
43− const struct xt_ct_target_info_v1 *info = par->targinfo;
39+ const struct xt_ct_target_info *info = par->targinfo;
4440 struct nf_conn *ct = info->ct;
4541
46− /* Previously seen (loopback)? Ignore. */
47− if (skb->nfct != NULL)
48− return XT_CONTINUE;
42+ return xt_ct_target(skb, ct);
43+}
4944
50− atomic_inc(&ct->ct_general.use);
51− skb->nfct = &ct->ct_general;
52− skb->nfctinfo = IP_CT_NEW;
45+static unsigned int xt_ct_target_v1(struct sk_buff *skb,
46+ const struct xt_action_param *par)
47+{
48+ const struct xt_ct_target_info_v1 *info = par->targinfo;
49+ struct nf_conn *ct = info->ct;
5350
54− return XT_CONTINUE;
51+ return xt_ct_target(skb, ct);
5552 }
5653
5754 static u8 xt_ct_find_proto(const struct xt_tgchk_param *par)
@@ -104,67 +101,6 @@ xt_ct_set_helper(struct nf_conn *ct, const char *helper_name, · 46 unmodified lines
104101 return 0;
105102 }
106103
107−static int xt_ct_tg_check_v0(const struct xt_tgchk_param *par)
108−{
109− struct xt_ct_target_info *info = par->targinfo;
110− struct nf_conntrack_tuple t;
111− struct nf_conn *ct;
112− int ret = -EOPNOTSUPP;
113−
114− if (info->flags & ~XT_CT_NOTRACK)
115− return -EINVAL;
116−
117− if (info->flags & XT_CT_NOTRACK) {
118− ct = nf_ct_untracked_get();
119− atomic_inc(&ct->ct_general.use);
120− goto out;
121− }
122−
123−#ifndef CONFIG_NF_CONNTRACK_ZONES
124− if (info->zone)
125− goto err1;
126−#endif
127−
128− ret = nf_ct_l3proto_try_module_get(par->family);
129− if (ret < 0)
130− goto err1;
131−
132− memset(&t, 0, sizeof(t));
133− ct = nf_conntrack_alloc(par->net, info->zone, &t, &t, GFP_KERNEL);
134− ret = PTR_ERR(ct);
135− if (IS_ERR(ct))
136− goto err2;
137−
138− ret = 0;
139− if ((info->ct_events || info->exp_events) &&
140− !nf_ct_ecache_ext_add(ct, info->ct_events, info->exp_events,
141− GFP_KERNEL))
142− goto err3;
143−
144− if (info->helper[0]) {
145− ret = xt_ct_set_helper(ct, info->helper, par);
146− if (ret < 0)
147− goto err3;
148− }
149−
150− __set_bit(IPS_TEMPLATE_BIT, &ct->status);
151− __set_bit(IPS_CONFIRMED_BIT, &ct->status);
152−
153− /* Overload tuple linked list to put us in template list. */
154− hlist_nulls_add_head_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode,
155− &par->net->ct.tmpl);
156−out:
157− info->ct = ct;
158− return 0;
159−
160−err3:
161− nf_conntrack_free(ct);
162−err2:
163− nf_ct_l3proto_module_put(par->family);
164−err1:
165− return ret;
166−}
167−
168104 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
169105 static void __xt_ct_tg_timeout_put(struct ctnl_timeout *timeout)
170106 {
@@ -242,9 +178,9 @@ out: · 71 unmodified lines
242178 #endif
243179 }
244180
245−static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par)
181+static int xt_ct_tg_check(const struct xt_tgchk_param *par,
182+ struct xt_ct_target_info_v1 *info)
246183 {
247− struct xt_ct_target_info_v1 *info = par->targinfo;
248184 struct nf_conntrack_tuple t;
249185 struct nf_conn *ct;
250186 int ret = -EOPNOTSUPP;
@@ -309,20 +245,31 @@ err1: · 58 unmodified lines
309245 return ret;
310246 }
311247
312−static void xt_ct_tg_destroy_v0(const struct xt_tgdtor_param *par)
248+static int xt_ct_tg_check_v0(const struct xt_tgchk_param *par)
313249 {
314250 struct xt_ct_target_info *info = par->targinfo;
315− struct nf_conn *ct = info->ct;
316− struct nf_conn_help *help;
251+ struct xt_ct_target_info_v1 info_v1 = {
252+ .flags = info->flags,
253+ .zone = info->zone,
254+ .ct_events = info->ct_events,
255+ .exp_events = info->exp_events,
256+ };
257+ int ret;
317258
318− if (!nf_ct_is_untracked(ct)) {
319− help = nfct_help(ct);
320− if (help)
321− module_put(help->helper->me);
259+ memcpy(info_v1.helper, info->helper, sizeof(info->helper));
322260
323− nf_ct_l3proto_module_put(par->family);
324− }
325− nf_ct_put(info->ct);
261+ ret = xt_ct_tg_check(par, &info_v1);
262+ if (ret < 0)
263+ return ret;
264+
265+ info->ct = info_v1.ct;
266+
267+ return ret;
268+}
269+
270+static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par)
271+{
272+ return xt_ct_tg_check(par, par->targinfo);
326273 }
327274
328275 static void xt_ct_destroy_timeout(struct nf_conn *ct)
@@ -343,9 +290,9 @@ static void xt_ct_destroy_timeout(struct nf_conn *ct) · 14 unmodified lines
343290 #endif
344291 }
345292
346−static void xt_ct_tg_destroy_v1(const struct xt_tgdtor_param *par)
293+static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par,
294+ struct xt_ct_target_info_v1 *info)
347295 {
348− struct xt_ct_target_info_v1 *info = par->targinfo;
349296 struct nf_conn *ct = info->ct;
350297 struct nf_conn_help *help;
351298
@@ -361,6 +308,26 @@ static void xt_ct_tg_destroy_v1(const struct xt_tgdtor_param *par) · 9 unmodified lines
361308 nf_ct_put(info->ct);
362309 }
363310
311+static void xt_ct_tg_destroy_v0(const struct xt_tgdtor_param *par)
312+{
313+ struct xt_ct_target_info *info = par->targinfo;
314+ struct xt_ct_target_info_v1 info_v1 = {
315+ .flags = info->flags,
316+ .zone = info->zone,
317+ .ct_events = info->ct_events,
318+ .exp_events = info->exp_events,
319+ .ct = info->ct,
320+ };
321+ memcpy(info_v1.helper, info->helper, sizeof(info->helper));
322+
323+ xt_ct_tg_destroy(par, &info_v1);
324+}
325+
326+static void xt_ct_tg_destroy_v1(const struct xt_tgdtor_param *par)
327+{
328+ xt_ct_tg_destroy(par, par->targinfo);
329+}
330+
364331 static struct xt_target xt_ct_tg_reg[] __read_mostly = {
365332 {
366333 .name = "CT",

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t