networkd-netdev-bond.c revision 1c4baffc1895809bae9ac36b670af90a4cb9cd7d
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Tom Gundersen <teg@jklm.no>
Copyright 2014 Susant Sahani
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <linux/if_bonding.h>
#include "conf-parser.h"
#include "sd-netlink.h"
#include "netlink-types.h"
#include "networkd-netdev-bond.h"
#include "missing.h"
/*
* Number of seconds between instances where the bonding
* driver sends learning packets to each slaves peer switch
*/
/* Number of IGMP membership reports to be issued after
* a failover event.
*/
#define RESEND_IGMP_MIN 0
#define RESEND_IGMP_MAX 255
#define RESEND_IGMP_DEFAULT 1
/*
* Number of packets to transmit through a slave before
* moving to the next one.
*/
#define PACKETS_PER_SLAVE_MIN 0
#define PACKETS_PER_SLAVE_MAX 65535
#define PACKETS_PER_SLAVE_DEFAULT 1
/*
* Number of peer notifications (gratuitous ARPs and
* unsolicited IPv6 Neighbor Advertisements) to be issued after a
* failover event.
*/
#define GRATUITOUS_ARP_MIN 0
#define GRATUITOUS_ARP_MAX 255
#define GRATUITOUS_ARP_DEFAULT 1
static const char* const bond_mode_table[_NETDEV_BOND_MODE_MAX] = {
[NETDEV_BOND_MODE_BALANCE_RR] = "balance-rr",
[NETDEV_BOND_MODE_ACTIVE_BACKUP] = "active-backup",
[NETDEV_BOND_MODE_BALANCE_XOR] = "balance-xor",
[NETDEV_BOND_MODE_BROADCAST] = "broadcast",
[NETDEV_BOND_MODE_802_3AD] = "802.3ad",
[NETDEV_BOND_MODE_BALANCE_TLB] = "balance-tlb",
[NETDEV_BOND_MODE_BALANCE_ALB] = "balance-alb",
};
static const char* const bond_xmit_hash_policy_table[_NETDEV_BOND_XMIT_HASH_POLICY_MAX] = {
[NETDEV_BOND_XMIT_HASH_POLICY_LAYER2] = "layer2",
[NETDEV_BOND_XMIT_HASH_POLICY_LAYER34] = "layer3+4",
[NETDEV_BOND_XMIT_HASH_POLICY_LAYER23] = "layer2+3",
[NETDEV_BOND_XMIT_HASH_POLICY_ENCAP23] = "encap2+3",
[NETDEV_BOND_XMIT_HASH_POLICY_ENCAP34] = "encap3+4",
};
"Failed to parse bond transmit hash policy")
static const char* const bond_lacp_rate_table[_NETDEV_BOND_LACP_RATE_MAX] = {
[NETDEV_BOND_LACP_RATE_SLOW] = "slow",
[NETDEV_BOND_LACP_RATE_FAST] = "fast",
};
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_lacp_rate, bond_lacp_rate, BondLacpRate, "Failed to parse bond lacp rate")
static const char* const bond_ad_select_table[_NETDEV_BOND_AD_SELECT_MAX] = {
[NETDEV_BOND_AD_SELECT_STABLE] = "stable",
[NETDEV_BOND_AD_SELECT_BANDWIDTH] = "bandwidth",
[NETDEV_BOND_AD_SELECT_COUNT] = "count",
};
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_ad_select, bond_ad_select, BondAdSelect, "Failed to parse bond AD select");
static const char* const bond_fail_over_mac_table[_NETDEV_BOND_FAIL_OVER_MAC_MAX] = {
[NETDEV_BOND_FAIL_OVER_MAC_NONE] = "none",
[NETDEV_BOND_FAIL_OVER_MAC_ACTIVE] = "active",
[NETDEV_BOND_FAIL_OVER_MAC_FOLLOW] = "follow",
};
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_fail_over_mac, bond_fail_over_mac, BondFailOverMac, "Failed to parse bond fail over MAC");
static const char *const bond_arp_validate_table[_NETDEV_BOND_ARP_VALIDATE_MAX] = {
[NETDEV_BOND_ARP_VALIDATE_NONE] = "none",
[NETDEV_BOND_ARP_VALIDATE_ACTIVE]= "active",
[NETDEV_BOND_ARP_VALIDATE_BACKUP]= "backup",
[NETDEV_BOND_ARP_VALIDATE_ALL]= "all",
};
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_arp_validate, bond_arp_validate, BondArpValidate, "Failed to parse bond arp validate");
static const char *const bond_arp_all_targets_table[_NETDEV_BOND_ARP_ALL_TARGETS_MAX] = {
[NETDEV_BOND_ARP_ALL_TARGETS_ANY] = "any",
[NETDEV_BOND_ARP_ALL_TARGETS_ALL] = "all",
};
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_arp_all_targets, bond_arp_all_targets, BondArpAllTargets, "Failed to parse bond Arp all targets");
static const char *bond_primary_reselect_table[_NETDEV_BOND_PRIMARY_RESELECT_MAX] = {
[NETDEV_BOND_PRIMARY_RESELECT_ALWAYS] = "always",
[NETDEV_BOND_PRIMARY_RESELECT_BETTER]= "better",
[NETDEV_BOND_PRIMARY_RESELECT_FAILURE]= "failure",
};
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_primary_reselect, bond_primary_reselect, BondPrimaryReselect, "Failed to parse bond primary reselect");
switch (mode) {
return BOND_MODE_ROUNDROBIN;
return BOND_MODE_ACTIVEBACKUP;
return BOND_MODE_XOR;
return BOND_MODE_BROADCAST;
case NETDEV_BOND_MODE_802_3AD:
return BOND_MODE_8023AD;
return BOND_MODE_TLB;
return BOND_MODE_ALB;
default:
return (uint8_t) -1;
}
}
switch (policy) {
return BOND_XMIT_POLICY_LAYER2;
return BOND_XMIT_POLICY_LAYER34;
return BOND_XMIT_POLICY_LAYER23;
return BOND_XMIT_POLICY_ENCAP23;
return BOND_XMIT_POLICY_ENCAP34;
default:
return (uint8_t) -1;
}
}
int r, i = 0;
assert(b);
assert(m);
if (b->mode != _NETDEV_BOND_MODE_INVALID) {
bond_mode_to_kernel(b->mode));
if (r < 0)
}
if (b->xmit_hash_policy != _NETDEV_BOND_XMIT_HASH_POLICY_INVALID) {
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_XMIT_HASH_POLICY attribute: %m");
}
if (b->lacp_rate != _NETDEV_BOND_LACP_RATE_INVALID &&
b->mode == NETDEV_BOND_MODE_802_3AD) {
if (r < 0) {
}
}
if (b->miimon != 0) {
if (r < 0)
}
if (b->downdelay != 0) {
if (r < 0)
}
if (b->updelay != 0) {
if (r < 0)
}
if (b->arp_interval != 0) {
if (r < 0)
if ((b->lp_interval >= LEARNING_PACKETS_INTERVAL_MIN_SEC) &&
(b->lp_interval <= LEARNING_PACKETS_INTERVAL_MAX_SEC)) {
if (r < 0)
}
}
if (b->ad_select != _NETDEV_BOND_AD_SELECT_INVALID &&
b->mode == NETDEV_BOND_MODE_802_3AD) {
if (r < 0)
}
if (b->fail_over_mac != _NETDEV_BOND_FAIL_OVER_MAC_INVALID &&
b->mode == NETDEV_BOND_MODE_ACTIVE_BACKUP) {
if (r < 0)
}
if (b->arp_validate != _NETDEV_BOND_ARP_VALIDATE_INVALID) {
if (r < 0)
}
if (b->arp_all_targets != _NETDEV_BOND_ARP_ALL_TARGETS_INVALID) {
if (r < 0)
}
if (b->primary_reselect != _NETDEV_BOND_PRIMARY_RESELECT_INVALID) {
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %m");
}
if (b->resend_igmp <= RESEND_IGMP_MAX) {
if (r < 0)
}
if (b->packets_per_slave <= PACKETS_PER_SLAVE_MAX &&
b->mode == NETDEV_BOND_MODE_BALANCE_RR) {
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_PACKETS_PER_SLAVE attribute: %m");
}
if (b->num_grat_arp <= GRATUITOUS_ARP_MAX) {
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_NUM_PEER_NOTIF attribute: %m");
}
if (b->min_links != 0) {
if (r < 0)
}
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ALL_SLAVES_ACTIVE attribute: %m");
if (b->arp_interval > 0) {
if (b->n_arp_ip_targets > 0) {
if (r < 0)
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %m");
}
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not close contaniner IFLA_BOND_ARP_IP_TARGET : %m");
}
}
return 0;
}
int config_parse_arp_ip_target_address(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
size_t l;
int r;
_cleanup_free_ char *n = NULL;
int f;
if (!n)
return -ENOMEM;
if (!buffer)
return -ENOMEM;
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Bond ARP ip target address is invalid, ignoring assignment: %s", n);
return 0;
}
if (f != AF_INET) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Bond ARP ip target address is invalid, ignoring assignment: %s", n);
return 0;
}
b->n_arp_ip_targets ++;
if (b->n_arp_ip_targets > BOND_ARP_TARGETS_MAX)
break;
}
return 0;
}
assert(b);
free(t);
b->arp_ip_targets = NULL;
}
assert(b);
b->all_slaves_active = false;
b->n_arp_ip_targets = 0;
}
const NetDevVTable bond_vtable = {
.object_size = sizeof(Bond),
.sections = "Match\0NetDev\0Bond\0",
};