diff options
author | Weiping Pan <wpan@redhat.com> | 2011-12-12 22:20:56 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2012-02-16 15:05:55 -0600 |
commit | 23c1b6ad30c016d856c0c5412afa7bc57e424e83 (patch) | |
tree | fb754dec806ae32a58b3c62e13cd26a834d2b1e5 /libnm-util | |
parent | 3f963d308adb20271597d07644470367db261ef7 (diff) |
libnm-util: add VLAN setting and properties
Signed-off-by: Weiping Pan <wpan@redhat.com>
(dcbw: formatting cleanups and priority map code simplifications)
Diffstat (limited to 'libnm-util')
-rw-r--r-- | libnm-util/Makefile.am | 2 | ||||
-rw-r--r-- | libnm-util/libnm-util.ver | 17 | ||||
-rw-r--r-- | libnm-util/nm-connection.c | 26 | ||||
-rw-r--r-- | libnm-util/nm-connection.h | 2 | ||||
-rw-r--r-- | libnm-util/nm-setting-vlan.c | 589 | ||||
-rw-r--r-- | libnm-util/nm-setting-vlan.h | 142 |
6 files changed, 776 insertions, 2 deletions
diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am index 2ccf1bdca9..a4272881f5 100644 --- a/libnm-util/Makefile.am +++ b/libnm-util/Makefile.am @@ -21,6 +21,7 @@ libnm_util_include_HEADERS = \ nm-setting-connection.h \ nm-setting-infiniband.h \ nm-setting-ip4-config.h \ + nm-setting-vlan.h \ nm-setting-ip6-config.h \ nm-setting-ppp.h \ nm-setting-pppoe.h \ @@ -53,6 +54,7 @@ libnm_util_la_csources = \ nm-setting-connection.c \ nm-setting-infiniband.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 f2c8b10d63..5e4d19ee75 100644 --- a/libnm-util/libnm-util.ver +++ b/libnm-util/libnm-util.ver @@ -28,6 +28,7 @@ global: nm_connection_get_setting_ppp; nm_connection_get_setting_pppoe; nm_connection_get_setting_serial; + nm_connection_get_setting_vlan; nm_connection_get_setting_vpn; nm_connection_get_setting_wimax; nm_connection_get_setting_wired; @@ -367,6 +368,20 @@ global: nm_setting_to_string; nm_setting_update_secrets; nm_setting_verify; + nm_setting_vlan_add_priority; + nm_setting_vlan_add_priority_str; + nm_setting_vlan_clear_priorities; + nm_setting_vlan_error_get_type; + nm_setting_vlan_error_quark; + nm_setting_vlan_get_flags; + nm_setting_vlan_get_id; + nm_setting_vlan_get_interface_name; + nm_setting_vlan_get_num_priorities; + nm_setting_vlan_get_priority; + nm_setting_vlan_get_slave; + nm_setting_vlan_get_type; + nm_setting_vlan_new; + nm_setting_vlan_remove_priority; nm_setting_vpn_add_data_item; nm_setting_vpn_add_secret; nm_setting_vpn_error_get_type; @@ -494,6 +509,8 @@ global: nm_utils_wifi_find_next_channel; nm_utils_wifi_freq_to_channel; nm_utils_wifi_is_channel_valid; + nm_vlan_flags_get_type; + nm_vlan_priority_map_get_type; nm_wep_key_type_get_type; local: *; diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c index b4b6f9d8a1..13099998fa 100644 --- a/libnm-util/nm-connection.c +++ b/libnm-util/nm-connection.c @@ -47,7 +47,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" @@ -117,7 +117,7 @@ static guint signals[LAST_SIGNAL] = { 0 }; static GHashTable *registered_settings = NULL; -#define DEFAULT_MAP_SIZE 18 +#define DEFAULT_MAP_SIZE 19 static struct SettingInfo { const char *name; @@ -234,6 +234,11 @@ register_default_settings (void) NM_SETTING_INFINIBAND_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, @@ -1653,6 +1658,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 *connection) +{ + g_return_val_if_fail (connection != NULL, NULL); + g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); + + return (NMSettingVlan *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VLAN); +} + /*************************************************************/ static void diff --git a/libnm-util/nm-connection.h b/libnm-util/nm-connection.h index 77f59eafc7..def022e765 100644 --- a/libnm-util/nm-connection.h +++ b/libnm-util/nm-connection.h @@ -48,6 +48,7 @@ #include <nm-setting-wired.h> #include <nm-setting-wireless.h> #include <nm-setting-wireless-security.h> +#include <nm-setting-vlan.h> G_BEGIN_DECLS @@ -201,6 +202,7 @@ NMSettingWimax * nm_connection_get_setting_wimax (NMConnec NMSettingWired * nm_connection_get_setting_wired (NMConnection *connection); NMSettingWireless * nm_connection_get_setting_wireless (NMConnection *connection); NMSettingWirelessSecurity *nm_connection_get_setting_wireless_security (NMConnection *connection); +NMSettingVlan * nm_connection_get_setting_vlan (NMConnection *connection); G_END_DECLS diff --git a/libnm-util/nm-setting-vlan.c b/libnm-util/nm-setting-vlan.c new file mode 100644 index 0000000000..0fe9a955b8 --- /dev/null +++ b/libnm-util/nm-setting-vlan.c @@ -0,0 +1,589 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ + +/* + * Weiping Pan <wpan@redhat.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * (C) Copyright 2011 Red Hat, Inc. + */ + +#include <dbus/dbus-glib.h> +#include "nm-setting-vlan.h" +#include "nm-param-spec-specialized.h" +#include "nm-utils.h" +#include "nm-dbus-glib-types.h" + +/** + * SECTION:nm-setting-vlan + * @short_description: Describes connection properties for VLAN interfaces + * @include: nm-setting-vlan.h + * + * The #NMSettingVlan object is a #NMSetting subclass that describes properties + * necessary for connection to VLAN interfaces. + **/ + +/** + * nm_setting_vlan_error_quark: + * + * Registers an error quark for #NMSettingVlan if necessary. + * + * Returns: the error quark used for #NMSettingVlan errors. + **/ +GQuark +nm_setting_vlan_error_quark (void) +{ + static GQuark quark; + + if (G_UNLIKELY (!quark)) + quark = g_quark_from_static_string ("nm-setting-vlan-error-quark"); + return quark; +} + +G_DEFINE_TYPE (NMSettingVlan, nm_setting_vlan, NM_TYPE_SETTING) + +#define NM_SETTING_VLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_VLAN, NMSettingVlanPrivate)) + +typedef struct { + char *iface_name; + char *slave; + guint32 id; + guint32 flags; + GSList *ingress_priority_map; + GSList *egress_priority_map; +} NMSettingVlanPrivate; + +enum { + PROP_0, + PROP_IFACE_NAME, + PROP_SLAVE, + PROP_ID, + PROP_FLAGS, + PROP_INGRESS_PRIORITY_MAP, + PROP_EGRESS_PRIORITY_MAP, + LAST_PROP +}; + +typedef struct { + guint32 from; + guint32 to; +} PriorityMap; + +/** + * nm_setting_vlan_new: + * Creates a new #NMSettingVlan object with default values. + * + * Returns: (transfer full): the new empty #NMSettingVlan object + **/ +NMSetting * +nm_setting_vlan_new (void) +{ + return (NMSetting *) g_object_new (NM_TYPE_SETTING_VLAN, NULL); +} + +/** + * nm_setting_vlan_get_interface_name: + * @setting: the #NMSettingVlan + * + * Returns: the #NMSettingVlan:interface_name property of the setting + **/ +const char * +nm_setting_vlan_get_interface_name (NMSettingVlan *setting) +{ + g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), NULL); + return NM_SETTING_VLAN_GET_PRIVATE (setting)->iface_name; +} + +/** + * nm_setting_vlan_get_slave: + * @setting: the #NMSettingVlan + * + * Returns: the #NMSettingVlan:slave property of the setting + **/ +const char * +nm_setting_vlan_get_slave (NMSettingVlan *setting) +{ + g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), NULL); + return NM_SETTING_VLAN_GET_PRIVATE (setting)->slave; +} + +/** + * nm_setting_vlan_get_id: + * @setting: the #NMSettingVlan + * + * Returns: the #NMSettingVlan:id property of the setting + **/ +guint32 +nm_setting_vlan_get_id (NMSettingVlan *setting) +{ + g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), 0); + return NM_SETTING_VLAN_GET_PRIVATE (setting)->id; +} + +/** + * nm_setting_vlan_get_flags: + * @setting: the #NMSettingVlan + * + * Returns: the #NMSettingVlan:flags property of the setting + **/ +guint32 +nm_setting_vlan_get_flags (NMSettingVlan *setting) +{ + g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), 0); + return NM_SETTING_VLAN_GET_PRIVATE (setting)->flags; +} + +static PriorityMap * +priority_map_new_from_str (const char *str) +{ + PriorityMap *p = NULL; + gchar **t = NULL; + guint32 len; + + g_return_val_if_fail (str && str[0], NULL); + + t = g_strsplit (str, ":", 0); + len = g_strv_length (t); + if (len == 2) { + p = g_malloc0 (sizeof (PriorityMap)); + p->from = g_ascii_strtoull (t[0], NULL, 10); + p->to = g_ascii_strtoull (t[1], NULL, 10); + } else { + /* Warn */ + g_warn_if_fail (len == 2); + } + + g_strfreev (t); + return p; +} + +static void +priority_map_free (PriorityMap *map) +{ + g_return_if_fail (map != NULL); + g_free (map); +} + +static GSList * +get_map (NMSettingVlan *self, NMVlanPriorityMap map) +{ + if (map == NM_VLAN_INGRESS_MAP) + return NM_SETTING_VLAN_GET_PRIVATE (self)->ingress_priority_map; + else if (map == NM_VLAN_EGRESS_MAP) + return NM_SETTING_VLAN_GET_PRIVATE (self)->egress_priority_map; + g_assert_not_reached (); + return NULL; +} + +static void +set_map (NMSettingVlan *self, NMVlanPriorityMap map, GSList *list) +{ + if (map == NM_VLAN_INGRESS_MAP) + NM_SETTING_VLAN_GET_PRIVATE (self)->ingress_priority_map = list; + else if (map == NM_VLAN_EGRESS_MAP) + NM_SETTING_VLAN_GET_PRIVATE (self)->egress_priority_map = list; + g_assert_not_reached (); +} + +/** + * nm_setting_vlan_add_priority_str + * @setting: the #NMSettingVlan + * @map: the type of priority map + * @str: the string which contains a priority map, like "3:7" + * + * Adds a priority map entry into either the #NMSettingVlan:ingress_priority_map + * or the #NMSettingVlan:egress_priority_map properties. The priority map maps + * the Linux 'skb' priority values to VLAN QoS values. + * + * Returns: TRUE if the entry was successfully added to the list, or it + * overwrote the old value, FALSE if error + */ +gboolean +nm_setting_vlan_add_priority_str (NMSettingVlan *setting, + NMVlanPriorityMap map, + const char *str) +{ + NMSettingVlanPrivate *priv = NULL; + GSList *list = NULL, *iter = NULL; + PriorityMap *item = NULL; + + g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), FALSE); + g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, FALSE); + g_return_val_if_fail (str && str[0], FALSE); + + priv = NM_SETTING_VLAN_GET_PRIVATE (setting); + list = get_map (setting, map); + g_assert (list); + + item = priority_map_new_from_str (str); + g_return_val_if_fail (item != NULL, FALSE); + + /* Duplicates get replaced */ + for (iter = list; iter; iter = g_slist_next (iter)) { + PriorityMap *p = iter->data; + + if (p->from == item->from) { + p->to = item->to; + g_free (item); + return TRUE; + } + } + + set_map (setting, map, g_slist_append (list, item)); + return TRUE; +} + +/** + * nm_setting_vlan_get_num_priorities: + * @map: the type of priority map + * @setting: the #NMSettingVlan + * + * Returns the number of entires in the + * #NMSettingVlan:ingress_priority_map or #NMSettingVlan:egress_priority_map + * properties of this setting. + * + * Returns: return the number of ingress/egress priority entries, -1 if error + **/ +gint32 +nm_setting_vlan_get_num_priorities (NMSettingVlan *setting, NMVlanPriorityMap map) +{ + g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), -1); + g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, -1); + + return g_slist_length (get_map (setting, map)); +} + +/** + * nm_setting_vlan_get_priority: + * @map: the type of priority map + * @setting: the #NMSettingVlan + * @idx: the zero-based index of the ingress/egress priority map entry + * @out_from: (out): on return the value of the priority map's 'from' item + * @out_to: (out): on return the value of priority map's 'to' item + * + * Retrieve one of the entries of the #NMSettingVlan:ingress_priority_map + * or #NMSettingVlan:egress_priority_map properties of this setting. + * + * Returns: %TRUE if a priority map was returned, %FALSE if error + **/ +gboolean +nm_setting_vlan_get_priority (NMSettingVlan *setting, + NMVlanPriorityMap map, + guint32 idx, + guint32 *out_from, + guint32 *out_to) +{ + GSList *list = NULL; + PriorityMap *item = NULL; + + g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), FALSE); + g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, FALSE); + g_return_val_if_fail (out_from != NULL, FALSE); + g_return_val_if_fail (out_to != NULL, FALSE); + + list = get_map (setting, map); + g_return_val_if_fail (idx < g_slist_length (list), FALSE); + + item = g_slist_nth_data (list, idx); + g_assert (item); + *out_from = item->from; + *out_to = item->to; + return TRUE; +} + +/** + * nm_setting_vlan_add_priority: + * @map: the type of priority map + * @setting: the #NMSettingVlan + * @from: the Linux 'skb' priority value to map to VLAN QoS value @to + * @to: the VLAN QoS value to map the Linux 'skb' priority value @from to + * + * Adds a priority mapping to the #NMSettingVlan:ingress_priority_map or + * #NMSettingVlan:egress_priority_map properties of the setting. If @from is + * already in the given priority map, this function will overwrite the + * existing entry with the new @to. + * + * Returns: TRUE if the new priority mapping was successfully added to the + * list, FALSE if error + */ +gboolean +nm_setting_vlan_add_priority (NMSettingVlan *setting, + NMVlanPriorityMap map, + guint32 from, + guint32 to) +{ + GSList *list = NULL, *iter = NULL; + PriorityMap *item; + + g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), FALSE); + g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, FALSE); + + list = get_map (setting, map); + for (iter = list; iter; iter = g_slist_next (iter)) { + item = iter->data; + if (item->from == from) { + item->to = to; + return TRUE; + } + } + + item = g_malloc0 (sizeof (PriorityMap)); + item->from = from; + item->to = to; + set_map (setting, map, g_slist_append (list, item)); + + return TRUE; +} + +/** + * nm_setting_vlan_remove_priority: + * @map: the type of priority map + * @setting: the #NMSettingVlan + * @idx: the zero-based index of the priority map to remove + * + * Removes the priority map at index @idx from the + * #NMSettingVlan:ingress_priority_map or #NMSettingVlan:egress_priority_map + * properties. + */ +void +nm_setting_vlan_remove_priority (NMSettingVlan *setting, + NMVlanPriorityMap map, + guint32 idx) +{ + GSList *list = NULL, *item = NULL; + + g_return_if_fail (NM_IS_SETTING_VLAN (setting)); + g_return_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP); + + list = get_map (setting, map); + g_return_if_fail (idx < g_slist_length (list)); + + item = g_slist_nth_data (list, idx); + priority_map_free ((PriorityMap *) item); + set_map (setting, map, g_slist_delete_link (list, item)); +} + +/** + * nm_setting_vlan_clear_priorities: + * @map: the type of priority map + * @setting: the #NMSettingVlan + * + * Clear all the entires from #NMSettingVlan:ingress_priority_map or + * #NMSettingVlan:egress_priority_map properties. + */ +void +nm_setting_vlan_clear_priorities (NMSettingVlan *setting, NMVlanPriorityMap map) +{ + GSList *list = NULL; + + g_return_if_fail (NM_IS_SETTING_VLAN (setting)); + g_return_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP); + + list = get_map (setting, map); + nm_utils_slist_free (list, g_free); + set_map (setting, map, NULL); +} + +/*********************************************************************/ + +static void +nm_setting_vlan_init (NMSettingVlan *setting) +{ + g_object_set (setting, NM_SETTING_NAME, NM_SETTING_VLAN_SETTING_NAME, NULL); +} + +static const char * +get_virtual_iface_name (NMSetting *setting) +{ + return nm_setting_vlan_get_interface_name (NM_SETTING_VLAN (setting)); +} + +static GSList * +priority_stringlist_to_maplist (GSList *strlist) +{ + GSList *list = NULL, *iter; + + for (iter = strlist; iter; iter = g_slist_next (iter)) { + PriorityMap *item; + + item = priority_map_new_from_str ((const char *) iter->data); + if (item) + list = g_slist_prepend (list, item); + } + return g_slist_reverse (list); +} + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NMSettingVlan *setting = NM_SETTING_VLAN (object); + NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting); + + switch (prop_id) { + case PROP_IFACE_NAME: + g_free (priv->iface_name); + priv->iface_name = g_value_dup_string (value); + break; + case PROP_SLAVE: + g_free (priv->slave); + priv->slave = g_value_dup_string (value); + break; + case PROP_ID: + priv->id = g_value_get_uint (value); + break; + case PROP_FLAGS: + priv->flags = g_value_get_uint (value); + break; + case PROP_INGRESS_PRIORITY_MAP: + nm_utils_slist_free (priv->ingress_priority_map, g_free); + priv->ingress_priority_map = + priority_stringlist_to_maplist (g_value_get_boxed (value)); + break; + case PROP_EGRESS_PRIORITY_MAP: + nm_utils_slist_free (priv->egress_priority_map, g_free); + priv->egress_priority_map = + priority_stringlist_to_maplist (g_value_get_boxed (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GSList * +priority_maplist_to_stringlist (GSList *list) +{ + GSList *strlist = NULL, *iter; + + for (iter = list; iter; iter = g_slist_next (iter)) { + PriorityMap *item = iter->data; + + strlist = g_slist_prepend (strlist, g_strdup_printf ("%d:%d", item->from, item->to)); + } + return g_slist_reverse (strlist); +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + NMSettingVlan *setting = NM_SETTING_VLAN (object); + NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting); + + switch (prop_id) { + case PROP_IFACE_NAME: + g_value_set_string (value, priv->iface_name); + break; + case PROP_SLAVE: + g_value_set_string (value, priv->slave); + break; + case PROP_ID: + g_value_set_uint (value, priv->id); + break; + case PROP_FLAGS: + g_value_set_uint (value, priv->flags); + break; + case PROP_INGRESS_PRIORITY_MAP: + g_value_take_boxed (value, priority_maplist_to_stringlist (priv->ingress_priority_map)); + break; + case PROP_EGRESS_PRIORITY_MAP: + g_value_take_boxed (value, priority_maplist_to_stringlist (priv->egress_priority_map)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +finalize (GObject *object) +{ + NMSettingVlan *setting = NM_SETTING_VLAN (object); + NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting); + + g_free (priv->iface_name); + g_free (priv->slave); + nm_utils_slist_free (priv->ingress_priority_map, g_free); + nm_utils_slist_free (priv->egress_priority_map, g_free); +} + +static void +nm_setting_vlan_class_init (NMSettingVlanClass *setting_class) +{ + GObjectClass *object_class = G_OBJECT_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 + (object_class, PROP_IFACE_NAME, + g_param_spec_string (NM_SETTING_VLAN_INTERFACE_NAME, + "InterfaceName", + "The vlan device name in kernel", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); + + g_object_class_install_property + (object_class, PROP_SLAVE, + g_param_spec_string (NM_SETTING_VLAN_SLAVE, + "vlan slave", + "The underlying physical ethernet device", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); + + g_object_class_install_property + (object_class, PROP_ID, + g_param_spec_uint (NM_SETTING_VLAN_ID, + "vlan id", + "vlan id", + 0, + 4095, + 0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); + + g_object_class_install_property + (object_class, PROP_FLAGS, + g_param_spec_uint (NM_SETTING_VLAN_FLAGS, + "vlan flags", + "vlan flags", + 0, + G_MAXUINT32, + 0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); + + g_object_class_install_property + (object_class, PROP_INGRESS_PRIORITY_MAP, + _nm_param_spec_specialized (NM_SETTING_VLAN_INGRESS_PRIORITY_MAP, + "vlan ingress priority mapping", + "vlan ingress priority mapping", + DBUS_TYPE_G_LIST_OF_STRING, + G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + + g_object_class_install_property + (object_class, PROP_EGRESS_PRIORITY_MAP, + _nm_param_spec_specialized (NM_SETTING_VLAN_EGRESS_PRIORITY_MAP, + "vlan egress priority mapping", + "vlan egress priority mapping", + DBUS_TYPE_G_LIST_OF_STRING, + G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); +} diff --git a/libnm-util/nm-setting-vlan.h b/libnm-util/nm-setting-vlan.h new file mode 100644 index 0000000000..fb238a0f43 --- /dev/null +++ b/libnm-util/nm-setting-vlan.h @@ -0,0 +1,142 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ + +/* + * Weiping Pan <wpan@redhat.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * (C) Copyright 2011 Red Hat, Inc. + */ + +#ifndef NM_SETTING_VLAN_H +#define NM_SETTING_VLAN_H + +#include "nm-setting.h" +#include <linux/if_vlan.h> + +G_BEGIN_DECLS + +#define NM_TYPE_SETTING_VLAN (nm_setting_vlan_get_type ()) +#define NM_SETTING_VLAN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_VLAN, NMSettingVlan)) +#define NM_SETTING_VLAN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_VLANCONFIG, NMSettingVlanClass)) +#define NM_IS_SETTING_VLAN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_VLAN)) +#define NM_IS_SETTING_VLAN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_SETTING_VLAN)) +#define NM_SETTING_VLAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_VLAN, NMSettingVlanClass)) + +#define NM_SETTING_VLAN_SETTING_NAME "vlan" + +/** + * NMSettingVlanError: + * @NM_SETTING_VLAN_ERROR_UNKNOWN: unknown or unclassified error + * @NM_SETTING_VLAN_ERROR_INVALID_PROPERTY: the property was invalid + * @NM_SETTING_VLAN_ERROR_MISSING_PROPERTY: the property was missing and is + * required + */ +typedef enum { + NM_SETTING_VLAN_ERROR_UNKNOWN = 0, + NM_SETTING_VLAN_ERROR_INVALID_PROPERTY, + NM_SETTING_VLAN_ERROR_MISSING_PROPERTY +} NMSettingVlanError; + +#define NM_SETTING_VLAN_ERROR nm_setting_vlan_error_quark () +GQuark nm_setting_vlan_error_quark (void); + +#define NM_SETTING_VLAN_INTERFACE_NAME "interface-name" +#define NM_SETTING_VLAN_SLAVE "slave" +#define NM_SETTING_VLAN_ID "id" +#define NM_SETTING_VLAN_FLAGS "flags" +#define NM_SETTING_VLAN_INGRESS_PRIORITY_MAP "ingress-priority-map" +#define NM_SETTING_VLAN_EGRESS_PRIORITY_MAP "egress-priority-map" + +typedef struct { + NMSetting parent; +} NMSettingVlan; + +typedef struct { + NMSettingClass parent; + + /* Padding for future expansion */ + void (*_reserved1) (void); + void (*_reserved2) (void); + void (*_reserved3) (void); + void (*_reserved4) (void); +} NMSettingVlanClass; + +/** + * NMVlanPriorityMap: + * @NM_VLAN_INGRESS_MAP: map for incoming data + * @NM_VLAN_EGRESS_MAP: map for outgoing data + * + * A selector for traffic QoS priority maps; these map outgoing packet priorities + * to VLAN QoS priorities. + **/ +typedef enum { + NM_VLAN_INGRESS_MAP, + NM_VLAN_EGRESS_MAP +} NMVlanPriorityMap; + +/** + * NMVlanFlags: + * @NM_VLAN_FLAG_REORDER_HEADERS: indicates that this interface should reorder + * outgoing packet headers to look more like a non-VLAN ethernet interface + * @NM_VLAN_FLAG_GVRP: indicates that this interface should use GVRP to register + * itself with it's switch + * @NM_VLAN_FLAG_LOOSE_BINDING: indicates that this interface's operating + * state is tied to the underlying network interface but other details + * (like routing) are not. + * + * #NMVlanFlags values control the behavior of the VLAN interface. + **/ +typedef enum { + NM_VLAN_FLAG_REORDER_HEADERS = 0x1, + NM_VLAN_FLAG_GVRP = 0x2, + NM_VLAN_FLAG_LOOSE_BINDING = 0x4, +} NMVlanFlags; + +GType nm_setting_vlan_get_type (void); +NMSetting *nm_setting_vlan_new (void); + +const char *nm_setting_vlan_get_interface_name (NMSettingVlan *setting); +const char *nm_setting_vlan_get_slave (NMSettingVlan *setting); +guint32 nm_setting_vlan_get_id (NMSettingVlan *setting); +guint32 nm_setting_vlan_get_flags (NMSettingVlan *setting); + +gint32 nm_setting_vlan_get_num_priorities (NMSettingVlan *setting, NMVlanPriorityMap map); + +gboolean nm_setting_vlan_get_priority (NMSettingVlan *setting, + NMVlanPriorityMap map, + guint32 idx, + guint32 *out_from, + guint32 *out_to); + +gboolean nm_setting_vlan_add_priority (NMSettingVlan *setting, + NMVlanPriorityMap map, + guint32 from, + guint32 to); + +void nm_setting_vlan_remove_priority (NMSettingVlan *setting, + NMVlanPriorityMap map, + guint32 idx); + +void nm_setting_vlan_clear_priorities (NMSettingVlan *setting, NMVlanPriorityMap map); + +gboolean nm_setting_vlan_add_priority_str (NMSettingVlan *setting, + NMVlanPriorityMap map, + const char *str); + +G_END_DECLS + +#endif /* NM_SETTING_VLAN_H */ |