diff options
author | Tom Gundersen <teg@jklm.no> | 2014-04-11 19:54:04 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-04-11 22:24:25 +0200 |
commit | 8a9e761600d0d44bcc2e665e4fe1fda30e3e4749 (patch) | |
tree | b19de494187740b2f240d967b5ce8def32a38441 /src | |
parent | eb105b96d58a3ebfeedb76a5d421b13748e0395c (diff) |
sd-dhcp-client: assert that we can only create DISCOVER or REQUEST messages
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd-network/sd-dhcp-client.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index 4be37a2389..e690f6785f 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -242,6 +242,7 @@ static sd_dhcp_client *client_stop(sd_dhcp_client *client, int error) { static int client_message_init(sd_dhcp_client *client, DHCPMessage *message, uint8_t type, uint8_t **opt, size_t *optlen) { + be16_t max_size; int r; assert(client); @@ -249,6 +250,7 @@ static int client_message_init(sd_dhcp_client *client, DHCPMessage *message, assert(message); assert(opt); assert(optlen); + assert(type == DHCP_DISCOVER || type == DHCP_REQUEST); r = dhcp_message_init(message, BOOTREQUEST, client->xid, type, opt, optlen); @@ -272,27 +274,23 @@ static int client_message_init(sd_dhcp_client *client, DHCPMessage *message, if (r < 0) return r; - if (type == DHCP_DISCOVER || type == DHCP_REQUEST) { - be16_t max_size; - - r = dhcp_option_append(opt, optlen, - DHCP_OPTION_PARAMETER_REQUEST_LIST, - client->req_opts_size, - client->req_opts); - if (r < 0) - return r; + r = dhcp_option_append(opt, optlen, + DHCP_OPTION_PARAMETER_REQUEST_LIST, + client->req_opts_size, + client->req_opts); + if (r < 0) + return r; - /* Some DHCP servers will send bigger DHCP packets than the - defined default size unless the Maximum Messge Size option - is explicitely set */ - max_size = htobe16(DHCP_IP_UDP_SIZE + DHCP_MESSAGE_SIZE + - DHCP_MIN_OPTIONS_SIZE); - r = dhcp_option_append(opt, optlen, - DHCP_OPTION_MAXIMUM_MESSAGE_SIZE, - 2, &max_size); - if (r < 0) - return r; - } + /* Some DHCP servers will send bigger DHCP packets than the + defined default size unless the Maximum Messge Size option + is explicitely set */ + max_size = htobe16(DHCP_IP_UDP_SIZE + DHCP_MESSAGE_SIZE + + DHCP_MIN_OPTIONS_SIZE); + r = dhcp_option_append(opt, optlen, + DHCP_OPTION_MAXIMUM_MESSAGE_SIZE, + 2, &max_size); + if (r < 0) + return r; return 0; } |