bonding: settings parser for ifcfg plugin + NMSettingBond class

Introduced a new TYPE=bond for ifcfg-rh configuration files.
Alternatively BONDING_MASTER=yes can be specified instead of
setting the type explicitely to maintain backwards compatibility
with existing configuration files.

Bonding device files require a DEVICE= line to be present which
specifies the virtual bonding interface in the kernel. We do not
allow auto-generation of the name in order to keep confusion to
a minimum when reusing existing bonding interfaces.

The BONDING_OPTS= parameter can be used to specify various bonding
related options, such as:
  - mode
  - miimon
  - updelay
  - downdelay
  - arp_interval
  - arp_ip_target

By default, the NMSettingBond class uses a miimon value of 100 which
seems like a sensible default value for 99% of all configurations.
If this is not suitable, an arp_ip_target needs to be specified
manually.

A writer is not yet implemented.

Changes v2:
 - renamed DeviceName property to InterfaceName
 - moved code to validate device name to dev_valid_name() for future use

Signed-off-by: Thomas Graf <tgraf@redhat.com>
This commit is contained in:
Thomas Graf 2011-10-18 13:48:42 +02:00 committed by Dan Williams
parent d0b71957e7
commit a2a0d78818
8 changed files with 857 additions and 7 deletions

View file

@ -15,6 +15,7 @@ libnm_util_include_HEADERS = \
nm-setting.h \
nm-setting-8021x.h \
nm-setting-bluetooth.h \
nm-setting-bond.h \
nm-setting-connection.h \
nm-setting-ip4-config.h \
nm-setting-ip6-config.h \
@ -44,6 +45,7 @@ libnm_util_la_csources = \
nm-setting.c \
nm-setting-8021x.c \
nm-setting-bluetooth.c \
nm-setting-bond.c \
nm-setting-connection.c \
nm-setting-ip4-config.c \
nm-setting-ip6-config.c \

View file

@ -16,6 +16,7 @@ global:
nm_connection_get_setting;
nm_connection_get_setting_802_1x;
nm_connection_get_setting_bluetooth;
nm_connection_get_setting_bond;
nm_connection_get_setting_by_name;
nm_connection_get_setting_cdma;
nm_connection_get_setting_connection;
@ -167,6 +168,17 @@ global:
nm_setting_bluetooth_get_connection_type;
nm_setting_bluetooth_get_type;
nm_setting_bluetooth_new;
nm_setting_bond_error_get_type;
nm_setting_bond_error_quark;
nm_setting_bond_new;
nm_setting_bond_get_type;
nm_setting_bond_get_interface_name;
nm_setting_bond_get_mode;
nm_setting_bond_get_miimon;
nm_setting_bond_get_downdelay;
nm_setting_bond_get_updelay;
nm_setting_bond_get_arp_interval;
nm_setting_bond_get_arp_ip_target;
nm_setting_cdma_error_get_type;
nm_setting_cdma_error_quark;
nm_setting_cdma_get_number;

View file

@ -44,6 +44,7 @@
#include "nm-setting-wireless-security.h"
#include "nm-setting-vpn.h"
#include "nm-setting-olpc-mesh.h"
#include "nm-setting-bond.h"
#include "nm-setting-serial.h"
#include "nm-setting-gsm.h"
@ -135,7 +136,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
static GHashTable *registered_settings = NULL;
#define DEFAULT_MAP_SIZE 16
#define DEFAULT_MAP_SIZE 17
static struct SettingInfo {
const char *name;
@ -242,6 +243,11 @@ register_default_settings (void)
NM_SETTING_WIMAX_ERROR,
1, TRUE);
register_one_setting (NM_SETTING_BOND_SETTING_NAME,
NM_TYPE_SETTING_BOND,
NM_SETTING_BOND_ERROR,
1, TRUE);
register_one_setting (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
NM_TYPE_SETTING_WIRELESS_SECURITY,
NM_SETTING_WIRELESS_SECURITY_ERROR,
@ -1338,6 +1344,23 @@ nm_connection_get_setting_bluetooth (NMConnection *connection)
return (NMSettingBluetooth *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH);
}
/**
* nm_connection_get_setting_bond:
* @connection: the #NMConnection
*
* A shortcut to return any #NMSettingBond the connection might contain.
*
* Returns: (transfer none): an #NMSettingBond if the connection contains one, otherwise NULL
**/
NMSettingBond *
nm_connection_get_setting_bond (NMConnection *connection)
{
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
return (NMSettingBond *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BOND);
}
/**
* nm_connection_get_setting_cdma:
* @connection: the #NMConnection

View file

@ -32,6 +32,7 @@
#include <nm-setting-8021x.h>
#include <nm-setting-bluetooth.h>
#include <nm-setting-bond.h>
#include <nm-setting-cdma.h>
#include <nm-setting-connection.h>
#include <nm-setting-gsm.h>
@ -183,6 +184,7 @@ const char * nm_connection_get_id (NMConnection *connection);
NMSetting8021x * nm_connection_get_setting_802_1x (NMConnection *connection);
NMSettingBluetooth * nm_connection_get_setting_bluetooth (NMConnection *connection);
NMSettingBond * nm_connection_get_setting_bond (NMConnection *connection);
NMSettingCdma * nm_connection_get_setting_cdma (NMConnection *connection);
NMSettingConnection * nm_connection_get_setting_connection (NMConnection *connection);
NMSettingGsm * nm_connection_get_setting_gsm (NMConnection *connection);

View file

@ -0,0 +1,563 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* Thomas Graf <tgraf@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 <string.h>
#include <ctype.h>
#include <dbus/dbus-glib.h>
#include "nm-setting-bond.h"
#include "nm-param-spec-specialized.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-dbus-glib-types.h"
/**
* SECTION:nm-setting-bond
* @short_description: Describes connection properties for bonds
* @include: nm-setting-bond.h
*
* The #NMSettingBond object is a #NMSetting subclass that describes properties
* necessary for bond connections.
**/
/**
* nm_setting_bond_error_quark:
*
* Registers an error quark for #NMSettingBond if necessary.
*
* Returns: the error quark used for #NMSettingBond errors.
**/
GQuark
nm_setting_bond_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-bond-error-quark");
return quark;
}
/* This should really be standard. */
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
GType
nm_setting_bond_error_get_type (void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
/* Unknown error. */
ENUM_ENTRY (NM_SETTING_BOND_ERROR_UNKNOWN, "UnknownError"),
/* The specified property was invalid. */
ENUM_ENTRY (NM_SETTING_BOND_ERROR_INVALID_PROPERTY, "InvalidProperty"),
/* The specified property was missing and is required. */
ENUM_ENTRY (NM_SETTING_BOND_ERROR_MISSING_PROPERTY, "MissingProperty"),
{ 0, 0, 0 }
};
etype = g_enum_register_static ("NMSettingBondError", values);
}
return etype;
}
G_DEFINE_TYPE (NMSettingBond, nm_setting_bond, NM_TYPE_SETTING)
#define NM_SETTING_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BOND, NMSettingBondPrivate))
typedef struct {
char * interface_name;
char * mode;
guint32 miimon;
guint32 downdelay;
guint32 updelay;
guint32 arp_interval;
char * arp_ip_target;
} NMSettingBondPrivate;
enum {
PROP_0,
PROP_INTERFACE_NAME,
PROP_MODE,
PROP_MIIMON,
PROP_DOWNDELAY,
PROP_UPDELAY,
PROP_ARP_INTERVAL,
PROP_ARP_IP_TARGET,
LAST_PROP
};
/**
* nm_setting_bond_new:
*
* Creates a new #NMSettingBond object with default values.
*
* Returns: (transfer full): the new empty #NMSettingBond object
**/
NMSetting *
nm_setting_bond_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_BOND, NULL);
}
/**
* nm_setting_bond_get_interface_name
* @setting: the #NMSettingBond
*
* Returns: the #NMSettingBond:interface-name property of the setting
**/
const char *
nm_setting_bond_get_interface_name (NMSettingBond *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);
return NM_SETTING_BOND_GET_PRIVATE (setting)->interface_name;
}
/**
* nm_setting_bond_get_mode:
* @setting: the #NMSettingBond
*
* Returns: the #NMSettingBond:mode property of the setting
**/
const char *
nm_setting_bond_get_mode (NMSettingBond *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);
return NM_SETTING_BOND_GET_PRIVATE (setting)->mode;
}
/**
* nm_setting_bond_get_miimon:
* @setting: the #NMSettingBond
*
* Returns: the #NMSettingBond:miimon property of the setting
**/
guint32
nm_setting_bond_get_miimon (NMSettingBond *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);
return NM_SETTING_BOND_GET_PRIVATE (setting)->miimon;
}
/**
* nm_setting_bond_get_downdelay:
* @setting: the #NMSettingBond
*
* Returns: the #NMSettingBond:downdelay property of the setting
**/
guint32
nm_setting_bond_get_downdelay (NMSettingBond *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);
return NM_SETTING_BOND_GET_PRIVATE (setting)->downdelay;
}
/**
* nm_setting_bond_get_updelay:
* @setting: the #NMSettingBond
*
* Returns: the #NMSettingBond:updelay property of the setting
**/
guint32
nm_setting_bond_get_updelay (NMSettingBond *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);
return NM_SETTING_BOND_GET_PRIVATE (setting)->updelay;
}
/**
* nm_setting_bond_get_arp_interval:
* @setting: the #NMSettingBond
*
* Returns: the #NMSettingBond:arp_interval property of the setting
**/
guint32
nm_setting_bond_get_arp_interval (NMSettingBond *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);
return NM_SETTING_BOND_GET_PRIVATE (setting)->arp_interval;
}
/**
* nm_setting_bond_get_arp_ip_target:
* @setting: the #NMSettingBond
*
* Returns: the #NMSettingBond:arp_ip_target property of the setting
**/
const char *
nm_setting_bond_get_arp_ip_target (NMSettingBond *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);
return NM_SETTING_BOND_GET_PRIVATE (setting)->arp_ip_target;
}
/*
* This function is a 1:1 copy of the kernel's
* dev_valid_name() in net/core/dev.c
*/
static gboolean
dev_valid_name(const char *name)
{
if (*name == '\0')
return FALSE;
if (strlen (name) >= 16)
return FALSE;
if (!strcmp (name, ".") || !strcmp (name, ".."))
return FALSE;
while (*name) {
if (*name == '/' || isspace (*name))
return FALSE;
name++;
}
return TRUE;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (setting);
const char *valid_modes[] = { "balance-rr",
"active-backup",
"balance-xor",
"broadcast",
"802.3ad",
"balance-tlb",
"balance-alb",
NULL };
if (!priv->interface_name || !strlen(priv->interface_name)) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_MISSING_PROPERTY,
NM_SETTING_BOND_INTERFACE_NAME);
return FALSE;
}
if (!dev_valid_name (priv->interface_name)) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
NM_SETTING_BOND_INTERFACE_NAME);
return FALSE;
}
if (priv->mode && !_nm_utils_string_in_list (priv->mode, valid_modes)) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
NM_SETTING_BOND_MODE);
return FALSE;
}
/* XXX: Validate arp-ip-target */
return TRUE;
}
static void
nm_setting_bond_init (NMSettingBond *setting)
{
g_object_set (setting, NM_SETTING_NAME, NM_SETTING_BOND_SETTING_NAME,
NM_SETTING_BOND_MIIMON, 100, /* default: miimon=100 */
NULL);
}
static void
finalize (GObject *object)
{
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
g_free (priv->interface_name);
g_free (priv->mode);
g_free (priv->arp_ip_target);
G_OBJECT_CLASS (nm_setting_bond_parent_class)->finalize (object);
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
switch (prop_id) {
case PROP_INTERFACE_NAME:
priv->interface_name = g_value_dup_string (value);
break;
case PROP_MODE:
priv->mode = g_value_dup_string (value);
break;
case PROP_MIIMON:
priv->miimon = g_value_get_uint (value);
break;
case PROP_DOWNDELAY:
priv->downdelay = g_value_get_uint (value);
break;
case PROP_UPDELAY:
priv->updelay = g_value_get_uint (value);
break;
case PROP_ARP_INTERVAL:
priv->arp_interval = g_value_get_uint (value);
break;
case PROP_ARP_IP_TARGET:
g_free (priv->arp_ip_target);
priv->arp_ip_target = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingBond *setting = NM_SETTING_BOND (object);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_value_set_string (value, nm_setting_bond_get_interface_name (setting));
break;
case PROP_MODE:
g_value_set_string (value, nm_setting_bond_get_mode (setting));
break;
case PROP_MIIMON:
g_value_set_uint (value, nm_setting_bond_get_miimon (setting));
break;
case PROP_DOWNDELAY:
g_value_set_uint (value, nm_setting_bond_get_downdelay (setting));
break;
case PROP_UPDELAY:
g_value_set_uint (value, nm_setting_bond_get_updelay (setting));
break;
case PROP_ARP_INTERVAL:
g_value_set_uint (value, nm_setting_bond_get_arp_interval (setting));
break;
case PROP_ARP_IP_TARGET:
g_value_set_string (value, nm_setting_bond_get_arp_ip_target (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_bond_class_init (NMSettingBondClass *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 (NMSettingBondPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
/* Properties */
/**
* NMSettingBond:interface-name:
*
* Name of virtual kernel interface
**/
g_object_class_install_property
(object_class, PROP_INTERFACE_NAME,
g_param_spec_string (NM_SETTING_BOND_INTERFACE_NAME,
"InterfaceName",
"The name of the virtual in-kernel bonding nework interface",
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSettingBond:mode:
*
* Bonding policy
**/
g_object_class_install_property
(object_class, PROP_MODE,
g_param_spec_string (NM_SETTING_BOND_MODE,
"Mode",
"The bonding policy to use. One of 'balance-rr' (default), "
"'active-backup', 'balance-xor', 'broadcast', '802.3ad', "
"'balance-tlb', 'balance-alb'.",
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSettingBond:miimon:
*
* Specifies the MII link monitoring frequency in milliseconds.
* This determines how often the link state of each slave is
* inspected for link failures. A value of zero disables MII
* link monitoring. A value of 100 is a good starting point.
* The use_carrier option, below, affects how the link state is
* determined.
**/
g_object_class_install_property
(object_class, PROP_MIIMON,
g_param_spec_uint (NM_SETTING_BOND_MIIMON,
"MiiMon",
"Specifies the MII link monitoring frequency in milliseconds. "
"This determines how often the link state of each slave is "
"inspected for link failures. A value of zero disables MII "
"link monitoring. A value of 100 is a good starting point. "
"The use_carrier option, below, affects how the link state is "
"determined. The default value is 0.",
0, G_MAXUINT32, 100,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSettingBond:downdelay:
*
* Specifies the time, in milliseconds, to wait before disabling
* a slave after a link failure has been detected. This option
* is only valid for the miimon link monitor. The downdelay
* value should be a multiple of the miimon value; if not, it
* will be rounded down to the nearest multiple. The default
* value is 0.
**/
g_object_class_install_property
(object_class, PROP_DOWNDELAY,
g_param_spec_uint (NM_SETTING_BOND_DOWNDELAY,
"DownDelay",
"Specifies the time, in milliseconds, to wait before disabling "
"a slave after a link failure has been detected. This option "
"is only valid for the miimon link monitor. The downdelay "
"value should be a multiple of the miimon value; if not, it "
"will be rounded down to the nearest multiple. The default "
"value is 0.",
0, G_MAXUINT32, 0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSettingBond:updelay:
*
* Specifies the time, in milliseconds, to wait before enabling a
* slave after a link recovery has been detected. This option is
* only valid for the miimon link monitor. The updelay value
* should be a multiple of the miimon value; if not, it will be
* rounded down to the nearest multiple. The default value is 0.
**/
g_object_class_install_property
(object_class, PROP_UPDELAY,
g_param_spec_uint (NM_SETTING_BOND_UPDELAY,
"UpDelay",
"Specifies the time, in milliseconds, to wait before enabling a "
"slave after a link recovery has been detected. This option is "
"only valid for the miimon link monitor. The updelay value "
"should be a multiple of the miimon value; if not, it will be "
"rounded down to the nearest multiple. The default value is 0.",
0, G_MAXUINT32, 0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSettingBond:arp_interval:
*
* Specifies the ARP link monitoring frequency in milliseconds.
*
* The ARP monitor works by periodically checking the slave
* devices to determine whether they have sent or received
* traffic recently (the precise criteria depends upon the
* bonding mode, and the state of the slave). Regular traffic is
* generated via ARP probes issued for the addresses specified by
* the arp-ip-target option.
*
* This behavior can be modified by the arp-validate option.
*
* If ARP monitoring is used in an etherchannel compatible mode
* (modes 0 and 2), the switch should be configured in a mode
* that evenly distributes packets across all links. If the
* switch is configured to distribute the packets in an XOR
* fashion, all replies from the ARP targets will be received on
* the same link which could cause the other team members to
* fail. ARP monitoring should not be used in conjunction with
* miimon. A value of 0 disables ARP monitoring. The default
* value is 0.
**/
g_object_class_install_property
(object_class, PROP_ARP_INTERVAL,
g_param_spec_uint (NM_SETTING_BOND_ARP_INTERVAL,
"ArpInterval",
"Specifies the ARP link monitoring frequency in milliseconds. "
"The ARP monitor works by periodically checking the slave "
"devices to determine whether they have sent or received "
"traffic recently (the precise criteria depends upon the "
"bonding mode, and the state of the slave). Regular traffic is "
"generated via ARP probes issued for the addresses specified by "
"the arp-ip-target option. "
"This behavior can be modified by the arp-validate option. "
"If ARP monitoring is used in an etherchannel compatible mode "
"(modes 0 and 2), the switch should be configured in a mode "
"that evenly distributes packets across all links. If the "
"switch is configured to distribute the packets in an XOR "
"fashion, all replies from the ARP targets will be received on "
"the same link which could cause the other team members to "
"fail. ARP monitoring should not be used in conjunction with "
"miimon. A value of 0 disables ARP monitoring. The default "
"value is 0.",
0, G_MAXUINT32, 0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
/**
* NMSettingBond:arp_ip_target:
*
* Specifies the IP addresses to use as ARP monitoring peers when
* arp_interval is > 0. These are the targets of the ARP request
* sent to determine the health of the link to the targets.
* Specify these values in ddd.ddd.ddd.ddd format. Multiple IP
* addresses must be separated by a comma. At least one IP
* address must be given for ARP monitoring to function. The
* maximum number of targets that can be specified is 16. The
* default value is no IP addresses.
**/
g_object_class_install_property
(object_class, PROP_ARP_IP_TARGET,
g_param_spec_string (NM_SETTING_BOND_ARP_IP_TARGET,
"ArpIpTarget",
"Specifies the IP addresses to use as ARP monitoring peers when "
"arp-interval is > 0. These are the targets of the ARP request "
"sent to determine the health of the link to the targets. "
"Specify these values in ddd.ddd.ddd.ddd format. Multiple IP "
"addresses must be separated by a comma. At least one IP "
"address must be given for ARP monitoring to function. The "
"maximum number of targets that can be specified is 16. The "
"default value is no IP addresses.",
NULL,
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
}

View file

@ -0,0 +1,94 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* Thomas Graf <tgraf@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_BOND_H
#define NM_SETTING_BOND_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_BOND (nm_setting_bond_get_type ())
#define NM_SETTING_BOND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_BOND, NMSettingBond))
#define NM_SETTING_BOND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_BOND, NMSettingBondClass))
#define NM_IS_SETTING_BOND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_BOND))
#define NM_IS_SETTING_BOND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_SETTING_BOND))
#define NM_SETTING_BOND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_BOND, NMSettingBondClass))
#define NM_SETTING_BOND_SETTING_NAME "bond"
/**
* NMSettingBondError:
* @NM_SETTING_BOND_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_BOND_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_BOND_ERROR_MISSING_PROPERTY: the property was missing and is
* required
*/
typedef enum {
NM_SETTING_BOND_ERROR_UNKNOWN = 0,
NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
NM_SETTING_BOND_ERROR_MISSING_PROPERTY,
} NMSettingBondError;
#define NM_TYPE_SETTING_BOND_ERROR (nm_setting_bond_error_get_type ())
GType nm_setting_bond_error_get_type (void);
#define NM_SETTING_BOND_ERROR nm_setting_bond_error_quark ()
GQuark nm_setting_bond_error_quark (void);
#define NM_SETTING_BOND_INTERFACE_NAME "interface-name"
#define NM_SETTING_BOND_MODE "mode"
#define NM_SETTING_BOND_MIIMON "miimon"
#define NM_SETTING_BOND_DOWNDELAY "down-delay"
#define NM_SETTING_BOND_UPDELAY "up-delay"
#define NM_SETTING_BOND_ARP_INTERVAL "arp-interval"
#define NM_SETTING_BOND_ARP_IP_TARGET "arp-ip-target"
typedef struct {
NMSetting parent;
} NMSettingBond;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingBondClass;
GType nm_setting_bond_get_type (void);
NMSetting * nm_setting_bond_new (void);
const char * nm_setting_bond_get_interface_name (NMSettingBond *setting);
const char * nm_setting_bond_get_mode (NMSettingBond *setting);
guint32 nm_setting_bond_get_miimon (NMSettingBond *setting);
guint32 nm_setting_bond_get_downdelay (NMSettingBond *setting);
guint32 nm_setting_bond_get_updelay (NMSettingBond *setting);
guint32 nm_setting_bond_get_arp_interval (NMSettingBond *setting);
const char * nm_setting_bond_get_arp_ip_target (NMSettingBond *setting);
G_END_DECLS
#endif /* NM_SETTING_BOND_H */

View file

@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2008 - 2010 Red Hat, Inc.
* (C) Copyright 2008 - 2011 Red Hat, Inc.
*/
#ifndef __COMMON_H__
@ -44,6 +44,7 @@
#define TYPE_ETHERNET "Ethernet"
#define TYPE_WIRELESS "Wireless"
#define TYPE_BRIDGE "Bridge"
#define TYPE_BOND "Bond"
#define SECRET_FLAG_AGENT "user"
#define SECRET_FLAG_NOT_SAVED "ask"

View file

@ -50,6 +50,7 @@
#include <nm-setting-wired.h>
#include <nm-setting-wireless.h>
#include <nm-setting-8021x.h>
#include <nm-setting-bond.h>
#include <nm-utils.h>
#include "common.h"
@ -3349,6 +3350,150 @@ is_wireless_device (const char *iface)
return is_wireless;
}
static void
handle_bond_option (NMSettingBond *s_bond,
const char *key,
const char *value)
{
if (!g_strcmp0 (key, "mode"))
g_object_set (s_bond, NM_SETTING_BOND_MODE, value, NULL);
else if (!g_strcmp0 (key, "miimon"))
g_object_set (s_bond, NM_SETTING_BOND_MIIMON, strtoul(value, NULL, 0), NULL);
else if (!g_strcmp0 (key, "updelay"))
g_object_set (s_bond, NM_SETTING_BOND_UPDELAY, strtoul(value, NULL, 0), NULL);
else if (!g_strcmp0 (key, "downdelay"))
g_object_set (s_bond, NM_SETTING_BOND_DOWNDELAY, strtoul(value, NULL, 0), NULL);
else if (!g_strcmp0 (key, "arp_interval"))
g_object_set (s_bond, NM_SETTING_BOND_ARP_INTERVAL, strtoul(value, NULL, 0), NULL);
else if (!g_strcmp0 (key, "arp_ip_target"))
g_object_set (s_bond, NM_SETTING_BOND_ARP_IP_TARGET, value, NULL);
else
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: invalid bonding option '%s'", key);
}
static NMSetting *
make_bond_setting (shvarFile *ifcfg,
const char *file,
gboolean nm_controlled,
char **unmanaged,
GError **error)
{
NMSettingBond *s_bond;
char *value;
s_bond = NM_SETTING_BOND (nm_setting_bond_new ());
value = svGetValue (ifcfg, "DEVICE", FALSE);
if (!value || !strlen (value)) {
g_set_error (error, IFCFG_PLUGIN_ERROR, 0, "mandatory DEVICE keyword missing");
goto error;
}
g_object_set (s_bond, NM_SETTING_BOND_INTERFACE_NAME, value, NULL);
g_free (value);
value = svGetValue (ifcfg, "BONDING_OPTS", FALSE);
if (value) {
char **items, **iter;
items = g_strsplit_set (value, " ", -1);
for (iter = items; iter && *iter; iter++) {
if (strlen (*iter)) {
char **keys, *key, *val;
keys = g_strsplit_set (*iter, "=", 2);
if (keys && *keys) {
key = *keys;
val = *(keys + 1);
if (val && strlen(key) && strlen(val))
handle_bond_option (s_bond, key, val);
}
g_strfreev (keys);
}
}
g_free (value);
g_strfreev (items);
}
return (NMSetting *) s_bond;
error:
g_object_unref (s_bond);
return NULL;
}
static NMConnection *
bond_connection_from_ifcfg (const char *file,
shvarFile *ifcfg,
gboolean nm_controlled,
char **unmanaged,
GError **error)
{
NMConnection *connection = NULL;
NMSetting *con_setting = NULL;
NMSetting *bond_setting = NULL;
NMSetting *wired_setting = NULL;
NMSetting8021x *s_8021x = NULL;
g_return_val_if_fail (file != NULL, NULL);
g_return_val_if_fail (ifcfg != NULL, NULL);
connection = nm_connection_new ();
if (!connection) {
g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
"Failed to allocate new connection for %s.", file);
return NULL;
}
con_setting = make_connection_setting (file, ifcfg, NM_SETTING_BOND_SETTING_NAME, NULL);
if (!con_setting) {
g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
"Failed to create connection setting.");
g_object_unref (connection);
return NULL;
}
nm_connection_add_setting (connection, con_setting);
bond_setting = make_bond_setting (ifcfg, file, nm_controlled, unmanaged, error);
if (!bond_setting) {
g_object_unref (connection);
return NULL;
}
nm_connection_add_setting (connection, bond_setting);
wired_setting = make_wired_setting (ifcfg, file, nm_controlled, unmanaged, &s_8021x, error);
if (!wired_setting) {
g_object_unref (connection);
return NULL;
}
nm_connection_add_setting (connection, wired_setting);
if (s_8021x)
nm_connection_add_setting (connection, NM_SETTING (s_8021x));
if (!nm_connection_verify (connection, error)) {
g_object_unref (connection);
return NULL;
}
return connection;
}
static gboolean
is_bond_device (const char *name, shvarFile *parsed)
{
g_return_val_if_fail (name != NULL, FALSE);
g_return_val_if_fail (parsed != NULL, FALSE);
if (svTrueValue (parsed, "BONDING_MASTER", FALSE))
return TRUE;
/* XXX: Check for "bond[\d]+"? */
return FALSE;
}
enum {
IGNORE_REASON_NONE = 0x00,
IGNORE_REASON_BRIDGE = 0x01,
@ -3412,9 +3557,6 @@ connection_from_file (const char *filename,
if (!type) {
char *device;
/* If no type, if the device has wireless extensions, it's wifi,
* otherwise it's ethernet.
*/
device = svGetValue (parsed, "DEVICE", FALSE);
if (!device) {
g_set_error (&error, IFCFG_PLUGIN_ERROR, 0,
@ -3432,8 +3574,10 @@ connection_from_file (const char *filename,
}
if (!test_type) {
if (is_bond_device (device, parsed))
type = g_strdup (TYPE_BOND);
/* Test wireless extensions */
if (is_wireless_device (device))
else if (is_wireless_device (device))
type = g_strdup (TYPE_WIRELESS);
else
type = g_strdup (TYPE_ETHERNET);
@ -3466,6 +3610,13 @@ connection_from_file (const char *filename,
g_free (lower);
}
if (svTrueValue (parsed, "BONDING_MASTER", FALSE) &&
strcasecmp (type, TYPE_BOND)) {
g_set_error (&error, IFCFG_PLUGIN_ERROR, 0,
"BONDING_MASTER=yes key only allowed in TYPE=bond connections");
goto done;
}
/* Ignore BRIDGE= and VLAN= connections for now too (rh #619863) */
tmp = svGetValue (parsed, "BRIDGE", FALSE);
if (tmp) {
@ -3491,7 +3642,9 @@ connection_from_file (const char *filename,
else if (!strcasecmp (type, TYPE_BRIDGE)) {
g_set_error (&error, IFCFG_PLUGIN_ERROR, 0,
"Bridge connections are not yet supported");
} else {
} else if (!strcasecmp (type, TYPE_BOND))
connection = bond_connection_from_ifcfg (filename, parsed, nm_controlled, unmanaged, &error);
else {
g_set_error (&error, IFCFG_PLUGIN_ERROR, 0,
"Unknown connection type '%s'", type);
}