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 inline int compute_score(struct sock *sk, struct net *net,
59 struct in6_addr *saddr, __be16 sport,
60 struct in6_addr *daddr, __be16 dport,
65 if (net_eq(sock_net(sk), net) && sk->sk_hash == hnum &&
66 sk->sk_family == PF_INET6) {
67 struct ipv6_pinfo *np = inet6_sk(sk);
68 struct inet_sock *inet = inet_sk(sk);
72 if (inet->dport != sport)
76 if (!ipv6_addr_any(&np->rcv_saddr)) {
77 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
81 if (!ipv6_addr_any(&np->daddr)) {
82 if (!ipv6_addr_equal(&np->daddr, saddr))
86 if (sk->sk_bound_dev_if) {
87 if (sk->sk_bound_dev_if != dif)
95 static struct sock *__udp6_lib_lookup(struct net *net,
96 struct in6_addr *saddr, __be16 sport,
97 struct in6_addr *daddr, __be16 dport,
98 int dif, struct udp_table *udptable)
100 struct sock *sk, *result;
101 struct hlist_nulls_node *node;
102 unsigned short hnum = ntohs(dport);
103 unsigned int hash = udp_hashfn(net, hnum);
104 struct udp_hslot *hslot = &udptable->hash[hash];
111 sk_nulls_for_each_rcu(sk, node, &hslot->head) {
112 score = compute_score(sk, net, hnum, saddr, sport, daddr, dport, dif);
113 if (score > badness) {
119 * if the nulls value we got at the end of this lookup is
120 * not the expected one, we must restart lookup.
121 * We probably met an item that was moved to another chain.
123 if (get_nulls_value(node) != hash)
127 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
129 else if (unlikely(compute_score(result, net, hnum, saddr, sport,
130 daddr, dport, dif) < badness)) {
139 static struct sock *__udp6_lib_lookup_skb(struct sk_buff *skb,
140 __be16 sport, __be16 dport,
141 struct udp_table *udptable)
144 struct ipv6hdr *iph = ipv6_hdr(skb);
146 if (unlikely(sk = skb_steal_sock(skb)))
149 return __udp6_lib_lookup(dev_net(skb->dst->dev), &iph->saddr, sport,
150 &iph->daddr, dport, inet6_iif(skb),
155 * This should be easy, if there is something there we
156 * return it, otherwise we block.
159 int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
160 struct msghdr *msg, size_t len,
161 int noblock, int flags, int *addr_len)
163 struct ipv6_pinfo *np = inet6_sk(sk);
164 struct inet_sock *inet = inet_sk(sk);
166 unsigned int ulen, copied;
169 int is_udplite = IS_UDPLITE(sk);
173 *addr_len=sizeof(struct sockaddr_in6);
175 if (flags & MSG_ERRQUEUE)
176 return ipv6_recv_error(sk, msg, len);
179 skb = __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0),
184 ulen = skb->len - sizeof(struct udphdr);
188 else if (copied < ulen)
189 msg->msg_flags |= MSG_TRUNC;
191 is_udp4 = (skb->protocol == htons(ETH_P_IP));
194 * If checksum is needed at all, try to do it while copying the
195 * data. If the data is truncated, or if we only want a partial
196 * coverage checksum (UDP-Lite), do it before the copy.
199 if (copied < ulen || UDP_SKB_CB(skb)->partial_cov) {
200 if (udp_lib_checksum_complete(skb))
204 if (skb_csum_unnecessary(skb))
205 err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr),
206 msg->msg_iov, copied );
208 err = skb_copy_and_csum_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov);
217 UDP_INC_STATS_USER(sock_net(sk),
218 UDP_MIB_INDATAGRAMS, is_udplite);
220 UDP6_INC_STATS_USER(sock_net(sk),
221 UDP_MIB_INDATAGRAMS, is_udplite);
224 sock_recv_timestamp(msg, sk, skb);
226 /* Copy the address. */
228 struct sockaddr_in6 *sin6;
230 sin6 = (struct sockaddr_in6 *) msg->msg_name;
231 sin6->sin6_family = AF_INET6;
232 sin6->sin6_port = udp_hdr(skb)->source;
233 sin6->sin6_flowinfo = 0;
234 sin6->sin6_scope_id = 0;
237 ipv6_addr_set(&sin6->sin6_addr, 0, 0,
238 htonl(0xffff), ip_hdr(skb)->saddr);
240 ipv6_addr_copy(&sin6->sin6_addr,
241 &ipv6_hdr(skb)->saddr);
242 if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)
243 sin6->sin6_scope_id = IP6CB(skb)->iif;
248 if (inet->cmsg_flags)
249 ip_cmsg_recv(msg, skb);
252 datagram_recv_ctl(sk, msg, skb);
256 if (flags & MSG_TRUNC)
261 skb_free_datagram(sk, skb);
268 if (!skb_kill_datagram(sk, skb, flags)) {
270 UDP_INC_STATS_USER(sock_net(sk),
271 UDP_MIB_INERRORS, is_udplite);
273 UDP6_INC_STATS_USER(sock_net(sk),
274 UDP_MIB_INERRORS, is_udplite);
278 if (flags & MSG_DONTWAIT)
283 void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
284 int type, int code, int offset, __be32 info,
285 struct udp_table *udptable)
287 struct ipv6_pinfo *np;
288 struct ipv6hdr *hdr = (struct ipv6hdr*)skb->data;
289 struct in6_addr *saddr = &hdr->saddr;
290 struct in6_addr *daddr = &hdr->daddr;
291 struct udphdr *uh = (struct udphdr*)(skb->data+offset);
295 sk = __udp6_lib_lookup(dev_net(skb->dev), daddr, uh->dest,
296 saddr, uh->source, inet6_iif(skb), udptable);
302 if (!icmpv6_err_convert(type, code, &err) && !np->recverr)
305 if (sk->sk_state != TCP_ESTABLISHED && !np->recverr)
309 ipv6_icmp_error(sk, skb, err, uh->dest, ntohl(info), (u8 *)(uh+1));
312 sk->sk_error_report(sk);
317 static __inline__ void udpv6_err(struct sk_buff *skb,
318 struct inet6_skb_parm *opt, int type,
319 int code, int offset, __be32 info )
321 __udp6_lib_err(skb, opt, type, code, offset, info, &udp_table);
324 int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
326 struct udp_sock *up = udp_sk(sk);
328 int is_udplite = IS_UDPLITE(sk);
330 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
334 * UDP-Lite specific tests, ignored on UDP sockets (see net/ipv4/udp.c).
336 if ((is_udplite & UDPLITE_RECV_CC) && UDP_SKB_CB(skb)->partial_cov) {
338 if (up->pcrlen == 0) { /* full coverage was set */
339 LIMIT_NETDEBUG(KERN_WARNING "UDPLITE6: partial coverage"
340 " %d while full coverage %d requested\n",
341 UDP_SKB_CB(skb)->cscov, skb->len);
344 if (UDP_SKB_CB(skb)->cscov < up->pcrlen) {
345 LIMIT_NETDEBUG(KERN_WARNING "UDPLITE6: coverage %d "
346 "too small, need min %d\n",
347 UDP_SKB_CB(skb)->cscov, up->pcrlen);
353 if (udp_lib_checksum_complete(skb))
357 if ((rc = sock_queue_rcv_skb(sk,skb)) < 0) {
358 /* Note that an ENOMEM error is charged twice */
360 UDP6_INC_STATS_BH(sock_net(sk),
361 UDP_MIB_RCVBUFERRORS, is_udplite);
362 atomic_inc(&sk->sk_drops);
369 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
374 static struct sock *udp_v6_mcast_next(struct net *net, struct sock *sk,
375 __be16 loc_port, struct in6_addr *loc_addr,
376 __be16 rmt_port, struct in6_addr *rmt_addr,
379 struct hlist_nulls_node *node;
381 unsigned short num = ntohs(loc_port);
383 sk_nulls_for_each_from(s, node) {
384 struct inet_sock *inet = inet_sk(s);
386 if (!net_eq(sock_net(s), net))
389 if (s->sk_hash == num && s->sk_family == PF_INET6) {
390 struct ipv6_pinfo *np = inet6_sk(s);
392 if (inet->dport != rmt_port)
395 if (!ipv6_addr_any(&np->daddr) &&
396 !ipv6_addr_equal(&np->daddr, rmt_addr))
399 if (s->sk_bound_dev_if && s->sk_bound_dev_if != dif)
402 if (!ipv6_addr_any(&np->rcv_saddr)) {
403 if (!ipv6_addr_equal(&np->rcv_saddr, loc_addr))
406 if (!inet6_mc_check(s, loc_addr, rmt_addr))
415 * Note: called only from the BH handler context,
416 * so we don't need to lock the hashes.
418 static int __udp6_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
419 struct in6_addr *saddr, struct in6_addr *daddr,
420 struct udp_table *udptable)
422 struct sock *sk, *sk2;
423 const struct udphdr *uh = udp_hdr(skb);
424 struct udp_hslot *hslot = &udptable->hash[udp_hashfn(net, ntohs(uh->dest))];
427 spin_lock(&hslot->lock);
428 sk = sk_nulls_head(&hslot->head);
429 dif = inet6_iif(skb);
430 sk = udp_v6_mcast_next(net, sk, uh->dest, daddr, uh->source, saddr, dif);
437 while ((sk2 = udp_v6_mcast_next(net, sk_nulls_next(sk2), uh->dest, daddr,
438 uh->source, saddr, dif))) {
439 struct sk_buff *buff = skb_clone(skb, GFP_ATOMIC);
442 if (!sock_owned_by_user(sk2))
443 udpv6_queue_rcv_skb(sk2, buff);
445 sk_add_backlog(sk2, buff);
450 if (!sock_owned_by_user(sk))
451 udpv6_queue_rcv_skb(sk, skb);
453 sk_add_backlog(sk, skb);
456 spin_unlock(&hslot->lock);
460 static inline int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh,
465 UDP_SKB_CB(skb)->partial_cov = 0;
466 UDP_SKB_CB(skb)->cscov = skb->len;
468 if (proto == IPPROTO_UDPLITE) {
469 err = udplite_checksum_init(skb, uh);
474 if (uh->check == 0) {
475 /* RFC 2460 section 8.1 says that we SHOULD log
476 this error. Well, it is reasonable.
478 LIMIT_NETDEBUG(KERN_INFO "IPv6: udp checksum is 0\n");
481 if (skb->ip_summed == CHECKSUM_COMPLETE &&
482 !csum_ipv6_magic(&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr,
483 skb->len, proto, skb->csum))
484 skb->ip_summed = CHECKSUM_UNNECESSARY;
486 if (!skb_csum_unnecessary(skb))
487 skb->csum = ~csum_unfold(csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
488 &ipv6_hdr(skb)->daddr,
489 skb->len, proto, 0));
494 int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
499 struct net_device *dev = skb->dev;
500 struct in6_addr *saddr, *daddr;
502 struct net *net = dev_net(skb->dev);
504 if (!pskb_may_pull(skb, sizeof(struct udphdr)))
507 saddr = &ipv6_hdr(skb)->saddr;
508 daddr = &ipv6_hdr(skb)->daddr;
511 ulen = ntohs(uh->len);
515 if (proto == IPPROTO_UDP) {
516 /* UDP validates ulen. */
518 /* Check for jumbo payload */
522 if (ulen < sizeof(*uh))
525 if (ulen < skb->len) {
526 if (pskb_trim_rcsum(skb, ulen))
528 saddr = &ipv6_hdr(skb)->saddr;
529 daddr = &ipv6_hdr(skb)->daddr;
534 if (udp6_csum_init(skb, uh, proto))
538 * Multicast receive code
540 if (ipv6_addr_is_multicast(daddr))
541 return __udp6_lib_mcast_deliver(net, skb,
542 saddr, daddr, udptable);
547 * check socket cache ... must talk to Alan about his plans
548 * for sock caches... i'll skip this for now.
550 sk = __udp6_lib_lookup_skb(skb, uh->source, uh->dest, udptable);
553 if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
556 if (udp_lib_checksum_complete(skb))
558 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
559 proto == IPPROTO_UDPLITE);
561 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev);
570 if (!sock_owned_by_user(sk))
571 udpv6_queue_rcv_skb(sk, skb);
573 sk_add_backlog(sk, skb);
579 LIMIT_NETDEBUG(KERN_DEBUG "UDP%sv6: short packet: %d/%u\n",
580 proto == IPPROTO_UDPLITE ? "-Lite" : "",
584 UDP6_INC_STATS_BH(net, UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE);
589 static __inline__ int udpv6_rcv(struct sk_buff *skb)
591 return __udp6_lib_rcv(skb, &udp_table, IPPROTO_UDP);
595 * Throw away all pending data and cancel the corking. Socket is locked.
597 static void udp_v6_flush_pending_frames(struct sock *sk)
599 struct udp_sock *up = udp_sk(sk);
601 if (up->pending == AF_INET)
602 udp_flush_pending_frames(sk);
603 else if (up->pending) {
606 ip6_flush_pending_frames(sk);
614 static int udp_v6_push_pending_frames(struct sock *sk)
618 struct udp_sock *up = udp_sk(sk);
619 struct inet_sock *inet = inet_sk(sk);
620 struct flowi *fl = &inet->cork.fl;
622 int is_udplite = IS_UDPLITE(sk);
625 /* Grab the skbuff where UDP header space exists. */
626 if ((skb = skb_peek(&sk->sk_write_queue)) == NULL)
630 * Create a UDP header
633 uh->source = fl->fl_ip_sport;
634 uh->dest = fl->fl_ip_dport;
635 uh->len = htons(up->len);
639 csum = udplite_csum_outgoing(sk, skb);
641 csum = udp_csum_outgoing(sk, skb);
643 /* add protocol-dependent pseudo-header */
644 uh->check = csum_ipv6_magic(&fl->fl6_src, &fl->fl6_dst,
645 up->len, fl->proto, csum );
647 uh->check = CSUM_MANGLED_0;
649 err = ip6_push_pending_frames(sk);
654 UDP6_INC_STATS_USER(sock_net(sk),
655 UDP_MIB_OUTDATAGRAMS, is_udplite);
659 int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk,
660 struct msghdr *msg, size_t len)
662 struct ipv6_txoptions opt_space;
663 struct udp_sock *up = udp_sk(sk);
664 struct inet_sock *inet = inet_sk(sk);
665 struct ipv6_pinfo *np = inet6_sk(sk);
666 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) msg->msg_name;
667 struct in6_addr *daddr, *final_p = NULL, final;
668 struct ipv6_txoptions *opt = NULL;
669 struct ip6_flowlabel *flowlabel = NULL;
671 struct dst_entry *dst;
672 int addr_len = msg->msg_namelen;
676 int corkreq = up->corkflag || msg->msg_flags&MSG_MORE;
679 int is_udplite = IS_UDPLITE(sk);
680 int (*getfrag)(void *, char *, int, int, int, struct sk_buff *);
682 /* destination address check */
684 if (addr_len < offsetof(struct sockaddr, sa_data))
687 switch (sin6->sin6_family) {
689 if (addr_len < SIN6_LEN_RFC2133)
691 daddr = &sin6->sin6_addr;
696 msg->msg_name = sin6 = NULL;
697 msg->msg_namelen = addr_len = 0;
703 } else if (!up->pending) {
704 if (sk->sk_state != TCP_ESTABLISHED)
705 return -EDESTADDRREQ;
711 if (ipv6_addr_v4mapped(daddr)) {
712 struct sockaddr_in sin;
713 sin.sin_family = AF_INET;
714 sin.sin_port = sin6 ? sin6->sin6_port : inet->dport;
715 sin.sin_addr.s_addr = daddr->s6_addr32[3];
716 msg->msg_name = &sin;
717 msg->msg_namelen = sizeof(sin);
719 if (__ipv6_only_sock(sk))
721 return udp_sendmsg(iocb, sk, msg, len);
725 if (up->pending == AF_INET)
726 return udp_sendmsg(iocb, sk, msg, len);
728 /* Rough check on arithmetic overflow,
729 better check is made in ip6_append_data().
731 if (len > INT_MAX - sizeof(struct udphdr))
736 * There are pending frames.
737 * The socket lock must be held while it's corked.
740 if (likely(up->pending)) {
741 if (unlikely(up->pending != AF_INET6)) {
743 return -EAFNOSUPPORT;
750 ulen += sizeof(struct udphdr);
752 memset(&fl, 0, sizeof(fl));
755 if (sin6->sin6_port == 0)
758 fl.fl_ip_dport = sin6->sin6_port;
759 daddr = &sin6->sin6_addr;
762 fl.fl6_flowlabel = sin6->sin6_flowinfo&IPV6_FLOWINFO_MASK;
763 if (fl.fl6_flowlabel&IPV6_FLOWLABEL_MASK) {
764 flowlabel = fl6_sock_lookup(sk, fl.fl6_flowlabel);
765 if (flowlabel == NULL)
767 daddr = &flowlabel->dst;
772 * Otherwise it will be difficult to maintain
775 if (sk->sk_state == TCP_ESTABLISHED &&
776 ipv6_addr_equal(daddr, &np->daddr))
779 if (addr_len >= sizeof(struct sockaddr_in6) &&
780 sin6->sin6_scope_id &&
781 ipv6_addr_type(daddr)&IPV6_ADDR_LINKLOCAL)
782 fl.oif = sin6->sin6_scope_id;
784 if (sk->sk_state != TCP_ESTABLISHED)
785 return -EDESTADDRREQ;
787 fl.fl_ip_dport = inet->dport;
789 fl.fl6_flowlabel = np->flow_label;
794 fl.oif = sk->sk_bound_dev_if;
797 fl.oif = np->sticky_pktinfo.ipi6_ifindex;
799 if (msg->msg_controllen) {
801 memset(opt, 0, sizeof(struct ipv6_txoptions));
802 opt->tot_len = sizeof(*opt);
804 err = datagram_send_ctl(sock_net(sk), msg, &fl, opt, &hlimit, &tclass);
806 fl6_sock_release(flowlabel);
809 if ((fl.fl6_flowlabel&IPV6_FLOWLABEL_MASK) && !flowlabel) {
810 flowlabel = fl6_sock_lookup(sk, fl.fl6_flowlabel);
811 if (flowlabel == NULL)
814 if (!(opt->opt_nflen|opt->opt_flen))
821 opt = fl6_merge_options(&opt_space, flowlabel, opt);
822 opt = ipv6_fixup_options(&opt_space, opt);
824 fl.proto = sk->sk_protocol;
825 if (!ipv6_addr_any(daddr))
826 ipv6_addr_copy(&fl.fl6_dst, daddr);
828 fl.fl6_dst.s6_addr[15] = 0x1; /* :: means loopback (BSD'ism) */
829 if (ipv6_addr_any(&fl.fl6_src) && !ipv6_addr_any(&np->saddr))
830 ipv6_addr_copy(&fl.fl6_src, &np->saddr);
831 fl.fl_ip_sport = inet->sport;
833 /* merge ip6_build_xmit from ip6_output */
834 if (opt && opt->srcrt) {
835 struct rt0_hdr *rt0 = (struct rt0_hdr *) opt->srcrt;
836 ipv6_addr_copy(&final, &fl.fl6_dst);
837 ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
842 if (!fl.oif && ipv6_addr_is_multicast(&fl.fl6_dst)) {
843 fl.oif = np->mcast_oif;
847 security_sk_classify_flow(sk, &fl);
849 err = ip6_sk_dst_lookup(sk, &dst, &fl);
853 ipv6_addr_copy(&fl.fl6_dst, final_p);
855 err = __xfrm_lookup(sock_net(sk), &dst, &fl, sk, XFRM_LOOKUP_WAIT);
858 err = ip6_dst_blackhole(sk, &dst, &fl);
864 if (ipv6_addr_is_multicast(&fl.fl6_dst))
865 hlimit = np->mcast_hops;
867 hlimit = np->hop_limit;
869 hlimit = ip6_dst_hoplimit(dst);
878 if (msg->msg_flags&MSG_CONFIRM)
883 if (unlikely(up->pending)) {
884 /* The socket is already corked while preparing it. */
885 /* ... which is an evident application bug. --ANK */
888 LIMIT_NETDEBUG(KERN_DEBUG "udp cork app bug 2\n");
893 up->pending = AF_INET6;
897 getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag;
898 err = ip6_append_data(sk, getfrag, msg->msg_iov, ulen,
899 sizeof(struct udphdr), hlimit, tclass, opt, &fl,
900 (struct rt6_info*)dst,
901 corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags);
903 udp_v6_flush_pending_frames(sk);
905 err = udp_v6_push_pending_frames(sk);
906 else if (unlikely(skb_queue_empty(&sk->sk_write_queue)))
911 ip6_dst_store(sk, dst,
912 ipv6_addr_equal(&fl.fl6_dst, &np->daddr) ?
914 #ifdef CONFIG_IPV6_SUBTREES
915 ipv6_addr_equal(&fl.fl6_src, &np->saddr) ?
926 err = np->recverr ? net_xmit_errno(err) : 0;
930 fl6_sock_release(flowlabel);
934 * ENOBUFS = no kernel mem, SOCK_NOSPACE = no sndbuf space. Reporting
935 * ENOBUFS might not be good (it's not tunable per se), but otherwise
936 * we don't have a good statistic (IpOutDiscards but it can be too many
937 * things). We could add another new stat but at least for now that
938 * seems like overkill.
940 if (err == -ENOBUFS || test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) {
941 UDP6_INC_STATS_USER(sock_net(sk),
942 UDP_MIB_SNDBUFERRORS, is_udplite);
948 if (!(msg->msg_flags&MSG_PROBE) || len)
949 goto back_from_confirm;
954 void udpv6_destroy_sock(struct sock *sk)
957 udp_v6_flush_pending_frames(sk);
960 inet6_destroy_sock(sk);
964 * Socket option code for UDP
966 int udpv6_setsockopt(struct sock *sk, int level, int optname,
967 char __user *optval, int optlen)
969 if (level == SOL_UDP || level == SOL_UDPLITE)
970 return udp_lib_setsockopt(sk, level, optname, optval, optlen,
971 udp_v6_push_pending_frames);
972 return ipv6_setsockopt(sk, level, optname, optval, optlen);
976 int compat_udpv6_setsockopt(struct sock *sk, int level, int optname,
977 char __user *optval, int optlen)
979 if (level == SOL_UDP || level == SOL_UDPLITE)
980 return udp_lib_setsockopt(sk, level, optname, optval, optlen,
981 udp_v6_push_pending_frames);
982 return compat_ipv6_setsockopt(sk, level, optname, optval, optlen);
986 int udpv6_getsockopt(struct sock *sk, int level, int optname,
987 char __user *optval, int __user *optlen)
989 if (level == SOL_UDP || level == SOL_UDPLITE)
990 return udp_lib_getsockopt(sk, level, optname, optval, optlen);
991 return ipv6_getsockopt(sk, level, optname, optval, optlen);
995 int compat_udpv6_getsockopt(struct sock *sk, int level, int optname,
996 char __user *optval, int __user *optlen)
998 if (level == SOL_UDP || level == SOL_UDPLITE)
999 return udp_lib_getsockopt(sk, level, optname, optval, optlen);
1000 return compat_ipv6_getsockopt(sk, level, optname, optval, optlen);
1004 static struct inet6_protocol udpv6_protocol = {
1005 .handler = udpv6_rcv,
1006 .err_handler = udpv6_err,
1007 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
1010 /* ------------------------------------------------------------------------ */
1011 #ifdef CONFIG_PROC_FS
1013 static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket)
1015 struct inet_sock *inet = inet_sk(sp);
1016 struct ipv6_pinfo *np = inet6_sk(sp);
1017 struct in6_addr *dest, *src;
1021 src = &np->rcv_saddr;
1022 destp = ntohs(inet->dport);
1023 srcp = ntohs(inet->sport);
1025 "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
1026 "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
1028 src->s6_addr32[0], src->s6_addr32[1],
1029 src->s6_addr32[2], src->s6_addr32[3], srcp,
1030 dest->s6_addr32[0], dest->s6_addr32[1],
1031 dest->s6_addr32[2], dest->s6_addr32[3], destp,
1033 atomic_read(&sp->sk_wmem_alloc),
1034 atomic_read(&sp->sk_rmem_alloc),
1038 atomic_read(&sp->sk_refcnt), sp,
1039 atomic_read(&sp->sk_drops));
1042 int udp6_seq_show(struct seq_file *seq, void *v)
1044 if (v == SEQ_START_TOKEN)
1049 "st tx_queue rx_queue tr tm->when retrnsmt"
1050 " uid timeout inode ref pointer drops\n");
1052 udp6_sock_seq_show(seq, v, ((struct udp_iter_state *)seq->private)->bucket);
1056 static struct udp_seq_afinfo udp6_seq_afinfo = {
1059 .udp_table = &udp_table,
1061 .owner = THIS_MODULE,
1064 .show = udp6_seq_show,
1068 int udp6_proc_init(struct net *net)
1070 return udp_proc_register(net, &udp6_seq_afinfo);
1073 void udp6_proc_exit(struct net *net) {
1074 udp_proc_unregister(net, &udp6_seq_afinfo);
1076 #endif /* CONFIG_PROC_FS */
1078 /* ------------------------------------------------------------------------ */
1080 struct proto udpv6_prot = {
1082 .owner = THIS_MODULE,
1083 .close = udp_lib_close,
1084 .connect = ip6_datagram_connect,
1085 .disconnect = udp_disconnect,
1087 .destroy = udpv6_destroy_sock,
1088 .setsockopt = udpv6_setsockopt,
1089 .getsockopt = udpv6_getsockopt,
1090 .sendmsg = udpv6_sendmsg,
1091 .recvmsg = udpv6_recvmsg,
1092 .backlog_rcv = udpv6_queue_rcv_skb,
1093 .hash = udp_lib_hash,
1094 .unhash = udp_lib_unhash,
1095 .get_port = udp_v6_get_port,
1096 .memory_allocated = &udp_memory_allocated,
1097 .sysctl_mem = sysctl_udp_mem,
1098 .sysctl_wmem = &sysctl_udp_wmem_min,
1099 .sysctl_rmem = &sysctl_udp_rmem_min,
1100 .obj_size = sizeof(struct udp6_sock),
1101 .slab_flags = SLAB_DESTROY_BY_RCU,
1102 .h.udp_table = &udp_table,
1103 #ifdef CONFIG_COMPAT
1104 .compat_setsockopt = compat_udpv6_setsockopt,
1105 .compat_getsockopt = compat_udpv6_getsockopt,
1109 static struct inet_protosw udpv6_protosw = {
1111 .protocol = IPPROTO_UDP,
1112 .prot = &udpv6_prot,
1113 .ops = &inet6_dgram_ops,
1115 .no_check = UDP_CSUM_DEFAULT,
1116 .flags = INET_PROTOSW_PERMANENT,
1120 int __init udpv6_init(void)
1124 ret = inet6_add_protocol(&udpv6_protocol, IPPROTO_UDP);
1128 ret = inet6_register_protosw(&udpv6_protosw);
1130 goto out_udpv6_protocol;
1135 inet6_del_protocol(&udpv6_protocol, IPPROTO_UDP);
1139 void udpv6_exit(void)
1141 inet6_unregister_protosw(&udpv6_protosw);
1142 inet6_del_protocol(&udpv6_protocol, IPPROTO_UDP);