38 const uint8_t *p = (uint8_t *)(
dhcp + 1);
41 for (
i = 0;
i < optlen; ++
i)
43 const uint8_t type = p[
i];
44 const int room = optlen -
i;
67 const int len = p[
i + 1];
78 uint8_t *p = (uint8_t *)(
dhcp + 1);
82 for (
i = 0;
i < optlen;)
84 const uint8_t type = p[
i];
85 const int room = optlen -
i;
98 const int len = p[
i + 1];
99 if (len <= (room - 2))
102 if (!ret && len >= 4 && (len & 3) == 0)
104 memcpy(&ret, p +
i + 2, 4);
109 uint8_t *dest = p +
i;
110 const int owlen = len + 2;
111 uint8_t *src = dest + owlen;
112 uint8_t *end = p + optlen;
113 const intptr_t movlen = end - src;
116 memmove(dest, src, movlen);
118 memset(end - owlen,
DHCP_PAD, owlen);
135 const int len = p[
i + 1];
189#if defined(_WIN32) || defined(DHCP_UNIT_TEST)
202 msg(
M_WARN,
"write_dhcp_u8: buffer overflow building DHCP options");
212 const unsigned int len,
bool *error)
216 const size_t size = len *
sizeof(uint32_t);
221 msg(
M_WARN,
"write_dhcp_u32_array: buffer overflow building DHCP options");
224 if (size < 1 || size > 255)
227 msg(
M_WARN,
"write_dhcp_u32_array: size (%zu) must be > 0 and <= 255", size);
232 for (
unsigned int i = 0;
i < len; ++
i)
242 const size_t len = strlen(str);
246 msg(
M_WARN,
"write_dhcp_str: buffer overflow building DHCP options");
249 if (len < 1 || len > 255)
252 msg(
M_WARN,
"write_dhcp_str: string '%s' must be > 0 bytes and <= 255 bytes", str);
270 int array_len,
bool *error)
274 size_t label_length_pos;
276 for (
int i = 0;
i < array_len;
i++)
278 const char *ptr = str_array[
i];
280 if (strlen(ptr) + len + 1 >
sizeof(tmp_buf))
283 msg(
M_WARN,
"write_dhcp_search_str: temp buffer overflow building DHCP options");
291 label_length_pos = len++;
295 if (*ptr ==
'.' || *ptr ==
'\0')
298 tmp_buf[label_length_pos] = (char)(len - label_length_pos - 1);
299 label_length_pos = len;
305 tmp_buf[len++] = *ptr++;
314 msg(
M_WARN,
"write_search_dhcp_str: buffer overflow building DHCP options");
320 msg(
M_WARN,
"write_dhcp_search_str: search domain string must be <= 255 bytes");
365 msg(
M_WARN,
"build_dhcp_options_string: buffer overflow building DHCP options");
static bool buf_write_u32(struct buffer *dest, uint32_t data)
static bool buf_safe(const struct buffer *buf, size_t len)
static bool buf_write(struct buffer *dest, const void *src, size_t size)
static bool buf_write_u8(struct buffer *dest, uint8_t data)
static void gc_free(struct gc_arena *a)
static struct gc_arena gc_new(void)
in_addr_t dhcp_extract_router_msg(struct buffer *ipbuf)
static in_addr_t do_extract(struct dhcp *dhcp, int optlen)
static void write_dhcp_search_str(struct buffer *buf, const uint8_t type, const char *const *str_array, int array_len, bool *error)
static void write_dhcp_u8(struct buffer *buf, const uint8_t type, const uint8_t data, bool *error)
static void write_dhcp_u32_array(struct buffer *buf, const uint8_t type, const uint32_t *data, const unsigned int len, bool *error)
static int get_dhcp_message_type(const struct dhcp *dhcp, const int optlen)
static void write_dhcp_str(struct buffer *buf, const uint8_t type, const char *str, bool *error)
bool build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o)
#define DHCP_NETBIOS_DOMAIN_SERVER
#define DHCP_NETBIOS_DIST_SERVER
#define DHCP_NETBIOS_SCOPE
#define DHCP_DOMAIN_SEARCH
#define DHCP_NETBIOS_NODE_TYPE
#define DHCP_DOMAIN_SERVER
uint16_t ip_checksum(const sa_family_t af, const uint8_t *payload, const int len_payload, const uint8_t *src_addr, const uint8_t *dest_addr, const int proto)
Calculates an IP or IPv6 checksum with a pseudo header as required by TCP, UDP and ICMPv6.
#define OPENVPN_IPPROTO_UDP
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
Wrapper structure for dynamically allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
in_addr_t nbdd[N_DHCP_ADDR]
in_addr_t ntp[N_DHCP_ADDR]
in_addr_t wins[N_DHCP_ADDR]
uint8_t netbios_node_type
in_addr_t dns[N_DHCP_ADDR]
const char * netbios_scope
int domain_search_list_len
const char * domain_search_list[N_SEARCH_LIST_LEN]