diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-05-10 23:29:07 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-05-11 06:24:04 +0900 |
commit | 4799f19e30623fcbc12fe0d39b7fbbd5b7ea1832 (patch) | |
tree | d5683ad757a2ae492b5b59dd8ff147c9b47f877f | |
parent | 9a81f119562879d93a8d518da39a5e61d457b36a (diff) | |
download | systemd-4799f19e30623fcbc12fe0d39b7fbbd5b7ea1832.tar.gz systemd-4799f19e30623fcbc12fe0d39b7fbbd5b7ea1832.tar.bz2 systemd-4799f19e30623fcbc12fe0d39b7fbbd5b7ea1832.zip |
network: move link_set_bond() to netdev/bond.c
-rw-r--r-- | src/network/netdev/bond.c | 74 | ||||
-rw-r--r-- | src/network/netdev/bond.h | 2 | ||||
-rw-r--r-- | src/network/networkd-link.c | 73 |
3 files changed, 77 insertions, 72 deletions
diff --git a/src/network/netdev/bond.c b/src/network/netdev/bond.c index 166aa37139..240cfe34e2 100644 --- a/src/network/netdev/bond.c +++ b/src/network/netdev/bond.c @@ -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, diff --git a/src/network/netdev/bond.h b/src/network/netdev/bond.h index 038272f107..28796a3a8b 100644 --- a/src/network/netdev/bond.h +++ b/src/network/netdev/bond.h @@ -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_; diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 8ad590dae3..aa28828354 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -12,6 +12,7 @@ #include "fd-util.h" #include "fileio.h" #include "missing_network.h" +#include "netdev/bond.h" #include "netdev/bridge.h" #include "netdev/vrf.h" #include "netlink-util.h" @@ -1500,78 +1501,6 @@ static int link_set_flags(Link *link) { 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; -} - -static 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; -} - static int link_acquire_ipv6_conf(Link *link) { int r; |