diff options
Diffstat (limited to 'net/ipv6')
| -rw-r--r-- | net/ipv6/addrconf.c | 25 | ||||
| -rw-r--r-- | net/ipv6/ip6_input.c | 2 | ||||
| -rw-r--r-- | net/ipv6/ip6_output.c | 4 | ||||
| -rw-r--r-- | net/ipv6/ip6_tunnel.c | 3 | ||||
| -rw-r--r-- | net/ipv6/ipcomp6.c | 3 | ||||
| -rw-r--r-- | net/ipv6/ipv6_sockglue.c | 89 | ||||
| -rw-r--r-- | net/ipv6/raw.c | 1 | ||||
| -rw-r--r-- | net/ipv6/sit.c | 1 | ||||
| -rw-r--r-- | net/ipv6/tcp_ipv6.c | 19 | ||||
| -rw-r--r-- | net/ipv6/xfrm6_output.c | 2 | ||||
| -rw-r--r-- | net/ipv6/xfrm6_tunnel.c | 140 |
11 files changed, 121 insertions, 168 deletions
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index c250d0af10d7..2316a4315a18 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c | |||
| @@ -508,6 +508,26 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp) | |||
| 508 | kfree(ifp); | 508 | kfree(ifp); |
| 509 | } | 509 | } |
| 510 | 510 | ||
| 511 | static void | ||
| 512 | ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp) | ||
| 513 | { | ||
| 514 | struct inet6_ifaddr *ifa, **ifap; | ||
| 515 | int ifp_scope = ipv6_addr_src_scope(&ifp->addr); | ||
| 516 | |||
| 517 | /* | ||
| 518 | * Each device address list is sorted in order of scope - | ||
| 519 | * global before linklocal. | ||
| 520 | */ | ||
| 521 | for (ifap = &idev->addr_list; (ifa = *ifap) != NULL; | ||
| 522 | ifap = &ifa->if_next) { | ||
| 523 | if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr)) | ||
| 524 | break; | ||
| 525 | } | ||
| 526 | |||
| 527 | ifp->if_next = *ifap; | ||
| 528 | *ifap = ifp; | ||
| 529 | } | ||
| 530 | |||
| 511 | /* On success it returns ifp with increased reference count */ | 531 | /* On success it returns ifp with increased reference count */ |
| 512 | 532 | ||
| 513 | static struct inet6_ifaddr * | 533 | static struct inet6_ifaddr * |
| @@ -573,8 +593,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen, | |||
| 573 | 593 | ||
| 574 | write_lock(&idev->lock); | 594 | write_lock(&idev->lock); |
| 575 | /* Add to inet6_dev unicast addr list. */ | 595 | /* Add to inet6_dev unicast addr list. */ |
| 576 | ifa->if_next = idev->addr_list; | 596 | ipv6_link_dev_addr(idev, ifa); |
| 577 | idev->addr_list = ifa; | ||
| 578 | 597 | ||
| 579 | #ifdef CONFIG_IPV6_PRIVACY | 598 | #ifdef CONFIG_IPV6_PRIVACY |
| 580 | if (ifa->flags&IFA_F_TEMPORARY) { | 599 | if (ifa->flags&IFA_F_TEMPORARY) { |
| @@ -987,7 +1006,7 @@ int ipv6_dev_get_saddr(struct net_device *daddr_dev, | |||
| 987 | continue; | 1006 | continue; |
| 988 | } else if (score.scope < hiscore.scope) { | 1007 | } else if (score.scope < hiscore.scope) { |
| 989 | if (score.scope < daddr_scope) | 1008 | if (score.scope < daddr_scope) |
| 990 | continue; | 1009 | break; /* addresses sorted by scope */ |
| 991 | else { | 1010 | else { |
| 992 | score.rule = 2; | 1011 | score.rule = 2; |
| 993 | goto record_it; | 1012 | goto record_it; |
diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c index df8f051c0fce..25c2a9e03895 100644 --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c | |||
| @@ -71,6 +71,8 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt | |||
| 71 | goto out; | 71 | goto out; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | memset(IP6CB(skb), 0, sizeof(struct inet6_skb_parm)); | ||
| 75 | |||
| 74 | /* | 76 | /* |
| 75 | * Store incoming device index. When the packet will | 77 | * Store incoming device index. When the packet will |
| 76 | * be queued, we cannot refer to skb->dev anymore. | 78 | * be queued, we cannot refer to skb->dev anymore. |
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 2c5b44575af0..3bc74ce78800 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c | |||
| @@ -147,7 +147,7 @@ static int ip6_output2(struct sk_buff *skb) | |||
| 147 | 147 | ||
| 148 | int ip6_output(struct sk_buff *skb) | 148 | int ip6_output(struct sk_buff *skb) |
| 149 | { | 149 | { |
| 150 | if ((skb->len > dst_mtu(skb->dst) && !skb_shinfo(skb)->gso_size) || | 150 | if ((skb->len > dst_mtu(skb->dst) && !skb_is_gso(skb)) || |
| 151 | dst_allfrag(skb->dst)) | 151 | dst_allfrag(skb->dst)) |
| 152 | return ip6_fragment(skb, ip6_output2); | 152 | return ip6_fragment(skb, ip6_output2); |
| 153 | else | 153 | else |
| @@ -229,7 +229,7 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl, | |||
| 229 | skb->priority = sk->sk_priority; | 229 | skb->priority = sk->sk_priority; |
| 230 | 230 | ||
| 231 | mtu = dst_mtu(dst); | 231 | mtu = dst_mtu(dst); |
| 232 | if ((skb->len <= mtu) || ipfragok || skb_shinfo(skb)->gso_size) { | 232 | if ((skb->len <= mtu) || ipfragok || skb_is_gso(skb)) { |
| 233 | IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS); | 233 | IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS); |
| 234 | return NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, dst->dev, | 234 | return NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, dst->dev, |
| 235 | dst_output); | 235 | dst_output); |
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index bc77c0e1a943..84d7ebdb9d21 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c | |||
| @@ -567,10 +567,9 @@ static inline struct ipv6_txoptions *create_tel(__u8 encap_limit) | |||
| 567 | 567 | ||
| 568 | int opt_len = sizeof(*opt) + 8; | 568 | int opt_len = sizeof(*opt) + 8; |
| 569 | 569 | ||
| 570 | if (!(opt = kmalloc(opt_len, GFP_ATOMIC))) { | 570 | if (!(opt = kzalloc(opt_len, GFP_ATOMIC))) { |
| 571 | return NULL; | 571 | return NULL; |
| 572 | } | 572 | } |
| 573 | memset(opt, 0, opt_len); | ||
| 574 | opt->tot_len = opt_len; | 573 | opt->tot_len = opt_len; |
| 575 | opt->dst0opt = (struct ipv6_opt_hdr *) (opt + 1); | 574 | opt->dst0opt = (struct ipv6_opt_hdr *) (opt + 1); |
| 576 | opt->opt_nflen = 8; | 575 | opt->opt_nflen = 8; |
diff --git a/net/ipv6/ipcomp6.c b/net/ipv6/ipcomp6.c index b285b0357084..7e4d1c17bfbc 100644 --- a/net/ipv6/ipcomp6.c +++ b/net/ipv6/ipcomp6.c | |||
| @@ -109,7 +109,8 @@ static int ipcomp6_input(struct xfrm_state *x, struct sk_buff *skb) | |||
| 109 | goto out_put_cpu; | 109 | goto out_put_cpu; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | skb_put(skb, dlen - plen); | 112 | skb->truesize += dlen - plen; |
| 113 | __skb_put(skb, dlen - plen); | ||
| 113 | memcpy(skb->data, scratch, dlen); | 114 | memcpy(skb->data, scratch, dlen); |
| 114 | err = ipch->nexthdr; | 115 | err = ipch->nexthdr; |
| 115 | 116 | ||
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c index 0c17dec11c8d..43327264e69c 100644 --- a/net/ipv6/ipv6_sockglue.c +++ b/net/ipv6/ipv6_sockglue.c | |||
| @@ -57,29 +57,11 @@ | |||
| 57 | 57 | ||
| 58 | DEFINE_SNMP_STAT(struct ipstats_mib, ipv6_statistics) __read_mostly; | 58 | DEFINE_SNMP_STAT(struct ipstats_mib, ipv6_statistics) __read_mostly; |
| 59 | 59 | ||
| 60 | static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features) | 60 | static struct inet6_protocol *ipv6_gso_pull_exthdrs(struct sk_buff *skb, |
| 61 | int proto) | ||
| 61 | { | 62 | { |
| 62 | struct sk_buff *segs = ERR_PTR(-EINVAL); | 63 | struct inet6_protocol *ops = NULL; |
| 63 | struct ipv6hdr *ipv6h; | ||
| 64 | struct inet6_protocol *ops; | ||
| 65 | int proto; | ||
| 66 | 64 | ||
| 67 | if (unlikely(skb_shinfo(skb)->gso_type & | ||
| 68 | ~(SKB_GSO_UDP | | ||
| 69 | SKB_GSO_DODGY | | ||
| 70 | SKB_GSO_TCP_ECN | | ||
| 71 | SKB_GSO_TCPV6 | | ||
| 72 | 0))) | ||
| 73 | goto out; | ||
| 74 | |||
| 75 | if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) | ||
| 76 | goto out; | ||
| 77 | |||
| 78 | ipv6h = skb->nh.ipv6h; | ||
| 79 | proto = ipv6h->nexthdr; | ||
| 80 | __skb_pull(skb, sizeof(*ipv6h)); | ||
| 81 | |||
| 82 | rcu_read_lock(); | ||
| 83 | for (;;) { | 65 | for (;;) { |
| 84 | struct ipv6_opt_hdr *opth; | 66 | struct ipv6_opt_hdr *opth; |
| 85 | int len; | 67 | int len; |
| @@ -88,30 +70,80 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features) | |||
| 88 | ops = rcu_dereference(inet6_protos[proto]); | 70 | ops = rcu_dereference(inet6_protos[proto]); |
| 89 | 71 | ||
| 90 | if (unlikely(!ops)) | 72 | if (unlikely(!ops)) |
| 91 | goto unlock; | 73 | break; |
| 92 | 74 | ||
| 93 | if (!(ops->flags & INET6_PROTO_GSO_EXTHDR)) | 75 | if (!(ops->flags & INET6_PROTO_GSO_EXTHDR)) |
| 94 | break; | 76 | break; |
| 95 | } | 77 | } |
| 96 | 78 | ||
| 97 | if (unlikely(!pskb_may_pull(skb, 8))) | 79 | if (unlikely(!pskb_may_pull(skb, 8))) |
| 98 | goto unlock; | 80 | break; |
| 99 | 81 | ||
| 100 | opth = (void *)skb->data; | 82 | opth = (void *)skb->data; |
| 101 | len = opth->hdrlen * 8 + 8; | 83 | len = opth->hdrlen * 8 + 8; |
| 102 | 84 | ||
| 103 | if (unlikely(!pskb_may_pull(skb, len))) | 85 | if (unlikely(!pskb_may_pull(skb, len))) |
| 104 | goto unlock; | 86 | break; |
| 105 | 87 | ||
| 106 | proto = opth->nexthdr; | 88 | proto = opth->nexthdr; |
| 107 | __skb_pull(skb, len); | 89 | __skb_pull(skb, len); |
| 108 | } | 90 | } |
| 109 | 91 | ||
| 110 | skb->h.raw = skb->data; | 92 | return ops; |
| 111 | if (likely(ops->gso_segment)) | 93 | } |
| 112 | segs = ops->gso_segment(skb, features); | 94 | |
| 95 | static int ipv6_gso_send_check(struct sk_buff *skb) | ||
| 96 | { | ||
| 97 | struct ipv6hdr *ipv6h; | ||
| 98 | struct inet6_protocol *ops; | ||
| 99 | int err = -EINVAL; | ||
| 100 | |||
| 101 | if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) | ||
| 102 | goto out; | ||
| 113 | 103 | ||
| 114 | unlock: | 104 | ipv6h = skb->nh.ipv6h; |
| 105 | __skb_pull(skb, sizeof(*ipv6h)); | ||
| 106 | err = -EPROTONOSUPPORT; | ||
| 107 | |||
| 108 | rcu_read_lock(); | ||
| 109 | ops = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr); | ||
| 110 | if (likely(ops && ops->gso_send_check)) { | ||
| 111 | skb->h.raw = skb->data; | ||
| 112 | err = ops->gso_send_check(skb); | ||
| 113 | } | ||
| 114 | rcu_read_unlock(); | ||
| 115 | |||
| 116 | out: | ||
| 117 | return err; | ||
| 118 | } | ||
| 119 | |||
| 120 | static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features) | ||
| 121 | { | ||
| 122 | struct sk_buff *segs = ERR_PTR(-EINVAL); | ||
| 123 | struct ipv6hdr *ipv6h; | ||
| 124 | struct inet6_protocol *ops; | ||
| 125 | |||
| 126 | if (unlikely(skb_shinfo(skb)->gso_type & | ||
| 127 | ~(SKB_GSO_UDP | | ||
| 128 | SKB_GSO_DODGY | | ||
| 129 | SKB_GSO_TCP_ECN | | ||
| 130 | SKB_GSO_TCPV6 | | ||
| 131 | 0))) | ||
| 132 | goto out; | ||
| 133 | |||
| 134 | if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) | ||
| 135 | goto out; | ||
| 136 | |||
| 137 | ipv6h = skb->nh.ipv6h; | ||
| 138 | __skb_pull(skb, sizeof(*ipv6h)); | ||
| 139 | segs = ERR_PTR(-EPROTONOSUPPORT); | ||
| 140 | |||
| 141 | rcu_read_lock(); | ||
| 142 | ops = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr); | ||
| 143 | if (likely(ops && ops->gso_segment)) { | ||
| 144 | skb->h.raw = skb->data; | ||
| 145 | segs = ops->gso_segment(skb, features); | ||
| 146 | } | ||
| 115 | rcu_read_unlock(); | 147 | rcu_read_unlock(); |
| 116 | 148 | ||
| 117 | if (unlikely(IS_ERR(segs))) | 149 | if (unlikely(IS_ERR(segs))) |
| @@ -130,6 +162,7 @@ out: | |||
| 130 | static struct packet_type ipv6_packet_type = { | 162 | static struct packet_type ipv6_packet_type = { |
| 131 | .type = __constant_htons(ETH_P_IPV6), | 163 | .type = __constant_htons(ETH_P_IPV6), |
| 132 | .func = ipv6_rcv, | 164 | .func = ipv6_rcv, |
| 165 | .gso_send_check = ipv6_gso_send_check, | ||
| 133 | .gso_segment = ipv6_gso_segment, | 166 | .gso_segment = ipv6_gso_segment, |
| 134 | }; | 167 | }; |
| 135 | 168 | ||
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c index fa1ce0ae123e..d57e61ce4a7d 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c | |||
| @@ -411,6 +411,7 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk, | |||
| 411 | /* Copy the address. */ | 411 | /* Copy the address. */ |
| 412 | if (sin6) { | 412 | if (sin6) { |
| 413 | sin6->sin6_family = AF_INET6; | 413 | sin6->sin6_family = AF_INET6; |
| 414 | sin6->sin6_port = 0; | ||
| 414 | ipv6_addr_copy(&sin6->sin6_addr, &skb->nh.ipv6h->saddr); | 415 | ipv6_addr_copy(&sin6->sin6_addr, &skb->nh.ipv6h->saddr); |
| 415 | sin6->sin6_flowinfo = 0; | 416 | sin6->sin6_flowinfo = 0; |
| 416 | sin6->sin6_scope_id = 0; | 417 | sin6->sin6_scope_id = 0; |
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index c56aeece2bf5..836eecd7e62b 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c | |||
| @@ -380,7 +380,6 @@ static int ipip6_rcv(struct sk_buff *skb) | |||
| 380 | secpath_reset(skb); | 380 | secpath_reset(skb); |
| 381 | skb->mac.raw = skb->nh.raw; | 381 | skb->mac.raw = skb->nh.raw; |
| 382 | skb->nh.raw = skb->data; | 382 | skb->nh.raw = skb->data; |
| 383 | memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options)); | ||
| 384 | IPCB(skb)->flags = 0; | 383 | IPCB(skb)->flags = 0; |
| 385 | skb->protocol = htons(ETH_P_IPV6); | 384 | skb->protocol = htons(ETH_P_IPV6); |
| 386 | skb->pkt_type = PACKET_HOST; | 385 | skb->pkt_type = PACKET_HOST; |
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 5bdcb9002cf7..923989d0520d 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c | |||
| @@ -552,6 +552,24 @@ static void tcp_v6_send_check(struct sock *sk, int len, struct sk_buff *skb) | |||
| 552 | } | 552 | } |
| 553 | } | 553 | } |
| 554 | 554 | ||
| 555 | static int tcp_v6_gso_send_check(struct sk_buff *skb) | ||
| 556 | { | ||
| 557 | struct ipv6hdr *ipv6h; | ||
| 558 | struct tcphdr *th; | ||
| 559 | |||
| 560 | if (!pskb_may_pull(skb, sizeof(*th))) | ||
| 561 | return -EINVAL; | ||
| 562 | |||
| 563 | ipv6h = skb->nh.ipv6h; | ||
| 564 | th = skb->h.th; | ||
| 565 | |||
| 566 | th->check = 0; | ||
| 567 | th->check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr, skb->len, | ||
| 568 | IPPROTO_TCP, 0); | ||
| 569 | skb->csum = offsetof(struct tcphdr, check); | ||
| 570 | skb->ip_summed = CHECKSUM_HW; | ||
| 571 | return 0; | ||
| 572 | } | ||
| 555 | 573 | ||
| 556 | static void tcp_v6_send_reset(struct sk_buff *skb) | 574 | static void tcp_v6_send_reset(struct sk_buff *skb) |
| 557 | { | 575 | { |
| @@ -1603,6 +1621,7 @@ struct proto tcpv6_prot = { | |||
| 1603 | static struct inet6_protocol tcpv6_protocol = { | 1621 | static struct inet6_protocol tcpv6_protocol = { |
| 1604 | .handler = tcp_v6_rcv, | 1622 | .handler = tcp_v6_rcv, |
| 1605 | .err_handler = tcp_v6_err, | 1623 | .err_handler = tcp_v6_err, |
| 1624 | .gso_send_check = tcp_v6_gso_send_check, | ||
| 1606 | .gso_segment = tcp_tso_segment, | 1625 | .gso_segment = tcp_tso_segment, |
| 1607 | .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, | 1626 | .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, |
| 1608 | }; | 1627 | }; |
diff --git a/net/ipv6/xfrm6_output.c b/net/ipv6/xfrm6_output.c index 48fccb1eca08..0eea60ea9ebc 100644 --- a/net/ipv6/xfrm6_output.c +++ b/net/ipv6/xfrm6_output.c | |||
| @@ -122,7 +122,7 @@ static int xfrm6_output_finish(struct sk_buff *skb) | |||
| 122 | { | 122 | { |
| 123 | struct sk_buff *segs; | 123 | struct sk_buff *segs; |
| 124 | 124 | ||
| 125 | if (!skb_shinfo(skb)->gso_size) | 125 | if (!skb_is_gso(skb)) |
| 126 | return xfrm6_output_finish2(skb); | 126 | return xfrm6_output_finish2(skb); |
| 127 | 127 | ||
| 128 | skb->protocol = htons(ETH_P_IP); | 128 | skb->protocol = htons(ETH_P_IP); |
diff --git a/net/ipv6/xfrm6_tunnel.c b/net/ipv6/xfrm6_tunnel.c index 6b44fe8516c3..c8f9369c2a87 100644 --- a/net/ipv6/xfrm6_tunnel.c +++ b/net/ipv6/xfrm6_tunnel.c | |||
| @@ -31,27 +31,6 @@ | |||
| 31 | #include <linux/icmpv6.h> | 31 | #include <linux/icmpv6.h> |
| 32 | #include <linux/mutex.h> | 32 | #include <linux/mutex.h> |
| 33 | 33 | ||
| 34 | #ifdef CONFIG_IPV6_XFRM6_TUNNEL_DEBUG | ||
| 35 | # define X6TDEBUG 3 | ||
| 36 | #else | ||
| 37 | # define X6TDEBUG 1 | ||
| 38 | #endif | ||
| 39 | |||
| 40 | #define X6TPRINTK(fmt, args...) printk(fmt, ## args) | ||
| 41 | #define X6TNOPRINTK(fmt, args...) do { ; } while(0) | ||
| 42 | |||
| 43 | #if X6TDEBUG >= 1 | ||
| 44 | # define X6TPRINTK1 X6TPRINTK | ||
| 45 | #else | ||
| 46 | # define X6TPRINTK1 X6TNOPRINTK | ||
| 47 | #endif | ||
| 48 | |||
| 49 | #if X6TDEBUG >= 3 | ||
| 50 | # define X6TPRINTK3 X6TPRINTK | ||
| 51 | #else | ||
| 52 | # define X6TPRINTK3 X6TNOPRINTK | ||
| 53 | #endif | ||
| 54 | |||
| 55 | /* | 34 | /* |
| 56 | * xfrm_tunnel_spi things are for allocating unique id ("spi") | 35 | * xfrm_tunnel_spi things are for allocating unique id ("spi") |
| 57 | * per xfrm_address_t. | 36 | * per xfrm_address_t. |
| @@ -62,15 +41,8 @@ struct xfrm6_tunnel_spi { | |||
| 62 | xfrm_address_t addr; | 41 | xfrm_address_t addr; |
| 63 | u32 spi; | 42 | u32 spi; |
| 64 | atomic_t refcnt; | 43 | atomic_t refcnt; |
| 65 | #ifdef XFRM6_TUNNEL_SPI_MAGIC | ||
| 66 | u32 magic; | ||
| 67 | #endif | ||
| 68 | }; | 44 | }; |
| 69 | 45 | ||
| 70 | #ifdef CONFIG_IPV6_XFRM6_TUNNEL_DEBUG | ||
| 71 | # define XFRM6_TUNNEL_SPI_MAGIC 0xdeadbeef | ||
| 72 | #endif | ||
| 73 | |||
| 74 | static DEFINE_RWLOCK(xfrm6_tunnel_spi_lock); | 46 | static DEFINE_RWLOCK(xfrm6_tunnel_spi_lock); |
| 75 | 47 | ||
| 76 | static u32 xfrm6_tunnel_spi; | 48 | static u32 xfrm6_tunnel_spi; |
| @@ -86,43 +58,15 @@ static kmem_cache_t *xfrm6_tunnel_spi_kmem __read_mostly; | |||
| 86 | static struct hlist_head xfrm6_tunnel_spi_byaddr[XFRM6_TUNNEL_SPI_BYADDR_HSIZE]; | 58 | static struct hlist_head xfrm6_tunnel_spi_byaddr[XFRM6_TUNNEL_SPI_BYADDR_HSIZE]; |
| 87 | static struct hlist_head xfrm6_tunnel_spi_byspi[XFRM6_TUNNEL_SPI_BYSPI_HSIZE]; | 59 | static struct hlist_head xfrm6_tunnel_spi_byspi[XFRM6_TUNNEL_SPI_BYSPI_HSIZE]; |
| 88 | 60 | ||
| 89 | #ifdef XFRM6_TUNNEL_SPI_MAGIC | ||
| 90 | static int x6spi_check_magic(const struct xfrm6_tunnel_spi *x6spi, | ||
| 91 | const char *name) | ||
| 92 | { | ||
| 93 | if (unlikely(x6spi->magic != XFRM6_TUNNEL_SPI_MAGIC)) { | ||
| 94 | X6TPRINTK3(KERN_DEBUG "%s(): x6spi object " | ||
| 95 | "at %p has corrupted magic %08x " | ||
| 96 | "(should be %08x)\n", | ||
| 97 | name, x6spi, x6spi->magic, XFRM6_TUNNEL_SPI_MAGIC); | ||
| 98 | return -1; | ||
| 99 | } | ||
| 100 | return 0; | ||
| 101 | } | ||
| 102 | #else | ||
| 103 | static int inline x6spi_check_magic(const struct xfrm6_tunnel_spi *x6spi, | ||
| 104 | const char *name) | ||
| 105 | { | ||
| 106 | return 0; | ||
| 107 | } | ||
| 108 | #endif | ||
| 109 | |||
| 110 | #define X6SPI_CHECK_MAGIC(x6spi) x6spi_check_magic((x6spi), __FUNCTION__) | ||
| 111 | |||
| 112 | |||
| 113 | static unsigned inline xfrm6_tunnel_spi_hash_byaddr(xfrm_address_t *addr) | 61 | static unsigned inline xfrm6_tunnel_spi_hash_byaddr(xfrm_address_t *addr) |
| 114 | { | 62 | { |
| 115 | unsigned h; | 63 | unsigned h; |
| 116 | 64 | ||
| 117 | X6TPRINTK3(KERN_DEBUG "%s(addr=%p)\n", __FUNCTION__, addr); | ||
| 118 | |||
| 119 | h = addr->a6[0] ^ addr->a6[1] ^ addr->a6[2] ^ addr->a6[3]; | 65 | h = addr->a6[0] ^ addr->a6[1] ^ addr->a6[2] ^ addr->a6[3]; |
| 120 | h ^= h >> 16; | 66 | h ^= h >> 16; |
| 121 | h ^= h >> 8; | 67 | h ^= h >> 8; |
| 122 | h &= XFRM6_TUNNEL_SPI_BYADDR_HSIZE - 1; | 68 | h &= XFRM6_TUNNEL_SPI_BYADDR_HSIZE - 1; |
| 123 | 69 | ||
| 124 | X6TPRINTK3(KERN_DEBUG "%s() = %u\n", __FUNCTION__, h); | ||
| 125 | |||
| 126 | return h; | 70 | return h; |
| 127 | } | 71 | } |
| 128 | 72 | ||
| @@ -136,19 +80,13 @@ static int xfrm6_tunnel_spi_init(void) | |||
| 136 | { | 80 | { |
| 137 | int i; | 81 | int i; |
| 138 | 82 | ||
| 139 | X6TPRINTK3(KERN_DEBUG "%s()\n", __FUNCTION__); | ||
| 140 | |||
| 141 | xfrm6_tunnel_spi = 0; | 83 | xfrm6_tunnel_spi = 0; |
| 142 | xfrm6_tunnel_spi_kmem = kmem_cache_create("xfrm6_tunnel_spi", | 84 | xfrm6_tunnel_spi_kmem = kmem_cache_create("xfrm6_tunnel_spi", |
| 143 | sizeof(struct xfrm6_tunnel_spi), | 85 | sizeof(struct xfrm6_tunnel_spi), |
| 144 | 0, SLAB_HWCACHE_ALIGN, | 86 | 0, SLAB_HWCACHE_ALIGN, |
| 145 | NULL, NULL); | 87 | NULL, NULL); |
| 146 | if (!xfrm6_tunnel_spi_kmem) { | 88 | if (!xfrm6_tunnel_spi_kmem) |
| 147 | X6TPRINTK1(KERN_ERR | ||
| 148 | "%s(): failed to allocate xfrm6_tunnel_spi_kmem\n", | ||
| 149 | __FUNCTION__); | ||
| 150 | return -ENOMEM; | 89 | return -ENOMEM; |
| 151 | } | ||
| 152 | 90 | ||
| 153 | for (i = 0; i < XFRM6_TUNNEL_SPI_BYADDR_HSIZE; i++) | 91 | for (i = 0; i < XFRM6_TUNNEL_SPI_BYADDR_HSIZE; i++) |
| 154 | INIT_HLIST_HEAD(&xfrm6_tunnel_spi_byaddr[i]); | 92 | INIT_HLIST_HEAD(&xfrm6_tunnel_spi_byaddr[i]); |
| @@ -161,22 +99,16 @@ static void xfrm6_tunnel_spi_fini(void) | |||
| 161 | { | 99 | { |
| 162 | int i; | 100 | int i; |
| 163 | 101 | ||
| 164 | X6TPRINTK3(KERN_DEBUG "%s()\n", __FUNCTION__); | ||
| 165 | |||
| 166 | for (i = 0; i < XFRM6_TUNNEL_SPI_BYADDR_HSIZE; i++) { | 102 | for (i = 0; i < XFRM6_TUNNEL_SPI_BYADDR_HSIZE; i++) { |
| 167 | if (!hlist_empty(&xfrm6_tunnel_spi_byaddr[i])) | 103 | if (!hlist_empty(&xfrm6_tunnel_spi_byaddr[i])) |
| 168 | goto err; | 104 | return; |
| 169 | } | 105 | } |
| 170 | for (i = 0; i < XFRM6_TUNNEL_SPI_BYSPI_HSIZE; i++) { | 106 | for (i = 0; i < XFRM6_TUNNEL_SPI_BYSPI_HSIZE; i++) { |
| 171 | if (!hlist_empty(&xfrm6_tunnel_spi_byspi[i])) | 107 | if (!hlist_empty(&xfrm6_tunnel_spi_byspi[i])) |
| 172 | goto err; | 108 | return; |
| 173 | } | 109 | } |
| 174 | kmem_cache_destroy(xfrm6_tunnel_spi_kmem); | 110 | kmem_cache_destroy(xfrm6_tunnel_spi_kmem); |
| 175 | xfrm6_tunnel_spi_kmem = NULL; | 111 | xfrm6_tunnel_spi_kmem = NULL; |
| 176 | return; | ||
| 177 | err: | ||
| 178 | X6TPRINTK1(KERN_ERR "%s(): table is not empty\n", __FUNCTION__); | ||
| 179 | return; | ||
| 180 | } | 112 | } |
| 181 | 113 | ||
| 182 | static struct xfrm6_tunnel_spi *__xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr) | 114 | static struct xfrm6_tunnel_spi *__xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr) |
| @@ -184,19 +116,13 @@ static struct xfrm6_tunnel_spi *__xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr) | |||
| 184 | struct xfrm6_tunnel_spi *x6spi; | 116 | struct xfrm6_tunnel_spi *x6spi; |
| 185 | struct hlist_node *pos; | 117 | struct hlist_node *pos; |
| 186 | 118 | ||
| 187 | X6TPRINTK3(KERN_DEBUG "%s(saddr=%p)\n", __FUNCTION__, saddr); | ||
| 188 | |||
| 189 | hlist_for_each_entry(x6spi, pos, | 119 | hlist_for_each_entry(x6spi, pos, |
| 190 | &xfrm6_tunnel_spi_byaddr[xfrm6_tunnel_spi_hash_byaddr(saddr)], | 120 | &xfrm6_tunnel_spi_byaddr[xfrm6_tunnel_spi_hash_byaddr(saddr)], |
| 191 | list_byaddr) { | 121 | list_byaddr) { |
| 192 | if (memcmp(&x6spi->addr, saddr, sizeof(x6spi->addr)) == 0) { | 122 | if (memcmp(&x6spi->addr, saddr, sizeof(x6spi->addr)) == 0) |
| 193 | X6SPI_CHECK_MAGIC(x6spi); | ||
| 194 | X6TPRINTK3(KERN_DEBUG "%s() = %p(%u)\n", __FUNCTION__, x6spi, x6spi->spi); | ||
| 195 | return x6spi; | 123 | return x6spi; |
| 196 | } | ||
| 197 | } | 124 | } |
| 198 | 125 | ||
| 199 | X6TPRINTK3(KERN_DEBUG "%s() = NULL(0)\n", __FUNCTION__); | ||
| 200 | return NULL; | 126 | return NULL; |
| 201 | } | 127 | } |
| 202 | 128 | ||
| @@ -205,8 +131,6 @@ u32 xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr) | |||
| 205 | struct xfrm6_tunnel_spi *x6spi; | 131 | struct xfrm6_tunnel_spi *x6spi; |
| 206 | u32 spi; | 132 | u32 spi; |
| 207 | 133 | ||
| 208 | X6TPRINTK3(KERN_DEBUG "%s(saddr=%p)\n", __FUNCTION__, saddr); | ||
| 209 | |||
| 210 | read_lock_bh(&xfrm6_tunnel_spi_lock); | 134 | read_lock_bh(&xfrm6_tunnel_spi_lock); |
| 211 | x6spi = __xfrm6_tunnel_spi_lookup(saddr); | 135 | x6spi = __xfrm6_tunnel_spi_lookup(saddr); |
| 212 | spi = x6spi ? x6spi->spi : 0; | 136 | spi = x6spi ? x6spi->spi : 0; |
| @@ -223,8 +147,6 @@ static u32 __xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr) | |||
| 223 | struct hlist_node *pos; | 147 | struct hlist_node *pos; |
| 224 | unsigned index; | 148 | unsigned index; |
| 225 | 149 | ||
| 226 | X6TPRINTK3(KERN_DEBUG "%s(saddr=%p)\n", __FUNCTION__, saddr); | ||
| 227 | |||
| 228 | if (xfrm6_tunnel_spi < XFRM6_TUNNEL_SPI_MIN || | 150 | if (xfrm6_tunnel_spi < XFRM6_TUNNEL_SPI_MIN || |
| 229 | xfrm6_tunnel_spi >= XFRM6_TUNNEL_SPI_MAX) | 151 | xfrm6_tunnel_spi >= XFRM6_TUNNEL_SPI_MAX) |
| 230 | xfrm6_tunnel_spi = XFRM6_TUNNEL_SPI_MIN; | 152 | xfrm6_tunnel_spi = XFRM6_TUNNEL_SPI_MIN; |
| @@ -258,18 +180,10 @@ try_next_2:; | |||
| 258 | spi = 0; | 180 | spi = 0; |
| 259 | goto out; | 181 | goto out; |
| 260 | alloc_spi: | 182 | alloc_spi: |
| 261 | X6TPRINTK3(KERN_DEBUG "%s(): allocate new spi for " NIP6_FMT "\n", | ||
| 262 | __FUNCTION__, | ||
| 263 | NIP6(*(struct in6_addr *)saddr)); | ||
| 264 | x6spi = kmem_cache_alloc(xfrm6_tunnel_spi_kmem, SLAB_ATOMIC); | 183 | x6spi = kmem_cache_alloc(xfrm6_tunnel_spi_kmem, SLAB_ATOMIC); |
| 265 | if (!x6spi) { | 184 | if (!x6spi) |
| 266 | X6TPRINTK1(KERN_ERR "%s(): kmem_cache_alloc() failed\n", | ||
| 267 | __FUNCTION__); | ||
| 268 | goto out; | 185 | goto out; |
| 269 | } | 186 | |
| 270 | #ifdef XFRM6_TUNNEL_SPI_MAGIC | ||
| 271 | x6spi->magic = XFRM6_TUNNEL_SPI_MAGIC; | ||
| 272 | #endif | ||
| 273 | memcpy(&x6spi->addr, saddr, sizeof(x6spi->addr)); | 187 | memcpy(&x6spi->addr, saddr, sizeof(x6spi->addr)); |
| 274 | x6spi->spi = spi; | 188 | x6spi->spi = spi; |
| 275 | atomic_set(&x6spi->refcnt, 1); | 189 | atomic_set(&x6spi->refcnt, 1); |
| @@ -278,9 +192,7 @@ alloc_spi: | |||
| 278 | 192 | ||
| 279 | index = xfrm6_tunnel_spi_hash_byaddr(saddr); | 193 | index = xfrm6_tunnel_spi_hash_byaddr(saddr); |
| 280 | hlist_add_head(&x6spi->list_byaddr, &xfrm6_tunnel_spi_byaddr[index]); | 194 | hlist_add_head(&x6spi->list_byaddr, &xfrm6_tunnel_spi_byaddr[index]); |
| 281 | X6SPI_CHECK_MAGIC(x6spi); | ||
| 282 | out: | 195 | out: |
| 283 | X6TPRINTK3(KERN_DEBUG "%s() = %u\n", __FUNCTION__, spi); | ||
| 284 | return spi; | 196 | return spi; |
| 285 | } | 197 | } |
| 286 | 198 | ||
| @@ -289,8 +201,6 @@ u32 xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr) | |||
| 289 | struct xfrm6_tunnel_spi *x6spi; | 201 | struct xfrm6_tunnel_spi *x6spi; |
| 290 | u32 spi; | 202 | u32 spi; |
| 291 | 203 | ||
| 292 | X6TPRINTK3(KERN_DEBUG "%s(saddr=%p)\n", __FUNCTION__, saddr); | ||
| 293 | |||
| 294 | write_lock_bh(&xfrm6_tunnel_spi_lock); | 204 | write_lock_bh(&xfrm6_tunnel_spi_lock); |
| 295 | x6spi = __xfrm6_tunnel_spi_lookup(saddr); | 205 | x6spi = __xfrm6_tunnel_spi_lookup(saddr); |
| 296 | if (x6spi) { | 206 | if (x6spi) { |
| @@ -300,8 +210,6 @@ u32 xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr) | |||
| 300 | spi = __xfrm6_tunnel_alloc_spi(saddr); | 210 | spi = __xfrm6_tunnel_alloc_spi(saddr); |
| 301 | write_unlock_bh(&xfrm6_tunnel_spi_lock); | 211 | write_unlock_bh(&xfrm6_tunnel_spi_lock); |
| 302 | 212 | ||
| 303 | X6TPRINTK3(KERN_DEBUG "%s() = %u\n", __FUNCTION__, spi); | ||
| 304 | |||
| 305 | return spi; | 213 | return spi; |
| 306 | } | 214 | } |
| 307 | 215 | ||
| @@ -312,8 +220,6 @@ void xfrm6_tunnel_free_spi(xfrm_address_t *saddr) | |||
| 312 | struct xfrm6_tunnel_spi *x6spi; | 220 | struct xfrm6_tunnel_spi *x6spi; |
| 313 | struct hlist_node *pos, *n; | 221 | struct hlist_node *pos, *n; |
| 314 | 222 | ||
| 315 | X6TPRINTK3(KERN_DEBUG "%s(saddr=%p)\n", __FUNCTION__, saddr); | ||
| 316 | |||
| 317 | write_lock_bh(&xfrm6_tunnel_spi_lock); | 223 | write_lock_bh(&xfrm6_tunnel_spi_lock); |
| 318 | 224 | ||
| 319 | hlist_for_each_entry_safe(x6spi, pos, n, | 225 | hlist_for_each_entry_safe(x6spi, pos, n, |
| @@ -321,12 +227,6 @@ void xfrm6_tunnel_free_spi(xfrm_address_t *saddr) | |||
| 321 | list_byaddr) | 227 | list_byaddr) |
| 322 | { | 228 | { |
| 323 | if (memcmp(&x6spi->addr, saddr, sizeof(x6spi->addr)) == 0) { | 229 | if (memcmp(&x6spi->addr, saddr, sizeof(x6spi->addr)) == 0) { |
| 324 | X6TPRINTK3(KERN_DEBUG "%s(): x6spi object for " NIP6_FMT | ||
| 325 | " found at %p\n", | ||
| 326 | __FUNCTION__, | ||
| 327 | NIP6(*(struct in6_addr *)saddr), | ||
| 328 | x6spi); | ||
| 329 | X6SPI_CHECK_MAGIC(x6spi); | ||
| 330 | if (atomic_dec_and_test(&x6spi->refcnt)) { | 230 | if (atomic_dec_and_test(&x6spi->refcnt)) { |
| 331 | hlist_del(&x6spi->list_byaddr); | 231 | hlist_del(&x6spi->list_byaddr); |
| 332 | hlist_del(&x6spi->list_byspi); | 232 | hlist_del(&x6spi->list_byspi); |
| @@ -377,20 +277,14 @@ static int xfrm6_tunnel_err(struct sk_buff *skb, struct inet6_skb_parm *opt, | |||
| 377 | case ICMPV6_ADDR_UNREACH: | 277 | case ICMPV6_ADDR_UNREACH: |
| 378 | case ICMPV6_PORT_UNREACH: | 278 | case ICMPV6_PORT_UNREACH: |
| 379 | default: | 279 | default: |
| 380 | X6TPRINTK3(KERN_DEBUG | ||
| 381 | "xfrm6_tunnel: Destination Unreach.\n"); | ||
| 382 | break; | 280 | break; |
| 383 | } | 281 | } |
| 384 | break; | 282 | break; |
| 385 | case ICMPV6_PKT_TOOBIG: | 283 | case ICMPV6_PKT_TOOBIG: |
| 386 | X6TPRINTK3(KERN_DEBUG | ||
| 387 | "xfrm6_tunnel: Packet Too Big.\n"); | ||
| 388 | break; | 284 | break; |
| 389 | case ICMPV6_TIME_EXCEED: | 285 | case ICMPV6_TIME_EXCEED: |
| 390 | switch (code) { | 286 | switch (code) { |
| 391 | case ICMPV6_EXC_HOPLIMIT: | 287 | case ICMPV6_EXC_HOPLIMIT: |
| 392 | X6TPRINTK3(KERN_DEBUG | ||
| 393 | "xfrm6_tunnel: Too small Hoplimit.\n"); | ||
| 394 | break; | 288 | break; |
| 395 | case ICMPV6_EXC_FRAGTIME: | 289 | case ICMPV6_EXC_FRAGTIME: |
| 396 | default: | 290 | default: |
| @@ -447,22 +341,14 @@ static struct xfrm6_tunnel xfrm6_tunnel_handler = { | |||
| 447 | 341 | ||
| 448 | static int __init xfrm6_tunnel_init(void) | 342 | static int __init xfrm6_tunnel_init(void) |
| 449 | { | 343 | { |
| 450 | X6TPRINTK3(KERN_DEBUG "%s()\n", __FUNCTION__); | 344 | if (xfrm_register_type(&xfrm6_tunnel_type, AF_INET6) < 0) |
| 451 | |||
| 452 | if (xfrm_register_type(&xfrm6_tunnel_type, AF_INET6) < 0) { | ||
| 453 | X6TPRINTK1(KERN_ERR | ||
| 454 | "xfrm6_tunnel init: can't add xfrm type\n"); | ||
| 455 | return -EAGAIN; | 345 | return -EAGAIN; |
| 456 | } | 346 | |
| 457 | if (xfrm6_tunnel_register(&xfrm6_tunnel_handler)) { | 347 | if (xfrm6_tunnel_register(&xfrm6_tunnel_handler)) { |
| 458 | X6TPRINTK1(KERN_ERR | ||
| 459 | "xfrm6_tunnel init(): can't add handler\n"); | ||
| 460 | xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6); | 348 | xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6); |
| 461 | return -EAGAIN; | 349 | return -EAGAIN; |
| 462 | } | 350 | } |
| 463 | if (xfrm6_tunnel_spi_init() < 0) { | 351 | if (xfrm6_tunnel_spi_init() < 0) { |
| 464 | X6TPRINTK1(KERN_ERR | ||
| 465 | "xfrm6_tunnel init: failed to initialize spi\n"); | ||
| 466 | xfrm6_tunnel_deregister(&xfrm6_tunnel_handler); | 352 | xfrm6_tunnel_deregister(&xfrm6_tunnel_handler); |
| 467 | xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6); | 353 | xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6); |
| 468 | return -EAGAIN; | 354 | return -EAGAIN; |
| @@ -472,15 +358,9 @@ static int __init xfrm6_tunnel_init(void) | |||
| 472 | 358 | ||
| 473 | static void __exit xfrm6_tunnel_fini(void) | 359 | static void __exit xfrm6_tunnel_fini(void) |
| 474 | { | 360 | { |
| 475 | X6TPRINTK3(KERN_DEBUG "%s()\n", __FUNCTION__); | ||
| 476 | |||
| 477 | xfrm6_tunnel_spi_fini(); | 361 | xfrm6_tunnel_spi_fini(); |
| 478 | if (xfrm6_tunnel_deregister(&xfrm6_tunnel_handler)) | 362 | xfrm6_tunnel_deregister(&xfrm6_tunnel_handler); |
| 479 | X6TPRINTK1(KERN_ERR | 363 | xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6); |
| 480 | "xfrm6_tunnel close: can't remove handler\n"); | ||
| 481 | if (xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6) < 0) | ||
| 482 | X6TPRINTK1(KERN_ERR | ||
| 483 | "xfrm6_tunnel close: can't remove xfrm type\n"); | ||
| 484 | } | 364 | } |
| 485 | 365 | ||
| 486 | module_init(xfrm6_tunnel_init); | 366 | module_init(xfrm6_tunnel_init); |
