lantiq: Tune the XWAY subtarget cflags
[openwrt.git] / package / busybox / patches / 950-partial-checksum.patch
1 --- a/networking/udhcp/dhcpc.c
2 +++ b/networking/udhcp/dhcpc.c
3 @@ -26,8 +26,8 @@
4  #include "dhcpc.h"
5  
6  #include <netinet/if_ether.h>
7 -#include <netpacket/packet.h>
8  #include <linux/filter.h>
9 +#include <linux/if_packet.h>
10  
11  /* struct client_config_t client_config is in bb_common_bufsiz1 */
12  
13 @@ -846,17 +846,41 @@ static int send_release(uint32_t server,
14  static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
15  {
16         int bytes;
17 +       int nocsum = 0;
18         struct ip_udp_dhcp_packet packet;
19         uint16_t check;
20 +       unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
21 +       struct iovec iov = {
22 +               .iov_base = &packet,
23 +               .iov_len = sizeof(packet),
24 +       };
25 +       struct msghdr msg = {
26 +               .msg_iov = &iov,
27 +               .msg_iovlen = 1,
28 +               .msg_control = cmsgbuf,
29 +               .msg_controllen = sizeof(cmsgbuf),
30 +       };
31 +       struct cmsghdr *cmsg;
32  
33         memset(&packet, 0, sizeof(packet));
34 -       bytes = safe_read(fd, &packet, sizeof(packet));
35 +       do {
36 +               bytes = recvmsg(fd, &msg, 0);
37 +       } while (bytes < 0 && errno == EINTR);
38 +
39         if (bytes < 0) {
40                 log1("Packet read error, ignoring");
41                 /* NB: possible down interface, etc. Caller should pause. */
42                 return bytes; /* returns -1 */
43         }
44  
45 +       for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
46 +               if (cmsg->cmsg_level == SOL_PACKET &&
47 +                       cmsg->cmsg_type == PACKET_AUXDATA) {
48 +                       struct tpacket_auxdata *aux = (void *)CMSG_DATA(cmsg);
49 +                       nocsum = aux->tp_status & TP_STATUS_CSUMNOTREADY;
50 +               }
51 +       }
52 +
53         if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) {
54                 log1("Packet is too short, ignoring");
55                 return -2;
56 @@ -896,7 +920,7 @@ static NOINLINE int udhcp_recv_raw_packe
57         packet.ip.tot_len = packet.udp.len; /* yes, this is needed */
58         check = packet.udp.check;
59         packet.udp.check = 0;
60 -       if (check && check != udhcp_checksum(&packet, bytes)) {
61 +       if (!nocsum && check && check != udhcp_checksum(&packet, bytes)) {
62                 log1("Packet with bad UDP checksum received, ignoring");
63                 return -2;
64         }
65 @@ -942,6 +966,7 @@ static int udhcp_raw_socket(int ifindex)
66  {
67         int fd;
68         struct sockaddr_ll sock;
69 +       int val;
70  
71         /*
72          * Comment:
73 @@ -1008,6 +1033,13 @@ static int udhcp_raw_socket(int ifindex)
74                         log1("Attached filter to raw socket fd %d", fd); // log?
75         }
76  
77 +       val = 1;
78 +       if (setsockopt(fd, SOL_PACKET, PACKET_AUXDATA, &val,
79 +                       sizeof(val)) < 0) {
80 +               if (errno != ENOPROTOOPT)
81 +                       log1("Failed to set auxiliary packet data for socket fd %d", fd);
82 +       }
83 +
84         log1("Created raw socket");
85  
86         return fd;