Skip to content

Commit

Permalink
dhcp4: add option to set route pref-src to dhcp IP
Browse files Browse the repository at this point in the history
When enabled in SUSE ifcfg config files with DHCLIENT_ROUTE_SET_SRC=yes
or via <ipv4:dhcp><route-set-src>true</route-set-src></ipv4:dhcp> in xml
config, the DHCP IP address is set as the preferred source in dhcp routes.
  • Loading branch information
mtomaschewski committed Nov 2, 2021
1 parent 9ec360f commit 054f99e
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions client/compat.c
Expand Up @@ -2269,6 +2269,9 @@ __ni_compat_generate_dhcp4_addrconf(xml_node_t *ifnode, const ni_compat_netdev_t
xml_node_dict_set(dhcp, "route-priority",
ni_sprint_uint(compat->dhcp4.route_priority));

if (compat->dhcp4.route_set_src)
xml_node_dict_set(dhcp, "route-set-src",
ni_format_boolean(compat->dhcp4.route_set_src));

if (compat->dhcp4.start_delay)
xml_node_dict_set(dhcp, "start-delay",
Expand Down
2 changes: 2 additions & 0 deletions client/suse/compat-suse.c
Expand Up @@ -5422,6 +5422,8 @@ __ni_suse_addrconf_dhcp4_options(const ni_sysconfig_t *sc, ni_compat_netdev_t *c
}
if (ni_sysconfig_get_integer(sc, "DHCLIENT_ROUTE_PRIORITY", &uint))
compat->dhcp4.route_priority = uint;
if ((string = ni_sysconfig_get_value(sc, "DHCLIENT_ROUTE_SET_SRC")))
ni_parse_boolean(string, &compat->dhcp4.route_set_src);

if ((string = ni_sysconfig_get_value(sc, "DHCLIENT_MODIFY_SMB_CONF"))) {
if (ni_string_eq(string, "yes")) {
Expand Down
8 changes: 8 additions & 0 deletions client/suse/config/sysconfig.dhcp-wicked
Expand Up @@ -76,6 +76,14 @@ DHCLIENT_BROADCAST=""
#
DHCLIENT_CREATE_CID=""

## Type: list(,yes,no)
## Default: ""
#
# When set to yes, the DHCP IP address is set as the preferred source
# in dhcp routes.
#
DHCLIENT_ROUTE_SET_SRC=""

## Type: list(enabled,disabled,default,)
## Default: ""
#
Expand Down
1 change: 1 addition & 0 deletions client/wicked-client.h
Expand Up @@ -82,6 +82,7 @@ typedef struct ni_compat_netdev {
ni_tristate_t broadcast;

unsigned int route_priority;
ni_bool_t route_set_src;
unsigned int update;

ni_string_array_t request_options;
Expand Down
1 change: 1 addition & 0 deletions dhcp4/dbus-api.c
Expand Up @@ -480,6 +480,7 @@ static ni_dbus_property_t dhcp4_request_properties[] = {
DHCP4REQ_STRING_PROPERTY(hostname, hostname, RO),
DHCP4REQ_DICT_PROPERTY(fqdn, fqdn, RO),
DHCP4REQ_UINT_PROPERTY(route-priority, route_priority, RO),
DHCP4REQ_BOOL_PROPERTY(route-set-src, route_set_src, RO),

DHCP4REQ_STRING_ARRAY_PROPERTY(request-options, request_options, RO),

Expand Down
4 changes: 4 additions & 0 deletions man/ifcfg-dhcp.5.in
Expand Up @@ -71,6 +71,10 @@ one of them does it.
.BR DHCLIENT_ROUTE_PRIORITY
This option allows to set a metric/priority for DHCPv4 routes. Default is 0.
.TP
.BR DHCLIENT_ROUTE_SET_SRC\ { \fIno\fR* | yes }
When set to yes, the DHCP IP address is set as the preferred source
preferred source in dhcp routes.
.TP
.BR DHCLIENT_CLIENT_ID
Specifies a client identifier string. By default an id derived from the
hardware address of the network interface is sent as client identifier.
Expand Down
1 change: 1 addition & 0 deletions schema/addrconf.xml
Expand Up @@ -222,6 +222,7 @@
<qualify type="boolean"/>
</fqdn>
<route-priority type="uint32" />
<route-set-src type="boolean" />

<request-options class="array" element-type="string" element-name="option" />
</define>
Expand Down
1 change: 1 addition & 0 deletions src/dhcp4/device.c
Expand Up @@ -292,6 +292,7 @@ ni_dhcp4_acquire(ni_dhcp4_device_t *dev, const ni_dhcp4_request_t *info)
config->doflags = ni_dhcp4_do_bits(ni_config_dhcp4_find_device(dev->ifname), config->update);

config->route_priority = info->route_priority;
config->route_set_src = info->route_set_src;
config->recover_lease = info->recover_lease;
config->release_lease = info->release_lease;
config->broadcast = info->broadcast;
Expand Down
2 changes: 2 additions & 0 deletions src/dhcp4/dhcp4.h
Expand Up @@ -155,6 +155,7 @@ struct ni_dhcp4_request {
ni_dhcp_fqdn_t fqdn;
char * hostname;
unsigned int route_priority;
ni_bool_t route_set_src;

ni_string_array_t request_options;

Expand Down Expand Up @@ -198,6 +199,7 @@ struct ni_dhcp4_config {
ni_tristate_t broadcast;

unsigned int route_priority;
ni_bool_t route_set_src;

unsigned int max_lease_time;
ni_bool_t recover_lease;
Expand Down
4 changes: 4 additions & 0 deletions src/dhcp4/fsm.c
Expand Up @@ -897,6 +897,10 @@ ni_dhcp4_fsm_commit_lease(ni_dhcp4_device_t *dev, ni_addrconf_lease_t *lease)
continue;
rp->protocol = RTPROT_DHCP;
rp->priority = dev->config->route_priority;
if (dev->config->route_set_src) {
ni_sockaddr_set_ipv4(&rp->pref_src,
lease->dhcp4.address, 0);
}
}
}
}
Expand Down

0 comments on commit 054f99e

Please sign in to comment.