02017bb
diff -urN dhcp-3.0.5.xen/common/bpf.c dhcp-3.0.5/common/bpf.c
02017bb
--- dhcp-3.0.5.xen/common/bpf.c	2004-11-24 12:39:15.000000000 -0500
02017bb
+++ dhcp-3.0.5/common/bpf.c	2007-01-30 13:23:57.000000000 -0500
02017bb
@@ -478,7 +478,8 @@
02017bb
 					       interface -> rbuf,
02017bb
 					       interface -> rbuf_offset,
02017bb
 					       from,
02017bb
-					       hdr.bh_caplen);
02017bb
+					       hdr.bh_caplen,
02017bb
+					       0);
02017bb
 
02017bb
 		/* If the IP or UDP checksum was bad, skip the packet... */
02017bb
 		if (offset < 0) {
02017bb
diff -urN dhcp-3.0.5.xen/common/dlpi.c dhcp-3.0.5/common/dlpi.c
02017bb
--- dhcp-3.0.5.xen/common/dlpi.c	2004-11-24 12:39:15.000000000 -0500
02017bb
+++ dhcp-3.0.5/common/dlpi.c	2007-01-30 13:23:57.000000000 -0500
02017bb
@@ -679,7 +679,7 @@
02017bb
 	length -= offset;
02017bb
 #endif
02017bb
 	offset = decode_udp_ip_header (interface, dbuf, bufix,
02017bb
-				       from, length);
02017bb
+				       from, length, 0);
02017bb
 
02017bb
 	/* If the IP or UDP checksum was bad, skip the packet... */
02017bb
 	if (offset < 0) {
02017bb
diff -urN dhcp-3.0.5.xen/common/lpf.c dhcp-3.0.5/common/lpf.c
02017bb
--- dhcp-3.0.5.xen/common/lpf.c	2004-11-24 12:39:15.000000000 -0500
02017bb
+++ dhcp-3.0.5/common/lpf.c	2007-01-30 13:27:39.000000000 -0500
02017bb
@@ -34,16 +34,31 @@
02017bb
 #include "dhcpd.h"
02017bb
 #if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE)
02017bb
 #include <sys/ioctl.h>
02017bb
+#include <sys/socket.h>
02017bb
 #include <sys/uio.h>
02017bb
 
02017bb
 #include <asm/types.h>
02017bb
 #include <linux/filter.h>
02017bb
 #include <linux/if_ether.h>
02017bb
+#include <linux/if_packet.h>
02017bb
 #include <netinet/in_systm.h>
02017bb
 #include "includes/netinet/ip.h"
02017bb
 #include "includes/netinet/udp.h"
02017bb
 #include "includes/netinet/if_ether.h"
02017bb
 
02017bb
+#ifndef PACKET_AUXDATA
02017bb
+#define PACKET_AUXDATA 8
02017bb
+
02017bb
+struct tpacket_auxdata
02017bb
+{
02017bb
+	__u32		tp_status;
02017bb
+	__u32		tp_len;
02017bb
+	__u32		tp_snaplen;
02017bb
+	__u16		tp_mac;
02017bb
+	__u16		tp_net;
02017bb
+};
02017bb
+#endif
02017bb
+
02017bb
 /* Reinitializes the specified interface after an address change.   This
02017bb
    is not required for packet-filter APIs. */
02017bb
 
02017bb
@@ -69,12 +84,16 @@
02017bb
 	struct interface_info *info;
02017bb
 {
02017bb
 	int sock;
02017bb
+	union {
02017bb
+		struct sockaddr_ll ll;
02017bb
+		struct sockaddr common;
02017bb
+	} sa;
02017bb
+	struct ifreq ifr;
02017bb
 	char filename[50];
02017bb
 	int b;
02017bb
-	struct sockaddr sa;
02017bb
 
02017bb
 	/* Make an LPF socket. */
02017bb
-	if ((sock = socket(PF_PACKET, SOCK_PACKET,
02017bb
+	if ((sock = socket(PF_PACKET, SOCK_RAW,
02017bb
 			   htons((short)ETH_P_ALL))) < 0) {
02017bb
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
02017bb
 		    errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
02017bb
@@ -89,11 +108,16 @@
02017bb
 		log_fatal ("Open a socket for LPF: %m");
02017bb
 	}
02017bb
 
02017bb
+	memset (&ifr, 0, sizeof ifr);
02017bb
+	strncpy (ifr.ifr_name, (const char *)info -> ifp, sizeof ifr.ifr_name);
02017bb
+	if (ioctl (sock, SIOCGIFINDEX, &ifr))
02017bb
+		log_fatal ("Failed to get interface index: %m");
02017bb
+
02017bb
 	/* Bind to the interface name */
02017bb
 	memset (&sa, 0, sizeof sa);
02017bb
-	sa.sa_family = AF_PACKET;
02017bb
-	strncpy (sa.sa_data, (const char *)info -> ifp, sizeof sa.sa_data);
02017bb
-	if (bind (sock, &sa, sizeof sa)) {
02017bb
+	sa.ll.sll_family = AF_PACKET;
02017bb
+	sa.ll.sll_ifindex = ifr.ifr_ifindex;
02017bb
+	if (bind (sock, &sa.common, sizeof sa)) {
02017bb
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
02017bb
 		    errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
02017bb
 		    errno == EAFNOSUPPORT || errno == EINVAL) {
02017bb
@@ -173,9 +197,18 @@
02017bb
 void if_register_receive (info)
02017bb
 	struct interface_info *info;
02017bb
 {
02017bb
+	int val;
02017bb
+
02017bb
 	/* Open a LPF device and hang it on this interface... */
02017bb
 	info -> rfdesc = if_register_lpf (info);
02017bb
 
02017bb
+	val = 1;
02017bb
+	if (setsockopt (info -> rfdesc, SOL_PACKET, PACKET_AUXDATA, &val,
02017bb
+			sizeof val) < 0) {
02017bb
+		if (errno != ENOPROTOOPT)
02017bb
+			log_fatal ("Failed to set auxiliary packet data: %m");
02017bb
+	}
02017bb
+
02017bb
 #if defined (HAVE_TR_SUPPORT)
02017bb
 	if (info -> hw_address.hbuf [0] == HTYPE_IEEE802)
02017bb
 		lpf_tr_filter_setup (info);
02017bb
@@ -293,7 +326,6 @@
02017bb
 	double hh [16];
02017bb
 	double ih [1536 / sizeof (double)];
02017bb
 	unsigned char *buf = (unsigned char *)ih;
02017bb
-	struct sockaddr sa;
02017bb
 	int result;
02017bb
 	int fudge;
02017bb
 
02017bb
@@ -311,15 +343,7 @@
02017bb
 				(unsigned char *)raw, len);
02017bb
 	memcpy (buf + ibufp, raw, len);
02017bb
 
02017bb
-	/* For some reason, SOCK_PACKET sockets can't be connected,
02017bb
-	   so we have to do a sentdo every time. */
02017bb
-	memset (&sa, 0, sizeof sa);
02017bb
-	sa.sa_family = AF_PACKET;
02017bb
-	strncpy (sa.sa_data,
02017bb
-		 (const char *)interface -> ifp, sizeof sa.sa_data);
02017bb
-
02017bb
-	result = sendto (interface -> wfdesc,
02017bb
-			 buf + fudge, ibufp + len - fudge, 0, &sa, sizeof sa);
02017bb
+	result = write (interface -> wfdesc, buf + fudge, ibufp + len - fudge);
02017bb
 	if (result < 0)
02017bb
 		log_error ("send_packet: %m");
02017bb
 	return result;
02017bb
@@ -337,13 +361,34 @@
02017bb
 	int nread;
02017bb
 	int length = 0;
02017bb
 	int offset = 0;
02017bb
+	int nocsum = 0;
02017bb
 	unsigned char ibuf [1536];
02017bb
 	unsigned bufix = 0;
02017bb
+	unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
02017bb
+	struct iovec iov = {
02017bb
+		.iov_base = ibuf,
02017bb
+		.iov_len = sizeof ibuf,
02017bb
+	};
02017bb
+	struct msghdr msg = {
02017bb
+		.msg_iov = &iov,
02017bb
+		.msg_iovlen = 1,
02017bb
+		.msg_control = cmsgbuf,
02017bb
+		.msg_controllen = sizeof(cmsgbuf),
02017bb
+	};
02017bb
+	struct cmsghdr *cmsg;
02017bb
 
02017bb
-	length = read (interface -> rfdesc, ibuf, sizeof ibuf);
02017bb
+	length = recvmsg (interface -> rfdesc, &msg, 0);
02017bb
 	if (length <= 0)
02017bb
 		return length;
02017bb
 
02017bb
+	for (cmsg = CMSG_FIRSTHDR(&msg;; cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
02017bb
+		if (cmsg->cmsg_level == SOL_PACKET &&
02017bb
+		    cmsg->cmsg_type == PACKET_AUXDATA) {
02017bb
+			struct tpacket_auxdata *aux = (void *)CMSG_DATA(cmsg);
02017bb
+			nocsum = aux->tp_status & TP_STATUS_CSUMNOTREADY;
02017bb
+		}
02017bb
+	}
02017bb
+
02017bb
 	bufix = 0;
02017bb
 	/* Decode the physical header... */
02017bb
 	offset = decode_hw_header (interface, ibuf, bufix, hfrom);
02017bb
@@ -360,7 +405,7 @@
02017bb
 
02017bb
 	/* Decode the IP and UDP headers... */
02017bb
 	offset = decode_udp_ip_header (interface, ibuf, bufix, from,
02017bb
-				       (unsigned)length);
02017bb
+				       (unsigned)length, nocsum);
02017bb
 
02017bb
 	/* If the IP or UDP checksum was bad, skip the packet... */
02017bb
 	if (offset < 0)
02017bb
diff -urN dhcp-3.0.5.xen/common/nit.c dhcp-3.0.5/common/nit.c
02017bb
--- dhcp-3.0.5.xen/common/nit.c	2004-11-24 12:39:15.000000000 -0500
02017bb
+++ dhcp-3.0.5/common/nit.c	2007-01-30 13:23:57.000000000 -0500
02017bb
@@ -370,7 +370,7 @@
02017bb
 
02017bb
 	/* Decode the IP and UDP headers... */
02017bb
 	offset = decode_udp_ip_header (interface, ibuf, bufix,
02017bb
-				       from, length);
02017bb
+				       from, length, 0);
02017bb
 
02017bb
 	/* If the IP or UDP checksum was bad, skip the packet... */
02017bb
 	if (offset < 0)
02017bb
diff -urN dhcp-3.0.5.xen/common/packet.c dhcp-3.0.5/common/packet.c
02017bb
--- dhcp-3.0.5.xen/common/packet.c	2007-01-30 13:23:27.000000000 -0500
02017bb
+++ dhcp-3.0.5/common/packet.c	2007-01-30 13:23:57.000000000 -0500
02017bb
@@ -211,12 +211,13 @@
02017bb
 
02017bb
 /* UDP header and IP header decoded together for convenience. */
02017bb
 
02017bb
-ssize_t decode_udp_ip_header (interface, buf, bufix, from, buflen)
02017bb
+ssize_t decode_udp_ip_header (interface, buf, bufix, from, buflen, nocsum)
02017bb
 	struct interface_info *interface;
02017bb
 	unsigned char *buf;
02017bb
 	unsigned bufix;
02017bb
 	struct sockaddr_in *from;
02017bb
 	unsigned buflen;
02017bb
+	int nocsum;
02017bb
 {
02017bb
   unsigned char *data;
02017bb
   struct ip ip;
02017bb
@@ -319,7 +320,7 @@
02017bb
 					       (u_int32_t)ulen))));
02017bb
 
02017bb
   udp_packets_seen++;
02017bb
-  if (usum && usum != sum) {
02017bb
+  if (!nocsum && usum && usum != sum) {
02017bb
 	  udp_packets_bad_checksum++;
02017bb
 	  if (udp_packets_seen > 4 &&
02017bb
 	      (udp_packets_seen / udp_packets_bad_checksum) < 2) {
02017bb
diff -urN dhcp-3.0.5.xen/common/upf.c dhcp-3.0.5/common/upf.c
02017bb
--- dhcp-3.0.5.xen/common/upf.c	2004-11-24 12:39:16.000000000 -0500
02017bb
+++ dhcp-3.0.5/common/upf.c	2007-01-30 13:23:57.000000000 -0500
02017bb
@@ -321,7 +321,7 @@
02017bb
 
02017bb
 	/* Decode the IP and UDP headers... */
02017bb
 	offset = decode_udp_ip_header (interface, ibuf, bufix,
02017bb
-				       from, length);
02017bb
+				       from, length, 0);
02017bb
 
02017bb
 	/* If the IP or UDP checksum was bad, skip the packet... */
02017bb
 	if (offset < 0)
02017bb
diff -urN dhcp-3.0.5.xen/includes/dhcpd.h dhcp-3.0.5/includes/dhcpd.h
02017bb
--- dhcp-3.0.5.xen/includes/dhcpd.h	2007-01-30 13:23:28.000000000 -0500
02017bb
+++ dhcp-3.0.5/includes/dhcpd.h	2007-01-30 13:23:57.000000000 -0500
02017bb
@@ -1948,7 +1948,7 @@
02017bb
 				 unsigned, struct hardware *));
02017bb
 ssize_t decode_udp_ip_header PROTO ((struct interface_info *, unsigned char *,
02017bb
 				     unsigned, struct sockaddr_in *,
02017bb
-				     unsigned));
02017bb
+				     unsigned, int));
02017bb
 
02017bb
 /* ethernet.c */
02017bb
 void assemble_ethernet_header PROTO ((struct interface_info *, unsigned char *,