diff options
author | Tom Gundersen <teg@jklm.no> | 2014-01-13 23:07:59 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-01-16 01:44:19 +0100 |
commit | 4f882b2a5007e51032459e29d15a86df6b5ea9f4 (patch) | |
tree | 7880ef1726915c77ee3cb7b37fa0d7b4b908cc67 /src/libsystemd/sd-dhcp-client.c | |
parent | eb2f9b18026c7b52099b324f4e9136f23b340c8d (diff) |
sd-dhcp-client/networkd: add interface MTU support
Diffstat (limited to 'src/libsystemd/sd-dhcp-client.c')
-rw-r--r-- | src/libsystemd/sd-dhcp-client.c | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/src/libsystemd/sd-dhcp-client.c b/src/libsystemd/sd-dhcp-client.c index 1df89dc651..76abcbd2ac 100644 --- a/src/libsystemd/sd-dhcp-client.c +++ b/src/libsystemd/sd-dhcp-client.c @@ -42,6 +42,7 @@ struct DHCPLease { be32_t subnet_mask; be32_t router; struct in_addr **dns; + uint16_t mtu; }; typedef struct DHCPLease DHCPLease; @@ -186,10 +187,10 @@ int sd_dhcp_client_get_address(sd_dhcp_client *client, struct in_addr *addr) return 0; } -int sd_dhcp_client_get_netmask(sd_dhcp_client *client, struct in_addr *addr) +int sd_dhcp_client_get_mtu(sd_dhcp_client *client, uint16_t *mtu) { assert_return(client, -EINVAL); - assert_return(addr, -EINVAL); + assert_return(mtu, -EINVAL); switch (client->state) { case DHCP_STATE_INIT: @@ -202,7 +203,10 @@ int sd_dhcp_client_get_netmask(sd_dhcp_client *client, struct in_addr *addr) case DHCP_STATE_BOUND: case DHCP_STATE_RENEWING: case DHCP_STATE_REBINDING: - addr->s_addr = client->lease->subnet_mask; + if (client->lease->mtu) + *mtu = client->lease->mtu; + else + return -ENOENT; break; } @@ -277,6 +281,30 @@ int sd_dhcp_client_get_router(sd_dhcp_client *client, struct in_addr *addr) return 0; } +int sd_dhcp_client_get_netmask(sd_dhcp_client *client, struct in_addr *addr) +{ + assert_return(client, -EINVAL); + assert_return(addr, -EINVAL); + + switch (client->state) { + case DHCP_STATE_INIT: + case DHCP_STATE_SELECTING: + case DHCP_STATE_INIT_REBOOT: + case DHCP_STATE_REBOOTING: + case DHCP_STATE_REQUESTING: + return -EADDRNOTAVAIL; + + case DHCP_STATE_BOUND: + case DHCP_STATE_RENEWING: + case DHCP_STATE_REBINDING: + addr->s_addr = client->lease->subnet_mask; + + break; + } + + return 0; +} + static int client_notify(sd_dhcp_client *client, int event) { if (client->cb) @@ -788,6 +816,19 @@ static int client_parse_offer(uint8_t code, uint8_t len, const uint8_t *option, break; + case DHCP_OPTION_INTERFACE_MTU: + if (len >= 2) { + be16_t mtu; + + memcpy(&mtu, option, 2); + lease->mtu = be16toh(mtu); + + if (lease->mtu < 68) + lease->mtu = 0; + } + + break; + case DHCP_OPTION_RENEWAL_T1_TIME: if (len == 4) { memcpy(&val, option, 4); |