diff options
author | Jean-Francois Remy <jeff@melix.org> | 2015-01-13 22:22:39 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-01-14 00:28:00 -0500 |
commit | 4bf6980dd0328530783fd657c776e3719b421d30 (patch) | |
tree | ebfdd64060a02dd8cee743e27f06a95e598e136a | |
parent | 3d125f9c91c599a77ac3cb8f05113a6c8df99cbe (diff) |
neighbour: fix base_reachable_time(_ms) not effective immediatly when changed
When setting base_reachable_time or base_reachable_time_ms on a
specific interface through sysctl or netlink, the reachable_time
value is not updated.
This means that neighbour entries will continue to be updated using the
old value until it is recomputed in neigh_period_work (which
recomputes the value every 300*HZ).
On systems with HZ equal to 1000 for instance, it means 5mins before
the change is effective.
This patch changes this behavior by recomputing reachable_time after
each set on base_reachable_time or base_reachable_time_ms.
The new value will become effective the next time the neighbour's timer
is triggered.
Changes are made in two places: the netlink code for set and the sysctl
handling code. For sysctl, I use a proc_handler. The ipv6 network
code does provide its own handler but it already refreshes
reachable_time correctly so it's not an issue.
Any other user of neighbour which provide its own handlers must
refresh reachable_time.
Signed-off-by: Jean-Francois Remy <jeff@melix.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/core/neighbour.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 8e38f17288d3..8d614c93f86a 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c | |||
@@ -2043,6 +2043,12 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
2043 | case NDTPA_BASE_REACHABLE_TIME: | 2043 | case NDTPA_BASE_REACHABLE_TIME: |
2044 | NEIGH_VAR_SET(p, BASE_REACHABLE_TIME, | 2044 | NEIGH_VAR_SET(p, BASE_REACHABLE_TIME, |
2045 | nla_get_msecs(tbp[i])); | 2045 | nla_get_msecs(tbp[i])); |
2046 | /* update reachable_time as well, otherwise, the change will | ||
2047 | * only be effective after the next time neigh_periodic_work | ||
2048 | * decides to recompute it (can be multiple minutes) | ||
2049 | */ | ||
2050 | p->reachable_time = | ||
2051 | neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME)); | ||
2046 | break; | 2052 | break; |
2047 | case NDTPA_GC_STALETIME: | 2053 | case NDTPA_GC_STALETIME: |
2048 | NEIGH_VAR_SET(p, GC_STALETIME, | 2054 | NEIGH_VAR_SET(p, GC_STALETIME, |
@@ -2921,6 +2927,31 @@ static int neigh_proc_dointvec_unres_qlen(struct ctl_table *ctl, int write, | |||
2921 | return ret; | 2927 | return ret; |
2922 | } | 2928 | } |
2923 | 2929 | ||
2930 | static int neigh_proc_base_reachable_time(struct ctl_table *ctl, int write, | ||
2931 | void __user *buffer, | ||
2932 | size_t *lenp, loff_t *ppos) | ||
2933 | { | ||
2934 | struct neigh_parms *p = ctl->extra2; | ||
2935 | int ret; | ||
2936 | |||
2937 | if (strcmp(ctl->procname, "base_reachable_time") == 0) | ||
2938 | ret = neigh_proc_dointvec_jiffies(ctl, write, buffer, lenp, ppos); | ||
2939 | else if (strcmp(ctl->procname, "base_reachable_time_ms") == 0) | ||
2940 | ret = neigh_proc_dointvec_ms_jiffies(ctl, write, buffer, lenp, ppos); | ||
2941 | else | ||
2942 | ret = -1; | ||
2943 | |||
2944 | if (write && ret == 0) { | ||
2945 | /* update reachable_time as well, otherwise, the change will | ||
2946 | * only be effective after the next time neigh_periodic_work | ||
2947 | * decides to recompute it | ||
2948 | */ | ||
2949 | p->reachable_time = | ||
2950 | neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME)); | ||
2951 | } | ||
2952 | return ret; | ||
2953 | } | ||
2954 | |||
2924 | #define NEIGH_PARMS_DATA_OFFSET(index) \ | 2955 | #define NEIGH_PARMS_DATA_OFFSET(index) \ |
2925 | (&((struct neigh_parms *) 0)->data[index]) | 2956 | (&((struct neigh_parms *) 0)->data[index]) |
2926 | 2957 | ||
@@ -3047,6 +3078,19 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p, | |||
3047 | t->neigh_vars[NEIGH_VAR_RETRANS_TIME_MS].proc_handler = handler; | 3078 | t->neigh_vars[NEIGH_VAR_RETRANS_TIME_MS].proc_handler = handler; |
3048 | /* ReachableTime (in milliseconds) */ | 3079 | /* ReachableTime (in milliseconds) */ |
3049 | t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME_MS].proc_handler = handler; | 3080 | t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME_MS].proc_handler = handler; |
3081 | } else { | ||
3082 | /* Those handlers will update p->reachable_time after | ||
3083 | * base_reachable_time(_ms) is set to ensure the new timer starts being | ||
3084 | * applied after the next neighbour update instead of waiting for | ||
3085 | * neigh_periodic_work to update its value (can be multiple minutes) | ||
3086 | * So any handler that replaces them should do this as well | ||
3087 | */ | ||
3088 | /* ReachableTime */ | ||
3089 | t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME].proc_handler = | ||
3090 | neigh_proc_base_reachable_time; | ||
3091 | /* ReachableTime (in milliseconds) */ | ||
3092 | t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME_MS].proc_handler = | ||
3093 | neigh_proc_base_reachable_time; | ||
3050 | } | 3094 | } |
3051 | 3095 | ||
3052 | /* Don't export sysctls to unprivileged users */ | 3096 | /* Don't export sysctls to unprivileged users */ |