/[packages]/cauldron/dhcp/current/SOURCES/dhcp-4.2.2-xen-checksum.patch
ViewVC logotype

Contents of /cauldron/dhcp/current/SOURCES/dhcp-4.2.2-xen-checksum.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 636554 - (show annotations) (download)
Sun Jun 15 15:59:35 2014 UTC (9 years, 9 months ago) by luigiwalser
File size: 8773 byte(s)
- 4.3.0
- rediff patches 101, 8, and 18

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

  ViewVC Help
Powered by ViewVC 1.1.30