-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend KeepConfiguration= functionality #409
base: main
Are you sure you want to change the base?
Changes from all commits
e71e865
7a1914e
82442d8
8ae3b07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -374,11 +374,19 @@ Match devices by MAC when setting options like: `wakeonlan` or `*-offload`. | |
> (networkd backend only) Allow the specified interface to be configured even | ||
> if it has no carrier. | ||
|
||
- **critical** (bool) | ||
- **critical** (scalar) | ||
|
||
> Designate the connection as "critical to the system", meaning that special | ||
> care will be taken by to not release the assigned IP when the daemon is | ||
> restarted. (not recognized by NetworkManager) | ||
> This option sets the systemd KeepConfiguration option. | ||
> (not recognized by NetworkManager) | ||
> | ||
> When set to "static", static addresses and routes won't be dropped on | ||
> starting up process. | ||
> When set to "dhcp-on-stop", addresses and routes won't be dropped when | ||
> stopping the daemon. | ||
> When set to "dhcp", addresses and routes provided by a DHCP server will | ||
> never be dropped even if the DHCP lease expires, implies "dhcp-on-stop". | ||
> When set to "yes", "dhcp" and "static" is implied. | ||
Comment on lines
+382
to
+388
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Did you double-check if something similar to |
||
> Defaults to "no". | ||
|
||
- **dhcp-identifier** (scalar) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,14 @@ typedef enum { | |
NETPLAN_OPTIONAL_STATIC = 1<<4, | ||
} NetplanOptionalAddressFlag; | ||
|
||
typedef enum { | ||
NETPLAN_CRITICAL_FALSE, | ||
NETPLAN_CRITICAL_TRUE, | ||
NETPLAN_CRITICAL_STATIC, | ||
NETPLAN_CRITICAL_DHCP, | ||
NETPLAN_CRITICAL_DHCP_ON_STOP, | ||
} NetplanCriticalOption; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: we might just want to call that PS: please also add and use a Note: changing the |
||
|
||
/* Fields below are valid for dhcp4 and dhcp6 unless otherwise noted. */ | ||
typedef struct dhcp_overrides { | ||
gboolean use_dns; | ||
|
@@ -211,7 +219,7 @@ struct netplan_net_definition { | |
/* status options */ | ||
gboolean optional; | ||
NetplanOptionalAddressFlag optional_addresses; | ||
gboolean critical; | ||
NetplanCriticalOption critical; | ||
|
||
/* addresses */ | ||
gboolean dhcp4; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,7 +353,7 @@ write_bond_parameters(const NetplanNetDefinition* def, GString* s) | |
if (def->bond_params.selection_logic) | ||
g_string_append_printf(params, "\nAdSelect=%s", def->bond_params.selection_logic); | ||
if (def->bond_params.all_members_active) | ||
g_string_append_printf(params, "\nAllSlavesActive=%d", def->bond_params.all_members_active); /* wokeignore:rule=slave */ | ||
g_string_append_printf(params, "\nAllSlavesActive=%d", def->bond_params.all_members_active); /* wokeignore:rule=slave */ | ||
if (def->bond_params.arp_interval) { | ||
g_string_append(params, "\nARPIntervalSec="); | ||
if (interval_has_suffix(def->bond_params.arp_interval)) | ||
|
@@ -393,7 +393,7 @@ write_bond_parameters(const NetplanNetDefinition* def, GString* s) | |
g_string_append_printf(params, "\nGratuitousARP=%d", def->bond_params.gratuitous_arp); | ||
/* TODO: add unsolicited_na, not documented as supported by NM. */ | ||
if (def->bond_params.packets_per_member) | ||
g_string_append_printf(params, "\nPacketsPerSlave=%d", def->bond_params.packets_per_member); /* wokeignore:rule=slave */ | ||
g_string_append_printf(params, "\nPacketsPerSlave=%d", def->bond_params.packets_per_member); /* wokeignore:rule=slave */ | ||
if (def->bond_params.primary_reselect_policy) | ||
g_string_append_printf(params, "\nPrimaryReselectPolicy=%s", def->bond_params.primary_reselect_policy); | ||
if (def->bond_params.resend_igmp) | ||
|
@@ -921,8 +921,21 @@ netplan_netdef_write_network_file( | |
g_string_append(network, "\n[DHCP]\n"); | ||
} | ||
|
||
if (def->critical) | ||
g_string_append_printf(network, "CriticalConnection=true\n"); | ||
switch (def->critical) { | ||
case NETPLAN_CRITICAL_TRUE: | ||
g_string_append(s, "KeepConnection=true\n"); | ||
break; | ||
case NETPLAN_CRITICAL_STATIC: | ||
g_string_append(s, "KeepConnection=static\n"); | ||
break; | ||
case NETPLAN_CRITICAL_DHCP: | ||
g_string_append(s, "KeepConnection=dhcp\n"); | ||
break; | ||
case NETPLAN_CRITICAL_DHCP_ON_STOP: | ||
g_string_append(s, "KeepConnection=dhcp-on-stop\n"); | ||
break; | ||
default: g_assert_not_reached(); // LCOV_EXCL_LINE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of the reasons it's failing tests is because the case for the false option is missing here. See my comment below about the enum. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
} | ||
|
||
if (def->dhcp4 || def->dhcp6) { | ||
if (def->dhcp_identifier) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,7 +225,7 @@ reset_netdef(NetplanNetDefinition* netdef, NetplanDefType new_type, NetplanBacke | |
|
||
netdef->optional = FALSE; | ||
netdef->optional_addresses = 0; | ||
netdef->critical = FALSE; | ||
netdef->critical = NETPLAN_CRITICAL_FALSE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably shouldn't initialize According to the documentation, KeepConfiguration Initializing it to false would imply setting it to false even when the default is something else. I suggest adding a new entry in the enum, something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for using |
||
|
||
netdef->dhcp4 = FALSE; | ||
netdef->dhcp6 = FALSE; | ||
|
@@ -594,7 +594,7 @@ _netplan_netdef_get_vlan_id(const NetplanNetDefinition* netdef) | |
return netdef->vlan_id; | ||
} | ||
|
||
gboolean | ||
NetplanCriticalOption | ||
_netplan_netdef_get_critical(const NetplanNetDefinition* netdef) | ||
{ | ||
g_assert(netdef); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,7 @@ _netplan_state_get_vf_count_for_def(const NetplanState* np_state, const NetplanN | |
NETPLAN_INTERNAL gboolean | ||
_netplan_netdef_get_sriov_vlan_filter(const NetplanNetDefinition* netdef); | ||
|
||
NETPLAN_INTERNAL gboolean | ||
NETPLAN_INTERNAL NetplanCriticalOption | ||
_netplan_netdef_get_critical(const NetplanNetDefinition* netdef); | ||
Comment on lines
+105
to
106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: This is |
||
|
||
NETPLAN_INTERNAL gboolean | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd need to keep this as "(bool or scalar)", making use of
handle_generic_bool()
internally inparse.c
, checking for the error condition in theGError** error
parameter. Then falling back to "scalar" (and validating the input to be one of the accepted strings) if a bool cannot be parsed.