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