patch-1.3.38 linux/net/ipv4/udp.c

Next file: linux/net/ipx/af_ipx.c
Previous file: linux/net/ipv4/tcp.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.37/linux/net/ipv4/udp.c linux/net/ipv4/udp.c
@@ -397,16 +397,40 @@
 }
 
 /*
- *	In BSD SOCK_DGRAM a write is just like a send.
+ *	Temporary
  */
-
-static int udp_write(struct sock *sk, const unsigned char *buff, int len, int noblock,
-	  unsigned flags)
+ 
+static int udp_sendmsg(struct sock *sk, struct msghdr *msg,
+	int len, int noblock, int flags)
 {
-	return(udp_sendto(sk, buff, len, noblock, flags, NULL, 0));
+	if(msg->msg_iovlen==1)
+		return udp_sendto(sk,msg->msg_iov[0].iov_base,len, noblock, flags, msg->msg_name, msg->msg_namelen);
+	else
+	{
+		/*
+		 *	For awkward cases we linearise the buffer first. In theory this is only frames
+		 *	whose iovec's don't split on 4 byte boundaries, and soon encrypted stuff (to keep
+		 *	skip happy). We are a bit more general about it.
+		 */
+		 
+		unsigned char *buf;
+		int fs;
+		int err;
+		if(len>65515)
+			return -EMSGSIZE;
+		buf=kmalloc(len, GFP_KERNEL);
+		if(buf==NULL)
+			return -ENOBUFS;
+		memcpy_fromiovec(buf, msg->msg_iov, len);
+		fs=get_fs();
+		set_fs(get_fs());
+		err=udp_sendto(sk,buf,len, noblock, flags, msg->msg_name, msg->msg_namelen);
+		set_fs(fs);
+		kfree_s(buf,len);
+		return err;
+	}
 }
 
-
 /*
  *	IOCTL requests applicable to the UDP protocol
  */
@@ -514,38 +538,6 @@
   	return(copied);
 }
 
-int udp_recvfrom(struct sock *sk, unsigned char *ubuf, int size, int noblock, unsigned flags,
-		struct sockaddr_in *sa, int *addr_len)
-{
-	struct iovec iov;
-	struct msghdr msg;
-
-	iov.iov_base = ubuf;
-	iov.iov_len  = size;
-
-	msg.msg_name      = (void *)sa;
-	msg.msg_namelen   = 0;
-	if (addr_len)
-		msg.msg_namelen = *addr_len;
-	msg.msg_accrights = NULL;
-	msg.msg_iov       = &iov;
-	msg.msg_iovlen    = 1;
-
-	return udp_recvmsg(sk, &msg, size, noblock, flags, addr_len);
-}
-
-
-/*
- *	Read has the same semantics as recv in SOCK_DGRAM
- */
-
-int udp_read(struct sock *sk, unsigned char *buff, int len, int noblock,
-	 unsigned flags)
-{
-	return(udp_recvfrom(sk, buff, len, noblock, flags, NULL, NULL));
-}
-
-
 int udp_connect(struct sock *sk, struct sockaddr_in *usin, int addr_len)
 {
 	struct rtable *rt;
@@ -760,10 +752,6 @@
 
 struct proto udp_prot = {
 	udp_close,
-	udp_read,
-	udp_write,
-	udp_sendto,
-	udp_recvfrom,
 	ip_build_header,
 	udp_connect,
 	NULL,
@@ -778,8 +766,9 @@
 	NULL,
 	ip_setsockopt,
 	ip_getsockopt,
-	NULL,
+	udp_sendmsg,
 	udp_recvmsg,
+	NULL,		/* No special bind function */
 	128,
 	0,
 	"UDP",

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this