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