1 diff -up dhcp-4.0.0/common/nit.c.xen dhcp-4.0.0/common/nit.c
2 --- dhcp-4.0.0/common/nit.c.xen 2007-09-05 07:32:10.000000000 -1000
3 +++ dhcp-4.0.0/common/nit.c 2007-12-29 06:39:16.000000000 -1000
4 @@ -366,7 +366,7 @@ ssize_t receive_packet (interface, buf,
6 /* Decode the IP and UDP headers... */
7 offset = decode_udp_ip_header (interface, ibuf, bufix,
8 - from, length, &paylen);
9 + from, length, &paylen, 0);
11 /* If the IP or UDP checksum was bad, skip the packet... */
13 diff -up dhcp-4.0.0/common/dlpi.c.xen dhcp-4.0.0/common/dlpi.c
14 --- dhcp-4.0.0/common/dlpi.c.xen 2007-10-08 04:27:53.000000000 -1000
15 +++ dhcp-4.0.0/common/dlpi.c 2007-12-29 06:39:13.000000000 -1000
16 @@ -689,7 +689,7 @@ ssize_t receive_packet (interface, buf,
19 offset = decode_udp_ip_header (interface, dbuf, bufix,
20 - from, length, &paylen);
21 + from, length, &paylen, 0);
23 /* If the IP or UDP checksum was bad, skip the packet... */
25 diff -up dhcp-4.0.0/common/upf.c.xen dhcp-4.0.0/common/upf.c
26 --- dhcp-4.0.0/common/upf.c.xen 2007-07-12 20:43:42.000000000 -1000
27 +++ dhcp-4.0.0/common/upf.c 2007-12-29 06:39:24.000000000 -1000
28 @@ -317,7 +317,7 @@ ssize_t receive_packet (interface, buf,
30 /* Decode the IP and UDP headers... */
31 offset = decode_udp_ip_header (interface, ibuf, bufix,
32 - from, length, &paylen);
33 + from, length, &paylen, 0);
35 /* If the IP or UDP checksum was bad, skip the packet... */
37 diff -up dhcp-4.0.0/common/lpf.c.xen dhcp-4.0.0/common/lpf.c
38 --- dhcp-4.0.0/common/lpf.c.xen 2007-12-29 06:37:53.000000000 -1000
39 +++ dhcp-4.0.0/common/lpf.c 2007-12-29 06:43:08.000000000 -1000
42 #if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE)
43 #include <sys/ioctl.h>
44 +#include <sys/socket.h>
48 #include <asm/types.h>
49 #include <linux/filter.h>
50 #include <linux/if_ether.h>
51 +#include <linux/if_packet.h>
52 #include <netinet/in_systm.h>
53 #include "includes/netinet/ip.h"
54 #include "includes/netinet/udp.h"
55 #include "includes/netinet/if_ether.h"
58 +#ifndef PACKET_AUXDATA
59 +#define PACKET_AUXDATA 8
61 +struct tpacket_auxdata
71 /* Reinitializes the specified interface after an address change. This
72 is not required for packet-filter APIs. */
74 @@ -66,10 +81,14 @@ int if_register_lpf (info)
75 struct interface_info *info;
80 + struct sockaddr_ll ll;
81 + struct sockaddr common;
85 /* Make an LPF socket. */
86 - if ((sock = socket(PF_PACKET, SOCK_PACKET,
87 + if ((sock = socket(PF_PACKET, SOCK_RAW,
88 htons((short)ETH_P_ALL))) < 0) {
89 if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
90 errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
91 @@ -84,11 +103,16 @@ int if_register_lpf (info)
92 log_fatal ("Open a socket for LPF: %m");
95 + memset (&ifr, 0, sizeof ifr);
96 + strncpy (ifr.ifr_name, (const char *)info -> ifp, sizeof ifr.ifr_name);
97 + if (ioctl (sock, SIOCGIFINDEX, &ifr))
98 + log_fatal ("Failed to get interface index: %m");
100 /* Bind to the interface name */
101 memset (&sa, 0, sizeof sa);
102 - sa.sa_family = AF_PACKET;
103 - strncpy (sa.sa_data, (const char *)info -> ifp, sizeof sa.sa_data);
104 - if (bind (sock, &sa, sizeof sa)) {
105 + sa.ll.sll_family = AF_PACKET;
106 + sa.ll.sll_ifindex = ifr.ifr_ifindex;
107 + if (bind (sock, &sa.common, sizeof sa)) {
108 if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
109 errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
110 errno == EAFNOSUPPORT || errno == EINVAL) {
111 @@ -170,9 +194,18 @@ static void lpf_gen_filter_setup (struct
112 void if_register_receive (info)
113 struct interface_info *info;
117 /* Open a LPF device and hang it on this interface... */
118 info -> rfdesc = if_register_lpf (info);
121 + if (setsockopt (info -> rfdesc, SOL_PACKET, PACKET_AUXDATA, &val,
123 + if (errno != ENOPROTOOPT)
124 + log_fatal ("Failed to set auxiliary packet data: %m");
127 #if defined (HAVE_TR_SUPPORT)
128 if (info -> hw_address.hbuf [0] == HTYPE_IEEE802)
129 lpf_tr_filter_setup (info);
130 @@ -291,7 +324,6 @@ ssize_t send_packet (interface, packet,
132 double ih [1536 / sizeof (double)];
133 unsigned char *buf = (unsigned char *)ih;
134 - struct sockaddr sa;
138 @@ -309,15 +341,7 @@ ssize_t send_packet (interface, packet,
139 (unsigned char *)raw, len);
140 memcpy (buf + ibufp, raw, len);
142 - /* For some reason, SOCK_PACKET sockets can't be connected,
143 - so we have to do a sentdo every time. */
144 - memset (&sa, 0, sizeof sa);
145 - sa.sa_family = AF_PACKET;
146 - strncpy (sa.sa_data,
147 - (const char *)interface -> ifp, sizeof sa.sa_data);
149 - result = sendto (interface -> wfdesc,
150 - buf + fudge, ibufp + len - fudge, 0, &sa, sizeof sa);
151 + result = write (interface -> wfdesc, buf + fudge, ibufp + len - fudge);
153 log_error ("send_packet: %m");
155 @@ -334,14 +358,35 @@ ssize_t receive_packet (interface, buf,
160 unsigned char ibuf [1536];
163 + unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
164 + struct iovec iov = {
166 + .iov_len = sizeof ibuf,
168 + struct msghdr msg = {
171 + .msg_control = cmsgbuf,
172 + .msg_controllen = sizeof(cmsgbuf),
174 + struct cmsghdr *cmsg;
176 - length = read (interface -> rfdesc, ibuf, sizeof ibuf);
177 + length = recvmsg (interface -> rfdesc, &msg, 0);
181 + for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
182 + if (cmsg->cmsg_level == SOL_PACKET &&
183 + cmsg->cmsg_type == PACKET_AUXDATA) {
184 + struct tpacket_auxdata *aux = (void *)CMSG_DATA(cmsg);
185 + nocsum = aux->tp_status & TP_STATUS_CSUMNOTREADY;
190 /* Decode the physical header... */
191 offset = decode_hw_header (interface, ibuf, bufix, hfrom);
192 @@ -358,7 +403,7 @@ ssize_t receive_packet (interface, buf,
194 /* Decode the IP and UDP headers... */
195 offset = decode_udp_ip_header (interface, ibuf, bufix, from,
196 - (unsigned)length, &paylen);
197 + (unsigned)length, &paylen, nocsum);
199 /* If the IP or UDP checksum was bad, skip the packet... */
201 diff -up dhcp-4.0.0/common/bpf.c.xen dhcp-4.0.0/common/bpf.c
202 --- dhcp-4.0.0/common/bpf.c.xen 2007-08-22 23:49:51.000000000 -1000
203 +++ dhcp-4.0.0/common/bpf.c 2007-12-29 06:39:09.000000000 -1000
204 @@ -482,7 +482,7 @@ ssize_t receive_packet (interface, buf,
205 offset = decode_udp_ip_header (interface,
207 interface -> rbuf_offset,
208 - from, hdr.bh_caplen, &paylen);
209 + from, hdr.bh_caplen, &paylen, 0);
211 /* If the IP or UDP checksum was bad, skip the packet... */
213 diff -up dhcp-4.0.0/common/packet.c.xen dhcp-4.0.0/common/packet.c
214 --- dhcp-4.0.0/common/packet.c.xen 2007-12-29 06:37:53.000000000 -1000
215 +++ dhcp-4.0.0/common/packet.c 2007-12-29 06:39:20.000000000 -1000
216 @@ -210,7 +210,7 @@ ssize_t
217 decode_udp_ip_header(struct interface_info *interface,
218 unsigned char *buf, unsigned bufix,
219 struct sockaddr_in *from, unsigned buflen,
221 + unsigned *rbuflen, int nocsum)
225 @@ -321,7 +321,7 @@ decode_udp_ip_header(struct interface_in
226 8, IPPROTO_UDP + ulen))));
229 - if (usum && usum != sum) {
230 + if (!nocsum && usum && usum != sum) {
231 udp_packets_bad_checksum++;
232 if (udp_packets_seen > 4 &&
233 (udp_packets_seen / udp_packets_bad_checksum) < 2) {
234 diff -up dhcp-4.0.0/includes/dhcpd.h.xen dhcp-4.0.0/includes/dhcpd.h
235 --- dhcp-4.0.0/includes/dhcpd.h.xen 2007-12-29 06:37:53.000000000 -1000
236 +++ dhcp-4.0.0/includes/dhcpd.h 2007-12-29 06:39:27.000000000 -1000
237 @@ -2561,7 +2561,7 @@ ssize_t decode_hw_header PROTO ((struct
238 unsigned, struct hardware *));
239 ssize_t decode_udp_ip_header PROTO ((struct interface_info *, unsigned char *,
240 unsigned, struct sockaddr_in *,
241 - unsigned, unsigned *));
242 + unsigned, unsigned *, int));
245 void assemble_ethernet_header PROTO ((struct interface_info *, unsigned char *,