From: Patrick McHardy <kaber@trash.net>
To: Jan Engelhardt <jengelh@medozas.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH 7/9] netfilter: xtables: slightly better error reporting (2/2)
Date: Tue, 23 Mar 2010 15:44:33 +0100 [thread overview]
Message-ID: <4BA8D3D1.7000409@trash.net> (raw)
In-Reply-To: <1269285486-22653-8-git-send-email-jengelh@medozas.de>
Jan Engelhardt wrote:
> diff --git a/net/ipv4/netfilter/ipt_LOG.c b/net/ipv4/netfilter/ipt_LOG.c
> index c9ee5c4..33213d6 100644
> --- a/net/ipv4/netfilter/ipt_LOG.c
> +++ b/net/ipv4/netfilter/ipt_LOG.c
> @@ -445,7 +445,7 @@ static int log_tg_check(const struct xt_tgchk_param *par)
>
> if (loginfo->level >= 8) {
> pr_debug("level %u >= 8\n", loginfo->level);
> - return false;
> + return -EDOM;
>
Mhh is that really a "Math argument out of domain of func"? ERANGE seems
slightly
better fitting to me.
> }
> if (loginfo->prefix[sizeof(loginfo->prefix)-1] != '\0') {
> pr_debug("prefix is not null-terminated\n");
> diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
> index 4e84d8a..6ead6e0 100644
> --- a/net/netfilter/x_tables.c
> +++ b/net/netfilter/x_tables.c
> @@ -363,6 +363,8 @@ static char *textify_hooks(char *buf, size_t size, unsigned int mask)
> int xt_check_match(struct xt_mtchk_param *par,
> unsigned int size, u_int8_t proto, bool inv_proto)
> {
> + int ret;
> +
> if (XT_ALIGN(par->match->matchsize) != size &&
> par->match->matchsize != -1) {
> /*
> @@ -399,8 +401,13 @@ int xt_check_match(struct xt_mtchk_param *par,
> par->match->proto);
> return -EINVAL;
> }
> - if (par->match->checkentry != NULL && !par->match->checkentry(par))
> - return -EINVAL;
> + if (par->match->checkentry != NULL) {
> + ret = par->match->checkentry(par);
> + if (ret < 0)
> + return ret;
> + else if (ret == 0)
> + return -EINVAL;
>
I'd suggest to do the true/false conversion before this patch. Currently I
don't understand the split of these patches, this one keeps lots of boolean
return values and initializations, but changes some.
> --- a/net/netfilter/xt_CONNSECMARK.c
> +++ b/net/netfilter/xt_CONNSECMARK.c
> @@ -87,6 +87,7 @@ connsecmark_tg(struct sk_buff *skb, const struct xt_target_param *par)
> static int connsecmark_tg_check(const struct xt_tgchk_param *par)
> {
> const struct xt_connsecmark_target_info *info = par->targinfo;
> + int ret;
>
> if (strcmp(par->table, "mangle") != 0 &&
> strcmp(par->table, "security") != 0) {
> @@ -102,13 +103,14 @@ static int connsecmark_tg_check(const struct xt_tgchk_param *par)
>
> default:
> pr_info("invalid mode: %hu\n", info->mode);
> - return false;
> + return -EDOM;
>
Actually EINVAL does seem like the best fit here.
>
> diff --git a/net/netfilter/xt_LED.c b/net/netfilter/xt_LED.c
> index 1a3e3dd..899da12 100644
> --- a/net/netfilter/xt_LED.c
> +++ b/net/netfilter/xt_LED.c
> @@ -93,7 +93,7 @@ static int led_tg_check(const struct xt_tgchk_param *par)
>
> ledinternal = kzalloc(sizeof(struct xt_led_info_internal), GFP_KERNEL);
> if (!ledinternal)
> - return false;
> + return -ENOMEM;
>
> ledinternal->netfilter_led_trigger.name = ledinfo->id;
>
> @@ -102,7 +102,8 @@ static int led_tg_check(const struct xt_tgchk_param *par)
> pr_warning("led_trigger_register() failed\n");
> if (err == -EEXIST)
> pr_warning("Trigger name is already in use.\n");
> - goto exit_alloc;
> + kfree(ledinternal);
> + return err;
> }
>
> /* See if we need to set up a timer */
> @@ -111,13 +112,7 @@ static int led_tg_check(const struct xt_tgchk_param *par)
> (unsigned long)ledinfo);
>
> ledinfo->internal_data = ledinternal;
> -
> return true;
>
^^ return true? I'd also prefer to keep the goto-based error handling.
> -
> -exit_alloc:
> - kfree(ledinternal);
> -
> - return false;
> }
>
> diff --git a/net/netfilter/xt_SECMARK.c b/net/netfilter/xt_SECMARK.c
> index 48f8e4f..6525eee 100644
> --- a/net/netfilter/xt_SECMARK.c
> +++ b/net/netfilter/xt_SECMARK.c
> @@ -50,7 +50,7 @@ secmark_tg(struct sk_buff *skb, const struct xt_target_param *par)
> return XT_CONTINUE;
> }
>
> -static bool checkentry_selinux(struct xt_secmark_target_info *info)
> +static int checkentry_selinux(struct xt_secmark_target_info *info)
> {
> int err;
> struct xt_secmark_target_selinux_info *sel = &info->u.sel;
> @@ -62,18 +62,18 @@ static bool checkentry_selinux(struct xt_secmark_target_info *info)
> if (err == -EINVAL)
> pr_info("invalid SELinux context \'%s\'\n",
> sel->selctx);
> - return false;
> + return err;
> }
>
> if (!sel->selsid) {
> pr_info("unable to map SELinux context \'%s\'\n", sel->selctx);
> - return false;
> + return -ENOENT;
> }
>
> err = selinux_secmark_relabel_packet_permission(sel->selsid);
> if (err) {
> pr_info("unable to obtain relabeling permission\n");
> - return false;
> + return err;
> }
>
> selinux_secmark_refcount_inc();
>
Missing conversion of "return true" at the end?
> @@ -83,6 +83,7 @@ static bool checkentry_selinux(struct xt_secmark_target_info *info)
> static int secmark_tg_check(const struct xt_tgchk_param *par)
> {
> struct xt_secmark_target_info *info = par->targinfo;
> + int err;
>
> if (strcmp(par->table, "mangle") != 0 &&
> strcmp(par->table, "security") != 0) {
> @@ -99,13 +100,14 @@ static int secmark_tg_check(const struct xt_tgchk_param *par)
>
> switch (info->mode) {
> case SECMARK_MODE_SEL:
> - if (!checkentry_selinux(info))
> - return false;
> + err = checkentry_selinux(info);
> + if (err <= 0)
>
<= ?
> + return err;
> break;
>
> default:
> pr_info("invalid mode: %hu\n", info->mode);
> - return false;
> + return -EDOM;
> }
>
> if (!mode)
>
I stopped here since I don't understand the logic this partial conversion
follows.
next prev parent reply other threads:[~2010-03-23 14:44 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-22 19:17 nf-next: cleanups, err reporting (rd.2) Jan Engelhardt
2010-03-22 19:17 ` [PATCH 1/9] netfilter: xtables: make use of caller family rather than target family Jan Engelhardt
2010-03-22 19:17 ` [PATCH 2/9] netfilter: xt extensions: use pr_<level> (2) Jan Engelhardt
2010-03-22 19:17 ` [PATCH 3/9] netfilter: xtables: make use of xt_request_find_target Jan Engelhardt
2010-03-23 14:24 ` Patrick McHardy
2010-03-23 14:27 ` Jan Engelhardt
2010-03-22 19:18 ` [PATCH 4/9] netfilter: xtables: consolidate code into xt_request_find_match Jan Engelhardt
2010-03-23 14:27 ` Patrick McHardy
2010-03-22 19:18 ` [PATCH 5/9] netfilter: xt_recent: allow changing ip_list_[ug]id at runtime Jan Engelhardt
2010-03-23 14:18 ` Patrick McHardy
2010-03-23 14:23 ` Jan Engelhardt
2010-03-23 14:55 ` Patrick McHardy
2010-03-23 15:06 ` Jan Engelhardt
2010-03-23 15:10 ` Patrick McHardy
2010-03-22 19:18 ` [PATCH 6/9] netfilter: xtables: slightly better error reporting (1/2) Jan Engelhardt
2010-03-22 19:18 ` [PATCH 7/9] netfilter: xtables: slightly better error reporting (2/2) Jan Engelhardt
2010-03-23 14:44 ` Patrick McHardy [this message]
2010-03-23 15:00 ` Jan Engelhardt
2010-03-23 15:02 ` Patrick McHardy
2010-03-22 19:18 ` [PATCH 8/9] netfilter: xtables: use only error codes for checkentry Jan Engelhardt
2010-03-22 19:18 ` [PATCH 9/9] netfilter: xtables: shorten up return clause Jan Engelhardt
2010-03-23 16:35 ` nf-next: cleanups, err reporting (rd.2) Jan Engelhardt
2010-03-25 12:48 ` Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4BA8D3D1.7000409@trash.net \
--to=kaber@trash.net \
--cc=jengelh@medozas.de \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).