diff options
author | Dan Winship <danw@redhat.com> | 2014-12-18 09:13:57 -0500 |
---|---|---|
committer | Dan Winship <danw@redhat.com> | 2015-01-08 09:39:47 -0500 |
commit | 63c42556fae04c87aaf22eb7461f54aea56bd6f3 (patch) | |
tree | 61e0943d4c94f7227a1b528b89ecd90c7e086c12 | |
parent | bd21ae351b183e4d49b6b9b8bf5b32a0cfe1be94 (diff) | |
download | NetworkManager-danw/dispatcher-external-bgo742588.tar.gz |
dispatcher: add an env var indicating a connection is "external"danw/dispatcher-external-bgo742588
Add CONNECTION_EXTERNAL=1 to the environment when dispatching actions
on a "generated-assumed" connection (ie, one that was created outside
of NM).
-rw-r--r-- | callouts/nm-dispatcher-api.h | 1 | ||||
-rw-r--r-- | callouts/nm-dispatcher-utils.c | 4 | ||||
-rw-r--r-- | callouts/tests/Makefile.am | 1 | ||||
-rw-r--r-- | callouts/tests/dispatcher-external | 33 | ||||
-rw-r--r-- | callouts/tests/test-dispatcher-envp.c | 15 | ||||
-rw-r--r-- | src/nm-dispatcher.c | 5 |
6 files changed, 59 insertions, 0 deletions
diff --git a/callouts/nm-dispatcher-api.h b/callouts/nm-dispatcher-api.h index 9b2c3b32cb..71410939cb 100644 --- a/callouts/nm-dispatcher-api.h +++ b/callouts/nm-dispatcher-api.h @@ -32,6 +32,7 @@ #define NMD_CONNECTION_PROPS_PATH "path" #define NMD_CONNECTION_PROPS_FILENAME "filename" +#define NMD_CONNECTION_PROPS_EXTERNAL "external" #define NMD_DEVICE_PROPS_INTERFACE "interface" #define NMD_DEVICE_PROPS_IP_INTERFACE "ip-interface" diff --git a/callouts/nm-dispatcher-utils.c b/callouts/nm-dispatcher-utils.c index 7c98c909dd..4a1839eceb 100644 --- a/callouts/nm-dispatcher-utils.c +++ b/callouts/nm-dispatcher-utils.c @@ -335,6 +335,7 @@ nm_dispatcher_utils_construct_envp (const char *action, const char *iface = NULL, *ip_iface = NULL; const char *uuid = NULL, *id = NULL, *path = NULL; const char *filename = NULL; + gboolean external; NMDeviceState dev_state = NM_DEVICE_STATE_UNKNOWN; GVariant *value; char **envp = NULL, *path_item; @@ -357,6 +358,9 @@ nm_dispatcher_utils_construct_envp (const char *action, } items = g_slist_prepend (items, g_strdup_printf ("CONNECTION_PATH=%s", path)); + if (g_variant_lookup (connection_props, NMD_CONNECTION_PROPS_EXTERNAL, "b", &external) && external) + items = g_slist_prepend (items, g_strdup ("CONNECTION_EXTERNAL=1")); + if (g_variant_lookup (connection_props, NMD_CONNECTION_PROPS_FILENAME, "&s", &filename)) items = g_slist_prepend (items, g_strdup_printf ("CONNECTION_FILENAME=%s", filename)); diff --git a/callouts/tests/Makefile.am b/callouts/tests/Makefile.am index 49b2f94588..3d16d74e25 100644 --- a/callouts/tests/Makefile.am +++ b/callouts/tests/Makefile.am @@ -34,6 +34,7 @@ endif EXTRA_DIST= \ dispatcher-down \ + dispatcher-external \ dispatcher-up \ dispatcher-vpn-down \ dispatcher-vpn-up diff --git a/callouts/tests/dispatcher-external b/callouts/tests/dispatcher-external new file mode 100644 index 0000000000..d30ba11159 --- /dev/null +++ b/callouts/tests/dispatcher-external @@ -0,0 +1,33 @@ +[main] +action=up +expected-iface=virbr0 +uuid=92bbc2fb-7304-46be-8ebb-6093dbe19a6a +id=virbr0 +external=1 + +[device] +state=100 +ip-interface=virbr0 +type=13 +interface=virbr0 +path=/org/freedesktop/NetworkManager/Devices/0 + +[ip4] +addresses=192.168.122.1/24 0.0.0.0 +domains= +gateway=0.0.0.0 + +[env] +PATH= +CONNECTION_UUID=92bbc2fb-7304-46be-8ebb-6093dbe19a6a +CONNECTION_PATH=/org/freedesktop/NetworkManager/Connections/5 +CONNECTION_FILENAME=/callouts/tests/dispatcher-external +CONNECTION_ID=virbr0 +CONNECTION_EXTERNAL=1 +DEVICE_IFACE=virbr0 +DEVICE_IP_IFACE=virbr0 +IP4_NUM_ADDRESSES=1 +IP4_ADDRESS_0=192.168.122.1/24 0.0.0.0 +IP4_GATEWAY=0.0.0.0 +IP4_NUM_ROUTES=0 + diff --git a/callouts/tests/test-dispatcher-envp.c b/callouts/tests/test-dispatcher-envp.c index 3c0a47050d..527dc35c43 100644 --- a/callouts/tests/test-dispatcher-envp.c +++ b/callouts/tests/test-dispatcher-envp.c @@ -83,11 +83,19 @@ parse_main (GKeyFile *kf, g_variant_builder_add (&props, "{sv}", NMD_CONNECTION_PROPS_PATH, g_variant_new_object_path ("/org/freedesktop/NetworkManager/Connections/5")); + /* Strip out the non-fixed portion of the filename */ filename = strstr (filename, "/callouts"); g_variant_builder_add (&props, "{sv}", "filename", g_variant_new_string (filename)); + + if (g_key_file_get_boolean (kf, "main", "external", NULL)) { + g_variant_builder_add (&props, "{sv}", + "external", + g_variant_new_boolean (TRUE)); + } + *out_con_props = g_variant_builder_end (&props); return TRUE; @@ -561,6 +569,12 @@ test_vpn_down (void) } static void +test_external (void) +{ + test_generic ("dispatcher-external", NULL); +} + +static void test_up_empty_vpn_iface (void) { /* Test that an empty VPN iface variable, like is passed through D-Bus @@ -584,6 +598,7 @@ main (int argc, char **argv) g_test_add_func ("/dispatcher/down", test_down); 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/up_empty_vpn_iface", test_up_empty_vpn_iface); diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c index 4e2002660c..4e0a05ed7d 100644 --- a/src/nm-dispatcher.c +++ b/src/nm-dispatcher.c @@ -491,6 +491,11 @@ _dispatcher_call (DispatcherAction action, NMD_CONNECTION_PROPS_FILENAME, filename); } + if (nm_settings_connection_get_nm_generated_assumed (NM_SETTINGS_CONNECTION (connection))) { + value_hash_add_bool (connection_props, + NMD_CONNECTION_PROPS_EXTERNAL, + TRUE); + } } else { connection_hash = value_hash_create (); connection_props = value_hash_create (); |