Merge pull request #12516 from yuwata/network-split-link
networkd: split networkd-link.c
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
#include "conf-parser.h"
|
||||
#include "ether-addr-util.h"
|
||||
#include "extract-word.h"
|
||||
#include "netlink-util.h"
|
||||
#include "networkd-manager.h"
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
|
||||
@@ -291,6 +293,78 @@ static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlin
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int config_parse_arp_ip_target_address(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
|
||||
@@ -120,6 +120,8 @@ typedef struct Bond {
|
||||
DEFINE_NETDEV_CAST(BOND, Bond);
|
||||
extern const NetDevVTable bond_vtable;
|
||||
|
||||
int link_set_bond(Link *link);
|
||||
|
||||
const char *bond_mode_to_string(BondMode d) _const_;
|
||||
BondMode bond_mode_from_string(const char *d) _pure_;
|
||||
|
||||
|
||||
@@ -5,9 +5,22 @@
|
||||
#include "missing.h"
|
||||
#include "netlink-util.h"
|
||||
#include "netdev/bridge.h"
|
||||
#include "network-internal.h"
|
||||
#include "networkd-manager.h"
|
||||
#include "string-table.h"
|
||||
#include "vlan-util.h"
|
||||
|
||||
static const char* const multicast_router_table[_MULTICAST_ROUTER_MAX] = {
|
||||
[MULTICAST_ROUTER_NONE] = "no",
|
||||
[MULTICAST_ROUTER_TEMPORARY_QUERY] = "query",
|
||||
[MULTICAST_ROUTER_PERMANENT] = "permanent",
|
||||
[MULTICAST_ROUTER_TEMPORARY] = "temporary",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(multicast_router, MulticastRouter, _MULTICAST_ROUTER_INVALID);
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_multicast_router, multicast_router, MulticastRouter,
|
||||
"Failed to parse bridge multicast router setting");
|
||||
|
||||
/* callback for bridge netdev's parameter set */
|
||||
static int netdev_bridge_set_handler(sd_netlink *rtnl, sd_netlink_message *m, NetDev *netdev) {
|
||||
int r;
|
||||
@@ -138,6 +151,142 @@ static int netdev_bridge_post_create(NetDev *netdev, Link *link, sd_netlink_mess
|
||||
return r;
|
||||
}
|
||||
|
||||
static int link_set_bridge_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 bridge interface: %m");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int link_set_bridge(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_SETLINK, link->ifindex);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not allocate RTM_SETLINK message: %m");
|
||||
|
||||
r = sd_rtnl_message_link_set_family(req, PF_BRIDGE);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not set message family: %m");
|
||||
|
||||
r = sd_netlink_message_open_container(req, IFLA_PROTINFO);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_PROTINFO attribute: %m");
|
||||
|
||||
if (link->network->use_bpdu >= 0) {
|
||||
r = sd_netlink_message_append_u8(req, IFLA_BRPORT_GUARD, link->network->use_bpdu);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_GUARD attribute: %m");
|
||||
}
|
||||
|
||||
if (link->network->hairpin >= 0) {
|
||||
r = sd_netlink_message_append_u8(req, IFLA_BRPORT_MODE, link->network->hairpin);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_MODE attribute: %m");
|
||||
}
|
||||
|
||||
if (link->network->fast_leave >= 0) {
|
||||
r = sd_netlink_message_append_u8(req, IFLA_BRPORT_FAST_LEAVE, link->network->fast_leave);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_FAST_LEAVE attribute: %m");
|
||||
}
|
||||
|
||||
if (link->network->allow_port_to_be_root >= 0) {
|
||||
r = sd_netlink_message_append_u8(req, IFLA_BRPORT_PROTECT, link->network->allow_port_to_be_root);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_PROTECT attribute: %m");
|
||||
}
|
||||
|
||||
if (link->network->unicast_flood >= 0) {
|
||||
r = sd_netlink_message_append_u8(req, IFLA_BRPORT_UNICAST_FLOOD, link->network->unicast_flood);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_UNICAST_FLOOD attribute: %m");
|
||||
}
|
||||
|
||||
if (link->network->multicast_flood >= 0) {
|
||||
r = sd_netlink_message_append_u8(req, IFLA_BRPORT_MCAST_FLOOD, link->network->multicast_flood);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_MCAST_FLOOD attribute: %m");
|
||||
}
|
||||
|
||||
if (link->network->multicast_to_unicast >= 0) {
|
||||
r = sd_netlink_message_append_u8(req, IFLA_BRPORT_MCAST_TO_UCAST, link->network->multicast_to_unicast);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_MCAST_TO_UCAST attribute: %m");
|
||||
}
|
||||
|
||||
if (link->network->neighbor_suppression >= 0) {
|
||||
r = sd_netlink_message_append_u8(req, IFLA_BRPORT_NEIGH_SUPPRESS, link->network->neighbor_suppression);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_NEIGH_SUPPRESS attribute: %m");
|
||||
}
|
||||
|
||||
if (link->network->learning >= 0) {
|
||||
r = sd_netlink_message_append_u8(req, IFLA_BRPORT_LEARNING, link->network->learning);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_LEARNING attribute: %m");
|
||||
}
|
||||
|
||||
if (link->network->bridge_proxy_arp >= 0) {
|
||||
r = sd_netlink_message_append_u8(req, IFLA_BRPORT_PROXYARP, link->network->bridge_proxy_arp);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_PROXYARP attribute: %m");
|
||||
}
|
||||
|
||||
if (link->network->bridge_proxy_arp_wifi >= 0) {
|
||||
r = sd_netlink_message_append_u8(req, IFLA_BRPORT_PROXYARP_WIFI, link->network->bridge_proxy_arp_wifi);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_PROXYARP_WIFI attribute: %m");
|
||||
}
|
||||
|
||||
if (link->network->cost != 0) {
|
||||
r = sd_netlink_message_append_u32(req, IFLA_BRPORT_COST, link->network->cost);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_COST attribute: %m");
|
||||
}
|
||||
|
||||
if (link->network->priority != LINK_BRIDGE_PORT_PRIORITY_INVALID) {
|
||||
r = sd_netlink_message_append_u16(req, IFLA_BRPORT_PRIORITY, link->network->priority);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_PRIORITY attribute: %m");
|
||||
}
|
||||
|
||||
if (link->network->multicast_router != _MULTICAST_ROUTER_INVALID) {
|
||||
r = sd_netlink_message_append_u8(req, IFLA_BRPORT_MULTICAST_ROUTER, link->network->multicast_router);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_MULTICAST_ROUTER 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 = netlink_call_async(link->manager->rtnl, NULL, req, link_set_bridge_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;
|
||||
}
|
||||
|
||||
static void bridge_init(NetDev *n) {
|
||||
Bridge *b;
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
#include "netdev/netdev.h"
|
||||
#include <netinet/in.h>
|
||||
#include <linux/if_bridge.h>
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "netdev.h"
|
||||
|
||||
typedef struct Bridge {
|
||||
NetDev meta;
|
||||
@@ -20,5 +24,21 @@ typedef struct Bridge {
|
||||
usec_t ageing_time;
|
||||
} Bridge;
|
||||
|
||||
typedef enum MulticastRouter {
|
||||
MULTICAST_ROUTER_NONE = MDB_RTR_TYPE_DISABLED,
|
||||
MULTICAST_ROUTER_TEMPORARY_QUERY = MDB_RTR_TYPE_TEMP_QUERY,
|
||||
MULTICAST_ROUTER_PERMANENT = MDB_RTR_TYPE_PERM,
|
||||
MULTICAST_ROUTER_TEMPORARY = MDB_RTR_TYPE_TEMP,
|
||||
_MULTICAST_ROUTER_MAX,
|
||||
_MULTICAST_ROUTER_INVALID = -1,
|
||||
} MulticastRouter;
|
||||
|
||||
DEFINE_NETDEV_CAST(BRIDGE, Bridge);
|
||||
extern const NetDevVTable bridge_vtable;
|
||||
|
||||
int link_set_bridge(Link *link);
|
||||
|
||||
const char* multicast_router_to_string(MulticastRouter i) _const_;
|
||||
MulticastRouter multicast_router_from_string(const char *s) _pure_;
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_multicast_router);
|
||||
|
||||
@@ -254,7 +254,7 @@ static int netdev_enslave_ready(NetDev *netdev, Link* link, link_netlink_message
|
||||
|
||||
if (link->flags & IFF_UP && netdev->kind == NETDEV_KIND_BOND) {
|
||||
log_netdev_debug(netdev, "Link '%s' was up when attempting to enslave it. Bringing link down.", link->ifname);
|
||||
r = link_down(link);
|
||||
r = link_down(link, NULL);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not bring link down: %m");
|
||||
}
|
||||
|
||||
@@ -401,7 +401,7 @@ static void resolve_endpoints(NetDev *netdev) {
|
||||
WireguardPeer *peer;
|
||||
Wireguard *w;
|
||||
Iterator i;
|
||||
int r = 0;
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
w = WIREGUARD(netdev);
|
||||
|
||||
Reference in New Issue
Block a user