|
| 1 | +diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt |
| 2 | +index 7eb936642..c61c22808 100644 |
| 3 | +--- a/Documentation/networking/ip-sysctl.txt |
| 4 | ++++ b/Documentation/networking/ip-sysctl.txt |
| 5 | +@@ -1537,6 +1537,16 @@ accept_ra_defrtr - BOOLEAN |
| 6 | + Functional default: enabled if accept_ra is enabled. |
| 7 | + disabled if accept_ra is disabled. |
| 8 | + |
| 9 | ++ra_defrtr_metric - UNSIGNED INTEGER |
| 10 | ++ Route metric for default route learned in Router Advertisement. This value |
| 11 | ++ will be assigned as metric for the default route learned via IPv6 Router |
| 12 | ++ Advertisement. Takes affect only if accept_ra_defrtr is enabled. |
| 13 | ++ |
| 14 | ++ Possible values: |
| 15 | ++ 1 to 0xFFFFFFFF |
| 16 | ++ |
| 17 | ++ Default: IP6_RT_PRIO_USER i.e. 1024. |
| 18 | ++ |
| 19 | + accept_ra_from_local - BOOLEAN |
| 20 | + Accept RA with source-address that is found on local machine |
| 21 | + if the RA is otherwise proper and able to be accepted. |
| 22 | +diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h |
| 23 | +index 8415bf1a9..ab98f5fa2 100644 |
| 24 | +--- a/include/linux/ipv6.h |
| 25 | ++++ b/include/linux/ipv6.h |
| 26 | +@@ -31,6 +31,7 @@ struct ipv6_devconf { |
| 27 | + __s32 max_desync_factor; |
| 28 | + __s32 max_addresses; |
| 29 | + __s32 accept_ra_defrtr; |
| 30 | ++ __u32 ra_defrtr_metric; |
| 31 | + __s32 accept_ra_min_hop_limit; |
| 32 | + __s32 accept_ra_pinfo; |
| 33 | + __s32 ignore_routes_with_linkdown; |
| 34 | +diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h |
| 35 | +index 5e26d6186..7087fb5e5 100644 |
| 36 | +--- a/include/net/ip6_route.h |
| 37 | ++++ b/include/net/ip6_route.h |
| 38 | +@@ -153,7 +153,8 @@ struct fib6_info *rt6_get_dflt_router(struct net *net, |
| 39 | + struct net_device *dev); |
| 40 | + struct fib6_info *rt6_add_dflt_router(struct net *net, |
| 41 | + const struct in6_addr *gwaddr, |
| 42 | +- struct net_device *dev, unsigned int pref); |
| 43 | ++ struct net_device *dev, unsigned int pref, |
| 44 | ++ u32 defrtr_usr_metric); |
| 45 | + |
| 46 | + void rt6_purge_dflt_routers(struct net *net); |
| 47 | + |
| 48 | +diff --git a/include/uapi/linux/ipv6.h b/include/uapi/linux/ipv6.h |
| 49 | +index 9c0f4a92b..481616cc2 100644 |
| 50 | +--- a/include/uapi/linux/ipv6.h |
| 51 | ++++ b/include/uapi/linux/ipv6.h |
| 52 | +@@ -187,6 +187,7 @@ enum { |
| 53 | + DEVCONF_DISABLE_POLICY, |
| 54 | + DEVCONF_ACCEPT_RA_RT_INFO_MIN_PLEN, |
| 55 | + DEVCONF_NDISC_TCLASS, |
| 56 | ++ DEVCONF_RA_DEFRTR_METRIC, |
| 57 | + DEVCONF_MAX |
| 58 | + }; |
| 59 | + |
| 60 | +diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h |
| 61 | +index d71013fff..42fb25093 100644 |
| 62 | +--- a/include/uapi/linux/sysctl.h |
| 63 | ++++ b/include/uapi/linux/sysctl.h |
| 64 | +@@ -570,6 +570,7 @@ enum { |
| 65 | + NET_IPV6_ACCEPT_SOURCE_ROUTE=25, |
| 66 | + NET_IPV6_ACCEPT_RA_FROM_LOCAL=26, |
| 67 | + NET_IPV6_ACCEPT_RA_RT_INFO_MIN_PLEN=27, |
| 68 | ++ NET_IPV6_RA_DEFRTR_METRIC=28, |
| 69 | + __NET_IPV6_MAX |
| 70 | + }; |
| 71 | + |
| 72 | +diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c |
| 73 | +index 07148b497..67b5ef45b 100644 |
| 74 | +--- a/kernel/sysctl_binary.c |
| 75 | ++++ b/kernel/sysctl_binary.c |
| 76 | +@@ -525,6 +525,7 @@ static const struct bin_table bin_net_ipv6_conf_var_table[] = { |
| 77 | + { CTL_INT, NET_IPV6_PROXY_NDP, "proxy_ndp" }, |
| 78 | + { CTL_INT, NET_IPV6_ACCEPT_SOURCE_ROUTE, "accept_source_route" }, |
| 79 | + { CTL_INT, NET_IPV6_ACCEPT_RA_FROM_LOCAL, "accept_ra_from_local" }, |
| 80 | ++ { CTL_INT, NET_IPV6_RA_DEFRTR_METRIC, "ra_defrtr_metric" }, |
| 81 | + {} |
| 82 | + }; |
| 83 | + |
| 84 | +diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c |
| 85 | +index 627cd24b7..2c8be7d60 100644 |
| 86 | +--- a/net/ipv6/addrconf.c |
| 87 | ++++ b/net/ipv6/addrconf.c |
| 88 | +@@ -209,6 +209,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = { |
| 89 | + .max_desync_factor = MAX_DESYNC_FACTOR, |
| 90 | + .max_addresses = IPV6_MAX_ADDRESSES, |
| 91 | + .accept_ra_defrtr = 1, |
| 92 | ++ .ra_defrtr_metric = IP6_RT_PRIO_USER, |
| 93 | + .accept_ra_from_local = 0, |
| 94 | + .accept_ra_min_hop_limit= 1, |
| 95 | + .accept_ra_pinfo = 1, |
| 96 | +@@ -263,6 +264,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = { |
| 97 | + .max_desync_factor = MAX_DESYNC_FACTOR, |
| 98 | + .max_addresses = IPV6_MAX_ADDRESSES, |
| 99 | + .accept_ra_defrtr = 1, |
| 100 | ++ .ra_defrtr_metric = IP6_RT_PRIO_USER, |
| 101 | + .accept_ra_from_local = 0, |
| 102 | + .accept_ra_min_hop_limit= 1, |
| 103 | + .accept_ra_pinfo = 1, |
| 104 | +@@ -5199,6 +5201,7 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf, |
| 105 | + array[DEVCONF_MAX_DESYNC_FACTOR] = cnf->max_desync_factor; |
| 106 | + array[DEVCONF_MAX_ADDRESSES] = cnf->max_addresses; |
| 107 | + array[DEVCONF_ACCEPT_RA_DEFRTR] = cnf->accept_ra_defrtr; |
| 108 | ++ array[DEVCONF_RA_DEFRTR_METRIC] = cnf->ra_defrtr_metric; |
| 109 | + array[DEVCONF_ACCEPT_RA_MIN_HOP_LIMIT] = cnf->accept_ra_min_hop_limit; |
| 110 | + array[DEVCONF_ACCEPT_RA_PINFO] = cnf->accept_ra_pinfo; |
| 111 | + #ifdef CONFIG_IPV6_ROUTER_PREF |
| 112 | +@@ -6347,6 +6350,14 @@ static const struct ctl_table addrconf_sysctl[] = { |
| 113 | + .mode = 0644, |
| 114 | + .proc_handler = proc_dointvec, |
| 115 | + }, |
| 116 | ++ { |
| 117 | ++ .procname = "ra_defrtr_metric", |
| 118 | ++ .data = &ipv6_devconf.ra_defrtr_metric, |
| 119 | ++ .maxlen = sizeof(u32), |
| 120 | ++ .mode = 0644, |
| 121 | ++ .proc_handler = proc_douintvec_minmax, |
| 122 | ++ .extra1 = SYSCTL_ONE, |
| 123 | ++ }, |
| 124 | + { |
| 125 | + .procname = "accept_ra_min_hop_limit", |
| 126 | + .data = &ipv6_devconf.accept_ra_min_hop_limit, |
| 127 | +diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c |
| 128 | +index 673a4a932..5dc072809 100644 |
| 129 | +--- a/net/ipv6/ndisc.c |
| 130 | ++++ b/net/ipv6/ndisc.c |
| 131 | +@@ -1156,6 +1156,7 @@ static void ndisc_router_discovery(struct sk_buff *skb) |
| 132 | + struct neighbour *neigh = NULL; |
| 133 | + struct inet6_dev *in6_dev; |
| 134 | + struct fib6_info *rt = NULL; |
| 135 | ++ u32 defrtr_usr_metric; |
| 136 | + struct net *net; |
| 137 | + int lifetime; |
| 138 | + struct ndisc_options ndopts; |
| 139 | +@@ -1287,18 +1288,21 @@ static void ndisc_router_discovery(struct sk_buff *skb) |
| 140 | + return; |
| 141 | + } |
| 142 | + } |
| 143 | +- if (rt && lifetime == 0) { |
| 144 | ++ /* Set default route metric if specified by user */ |
| 145 | ++ defrtr_usr_metric = in6_dev->cnf.ra_defrtr_metric; |
| 146 | ++ /* delete the route if lifetime is 0 or if metric needs change */ |
| 147 | ++ if (rt && (lifetime == 0 || rt->fib6_metric != defrtr_usr_metric)) { |
| 148 | + ip6_del_rt(net, rt); |
| 149 | + rt = NULL; |
| 150 | + } |
| 151 | + |
| 152 | +- ND_PRINTK(3, info, "RA: rt: %p lifetime: %d, for dev: %s\n", |
| 153 | +- rt, lifetime, skb->dev->name); |
| 154 | ++ ND_PRINTK(3, info, "RA: rt: %p lifetime: %d, metric: %d, for dev: %s\n", |
| 155 | ++ rt, lifetime, defrtr_usr_metric, skb->dev->name); |
| 156 | + if (!rt && lifetime) { |
| 157 | + ND_PRINTK(3, info, "RA: adding default router\n"); |
| 158 | + |
| 159 | + rt = rt6_add_dflt_router(net, &ipv6_hdr(skb)->saddr, |
| 160 | +- skb->dev, pref); |
| 161 | ++ skb->dev, pref, defrtr_usr_metric); |
| 162 | + if (!rt) { |
| 163 | + ND_PRINTK(0, err, |
| 164 | + "RA: %s failed to add default route\n", |
| 165 | +diff --git a/net/ipv6/route.c b/net/ipv6/route.c |
| 166 | +index 9c36a743d..2ba8e6411 100644 |
| 167 | +--- a/net/ipv6/route.c |
| 168 | ++++ b/net/ipv6/route.c |
| 169 | +@@ -3608,11 +3608,12 @@ struct fib6_info *rt6_get_dflt_router(struct net *net, |
| 170 | + struct fib6_info *rt6_add_dflt_router(struct net *net, |
| 171 | + const struct in6_addr *gwaddr, |
| 172 | + struct net_device *dev, |
| 173 | +- unsigned int pref) |
| 174 | ++ unsigned int pref, |
| 175 | ++ u32 defrtr_usr_metric) |
| 176 | + { |
| 177 | + struct fib6_config cfg = { |
| 178 | + .fc_table = l3mdev_fib_table(dev) ? : RT6_TABLE_DFLT, |
| 179 | +- .fc_metric = IP6_RT_PRIO_USER, |
| 180 | ++ .fc_metric = defrtr_usr_metric, |
| 181 | + .fc_ifindex = dev->ifindex, |
| 182 | + .fc_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_DEFAULT | |
| 183 | + RTF_UP | RTF_EXPIRES | RTF_PREF(pref), |
0 commit comments