c987ce5
diff -up dhcp-4.0.0/common/nit.c.xen dhcp-4.0.0/common/nit.c
c987ce5
--- dhcp-4.0.0/common/nit.c.xen	2007-09-05 07:32:10.000000000 -1000
c987ce5
+++ dhcp-4.0.0/common/nit.c	2007-12-29 06:39:16.000000000 -1000
c987ce5
@@ -366,7 +366,7 @@ ssize_t receive_packet (interface, buf, 
0713d0c
 
af39808
 	/* Decode the IP and UDP headers... */
af39808
 	offset = decode_udp_ip_header (interface, ibuf, bufix,
af39808
-				       from, length, &paylen);
af39808
+				       from, length, &paylen, 0);
27c9546
 
af39808
 	/* If the IP or UDP checksum was bad, skip the packet... */
af39808
 	if (offset < 0)
c987ce5
diff -up dhcp-4.0.0/common/dlpi.c.xen dhcp-4.0.0/common/dlpi.c
c987ce5
--- dhcp-4.0.0/common/dlpi.c.xen	2007-10-08 04:27:53.000000000 -1000
c987ce5
+++ dhcp-4.0.0/common/dlpi.c	2007-12-29 06:39:13.000000000 -1000
c987ce5
@@ -689,7 +689,7 @@ ssize_t receive_packet (interface, buf, 
27c9546
 	length -= offset;
27c9546
 #endif
27c9546
 	offset = decode_udp_ip_header (interface, dbuf, bufix,
0713d0c
-				       from, length, &paylen);
0713d0c
+				       from, length, &paylen, 0);
27c9546
 
27c9546
 	/* If the IP or UDP checksum was bad, skip the packet... */
27c9546
 	if (offset < 0) {
c987ce5
diff -up dhcp-4.0.0/common/upf.c.xen dhcp-4.0.0/common/upf.c
c987ce5
--- dhcp-4.0.0/common/upf.c.xen	2007-07-12 20:43:42.000000000 -1000
c987ce5
+++ dhcp-4.0.0/common/upf.c	2007-12-29 06:39:24.000000000 -1000
c987ce5
@@ -317,7 +317,7 @@ ssize_t receive_packet (interface, buf, 
af39808
 
af39808
 	/* Decode the IP and UDP headers... */
af39808
 	offset = decode_udp_ip_header (interface, ibuf, bufix,
af39808
-				       from, length, &paylen);
af39808
+				       from, length, &paylen, 0);
af39808
 
af39808
 	/* If the IP or UDP checksum was bad, skip the packet... */
af39808
 	if (offset < 0)
c987ce5
diff -up dhcp-4.0.0/common/lpf.c.xen dhcp-4.0.0/common/lpf.c
c987ce5
--- dhcp-4.0.0/common/lpf.c.xen	2007-12-29 06:37:53.000000000 -1000
c987ce5
+++ dhcp-4.0.0/common/lpf.c	2007-12-29 06:43:08.000000000 -1000
c987ce5
@@ -29,18 +29,33 @@
27c9546
 #include "dhcpd.h"
27c9546
 #if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE)
27c9546
 #include <sys/ioctl.h>
27c9546
+#include <sys/socket.h>
27c9546
 #include <sys/uio.h>
c987ce5
 #include <errno.h>
27c9546
 
27c9546
 #include <asm/types.h>
27c9546
 #include <linux/filter.h>
27c9546
 #include <linux/if_ether.h>
27c9546
+#include <linux/if_packet.h>
27c9546
 #include <netinet/in_systm.h>
27c9546
 #include "includes/netinet/ip.h"
27c9546
 #include "includes/netinet/udp.h"
27c9546
 #include "includes/netinet/if_ether.h"
c987ce5
 #include <net/if.h>
27c9546
 
27c9546
+#ifndef PACKET_AUXDATA
27c9546
+#define PACKET_AUXDATA 8
27c9546
+
27c9546
+struct tpacket_auxdata
27c9546
+{
27c9546
+	__u32		tp_status;
27c9546
+	__u32		tp_len;
27c9546
+	__u32		tp_snaplen;
27c9546
+	__u16		tp_mac;
27c9546
+	__u16		tp_net;
27c9546
+};
27c9546
+#endif
27c9546
+
27c9546
 /* Reinitializes the specified interface after an address change.   This
27c9546
    is not required for packet-filter APIs. */
27c9546
 
c987ce5
@@ -66,10 +81,14 @@ int if_register_lpf (info)
c987ce5
 	struct interface_info *info;
c987ce5
 {
27c9546
 	int sock;
27c9546
-	struct sockaddr sa;
27c9546
+	union {
27c9546
+		struct sockaddr_ll ll;
27c9546
+		struct sockaddr common;
27c9546
+	} sa;
27c9546
+	struct ifreq ifr;
27c9546
 
27c9546
 	/* Make an LPF socket. */
27c9546
-	if ((sock = socket(PF_PACKET, SOCK_PACKET,
27c9546
+	if ((sock = socket(PF_PACKET, SOCK_RAW,
27c9546
 			   htons((short)ETH_P_ALL))) < 0) {
27c9546
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
27c9546
 		    errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
c987ce5
@@ -84,11 +103,16 @@ int if_register_lpf (info)
27c9546
 		log_fatal ("Open a socket for LPF: %m");
27c9546
 	}
27c9546
 
27c9546
+	memset (&ifr, 0, sizeof ifr);
27c9546
+	strncpy (ifr.ifr_name, (const char *)info -> ifp, sizeof ifr.ifr_name);
27c9546
+	if (ioctl (sock, SIOCGIFINDEX, &ifr))
27c9546
+		log_fatal ("Failed to get interface index: %m");
27c9546
+
27c9546
 	/* Bind to the interface name */
27c9546
 	memset (&sa, 0, sizeof sa);
27c9546
-	sa.sa_family = AF_PACKET;
27c9546
-	strncpy (sa.sa_data, (const char *)info -> ifp, sizeof sa.sa_data);
27c9546
-	if (bind (sock, &sa, sizeof sa)) {
27c9546
+	sa.ll.sll_family = AF_PACKET;
27c9546
+	sa.ll.sll_ifindex = ifr.ifr_ifindex;
27c9546
+	if (bind (sock, &sa.common, sizeof sa)) {
27c9546
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
27c9546
 		    errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
27c9546
 		    errno == EAFNOSUPPORT || errno == EINVAL) {
c987ce5
@@ -170,9 +194,18 @@ static void lpf_gen_filter_setup (struct
27c9546
 void if_register_receive (info)
27c9546
 	struct interface_info *info;
27c9546
 {
27c9546
+	int val;
27c9546
+
27c9546
 	/* Open a LPF device and hang it on this interface... */
27c9546
 	info -> rfdesc = if_register_lpf (info);
27c9546
 
27c9546
+	val = 1;
27c9546
+	if (setsockopt (info -> rfdesc, SOL_PACKET, PACKET_AUXDATA, &val,
27c9546
+			sizeof val) < 0) {
27c9546
+		if (errno != ENOPROTOOPT)
27c9546
+			log_fatal ("Failed to set auxiliary packet data: %m");
27c9546
+	}
27c9546
+
27c9546
 #if defined (HAVE_TR_SUPPORT)
27c9546
 	if (info -> hw_address.hbuf [0] == HTYPE_IEEE802)
27c9546
 		lpf_tr_filter_setup (info);
c987ce5
@@ -291,7 +324,6 @@ ssize_t send_packet (interface, packet, 
27c9546
 	double hh [16];
27c9546
 	double ih [1536 / sizeof (double)];
27c9546
 	unsigned char *buf = (unsigned char *)ih;
27c9546
-	struct sockaddr sa;
27c9546
 	int result;
27c9546
 	int fudge;
27c9546
 
c987ce5
@@ -309,15 +341,7 @@ ssize_t send_packet (interface, packet, 
27c9546
 				(unsigned char *)raw, len);
27c9546
 	memcpy (buf + ibufp, raw, len);
27c9546
 
27c9546
-	/* For some reason, SOCK_PACKET sockets can't be connected,
27c9546
-	   so we have to do a sentdo every time. */
27c9546
-	memset (&sa, 0, sizeof sa);
27c9546
-	sa.sa_family = AF_PACKET;
27c9546
-	strncpy (sa.sa_data,
27c9546
-		 (const char *)interface -> ifp, sizeof sa.sa_data);
27c9546
-
27c9546
-	result = sendto (interface -> wfdesc,
27c9546
-			 buf + fudge, ibufp + len - fudge, 0, &sa, sizeof sa);
27c9546
+	result = write (interface -> wfdesc, buf + fudge, ibufp + len - fudge);
27c9546
 	if (result < 0)
27c9546
 		log_error ("send_packet: %m");
27c9546
 	return result;
c987ce5
@@ -334,14 +358,35 @@ ssize_t receive_packet (interface, buf, 
c987ce5
 {
27c9546
 	int length = 0;
27c9546
 	int offset = 0;
27c9546
+	int nocsum = 0;
27c9546
 	unsigned char ibuf [1536];
27c9546
 	unsigned bufix = 0;
0713d0c
 	unsigned paylen;
27c9546
+	unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
27c9546
+	struct iovec iov = {
27c9546
+		.iov_base = ibuf,
27c9546
+		.iov_len = sizeof ibuf,
27c9546
+	};
27c9546
+	struct msghdr msg = {
27c9546
+		.msg_iov = &iov,
27c9546
+		.msg_iovlen = 1,
27c9546
+		.msg_control = cmsgbuf,
27c9546
+		.msg_controllen = sizeof(cmsgbuf),
27c9546
+	};
27c9546
+	struct cmsghdr *cmsg;
27c9546
 
27c9546
-	length = read (interface -> rfdesc, ibuf, sizeof ibuf);
27c9546
+	length = recvmsg (interface -> rfdesc, &msg, 0);
27c9546
 	if (length <= 0)
27c9546
 		return length;
27c9546
 
27c9546
+	for (cmsg = CMSG_FIRSTHDR(&msg;; cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
27c9546
+		if (cmsg->cmsg_level == SOL_PACKET &&
27c9546
+		    cmsg->cmsg_type == PACKET_AUXDATA) {
27c9546
+			struct tpacket_auxdata *aux = (void *)CMSG_DATA(cmsg);
27c9546
+			nocsum = aux->tp_status & TP_STATUS_CSUMNOTREADY;
27c9546
+		}
27c9546
+	}
27c9546
+
27c9546
 	bufix = 0;
27c9546
 	/* Decode the physical header... */
27c9546
 	offset = decode_hw_header (interface, ibuf, bufix, hfrom);
c987ce5
@@ -358,7 +403,7 @@ ssize_t receive_packet (interface, buf, 
27c9546
 
27c9546
 	/* Decode the IP and UDP headers... */
27c9546
 	offset = decode_udp_ip_header (interface, ibuf, bufix, from,
0713d0c
-				       (unsigned)length, &paylen);
0713d0c
+				       (unsigned)length, &paylen, nocsum);
27c9546
 
27c9546
 	/* If the IP or UDP checksum was bad, skip the packet... */
27c9546
 	if (offset < 0)
c987ce5
diff -up dhcp-4.0.0/common/bpf.c.xen dhcp-4.0.0/common/bpf.c
c987ce5
--- dhcp-4.0.0/common/bpf.c.xen	2007-08-22 23:49:51.000000000 -1000
c987ce5
+++ dhcp-4.0.0/common/bpf.c	2007-12-29 06:39:09.000000000 -1000
c987ce5
@@ -482,7 +482,7 @@ ssize_t receive_packet (interface, buf, 
af39808
 		offset = decode_udp_ip_header (interface,
af39808
 					       interface -> rbuf,
af39808
 					       interface -> rbuf_offset,
af39808
-  					       from, hdr.bh_caplen, &paylen);
af39808
+  					       from, hdr.bh_caplen, &paylen, 0);
27c9546
 
af39808
 		/* If the IP or UDP checksum was bad, skip the packet... */
af39808
 		if (offset < 0) {
c987ce5
diff -up dhcp-4.0.0/common/packet.c.xen dhcp-4.0.0/common/packet.c
c987ce5
--- dhcp-4.0.0/common/packet.c.xen	2007-12-29 06:37:53.000000000 -1000
c987ce5
+++ dhcp-4.0.0/common/packet.c	2007-12-29 06:39:20.000000000 -1000
c987ce5
@@ -210,7 +210,7 @@ ssize_t
0713d0c
 decode_udp_ip_header(struct interface_info *interface,
0713d0c
 		     unsigned char *buf, unsigned bufix,
0713d0c
 		     struct sockaddr_in *from, unsigned buflen,
0713d0c
-		     unsigned *rbuflen)
0713d0c
+		     unsigned *rbuflen, int nocsum)
27c9546
 {
27c9546
   unsigned char *data;
27c9546
   struct ip ip;
c987ce5
@@ -321,7 +321,7 @@ decode_udp_ip_header(struct interface_in
0713d0c
 					   8, IPPROTO_UDP + ulen))));
27c9546
 
27c9546
   udp_packets_seen++;
27c9546
-  if (usum && usum != sum) {
27c9546
+  if (!nocsum && usum && usum != sum) {
27c9546
 	  udp_packets_bad_checksum++;
27c9546
 	  if (udp_packets_seen > 4 &&
27c9546
 	      (udp_packets_seen / udp_packets_bad_checksum) < 2) {
c987ce5
diff -up dhcp-4.0.0/includes/dhcpd.h.xen dhcp-4.0.0/includes/dhcpd.h
c987ce5
--- dhcp-4.0.0/includes/dhcpd.h.xen	2007-12-29 06:37:53.000000000 -1000
c987ce5
+++ dhcp-4.0.0/includes/dhcpd.h	2007-12-29 06:39:27.000000000 -1000
c987ce5
@@ -2561,7 +2561,7 @@ ssize_t decode_hw_header PROTO ((struct 
af39808
 				 unsigned, struct hardware *));
af39808
 ssize_t decode_udp_ip_header PROTO ((struct interface_info *, unsigned char *,
af39808
 				     unsigned, struct sockaddr_in *,
af39808
-				     unsigned, unsigned *));
af39808
+				     unsigned, unsigned *, int));
27c9546
 
af39808
 /* ethernet.c */
af39808
 void assemble_ethernet_header PROTO ((struct interface_info *, unsigned char *,