aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/udp.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/udp.c')
-rw-r--r--net/ipv4/udp.c100
1 files changed, 50 insertions, 50 deletions
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 8b54c68a0d12..2a246de6a671 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -20,8 +20,8 @@
20 * for udp at least is 'valid'. 20 * for udp at least is 'valid'.
21 * Alan Cox : Fixed icmp handling properly 21 * Alan Cox : Fixed icmp handling properly
22 * Alan Cox : Correct error for oversized datagrams 22 * Alan Cox : Correct error for oversized datagrams
23 * Alan Cox : Tidied select() semantics. 23 * Alan Cox : Tidied select() semantics.
24 * Alan Cox : udp_err() fixed properly, also now 24 * Alan Cox : udp_err() fixed properly, also now
25 * select and read wake correctly on errors 25 * select and read wake correctly on errors
26 * Alan Cox : udp_send verify_area moved to avoid mem leak 26 * Alan Cox : udp_send verify_area moved to avoid mem leak
27 * Alan Cox : UDP can count its memory 27 * Alan Cox : UDP can count its memory
@@ -56,7 +56,7 @@
56 * does have a high hit rate. 56 * does have a high hit rate.
57 * Olaf Kirch : Don't linearise iovec on sendmsg. 57 * Olaf Kirch : Don't linearise iovec on sendmsg.
58 * Andi Kleen : Some cleanups, cache destination entry 58 * Andi Kleen : Some cleanups, cache destination entry
59 * for connect. 59 * for connect.
60 * Vitaly E. Lavrov : Transparent proxy revived after year coma. 60 * Vitaly E. Lavrov : Transparent proxy revived after year coma.
61 * Melvin Smith : Check msg_name not msg_namelen in sendto(), 61 * Melvin Smith : Check msg_name not msg_namelen in sendto(),
62 * return ENOTCONN for unconnected sockets (POSIX) 62 * return ENOTCONN for unconnected sockets (POSIX)
@@ -77,7 +77,7 @@
77 * as published by the Free Software Foundation; either version 77 * as published by the Free Software Foundation; either version
78 * 2 of the License, or (at your option) any later version. 78 * 2 of the License, or (at your option) any later version.
79 */ 79 */
80 80
81#include <asm/system.h> 81#include <asm/system.h>
82#include <asm/uaccess.h> 82#include <asm/uaccess.h>
83#include <asm/ioctls.h> 83#include <asm/ioctls.h>
@@ -306,17 +306,17 @@ static inline struct sock *udp_v4_mcast_next(struct sock *sk,
306 if (!ip_mc_sf_allow(s, loc_addr, rmt_addr, dif)) 306 if (!ip_mc_sf_allow(s, loc_addr, rmt_addr, dif))
307 continue; 307 continue;
308 goto found; 308 goto found;
309 } 309 }
310 s = NULL; 310 s = NULL;
311found: 311found:
312 return s; 312 return s;
313} 313}
314 314
315/* 315/*
316 * This routine is called by the ICMP module when it gets some 316 * This routine is called by the ICMP module when it gets some
317 * sort of error condition. If err < 0 then the socket should 317 * sort of error condition. If err < 0 then the socket should
318 * be closed and the error returned to the user. If err > 0 318 * be closed and the error returned to the user. If err > 0
319 * it's just the icmp type << 8 | icmp code. 319 * it's just the icmp type << 8 | icmp code.
320 * Header points to the ip header of the error packet. We move 320 * Header points to the ip header of the error packet. We move
321 * on past this. Then (as it used to claim before adjustment) 321 * on past this. Then (as it used to claim before adjustment)
322 * header points to the first 8 bytes of the udp header. We need 322 * header points to the first 8 bytes of the udp header. We need
@@ -338,7 +338,7 @@ void __udp4_lib_err(struct sk_buff *skb, u32 info, struct hlist_head udptable[])
338 skb->dev->ifindex, udptable ); 338 skb->dev->ifindex, udptable );
339 if (sk == NULL) { 339 if (sk == NULL) {
340 ICMP_INC_STATS_BH(ICMP_MIB_INERRORS); 340 ICMP_INC_STATS_BH(ICMP_MIB_INERRORS);
341 return; /* No socket for error */ 341 return; /* No socket for error */
342 } 342 }
343 343
344 err = 0; 344 err = 0;
@@ -374,7 +374,7 @@ void __udp4_lib_err(struct sk_buff *skb, u32 info, struct hlist_head udptable[])
374 } 374 }
375 375
376 /* 376 /*
377 * RFC1122: OK. Passes ICMP errors back to application, as per 377 * RFC1122: OK. Passes ICMP errors back to application, as per
378 * 4.1.3.3. 378 * 4.1.3.3.
379 */ 379 */
380 if (!inet->recverr) { 380 if (!inet->recverr) {
@@ -524,7 +524,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
524 if (len > 0xFFFF) 524 if (len > 0xFFFF)
525 return -EMSGSIZE; 525 return -EMSGSIZE;
526 526
527 /* 527 /*
528 * Check the flags. 528 * Check the flags.
529 */ 529 */
530 530
@@ -536,7 +536,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
536 if (up->pending) { 536 if (up->pending) {
537 /* 537 /*
538 * There are pending frames. 538 * There are pending frames.
539 * The socket lock must be held while it's corked. 539 * The socket lock must be held while it's corked.
540 */ 540 */
541 lock_sock(sk); 541 lock_sock(sk);
542 if (likely(up->pending)) { 542 if (likely(up->pending)) {
@@ -544,14 +544,14 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
544 release_sock(sk); 544 release_sock(sk);
545 return -EINVAL; 545 return -EINVAL;
546 } 546 }
547 goto do_append_data; 547 goto do_append_data;
548 } 548 }
549 release_sock(sk); 549 release_sock(sk);
550 } 550 }
551 ulen += sizeof(struct udphdr); 551 ulen += sizeof(struct udphdr);
552 552
553 /* 553 /*
554 * Get and verify the address. 554 * Get and verify the address.
555 */ 555 */
556 if (msg->msg_name) { 556 if (msg->msg_name) {
557 struct sockaddr_in * usin = (struct sockaddr_in*)msg->msg_name; 557 struct sockaddr_in * usin = (struct sockaddr_in*)msg->msg_name;
@@ -575,7 +575,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
575 Route will not be used, if at least one option is set. 575 Route will not be used, if at least one option is set.
576 */ 576 */
577 connected = 1; 577 connected = 1;
578 } 578 }
579 ipc.addr = inet->saddr; 579 ipc.addr = inet->saddr;
580 580
581 ipc.oif = sk->sk_bound_dev_if; 581 ipc.oif = sk->sk_bound_dev_if;
@@ -601,7 +601,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
601 } 601 }
602 tos = RT_TOS(inet->tos); 602 tos = RT_TOS(inet->tos);
603 if (sock_flag(sk, SOCK_LOCALROUTE) || 603 if (sock_flag(sk, SOCK_LOCALROUTE) ||
604 (msg->msg_flags & MSG_DONTROUTE) || 604 (msg->msg_flags & MSG_DONTROUTE) ||
605 (ipc.opt && ipc.opt->is_strictroute)) { 605 (ipc.opt && ipc.opt->is_strictroute)) {
606 tos |= RTO_ONLINK; 606 tos |= RTO_ONLINK;
607 connected = 0; 607 connected = 0;
@@ -761,10 +761,10 @@ out:
761/* 761/*
762 * IOCTL requests applicable to the UDP protocol 762 * IOCTL requests applicable to the UDP protocol
763 */ 763 */
764 764
765int udp_ioctl(struct sock *sk, int cmd, unsigned long arg) 765int udp_ioctl(struct sock *sk, int cmd, unsigned long arg)
766{ 766{
767 switch(cmd) 767 switch(cmd)
768 { 768 {
769 case SIOCOUTQ: 769 case SIOCOUTQ:
770 { 770 {
@@ -804,11 +804,11 @@ int udp_ioctl(struct sock *sk, int cmd, unsigned long arg)
804 */ 804 */
805 805
806int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, 806int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
807 size_t len, int noblock, int flags, int *addr_len) 807 size_t len, int noblock, int flags, int *addr_len)
808{ 808{
809 struct inet_sock *inet = inet_sk(sk); 809 struct inet_sock *inet = inet_sk(sk);
810 struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name; 810 struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name;
811 struct sk_buff *skb; 811 struct sk_buff *skb;
812 int copied, err, copy_only, is_udplite = IS_UDPLITE(sk); 812 int copied, err, copy_only, is_udplite = IS_UDPLITE(sk);
813 813
814 /* 814 /*
@@ -824,8 +824,8 @@ try_again:
824 skb = skb_recv_datagram(sk, flags, noblock, &err); 824 skb = skb_recv_datagram(sk, flags, noblock, &err);
825 if (!skb) 825 if (!skb)
826 goto out; 826 goto out;
827 827
828 copied = skb->len - sizeof(struct udphdr); 828 copied = skb->len - sizeof(struct udphdr);
829 if (copied > len) { 829 if (copied > len) {
830 copied = len; 830 copied = len;
831 msg->msg_flags |= MSG_TRUNC; 831 msg->msg_flags |= MSG_TRUNC;
@@ -868,18 +868,18 @@ try_again:
868 sin->sin_port = skb->h.uh->source; 868 sin->sin_port = skb->h.uh->source;
869 sin->sin_addr.s_addr = skb->nh.iph->saddr; 869 sin->sin_addr.s_addr = skb->nh.iph->saddr;
870 memset(sin->sin_zero, 0, sizeof(sin->sin_zero)); 870 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
871 } 871 }
872 if (inet->cmsg_flags) 872 if (inet->cmsg_flags)
873 ip_cmsg_recv(msg, skb); 873 ip_cmsg_recv(msg, skb);
874 874
875 err = copied; 875 err = copied;
876 if (flags & MSG_TRUNC) 876 if (flags & MSG_TRUNC)
877 err = skb->len - sizeof(struct udphdr); 877 err = skb->len - sizeof(struct udphdr);
878 878
879out_free: 879out_free:
880 skb_free_datagram(sk, skb); 880 skb_free_datagram(sk, skb);
881out: 881out:
882 return err; 882 return err;
883 883
884csum_copy_err: 884csum_copy_err:
885 UDP_INC_STATS_BH(UDP_MIB_INERRORS, is_udplite); 885 UDP_INC_STATS_BH(UDP_MIB_INERRORS, is_udplite);
@@ -887,7 +887,7 @@ csum_copy_err:
887 skb_kill_datagram(sk, skb, flags); 887 skb_kill_datagram(sk, skb, flags);
888 888
889 if (noblock) 889 if (noblock)
890 return -EAGAIN; 890 return -EAGAIN;
891 goto try_again; 891 goto try_again;
892} 892}
893 893
@@ -898,7 +898,7 @@ int udp_disconnect(struct sock *sk, int flags)
898 /* 898 /*
899 * 1003.1g - break association. 899 * 1003.1g - break association.
900 */ 900 */
901 901
902 sk->sk_state = TCP_CLOSE; 902 sk->sk_state = TCP_CLOSE;
903 inet->daddr = 0; 903 inet->daddr = 0;
904 inet->dport = 0; 904 inet->dport = 0;
@@ -922,13 +922,13 @@ int udp_disconnect(struct sock *sk, int flags)
922static int udp_encap_rcv(struct sock * sk, struct sk_buff *skb) 922static int udp_encap_rcv(struct sock * sk, struct sk_buff *skb)
923{ 923{
924#ifndef CONFIG_XFRM 924#ifndef CONFIG_XFRM
925 return 1; 925 return 1;
926#else 926#else
927 struct udp_sock *up = udp_sk(sk); 927 struct udp_sock *up = udp_sk(sk);
928 struct udphdr *uh; 928 struct udphdr *uh;
929 struct iphdr *iph; 929 struct iphdr *iph;
930 int iphlen, len; 930 int iphlen, len;
931 931
932 __u8 *udpdata; 932 __u8 *udpdata;
933 __be32 *udpdata32; 933 __be32 *udpdata32;
934 __u16 encap_type = up->encap_type; 934 __u16 encap_type = up->encap_type;
@@ -971,7 +971,7 @@ static int udp_encap_rcv(struct sock * sk, struct sk_buff *skb)
971 return 0; 971 return 0;
972 } else if (len > 2 * sizeof(u32) + sizeof(struct ip_esp_hdr) && 972 } else if (len > 2 * sizeof(u32) + sizeof(struct ip_esp_hdr) &&
973 udpdata32[0] == 0 && udpdata32[1] == 0) { 973 udpdata32[0] == 0 && udpdata32[1] == 0) {
974 974
975 /* ESP Packet with Non-IKE marker */ 975 /* ESP Packet with Non-IKE marker */
976 len = sizeof(struct udphdr) + 2 * sizeof(u32); 976 len = sizeof(struct udphdr) + 2 * sizeof(u32);
977 } else 977 } else
@@ -1187,14 +1187,14 @@ static inline void udp4_csum_init(struct sk_buff *skb, struct udphdr *uh)
1187} 1187}
1188 1188
1189/* 1189/*
1190 * All we need to do is get the socket, and then do a checksum. 1190 * All we need to do is get the socket, and then do a checksum.
1191 */ 1191 */
1192 1192
1193int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[], 1193int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
1194 int is_udplite) 1194 int is_udplite)
1195{ 1195{
1196 struct sock *sk; 1196 struct sock *sk;
1197 struct udphdr *uh = skb->h.uh; 1197 struct udphdr *uh = skb->h.uh;
1198 unsigned short ulen; 1198 unsigned short ulen;
1199 struct rtable *rt = (struct rtable*)skb->dst; 1199 struct rtable *rt = (struct rtable*)skb->dst;
1200 __be32 saddr = skb->nh.iph->saddr; 1200 __be32 saddr = skb->nh.iph->saddr;
@@ -1270,9 +1270,9 @@ short_packet:
1270 goto drop; 1270 goto drop;
1271 1271
1272csum_error: 1272csum_error:
1273 /* 1273 /*
1274 * RFC1122: OK. Discards the bad packet silently (as far as 1274 * RFC1122: OK. Discards the bad packet silently (as far as
1275 * the network is concerned, anyway) as per 4.1.3.4 (MUST). 1275 * the network is concerned, anyway) as per 4.1.3.4 (MUST).
1276 */ 1276 */
1277 LIMIT_NETDEBUG(KERN_DEBUG "UDP%s: bad checksum. From %d.%d.%d.%d:%d to %d.%d.%d.%d:%d ulen %d\n", 1277 LIMIT_NETDEBUG(KERN_DEBUG "UDP%s: bad checksum. From %d.%d.%d.%d:%d to %d.%d.%d.%d:%d ulen %d\n",
1278 is_udplite? "-Lite" : "", 1278 is_udplite? "-Lite" : "",
@@ -1328,7 +1328,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
1328 release_sock(sk); 1328 release_sock(sk);
1329 } 1329 }
1330 break; 1330 break;
1331 1331
1332 case UDP_ENCAP: 1332 case UDP_ENCAP:
1333 switch (val) { 1333 switch (val) {
1334 case 0: 1334 case 0:
@@ -1356,8 +1356,8 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
1356 up->pcflag |= UDPLITE_SEND_CC; 1356 up->pcflag |= UDPLITE_SEND_CC;
1357 break; 1357 break;
1358 1358
1359 /* The receiver specifies a minimum checksum coverage value. To make 1359 /* The receiver specifies a minimum checksum coverage value. To make
1360 * sense, this should be set to at least 8 (as done below). If zero is 1360 * sense, this should be set to at least 8 (as done below). If zero is
1361 * used, this again means full checksum coverage. */ 1361 * used, this again means full checksum coverage. */
1362 case UDPLITE_RECV_CSCOV: 1362 case UDPLITE_RECV_CSCOV:
1363 if (!up->pcflag) /* Disable the option on UDP sockets */ 1363 if (!up->pcflag) /* Disable the option on UDP sockets */
@@ -1406,7 +1406,7 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname,
1406 return -EFAULT; 1406 return -EFAULT;
1407 1407
1408 len = min_t(unsigned int, len, sizeof(int)); 1408 len = min_t(unsigned int, len, sizeof(int));
1409 1409
1410 if(len < 0) 1410 if(len < 0)
1411 return -EINVAL; 1411 return -EINVAL;
1412 1412
@@ -1433,11 +1433,11 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname,
1433 return -ENOPROTOOPT; 1433 return -ENOPROTOOPT;
1434 }; 1434 };
1435 1435
1436 if(put_user(len, optlen)) 1436 if(put_user(len, optlen))
1437 return -EFAULT; 1437 return -EFAULT;
1438 if(copy_to_user(optval, &val,len)) 1438 if(copy_to_user(optval, &val,len))
1439 return -EFAULT; 1439 return -EFAULT;
1440 return 0; 1440 return 0;
1441} 1441}
1442 1442
1443int udp_getsockopt(struct sock *sk, int level, int optname, 1443int udp_getsockopt(struct sock *sk, int level, int optname,
@@ -1463,7 +1463,7 @@ int compat_udp_getsockopt(struct sock *sk, int level, int optname,
1463 * @sock - socket 1463 * @sock - socket
1464 * @wait - poll table 1464 * @wait - poll table
1465 * 1465 *
1466 * This is same as datagram poll, except for the special case of 1466 * This is same as datagram poll, except for the special case of
1467 * blocking sockets. If application is using a blocking fd 1467 * blocking sockets. If application is using a blocking fd
1468 * and a packet with checksum error is in the queue; 1468 * and a packet with checksum error is in the queue;
1469 * then it could get return from select indicating data available 1469 * then it could get return from select indicating data available
@@ -1502,11 +1502,11 @@ unsigned int udp_poll(struct file *file, struct socket *sock, poll_table *wait)
1502 } 1502 }
1503 1503
1504 return mask; 1504 return mask;
1505 1505
1506} 1506}
1507 1507
1508struct proto udp_prot = { 1508struct proto udp_prot = {
1509 .name = "UDP", 1509 .name = "UDP",
1510 .owner = THIS_MODULE, 1510 .owner = THIS_MODULE,
1511 .close = udp_lib_close, 1511 .close = udp_lib_close,
1512 .connect = ip4_datagram_connect, 1512 .connect = ip4_datagram_connect,
@@ -1670,7 +1670,7 @@ static void udp4_format_sock(struct sock *sp, char *tmpbuf, int bucket)
1670 1670
1671 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X" 1671 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
1672 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p", 1672 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
1673 bucket, src, srcp, dest, destp, sp->sk_state, 1673 bucket, src, srcp, dest, destp, sp->sk_state,
1674 atomic_read(&sp->sk_wmem_alloc), 1674 atomic_read(&sp->sk_wmem_alloc),
1675 atomic_read(&sp->sk_rmem_alloc), 1675 atomic_read(&sp->sk_rmem_alloc),
1676 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp), 1676 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),