Skip to contentSkip to conversation

ipv6: Change addrconf_f6i_alloc to use ip6_route_info_create

PATCH In review David Ahern 2 participants 4 messages Mar 21, 2019

Subsystems (3)
lore
Share & tools
lore

David Ahern

author maintainer
#0 lore raw

cover ipv6: Change addrconf_f6i_alloc to use ip6_route_info_create

From: David Ahern <[email protected]>

addrconf_f6i_alloc is the last caller of fib6_info_alloc besides ip6_route_info_create. There really is no good reason for it do its own fib6_info initialization, so convert it to call ip6_route_info_create.

David Ahern (2):
ipv6: Move setting default metric for routes
ipv6: Change addrconf_f6i_alloc to use ip6_route_info_create

 include/net/ip6_fib.h |  3 ++-
 net/ipv6/route.c      | 50 ++++++++++++++++++++------------------------------
 2 files changed, 22 insertions(+), 31 deletions(-)
Signature · 1 line
2.11.0
author maintainer
#1 lore raw

PATCH 1/2 ipv6: Move setting default metric for routes

From: David Ahern <[email protected]>

ip6_route_info_create is a low level function for ensuring fc_metric is set. Move the check and default setting to the 2 locations that do not already set fc_metric before calling ip6_route_info_create. This is required for the next patch which moves addrconf allocations to ip6_route_info_create and want the metric for host routes to be 0.

---
 net/ipv6/route.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/ipv6/route.c +4 -4
index c9a2f0f2dea6..d52f215870e2 100644
@@ -2950,9 +2950,6 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
 			goto out;
 	}
 
-	if (cfg->fc_metric == 0)
-		cfg->fc_metric = IP6_RT_PRIO_USER;
-
 	if (cfg->fc_flags & RTNH_F_ONLINK) {
 		if (!dev) {
 			NL_SET_ERR_MSG(extack,
@@ -3603,7 +3600,7 @@ static void rtmsg_to_fib6_config(struct net *net,
 		.fc_table = l3mdev_fib_table_by_index(net, rtmsg->rtmsg_ifindex) ?
 			 : RT6_TABLE_MAIN,
 		.fc_ifindex = rtmsg->rtmsg_ifindex,
-		.fc_metric = rtmsg->rtmsg_metric,
+		.fc_metric = rtmsg->rtmsg_metric ? : IP6_RT_PRIO_USER,
 		.fc_expires = rtmsg->rtmsg_info,
 		.fc_dst_len = rtmsg->rtmsg_dst_len,
 		.fc_src_len = rtmsg->rtmsg_src_len,
@@ -4523,6 +4520,9 @@ static int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
 	if (err < 0)
 		return err;
 
+	if (cfg.fc_metric == 0)
+		cfg.fc_metric = IP6_RT_PRIO_USER;
+
 	if (cfg.fc_mp)
 		return ip6_route_multipath_add(&cfg, extack);
 	else
Signature · 1 line
2.11.0
author maintainer
#2 lore raw

PATCH 2/2 ipv6: Change addrconf_f6i_alloc to use ip6_route_info_create

In reply to David Ahern

From: David Ahern <[email protected]>

Change addrconf_f6i_alloc to generate a fib6_config and call ip6_route_info_create. addrconf_f6i_alloc is the last caller to fib6_info_alloc besides ip6_route_info_create, and there is no reason for it to do its own initialization on a fib6_info.

Host routes need to be created even if the device is down, so add a new flag, fc_ignore_dev_down, to fib6_config and update fib6_nh_init to not error out if device is not up.

Notes on the conversion:
- ip_fib_metrics_init is the same as fib6_config has fc_mx set to NULL and fc_mx_len set to 0
- dst_nocount is handled by the RTF_ADDRCONF flag
- dst_host is handled by fc_dst_len = 128

nh_gw does not get set after the conversion to ip6_route_info_create but it should not be set in addrconf_f6i_alloc since this is a host route not a gateway route.

Everything else is a straight forward map between fib6_info and fib6_config.

---
 include/net/ip6_fib.h |  3 ++-
 net/ipv6/route.c      | 42 ++++++++++++++++--------------------------
 2 files changed, 18 insertions(+), 27 deletions(-)
include/net/ip6_fib.h +2 -1
index 84097010237c..2acb78a762ee 100644
@@ -50,7 +50,8 @@ struct fib6_config {
 	u32		fc_protocol;
 	u16		fc_type;        /* only 8 bits are used */
 	u16		fc_delete_all_nh : 1,
-			__unused : 15;
+			fc_ignore_dev_down:1,
+			__unused : 14;
 
 	struct in6_addr	fc_dst;
 	struct in6_addr	fc_src;
net/ipv6/route.c +16 -26

59 lines not on this page · raw message

Signature · 1 line
2.11.0
maintainer
#3 lore raw
In reply to David Ahern

From: David Ahern <[email protected]>
Date: Thu, 21 Mar 2019 05:21:33 -0700

Quoted 6 lines

From: David Ahern <[email protected]>

addrconf_f6i_alloc is the last caller of fib6_info_alloc besides ip6_route_info_create. There really is no good reason for it do its own fib6_info initialization, so convert it to call ip6_route_info_create.

Looks great, series applied.