From a6416cbd134b7f38408e659bfb346ca8f2af5a24 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 8 Nov 2016 09:42:31 +0100 Subject: [PATCH] ip-tunnel: tigthen up checks for valid IP tunnel modes The compiler warns us when we don't specify all enum values in a switch(), provided that default: is missing. Make use of that to get a warning when we add a new tunnel mode. --- libnm-core/nm-setting-ip-tunnel.c | 6 +++--- src/devices/nm-device-ip-tunnel.c | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libnm-core/nm-setting-ip-tunnel.c b/libnm-core/nm-setting-ip-tunnel.c index e7d625c381..50630a4572 100644 --- a/libnm-core/nm-setting-ip-tunnel.c +++ b/libnm-core/nm-setting-ip-tunnel.c @@ -291,7 +291,7 @@ static gboolean verify (NMSetting *setting, NMConnection *connection, GError **error) { NMSettingIPTunnelPrivate *priv = NM_SETTING_IP_TUNNEL_GET_PRIVATE (setting); - int family; + int family = AF_UNSPEC; switch (priv->mode) { case NM_IP_TUNNEL_MODE_IPIP: @@ -307,8 +307,8 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) case NM_IP_TUNNEL_MODE_VTI6: family = AF_INET6; break; - default: - family = AF_UNSPEC; + case NM_IP_TUNNEL_MODE_UNKNOWN: + break; } if (family == AF_UNSPEC) { diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c index d0b2ca71fc..8732ddf9b5 100644 --- a/src/devices/nm-device-ip-tunnel.c +++ b/src/devices/nm-device-ip-tunnel.c @@ -585,9 +585,15 @@ tunnel_mode_to_link_type (NMIPTunnelMode tunnel_mode) return NM_LINK_TYPE_IPIP; case NM_IP_TUNNEL_MODE_SIT: return NM_LINK_TYPE_SIT; - default: + case NM_IP_TUNNEL_MODE_VTI: + case NM_IP_TUNNEL_MODE_IP6GRE: + case NM_IP_TUNNEL_MODE_VTI6: + case NM_IP_TUNNEL_MODE_ISATAP: return NM_LINK_TYPE_UNKNOWN; + case NM_IP_TUNNEL_MODE_UNKNOWN: + break; } + g_return_val_if_reached (NM_LINK_TYPE_UNKNOWN); } /*****************************************************************************/