Linux Netfilter development
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Laura Garcia Liebana <nevola@gmail.com>
Cc: netfilter-devel@vger.kernel.org, devel@zevenet.com
Subject: Re: [PATCH v2 nf-next] netfilter: introduce support for reject at prerouting stage
Date: Fri, 29 May 2020 21:15:19 +0200	[thread overview]
Message-ID: <20200529191519.GA32761@salvia> (raw)
In-Reply-To: <20200529110328.GA20367@nevthink>

On Fri, May 29, 2020 at 01:03:28PM +0200, Laura Garcia Liebana wrote:
[...]
> diff --git a/net/ipv4/netfilter/nf_reject_ipv4.c b/net/ipv4/netfilter/nf_reject_ipv4.c
> index 2361fdac2c43..b5b7633d9433 100644
> --- a/net/ipv4/netfilter/nf_reject_ipv4.c
> +++ b/net/ipv4/netfilter/nf_reject_ipv4.c
> @@ -96,6 +96,22 @@ void nf_reject_ip_tcphdr_put(struct sk_buff *nskb, const struct sk_buff *oldskb,
>  }
>  EXPORT_SYMBOL_GPL(nf_reject_ip_tcphdr_put);
>  
> +static int nf_reject_fill_skb_dst(struct sk_buff *skb_in)
> +{
> +	struct dst_entry *dst = NULL;
> +	struct flowi fl;
> +	struct flowi4 *fl4 = &fl.u.ip4;
> +
> +	memset(fl4, 0, sizeof(*fl4));
> +	fl4->daddr = ip_hdr(skb_in)->saddr;
> +	nf_route(dev_net(skb_in->dev), &dst, &fl, false, AF_INET);
> +	if (!dst)
> +		return -1;
> +
> +	skb_dst_set(skb_in, dst);
> +	return 0;
> +}

Probably slightly simplify this? I'd suggest:

* make calls to nf_ip_route() and nf_ip6_route() instead of the nf_route()
  wrapper.

* use flowi structure, no need to add struct flowi4 ? Probably:

static int nf_reject_fill_skb_dst(struct sk_buff *skb_in)
{
        struct dst_entry *dst = NULL;
        struct flowi fl;

        memset(fl, 0, sizeof(*fl));
        fl.u.ip4 = ip_hdr(skb_in)->saddr;
        nf_ip_route(dev_net(skb_in->dev), &dst, &fl, false);
        if (!dst)
                return -1;

        skb_dst_set(skb_in, dst);
        return 0;
}

Another possibility would be to use C99 structure initialization. But
I think the code above should be fine.

Thanks.

  reply	other threads:[~2020-05-29 19:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-29 11:03 [PATCH v2 nf-next] netfilter: introduce support for reject at prerouting stage Laura Garcia Liebana
2020-05-29 19:15 ` Pablo Neira Ayuso [this message]
2020-05-30 20:51   ` Laura García Liébana

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=20200529191519.GA32761@salvia \
    --to=pablo@netfilter.org \
    --cc=devel@zevenet.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=nevola@gmail.com \
    /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