mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-03 23:00:28 +01:00
nm-dispatcher: Handle the 'connectivity-state' parameter for 'Action'
Actually handle this new parameter in the nm-dispatcher process, setting the value of a new CONNECTIVITY_STATE environment variable accordingly. This patch also includes new tests to check the different cases. https://bugzilla.gnome.org/show_bug.cgi?id=768969
This commit is contained in:
parent
3359368f28
commit
570e8ee296
7 changed files with 74 additions and 0 deletions
|
|
@ -327,6 +327,7 @@ nm_dispatcher_utils_construct_envp (const char *action,
|
|||
GVariant *device_ip6_props,
|
||||
GVariant *device_dhcp4_props,
|
||||
GVariant *device_dhcp6_props,
|
||||
const char *connectivity_state,
|
||||
const char *vpn_ip_iface,
|
||||
GVariant *vpn_ip4_props,
|
||||
GVariant *vpn_ip6_props,
|
||||
|
|
@ -467,6 +468,12 @@ nm_dispatcher_utils_construct_envp (const char *action,
|
|||
*out_iface = g_strdup (iface);
|
||||
|
||||
done:
|
||||
/* The connectivity_state value will only be meaningful for 'connectivity-change' events
|
||||
* (otherwise it will be "UNKNOWN"), so we only set the environment variable in those cases.
|
||||
*/
|
||||
if (connectivity_state && strcmp(connectivity_state, "UNKNOWN"))
|
||||
items = g_slist_prepend (items, g_strdup_printf ("CONNECTIVITY_STATE=%s", connectivity_state));
|
||||
|
||||
path = g_getenv ("PATH");
|
||||
if (path) {
|
||||
path_item = g_strdup_printf ("PATH=%s", path);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ nm_dispatcher_utils_construct_envp (const char *action,
|
|||
GVariant *device_ip6_props,
|
||||
GVariant *device_dhcp4_props,
|
||||
GVariant *device_dhcp6_props,
|
||||
const char *connectivity_state,
|
||||
const char *vpn_ip_iface,
|
||||
GVariant *vpn_ip4_props,
|
||||
GVariant *vpn_ip6_props,
|
||||
|
|
|
|||
|
|
@ -701,6 +701,7 @@ handle_action (NMDBusDispatcher *dbus_dispatcher,
|
|||
device_ip6_props,
|
||||
device_dhcp4_props,
|
||||
device_dhcp6_props,
|
||||
connectivity_state,
|
||||
vpn_ip_iface,
|
||||
vpn_ip4_props,
|
||||
vpn_ip6_props,
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ TESTS = test-dispatcher-envp
|
|||
endif
|
||||
|
||||
EXTRA_DIST= \
|
||||
dispatcher-connectivity-full \
|
||||
dispatcher-connectivity-unknown \
|
||||
dispatcher-down \
|
||||
dispatcher-external \
|
||||
dispatcher-up \
|
||||
|
|
|
|||
23
callouts/tests/dispatcher-connectivity-full
Normal file
23
callouts/tests/dispatcher-connectivity-full
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
[main]
|
||||
action=connectiviy-change
|
||||
expected-iface=wlan0
|
||||
uuid=3fd2a33a-d81b-423f-ae99-e6baba742311
|
||||
id=Random Connection
|
||||
connectivity-state=FULL
|
||||
|
||||
[device]
|
||||
state=30
|
||||
ip-interface=wlan0
|
||||
type=2
|
||||
interface=wlan0
|
||||
path=/org/freedesktop/NetworkManager/Devices/0
|
||||
|
||||
[env]
|
||||
PATH=
|
||||
CONNECTION_UUID=3fd2a33a-d81b-423f-ae99-e6baba742311
|
||||
CONNECTION_DBUS_PATH=/org/freedesktop/NetworkManager/Connections/5
|
||||
CONNECTION_ID=Random Connection
|
||||
CONNECTION_FILENAME=/callouts/tests/dispatcher-connectivity-full
|
||||
DEVICE_IFACE=wlan0
|
||||
DEVICE_IP_IFACE=wlan0
|
||||
CONNECTIVITY_STATE=FULL
|
||||
22
callouts/tests/dispatcher-connectivity-unknown
Normal file
22
callouts/tests/dispatcher-connectivity-unknown
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
[main]
|
||||
action=connectiviy-change
|
||||
expected-iface=wlan0
|
||||
uuid=3fd2a33a-d81b-423f-ae99-e6baba742311
|
||||
id=Random Connection
|
||||
connectivity-state=UNKNOWN
|
||||
|
||||
[device]
|
||||
state=30
|
||||
ip-interface=wlan0
|
||||
type=2
|
||||
interface=wlan0
|
||||
path=/org/freedesktop/NetworkManager/Devices/0
|
||||
|
||||
[env]
|
||||
PATH=
|
||||
CONNECTION_UUID=3fd2a33a-d81b-423f-ae99-e6baba742311
|
||||
CONNECTION_DBUS_PATH=/org/freedesktop/NetworkManager/Connections/5
|
||||
CONNECTION_ID=Random Connection
|
||||
CONNECTION_FILENAME=/callouts/tests/dispatcher-connectivity-unknown
|
||||
DEVICE_IFACE=wlan0
|
||||
DEVICE_IP_IFACE=wlan0
|
||||
|
|
@ -39,6 +39,7 @@ parse_main (GKeyFile *kf,
|
|||
GVariant **out_con_props,
|
||||
char **out_expected_iface,
|
||||
char **out_action,
|
||||
char **out_connectivity_state,
|
||||
char **out_vpn_ip_iface,
|
||||
GError **error)
|
||||
{
|
||||
|
|
@ -51,6 +52,7 @@ parse_main (GKeyFile *kf,
|
|||
if (*out_expected_iface == NULL)
|
||||
return FALSE;
|
||||
|
||||
*out_connectivity_state = g_key_file_get_string (kf, "main", "connectivity-state", NULL);
|
||||
*out_vpn_ip_iface = g_key_file_get_string (kf, "main", "vpn-ip-iface", NULL);
|
||||
|
||||
*out_action = g_key_file_get_string (kf, "main", "action", error);
|
||||
|
|
@ -359,6 +361,7 @@ get_dispatcher_file (const char *file,
|
|||
GVariant **out_device_ip6_props,
|
||||
GVariant **out_device_dhcp4_props,
|
||||
GVariant **out_device_dhcp6_props,
|
||||
char **out_connectivity_state,
|
||||
char **out_vpn_ip_iface,
|
||||
GVariant **out_vpn_ip4_props,
|
||||
GVariant **out_vpn_ip6_props,
|
||||
|
|
@ -379,6 +382,7 @@ get_dispatcher_file (const char *file,
|
|||
g_assert (out_device_ip6_props && !*out_device_ip6_props);
|
||||
g_assert (out_device_dhcp4_props && !*out_device_dhcp4_props);
|
||||
g_assert (out_device_dhcp6_props && !*out_device_dhcp6_props);
|
||||
g_assert (out_connectivity_state && !*out_connectivity_state);
|
||||
g_assert (out_vpn_ip_iface && !*out_vpn_ip_iface);
|
||||
g_assert (out_vpn_ip4_props && !*out_vpn_ip4_props);
|
||||
g_assert (out_vpn_ip6_props && !*out_vpn_ip6_props);
|
||||
|
|
@ -396,6 +400,7 @@ get_dispatcher_file (const char *file,
|
|||
out_con_props,
|
||||
out_expected_iface,
|
||||
out_action,
|
||||
out_connectivity_state,
|
||||
out_vpn_ip_iface,
|
||||
error))
|
||||
goto out;
|
||||
|
|
@ -451,6 +456,7 @@ test_generic (const char *file, const char *override_vpn_ip_iface)
|
|||
GVariant *device_ip6_props = NULL;
|
||||
GVariant *device_dhcp4_props = NULL;
|
||||
GVariant *device_dhcp6_props = NULL;
|
||||
char *connectivity_change = NULL;
|
||||
char *vpn_ip_iface = NULL;
|
||||
GVariant *vpn_ip4_props = NULL;
|
||||
GVariant *vpn_ip6_props = NULL;
|
||||
|
|
@ -474,6 +480,7 @@ test_generic (const char *file, const char *override_vpn_ip_iface)
|
|||
&device_ip6_props,
|
||||
&device_dhcp4_props,
|
||||
&device_dhcp6_props,
|
||||
&connectivity_change,
|
||||
&vpn_ip_iface,
|
||||
&vpn_ip4_props,
|
||||
&vpn_ip6_props,
|
||||
|
|
@ -494,6 +501,7 @@ test_generic (const char *file, const char *override_vpn_ip_iface)
|
|||
device_ip6_props,
|
||||
device_dhcp4_props,
|
||||
device_dhcp6_props,
|
||||
connectivity_change,
|
||||
override_vpn_ip_iface ? override_vpn_ip_iface : vpn_ip_iface,
|
||||
vpn_ip4_props,
|
||||
vpn_ip6_props,
|
||||
|
|
@ -601,6 +609,15 @@ test_external (void)
|
|||
test_generic ("dispatcher-external", NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
test_connectivity_changed (void)
|
||||
{
|
||||
/* These tests will check that the CONNECTIVITY_STATE environment
|
||||
* variable is only defined for known states, such as 'full'. */
|
||||
test_generic ("dispatcher-connectivity-unknown", NULL);
|
||||
test_generic ("dispatcher-connectivity-full", NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
test_up_empty_vpn_iface (void)
|
||||
{
|
||||
|
|
@ -624,6 +641,7 @@ main (int argc, char **argv)
|
|||
g_test_add_func ("/dispatcher/vpn_up", test_vpn_up);
|
||||
g_test_add_func ("/dispatcher/vpn_down", test_vpn_down);
|
||||
g_test_add_func ("/dispatcher/external", test_external);
|
||||
g_test_add_func ("/dispatcher/connectivity_changed", test_connectivity_changed);
|
||||
|
||||
g_test_add_func ("/dispatcher/up_empty_vpn_iface", test_up_empty_vpn_iface);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue