]> git.pld-linux.org Git - packages/dhcp.git/blob - dhcp-xen-checksum.patch
- patch no-ipv6 - don't require ipv6 support in kernel
[packages/dhcp.git] / dhcp-xen-checksum.patch
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, 
5  
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);
10  
11         /* If the IP or UDP checksum was bad, skip the packet... */
12         if (offset < 0)
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, 
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.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, 
29  
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);
34  
35         /* If the IP or UDP checksum was bad, skip the packet... */
36         if (offset < 0)
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
40 @@ -29,18 +29,33 @@
41  #include "dhcpd.h"
42  #if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE)
43  #include <sys/ioctl.h>
44 +#include <sys/socket.h>
45  #include <sys/uio.h>
46  #include <errno.h>
47  
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"
56  #include <net/if.h>
57  
58 +#ifndef PACKET_AUXDATA
59 +#define PACKET_AUXDATA 8
60 +
61 +struct tpacket_auxdata
62 +{
63 +       __u32           tp_status;
64 +       __u32           tp_len;
65 +       __u32           tp_snaplen;
66 +       __u16           tp_mac;
67 +       __u16           tp_net;
68 +};
69 +#endif
70 +
71  /* Reinitializes the specified interface after an address change.   This
72     is not required for packet-filter APIs. */
73  
74 @@ -66,10 +81,14 @@ int if_register_lpf (info)
75         struct interface_info *info;
76  {
77         int sock;
78 -       struct sockaddr sa;
79 +       union {
80 +               struct sockaddr_ll ll;
81 +               struct sockaddr common;
82 +       } sa;
83 +       struct ifreq ifr;
84  
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");
93         }
94  
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");
99 +
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;
114  {
115 +       int val;
116 +
117         /* Open a LPF device and hang it on this interface... */
118         info -> rfdesc = if_register_lpf (info);
119  
120 +       val = 1;
121 +       if (setsockopt (info -> rfdesc, SOL_PACKET, PACKET_AUXDATA, &val,
122 +                       sizeof val) < 0) {
123 +               if (errno != ENOPROTOOPT)
124 +                       log_fatal ("Failed to set auxiliary packet data: %m");
125 +       }
126 +
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, 
131         double hh [16];
132         double ih [1536 / sizeof (double)];
133         unsigned char *buf = (unsigned char *)ih;
134 -       struct sockaddr sa;
135         int result;
136         int fudge;
137  
138 @@ -309,15 +341,7 @@ ssize_t send_packet (interface, packet, 
139                                 (unsigned char *)raw, len);
140         memcpy (buf + ibufp, raw, len);
141  
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);
148 -
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);
152         if (result < 0)
153                 log_error ("send_packet: %m");
154         return result;
155 @@ -334,14 +358,35 @@ ssize_t receive_packet (interface, buf, 
156  {
157         int length = 0;
158         int offset = 0;
159 +       int nocsum = 0;
160         unsigned char ibuf [1536];
161         unsigned bufix = 0;
162         unsigned paylen;
163 +       unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
164 +       struct iovec iov = {
165 +               .iov_base = ibuf,
166 +               .iov_len = sizeof ibuf,
167 +       };
168 +       struct msghdr msg = {
169 +               .msg_iov = &iov,
170 +               .msg_iovlen = 1,
171 +               .msg_control = cmsgbuf,
172 +               .msg_controllen = sizeof(cmsgbuf),
173 +       };
174 +       struct cmsghdr *cmsg;
175  
176 -       length = read (interface -> rfdesc, ibuf, sizeof ibuf);
177 +       length = recvmsg (interface -> rfdesc, &msg, 0);
178         if (length <= 0)
179                 return length;
180  
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;
186 +               }
187 +       }
188 +
189         bufix = 0;
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, 
193  
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);
198  
199         /* If the IP or UDP checksum was bad, skip the packet... */
200         if (offset < 0)
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,
206                                                interface -> rbuf,
207                                                interface -> rbuf_offset,
208 -                                              from, hdr.bh_caplen, &paylen);
209 +                                              from, hdr.bh_caplen, &paylen, 0);
210  
211                 /* If the IP or UDP checksum was bad, skip the packet... */
212                 if (offset < 0) {
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,
220 -                    unsigned *rbuflen)
221 +                    unsigned *rbuflen, int nocsum)
222  {
223    unsigned char *data;
224    struct ip ip;
225 @@ -321,7 +321,7 @@ decode_udp_ip_header(struct interface_in
226                                            8, IPPROTO_UDP + ulen))));
227  
228    udp_packets_seen++;
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));
243  
244  /* ethernet.c */
245  void assemble_ethernet_header PROTO ((struct interface_info *, unsigned char *,
This page took 0.077316 seconds and 3 git commands to generate.