Skip to content

Commit f66728c

Browse files
committed
Migrate CriticalConnection (deprecated) to KeepConfiguration
See: https://bugs.launchpad.net/netplan/+bug/1896799
1 parent a7e4be0 commit f66728c

File tree

13 files changed

+42
-39
lines changed

13 files changed

+42
-39
lines changed

abi-compat/jammy_0.107.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +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'/>
18+
<elf-symbol name='_netplan_netdef_get_keep_configuration' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
1919
<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'/>
2020
<elf-symbol name='_netplan_netdef_get_embedded_switch_mode' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
2121
<elf-symbol name='_netplan_netdef_get_optional' 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='critical' type-id='type-id-42' visibility='default' filepath='../src/abi.h' line='204' column='1'/>
424+
<var-decl name='keep_configuration' 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,9 +4191,9 @@
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'>
4194+
<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'>
41954195
<parameter type-id='type-id-181' name='netdef' filepath='../src/types.c' line='597' column='1'/>
4196-
<return type-id='type-id-42'/>
4196+
<return type-id='type-id-43'/>
41974197
</function-decl>
41984198
<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'>
41994199
<parameter type-id='type-id-181' name='netdef' filepath='../src/types.c' line='604' column='1'/>

doc/netplan-yaml.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,14 @@ 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-
- **critical** (bool)
378-
379-
> Designate the connection as "critical to the system", meaning that special
380-
> care will be taken by to not release the assigned IP when the daemon is
381-
> restarted. (not recognized by NetworkManager)
377+
- **keep-configuration** (scalar)
378+
379+
> When set to "static", static addresses and routes won't be dropped on starting up process.
380+
> When set to "dhcp-on-stop", drop 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"
382+
> When set to "yes", "dhcp" and "static" is implied.
383+
> Defaults to "no".
384+
> (not recognized by NetworkManager)
382385

383386
- **dhcp-identifier** (scalar)
384387

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 non-critical network interfaces
236+
# rename network interfaces without keep_configuration set
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 non-critical interfaces which can be safely updated.
359+
Only applies to interfaces not having keep_configuration set, 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.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'
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'
390390
.format(netdef.id, current_iface_name, newname))
391391
continue
392392

python-cffi/netplan/_build_cffi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
ssize_t _netplan_netdef_get_embedded_switch_mode(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buf_size);
113113
gboolean _netplan_netdef_get_sriov_vlan_filter(const NetplanNetDefinition* netdef);
114114
guint _netplan_netdef_get_vlan_id(const NetplanNetDefinition* netdef);
115-
gboolean _netplan_netdef_get_critical(const NetplanNetDefinition* netdef);
115+
char* _netplan_netdef_get_keep_configuration(const NetplanNetDefinition* netdef);
116116
gboolean _netplan_netdef_is_trivial_compound_itf(const NetplanNetDefinition* netdef);
117117
int _netplan_state_get_vf_count_for_def(
118118
const NetplanState* np_state, const NetplanNetDefinition* netdef, NetplanError** error);

python-cffi/netplan/netdef.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def set_name(self) -> str:
7575
return _string_realloc_call_no_error(lambda b: lib.netplan_netdef_get_set_name(self._ptr, b, len(b)))
7676

7777
@property
78-
def critical(self) -> bool:
79-
return bool(lib._netplan_netdef_get_critical(self._ptr))
78+
def keep_configuration(self) -> str:
79+
return _string_realloc_call_no_error(lambda b: lib.netplan_netdef_get_keep_configuration(self._ptr, b, len(b)))
8080

8181
@property
8282
def links(self) -> dict:

src/abi.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ struct netplan_net_definition {
211211
/* status options */
212212
gboolean optional;
213213
NetplanOptionalAddressFlag optional_addresses;
214-
gboolean critical;
214+
char* keep_configuration;
215215

216216
/* addresses */
217217
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->critical)
746-
YAML_NONNULL_STRING_PLAIN(event, emitter, "critical", "true");
745+
if (def->keep_configuration)
746+
YAML_STRING_PLAIN(def, event, emitter, "keep-configuration", def->keep_configuration);
747747

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

src/networkd.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ write_bond_parameters(const NetplanNetDefinition* def, GString* s)
353353
if (def->bond_params.selection_logic)
354354
g_string_append_printf(params, "\nAdSelect=%s", def->bond_params.selection_logic);
355355
if (def->bond_params.all_members_active)
356-
g_string_append_printf(params, "\nAllSlavesActive=%d", def->bond_params.all_members_active); /* wokeignore:rule=slave */
356+
g_string_append_printf(params, "\nAllSlavesActive=%d", def->bond_params.all_members_active); /* wokeignore:rule=slave */
357357
if (def->bond_params.arp_interval) {
358358
g_string_append(params, "\nARPIntervalSec=");
359359
if (interval_has_suffix(def->bond_params.arp_interval))
@@ -393,7 +393,7 @@ write_bond_parameters(const NetplanNetDefinition* def, GString* s)
393393
g_string_append_printf(params, "\nGratuitousARP=%d", def->bond_params.gratuitous_arp);
394394
/* TODO: add unsolicited_na, not documented as supported by NM. */
395395
if (def->bond_params.packets_per_member)
396-
g_string_append_printf(params, "\nPacketsPerSlave=%d", def->bond_params.packets_per_member); /* wokeignore:rule=slave */
396+
g_string_append_printf(params, "\nPacketsPerSlave=%d", def->bond_params.packets_per_member); /* wokeignore:rule=slave */
397397
if (def->bond_params.primary_reselect_policy)
398398
g_string_append_printf(params, "\nPrimaryReselectPolicy=%s", def->bond_params.primary_reselect_policy);
399399
if (def->bond_params.resend_igmp)
@@ -916,13 +916,13 @@ netplan_netdef_write_network_file(
916916
}
917917
}
918918

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

924-
if (def->critical)
925-
g_string_append_printf(network, "CriticalConnection=true\n");
924+
if (def->keep_configuration)
925+
g_string_append_printf(network, "KeepConfiguration=%s\n", def->keep_configuration);
926926

927927
if (def->dhcp4 || def->dhcp6) {
928928
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-
{"critical", YAML_SCALAR_NODE, {.generic=handle_netdef_bool}, netdef_offset(critical)}, \
2788+
{"keep-configuration", YAML_SCALAR_NODE, {.generic=handle_netdef_bool}, netdef_offset(keep_configuration)}, \
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

+4-4
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-
netdef->critical = FALSE;
228+
FREE_AND_NULLIFY(netdef->keep_configuration);
229229

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

597-
gboolean
598-
_netplan_netdef_get_critical(const NetplanNetDefinition* netdef)
597+
char *
598+
_netplan_netdef_get_keep_configuration(const NetplanNetDefinition* netdef)
599599
{
600600
g_assert(netdef);
601-
return netdef->critical;
601+
return netdef->keep_configuration;
602602
}
603603

604604
gboolean

src/util-internal.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ _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 gboolean
106-
_netplan_netdef_get_critical(const NetplanNetDefinition* netdef);
105+
NETPLAN_INTERNAL char *
106+
_netplan_netdef_get_keep_configuration(const NetplanNetDefinition* netdef);
107107

108108
NETPLAN_INTERNAL gboolean
109109
_netplan_netdef_get_optional(const NetplanNetDefinition* netdef);

tests/generator/test_common.py

+3-3
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_critical_true(self):
470+
def test_dhcp_keep_configuration_true(self):
471471
self.generate('''network:
472472
version: 2
473473
ethernets:
474474
engreen:
475-
critical: yes
475+
keep-configuration: yes
476476
''')
477477

478478
self.assert_networkd({'engreen.network': '''[Match]
@@ -482,7 +482,7 @@ def test_dhcp_critical_true(self):
482482
LinkLocalAddressing=ipv6
483483
484484
[DHCP]
485-
CriticalConnection=true
485+
KeepConfiguration=true
486486
'''})
487487

488488
def test_dhcp_identifier_mac(self):

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_critical(self):
584+
def test_keep_configuration(self):
585585
state = state_from_yaml(self.confdir, '''network:
586586
ethernets:
587587
eth0:
588-
critical: true
588+
keep-configuration: true
589589
eth1: {}''')
590590

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

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

0 commit comments

Comments
 (0)