dhcp: Increase buffer size for options in DHCP messages
According to RFC 2131, the minimum size of the 'options' field is 312 bytes, including the 4 byte magic cookie. There also does not seem to be any restriction regarding the message length, previously the length was rounded to a multiple of 64 bytes. The latter might have been because in BOOTP the options field (or rather vendor-specific area as it was called back then) had a fixed length of 64 bytes (so max(optlen+4, 64) might actually have been what was intended), but for DHCP the field is explicitly variable length, so I don't think it's necessary to pad it.
This commit is contained in:
@@ -160,7 +160,7 @@ typedef struct __attribute__((packed)) {
|
|||||||
} dhcp_option_t;
|
} dhcp_option_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DHCP message format, with a maximum size options buffer
|
* DHCP message format, with a minimum size options buffer
|
||||||
*/
|
*/
|
||||||
typedef struct __attribute__((packed)) {
|
typedef struct __attribute__((packed)) {
|
||||||
uint8_t opcode;
|
uint8_t opcode;
|
||||||
@@ -179,7 +179,7 @@ typedef struct __attribute__((packed)) {
|
|||||||
char server_hostname[64];
|
char server_hostname[64];
|
||||||
char boot_filename[128];
|
char boot_filename[128];
|
||||||
uint32_t magic_cookie;
|
uint32_t magic_cookie;
|
||||||
u_char options[252];
|
u_char options[308];
|
||||||
} dhcp_t;
|
} dhcp_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -286,7 +286,7 @@ static bool send_dhcp(private_dhcp_socket_t *this,
|
|||||||
{
|
{
|
||||||
dst = this->dst;
|
dst = this->dst;
|
||||||
}
|
}
|
||||||
len = offsetof(dhcp_t, magic_cookie) + ((optlen + 4) / 64 * 64 + 64);
|
len = offsetof(dhcp_t, magic_cookie) + optlen + 4;
|
||||||
return sendto(this->send, dhcp, len, 0, dst->get_sockaddr(dst),
|
return sendto(this->send, dhcp, len, 0, dst->get_sockaddr(dst),
|
||||||
*dst->get_sockaddr_len(dst)) == len;
|
*dst->get_sockaddr_len(dst)) == len;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user