From: "Anders K. Pedersen | Cohaesio" <akp@cohaesio.com>
To: "zlpnobody@gmail.com" <zlpnobody@gmail.com>
Cc: "netfilter-devel@vger.kernel.org"
<netfilter-devel@vger.kernel.org>,
"pablo@netfilter.org" <pablo@netfilter.org>
Subject: Re: [PATCH v2 nf-next 5/5] netfilter: nft: rt nexthop for inet family
Date: Thu, 20 Oct 2016 12:36:20 +0000 [thread overview]
Message-ID: <1476966980.1161.52.camel@cohaesio.com> (raw)
In-Reply-To: <CAML_gOdd7=XOk+5csafW2zUjzTqzqufSp7L=3CpS8FBf6r+9nA@mail.gmail.com>
Hi Liping,
On thu, 2016-10-20 at 17:13 +0800, Liping Zhang wrote:
> Hi Anders,
> 2016-10-20 2:41 GMT+08:00 Anders K. Pedersen | Cohaesio <akp@cohaesio
> .com>:
>
> >
> > +static void nft_rt_inet_get_eval(const struct nft_expr *expr,
> > + struct nft_regs *regs,
> > + const struct nft_pktinfo *pkt)
> > +{
> > + const struct nft_rt *priv = nft_expr_priv(expr);
> > + const struct sk_buff *skb = pkt->skb;
> > + u32 *dest = ®s->data[priv->dreg];
> > +
> > + if (unlikely(pkt->pf != priv->family)) {
> > + WARN_ONCE(1, "Address families do not match\n");
>
> I think this WARN_ONCE seems unnecessary, in inet family, it's
> possible that
> the family is mismatched.
Well, the suggested userspace implementation doesn't allow a rule that
would hit this warning. It is required to use 'ether type ip ... rt ip
nexthop' or 'ether type ip6 ... rt ip6 nexthop', when nexthop is used
from the inet table.
So I found it reasonable to generate a warning if such a rule somehow
got configured anyway, but if you still feel that it should be removed,
I can do that.
> + goto err;
> > + }
> > +
> > + switch (pkt->pf) {
> > + case NFPROTO_IPV4:
> > + switch (priv->key) {
> > + case NFT_RT_NEXTHOP: {
> > + const struct rtable *rt = skb_rtable(skb);
> > +
> > + if (!rt)
> > + goto err;
> > + *dest = rt_nexthop(rt, ip_hdr(skb)->daddr);
> > + break;
> > + }
> > + default:
> > + goto out;
> > + }
> > + break;
> > + case NFPROTO_IPV6:
> > + switch (priv->key) {
> > + case NFT_RT_NEXTHOP: {
> > + struct rt6_info *rt =
> > + (struct rt6_info
> > *)skb_dst(skb);
> > +
> > + if (!rt)
> > + goto err;
> > + memcpy(dest, rt6_nexthop(rt,
> > &ipv6_hdr(skb)->daddr),
> > + sizeof(struct in6_addr));
> > + break;
> > + }
> > + default:
> > + goto out;
> > + }
> > + break;
> > + }
> > +
>
> This code looks not clean, I think it can be converted to such:
>
> switch (priv->key) {
> case NFT_RT_NEXTHOP:
> switch (pkt->pf)
> ...
> default:
> return nft_rt_get_eval(expr, regs, pkt);
> }
My thinking was that for future rt sub-expressions, it will probably
make sense to move
const struct rtable *rt = skb_rtable(skb);
if (!rt)
goto err;
outside the inner switch statement, so it doesn't need to be duplicated
for each sub-expression. And ditto for the IPV6 part.
> >
> > + return;
> > +out:
> > + return nft_rt_get_eval(expr, regs, pkt);
> > +err:
> > + regs->verdict.code = NFT_BREAK;
> > +}
> > +
> > +static int nft_rt_inet_get_init(const struct nft_ctx *ctx,
> > + const struct nft_expr *expr,
> > + const struct nlattr * const tb[])
> > +{
> > + struct nft_rt *priv = nft_expr_priv(expr);
> > + unsigned int len;
> > +
> > + if (tb[NFTA_RT_KEY] == NULL ||
> > + tb[NFTA_RT_DREG] == NULL ||
> > + tb[NFTA_RT_FAMILY] == NULL)
> > + return -EINVAL;
> > +
> > + priv->key = ntohl(nla_get_be32(tb[NFTA_RT_KEY]));
> > + priv->family = ntohl(nla_get_be32(tb[NFTA_RT_FAMILY]));
> > + switch (priv->key) {
> > + case NFT_RT_NEXTHOP:
> > + switch (priv->family) {
> > + case NFPROTO_IPV4:
> > + len = sizeof(u32);
> > + break;
> > + case NFPROTO_IPV6:
> > + len = sizeof(struct in6_addr);
> > + break;
> > + }
> > + len = sizeof(u32);
> > + break;
>
> If the family is invalid, you should report -EINVAL to the userspace.
> And the code "len = sizeof(u32);" here makes no sense.
Yes, I'll fix that. Thanks for reviewing.
Regards,
Anders K. Pedersen
next prev parent reply other threads:[~2016-10-20 12:36 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-19 18:34 [PATCH v2 nf-next 0/5] netfilter: nft: introduce routing expression Anders K. Pedersen | Cohaesio
2016-10-19 18:35 ` [PATCH v2 nf-next 1/5] netfilter: nft: UAPI headers for " Anders K. Pedersen | Cohaesio
2016-10-19 18:38 ` [PATCH v2 nf-next 2/5] netfilter: nft: basic " Anders K. Pedersen | Cohaesio
2016-10-19 18:39 ` [PATCH v2 nf-next 3/5] netfilter: nft: rt nexthop for IPv4 family Anders K. Pedersen | Cohaesio
2016-10-19 18:40 ` [PATCH v2 nf-next 4/5] netfilter: nft: rt nexthop for IPv6 family Anders K. Pedersen | Cohaesio
2016-10-19 18:41 ` [PATCH v2 nf-next 5/5] netfilter: nft: rt nexthop for inet family Anders K. Pedersen | Cohaesio
2016-10-20 9:13 ` Liping Zhang
2016-10-20 12:36 ` Anders K. Pedersen | Cohaesio [this message]
2016-10-20 13:27 ` Liping Zhang
2016-10-20 13:52 ` Anders K. Pedersen | Cohaesio
2016-10-21 2:06 ` Liping Zhang
2016-10-21 4:16 ` Anders K. Pedersen | Cohaesio
2016-10-21 6:17 ` Liping Zhang
2016-10-21 8:26 ` Anders K. Pedersen | Cohaesio
2016-10-21 12:42 ` Liping Zhang
2016-10-22 15:25 ` Anders K. Pedersen | Cohaesio
2016-10-21 9:21 ` Pablo Neira Ayuso
2016-10-21 13:22 ` Liping Zhang
2016-10-21 16:58 ` Pablo Neira Ayuso
2016-10-22 1:44 ` Liping Zhang
2016-10-22 16:08 ` Anders K. Pedersen | Cohaesio
2016-10-23 5:01 ` Liping Zhang
2016-10-27 17:50 ` Pablo Neira Ayuso
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=1476966980.1161.52.camel@cohaesio.com \
--to=akp@cohaesio.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=zlpnobody@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.