network: move link_set_bridge to netdev/bridge.c
This commit is contained in:
parent
3ddcbeea45
commit
9a81f11956
|
@ -5,6 +5,7 @@
|
|||
#include "missing.h"
|
||||
#include "netlink-util.h"
|
||||
#include "netdev/bridge.h"
|
||||
#include "network-internal.h"
|
||||
#include "networkd-manager.h"
|
||||
#include "vlan-util.h"
|
||||
|
||||
|
@ -138,6 +139,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;
|
||||
|
||||
|
|
|
@ -22,3 +22,5 @@ typedef struct Bridge {
|
|||
|
||||
DEFINE_NETDEV_CAST(BRIDGE, Bridge);
|
||||
extern const NetDevVTable bridge_vtable;
|
||||
|
||||
int link_set_bridge(Link *link);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "missing_network.h"
|
||||
#include "netdev/bridge.h"
|
||||
#include "netdev/vrf.h"
|
||||
#include "netlink-util.h"
|
||||
#include "network-internal.h"
|
||||
|
@ -1353,22 +1354,6 @@ static int link_set_proxy_arp(Link *link) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int link_set_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
|
||||
log_link_debug(link, "Set link");
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EEXIST) {
|
||||
log_link_error_errno(link, r, "Could not join netdev: %m");
|
||||
link_enter_failed(link);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int link_configure_after_setting_mtu(Link *link);
|
||||
|
||||
static int set_mtu_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
|
@ -1515,123 +1500,6 @@ static int link_set_flags(Link *link) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static 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_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 int link_set_bond_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
int r;
|
||||
|
||||
|
|
Loading…
Reference in a new issue