aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKirill Tkhai <ktkhai@virtuozzo.com>2018-03-22 05:45:32 -0400
committerDavid S. Miller <davem@davemloft.net>2018-03-22 15:12:56 -0400
commit5796ef75ec7b6019eac88f66751d663d537a5cd3 (patch)
tree227c356176272dcbfb2ed06586043863bff2a3a9
parent128aaa98ad1422eacc4c74879840cb3e579cd934 (diff)
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>
-rw-r--r--include/net/ip.h13
-rw-r--r--include/net/netns/ipv4.h1
-rw-r--r--net/ipv4/ip_input.c5
-rw-r--r--net/ipv4/ip_sockglue.c15
4 files changed, 16 insertions, 18 deletions
diff --git a/include/net/ip.h b/include/net/ip.h
index fe63ba95d12b..d53b5a9eae34 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -91,6 +91,17 @@ static inline int inet_sdif(struct sk_buff *skb)
91 return 0; 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
94struct ip_ra_chain { 105struct ip_ra_chain {
95 struct ip_ra_chain __rcu *next; 106 struct ip_ra_chain __rcu *next;
96 struct sock *sk; 107 struct sock *sk;
@@ -101,8 +112,6 @@ struct ip_ra_chain {
101 struct rcu_head rcu; 112 struct rcu_head rcu;
102}; 113};
103 114
104extern struct ip_ra_chain __rcu *ip_ra_chain;
105
106/* IP flags. */ 115/* IP flags. */
107#define IP_CE 0x8000 /* Flag: "Congestion" */ 116#define IP_CE 0x8000 /* Flag: "Congestion" */
108#define IP_DF 0x4000 /* Flag: "Don't Fragment" */ 117#define IP_DF 0x4000 /* Flag: "Don't Fragment" */
diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index 382bfd7583cf..97d7ee6667c7 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -49,6 +49,7 @@ struct netns_ipv4 {
49#endif 49#endif
50 struct ipv4_devconf *devconf_all; 50 struct ipv4_devconf *devconf_all;
51 struct ipv4_devconf *devconf_dflt; 51 struct ipv4_devconf *devconf_dflt;
52 struct ip_ra_chain __rcu *ra_chain;
52#ifdef CONFIG_IP_MULTIPLE_TABLES 53#ifdef CONFIG_IP_MULTIPLE_TABLES
53 struct fib_rules_ops *rules_ops; 54 struct fib_rules_ops *rules_ops;
54 bool fib_has_custom_rules; 55 bool fib_has_custom_rules;
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index 57fc13c6ab2b..7582713dd18f 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -159,7 +159,7 @@ bool ip_call_ra_chain(struct sk_buff *skb)
159 struct net_device *dev = skb->dev; 159 struct net_device *dev = skb->dev;
160 struct net *net = dev_net(dev); 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 struct sock *sk = ra->sk; 163 struct sock *sk = ra->sk;
164 164
165 /* If socket is bound to an interface, only report 165 /* If socket is bound to an interface, only report
@@ -167,8 +167,7 @@ bool ip_call_ra_chain(struct sk_buff *skb)
167 */ 167 */
168 if (sk && inet_sk(sk)->inet_num == protocol && 168 if (sk && inet_sk(sk)->inet_num == protocol &&
169 (!sk->sk_bound_dev_if || 169 (!sk->sk_bound_dev_if ||
170 sk->sk_bound_dev_if == dev->ifindex) && 170 sk->sk_bound_dev_if == dev->ifindex)) {
171 net_eq(sock_net(sk), net)) {
172 if (ip_is_fragment(ip_hdr(skb))) { 171 if (ip_is_fragment(ip_hdr(skb))) {
173 if (ip_defrag(net, skb, IP_DEFRAG_CALL_RA_CHAIN)) 172 if (ip_defrag(net, skb, IP_DEFRAG_CALL_RA_CHAIN))
174 return true; 173 return true;
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index bf5f44b27b7e..f36d35fe924b 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -322,18 +322,6 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc,
322 return 0; 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 */
336struct ip_ra_chain __rcu *ip_ra_chain;
337static DEFINE_SPINLOCK(ip_ra_lock); 325static DEFINE_SPINLOCK(ip_ra_lock);
338 326
339 327
@@ -350,6 +338,7 @@ int ip_ra_control(struct sock *sk, unsigned char on,
350{ 338{
351 struct ip_ra_chain *ra, *new_ra; 339 struct ip_ra_chain *ra, *new_ra;
352 struct ip_ra_chain __rcu **rap; 340 struct ip_ra_chain __rcu **rap;
341 struct net *net = sock_net(sk);
353 342
354 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num == IPPROTO_RAW) 343 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num == IPPROTO_RAW)
355 return -EINVAL; 344 return -EINVAL;
@@ -357,7 +346,7 @@ int ip_ra_control(struct sock *sk, unsigned char on,
357 new_ra = on ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL; 346 new_ra = on ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
358 347
359 spin_lock_bh(&ip_ra_lock); 348 spin_lock_bh(&ip_ra_lock);
360 for (rap = &ip_ra_chain; 349 for (rap = &net->ipv4.ra_chain;
361 (ra = rcu_dereference_protected(*rap, 350 (ra = rcu_dereference_protected(*rap,
362 lockdep_is_held(&ip_ra_lock))) != NULL; 351 lockdep_is_held(&ip_ra_lock))) != NULL;
363 rap = &ra->next) { 352 rap = &ra->next) {