Skip to content

Commit edb85f0

Browse files
Susant Sahaniteg
authored andcommitted
networkd: dhcp add vendor class indentifier option 60
Vendor Class Identifier be used by DHCP clients to identify their vendor type and configuration. When using this option, vendors can define their own specific identifier values, such as to convey a particular hardware or operating system configuration or other identifying information. Vendor-specified DHCP options—features that let administrators assign separate options to clients with similar configuration requirements. For example, if DHCP-aware clients for example we want to separate different gateway and option for different set of people (dev/test/hr/finance) in a org or devices for example web/database servers or let's say in a embedded device etc and require a different default gateway or DNS server than the rest of clients.
1 parent 5d8e593 commit edb85f0

File tree

8 files changed

+47
-0
lines changed

8 files changed

+47
-0
lines changed

man/systemd.network.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,12 @@
446446
if, say, the root filesystem relies on this connection. Defaults to false.</para>
447447
</listitem>
448448
</varlistentry>
449+
<varlistentry>
450+
<term><varname>VendorClassIdentifier=</varname></term>
451+
<listitem>
452+
<para>The vendor class identifier used to identify vendor type and configuration.</para>
453+
</listitem>
454+
</varlistentry>
449455
</variablelist>
450456

451457
</refsect1>

src/libsystemd-network/dhcp-protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ enum {
131131
DHCP_OPTION_MAXIMUM_MESSAGE_SIZE = 57,
132132
DHCP_OPTION_RENEWAL_T1_TIME = 58,
133133
DHCP_OPTION_REBINDING_T2_TIME = 59,
134+
DHCP_OPTION_VENDOR_CLASS_IDENTIFIER = 60,
134135
DHCP_OPTION_CLIENT_IDENTIFIER = 61,
135136
DHCP_OPTION_CLASSLESS_STATIC_ROUTE = 121,
136137
DHCP_OPTION_END = 255,

src/libsystemd-network/sd-dhcp-client.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct sd_dhcp_client {
5757
struct ether_addr mac_addr;
5858
} _packed_ client_id;
5959
char *hostname;
60+
char *vendor_class_identifier;
6061
uint32_t xid;
6162
usec_t start_time;
6263
uint16_t secs;
@@ -200,6 +201,23 @@ int sd_dhcp_client_set_hostname(sd_dhcp_client *client,
200201
return 0;
201202
}
202203

204+
int sd_dhcp_client_set_vendor_class_identifier(sd_dhcp_client *client,
205+
const char *vci) {
206+
char *new_vci = NULL;
207+
208+
assert_return(client, -EINVAL);
209+
210+
new_vci = strdup(vci);
211+
if (!new_vci)
212+
return -ENOMEM;
213+
214+
free(client->vendor_class_identifier);
215+
216+
client->vendor_class_identifier = new_vci;
217+
218+
return 0;
219+
}
220+
203221
int sd_dhcp_client_get_lease(sd_dhcp_client *client, sd_dhcp_lease **ret) {
204222
assert_return(client, -EINVAL);
205223
assert_return(ret, -EINVAL);
@@ -419,6 +437,15 @@ static int client_send_discover(sd_dhcp_client *client) {
419437
return r;
420438
}
421439

440+
if (client->vendor_class_identifier) {
441+
r = dhcp_option_append(&discover->dhcp, optlen, &optoffset, 0,
442+
DHCP_OPTION_VENDOR_CLASS_IDENTIFIER,
443+
strlen(client->vendor_class_identifier),
444+
client->vendor_class_identifier);
445+
if (r < 0)
446+
return r;
447+
}
448+
422449
r = dhcp_option_append(&discover->dhcp, optlen, &optoffset, 0,
423450
DHCP_OPTION_END, 0, NULL);
424451
if (r < 0)
@@ -1406,6 +1433,7 @@ sd_dhcp_client *sd_dhcp_client_unref(sd_dhcp_client *client) {
14061433

14071434
free(client->req_opts);
14081435
free(client->hostname);
1436+
free(client->vendor_class_identifier);
14091437
free(client);
14101438
}
14111439

src/network/networkd-link.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,13 @@ static int link_configure(Link *link) {
20232023
return r;
20242024
}
20252025
}
2026+
2027+
if (link->network->dhcp_vendor_class_identifier) {
2028+
r = sd_dhcp_client_set_vendor_class_identifier(link->dhcp_client,
2029+
link->network->dhcp_vendor_class_identifier);
2030+
if (r < 0)
2031+
return r;
2032+
}
20262033
}
20272034

20282035
if (link->network->dhcp_server) {

src/network/networkd-network-gperf.gperf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ DHCP.UseDomainName, config_parse_bool, 0,
5151
DHCP.UseRoutes, config_parse_bool, 0, offsetof(Network, dhcp_routes)
5252
DHCP.SendHostname, config_parse_bool, 0, offsetof(Network, dhcp_sendhost)
5353
DHCP.CriticalConnection, config_parse_bool, 0, offsetof(Network, dhcp_critical)
54+
DHCP.VendorClassIdentifier, config_parse_string, 0, offsetof(Network, dhcp_vendor_class_identifier)
5455
/* backwards compatibility: do not add new entries to this section */
5556
DHCPv4.UseDNS, config_parse_bool, 0, offsetof(Network, dhcp_dns)
5657
DHCPv4.UseMTU, config_parse_bool, 0, offsetof(Network, dhcp_mtu)

src/network/networkd-network.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ void network_free(Network *network) {
166166
free(network->match_name);
167167

168168
free(network->description);
169+
free(network->dhcp_vendor_class_identifier);
169170

170171
while ((address = network->ntp)) {
171172
LIST_REMOVE(addresses, network->ntp, address);

src/network/networkd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ struct Network {
175175
char *match_driver;
176176
char *match_type;
177177
char *match_name;
178+
char *dhcp_vendor_class_identifier;
179+
178180
Condition *match_host;
179181
Condition *match_virt;
180182
Condition *match_kernel;

src/systemd/sd-dhcp-client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ int sd_dhcp_client_set_index(sd_dhcp_client *client, int interface_index);
5252
int sd_dhcp_client_set_mac(sd_dhcp_client *client,
5353
const struct ether_addr *addr);
5454
int sd_dhcp_client_set_hostname(sd_dhcp_client *client, const char *hostname);
55+
int sd_dhcp_client_set_vendor_class_identifier(sd_dhcp_client *client, const char *vci);
5556
int sd_dhcp_client_get_lease(sd_dhcp_client *client, sd_dhcp_lease **ret);
5657

5758
int sd_dhcp_client_stop(sd_dhcp_client *client);

0 commit comments

Comments
 (0)