1 --- a/networking/udhcp/dhcpc.c
2 +++ b/networking/udhcp/dhcpc.c
6 #include <netinet/if_ether.h>
7 -#include <netpacket/packet.h>
8 #include <linux/filter.h>
9 +#include <linux/if_packet.h>
11 /* struct client_config_t client_config is in bb_common_bufsiz1 */
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)
18 struct ip_udp_dhcp_packet packet;
20 + unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
21 + struct iovec iov = {
22 + .iov_base = &packet,
23 + .iov_len = sizeof(packet),
25 + struct msghdr msg = {
28 + .msg_control = cmsgbuf,
29 + .msg_controllen = sizeof(cmsgbuf),
31 + struct cmsghdr *cmsg;
33 memset(&packet, 0, sizeof(packet));
34 - bytes = safe_read(fd, &packet, sizeof(packet));
36 + bytes = recvmsg(fd, &msg, 0);
37 + } while (bytes < 0 && errno == EINTR);
40 log1("Packet read error, ignoring");
41 /* NB: possible down interface, etc. Caller should pause. */
42 return bytes; /* returns -1 */
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;
53 if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) {
54 log1("Packet is too short, ignoring");
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;
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");
65 @@ -942,6 +966,7 @@ static int udhcp_raw_socket(int ifindex)
68 struct sockaddr_ll sock;
73 @@ -1008,6 +1033,13 @@ static int udhcp_raw_socket(int ifindex)
74 log1("Attached filter to raw socket fd %d", fd); // log?
78 + if (setsockopt(fd, SOL_PACKET, PACKET_AUXDATA, &val,
80 + if (errno != ENOPROTOOPT)
81 + log1("Failed to set auxiliary packet data for socket fd %d", fd);
84 log1("Created raw socket");