Skip to content

Commit 7c237c6

Browse files
committed
[squashme] revamp keep-configuration option backwards compatible
1 parent 7a1914e commit 7c237c6

File tree

12 files changed

+63
-37
lines changed

12 files changed

+63
-37
lines changed

abi-compat/jammy_0.107.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<elf-symbol name='_netplan_iter_defs_per_devtype_next' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
1616
<elf-symbol name='_netplan_nameserver_iter_free' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
1717
<elf-symbol name='_netplan_nameserver_iter_next' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
18+
<elf-symbol name='_netplan_netdef_get_critical' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
1819
<elf-symbol name='_netplan_netdef_get_delay_vf_rebind' type='func-type' binding='global-binding' visibility='default-visibility' alias='netplan_netdef_get_delay_virtual_functions_rebind' is-defined='yes'/>
1920
<elf-symbol name='_netplan_netdef_get_embedded_switch_mode' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
2021
<elf-symbol name='_netplan_netdef_get_optional' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
@@ -58,7 +59,6 @@
5859
<elf-symbol name='netplan_get_global_backend' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
5960
<elf-symbol name='netplan_get_id_from_nm_filename' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
6061
<elf-symbol name='netplan_get_id_from_nm_filepath' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
61-
<elf-symbol name='netplan_netdef_get_keep_configuration' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
6262
<elf-symbol name='netplan_netdef_get_backend' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
6363
<elf-symbol name='netplan_netdef_get_bond_link' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
6464
<elf-symbol name='netplan_netdef_get_bridge_link' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
@@ -421,7 +421,7 @@
421421
<var-decl name='optional_addresses' type-id='type-id-39' visibility='default' filepath='../src/abi.h' line='203' column='1'/>
422422
</data-member>
423423
<data-member access='public' layout-offset-in-bits='320'>
424-
<var-decl name='keep_configuration' type-id='type-id-42' visibility='default' filepath='../src/abi.h' line='204' column='1'/>
424+
<var-decl name='critical' type-id='type-id-42' visibility='default' filepath='../src/abi.h' line='204' column='1'/>
425425
</data-member>
426426
<data-member access='public' layout-offset-in-bits='352'>
427427
<var-decl name='dhcp4' type-id='type-id-42' visibility='default' filepath='../src/abi.h' line='207' column='1'/>
@@ -4191,6 +4191,10 @@
41914191
<parameter type-id='type-id-181' name='netdef' filepath='../src/types.c' line='590' column='1'/>
41924192
<return type-id='type-id-44'/>
41934193
</function-decl>
4194+
<function-decl name='_netplan_netdef_get_critical' mangled-name='_netplan_netdef_get_critical' filepath='../src/types.c' line='597' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='_netplan_netdef_get_critical'>
4195+
<parameter type-id='type-id-181' name='netdef' filepath='../src/types.c' line='597' column='1'/>
4196+
<return type-id='type-id-42'/>
4197+
</function-decl>
41944198
<function-decl name='_netplan_netdef_get_optional' mangled-name='_netplan_netdef_get_optional' filepath='../src/types.c' line='604' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='_netplan_netdef_get_optional'>
41954199
<parameter type-id='type-id-181' name='netdef' filepath='../src/types.c' line='604' column='1'/>
41964200
<return type-id='type-id-42'/>
@@ -4369,10 +4373,6 @@
43694373
<parameter type-id='type-id-106' name='rootdir' filepath='../src/util.c' line='590' column='1'/>
43704374
<return type-id='type-id-42'/>
43714375
</function-decl>
4372-
<function-decl name='netplan_netdef_get_keep_configuration' mangled-name='netplan_netdef_get_keep_configuration' filepath='../src/types.c' line='597' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='netplan_netdef_get_keep_configuration'>
4373-
<parameter type-id='type-id-181' name='netdef' filepath='../src/types.c' line='597' column='1'/>
4374-
<return type-id='type-id-43'/>
4375-
</function-decl>
43764376
<function-decl name='netplan_netdef_get_output_filename' mangled-name='netplan_netdef_get_output_filename' filepath='../src/util.c' line='645' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='netplan_netdef_get_output_filename'>
43774377
<parameter type-id='type-id-181' name='netdef' filepath='../src/util.c' line='645' column='1'/>
43784378
<parameter type-id='type-id-106' name='ssid' filepath='../src/util.c' line='645' column='1'/>

doc/netplan-yaml.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,19 @@ Match devices by MAC when setting options like: `wakeonlan` or `*-offload`.
374374
> (networkd backend only) Allow the specified interface to be configured even
375375
> if it has no carrier.
376376

377-
- **keep-configuration** (scalar)
377+
- **critical** (scalar)
378378

379-
> When set to "static", static addresses and routes won't be dropped on starting up process.
380-
> When set to "dhcp-on-stop", addresses and routes won't be dropped when stopping the daemon.
381-
> 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"
379+
> This option sets the systemd KeepConfiguration option.
380+
> (not recognized by NetworkManager)
381+
>
382+
> When set to "static", static addresses and routes won't be dropped on
383+
> starting up process.
384+
> When set to "dhcp-on-stop", addresses and routes won't be dropped when
385+
> stopping the daemon.
386+
> When set to "dhcp", addresses and routes provided by a DHCP server will
387+
> never be dropped even if the DHCP lease expires, implies "dhcp-on-stop".
382388
> When set to "yes", "dhcp" and "static" is implied.
383389
> Defaults to "no".
384-
> (not recognized by NetworkManager)
385390

386391
- **dhcp-identifier** (scalar)
387392

netplan_cli/cli/commands/apply.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def command_apply(self, run_generate=True, sync=False, exit_on_error=True, state
233233
devices_after_udev = netifaces.interfaces()
234234
# apply some more changes manually
235235
for iface, settings in changes.items():
236-
# rename network interfaces without keep_configuration set
236+
# rename non-critical network interfaces
237237
new_name = settings.get('name')
238238
if new_name:
239239
if len(new_name) >= IF_NAMESIZE:
@@ -356,7 +356,7 @@ def clear_virtual_links(prev_links, curr_links, devices=[]):
356356
def process_link_changes(interfaces, config_manager: ConfigManager): # pragma: nocover (covered in autopkgtest)
357357
"""
358358
Go through the pending changes and pick what needs special handling.
359-
Only applies to interfaces not having keep_configuration set, which can be safely updated.
359+
Only applies to non-critical interfaces which can be safely updated.
360360
"""
361361

362362
changes = {}
@@ -384,9 +384,9 @@ def process_link_changes(interfaces, config_manager: ConfigManager): # pragma:
384384
# Skip interface if it already has the correct name
385385
logging.debug('Skipping correctly named interface: {}'.format(newname))
386386
continue
387-
if netdef.keep_configuration:
388-
# Skip interfaces with keep_configuration set, as we should not take them down in order to rename
389-
logging.warning('Cannot rename {} ({} -> {}) at runtime (needs reboot), due to keep_configuration being set'
387+
if netdef.critical:
388+
# Skip interfaces defined as critical, as we should not take them down in order to rename
389+
logging.warning('Cannot rename {} ({} -> {}) at runtime (needs reboot), due to being critical'
390390
.format(netdef.id, current_iface_name, newname))
391391
continue
392392

src/abi.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ typedef enum {
3232
NETPLAN_OPTIONAL_STATIC = 1<<4,
3333
} NetplanOptionalAddressFlag;
3434

35+
typedef enum {
36+
NETPLAN_CRITICAL_TRUE,
37+
NETPLAN_CRITICAL_FALSE,
38+
NETPLAN_CRITICAL_STATIC,
39+
NETPLAN_CRITICAL_DHCP,
40+
NETPLAN_CRITICAL_DHCP_ON_STOP,
41+
} NetplanCriticalOption;
42+
3543
/* Fields below are valid for dhcp4 and dhcp6 unless otherwise noted. */
3644
typedef struct dhcp_overrides {
3745
gboolean use_dns;
@@ -211,7 +219,7 @@ struct netplan_net_definition {
211219
/* status options */
212220
gboolean optional;
213221
NetplanOptionalAddressFlag optional_addresses;
214-
char* keep_configuration;
222+
NetplanCriticalOption critical;
215223

216224
/* addresses */
217225
gboolean dhcp4;

src/netplan.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ _serialize_yaml(
742742

743743
if (def->optional)
744744
YAML_NONNULL_STRING_PLAIN(event, emitter, "optional", "true");
745-
if (def->keep_configuration)
746-
YAML_STRING_PLAIN(def, event, emitter, "keep-configuration", def->keep_configuration);
745+
if (def->critical)
746+
YAML_STRING_PLAIN(def, event, emitter, "critical", def->critical);
747747

748748
if (def->ignore_carrier)
749749
YAML_NONNULL_STRING_PLAIN(event, emitter, "ignore-carrier", "true");

src/networkd.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -916,13 +916,23 @@ netplan_netdef_write_network_file(
916916
}
917917
}
918918

919-
if (def->dhcp4 || def->dhcp6 || def->keep_configuration) {
919+
if (def->dhcp4 || def->dhcp6 || def->critical) {
920920
/* NetworkManager compatible route metrics */
921921
g_string_append(network, "\n[DHCP]\n");
922922
}
923923

924-
if (def->keep_configuration)
925-
g_string_append_printf(network, "KeepConfiguration=%s\n", def->keep_configuration);
924+
if (def->critical) {
925+
const char *s;
926+
switch def->critical {
927+
case NETPLAN_CRITICAL_TRUE: s = "true";
928+
case NETPLAN_CRITICAL_STATIC: s = "static";
929+
case NETPLAN_CRITICAL_DHCP: s = "dhcp";
930+
case NETPLAN_CRITICAL_DHCP_ON_STOP: "dhcp-on-stop";
931+
default: s = "no"
932+
}
933+
934+
g_string_append_printf(network, "KeepConfiguration=%s\n", s);
935+
}
926936

927937
if (def->dhcp4 || def->dhcp6) {
928938
if (def->dhcp_identifier)

src/parse.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2785,7 +2785,7 @@ static const mapping_entry_handler dhcp6_overrides_handlers[] = {
27852785
{"accept-ra", YAML_SCALAR_NODE, {.generic=handle_accept_ra}, netdef_offset(accept_ra)}, \
27862786
{"activation-mode", YAML_SCALAR_NODE, {.generic=handle_activation_mode}, netdef_offset(activation_mode)}, \
27872787
{"addresses", YAML_SEQUENCE_NODE, {.generic=handle_addresses}, NULL}, \
2788-
{"keep-configuration", YAML_SCALAR_NODE, {.generic=handle_netdef_bool}, netdef_offset(keep_configuration)}, \
2788+
{"critical", YAML_SCALAR_NODE, {.generic=handle_netdef_bool}, netdef_offset(critical)}, \
27892789
{"ignore-carrier", YAML_SCALAR_NODE, {.generic=handle_netdef_bool}, netdef_offset(ignore_carrier)}, \
27902790
{"dhcp4", YAML_SCALAR_NODE, {.generic=handle_netdef_bool}, netdef_offset(dhcp4)}, \
27912791
{"dhcp6", YAML_SCALAR_NODE, {.generic=handle_netdef_bool}, netdef_offset(dhcp6)}, \

src/types.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ reset_netdef(NetplanNetDefinition* netdef, NetplanDefType new_type, NetplanBacke
225225

226226
netdef->optional = FALSE;
227227
netdef->optional_addresses = 0;
228-
FREE_AND_NULLIFY(netdef->keep_configuration);
228+
FREE_AND_NULLIFY(netdef->critical);
229229

230230
netdef->dhcp4 = FALSE;
231231
netdef->dhcp6 = FALSE;
@@ -594,6 +594,13 @@ _netplan_netdef_get_vlan_id(const NetplanNetDefinition* netdef)
594594
return netdef->vlan_id;
595595
}
596596

597+
NetplanCriticalOption
598+
_netplan_netdef_get_critical(const NetplanNetDefinition* netdef)
599+
{
600+
g_assert(netdef);
601+
return netdef->critical;
602+
}
603+
597604
gboolean
598605
_netplan_netdef_get_optional(const NetplanNetDefinition* netdef)
599606
{

src/util-internal.h

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ _netplan_state_get_vf_count_for_def(const NetplanState* np_state, const NetplanN
102102
NETPLAN_INTERNAL gboolean
103103
_netplan_netdef_get_sriov_vlan_filter(const NetplanNetDefinition* netdef);
104104

105+
NETPLAN_INTERNAL NetplanCriticalOption
106+
_netplan_netdef_get_critical(const NetplanNetDefinition* netdef);
107+
105108
NETPLAN_INTERNAL gboolean
106109
_netplan_netdef_get_optional(const NetplanNetDefinition* netdef);
107110

src/util.c

-7
Original file line numberDiff line numberDiff line change
@@ -1018,13 +1018,6 @@ netplan_netdef_match_interface(const NetplanNetDefinition* netdef, const char* n
10181018
return TRUE;
10191019
}
10201020

1021-
char *
1022-
netplan_netdef_get_keep_configuration(const NetplanNetDefinition* netdef)
1023-
{
1024-
g_assert(netdef);
1025-
return netdef->keep_configuration;
1026-
}
1027-
10281021
ssize_t
10291022
netplan_netdef_get_set_name(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buf_size)
10301023
{

tests/generator/test_common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,12 @@ def test_bond_arp_ip_targets_multi_pass(self):
467467
Bond=bond0
468468
'''})
469469

470-
def test_dhcp_keep_configuration_true(self):
470+
def test_dhcp_critical_true(self):
471471
self.generate('''network:
472472
version: 2
473473
ethernets:
474474
engreen:
475-
keep-configuration: yes
475+
critical: yes
476476
''')
477477

478478
self.assert_networkd({'engreen.network': '''[Match]

tests/test_libnetplan.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -581,15 +581,15 @@ def test_backend(self):
581581
self.assertEqual(state['eth0'].backend, 'networkd')
582582
self.assertEqual(state['eth1'].backend, 'NetworkManager')
583583

584-
def test_keep_configuration(self):
584+
def test_critical(self):
585585
state = state_from_yaml(self.confdir, '''network:
586586
ethernets:
587587
eth0:
588-
keep-configuration: true
588+
critical: true
589589
eth1: {}''')
590590

591-
self.assertTrue(state['eth0'].keep_configuration)
592-
self.assertFalse(state['eth1'].keep_configuration)
591+
self.assertTrue(state['eth0'].critical)
592+
self.assertFalse(state['eth1'].critical)
593593

594594
def test_eq(self):
595595
state = state_from_yaml(self.confdir, '''network:

0 commit comments

Comments
 (0)