From 020a2707c44849077f0c30af6d800f8e5f930f7f Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 9 Feb 2021 21:24:59 +0100 Subject: dhcp: nettools: export broadcast and server-id options https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/426 --- src/core/dhcp/nm-dhcp-nettools.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/core/dhcp/nm-dhcp-nettools.c b/src/core/dhcp/nm-dhcp-nettools.c index d1451a5319..ae1aeadfa4 100644 --- a/src/core/dhcp/nm-dhcp-nettools.c +++ b/src/core/dhcp/nm-dhcp-nettools.c @@ -516,6 +516,38 @@ lease_parse_address_list(NDhcp4ClientLease * lease, nm_dhcp_option_add_option(options, _nm_dhcp_option_dhcp4_options, option, str->str); } +static void +lease_parse_server_id(NDhcp4ClientLease *lease, NMIP4Config *ip4_config, GHashTable *options) +{ + struct in_addr addr; + char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + + if (n_dhcp4_client_lease_get_server_identifier(lease, &addr)) + return; + + _nm_utils_inet4_ntop(addr.s_addr, addr_str); + nm_dhcp_option_add_option(options, + _nm_dhcp_option_dhcp4_options, + NM_DHCP_OPTION_DHCP4_SERVER_ID, + addr_str); +} + +static void +lease_parse_broadcast(NDhcp4ClientLease *lease, NMIP4Config *ip4_config, GHashTable *options) +{ + struct in_addr addr; + char addr_str[NM_UTILS_INET_ADDRSTRLEN]; + + if (!lease_get_in_addr(lease, NM_DHCP_OPTION_DHCP4_BROADCAST, &addr)) + return; + + _nm_utils_inet4_ntop(addr.s_addr, addr_str); + nm_dhcp_option_add_option(options, + _nm_dhcp_option_dhcp4_options, + NM_DHCP_OPTION_DHCP4_BROADCAST, + addr_str); +} + static void lease_parse_routes(NDhcp4ClientLease *lease, NMIP4Config * ip4_config, @@ -974,6 +1006,8 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, if (!lease_parse_address(lease, ip4_config, options, error)) return NULL; + lease_parse_server_id(lease, ip4_config, options); + lease_parse_broadcast(lease, ip4_config, options); lease_parse_routes(lease, ip4_config, options, route_table, route_metric); lease_parse_address_list(lease, ip4_config, NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER, options); lease_parse_domainname(lease, ip4_config, options); -- cgit v1.2.1