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);
110 static struct sock *__udp6_lib_lookup_skb(struct sk_buff *skb,
111 __be16 sport, __be16 dport,
112 struct hlist_head udptable[])
115 struct ipv6hdr *iph = ipv6_hdr(skb);
117 if (unlikely(sk = skb_steal_sock(skb)))
120 return __udp6_lib_lookup(dev_net(skb->dst->dev), &iph->saddr, sport,
121 &iph->daddr, dport, inet6_iif(skb),
126 * This should be easy, if there is something there we
127 * return it, otherwise we block.
130 int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
131 struct msghdr *msg, size_t len,
132 int noblock, int flags, int *addr_len)
134 struct ipv6_pinfo *np = inet6_sk(sk);
135 struct inet_sock *inet = inet_sk(sk);
137 unsigned int ulen, copied;
140 int is_udplite = IS_UDPLITE(sk);
143 *addr_len=sizeof(struct sockaddr_in6);
145 if (flags & MSG_ERRQUEUE)
146 return ipv6_recv_error(sk, msg, len);
149 skb = __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0),
154 ulen = skb->len - sizeof(struct udphdr);
158 else if (copied < ulen)
159 msg->msg_flags |= MSG_TRUNC;
162 * If checksum is needed at all, try to do it while copying the
163 * data. If the data is truncated, or if we only want a partial
164 * coverage checksum (UDP-Lite), do it before the copy.
167 if (copied < ulen || UDP_SKB_CB(skb)->partial_cov) {
168 if (udp_lib_checksum_complete(skb))
172 if (skb_csum_unnecessary(skb))
173 err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr),
174 msg->msg_iov, copied );
176 err = skb_copy_and_csum_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov);
184 UDP6_INC_STATS_USER(sock_net(sk),
185 UDP_MIB_INDATAGRAMS, is_udplite);
187 sock_recv_timestamp(msg, sk, skb);
189 /* Copy the address. */
191 struct sockaddr_in6 *sin6;
193 sin6 = (struct sockaddr_in6 *) msg->msg_name;
194 sin6->sin6_family = AF_INET6;
195 sin6->sin6_port = udp_hdr(skb)->source;
196 sin6->sin6_flowinfo = 0;
197 sin6->sin6_scope_id = 0;
199 if (skb->protocol == htons(ETH_P_IP))
200 ipv6_addr_set(&sin6->sin6_addr, 0, 0,
201 htonl(0xffff), ip_hdr(skb)->saddr);
203 ipv6_addr_copy(&sin6->sin6_addr,
204 &ipv6_hdr(skb)->saddr);
205 if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)
206 sin6->sin6_scope_id = IP6CB(skb)->iif;
210 if (skb->protocol == htons(ETH_P_IP)) {
211 if (inet->cmsg_flags)
212 ip_cmsg_recv(msg, skb);
215 datagram_recv_ctl(sk, msg, skb);
219 if (flags & MSG_TRUNC)
224 skb_free_datagram(sk, skb);
231 if (!skb_kill_datagram(sk, skb, flags))
232 UDP6_INC_STATS_USER(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
235 if (flags & MSG_DONTWAIT)
240 void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
241 int type, int code, int offset, __be32 info,
242 struct hlist_head udptable[] )
244 struct ipv6_pinfo *np;
245 struct ipv6hdr *hdr = (struct ipv6hdr*)skb->data;
246 struct in6_addr *saddr = &hdr->saddr;
247 struct in6_addr *daddr = &hdr->daddr;
248 struct udphdr *uh = (struct udphdr*)(skb->data+offset);
252 sk = __udp6_lib_lookup(dev_net(skb->dev), daddr, uh->dest,
253 saddr, uh->source, inet6_iif(skb), udptable);
259 if (!icmpv6_err_convert(type, code, &err) && !np->recverr)
262 if (sk->sk_state != TCP_ESTABLISHED && !np->recverr)
266 ipv6_icmp_error(sk, skb, err, uh->dest, ntohl(info), (u8 *)(uh+1));
269 sk->sk_error_report(sk);
274 static __inline__ void udpv6_err(struct sk_buff *skb,
275 struct inet6_skb_parm *opt, int type,
276 int code, int offset, __be32 info )
278 __udp6_lib_err(skb, opt, type, code, offset, info, udp_hash);
281 int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
283 struct udp_sock *up = udp_sk(sk);
285 int is_udplite = IS_UDPLITE(sk);
287 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
291 * UDP-Lite specific tests, ignored on UDP sockets (see net/ipv4/udp.c).
293 if ((is_udplite & UDPLITE_RECV_CC) && UDP_SKB_CB(skb)->partial_cov) {
295 if (up->pcrlen == 0) { /* full coverage was set */
296 LIMIT_NETDEBUG(KERN_WARNING "UDPLITE6: partial coverage"
297 " %d while full coverage %d requested\n",
298 UDP_SKB_CB(skb)->cscov, skb->len);
301 if (UDP_SKB_CB(skb)->cscov < up->pcrlen) {
302 LIMIT_NETDEBUG(KERN_WARNING "UDPLITE6: coverage %d "
303 "too small, need min %d\n",
304 UDP_SKB_CB(skb)->cscov, up->pcrlen);
310 if (udp_lib_checksum_complete(skb))
314 if ((rc = sock_queue_rcv_skb(sk,skb)) < 0) {
315 /* Note that an ENOMEM error is charged twice */
317 UDP6_INC_STATS_BH(sock_net(sk),
318 UDP_MIB_RCVBUFERRORS, is_udplite);
319 atomic_inc(&sk->sk_drops);
326 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
331 static struct sock *udp_v6_mcast_next(struct sock *sk,
332 __be16 loc_port, struct in6_addr *loc_addr,
333 __be16 rmt_port, struct in6_addr *rmt_addr,
336 struct hlist_node *node;
338 unsigned short num = ntohs(loc_port);
340 sk_for_each_from(s, node) {
341 struct inet_sock *inet = inet_sk(s);
343 if (sock_net(s) != sock_net(sk))
346 if (s->sk_hash == num && s->sk_family == PF_INET6) {
347 struct ipv6_pinfo *np = inet6_sk(s);
349 if (inet->dport != rmt_port)
352 if (!ipv6_addr_any(&np->daddr) &&
353 !ipv6_addr_equal(&np->daddr, rmt_addr))
356 if (s->sk_bound_dev_if && s->sk_bound_dev_if != dif)
359 if (!ipv6_addr_any(&np->rcv_saddr)) {
360 if (!ipv6_addr_equal(&np->rcv_saddr, loc_addr))
363 if (!inet6_mc_check(s, loc_addr, rmt_addr))
372 * Note: called only from the BH handler context,
373 * so we don't need to lock the hashes.
375 static int __udp6_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
376 struct in6_addr *saddr, struct in6_addr *daddr,
377 struct hlist_head udptable[])
379 struct sock *sk, *sk2;
380 const struct udphdr *uh = udp_hdr(skb);
383 read_lock(&udp_hash_lock);
384 sk = sk_head(&udptable[udp_hashfn(net, ntohs(uh->dest))]);
385 dif = inet6_iif(skb);
386 sk = udp_v6_mcast_next(sk, uh->dest, daddr, uh->source, saddr, dif);
393 while ((sk2 = udp_v6_mcast_next(sk_next(sk2), uh->dest, daddr,
394 uh->source, saddr, dif))) {
395 struct sk_buff *buff = skb_clone(skb, GFP_ATOMIC);
398 if (!sock_owned_by_user(sk2))
399 udpv6_queue_rcv_skb(sk2, buff);
401 sk_add_backlog(sk2, buff);
406 if (!sock_owned_by_user(sk))
407 udpv6_queue_rcv_skb(sk, skb);
409 sk_add_backlog(sk, skb);
412 read_unlock(&udp_hash_lock);
416 static inline int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh,
421 UDP_SKB_CB(skb)->partial_cov = 0;
422 UDP_SKB_CB(skb)->cscov = skb->len;
424 if (proto == IPPROTO_UDPLITE) {
425 err = udplite_checksum_init(skb, uh);
430 if (uh->check == 0) {
431 /* RFC 2460 section 8.1 says that we SHOULD log
432 this error. Well, it is reasonable.
434 LIMIT_NETDEBUG(KERN_INFO "IPv6: udp checksum is 0\n");
437 if (skb->ip_summed == CHECKSUM_COMPLETE &&
438 !csum_ipv6_magic(&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr,
439 skb->len, proto, skb->csum))
440 skb->ip_summed = CHECKSUM_UNNECESSARY;
442 if (!skb_csum_unnecessary(skb))
443 skb->csum = ~csum_unfold(csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
444 &ipv6_hdr(skb)->daddr,
445 skb->len, proto, 0));
450 int __udp6_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
455 struct net_device *dev = skb->dev;
456 struct in6_addr *saddr, *daddr;
458 struct net *net = dev_net(skb->dev);
460 if (!pskb_may_pull(skb, sizeof(struct udphdr)))
463 saddr = &ipv6_hdr(skb)->saddr;
464 daddr = &ipv6_hdr(skb)->daddr;
467 ulen = ntohs(uh->len);
471 if (proto == IPPROTO_UDP) {
472 /* UDP validates ulen. */
474 /* Check for jumbo payload */
478 if (ulen < sizeof(*uh))
481 if (ulen < skb->len) {
482 if (pskb_trim_rcsum(skb, ulen))
484 saddr = &ipv6_hdr(skb)->saddr;
485 daddr = &ipv6_hdr(skb)->daddr;
490 if (udp6_csum_init(skb, uh, proto))
494 * Multicast receive code
496 if (ipv6_addr_is_multicast(daddr))
497 return __udp6_lib_mcast_deliver(net, skb,
498 saddr, daddr, udptable);
503 * check socket cache ... must talk to Alan about his plans
504 * for sock caches... i'll skip this for now.
506 sk = __udp6_lib_lookup_skb(skb, uh->source, uh->dest, udptable);
509 if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
512 if (udp_lib_checksum_complete(skb))
514 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
515 proto == IPPROTO_UDPLITE);
517 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev);
526 if (!sock_owned_by_user(sk))
527 udpv6_queue_rcv_skb(sk, skb);
529 sk_add_backlog(sk, skb);
535 LIMIT_NETDEBUG(KERN_DEBUG "UDP%sv6: short packet: %d/%u\n",
536 proto == IPPROTO_UDPLITE ? "-Lite" : "",
540 UDP6_INC_STATS_BH(net, UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE);
545 static __inline__ int udpv6_rcv(struct sk_buff *skb)
547 return __udp6_lib_rcv(skb, udp_hash, IPPROTO_UDP);
551 * Throw away all pending data and cancel the corking. Socket is locked.
553 static void udp_v6_flush_pending_frames(struct sock *sk)
555 struct udp_sock *up = udp_sk(sk);
557 if (up->pending == AF_INET)
558 udp_flush_pending_frames(sk);
559 else if (up->pending) {
562 ip6_flush_pending_frames(sk);
570 static int udp_v6_push_pending_frames(struct sock *sk)
574 struct udp_sock *up = udp_sk(sk);
575 struct inet_sock *inet = inet_sk(sk);
576 struct flowi *fl = &inet->cork.fl;
578 int is_udplite = IS_UDPLITE(sk);
581 /* Grab the skbuff where UDP header space exists. */
582 if ((skb = skb_peek(&sk->sk_write_queue)) == NULL)
586 * Create a UDP header
589 uh->source = fl->fl_ip_sport;
590 uh->dest = fl->fl_ip_dport;
591 uh->len = htons(up->len);
595 csum = udplite_csum_outgoing(sk, skb);
597 csum = udp_csum_outgoing(sk, skb);
599 /* add protocol-dependent pseudo-header */
600 uh->check = csum_ipv6_magic(&fl->fl6_src, &fl->fl6_dst,
601 up->len, fl->proto, csum );
603 uh->check = CSUM_MANGLED_0;
605 err = ip6_push_pending_frames(sk);
610 UDP6_INC_STATS_USER(sock_net(sk),
611 UDP_MIB_OUTDATAGRAMS, is_udplite);
615 int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk,
616 struct msghdr *msg, size_t len)
618 struct ipv6_txoptions opt_space;
619 struct udp_sock *up = udp_sk(sk);
620 struct inet_sock *inet = inet_sk(sk);
621 struct ipv6_pinfo *np = inet6_sk(sk);
622 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) msg->msg_name;
623 struct in6_addr *daddr, *final_p = NULL, final;
624 struct ipv6_txoptions *opt = NULL;
625 struct ip6_flowlabel *flowlabel = NULL;
627 struct dst_entry *dst;
628 int addr_len = msg->msg_namelen;
632 int corkreq = up->corkflag || msg->msg_flags&MSG_MORE;
635 int is_udplite = IS_UDPLITE(sk);
636 int (*getfrag)(void *, char *, int, int, int, struct sk_buff *);
638 /* destination address check */
640 if (addr_len < offsetof(struct sockaddr, sa_data))
643 switch (sin6->sin6_family) {
645 if (addr_len < SIN6_LEN_RFC2133)
647 daddr = &sin6->sin6_addr;
652 msg->msg_name = sin6 = NULL;
653 msg->msg_namelen = addr_len = 0;
659 } else if (!up->pending) {
660 if (sk->sk_state != TCP_ESTABLISHED)
661 return -EDESTADDRREQ;
667 if (ipv6_addr_v4mapped(daddr)) {
668 struct sockaddr_in sin;
669 sin.sin_family = AF_INET;
670 sin.sin_port = sin6 ? sin6->sin6_port : inet->dport;
671 sin.sin_addr.s_addr = daddr->s6_addr32[3];
672 msg->msg_name = &sin;
673 msg->msg_namelen = sizeof(sin);
675 if (__ipv6_only_sock(sk))
677 return udp_sendmsg(iocb, sk, msg, len);
681 if (up->pending == AF_INET)
682 return udp_sendmsg(iocb, sk, msg, len);
684 /* Rough check on arithmetic overflow,
685 better check is made in ip6_append_data().
687 if (len > INT_MAX - sizeof(struct udphdr))
692 * There are pending frames.
693 * The socket lock must be held while it's corked.
696 if (likely(up->pending)) {
697 if (unlikely(up->pending != AF_INET6)) {
699 return -EAFNOSUPPORT;
706 ulen += sizeof(struct udphdr);
708 memset(&fl, 0, sizeof(fl));
711 if (sin6->sin6_port == 0)
714 fl.fl_ip_dport = sin6->sin6_port;
715 daddr = &sin6->sin6_addr;
718 fl.fl6_flowlabel = sin6->sin6_flowinfo&IPV6_FLOWINFO_MASK;
719 if (fl.fl6_flowlabel&IPV6_FLOWLABEL_MASK) {
720 flowlabel = fl6_sock_lookup(sk, fl.fl6_flowlabel);
721 if (flowlabel == NULL)
723 daddr = &flowlabel->dst;
728 * Otherwise it will be difficult to maintain
731 if (sk->sk_state == TCP_ESTABLISHED &&
732 ipv6_addr_equal(daddr, &np->daddr))
735 if (addr_len >= sizeof(struct sockaddr_in6) &&
736 sin6->sin6_scope_id &&
737 ipv6_addr_type(daddr)&IPV6_ADDR_LINKLOCAL)
738 fl.oif = sin6->sin6_scope_id;
740 if (sk->sk_state != TCP_ESTABLISHED)
741 return -EDESTADDRREQ;
743 fl.fl_ip_dport = inet->dport;
745 fl.fl6_flowlabel = np->flow_label;
750 fl.oif = sk->sk_bound_dev_if;
752 if (msg->msg_controllen) {
754 memset(opt, 0, sizeof(struct ipv6_txoptions));
755 opt->tot_len = sizeof(*opt);
757 err = datagram_send_ctl(sock_net(sk), msg, &fl, opt, &hlimit, &tclass);
759 fl6_sock_release(flowlabel);
762 if ((fl.fl6_flowlabel&IPV6_FLOWLABEL_MASK) && !flowlabel) {
763 flowlabel = fl6_sock_lookup(sk, fl.fl6_flowlabel);
764 if (flowlabel == NULL)
767 if (!(opt->opt_nflen|opt->opt_flen))
774 opt = fl6_merge_options(&opt_space, flowlabel, opt);
775 opt = ipv6_fixup_options(&opt_space, opt);
777 fl.proto = sk->sk_protocol;
778 if (!ipv6_addr_any(daddr))
779 ipv6_addr_copy(&fl.fl6_dst, daddr);
781 fl.fl6_dst.s6_addr[15] = 0x1; /* :: means loopback (BSD'ism) */
782 if (ipv6_addr_any(&fl.fl6_src) && !ipv6_addr_any(&np->saddr))
783 ipv6_addr_copy(&fl.fl6_src, &np->saddr);
784 fl.fl_ip_sport = inet->sport;
786 /* merge ip6_build_xmit from ip6_output */
787 if (opt && opt->srcrt) {
788 struct rt0_hdr *rt0 = (struct rt0_hdr *) opt->srcrt;
789 ipv6_addr_copy(&final, &fl.fl6_dst);
790 ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
795 if (!fl.oif && ipv6_addr_is_multicast(&fl.fl6_dst)) {
796 fl.oif = np->mcast_oif;
800 security_sk_classify_flow(sk, &fl);
802 err = ip6_sk_dst_lookup(sk, &dst, &fl);
806 ipv6_addr_copy(&fl.fl6_dst, final_p);
808 if ((err = __xfrm_lookup(&dst, &fl, sk, XFRM_LOOKUP_WAIT)) < 0) {
810 err = ip6_dst_blackhole(sk, &dst, &fl);
816 if (ipv6_addr_is_multicast(&fl.fl6_dst))
817 hlimit = np->mcast_hops;
819 hlimit = np->hop_limit;
821 hlimit = ip6_dst_hoplimit(dst);
830 if (msg->msg_flags&MSG_CONFIRM)
835 if (unlikely(up->pending)) {
836 /* The socket is already corked while preparing it. */
837 /* ... which is an evident application bug. --ANK */
840 LIMIT_NETDEBUG(KERN_DEBUG "udp cork app bug 2\n");
845 up->pending = AF_INET6;
849 getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag;
850 err = ip6_append_data(sk, getfrag, msg->msg_iov, ulen,
851 sizeof(struct udphdr), hlimit, tclass, opt, &fl,
852 (struct rt6_info*)dst,
853 corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags);
855 udp_v6_flush_pending_frames(sk);
857 err = udp_v6_push_pending_frames(sk);
858 else if (unlikely(skb_queue_empty(&sk->sk_write_queue)))
863 ip6_dst_store(sk, dst,
864 ipv6_addr_equal(&fl.fl6_dst, &np->daddr) ?
866 #ifdef CONFIG_IPV6_SUBTREES
867 ipv6_addr_equal(&fl.fl6_src, &np->saddr) ?
878 err = np->recverr ? net_xmit_errno(err) : 0;
882 fl6_sock_release(flowlabel);
886 * ENOBUFS = no kernel mem, SOCK_NOSPACE = no sndbuf space. Reporting
887 * ENOBUFS might not be good (it's not tunable per se), but otherwise
888 * we don't have a good statistic (IpOutDiscards but it can be too many
889 * things). We could add another new stat but at least for now that
890 * seems like overkill.
892 if (err == -ENOBUFS || test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) {
893 UDP6_INC_STATS_USER(sock_net(sk),
894 UDP_MIB_SNDBUFERRORS, is_udplite);
900 if (!(msg->msg_flags&MSG_PROBE) || len)
901 goto back_from_confirm;
906 void udpv6_destroy_sock(struct sock *sk)
909 udp_v6_flush_pending_frames(sk);
912 inet6_destroy_sock(sk);
916 * Socket option code for UDP
918 int udpv6_setsockopt(struct sock *sk, int level, int optname,
919 char __user *optval, int optlen)
921 if (level == SOL_UDP || level == SOL_UDPLITE)
922 return udp_lib_setsockopt(sk, level, optname, optval, optlen,
923 udp_v6_push_pending_frames);
924 return ipv6_setsockopt(sk, level, optname, optval, optlen);
928 int compat_udpv6_setsockopt(struct sock *sk, int level, int optname,
929 char __user *optval, int optlen)
931 if (level == SOL_UDP || level == SOL_UDPLITE)
932 return udp_lib_setsockopt(sk, level, optname, optval, optlen,
933 udp_v6_push_pending_frames);
934 return compat_ipv6_setsockopt(sk, level, optname, optval, optlen);
938 int udpv6_getsockopt(struct sock *sk, int level, int optname,
939 char __user *optval, int __user *optlen)
941 if (level == SOL_UDP || level == SOL_UDPLITE)
942 return udp_lib_getsockopt(sk, level, optname, optval, optlen);
943 return ipv6_getsockopt(sk, level, optname, optval, optlen);
947 int compat_udpv6_getsockopt(struct sock *sk, int level, int optname,
948 char __user *optval, int __user *optlen)
950 if (level == SOL_UDP || level == SOL_UDPLITE)
951 return udp_lib_getsockopt(sk, level, optname, optval, optlen);
952 return compat_ipv6_getsockopt(sk, level, optname, optval, optlen);
956 static struct inet6_protocol udpv6_protocol = {
957 .handler = udpv6_rcv,
958 .err_handler = udpv6_err,
959 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
962 /* ------------------------------------------------------------------------ */
963 #ifdef CONFIG_PROC_FS
965 static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket)
967 struct inet_sock *inet = inet_sk(sp);
968 struct ipv6_pinfo *np = inet6_sk(sp);
969 struct in6_addr *dest, *src;
973 src = &np->rcv_saddr;
974 destp = ntohs(inet->dport);
975 srcp = ntohs(inet->sport);
977 "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
978 "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
980 src->s6_addr32[0], src->s6_addr32[1],
981 src->s6_addr32[2], src->s6_addr32[3], srcp,
982 dest->s6_addr32[0], dest->s6_addr32[1],
983 dest->s6_addr32[2], dest->s6_addr32[3], destp,
985 atomic_read(&sp->sk_wmem_alloc),
986 atomic_read(&sp->sk_rmem_alloc),
990 atomic_read(&sp->sk_refcnt), sp,
991 atomic_read(&sp->sk_drops));
994 int udp6_seq_show(struct seq_file *seq, void *v)
996 if (v == SEQ_START_TOKEN)
1001 "st tx_queue rx_queue tr tm->when retrnsmt"
1002 " uid timeout inode ref pointer drops\n");
1004 udp6_sock_seq_show(seq, v, ((struct udp_iter_state *)seq->private)->bucket);
1008 static struct udp_seq_afinfo udp6_seq_afinfo = {
1011 .hashtable = udp_hash,
1013 .owner = THIS_MODULE,
1016 .show = udp6_seq_show,
1020 int udp6_proc_init(struct net *net)
1022 return udp_proc_register(net, &udp6_seq_afinfo);
1025 void udp6_proc_exit(struct net *net) {
1026 udp_proc_unregister(net, &udp6_seq_afinfo);
1028 #endif /* CONFIG_PROC_FS */
1030 /* ------------------------------------------------------------------------ */
1032 struct proto udpv6_prot = {
1034 .owner = THIS_MODULE,
1035 .close = udp_lib_close,
1036 .connect = ip6_datagram_connect,
1037 .disconnect = udp_disconnect,
1039 .destroy = udpv6_destroy_sock,
1040 .setsockopt = udpv6_setsockopt,
1041 .getsockopt = udpv6_getsockopt,
1042 .sendmsg = udpv6_sendmsg,
1043 .recvmsg = udpv6_recvmsg,
1044 .backlog_rcv = udpv6_queue_rcv_skb,
1045 .hash = udp_lib_hash,
1046 .unhash = udp_lib_unhash,
1047 .get_port = udp_v6_get_port,
1048 .memory_allocated = &udp_memory_allocated,
1049 .sysctl_mem = sysctl_udp_mem,
1050 .sysctl_wmem = &sysctl_udp_wmem_min,
1051 .sysctl_rmem = &sysctl_udp_rmem_min,
1052 .obj_size = sizeof(struct udp6_sock),
1053 .h.udp_hash = udp_hash,
1054 #ifdef CONFIG_COMPAT
1055 .compat_setsockopt = compat_udpv6_setsockopt,
1056 .compat_getsockopt = compat_udpv6_getsockopt,
1060 static struct inet_protosw udpv6_protosw = {
1062 .protocol = IPPROTO_UDP,
1063 .prot = &udpv6_prot,
1064 .ops = &inet6_dgram_ops,
1066 .no_check = UDP_CSUM_DEFAULT,
1067 .flags = INET_PROTOSW_PERMANENT,
1071 int __init udpv6_init(void)
1075 ret = inet6_add_protocol(&udpv6_protocol, IPPROTO_UDP);
1079 ret = inet6_register_protosw(&udpv6_protosw);
1081 goto out_udpv6_protocol;
1086 inet6_del_protocol(&udpv6_protocol, IPPROTO_UDP);
1090 void udpv6_exit(void)
1092 inet6_unregister_protosw(&udpv6_protosw);
1093 inet6_del_protocol(&udpv6_protocol, IPPROTO_UDP);