Commit 849ae9ee authored by Dan Winship's avatar Dan Winship

dispatcher: add an env var indicating a connection is "external"

Add CONNECTION_EXTERNAL=1 to the environment when dispatching actions
on a "generated-assumed" connection (ie, one that was created outside
of NM).
parent 995da9a5
......@@ -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"
......
......@@ -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));
......
......@@ -34,6 +34,7 @@ endif
EXTRA_DIST= \
dispatcher-down \
dispatcher-external \
dispatcher-up \
dispatcher-vpn-down \
dispatcher-vpn-up
[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
......@@ -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);
......
......@@ -178,6 +178,13 @@
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>
......
......@@ -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 ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment