Blame SOURCES/dhcp-4.2.2-xen-checksum.patch

fad460
diff -up dhcp-4.2.2b1/common/bpf.c.xen dhcp-4.2.2b1/common/bpf.c
fad460
--- dhcp-4.2.2b1/common/bpf.c.xen	2009-11-20 02:48:59.000000000 +0100
fad460
+++ dhcp-4.2.2b1/common/bpf.c	2011-07-01 14:00:16.936959001 +0200
fad460
@@ -485,7 +485,7 @@ ssize_t receive_packet (interface, buf, 
fad460
 		offset = decode_udp_ip_header (interface,
fad460
 					       interface -> rbuf,
fad460
 					       interface -> rbuf_offset,
fad460
-  					       from, hdr.bh_caplen, &paylen);
fad460
+  					       from, hdr.bh_caplen, &paylen, 0);
fad460
 
fad460
 		/* If the IP or UDP checksum was bad, skip the packet... */
fad460
 		if (offset < 0) {
fad460
diff -up dhcp-4.2.2b1/common/dlpi.c.xen dhcp-4.2.2b1/common/dlpi.c
fad460
--- dhcp-4.2.2b1/common/dlpi.c.xen	2011-05-11 16:20:59.000000000 +0200
fad460
+++ dhcp-4.2.2b1/common/dlpi.c	2011-07-01 14:00:16.937958997 +0200
fad460
@@ -693,7 +693,7 @@ ssize_t receive_packet (interface, buf, 
fad460
 	length -= offset;
fad460
 #endif
fad460
 	offset = decode_udp_ip_header (interface, dbuf, bufix,
fad460
-				       from, length, &paylen);
fad460
+				       from, length, &paylen, 0);
fad460
 
fad460
 	/*
fad460
 	 * If the IP or UDP checksum was bad, skip the packet...
fad460
diff -up dhcp-4.2.2b1/common/lpf.c.xen dhcp-4.2.2b1/common/lpf.c
fad460
--- dhcp-4.2.2b1/common/lpf.c.xen	2011-05-10 16:38:58.000000000 +0200
fad460
+++ dhcp-4.2.2b1/common/lpf.c	2011-07-01 14:11:24.725748028 +0200
fad460
@@ -29,19 +29,33 @@
fad460
 #include "dhcpd.h"
fad460
 #if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE)
fad460
 #include <sys/ioctl.h>
fad460
+#include <sys/socket.h>
fad460
 #include <sys/uio.h>
fad460
 #include <errno.h>
fad460
 
fad460
 #include <asm/types.h>
fad460
 #include <linux/filter.h>
fad460
 #include <linux/if_ether.h>
fad460
+#include <linux/if_packet.h>
fad460
 #include <netinet/in_systm.h>
fad460
-#include <net/if_packet.h>
fad460
 #include "includes/netinet/ip.h"
fad460
 #include "includes/netinet/udp.h"
fad460
 #include "includes/netinet/if_ether.h"
fad460
 #include <net/if.h>
fad460
 
fad460
+#ifndef PACKET_AUXDATA
fad460
+#define PACKET_AUXDATA 8
fad460
+
fad460
+struct tpacket_auxdata
fad460
+{
fad460
+	__u32		tp_status;
fad460
+	__u32		tp_len;
fad460
+	__u32		tp_snaplen;
fad460
+	__u16		tp_mac;
fad460
+	__u16		tp_net;
fad460
+};
fad460
+#endif
fad460
+
fad460
 /* Reinitializes the specified interface after an address change.   This
fad460
    is not required for packet-filter APIs. */
fad460
 
fad460
@@ -67,10 +81,14 @@ int if_register_lpf (info)
fad460
 	struct interface_info *info;
fad460
 {
fad460
 	int sock;
fad460
-	struct sockaddr sa;
fad460
+	union {
fad460
+		struct sockaddr_ll ll;
fad460
+		struct sockaddr common;
fad460
+	} sa;
fad460
+	struct ifreq ifr;
fad460
 
fad460
 	/* Make an LPF socket. */
fad460
-	if ((sock = socket(PF_PACKET, SOCK_PACKET,
fad460
+	if ((sock = socket(PF_PACKET, SOCK_RAW,
fad460
 			   htons((short)ETH_P_ALL))) < 0) {
fad460
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
fad460
 		    errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
fad460
@@ -85,11 +103,17 @@ int if_register_lpf (info)
fad460
 		log_fatal ("Open a socket for LPF: %m");
fad460
 	}
fad460
 
fad460
+	memset (&ifr, 0, sizeof ifr);
fad460
+	strncpy (ifr.ifr_name, (const char *)info -> ifp, sizeof ifr.ifr_name);
fad460
+	ifr.ifr_name[IFNAMSIZ-1] = '\0';
fad460
+	if (ioctl (sock, SIOCGIFINDEX, &ifr))
fad460
+		log_fatal ("Failed to get interface index: %m");
fad460
+
fad460
 	/* Bind to the interface name */
fad460
 	memset (&sa, 0, sizeof sa);
fad460
-	sa.sa_family = AF_PACKET;
fad460
-	strncpy (sa.sa_data, (const char *)info -> ifp, sizeof sa.sa_data);
fad460
-	if (bind (sock, &sa, sizeof sa)) {
fad460
+	sa.ll.sll_family = AF_PACKET;
fad460
+	sa.ll.sll_ifindex = ifr.ifr_ifindex;
fad460
+	if (bind (sock, &sa.common, sizeof sa)) {
fad460
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
fad460
 		    errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
fad460
 		    errno == EAFNOSUPPORT || errno == EINVAL) {
fad460
@@ -171,9 +195,18 @@ static void lpf_gen_filter_setup (struct
fad460
 void if_register_receive (info)
fad460
 	struct interface_info *info;
fad460
 {
fad460
+	int val;
fad460
+
fad460
 	/* Open a LPF device and hang it on this interface... */
fad460
 	info -> rfdesc = if_register_lpf (info);
fad460
 
fad460
+	val = 1;
fad460
+	if (setsockopt (info -> rfdesc, SOL_PACKET, PACKET_AUXDATA, &val,
fad460
+			sizeof val) < 0) {
fad460
+		if (errno != ENOPROTOOPT)
fad460
+			log_fatal ("Failed to set auxiliary packet data: %m");
fad460
+	}
fad460
+
fad460
 #if defined (HAVE_TR_SUPPORT)
fad460
 	if (info -> hw_address.hbuf [0] == HTYPE_IEEE802)
fad460
 		lpf_tr_filter_setup (info);
fad460
@@ -295,7 +328,6 @@ ssize_t send_packet (interface, packet, 
fad460
 	double hh [16];
fad460
 	double ih [1536 / sizeof (double)];
fad460
 	unsigned char *buf = (unsigned char *)ih;
fad460
-	struct sockaddr_pkt sa;
fad460
 	int result;
fad460
 	int fudge;
fad460
 
fad460
@@ -316,17 +348,7 @@ ssize_t send_packet (interface, packet, 
fad460
 				(unsigned char *)raw, len);
fad460
 	memcpy (buf + ibufp, raw, len);
fad460
 
fad460
-	/* For some reason, SOCK_PACKET sockets can't be connected,
fad460
-	   so we have to do a sentdo every time. */
fad460
-	memset (&sa, 0, sizeof sa);
fad460
-	sa.spkt_family = AF_PACKET;
fad460
-	strncpy ((char *)sa.spkt_device,
fad460
-		 (const char *)interface -> ifp, sizeof sa.spkt_device);
fad460
-	sa.spkt_protocol = htons(ETH_P_IP);
fad460
-
fad460
-	result = sendto (interface -> wfdesc,
fad460
-			 buf + fudge, ibufp + len - fudge, 0, 
fad460
-			 (const struct sockaddr *)&sa, sizeof sa);
fad460
+	result = write (interface -> wfdesc, buf + fudge, ibufp + len - fudge);
fad460
 	if (result < 0)
fad460
 		log_error ("send_packet: %m");
fad460
 	return result;
fad460
@@ -343,14 +365,35 @@ ssize_t receive_packet (interface, buf, 
fad460
 {
fad460
 	int length = 0;
fad460
 	int offset = 0;
fad460
+	int nocsum = 0;
fad460
 	unsigned char ibuf [1536];
fad460
 	unsigned bufix = 0;
fad460
 	unsigned paylen;
fad460
+	unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
fad460
+	struct iovec iov = {
fad460
+		.iov_base = ibuf,
fad460
+		.iov_len = sizeof ibuf,
fad460
+	};
fad460
+	struct msghdr msg = {
fad460
+		.msg_iov = &iov,
fad460
+		.msg_iovlen = 1,
fad460
+		.msg_control = cmsgbuf,
fad460
+		.msg_controllen = sizeof(cmsgbuf),
fad460
+	};
fad460
+	struct cmsghdr *cmsg;
fad460
 
fad460
-	length = read (interface -> rfdesc, ibuf, sizeof ibuf);
fad460
+	length = recvmsg (interface -> rfdesc, &msg, 0);
fad460
 	if (length <= 0)
fad460
 		return length;
fad460
 
fad460
+	for (cmsg = CMSG_FIRSTHDR(&msg;; cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
fad460
+		if (cmsg->cmsg_level == SOL_PACKET &&
fad460
+		    cmsg->cmsg_type == PACKET_AUXDATA) {
fad460
+			struct tpacket_auxdata *aux = (void *)CMSG_DATA(cmsg);
fad460
+			nocsum = aux->tp_status & TP_STATUS_CSUMNOTREADY;
fad460
+		}
fad460
+	}
fad460
+
fad460
 	bufix = 0;
fad460
 	/* Decode the physical header... */
fad460
 	offset = decode_hw_header (interface, ibuf, bufix, hfrom);
fad460
@@ -367,7 +410,7 @@ ssize_t receive_packet (interface, buf, 
fad460
 
fad460
 	/* Decode the IP and UDP headers... */
fad460
 	offset = decode_udp_ip_header (interface, ibuf, bufix, from,
fad460
-				       (unsigned)length, &paylen);
fad460
+				       (unsigned)length, &paylen, nocsum);
fad460
 
fad460
 	/* If the IP or UDP checksum was bad, skip the packet... */
fad460
 	if (offset < 0)
fad460
diff -up dhcp-4.2.2b1/common/nit.c.xen dhcp-4.2.2b1/common/nit.c
fad460
--- dhcp-4.2.2b1/common/nit.c.xen	2009-11-20 02:49:01.000000000 +0100
fad460
+++ dhcp-4.2.2b1/common/nit.c	2011-07-01 14:00:16.939958989 +0200
fad460
@@ -369,7 +369,7 @@ ssize_t receive_packet (interface, buf, 
fad460
 
fad460
 	/* Decode the IP and UDP headers... */
fad460
 	offset = decode_udp_ip_header (interface, ibuf, bufix,
fad460
-				       from, length, &paylen);
fad460
+				       from, length, &paylen, 0);
fad460
 
fad460
 	/* If the IP or UDP checksum was bad, skip the packet... */
fad460
 	if (offset < 0)
fad460
diff -up dhcp-4.2.2b1/common/packet.c.xen dhcp-4.2.2b1/common/packet.c
fad460
--- dhcp-4.2.2b1/common/packet.c.xen	2009-07-23 20:52:20.000000000 +0200
fad460
+++ dhcp-4.2.2b1/common/packet.c	2011-07-01 14:00:16.939958989 +0200
fad460
@@ -211,7 +211,7 @@ ssize_t
fad460
 decode_udp_ip_header(struct interface_info *interface,
fad460
 		     unsigned char *buf, unsigned bufix,
fad460
 		     struct sockaddr_in *from, unsigned buflen,
fad460
-		     unsigned *rbuflen)
fad460
+		     unsigned *rbuflen, int nocsum)
fad460
 {
fad460
   unsigned char *data;
fad460
   struct ip ip;
fad460
@@ -322,7 +322,7 @@ decode_udp_ip_header(struct interface_in
fad460
 					   8, IPPROTO_UDP + ulen))));
fad460
 
fad460
   udp_packets_seen++;
fad460
-  if (usum && usum != sum) {
fad460
+  if (!nocsum && usum && usum != sum) {
fad460
 	  udp_packets_bad_checksum++;
fad460
 	  if (udp_packets_seen > 4 &&
fad460
 	      (udp_packets_seen / udp_packets_bad_checksum) < 2) {
fad460
diff -up dhcp-4.2.2b1/common/upf.c.xen dhcp-4.2.2b1/common/upf.c
fad460
--- dhcp-4.2.2b1/common/upf.c.xen	2009-11-20 02:49:01.000000000 +0100
fad460
+++ dhcp-4.2.2b1/common/upf.c	2011-07-01 14:00:16.940958986 +0200
fad460
@@ -320,7 +320,7 @@ ssize_t receive_packet (interface, buf, 
fad460
 
fad460
 	/* Decode the IP and UDP headers... */
fad460
 	offset = decode_udp_ip_header (interface, ibuf, bufix,
fad460
-				       from, length, &paylen);
fad460
+				       from, length, &paylen, 0);
fad460
 
fad460
 	/* If the IP or UDP checksum was bad, skip the packet... */
fad460
 	if (offset < 0)
fad460
diff -up dhcp-4.2.2b1/includes/dhcpd.h.xen dhcp-4.2.2b1/includes/dhcpd.h
fad460
--- dhcp-4.2.2b1/includes/dhcpd.h.xen	2011-07-01 14:00:16.000000000 +0200
fad460
+++ dhcp-4.2.2b1/includes/dhcpd.h	2011-07-01 14:12:18.069642470 +0200
fad460
@@ -2796,7 +2796,7 @@ ssize_t decode_hw_header (struct interfa
fad460
 			  unsigned, struct hardware *);
fad460
 ssize_t decode_udp_ip_header (struct interface_info *, unsigned char *,
fad460
 			      unsigned, struct sockaddr_in *,
fad460
-			      unsigned, unsigned *);
fad460
+			      unsigned, unsigned *, int);
fad460
 
fad460
 /* ethernet.c */
fad460
 void assemble_ethernet_header (struct interface_info *, unsigned char *,