90936e4
diff -up dhcp-4.3.0rc1/common/bpf.c.xen dhcp-4.3.0rc1/common/bpf.c
90936e4
--- dhcp-4.3.0rc1/common/bpf.c.xen	2014-01-29 10:03:27.503941664 +0100
90936e4
+++ dhcp-4.3.0rc1/common/bpf.c	2014-01-29 10:03:37.564812175 +0100
90936e4
@@ -481,7 +481,7 @@ ssize_t receive_packet (interface, buf,
90936e4
 		/* Decode the IP and UDP headers... */
90936e4
 		offset = decode_udp_ip_header(interface, interface->rbuf,
90936e4
 					       interface->rbuf_offset,
4bf24c8
-  					       from, hdr.bh_caplen, &paylen);
4bf24c8
+  					       from, hdr.bh_caplen, &paylen, 0);
203b45c
 
4bf24c8
 		/* If the IP or UDP checksum was bad, skip the packet... */
4bf24c8
 		if (offset < 0) {
90936e4
diff -up dhcp-4.3.0rc1/common/dlpi.c.xen dhcp-4.3.0rc1/common/dlpi.c
90936e4
--- dhcp-4.3.0rc1/common/dlpi.c.xen	2014-01-25 05:18:03.000000000 +0100
90936e4
+++ dhcp-4.3.0rc1/common/dlpi.c	2014-01-29 10:03:27.503941664 +0100
e83fb19
@@ -691,7 +691,7 @@ ssize_t receive_packet (interface, buf,
203b45c
 	length -= offset;
203b45c
 #endif
203b45c
 	offset = decode_udp_ip_header (interface, dbuf, bufix,
203b45c
-				       from, length, &paylen);
203b45c
+				       from, length, &paylen, 0);
203b45c
 
9538db2
 	/*
9538db2
 	 * If the IP or UDP checksum was bad, skip the packet...
90936e4
diff -up dhcp-4.3.0rc1/common/lpf.c.xen dhcp-4.3.0rc1/common/lpf.c
90936e4
--- dhcp-4.3.0rc1/common/lpf.c.xen	2014-01-25 05:18:03.000000000 +0100
90936e4
+++ dhcp-4.3.0rc1/common/lpf.c	2014-01-29 10:03:27.504941651 +0100
e83fb19
@@ -29,14 +29,15 @@
e83fb19
 
203b45c
 #include "dhcpd.h"
203b45c
 #if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE)
203b45c
+#include <sys/socket.h>
203b45c
 #include <sys/uio.h>
82186fd
 #include <errno.h>
203b45c
 
203b45c
 #include <asm/types.h>
203b45c
 #include <linux/filter.h>
203b45c
 #include <linux/if_ether.h>
203b45c
+#include <linux/if_packet.h>
203b45c
 #include <netinet/in_systm.h>
bb77af8
-#include <net/if_packet.h>
203b45c
 #include "includes/netinet/ip.h"
203b45c
 #include "includes/netinet/udp.h"
203b45c
 #include "includes/netinet/if_ether.h"
e83fb19
@@ -51,6 +52,19 @@
e83fb19
 /* Reinitializes the specified interface after an address change.   This
e83fb19
    is not required for packet-filter APIs. */
203b45c
 
203b45c
+#ifndef PACKET_AUXDATA
203b45c
+#define PACKET_AUXDATA 8
203b45c
+
203b45c
+struct tpacket_auxdata
203b45c
+{
203b45c
+	__u32		tp_status;
203b45c
+	__u32		tp_len;
203b45c
+	__u32		tp_snaplen;
203b45c
+	__u16		tp_mac;
203b45c
+	__u16		tp_net;
203b45c
+};
203b45c
+#endif
203b45c
+
e83fb19
 #ifdef USE_LPF_SEND
e83fb19
 void if_reinitialize_send (info)
e83fb19
 	struct interface_info *info;
e83fb19
@@ -73,10 +87,14 @@ int if_register_lpf (info)
82186fd
 	struct interface_info *info;
82186fd
 {
203b45c
 	int sock;
203b45c
-	struct sockaddr sa;
203b45c
+	union {
203b45c
+		struct sockaddr_ll ll;
203b45c
+		struct sockaddr common;
203b45c
+	} sa;
203b45c
+	struct ifreq ifr;
203b45c
 
203b45c
 	/* Make an LPF socket. */
203b45c
-	if ((sock = socket(PF_PACKET, SOCK_PACKET,
203b45c
+	if ((sock = socket(PF_PACKET, SOCK_RAW,
203b45c
 			   htons((short)ETH_P_ALL))) < 0) {
203b45c
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
203b45c
 		    errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
e83fb19
@@ -91,11 +109,17 @@ int if_register_lpf (info)
203b45c
 		log_fatal ("Open a socket for LPF: %m");
203b45c
 	}
203b45c
 
203b45c
+	memset (&ifr, 0, sizeof ifr);
203b45c
+	strncpy (ifr.ifr_name, (const char *)info -> ifp, sizeof ifr.ifr_name);
030991f
+	ifr.ifr_name[IFNAMSIZ-1] = '\0';
203b45c
+	if (ioctl (sock, SIOCGIFINDEX, &ifr))
203b45c
+		log_fatal ("Failed to get interface index: %m");
203b45c
+
203b45c
 	/* Bind to the interface name */
203b45c
 	memset (&sa, 0, sizeof sa);
203b45c
-	sa.sa_family = AF_PACKET;
203b45c
-	strncpy (sa.sa_data, (const char *)info -> ifp, sizeof sa.sa_data);
203b45c
-	if (bind (sock, &sa, sizeof sa)) {
203b45c
+	sa.ll.sll_family = AF_PACKET;
203b45c
+	sa.ll.sll_ifindex = ifr.ifr_ifindex;
203b45c
+	if (bind (sock, &sa.common, sizeof sa)) {
203b45c
 		if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
203b45c
 		    errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
203b45c
 		    errno == EAFNOSUPPORT || errno == EINVAL) {
e83fb19
@@ -177,9 +201,18 @@ static void lpf_gen_filter_setup (struct
203b45c
 void if_register_receive (info)
203b45c
 	struct interface_info *info;
203b45c
 {
203b45c
+	int val;
203b45c
+
203b45c
 	/* Open a LPF device and hang it on this interface... */
203b45c
 	info -> rfdesc = if_register_lpf (info);
203b45c
 
203b45c
+	val = 1;
203b45c
+	if (setsockopt (info -> rfdesc, SOL_PACKET, PACKET_AUXDATA, &val,
203b45c
+			sizeof val) < 0) {
203b45c
+		if (errno != ENOPROTOOPT)
203b45c
+			log_fatal ("Failed to set auxiliary packet data: %m");
203b45c
+	}
203b45c
+
203b45c
 #if defined (HAVE_TR_SUPPORT)
203b45c
 	if (info -> hw_address.hbuf [0] == HTYPE_IEEE802)
203b45c
 		lpf_tr_filter_setup (info);
e83fb19
@@ -301,7 +334,6 @@ ssize_t send_packet (interface, packet,
203b45c
 	double hh [16];
203b45c
 	double ih [1536 / sizeof (double)];
203b45c
 	unsigned char *buf = (unsigned char *)ih;
bb77af8
-	struct sockaddr_pkt sa;
203b45c
 	int result;
203b45c
 	int fudge;
203b45c
 
e83fb19
@@ -322,17 +354,7 @@ ssize_t send_packet (interface, packet,
203b45c
 				(unsigned char *)raw, len);
203b45c
 	memcpy (buf + ibufp, raw, len);
203b45c
 
203b45c
-	/* For some reason, SOCK_PACKET sockets can't be connected,
203b45c
-	   so we have to do a sentdo every time. */
203b45c
-	memset (&sa, 0, sizeof sa);
bb77af8
-	sa.spkt_family = AF_PACKET;
bb77af8
-	strncpy ((char *)sa.spkt_device,
bb77af8
-		 (const char *)interface -> ifp, sizeof sa.spkt_device);
bb77af8
-	sa.spkt_protocol = htons(ETH_P_IP);
203b45c
-
203b45c
-	result = sendto (interface -> wfdesc,
bb77af8
-			 buf + fudge, ibufp + len - fudge, 0, 
bb77af8
-			 (const struct sockaddr *)&sa, sizeof sa);
203b45c
+	result = write (interface -> wfdesc, buf + fudge, ibufp + len - fudge);
203b45c
 	if (result < 0)
203b45c
 		log_error ("send_packet: %m");
203b45c
 	return result;
e83fb19
@@ -349,14 +371,35 @@ ssize_t receive_packet (interface, buf,
82186fd
 {
203b45c
 	int length = 0;
203b45c
 	int offset = 0;
203b45c
+	int nocsum = 0;
203b45c
 	unsigned char ibuf [1536];
203b45c
 	unsigned bufix = 0;
203b45c
 	unsigned paylen;
203b45c
+	unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
203b45c
+	struct iovec iov = {
203b45c
+		.iov_base = ibuf,
203b45c
+		.iov_len = sizeof ibuf,
203b45c
+	};
203b45c
+	struct msghdr msg = {
203b45c
+		.msg_iov = &iov,
203b45c
+		.msg_iovlen = 1,
203b45c
+		.msg_control = cmsgbuf,
203b45c
+		.msg_controllen = sizeof(cmsgbuf),
203b45c
+	};
203b45c
+	struct cmsghdr *cmsg;
203b45c
 
203b45c
-	length = read (interface -> rfdesc, ibuf, sizeof ibuf);
203b45c
+	length = recvmsg (interface -> rfdesc, &msg, 0);
203b45c
 	if (length <= 0)
203b45c
 		return length;
203b45c
 
203b45c
+	for (cmsg = CMSG_FIRSTHDR(&msg;; cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
203b45c
+		if (cmsg->cmsg_level == SOL_PACKET &&
203b45c
+		    cmsg->cmsg_type == PACKET_AUXDATA) {
203b45c
+			struct tpacket_auxdata *aux = (void *)CMSG_DATA(cmsg);
203b45c
+			nocsum = aux->tp_status & TP_STATUS_CSUMNOTREADY;
203b45c
+		}
203b45c
+	}
203b45c
+
203b45c
 	bufix = 0;
203b45c
 	/* Decode the physical header... */
203b45c
 	offset = decode_hw_header (interface, ibuf, bufix, hfrom);
e83fb19
@@ -373,7 +416,7 @@ ssize_t receive_packet (interface, buf,
203b45c
 
203b45c
 	/* Decode the IP and UDP headers... */
203b45c
 	offset = decode_udp_ip_header (interface, ibuf, bufix, from,
203b45c
-				       (unsigned)length, &paylen);
203b45c
+				       (unsigned)length, &paylen, nocsum);
203b45c
 
203b45c
 	/* If the IP or UDP checksum was bad, skip the packet... */
203b45c
 	if (offset < 0)
90936e4
diff -up dhcp-4.3.0rc1/common/nit.c.xen dhcp-4.3.0rc1/common/nit.c
90936e4
--- dhcp-4.3.0rc1/common/nit.c.xen	2014-01-26 19:40:44.000000000 +0100
90936e4
+++ dhcp-4.3.0rc1/common/nit.c	2014-01-29 10:03:27.504941651 +0100
90936e4
@@ -363,7 +363,7 @@ ssize_t receive_packet (interface, buf,
203b45c
 
4bf24c8
 	/* Decode the IP and UDP headers... */
4bf24c8
 	offset = decode_udp_ip_header (interface, ibuf, bufix,
4bf24c8
-				       from, length, &paylen);
4bf24c8
+				       from, length, &paylen, 0);
4bf24c8
 
4bf24c8
 	/* If the IP or UDP checksum was bad, skip the packet... */
4bf24c8
 	if (offset < 0)
90936e4
diff -up dhcp-4.3.0rc1/common/packet.c.xen dhcp-4.3.0rc1/common/packet.c
90936e4
--- dhcp-4.3.0rc1/common/packet.c.xen	2013-12-11 01:01:02.000000000 +0100
90936e4
+++ dhcp-4.3.0rc1/common/packet.c	2014-01-29 10:03:27.504941651 +0100
e83fb19
@@ -226,7 +226,7 @@ ssize_t
203b45c
 decode_udp_ip_header(struct interface_info *interface,
203b45c
 		     unsigned char *buf, unsigned bufix,
203b45c
 		     struct sockaddr_in *from, unsigned buflen,
203b45c
-		     unsigned *rbuflen)
203b45c
+		     unsigned *rbuflen, int nocsum)
203b45c
 {
203b45c
   unsigned char *data;
203b45c
   struct ip ip;
e83fb19
@@ -337,7 +337,7 @@ decode_udp_ip_header(struct interface_in
203b45c
 					   8, IPPROTO_UDP + ulen))));
203b45c
 
203b45c
   udp_packets_seen++;
203b45c
-  if (usum && usum != sum) {
203b45c
+  if (!nocsum && usum && usum != sum) {
203b45c
 	  udp_packets_bad_checksum++;
203b45c
 	  if (udp_packets_seen > 4 &&
203b45c
 	      (udp_packets_seen / udp_packets_bad_checksum) < 2) {
90936e4
diff -up dhcp-4.3.0rc1/common/upf.c.xen dhcp-4.3.0rc1/common/upf.c
90936e4
--- dhcp-4.3.0rc1/common/upf.c.xen	2014-01-26 19:40:44.000000000 +0100
90936e4
+++ dhcp-4.3.0rc1/common/upf.c	2014-01-29 10:03:27.505941638 +0100
90936e4
@@ -314,7 +314,7 @@ ssize_t receive_packet (interface, buf,
4bf24c8
 
4bf24c8
 	/* Decode the IP and UDP headers... */
4bf24c8
 	offset = decode_udp_ip_header (interface, ibuf, bufix,
4bf24c8
-				       from, length, &paylen);
4bf24c8
+				       from, length, &paylen, 0);
4bf24c8
 
4bf24c8
 	/* If the IP or UDP checksum was bad, skip the packet... */
4bf24c8
 	if (offset < 0)
90936e4
diff -up dhcp-4.3.0rc1/includes/dhcpd.h.xen dhcp-4.3.0rc1/includes/dhcpd.h
90936e4
--- dhcp-4.3.0rc1/includes/dhcpd.h.xen	2014-01-29 10:03:27.489941844 +0100
90936e4
+++ dhcp-4.3.0rc1/includes/dhcpd.h	2014-01-29 10:03:27.506941626 +0100
90936e4
@@ -2861,7 +2861,7 @@ ssize_t decode_hw_header (struct interfa
bb77af8
 			  unsigned, struct hardware *);
bb77af8
 ssize_t decode_udp_ip_header (struct interface_info *, unsigned char *,
bb77af8
 			      unsigned, struct sockaddr_in *,
bb77af8
-			      unsigned, unsigned *);
bb77af8
+			      unsigned, unsigned *, int);
203b45c
 
203b45c
 /* ethernet.c */
bb77af8
 void assemble_ethernet_header (struct interface_info *, unsigned char *,