diff options
| author | Tom Herbert <therbert@google.com> | 2014-06-04 20:19:56 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2014-06-05 01:46:38 -0400 |
| commit | 77157e1973cbdb8d60bdb0ec749d6014bedc5bd5 (patch) | |
| tree | d4dab38f82bb1e287693a78c5e5b983202eab07a | |
| parent | af5fcba7f38f3166392f4087ab734433c84f160b (diff) | |
l2tp: call udp{6}_set_csum
Call common functions to set checksum for UDP tunnel.
Signed-off-by: Tom Herbert <therbert@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
| -rw-r--r-- | net/l2tp/l2tp_core.c | 54 |
1 files changed, 5 insertions, 49 deletions
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index 379558014b60..bea259043205 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c | |||
| @@ -1095,33 +1095,6 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, | |||
| 1095 | return 0; | 1095 | return 0; |
| 1096 | } | 1096 | } |
| 1097 | 1097 | ||
| 1098 | #if IS_ENABLED(CONFIG_IPV6) | ||
| 1099 | static void l2tp_xmit_ipv6_csum(struct sock *sk, struct sk_buff *skb, | ||
| 1100 | int udp_len) | ||
| 1101 | { | ||
| 1102 | struct ipv6_pinfo *np = inet6_sk(sk); | ||
| 1103 | struct udphdr *uh = udp_hdr(skb); | ||
| 1104 | |||
| 1105 | if (udp_get_no_check6_tx(sk)) | ||
| 1106 | skb->ip_summed = CHECKSUM_NONE; | ||
| 1107 | else if (!skb_dst(skb) || !skb_dst(skb)->dev || | ||
| 1108 | !(skb_dst(skb)->dev->features & NETIF_F_IPV6_CSUM)) { | ||
| 1109 | __wsum csum = skb_checksum(skb, 0, udp_len, 0); | ||
| 1110 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
| 1111 | uh->check = csum_ipv6_magic(&np->saddr, &sk->sk_v6_daddr, udp_len, | ||
| 1112 | IPPROTO_UDP, csum); | ||
| 1113 | if (uh->check == 0) | ||
| 1114 | uh->check = CSUM_MANGLED_0; | ||
| 1115 | } else { | ||
| 1116 | skb->ip_summed = CHECKSUM_PARTIAL; | ||
| 1117 | skb->csum_start = skb_transport_header(skb) - skb->head; | ||
| 1118 | skb->csum_offset = offsetof(struct udphdr, check); | ||
| 1119 | uh->check = ~csum_ipv6_magic(&np->saddr, &sk->sk_v6_daddr, | ||
| 1120 | udp_len, IPPROTO_UDP, 0); | ||
| 1121 | } | ||
| 1122 | } | ||
| 1123 | #endif | ||
| 1124 | |||
| 1125 | /* If caller requires the skb to have a ppp header, the header must be | 1098 | /* If caller requires the skb to have a ppp header, the header must be |
| 1126 | * inserted in the skb data before calling this function. | 1099 | * inserted in the skb data before calling this function. |
| 1127 | */ | 1100 | */ |
| @@ -1133,7 +1106,6 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len | |||
| 1133 | struct flowi *fl; | 1106 | struct flowi *fl; |
| 1134 | struct udphdr *uh; | 1107 | struct udphdr *uh; |
| 1135 | struct inet_sock *inet; | 1108 | struct inet_sock *inet; |
| 1136 | __wsum csum; | ||
| 1137 | int headroom; | 1109 | int headroom; |
| 1138 | int uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0; | 1110 | int uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0; |
| 1139 | int udp_len; | 1111 | int udp_len; |
| @@ -1182,33 +1154,17 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len | |||
| 1182 | uh->dest = inet->inet_dport; | 1154 | uh->dest = inet->inet_dport; |
| 1183 | udp_len = uhlen + hdr_len + data_len; | 1155 | udp_len = uhlen + hdr_len + data_len; |
| 1184 | uh->len = htons(udp_len); | 1156 | uh->len = htons(udp_len); |
| 1185 | uh->check = 0; | ||
| 1186 | 1157 | ||
| 1187 | /* Calculate UDP checksum if configured to do so */ | 1158 | /* Calculate UDP checksum if configured to do so */ |
| 1188 | #if IS_ENABLED(CONFIG_IPV6) | 1159 | #if IS_ENABLED(CONFIG_IPV6) |
| 1189 | if (sk->sk_family == PF_INET6 && !tunnel->v4mapped) | 1160 | if (sk->sk_family == PF_INET6 && !tunnel->v4mapped) |
| 1190 | l2tp_xmit_ipv6_csum(sk, skb, udp_len); | 1161 | udp6_set_csum(udp_get_no_check6_tx(sk), |
| 1162 | skb, &inet6_sk(sk)->saddr, | ||
| 1163 | &sk->sk_v6_daddr, udp_len); | ||
| 1191 | else | 1164 | else |
| 1192 | #endif | 1165 | #endif |
| 1193 | if (sk->sk_no_check_tx) | 1166 | udp_set_csum(sk->sk_no_check_tx, skb, inet->inet_saddr, |
| 1194 | skb->ip_summed = CHECKSUM_NONE; | 1167 | inet->inet_daddr, udp_len); |
| 1195 | else if ((skb_dst(skb) && skb_dst(skb)->dev) && | ||
| 1196 | (!(skb_dst(skb)->dev->features & NETIF_F_V4_CSUM))) { | ||
| 1197 | skb->ip_summed = CHECKSUM_COMPLETE; | ||
| 1198 | csum = skb_checksum(skb, 0, udp_len, 0); | ||
| 1199 | uh->check = csum_tcpudp_magic(inet->inet_saddr, | ||
| 1200 | inet->inet_daddr, | ||
| 1201 | udp_len, IPPROTO_UDP, csum); | ||
| 1202 | if (uh->check == 0) | ||
| 1203 | uh->check = CSUM_MANGLED_0; | ||
| 1204 | } else { | ||
| 1205 | skb->ip_summed = CHECKSUM_PARTIAL; | ||
| 1206 | skb->csum_start = skb_transport_header(skb) - skb->head; | ||
| 1207 | skb->csum_offset = offsetof(struct udphdr, check); | ||
| 1208 | uh->check = ~csum_tcpudp_magic(inet->inet_saddr, | ||
| 1209 | inet->inet_daddr, | ||
| 1210 | udp_len, IPPROTO_UDP, 0); | ||
| 1211 | } | ||
| 1212 | break; | 1168 | break; |
| 1213 | 1169 | ||
| 1214 | case L2TP_ENCAPTYPE_IP: | 1170 | case L2TP_ENCAPTYPE_IP: |
