3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
8 * Based on linux/ipv4/udp.c
11 * Hideaki YOSHIFUJI : sin6_scope_id support
12 * YOSHIFUJI Hideaki @USAGI and: Support IPV6_V6ONLY socket option, which
13 * Alexey Kuznetsov allow both IPv4 and IPv6 sockets to bind
14 * a single port at the same time.
15 * Kazunori MIYAZAWA @USAGI: change process style to use ip6_append_data
16 * YOSHIFUJI Hideaki @USAGI: convert /proc/net/udp6 to seq_file.
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
24 #include <linux/errno.h>
25 #include <linux/types.h>
26 #include <linux/socket.h>
27 #include <linux/sockios.h>
28 #include <linux/net.h>
29 #include <linux/in6.h>
30 #include <linux/netdevice.h>
31 #include <linux/if_arp.h>
32 #include <linux/ipv6.h>
33 #include <linux/icmpv6.h>
34 #include <linux/init.h>
35 #include <linux/module.h>
36 #include <linux/skbuff.h>
37 #include <asm/uaccess.h>
39 #include <net/ndisc.h>
40 #include <net/protocol.h>
41 #include <net/transp_v6.h>
42 #include <net/ip6_route.h>
44 #include <net/tcp_states.h>
45 #include <net/ip6_checksum.h>
48 #include <linux/proc_fs.h>
49 #include <linux/seq_file.h>
52 int udp_v6_get_port(struct sock
*sk
, unsigned short snum
)
54 return udp_lib_get_port(sk
, snum
, ipv6_rcv_saddr_equal
);
57 static struct sock
*__udp6_lib_lookup(struct net
*net
,
58 struct in6_addr
*saddr
, __be16 sport
,
59 struct in6_addr
*daddr
, __be16 dport
,
60 int dif
, struct hlist_head udptable
[])
62 struct sock
*sk
, *result
= NULL
;
63 struct hlist_node
*node
;
64 unsigned short hnum
= ntohs(dport
);
67 read_lock(&udp_hash_lock
);
68 sk_for_each(sk
, node
, &udptable
[udp_hashfn(net
, hnum
)]) {
69 struct inet_sock
*inet
= inet_sk(sk
);
71 if (net_eq(sock_net(sk
), net
) && sk
->sk_hash
== hnum
&&
72 sk
->sk_family
== PF_INET6
) {
73 struct ipv6_pinfo
*np
= inet6_sk(sk
);
76 if (inet
->dport
!= sport
)
80 if (!ipv6_addr_any(&np
->rcv_saddr
)) {
81 if (!ipv6_addr_equal(&np
->rcv_saddr
, daddr
))
85 if (!ipv6_addr_any(&np
->daddr
)) {
86 if (!ipv6_addr_equal(&np
->daddr
, saddr
))
90 if (sk
->sk_bound_dev_if
) {
91 if (sk
->sk_bound_dev_if
!= dif
)
98 } else if (score
> badness
) {
106 read_unlock(&udp_hash_lock
);
111 * This should be easy, if there is something there we
112 * return it, otherwise we block.
115 int udpv6_recvmsg(struct kiocb
*iocb
, struct sock
*sk
,
116 struct msghdr
*msg
, size_t len
,
117 int noblock
, int flags
, int *addr_len
)
119 struct ipv6_pinfo
*np
= inet6_sk(sk
);
120 struct inet_sock
*inet
= inet_sk(sk
);
122 unsigned int ulen
, copied
;
125 int is_udplite
= IS_UDPLITE(sk
);
128 *addr_len
=sizeof(struct sockaddr_in6
);
130 if (flags
& MSG_ERRQUEUE
)
131 return ipv6_recv_error(sk
, msg
, len
);
134 skb
= __skb_recv_datagram(sk
, flags
| (noblock
? MSG_DONTWAIT
: 0),
139 ulen
= skb
->len
- sizeof(struct udphdr
);
143 else if (copied
< ulen
)
144 msg
->msg_flags
|= MSG_TRUNC
;
147 * If checksum is needed at all, try to do it while copying the
148 * data. If the data is truncated, or if we only want a partial
149 * coverage checksum (UDP-Lite), do it before the copy.
152 if (copied
< ulen
|| UDP_SKB_CB(skb
)->partial_cov
) {
153 if (udp_lib_checksum_complete(skb
))
157 if (skb_csum_unnecessary(skb
))
158 err
= skb_copy_datagram_iovec(skb
, sizeof(struct udphdr
),
159 msg
->msg_iov
, copied
);
161 err
= skb_copy_and_csum_datagram_iovec(skb
, sizeof(struct udphdr
), msg
->msg_iov
);
169 UDP6_INC_STATS_USER(sock_net(sk
),
170 UDP_MIB_INDATAGRAMS
, is_udplite
);
172 sock_recv_timestamp(msg
, sk
, skb
);
174 /* Copy the address. */
176 struct sockaddr_in6
*sin6
;
178 sin6
= (struct sockaddr_in6
*) msg
->msg_name
;
179 sin6
->sin6_family
= AF_INET6
;
180 sin6
->sin6_port
= udp_hdr(skb
)->source
;
181 sin6
->sin6_flowinfo
= 0;
182 sin6
->sin6_scope_id
= 0;
184 if (skb
->protocol
== htons(ETH_P_IP
))
185 ipv6_addr_set(&sin6
->sin6_addr
, 0, 0,
186 htonl(0xffff), ip_hdr(skb
)->saddr
);
188 ipv6_addr_copy(&sin6
->sin6_addr
,
189 &ipv6_hdr(skb
)->saddr
);
190 if (ipv6_addr_type(&sin6
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
)
191 sin6
->sin6_scope_id
= IP6CB(skb
)->iif
;
195 if (skb
->protocol
== htons(ETH_P_IP
)) {
196 if (inet
->cmsg_flags
)
197 ip_cmsg_recv(msg
, skb
);
200 datagram_recv_ctl(sk
, msg
, skb
);
204 if (flags
& MSG_TRUNC
)
209 skb_free_datagram(sk
, skb
);
216 if (!skb_kill_datagram(sk
, skb
, flags
))
217 UDP6_INC_STATS_USER(sock_net(sk
), UDP_MIB_INERRORS
, is_udplite
);
220 if (flags
& MSG_DONTWAIT
)
225 void __udp6_lib_err(struct sk_buff
*skb
, struct inet6_skb_parm
*opt
,
226 int type
, int code
, int offset
, __be32 info
,
227 struct hlist_head udptable
[] )
229 struct ipv6_pinfo
*np
;
230 struct ipv6hdr
*hdr
= (struct ipv6hdr
*)skb
->data
;
231 struct in6_addr
*saddr
= &hdr
->saddr
;
232 struct in6_addr
*daddr
= &hdr
->daddr
;
233 struct udphdr
*uh
= (struct udphdr
*)(skb
->data
+offset
);
237 sk
= __udp6_lib_lookup(dev_net(skb
->dev
), daddr
, uh
->dest
,
238 saddr
, uh
->source
, inet6_iif(skb
), udptable
);
244 if (!icmpv6_err_convert(type
, code
, &err
) && !np
->recverr
)
247 if (sk
->sk_state
!= TCP_ESTABLISHED
&& !np
->recverr
)
251 ipv6_icmp_error(sk
, skb
, err
, uh
->dest
, ntohl(info
), (u8
*)(uh
+1));
254 sk
->sk_error_report(sk
);
259 static __inline__
void udpv6_err(struct sk_buff
*skb
,
260 struct inet6_skb_parm
*opt
, int type
,
261 int code
, int offset
, __be32 info
)
263 __udp6_lib_err(skb
, opt
, type
, code
, offset
, info
, udp_hash
);
266 int udpv6_queue_rcv_skb(struct sock
* sk
, struct sk_buff
*skb
)
268 struct udp_sock
*up
= udp_sk(sk
);
270 int is_udplite
= IS_UDPLITE(sk
);
272 if (!xfrm6_policy_check(sk
, XFRM_POLICY_IN
, skb
))
276 * UDP-Lite specific tests, ignored on UDP sockets (see net/ipv4/udp.c).
278 if ((is_udplite
& UDPLITE_RECV_CC
) && UDP_SKB_CB(skb
)->partial_cov
) {
280 if (up
->pcrlen
== 0) { /* full coverage was set */
281 LIMIT_NETDEBUG(KERN_WARNING
"UDPLITE6: partial coverage"
282 " %d while full coverage %d requested\n",
283 UDP_SKB_CB(skb
)->cscov
, skb
->len
);
286 if (UDP_SKB_CB(skb
)->cscov
< up
->pcrlen
) {
287 LIMIT_NETDEBUG(KERN_WARNING
"UDPLITE6: coverage %d "
288 "too small, need min %d\n",
289 UDP_SKB_CB(skb
)->cscov
, up
->pcrlen
);
295 if (udp_lib_checksum_complete(skb
))
299 if ((rc
= sock_queue_rcv_skb(sk
,skb
)) < 0) {
300 /* Note that an ENOMEM error is charged twice */
302 UDP6_INC_STATS_BH(sock_net(sk
),
303 UDP_MIB_RCVBUFERRORS
, is_udplite
);
304 atomic_inc(&sk
->sk_drops
);
311 UDP6_INC_STATS_BH(sock_net(sk
), UDP_MIB_INERRORS
, is_udplite
);
316 static struct sock
*udp_v6_mcast_next(struct sock
*sk
,
317 __be16 loc_port
, struct in6_addr
*loc_addr
,
318 __be16 rmt_port
, struct in6_addr
*rmt_addr
,
321 struct hlist_node
*node
;
323 unsigned short num
= ntohs(loc_port
);
325 sk_for_each_from(s
, node
) {
326 struct inet_sock
*inet
= inet_sk(s
);
328 if (sock_net(s
) != sock_net(sk
))
331 if (s
->sk_hash
== num
&& s
->sk_family
== PF_INET6
) {
332 struct ipv6_pinfo
*np
= inet6_sk(s
);
334 if (inet
->dport
!= rmt_port
)
337 if (!ipv6_addr_any(&np
->daddr
) &&
338 !ipv6_addr_equal(&np
->daddr
, rmt_addr
))
341 if (s
->sk_bound_dev_if
&& s
->sk_bound_dev_if
!= dif
)
344 if (!ipv6_addr_any(&np
->rcv_saddr
)) {
345 if (!ipv6_addr_equal(&np
->rcv_saddr
, loc_addr
))
348 if (!inet6_mc_check(s
, loc_addr
, rmt_addr
))
357 * Note: called only from the BH handler context,
358 * so we don't need to lock the hashes.
360 static int __udp6_lib_mcast_deliver(struct net
*net
, struct sk_buff
*skb
,
361 struct in6_addr
*saddr
, struct in6_addr
*daddr
,
362 struct hlist_head udptable
[])
364 struct sock
*sk
, *sk2
;
365 const struct udphdr
*uh
= udp_hdr(skb
);
368 read_lock(&udp_hash_lock
);
369 sk
= sk_head(&udptable
[udp_hashfn(net
, ntohs(uh
->dest
))]);
370 dif
= inet6_iif(skb
);
371 sk
= udp_v6_mcast_next(sk
, uh
->dest
, daddr
, uh
->source
, saddr
, dif
);
378 while ((sk2
= udp_v6_mcast_next(sk_next(sk2
), uh
->dest
, daddr
,
379 uh
->source
, saddr
, dif
))) {
380 struct sk_buff
*buff
= skb_clone(skb
, GFP_ATOMIC
);
383 if (!sock_owned_by_user(sk2
))
384 udpv6_queue_rcv_skb(sk2
, buff
);
386 sk_add_backlog(sk2
, buff
);
391 if (!sock_owned_by_user(sk
))
392 udpv6_queue_rcv_skb(sk
, skb
);
394 sk_add_backlog(sk
, skb
);
397 read_unlock(&udp_hash_lock
);
401 static inline int udp6_csum_init(struct sk_buff
*skb
, struct udphdr
*uh
,
406 UDP_SKB_CB(skb
)->partial_cov
= 0;
407 UDP_SKB_CB(skb
)->cscov
= skb
->len
;
409 if (proto
== IPPROTO_UDPLITE
) {
410 err
= udplite_checksum_init(skb
, uh
);
415 if (uh
->check
== 0) {
416 /* RFC 2460 section 8.1 says that we SHOULD log
417 this error. Well, it is reasonable.
419 LIMIT_NETDEBUG(KERN_INFO
"IPv6: udp checksum is 0\n");
422 if (skb
->ip_summed
== CHECKSUM_COMPLETE
&&
423 !csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
, &ipv6_hdr(skb
)->daddr
,
424 skb
->len
, proto
, skb
->csum
))
425 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
427 if (!skb_csum_unnecessary(skb
))
428 skb
->csum
= ~csum_unfold(csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
429 &ipv6_hdr(skb
)->daddr
,
430 skb
->len
, proto
, 0));
435 int __udp6_lib_rcv(struct sk_buff
*skb
, struct hlist_head udptable
[],
440 struct net_device
*dev
= skb
->dev
;
441 struct in6_addr
*saddr
, *daddr
;
443 struct net
*net
= dev_net(skb
->dev
);
445 if (!pskb_may_pull(skb
, sizeof(struct udphdr
)))
448 saddr
= &ipv6_hdr(skb
)->saddr
;
449 daddr
= &ipv6_hdr(skb
)->daddr
;
452 ulen
= ntohs(uh
->len
);
456 if (proto
== IPPROTO_UDP
) {
457 /* UDP validates ulen. */
459 /* Check for jumbo payload */
463 if (ulen
< sizeof(*uh
))
466 if (ulen
< skb
->len
) {
467 if (pskb_trim_rcsum(skb
, ulen
))
469 saddr
= &ipv6_hdr(skb
)->saddr
;
470 daddr
= &ipv6_hdr(skb
)->daddr
;
475 if (udp6_csum_init(skb
, uh
, proto
))
479 * Multicast receive code
481 if (ipv6_addr_is_multicast(daddr
))
482 return __udp6_lib_mcast_deliver(net
, skb
,
483 saddr
, daddr
, udptable
);
488 * check socket cache ... must talk to Alan about his plans
489 * for sock caches... i'll skip this for now.
491 sk
= __udp6_lib_lookup(net
, saddr
, uh
->source
,
492 daddr
, uh
->dest
, inet6_iif(skb
), udptable
);
495 if (!xfrm6_policy_check(NULL
, XFRM_POLICY_IN
, skb
))
498 if (udp_lib_checksum_complete(skb
))
500 UDP6_INC_STATS_BH(net
, UDP_MIB_NOPORTS
,
501 proto
== IPPROTO_UDPLITE
);
503 icmpv6_send(skb
, ICMPV6_DEST_UNREACH
, ICMPV6_PORT_UNREACH
, 0, dev
);
512 if (!sock_owned_by_user(sk
))
513 udpv6_queue_rcv_skb(sk
, skb
);
515 sk_add_backlog(sk
, skb
);
521 LIMIT_NETDEBUG(KERN_DEBUG
"UDP%sv6: short packet: %d/%u\n",
522 proto
== IPPROTO_UDPLITE
? "-Lite" : "",
526 UDP6_INC_STATS_BH(net
, UDP_MIB_INERRORS
, proto
== IPPROTO_UDPLITE
);
531 static __inline__
int udpv6_rcv(struct sk_buff
*skb
)
533 return __udp6_lib_rcv(skb
, udp_hash
, IPPROTO_UDP
);
537 * Throw away all pending data and cancel the corking. Socket is locked.
539 static void udp_v6_flush_pending_frames(struct sock
*sk
)
541 struct udp_sock
*up
= udp_sk(sk
);
543 if (up
->pending
== AF_INET
)
544 udp_flush_pending_frames(sk
);
545 else if (up
->pending
) {
548 ip6_flush_pending_frames(sk
);
556 static int udp_v6_push_pending_frames(struct sock
*sk
)
560 struct udp_sock
*up
= udp_sk(sk
);
561 struct inet_sock
*inet
= inet_sk(sk
);
562 struct flowi
*fl
= &inet
->cork
.fl
;
564 int is_udplite
= IS_UDPLITE(sk
);
567 /* Grab the skbuff where UDP header space exists. */
568 if ((skb
= skb_peek(&sk
->sk_write_queue
)) == NULL
)
572 * Create a UDP header
575 uh
->source
= fl
->fl_ip_sport
;
576 uh
->dest
= fl
->fl_ip_dport
;
577 uh
->len
= htons(up
->len
);
581 csum
= udplite_csum_outgoing(sk
, skb
);
583 csum
= udp_csum_outgoing(sk
, skb
);
585 /* add protocol-dependent pseudo-header */
586 uh
->check
= csum_ipv6_magic(&fl
->fl6_src
, &fl
->fl6_dst
,
587 up
->len
, fl
->proto
, csum
);
589 uh
->check
= CSUM_MANGLED_0
;
591 err
= ip6_push_pending_frames(sk
);
596 UDP6_INC_STATS_USER(sock_net(sk
),
597 UDP_MIB_OUTDATAGRAMS
, is_udplite
);
601 int udpv6_sendmsg(struct kiocb
*iocb
, struct sock
*sk
,
602 struct msghdr
*msg
, size_t len
)
604 struct ipv6_txoptions opt_space
;
605 struct udp_sock
*up
= udp_sk(sk
);
606 struct inet_sock
*inet
= inet_sk(sk
);
607 struct ipv6_pinfo
*np
= inet6_sk(sk
);
608 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*) msg
->msg_name
;
609 struct in6_addr
*daddr
, *final_p
= NULL
, final
;
610 struct ipv6_txoptions
*opt
= NULL
;
611 struct ip6_flowlabel
*flowlabel
= NULL
;
613 struct dst_entry
*dst
;
614 int addr_len
= msg
->msg_namelen
;
618 int corkreq
= up
->corkflag
|| msg
->msg_flags
&MSG_MORE
;
621 int is_udplite
= IS_UDPLITE(sk
);
622 int (*getfrag
)(void *, char *, int, int, int, struct sk_buff
*);
624 /* destination address check */
626 if (addr_len
< offsetof(struct sockaddr
, sa_data
))
629 switch (sin6
->sin6_family
) {
631 if (addr_len
< SIN6_LEN_RFC2133
)
633 daddr
= &sin6
->sin6_addr
;
638 msg
->msg_name
= sin6
= NULL
;
639 msg
->msg_namelen
= addr_len
= 0;
645 } else if (!up
->pending
) {
646 if (sk
->sk_state
!= TCP_ESTABLISHED
)
647 return -EDESTADDRREQ
;
653 if (ipv6_addr_v4mapped(daddr
)) {
654 struct sockaddr_in sin
;
655 sin
.sin_family
= AF_INET
;
656 sin
.sin_port
= sin6
? sin6
->sin6_port
: inet
->dport
;
657 sin
.sin_addr
.s_addr
= daddr
->s6_addr32
[3];
658 msg
->msg_name
= &sin
;
659 msg
->msg_namelen
= sizeof(sin
);
661 if (__ipv6_only_sock(sk
))
663 return udp_sendmsg(iocb
, sk
, msg
, len
);
667 if (up
->pending
== AF_INET
)
668 return udp_sendmsg(iocb
, sk
, msg
, len
);
670 /* Rough check on arithmetic overflow,
671 better check is made in ip6_append_data().
673 if (len
> INT_MAX
- sizeof(struct udphdr
))
678 * There are pending frames.
679 * The socket lock must be held while it's corked.
682 if (likely(up
->pending
)) {
683 if (unlikely(up
->pending
!= AF_INET6
)) {
685 return -EAFNOSUPPORT
;
692 ulen
+= sizeof(struct udphdr
);
694 memset(&fl
, 0, sizeof(fl
));
697 if (sin6
->sin6_port
== 0)
700 fl
.fl_ip_dport
= sin6
->sin6_port
;
701 daddr
= &sin6
->sin6_addr
;
704 fl
.fl6_flowlabel
= sin6
->sin6_flowinfo
&IPV6_FLOWINFO_MASK
;
705 if (fl
.fl6_flowlabel
&IPV6_FLOWLABEL_MASK
) {
706 flowlabel
= fl6_sock_lookup(sk
, fl
.fl6_flowlabel
);
707 if (flowlabel
== NULL
)
709 daddr
= &flowlabel
->dst
;
714 * Otherwise it will be difficult to maintain
717 if (sk
->sk_state
== TCP_ESTABLISHED
&&
718 ipv6_addr_equal(daddr
, &np
->daddr
))
721 if (addr_len
>= sizeof(struct sockaddr_in6
) &&
722 sin6
->sin6_scope_id
&&
723 ipv6_addr_type(daddr
)&IPV6_ADDR_LINKLOCAL
)
724 fl
.oif
= sin6
->sin6_scope_id
;
726 if (sk
->sk_state
!= TCP_ESTABLISHED
)
727 return -EDESTADDRREQ
;
729 fl
.fl_ip_dport
= inet
->dport
;
731 fl
.fl6_flowlabel
= np
->flow_label
;
736 fl
.oif
= sk
->sk_bound_dev_if
;
738 if (msg
->msg_controllen
) {
740 memset(opt
, 0, sizeof(struct ipv6_txoptions
));
741 opt
->tot_len
= sizeof(*opt
);
743 err
= datagram_send_ctl(sock_net(sk
), msg
, &fl
, opt
, &hlimit
, &tclass
);
745 fl6_sock_release(flowlabel
);
748 if ((fl
.fl6_flowlabel
&IPV6_FLOWLABEL_MASK
) && !flowlabel
) {
749 flowlabel
= fl6_sock_lookup(sk
, fl
.fl6_flowlabel
);
750 if (flowlabel
== NULL
)
753 if (!(opt
->opt_nflen
|opt
->opt_flen
))
760 opt
= fl6_merge_options(&opt_space
, flowlabel
, opt
);
761 opt
= ipv6_fixup_options(&opt_space
, opt
);
763 fl
.proto
= sk
->sk_protocol
;
764 if (!ipv6_addr_any(daddr
))
765 ipv6_addr_copy(&fl
.fl6_dst
, daddr
);
767 fl
.fl6_dst
.s6_addr
[15] = 0x1; /* :: means loopback (BSD'ism) */
768 if (ipv6_addr_any(&fl
.fl6_src
) && !ipv6_addr_any(&np
->saddr
))
769 ipv6_addr_copy(&fl
.fl6_src
, &np
->saddr
);
770 fl
.fl_ip_sport
= inet
->sport
;
772 /* merge ip6_build_xmit from ip6_output */
773 if (opt
&& opt
->srcrt
) {
774 struct rt0_hdr
*rt0
= (struct rt0_hdr
*) opt
->srcrt
;
775 ipv6_addr_copy(&final
, &fl
.fl6_dst
);
776 ipv6_addr_copy(&fl
.fl6_dst
, rt0
->addr
);
781 if (!fl
.oif
&& ipv6_addr_is_multicast(&fl
.fl6_dst
)) {
782 fl
.oif
= np
->mcast_oif
;
786 security_sk_classify_flow(sk
, &fl
);
788 err
= ip6_sk_dst_lookup(sk
, &dst
, &fl
);
792 ipv6_addr_copy(&fl
.fl6_dst
, final_p
);
794 if ((err
= __xfrm_lookup(&dst
, &fl
, sk
, XFRM_LOOKUP_WAIT
)) < 0) {
796 err
= ip6_dst_blackhole(sk
, &dst
, &fl
);
802 if (ipv6_addr_is_multicast(&fl
.fl6_dst
))
803 hlimit
= np
->mcast_hops
;
805 hlimit
= np
->hop_limit
;
807 hlimit
= ip6_dst_hoplimit(dst
);
816 if (msg
->msg_flags
&MSG_CONFIRM
)
821 if (unlikely(up
->pending
)) {
822 /* The socket is already corked while preparing it. */
823 /* ... which is an evident application bug. --ANK */
826 LIMIT_NETDEBUG(KERN_DEBUG
"udp cork app bug 2\n");
831 up
->pending
= AF_INET6
;
835 getfrag
= is_udplite
? udplite_getfrag
: ip_generic_getfrag
;
836 err
= ip6_append_data(sk
, getfrag
, msg
->msg_iov
, ulen
,
837 sizeof(struct udphdr
), hlimit
, tclass
, opt
, &fl
,
838 (struct rt6_info
*)dst
,
839 corkreq
? msg
->msg_flags
|MSG_MORE
: msg
->msg_flags
);
841 udp_v6_flush_pending_frames(sk
);
843 err
= udp_v6_push_pending_frames(sk
);
844 else if (unlikely(skb_queue_empty(&sk
->sk_write_queue
)))
849 ip6_dst_store(sk
, dst
,
850 ipv6_addr_equal(&fl
.fl6_dst
, &np
->daddr
) ?
852 #ifdef CONFIG_IPV6_SUBTREES
853 ipv6_addr_equal(&fl
.fl6_src
, &np
->saddr
) ?
864 err
= np
->recverr
? net_xmit_errno(err
) : 0;
868 fl6_sock_release(flowlabel
);
872 * ENOBUFS = no kernel mem, SOCK_NOSPACE = no sndbuf space. Reporting
873 * ENOBUFS might not be good (it's not tunable per se), but otherwise
874 * we don't have a good statistic (IpOutDiscards but it can be too many
875 * things). We could add another new stat but at least for now that
876 * seems like overkill.
878 if (err
== -ENOBUFS
|| test_bit(SOCK_NOSPACE
, &sk
->sk_socket
->flags
)) {
879 UDP6_INC_STATS_USER(sock_net(sk
),
880 UDP_MIB_SNDBUFERRORS
, is_udplite
);
886 if (!(msg
->msg_flags
&MSG_PROBE
) || len
)
887 goto back_from_confirm
;
892 void udpv6_destroy_sock(struct sock
*sk
)
895 udp_v6_flush_pending_frames(sk
);
898 inet6_destroy_sock(sk
);
902 * Socket option code for UDP
904 int udpv6_setsockopt(struct sock
*sk
, int level
, int optname
,
905 char __user
*optval
, int optlen
)
907 if (level
== SOL_UDP
|| level
== SOL_UDPLITE
)
908 return udp_lib_setsockopt(sk
, level
, optname
, optval
, optlen
,
909 udp_v6_push_pending_frames
);
910 return ipv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
914 int compat_udpv6_setsockopt(struct sock
*sk
, int level
, int optname
,
915 char __user
*optval
, int optlen
)
917 if (level
== SOL_UDP
|| level
== SOL_UDPLITE
)
918 return udp_lib_setsockopt(sk
, level
, optname
, optval
, optlen
,
919 udp_v6_push_pending_frames
);
920 return compat_ipv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
924 int udpv6_getsockopt(struct sock
*sk
, int level
, int optname
,
925 char __user
*optval
, int __user
*optlen
)
927 if (level
== SOL_UDP
|| level
== SOL_UDPLITE
)
928 return udp_lib_getsockopt(sk
, level
, optname
, optval
, optlen
);
929 return ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
933 int compat_udpv6_getsockopt(struct sock
*sk
, int level
, int optname
,
934 char __user
*optval
, int __user
*optlen
)
936 if (level
== SOL_UDP
|| level
== SOL_UDPLITE
)
937 return udp_lib_getsockopt(sk
, level
, optname
, optval
, optlen
);
938 return compat_ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
942 static struct inet6_protocol udpv6_protocol
= {
943 .handler
= udpv6_rcv
,
944 .err_handler
= udpv6_err
,
945 .flags
= INET6_PROTO_NOPOLICY
|INET6_PROTO_FINAL
,
948 /* ------------------------------------------------------------------------ */
949 #ifdef CONFIG_PROC_FS
951 static void udp6_sock_seq_show(struct seq_file
*seq
, struct sock
*sp
, int bucket
)
953 struct inet_sock
*inet
= inet_sk(sp
);
954 struct ipv6_pinfo
*np
= inet6_sk(sp
);
955 struct in6_addr
*dest
, *src
;
959 src
= &np
->rcv_saddr
;
960 destp
= ntohs(inet
->dport
);
961 srcp
= ntohs(inet
->sport
);
963 "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
964 "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
966 src
->s6_addr32
[0], src
->s6_addr32
[1],
967 src
->s6_addr32
[2], src
->s6_addr32
[3], srcp
,
968 dest
->s6_addr32
[0], dest
->s6_addr32
[1],
969 dest
->s6_addr32
[2], dest
->s6_addr32
[3], destp
,
971 atomic_read(&sp
->sk_wmem_alloc
),
972 atomic_read(&sp
->sk_rmem_alloc
),
976 atomic_read(&sp
->sk_refcnt
), sp
,
977 atomic_read(&sp
->sk_drops
));
980 int udp6_seq_show(struct seq_file
*seq
, void *v
)
982 if (v
== SEQ_START_TOKEN
)
987 "st tx_queue rx_queue tr tm->when retrnsmt"
988 " uid timeout inode ref pointer drops\n");
990 udp6_sock_seq_show(seq
, v
, ((struct udp_iter_state
*)seq
->private)->bucket
);
994 static struct udp_seq_afinfo udp6_seq_afinfo
= {
997 .hashtable
= udp_hash
,
999 .owner
= THIS_MODULE
,
1002 .show
= udp6_seq_show
,
1006 int udp6_proc_init(struct net
*net
)
1008 return udp_proc_register(net
, &udp6_seq_afinfo
);
1011 void udp6_proc_exit(struct net
*net
) {
1012 udp_proc_unregister(net
, &udp6_seq_afinfo
);
1014 #endif /* CONFIG_PROC_FS */
1016 /* ------------------------------------------------------------------------ */
1018 struct proto udpv6_prot
= {
1020 .owner
= THIS_MODULE
,
1021 .close
= udp_lib_close
,
1022 .connect
= ip6_datagram_connect
,
1023 .disconnect
= udp_disconnect
,
1025 .destroy
= udpv6_destroy_sock
,
1026 .setsockopt
= udpv6_setsockopt
,
1027 .getsockopt
= udpv6_getsockopt
,
1028 .sendmsg
= udpv6_sendmsg
,
1029 .recvmsg
= udpv6_recvmsg
,
1030 .backlog_rcv
= udpv6_queue_rcv_skb
,
1031 .hash
= udp_lib_hash
,
1032 .unhash
= udp_lib_unhash
,
1033 .get_port
= udp_v6_get_port
,
1034 .memory_allocated
= &udp_memory_allocated
,
1035 .sysctl_mem
= sysctl_udp_mem
,
1036 .sysctl_wmem
= &sysctl_udp_wmem_min
,
1037 .sysctl_rmem
= &sysctl_udp_rmem_min
,
1038 .obj_size
= sizeof(struct udp6_sock
),
1039 .h
.udp_hash
= udp_hash
,
1040 #ifdef CONFIG_COMPAT
1041 .compat_setsockopt
= compat_udpv6_setsockopt
,
1042 .compat_getsockopt
= compat_udpv6_getsockopt
,
1046 static struct inet_protosw udpv6_protosw
= {
1048 .protocol
= IPPROTO_UDP
,
1049 .prot
= &udpv6_prot
,
1050 .ops
= &inet6_dgram_ops
,
1052 .no_check
= UDP_CSUM_DEFAULT
,
1053 .flags
= INET_PROTOSW_PERMANENT
,
1057 int __init
udpv6_init(void)
1061 ret
= inet6_add_protocol(&udpv6_protocol
, IPPROTO_UDP
);
1065 ret
= inet6_register_protosw(&udpv6_protosw
);
1067 goto out_udpv6_protocol
;
1072 inet6_del_protocol(&udpv6_protocol
, IPPROTO_UDP
);
1076 void udpv6_exit(void)
1078 inet6_unregister_protosw(&udpv6_protosw
);
1079 inet6_del_protocol(&udpv6_protocol
, IPPROTO_UDP
);