Fix the counters bug (#983)
[openwrt.git] / package / busybox / patches / 241-udhcpc-oversized_packets.patch
1 diff -ruN busybox-1.2.1-old/networking/udhcp/packet.c busybox-1.2.1-new/networking/udhcp/packet.c
2 --- busybox-1.2.1-old/networking/udhcp/packet.c 2006-07-01 00:42:02.000000000 +0200
3 +++ busybox-1.2.1-new/networking/udhcp/packet.c 2006-11-19 01:04:40.000000000 +0100
4 @@ -111,6 +111,10 @@
5 return ~sum;
6 }
7
8 +int udhcp_get_payload_len(struct dhcpMessage *payload)
9 +{
10 + return sizeof(struct dhcpMessage) - MAX_OPTIONS_LEN + end_option(payload->options) + sizeof(payload->options[0]);
11 +}
12
13 /* Construct a ip/udp header for a packet, and specify the source and dest hardware address */
14 int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
15 @@ -120,6 +124,7 @@
16 int result;
17 struct sockaddr_ll dest;
18 struct udp_dhcp_packet packet;
19 + int p_len = udhcp_get_payload_len(payload);
20
21 if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
22 DEBUG(LOG_ERR, "socket call failed: %m");
23 @@ -128,6 +133,7 @@
24
25 memset(&dest, 0, sizeof(dest));
26 memset(&packet, 0, sizeof(packet));
27 + memcpy(&(packet.data), payload, p_len);
28
29 dest.sll_family = AF_PACKET;
30 dest.sll_protocol = htons(ETH_P_IP);
31 @@ -145,18 +151,19 @@
32 packet.ip.daddr = dest_ip;
33 packet.udp.source = htons(source_port);
34 packet.udp.dest = htons(dest_port);
35 - packet.udp.len = htons(sizeof(packet.udp) + sizeof(struct dhcpMessage)); /* cheat on the psuedo-header */
36 + p_len += sizeof(packet.udp);
37 + packet.udp.len = htons(p_len);
38 packet.ip.tot_len = packet.udp.len;
39 - memcpy(&(packet.data), payload, sizeof(struct dhcpMessage));
40 - packet.udp.check = udhcp_checksum(&packet, sizeof(struct udp_dhcp_packet));
41 + p_len += sizeof(packet.ip);
42 + packet.udp.check = udhcp_checksum(&packet, p_len);
43
44 - packet.ip.tot_len = htons(sizeof(struct udp_dhcp_packet));
45 + packet.ip.tot_len = htons(p_len);
46 packet.ip.ihl = sizeof(packet.ip) >> 2;
47 packet.ip.version = IPVERSION;
48 packet.ip.ttl = IPDEFTTL;
49 packet.ip.check = udhcp_checksum(&(packet.ip), sizeof(packet.ip));
50
51 - result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0, (struct sockaddr *) &dest, sizeof(dest));
52 + result = sendto(fd, &packet, p_len, 0, (struct sockaddr *) &dest, sizeof(dest));
53 if (result <= 0) {
54 DEBUG(LOG_ERR, "write on socket failed: %m");
55 }
56 @@ -201,7 +208,7 @@
57 return -1;
58 }
59
60 - result = write(fd, payload, sizeof(struct dhcpMessage));
61 + result = write(fd, payload, udhcp_get_payload_len(payload));
62 close(fd);
63 return result;
64 }
65 diff -ruN busybox-1.2.1-old/networking/udhcp/packet.h busybox-1.2.1-new/networking/udhcp/packet.h
66 --- busybox-1.2.1-old/networking/udhcp/packet.h 2006-07-01 00:42:02.000000000 +0200
67 +++ busybox-1.2.1-new/networking/udhcp/packet.h 2006-11-19 00:49:38.000000000 +0100
68 @@ -4,6 +4,8 @@
69 #include <netinet/udp.h>
70 #include <netinet/ip.h>
71
72 +#define MAX_OPTIONS_LEN 308
73 +
74 struct dhcpMessage {
75 uint8_t op;
76 uint8_t htype;
77 @@ -20,7 +22,7 @@
78 uint8_t sname[64];
79 uint8_t file[128];
80 uint32_t cookie;
81 - uint8_t options[308]; /* 312 - cookie */
82 + uint8_t options[MAX_OPTIONS_LEN]; /* 312 - cookie */
83 };
84
85 struct udp_dhcp_packet {
This page took 0.046392 seconds and 5 git commands to generate.