ar71xx: D-Link DIR-825 B1 eth1 MAC address is garbage
[openwrt.git] / package / busybox / patches / 244-udhcpc_add_6rd_option.patch
1 --- a/networking/udhcp/common.c
2 +++ b/networking/udhcp/common.c
3 @@ -54,6 +54,7 @@ const struct dhcp_optflag dhcp_optflags[
4 { OPTION_SIP_SERVERS , 0x78 }, /* DHCP_SIP_SERVERS */
5 #endif
6 { OPTION_STATIC_ROUTES , 0x79 }, /* DHCP_STATIC_ROUTES */
7 + { OPTION_6RD , 0xd4 }, /* DHCP_6RD */
8 { OPTION_STRING , 0xfc }, /* DHCP_WPAD */
9
10 /* Options below have no match in dhcp_option_strings[],
11 @@ -114,6 +115,7 @@ const char dhcp_option_strings[] ALIGN1
12 // doesn't work in udhcpd.conf since OPTION_STATIC_ROUTES
13 // is not handled yet by "string->option" conversion code:
14 "staticroutes" "\0"/* DHCP_STATIC_ROUTES */
15 + "ip6rd" "\0" /* DHCP_6RD */
16 "wpad" "\0" /* DHCP_WPAD */
17 ;
18
19 @@ -141,6 +143,7 @@ const uint8_t dhcp_option_lengths[] ALIG
20 [OPTION_S32] = 4,
21 /* Just like OPTION_STRING, we use minimum length here */
22 [OPTION_STATIC_ROUTES] = 5,
23 + [OPTION_6RD] = 22,
24 };
25
26
27 --- a/networking/udhcp/dhcpc.c
28 +++ b/networking/udhcp/dhcpc.c
29 @@ -45,6 +45,7 @@ static const uint8_t len_of_option_as_st
30 [OPTION_IP ] = sizeof("255.255.255.255 "),
31 [OPTION_IP_PAIR ] = sizeof("255.255.255.255 ") * 2,
32 [OPTION_STATIC_ROUTES ] = sizeof("255.255.255.255/32 255.255.255.255 "),
33 + [OPTION_6RD ] = sizeof("32 128 FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF 255.255.255.255 "),
34 [OPTION_STRING ] = 1,
35 #if ENABLE_FEATURE_UDHCP_RFC3397
36 [OPTION_DNS_STRING ] = 1, /* unused */
37 @@ -68,6 +69,23 @@ static int sprint_nip(char *dest, const
38 return sprintf(dest, "%s%u.%u.%u.%u", pre, ip[0], ip[1], ip[2], ip[3]);
39 }
40
41 +static int sprint_nip6(char *dest, const char *pre, const uint8_t *ip)
42 +{
43 + int len = 0;
44 + int off;
45 + uint16_t word;
46 +
47 + len += sprintf(dest, "%s", pre);
48 +
49 + for (off = 0; off < 16; off += 2)
50 + {
51 + move_from_unaligned16(word, &ip[off]);
52 + len += sprintf(dest+len, "%s%04X", off ? ":" : "", htons(word));
53 + }
54 +
55 + return len;
56 +}
57 +
58 /* really simple implementation, just count the bits */
59 static int mton(uint32_t mask)
60 {
61 @@ -177,6 +195,70 @@ static NOINLINE char *xmalloc_optname_op
62
63 return ret;
64 }
65 + case OPTION_6RD: {
66 + /* Option binary format:
67 + * 0 1 2 3
68 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
69 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 + * | OPTION_6RD | option-length | IPv4MaskLen | 6rdPrefixLen |
71 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72 + * | |
73 + * | 6rdPrefix |
74 + * | (16 octets) |
75 + * | |
76 + * | |
77 + * | |
78 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79 + * | 6rdBRIPv4Address(es) |
80 + * . .
81 + * . .
82 + * . .
83 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
84 + *
85 + * We convert it to a string "IPv4MaskLen 6rdPrefixLen 6rdPrefix 6rdBRIPv4Address"
86 + */
87 +
88 + /* Sanity check: ensure that our length is at least 22 bytes, that
89 + * IPv4MaskLen is <= 32, 6rdPrefixLen <= 128 and that the sum of
90 + * (32 - IPv4MaskLen) + 6rdPrefixLen is less than or equal to 128.
91 + * If any of these requirements is not fulfilled, return with empty
92 + * value.
93 + */
94 + if ((len >= 22) && (*option <= 32) && (*(option+1) <= 128) &&
95 + (((32 - *option) + *(option+1)) <= 128))
96 + {
97 + /* IPv4MaskLen */
98 + dest += sprintf(dest, "%u ", *option++);
99 + len--;
100 +
101 + /* 6rdPrefixLen */
102 + dest += sprintf(dest, "%u ", *option++);
103 + len--;
104 +
105 + /* 6rdPrefix */
106 + dest += sprint_nip6(dest, "", option);
107 + option += 16;
108 + len -= 16;
109 +
110 + /* 6rdBRIPv4Addresses */
111 + while (len >= 4)
112 + {
113 + dest += sprint_nip(dest, " ", option);
114 + option += 4;
115 + len -= 4;
116 +
117 + /* the code to determine the option size fails to work with
118 + * lengths that are not a multiple of the minimum length,
119 + * adding all advertised 6rdBRIPv4Addresses here would
120 + * overflow the destination buffer, therefore skip the rest
121 + * for now
122 + */
123 + break;
124 + }
125 + }
126 +
127 + return ret;
128 + }
129 #if ENABLE_FEATURE_UDHCP_RFC3397
130 case OPTION_DNS_STRING:
131 /* unpack option into dest; use ret for prefix (i.e., "optname=") */
132 --- a/networking/udhcp/common.h
133 +++ b/networking/udhcp/common.h
134 @@ -88,6 +88,7 @@ enum {
135 OPTION_S32,
136 OPTION_BIN,
137 OPTION_STATIC_ROUTES,
138 + OPTION_6RD,
139 #if ENABLE_FEATURE_UDHCP_RFC3397
140 OPTION_DNS_STRING, /* RFC1035 compressed domain name list */
141 OPTION_SIP_SERVERS,
This page took 0.045899 seconds and 5 git commands to generate.