2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2014-07-04 19:05:02 +02:00
|
|
|
|
2015-10-27 03:01:06 +01:00
|
|
|
#include "alloc-util.h"
|
2019-04-12 06:29:46 +02:00
|
|
|
#include "bond.h"
|
2020-05-17 06:14:49 +02:00
|
|
|
#include "bond-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "conf-parser.h"
|
2018-11-02 02:31:20 +01:00
|
|
|
#include "ether-addr-util.h"
|
2016-04-29 04:52:04 +02:00
|
|
|
#include "extract-word.h"
|
2019-05-10 16:29:07 +02:00
|
|
|
#include "netlink-util.h"
|
|
|
|
#include "networkd-manager.h"
|
2015-10-26 22:31:05 +01:00
|
|
|
#include "string-table.h"
|
2014-07-04 19:05:02 +02:00
|
|
|
|
2015-03-09 10:58:29 +01:00
|
|
|
/*
|
|
|
|
* Number of seconds between instances where the bonding
|
|
|
|
* driver sends learning packets to each slaves peer switch
|
|
|
|
*/
|
|
|
|
#define LEARNING_PACKETS_INTERVAL_MIN_SEC (1 * USEC_PER_SEC)
|
|
|
|
#define LEARNING_PACKETS_INTERVAL_MAX_SEC (0x7fffffff * USEC_PER_SEC)
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
2014-07-04 19:05:02 +02:00
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_mode, bond_mode, BondMode, "Failed to parse bond mode");
|
2014-07-21 15:07:05 +02:00
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_xmit_hash_policy,
|
|
|
|
bond_xmit_hash_policy,
|
|
|
|
BondXmitHashPolicy,
|
2020-05-17 06:14:49 +02:00
|
|
|
"Failed to parse bond transmit hash policy");
|
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_lacp_rate, bond_lacp_rate, BondLacpRate, "Failed to parse bond lacp rate");
|
2015-03-09 10:58:29 +01:00
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_ad_select, bond_ad_select, BondAdSelect, "Failed to parse bond AD select");
|
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_fail_over_mac, bond_fail_over_mac, BondFailOverMac, "Failed to parse bond fail over MAC");
|
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_arp_validate, bond_arp_validate, BondArpValidate, "Failed to parse bond arp validate");
|
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_arp_all_targets, bond_arp_all_targets, BondArpAllTargets, "Failed to parse bond Arp all targets");
|
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_primary_reselect, bond_primary_reselect, BondPrimaryReselect, "Failed to parse bond primary reselect");
|
|
|
|
|
2015-06-12 16:31:33 +02:00
|
|
|
static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
2015-10-25 04:54:31 +01:00
|
|
|
Bond *b;
|
2019-04-12 07:14:19 +02:00
|
|
|
int r;
|
2014-07-04 19:05:02 +02:00
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
assert(netdev);
|
|
|
|
assert(!link);
|
2014-07-04 19:05:02 +02:00
|
|
|
assert(m);
|
|
|
|
|
2015-10-25 04:54:31 +01:00
|
|
|
b = BOND(netdev);
|
|
|
|
|
|
|
|
assert(b);
|
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
if (b->mode != _NETDEV_BOND_MODE_INVALID) {
|
2019-04-12 06:29:46 +02:00
|
|
|
r = sd_netlink_message_append_u8(m, IFLA_BOND_MODE, b->mode);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_MODE attribute: %m");
|
2014-07-04 19:05:02 +02:00
|
|
|
}
|
|
|
|
|
2014-07-21 15:07:05 +02:00
|
|
|
if (b->xmit_hash_policy != _NETDEV_BOND_XMIT_HASH_POLICY_INVALID) {
|
2019-04-12 06:29:46 +02:00
|
|
|
r = sd_netlink_message_append_u8(m, IFLA_BOND_XMIT_HASH_POLICY, b->xmit_hash_policy);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_XMIT_HASH_POLICY attribute: %m");
|
2014-07-21 15:07:05 +02:00
|
|
|
}
|
|
|
|
|
2014-07-21 15:22:14 +02:00
|
|
|
if (b->lacp_rate != _NETDEV_BOND_LACP_RATE_INVALID &&
|
|
|
|
b->mode == NETDEV_BOND_MODE_802_3AD) {
|
2019-02-03 00:24:17 +01:00
|
|
|
r = sd_netlink_message_append_u8(m, IFLA_BOND_AD_LACP_RATE, b->lacp_rate);
|
2015-09-08 23:03:38 +02:00
|
|
|
if (r < 0)
|
2015-06-10 08:09:26 +02:00
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_LACP_RATE attribute: %m");
|
2014-07-21 15:22:14 +02:00
|
|
|
}
|
|
|
|
|
2014-07-21 15:44:48 +02:00
|
|
|
if (b->miimon != 0) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u32(m, IFLA_BOND_MIIMON, b->miimon / USEC_PER_MSEC);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_BOND_MIIMON attribute: %m");
|
2014-07-21 15:44:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b->downdelay != 0) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u32(m, IFLA_BOND_DOWNDELAY, b->downdelay / USEC_PER_MSEC);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_DOWNDELAY attribute: %m");
|
2014-07-21 15:44:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b->updelay != 0) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u32(m, IFLA_BOND_UPDELAY, b->updelay / USEC_PER_MSEC);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_UPDELAY attribute: %m");
|
2014-07-21 15:44:48 +02:00
|
|
|
}
|
|
|
|
|
2015-03-09 10:58:29 +01:00
|
|
|
if (b->arp_interval != 0) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u32(m, IFLA_BOND_ARP_INTERVAL, b->arp_interval / USEC_PER_MSEC);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_INTERVAL attribute: %m");
|
|
|
|
|
2019-02-03 00:24:17 +01:00
|
|
|
if (b->lp_interval >= LEARNING_PACKETS_INTERVAL_MIN_SEC &&
|
|
|
|
b->lp_interval <= LEARNING_PACKETS_INTERVAL_MAX_SEC) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u32(m, IFLA_BOND_LP_INTERVAL, b->lp_interval / USEC_PER_SEC);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_LP_INTERVAL attribute: %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b->ad_select != _NETDEV_BOND_AD_SELECT_INVALID &&
|
2015-06-10 17:05:04 +02:00
|
|
|
b->mode == NETDEV_BOND_MODE_802_3AD) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u8(m, IFLA_BOND_AD_SELECT, b->ad_select);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_SELECT attribute: %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b->fail_over_mac != _NETDEV_BOND_FAIL_OVER_MAC_INVALID &&
|
|
|
|
b->mode == NETDEV_BOND_MODE_ACTIVE_BACKUP) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u8(m, IFLA_BOND_FAIL_OVER_MAC, b->fail_over_mac);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_FAIL_OVER_MAC attribute: %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b->arp_validate != _NETDEV_BOND_ARP_VALIDATE_INVALID) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u32(m, IFLA_BOND_ARP_VALIDATE, b->arp_validate);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_VALIDATE attribute: %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b->arp_all_targets != _NETDEV_BOND_ARP_ALL_TARGETS_INVALID) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u32(m, IFLA_BOND_ARP_ALL_TARGETS, b->arp_all_targets);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
2016-10-24 21:24:47 +02:00
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b->primary_reselect != _NETDEV_BOND_PRIMARY_RESELECT_INVALID) {
|
2016-10-24 21:24:47 +02:00
|
|
|
r = sd_netlink_message_append_u8(m, IFLA_BOND_PRIMARY_RESELECT, b->primary_reselect);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
2016-10-24 21:24:47 +02:00
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_PRIMARY_RESELECT attribute: %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b->resend_igmp <= RESEND_IGMP_MAX) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u32(m, IFLA_BOND_RESEND_IGMP, b->resend_igmp);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_RESEND_IGMP attribute: %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
2015-06-10 17:05:04 +02:00
|
|
|
if (b->packets_per_slave <= PACKETS_PER_SLAVE_MAX &&
|
|
|
|
b->mode == NETDEV_BOND_MODE_BALANCE_RR) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u32(m, IFLA_BOND_PACKETS_PER_SLAVE, b->packets_per_slave);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_PACKETS_PER_SLAVE attribute: %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b->num_grat_arp <= GRATUITOUS_ARP_MAX) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u8(m, IFLA_BOND_NUM_PEER_NOTIF, b->num_grat_arp);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_NUM_PEER_NOTIF attribute: %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b->min_links != 0) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u32(m, IFLA_BOND_MIN_LINKS, b->min_links);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_MIN_LINKS attribute: %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
2018-11-02 02:31:20 +01:00
|
|
|
if (b->ad_actor_sys_prio != 0) {
|
|
|
|
r = sd_netlink_message_append_u16(m, IFLA_BOND_AD_ACTOR_SYS_PRIO, b->ad_actor_sys_prio);
|
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_ACTOR_SYS_PRIO attribute: %m");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b->ad_user_port_key != 0) {
|
|
|
|
r = sd_netlink_message_append_u16(m, IFLA_BOND_AD_USER_PORT_KEY, b->ad_user_port_key);
|
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_USER_PORT_KEY attribute: %m");
|
|
|
|
}
|
|
|
|
|
2019-04-12 06:37:02 +02:00
|
|
|
if (!ether_addr_is_null(&b->ad_actor_system)) {
|
|
|
|
r = sd_netlink_message_append_ether_addr(m, IFLA_BOND_AD_ACTOR_SYSTEM, &b->ad_actor_system);
|
2018-11-02 02:31:20 +01:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_ACTOR_SYSTEM attribute: %m");
|
|
|
|
}
|
|
|
|
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_u8(m, IFLA_BOND_ALL_SLAVES_ACTIVE, b->all_slaves_active);
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ALL_SLAVES_ACTIVE attribute: %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
|
2018-12-13 10:23:07 +01:00
|
|
|
if (b->tlb_dynamic_lb >= 0) {
|
|
|
|
r = sd_netlink_message_append_u8(m, IFLA_BOND_TLB_DYNAMIC_LB, b->tlb_dynamic_lb);
|
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_TLB_DYNAMIC_LB attribute: %m");
|
|
|
|
}
|
|
|
|
|
2019-04-12 07:14:19 +02:00
|
|
|
if (b->arp_interval > 0 && !ordered_set_isempty(b->arp_ip_targets)) {
|
|
|
|
Iterator i;
|
|
|
|
void *val;
|
|
|
|
int n = 0;
|
|
|
|
|
2019-02-03 00:24:17 +01:00
|
|
|
r = sd_netlink_message_open_container(m, IFLA_BOND_ARP_IP_TARGET);
|
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not open contaniner IFLA_BOND_ARP_IP_TARGET : %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
|
2019-04-12 07:14:19 +02:00
|
|
|
ORDERED_SET_FOREACH(val, b->arp_ip_targets, i) {
|
|
|
|
r = sd_netlink_message_append_u32(m, n++, PTR_TO_UINT32(val));
|
2015-06-10 08:09:26 +02:00
|
|
|
if (r < 0)
|
2019-02-03 00:24:17 +01:00
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
2019-02-03 00:24:17 +01:00
|
|
|
|
|
|
|
r = sd_netlink_message_close_container(m);
|
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not close contaniner IFLA_BOND_ARP_IP_TARGET : %m");
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2014-07-04 19:05:02 +02:00
|
|
|
|
2019-05-10 16:29:07 +02:00
|
|
|
static int link_set_bond_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(m);
|
|
|
|
assert(link);
|
|
|
|
assert(link->ifname);
|
|
|
|
|
|
|
|
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
r = sd_netlink_message_get_errno(m);
|
|
|
|
if (r < 0) {
|
|
|
|
log_link_warning_errno(link, r, "Could not set bonding interface: %m");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int link_set_bond(Link *link) {
|
|
|
|
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(link);
|
|
|
|
assert(link->network);
|
|
|
|
|
|
|
|
r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_NEWLINK, link->network->bond->ifindex);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "Could not allocate RTM_SETLINK message: %m");
|
|
|
|
|
|
|
|
r = sd_netlink_message_set_flags(req, NLM_F_REQUEST | NLM_F_ACK);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "Could not set netlink flags: %m");
|
|
|
|
|
|
|
|
r = sd_netlink_message_open_container(req, IFLA_LINKINFO);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "Could not append IFLA_PROTINFO attribute: %m");
|
|
|
|
|
|
|
|
r = sd_netlink_message_open_container_union(req, IFLA_INFO_DATA, "bond");
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "Could not append IFLA_INFO_DATA attribute: %m");
|
|
|
|
|
|
|
|
if (link->network->active_slave) {
|
|
|
|
r = sd_netlink_message_append_u32(req, IFLA_BOND_ACTIVE_SLAVE, link->ifindex);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "Could not append IFLA_BOND_ACTIVE_SLAVE attribute: %m");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (link->network->primary_slave) {
|
|
|
|
r = sd_netlink_message_append_u32(req, IFLA_BOND_PRIMARY, link->ifindex);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "Could not append IFLA_BOND_PRIMARY attribute: %m");
|
|
|
|
}
|
|
|
|
|
|
|
|
r = sd_netlink_message_close_container(req);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "Could not append IFLA_LINKINFO attribute: %m");
|
|
|
|
|
|
|
|
r = sd_netlink_message_close_container(req);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "Could not append IFLA_INFO_DATA attribute: %m");
|
|
|
|
|
|
|
|
r = netlink_call_async(link->manager->rtnl, NULL, req, link_set_bond_handler,
|
|
|
|
link_netlink_destroy_callback, link);
|
|
|
|
if (r < 0)
|
|
|
|
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
|
|
|
|
|
|
|
|
link_ref(link);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2019-04-12 07:14:19 +02:00
|
|
|
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) {
|
|
|
|
|
2015-03-09 10:58:29 +01:00
|
|
|
Bond *b = userdata;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2019-04-12 07:14:19 +02:00
|
|
|
if (isempty(rvalue)) {
|
|
|
|
b->arp_ip_targets = ordered_set_free(b->arp_ip_targets);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-23 18:36:42 +02:00
|
|
|
for (;;) {
|
2015-03-09 10:58:29 +01:00
|
|
|
_cleanup_free_ char *n = NULL;
|
2019-04-12 07:14:19 +02:00
|
|
|
union in_addr_union ip;
|
2015-03-09 10:58:29 +01:00
|
|
|
|
2015-10-23 18:36:42 +02:00
|
|
|
r = extract_first_word(&rvalue, &n, NULL, 0);
|
|
|
|
if (r < 0) {
|
2019-04-12 07:14:19 +02:00
|
|
|
log_syntax(unit, LOG_ERR, filename, line, r,
|
|
|
|
"Failed to parse Bond ARP ip target address, ignoring assignment: %s",
|
|
|
|
rvalue);
|
2015-10-23 18:36:42 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (r == 0)
|
2019-04-12 07:14:19 +02:00
|
|
|
return 0;
|
2015-03-09 10:58:29 +01:00
|
|
|
|
2019-04-12 07:14:19 +02:00
|
|
|
r = in_addr_from_string(AF_INET, n, &ip);
|
2015-03-09 10:58:29 +01:00
|
|
|
if (r < 0) {
|
2019-04-12 07:14:19 +02:00
|
|
|
log_syntax(unit, LOG_ERR, filename, line, r,
|
|
|
|
"Bond ARP ip target address is invalid, ignoring assignment: %s", n);
|
|
|
|
continue;
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 07:14:19 +02:00
|
|
|
r = ordered_set_ensure_allocated(&b->arp_ip_targets, NULL);
|
|
|
|
if (r < 0)
|
|
|
|
return log_oom();
|
|
|
|
|
|
|
|
if (ordered_set_size(b->arp_ip_targets) >= NETDEV_BOND_ARP_TARGETS_MAX) {
|
|
|
|
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
|
|
|
"Too many ARP ip targets are specified. The maximum number is %d. Ignoring assignment: %s",
|
|
|
|
NETDEV_BOND_ARP_TARGETS_MAX, n);
|
|
|
|
continue;
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 07:14:19 +02:00
|
|
|
r = ordered_set_put(b->arp_ip_targets, UINT32_TO_PTR(ip.in.s_addr));
|
|
|
|
if (r == -EEXIST)
|
|
|
|
log_syntax(unit, LOG_WARNING, filename, line, r,
|
|
|
|
"Bond ARP ip target address is duplicated, ignoring assignment: %s", n);
|
|
|
|
if (r < 0)
|
|
|
|
log_syntax(unit, LOG_ERR, filename, line, r,
|
|
|
|
"Failed to store bond ARP ip target address '%s', ignoring assignment: %m", n);
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 07:15:29 +02:00
|
|
|
int config_parse_ad_actor_sys_prio(
|
|
|
|
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) {
|
2018-11-02 02:31:20 +01:00
|
|
|
Bond *b = userdata;
|
|
|
|
uint16_t v;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
r = safe_atou16(rvalue, &v);
|
|
|
|
if (r < 0) {
|
2019-04-12 07:15:29 +02:00
|
|
|
log_syntax(unit, LOG_ERR, filename, line, r,
|
|
|
|
"Failed to parse actor system priority '%s', ignoring: %m", rvalue);
|
2018-11-02 02:31:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v == 0) {
|
2019-04-12 07:15:29 +02:00
|
|
|
log_syntax(unit, LOG_ERR, filename, line, 0,
|
|
|
|
"Failed to parse actor system priority '%s'. Range is [1,65535], ignoring.",
|
|
|
|
rvalue);
|
2018-11-02 02:31:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
b->ad_actor_sys_prio = v;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-12 07:15:29 +02:00
|
|
|
int config_parse_ad_user_port_key(
|
|
|
|
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) {
|
2018-11-02 02:31:20 +01:00
|
|
|
Bond *b = userdata;
|
|
|
|
uint16_t v;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
r = safe_atou16(rvalue, &v);
|
|
|
|
if (r < 0) {
|
2019-04-12 07:15:29 +02:00
|
|
|
log_syntax(unit, LOG_ERR, filename, line, r,
|
|
|
|
"Failed to parse user port key '%s', ignoring: %m", rvalue);
|
2018-11-02 02:31:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v > 1023) {
|
2019-04-12 07:15:29 +02:00
|
|
|
log_syntax(unit, LOG_ERR, filename, line, 0,
|
|
|
|
"Failed to parse user port key '%s'. Range is [0…1023], ignoring.", rvalue);
|
2018-11-02 02:31:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
b->ad_user_port_key = v;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-12 06:37:02 +02:00
|
|
|
int config_parse_ad_actor_system(
|
|
|
|
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) {
|
2018-11-02 02:31:20 +01:00
|
|
|
Bond *b = userdata;
|
2019-04-12 06:37:02 +02:00
|
|
|
struct ether_addr n;
|
2018-11-02 02:31:20 +01:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2019-04-12 06:37:02 +02:00
|
|
|
r = ether_addr_from_string(rvalue, &n);
|
2018-11-02 02:31:20 +01:00
|
|
|
if (r < 0) {
|
2019-04-12 06:37:02 +02:00
|
|
|
log_syntax(unit, LOG_ERR, filename, line, r,
|
|
|
|
"Not a valid MAC address %s. Ignoring assignment: %m",
|
|
|
|
rvalue);
|
2018-11-02 02:31:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2019-04-12 06:37:02 +02:00
|
|
|
if (ether_addr_is_null(&n) || (n.ether_addr_octet[0] & 0x01)) {
|
|
|
|
log_syntax(unit, LOG_ERR, filename, line, 0,
|
|
|
|
"Not a valid MAC address %s, can not be null or multicast. Ignoring assignment.",
|
|
|
|
rvalue);
|
2018-11-02 02:31:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-12 06:37:02 +02:00
|
|
|
b->ad_actor_system = n;
|
2018-11-02 02:31:20 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-09 10:58:29 +01:00
|
|
|
static void bond_done(NetDev *netdev) {
|
2015-10-25 04:54:31 +01:00
|
|
|
Bond *b;
|
2015-03-09 10:58:29 +01:00
|
|
|
|
|
|
|
assert(netdev);
|
2015-10-25 04:54:31 +01:00
|
|
|
b = BOND(netdev);
|
2015-03-09 10:58:29 +01:00
|
|
|
assert(b);
|
|
|
|
|
2019-04-12 07:14:19 +02:00
|
|
|
ordered_set_free(b->arp_ip_targets);
|
2015-03-09 10:58:29 +01:00
|
|
|
}
|
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
static void bond_init(NetDev *netdev) {
|
2015-10-25 04:54:31 +01:00
|
|
|
Bond *b;
|
2014-07-16 13:17:10 +02:00
|
|
|
|
|
|
|
assert(netdev);
|
2015-10-25 04:54:31 +01:00
|
|
|
|
|
|
|
b = BOND(netdev);
|
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
assert(b);
|
2014-07-04 19:05:02 +02:00
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
b->mode = _NETDEV_BOND_MODE_INVALID;
|
2014-07-21 15:07:05 +02:00
|
|
|
b->xmit_hash_policy = _NETDEV_BOND_XMIT_HASH_POLICY_INVALID;
|
2014-07-21 15:22:14 +02:00
|
|
|
b->lacp_rate = _NETDEV_BOND_LACP_RATE_INVALID;
|
2015-03-09 10:58:29 +01:00
|
|
|
b->ad_select = _NETDEV_BOND_AD_SELECT_INVALID;
|
|
|
|
b->fail_over_mac = _NETDEV_BOND_FAIL_OVER_MAC_INVALID;
|
|
|
|
b->arp_validate = _NETDEV_BOND_ARP_VALIDATE_INVALID;
|
|
|
|
b->arp_all_targets = _NETDEV_BOND_ARP_ALL_TARGETS_INVALID;
|
|
|
|
b->primary_reselect = _NETDEV_BOND_PRIMARY_RESELECT_INVALID;
|
|
|
|
|
|
|
|
b->all_slaves_active = false;
|
2018-12-13 10:23:07 +01:00
|
|
|
b->tlb_dynamic_lb = -1;
|
2015-03-09 10:58:29 +01:00
|
|
|
|
|
|
|
b->resend_igmp = RESEND_IGMP_DEFAULT;
|
|
|
|
b->packets_per_slave = PACKETS_PER_SLAVE_DEFAULT;
|
|
|
|
b->num_grat_arp = GRATUITOUS_ARP_DEFAULT;
|
|
|
|
b->lp_interval = LEARNING_PACKETS_INTERVAL_MIN_SEC;
|
2014-07-04 19:05:02 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 14:07:34 +02:00
|
|
|
const NetDevVTable bond_vtable = {
|
2014-07-16 13:17:10 +02:00
|
|
|
.object_size = sizeof(Bond),
|
|
|
|
.init = bond_init,
|
2015-03-09 10:58:29 +01:00
|
|
|
.done = bond_done,
|
2019-11-22 11:43:26 +01:00
|
|
|
.sections = NETDEV_COMMON_SECTIONS "Bond\0",
|
2014-07-06 14:07:34 +02:00
|
|
|
.fill_message_create = netdev_bond_fill_message_create,
|
2014-07-16 13:17:10 +02:00
|
|
|
.create_type = NETDEV_CREATE_MASTER,
|
2019-05-23 04:27:12 +02:00
|
|
|
.generate_mac = true,
|
2014-07-06 14:07:34 +02:00
|
|
|
};
|