WIP: config-data: add on-add-and-activate= to [connection*]

This marks the [connection*] section as taking effect on connection
being added with AddAndActivate as opposed to impacting the existing
connections.

  [connection.wifi]
  match-device=type:wifi
  on-add-and-activate=yes
  802-11-wireless.assigned-mac-address=stable

TODO: document, figure out if this is a good idea, make it suck less if
possible
This commit is contained in:
Lubomir Rintel 2023-03-14 12:48:34 +01:00
parent e685c5ebb6
commit 8425edeb00
2 changed files with 18 additions and 3 deletions

View file

@ -19,6 +19,7 @@
typedef struct {
char *group_name;
gboolean stop_match;
gboolean on_add_and_activate;
struct {
/* have a separate boolean field @has, because a @spec with
* value %NULL does not necessarily mean, that the property
@ -1493,6 +1494,7 @@ _match_section_infos_foreach(const MatchSectionInfo *match_section_infos,
NMDevice *device,
const NMPlatformLink *pllink,
const char *match_device_type,
gboolean on_add_and_activate,
gpointer (*match_section_cb)(const MatchSectionInfo *m,
GKeyFile *keyfile,
gpointer user_data),
@ -1504,6 +1506,9 @@ _match_section_infos_foreach(const MatchSectionInfo *match_section_infos,
if (!match_section_infos)
goto out;
if (match_section_infos->on_add_and_activate != on_add_and_activate)
goto out;
match_dhcp_plugin = nm_dhcp_manager_get_config(nm_dhcp_manager_get());
for (; match_section_infos->group_name; match_section_infos++) {
@ -1561,6 +1566,7 @@ _match_section_infos_lookup(const MatchSectionInfo *match_section_infos,
device,
pllink,
match_device_type,
FALSE,
_match_section_info_get_str,
(gpointer) property,
(gpointer *) out_value);
@ -1783,6 +1789,11 @@ _match_section_info_init(MatchSectionInfo *connection_info,
&connection_info->match_device.has);
connection_info->stop_match =
nm_config_keyfile_get_boolean(keyfile, group, NM_CONFIG_KEYFILE_KEY_STOP_MATCH, FALSE);
connection_info->on_add_and_activate =
nm_config_keyfile_get_boolean(keyfile,
group,
NM_CONFIG_KEYFILE_KEY_ON_ADD_AND_ACTIVATE,
FALSE);
if (is_device) {
connection_info->device.allowed_connections =
@ -1801,7 +1812,10 @@ _match_section_info_init(MatchSectionInfo *connection_info,
gs_free char *key = g_steal_pointer(&keys[i]);
char *value;
if (NM_IN_STRSET(key, NM_CONFIG_KEYFILE_KEY_STOP_MATCH, NM_CONFIG_KEYFILE_KEY_MATCH_DEVICE))
if (NM_IN_STRSET(key,
NM_CONFIG_KEYFILE_KEY_STOP_MATCH,
NM_CONFIG_KEYFILE_KEY_MATCH_DEVICE,
NM_CONFIG_KEYFILE_KEY_ON_ADD_AND_ACTIVATE))
continue;
if (j > 0 && nm_streq(vals[j - 1].name, key))

View file

@ -71,8 +71,9 @@
#define NM_CONFIG_KEYFILE_KEY_DEVICE_CARRIER_WAIT_TIMEOUT "carrier-wait-timeout"
#define NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_IWD_AUTOCONNECT "wifi.iwd.autoconnect"
#define NM_CONFIG_KEYFILE_KEY_MATCH_DEVICE "match-device"
#define NM_CONFIG_KEYFILE_KEY_STOP_MATCH "stop-match"
#define NM_CONFIG_KEYFILE_KEY_MATCH_DEVICE "match-device"
#define NM_CONFIG_KEYFILE_KEY_STOP_MATCH "stop-match"
#define NM_CONFIG_KEYFILE_KEY_ON_ADD_AND_ACTIVATE "on-add-and-activate"
#define NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS ".was" /* check-config-options skip */
#define NM_CONFIG_KEYFILE_KEY_CONFIG_ENABLE "enable" /* check-config-options skip */