| 1 |
diff -up dhcp-4.1.0/common/bpf.c.xen dhcp-4.1.0/common/bpf.c
|
| 2 |
--- dhcp-4.1.0/common/bpf.c.xen 2007-08-22 23:49:51.000000000 -1000
|
| 3 |
+++ dhcp-4.1.0/common/bpf.c 2009-01-06 10:41:32.000000000 -1000
|
| 4 |
@@ -482,7 +482,7 @@ ssize_t receive_packet (interface, buf,
|
| 5 |
offset = decode_udp_ip_header (interface,
|
| 6 |
interface -> rbuf,
|
| 7 |
interface -> rbuf_offset,
|
| 8 |
- from, hdr.bh_caplen, &paylen);
|
| 9 |
+ from, hdr.bh_caplen, &paylen, 0);
|
| 10 |
|
| 11 |
/* If the IP or UDP checksum was bad, skip the packet... */
|
| 12 |
if (offset < 0) {
|
| 13 |
diff -up dhcp-4.1.0/common/dlpi.c.xen dhcp-4.1.0/common/dlpi.c
|
| 14 |
--- dhcp-4.1.0/common/dlpi.c.xen 2008-02-29 13:57:56.000000000 -1000
|
| 15 |
+++ dhcp-4.1.0/common/dlpi.c 2009-01-06 10:41:32.000000000 -1000
|
| 16 |
@@ -689,7 +689,7 @@ ssize_t receive_packet (interface, buf,
|
| 17 |
length -= offset;
|
| 18 |
#endif
|
| 19 |
offset = decode_udp_ip_header (interface, dbuf, bufix,
|
| 20 |
- from, length, &paylen);
|
| 21 |
+ from, length, &paylen, 0);
|
| 22 |
|
| 23 |
/* If the IP or UDP checksum was bad, skip the packet... */
|
| 24 |
if (offset < 0) {
|
| 25 |
diff -up dhcp-4.1.0/common/lpf.c.xen dhcp-4.1.0/common/lpf.c
|
| 26 |
--- dhcp-4.1.0/common/lpf.c.xen 2009-01-06 10:41:31.000000000 -1000
|
| 27 |
+++ dhcp-4.1.0/common/lpf.c 2009-01-06 10:41:32.000000000 -1000
|
| 28 |
@@ -29,18 +29,33 @@
|
| 29 |
#include "dhcpd.h"
|
| 30 |
#if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE)
|
| 31 |
#include <sys/ioctl.h>
|
| 32 |
+#include <sys/socket.h>
|
| 33 |
#include <sys/uio.h>
|
| 34 |
#include <errno.h>
|
| 35 |
|
| 36 |
#include <asm/types.h>
|
| 37 |
#include <linux/filter.h>
|
| 38 |
#include <linux/if_ether.h>
|
| 39 |
+#include <linux/if_packet.h>
|
| 40 |
#include <netinet/in_systm.h>
|
| 41 |
#include "includes/netinet/ip.h"
|
| 42 |
#include "includes/netinet/udp.h"
|
| 43 |
#include "includes/netinet/if_ether.h"
|
| 44 |
#include <net/if.h>
|
| 45 |
|
| 46 |
+#ifndef PACKET_AUXDATA
|
| 47 |
+#define PACKET_AUXDATA 8
|
| 48 |
+
|
| 49 |
+struct tpacket_auxdata
|
| 50 |
+{
|
| 51 |
+ __u32 tp_status;
|
| 52 |
+ __u32 tp_len;
|
| 53 |
+ __u32 tp_snaplen;
|
| 54 |
+ __u16 tp_mac;
|
| 55 |
+ __u16 tp_net;
|
| 56 |
+};
|
| 57 |
+#endif
|
| 58 |
+
|
| 59 |
/* Reinitializes the specified interface after an address change. This
|
| 60 |
is not required for packet-filter APIs. */
|
| 61 |
|
| 62 |
@@ -66,10 +81,14 @@ int if_register_lpf (info)
|
| 63 |
struct interface_info *info;
|
| 64 |
{
|
| 65 |
int sock;
|
| 66 |
- struct sockaddr sa;
|
| 67 |
+ union {
|
| 68 |
+ struct sockaddr_ll ll;
|
| 69 |
+ struct sockaddr common;
|
| 70 |
+ } sa;
|
| 71 |
+ struct ifreq ifr;
|
| 72 |
|
| 73 |
/* Make an LPF socket. */
|
| 74 |
- if ((sock = socket(PF_PACKET, SOCK_PACKET,
|
| 75 |
+ if ((sock = socket(PF_PACKET, SOCK_RAW,
|
| 76 |
htons((short)ETH_P_ALL))) < 0) {
|
| 77 |
if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
|
| 78 |
errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
|
| 79 |
@@ -84,11 +103,16 @@ int if_register_lpf (info)
|
| 80 |
log_fatal ("Open a socket for LPF: %m");
|
| 81 |
}
|
| 82 |
|
| 83 |
+ memset (&ifr, 0, sizeof ifr);
|
| 84 |
+ strncpy (ifr.ifr_name, (const char *)info -> ifp, sizeof ifr.ifr_name);
|
| 85 |
+ if (ioctl (sock, SIOCGIFINDEX, &ifr))
|
| 86 |
+ log_fatal ("Failed to get interface index: %m");
|
| 87 |
+
|
| 88 |
/* Bind to the interface name */
|
| 89 |
memset (&sa, 0, sizeof sa);
|
| 90 |
- sa.sa_family = AF_PACKET;
|
| 91 |
- strncpy (sa.sa_data, (const char *)info -> ifp, sizeof sa.sa_data);
|
| 92 |
- if (bind (sock, &sa, sizeof sa)) {
|
| 93 |
+ sa.ll.sll_family = AF_PACKET;
|
| 94 |
+ sa.ll.sll_ifindex = ifr.ifr_ifindex;
|
| 95 |
+ if (bind (sock, &sa.common, sizeof sa)) {
|
| 96 |
if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
|
| 97 |
errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
|
| 98 |
errno == EAFNOSUPPORT || errno == EINVAL) {
|
| 99 |
@@ -170,9 +194,18 @@ static void lpf_gen_filter_setup (struct
|
| 100 |
void if_register_receive (info)
|
| 101 |
struct interface_info *info;
|
| 102 |
{
|
| 103 |
+ int val;
|
| 104 |
+
|
| 105 |
/* Open a LPF device and hang it on this interface... */
|
| 106 |
info -> rfdesc = if_register_lpf (info);
|
| 107 |
|
| 108 |
+ val = 1;
|
| 109 |
+ if (setsockopt (info -> rfdesc, SOL_PACKET, PACKET_AUXDATA, &val,
|
| 110 |
+ sizeof val) < 0) {
|
| 111 |
+ if (errno != ENOPROTOOPT)
|
| 112 |
+ log_fatal ("Failed to set auxiliary packet data: %m");
|
| 113 |
+ }
|
| 114 |
+
|
| 115 |
#if defined (HAVE_TR_SUPPORT)
|
| 116 |
if (info -> hw_address.hbuf [0] == HTYPE_IEEE802)
|
| 117 |
lpf_tr_filter_setup (info);
|
| 118 |
@@ -293,7 +326,6 @@ ssize_t send_packet (interface, packet,
|
| 119 |
double hh [16];
|
| 120 |
double ih [1536 / sizeof (double)];
|
| 121 |
unsigned char *buf = (unsigned char *)ih;
|
| 122 |
- struct sockaddr sa;
|
| 123 |
int result;
|
| 124 |
int fudge;
|
| 125 |
|
| 126 |
@@ -311,15 +343,7 @@ ssize_t send_packet (interface, packet,
|
| 127 |
(unsigned char *)raw, len);
|
| 128 |
memcpy (buf + ibufp, raw, len);
|
| 129 |
|
| 130 |
- /* For some reason, SOCK_PACKET sockets can't be connected,
|
| 131 |
- so we have to do a sentdo every time. */
|
| 132 |
- memset (&sa, 0, sizeof sa);
|
| 133 |
- sa.sa_family = AF_PACKET;
|
| 134 |
- strncpy (sa.sa_data,
|
| 135 |
- (const char *)interface -> ifp, sizeof sa.sa_data);
|
| 136 |
-
|
| 137 |
- result = sendto (interface -> wfdesc,
|
| 138 |
- buf + fudge, ibufp + len - fudge, 0, &sa, sizeof sa);
|
| 139 |
+ result = write (interface -> wfdesc, buf + fudge, ibufp + len - fudge);
|
| 140 |
if (result < 0)
|
| 141 |
log_error ("send_packet: %m");
|
| 142 |
return result;
|
| 143 |
@@ -336,14 +360,35 @@ ssize_t receive_packet (interface, buf,
|
| 144 |
{
|
| 145 |
int length = 0;
|
| 146 |
int offset = 0;
|
| 147 |
+ int nocsum = 0;
|
| 148 |
unsigned char ibuf [1536];
|
| 149 |
unsigned bufix = 0;
|
| 150 |
unsigned paylen;
|
| 151 |
+ unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
|
| 152 |
+ struct iovec iov = {
|
| 153 |
+ .iov_base = ibuf,
|
| 154 |
+ .iov_len = sizeof ibuf,
|
| 155 |
+ };
|
| 156 |
+ struct msghdr msg = {
|
| 157 |
+ .msg_iov = &iov,
|
| 158 |
+ .msg_iovlen = 1,
|
| 159 |
+ .msg_control = cmsgbuf,
|
| 160 |
+ .msg_controllen = sizeof(cmsgbuf),
|
| 161 |
+ };
|
| 162 |
+ struct cmsghdr *cmsg;
|
| 163 |
|
| 164 |
- length = read (interface -> rfdesc, ibuf, sizeof ibuf);
|
| 165 |
+ length = recvmsg (interface -> rfdesc, &msg, 0);
|
| 166 |
if (length <= 0)
|
| 167 |
return length;
|
| 168 |
|
| 169 |
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
| 170 |
+ if (cmsg->cmsg_level == SOL_PACKET &&
|
| 171 |
+ cmsg->cmsg_type == PACKET_AUXDATA) {
|
| 172 |
+ struct tpacket_auxdata *aux = (void *)CMSG_DATA(cmsg);
|
| 173 |
+ nocsum = aux->tp_status & TP_STATUS_CSUMNOTREADY;
|
| 174 |
+ }
|
| 175 |
+ }
|
| 176 |
+
|
| 177 |
bufix = 0;
|
| 178 |
/* Decode the physical header... */
|
| 179 |
offset = decode_hw_header (interface, ibuf, bufix, hfrom);
|
| 180 |
@@ -360,7 +405,7 @@ ssize_t receive_packet (interface, buf,
|
| 181 |
|
| 182 |
/* Decode the IP and UDP headers... */
|
| 183 |
offset = decode_udp_ip_header (interface, ibuf, bufix, from,
|
| 184 |
- (unsigned)length, &paylen);
|
| 185 |
+ (unsigned)length, &paylen, nocsum);
|
| 186 |
|
| 187 |
/* If the IP or UDP checksum was bad, skip the packet... */
|
| 188 |
if (offset < 0)
|
| 189 |
diff -up dhcp-4.1.0/common/nit.c.xen dhcp-4.1.0/common/nit.c
|
| 190 |
--- dhcp-4.1.0/common/nit.c.xen 2007-09-05 07:32:10.000000000 -1000
|
| 191 |
+++ dhcp-4.1.0/common/nit.c 2009-01-06 10:41:32.000000000 -1000
|
| 192 |
@@ -366,7 +366,7 @@ ssize_t receive_packet (interface, buf,
|
| 193 |
|
| 194 |
/* Decode the IP and UDP headers... */
|
| 195 |
offset = decode_udp_ip_header (interface, ibuf, bufix,
|
| 196 |
- from, length, &paylen);
|
| 197 |
+ from, length, &paylen, 0);
|
| 198 |
|
| 199 |
/* If the IP or UDP checksum was bad, skip the packet... */
|
| 200 |
if (offset < 0)
|
| 201 |
diff -up dhcp-4.1.0/common/packet.c.xen dhcp-4.1.0/common/packet.c
|
| 202 |
--- dhcp-4.1.0/common/packet.c.xen 2009-01-06 10:41:31.000000000 -1000
|
| 203 |
+++ dhcp-4.1.0/common/packet.c 2009-01-06 10:41:32.000000000 -1000
|
| 204 |
@@ -210,7 +210,7 @@ ssize_t
|
| 205 |
decode_udp_ip_header(struct interface_info *interface,
|
| 206 |
unsigned char *buf, unsigned bufix,
|
| 207 |
struct sockaddr_in *from, unsigned buflen,
|
| 208 |
- unsigned *rbuflen)
|
| 209 |
+ unsigned *rbuflen, int nocsum)
|
| 210 |
{
|
| 211 |
unsigned char *data;
|
| 212 |
struct ip ip;
|
| 213 |
@@ -321,7 +321,7 @@ decode_udp_ip_header(struct interface_in
|
| 214 |
8, IPPROTO_UDP + ulen))));
|
| 215 |
|
| 216 |
udp_packets_seen++;
|
| 217 |
- if (usum && usum != sum) {
|
| 218 |
+ if (!nocsum && usum && usum != sum) {
|
| 219 |
udp_packets_bad_checksum++;
|
| 220 |
if (udp_packets_seen > 4 &&
|
| 221 |
(udp_packets_seen / udp_packets_bad_checksum) < 2) {
|
| 222 |
diff -up dhcp-4.1.0/common/upf.c.xen dhcp-4.1.0/common/upf.c
|
| 223 |
--- dhcp-4.1.0/common/upf.c.xen 2007-07-12 20:43:42.000000000 -1000
|
| 224 |
+++ dhcp-4.1.0/common/upf.c 2009-01-06 10:41:32.000000000 -1000
|
| 225 |
@@ -317,7 +317,7 @@ ssize_t receive_packet (interface, buf,
|
| 226 |
|
| 227 |
/* Decode the IP and UDP headers... */
|
| 228 |
offset = decode_udp_ip_header (interface, ibuf, bufix,
|
| 229 |
- from, length, &paylen);
|
| 230 |
+ from, length, &paylen, 0);
|
| 231 |
|
| 232 |
/* If the IP or UDP checksum was bad, skip the packet... */
|
| 233 |
if (offset < 0)
|
| 234 |
diff -up dhcp-4.1.0/includes/dhcpd.h.xen dhcp-4.1.0/includes/dhcpd.h
|
| 235 |
--- dhcp-4.1.0/includes/dhcpd.h.xen 2009-01-06 10:41:32.000000000 -1000
|
| 236 |
+++ dhcp-4.1.0/includes/dhcpd.h 2009-01-06 10:41:32.000000000 -1000
|
| 237 |
@@ -2640,7 +2640,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));
|
| 243 |
|
| 244 |
/* ethernet.c */
|
| 245 |
void assemble_ethernet_header PROTO ((struct interface_info *, unsigned char *,
|