Re: [PATCH 2/5] vlan: add ifcfg-vlan parser

2011-11-20 Thread Chuck Anderson
I think you should support the common and documented format:

DEVICE=eth0.43

which is documented in /usr/share/doc/initscripts-*/sysconfig.txt

  Ethernet 802.1q VLAN items:
 DEVICE=eth0.42
   Initscripts use the device name for VLAN devices.
   Example: eth0.42 for vlan 42 on device eth0.
   Valid VLAN ID range is 0-4095. Most ethernet switches reserve
   VLAN ID 1 to be used as management VLAN; starting from VLAN
   ID 2 is recommended.
 REORDER_HDR=yes|no
   When enabled the VLAN device will move the ethernet header
   around to make it look exactly like a real ethernet device.
   This may help programs such as ISC dhcpd which read the raw
   ethernet packet and make assumptions about the location of
   bytes. If you don't need it turn it off because there
   is a small performance penalty. Default is on.
 GVRP=yes|no
   When enabled, this will announce new vlan creation to a GVRP
   enabled trunk port on a switch. Default is off.

On Sun, Nov 20, 2011 at 07:16:17AM -0500, Weiping Pan wrote:
> The example of ifcfg-vlan is as followed:
> 
> VLAN=yes
> TYPE=vlan
> DEVICE=vlan43
> PHYSDEV=eth9
> REORDER_HDR=0
> VLAN_FLAGS=GVRP,LOOSE_BINDING
> VLAN_INGRESS_PRIORITY_MAP=0:1,2:5
> VLAN_EGRESS_PRIORITY_MAP=12:3,14:7
> ONBOOT=yes
> BOOTPROTO=static
> IPADDR=192.168.43.149
> NETMASK=255.255.255.0
> 
> And we try to make it compitable with the format used by initscripts,
> and there is no need to change anything in ifcfg-eth9.
> 
> Pay attention the format of DEVICE here is 'vlan+id', and id is 0-4095.
> 
> V2:
> 1 use "Vlan" and "vlan" to keep consistency
> 2 remove duplicate "VLAN" or "vlan"
> 3 add enum NMVlanFlags
> 
> Signed-off-by: Weiping Pan 
> ---
>  libnm-util/Makefile.am |2 +
>  libnm-util/libnm-util.ver  |   11 +
>  libnm-util/nm-connection.c |   26 +-
>  libnm-util/nm-connection.h |2 +
>  libnm-util/nm-setting-vlan.c   |  584 
> 
>  libnm-util/nm-setting-vlan.h   |  118 
>  src/settings/plugins/ifcfg-rh/common.h |1 +
>  src/settings/plugins/ifcfg-rh/reader.c |  179 ++-
>  .../network-scripts/ifcfg-test-vlan-interface  |   11 +-
>  .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c |3 +-
>  10 files changed, 918 insertions(+), 19 deletions(-)
>  create mode 100644 libnm-util/nm-setting-vlan.c
>  create mode 100644 libnm-util/nm-setting-vlan.h
> 
> diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am
> index 627c3e3..ed7134a 100644
> --- a/libnm-util/Makefile.am
> +++ b/libnm-util/Makefile.am
> @@ -18,6 +18,7 @@ libnm_util_include_HEADERS =\
>   nm-setting-bond.h   \
>   nm-setting-connection.h \
>   nm-setting-ip4-config.h \
> + nm-setting-vlan.h   \
>   nm-setting-ip6-config.h \
>   nm-setting-ppp.h\
>   nm-setting-pppoe.h  \
> @@ -48,6 +49,7 @@ libnm_util_la_csources = \
>   nm-setting-bond.c   \
>   nm-setting-connection.c \
>   nm-setting-ip4-config.c \
> + nm-setting-vlan.c   \
>   nm-setting-ip6-config.c \
>   nm-setting-ppp.c\
>   nm-setting-pppoe.c  \
> diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
> index 9b714ba..12970ad 100644
> --- a/libnm-util/libnm-util.ver
> +++ b/libnm-util/libnm-util.ver
> @@ -31,6 +31,7 @@ global:
>   nm_connection_get_setting_wired;
>   nm_connection_get_setting_wireless;
>   nm_connection_get_setting_wireless_security;
> + nm_connection_get_setting_vlan;
>   nm_connection_get_type;
>   nm_connection_get_uuid;
>   nm_connection_is_type;
> @@ -464,6 +465,16 @@ global:
>   nm_utils_wifi_find_next_channel;
>   nm_utils_wifi_freq_to_channel;
>   nm_utils_wifi_is_channel_valid;
> + nm_setting_vlan_error_get_type;
> + nm_setting_vlan_error_quark;
> + nm_setting_vlan_get_type;
> + nm_setting_vlan_new;
> + nm_setting_vlan_get_interface_name;
> + nm_setting_vlan_get_slave;
> + nm_setting_vlan_get_id;
> + nm_setting_vlan_get_flags;
> + nm_setting_vlan_get_ingress_priority_map;
> + nm_setting_vlan_get_egress_priority_map;
>  local:
>   *;
>  };
> diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c
> index de6e948..e77f892 100644
> --- a/libnm-util/nm-connection.c
> +++ b/libnm-util/nm-connection.c
> @@ -45,7 +45,7 @@
>  #include "nm-setting-vpn.h"
>  #include "nm-setting-olpc-mesh.h"
>  #include "nm-setting-bond.h"
> -
> +#include "nm-setting-vlan.h"
>  #include "nm-setting-serial.h"
>  #include "nm-setting-gsm.h"
>  #include "nm-setting-cdma.h"
> @@ -136,7 +136,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
>  
>  static GHashTable *registered_sett

how to use NetworkManager in ubuntu 10.04

2011-11-20 Thread 金 晓烨
I want to develop an application run in ubuntu 10.04 and this application may 
have some IPC with the NetworkManager.
When i installed the NetworkManager 0.9.20 after "./configure" "make check" 
"make install" "make installcheck" it is all clear ,but then i can not get my 
eth device information with"ifconfig" and get into the Internet.
I use "ps -aux"can find that the nm-applet is running, but there must have some 
mistakes for me, when i use the tool provided in  "use/local/bin/"like nmcli 
the terminal`s output is that "./nmcli: error while loading shared libraries: 
libnm-util.so.2: cannot open shared object file :No such file or directory"
Is that device`s driver problem? how can i fix it.

please help me how can i use NetworkManager in ubuntu 10.04 .

Thanks very much!

___
networkmanager-list mailing list
networkmanager-list@gnome.org
http://mail.gnome.org/mailman/listinfo/networkmanager-list


[PATCH 2/5] vlan: add ifcfg-vlan parser

2011-11-20 Thread Weiping Pan
The example of ifcfg-vlan is as followed:

VLAN=yes
TYPE=vlan
DEVICE=vlan43
PHYSDEV=eth9
REORDER_HDR=0
VLAN_FLAGS=GVRP,LOOSE_BINDING
VLAN_INGRESS_PRIORITY_MAP=0:1,2:5
VLAN_EGRESS_PRIORITY_MAP=12:3,14:7
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.43.149
NETMASK=255.255.255.0

And we try to make it compitable with the format used by initscripts,
and there is no need to change anything in ifcfg-eth9.

Pay attention the format of DEVICE here is 'vlan+id', and id is 0-4095.

V2:
1 use "Vlan" and "vlan" to keep consistency
2 remove duplicate "VLAN" or "vlan"
3 add enum NMVlanFlags

Signed-off-by: Weiping Pan 
---
 libnm-util/Makefile.am |2 +
 libnm-util/libnm-util.ver  |   11 +
 libnm-util/nm-connection.c |   26 +-
 libnm-util/nm-connection.h |2 +
 libnm-util/nm-setting-vlan.c   |  584 
 libnm-util/nm-setting-vlan.h   |  118 
 src/settings/plugins/ifcfg-rh/common.h |1 +
 src/settings/plugins/ifcfg-rh/reader.c |  179 ++-
 .../network-scripts/ifcfg-test-vlan-interface  |   11 +-
 .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c |3 +-
 10 files changed, 918 insertions(+), 19 deletions(-)
 create mode 100644 libnm-util/nm-setting-vlan.c
 create mode 100644 libnm-util/nm-setting-vlan.h

diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am
index 627c3e3..ed7134a 100644
--- a/libnm-util/Makefile.am
+++ b/libnm-util/Makefile.am
@@ -18,6 +18,7 @@ libnm_util_include_HEADERS =  \
nm-setting-bond.h   \
nm-setting-connection.h \
nm-setting-ip4-config.h \
+   nm-setting-vlan.h   \
nm-setting-ip6-config.h \
nm-setting-ppp.h\
nm-setting-pppoe.h  \
@@ -48,6 +49,7 @@ libnm_util_la_csources = \
nm-setting-bond.c   \
nm-setting-connection.c \
nm-setting-ip4-config.c \
+   nm-setting-vlan.c   \
nm-setting-ip6-config.c \
nm-setting-ppp.c\
nm-setting-pppoe.c  \
diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index 9b714ba..12970ad 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -31,6 +31,7 @@ global:
nm_connection_get_setting_wired;
nm_connection_get_setting_wireless;
nm_connection_get_setting_wireless_security;
+   nm_connection_get_setting_vlan;
nm_connection_get_type;
nm_connection_get_uuid;
nm_connection_is_type;
@@ -464,6 +465,16 @@ global:
nm_utils_wifi_find_next_channel;
nm_utils_wifi_freq_to_channel;
nm_utils_wifi_is_channel_valid;
+   nm_setting_vlan_error_get_type;
+   nm_setting_vlan_error_quark;
+   nm_setting_vlan_get_type;
+   nm_setting_vlan_new;
+   nm_setting_vlan_get_interface_name;
+   nm_setting_vlan_get_slave;
+   nm_setting_vlan_get_id;
+   nm_setting_vlan_get_flags;
+   nm_setting_vlan_get_ingress_priority_map;
+   nm_setting_vlan_get_egress_priority_map;
 local:
*;
 };
diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c
index de6e948..e77f892 100644
--- a/libnm-util/nm-connection.c
+++ b/libnm-util/nm-connection.c
@@ -45,7 +45,7 @@
 #include "nm-setting-vpn.h"
 #include "nm-setting-olpc-mesh.h"
 #include "nm-setting-bond.h"
-
+#include "nm-setting-vlan.h"
 #include "nm-setting-serial.h"
 #include "nm-setting-gsm.h"
 #include "nm-setting-cdma.h"
@@ -136,7 +136,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
 
 static GHashTable *registered_settings = NULL;
 
-#define DEFAULT_MAP_SIZE 17
+#define DEFAULT_MAP_SIZE 18
 
 static struct SettingInfo {
const char *name;
@@ -248,6 +248,11 @@ register_default_settings (void)
  NM_SETTING_BOND_ERROR,
  1, TRUE);
 
+   register_one_setting (NM_SETTING_VLAN_SETTING_NAME,
+ NM_TYPE_SETTING_VLAN,
+ NM_SETTING_VLAN_ERROR,
+ 1, TRUE);
+
register_one_setting (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
  NM_TYPE_SETTING_WIRELESS_SECURITY,
  NM_SETTING_WIRELESS_SECURITY_ERROR,
@@ -1582,6 +1587,23 @@ nm_connection_get_setting_wireless_security 
(NMConnection *connection)
return (NMSettingWirelessSecurity *) nm_connection_get_setting 
(connection, NM_TYPE_SETTING_WIRELESS_SECURITY);
 }
 
+/**
+ * nm_connection_get_setting_vlan:
+ * @connection: the #NMConnection
+ *
+ * A shortcut to return any #NMSettingVlan the connection might contain.
+ *
+ * Returns: (transfer none): an #NMSettingVlan if the connection contains one, 
otherwise NULL
+ **/
+NMSettingVlan *
+nm_connection_get_setting_vlan (NMConnection 

[PATCH 5/5] vlan: add ifcfg-vlan writer

2011-11-20 Thread Weiping Pan
add write_vlan_setting() and modify test-ifcfg-rh.c to test it.

Signed-off-by: Weiping Pan 
---
 .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c |   38 
 src/settings/plugins/ifcfg-rh/writer.c |   90 
 2 files changed, 128 insertions(+), 0 deletions(-)

diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c 
b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index 4b84a59..3c72407 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -43,6 +43,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "nm-test-helpers.h"
 
@@ -11775,6 +11776,42 @@ test_read_vlan_interface (void)
g_free (route6file);
 }
 
+static void
+test_write_vlan(void)
+{
+   NMConnection *connection;
+   char *unmanaged = NULL;
+   char *keyfile = NULL;
+   char *routefile = NULL;
+   char *route6file = NULL;
+   gboolean ignore_error = FALSE;
+   GError *error = NULL;
+   gboolean success = FALSE;
+
+   connection = connection_from_file (TEST_IFCFG_VLAN_INTERFACE,
+  NULL,
+  TYPE_VLAN,
+  NULL,
+  &unmanaged,
+  &keyfile,
+  &routefile,
+  &route6file,
+  &error,
+  &ignore_error);
+   g_assert (connection != NULL);
+
+   success = writer_new_connection (connection,
+TEST_SCRATCH_DIR "/network-scripts/",
+NULL,
+&error);
+   g_assert (success);
+
+   g_free (unmanaged);
+   g_free (keyfile);
+   g_free (routefile);
+   g_free (route6file);
+}
+
 #define TEST_IFCFG_WIFI_OPEN_SSID_BAD_HEX 
TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex"
 #define TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED 
TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-quoted"
 #define TEST_IFCFG_WIFI_OPEN_SSID_LONG_HEX 
TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-hex"
@@ -11939,6 +11976,7 @@ int main (int argc, char **argv)
test_read_bridge_main ();
test_read_bridge_component ();
test_read_vlan_interface ();
+   test_write_vlan();
 
base = g_path_get_basename (argv[0]);
fprintf (stdout, "%s: SUCCESS\n", base);
diff --git a/src/settings/plugins/ifcfg-rh/writer.c 
b/src/settings/plugins/ifcfg-rh/writer.c
index 068bcda..9124e25 100644
--- a/src/settings/plugins/ifcfg-rh/writer.c
+++ b/src/settings/plugins/ifcfg-rh/writer.c
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "common.h"
@@ -1064,6 +1065,92 @@ write_wired_setting (NMConnection *connection, shvarFile 
*ifcfg, GError **error)
return TRUE;
 }
 
+static GString *vlan_priority_maplist_to_stringlist(const GSList *list)
+{
+   GString *text = NULL;
+   const GSList *iterator = NULL;
+   vlan_priority_map *item = NULL;
+   gsize len = 0;
+
+   g_return_val_if_fail(list != NULL, NULL);
+   text = g_string_new("");
+
+   for (iterator = list; iterator; iterator = iterator->next) {
+   item = (vlan_priority_map*)(iterator->data);
+   g_string_append_printf(text, "%d:%d,", item->from, item->to);
+   }
+
+   len = text->len;
+   g_string_truncate(text, --len);
+   return text;
+}
+
+static gboolean
+write_vlan_setting(NMConnection *connection, shvarFile *ifcfg, GError **error)
+{
+   NMSettingVlan *s_vlan;
+   const char *interface_name = NULL;
+   const char *vlan_slave = NULL;
+   guint32 vlan_flags = 0;
+   const GSList *list= NULL;
+   GString *text = NULL;
+
+   s_vlan = (NMSettingVlan *) nm_connection_get_setting (connection, 
NM_TYPE_SETTING_VLAN);
+   if (!s_vlan) {
+   g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+"Missing '%s' setting", 
NM_SETTING_VLAN_SETTING_NAME);
+   return FALSE;
+   }
+
+   svSetValue (ifcfg, "TYPE", TYPE_VLAN, FALSE);
+   svSetValue (ifcfg, "VLAN", "yes", FALSE);
+
+   interface_name = nm_setting_vlan_get_interface_name(s_vlan);
+   if (!interface_name)
+   return FALSE;
+   svSetValue (ifcfg, "DEVICE", interface_name, FALSE);
+
+   vlan_slave = nm_setting_vlan_get_slave(s_vlan);
+   if (!vlan_slave)
+   return FALSE;
+   svSetValue (ifcfg, "PHYSDEV", vlan_slave, FALSE);
+
+   vlan_flags = nm_setting_vlan_get_flags(s_vlan);
+   if (vlan_flags & NM_VLAN_FLAG_REORDER_HDR)
+   svSetValue (ifcfg, "REORDER_HDR", "1", FALSE);
+   else
+   svSetValue

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

2011-11-20 Thread Weiping Pan
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.

V2:
1 delete NMDeviceVlan, just use NMDeviceEthernet

Signed-off-by: Weiping Pan 
---
 src/nm-device-ethernet.c   |   34 +++---
 src/nm-device-ethernet.h   |1 +
 src/nm-udev-manager.c  |4 +++-
 src/settings/nm-settings.c |9 +
 4 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/src/nm-device-ethernet.c b/src/nm-device-ethernet.c
index b64a1da..0dd3992 100644
--- a/src/nm-device-ethernet.c
+++ b/src/nm-device-ethernet.c
@@ -56,6 +56,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"
@@ -616,6 +617,22 @@ nm_device_bond_connection_matches (NMDevice *device, 
NMConnection *connection)
return FALSE;
 }
 
+gboolean
+nm_device_vlan_connection_matches (NMDevice *device, NMConnection *connection)
+{
+   NMSettingVlan *s_vlan;
+   const char *devname;
+
+   devname = nm_device_get_iface (device);
+   g_assert(devname);
+
+   s_vlan = nm_connection_get_setting_vlan (connection);
+   if (s_vlan && !strcmp (devname, nm_setting_vlan_get_interface_name 
(s_vlan)))
+   return TRUE;
+
+   return FALSE;
+}
+
 /* Returns speed in Mb/s */
 static guint32
 nm_device_ethernet_get_speed (NMDeviceEthernet *self)
@@ -915,6 +932,13 @@ real_get_best_auto_connection (NMDevice *dev,
continue;
}

+   if (!strcmp (connection_type, NM_SETTING_VLAN_SETTING_NAME)) {
+   if (nm_device_vlan_connection_matches (dev, connection))
+   return connection;
+
+   continue;
+   }
+
if (!strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME))
is_pppoe = TRUE;
 
@@ -1650,7 +1674,7 @@ real_check_connection_compatible (NMDevice *device,
NMSettingConnection *s_con;
NMSettingWired *s_wired;
const char *connection_type;
-   gboolean is_pppoe = FALSE, is_bond = FALSE;
+   gboolean is_pppoe = FALSE, is_bond = FALSE, is_vlan = FALSE;
const GByteArray *mac;
gboolean try_mac = TRUE;
const GSList *mac_blacklist, *mac_blacklist_iter;
@@ -1661,10 +1685,11 @@ real_check_connection_compatible (NMDevice *device,
connection_type = nm_setting_connection_get_connection_type (s_con);
if (   strcmp (connection_type, NM_SETTING_WIRED_SETTING_NAME)
&& strcmp (connection_type, NM_SETTING_BOND_SETTING_NAME)
+   && strcmp (connection_type, NM_SETTING_VLAN_SETTING_NAME)
&& strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME)) {
g_set_error (error,
 NM_ETHERNET_ERROR, 
NM_ETHERNET_ERROR_CONNECTION_NOT_WIRED,
-"The connection was not a wired, bond, or PPPoE 
connection.");
+"The connection was not a wired, bond, vlan, or 
PPPoE connection.");
return FALSE;
}
 
@@ -1674,9 +1699,12 @@ real_check_connection_compatible (NMDevice *device,
if (!strcmp (connection_type, NM_SETTING_BOND_SETTING_NAME))
is_bond = TRUE;
 
+   if (!strcmp (connection_type, NM_SETTING_VLAN_SETTING_NAME))
+   is_vlan = TRUE;
+
s_wired = (NMSettingWired *) nm_connection_get_setting (connection, 
NM_TYPE_SETTING_WIRED);
/* Wired setting is optional for PPPoE */
-   if (!is_pppoe && !s_wired && !is_bond) {
+   if (!is_pppoe && !s_wired && !is_bond && !is_vlan) {
g_set_error (error,
 NM_ETHERNET_ERROR, 
NM_ETHERNET_ERROR_CONNECTION_INVALID,
 "The connection was not a valid wired 
connection.");
diff --git a/src/nm-device-ethernet.h b/src/nm-device-ethernet.h
index c7adbf8..9fe6765 100644
--- a/src/nm-device-ethernet.h
+++ b/src/nm-device-ethernet.h
@@ -64,6 +64,7 @@ void nm_device_ethernet_get_address (NMDeviceEthernet *dev,
  struct ether_addr *addr);
 
 gboolean nm_device_bond_connection_matches (NMDevice *device, NMConnection 
*connection);
+gboolean nm_device_vlan_connection_matches (NMDevice *device, NMConnection 
*connection);
 
 G_END_DECLS
 
diff --git a/src/nm-udev-manager.c b/src/nm-udev-manager.c
index ede39bb..c66bb9a 100644
--- a/src/nm-udev-manager.c
+++ b/src/nm-udev-manager.c
@@ -437,11 +437,13 @@ device_creator (NMUdevManager *manager,
if (type) {
if (g_strcmp0 (type, "bond") == 0)
driver = "bonding";
+   else if (g_strcmp0 (type, "vlan") == 0)
+

[PATCH 3/5] vlan: create/delete kernel vlan device

2011-11-20 Thread Weiping Pan
We make use of libnl (>=3.2.1) to create/delete kernel vlan device,
and it can set vlan id, vlan flags and ingress/egress priority mapping.

V2:
1 use existing nm_netlink_iface_to_index()

Signed-off-by: Weiping Pan 
---
 src/nm-system.c |  156 +++
 src/nm-system.h |5 ++-
 2 files changed, 160 insertions(+), 1 deletions(-)

diff --git a/src/nm-system.c b/src/nm-system.c
index 709a08b..8f9ddc8 100644
--- a/src/nm-system.c
+++ b/src/nm-system.c
@@ -59,6 +59,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #ifdef HAVE_LIBNL3
 #include 
@@ -1453,3 +1454,158 @@ nm_system_get_link_type (const char *name)
return type;
 }
 
+static void ingress_priority_iterator(gpointer data, gpointer user_data)
+{
+   struct rtnl_link *new_link = (struct rtnl_link *)user_data;
+   vlan_priority_map *item = (vlan_priority_map *)data;
+
+   g_return_if_fail (item != NULL);
+   g_return_if_fail (new_link!= NULL);
+
+   if ((item->from < 0) || (item->from > 7))
+   return;
+   rtnl_link_vlan_set_ingress_map(new_link, item->from, item->to);
+}
+
+static void egress_priority_iterator(gpointer data, gpointer user_data)
+{
+   struct rtnl_link *new_link = (struct rtnl_link *)user_data;
+   vlan_priority_map *item = (vlan_priority_map *)data;
+
+   g_return_if_fail (item != NULL);
+   g_return_if_fail (new_link!= NULL);
+
+   if ((item->to < 0) || (item->to > 7))
+   return;
+
+   rtnl_link_vlan_set_egress_map(new_link, item->from, item->to);
+}
+
+/**
+ * nm_system_add_vlan_device:
+ * @setting: NMSettingVlan
+ *
+ * Add a VLAN device specified in setting.
+ *
+ * Returns: %TRUE on success, or %FALSE
+ */
+gboolean
+nm_system_add_vlan_device(NMSettingVlan *setting)
+{
+   int ret = 0;
+   int if_index = 0;
+   struct rtnl_link *new_link = NULL;
+   struct nl_sock *nlh = NULL;
+   const GSList *list = NULL;
+
+   const char *interface_name = NULL;
+   const char *vlan_slave = NULL;
+   guint32 vlan_id = 0;
+   guint32 vlan_flags = 0;
+
+   g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), FALSE);
+
+   vlan_slave = nm_setting_vlan_get_slave(setting);
+   g_return_val_if_fail (vlan_slave != NULL, FALSE);
+
+   vlan_id = nm_setting_vlan_get_id(setting);
+   g_return_val_if_fail (vlan_id != 0, FALSE);
+   g_return_val_if_fail (vlan_id < 4096, FALSE);
+
+   nlh = nm_netlink_get_default_handle();
+   g_return_val_if_fail (nlh != NULL, FALSE);
+
+   interface_name = nm_setting_vlan_get_interface_name(setting);
+   g_return_val_if_fail (interface_name != NULL, FALSE);
+
+   if_index = nm_netlink_iface_to_index(interface_name);
+   g_return_val_if_fail (if_index > 0, FALSE);
+
+   new_link = rtnl_link_alloc();
+   g_return_val_if_fail (new_link != NULL, FALSE);
+
+   ret = rtnl_link_set_type(new_link, "vlan");
+   if (ret < 0)
+   goto free_new_link;
+
+   rtnl_link_set_link(new_link, if_index);
+   rtnl_link_set_name(new_link, interface_name);
+   rtnl_link_vlan_set_id(new_link, vlan_id);
+
+   vlan_flags = nm_setting_vlan_get_flags(setting);
+   if (vlan_flags)
+   rtnl_link_vlan_set_flags(new_link, vlan_flags);
+
+   list = nm_setting_vlan_get_ingress_priority_map(setting);
+   if (list != NULL)
+   g_slist_foreach((GSList *)list, 
(GFunc)ingress_priority_iterator, (gpointer)new_link);
+
+   list = nm_setting_vlan_get_egress_priority_map(setting);
+   if (list != NULL)
+   g_slist_foreach((GSList *)list, 
(GFunc)egress_priority_iterator, (gpointer)new_link);
+
+   ret = rtnl_link_add(nlh, new_link, NLM_F_CREATE);
+   if (ret < 0)
+   goto free_new_link;
+
+   rtnl_link_put(new_link);
+
+   return TRUE;
+
+free_new_link:
+   rtnl_link_put(new_link);
+
+   return FALSE;
+}
+
+/**
+ * nm_system_del_vlan_device:
+ * @setting: NMSettingVlan
+ *
+ * Delete a VLAN device specified in setting.
+ *
+ * Returns: %TRUE on success, or %FALSE
+ */
+gboolean
+nm_system_del_vlan_device(NMSettingVlan *setting)
+{
+   int ret = 0;
+   struct nl_sock *nlh = NULL;
+   struct nl_cache *cache = NULL;
+   struct rtnl_link *new_link = NULL;
+   const char *interface_name = NULL;
+
+   interface_name = nm_setting_vlan_get_interface_name(setting);
+   if (!interface_name)
+   return FALSE;
+
+   nlh = nm_netlink_get_default_handle();
+   if (!nlh)
+   return FALSE;
+
+   ret = rtnl_link_alloc_cache(nlh, &cache);
+   if (ret < 0)
+   return FALSE;
+
+   if (!cache)
+   return FALSE;
+
+   new_link = rtnl_link_get_by_name(cache, interface_name);
+   if (!new_link)
+   goto free_cache;
+
+   ret = rtnl_link_delete(nlh, new_link);
+   if (ret < 0)
+   goto free_new_link;
+
+   rt

[PATCH 1/5] configure: use correct if defined

2011-11-20 Thread Weiping Pan
I only install libnl-3.2.3 on my system, and I met an error:

In file included from ../../src/nm-netlink-monitor.h:93:0,
from nm-vpn-connection.c:48:
../../src/nm-netlink-compat.h:210:5: error: "HAVE_LIBNL1" is not defined
../../src/nm-netlink-compat.h:210:20: error: "HAVE_LIBNL2" is not defined
make[5]: *** [libvpn_manager_la-nm-vpn-connection.lo] Error 1

Signed-off-by: Weiping Pan 
---
 src/nm-netlink-compat.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/nm-netlink-compat.h b/src/nm-netlink-compat.h
index 5038851..2ed99d5 100644
--- a/src/nm-netlink-compat.h
+++ b/src/nm-netlink-compat.h
@@ -207,7 +207,7 @@ __nl_cache_include (struct nl_cache *cache, struct 
nl_object *obj, change_func_t
 #endif  /* HAVE_LIBNL1 */
 
 /* Stuff that only libnl3 has */
-#if HAVE_LIBNL1 || HAVE_LIBNL2
+#if defined(HAVE_LIBNL1) || defined(HAVE_LIBNL2)
 
 static inline int
 rtnl_link_bond_add (struct nl_sock *h, const char *name, void *data)
-- 
1.7.4.4

___
networkmanager-list mailing list
networkmanager-list@gnome.org
http://mail.gnome.org/mailman/listinfo/networkmanager-list


[PATCH 0/5] vlan support for NetworkManager(V2)

2011-11-20 Thread Weiping Pan
This patchset is to add vlan support for NetworkManager,
based on nm/bonding branch, commit 6b1d0ca510d2(bonding:
don't fall back to DHCP if IP config is missing).

Requires libnl-3.2.1

FEATURE DESCRIPTION
1 example of vlan ifcfg file
We try to make it compitable with the format used by initscripts,
and there is no need to change anything for ifcfg-eth9.

vlan=yes
TYPE=vlan
DEVICE=vlan43
PHYSDEV=eth9
REORDER_HDR=0
vlan_FLAGS=GVRP,LOOSE_BINDING
vlan_INGRESS_PRIORITY_MAP=0:1,2:5
vlan_EGRESS_PRIORITY_MAP=12:3,14:7
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.43.149
NETMASK=255.255.255.0

2 create and delete vlan device
We use libnl to create and delete vlan device in kernel.

3 support both static IP configuration and DHCP for vlan device

TODO
1 accept MAC address or NM connection UUID as PHYSDEV

2 activating dependency
Before activating a vlan device, we should make sure that the underlying
physical ethernet device is up.
For example, before activating eth0.100, we should make sure that eth0 is up.
NetworkManager calls g_udev_client_query_by_subsystem() to get the device
list, and then activates each devices on that device list.
And luckily I found that the physical ethernet device is prior to vlan device
on that device list, so there is nothing to do to make sure the activating
sequence between a vlan device and its underlying physical ethernet device.

Maybe we should not rely on the behavior of
g_udev_client_query_by_subsystem(), and we should add special restriction to
make sure that before activating a vlan device, the underlying physical 
ethernet device is up.

Changelog:
V2:
1 rebase on nm/bonding branch
2 use "vlan" or "Vlan" instead of "VLAN" for consistency.
3 use GSList to store vlan ingress/egress priority map.
4 add enum NMVlanFlags.
5 delete NMDeviceVLAN, just use NMDeviceEthernet.
6 add ifcfg-vlan writer

Weiping Pan (5):
  configure: use correct if defined
  vlan: add ifcfg-vlan parser
  vlan: create/delete kernel vlan device
  vlan: create NMDeviceEthernet for vlan device
  vlan: add ifcfg-vlan writer

 libnm-util/Makefile.am |2 +
 libnm-util/libnm-util.ver  |   11 +
 libnm-util/nm-connection.c |   26 +-
 libnm-util/nm-connection.h |2 +
 libnm-util/nm-setting-vlan.c   |  584 
 libnm-util/nm-setting-vlan.h   |  118 
 src/nm-device-ethernet.c   |   34 +-
 src/nm-device-ethernet.h   |1 +
 src/nm-netlink-compat.h|2 +-
 src/nm-system.c|  156 ++
 src/nm-system.h|5 +-
 src/nm-udev-manager.c  |4 +-
 src/settings/nm-settings.c |9 +
 src/settings/plugins/ifcfg-rh/common.h |1 +
 src/settings/plugins/ifcfg-rh/reader.c |  179 ++-
 .../network-scripts/ifcfg-test-vlan-interface  |   11 +-
 .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c |   41 ++-
 src/settings/plugins/ifcfg-rh/writer.c |   90 +++
 18 files changed, 1251 insertions(+), 25 deletions(-)
 create mode 100644 libnm-util/nm-setting-vlan.c
 create mode 100644 libnm-util/nm-setting-vlan.h

-- 
1.7.4.4

___
networkmanager-list mailing list
networkmanager-list@gnome.org
http://mail.gnome.org/mailman/listinfo/networkmanager-list


Re: [PATCH 4/6] VLAN: add NMDeviceVLAN

2011-11-20 Thread Weiping Pan

On 11/18/2011 04:28 AM, Dan Williams wrote:

On Wed, 2011-11-16 at 16:54 +0800, Weiping Pan wrote:

On 11/16/2011 01:54 PM, Dan Williams wrote:

On Fri, 2011-10-21 at 09:52 +0800, Weiping Pan wrote:

NMDeviceVLAN represents a VLAN device in NetworkManager.
When a VLAN device is created in kernel, NetworkManager will receive the event
and create a corresponding NMDeviceVLAN.

Like the setting, let's use NMDeviceVlan here for consistency.


Ok.

Signed-off-by: Weiping Pan
---
  include/NetworkManager.h |1 +
  src/Makefile.am  |2 +
  src/nm-device-vlan.c |  330 ++
  src/nm-device-vlan.h |   59 
  4 files changed, 392 insertions(+), 0 deletions(-)
  create mode 100644 src/nm-device-vlan.c
  create mode 100644 src/nm-device-vlan.h

diff --git a/include/NetworkManager.h b/include/NetworkManager.h
index 3522dd2..87d7d7f 100644
--- a/include/NetworkManager.h
+++ b/include/NetworkManager.h
@@ -114,6 +114,7 @@ typedef enum {
NM_DEVICE_TYPE_OLPC_MESH = 6,
NM_DEVICE_TYPE_WIMAX = 7,
NM_DEVICE_TYPE_MODEM = 8,
+   NM_DEVICE_TYPE_VLAN  = 9,
  } NMDeviceType;

  /**
diff --git a/src/Makefile.am b/src/Makefile.am
index cbcfdc6..e086024 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -126,6 +126,8 @@ NetworkManager_SOURCES = \
nm-device-bt.h \
nm-device-modem.h \
nm-device-modem.c \
+   nm-device-vlan.h \
+   nm-device-vlan.c \
nm-wifi-ap.c \
nm-wifi-ap.h \
nm-wifi-ap-utils.c \
diff --git a/src/nm-device-vlan.c b/src/nm-device-vlan.c
new file mode 100644
index 000..23abdbc
--- /dev/null
+++ b/src/nm-device-vlan.c
@@ -0,0 +1,330 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager -- Network link manager
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2011 Red Hat, Inc.
+ */
+
+#include
+#include
+
+#include "nm-system.h"
+#include "nm-device-vlan.h"
+#include "nm-device-interface.h"
+#include "nm-device-private.h"
+#include "nm-properties-changed-signal.h"
+#include "nm-marshal.h"
+#include "nm-logging.h"
+
+static void device_interface_init (NMDeviceInterface *iface_class);
+
+G_DEFINE_TYPE_EXTENDED (NMDeviceVLAN, nm_device_vlan, NM_TYPE_DEVICE, 0,
+G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_INTERFACE, 
device_interface_init))
+
+#define NM_DEVICE_VLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), 
NM_TYPE_DEVICE_VLAN, NMDeviceVLANPrivate))
+
+typedef struct {
+   char *interface_name;
+   guint32 vlan_id;
+   guint32 vlan_flags;
+   char *vlan_priority_ingress_map;
+   char *vlan_priority_egress_map;
+} NMDeviceVLANPrivate;
+
+enum {
+   PROP_0,
+   PROP_INTERFACE_NAME,
+   PROP_VLAN_ID,
+   PROP_VLAN_FLAGS,
+   PROP_VLAN_PRIORITY_INGRESS_MAP,
+   PROP_VLAN_PRIORITY_EGRESS_MAP,
+   LAST_PROP
+};

So for properties on the device (which get exported over D-Bus) it's
really only useful to have properties that clients are going to be
interested in; are all these properties interesting ones, or are they
mainly implementation details?  Clients can get most of these properties
from the NMSettingVlan itself since they aren't going to change while
the interface is activated.  Especially INTERFACE_NAME; that's already
handled by the parent class' 'interface' property.  Basically, if a
property isn't going to change while the interface is activated/up, it
probably shouldn't be a property of the device, but clients can get it
via the connection data itself.  We can always add device properties
later if we find clients want them for some reason, but we can't really
take them away.


When a vlan device is up, the client can only change
+   PROP_VLAN_FLAGS,
+   PROP_VLAN_PRIORITY_INGRESS_MAP,
+   PROP_VLAN_PRIORITY_EGRESS_MAP,

I test them with command vconfig.

I thought the client could change the name of vlan device,
either through "ip link set p2p4 name pwp", or  rtnl_link_set_name(),
but both methods can work when the device is down.
So, I can remove PROP_INTERFACE_NAME and PROP_VLAN_ID here.

Are flags likely to change?  How likely is it that these values would
change