dispatcher: add an env var indicating a connection is "external"
authorDan Winship <danw@redhat.com>
Thu, 18 Dec 2014 14:13:57 +0000 (09:13 -0500)
committerDan Winship <danw@redhat.com>
Mon, 19 Jan 2015 16:19:33 +0000 (11:19 -0500)
Add CONNECTION_EXTERNAL=1 to the environment when dispatching actions
on a "generated-assumed" connection (ie, one that was created outside
of NM).

callouts/nm-dispatcher-api.h
callouts/nm-dispatcher-utils.c
callouts/tests/Makefile.am
callouts/tests/dispatcher-external [new file with mode: 0644]
callouts/tests/test-dispatcher-envp.c
man/NetworkManager.xml
src/nm-dispatcher.c

index 9b2c3b3..7141093 100644 (file)
@@ -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"
index dd761f7..82ae353 100644 (file)
@@ -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_DBUS_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));
 
index 49b2f94..3d16d74 100644 (file)
@@ -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 (file)
index 0000000..5430bec
--- /dev/null
@@ -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_DBUS_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
+
index 3c0a470..527dc35 100644 (file)
@@ -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;
@@ -560,6 +568,12 @@ test_vpn_down (void)
        test_generic ("dispatcher-vpn-down", NULL);
 }
 
+static void
+test_external (void)
+{
+       test_generic ("dispatcher-external", NULL);
+}
+
 static void
 test_up_empty_vpn_iface (void)
 {
@@ -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);
 
index 6b2d886..aa54fe1 100644 (file)
             The backing file name of the connection profile (if any).
           </para></listitem>
         </varlistentry>
+        <varlistentry>
+          <term><varname>CONNECTION_EXTERNAL</varname></term>
+          <listitem><para>
+            If "1", this indicates that the connection describes a
+            network configuration created outside of NetworkManager.
+          </para></listitem>
+        </varlistentry>
         <varlistentry>
           <term><varname>DEVICE_IFACE</varname></term>
           <listitem><para>
index 4e20026..4e0a05e 100644 (file)
@@ -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 ();