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 5/5] ipv6: Flip to fib_nexthop_info
Date: Tue, 2 Apr 2019 14:11:58 -0700 [thread overview]
Message-ID: <20190402211158.19459-6-dsahern@kernel.org> (raw)
In-Reply-To: <20190402211158.19459-1-dsahern@kernel.org>
From: David Ahern <dsahern@gmail.com>
Export fib_nexthop_info and fib_add_nexthop for use by IPv6 code.
Remove rt6_nexthop_info and rt6_add_nexthop in favor of the IPv4
versions. Update fib_nexthop_info for IPv6 linkdown check and
RTA_GATEWAY for AF_INET6.
Signed-off-by: David Ahern <dsahern@gmail.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
---
include/net/ip_fib.h | 5 ++++
net/ipv4/fib_semantics.c | 22 ++++++++++----
net/ipv6/route.c | 77 ++++--------------------------------------------
3 files changed, 28 insertions(+), 76 deletions(-)
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index 1f4a3b8bf584..3ce07841dc3b 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -492,4 +492,9 @@ u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr);
int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,
struct fib_dump_filter *filter,
struct netlink_callback *cb);
+
+int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nh,
+ unsigned int *flags, bool skip_oif);
+int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nh,
+ int nh_weight);
#endif /* _NET_FIB_H */
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 33a43965a232..8e0cb1687a74 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -45,6 +45,7 @@
#include <net/nexthop.h>
#include <net/lwtunnel.h>
#include <net/fib_notifier.h>
+#include <net/addrconf.h>
#include "fib_lookup.h"
@@ -1317,8 +1318,8 @@ 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_common *nhc,
- unsigned int *flags, bool skip_oif)
+int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nhc,
+ unsigned int *flags, bool skip_oif)
{
if (nhc->nhc_flags & RTNH_F_DEAD)
*flags |= RTNH_F_DEAD;
@@ -1332,6 +1333,10 @@ static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nhc
if (ip_ignore_linkdown(nhc->nhc_dev))
*flags |= RTNH_F_DEAD;
break;
+ case AF_INET6:
+ if (ip6_ignore_linkdown(nhc->nhc_dev))
+ *flags |= RTNH_F_DEAD;
+ break;
}
rcu_read_unlock();
}
@@ -1342,6 +1347,11 @@ static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nhc
if (nla_put_in_addr(skb, RTA_GATEWAY, nhc->nhc_gw.ipv4))
goto nla_put_failure;
break;
+ case AF_INET6:
+ if (nla_put_in6_addr(skb, RTA_GATEWAY,
+ &nhc->nhc_gw.ipv6) < 0)
+ goto nla_put_failure;
+ break;
}
}
@@ -1362,10 +1372,11 @@ static int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nhc
nla_put_failure:
return -EMSGSIZE;
}
+EXPORT_SYMBOL_GPL(fib_nexthop_info);
-#ifdef CONFIG_IP_ROUTE_MULTIPATH
-static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc,
- int nh_weight)
+#if IS_ENABLED(CONFIG_IP_ROUTE_MULTIPATH) || IS_ENABLED(CONFIG_IPV6)
+int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc,
+ int nh_weight)
{
const struct net_device *dev = nhc->nhc_dev;
struct rtnexthop *rtnh;
@@ -1391,6 +1402,7 @@ static int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc,
nla_put_failure:
return -EMSGSIZE;
}
+EXPORT_SYMBOL_GPL(fib_add_nexthop);
#endif
#ifdef CONFIG_IP_ROUTE_MULTIPATH
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index e0ee30cbd079..6e89151693d0 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -4582,73 +4582,6 @@ static size_t rt6_nlmsg_size(struct fib6_info *rt)
+ nexthop_len;
}
-static int rt6_nexthop_info(struct sk_buff *skb, const struct fib6_nh *fib6_nh,
- unsigned int *flags, bool skip_oif)
-{
- if (fib6_nh->fib_nh_flags & RTNH_F_DEAD)
- *flags |= RTNH_F_DEAD;
-
- if (fib6_nh->fib_nh_flags & RTNH_F_LINKDOWN) {
- *flags |= RTNH_F_LINKDOWN;
-
- rcu_read_lock();
- if (ip6_ignore_linkdown(fib6_nh->fib_nh_dev))
- *flags |= RTNH_F_DEAD;
- rcu_read_unlock();
- }
-
- if (fib6_nh->fib_nh_has_gw) {
- if (nla_put_in6_addr(skb, RTA_GATEWAY, &fib6_nh->fib_nh_gw6) < 0)
- goto nla_put_failure;
- }
-
- *flags |= (fib6_nh->fib_nh_flags & RTNH_F_ONLINK);
- if (fib6_nh->fib_nh_flags & RTNH_F_OFFLOAD)
- *flags |= RTNH_F_OFFLOAD;
-
- /* not needed for multipath encoding b/c it has a rtnexthop struct */
- if (!skip_oif && fib6_nh->fib_nh_dev &&
- nla_put_u32(skb, RTA_OIF, fib6_nh->fib_nh_dev->ifindex))
- goto nla_put_failure;
-
- if (fib6_nh->fib_nh_lws &&
- lwtunnel_fill_encap(skb, fib6_nh->fib_nh_lws) < 0)
- goto nla_put_failure;
-
- return 0;
-
-nla_put_failure:
- return -EMSGSIZE;
-}
-
-/* add multipath next hop */
-static int rt6_add_nexthop(struct sk_buff *skb, const struct fib6_nh *fib6_nh)
-{
- const struct net_device *dev = fib6_nh->fib_nh_dev;
- struct rtnexthop *rtnh;
- unsigned int flags = 0;
-
- rtnh = nla_reserve_nohdr(skb, sizeof(*rtnh));
- if (!rtnh)
- goto nla_put_failure;
-
- rtnh->rtnh_hops = fib6_nh->fib_nh_weight - 1;
- rtnh->rtnh_ifindex = dev ? dev->ifindex : 0;
-
- if (rt6_nexthop_info(skb, fib6_nh, &flags, true) < 0)
- goto nla_put_failure;
-
- rtnh->rtnh_flags = flags;
-
- /* length of rtnetlink header + attributes */
- rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *)rtnh;
-
- return 0;
-
-nla_put_failure:
- return -EMSGSIZE;
-}
-
static int rt6_fill_node(struct net *net, struct sk_buff *skb,
struct fib6_info *rt, struct dst_entry *dst,
struct in6_addr *dest, struct in6_addr *src,
@@ -4765,19 +4698,21 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb,
if (!mp)
goto nla_put_failure;
- if (rt6_add_nexthop(skb, &rt->fib6_nh) < 0)
+ if (fib_add_nexthop(skb, &rt->fib6_nh.nh_common,
+ rt->fib6_nh.fib_nh_weight) < 0)
goto nla_put_failure;
list_for_each_entry_safe(sibling, next_sibling,
&rt->fib6_siblings, fib6_siblings) {
- if (rt6_add_nexthop(skb, &sibling->fib6_nh) < 0)
+ if (fib_add_nexthop(skb, &sibling->fib6_nh.nh_common,
+ sibling->fib6_nh.fib_nh_weight) < 0)
goto nla_put_failure;
}
nla_nest_end(skb, mp);
} else {
- if (rt6_nexthop_info(skb, &rt->fib6_nh, &rtm->rtm_flags,
- false) < 0)
+ if (fib_nexthop_info(skb, &rt->fib6_nh.nh_common,
+ &rtm->rtm_flags, false) < 0)
goto nla_put_failure;
}
--
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 ` [PATCH v4 net-next 4/5] ipv4: Change fib_nexthop_info and fib_add_nexthop to take fib_nh_common David Ahern
2019-04-02 21:11 ` David Ahern [this message]
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-6-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).