diff options
Diffstat (limited to 'net/ipv6/sit.c')
-rw-r--r-- | net/ipv6/sit.c | 270 |
1 files changed, 160 insertions, 110 deletions
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 4699cd3c3118..1cca5761aea9 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c | |||
@@ -63,36 +63,63 @@ | |||
63 | #define HASH_SIZE 16 | 63 | #define HASH_SIZE 16 |
64 | #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF) | 64 | #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF) |
65 | 65 | ||
66 | static void ipip6_tunnel_init(struct net_device *dev); | 66 | static int ipip6_tunnel_init(struct net_device *dev); |
67 | static void ipip6_tunnel_setup(struct net_device *dev); | 67 | static void ipip6_tunnel_setup(struct net_device *dev); |
68 | static void ipip6_dev_free(struct net_device *dev); | ||
68 | 69 | ||
69 | static int sit_net_id __read_mostly; | 70 | static int sit_net_id __read_mostly; |
70 | struct sit_net { | 71 | struct sit_net { |
71 | struct ip_tunnel *tunnels_r_l[HASH_SIZE]; | 72 | struct ip_tunnel __rcu *tunnels_r_l[HASH_SIZE]; |
72 | struct ip_tunnel *tunnels_r[HASH_SIZE]; | 73 | struct ip_tunnel __rcu *tunnels_r[HASH_SIZE]; |
73 | struct ip_tunnel *tunnels_l[HASH_SIZE]; | 74 | struct ip_tunnel __rcu *tunnels_l[HASH_SIZE]; |
74 | struct ip_tunnel *tunnels_wc[1]; | 75 | struct ip_tunnel __rcu *tunnels_wc[1]; |
75 | struct ip_tunnel **tunnels[4]; | 76 | struct ip_tunnel __rcu **tunnels[4]; |
76 | 77 | ||
77 | struct net_device *fb_tunnel_dev; | 78 | struct net_device *fb_tunnel_dev; |
78 | }; | 79 | }; |
79 | 80 | ||
80 | /* | 81 | /* |
81 | * Locking : hash tables are protected by RCU and a spinlock | 82 | * Locking : hash tables are protected by RCU and RTNL |
82 | */ | 83 | */ |
83 | static DEFINE_SPINLOCK(ipip6_lock); | ||
84 | 84 | ||
85 | #define for_each_ip_tunnel_rcu(start) \ | 85 | #define for_each_ip_tunnel_rcu(start) \ |
86 | for (t = rcu_dereference(start); t; t = rcu_dereference(t->next)) | 86 | for (t = rcu_dereference(start); t; t = rcu_dereference(t->next)) |
87 | 87 | ||
88 | /* often modified stats are per cpu, other are shared (netdev->stats) */ | ||
89 | struct pcpu_tstats { | ||
90 | unsigned long rx_packets; | ||
91 | unsigned long rx_bytes; | ||
92 | unsigned long tx_packets; | ||
93 | unsigned long tx_bytes; | ||
94 | }; | ||
95 | |||
96 | static struct net_device_stats *ipip6_get_stats(struct net_device *dev) | ||
97 | { | ||
98 | struct pcpu_tstats sum = { 0 }; | ||
99 | int i; | ||
100 | |||
101 | for_each_possible_cpu(i) { | ||
102 | const struct pcpu_tstats *tstats = per_cpu_ptr(dev->tstats, i); | ||
103 | |||
104 | sum.rx_packets += tstats->rx_packets; | ||
105 | sum.rx_bytes += tstats->rx_bytes; | ||
106 | sum.tx_packets += tstats->tx_packets; | ||
107 | sum.tx_bytes += tstats->tx_bytes; | ||
108 | } | ||
109 | dev->stats.rx_packets = sum.rx_packets; | ||
110 | dev->stats.rx_bytes = sum.rx_bytes; | ||
111 | dev->stats.tx_packets = sum.tx_packets; | ||
112 | dev->stats.tx_bytes = sum.tx_bytes; | ||
113 | return &dev->stats; | ||
114 | } | ||
88 | /* | 115 | /* |
89 | * Must be invoked with rcu_read_lock | 116 | * Must be invoked with rcu_read_lock |
90 | */ | 117 | */ |
91 | static struct ip_tunnel * ipip6_tunnel_lookup(struct net *net, | 118 | static struct ip_tunnel * ipip6_tunnel_lookup(struct net *net, |
92 | struct net_device *dev, __be32 remote, __be32 local) | 119 | struct net_device *dev, __be32 remote, __be32 local) |
93 | { | 120 | { |
94 | unsigned h0 = HASH(remote); | 121 | unsigned int h0 = HASH(remote); |
95 | unsigned h1 = HASH(local); | 122 | unsigned int h1 = HASH(local); |
96 | struct ip_tunnel *t; | 123 | struct ip_tunnel *t; |
97 | struct sit_net *sitn = net_generic(net, sit_net_id); | 124 | struct sit_net *sitn = net_generic(net, sit_net_id); |
98 | 125 | ||
@@ -121,12 +148,12 @@ static struct ip_tunnel * ipip6_tunnel_lookup(struct net *net, | |||
121 | return NULL; | 148 | return NULL; |
122 | } | 149 | } |
123 | 150 | ||
124 | static struct ip_tunnel **__ipip6_bucket(struct sit_net *sitn, | 151 | static struct ip_tunnel __rcu **__ipip6_bucket(struct sit_net *sitn, |
125 | struct ip_tunnel_parm *parms) | 152 | struct ip_tunnel_parm *parms) |
126 | { | 153 | { |
127 | __be32 remote = parms->iph.daddr; | 154 | __be32 remote = parms->iph.daddr; |
128 | __be32 local = parms->iph.saddr; | 155 | __be32 local = parms->iph.saddr; |
129 | unsigned h = 0; | 156 | unsigned int h = 0; |
130 | int prio = 0; | 157 | int prio = 0; |
131 | 158 | ||
132 | if (remote) { | 159 | if (remote) { |
@@ -140,7 +167,7 @@ static struct ip_tunnel **__ipip6_bucket(struct sit_net *sitn, | |||
140 | return &sitn->tunnels[prio][h]; | 167 | return &sitn->tunnels[prio][h]; |
141 | } | 168 | } |
142 | 169 | ||
143 | static inline struct ip_tunnel **ipip6_bucket(struct sit_net *sitn, | 170 | static inline struct ip_tunnel __rcu **ipip6_bucket(struct sit_net *sitn, |
144 | struct ip_tunnel *t) | 171 | struct ip_tunnel *t) |
145 | { | 172 | { |
146 | return __ipip6_bucket(sitn, &t->parms); | 173 | return __ipip6_bucket(sitn, &t->parms); |
@@ -148,13 +175,14 @@ static inline struct ip_tunnel **ipip6_bucket(struct sit_net *sitn, | |||
148 | 175 | ||
149 | static void ipip6_tunnel_unlink(struct sit_net *sitn, struct ip_tunnel *t) | 176 | static void ipip6_tunnel_unlink(struct sit_net *sitn, struct ip_tunnel *t) |
150 | { | 177 | { |
151 | struct ip_tunnel **tp; | 178 | struct ip_tunnel __rcu **tp; |
152 | 179 | struct ip_tunnel *iter; | |
153 | for (tp = ipip6_bucket(sitn, t); *tp; tp = &(*tp)->next) { | 180 | |
154 | if (t == *tp) { | 181 | for (tp = ipip6_bucket(sitn, t); |
155 | spin_lock_bh(&ipip6_lock); | 182 | (iter = rtnl_dereference(*tp)) != NULL; |
156 | *tp = t->next; | 183 | tp = &iter->next) { |
157 | spin_unlock_bh(&ipip6_lock); | 184 | if (t == iter) { |
185 | rcu_assign_pointer(*tp, t->next); | ||
158 | break; | 186 | break; |
159 | } | 187 | } |
160 | } | 188 | } |
@@ -162,12 +190,10 @@ static void ipip6_tunnel_unlink(struct sit_net *sitn, struct ip_tunnel *t) | |||
162 | 190 | ||
163 | static void ipip6_tunnel_link(struct sit_net *sitn, struct ip_tunnel *t) | 191 | static void ipip6_tunnel_link(struct sit_net *sitn, struct ip_tunnel *t) |
164 | { | 192 | { |
165 | struct ip_tunnel **tp = ipip6_bucket(sitn, t); | 193 | struct ip_tunnel __rcu **tp = ipip6_bucket(sitn, t); |
166 | 194 | ||
167 | spin_lock_bh(&ipip6_lock); | 195 | rcu_assign_pointer(t->next, rtnl_dereference(*tp)); |
168 | t->next = *tp; | ||
169 | rcu_assign_pointer(*tp, t); | 196 | rcu_assign_pointer(*tp, t); |
170 | spin_unlock_bh(&ipip6_lock); | ||
171 | } | 197 | } |
172 | 198 | ||
173 | static void ipip6_tunnel_clone_6rd(struct net_device *dev, struct sit_net *sitn) | 199 | static void ipip6_tunnel_clone_6rd(struct net_device *dev, struct sit_net *sitn) |
@@ -187,17 +213,20 @@ static void ipip6_tunnel_clone_6rd(struct net_device *dev, struct sit_net *sitn) | |||
187 | #endif | 213 | #endif |
188 | } | 214 | } |
189 | 215 | ||
190 | static struct ip_tunnel * ipip6_tunnel_locate(struct net *net, | 216 | static struct ip_tunnel *ipip6_tunnel_locate(struct net *net, |
191 | struct ip_tunnel_parm *parms, int create) | 217 | struct ip_tunnel_parm *parms, int create) |
192 | { | 218 | { |
193 | __be32 remote = parms->iph.daddr; | 219 | __be32 remote = parms->iph.daddr; |
194 | __be32 local = parms->iph.saddr; | 220 | __be32 local = parms->iph.saddr; |
195 | struct ip_tunnel *t, **tp, *nt; | 221 | struct ip_tunnel *t, *nt; |
222 | struct ip_tunnel __rcu **tp; | ||
196 | struct net_device *dev; | 223 | struct net_device *dev; |
197 | char name[IFNAMSIZ]; | 224 | char name[IFNAMSIZ]; |
198 | struct sit_net *sitn = net_generic(net, sit_net_id); | 225 | struct sit_net *sitn = net_generic(net, sit_net_id); |
199 | 226 | ||
200 | for (tp = __ipip6_bucket(sitn, parms); (t = *tp) != NULL; tp = &t->next) { | 227 | for (tp = __ipip6_bucket(sitn, parms); |
228 | (t = rtnl_dereference(*tp)) != NULL; | ||
229 | tp = &t->next) { | ||
201 | if (local == t->parms.iph.saddr && | 230 | if (local == t->parms.iph.saddr && |
202 | remote == t->parms.iph.daddr && | 231 | remote == t->parms.iph.daddr && |
203 | parms->link == t->parms.link) { | 232 | parms->link == t->parms.link) { |
@@ -213,7 +242,7 @@ static struct ip_tunnel * ipip6_tunnel_locate(struct net *net, | |||
213 | if (parms->name[0]) | 242 | if (parms->name[0]) |
214 | strlcpy(name, parms->name, IFNAMSIZ); | 243 | strlcpy(name, parms->name, IFNAMSIZ); |
215 | else | 244 | else |
216 | sprintf(name, "sit%%d"); | 245 | strcpy(name, "sit%d"); |
217 | 246 | ||
218 | dev = alloc_netdev(sizeof(*t), name, ipip6_tunnel_setup); | 247 | dev = alloc_netdev(sizeof(*t), name, ipip6_tunnel_setup); |
219 | if (dev == NULL) | 248 | if (dev == NULL) |
@@ -221,15 +250,11 @@ static struct ip_tunnel * ipip6_tunnel_locate(struct net *net, | |||
221 | 250 | ||
222 | dev_net_set(dev, net); | 251 | dev_net_set(dev, net); |
223 | 252 | ||
224 | if (strchr(name, '%')) { | ||
225 | if (dev_alloc_name(dev, name) < 0) | ||
226 | goto failed_free; | ||
227 | } | ||
228 | |||
229 | nt = netdev_priv(dev); | 253 | nt = netdev_priv(dev); |
230 | 254 | ||
231 | nt->parms = *parms; | 255 | nt->parms = *parms; |
232 | ipip6_tunnel_init(dev); | 256 | if (ipip6_tunnel_init(dev) < 0) |
257 | goto failed_free; | ||
233 | ipip6_tunnel_clone_6rd(dev, sitn); | 258 | ipip6_tunnel_clone_6rd(dev, sitn); |
234 | 259 | ||
235 | if (parms->i_flags & SIT_ISATAP) | 260 | if (parms->i_flags & SIT_ISATAP) |
@@ -244,7 +269,7 @@ static struct ip_tunnel * ipip6_tunnel_locate(struct net *net, | |||
244 | return nt; | 269 | return nt; |
245 | 270 | ||
246 | failed_free: | 271 | failed_free: |
247 | free_netdev(dev); | 272 | ipip6_dev_free(dev); |
248 | failed: | 273 | failed: |
249 | return NULL; | 274 | return NULL; |
250 | } | 275 | } |
@@ -340,7 +365,7 @@ ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg) | |||
340 | 365 | ||
341 | ASSERT_RTNL(); | 366 | ASSERT_RTNL(); |
342 | 367 | ||
343 | for (p = t->prl; p; p = p->next) { | 368 | for (p = rtnl_dereference(t->prl); p; p = rtnl_dereference(p->next)) { |
344 | if (p->addr == a->addr) { | 369 | if (p->addr == a->addr) { |
345 | if (chg) { | 370 | if (chg) { |
346 | p->flags = a->flags; | 371 | p->flags = a->flags; |
@@ -371,18 +396,13 @@ out: | |||
371 | return err; | 396 | return err; |
372 | } | 397 | } |
373 | 398 | ||
374 | static void prl_entry_destroy_rcu(struct rcu_head *head) | ||
375 | { | ||
376 | kfree(container_of(head, struct ip_tunnel_prl_entry, rcu_head)); | ||
377 | } | ||
378 | |||
379 | static void prl_list_destroy_rcu(struct rcu_head *head) | 399 | static void prl_list_destroy_rcu(struct rcu_head *head) |
380 | { | 400 | { |
381 | struct ip_tunnel_prl_entry *p, *n; | 401 | struct ip_tunnel_prl_entry *p, *n; |
382 | 402 | ||
383 | p = container_of(head, struct ip_tunnel_prl_entry, rcu_head); | 403 | p = container_of(head, struct ip_tunnel_prl_entry, rcu_head); |
384 | do { | 404 | do { |
385 | n = p->next; | 405 | n = rcu_dereference_protected(p->next, 1); |
386 | kfree(p); | 406 | kfree(p); |
387 | p = n; | 407 | p = n; |
388 | } while (p); | 408 | } while (p); |
@@ -391,26 +411,28 @@ static void prl_list_destroy_rcu(struct rcu_head *head) | |||
391 | static int | 411 | static int |
392 | ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a) | 412 | ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a) |
393 | { | 413 | { |
394 | struct ip_tunnel_prl_entry *x, **p; | 414 | struct ip_tunnel_prl_entry *x; |
415 | struct ip_tunnel_prl_entry __rcu **p; | ||
395 | int err = 0; | 416 | int err = 0; |
396 | 417 | ||
397 | ASSERT_RTNL(); | 418 | ASSERT_RTNL(); |
398 | 419 | ||
399 | if (a && a->addr != htonl(INADDR_ANY)) { | 420 | if (a && a->addr != htonl(INADDR_ANY)) { |
400 | for (p = &t->prl; *p; p = &(*p)->next) { | 421 | for (p = &t->prl; |
401 | if ((*p)->addr == a->addr) { | 422 | (x = rtnl_dereference(*p)) != NULL; |
402 | x = *p; | 423 | p = &x->next) { |
424 | if (x->addr == a->addr) { | ||
403 | *p = x->next; | 425 | *p = x->next; |
404 | call_rcu(&x->rcu_head, prl_entry_destroy_rcu); | 426 | kfree_rcu(x, rcu_head); |
405 | t->prl_count--; | 427 | t->prl_count--; |
406 | goto out; | 428 | goto out; |
407 | } | 429 | } |
408 | } | 430 | } |
409 | err = -ENXIO; | 431 | err = -ENXIO; |
410 | } else { | 432 | } else { |
411 | if (t->prl) { | 433 | x = rtnl_dereference(t->prl); |
434 | if (x) { | ||
412 | t->prl_count = 0; | 435 | t->prl_count = 0; |
413 | x = t->prl; | ||
414 | call_rcu(&x->rcu_head, prl_list_destroy_rcu); | 436 | call_rcu(&x->rcu_head, prl_list_destroy_rcu); |
415 | t->prl = NULL; | 437 | t->prl = NULL; |
416 | } | 438 | } |
@@ -420,7 +442,7 @@ out: | |||
420 | } | 442 | } |
421 | 443 | ||
422 | static int | 444 | static int |
423 | isatap_chksrc(struct sk_buff *skb, struct iphdr *iph, struct ip_tunnel *t) | 445 | isatap_chksrc(struct sk_buff *skb, const struct iphdr *iph, struct ip_tunnel *t) |
424 | { | 446 | { |
425 | struct ip_tunnel_prl_entry *p; | 447 | struct ip_tunnel_prl_entry *p; |
426 | int ok = 1; | 448 | int ok = 1; |
@@ -433,7 +455,8 @@ isatap_chksrc(struct sk_buff *skb, struct iphdr *iph, struct ip_tunnel *t) | |||
433 | else | 455 | else |
434 | skb->ndisc_nodetype = NDISC_NODETYPE_NODEFAULT; | 456 | skb->ndisc_nodetype = NDISC_NODETYPE_NODEFAULT; |
435 | } else { | 457 | } else { |
436 | struct in6_addr *addr6 = &ipv6_hdr(skb)->saddr; | 458 | const struct in6_addr *addr6 = &ipv6_hdr(skb)->saddr; |
459 | |||
437 | if (ipv6_addr_is_isatap(addr6) && | 460 | if (ipv6_addr_is_isatap(addr6) && |
438 | (addr6->s6_addr32[3] == iph->saddr) && | 461 | (addr6->s6_addr32[3] == iph->saddr) && |
439 | ipv6_chk_prefix(addr6, t->dev)) | 462 | ipv6_chk_prefix(addr6, t->dev)) |
@@ -451,15 +474,12 @@ static void ipip6_tunnel_uninit(struct net_device *dev) | |||
451 | struct sit_net *sitn = net_generic(net, sit_net_id); | 474 | struct sit_net *sitn = net_generic(net, sit_net_id); |
452 | 475 | ||
453 | if (dev == sitn->fb_tunnel_dev) { | 476 | if (dev == sitn->fb_tunnel_dev) { |
454 | spin_lock_bh(&ipip6_lock); | 477 | rcu_assign_pointer(sitn->tunnels_wc[0], NULL); |
455 | sitn->tunnels_wc[0] = NULL; | ||
456 | spin_unlock_bh(&ipip6_lock); | ||
457 | dev_put(dev); | ||
458 | } else { | 478 | } else { |
459 | ipip6_tunnel_unlink(sitn, netdev_priv(dev)); | 479 | ipip6_tunnel_unlink(sitn, netdev_priv(dev)); |
460 | ipip6_tunnel_del_prl(netdev_priv(dev), NULL); | 480 | ipip6_tunnel_del_prl(netdev_priv(dev), NULL); |
461 | dev_put(dev); | ||
462 | } | 481 | } |
482 | dev_put(dev); | ||
463 | } | 483 | } |
464 | 484 | ||
465 | 485 | ||
@@ -470,7 +490,7 @@ static int ipip6_err(struct sk_buff *skb, u32 info) | |||
470 | 8 bytes of packet payload. It means, that precise relaying of | 490 | 8 bytes of packet payload. It means, that precise relaying of |
471 | ICMP in the real Internet is absolutely infeasible. | 491 | ICMP in the real Internet is absolutely infeasible. |
472 | */ | 492 | */ |
473 | struct iphdr *iph = (struct iphdr*)skb->data; | 493 | const struct iphdr *iph = (const struct iphdr *)skb->data; |
474 | const int type = icmp_hdr(skb)->type; | 494 | const int type = icmp_hdr(skb)->type; |
475 | const int code = icmp_hdr(skb)->code; | 495 | const int code = icmp_hdr(skb)->code; |
476 | struct ip_tunnel *t; | 496 | struct ip_tunnel *t; |
@@ -528,7 +548,7 @@ out: | |||
528 | return err; | 548 | return err; |
529 | } | 549 | } |
530 | 550 | ||
531 | static inline void ipip6_ecn_decapsulate(struct iphdr *iph, struct sk_buff *skb) | 551 | static inline void ipip6_ecn_decapsulate(const struct iphdr *iph, struct sk_buff *skb) |
532 | { | 552 | { |
533 | if (INET_ECN_is_ce(iph->tos)) | 553 | if (INET_ECN_is_ce(iph->tos)) |
534 | IP6_ECN_set_ce(ipv6_hdr(skb)); | 554 | IP6_ECN_set_ce(ipv6_hdr(skb)); |
@@ -536,7 +556,7 @@ static inline void ipip6_ecn_decapsulate(struct iphdr *iph, struct sk_buff *skb) | |||
536 | 556 | ||
537 | static int ipip6_rcv(struct sk_buff *skb) | 557 | static int ipip6_rcv(struct sk_buff *skb) |
538 | { | 558 | { |
539 | struct iphdr *iph; | 559 | const struct iphdr *iph; |
540 | struct ip_tunnel *tunnel; | 560 | struct ip_tunnel *tunnel; |
541 | 561 | ||
542 | if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) | 562 | if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) |
@@ -548,6 +568,8 @@ static int ipip6_rcv(struct sk_buff *skb) | |||
548 | tunnel = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev, | 568 | tunnel = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev, |
549 | iph->saddr, iph->daddr); | 569 | iph->saddr, iph->daddr); |
550 | if (tunnel != NULL) { | 570 | if (tunnel != NULL) { |
571 | struct pcpu_tstats *tstats; | ||
572 | |||
551 | secpath_reset(skb); | 573 | secpath_reset(skb); |
552 | skb->mac_header = skb->network_header; | 574 | skb->mac_header = skb->network_header; |
553 | skb_reset_network_header(skb); | 575 | skb_reset_network_header(skb); |
@@ -563,16 +585,23 @@ static int ipip6_rcv(struct sk_buff *skb) | |||
563 | return 0; | 585 | return 0; |
564 | } | 586 | } |
565 | 587 | ||
566 | skb_tunnel_rx(skb, tunnel->dev); | 588 | tstats = this_cpu_ptr(tunnel->dev->tstats); |
589 | tstats->rx_packets++; | ||
590 | tstats->rx_bytes += skb->len; | ||
591 | |||
592 | __skb_tunnel_rx(skb, tunnel->dev); | ||
567 | 593 | ||
568 | ipip6_ecn_decapsulate(iph, skb); | 594 | ipip6_ecn_decapsulate(iph, skb); |
595 | |||
569 | netif_rx(skb); | 596 | netif_rx(skb); |
597 | |||
570 | rcu_read_unlock(); | 598 | rcu_read_unlock(); |
571 | return 0; | 599 | return 0; |
572 | } | 600 | } |
573 | 601 | ||
574 | icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); | 602 | /* no tunnel matched, let upstream know, ipsec may handle it */ |
575 | rcu_read_unlock(); | 603 | rcu_read_unlock(); |
604 | return 1; | ||
576 | out: | 605 | out: |
577 | kfree_skb(skb); | 606 | kfree_skb(skb); |
578 | return 0; | 607 | return 0; |
@@ -583,14 +612,14 @@ out: | |||
583 | * comes from 6rd / 6to4 (RFC 3056) addr space. | 612 | * comes from 6rd / 6to4 (RFC 3056) addr space. |
584 | */ | 613 | */ |
585 | static inline | 614 | static inline |
586 | __be32 try_6rd(struct in6_addr *v6dst, struct ip_tunnel *tunnel) | 615 | __be32 try_6rd(const struct in6_addr *v6dst, struct ip_tunnel *tunnel) |
587 | { | 616 | { |
588 | __be32 dst = 0; | 617 | __be32 dst = 0; |
589 | 618 | ||
590 | #ifdef CONFIG_IPV6_SIT_6RD | 619 | #ifdef CONFIG_IPV6_SIT_6RD |
591 | if (ipv6_prefix_equal(v6dst, &tunnel->ip6rd.prefix, | 620 | if (ipv6_prefix_equal(v6dst, &tunnel->ip6rd.prefix, |
592 | tunnel->ip6rd.prefixlen)) { | 621 | tunnel->ip6rd.prefixlen)) { |
593 | unsigned pbw0, pbi0; | 622 | unsigned int pbw0, pbi0; |
594 | int pbi1; | 623 | int pbi1; |
595 | u32 d; | 624 | u32 d; |
596 | 625 | ||
@@ -625,19 +654,19 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, | |||
625 | struct net_device *dev) | 654 | struct net_device *dev) |
626 | { | 655 | { |
627 | struct ip_tunnel *tunnel = netdev_priv(dev); | 656 | struct ip_tunnel *tunnel = netdev_priv(dev); |
628 | struct net_device_stats *stats = &dev->stats; | 657 | struct pcpu_tstats *tstats; |
629 | struct netdev_queue *txq = netdev_get_tx_queue(dev, 0); | 658 | const struct iphdr *tiph = &tunnel->parms.iph; |
630 | struct iphdr *tiph = &tunnel->parms.iph; | 659 | const struct ipv6hdr *iph6 = ipv6_hdr(skb); |
631 | struct ipv6hdr *iph6 = ipv6_hdr(skb); | ||
632 | u8 tos = tunnel->parms.iph.tos; | 660 | u8 tos = tunnel->parms.iph.tos; |
633 | __be16 df = tiph->frag_off; | 661 | __be16 df = tiph->frag_off; |
634 | struct rtable *rt; /* Route to the other host */ | 662 | struct rtable *rt; /* Route to the other host */ |
635 | struct net_device *tdev; /* Device to other host */ | 663 | struct net_device *tdev; /* Device to other host */ |
636 | struct iphdr *iph; /* Our new IP header */ | 664 | struct iphdr *iph; /* Our new IP header */ |
637 | unsigned int max_headroom; /* The extra header space needed */ | 665 | unsigned int max_headroom; /* The extra header space needed */ |
638 | __be32 dst = tiph->daddr; | 666 | __be32 dst = tiph->daddr; |
667 | struct flowi4 fl4; | ||
639 | int mtu; | 668 | int mtu; |
640 | struct in6_addr *addr6; | 669 | const struct in6_addr *addr6; |
641 | int addr_type; | 670 | int addr_type; |
642 | 671 | ||
643 | if (skb->protocol != htons(ETH_P_IPV6)) | 672 | if (skb->protocol != htons(ETH_P_IPV6)) |
@@ -656,7 +685,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, | |||
656 | goto tx_error; | 685 | goto tx_error; |
657 | } | 686 | } |
658 | 687 | ||
659 | addr6 = (struct in6_addr*)&neigh->primary_key; | 688 | addr6 = (const struct in6_addr*)&neigh->primary_key; |
660 | addr_type = ipv6_addr_type(addr6); | 689 | addr_type = ipv6_addr_type(addr6); |
661 | 690 | ||
662 | if ((addr_type & IPV6_ADDR_UNICAST) && | 691 | if ((addr_type & IPV6_ADDR_UNICAST) && |
@@ -681,7 +710,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, | |||
681 | goto tx_error; | 710 | goto tx_error; |
682 | } | 711 | } |
683 | 712 | ||
684 | addr6 = (struct in6_addr*)&neigh->primary_key; | 713 | addr6 = (const struct in6_addr*)&neigh->primary_key; |
685 | addr_type = ipv6_addr_type(addr6); | 714 | addr_type = ipv6_addr_type(addr6); |
686 | 715 | ||
687 | if (addr_type == IPV6_ADDR_ANY) { | 716 | if (addr_type == IPV6_ADDR_ANY) { |
@@ -695,28 +724,25 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, | |||
695 | dst = addr6->s6_addr32[3]; | 724 | dst = addr6->s6_addr32[3]; |
696 | } | 725 | } |
697 | 726 | ||
698 | { | 727 | rt = ip_route_output_ports(dev_net(dev), &fl4, NULL, |
699 | struct flowi fl = { .nl_u = { .ip4_u = | 728 | dst, tiph->saddr, |
700 | { .daddr = dst, | 729 | 0, 0, |
701 | .saddr = tiph->saddr, | 730 | IPPROTO_IPV6, RT_TOS(tos), |
702 | .tos = RT_TOS(tos) } }, | 731 | tunnel->parms.link); |
703 | .oif = tunnel->parms.link, | 732 | if (IS_ERR(rt)) { |
704 | .proto = IPPROTO_IPV6 }; | 733 | dev->stats.tx_carrier_errors++; |
705 | if (ip_route_output_key(dev_net(dev), &rt, &fl)) { | 734 | goto tx_error_icmp; |
706 | stats->tx_carrier_errors++; | ||
707 | goto tx_error_icmp; | ||
708 | } | ||
709 | } | 735 | } |
710 | if (rt->rt_type != RTN_UNICAST) { | 736 | if (rt->rt_type != RTN_UNICAST) { |
711 | ip_rt_put(rt); | 737 | ip_rt_put(rt); |
712 | stats->tx_carrier_errors++; | 738 | dev->stats.tx_carrier_errors++; |
713 | goto tx_error_icmp; | 739 | goto tx_error_icmp; |
714 | } | 740 | } |
715 | tdev = rt->dst.dev; | 741 | tdev = rt->dst.dev; |
716 | 742 | ||
717 | if (tdev == dev) { | 743 | if (tdev == dev) { |
718 | ip_rt_put(rt); | 744 | ip_rt_put(rt); |
719 | stats->collisions++; | 745 | dev->stats.collisions++; |
720 | goto tx_error; | 746 | goto tx_error; |
721 | } | 747 | } |
722 | 748 | ||
@@ -724,7 +750,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, | |||
724 | mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr); | 750 | mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr); |
725 | 751 | ||
726 | if (mtu < 68) { | 752 | if (mtu < 68) { |
727 | stats->collisions++; | 753 | dev->stats.collisions++; |
728 | ip_rt_put(rt); | 754 | ip_rt_put(rt); |
729 | goto tx_error; | 755 | goto tx_error; |
730 | } | 756 | } |
@@ -763,7 +789,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, | |||
763 | struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom); | 789 | struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom); |
764 | if (!new_skb) { | 790 | if (!new_skb) { |
765 | ip_rt_put(rt); | 791 | ip_rt_put(rt); |
766 | txq->tx_dropped++; | 792 | dev->stats.tx_dropped++; |
767 | dev_kfree_skb(skb); | 793 | dev_kfree_skb(skb); |
768 | return NETDEV_TX_OK; | 794 | return NETDEV_TX_OK; |
769 | } | 795 | } |
@@ -792,21 +818,21 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, | |||
792 | iph->frag_off = df; | 818 | iph->frag_off = df; |
793 | iph->protocol = IPPROTO_IPV6; | 819 | iph->protocol = IPPROTO_IPV6; |
794 | iph->tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6)); | 820 | iph->tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6)); |
795 | iph->daddr = rt->rt_dst; | 821 | iph->daddr = fl4.daddr; |
796 | iph->saddr = rt->rt_src; | 822 | iph->saddr = fl4.saddr; |
797 | 823 | ||
798 | if ((iph->ttl = tiph->ttl) == 0) | 824 | if ((iph->ttl = tiph->ttl) == 0) |
799 | iph->ttl = iph6->hop_limit; | 825 | iph->ttl = iph6->hop_limit; |
800 | 826 | ||
801 | nf_reset(skb); | 827 | nf_reset(skb); |
802 | 828 | tstats = this_cpu_ptr(dev->tstats); | |
803 | IPTUNNEL_XMIT(); | 829 | __IPTUNNEL_XMIT(tstats, &dev->stats); |
804 | return NETDEV_TX_OK; | 830 | return NETDEV_TX_OK; |
805 | 831 | ||
806 | tx_error_icmp: | 832 | tx_error_icmp: |
807 | dst_link_failure(skb); | 833 | dst_link_failure(skb); |
808 | tx_error: | 834 | tx_error: |
809 | stats->tx_errors++; | 835 | dev->stats.tx_errors++; |
810 | dev_kfree_skb(skb); | 836 | dev_kfree_skb(skb); |
811 | return NETDEV_TX_OK; | 837 | return NETDEV_TX_OK; |
812 | } | 838 | } |
@@ -815,20 +841,21 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev) | |||
815 | { | 841 | { |
816 | struct net_device *tdev = NULL; | 842 | struct net_device *tdev = NULL; |
817 | struct ip_tunnel *tunnel; | 843 | struct ip_tunnel *tunnel; |
818 | struct iphdr *iph; | 844 | const struct iphdr *iph; |
845 | struct flowi4 fl4; | ||
819 | 846 | ||
820 | tunnel = netdev_priv(dev); | 847 | tunnel = netdev_priv(dev); |
821 | iph = &tunnel->parms.iph; | 848 | iph = &tunnel->parms.iph; |
822 | 849 | ||
823 | if (iph->daddr) { | 850 | if (iph->daddr) { |
824 | struct flowi fl = { .nl_u = { .ip4_u = | 851 | struct rtable *rt = ip_route_output_ports(dev_net(dev), &fl4, NULL, |
825 | { .daddr = iph->daddr, | 852 | iph->daddr, iph->saddr, |
826 | .saddr = iph->saddr, | 853 | 0, 0, |
827 | .tos = RT_TOS(iph->tos) } }, | 854 | IPPROTO_IPV6, |
828 | .oif = tunnel->parms.link, | 855 | RT_TOS(iph->tos), |
829 | .proto = IPPROTO_IPV6 }; | 856 | tunnel->parms.link); |
830 | struct rtable *rt; | 857 | |
831 | if (!ip_route_output_key(dev_net(dev), &rt, &fl)) { | 858 | if (!IS_ERR(rt)) { |
832 | tdev = rt->dst.dev; | 859 | tdev = rt->dst.dev; |
833 | ip_rt_put(rt); | 860 | ip_rt_put(rt); |
834 | } | 861 | } |
@@ -929,6 +956,7 @@ ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd) | |||
929 | } | 956 | } |
930 | t = netdev_priv(dev); | 957 | t = netdev_priv(dev); |
931 | ipip6_tunnel_unlink(sitn, t); | 958 | ipip6_tunnel_unlink(sitn, t); |
959 | synchronize_net(); | ||
932 | t->parms.iph.saddr = p.iph.saddr; | 960 | t->parms.iph.saddr = p.iph.saddr; |
933 | t->parms.iph.daddr = p.iph.daddr; | 961 | t->parms.iph.daddr = p.iph.daddr; |
934 | memcpy(dev->dev_addr, &p.iph.saddr, 4); | 962 | memcpy(dev->dev_addr, &p.iph.saddr, 4); |
@@ -1083,12 +1111,19 @@ static const struct net_device_ops ipip6_netdev_ops = { | |||
1083 | .ndo_start_xmit = ipip6_tunnel_xmit, | 1111 | .ndo_start_xmit = ipip6_tunnel_xmit, |
1084 | .ndo_do_ioctl = ipip6_tunnel_ioctl, | 1112 | .ndo_do_ioctl = ipip6_tunnel_ioctl, |
1085 | .ndo_change_mtu = ipip6_tunnel_change_mtu, | 1113 | .ndo_change_mtu = ipip6_tunnel_change_mtu, |
1114 | .ndo_get_stats = ipip6_get_stats, | ||
1086 | }; | 1115 | }; |
1087 | 1116 | ||
1117 | static void ipip6_dev_free(struct net_device *dev) | ||
1118 | { | ||
1119 | free_percpu(dev->tstats); | ||
1120 | free_netdev(dev); | ||
1121 | } | ||
1122 | |||
1088 | static void ipip6_tunnel_setup(struct net_device *dev) | 1123 | static void ipip6_tunnel_setup(struct net_device *dev) |
1089 | { | 1124 | { |
1090 | dev->netdev_ops = &ipip6_netdev_ops; | 1125 | dev->netdev_ops = &ipip6_netdev_ops; |
1091 | dev->destructor = free_netdev; | 1126 | dev->destructor = ipip6_dev_free; |
1092 | 1127 | ||
1093 | dev->type = ARPHRD_SIT; | 1128 | dev->type = ARPHRD_SIT; |
1094 | dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr); | 1129 | dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr); |
@@ -1098,9 +1133,10 @@ static void ipip6_tunnel_setup(struct net_device *dev) | |||
1098 | dev->iflink = 0; | 1133 | dev->iflink = 0; |
1099 | dev->addr_len = 4; | 1134 | dev->addr_len = 4; |
1100 | dev->features |= NETIF_F_NETNS_LOCAL; | 1135 | dev->features |= NETIF_F_NETNS_LOCAL; |
1136 | dev->features |= NETIF_F_LLTX; | ||
1101 | } | 1137 | } |
1102 | 1138 | ||
1103 | static void ipip6_tunnel_init(struct net_device *dev) | 1139 | static int ipip6_tunnel_init(struct net_device *dev) |
1104 | { | 1140 | { |
1105 | struct ip_tunnel *tunnel = netdev_priv(dev); | 1141 | struct ip_tunnel *tunnel = netdev_priv(dev); |
1106 | 1142 | ||
@@ -1111,9 +1147,14 @@ static void ipip6_tunnel_init(struct net_device *dev) | |||
1111 | memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4); | 1147 | memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4); |
1112 | 1148 | ||
1113 | ipip6_tunnel_bind_dev(dev); | 1149 | ipip6_tunnel_bind_dev(dev); |
1150 | dev->tstats = alloc_percpu(struct pcpu_tstats); | ||
1151 | if (!dev->tstats) | ||
1152 | return -ENOMEM; | ||
1153 | |||
1154 | return 0; | ||
1114 | } | 1155 | } |
1115 | 1156 | ||
1116 | static void __net_init ipip6_fb_tunnel_init(struct net_device *dev) | 1157 | static int __net_init ipip6_fb_tunnel_init(struct net_device *dev) |
1117 | { | 1158 | { |
1118 | struct ip_tunnel *tunnel = netdev_priv(dev); | 1159 | struct ip_tunnel *tunnel = netdev_priv(dev); |
1119 | struct iphdr *iph = &tunnel->parms.iph; | 1160 | struct iphdr *iph = &tunnel->parms.iph; |
@@ -1128,11 +1169,15 @@ static void __net_init ipip6_fb_tunnel_init(struct net_device *dev) | |||
1128 | iph->ihl = 5; | 1169 | iph->ihl = 5; |
1129 | iph->ttl = 64; | 1170 | iph->ttl = 64; |
1130 | 1171 | ||
1172 | dev->tstats = alloc_percpu(struct pcpu_tstats); | ||
1173 | if (!dev->tstats) | ||
1174 | return -ENOMEM; | ||
1131 | dev_hold(dev); | 1175 | dev_hold(dev); |
1132 | sitn->tunnels_wc[0] = tunnel; | 1176 | rcu_assign_pointer(sitn->tunnels_wc[0], tunnel); |
1177 | return 0; | ||
1133 | } | 1178 | } |
1134 | 1179 | ||
1135 | static struct xfrm_tunnel sit_handler = { | 1180 | static struct xfrm_tunnel sit_handler __read_mostly = { |
1136 | .handler = ipip6_rcv, | 1181 | .handler = ipip6_rcv, |
1137 | .err_handler = ipip6_err, | 1182 | .err_handler = ipip6_err, |
1138 | .priority = 1, | 1183 | .priority = 1, |
@@ -1145,11 +1190,12 @@ static void __net_exit sit_destroy_tunnels(struct sit_net *sitn, struct list_hea | |||
1145 | for (prio = 1; prio < 4; prio++) { | 1190 | for (prio = 1; prio < 4; prio++) { |
1146 | int h; | 1191 | int h; |
1147 | for (h = 0; h < HASH_SIZE; h++) { | 1192 | for (h = 0; h < HASH_SIZE; h++) { |
1148 | struct ip_tunnel *t = sitn->tunnels[prio][h]; | 1193 | struct ip_tunnel *t; |
1149 | 1194 | ||
1195 | t = rtnl_dereference(sitn->tunnels[prio][h]); | ||
1150 | while (t != NULL) { | 1196 | while (t != NULL) { |
1151 | unregister_netdevice_queue(t->dev, head); | 1197 | unregister_netdevice_queue(t->dev, head); |
1152 | t = t->next; | 1198 | t = rtnl_dereference(t->next); |
1153 | } | 1199 | } |
1154 | } | 1200 | } |
1155 | } | 1201 | } |
@@ -1173,7 +1219,10 @@ static int __net_init sit_init_net(struct net *net) | |||
1173 | } | 1219 | } |
1174 | dev_net_set(sitn->fb_tunnel_dev, net); | 1220 | dev_net_set(sitn->fb_tunnel_dev, net); |
1175 | 1221 | ||
1176 | ipip6_fb_tunnel_init(sitn->fb_tunnel_dev); | 1222 | err = ipip6_fb_tunnel_init(sitn->fb_tunnel_dev); |
1223 | if (err) | ||
1224 | goto err_dev_free; | ||
1225 | |||
1177 | ipip6_tunnel_clone_6rd(sitn->fb_tunnel_dev, sitn); | 1226 | ipip6_tunnel_clone_6rd(sitn->fb_tunnel_dev, sitn); |
1178 | 1227 | ||
1179 | if ((err = register_netdev(sitn->fb_tunnel_dev))) | 1228 | if ((err = register_netdev(sitn->fb_tunnel_dev))) |
@@ -1183,7 +1232,8 @@ static int __net_init sit_init_net(struct net *net) | |||
1183 | 1232 | ||
1184 | err_reg_dev: | 1233 | err_reg_dev: |
1185 | dev_put(sitn->fb_tunnel_dev); | 1234 | dev_put(sitn->fb_tunnel_dev); |
1186 | free_netdev(sitn->fb_tunnel_dev); | 1235 | err_dev_free: |
1236 | ipip6_dev_free(sitn->fb_tunnel_dev); | ||
1187 | err_alloc_dev: | 1237 | err_alloc_dev: |
1188 | return err; | 1238 | return err; |
1189 | } | 1239 | } |
@@ -1235,4 +1285,4 @@ static int __init sit_init(void) | |||
1235 | module_init(sit_init); | 1285 | module_init(sit_init); |
1236 | module_exit(sit_cleanup); | 1286 | module_exit(sit_cleanup); |
1237 | MODULE_LICENSE("GPL"); | 1287 | MODULE_LICENSE("GPL"); |
1238 | MODULE_ALIAS("sit0"); | 1288 | MODULE_ALIAS_NETDEV("sit0"); |