aboutsummaryrefslogtreecommitdiffstats
path: root/net/netfilter
diff options
context:
space:
mode:
authorJan Engelhardt <jengelh@medozas.de>2010-03-25 11:34:45 -0400
committerJan Engelhardt <jengelh@medozas.de>2010-03-25 11:55:49 -0400
commitd6b00a5345ce4e86e8b00a88bb84a2c0c1f69ddc (patch)
tree11d68bb08584fbbae02a7bf22599bdd67da4408e /net/netfilter
parentbd414ee605ff3ac5fcd79f57269a897879ee4cde (diff)
netfilter: xtables: change targets to return error code
Part of the transition of done by this semantic patch: // <smpl> @ rule1 @ struct xt_target ops; identifier check; @@ ops.checkentry = check; @@ identifier rule1.check; @@ check(...) { <... -return true; +return 0; ...> } @@ identifier rule1.check; @@ check(...) { <... -return false; +return -EINVAL; ...> } // </smpl> Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
Diffstat (limited to 'net/netfilter')
-rw-r--r--net/netfilter/x_tables.c12
-rw-r--r--net/netfilter/xt_CONNSECMARK.c6
-rw-r--r--net/netfilter/xt_CT.c6
-rw-r--r--net/netfilter/xt_DSCP.c4
-rw-r--r--net/netfilter/xt_HL.c10
-rw-r--r--net/netfilter/xt_LED.c10
-rw-r--r--net/netfilter/xt_NFLOG.c6
-rw-r--r--net/netfilter/xt_NFQUEUE.c6
-rw-r--r--net/netfilter/xt_RATEEST.c9
-rw-r--r--net/netfilter/xt_SECMARK.c10
-rw-r--r--net/netfilter/xt_TCPMSS.c12
-rw-r--r--net/netfilter/xt_TPROXY.c4
12 files changed, 50 insertions, 45 deletions
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index 7ee177746172..8e23d8f68459 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -528,6 +528,8 @@ EXPORT_SYMBOL_GPL(xt_compat_match_to_user);
528int xt_check_target(struct xt_tgchk_param *par, 528int xt_check_target(struct xt_tgchk_param *par,
529 unsigned int size, u_int8_t proto, bool inv_proto) 529 unsigned int size, u_int8_t proto, bool inv_proto)
530{ 530{
531 int ret;
532
531 if (XT_ALIGN(par->target->targetsize) != size) { 533 if (XT_ALIGN(par->target->targetsize) != size) {
532 pr_err("%s_tables: %s.%u target: invalid size " 534 pr_err("%s_tables: %s.%u target: invalid size "
533 "%u (kernel) != (user) %u\n", 535 "%u (kernel) != (user) %u\n",
@@ -559,8 +561,14 @@ int xt_check_target(struct xt_tgchk_param *par,
559 par->target->proto); 561 par->target->proto);
560 return -EINVAL; 562 return -EINVAL;
561 } 563 }
562 if (par->target->checkentry != NULL && !par->target->checkentry(par)) 564 if (par->target->checkentry != NULL) {
563 return -EINVAL; 565 ret = par->target->checkentry(par);
566 if (ret < 0)
567 return ret;
568 else if (ret > 0)
569 /* Flag up potential errors. */
570 return -EIO;
571 }
564 return 0; 572 return 0;
565} 573}
566EXPORT_SYMBOL_GPL(xt_check_target); 574EXPORT_SYMBOL_GPL(xt_check_target);
diff --git a/net/netfilter/xt_CONNSECMARK.c b/net/netfilter/xt_CONNSECMARK.c
index 3f9d0f4f852d..2287a82a0703 100644
--- a/net/netfilter/xt_CONNSECMARK.c
+++ b/net/netfilter/xt_CONNSECMARK.c
@@ -92,7 +92,7 @@ static int connsecmark_tg_check(const struct xt_tgchk_param *par)
92 strcmp(par->table, "security") != 0) { 92 strcmp(par->table, "security") != 0) {
93 pr_info("target only valid in the \'mangle\' " 93 pr_info("target only valid in the \'mangle\' "
94 "or \'security\' tables, not \'%s\'.\n", par->table); 94 "or \'security\' tables, not \'%s\'.\n", par->table);
95 return false; 95 return -EINVAL;
96 } 96 }
97 97
98 switch (info->mode) { 98 switch (info->mode) {
@@ -108,9 +108,9 @@ static int connsecmark_tg_check(const struct xt_tgchk_param *par)
108 if (nf_ct_l3proto_try_module_get(par->family) < 0) { 108 if (nf_ct_l3proto_try_module_get(par->family) < 0) {
109 pr_info("cannot load conntrack support for proto=%u\n", 109 pr_info("cannot load conntrack support for proto=%u\n",
110 par->family); 110 par->family);
111 return false; 111 return -EINVAL;
112 } 112 }
113 return true; 113 return 0;
114} 114}
115 115
116static void connsecmark_tg_destroy(const struct xt_tgdtor_param *par) 116static void connsecmark_tg_destroy(const struct xt_tgdtor_param *par)
diff --git a/net/netfilter/xt_CT.c b/net/netfilter/xt_CT.c
index c1553bf06cf6..ee566e2e4534 100644
--- a/net/netfilter/xt_CT.c
+++ b/net/netfilter/xt_CT.c
@@ -62,7 +62,7 @@ static int xt_ct_tg_check(const struct xt_tgchk_param *par)
62 u8 proto; 62 u8 proto;
63 63
64 if (info->flags & ~XT_CT_NOTRACK) 64 if (info->flags & ~XT_CT_NOTRACK)
65 return false; 65 return -EINVAL;
66 66
67 if (info->flags & XT_CT_NOTRACK) { 67 if (info->flags & XT_CT_NOTRACK) {
68 ct = &nf_conntrack_untracked; 68 ct = &nf_conntrack_untracked;
@@ -108,14 +108,14 @@ static int xt_ct_tg_check(const struct xt_tgchk_param *par)
108 __set_bit(IPS_CONFIRMED_BIT, &ct->status); 108 __set_bit(IPS_CONFIRMED_BIT, &ct->status);
109out: 109out:
110 info->ct = ct; 110 info->ct = ct;
111 return true; 111 return 0;
112 112
113err3: 113err3:
114 nf_conntrack_free(ct); 114 nf_conntrack_free(ct);
115err2: 115err2:
116 nf_ct_l3proto_module_put(par->family); 116 nf_ct_l3proto_module_put(par->family);
117err1: 117err1:
118 return false; 118 return -EINVAL;
119} 119}
120 120
121static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par) 121static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par)
diff --git a/net/netfilter/xt_DSCP.c b/net/netfilter/xt_DSCP.c
index 1fa7b67bf225..aa263b80f8c0 100644
--- a/net/netfilter/xt_DSCP.c
+++ b/net/netfilter/xt_DSCP.c
@@ -66,9 +66,9 @@ static int dscp_tg_check(const struct xt_tgchk_param *par)
66 66
67 if (info->dscp > XT_DSCP_MAX) { 67 if (info->dscp > XT_DSCP_MAX) {
68 pr_info("dscp %x out of range\n", info->dscp); 68 pr_info("dscp %x out of range\n", info->dscp);
69 return false; 69 return -EINVAL;
70 } 70 }
71 return true; 71 return 0;
72} 72}
73 73
74static unsigned int 74static unsigned int
diff --git a/net/netfilter/xt_HL.c b/net/netfilter/xt_HL.c
index 15ba16108182..7a47383ec723 100644
--- a/net/netfilter/xt_HL.c
+++ b/net/netfilter/xt_HL.c
@@ -110,8 +110,8 @@ static int ttl_tg_check(const struct xt_tgchk_param *par)
110 return false; 110 return false;
111 } 111 }
112 if (info->mode != IPT_TTL_SET && info->ttl == 0) 112 if (info->mode != IPT_TTL_SET && info->ttl == 0)
113 return false; 113 return -EINVAL;
114 return true; 114 return 0;
115} 115}
116 116
117static int hl_tg6_check(const struct xt_tgchk_param *par) 117static int hl_tg6_check(const struct xt_tgchk_param *par)
@@ -120,14 +120,14 @@ static int hl_tg6_check(const struct xt_tgchk_param *par)
120 120
121 if (info->mode > IP6T_HL_MAXMODE) { 121 if (info->mode > IP6T_HL_MAXMODE) {
122 pr_info("invalid or unknown mode %u\n", info->mode); 122 pr_info("invalid or unknown mode %u\n", info->mode);
123 return false; 123 return -EINVAL;
124 } 124 }
125 if (info->mode != IP6T_HL_SET && info->hop_limit == 0) { 125 if (info->mode != IP6T_HL_SET && info->hop_limit == 0) {
126 pr_info("increment/decrement does not " 126 pr_info("increment/decrement does not "
127 "make sense with value 0\n"); 127 "make sense with value 0\n");
128 return false; 128 return -EINVAL;
129 } 129 }
130 return true; 130 return 0;
131} 131}
132 132
133static struct xt_target hl_tg_reg[] __read_mostly = { 133static struct xt_target hl_tg_reg[] __read_mostly = {
diff --git a/net/netfilter/xt_LED.c b/net/netfilter/xt_LED.c
index 1a3e3dd5a774..22b5b7057397 100644
--- a/net/netfilter/xt_LED.c
+++ b/net/netfilter/xt_LED.c
@@ -88,12 +88,12 @@ static int led_tg_check(const struct xt_tgchk_param *par)
88 88
89 if (ledinfo->id[0] == '\0') { 89 if (ledinfo->id[0] == '\0') {
90 pr_info("No 'id' parameter given.\n"); 90 pr_info("No 'id' parameter given.\n");
91 return false; 91 return -EINVAL;
92 } 92 }
93 93
94 ledinternal = kzalloc(sizeof(struct xt_led_info_internal), GFP_KERNEL); 94 ledinternal = kzalloc(sizeof(struct xt_led_info_internal), GFP_KERNEL);
95 if (!ledinternal) 95 if (!ledinternal)
96 return false; 96 return -EINVAL;
97 97
98 ledinternal->netfilter_led_trigger.name = ledinfo->id; 98 ledinternal->netfilter_led_trigger.name = ledinfo->id;
99 99
@@ -111,13 +111,11 @@ static int led_tg_check(const struct xt_tgchk_param *par)
111 (unsigned long)ledinfo); 111 (unsigned long)ledinfo);
112 112
113 ledinfo->internal_data = ledinternal; 113 ledinfo->internal_data = ledinternal;
114 114 return 0;
115 return true;
116 115
117exit_alloc: 116exit_alloc:
118 kfree(ledinternal); 117 kfree(ledinternal);
119 118 return -EINVAL;
120 return false;
121} 119}
122 120
123static void led_tg_destroy(const struct xt_tgdtor_param *par) 121static void led_tg_destroy(const struct xt_tgdtor_param *par)
diff --git a/net/netfilter/xt_NFLOG.c b/net/netfilter/xt_NFLOG.c
index 13e6c0002c8a..42dd8747b421 100644
--- a/net/netfilter/xt_NFLOG.c
+++ b/net/netfilter/xt_NFLOG.c
@@ -42,10 +42,10 @@ static int nflog_tg_check(const struct xt_tgchk_param *par)
42 const struct xt_nflog_info *info = par->targinfo; 42 const struct xt_nflog_info *info = par->targinfo;
43 43
44 if (info->flags & ~XT_NFLOG_MASK) 44 if (info->flags & ~XT_NFLOG_MASK)
45 return false; 45 return -EINVAL;
46 if (info->prefix[sizeof(info->prefix) - 1] != '\0') 46 if (info->prefix[sizeof(info->prefix) - 1] != '\0')
47 return false; 47 return -EINVAL;
48 return true; 48 return 0;
49} 49}
50 50
51static struct xt_target nflog_tg_reg __read_mostly = { 51static struct xt_target nflog_tg_reg __read_mostly = {
diff --git a/net/netfilter/xt_NFQUEUE.c b/net/netfilter/xt_NFQUEUE.c
index d435579a64ca..add1789ae4a8 100644
--- a/net/netfilter/xt_NFQUEUE.c
+++ b/net/netfilter/xt_NFQUEUE.c
@@ -92,15 +92,15 @@ static int nfqueue_tg_v1_check(const struct xt_tgchk_param *par)
92 } 92 }
93 if (info->queues_total == 0) { 93 if (info->queues_total == 0) {
94 pr_err("NFQUEUE: number of total queues is 0\n"); 94 pr_err("NFQUEUE: number of total queues is 0\n");
95 return false; 95 return -EINVAL;
96 } 96 }
97 maxid = info->queues_total - 1 + info->queuenum; 97 maxid = info->queues_total - 1 + info->queuenum;
98 if (maxid > 0xffff) { 98 if (maxid > 0xffff) {
99 pr_err("NFQUEUE: number of queues (%u) out of range (got %u)\n", 99 pr_err("NFQUEUE: number of queues (%u) out of range (got %u)\n",
100 info->queues_total, maxid); 100 info->queues_total, maxid);
101 return false; 101 return -EINVAL;
102 } 102 }
103 return true; 103 return 0;
104} 104}
105 105
106static struct xt_target nfqueue_tg_reg[] __read_mostly = { 106static struct xt_target nfqueue_tg_reg[] __read_mostly = {
diff --git a/net/netfilter/xt_RATEEST.c b/net/netfilter/xt_RATEEST.c
index 9743e50be8ef..7af5fba39cdd 100644
--- a/net/netfilter/xt_RATEEST.c
+++ b/net/netfilter/xt_RATEEST.c
@@ -109,10 +109,10 @@ static int xt_rateest_tg_checkentry(const struct xt_tgchk_param *par)
109 (info->interval != est->params.interval || 109 (info->interval != est->params.interval ||
110 info->ewma_log != est->params.ewma_log)) { 110 info->ewma_log != est->params.ewma_log)) {
111 xt_rateest_put(est); 111 xt_rateest_put(est);
112 return false; 112 return -EINVAL;
113 } 113 }
114 info->est = est; 114 info->est = est;
115 return true; 115 return 0;
116 } 116 }
117 117
118 est = kzalloc(sizeof(*est), GFP_KERNEL); 118 est = kzalloc(sizeof(*est), GFP_KERNEL);
@@ -136,13 +136,12 @@ static int xt_rateest_tg_checkentry(const struct xt_tgchk_param *par)
136 136
137 info->est = est; 137 info->est = est;
138 xt_rateest_hash_insert(est); 138 xt_rateest_hash_insert(est);
139 139 return 0;
140 return true;
141 140
142err2: 141err2:
143 kfree(est); 142 kfree(est);
144err1: 143err1:
145 return false; 144 return -EINVAL;
146} 145}
147 146
148static void xt_rateest_tg_destroy(const struct xt_tgdtor_param *par) 147static void xt_rateest_tg_destroy(const struct xt_tgdtor_param *par)
diff --git a/net/netfilter/xt_SECMARK.c b/net/netfilter/xt_SECMARK.c
index 48f8e4f7ea8a..39098fc9887d 100644
--- a/net/netfilter/xt_SECMARK.c
+++ b/net/netfilter/xt_SECMARK.c
@@ -88,29 +88,29 @@ static int secmark_tg_check(const struct xt_tgchk_param *par)
88 strcmp(par->table, "security") != 0) { 88 strcmp(par->table, "security") != 0) {
89 pr_info("target only valid in the \'mangle\' " 89 pr_info("target only valid in the \'mangle\' "
90 "or \'security\' tables, not \'%s\'.\n", par->table); 90 "or \'security\' tables, not \'%s\'.\n", par->table);
91 return false; 91 return -EINVAL;
92 } 92 }
93 93
94 if (mode && mode != info->mode) { 94 if (mode && mode != info->mode) {
95 pr_info("mode already set to %hu cannot mix with " 95 pr_info("mode already set to %hu cannot mix with "
96 "rules for mode %hu\n", mode, info->mode); 96 "rules for mode %hu\n", mode, info->mode);
97 return false; 97 return -EINVAL;
98 } 98 }
99 99
100 switch (info->mode) { 100 switch (info->mode) {
101 case SECMARK_MODE_SEL: 101 case SECMARK_MODE_SEL:
102 if (!checkentry_selinux(info)) 102 if (!checkentry_selinux(info))
103 return false; 103 return -EINVAL;
104 break; 104 break;
105 105
106 default: 106 default:
107 pr_info("invalid mode: %hu\n", info->mode); 107 pr_info("invalid mode: %hu\n", info->mode);
108 return false; 108 return -EINVAL;
109 } 109 }
110 110
111 if (!mode) 111 if (!mode)
112 mode = info->mode; 112 mode = info->mode;
113 return true; 113 return 0;
114} 114}
115 115
116static void secmark_tg_destroy(const struct xt_tgdtor_param *par) 116static void secmark_tg_destroy(const struct xt_tgdtor_param *par)
diff --git a/net/netfilter/xt_TCPMSS.c b/net/netfilter/xt_TCPMSS.c
index 70288dc31583..385677b963d5 100644
--- a/net/netfilter/xt_TCPMSS.c
+++ b/net/netfilter/xt_TCPMSS.c
@@ -246,13 +246,13 @@ static int tcpmss_tg4_check(const struct xt_tgchk_param *par)
246 (1 << NF_INET_POST_ROUTING))) != 0) { 246 (1 << NF_INET_POST_ROUTING))) != 0) {
247 pr_info("path-MTU clamping only supported in " 247 pr_info("path-MTU clamping only supported in "
248 "FORWARD, OUTPUT and POSTROUTING hooks\n"); 248 "FORWARD, OUTPUT and POSTROUTING hooks\n");
249 return false; 249 return -EINVAL;
250 } 250 }
251 xt_ematch_foreach(ematch, e) 251 xt_ematch_foreach(ematch, e)
252 if (find_syn_match(ematch)) 252 if (find_syn_match(ematch))
253 return true; 253 return 0;
254 pr_info("Only works on TCP SYN packets\n"); 254 pr_info("Only works on TCP SYN packets\n");
255 return false; 255 return -EINVAL;
256} 256}
257 257
258#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE) 258#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
@@ -268,13 +268,13 @@ static int tcpmss_tg6_check(const struct xt_tgchk_param *par)
268 (1 << NF_INET_POST_ROUTING))) != 0) { 268 (1 << NF_INET_POST_ROUTING))) != 0) {
269 pr_info("path-MTU clamping only supported in " 269 pr_info("path-MTU clamping only supported in "
270 "FORWARD, OUTPUT and POSTROUTING hooks\n"); 270 "FORWARD, OUTPUT and POSTROUTING hooks\n");
271 return false; 271 return -EINVAL;
272 } 272 }
273 xt_ematch_foreach(ematch, e) 273 xt_ematch_foreach(ematch, e)
274 if (find_syn_match(ematch)) 274 if (find_syn_match(ematch))
275 return true; 275 return 0;
276 pr_info("Only works on TCP SYN packets\n"); 276 pr_info("Only works on TCP SYN packets\n");
277 return false; 277 return -EINVAL;
278} 278}
279#endif 279#endif
280 280
diff --git a/net/netfilter/xt_TPROXY.c b/net/netfilter/xt_TPROXY.c
index 189df9af4de6..4f246ddc5c48 100644
--- a/net/netfilter/xt_TPROXY.c
+++ b/net/netfilter/xt_TPROXY.c
@@ -65,11 +65,11 @@ static int tproxy_tg_check(const struct xt_tgchk_param *par)
65 65
66 if ((i->proto == IPPROTO_TCP || i->proto == IPPROTO_UDP) 66 if ((i->proto == IPPROTO_TCP || i->proto == IPPROTO_UDP)
67 && !(i->invflags & IPT_INV_PROTO)) 67 && !(i->invflags & IPT_INV_PROTO))
68 return true; 68 return 0;
69 69
70 pr_info("Can be used only in combination with " 70 pr_info("Can be used only in combination with "
71 "either -p tcp or -p udp\n"); 71 "either -p tcp or -p udp\n");
72 return false; 72 return -EINVAL;
73} 73}
74 74
75static struct xt_target tproxy_tg_reg __read_mostly = { 75static struct xt_target tproxy_tg_reg __read_mostly = {