diff options
Diffstat (limited to 'net/ipv6/udp.c')
-rw-r--r-- | net/ipv6/udp.c | 426 |
1 files changed, 182 insertions, 244 deletions
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index c83f23e51c46..f52a5c3cc0a3 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c | |||
@@ -38,26 +38,18 @@ | |||
38 | #include <linux/skbuff.h> | 38 | #include <linux/skbuff.h> |
39 | #include <asm/uaccess.h> | 39 | #include <asm/uaccess.h> |
40 | 40 | ||
41 | #include <net/sock.h> | ||
42 | #include <net/snmp.h> | ||
43 | |||
44 | #include <net/ipv6.h> | ||
45 | #include <net/ndisc.h> | 41 | #include <net/ndisc.h> |
46 | #include <net/protocol.h> | 42 | #include <net/protocol.h> |
47 | #include <net/transp_v6.h> | 43 | #include <net/transp_v6.h> |
48 | #include <net/ip6_route.h> | 44 | #include <net/ip6_route.h> |
49 | #include <net/addrconf.h> | ||
50 | #include <net/ip.h> | ||
51 | #include <net/udp.h> | ||
52 | #include <net/raw.h> | 45 | #include <net/raw.h> |
53 | #include <net/inet_common.h> | ||
54 | #include <net/tcp_states.h> | 46 | #include <net/tcp_states.h> |
55 | |||
56 | #include <net/ip6_checksum.h> | 47 | #include <net/ip6_checksum.h> |
57 | #include <net/xfrm.h> | 48 | #include <net/xfrm.h> |
58 | 49 | ||
59 | #include <linux/proc_fs.h> | 50 | #include <linux/proc_fs.h> |
60 | #include <linux/seq_file.h> | 51 | #include <linux/seq_file.h> |
52 | #include "udp_impl.h" | ||
61 | 53 | ||
62 | DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly; | 54 | DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly; |
63 | 55 | ||
@@ -66,23 +58,9 @@ static inline int udp_v6_get_port(struct sock *sk, unsigned short snum) | |||
66 | return udp_get_port(sk, snum, ipv6_rcv_saddr_equal); | 58 | return udp_get_port(sk, snum, ipv6_rcv_saddr_equal); |
67 | } | 59 | } |
68 | 60 | ||
69 | static void udp_v6_hash(struct sock *sk) | 61 | static struct sock *__udp6_lib_lookup(struct in6_addr *saddr, __be16 sport, |
70 | { | 62 | struct in6_addr *daddr, __be16 dport, |
71 | BUG(); | 63 | int dif, struct hlist_head udptable[]) |
72 | } | ||
73 | |||
74 | static void udp_v6_unhash(struct sock *sk) | ||
75 | { | ||
76 | write_lock_bh(&udp_hash_lock); | ||
77 | if (sk_del_node_init(sk)) { | ||
78 | inet_sk(sk)->num = 0; | ||
79 | sock_prot_dec_use(sk->sk_prot); | ||
80 | } | ||
81 | write_unlock_bh(&udp_hash_lock); | ||
82 | } | ||
83 | |||
84 | static struct sock *udp_v6_lookup(struct in6_addr *saddr, u16 sport, | ||
85 | struct in6_addr *daddr, u16 dport, int dif) | ||
86 | { | 64 | { |
87 | struct sock *sk, *result = NULL; | 65 | struct sock *sk, *result = NULL; |
88 | struct hlist_node *node; | 66 | struct hlist_node *node; |
@@ -90,7 +68,7 @@ static struct sock *udp_v6_lookup(struct in6_addr *saddr, u16 sport, | |||
90 | int badness = -1; | 68 | int badness = -1; |
91 | 69 | ||
92 | read_lock(&udp_hash_lock); | 70 | read_lock(&udp_hash_lock); |
93 | sk_for_each(sk, node, &udp_hash[hnum & (UDP_HTABLE_SIZE - 1)]) { | 71 | sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) { |
94 | struct inet_sock *inet = inet_sk(sk); | 72 | struct inet_sock *inet = inet_sk(sk); |
95 | 73 | ||
96 | if (inet->num == hnum && sk->sk_family == PF_INET6) { | 74 | if (inet->num == hnum && sk->sk_family == PF_INET6) { |
@@ -132,20 +110,11 @@ static struct sock *udp_v6_lookup(struct in6_addr *saddr, u16 sport, | |||
132 | } | 110 | } |
133 | 111 | ||
134 | /* | 112 | /* |
135 | * | ||
136 | */ | ||
137 | |||
138 | static void udpv6_close(struct sock *sk, long timeout) | ||
139 | { | ||
140 | sk_common_release(sk); | ||
141 | } | ||
142 | |||
143 | /* | ||
144 | * This should be easy, if there is something there we | 113 | * This should be easy, if there is something there we |
145 | * return it, otherwise we block. | 114 | * return it, otherwise we block. |
146 | */ | 115 | */ |
147 | 116 | ||
148 | static int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk, | 117 | int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk, |
149 | struct msghdr *msg, size_t len, | 118 | struct msghdr *msg, size_t len, |
150 | int noblock, int flags, int *addr_len) | 119 | int noblock, int flags, int *addr_len) |
151 | { | 120 | { |
@@ -153,7 +122,7 @@ static int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk, | |||
153 | struct inet_sock *inet = inet_sk(sk); | 122 | struct inet_sock *inet = inet_sk(sk); |
154 | struct sk_buff *skb; | 123 | struct sk_buff *skb; |
155 | size_t copied; | 124 | size_t copied; |
156 | int err; | 125 | int err, copy_only, is_udplite = IS_UDPLITE(sk); |
157 | 126 | ||
158 | if (addr_len) | 127 | if (addr_len) |
159 | *addr_len=sizeof(struct sockaddr_in6); | 128 | *addr_len=sizeof(struct sockaddr_in6); |
@@ -172,15 +141,21 @@ try_again: | |||
172 | msg->msg_flags |= MSG_TRUNC; | 141 | msg->msg_flags |= MSG_TRUNC; |
173 | } | 142 | } |
174 | 143 | ||
175 | if (skb->ip_summed==CHECKSUM_UNNECESSARY) { | 144 | /* |
176 | err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov, | 145 | * Decide whether to checksum and/or copy data. |
177 | copied); | 146 | */ |
178 | } else if (msg->msg_flags&MSG_TRUNC) { | 147 | copy_only = (skb->ip_summed==CHECKSUM_UNNECESSARY); |
179 | if (__skb_checksum_complete(skb)) | 148 | |
149 | if (is_udplite || (!copy_only && msg->msg_flags&MSG_TRUNC)) { | ||
150 | if (__udp_lib_checksum_complete(skb)) | ||
180 | goto csum_copy_err; | 151 | goto csum_copy_err; |
181 | err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov, | 152 | copy_only = 1; |
182 | copied); | 153 | } |
183 | } else { | 154 | |
155 | if (copy_only) | ||
156 | err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), | ||
157 | msg->msg_iov, copied ); | ||
158 | else { | ||
184 | err = skb_copy_and_csum_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov); | 159 | err = skb_copy_and_csum_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov); |
185 | if (err == -EINVAL) | 160 | if (err == -EINVAL) |
186 | goto csum_copy_err; | 161 | goto csum_copy_err; |
@@ -231,14 +206,15 @@ csum_copy_err: | |||
231 | skb_kill_datagram(sk, skb, flags); | 206 | skb_kill_datagram(sk, skb, flags); |
232 | 207 | ||
233 | if (flags & MSG_DONTWAIT) { | 208 | if (flags & MSG_DONTWAIT) { |
234 | UDP6_INC_STATS_USER(UDP_MIB_INERRORS); | 209 | UDP6_INC_STATS_USER(UDP_MIB_INERRORS, is_udplite); |
235 | return -EAGAIN; | 210 | return -EAGAIN; |
236 | } | 211 | } |
237 | goto try_again; | 212 | goto try_again; |
238 | } | 213 | } |
239 | 214 | ||
240 | static void udpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, | 215 | void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt, |
241 | int type, int code, int offset, __u32 info) | 216 | int type, int code, int offset, __be32 info, |
217 | struct hlist_head udptable[] ) | ||
242 | { | 218 | { |
243 | struct ipv6_pinfo *np; | 219 | struct ipv6_pinfo *np; |
244 | struct ipv6hdr *hdr = (struct ipv6hdr*)skb->data; | 220 | struct ipv6hdr *hdr = (struct ipv6hdr*)skb->data; |
@@ -248,8 +224,8 @@ static void udpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, | |||
248 | struct sock *sk; | 224 | struct sock *sk; |
249 | int err; | 225 | int err; |
250 | 226 | ||
251 | sk = udp_v6_lookup(daddr, uh->dest, saddr, uh->source, inet6_iif(skb)); | 227 | sk = __udp6_lib_lookup(daddr, uh->dest, |
252 | 228 | saddr, uh->source, inet6_iif(skb), udptable); | |
253 | if (sk == NULL) | 229 | if (sk == NULL) |
254 | return; | 230 | return; |
255 | 231 | ||
@@ -270,36 +246,60 @@ out: | |||
270 | sock_put(sk); | 246 | sock_put(sk); |
271 | } | 247 | } |
272 | 248 | ||
273 | static inline int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb) | 249 | static __inline__ void udpv6_err(struct sk_buff *skb, |
250 | struct inet6_skb_parm *opt, int type, | ||
251 | int code, int offset, __be32 info ) | ||
252 | { | ||
253 | return __udp6_lib_err(skb, opt, type, code, offset, info, udp_hash); | ||
254 | } | ||
255 | |||
256 | int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb) | ||
274 | { | 257 | { |
258 | struct udp_sock *up = udp_sk(sk); | ||
275 | int rc; | 259 | int rc; |
276 | 260 | ||
277 | if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) { | 261 | if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) |
278 | kfree_skb(skb); | 262 | goto drop; |
279 | return -1; | ||
280 | } | ||
281 | 263 | ||
282 | if (skb_checksum_complete(skb)) { | 264 | /* |
283 | UDP6_INC_STATS_BH(UDP_MIB_INERRORS); | 265 | * UDP-Lite specific tests, ignored on UDP sockets (see net/ipv4/udp.c). |
284 | kfree_skb(skb); | 266 | */ |
285 | return 0; | 267 | if ((up->pcflag & UDPLITE_RECV_CC) && UDP_SKB_CB(skb)->partial_cov) { |
268 | |||
269 | if (up->pcrlen == 0) { /* full coverage was set */ | ||
270 | LIMIT_NETDEBUG(KERN_WARNING "UDPLITE6: partial coverage" | ||
271 | " %d while full coverage %d requested\n", | ||
272 | UDP_SKB_CB(skb)->cscov, skb->len); | ||
273 | goto drop; | ||
274 | } | ||
275 | if (UDP_SKB_CB(skb)->cscov < up->pcrlen) { | ||
276 | LIMIT_NETDEBUG(KERN_WARNING "UDPLITE6: coverage %d " | ||
277 | "too small, need min %d\n", | ||
278 | UDP_SKB_CB(skb)->cscov, up->pcrlen); | ||
279 | goto drop; | ||
280 | } | ||
286 | } | 281 | } |
287 | 282 | ||
283 | if (udp_lib_checksum_complete(skb)) | ||
284 | goto drop; | ||
285 | |||
288 | if ((rc = sock_queue_rcv_skb(sk,skb)) < 0) { | 286 | if ((rc = sock_queue_rcv_skb(sk,skb)) < 0) { |
289 | /* Note that an ENOMEM error is charged twice */ | 287 | /* Note that an ENOMEM error is charged twice */ |
290 | if (rc == -ENOMEM) | 288 | if (rc == -ENOMEM) |
291 | UDP6_INC_STATS_BH(UDP_MIB_RCVBUFERRORS); | 289 | UDP6_INC_STATS_BH(UDP_MIB_RCVBUFERRORS, up->pcflag); |
292 | UDP6_INC_STATS_BH(UDP_MIB_INERRORS); | 290 | goto drop; |
293 | kfree_skb(skb); | ||
294 | return 0; | ||
295 | } | 291 | } |
296 | UDP6_INC_STATS_BH(UDP_MIB_INDATAGRAMS); | 292 | UDP6_INC_STATS_BH(UDP_MIB_INDATAGRAMS, up->pcflag); |
297 | return 0; | 293 | return 0; |
294 | drop: | ||
295 | UDP6_INC_STATS_BH(UDP_MIB_INERRORS, up->pcflag); | ||
296 | kfree_skb(skb); | ||
297 | return -1; | ||
298 | } | 298 | } |
299 | 299 | ||
300 | static struct sock *udp_v6_mcast_next(struct sock *sk, | 300 | static struct sock *udp_v6_mcast_next(struct sock *sk, |
301 | u16 loc_port, struct in6_addr *loc_addr, | 301 | __be16 loc_port, struct in6_addr *loc_addr, |
302 | u16 rmt_port, struct in6_addr *rmt_addr, | 302 | __be16 rmt_port, struct in6_addr *rmt_addr, |
303 | int dif) | 303 | int dif) |
304 | { | 304 | { |
305 | struct hlist_node *node; | 305 | struct hlist_node *node; |
@@ -338,15 +338,15 @@ static struct sock *udp_v6_mcast_next(struct sock *sk, | |||
338 | * Note: called only from the BH handler context, | 338 | * Note: called only from the BH handler context, |
339 | * so we don't need to lock the hashes. | 339 | * so we don't need to lock the hashes. |
340 | */ | 340 | */ |
341 | static void udpv6_mcast_deliver(struct udphdr *uh, | 341 | static int __udp6_lib_mcast_deliver(struct sk_buff *skb, struct in6_addr *saddr, |
342 | struct in6_addr *saddr, struct in6_addr *daddr, | 342 | struct in6_addr *daddr, struct hlist_head udptable[]) |
343 | struct sk_buff *skb) | ||
344 | { | 343 | { |
345 | struct sock *sk, *sk2; | 344 | struct sock *sk, *sk2; |
345 | const struct udphdr *uh = skb->h.uh; | ||
346 | int dif; | 346 | int dif; |
347 | 347 | ||
348 | read_lock(&udp_hash_lock); | 348 | read_lock(&udp_hash_lock); |
349 | sk = sk_head(&udp_hash[ntohs(uh->dest) & (UDP_HTABLE_SIZE - 1)]); | 349 | sk = sk_head(&udptable[ntohs(uh->dest) & (UDP_HTABLE_SIZE - 1)]); |
350 | dif = inet6_iif(skb); | 350 | dif = inet6_iif(skb); |
351 | sk = udp_v6_mcast_next(sk, uh->dest, daddr, uh->source, saddr, dif); | 351 | sk = udp_v6_mcast_next(sk, uh->dest, daddr, uh->source, saddr, dif); |
352 | if (!sk) { | 352 | if (!sk) { |
@@ -364,9 +364,35 @@ static void udpv6_mcast_deliver(struct udphdr *uh, | |||
364 | udpv6_queue_rcv_skb(sk, skb); | 364 | udpv6_queue_rcv_skb(sk, skb); |
365 | out: | 365 | out: |
366 | read_unlock(&udp_hash_lock); | 366 | read_unlock(&udp_hash_lock); |
367 | return 0; | ||
368 | } | ||
369 | |||
370 | static inline int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh) | ||
371 | |||
372 | { | ||
373 | if (uh->check == 0) { | ||
374 | /* RFC 2460 section 8.1 says that we SHOULD log | ||
375 | this error. Well, it is reasonable. | ||
376 | */ | ||
377 | LIMIT_NETDEBUG(KERN_INFO "IPv6: udp checksum is 0\n"); | ||
378 | return 1; | ||
379 | } | ||
380 | if (skb->ip_summed == CHECKSUM_COMPLETE && | ||
381 | !csum_ipv6_magic(&skb->nh.ipv6h->saddr, &skb->nh.ipv6h->daddr, | ||
382 | skb->len, IPPROTO_UDP, skb->csum )) | ||
383 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
384 | |||
385 | if (skb->ip_summed != CHECKSUM_UNNECESSARY) | ||
386 | skb->csum = ~csum_unfold(csum_ipv6_magic(&skb->nh.ipv6h->saddr, | ||
387 | &skb->nh.ipv6h->daddr, | ||
388 | skb->len, IPPROTO_UDP, | ||
389 | 0)); | ||
390 | |||
391 | return (UDP_SKB_CB(skb)->partial_cov = 0); | ||
367 | } | 392 | } |
368 | 393 | ||
369 | static int udpv6_rcv(struct sk_buff **pskb) | 394 | int __udp6_lib_rcv(struct sk_buff **pskb, struct hlist_head udptable[], |
395 | int is_udplite) | ||
370 | { | 396 | { |
371 | struct sk_buff *skb = *pskb; | 397 | struct sk_buff *skb = *pskb; |
372 | struct sock *sk; | 398 | struct sock *sk; |
@@ -383,44 +409,39 @@ static int udpv6_rcv(struct sk_buff **pskb) | |||
383 | uh = skb->h.uh; | 409 | uh = skb->h.uh; |
384 | 410 | ||
385 | ulen = ntohs(uh->len); | 411 | ulen = ntohs(uh->len); |
412 | if (ulen > skb->len) | ||
413 | goto short_packet; | ||
386 | 414 | ||
387 | /* Check for jumbo payload */ | 415 | if(! is_udplite ) { /* UDP validates ulen. */ |
388 | if (ulen == 0) | ||
389 | ulen = skb->len; | ||
390 | 416 | ||
391 | if (ulen > skb->len || ulen < sizeof(*uh)) | 417 | /* Check for jumbo payload */ |
392 | goto short_packet; | 418 | if (ulen == 0) |
419 | ulen = skb->len; | ||
393 | 420 | ||
394 | if (uh->check == 0) { | 421 | if (ulen < sizeof(*uh)) |
395 | /* RFC 2460 section 8.1 says that we SHOULD log | 422 | goto short_packet; |
396 | this error. Well, it is reasonable. | ||
397 | */ | ||
398 | LIMIT_NETDEBUG(KERN_INFO "IPv6: udp checksum is 0\n"); | ||
399 | goto discard; | ||
400 | } | ||
401 | 423 | ||
402 | if (ulen < skb->len) { | 424 | if (ulen < skb->len) { |
403 | if (pskb_trim_rcsum(skb, ulen)) | 425 | if (pskb_trim_rcsum(skb, ulen)) |
404 | goto discard; | 426 | goto short_packet; |
405 | saddr = &skb->nh.ipv6h->saddr; | 427 | saddr = &skb->nh.ipv6h->saddr; |
406 | daddr = &skb->nh.ipv6h->daddr; | 428 | daddr = &skb->nh.ipv6h->daddr; |
407 | uh = skb->h.uh; | 429 | uh = skb->h.uh; |
408 | } | 430 | } |
409 | 431 | ||
410 | if (skb->ip_summed == CHECKSUM_COMPLETE && | 432 | if (udp6_csum_init(skb, uh)) |
411 | !csum_ipv6_magic(saddr, daddr, ulen, IPPROTO_UDP, skb->csum)) | 433 | goto discard; |
412 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
413 | 434 | ||
414 | if (skb->ip_summed != CHECKSUM_UNNECESSARY) | 435 | } else { /* UDP-Lite validates cscov. */ |
415 | skb->csum = ~csum_ipv6_magic(saddr, daddr, ulen, IPPROTO_UDP, 0); | 436 | if (udplite6_csum_init(skb, uh)) |
437 | goto discard; | ||
438 | } | ||
416 | 439 | ||
417 | /* | 440 | /* |
418 | * Multicast receive code | 441 | * Multicast receive code |
419 | */ | 442 | */ |
420 | if (ipv6_addr_is_multicast(daddr)) { | 443 | if (ipv6_addr_is_multicast(daddr)) |
421 | udpv6_mcast_deliver(uh, saddr, daddr, skb); | 444 | return __udp6_lib_mcast_deliver(skb, saddr, daddr, udptable); |
422 | return 0; | ||
423 | } | ||
424 | 445 | ||
425 | /* Unicast */ | 446 | /* Unicast */ |
426 | 447 | ||
@@ -428,15 +449,16 @@ static int udpv6_rcv(struct sk_buff **pskb) | |||
428 | * check socket cache ... must talk to Alan about his plans | 449 | * check socket cache ... must talk to Alan about his plans |
429 | * for sock caches... i'll skip this for now. | 450 | * for sock caches... i'll skip this for now. |
430 | */ | 451 | */ |
431 | sk = udp_v6_lookup(saddr, uh->source, daddr, uh->dest, inet6_iif(skb)); | 452 | sk = __udp6_lib_lookup(saddr, uh->source, |
453 | daddr, uh->dest, inet6_iif(skb), udptable); | ||
432 | 454 | ||
433 | if (sk == NULL) { | 455 | if (sk == NULL) { |
434 | if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) | 456 | if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) |
435 | goto discard; | 457 | goto discard; |
436 | 458 | ||
437 | if (skb_checksum_complete(skb)) | 459 | if (udp_lib_checksum_complete(skb)) |
438 | goto discard; | 460 | goto discard; |
439 | UDP6_INC_STATS_BH(UDP_MIB_NOPORTS); | 461 | UDP6_INC_STATS_BH(UDP_MIB_NOPORTS, is_udplite); |
440 | 462 | ||
441 | icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev); | 463 | icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev); |
442 | 464 | ||
@@ -451,14 +473,20 @@ static int udpv6_rcv(struct sk_buff **pskb) | |||
451 | return(0); | 473 | return(0); |
452 | 474 | ||
453 | short_packet: | 475 | short_packet: |
454 | if (net_ratelimit()) | 476 | LIMIT_NETDEBUG(KERN_DEBUG "UDP%sv6: short packet: %d/%u\n", |
455 | printk(KERN_DEBUG "UDP: short packet: %d/%u\n", ulen, skb->len); | 477 | is_udplite? "-Lite" : "", ulen, skb->len); |
456 | 478 | ||
457 | discard: | 479 | discard: |
458 | UDP6_INC_STATS_BH(UDP_MIB_INERRORS); | 480 | UDP6_INC_STATS_BH(UDP_MIB_INERRORS, is_udplite); |
459 | kfree_skb(skb); | 481 | kfree_skb(skb); |
460 | return(0); | 482 | return(0); |
461 | } | 483 | } |
484 | |||
485 | static __inline__ int udpv6_rcv(struct sk_buff **pskb) | ||
486 | { | ||
487 | return __udp6_lib_rcv(pskb, udp_hash, 0); | ||
488 | } | ||
489 | |||
462 | /* | 490 | /* |
463 | * Throw away all pending data and cancel the corking. Socket is locked. | 491 | * Throw away all pending data and cancel the corking. Socket is locked. |
464 | */ | 492 | */ |
@@ -477,13 +505,15 @@ static void udp_v6_flush_pending_frames(struct sock *sk) | |||
477 | * Sending | 505 | * Sending |
478 | */ | 506 | */ |
479 | 507 | ||
480 | static int udp_v6_push_pending_frames(struct sock *sk, struct udp_sock *up) | 508 | static int udp_v6_push_pending_frames(struct sock *sk) |
481 | { | 509 | { |
482 | struct sk_buff *skb; | 510 | struct sk_buff *skb; |
483 | struct udphdr *uh; | 511 | struct udphdr *uh; |
512 | struct udp_sock *up = udp_sk(sk); | ||
484 | struct inet_sock *inet = inet_sk(sk); | 513 | struct inet_sock *inet = inet_sk(sk); |
485 | struct flowi *fl = &inet->cork.fl; | 514 | struct flowi *fl = &inet->cork.fl; |
486 | int err = 0; | 515 | int err = 0; |
516 | __wsum csum = 0; | ||
487 | 517 | ||
488 | /* Grab the skbuff where UDP header space exists. */ | 518 | /* Grab the skbuff where UDP header space exists. */ |
489 | if ((skb = skb_peek(&sk->sk_write_queue)) == NULL) | 519 | if ((skb = skb_peek(&sk->sk_write_queue)) == NULL) |
@@ -498,35 +528,17 @@ static int udp_v6_push_pending_frames(struct sock *sk, struct udp_sock *up) | |||
498 | uh->len = htons(up->len); | 528 | uh->len = htons(up->len); |
499 | uh->check = 0; | 529 | uh->check = 0; |
500 | 530 | ||
501 | if (sk->sk_no_check == UDP_CSUM_NOXMIT) { | 531 | if (up->pcflag) |
502 | skb->ip_summed = CHECKSUM_NONE; | 532 | csum = udplite_csum_outgoing(sk, skb); |
503 | goto send; | 533 | else |
504 | } | 534 | csum = udp_csum_outgoing(sk, skb); |
505 | |||
506 | if (skb_queue_len(&sk->sk_write_queue) == 1) { | ||
507 | skb->csum = csum_partial((char *)uh, | ||
508 | sizeof(struct udphdr), skb->csum); | ||
509 | uh->check = csum_ipv6_magic(&fl->fl6_src, | ||
510 | &fl->fl6_dst, | ||
511 | up->len, fl->proto, skb->csum); | ||
512 | } else { | ||
513 | u32 tmp_csum = 0; | ||
514 | |||
515 | skb_queue_walk(&sk->sk_write_queue, skb) { | ||
516 | tmp_csum = csum_add(tmp_csum, skb->csum); | ||
517 | } | ||
518 | tmp_csum = csum_partial((char *)uh, | ||
519 | sizeof(struct udphdr), tmp_csum); | ||
520 | tmp_csum = csum_ipv6_magic(&fl->fl6_src, | ||
521 | &fl->fl6_dst, | ||
522 | up->len, fl->proto, tmp_csum); | ||
523 | uh->check = tmp_csum; | ||
524 | 535 | ||
525 | } | 536 | /* add protocol-dependent pseudo-header */ |
537 | uh->check = csum_ipv6_magic(&fl->fl6_src, &fl->fl6_dst, | ||
538 | up->len, fl->proto, csum ); | ||
526 | if (uh->check == 0) | 539 | if (uh->check == 0) |
527 | uh->check = -1; | 540 | uh->check = CSUM_MANGLED_0; |
528 | 541 | ||
529 | send: | ||
530 | err = ip6_push_pending_frames(sk); | 542 | err = ip6_push_pending_frames(sk); |
531 | out: | 543 | out: |
532 | up->len = 0; | 544 | up->len = 0; |
@@ -534,7 +546,7 @@ out: | |||
534 | return err; | 546 | return err; |
535 | } | 547 | } |
536 | 548 | ||
537 | static int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk, | 549 | int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk, |
538 | struct msghdr *msg, size_t len) | 550 | struct msghdr *msg, size_t len) |
539 | { | 551 | { |
540 | struct ipv6_txoptions opt_space; | 552 | struct ipv6_txoptions opt_space; |
@@ -554,6 +566,8 @@ static int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk, | |||
554 | int corkreq = up->corkflag || msg->msg_flags&MSG_MORE; | 566 | int corkreq = up->corkflag || msg->msg_flags&MSG_MORE; |
555 | int err; | 567 | int err; |
556 | int connected = 0; | 568 | int connected = 0; |
569 | int is_udplite = up->pcflag; | ||
570 | int (*getfrag)(void *, char *, int, int, int, struct sk_buff *); | ||
557 | 571 | ||
558 | /* destination address check */ | 572 | /* destination address check */ |
559 | if (sin6) { | 573 | if (sin6) { |
@@ -694,7 +708,7 @@ do_udp_sendmsg: | |||
694 | opt = fl6_merge_options(&opt_space, flowlabel, opt); | 708 | opt = fl6_merge_options(&opt_space, flowlabel, opt); |
695 | opt = ipv6_fixup_options(&opt_space, opt); | 709 | opt = ipv6_fixup_options(&opt_space, opt); |
696 | 710 | ||
697 | fl.proto = IPPROTO_UDP; | 711 | fl.proto = sk->sk_protocol; |
698 | ipv6_addr_copy(&fl.fl6_dst, daddr); | 712 | ipv6_addr_copy(&fl.fl6_dst, daddr); |
699 | if (ipv6_addr_any(&fl.fl6_src) && !ipv6_addr_any(&np->saddr)) | 713 | if (ipv6_addr_any(&fl.fl6_src) && !ipv6_addr_any(&np->saddr)) |
700 | ipv6_addr_copy(&fl.fl6_src, &np->saddr); | 714 | ipv6_addr_copy(&fl.fl6_src, &np->saddr); |
@@ -761,14 +775,15 @@ back_from_confirm: | |||
761 | 775 | ||
762 | do_append_data: | 776 | do_append_data: |
763 | up->len += ulen; | 777 | up->len += ulen; |
764 | err = ip6_append_data(sk, ip_generic_getfrag, msg->msg_iov, ulen, | 778 | getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag; |
779 | err = ip6_append_data(sk, getfrag, msg->msg_iov, ulen, | ||
765 | sizeof(struct udphdr), hlimit, tclass, opt, &fl, | 780 | sizeof(struct udphdr), hlimit, tclass, opt, &fl, |
766 | (struct rt6_info*)dst, | 781 | (struct rt6_info*)dst, |
767 | corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags); | 782 | corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags); |
768 | if (err) | 783 | if (err) |
769 | udp_v6_flush_pending_frames(sk); | 784 | udp_v6_flush_pending_frames(sk); |
770 | else if (!corkreq) | 785 | else if (!corkreq) |
771 | err = udp_v6_push_pending_frames(sk, up); | 786 | err = udp_v6_push_pending_frames(sk); |
772 | else if (unlikely(skb_queue_empty(&sk->sk_write_queue))) | 787 | else if (unlikely(skb_queue_empty(&sk->sk_write_queue))) |
773 | up->pending = 0; | 788 | up->pending = 0; |
774 | 789 | ||
@@ -793,7 +808,7 @@ do_append_data: | |||
793 | out: | 808 | out: |
794 | fl6_sock_release(flowlabel); | 809 | fl6_sock_release(flowlabel); |
795 | if (!err) { | 810 | if (!err) { |
796 | UDP6_INC_STATS_USER(UDP_MIB_OUTDATAGRAMS); | 811 | UDP6_INC_STATS_USER(UDP_MIB_OUTDATAGRAMS, is_udplite); |
797 | return len; | 812 | return len; |
798 | } | 813 | } |
799 | /* | 814 | /* |
@@ -804,7 +819,7 @@ out: | |||
804 | * seems like overkill. | 819 | * seems like overkill. |
805 | */ | 820 | */ |
806 | if (err == -ENOBUFS || test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) { | 821 | if (err == -ENOBUFS || test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) { |
807 | UDP6_INC_STATS_USER(UDP_MIB_SNDBUFERRORS); | 822 | UDP6_INC_STATS_USER(UDP_MIB_SNDBUFERRORS, is_udplite); |
808 | } | 823 | } |
809 | return err; | 824 | return err; |
810 | 825 | ||
@@ -816,7 +831,7 @@ do_confirm: | |||
816 | goto out; | 831 | goto out; |
817 | } | 832 | } |
818 | 833 | ||
819 | static int udpv6_destroy_sock(struct sock *sk) | 834 | int udpv6_destroy_sock(struct sock *sk) |
820 | { | 835 | { |
821 | lock_sock(sk); | 836 | lock_sock(sk); |
822 | udp_v6_flush_pending_frames(sk); | 837 | udp_v6_flush_pending_frames(sk); |
@@ -830,119 +845,41 @@ static int udpv6_destroy_sock(struct sock *sk) | |||
830 | /* | 845 | /* |
831 | * Socket option code for UDP | 846 | * Socket option code for UDP |
832 | */ | 847 | */ |
833 | static int do_udpv6_setsockopt(struct sock *sk, int level, int optname, | 848 | int udpv6_setsockopt(struct sock *sk, int level, int optname, |
834 | char __user *optval, int optlen) | 849 | char __user *optval, int optlen) |
835 | { | ||
836 | struct udp_sock *up = udp_sk(sk); | ||
837 | int val; | ||
838 | int err = 0; | ||
839 | |||
840 | if(optlen<sizeof(int)) | ||
841 | return -EINVAL; | ||
842 | |||
843 | if (get_user(val, (int __user *)optval)) | ||
844 | return -EFAULT; | ||
845 | |||
846 | switch(optname) { | ||
847 | case UDP_CORK: | ||
848 | if (val != 0) { | ||
849 | up->corkflag = 1; | ||
850 | } else { | ||
851 | up->corkflag = 0; | ||
852 | lock_sock(sk); | ||
853 | udp_v6_push_pending_frames(sk, up); | ||
854 | release_sock(sk); | ||
855 | } | ||
856 | break; | ||
857 | |||
858 | case UDP_ENCAP: | ||
859 | switch (val) { | ||
860 | case 0: | ||
861 | up->encap_type = val; | ||
862 | break; | ||
863 | default: | ||
864 | err = -ENOPROTOOPT; | ||
865 | break; | ||
866 | } | ||
867 | break; | ||
868 | |||
869 | default: | ||
870 | err = -ENOPROTOOPT; | ||
871 | break; | ||
872 | }; | ||
873 | |||
874 | return err; | ||
875 | } | ||
876 | |||
877 | static int udpv6_setsockopt(struct sock *sk, int level, int optname, | ||
878 | char __user *optval, int optlen) | ||
879 | { | 850 | { |
880 | if (level != SOL_UDP) | 851 | if (level == SOL_UDP || level == SOL_UDPLITE) |
881 | return ipv6_setsockopt(sk, level, optname, optval, optlen); | 852 | return udp_lib_setsockopt(sk, level, optname, optval, optlen, |
882 | return do_udpv6_setsockopt(sk, level, optname, optval, optlen); | 853 | udp_v6_push_pending_frames); |
854 | return ipv6_setsockopt(sk, level, optname, optval, optlen); | ||
883 | } | 855 | } |
884 | 856 | ||
885 | #ifdef CONFIG_COMPAT | 857 | #ifdef CONFIG_COMPAT |
886 | static int compat_udpv6_setsockopt(struct sock *sk, int level, int optname, | 858 | int compat_udpv6_setsockopt(struct sock *sk, int level, int optname, |
887 | char __user *optval, int optlen) | 859 | char __user *optval, int optlen) |
888 | { | 860 | { |
889 | if (level != SOL_UDP) | 861 | if (level == SOL_UDP || level == SOL_UDPLITE) |
890 | return compat_ipv6_setsockopt(sk, level, optname, | 862 | return udp_lib_setsockopt(sk, level, optname, optval, optlen, |
891 | optval, optlen); | 863 | udp_v6_push_pending_frames); |
892 | return do_udpv6_setsockopt(sk, level, optname, optval, optlen); | 864 | return compat_ipv6_setsockopt(sk, level, optname, optval, optlen); |
893 | } | 865 | } |
894 | #endif | 866 | #endif |
895 | 867 | ||
896 | static int do_udpv6_getsockopt(struct sock *sk, int level, int optname, | 868 | int udpv6_getsockopt(struct sock *sk, int level, int optname, |
897 | char __user *optval, int __user *optlen) | 869 | char __user *optval, int __user *optlen) |
898 | { | ||
899 | struct udp_sock *up = udp_sk(sk); | ||
900 | int val, len; | ||
901 | |||
902 | if(get_user(len,optlen)) | ||
903 | return -EFAULT; | ||
904 | |||
905 | len = min_t(unsigned int, len, sizeof(int)); | ||
906 | |||
907 | if(len < 0) | ||
908 | return -EINVAL; | ||
909 | |||
910 | switch(optname) { | ||
911 | case UDP_CORK: | ||
912 | val = up->corkflag; | ||
913 | break; | ||
914 | |||
915 | case UDP_ENCAP: | ||
916 | val = up->encap_type; | ||
917 | break; | ||
918 | |||
919 | default: | ||
920 | return -ENOPROTOOPT; | ||
921 | }; | ||
922 | |||
923 | if(put_user(len, optlen)) | ||
924 | return -EFAULT; | ||
925 | if(copy_to_user(optval, &val,len)) | ||
926 | return -EFAULT; | ||
927 | return 0; | ||
928 | } | ||
929 | |||
930 | static int udpv6_getsockopt(struct sock *sk, int level, int optname, | ||
931 | char __user *optval, int __user *optlen) | ||
932 | { | 870 | { |
933 | if (level != SOL_UDP) | 871 | if (level == SOL_UDP || level == SOL_UDPLITE) |
934 | return ipv6_getsockopt(sk, level, optname, optval, optlen); | 872 | return udp_lib_getsockopt(sk, level, optname, optval, optlen); |
935 | return do_udpv6_getsockopt(sk, level, optname, optval, optlen); | 873 | return ipv6_getsockopt(sk, level, optname, optval, optlen); |
936 | } | 874 | } |
937 | 875 | ||
938 | #ifdef CONFIG_COMPAT | 876 | #ifdef CONFIG_COMPAT |
939 | static int compat_udpv6_getsockopt(struct sock *sk, int level, int optname, | 877 | int compat_udpv6_getsockopt(struct sock *sk, int level, int optname, |
940 | char __user *optval, int __user *optlen) | 878 | char __user *optval, int __user *optlen) |
941 | { | 879 | { |
942 | if (level != SOL_UDP) | 880 | if (level == SOL_UDP || level == SOL_UDPLITE) |
943 | return compat_ipv6_getsockopt(sk, level, optname, | 881 | return udp_lib_getsockopt(sk, level, optname, optval, optlen); |
944 | optval, optlen); | 882 | return compat_ipv6_getsockopt(sk, level, optname, optval, optlen); |
945 | return do_udpv6_getsockopt(sk, level, optname, optval, optlen); | ||
946 | } | 883 | } |
947 | #endif | 884 | #endif |
948 | 885 | ||
@@ -983,7 +920,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket | |||
983 | atomic_read(&sp->sk_refcnt), sp); | 920 | atomic_read(&sp->sk_refcnt), sp); |
984 | } | 921 | } |
985 | 922 | ||
986 | static int udp6_seq_show(struct seq_file *seq, void *v) | 923 | int udp6_seq_show(struct seq_file *seq, void *v) |
987 | { | 924 | { |
988 | if (v == SEQ_START_TOKEN) | 925 | if (v == SEQ_START_TOKEN) |
989 | seq_printf(seq, | 926 | seq_printf(seq, |
@@ -1002,6 +939,7 @@ static struct udp_seq_afinfo udp6_seq_afinfo = { | |||
1002 | .owner = THIS_MODULE, | 939 | .owner = THIS_MODULE, |
1003 | .name = "udp6", | 940 | .name = "udp6", |
1004 | .family = AF_INET6, | 941 | .family = AF_INET6, |
942 | .hashtable = udp_hash, | ||
1005 | .seq_show = udp6_seq_show, | 943 | .seq_show = udp6_seq_show, |
1006 | .seq_fops = &udp6_seq_fops, | 944 | .seq_fops = &udp6_seq_fops, |
1007 | }; | 945 | }; |
@@ -1021,7 +959,7 @@ void udp6_proc_exit(void) { | |||
1021 | struct proto udpv6_prot = { | 959 | struct proto udpv6_prot = { |
1022 | .name = "UDPv6", | 960 | .name = "UDPv6", |
1023 | .owner = THIS_MODULE, | 961 | .owner = THIS_MODULE, |
1024 | .close = udpv6_close, | 962 | .close = udp_lib_close, |
1025 | .connect = ip6_datagram_connect, | 963 | .connect = ip6_datagram_connect, |
1026 | .disconnect = udp_disconnect, | 964 | .disconnect = udp_disconnect, |
1027 | .ioctl = udp_ioctl, | 965 | .ioctl = udp_ioctl, |
@@ -1031,8 +969,8 @@ struct proto udpv6_prot = { | |||
1031 | .sendmsg = udpv6_sendmsg, | 969 | .sendmsg = udpv6_sendmsg, |
1032 | .recvmsg = udpv6_recvmsg, | 970 | .recvmsg = udpv6_recvmsg, |
1033 | .backlog_rcv = udpv6_queue_rcv_skb, | 971 | .backlog_rcv = udpv6_queue_rcv_skb, |
1034 | .hash = udp_v6_hash, | 972 | .hash = udp_lib_hash, |
1035 | .unhash = udp_v6_unhash, | 973 | .unhash = udp_lib_unhash, |
1036 | .get_port = udp_v6_get_port, | 974 | .get_port = udp_v6_get_port, |
1037 | .obj_size = sizeof(struct udp6_sock), | 975 | .obj_size = sizeof(struct udp6_sock), |
1038 | #ifdef CONFIG_COMPAT | 976 | #ifdef CONFIG_COMPAT |