[PATCH 3/4] vlan: create NMDeviceEthernet for vlan device



A vlan device is like a virtual ethernet device.
So we reuse NMDeviceEthernet insead of creating another NMDeviceVlan,
and we add some special handling to detect vlan connections.

And it makes little sense for NetworkManager to control vlan devices created not
by itself, like devices created by "vconfig add" or netlink,
so we just skip such event, and free corresponding NMDevice.

V4:
1 use nm_system_get_iface_type() and nm_connection_get_virtual_iface_name()

V3:
1 call nm_system_add_vlan_device() to create vlan device in kernel

V2:
1 delete NMDeviceVlan, just use NMDeviceEthernet

Signed-off-by: Weiping Pan <wpan redhat com>
---
 libnm-util/nm-setting-vlan.c |   12 ++++++++++++
 src/nm-device-ethernet.c     |    3 +++
 src/nm-device-ethernet.h     |    2 --
 src/nm-manager.c             |   11 +++++++++++
 src/nm-udev-manager.c        |    5 ++++-
 5 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/libnm-util/nm-setting-vlan.c b/libnm-util/nm-setting-vlan.c
index c9384d0..48a67d7 100644
--- a/libnm-util/nm-setting-vlan.c
+++ b/libnm-util/nm-setting-vlan.c
@@ -190,6 +190,14 @@ nm_setting_vlan_get_egress_priority_map(NMSettingVlan *setting)
 	return NM_SETTING_VLAN_GET_PRIVATE (setting)->vlan_egress_priority_map;
 }
 
+static const char *
+get_virtual_iface_name (NMSetting *setting)
+{
+	NMSettingVlan *self = NM_SETTING_VLAN(setting);
+
+	return nm_setting_vlan_get_interface_name (self);
+}
+
 static void
 nm_setting_vlan_init (NMSettingVlan *setting)
 {
@@ -578,12 +586,16 @@ static void
 nm_setting_vlan_class_init (NMSettingVlanClass *setting_class)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
+	NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
+
 	g_type_class_add_private (setting_class, sizeof(NMSettingVlanPrivate));
 
 	/* virtual methods */
 	object_class->set_property = set_property;
 	object_class->get_property = get_property;
 	object_class->finalize     = finalize;
+	parent_class->get_virtual_iface_name = get_virtual_iface_name;
+
 
 	/* Properties */
 	g_object_class_install_property
diff --git a/src/nm-device-ethernet.c b/src/nm-device-ethernet.c
index 010d399..daf9099 100644
--- a/src/nm-device-ethernet.c
+++ b/src/nm-device-ethernet.c
@@ -52,6 +52,7 @@
 #include "nm-setting-8021x.h"
 #include "nm-setting-pppoe.h"
 #include "nm-setting-bond.h"
+#include "nm-setting-vlan.h"
 #include "ppp-manager/nm-ppp-manager.h"
 #include "nm-logging.h"
 #include "nm-properties-changed-signal.h"
@@ -668,6 +669,8 @@ match_ethernet_connection (NMDevice *device, NMConnection *connection,
 		/* NOP */
 	} else if (!strcmp (type, NM_SETTING_BOND_SETTING_NAME)) {
 		/* NOP */
+	} else if (!strcmp (type, NM_SETTING_VLAN_SETTING_NAME)) {
+		/* NOP */
 	} else if (!strcmp (type, NM_SETTING_WIRED_SETTING_NAME)) {
 		if (!s_wired) {
 			if (error)
diff --git a/src/nm-device-ethernet.h b/src/nm-device-ethernet.h
index 51993db..7b61f8b 100644
--- a/src/nm-device-ethernet.h
+++ b/src/nm-device-ethernet.h
@@ -59,8 +59,6 @@ NMDevice *nm_device_ethernet_new (const char *udi,
                                   const char *iface,
                                   const char *driver);
 
-gboolean nm_device_bond_connection_matches (NMDevice *device, NMConnection *connection);
-
 G_END_DECLS
 
 #endif	/* NM_DEVICE_ETHERNET_H */
diff --git a/src/nm-manager.c b/src/nm-manager.c
index f689837..8964093 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -943,6 +943,8 @@ connection_needs_virtual_device (NMConnection *connection)
 {
 	if (nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME))
 		return TRUE;
+	if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME))
+		return TRUE;
 
 	return FALSE;
 }
@@ -959,6 +961,15 @@ system_update_virtual_device (NMConnection *connection)
 		return nm_system_add_bonding_master (s_bond);
 	}
 
+	if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
+		NMSettingVlan *s_vlan;
+
+		s_vlan = nm_connection_get_setting_vlan (connection);
+		g_assert (s_vlan);
+
+		return nm_system_add_vlan_device (s_vlan);
+	}
+
 	return TRUE;
 }
 
diff --git a/src/nm-udev-manager.c b/src/nm-udev-manager.c
index 3ea447d..f6dd67b 100644
--- a/src/nm-udev-manager.c
+++ b/src/nm-udev-manager.c
@@ -432,13 +432,16 @@ device_creator (NMUdevManager *manager,
 		case NM_IFACE_TYPE_BOND:
 			driver = "bonding";
 			break;
+		case NM_IFACE_TYPE_VLAN:
+			driver = "8021q";
+			break;
 
 		default:
 			if (g_str_has_prefix (ifname, "easytether"))
 				driver = "easytether";
 			break;
 		}
-		
+
 		if (!driver) {
 			nm_log_warn (LOGD_HW, "%s: couldn't determine device driver; ignoring...", path);
 			goto out;
-- 
1.7.4.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]