package/busybox: update to busybox-1.7.1, include upstream patches
[openwrt/openwrt.git] / package / busybox / patches / 241-udhcpc-oversized_packets.patch
1 --- a/networking/udhcp/packet.c
2 +++ b/networking/udhcp/packet.c
3 @@ -165,6 +165,11 @@ uint16_t FAST_FUNC udhcp_checksum(void *
4 return ~sum;
5 }
6
7 +int udhcp_get_payload_len(struct dhcp_packet *dhcp_pkt)
8 +{
9 + return sizeof(struct dhcp_packet) - DHCP_OPTIONS_BUFSIZE + udhcp_end_option(dhcp_pkt->options) + sizeof(dhcp_pkt->options[0]);
10 +}
11 +
12 /* Construct a ip/udp header for a packet, send packet */
13 int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
14 uint32_t source_nip, int source_port,
15 @@ -173,11 +178,12 @@ int FAST_FUNC udhcp_send_raw_packet(stru
16 {
17 struct sockaddr_ll dest_sll;
18 struct ip_udp_dhcp_packet packet;
19 - unsigned padding;
20 int fd;
21 int result = -1;
22 const char *msg;
23
24 + int p_len = udhcp_get_payload_len(dhcp_pkt);
25 +
26 fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
27 if (fd < 0) {
28 msg = "socket(%s)";
29 @@ -186,7 +192,7 @@ int FAST_FUNC udhcp_send_raw_packet(stru
30
31 memset(&dest_sll, 0, sizeof(dest_sll));
32 memset(&packet, 0, offsetof(struct ip_udp_dhcp_packet, data));
33 - packet.data = *dhcp_pkt; /* struct copy */
34 + memcpy(&(packet.data), dhcp_pkt, p_len);
35
36 dest_sll.sll_family = AF_PACKET;
37 dest_sll.sll_protocol = htons(ETH_P_IP);
38 @@ -208,27 +214,25 @@ int FAST_FUNC udhcp_send_raw_packet(stru
39 * In order to work with those buggy servers,
40 * we truncate packets after end option byte.
41 */
42 - padding = DHCP_OPTIONS_BUFSIZE - 1 - udhcp_end_option(packet.data.options);
43
44 packet.ip.protocol = IPPROTO_UDP;
45 packet.ip.saddr = source_nip;
46 packet.ip.daddr = dest_nip;
47 packet.udp.source = htons(source_port);
48 packet.udp.dest = htons(dest_port);
49 - /* size, excluding IP header: */
50 - packet.udp.len = htons(UPD_DHCP_SIZE - padding);
51 - /* for UDP checksumming, ip.len is set to UDP packet len */
52 + p_len += sizeof(packet.udp);
53 + packet.udp.len = htons(p_len);
54 packet.ip.tot_len = packet.udp.len;
55 - packet.udp.check = udhcp_checksum(&packet, IP_UPD_DHCP_SIZE - padding);
56 - /* but for sending, it is set to IP packet len */
57 - packet.ip.tot_len = htons(IP_UPD_DHCP_SIZE - padding);
58 + p_len += sizeof(packet.ip);
59 + packet.udp.check = udhcp_checksum(&packet, p_len);
60 + packet.ip.tot_len = htons(p_len);
61 packet.ip.ihl = sizeof(packet.ip) >> 2;
62 packet.ip.version = IPVERSION;
63 packet.ip.ttl = IPDEFTTL;
64 packet.ip.check = udhcp_checksum(&packet.ip, sizeof(packet.ip));
65
66 udhcp_dump_packet(dhcp_pkt);
67 - result = sendto(fd, &packet, IP_UPD_DHCP_SIZE - padding, /*flags:*/ 0,
68 + result = sendto(fd, &packet, p_len, 0,
69 (struct sockaddr *) &dest_sll, sizeof(dest_sll));
70 msg = "sendto";
71 ret_close:
72 @@ -246,7 +250,6 @@ int FAST_FUNC udhcp_send_kernel_packet(s
73 uint32_t dest_nip, int dest_port)
74 {
75 struct sockaddr_in client;
76 - unsigned padding;
77 int fd;
78 int result = -1;
79 const char *msg;
80 @@ -278,8 +281,7 @@ int FAST_FUNC udhcp_send_kernel_packet(s
81
82 udhcp_dump_packet(dhcp_pkt);
83
84 - padding = DHCP_OPTIONS_BUFSIZE - 1 - udhcp_end_option(dhcp_pkt->options);
85 - result = safe_write(fd, dhcp_pkt, DHCP_SIZE - padding);
86 + result = safe_write(fd, dhcp_pkt, udhcp_get_payload_len(dhcp_pkt));
87 msg = "write";
88 ret_close:
89 close(fd);