-
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 1 commit
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 |
---|---|---|
|
@@ -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; | ||
char* keep_configuration; | ||
NetplanCriticalOption critical; | ||
|
||
/* addresses */ | ||
gboolean dhcp4; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -916,13 +916,26 @@ netplan_netdef_write_network_file( | |
} | ||
} | ||
|
||
if (def->dhcp4 || def->dhcp6 || def->keep_configuration) { | ||
if (def->dhcp4 || def->dhcp6 || def->critical) { | ||
/* NetworkManager compatible route metrics */ | ||
g_string_append(network, "\n[DHCP]\n"); | ||
} | ||
|
||
if (def->keep_configuration) | ||
g_string_append_printf(network, "KeepConfiguration=%s\n", def->keep_configuration); | ||
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 |
---|---|---|
|
@@ -2785,7 +2785,7 @@ static const mapping_entry_handler dhcp6_overrides_handlers[] = { | |
{"accept-ra", YAML_SCALAR_NODE, {.generic=handle_accept_ra}, netdef_offset(accept_ra)}, \ | ||
{"activation-mode", YAML_SCALAR_NODE, {.generic=handle_activation_mode}, netdef_offset(activation_mode)}, \ | ||
{"addresses", YAML_SEQUENCE_NODE, {.generic=handle_addresses}, NULL}, \ | ||
{"keep-configuration", YAML_SCALAR_NODE, {.generic=handle_netdef_bool}, netdef_offset(keep_configuration)}, \ | ||
{"critical", YAML_SCALAR_NODE, {.generic=handle_netdef_bool}, netdef_offset(critical)}, \ | ||
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. As the new critical option is not a boolean anymore, we'll need to update the parser. You'll need to create a new function that checks what option the user set and store one of the enum variants in the variable. You can base your implementation on the And as we want to still accept the boolean values so we'll not break existing configurations out there, we'll need to accept all the boolean values accepted by netplan. See https://github.com/chr4/netplan/blob/feat/keep-configuration/src/parse.c#L402 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. It looks like any changes to |
||
{"ignore-carrier", YAML_SCALAR_NODE, {.generic=handle_netdef_bool}, netdef_offset(ignore_carrier)}, \ | ||
{"dhcp4", YAML_SCALAR_NODE, {.generic=handle_netdef_bool}, netdef_offset(dhcp4)}, \ | ||
{"dhcp6", YAML_SCALAR_NODE, {.generic=handle_netdef_bool}, netdef_offset(dhcp6)}, \ | ||
|
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; | ||
FREE_AND_NULLIFY(netdef->keep_configuration); | ||
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,6 +594,13 @@ _netplan_netdef_get_vlan_id(const NetplanNetDefinition* netdef) | |
return netdef->vlan_id; | ||
} | ||
|
||
NetplanCriticalOption | ||
_netplan_netdef_get_critical(const NetplanNetDefinition* netdef) | ||
{ | ||
g_assert(netdef); | ||
return netdef->critical; | ||
} | ||
|
||
gboolean | ||
_netplan_netdef_get_optional(const NetplanNetDefinition* netdef) | ||
{ | ||
|
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.