Commit c08e5e1e authored by Florian Westphal's avatar Florian Westphal Committed by Pablo Neira Ayuso

netfilter: x_tables: use pr ratelimiting in matches/targets

all of these print simple error message - use single pr_ratelimit call.
checkpatch complains about lines > 80 but this would require splitting
several "literals" over multiple lines which is worse.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent cc48baef
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
* the Free Software Foundation. * the Free Software Foundation.
*/ */
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h> #include <linux/module.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/icmp.h> #include <linux/icmp.h>
...@@ -312,15 +314,15 @@ hmark_tg_v4(struct sk_buff *skb, const struct xt_action_param *par) ...@@ -312,15 +314,15 @@ hmark_tg_v4(struct sk_buff *skb, const struct xt_action_param *par)
static int hmark_tg_check(const struct xt_tgchk_param *par) static int hmark_tg_check(const struct xt_tgchk_param *par)
{ {
const struct xt_hmark_info *info = par->targinfo; const struct xt_hmark_info *info = par->targinfo;
const char *errmsg = "proto mask must be zero with L3 mode";
if (!info->hmodulus) if (!info->hmodulus)
return -EINVAL; return -EINVAL;
if (info->proto_mask && if (info->proto_mask &&
(info->flags & XT_HMARK_FLAG(XT_HMARK_METHOD_L3))) { (info->flags & XT_HMARK_FLAG(XT_HMARK_METHOD_L3)))
pr_info("xt_HMARK: proto mask must be zero with L3 mode\n"); goto err;
return -EINVAL;
}
if (info->flags & XT_HMARK_FLAG(XT_HMARK_SPI_MASK) && if (info->flags & XT_HMARK_FLAG(XT_HMARK_SPI_MASK) &&
(info->flags & (XT_HMARK_FLAG(XT_HMARK_SPORT_MASK) | (info->flags & (XT_HMARK_FLAG(XT_HMARK_SPORT_MASK) |
XT_HMARK_FLAG(XT_HMARK_DPORT_MASK)))) XT_HMARK_FLAG(XT_HMARK_DPORT_MASK))))
...@@ -329,10 +331,13 @@ static int hmark_tg_check(const struct xt_tgchk_param *par) ...@@ -329,10 +331,13 @@ static int hmark_tg_check(const struct xt_tgchk_param *par)
if (info->flags & XT_HMARK_FLAG(XT_HMARK_SPI) && if (info->flags & XT_HMARK_FLAG(XT_HMARK_SPI) &&
(info->flags & (XT_HMARK_FLAG(XT_HMARK_SPORT) | (info->flags & (XT_HMARK_FLAG(XT_HMARK_SPORT) |
XT_HMARK_FLAG(XT_HMARK_DPORT)))) { XT_HMARK_FLAG(XT_HMARK_DPORT)))) {
pr_info("xt_HMARK: spi-set and port-set can't be combined\n"); errmsg = "spi-set and port-set can't be combined";
return -EINVAL; goto err;
} }
return 0; return 0;
err:
pr_info_ratelimited("%s\n", errmsg);
return -EINVAL;
} }
static struct xt_target hmark_tg_reg[] __read_mostly = { static struct xt_target hmark_tg_reg[] __read_mostly = {
......
...@@ -164,48 +164,47 @@ addrtype_mt_v1(const struct sk_buff *skb, struct xt_action_param *par) ...@@ -164,48 +164,47 @@ addrtype_mt_v1(const struct sk_buff *skb, struct xt_action_param *par)
static int addrtype_mt_checkentry_v1(const struct xt_mtchk_param *par) static int addrtype_mt_checkentry_v1(const struct xt_mtchk_param *par)
{ {
const char *errmsg = "both incoming and outgoing interface limitation cannot be selected";
struct xt_addrtype_info_v1 *info = par->matchinfo; struct xt_addrtype_info_v1 *info = par->matchinfo;
if (info->flags & XT_ADDRTYPE_LIMIT_IFACE_IN && if (info->flags & XT_ADDRTYPE_LIMIT_IFACE_IN &&
info->flags & XT_ADDRTYPE_LIMIT_IFACE_OUT) { info->flags & XT_ADDRTYPE_LIMIT_IFACE_OUT)
pr_info("both incoming and outgoing " goto err;
"interface limitation cannot be selected\n");
return -EINVAL;
}
if (par->hook_mask & ((1 << NF_INET_PRE_ROUTING) | if (par->hook_mask & ((1 << NF_INET_PRE_ROUTING) |
(1 << NF_INET_LOCAL_IN)) && (1 << NF_INET_LOCAL_IN)) &&
info->flags & XT_ADDRTYPE_LIMIT_IFACE_OUT) { info->flags & XT_ADDRTYPE_LIMIT_IFACE_OUT) {
pr_info("output interface limitation " errmsg = "output interface limitation not valid in PREROUTING and INPUT";
"not valid in PREROUTING and INPUT\n"); goto err;
return -EINVAL;
} }
if (par->hook_mask & ((1 << NF_INET_POST_ROUTING) | if (par->hook_mask & ((1 << NF_INET_POST_ROUTING) |
(1 << NF_INET_LOCAL_OUT)) && (1 << NF_INET_LOCAL_OUT)) &&
info->flags & XT_ADDRTYPE_LIMIT_IFACE_IN) { info->flags & XT_ADDRTYPE_LIMIT_IFACE_IN) {
pr_info("input interface limitation " errmsg = "input interface limitation not valid in POSTROUTING and OUTPUT";
"not valid in POSTROUTING and OUTPUT\n"); goto err;
return -EINVAL;
} }
#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES) #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
if (par->family == NFPROTO_IPV6) { if (par->family == NFPROTO_IPV6) {
if ((info->source | info->dest) & XT_ADDRTYPE_BLACKHOLE) { if ((info->source | info->dest) & XT_ADDRTYPE_BLACKHOLE) {
pr_err("ipv6 BLACKHOLE matching not supported\n"); errmsg = "ipv6 BLACKHOLE matching not supported";
return -EINVAL; goto err;
} }
if ((info->source | info->dest) >= XT_ADDRTYPE_PROHIBIT) { if ((info->source | info->dest) >= XT_ADDRTYPE_PROHIBIT) {
pr_err("ipv6 PROHIBIT (THROW, NAT ..) matching not supported\n"); errmsg = "ipv6 PROHIBIT (THROW, NAT ..) matching not supported";
return -EINVAL; goto err;
} }
if ((info->source | info->dest) & XT_ADDRTYPE_BROADCAST) { if ((info->source | info->dest) & XT_ADDRTYPE_BROADCAST) {
pr_err("ipv6 does not support BROADCAST matching\n"); errmsg = "ipv6 does not support BROADCAST matching";
return -EINVAL; goto err;
} }
} }
#endif #endif
return 0; return 0;
err:
pr_info_ratelimited("%s\n", errmsg);
return -EINVAL;
} }
static struct xt_match addrtype_mt_reg[] __read_mostly = { static struct xt_match addrtype_mt_reg[] __read_mostly = {
......
...@@ -132,26 +132,29 @@ policy_mt(const struct sk_buff *skb, struct xt_action_param *par) ...@@ -132,26 +132,29 @@ policy_mt(const struct sk_buff *skb, struct xt_action_param *par)
static int policy_mt_check(const struct xt_mtchk_param *par) static int policy_mt_check(const struct xt_mtchk_param *par)
{ {
const struct xt_policy_info *info = par->matchinfo; const struct xt_policy_info *info = par->matchinfo;
const char *errmsg = "neither incoming nor outgoing policy selected";
if (!(info->flags & (XT_POLICY_MATCH_IN|XT_POLICY_MATCH_OUT)))
goto err;
if (!(info->flags & (XT_POLICY_MATCH_IN|XT_POLICY_MATCH_OUT))) {
pr_info("neither incoming nor outgoing policy selected\n");
return -EINVAL;
}
if (par->hook_mask & ((1 << NF_INET_PRE_ROUTING) | if (par->hook_mask & ((1 << NF_INET_PRE_ROUTING) |
(1 << NF_INET_LOCAL_IN)) && info->flags & XT_POLICY_MATCH_OUT) { (1 << NF_INET_LOCAL_IN)) && info->flags & XT_POLICY_MATCH_OUT) {
pr_info("output policy not valid in PREROUTING and INPUT\n"); errmsg = "output policy not valid in PREROUTING and INPUT";
return -EINVAL; goto err;
} }
if (par->hook_mask & ((1 << NF_INET_POST_ROUTING) | if (par->hook_mask & ((1 << NF_INET_POST_ROUTING) |
(1 << NF_INET_LOCAL_OUT)) && info->flags & XT_POLICY_MATCH_IN) { (1 << NF_INET_LOCAL_OUT)) && info->flags & XT_POLICY_MATCH_IN) {
pr_info("input policy not valid in POSTROUTING and OUTPUT\n"); errmsg = "input policy not valid in POSTROUTING and OUTPUT";
return -EINVAL; goto err;
} }
if (info->len > XT_POLICY_MAX_ELEM) { if (info->len > XT_POLICY_MAX_ELEM) {
pr_info("too many policy elements\n"); errmsg = "too many policy elements";
return -EINVAL; goto err;
} }
return 0; return 0;
err:
pr_info_ratelimited("%s\n", errmsg);
return -EINVAL;
} }
static struct xt_match policy_mt_reg[] __read_mostly = { static struct xt_match policy_mt_reg[] __read_mostly = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment