-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
svc-lnos-user
committed
Dec 18, 2020
1 parent
6f53047
commit 385ad2d
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
Allow user to set ipv6 Router Advertisement(RA) metric. | ||
|
||
Linux kernel allows user configured metric on IPv4 default | ||
routes learned via DHCP. For IPv6, default router is added | ||
via RA message, where currently a fixed metric value 1024 | ||
is applied. We should allow user to set ipv6 RA metric. | ||
|
||
Fix: | ||
Add new field in ipv6_devconf for RA default route metric. | ||
i.e accept_ra_defrtr_metric. | ||
Add accept_ra_defrtr_metric as sysctl. | ||
If accept_ra_defrtr_metric is set, then change metric on | ||
default route, whenever new IPv6 RA is received. | ||
|
||
Note: Metric is changed on default route only when new IPv6 | ||
RA is received. | ||
|
||
Signed-off-by: Praveen Chaudhary <[email protected]> | ||
Signed-off-by: Zhenggen Xu <[email protected]> | ||
diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h | ||
index b9dfca5..9b70be7 100644 | ||
--- a/include/linux/ipv6.h | ||
+++ b/include/linux/ipv6.h | ||
@@ -30,6 +30,7 @@ struct ipv6_devconf { | ||
__s32 max_desync_factor; | ||
__s32 max_addresses; | ||
__s32 accept_ra_defrtr; | ||
+ __u32 accept_ra_defrtr_metric; | ||
__s32 accept_ra_min_hop_limit; | ||
__s32 accept_ra_pinfo; | ||
__s32 ignore_routes_with_linkdown; | ||
diff --git a/include/uapi/linux/ipv6.h b/include/uapi/linux/ipv6.h | ||
index 8c27723..36d7097 100644 | ||
--- a/include/uapi/linux/ipv6.h | ||
+++ b/include/uapi/linux/ipv6.h | ||
@@ -152,6 +152,7 @@ enum { | ||
DEVCONF_MAX_ADDRESSES, | ||
DEVCONF_FORCE_MLD_VERSION, | ||
DEVCONF_ACCEPT_RA_DEFRTR, | ||
+ DEVCONF_ACCEPT_RA_DEFRTR_METRIC, | ||
DEVCONF_ACCEPT_RA_PINFO, | ||
DEVCONF_ACCEPT_RA_RTR_PREF, | ||
DEVCONF_RTR_PROBE_INTERVAL, | ||
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c | ||
index 4ce7f91..529db12 100644 | ||
--- a/net/ipv6/addrconf.c | ||
+++ b/net/ipv6/addrconf.c | ||
@@ -216,6 +216,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = { | ||
.max_desync_factor = MAX_DESYNC_FACTOR, | ||
.max_addresses = IPV6_MAX_ADDRESSES, | ||
.accept_ra_defrtr = 1, | ||
+ .accept_ra_defrtr_metric = 0, | ||
.accept_ra_from_local = 0, | ||
.accept_ra_min_hop_limit= 1, | ||
.accept_ra_pinfo = 1, | ||
@@ -262,6 +263,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = { | ||
.max_desync_factor = MAX_DESYNC_FACTOR, | ||
.max_addresses = IPV6_MAX_ADDRESSES, | ||
.accept_ra_defrtr = 1, | ||
+ .accept_ra_defrtr_metric = 0, | ||
.accept_ra_from_local = 0, | ||
.accept_ra_min_hop_limit= 1, | ||
.accept_ra_pinfo = 1, | ||
@@ -4951,6 +4953,7 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf, | ||
array[DEVCONF_MAX_DESYNC_FACTOR] = cnf->max_desync_factor; | ||
array[DEVCONF_MAX_ADDRESSES] = cnf->max_addresses; | ||
array[DEVCONF_ACCEPT_RA_DEFRTR] = cnf->accept_ra_defrtr; | ||
+ array[DEVCONF_ACCEPT_RA_DEFRTR_METRIC] = cnf->accept_ra_defrtr_metric; | ||
array[DEVCONF_ACCEPT_RA_MIN_HOP_LIMIT] = cnf->accept_ra_min_hop_limit; | ||
array[DEVCONF_ACCEPT_RA_PINFO] = cnf->accept_ra_pinfo; | ||
#ifdef CONFIG_IPV6_ROUTER_PREF | ||
@@ -5903,6 +5906,13 @@ static const struct ctl_table addrconf_sysctl[] = { | ||
.proc_handler = proc_dointvec, | ||
}, | ||
{ | ||
+ .procname = "accept_ra_defrtr_metric", | ||
+ .data = &ipv6_devconf.accept_ra_defrtr_metric, | ||
+ .maxlen = sizeof(u32), | ||
+ .mode = 0644, | ||
+ .proc_handler = proc_douintvec, | ||
+ }, | ||
+ { | ||
.procname = "accept_ra_min_hop_limit", | ||
.data = &ipv6_devconf.accept_ra_min_hop_limit, | ||
.maxlen = sizeof(int), | ||
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c | ||
index 505d048..eb6f16f 100644 | ||
--- a/net/ipv6/ndisc.c | ||
+++ b/net/ipv6/ndisc.c | ||
@@ -1279,8 +1279,12 @@ static void ndisc_router_discovery(struct sk_buff *skb) | ||
rt->rt6i_flags = (rt->rt6i_flags & ~RTF_PREF_MASK) | RTF_PREF(pref); | ||
} | ||
|
||
- if (rt) | ||
+ if (rt) { | ||
rt6_set_expires(rt, jiffies + (HZ * lifetime)); | ||
+ /* Set metric as per ipv6 dev cnf */ | ||
+ if (in6_dev->cnf.accept_ra_defrtr_metric) | ||
+ rt->rt6i_metric = in6_dev->cnf.accept_ra_defrtr_metric; | ||
+ } | ||
if (in6_dev->cnf.accept_ra_min_hop_limit < 256 && | ||
ra_msg->icmph.icmp6_hop_limit) { | ||
if (in6_dev->cnf.accept_ra_min_hop_limit <= ra_msg->icmph.icmp6_hop_limit) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters