[systemd-devel] [PATCH] networkd: Make DHCP client ID creation configurable

Tom Gundersen teg at jklm.no
Wed Mar 4 01:53:36 PST 2015


Great stuff! Applied.

Thanks!

Tom

On Tue, Mar 3, 2015 at 7:49 PM, Jan Janssen <medhefgo at web.de> wrote:
> ---
>  man/systemd.network.xml                  |  8 ++++++++
>  src/network/networkd-dhcp4.c             | 16 ++++++++++++++++
>  src/network/networkd-network-gperf.gperf |  1 +
>  src/network/networkd-network.c           |  9 +++++++++
>  src/network/networkd.h                   | 11 +++++++++++
>  5 files changed, 45 insertions(+)
>
> diff --git a/man/systemd.network.xml b/man/systemd.network.xml
> index 60252e5..3522551 100644
> --- a/man/systemd.network.xml
> +++ b/man/systemd.network.xml
> @@ -564,6 +564,14 @@
>            </listitem>
>          </varlistentry>
>          <varlistentry>
> +          <term><varname>ClientIdentifier=</varname></term>
> +          <listitem>
> +            <para>DHCP client identifier to use. Either <literal>mac</literal>
> +            to use the MAC address of the link or <literal>duid</literal>
> +            (the default) to use a RFC4361-complient Client ID.</para>
> +          </listitem>
> +        </varlistentry>
> +        <varlistentry>
>            <term><varname>VendorClassIdentifier=</varname></term>
>            <listitem>
>              <para>The vendor class identifier used to identify vendor
> diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
> index c3d0e3d..3832190 100644
> --- a/src/network/networkd-dhcp4.c
> +++ b/src/network/networkd-dhcp4.c
> @@ -661,5 +661,21 @@ int dhcp4_configure(Link *link) {
>                          return r;
>          }
>
> +        switch (link->network->dhcp_client_identifier) {
> +        case DHCP_CLIENT_ID_DUID:
> +                /* Library defaults to this. */
> +                break;
> +        case DHCP_CLIENT_ID_MAC:
> +                r = sd_dhcp_client_set_client_id(link->dhcp_client,
> +                                                 ARPHRD_ETHER,
> +                                                 (const uint8_t *) &link->mac,
> +                                                 sizeof (link->mac));
> +                if (r < 0)
> +                        return r;
> +                break;
> +        default:
> +                assert_not_reached("Unknown client identifier type.");
> +        }
> +
>          return 0;
>  }
> diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
> index b0c23a7..93df83a 100644
> --- a/src/network/networkd-network-gperf.gperf
> +++ b/src/network/networkd-network-gperf.gperf
> @@ -58,6 +58,7 @@ Route.Destination,           config_parse_destination,           0,
>  Route.Source,                config_parse_destination,           0,                             0
>  Route.Metric,                config_parse_route_priority,        0,                             0
>  Route.Scope,                 config_parse_route_scope,           0,                             0
> +DHCP.ClientIdentifier,       config_parse_dhcp_client_identifier,0,                             offsetof(Network, dhcp_client_identifier)
>  DHCP.UseDNS,                 config_parse_bool,                  0,                             offsetof(Network, dhcp_dns)
>  DHCP.UseMTU,                 config_parse_bool,                  0,                             offsetof(Network, dhcp_mtu)
>  DHCP.UseHostname,            config_parse_bool,                  0,                             offsetof(Network, dhcp_hostname)
> diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
> index 0ba0c75..f7f6eaf 100644
> --- a/src/network/networkd-network.c
> +++ b/src/network/networkd-network.c
> @@ -103,6 +103,7 @@ static int network_load_one(Manager *manager, const char *filename) {
>          network->dhcp_routes = true;
>          network->dhcp_sendhost = true;
>          network->dhcp_route_metric = DHCP_ROUTE_METRIC;
> +        network->dhcp_client_identifier = DHCP_CLIENT_ID_DUID;
>
>          network->llmnr = LLMNR_SUPPORT_YES;
>
> @@ -600,6 +601,14 @@ int config_parse_dhcp(
>          return 0;
>  }
>
> +static const char* const dhcp_client_identifier_table[_DHCP_CLIENT_ID_MAX] = {
> +        [DHCP_CLIENT_ID_MAC] = "mac",
> +        [DHCP_CLIENT_ID_DUID] = "duid"
> +};
> +
> +DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_client_identifier, DCHPClientIdentifier);
> +DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_client_identifier, dhcp_client_identifier, DCHPClientIdentifier, "Failed to parse client identifier type");
> +
>  static const char* const llmnr_support_table[_LLMNR_SUPPORT_MAX] = {
>          [LLMNR_SUPPORT_NO] = "no",
>          [LLMNR_SUPPORT_YES] = "yes",
> diff --git a/src/network/networkd.h b/src/network/networkd.h
> index e75746f..8bdc2be 100644
> --- a/src/network/networkd.h
> +++ b/src/network/networkd.h
> @@ -83,6 +83,13 @@ typedef enum LinkOperationalState {
>          _LINK_OPERSTATE_INVALID = -1
>  } LinkOperationalState;
>
> +typedef enum DCHPClientIdentifier {
> +        DHCP_CLIENT_ID_MAC,
> +        DHCP_CLIENT_ID_DUID,
> +        _DHCP_CLIENT_ID_MAX,
> +        _DHCP_CLIENT_ID_INVALID = -1,
> +} DCHPClientIdentifier;
> +
>  struct FdbEntry {
>          Network *network;
>          unsigned section;
> @@ -115,6 +122,7 @@ struct Network {
>          NetDev *bond;
>          Hashmap *stacked_netdevs;
>          AddressFamilyBoolean dhcp;
> +        DCHPClientIdentifier dhcp_client_identifier;
>          char *dhcp_vendor_class_identifier;
>          bool dhcp_dns;
>          bool dhcp_ntp;
> @@ -403,6 +411,9 @@ int config_parse_fdb_vlan_id(const char *unit, const char *filename, unsigned li
>  int config_parse_dhcp(const char *unit, const char *filename, unsigned line,
>                        const char *section, unsigned section_line, const char *lvalue,
>                        int ltype, const char *rvalue, void *data, void *userdata);
> +int config_parse_dhcp_client_identifier(const char *unit, const char *filename, unsigned line,
> +                                        const char *section, unsigned section_line, const char *lvalue,
> +                                        int ltype, const char *rvalue, void *data, void *userdata);
>
>  /* IPv4LL support (legacy) */
>
> --
> 2.3.1
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list