summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-12-07 11:06:35 +0100
committerThomas Haller <thaller@redhat.com>2015-12-07 11:32:12 +0100
commit72c36bd6db9652fce8d037d671cb5c62afad2ac2 (patch)
tree9b34ea89727bbef639e096425ba6684e9e9a74e0
parentda528b5ccd2c4b372dd88cf43920d7b7c4261ab3 (diff)
downloadNetworkManager-72c36bd6db9652fce8d037d671cb5c62afad2ac2.tar.gz
device/tun: fix reloading tun properties
Before the device is setup, we call nm_platform_tun_get_properties() without a valid ifindex. That triggered an assertion [1]. Thereby, change nm_platform_tun_get_properties() to effectively clear the tun properties when we are unable to fetch them. Also, never modify the tun-mode of NMDeviceTun. [1] #0 0x00007f0a4173e81b in g_logv (breakpoint=1) at gmessages.c:324 #1 0x00007f0a4173e81b in g_logv (log_domain=0x561e9264ccf6 "NetworkManager", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7ffd71a0d4d0) at gmessages.c:1081 #2 0x00007f0a4173e98f in g_log (log_domain=<optimized out>, log_level=<optimized out>, format=<optimized out>) at gmessages.c:1119 #3 0x0000561e9241ecec in nm_platform_tun_get_properties (self=0x561e9354ba70 [NMLinuxPlatform], ifindex=0, props=0x7ffd71a0d650) at platform/nm-platform.c:2081 #4 0x0000561e923aad9c in reload_tun_properties (self=0x561e937fb080 [NMDeviceTun]) at devices/nm-device-tun.c:68 #5 0x0000561e923aa795 in realize (device=0x561e937fb080 [NMDeviceTun], plink=0x7ffd71a0d818, error=0x7ffd71a0d798) at devices/nm-device-tun.c:225 #6 0x0000561e923bdc06 in nm_device_realize (self=0x561e937fb080 [NMDeviceTun], plink=0x7ffd71a0d818, out_compatible=0x7ffd71a0d77c, error=0x7ffd71a0d798) at devices/nm-device.c:1713 #7 0x0000561e924ad995 in platform_link_added (self=0x561e9356e230 [NMManager], ifindex=33, plink=0x7ffd71a0d818) at nm-manager.c:1947 #8 0x0000561e924ad717 in _platform_link_cb_idle (data=0x561e937eb940) at nm-manager.c:2029 #9 0x00007f0a41737e3a in g_main_context_dispatch (context=0x561e93547530) at gmain.c:3154 #10 0x00007f0a41737e3a in g_main_context_dispatch (context=context@entry=0x561e93547530) at gmain.c:3769 #11 0x00007f0a417381d0 in g_main_context_iterate (context=0x561e93547530, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3840 #12 0x00007f0a417384f2 in g_main_loop_run (loop=0x561e935475f0) at gmain.c:4034 #13 0x0000561e923ba3f3 in main (argc=1, argv=0x7ffd71a0dc68) at main.c:488 Fixes: 4dbaac4ba24ebc8b257fffe5197cc8e362804a58
-rw-r--r--src/devices/nm-device-tun.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c
index af37c3184d..60d9d7bba2 100644
--- a/src/devices/nm-device-tun.c
+++ b/src/devices/nm-device-tun.c
@@ -64,11 +64,26 @@ reload_tun_properties (NMDeviceTun *self)
NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE (self);
GObject *object = G_OBJECT (self);
NMPlatformTunProperties props;
-
- if (!nm_platform_tun_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), &props)) {
- _LOGD (LOGD_HW, "could not read tun properties");
- return;
- }
+ int ifindex;
+
+ ifindex = nm_device_get_ifindex (NM_DEVICE (self));
+ if (ifindex > 0) {
+ if (!nm_platform_tun_get_properties (NM_PLATFORM_GET, ifindex, &props)) {
+ _LOGD (LOGD_DEVICE, "tun-properties: cannot loading tun properties from platform for ifindex %d", ifindex);
+ ifindex = 0;
+ } else if (g_strcmp0 (priv->mode, props.mode) != 0) {
+ /* if the mode differs, we ignore what we loaded. A NMDeviceTun cannot
+ * change the mode after construction. */
+ _LOGD (LOGD_DEVICE, "tun-properties: loading tun properties yielded tun-mode %s%s%s, but %s%s%s expected (ifindex %d)",
+ NM_PRINT_FMT_QUOTE_STRING (props.mode),
+ NM_PRINT_FMT_QUOTE_STRING (priv->mode),
+ ifindex);
+ ifindex = 0;
+ }
+ } else
+ _LOGD (LOGD_DEVICE, "tun-properties: ignore loading properties due to missing ifindex");
+ if (ifindex <= 0)
+ memset (&props, 0, sizeof (props));
g_object_freeze_notify (object);
@@ -83,7 +98,6 @@ reload_tun_properties (NMDeviceTun *self)
if (priv->props.multi_queue != props.multi_queue)
g_object_notify (object, NM_DEVICE_TUN_MULTI_QUEUE);
- priv->mode = props.mode;
memcpy (&priv->props, &props, sizeof (NMPlatformTunProperties));
g_object_thaw_notify (object);