From: David Ahern <dsahern@kernel.org>
To: davem@davemloft.net, netdev@vger.kernel.org
Cc: idosch@mellanox.com, David Ahern <dsahern@gmail.com>
Subject: [PATCH v4 net-next 4/5] ipv4: Change fib_nexthop_info and fib_add_nexthop to take fib_nh_common
Date: Tue, 2 Apr 2019 14:11:57 -0700 [thread overview]
Message-ID: <20190402211158.19459-5-dsahern@kernel.org> (raw)
In-Reply-To: <20190402211158.19459-1-dsahern@kernel.org>
From: David Ahern <dsahern@gmail.com>
With the exception of the nexthop weight, the nexthop attributes used by
fib_nexthop_info and fib_add_nexthop come from the fib_nh_common struct.
Update both to use it and change fib_nexthop_info to check the family
as needed.
nexthop weight comes from the common struct for existing use cases, but
for nexthop groups the weight is outside of the fib_nh_common to allow
the same nexthop definition to be used in multiple groups with different
weights.
Signed-off-by: David Ahern <dsahern@gmail.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
---
net/ipv4/fib_semantics.c | 52 +++++++++++++++++++++++++++++-------------------
1 file changed, 32 insertions(+), 20 deletions(-)
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 32fb0123d881..33a43965a232 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -1317,35 +1317,44 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
return ERR_PTR(err);
}
-static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh *nh,
+static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nhc,
unsigned int *flags, bool skip_oif)
{
- if (nh->fib_nh_flags & RTNH_F_DEAD)
+ if (nhc->nhc_flags & RTNH_F_DEAD)
*flags |= RTNH_F_DEAD;
- if (nh->fib_nh_flags & RTNH_F_LINKDOWN) {
+ if (nhc->nhc_flags & RTNH_F_LINKDOWN) {
*flags |= RTNH_F_LINKDOWN;
rcu_read_lock();
- if (ip_ignore_linkdown(nh->fib_nh_dev))
- *flags |= RTNH_F_DEAD;
+ switch (nhc->nhc_family) {
+ case AF_INET:
+ if (ip_ignore_linkdown(nhc->nhc_dev))
+ *flags |= RTNH_F_DEAD;
+ break;
+ }
rcu_read_unlock();
}
- if (nh->fib_nh_gw4 &&
- nla_put_in_addr(skb, RTA_GATEWAY, nh->fib_nh_gw4))
- goto nla_put_failure;
+ if (nhc->nhc_has_gw) {
+ switch (nhc->nhc_family) {
+ case AF_INET:
+ if (nla_put_in_addr(skb, RTA_GATEWAY, nhc->nhc_gw.ipv4))
+ goto nla_put_failure;
+ break;
+ }
+ }
- *flags |= (nh->fib_nh_flags & RTNH_F_ONLINK);
- if (nh->fib_nh_flags & RTNH_F_OFFLOAD)
+ *flags |= (nhc->nhc_flags & RTNH_F_ONLINK);
+ if (nhc->nhc_flags & RTNH_F_OFFLOAD)
*flags |= RTNH_F_OFFLOAD;
- if (!skip_oif && nh->fib_nh_dev &&
- nla_put_u32(skb, RTA_OIF, nh->fib_nh_dev->ifindex))
+ if (!skip_oif && nhc->nhc_dev &&
+ nla_put_u32(skb, RTA_OIF, nhc->nhc_dev->ifindex))
goto nla_put_failure;
- if (nh->fib_nh_lws &&
- lwtunnel_fill_encap(skb, nh->fib_nh_lws) < 0)
+ if (nhc->nhc_lwtstate &&
+ lwtunnel_fill_encap(skb, nhc->nhc_lwtstate) < 0)
goto nla_put_failure;
return 0;
@@ -1355,9 +1364,10 @@ static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh *nh,
}
#ifdef CONFIG_IP_ROUTE_MULTIPATH
-static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh *nh)
+static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc,
+ int nh_weight)
{
- const struct net_device *dev = nh->fib_nh_dev;
+ const struct net_device *dev = nhc->nhc_dev;
struct rtnexthop *rtnh;
unsigned int flags = 0;
@@ -1365,10 +1375,10 @@ static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh *nh)
if (!rtnh)
goto nla_put_failure;
- rtnh->rtnh_hops = nh->fib_nh_weight - 1;
+ rtnh->rtnh_hops = nh_weight - 1;
rtnh->rtnh_ifindex = dev ? dev->ifindex : 0;
- if (fib_nexthop_info(skb, nh, &flags, true) < 0)
+ if (fib_nexthop_info(skb, nhc, &flags, true) < 0)
goto nla_put_failure;
rtnh->rtnh_flags = flags;
@@ -1381,7 +1391,9 @@ static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh *nh)
nla_put_failure:
return -EMSGSIZE;
}
+#endif
+#ifdef CONFIG_IP_ROUTE_MULTIPATH
static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi)
{
struct nlattr *mp;
@@ -1391,7 +1403,7 @@ static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi)
goto nla_put_failure;
for_nexthops(fi) {
- if (fib_add_nexthop(skb, nh) < 0)
+ if (fib_add_nexthop(skb, &nh->nh_common, nh->fib_nh_weight) < 0)
goto nla_put_failure;
#ifdef CONFIG_IP_ROUTE_CLASSID
if (nh->nh_tclassid &&
@@ -1457,7 +1469,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
struct fib_nh *nh = &fi->fib_nh[0];
unsigned int flags = 0;
- if (fib_nexthop_info(skb, nh, &flags, false) < 0)
+ if (fib_nexthop_info(skb, &nh->nh_common, &flags, false) < 0)
goto nla_put_failure;
rtm->rtm_flags = flags;
--
2.11.0
next prev parent reply other threads:[~2019-04-02 21:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-02 21:11 [PATCH v4 net-next 0/5] net: More movement to fib_nh_common David Ahern
2019-04-02 21:11 ` [PATCH v4 net-next 1/5] ipv4: Update fib_table_lookup tracepoint to take common nexthop David Ahern
2019-04-02 21:11 ` [PATCH v4 net-next 2/5] ipv4: Add fib_nh_common to fib_result David Ahern
2019-04-02 21:11 ` [PATCH v4 net-next 3/5] ipv4: Refactor nexthop attributes in fib_dump_info David Ahern
2019-04-02 21:11 ` David Ahern [this message]
2019-04-02 21:11 ` [PATCH v4 net-next 5/5] ipv6: Flip to fib_nexthop_info David Ahern
2019-04-03 5:27 ` [PATCH v4 net-next 0/5] net: More movement to fib_nh_common Martin Lau
2019-04-03 18:59 ` David Ahern
2019-04-04 4:50 ` David Miller
2019-04-04 15:07 ` David Ahern
2019-04-04 20:30 ` David Miller
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=20190402211158.19459-5-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=idosch@mellanox.com \
--cc=netdev@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).