use CONFIG_EMBEDDED for x86, too
[openwrt.git] / package / busybox / patches / 241-udhcpc-oversized_packets.patch
1 --- a/networking/udhcp/packet.c
2 +++ b/networking/udhcp/packet.c
3 @@ -120,6 +120,10 @@ uint16_t FAST_FUNC udhcp_checksum(void *
4 return ~sum;
5 }
6
7 +int udhcp_get_payload_len(struct dhcpMessage *payload)
8 +{
9 + return sizeof(struct dhcpMessage) - DHCP_OPTIONS_BUFSIZE + end_option(payload->options) + sizeof(payload->options[0]);
10 +}
11
12 /* Construct a ip/udp header for a packet, send packet */
13 int FAST_FUNC udhcp_send_raw_packet(struct dhcpMessage *payload,
14 @@ -132,11 +136,7 @@ int FAST_FUNC udhcp_send_raw_packet(stru
15 int fd;
16 int result = -1;
17 const char *msg;
18 -
19 - enum {
20 - IP_UPD_DHCP_SIZE = sizeof(struct udp_dhcp_packet) - CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS,
21 - UPD_DHCP_SIZE = IP_UPD_DHCP_SIZE - offsetof(struct udp_dhcp_packet, udp),
22 - };
23 + int p_len = udhcp_get_payload_len(payload);
24
25 fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
26 if (fd < 0) {
27 @@ -146,7 +146,7 @@ int FAST_FUNC udhcp_send_raw_packet(stru
28
29 memset(&dest, 0, sizeof(dest));
30 memset(&packet, 0, sizeof(packet));
31 - packet.data = *payload; /* struct copy */
32 + memcpy(&(packet.data), payload, p_len);
33
34 dest.sll_family = AF_PACKET;
35 dest.sll_protocol = htons(ETH_P_IP);
36 @@ -163,23 +163,18 @@ int FAST_FUNC udhcp_send_raw_packet(stru
37 packet.ip.daddr = dest_ip;
38 packet.udp.source = htons(source_port);
39 packet.udp.dest = htons(dest_port);
40 - /* size, excluding IP header: */
41 - packet.udp.len = htons(UPD_DHCP_SIZE);
42 - /* for UDP checksumming, ip.len is set to UDP packet len */
43 + p_len += sizeof(packet.udp);
44 + packet.udp.len = htons(p_len);
45 packet.ip.tot_len = packet.udp.len;
46 - packet.udp.check = udhcp_checksum(&packet, IP_UPD_DHCP_SIZE);
47 - /* but for sending, it is set to IP packet len */
48 - packet.ip.tot_len = htons(IP_UPD_DHCP_SIZE);
49 + p_len += sizeof(packet.ip);
50 + packet.udp.check = udhcp_checksum(&packet, p_len);
51 + packet.ip.tot_len = htons(p_len);
52 packet.ip.ihl = sizeof(packet.ip) >> 2;
53 packet.ip.version = IPVERSION;
54 packet.ip.ttl = IPDEFTTL;
55 packet.ip.check = udhcp_checksum(&packet.ip, sizeof(packet.ip));
56
57 - /* Currently we send full-sized DHCP packets (zero padded).
58 - * If you need to change this: last byte of the packet is
59 - * packet.data.options[end_option(packet.data.options)]
60 - */
61 - result = sendto(fd, &packet, IP_UPD_DHCP_SIZE, 0,
62 + result = sendto(fd, &packet, p_len, 0,
63 (struct sockaddr *) &dest, sizeof(dest));
64 msg = "sendto";
65 ret_close:
66 @@ -231,8 +226,7 @@ int FAST_FUNC udhcp_send_kernel_packet(s
67 goto ret_close;
68 }
69
70 - /* Currently we send full-sized DHCP packets (see above) */
71 - result = safe_write(fd, payload, DHCP_SIZE);
72 + result = safe_write(fd, payload, udhcp_get_payload_len(payload));
73 msg = "write";
74 ret_close:
75 close(fd);
This page took 0.041049 seconds and 5 git commands to generate.