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

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