Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: Make ip_ra_chain per struct net

This is optimization, which makes ip_call_ra_chain()
iterate less sockets to find the sockets it's looking for.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Kirill Tkhai and committed by
David S. Miller
5796ef75 128aaa98

+16 -18
+11 -2
include/net/ip.h
··· 91 91 return 0; 92 92 } 93 93 94 + /* Special input handler for packets caught by router alert option. 95 + They are selected only by protocol field, and then processed likely 96 + local ones; but only if someone wants them! Otherwise, router 97 + not running rsvpd will kill RSVP. 98 + 99 + It is user level problem, what it will make with them. 100 + I have no idea, how it will masquearde or NAT them (it is joke, joke :-)), 101 + but receiver should be enough clever f.e. to forward mtrace requests, 102 + sent to multicast group to reach destination designated router. 103 + */ 104 + 94 105 struct ip_ra_chain { 95 106 struct ip_ra_chain __rcu *next; 96 107 struct sock *sk; ··· 111 100 }; 112 101 struct rcu_head rcu; 113 102 }; 114 - 115 - extern struct ip_ra_chain __rcu *ip_ra_chain; 116 103 117 104 /* IP flags. */ 118 105 #define IP_CE 0x8000 /* Flag: "Congestion" */
+1
include/net/netns/ipv4.h
··· 49 49 #endif 50 50 struct ipv4_devconf *devconf_all; 51 51 struct ipv4_devconf *devconf_dflt; 52 + struct ip_ra_chain __rcu *ra_chain; 52 53 #ifdef CONFIG_IP_MULTIPLE_TABLES 53 54 struct fib_rules_ops *rules_ops; 54 55 bool fib_has_custom_rules;
+2 -3
net/ipv4/ip_input.c
··· 159 159 struct net_device *dev = skb->dev; 160 160 struct net *net = dev_net(dev); 161 161 162 - for (ra = rcu_dereference(ip_ra_chain); ra; ra = rcu_dereference(ra->next)) { 162 + for (ra = rcu_dereference(net->ipv4.ra_chain); ra; ra = rcu_dereference(ra->next)) { 163 163 struct sock *sk = ra->sk; 164 164 165 165 /* If socket is bound to an interface, only report ··· 167 167 */ 168 168 if (sk && inet_sk(sk)->inet_num == protocol && 169 169 (!sk->sk_bound_dev_if || 170 - sk->sk_bound_dev_if == dev->ifindex) && 171 - net_eq(sock_net(sk), net)) { 170 + sk->sk_bound_dev_if == dev->ifindex)) { 172 171 if (ip_is_fragment(ip_hdr(skb))) { 173 172 if (ip_defrag(net, skb, IP_DEFRAG_CALL_RA_CHAIN)) 174 173 return true;
+2 -13
net/ipv4/ip_sockglue.c
··· 322 322 return 0; 323 323 } 324 324 325 - 326 - /* Special input handler for packets caught by router alert option. 327 - They are selected only by protocol field, and then processed likely 328 - local ones; but only if someone wants them! Otherwise, router 329 - not running rsvpd will kill RSVP. 330 - 331 - It is user level problem, what it will make with them. 332 - I have no idea, how it will masquearde or NAT them (it is joke, joke :-)), 333 - but receiver should be enough clever f.e. to forward mtrace requests, 334 - sent to multicast group to reach destination designated router. 335 - */ 336 - struct ip_ra_chain __rcu *ip_ra_chain; 337 325 static DEFINE_SPINLOCK(ip_ra_lock); 338 326 339 327 ··· 338 350 { 339 351 struct ip_ra_chain *ra, *new_ra; 340 352 struct ip_ra_chain __rcu **rap; 353 + struct net *net = sock_net(sk); 341 354 342 355 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num == IPPROTO_RAW) 343 356 return -EINVAL; ··· 346 357 new_ra = on ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL; 347 358 348 359 spin_lock_bh(&ip_ra_lock); 349 - for (rap = &ip_ra_chain; 360 + for (rap = &net->ipv4.ra_chain; 350 361 (ra = rcu_dereference_protected(*rap, 351 362 lockdep_is_held(&ip_ra_lock))) != NULL; 352 363 rap = &ra->next) {