diff options
Diffstat (limited to 'net/ipv6')
-rw-r--r-- | net/ipv6/af_inet6.c | 20 | ||||
-rw-r--r-- | net/ipv6/ip6_input.c | 6 | ||||
-rw-r--r-- | net/ipv6/ip6_output.c | 26 | ||||
-rw-r--r-- | net/ipv6/ip6_tunnel.c | 4 | ||||
-rw-r--r-- | net/ipv6/ip6mr.c | 2 | ||||
-rw-r--r-- | net/ipv6/sit.c | 6 | ||||
-rw-r--r-- | net/ipv6/udp.c | 141 |
7 files changed, 174 insertions, 31 deletions
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index caa0278d30a9..bf85d5f97032 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c | |||
@@ -772,6 +772,11 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features) | |||
772 | struct sk_buff *segs = ERR_PTR(-EINVAL); | 772 | struct sk_buff *segs = ERR_PTR(-EINVAL); |
773 | struct ipv6hdr *ipv6h; | 773 | struct ipv6hdr *ipv6h; |
774 | struct inet6_protocol *ops; | 774 | struct inet6_protocol *ops; |
775 | int proto; | ||
776 | struct frag_hdr *fptr; | ||
777 | unsigned int unfrag_ip6hlen; | ||
778 | u8 *prevhdr; | ||
779 | int offset = 0; | ||
775 | 780 | ||
776 | if (!(features & NETIF_F_V6_CSUM)) | 781 | if (!(features & NETIF_F_V6_CSUM)) |
777 | features &= ~NETIF_F_SG; | 782 | features &= ~NETIF_F_SG; |
@@ -791,10 +796,9 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features) | |||
791 | __skb_pull(skb, sizeof(*ipv6h)); | 796 | __skb_pull(skb, sizeof(*ipv6h)); |
792 | segs = ERR_PTR(-EPROTONOSUPPORT); | 797 | segs = ERR_PTR(-EPROTONOSUPPORT); |
793 | 798 | ||
799 | proto = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr); | ||
794 | rcu_read_lock(); | 800 | rcu_read_lock(); |
795 | ops = rcu_dereference(inet6_protos[ | 801 | ops = rcu_dereference(inet6_protos[proto]); |
796 | ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr)]); | ||
797 | |||
798 | if (likely(ops && ops->gso_segment)) { | 802 | if (likely(ops && ops->gso_segment)) { |
799 | skb_reset_transport_header(skb); | 803 | skb_reset_transport_header(skb); |
800 | segs = ops->gso_segment(skb, features); | 804 | segs = ops->gso_segment(skb, features); |
@@ -808,6 +812,16 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features) | |||
808 | ipv6h = ipv6_hdr(skb); | 812 | ipv6h = ipv6_hdr(skb); |
809 | ipv6h->payload_len = htons(skb->len - skb->mac_len - | 813 | ipv6h->payload_len = htons(skb->len - skb->mac_len - |
810 | sizeof(*ipv6h)); | 814 | sizeof(*ipv6h)); |
815 | if (proto == IPPROTO_UDP) { | ||
816 | unfrag_ip6hlen = ip6_find_1stfragopt(skb, &prevhdr); | ||
817 | fptr = (struct frag_hdr *)(skb_network_header(skb) + | ||
818 | unfrag_ip6hlen); | ||
819 | fptr->frag_off = htons(offset); | ||
820 | if (skb->next != NULL) | ||
821 | fptr->frag_off |= htons(IP6_MF); | ||
822 | offset += (ntohs(ipv6h->payload_len) - | ||
823 | sizeof(struct frag_hdr)); | ||
824 | } | ||
811 | } | 825 | } |
812 | 826 | ||
813 | out: | 827 | out: |
diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c index 6d6a4277c677..2d9cbaa67edb 100644 --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c | |||
@@ -63,7 +63,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt | |||
63 | 63 | ||
64 | if (skb->pkt_type == PACKET_OTHERHOST) { | 64 | if (skb->pkt_type == PACKET_OTHERHOST) { |
65 | kfree_skb(skb); | 65 | kfree_skb(skb); |
66 | return 0; | 66 | return NET_RX_DROP; |
67 | } | 67 | } |
68 | 68 | ||
69 | rcu_read_lock(); | 69 | rcu_read_lock(); |
@@ -133,7 +133,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt | |||
133 | if (ipv6_parse_hopopts(skb) < 0) { | 133 | if (ipv6_parse_hopopts(skb) < 0) { |
134 | IP6_INC_STATS_BH(net, idev, IPSTATS_MIB_INHDRERRORS); | 134 | IP6_INC_STATS_BH(net, idev, IPSTATS_MIB_INHDRERRORS); |
135 | rcu_read_unlock(); | 135 | rcu_read_unlock(); |
136 | return 0; | 136 | return NET_RX_DROP; |
137 | } | 137 | } |
138 | } | 138 | } |
139 | 139 | ||
@@ -149,7 +149,7 @@ err: | |||
149 | drop: | 149 | drop: |
150 | rcu_read_unlock(); | 150 | rcu_read_unlock(); |
151 | kfree_skb(skb); | 151 | kfree_skb(skb); |
152 | return 0; | 152 | return NET_RX_DROP; |
153 | } | 153 | } |
154 | 154 | ||
155 | /* | 155 | /* |
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 87f8419a68fd..93beee944657 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c | |||
@@ -57,18 +57,6 @@ | |||
57 | 57 | ||
58 | static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)); | 58 | static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)); |
59 | 59 | ||
60 | static __inline__ void ipv6_select_ident(struct sk_buff *skb, struct frag_hdr *fhdr) | ||
61 | { | ||
62 | static u32 ipv6_fragmentation_id = 1; | ||
63 | static DEFINE_SPINLOCK(ip6_id_lock); | ||
64 | |||
65 | spin_lock_bh(&ip6_id_lock); | ||
66 | fhdr->identification = htonl(ipv6_fragmentation_id); | ||
67 | if (++ipv6_fragmentation_id == 0) | ||
68 | ipv6_fragmentation_id = 1; | ||
69 | spin_unlock_bh(&ip6_id_lock); | ||
70 | } | ||
71 | |||
72 | int __ip6_local_out(struct sk_buff *skb) | 60 | int __ip6_local_out(struct sk_buff *skb) |
73 | { | 61 | { |
74 | int len; | 62 | int len; |
@@ -706,7 +694,7 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) | |||
706 | skb_reset_network_header(skb); | 694 | skb_reset_network_header(skb); |
707 | memcpy(skb_network_header(skb), tmp_hdr, hlen); | 695 | memcpy(skb_network_header(skb), tmp_hdr, hlen); |
708 | 696 | ||
709 | ipv6_select_ident(skb, fh); | 697 | ipv6_select_ident(fh); |
710 | fh->nexthdr = nexthdr; | 698 | fh->nexthdr = nexthdr; |
711 | fh->reserved = 0; | 699 | fh->reserved = 0; |
712 | fh->frag_off = htons(IP6_MF); | 700 | fh->frag_off = htons(IP6_MF); |
@@ -844,7 +832,7 @@ slow_path: | |||
844 | fh->nexthdr = nexthdr; | 832 | fh->nexthdr = nexthdr; |
845 | fh->reserved = 0; | 833 | fh->reserved = 0; |
846 | if (!frag_id) { | 834 | if (!frag_id) { |
847 | ipv6_select_ident(skb, fh); | 835 | ipv6_select_ident(fh); |
848 | frag_id = fh->identification; | 836 | frag_id = fh->identification; |
849 | } else | 837 | } else |
850 | fh->identification = frag_id; | 838 | fh->identification = frag_id; |
@@ -1087,11 +1075,13 @@ static inline int ip6_ufo_append_data(struct sock *sk, | |||
1087 | if (!err) { | 1075 | if (!err) { |
1088 | struct frag_hdr fhdr; | 1076 | struct frag_hdr fhdr; |
1089 | 1077 | ||
1090 | /* specify the length of each IP datagram fragment*/ | 1078 | /* Specify the length of each IPv6 datagram fragment. |
1091 | skb_shinfo(skb)->gso_size = mtu - fragheaderlen - | 1079 | * It has to be a multiple of 8. |
1092 | sizeof(struct frag_hdr); | 1080 | */ |
1081 | skb_shinfo(skb)->gso_size = (mtu - fragheaderlen - | ||
1082 | sizeof(struct frag_hdr)) & ~7; | ||
1093 | skb_shinfo(skb)->gso_type = SKB_GSO_UDP; | 1083 | skb_shinfo(skb)->gso_type = SKB_GSO_UDP; |
1094 | ipv6_select_ident(skb, &fhdr); | 1084 | ipv6_select_ident(&fhdr); |
1095 | skb_shinfo(skb)->ip6_frag_id = fhdr.identification; | 1085 | skb_shinfo(skb)->ip6_frag_id = fhdr.identification; |
1096 | __skb_queue_tail(&sk->sk_write_queue, skb); | 1086 | __skb_queue_tail(&sk->sk_write_queue, skb); |
1097 | 1087 | ||
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index 51f410e7775a..a1d6045c4694 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c | |||
@@ -1063,14 +1063,14 @@ ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev) | |||
1063 | goto tx_err; | 1063 | goto tx_err; |
1064 | 1064 | ||
1065 | t->recursion--; | 1065 | t->recursion--; |
1066 | return 0; | 1066 | return NETDEV_TX_OK; |
1067 | 1067 | ||
1068 | tx_err: | 1068 | tx_err: |
1069 | stats->tx_errors++; | 1069 | stats->tx_errors++; |
1070 | stats->tx_dropped++; | 1070 | stats->tx_dropped++; |
1071 | kfree_skb(skb); | 1071 | kfree_skb(skb); |
1072 | t->recursion--; | 1072 | t->recursion--; |
1073 | return 0; | 1073 | return NETDEV_TX_OK; |
1074 | } | 1074 | } |
1075 | 1075 | ||
1076 | static void ip6_tnl_set_cap(struct ip6_tnl *t) | 1076 | static void ip6_tnl_set_cap(struct ip6_tnl *t) |
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index c769f155c698..07ded5075b33 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c | |||
@@ -427,7 +427,7 @@ static int reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) | |||
427 | MRT6MSG_WHOLEPKT); | 427 | MRT6MSG_WHOLEPKT); |
428 | read_unlock(&mrt_lock); | 428 | read_unlock(&mrt_lock); |
429 | kfree_skb(skb); | 429 | kfree_skb(skb); |
430 | return 0; | 430 | return NETDEV_TX_OK; |
431 | } | 431 | } |
432 | 432 | ||
433 | static const struct net_device_ops reg_vif_netdev_ops = { | 433 | static const struct net_device_ops reg_vif_netdev_ops = { |
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 98b7327d0949..d335a306a4db 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c | |||
@@ -753,7 +753,7 @@ static int ipip6_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) | |||
753 | stats->tx_dropped++; | 753 | stats->tx_dropped++; |
754 | dev_kfree_skb(skb); | 754 | dev_kfree_skb(skb); |
755 | tunnel->recursion--; | 755 | tunnel->recursion--; |
756 | return 0; | 756 | return NETDEV_TX_OK; |
757 | } | 757 | } |
758 | if (skb->sk) | 758 | if (skb->sk) |
759 | skb_set_owner_w(new_skb, skb->sk); | 759 | skb_set_owner_w(new_skb, skb->sk); |
@@ -794,7 +794,7 @@ static int ipip6_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) | |||
794 | 794 | ||
795 | IPTUNNEL_XMIT(); | 795 | IPTUNNEL_XMIT(); |
796 | tunnel->recursion--; | 796 | tunnel->recursion--; |
797 | return 0; | 797 | return NETDEV_TX_OK; |
798 | 798 | ||
799 | tx_error_icmp: | 799 | tx_error_icmp: |
800 | dst_link_failure(skb); | 800 | dst_link_failure(skb); |
@@ -802,7 +802,7 @@ tx_error: | |||
802 | stats->tx_errors++; | 802 | stats->tx_errors++; |
803 | dev_kfree_skb(skb); | 803 | dev_kfree_skb(skb); |
804 | tunnel->recursion--; | 804 | tunnel->recursion--; |
805 | return 0; | 805 | return NETDEV_TX_OK; |
806 | } | 806 | } |
807 | 807 | ||
808 | static void ipip6_tunnel_bind_dev(struct net_device *dev) | 808 | static void ipip6_tunnel_bind_dev(struct net_device *dev) |
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 33b59bd92c4d..d79fa6724451 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c | |||
@@ -638,6 +638,47 @@ static void udp_v6_flush_pending_frames(struct sock *sk) | |||
638 | } | 638 | } |
639 | } | 639 | } |
640 | 640 | ||
641 | /** | ||
642 | * udp6_hwcsum_outgoing - handle outgoing HW checksumming | ||
643 | * @sk: socket we are sending on | ||
644 | * @skb: sk_buff containing the filled-in UDP header | ||
645 | * (checksum field must be zeroed out) | ||
646 | */ | ||
647 | static void udp6_hwcsum_outgoing(struct sock *sk, struct sk_buff *skb, | ||
648 | const struct in6_addr *saddr, | ||
649 | const struct in6_addr *daddr, int len) | ||
650 | { | ||
651 | unsigned int offset; | ||
652 | struct udphdr *uh = udp_hdr(skb); | ||
653 | __wsum csum = 0; | ||
654 | |||
655 | if (skb_queue_len(&sk->sk_write_queue) == 1) { | ||
656 | /* Only one fragment on the socket. */ | ||
657 | skb->csum_start = skb_transport_header(skb) - skb->head; | ||
658 | skb->csum_offset = offsetof(struct udphdr, check); | ||
659 | uh->check = ~csum_ipv6_magic(saddr, daddr, len, IPPROTO_UDP, 0); | ||
660 | } else { | ||
661 | /* | ||
662 | * HW-checksum won't work as there are two or more | ||
663 | * fragments on the socket so that all csums of sk_buffs | ||
664 | * should be together | ||
665 | */ | ||
666 | offset = skb_transport_offset(skb); | ||
667 | skb->csum = skb_checksum(skb, offset, skb->len - offset, 0); | ||
668 | |||
669 | skb->ip_summed = CHECKSUM_NONE; | ||
670 | |||
671 | skb_queue_walk(&sk->sk_write_queue, skb) { | ||
672 | csum = csum_add(csum, skb->csum); | ||
673 | } | ||
674 | |||
675 | uh->check = csum_ipv6_magic(saddr, daddr, len, IPPROTO_UDP, | ||
676 | csum); | ||
677 | if (uh->check == 0) | ||
678 | uh->check = CSUM_MANGLED_0; | ||
679 | } | ||
680 | } | ||
681 | |||
641 | /* | 682 | /* |
642 | * Sending | 683 | * Sending |
643 | */ | 684 | */ |
@@ -668,7 +709,11 @@ static int udp_v6_push_pending_frames(struct sock *sk) | |||
668 | 709 | ||
669 | if (is_udplite) | 710 | if (is_udplite) |
670 | csum = udplite_csum_outgoing(sk, skb); | 711 | csum = udplite_csum_outgoing(sk, skb); |
671 | else | 712 | else if (skb->ip_summed == CHECKSUM_PARTIAL) { /* UDP hardware csum */ |
713 | udp6_hwcsum_outgoing(sk, skb, &fl->fl6_src, &fl->fl6_dst, | ||
714 | up->len); | ||
715 | goto send; | ||
716 | } else | ||
672 | csum = udp_csum_outgoing(sk, skb); | 717 | csum = udp_csum_outgoing(sk, skb); |
673 | 718 | ||
674 | /* add protocol-dependent pseudo-header */ | 719 | /* add protocol-dependent pseudo-header */ |
@@ -677,6 +722,7 @@ static int udp_v6_push_pending_frames(struct sock *sk) | |||
677 | if (uh->check == 0) | 722 | if (uh->check == 0) |
678 | uh->check = CSUM_MANGLED_0; | 723 | uh->check = CSUM_MANGLED_0; |
679 | 724 | ||
725 | send: | ||
680 | err = ip6_push_pending_frames(sk); | 726 | err = ip6_push_pending_frames(sk); |
681 | out: | 727 | out: |
682 | up->len = 0; | 728 | up->len = 0; |
@@ -1032,9 +1078,102 @@ int compat_udpv6_getsockopt(struct sock *sk, int level, int optname, | |||
1032 | } | 1078 | } |
1033 | #endif | 1079 | #endif |
1034 | 1080 | ||
1081 | static int udp6_ufo_send_check(struct sk_buff *skb) | ||
1082 | { | ||
1083 | struct ipv6hdr *ipv6h; | ||
1084 | struct udphdr *uh; | ||
1085 | |||
1086 | if (!pskb_may_pull(skb, sizeof(*uh))) | ||
1087 | return -EINVAL; | ||
1088 | |||
1089 | ipv6h = ipv6_hdr(skb); | ||
1090 | uh = udp_hdr(skb); | ||
1091 | |||
1092 | uh->check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr, skb->len, | ||
1093 | IPPROTO_UDP, 0); | ||
1094 | skb->csum_start = skb_transport_header(skb) - skb->head; | ||
1095 | skb->csum_offset = offsetof(struct udphdr, check); | ||
1096 | skb->ip_summed = CHECKSUM_PARTIAL; | ||
1097 | return 0; | ||
1098 | } | ||
1099 | |||
1100 | static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, int features) | ||
1101 | { | ||
1102 | struct sk_buff *segs = ERR_PTR(-EINVAL); | ||
1103 | unsigned int mss; | ||
1104 | unsigned int unfrag_ip6hlen, unfrag_len; | ||
1105 | struct frag_hdr *fptr; | ||
1106 | u8 *mac_start, *prevhdr; | ||
1107 | u8 nexthdr; | ||
1108 | u8 frag_hdr_sz = sizeof(struct frag_hdr); | ||
1109 | int offset; | ||
1110 | __wsum csum; | ||
1111 | |||
1112 | mss = skb_shinfo(skb)->gso_size; | ||
1113 | if (unlikely(skb->len <= mss)) | ||
1114 | goto out; | ||
1115 | |||
1116 | if (skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST)) { | ||
1117 | /* Packet is from an untrusted source, reset gso_segs. */ | ||
1118 | int type = skb_shinfo(skb)->gso_type; | ||
1119 | |||
1120 | if (unlikely(type & ~(SKB_GSO_UDP | SKB_GSO_DODGY) || | ||
1121 | !(type & (SKB_GSO_UDP)))) | ||
1122 | goto out; | ||
1123 | |||
1124 | skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(skb->len, mss); | ||
1125 | |||
1126 | segs = NULL; | ||
1127 | goto out; | ||
1128 | } | ||
1129 | |||
1130 | /* Do software UFO. Complete and fill in the UDP checksum as HW cannot | ||
1131 | * do checksum of UDP packets sent as multiple IP fragments. | ||
1132 | */ | ||
1133 | offset = skb->csum_start - skb_headroom(skb); | ||
1134 | csum = skb_checksum(skb, offset, skb->len- offset, 0); | ||
1135 | offset += skb->csum_offset; | ||
1136 | *(__sum16 *)(skb->data + offset) = csum_fold(csum); | ||
1137 | skb->ip_summed = CHECKSUM_NONE; | ||
1138 | |||
1139 | /* Check if there is enough headroom to insert fragment header. */ | ||
1140 | if ((skb_headroom(skb) < frag_hdr_sz) && | ||
1141 | pskb_expand_head(skb, frag_hdr_sz, 0, GFP_ATOMIC)) | ||
1142 | goto out; | ||
1143 | |||
1144 | /* Find the unfragmentable header and shift it left by frag_hdr_sz | ||
1145 | * bytes to insert fragment header. | ||
1146 | */ | ||
1147 | unfrag_ip6hlen = ip6_find_1stfragopt(skb, &prevhdr); | ||
1148 | nexthdr = *prevhdr; | ||
1149 | *prevhdr = NEXTHDR_FRAGMENT; | ||
1150 | unfrag_len = skb_network_header(skb) - skb_mac_header(skb) + | ||
1151 | unfrag_ip6hlen; | ||
1152 | mac_start = skb_mac_header(skb); | ||
1153 | memmove(mac_start-frag_hdr_sz, mac_start, unfrag_len); | ||
1154 | |||
1155 | skb->mac_header -= frag_hdr_sz; | ||
1156 | skb->network_header -= frag_hdr_sz; | ||
1157 | |||
1158 | fptr = (struct frag_hdr *)(skb_network_header(skb) + unfrag_ip6hlen); | ||
1159 | fptr->nexthdr = nexthdr; | ||
1160 | fptr->reserved = 0; | ||
1161 | ipv6_select_ident(fptr); | ||
1162 | |||
1163 | /* Fragment the skb. ipv6 header and the remaining fields of the | ||
1164 | * fragment header are updated in ipv6_gso_segment() | ||
1165 | */ | ||
1166 | segs = skb_segment(skb, features); | ||
1167 | |||
1168 | out: | ||
1169 | return segs; | ||
1170 | } | ||
1171 | |||
1035 | static struct inet6_protocol udpv6_protocol = { | 1172 | static struct inet6_protocol udpv6_protocol = { |
1036 | .handler = udpv6_rcv, | 1173 | .handler = udpv6_rcv, |
1037 | .err_handler = udpv6_err, | 1174 | .err_handler = udpv6_err, |
1175 | .gso_send_check = udp6_ufo_send_check, | ||
1176 | .gso_segment = udp6_ufo_fragment, | ||
1038 | .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, | 1177 | .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, |
1039 | }; | 1178 | }; |
1040 | 1179 | ||