neigh: respect default parms values
Subsystems (3)
v2 cover neigh: respect default parms values
This is a long standing regression. But since the patchset is bigger and the regression happened in 2007, I'm proposing this to net-next instead.
Basically the problem is that if user wants to use /etc/sysctl.conf to specify default values of neigh related params, he is not able to do that.
The reason is that the default values are copied to dev instance right after netdev is registered. And that is way to early. The original behaviour for ipv4 was that this happened after first address was assigned to device. For ipv6 this was apparently from the very beginning.
So this patchset basically reverts the behaviour back to what it was in 2007 for ipv4 and changes the behaviour for ipv6 so they are both the same.
v1->v2:
- use neigh_parms->tbl->family as suggested by davem
Jiri Pirko (5):
neigh: convert parms to an array
neigh: wrap proc dointvec functions
neigh: use tbl->family to distinguish ipv4 from ipv6
neigh: restore old behaviour of default parms values
neigh: ipv6: respect default values set before an address is assigned
to device
include/linux/inetdevice.h | 7 + include/net/addrconf.h | 7 + include/net/neighbour.h | 77 ++++++-- net/802/hippi.c | 4 +- net/core/neighbour.c | 451 +++++++++++++++++++++++++-------------------- net/decnet/dn_neigh.c | 28 +-- net/ipv4/arp.c | 35 ++-- net/ipv4/devinet.c | 4 +- net/ipv4/ipmr.c | 2 + net/ipv6/addrconf.c | 16 +- net/ipv6/ndisc.c | 55 +++--- 11 files changed, 414 insertions(+), 272 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/5 neigh: convert parms to an array
This patch converts the neigh param members to an array. This allows easier manipulation which will be needed later on to provide better management of default values.
--- include/net/neighbour.h | 48 +++++-- net/802/hippi.c | 4 +- net/core/neighbour.c | 327 ++++++++++++++++++++---------------------------- net/decnet/dn_neigh.c | 28 +++-- net/ipv4/arp.c | 33 ++--- net/ipv6/addrconf.c | 12 +- net/ipv6/ndisc.c | 43 ++++--- 7 files changed, 238 insertions(+), 257 deletions(-)
include/net/neighbour.h +35 -13
@@ -37,6 +37,32 @@struct neighbour ; +enum { +NEIGH_VAR_MCAST_PROBES , +NEIGH_VAR_UCAST_PROBES , +NEIGH_VAR_APP_PROBES , +NEIGH_VAR_RETRANS_TIME , +NEIGH_VAR_BASE_REACHABLE_TIME , +NEIGH_VAR_DELAY_PROBE_TIME , +NEIGH_VAR_GC_STALETIME , +NEIGH_VAR_QUEUE_LEN_BYTES , +NEIGH_VAR_PROXY_QLEN , +NEIGH_VAR_ANYCAST_DELAY , +NEIGH_VAR_PROXY_DELAY , +NEIGH_VAR_LOCKTIME , +#define NEIGH_VAR_DATA_MAX (NEIGH_VAR_LOCKTIME + 1) + /* Following are used as a second way to access one of the above */ +NEIGH_VAR_QUEUE_LEN ,/* same data as NEIGH_VAR_QUEUE_LEN_BYTES */ +NEIGH_VAR_RETRANS_TIME_MS ,/* same data as NEIGH_VAR_RETRANS_TIME */ +NEIGH_VAR_BASE_REACHABLE_TIME_MS ,/* same data as NEIGH_VAR_BASE_REACHABLE_TIME */ +/* Following are used by "default" only */ +NEIGH_VAR_GC_INTERVAL , +NEIGH_VAR_GC_THRESH1 , +NEIGH_VAR_GC_THRESH2 , +NEIGH_VAR_GC_THRESH3 , +NEIGH_VAR_MAX +}; +struct neigh_parms {#ifdef CONFIG_NET_NS struct net *net;
@@ -53,22 +79,18 @@ struct neigh_parms {atomic_t refcnt;struct rcu_head rcu_head; -int base_reachable_time; -int retrans_time; -int gc_staletime;int reachable_time; -int delay_probe_time; - -int queue_len_bytes; -int ucast_probes; -int app_probes; -int mcast_probes; -int anycast_delay; -int proxy_delay; -int proxy_qlen; -int locktime; +int data[NEIGH_VAR_DATA_MAX ]; }; +static inline void neigh_var_set (struct neigh_parms *p,int index,int val) +{ + p->data[index] = val; +} + +#define NEIGH_VAR (p, attr) ((p)->data[NEIGH_VAR_ ## attr]) +#define NEIGH_VAR_SET (p, attr, val) neigh_var_set(p, NEIGH_VAR_ ## attr, val) +struct neigh_statistics {unsigned long allocs;/* number of allocated neighs */ unsigned long destroys;/* number of destroyed neighs */
net/802/hippi.c +2 -2
@@ -172,14 +172,14 @@ EXPORT_SYMBOL(hippi_mac_addr);int hippi_neigh_setup_dev (struct net_device *dev,struct neigh_parms *p) {/* Never send broadcast/multicast ARP messages */ - p->mcast_probes =0 ; +NEIGH_VAR_SET (p,MCAST_PROBES ,0 );/* In IPv6 unicast probes are valid even on NBMA, * because they are encapsulated in normal IPv6 protocol. * Should be a generic flag. */ if (p->tbl->family !=AF_INET6 ) - p->ucast_probes =0 ; +NEIGH_VAR_SET (p,UCAST_PROBES ,0 );return 0 ; }EXPORT_SYMBOL (hippi_neigh_setup_dev);
net/core/neighbour.c +137 -190
502 lines not on this page · raw message
net/decnet/dn_neigh.c +15 -13
@@ -102,19 +102,21 @@ struct neigh_table dn_neigh_table = { .id = "dn_neigh_cache", .parms ={ .tbl = &dn_neigh_table, - .base_reachable_time = 30 * HZ, - .retrans_time = 1 * HZ, - .gc_staletime = 60 * HZ, - .reachable_time = 30 * HZ, - .delay_probe_time = 5 * HZ, - .queue_len_bytes = 64*1024, - .ucast_probes = 0, - .app_probes = 0, - .mcast_probes = 0, - .anycast_delay = 0, - .proxy_delay = 0, - .proxy_qlen = 0, - .locktime = 1 * HZ, + .reachable_time = 30 * HZ, + .data = { + [NEIGH_VAR_MCAST_PROBES] = 0, + [NEIGH_VAR_UCAST_PROBES] = 0, + [NEIGH_VAR_APP_PROBES] = 0, + [NEIGH_VAR_RETRANS_TIME] = 1 * HZ, + [NEIGH_VAR_BASE_REACHABLE_TIME] = 30 * HZ, + [NEIGH_VAR_DELAY_PROBE_TIME] = 5 * HZ, + [NEIGH_VAR_GC_STALETIME] = 60 * HZ, + [NEIGH_VAR_QUEUE_LEN_BYTES] = 64*1024, + [NEIGH_VAR_PROXY_QLEN] = 0, + [NEIGH_VAR_ANYCAST_DELAY] = 0, + [NEIGH_VAR_PROXY_DELAY] = 0, + [NEIGH_VAR_LOCKTIME ] =1 *HZ , + }, }, .gc_interval = 30 * HZ, .gc_thresh1 = 128,
net/ipv4/arp.c +18 -15
@@ -166,18 +166,20 @@ struct neigh_table arp_tbl = { .id = "arp_cache", .parms = { .tbl = &arp_tbl, - .base_reachable_time = 30 * HZ, - .retrans_time = 1 * HZ, - .gc_staletime = 60 * HZ, .reachable_time = 30 * HZ, - .delay_probe_time = 5 * HZ, - .queue_len_bytes = 64*1024, - .ucast_probes = 3, - .mcast_probes = 3, - .anycast_delay = 1 * HZ, - .proxy_delay = (8 * HZ) / 10, - .proxy_qlen = 64, - .locktime = 1 * HZ, + .data = { + [NEIGH_VAR_MCAST_PROBES] = 3, + [NEIGH_VAR_UCAST_PROBES] = 3, + [NEIGH_VAR_RETRANS_TIME] = 1 * HZ, + [NEIGH_VAR_BASE_REACHABLE_TIME] = 30 * HZ, + [NEIGH_VAR_DELAY_PROBE_TIME] = 5 * HZ, + [NEIGH_VAR_GC_STALETIME] = 60 * HZ, + [NEIGH_VAR_QUEUE_LEN_BYTES] = 64 * 1024, + [NEIGH_VAR_PROXY_QLEN] = 64, + [NEIGH_VAR_ANYCAST_DELAY] = 1 * HZ, + [NEIGH_VAR_PROXY_DELAY] = (8 * HZ) / 10, + [NEIGH_VAR_LOCKTIME ] =1 *HZ , + }, }, .gc_interval = 30 * HZ, .gc_thresh1 = 128,
@@ -359,14 +361,14 @@ static void arp_solicit(struct neighbour *neigh, struct sk_buff *skb)if (!saddr) saddr =inet_select_addr (dev, target,RT_SCOPE_LINK ); - probes -= neigh->parms->ucast_probes; + probes -=NEIGH_VAR (neigh->parms,UCAST_PROBES );if (probes <0 ) {if (!(neigh->nud_state &NUD_VALID ))pr_debug ("trying to ucast probe in NUD_INVALID\n" );neigh_ha_snapshot (dst_ha, neigh, dev); dst_hw = dst_ha; }else { - probes -= neigh->parms->app_probes; + probes -=NEIGH_VAR (neigh->parms,APP_PROBES );if (probes <0 ) {neigh_app_ns (neigh);return ;
@@ -871,7 +873,7 @@ static int arp_process(struct sk_buff *skb)if (NEIGH_CB (skb)->flags &LOCALLY_ENQUEUED || skb->pkt_type ==PACKET_HOST || - in_dev->arp_parms->proxy_delay ==0 ) { +NEIGH_VAR (in_dev->arp_parms,PROXY_DELAY ) ==0 ) {arp_send (ARPOP_REPLY ,ETH_P_ARP , sip, dev, tip, sha, dev->dev_addr, sha);
@@ -910,7 +912,8 @@ static int arp_process(struct sk_buff *skb)agents are active. Taking the first reply prevents arp trashing and chooses the fastest router. */ - override =time_after (jiffies, n->updated + n->parms->locktime); + override =time_after (jiffies, n->updated + +NEIGH_VAR (n->parms,LOCKTIME ));/* Broadcast replies and request packets do not assert neighbour reachability.
net/ipv6/addrconf.c +7 -5
@@ -1071,7 +1071,7 @@ retry: regen_advance = idev->cnf.regen_max_retry * idev->cnf.dad_transmits * - idev->nd_parms->retrans_time /HZ ; +NEIGH_VAR (idev->nd_parms,RETRANS_TIME ) /HZ ;write_unlock (&idev->lock);/* A temporary address is created only if this calculated Preferred
@@ -1888,7 +1888,8 @@ static void ipv6_regen_rndid(unsigned long data) expires = jiffies + idev->cnf.temp_prefered_lft *HZ - - idev->cnf.regen_max_retry * idev->cnf.dad_transmits * idev->nd_parms->retrans_time - + idev->cnf.regen_max_retry * idev->cnf.dad_transmits * +NEIGH_VAR (idev->nd_parms,RETRANS_TIME ) - idev->cnf.max_desync_factor *HZ ;if (time_before (expires, jiffies)) { pr_warn("%s: too short regeneration interval; timer disabled for %s\n",
@@ -3176,7 +3177,8 @@ static void addrconf_dad_timer(unsigned long data) } ifp->dad_probes--; -addrconf_mod_dad_timer (ifp, ifp->idev->nd_parms->retrans_time); +addrconf_mod_dad_timer (ifp, +NEIGH_VAR (ifp->idev->nd_parms,RETRANS_TIME ));spin_unlock (&ifp->lock);write_unlock (&idev->lock);
@@ -3497,7 +3499,7 @@ restart: !(ifp->flags&IFA_F_TENTATIVE)) {unsigned long regen_advance = ifp->idev->cnf.regen_max_retry * ifp->idev->cnf.dad_transmits * - ifp->idev->nd_parms->retrans_time /HZ ; +NEIGH_VAR (ifp->idev->nd_parms,RETRANS_TIME ) /HZ ;if (age >= ifp->prefered_lft - regen_advance) {struct inet6_ifaddr *ifpub = ifp->ifpub;
@@ -4196,7 +4198,7 @@ static int inet6_fill_ifla6_attrs(struct sk_buff *skb, struct inet6_dev *idev) ci.max_reasm_len =IPV6_MAXPLEN ; ci.tstamp =cstamp_delta (idev->tstamp); ci.reachable_time =jiffies_to_msecs (idev->nd_parms->reachable_time); - ci.retrans_time =jiffies_to_msecs (idev->nd_parms->retrans_time); + ci.retrans_time =jiffies_to_msecs (NEIGH_VAR (idev->nd_parms,RETRANS_TIME ));if (nla_put (skb,IFLA_INET6_CACHEINFO ,sizeof (ci), &ci)) goto nla_put_failure; nla =nla_reserve (skb,IFLA_INET6_CONF ,DEVCONF_MAX *sizeof (s32));
net/ipv6/ndisc.c +24 -19
86 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 2/5 neigh: wrap proc dointvec functions
In reply to Jiri PirkoThis will be needed later on to provide better management of default values.
--- include/net/neighbour.h | 9 ++++++++ net/core/neighbour.c | 55 ++++++++++++++++++++++++++++++++++++++++--------- net/ipv6/ndisc.c | 10 ++++----- 3 files changed, 59 insertions(+), 15 deletions(-)
include/net/neighbour.h +9 -0
@@ -296,6 +296,15 @@ void *neigh_seq_start(struct seq_file *, loff_t *, struct neigh_table *,void *neigh_seq_next (struct seq_file *,void *,loff_t *);void neigh_seq_stop (struct seq_file *,void *); +int neigh_proc_dointvec (struct ctl_table *ctl,int write, +void __user *buffer,size_t *lenp,loff_t *ppos); +int neigh_proc_dointvec_jiffies (struct ctl_table *ctl,int write, +void __user *buffer, +size_t *lenp,loff_t *ppos); +int neigh_proc_dointvec_ms_jiffies (struct ctl_table *ctl,int write, +void __user *buffer, +size_t *lenp,loff_t *ppos); +int neigh_sysctl_register (struct net_device *dev,struct neigh_parms *p,char *p_name,proc_handler *proc_handler);void neigh_sysctl_unregister (struct neigh_parms *p);
net/core/neighbour.c +45 -10
94 lines not on this page · raw message
net/ipv6/ndisc.c +5 -5
@@ -1655,16 +1655,16 @@ int ndisc_ifinfo_sysctl_change(struct ctl_table *ctl, int write, void __user *bundisc_warn_deprecated_sysctl (ctl,"syscall" , dev ? dev->name :"default" );if (strcmp (ctl->procname,"retrans_time" ) ==0 ) - ret =proc_dointvec (ctl, write, buffer, lenp, ppos); + ret =neigh_proc_dointvec (ctl, write, buffer, lenp, ppos);else if (strcmp (ctl->procname,"base_reachable_time" ) ==0 ) - ret =proc_dointvec_jiffies (ctl, write, - buffer, lenp, ppos); + ret =neigh_proc_dointvec_jiffies (ctl, write, + buffer, lenp, ppos);else if ((strcmp (ctl->procname,"retrans_time_ms" ) ==0 ) || (strcmp (ctl->procname,"base_reachable_time_ms" ) ==0 )) - ret =proc_dointvec_ms_jiffies (ctl, write, - buffer, lenp, ppos); + ret =neigh_proc_dointvec_ms_jiffies (ctl, write, + buffer, lenp, ppos);else ret =-1 ;
Signature · 1 line
1.8.3.1
PATCH v2 3/5 neigh: use tbl->family to distinguish ipv4 from ipv6
In reply to Jiri Pirko--- include/net/neighbour.h | 7 ++++++- net/core/neighbour.c | 14 +++++++++++++- net/ipv4/arp.c | 2 +- net/ipv4/devinet.c | 2 +- net/ipv6/addrconf.c | 2 +- net/ipv6/ndisc.c | 2 +- 6 files changed, 23 insertions(+), 6 deletions(-)
include/net/neighbour.h +6 -1
@@ -202,6 +202,11 @@ struct neigh_table {struct pneigh_entry **phash_buckets; }; +static inline int neigh_parms_family (struct neigh_parms *p) +{ +return p->tbl->family; +} +#define NEIGH_PRIV_ALIGN sizeof(long long)#define NEIGH_ENTRY_SIZE (size) ALIGN((size), NEIGH_PRIV_ALIGN)
@@ -306,7 +311,7 @@ int neigh_proc_dointvec_ms_jiffies(struct ctl_table *ctl, int write, size_t *lenp, loff_t *ppos);int neigh_sysctl_register (struct net_device *dev,struct neigh_parms *p, -char *p_name,proc_handler *proc_handler); +proc_handler *proc_handler);void neigh_sysctl_unregister (struct neigh_parms *p);static inline void __neigh_parms_put (struct neigh_parms *parms)
net/core/neighbour.c +13 -1
@@ -2947,12 +2947,13 @@ static struct neigh_sysctl_table { };int neigh_sysctl_register (struct net_device *dev,struct neigh_parms *p, -char *p_name,proc_handler *handler) +proc_handler *handler) {int i;struct neigh_sysctl_table *t;const char *dev_name_source;char neigh_path[sizeof ("net//neigh/" ) +IFNAMSIZ +IFNAMSIZ ]; +char *p_name; t =kmemdup (&neigh_sysctl_template,sizeof (*t),GFP_KERNEL );if (!t)
@@ -2991,6 +2992,17 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,if (neigh_parms_net (p)->user_ns != &init_user_ns) t->neigh_vars[0 ].procname =NULL ; +switch (neigh_parms_family (p)) { +case AF_INET : + p_name ="ipv4" ; +break ; +case AF_INET6 : + p_name ="ipv6" ; +break ; +default : +BUG (); + } +snprintf (neigh_path,sizeof (neigh_path),"net/%s/neigh/%s" , p_name, dev_name_source); t->sysctl_header =
net/ipv4/arp.c +1 -1
@@ -1287,7 +1287,7 @@ void __init arp_init(void)dev_add_pack (&arp_packet_type);arp_proc_init ();#ifdef CONFIG_SYSCTL -neigh_sysctl_register (NULL , &arp_tbl.parms,"ipv4" ,NULL ); +neigh_sysctl_register (NULL , &arp_tbl.parms,NULL );#endif register_netdevice_notifier (&arp_netdev_notifier); }
net/ipv4/devinet.c +1 -1
@@ -2160,7 +2160,7 @@ static void __devinet_sysctl_unregister(struct ipv4_devconf *cnf)static void devinet_sysctl_register (struct in_device *idev) { -neigh_sysctl_register (idev->dev, idev->arp_parms,"ipv4" ,NULL ); +neigh_sysctl_register (idev->dev, idev->arp_parms,NULL );__devinet_sysctl_register (dev_net (idev->dev), idev->dev->name, &idev->cnf); }
net/ipv6/addrconf.c +1 -1
@@ -4993,7 +4993,7 @@ static void __addrconf_sysctl_unregister(struct ipv6_devconf *p)static void addrconf_sysctl_register (struct inet6_dev *idev) { -neigh_sysctl_register (idev->dev, idev->nd_parms,"ipv6" , +neigh_sysctl_register (idev->dev, idev->nd_parms, &ndisc_ifinfo_sysctl_change);__addrconf_sysctl_register (dev_net (idev->dev), idev->dev->name, idev, &idev->cnf);
net/ipv6/ndisc.c +1 -1
@@ -1730,7 +1730,7 @@ int __init ndisc_init(void)neigh_table_init (&nd_tbl);#ifdef CONFIG_SYSCTL - err =neigh_sysctl_register (NULL , &nd_tbl.parms,"ipv6" , + err =neigh_sysctl_register (NULL , &nd_tbl.parms, &ndisc_ifinfo_sysctl_change);if (err) goto out_unregister_pernet;
Signature · 1 line
1.8.3.1
PATCH v2 4/5 neigh: restore old behaviour of default parms values
In reply to Jiri PirkoPreviously inet devices were only constructed when addresses are added. Therefore the default neigh parms values they get are the ones at the time of these operations.
Now that we're creating inet devices earlier, this changes the behaviour of default neigh parms values in an incompatible way (see bug #8519).
This patch creates a compromise by setting the default values at the same point as before but only for those that have not been explicitly set by the user since the inet device's creation.
Introduced by:
commit 8030f54499925d073a88c09f30d5d844fb1b3190
Author: Herbert Xu <[email protected]> Date: Thu Feb 22 01:53:47 2007 +0900
[IPV4] devinet: Register inetdev earlier.
--- include/linux/inetdevice.h | 7 +++++ include/net/neighbour.h | 13 ++++++++ net/core/neighbour.c | 74 ++++++++++++++++++++++++++++++++++++++++++---- net/ipv4/devinet.c | 2 ++ net/ipv4/ipmr.c | 2 ++ 5 files changed, 92 insertions(+), 6 deletions(-)
include/linux/inetdevice.h +7 -0
@@ -220,6 +220,13 @@ static inline struct in_device *__in_dev_get_rtnl(const struct net_device *dev)return rtnl_dereference (dev->ip_ptr); } +static inline struct neigh_parms *__in_dev_arp_parms_get_rcu (const struct net_device *dev) +{ +struct in_device *in_dev =__in_dev_get_rcu (dev); + +return in_dev ? in_dev->arp_parms :NULL ; +} +void in_dev_finish_destroy (struct in_device *idev);static inline void in_dev_put (struct in_device *idev)
include/net/neighbour.h +13 -0
@@ -21,6 +21,7 @@#include <linux/skbuff.h> #include <linux/rcupdate.h> #include <linux/seq_file.h> +#include <linux/bitmap.h> #include <linux/err.h> #include <linux/sysctl.h>
@@ -81,16 +82,28 @@ struct neigh_parms {int reachable_time;int data[NEIGH_VAR_DATA_MAX ]; +DECLARE_BITMAP (data_state,NEIGH_VAR_DATA_MAX ); };static inline void neigh_var_set (struct neigh_parms *p,int index,int val) { +set_bit (index, p->data_state); p->data[index] = val; }#define NEIGH_VAR (p, attr) ((p)->data[NEIGH_VAR_ ## attr])#define NEIGH_VAR_SET (p, attr, val) neigh_var_set(p, NEIGH_VAR_ ## attr, val) +static inline void neigh_parms_data_state_setall (struct neigh_parms *p) +{ +bitmap_fill (p->data_state,NEIGH_VAR_DATA_MAX ); +} + +static inline void neigh_parms_data_state_cleanall (struct neigh_parms *p) +{ +bitmap_zero (p->data_state,NEIGH_VAR_DATA_MAX ); +} +struct neigh_statistics {unsigned long allocs;/* number of allocated neighs */ unsigned long destroys;/* number of destroyed neighs */
net/core/neighbour.c +68 -6
136 lines not on this page · raw message
net/ipv4/devinet.c +2 -0
@@ -500,6 +500,7 @@ static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa)return -ENOBUFS ; }ipv4_devconf_setall (in_dev); +neigh_parms_data_state_setall (in_dev->arp_parms);if (ifa->ifa_dev != in_dev) {WARN_ON (ifa->ifa_dev);in_dev_hold (in_dev);
@@ -747,6 +748,7 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh, goto errout;ipv4_devconf_setall (in_dev); +neigh_parms_data_state_setall (in_dev->arp_parms);in_dev_hold (in_dev);if (tb[IFA_ADDRESS ] ==NULL )
net/ipv4/ipmr.c +2 -0
@@ -425,6 +425,7 @@ struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v) goto failure;ipv4_devconf_setall (in_dev); +neigh_parms_data_state_setall (in_dev->arp_parms);IPV4_DEVCONF (in_dev->cnf,RP_FILTER ) =0 ;if (dev_open (dev))
@@ -517,6 +518,7 @@ static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt) }ipv4_devconf_setall (in_dev); +neigh_parms_data_state_setall (in_dev->arp_parms);IPV4_DEVCONF (in_dev->cnf,RP_FILTER ) =0 ;rcu_read_unlock ();
Signature · 1 line
1.8.3.1
Re: [patch net-next v2 4/5] neigh: restore old behaviour of default parms values
Quoted 132 lines · Jiri Pirko
Previously inet devices were only constructed when addresses are added. Therefore the default neigh parms values they get are the ones at the time of these operations.
Now that we're creating inet devices earlier, this changes the behaviour of default neigh parms values in an incompatible way (see bug #8519).
This patch creates a compromise by setting the default values at the same point as before but only for those that have not been explicitly set by the user since the inet device's creation.
Introduced by:
commit8030f54499925d073a88c09f30d5d844fb1b3190Author: Herbert Xu <[email protected]> Date: Thu Feb 22 01:53:47 2007 +0900[IPV4] devinet: Register inetdev earlier.
Signed-off-by Jiri Pirko <[email protected]>--- include/linux/inetdevice.h | 7 +++++ include/net/neighbour.h | 13 ++++++++ net/core/neighbour.c | 74 ++++++++++++++++++++++++++++++++++++++++++---- net/ipv4/devinet.c | 2 ++ net/ipv4/ipmr.c | 2 ++ 5 files changed, 92 insertions(+), 6 deletions(-)include/linux/inetdevice.h +7
-0@@ -220,6 +220,13 @@ static inline struct in_device *__in_dev_get_rtnl(const struct net_device *dev)return rtnl_dereference (dev->ip_ptr); } +static inline struct neigh_parms *__in_dev_arp_parms_get_rcu (const struct net_device *dev) +{ +struct in_device *in_dev =__in_dev_get_rcu (dev); + +return in_dev ? in_dev->arp_parms :NULL ; +} +void in_dev_finish_destroy (struct in_device *idev);static inline void in_dev_put (struct in_device *idev)include/net/neighbour.h +13
-0@@ -21,6 +21,7 @@#include <linux/skbuff.h> #include <linux/rcupdate.h> #include <linux/seq_file.h> +#include <linux/bitmap.h> #include <linux/err.h> #include <linux/sysctl.h> @@ -81,16 +82,28 @@ struct neigh_parms {int reachable_time;int data[NEIGH_VAR_DATA_MAX ]; +DECLARE_BITMAP (data_state,NEIGH_VAR_DATA_MAX ); };static inline void neigh_var_set (struct neigh_parms *p,int index,int val) { +set_bit (index, p->data_state); p->data[index] = val; }#define NEIGH_VAR (p, attr) ((p)->data[NEIGH_VAR_ ## attr])#define NEIGH_VAR_SET (p, attr, val) neigh_var_set(p, NEIGH_VAR_ ## attr, val) +static inline void neigh_parms_data_state_setall (struct neigh_parms *p) +{ +bitmap_fill (p->data_state,NEIGH_VAR_DATA_MAX ); +} + +static inline void neigh_parms_data_state_cleanall (struct neigh_parms *p) +{ +bitmap_zero (p->data_state,NEIGH_VAR_DATA_MAX ); +} +struct neigh_statistics {unsigned long allocs;/* number of allocated neighs */ unsigned long destroys;/* number of destroyed neighs */ net/core/neighbour.c +23
-0@@ -38,6 +38,7 @@#include <linux/random.h> #include <linux/string.h> #include <linux/log2.h> +#include <linux/inetdevice.h> #define DEBUG #define NEIGH_DEBUG 1@@ -1464,6 +1465,8 @@ struct neigh_parms *neigh_parms_alloc(struct net_device *dev, p->next = tbl->parms.next; tbl->parms.next = p;write_unlock_bh (&tbl->lock); + +neigh_parms_data_state_cleanall (p); }return p; }@@ -2813,22 +2816,68 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,return ret; } +static struct neigh_parms *neigh_get_dev_parms_rcu (struct net_device *dev, +int family) +{ +if (family ==AF_INET ) +return __in_dev_arp_parms_get_rcu (dev); +return NULL ; +} + +static void neigh_copy_dflt_parms (struct net *net,struct neigh_parms *p, +int index) +{ +struct net_device *dev; +int family =neigh_parms_family (p); + +rcu_read_lock (); +for_each_netdev_rcu (net, dev) { +struct neigh_parms *dst_p = +neigh_get_dev_parms_rcu (dev, family); + +if (dst_p && !test_bit (index, dst_p->data_state))
net/core/neighbour.c static int proc_unres_qlen(struct ctl_table *ctl, int write, · line 2848
Quoted 10 lines
net/core/neighbour.c +10
-0+ dst_p->data[index] = p->data[index]; + } +rcu_read_unlock (); +} + +static void neigh_proc_update (struct ctl_table *ctl,int write) +{ +struct net_device *dev = ctl->extra1; +struct neigh_parms *p = ctl->extra2; +struct net *net = p->net;
Jiri, net-next build fails as of this line, if one doesn't have CONFIG_NET_NS on their .config
net/core/neighbour.c: In function neigh_proc_update:net/core/neighbour.c:2853: error: struct neigh_parms has no member named net
can you please fix?
Or.
Quoted 139 lines
net/core/neighbour.c +35
-6+int index = (int *) ctl->data - p->data; + +if (!write) +return ; + +set_bit (index, p->data_state); +if (!dev)/* NULL dev means this is default value */ +neigh_copy_dflt_parms (net, p, index); +} +static int neigh_proc_dointvec_zero_intmax (struct ctl_table *ctl,int write,void __user *buffer,size_t *lenp,loff_t *ppos) {struct ctl_table tmp = *ctl; +int ret; tmp.extra1 = &zero; tmp.extra2 = &int_max; -return proc_dointvec_minmax (&tmp, write, buffer, lenp, ppos); + ret =proc_dointvec_minmax (&tmp, write, buffer, lenp, ppos); +neigh_proc_update (ctl, write); +return ret; }int neigh_proc_dointvec (struct ctl_table *ctl,int write,void __user *buffer,size_t *lenp,loff_t *ppos) { -return proc_dointvec (ctl, write, buffer, lenp, ppos); +int ret =proc_dointvec (ctl, write, buffer, lenp, ppos); + +neigh_proc_update (ctl, write); +return ret; }EXPORT_SYMBOL (neigh_proc_dointvec);@@ -2836,7 +2885,10 @@ int neigh_proc_dointvec_jiffies(struct ctl_table *ctl, int write,void __user *buffer, size_t *lenp, loff_t *ppos) { - return proc_dointvec_jiffies(ctl, write, buffer, lenp, ppos); + int ret = proc_dointvec_jiffies(ctl, write, buffer, lenp, ppos); + +neigh_proc_update (ctl, write); +return ret; }EXPORT_SYMBOL (neigh_proc_dointvec_jiffies);@@ -2844,14 +2896,20 @@ static int neigh_proc_dointvec_userhz_jiffies(struct ctl_table *ctl, int write,void __user *buffer, size_t *lenp, loff_t *ppos) { - return proc_dointvec_userhz_jiffies(ctl, write, buffer, lenp, ppos); + int ret = proc_dointvec_userhz_jiffies(ctl, write, buffer, lenp, ppos); + +neigh_proc_update (ctl, write); +return ret; }int neigh_proc_dointvec_ms_jiffies (struct ctl_table *ctl,int write,void __user *buffer,size_t *lenp,loff_t *ppos) { -return proc_dointvec_ms_jiffies (ctl, write, buffer, lenp, ppos); +int ret =proc_dointvec_ms_jiffies (ctl, write, buffer, lenp, ppos); + +neigh_proc_update (ctl, write); +return ret; }EXPORT_SYMBOL (neigh_proc_dointvec_ms_jiffies);@@ -2859,7 +2917,10 @@ static int neigh_proc_dointvec_unres_qlen(struct ctl_table *ctl, int write,void __user *buffer, size_t *lenp, loff_t *ppos) { - return proc_unres_qlen(ctl, write, buffer, lenp, ppos); + int ret = proc_unres_qlen(ctl, write, buffer, lenp, ppos); + +neigh_proc_update (ctl, write); +return ret; }#define NEIGH_PARMS_DATA_OFFSET (index) \@@ -2962,6 +3023,7 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,for (i =0 ; i <ARRAY_SIZE (t->neigh_vars); i++) { t->neigh_vars[i].data += (long ) p; t->neigh_vars[i].extra1 = dev; + t->neigh_vars[i].extra2 = p; }if (dev) {net/ipv4/devinet.c +2
-0@@ -500,6 +500,7 @@ static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa)return -ENOBUFS ; }ipv4_devconf_setall (in_dev); +neigh_parms_data_state_setall (in_dev->arp_parms);if (ifa->ifa_dev != in_dev) {WARN_ON (ifa->ifa_dev);in_dev_hold (in_dev);@@ -747,6 +748,7 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh, goto errout;ipv4_devconf_setall (in_dev); +neigh_parms_data_state_setall (in_dev->arp_parms);in_dev_hold (in_dev);if (tb[IFA_ADDRESS ] ==NULL )net/ipv4/ipmr.c +2
-1@@ -425,6 +425,7 @@ struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v) goto failure;ipv4_devconf_setall (in_dev); +neigh_parms_data_state_setall (in_dev->arp_parms);IPV4_DEVCONF (in_dev->cnf,RP_FILTER ) =0 ;if (dev_open (dev))@@ -517,6 +518,7 @@ static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt) }ipv4_devconf_setall (in_dev); +neigh_parms_data_state_setall (in_dev->arp_parms);IPV4_DEVCONF (in_dev->cnf,RP_FILTER ) =0 ;rcu_read_unlock (); --1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [patch net-next v2 4/5] neigh: restore old behaviour of default parms values
Quoted 148 lines · Tue, Dec 10, 2013 at 03:09:05PM CET, [email protected] wrote:
Quoted 132 lines · Jiri Pirko
Previously inet devices were only constructed when addresses are added. Therefore the default neigh parms values they get are the ones at the time of these operations.
Now that we're creating inet devices earlier, this changes the behaviour of default neigh parms values in an incompatible way (see bug #8519).
This patch creates a compromise by setting the default values at the same point as before but only for those that have not been explicitly set by the user since the inet device's creation.
Introduced by:
commit8030f54499925d073a88c09f30d5d844fb1b3190Author: Herbert Xu <[email protected]> Date: Thu Feb 22 01:53:47 2007 +0900[IPV4] devinet: Register inetdev earlier.
Signed-off-by Jiri Pirko <[email protected]>--- include/linux/inetdevice.h | 7 +++++ include/net/neighbour.h | 13 ++++++++ net/core/neighbour.c | 74 ++++++++++++++++++++++++++++++++++++++++++---- net/ipv4/devinet.c | 2 ++ net/ipv4/ipmr.c | 2 ++ 5 files changed, 92 insertions(+), 6 deletions(-)include/linux/inetdevice.h +7
-0@@ -220,6 +220,13 @@ static inline struct in_device *__in_dev_get_rtnl(const struct net_device *dev)return rtnl_dereference (dev->ip_ptr); } +static inline struct neigh_parms *__in_dev_arp_parms_get_rcu (const struct net_device *dev) +{ +struct in_device *in_dev =__in_dev_get_rcu (dev); + +return in_dev ? in_dev->arp_parms :NULL ; +} +void in_dev_finish_destroy (struct in_device *idev);static inline void in_dev_put (struct in_device *idev)include/net/neighbour.h +13
-0@@ -21,6 +21,7 @@#include <linux/skbuff.h> #include <linux/rcupdate.h> #include <linux/seq_file.h> +#include <linux/bitmap.h> #include <linux/err.h> #include <linux/sysctl.h> @@ -81,16 +82,28 @@ struct neigh_parms {int reachable_time;int data[NEIGH_VAR_DATA_MAX ]; +DECLARE_BITMAP (data_state,NEIGH_VAR_DATA_MAX ); };static inline void neigh_var_set (struct neigh_parms *p,int index,int val) { +set_bit (index, p->data_state); p->data[index] = val; }#define NEIGH_VAR (p, attr) ((p)->data[NEIGH_VAR_ ## attr])#define NEIGH_VAR_SET (p, attr, val) neigh_var_set(p, NEIGH_VAR_ ## attr, val) +static inline void neigh_parms_data_state_setall (struct neigh_parms *p) +{ +bitmap_fill (p->data_state,NEIGH_VAR_DATA_MAX ); +} + +static inline void neigh_parms_data_state_cleanall (struct neigh_parms *p) +{ +bitmap_zero (p->data_state,NEIGH_VAR_DATA_MAX ); +} +struct neigh_statistics {unsigned long allocs;/* number of allocated neighs */ unsigned long destroys;/* number of destroyed neighs */ net/core/neighbour.c +23
-0@@ -38,6 +38,7 @@#include <linux/random.h> #include <linux/string.h> #include <linux/log2.h> +#include <linux/inetdevice.h> #define DEBUG #define NEIGH_DEBUG 1@@ -1464,6 +1465,8 @@ struct neigh_parms *neigh_parms_alloc(struct net_device *dev, p->next = tbl->parms.next; tbl->parms.next = p;write_unlock_bh (&tbl->lock); + +neigh_parms_data_state_cleanall (p); }return p; }@@ -2813,22 +2816,68 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,return ret; } +static struct neigh_parms *neigh_get_dev_parms_rcu (struct net_device *dev, +int family) +{ +if (family ==AF_INET ) +return __in_dev_arp_parms_get_rcu (dev); +return NULL ; +} + +static void neigh_copy_dflt_parms (struct net *net,struct neigh_parms *p, +int index) +{ +struct net_device *dev; +int family =neigh_parms_family (p); + +rcu_read_lock (); +for_each_netdev_rcu (net, dev) { +struct neigh_parms *dst_p = +neigh_get_dev_parms_rcu (dev, family); + +if (dst_p && !test_bit (index, dst_p->data_state))net/core/neighbour.c static int proc_unres_qlen(struct ctl_table *ctl, int write, · line 2848
Quoted 10 lines
net/core/neighbour.c +10
-0+ dst_p->data[index] = p->data[index]; + } +rcu_read_unlock (); +} + +static void neigh_proc_update (struct ctl_table *ctl,int write) +{ +struct net_device *dev = ctl->extra1; +struct neigh_parms *p = ctl->extra2; +struct net *net = p->net;Jiri, net-next build fails as of this line, if one doesn't have
CONFIG_NET_NSon their .config
Quoted 4 lines
net/core/neighbour.c: In functionneigh_proc_update:net/core/neighbour.c:2853: error: structneigh_parmshas no member named netcan you please fix?
I already sent a fix:
"[patch net-next] neighbour: always have struct net pointer in struct neigh_parms"
sorry for any inconvenience.
Quoted 145 lines
Or.
Quoted 139 lines
net/core/neighbour.c +35
-6+int index = (int *) ctl->data - p->data; + +if (!write) +return ; + +set_bit (index, p->data_state); +if (!dev)/* NULL dev means this is default value */ +neigh_copy_dflt_parms (net, p, index); +} +static int neigh_proc_dointvec_zero_intmax (struct ctl_table *ctl,int write,void __user *buffer,size_t *lenp,loff_t *ppos) {struct ctl_table tmp = *ctl; +int ret; tmp.extra1 = &zero; tmp.extra2 = &int_max; -return proc_dointvec_minmax (&tmp, write, buffer, lenp, ppos); + ret =proc_dointvec_minmax (&tmp, write, buffer, lenp, ppos); +neigh_proc_update (ctl, write); +return ret; }int neigh_proc_dointvec (struct ctl_table *ctl,int write,void __user *buffer,size_t *lenp,loff_t *ppos) { -return proc_dointvec (ctl, write, buffer, lenp, ppos); +int ret =proc_dointvec (ctl, write, buffer, lenp, ppos); + +neigh_proc_update (ctl, write); +return ret; }EXPORT_SYMBOL (neigh_proc_dointvec);@@ -2836,7 +2885,10 @@ int neigh_proc_dointvec_jiffies(struct ctl_table *ctl, int write,void __user *buffer, size_t *lenp, loff_t *ppos) { - return proc_dointvec_jiffies(ctl, write, buffer, lenp, ppos); + int ret = proc_dointvec_jiffies(ctl, write, buffer, lenp, ppos); + +neigh_proc_update (ctl, write); +return ret; }EXPORT_SYMBOL (neigh_proc_dointvec_jiffies);@@ -2844,14 +2896,20 @@ static int neigh_proc_dointvec_userhz_jiffies(struct ctl_table *ctl, int write,void __user *buffer, size_t *lenp, loff_t *ppos) { - return proc_dointvec_userhz_jiffies(ctl, write, buffer, lenp, ppos); + int ret = proc_dointvec_userhz_jiffies(ctl, write, buffer, lenp, ppos); + +neigh_proc_update (ctl, write); +return ret; }int neigh_proc_dointvec_ms_jiffies (struct ctl_table *ctl,int write,void __user *buffer,size_t *lenp,loff_t *ppos) { -return proc_dointvec_ms_jiffies (ctl, write, buffer, lenp, ppos); +int ret =proc_dointvec_ms_jiffies (ctl, write, buffer, lenp, ppos); + +neigh_proc_update (ctl, write); +return ret; }EXPORT_SYMBOL (neigh_proc_dointvec_ms_jiffies);@@ -2859,7 +2917,10 @@ static int neigh_proc_dointvec_unres_qlen(struct ctl_table *ctl, int write,void __user *buffer, size_t *lenp, loff_t *ppos) { - return proc_unres_qlen(ctl, write, buffer, lenp, ppos); + int ret = proc_unres_qlen(ctl, write, buffer, lenp, ppos); + +neigh_proc_update (ctl, write); +return ret; }#define NEIGH_PARMS_DATA_OFFSET (index) \@@ -2962,6 +3023,7 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,for (i =0 ; i <ARRAY_SIZE (t->neigh_vars); i++) { t->neigh_vars[i].data += (long ) p; t->neigh_vars[i].extra1 = dev; + t->neigh_vars[i].extra2 = p; }if (dev) {net/ipv4/devinet.c +2
-0@@ -500,6 +500,7 @@ static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa)return -ENOBUFS ; }ipv4_devconf_setall (in_dev); +neigh_parms_data_state_setall (in_dev->arp_parms);if (ifa->ifa_dev != in_dev) {WARN_ON (ifa->ifa_dev);in_dev_hold (in_dev);@@ -747,6 +748,7 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh, goto errout;ipv4_devconf_setall (in_dev); +neigh_parms_data_state_setall (in_dev->arp_parms);in_dev_hold (in_dev);if (tb[IFA_ADDRESS ] ==NULL )net/ipv4/ipmr.c +2
-1@@ -425,6 +425,7 @@ struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v) goto failure;ipv4_devconf_setall (in_dev); +neigh_parms_data_state_setall (in_dev->arp_parms);IPV4_DEVCONF (in_dev->cnf,RP_FILTER ) =0 ;if (dev_open (dev))@@ -517,6 +518,7 @@ static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt) }ipv4_devconf_setall (in_dev); +neigh_parms_data_state_setall (in_dev->arp_parms);IPV4_DEVCONF (in_dev->cnf,RP_FILTER ) =0 ;rcu_read_unlock (); --1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 5/5 neigh: ipv6: respect default values set before an address is assigned to device
In reply to Jiri PirkoMake the behaviour similar to ipv4. This will allow user to set sysctl default neigh param values and these values will be respected even by devices registered before (that ones what do not have address set yet).
--- include/net/addrconf.h | 7 +++++++ net/core/neighbour.c | 7 ++++++- net/ipv6/addrconf.c | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-)
include/net/addrconf.h +7 -0
@@ -248,6 +248,13 @@ static inline struct inet6_dev *in6_dev_get(const struct net_device *dev)return idev; } +static inline struct neigh_parms *__in6_dev_nd_parms_get_rcu (const struct net_device *dev) +{ +struct inet6_dev *idev =__in6_dev_get (dev); + +return idev ? idev->nd_parms :NULL ; +} +void in6_dev_finish_destroy (struct inet6_dev *idev);static inline void in6_dev_put (struct inet6_dev *idev)
net/core/neighbour.c +6 -1
@@ -39,6 +39,7 @@#include <linux/string.h> #include <linux/log2.h> #include <linux/inetdevice.h> +#include <net/addrconf.h> #define DEBUG #define NEIGH_DEBUG 1
@@ -2819,8 +2820,12 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,static struct neigh_parms *neigh_get_dev_parms_rcu (struct net_device *dev,int family) { -if (family ==AF_INET ) +switch (family) { +case AF_INET :return __in_dev_arp_parms_get_rcu (dev); +case AF_INET6 : +return __in6_dev_nd_parms_get_rcu (dev); + }return NULL ; }
net/ipv6/addrconf.c +2 -0
@@ -834,6 +834,8 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, goto out; } +neigh_parms_data_state_setall (idev->nd_parms); + ifa->addr = *addr;if (peer_addr) ifa->peer_addr = *peer_addr;
Signature · 1 line
1.8.3.1
Quoted 17 lines · Jiri Pirko
This is a long standing regression. But since the patchset is bigger and the regression happened in 2007, I'm proposing this to net-next instead.
Basically the problem is that if user wants to use
/etc/sysctl.confto specify default values of neigh related params, he is not able to do that.The reason is that the default values are copied to dev instance right after netdev is registered. And that is way to early. The original behaviour for ipv4 was that this happened after first address was assigned to device. For ipv6 this was apparently from the very beginning.
So this patchset basically reverts the behaviour back to what it was in 2007 for ipv4 and changes the behaviour for ipv6 so they are both the same.
v1->v2:
- useneigh_parms->tbl->familyas suggested by davem
Quoted 7 lines
Jiri Pirko (5):
neigh: convert parms to an array
neigh: wrap proc dointvec functions
neigh: usetbl->familyto distinguish ipv4 from ipv6
neigh: restore old behaviour of default parms values
neigh: ipv6: respect default values set before an address is assigned
to device
I haven't studied the patches in detail but the idea certainly sounds good to me.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
David Miller
maintainerFrom: Jiri Pirko <[email protected]>
Date: Sat, 7 Dec 2013 19:26:52 +0100
Quoted 11 lines
This is a long standing regression. But since the patchset is bigger and the regression happened in 2007, I'm proposing this to net-next instead.
Basically the problem is that if user wants to use
/etc/sysctl.confto specify default values of neigh related params, he is not able to do that.The reason is that the default values are copied to dev instance right after netdev is registered. And that is way to early. The original behaviour for ipv4 was that this happened after first address was assigned to device. For ipv6 this was apparently from the very beginning.
Quoted 5 lines
So this patchset basically reverts the behaviour back to what it was in 2007 for ipv4 and changes the behaviour for ipv6 so they are both the same.
v1->v2:
- useneigh_parms->tbl->familyas suggested by davem
Series applied, thanks Jiri.