diff options
50 files changed, 817 insertions, 758 deletions
diff --git a/src/libsystemd/sd-device/test-sd-device-monitor.c b/src/libsystemd/sd-device/test-sd-device-monitor.c index ae973cdba3..e6b289e6e4 100644 --- a/src/libsystemd/sd-device/test-sd-device-monitor.c +++ b/src/libsystemd/sd-device/test-sd-device-monitor.c @@ -302,7 +302,7 @@ int main(int argc, char *argv[]) { r = test_receive_device_fail(); if (r < 0) { assert_se(r == -EPERM && detect_container() > 0); - return log_tests_skipped("Running in container? Skipping remaining tests"); + return log_tests_skipped("Running in container"); } assert_se(sd_device_new_from_syspath(&loopback, "/sys/class/net/lo") >= 0); diff --git a/src/network/netdev/bareudp.c b/src/network/netdev/bareudp.c index 8ff0eb1360..24d3afb877 100644 --- a/src/network/netdev/bareudp.c +++ b/src/network/netdev/bareudp.c @@ -33,11 +33,11 @@ static int netdev_bare_udp_fill_message_create(NetDev *netdev, Link *link, sd_ne r = sd_netlink_message_append_u16(m, IFLA_BAREUDP_ETHERTYPE, htobe16(u->iftype)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BAREUDP_ETHERTYPE attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, IFLA_BAREUDP_PORT, htobe16(u->dest_port)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BAREUDP_PORT attribute: %m"); + return r; return 0; } diff --git a/src/network/netdev/batadv.c b/src/network/netdev/batadv.c index 15f3aee3a6..2a13aa31dd 100644 --- a/src/network/netdev/batadv.c +++ b/src/network/netdev/batadv.c @@ -114,64 +114,73 @@ static int netdev_batman_set_handler(sd_netlink *rtnl, sd_netlink_message *m, Ne return 1; } -static int netdev_batadv_post_create(NetDev *netdev, Link *link, sd_netlink_message *m) { +static int netdev_batadv_post_create_message(NetDev *netdev, sd_netlink_message *message) { BatmanAdvanced *b; int r; - _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL; - assert(netdev); - - b = BATADV(netdev); - assert(b); - - r = sd_genl_message_new(netdev->manager->genl, BATADV_NL_NAME, BATADV_CMD_SET_MESH, &message); - if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to allocate generic netlink message: %m"); + assert_se(b = BATADV(netdev)); r = sd_netlink_message_append_u32(message, BATADV_ATTR_MESH_IFINDEX, netdev->ifindex); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to set ifindex: %m"); + return r; r = sd_netlink_message_append_u8(message, BATADV_ATTR_GW_MODE, b->gateway_mode); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to set gateway_mode: %m"); + return r; r = sd_netlink_message_append_u8(message, BATADV_ATTR_AGGREGATED_OGMS_ENABLED, b->aggregation); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to set aggregation: %m"); + return r; r = sd_netlink_message_append_u8(message, BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED, b->bridge_loop_avoidance); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to set bridge_loop_avoidance: %m"); + return r; r = sd_netlink_message_append_u8(message, BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED, b->distributed_arp_table); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to set distributed_arp_table: %m"); + return r; r = sd_netlink_message_append_u8(message, BATADV_ATTR_FRAGMENTATION_ENABLED, b->fragmentation); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to set fragmentation: %m"); + return r; r = sd_netlink_message_append_u8(message, BATADV_ATTR_HOP_PENALTY, b->hop_penalty); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to set hop_penalty: %m"); + return r; r = sd_netlink_message_append_u32(message, BATADV_ATTR_ORIG_INTERVAL, DIV_ROUND_UP(b->originator_interval, USEC_PER_MSEC)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to set orig_interval: %m"); + return r; r = sd_netlink_message_append_u32(message, BATADV_ATTR_GW_BANDWIDTH_DOWN, b->gateway_bandwidth_down); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to set gateway_bandwidth_down: %m"); + return r; r = sd_netlink_message_append_u32(message, BATADV_ATTR_GW_BANDWIDTH_UP, b->gateway_bandwidth_up); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to set gateway_bandwidth_up: %m"); + return r; + + return 0; +} + +static int netdev_batadv_post_create(NetDev *netdev, Link *link, sd_netlink_message *m) { + _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL; + int r; + + assert(netdev); + + r = sd_genl_message_new(netdev->manager->genl, BATADV_NL_NAME, BATADV_CMD_SET_MESH, &message); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not allocate netlink message: %m"); + + r = netdev_batadv_post_create_message(netdev, message); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not create netlink message: %m"); r = netlink_call_async(netdev->manager->genl, NULL, message, netdev_batman_set_handler, netdev_destroy_callback, netdev); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not send batman device message: %m"); + return log_netdev_error_errno(netdev, r, "Could not send netlink message: %m"); netdev_ref(netdev); @@ -190,9 +199,9 @@ static int netdev_batadv_fill_message_create(NetDev *netdev, Link *link, sd_netl r = sd_netlink_message_append_string(m, IFLA_BATADV_ALGO_NAME, batadv_routing_algorithm_kernel_to_string(b->routing_algorithm)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BATADV_ALGO_NAME attribute: %m"); + return r; - return r; + return 0; } const NetDevVTable batadv_vtable = { diff --git a/src/network/netdev/bond.c b/src/network/netdev/bond.c index 5d94aa1d68..b0af12c8e2 100644 --- a/src/network/netdev/bond.c +++ b/src/network/netdev/bond.c @@ -71,50 +71,50 @@ static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlin if (b->mode != _NETDEV_BOND_MODE_INVALID) { r = sd_netlink_message_append_u8(m, IFLA_BOND_MODE, b->mode); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_MODE attribute: %m"); + return r; } if (b->xmit_hash_policy != _NETDEV_BOND_XMIT_HASH_POLICY_INVALID) { r = sd_netlink_message_append_u8(m, IFLA_BOND_XMIT_HASH_POLICY, b->xmit_hash_policy); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_XMIT_HASH_POLICY attribute: %m"); + return r; } if (b->lacp_rate != _NETDEV_BOND_LACP_RATE_INVALID && b->mode == NETDEV_BOND_MODE_802_3AD) { r = sd_netlink_message_append_u8(m, IFLA_BOND_AD_LACP_RATE, b->lacp_rate); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_LACP_RATE attribute: %m"); + return r; } if (b->miimon != 0) { r = sd_netlink_message_append_u32(m, IFLA_BOND_MIIMON, b->miimon / USEC_PER_MSEC); if (r < 0) - log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_BOND_MIIMON attribute: %m"); + return r; } if (b->downdelay != 0) { r = sd_netlink_message_append_u32(m, IFLA_BOND_DOWNDELAY, b->downdelay / USEC_PER_MSEC); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_DOWNDELAY attribute: %m"); + return r; } if (b->updelay != 0) { r = sd_netlink_message_append_u32(m, IFLA_BOND_UPDELAY, b->updelay / USEC_PER_MSEC); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_UPDELAY attribute: %m"); + return r; } if (b->arp_interval != 0) { r = sd_netlink_message_append_u32(m, IFLA_BOND_ARP_INTERVAL, b->arp_interval / USEC_PER_MSEC); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_INTERVAL attribute: %m"); + return r; if (b->lp_interval >= LEARNING_PACKETS_INTERVAL_MIN_SEC && b->lp_interval <= LEARNING_PACKETS_INTERVAL_MAX_SEC) { r = sd_netlink_message_append_u32(m, IFLA_BOND_LP_INTERVAL, b->lp_interval / USEC_PER_SEC); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_LP_INTERVAL attribute: %m"); + return r; } } @@ -122,85 +122,85 @@ static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlin b->mode == NETDEV_BOND_MODE_802_3AD) { r = sd_netlink_message_append_u8(m, IFLA_BOND_AD_SELECT, b->ad_select); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_SELECT attribute: %m"); + return r; } if (b->fail_over_mac != _NETDEV_BOND_FAIL_OVER_MAC_INVALID && b->mode == NETDEV_BOND_MODE_ACTIVE_BACKUP) { r = sd_netlink_message_append_u8(m, IFLA_BOND_FAIL_OVER_MAC, b->fail_over_mac); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_FAIL_OVER_MAC attribute: %m"); + return r; } if (b->arp_validate != _NETDEV_BOND_ARP_VALIDATE_INVALID) { r = sd_netlink_message_append_u32(m, IFLA_BOND_ARP_VALIDATE, b->arp_validate); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_VALIDATE attribute: %m"); + return r; } if (b->arp_all_targets != _NETDEV_BOND_ARP_ALL_TARGETS_INVALID) { r = sd_netlink_message_append_u32(m, IFLA_BOND_ARP_ALL_TARGETS, b->arp_all_targets); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %m"); + return r; } if (b->primary_reselect != _NETDEV_BOND_PRIMARY_RESELECT_INVALID) { r = sd_netlink_message_append_u8(m, IFLA_BOND_PRIMARY_RESELECT, b->primary_reselect); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_PRIMARY_RESELECT attribute: %m"); + return r; } if (b->resend_igmp <= RESEND_IGMP_MAX) { r = sd_netlink_message_append_u32(m, IFLA_BOND_RESEND_IGMP, b->resend_igmp); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_RESEND_IGMP attribute: %m"); + return r; } if (b->packets_per_slave <= PACKETS_PER_SLAVE_MAX && b->mode == NETDEV_BOND_MODE_BALANCE_RR) { r = sd_netlink_message_append_u32(m, IFLA_BOND_PACKETS_PER_SLAVE, b->packets_per_slave); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_PACKETS_PER_SLAVE attribute: %m"); + return r; } if (b->num_grat_arp <= GRATUITOUS_ARP_MAX) { r = sd_netlink_message_append_u8(m, IFLA_BOND_NUM_PEER_NOTIF, b->num_grat_arp); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_NUM_PEER_NOTIF attribute: %m"); + return r; } if (b->min_links != 0) { r = sd_netlink_message_append_u32(m, IFLA_BOND_MIN_LINKS, b->min_links); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_MIN_LINKS attribute: %m"); + return r; } 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"); + return r; } 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"); + return r; } 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); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_ACTOR_SYSTEM attribute: %m"); + return r; } r = sd_netlink_message_append_u8(m, IFLA_BOND_ALL_SLAVES_ACTIVE, b->all_slaves_active); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ALL_SLAVES_ACTIVE attribute: %m"); + return r; 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"); + return r; } if (b->arp_interval > 0 && !ordered_set_isempty(b->arp_ip_targets)) { @@ -209,17 +209,17 @@ static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlin 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"); + return r; ORDERED_SET_FOREACH(val, b->arp_ip_targets) { r = sd_netlink_message_append_u32(m, n++, PTR_TO_UINT32(val)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %m"); + return r; } 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"); + return r; } return 0; diff --git a/src/network/netdev/bridge.c b/src/network/netdev/bridge.c index 64d65493ca..7c38708121 100644 --- a/src/network/netdev/bridge.c +++ b/src/network/netdev/bridge.c @@ -45,124 +45,132 @@ static int netdev_bridge_set_handler(sd_netlink *rtnl, sd_netlink_message *m, Ne return 1; } -static int netdev_bridge_post_create(NetDev *netdev, Link *link, sd_netlink_message *m) { - _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; +static int netdev_bridge_post_create_message(NetDev *netdev, sd_netlink_message *req) { Bridge *b; int r; - assert(netdev); - - b = BRIDGE(netdev); - - assert(b); - - r = sd_rtnl_message_new_link(netdev->manager->rtnl, &req, RTM_NEWLINK, netdev->ifindex); - if (r < 0) - return log_netdev_error_errno(netdev, 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"); + assert_se(b = BRIDGE(netdev)); r = sd_netlink_message_open_container(req, IFLA_LINKINFO); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINKINFO attribute: %m"); + return r; r = sd_netlink_message_open_container_union(req, IFLA_INFO_DATA, netdev_kind_to_string(netdev->kind)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m"); + return r; /* convert to jiffes */ if (b->forward_delay != USEC_INFINITY) { r = sd_netlink_message_append_u32(req, IFLA_BR_FORWARD_DELAY, usec_to_jiffies(b->forward_delay)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_FORWARD_DELAY attribute: %m"); + return r; } if (b->hello_time > 0) { r = sd_netlink_message_append_u32(req, IFLA_BR_HELLO_TIME, usec_to_jiffies(b->hello_time)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_HELLO_TIME attribute: %m"); + return r; } if (b->max_age > 0) { r = sd_netlink_message_append_u32(req, IFLA_BR_MAX_AGE, usec_to_jiffies(b->max_age)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_MAX_AGE attribute: %m"); + return r; } if (b->ageing_time != USEC_INFINITY) { r = sd_netlink_message_append_u32(req, IFLA_BR_AGEING_TIME, usec_to_jiffies(b->ageing_time)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_AGEING_TIME attribute: %m"); + return r; } if (b->priority > 0) { r = sd_netlink_message_append_u16(req, IFLA_BR_PRIORITY, b->priority); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_PRIORITY attribute: %m"); + return r; } if (b->group_fwd_mask > 0) { r = sd_netlink_message_append_u16(req, IFLA_BR_GROUP_FWD_MASK, b->group_fwd_mask); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_GROUP_FWD_MASK attribute: %m"); + return r; } if (b->default_pvid != VLANID_INVALID) { r = sd_netlink_message_append_u16(req, IFLA_BR_VLAN_DEFAULT_PVID, b->default_pvid); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_VLAN_DEFAULT_PVID attribute: %m"); + return r; } if (b->mcast_querier >= 0) { r = sd_netlink_message_append_u8(req, IFLA_BR_MCAST_QUERIER, b->mcast_querier); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_MCAST_QUERIER attribute: %m"); + return r; } if (b->mcast_snooping >= 0) { r = sd_netlink_message_append_u8(req, IFLA_BR_MCAST_SNOOPING, b->mcast_snooping); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_MCAST_SNOOPING attribute: %m"); + return r; } if (b->vlan_filtering >= 0) { r = sd_netlink_message_append_u8(req, IFLA_BR_VLAN_FILTERING, b->vlan_filtering); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_VLAN_FILTERING attribute: %m"); + return r; } if (b->vlan_protocol >= 0) { r = sd_netlink_message_append_u16(req, IFLA_BR_VLAN_PROTOCOL, b->vlan_protocol); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_VLAN_PROTOCOL attribute: %m"); + return r; } if (b->stp >= 0) { r = sd_netlink_message_append_u32(req, IFLA_BR_STP_STATE, b->stp); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_STP_STATE attribute: %m"); + return r; } if (b->igmp_version > 0) { r = sd_netlink_message_append_u8(req, IFLA_BR_MCAST_IGMP_VERSION, b->igmp_version); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_MCAST_IGMP_VERSION attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINKINFO attribute: %m"); + return r; r = sd_netlink_message_close_container(req); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m"); + return r; + + return 0; +} + +static int netdev_bridge_post_create(NetDev *netdev, Link *link, sd_netlink_message *m) { + _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; + int r; + + assert(netdev); + + r = sd_rtnl_message_new_link(netdev->manager->rtnl, &req, RTM_NEWLINK, netdev->ifindex); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not allocate netlink 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 message flags: %m"); + + r = netdev_bridge_post_create_message(netdev, req); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not create netlink message: %m"); r = netlink_call_async(netdev->manager->rtnl, NULL, req, netdev_bridge_set_handler, netdev_destroy_callback, netdev); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m"); + return log_netdev_error_errno(netdev, r, "Could not send netlink message: %m"); netdev_ref(netdev); diff --git a/src/network/netdev/fou-tunnel.c b/src/network/netdev/fou-tunnel.c index bc4c108a22..cd8f2f8087 100644 --- a/src/network/netdev/fou-tunnel.c +++ b/src/network/netdev/fou-tunnel.c @@ -24,30 +24,21 @@ DEFINE_STRING_TABLE_LOOKUP(fou_encap_type, FooOverUDPEncapType); DEFINE_CONFIG_PARSE_ENUM(config_parse_fou_encap_type, fou_encap_type, FooOverUDPEncapType, "Failed to parse Encapsulation="); -static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message **ret) { - _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; +static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message *m) { FouTunnel *t; uint8_t encap_type; int r; - assert(netdev); - - t = FOU(netdev); - - assert(t); - - r = sd_genl_message_new(netdev->manager->genl, FOU_GENL_NAME, FOU_CMD_ADD, &m); - if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to allocate generic netlink message: %m"); + assert_se(t = FOU(netdev)); r = sd_netlink_message_append_u16(m, FOU_ATTR_PORT, htobe16(t->port)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_PORT attribute: %m"); + return r; if (IN_SET(t->peer_family, AF_INET, AF_INET6)) { r = sd_netlink_message_append_u16(m, FOU_ATTR_PEER_PORT, htobe16(t->peer_port)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_PEER_PORT attribute: %m"); + return r; } switch (t->fou_encap_type) { @@ -63,36 +54,53 @@ static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message **r r = sd_netlink_message_append_u8(m, FOU_ATTR_TYPE, encap_type); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_TYPE attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, FOU_ATTR_AF, AF_INET); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_AF attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, FOU_ATTR_IPPROTO, t->fou_protocol); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_IPPROTO attribute: %m"); + return r; if (t->local_family == AF_INET) { r = sd_netlink_message_append_in_addr(m, FOU_ATTR_LOCAL_V4, &t->local.in); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_LOCAL_V4 attribute: %m"); + return r; } else if (t->local_family == AF_INET6) { r = sd_netlink_message_append_in6_addr(m, FOU_ATTR_LOCAL_V6, &t->local.in6); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_LOCAL_V6 attribute: %m"); + return r; } if (t->peer_family == AF_INET) { r = sd_netlink_message_append_in_addr(m, FOU_ATTR_PEER_V4, &t->peer.in); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_PEER_V4 attribute: %m"); + return r; } else if (t->peer_family == AF_INET6){ r = sd_netlink_message_append_in6_addr(m, FOU_ATTR_PEER_V6, &t->peer.in6); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_PEER_V6 attribute: %m"); + return r; } + return 0; +} + +static int netdev_create_fou_tunnel_message(NetDev *netdev, sd_netlink_message **ret) { + _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; + int r; + + assert(netdev); + + r = sd_genl_message_new(netdev->manager->genl, FOU_GENL_NAME, FOU_CMD_ADD, &m); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not allocate netlink message: %m"); + + r = netdev_fill_fou_tunnel_message(netdev, m); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not create netlink message: %m"); + *ret = TAKE_PTR(m); return 0; } @@ -124,7 +132,7 @@ static int netdev_fou_tunnel_create(NetDev *netdev) { assert(netdev); assert(FOU(netdev)); - r = netdev_fill_fou_tunnel_message(netdev, &m); + r = netdev_create_fou_tunnel_message(netdev, &m); if (r < 0) return r; diff --git a/src/network/netdev/geneve.c b/src/network/netdev/geneve.c index 224c17e979..777a32d75c 100644 --- a/src/network/netdev/geneve.c +++ b/src/network/netdev/geneve.c @@ -39,7 +39,7 @@ static int netdev_geneve_fill_message_create(NetDev *netdev, Link *link, sd_netl if (v->id <= GENEVE_VID_MAX) { r = sd_netlink_message_append_u32(m, IFLA_GENEVE_ID, v->id); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_ID attribute: %m"); + return r; } if (in_addr_is_set(v->remote_family, &v->remote)) { @@ -48,51 +48,51 @@ static int netdev_geneve_fill_message_create(NetDev *netdev, Link *link, sd_netl else r = sd_netlink_message_append_in6_addr(m, IFLA_GENEVE_REMOTE6, &v->remote.in6); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_REMOTE/IFLA_GENEVE_REMOTE6 attribute: %m"); + return r; } if (v->inherit) { r = sd_netlink_message_append_u8(m, IFLA_GENEVE_TTL_INHERIT, 1); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_TTL_INHERIT attribute: %m"); + return r; } else { r = sd_netlink_message_append_u8(m, IFLA_GENEVE_TTL, v->ttl); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_TTL attribute: %m"); + return r; } r = sd_netlink_message_append_u8(m, IFLA_GENEVE_TOS, v->tos); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_TOS attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_GENEVE_UDP_CSUM, v->udpcsum); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_UDP_CSUM attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_GENEVE_UDP_ZERO_CSUM6_TX, v->udp6zerocsumtx); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_UDP_ZERO_CSUM6_TX attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_GENEVE_UDP_ZERO_CSUM6_RX, v->udp6zerocsumrx); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_UDP_ZERO_CSUM6_RX attribute: %m"); + return r; if (v->dest_port != DEFAULT_GENEVE_DESTINATION_PORT) { r = sd_netlink_message_append_u16(m, IFLA_GENEVE_PORT, htobe16(v->dest_port)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_PORT attribute: %m"); + return r; } if (v->flow_label > 0) { r = sd_netlink_message_append_u32(m, IFLA_GENEVE_LABEL, htobe32(v->flow_label)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_LABEL attribute: %m"); + return r; } if (v->geneve_df != _NETDEV_GENEVE_DF_INVALID) { r = sd_netlink_message_append_u8(m, IFLA_GENEVE_DF, v->geneve_df); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_DF attribute: %m"); + return r; } return 0; diff --git a/src/network/netdev/ipoib.c b/src/network/netdev/ipoib.c index e0ff9e8c62..0e27f5f044 100644 --- a/src/network/netdev/ipoib.c +++ b/src/network/netdev/ipoib.c @@ -39,19 +39,19 @@ static int netdev_ipoib_fill_message_create(NetDev *netdev, Link *link, sd_netli if (ipoib->pkey > 0) { r = sd_netlink_message_append_u16(m, IFLA_IPOIB_PKEY, ipoib->pkey); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPOIB_PKEY attribute: %m"); + return r; } if (ipoib->mode >= 0) { r = sd_netlink_message_append_u16(m, IFLA_IPOIB_MODE, ipoib->mode); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPOIB_MODE attribute: %m"); + return r; } if (ipoib->umcast >= 0) { r = sd_netlink_message_append_u16(m, IFLA_IPOIB_UMCAST, ipoib->umcast); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPOIB_UMCAST attribute: %m"); + return r; } return 0; @@ -66,35 +66,35 @@ int ipoib_set_netlink_message(Link *link, sd_netlink_message *m) { r = sd_netlink_message_set_flags(m, NLM_F_REQUEST | NLM_F_ACK); if (r < 0) - return log_link_debug_errno(link, r, "Could not set netlink flags: %m"); + return r; r = sd_netlink_message_open_container(m, IFLA_LINKINFO); if (r < 0) - return log_link_debug_errno(link, r, "Failed to open IFLA_LINKINFO container: %m"); + return r; r = sd_netlink_message_open_container_union(m, IFLA_INFO_DATA, link->kind); if (r < 0) - return log_link_debug_errno(link, r, "Could not open IFLA_INFO_DATA container: %m"); + return r; if (link->network->ipoib_mode >= 0) { r = sd_netlink_message_append_u16(m, IFLA_IPOIB_MODE, link->network->ipoib_mode); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_IPOIB_MODE attribute: %m"); + return r; } if (link->network->ipoib_umcast >= 0) { r = sd_netlink_message_append_u16(m, IFLA_IPOIB_UMCAST, link->network->ipoib_umcast); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_IPOIB_UMCAST attribute: %m"); + return r; } r = sd_netlink_message_close_container(m); if (r < 0) - return log_link_debug_errno(link, r, "Failed to close IFLA_INFO_DATA container: %m"); + return r; r = sd_netlink_message_close_container(m); if (r < 0) - return log_link_debug_errno(link, r, "Failed to close IFLA_LINKINFO container: %m"); + return r; return 0; } diff --git a/src/network/netdev/ipvlan.c b/src/network/netdev/ipvlan.c index d15766cd7b..727e46085b 100644 --- a/src/network/netdev/ipvlan.c +++ b/src/network/netdev/ipvlan.c @@ -31,13 +31,13 @@ static int netdev_ipvlan_fill_message_create(NetDev *netdev, Link *link, sd_netl if (m->mode != _NETDEV_IPVLAN_MODE_INVALID) { r = sd_netlink_message_append_u16(req, IFLA_IPVLAN_MODE, m->mode); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPVLAN_MODE attribute: %m"); + return r; } if (m->flags != _NETDEV_IPVLAN_FLAGS_INVALID) { r = sd_netlink_message_append_u16(req, IFLA_IPVLAN_FLAGS, m->flags); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPVLAN_FLAGS attribute: %m"); + return r; } return 0; diff --git a/src/network/netdev/l2tp-tunnel.c b/src/network/netdev/l2tp-tunnel.c index cfe54f600c..d870a11e00 100644 --- a/src/network/netdev/l2tp-tunnel.c +++ b/src/network/netdev/l2tp-tunnel.c @@ -91,7 +91,7 @@ static int l2tp_session_new_static(L2tpTunnel *t, const char *filename, unsigned return 0; } -static int netdev_l2tp_fill_message_tunnel(NetDev *netdev, union in_addr_union *local_address, sd_netlink_message **ret) { +static int netdev_l2tp_create_message_tunnel(NetDev *netdev, union in_addr_union *local_address, sd_netlink_message **ret) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; uint16_t encap_type; L2tpTunnel *t; @@ -99,26 +99,23 @@ static int netdev_l2tp_fill_message_tunnel(NetDev *netdev, union in_addr_union * assert(netdev); assert(local_address); - - t = L2TP(netdev); - - assert(t); + assert_se(t = L2TP(netdev)); r = sd_genl_message_new(netdev->manager->genl, L2TP_GENL_NAME, L2TP_CMD_TUNNEL_CREATE, &m); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to create generic netlink message: %m"); + return r; r = sd_netlink_message_append_u32(m, L2TP_ATTR_CONN_ID, t->tunnel_id); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_CONN_ID attribute: %m"); + return r; r = sd_netlink_message_append_u32(m, L2TP_ATTR_PEER_CONN_ID, t->peer_tunnel_id); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_PEER_CONN_ID attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, L2TP_ATTR_PROTO_VERSION, 3); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_PROTO_VERSION attribute: %m"); + return r; switch(t->l2tp_encap_type) { case NETDEV_L2TP_ENCAPTYPE_IP: @@ -132,51 +129,51 @@ static int netdev_l2tp_fill_message_tunnel(NetDev *netdev, union in_addr_union * r = sd_netlink_message_append_u16(m, L2TP_ATTR_ENCAP_TYPE, encap_type); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_ENCAP_TYPE attribute: %m"); + return r; if (t->family == AF_INET) { r = sd_netlink_message_append_in_addr(m, L2TP_ATTR_IP_SADDR, &local_address->in); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_IP_SADDR attribute: %m"); + return r; r = sd_netlink_message_append_in_addr(m, L2TP_ATTR_IP_DADDR, &t->remote.in); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_IP_DADDR attribute: %m"); + return r; } else { r = sd_netlink_message_append_in6_addr(m, L2TP_ATTR_IP6_SADDR, &local_address->in6); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_IP6_SADDR attribute: %m"); + return r; r = sd_netlink_message_append_in6_addr(m, L2TP_ATTR_IP6_DADDR, &t->remote.in6); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_IP6_DADDR attribute: %m"); + return r; } if (encap_type == L2TP_ENCAPTYPE_UDP) { r = sd_netlink_message_append_u16(m, L2TP_ATTR_UDP_SPORT, t->l2tp_udp_sport); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_UDP_SPORT, attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, L2TP_ATTR_UDP_DPORT, t->l2tp_udp_dport); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_UDP_DPORT attribute: %m"); + return r; if (t->udp_csum) { r = sd_netlink_message_append_u8(m, L2TP_ATTR_UDP_CSUM, t->udp_csum); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_UDP_CSUM attribute: %m"); + return r; } if (t->udp6_csum_tx) { r = sd_netlink_message_append_flag(m, L2TP_ATTR_UDP_ZERO_CSUM6_TX); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_UDP_ZERO_CSUM6_TX attribute: %m"); + return r; } if (t->udp6_csum_rx) { r = sd_netlink_message_append_flag(m, L2TP_ATTR_UDP_ZERO_CSUM6_RX); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_UDP_ZERO_CSUM6_RX attribute: %m"); + return r; } } @@ -185,7 +182,7 @@ static int netdev_l2tp_fill_message_tunnel(NetDev *netdev, union in_addr_union * return 0; } -static int netdev_l2tp_fill_message_session(NetDev *netdev, L2tpSession *session, sd_netlink_message **ret) { +static int netdev_l2tp_create_message_session(NetDev *netdev, L2tpSession *session, sd_netlink_message **ret) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; uint16_t l2_spec_len; uint8_t l2_spec_type; @@ -197,27 +194,27 @@ static int netdev_l2tp_fill_message_session(NetDev *netdev, L2tpSession *session r = sd_genl_message_new(netdev->manager->genl, L2TP_GENL_NAME, L2TP_CMD_SESSION_CREATE, &m); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to create generic netlink message: %m"); + return r; r = sd_netlink_message_append_u32(m, L2TP_ATTR_CONN_ID, session->tunnel->tunnel_id); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_CONN_ID attribute: %m"); + return r; r = sd_netlink_message_append_u32(m, L2TP_ATTR_PEER_CONN_ID, session->tunnel->peer_tunnel_id); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_PEER_CONN_ID attribute: %m"); + return r; r = sd_netlink_message_append_u32(m, L2TP_ATTR_SESSION_ID, session->session_id); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_SESSION_ID attribute: %m"); + return r; r = sd_netlink_message_append_u32(m, L2TP_ATTR_PEER_SESSION_ID, session->peer_session_id); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_PEER_SESSION_ID attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, L2TP_ATTR_PW_TYPE, L2TP_PWTYPE_ETH); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_PW_TYPE attribute: %m"); + return r; switch (session->l2tp_l2spec_type) { case NETDEV_L2TP_L2SPECTYPE_NONE: @@ -233,15 +230,15 @@ static int netdev_l2tp_fill_message_session(NetDev *netdev, L2tpSession *session r = sd_netlink_message_append_u8(m, L2TP_ATTR_L2SPEC_TYPE, l2_spec_type); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_L2SPEC_TYPE attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, L2TP_ATTR_L2SPEC_LEN, l2_spec_len); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_L2SPEC_LEN attribute: %m"); + return r; r = sd_netlink_message_append_string(m, L2TP_ATTR_IFNAME, session->name); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_IFNAME attribute: %m"); + return r; *ret = TAKE_PTR(m); @@ -321,9 +318,9 @@ static int l2tp_create_session(NetDev *netdev, L2tpSession *session) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *n = NULL; int r; - r = netdev_l2tp_fill_message_session(netdev, session, &n); + r = netdev_l2tp_create_message_session(netdev, session, &n); if (r < 0) - return r; + return log_netdev_error_errno(netdev, r, "Failed to create netlink message: %m"); r = netlink_call_async(netdev->manager->genl, NULL, n, l2tp_create_session_handler, l2tp_session_destroy_callback, session); @@ -371,10 +368,7 @@ static int l2tp_create_tunnel(NetDev *netdev, Link *link) { int r; assert(netdev); - - t = L2TP(netdev); - - assert(t); + assert_se(t = L2TP(netdev)); r = l2tp_acquire_local_address(t, link, &local_address); if (r < 0) @@ -387,9 +381,9 @@ static int l2tp_create_tunnel(NetDev *netdev, Link *link) { log_netdev_debug(netdev, "Local address %s acquired.", strna(str)); } - r = netdev_l2tp_fill_message_tunnel(netdev, &local_address, &m); + r = netdev_l2tp_create_message_tunnel(netdev, &local_address, &m); if (r < 0) - return r; + return log_netdev_error_errno(netdev, r, "Failed to create netlink message: %m"); r = netlink_call_async(netdev->manager->genl, NULL, m, l2tp_create_tunnel_handler, netdev_destroy_callback, netdev); diff --git a/src/network/netdev/macsec.c b/src/network/netdev/macsec.c index f1a566a9ca..ebb8c9c7dc 100644 --- a/src/network/netdev/macsec.c +++ b/src/network/netdev/macsec.c @@ -218,7 +218,7 @@ static int macsec_transmit_association_new_static(MACsec *s, const char *filenam return 0; } -static int netdev_macsec_fill_message(NetDev *netdev, int command, sd_netlink_message **ret) { +static int netdev_macsec_create_message(NetDev *netdev, int command, sd_netlink_message **ret) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; int r; @@ -227,11 +227,11 @@ static int netdev_macsec_fill_message(NetDev *netdev, int command, sd_netlink_me r = sd_genl_message_new(netdev->manager->genl, MACSEC_GENL_NAME, command, &m); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to create generic netlink message: %m"); + return r; r = sd_netlink_message_append_u32(m, MACSEC_ATTR_IFINDEX, netdev->ifindex); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append MACSEC_ATTR_IFINDEX attribute: %m"); + return r; *ret = TAKE_PTR(m); @@ -247,15 +247,15 @@ static int netdev_macsec_fill_message_sci(NetDev *netdev, MACsecSCI *sci, sd_net r = sd_netlink_message_open_container(m, MACSEC_ATTR_RXSC_CONFIG); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append MACSEC_ATTR_RXSC_CONFIG attribute: %m"); + return r; r = sd_netlink_message_append_u64(m, MACSEC_RXSC_ATTR_SCI, sci->as_uint64); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append MACSEC_RXSC_ATTR_SCI attribute: %m"); + return r; r = sd_netlink_message_close_container(m); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append MACSEC_ATTR_RXSC_CONFIG attribute: %m"); + return r; return 0; } @@ -269,37 +269,37 @@ static int netdev_macsec_fill_message_sa(NetDev *netdev, SecurityAssociation *a, r = sd_netlink_message_open_container(m, MACSEC_ATTR_SA_CONFIG); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append MACSEC_ATTR_SA_CONFIG attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, MACSEC_SA_ATTR_AN, a->association_number); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append MACSEC_SA_ATTR_AN attribute: %m"); + return r; if (a->packet_number > 0) { r = sd_netlink_message_append_u32(m, MACSEC_SA_ATTR_PN, a->packet_number); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append MACSEC_SA_ATTR_PN attribute: %m"); + return r; } if (a->key_len > 0) { r = sd_netlink_message_append_data(m, MACSEC_SA_ATTR_KEYID, a->key_id, MACSEC_KEYID_LEN); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append MACSEC_SA_ATTR_KEYID attribute: %m"); + return r; r = sd_netlink_message_append_data(m, MACSEC_SA_ATTR_KEY, a->key, a->key_len); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append MACSEC_SA_ATTR_KEY attribute: %m"); + return r; } if (a->activate >= 0) { r = sd_netlink_message_append_u8(m, MACSEC_SA_ATTR_ACTIVE, a->activate); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append MACSEC_SA_ATTR_ACTIVE attribute: %m"); + return r; } r = sd_netlink_message_close_container(m); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append MACSEC_ATTR_SA_CONFIG attribute: %m"); + return r; return 0; } @@ -313,8 +313,7 @@ static int macsec_receive_association_handler(sd_netlink *rtnl, sd_netlink_messa r = sd_netlink_message_get_errno(m); if (r == -EEXIST) log_netdev_info(netdev, - "MACsec receive secure association exists, " - "using existing without changing its parameters"); + "MACsec receive secure association exists, using it without changing parameters"); else if (r < 0) { log_netdev_warning_errno(netdev, r, "Failed to add receive secure association: %m"); @@ -335,17 +334,17 @@ static int netdev_macsec_configure_receive_association(NetDev *netdev, ReceiveAs assert(netdev); assert(a); - r = netdev_macsec_fill_message(netdev, MACSEC_CMD_ADD_RXSA, &m); + r = netdev_macsec_create_message(netdev, MACSEC_CMD_ADD_RXSA, &m); if (r < 0) - return r; + return log_netdev_error_errno(netdev, r, "Failed to create netlink message: %m"); r = netdev_macsec_fill_message_sa(netdev, &a->sa, m); if (r < 0) - return r; + return log_netdev_error_errno(netdev, r, "Failed to fill netlink message: %m"); r = netdev_macsec_fill_message_sci(netdev, &a->sci, m); if (r < 0) - return r; + return log_netdev_error_errno(netdev, r, "Failed to fill netlink message: %m"); r = netlink_call_async(netdev->manager->genl, NULL, m, macsec_receive_association_handler, netdev_destroy_callback, netdev); @@ -371,8 +370,7 @@ static int macsec_receive_channel_handler(sd_netlink *rtnl, sd_netlink_message * r = sd_netlink_message_get_errno(m); if (r == -EEXIST) log_netdev_debug(netdev, - "MACsec receive channel exists, " - "using existing without changing its parameters"); + "MACsec receive channel exists, using it without changing parameters"); else if (r < 0) { log_netdev_warning_errno(netdev, r, "Failed to add receive secure channel: %m"); @@ -410,13 +408,13 @@ static int netdev_macsec_configure_receive_channel(NetDev *netdev, ReceiveChanne assert(netdev); assert(c); - r = netdev_macsec_fill_message(netdev, MACSEC_CMD_ADD_RXSC, &m); + r = netdev_macsec_create_message(netdev, MACSEC_CMD_ADD_RXSC, &m); if (r < 0) - return r; + return log_netdev_error_errno(netdev, r, "Failed to create netlink message: %m"); r = netdev_macsec_fill_message_sci(netdev, &c->sci, m); if (r < 0) - return r; + return log_netdev_error_errno(netdev, r, "Failed to fill netlink message: %m"); r = netlink_call_async(netdev->manager->genl, NULL, m, macsec_receive_channel_handler, receive_channel_destroy_callback, c); @@ -437,8 +435,7 @@ static int macsec_transmit_association_handler(sd_netlink *rtnl, sd_netlink_mess r = sd_netlink_message_get_errno(m); if (r == -EEXIST) log_netdev_info(netdev, - "MACsec transmit secure association exists, " - "using existing without changing its parameters"); + "MACsec transmit secure association exists, using it without changing parameters"); else if (r < 0) { log_netdev_warning_errno(netdev, r, "Failed to add transmit secure association: %m"); @@ -459,13 +456,13 @@ static int netdev_macsec_configure_transmit_association(NetDev *netdev, Transmit assert(netdev); assert(a); - r = netdev_macsec_fill_message(netdev, MACSEC_CMD_ADD_TXSA, &m); + r = netdev_macsec_create_message(netdev, MACSEC_CMD_ADD_TXSA, &m); if (r < 0) - return r; + return log_netdev_error_errno(netdev, r, "Failed to create netlink message: %m"); r = netdev_macsec_fill_message_sa(netdev, &a->sa, m); if (r < 0) - return r; + return log_netdev_error_errno(netdev, r, "Failed to fill netlink message: %m"); r = netlink_call_async(netdev->manager->genl, NULL, m, macsec_transmit_association_handler, netdev_destroy_callback, netdev); @@ -516,20 +513,20 @@ static int netdev_macsec_fill_message_create(NetDev *netdev, Link *link, sd_netl if (v->port > 0) { r = sd_netlink_message_append_u16(m, IFLA_MACSEC_PORT, v->port); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACSEC_PORT attribute: %m"); + return r; } if (v->encrypt >= 0) { r = sd_netlink_message_append_u8(m, IFLA_MACSEC_ENCRYPT, v->encrypt); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACSEC_ENCRYPT attribute: %m"); + return r; } r = sd_netlink_message_append_u8(m, IFLA_MACSEC_ENCODING_SA, v->encoding_an); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACSEC_ENCODING_SA attribute: %m"); + return r; - return r; + return 0; } int config_parse_macsec_port( diff --git a/src/network/netdev/macvlan.c b/src/network/netdev/macvlan.c index c41be6e78f..aca05f0f77 100644 --- a/src/network/netdev/macvlan.c +++ b/src/network/netdev/macvlan.c @@ -33,40 +33,40 @@ static int netdev_macvlan_fill_message_create(NetDev *netdev, Link *link, sd_net r = sd_netlink_message_append_u32(req, IFLA_MACVLAN_MACADDR_MODE, MACVLAN_MACADDR_SET); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACVLAN_MACADDR_MODE attribute: %m"); + return r; r = sd_netlink_message_open_container(req, IFLA_MACVLAN_MACADDR_DATA); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not open IFLA_MACVLAN_MACADDR_DATA container: %m"); + return r; SET_FOREACH(mac_addr, m->match_source_mac) { r = sd_netlink_message_append_ether_addr(req, IFLA_MACVLAN_MACADDR, mac_addr); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACVLAN_MACADDR attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not close IFLA_MACVLAN_MACADDR_DATA container: %m"); + return r; } if (m->mode != _NETDEV_MACVLAN_MODE_INVALID) { r = sd_netlink_message_append_u32(req, IFLA_MACVLAN_MODE, m->mode); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACVLAN_MODE attribute: %m"); + return r; } /* set the nopromisc flag if Promiscuous= of the link is explicitly set to false */ if (m->mode == NETDEV_MACVLAN_MODE_PASSTHRU && link->network->promiscuous == 0) { r = sd_netlink_message_append_u16(req, IFLA_MACVLAN_FLAGS, MACVLAN_FLAG_NOPROMISC); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACVLAN_FLAGS attribute: %m"); + return r; } if (m->bc_queue_length != UINT32_MAX) { r = sd_netlink_message_append_u32(req, IFLA_MACVLAN_BC_QUEUE_LEN, m->bc_queue_length); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACVLAN_BC_QUEUE_LEN attribute: %m"); + return r; } return 0; diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c index 97d06a0d16..18d118e230 100644 --- a/src/network/netdev/netdev.c +++ b/src/network/netdev/netdev.c @@ -478,34 +478,14 @@ finalize: return 0; } -static int netdev_create(NetDev *netdev, Link *link, link_netlink_message_handler_t callback) { - _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; - struct hw_addr_data hw_addr; +static int netdev_create_message(NetDev *netdev, Link *link, sd_netlink_message *m) { int r; - assert(netdev); - assert(!link || callback); - - /* create netdev */ - if (NETDEV_VTABLE(netdev)->create) { - assert(!link); - - r = NETDEV_VTABLE(netdev)->create(netdev); - if (r < 0) - return r; - - log_netdev_debug(netdev, "Created"); - return 0; - } - - r = sd_rtnl_message_new_link(netdev->manager->rtnl, &m, RTM_NEWLINK, 0); - if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not allocate RTM_NEWLINK message: %m"); - r = sd_netlink_message_append_string(m, IFLA_IFNAME, netdev->ifname); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IFNAME, attribute: %m"); + return r; + struct hw_addr_data hw_addr; r = netdev_generate_hw_addr(netdev, link, netdev->ifname, &netdev->hw_addr, &hw_addr); if (r < 0) return r; @@ -514,29 +494,29 @@ static int netdev_create(NetDev *netdev, Link *link, link_netlink_message_handle log_netdev_debug(netdev, "Using MAC address: %s", HW_ADDR_TO_STR(&hw_addr)); r = netlink_message_append_hw_addr(m, IFLA_ADDRESS, &hw_addr); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_ADDRESS attribute: %m"); + return r; } if (netdev->mtu != 0) { r = sd_netlink_message_append_u32(m, IFLA_MTU, netdev->mtu); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_MTU attribute: %m"); + return r; } if (link) { r = sd_netlink_message_append_u32(m, IFLA_LINK, link->ifindex); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINK attribute: %m"); + return r; } r = sd_netlink_message_open_container(m, IFLA_LINKINFO); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINKINFO attribute: %m"); + return r; if (NETDEV_VTABLE(netdev)->fill_message_create) { r = sd_netlink_message_open_container_union(m, IFLA_INFO_DATA, netdev_kind_to_string(netdev->kind)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m"); + return r; r = NETDEV_VTABLE(netdev)->fill_message_create(netdev, link, m); if (r < 0) @@ -544,29 +524,59 @@ static int netdev_create(NetDev *netdev, Link *link, link_netlink_message_handle r = sd_netlink_message_close_container(m); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m"); + return r; } else { r = sd_netlink_message_append_string(m, IFLA_INFO_KIND, netdev_kind_to_string(netdev->kind)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_KIND attribute: %m"); + return r; } r = sd_netlink_message_close_container(m); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINKINFO attribute: %m"); + return r; + + return 0; +} + +static int netdev_create(NetDev *netdev, Link *link, link_netlink_message_handler_t callback) { + _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; + int r; + + assert(netdev); + assert(!link || callback); + + /* create netdev */ + if (NETDEV_VTABLE(netdev)->create) { + assert(!link); + + r = NETDEV_VTABLE(netdev)->create(netdev); + if (r < 0) + return r; + + log_netdev_debug(netdev, "Created"); + return 0; + } + + r = sd_rtnl_message_new_link(netdev->manager->rtnl, &m, RTM_NEWLINK, 0); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not allocate netlink message: %m"); + + r = netdev_create_message(netdev, link, m); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not create netlink message: %m"); if (link) { r = netlink_call_async(netdev->manager->rtnl, NULL, m, callback, link_netlink_destroy_callback, link); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m"); + return log_netdev_error_errno(netdev, r, "Could not send netlink message: %m"); link_ref(link); } else { r = netlink_call_async(netdev->manager->rtnl, NULL, m, netdev_create_handler, netdev_destroy_callback, netdev); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m"); + return log_netdev_error_errno(netdev, r, "Could not send netlink message: %m"); netdev_ref(netdev); } diff --git a/src/network/netdev/tunnel.c b/src/network/netdev/tunnel.c index b2e88eaa2f..389403f42c 100644 --- a/src/network/netdev/tunnel.c +++ b/src/network/netdev/tunnel.c @@ -86,82 +86,100 @@ int dhcp4_pd_create_6rd_tunnel_name(Link *link, char **ret) { return 0; } -int dhcp4_pd_create_6rd_tunnel(Link *link, link_netlink_message_handler_t callback) { - _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; - uint8_t ipv4masklen, sixrd_prefixlen; - struct in_addr ipv4address, relay_prefix; - struct in6_addr sixrd_prefix; +static int dhcp4_pd_create_6rd_tunnel_message( + Link *link, + sd_netlink_message *m, + const struct in_addr *ipv4address, + uint8_t ipv4masklen, + const struct in6_addr *sixrd_prefix, + uint8_t sixrd_prefixlen) { int r; - assert(link); - assert(link->ifindex > 0); - assert(link->manager); - assert(link->dhcp_lease); - assert(link->dhcp4_6rd_tunnel_name); - assert(callback); - - r = sd_dhcp_lease_get_address(link->dhcp_lease, &ipv4address); - if (r < 0) - return log_link_debug_errno(link, r, "Failed to get DHCPv4 address: %m"); - - r = sd_dhcp_lease_get_6rd(link->dhcp_lease, &ipv4masklen, &sixrd_prefixlen, &sixrd_prefix, NULL, NULL); - if (r < 0) - return log_link_debug_errno(link, r, "Failed to get 6rd option: %m"); - - r = sd_rtnl_message_new_link(link->manager->rtnl, &m, RTM_NEWLINK, 0); - if (r < 0) - return log_link_debug_errno(link, r, "Could not allocate RTM_NEWLINK message: %m"); - r = sd_netlink_message_append_string(m, IFLA_IFNAME, link->dhcp4_6rd_tunnel_name); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_IFNAME, attribute: %m"); + return r; r = sd_netlink_message_open_container(m, IFLA_LINKINFO); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_LINKINFO attribute: %m"); + return r; r = sd_netlink_message_open_container_union(m, IFLA_INFO_DATA, "sit"); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_INFO_DATA attribute: %m"); + return r; - r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &ipv4address); + r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, ipv4address); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, 64); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_IPTUN_TTL attribute: %m"); + return r; - r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_6RD_PREFIX, &sixrd_prefix); + r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_6RD_PREFIX, sixrd_prefix); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_IPTUN_6RD_PREFIX attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, IFLA_IPTUN_6RD_PREFIXLEN, sixrd_prefixlen); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_IPTUN_6RD_PREFIXLEN attribute: %m"); + return r; - relay_prefix = ipv4address; + struct in_addr relay_prefix = *ipv4address; (void) in4_addr_mask(&relay_prefix, ipv4masklen); r = sd_netlink_message_append_u32(m, IFLA_IPTUN_6RD_RELAY_PREFIX, relay_prefix.s_addr); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_IPTUN_6RD_RELAY_PREFIX attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, IFLA_IPTUN_6RD_RELAY_PREFIXLEN, ipv4masklen); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_IPTUN_6RD_RELAY_PREFIXLEN attribute: %m"); + return r; r = sd_netlink_message_close_container(m); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_INFO_DATA attribute: %m"); + return r; r = sd_netlink_message_close_container(m); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_LINKINFO attribute: %m"); + return r; + + return 0; +} + +int dhcp4_pd_create_6rd_tunnel(Link *link, link_netlink_message_handler_t callback) { + _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; + uint8_t ipv4masklen, sixrd_prefixlen; + struct in_addr ipv4address; + struct in6_addr sixrd_prefix; + int r; + + assert(link); + assert(link->ifindex > 0); + assert(link->manager); + assert(link->dhcp_lease); + assert(link->dhcp4_6rd_tunnel_name); + assert(callback); + + r = sd_dhcp_lease_get_address(link->dhcp_lease, &ipv4address); + if (r < 0) + return log_link_debug_errno(link, r, "Failed to get DHCPv4 address: %m"); + + r = sd_dhcp_lease_get_6rd(link->dhcp_lease, &ipv4masklen, &sixrd_prefixlen, &sixrd_prefix, NULL, NULL); + if (r < 0) + return log_link_debug_errno(link, r, "Failed to get 6rd option: %m"); + + r = sd_rtnl_message_new_link(link->manager->rtnl, &m, RTM_NEWLINK, 0); + if (r < 0) + return log_link_debug_errno(link, r, "Failed to create netlink message: %m"); + + r = dhcp4_pd_create_6rd_tunnel_message(link, m, + &ipv4address, ipv4masklen, + &sixrd_prefix, sixrd_prefixlen); + if (r < 0) + return log_link_debug_errno(link, r, "Failed to fill netlink message: %m"); r = netlink_call_async(link->manager->rtnl, NULL, m, callback, link_netlink_destroy_callback, link); if (r < 0) - return log_link_debug_errno(link, r, "Could not send rtnetlink message: %m"); + return log_link_debug_errno(link, r, "Could not send netlink message: %m"); link_ref(link); @@ -198,7 +216,7 @@ static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_ne if (link || t->assign_to_loopback) { r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link ? link->ifindex : LOOPBACK_IFINDEX); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); + return r; } r = tunnel_get_local_address(t, link, &local); @@ -207,46 +225,46 @@ static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_ne r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &local.in); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m"); + return r; r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PMTUDISC, t->pmtudisc); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_PMTUDISC attribute: %m"); + return r; if (t->fou_tunnel) { r = sd_netlink_message_append_u16(m, IFLA_IPTUN_ENCAP_TYPE, t->fou_encap_type); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_ENCAP_TYPE attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, IFLA_IPTUN_ENCAP_SPORT, htobe16(t->encap_src_port)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_ENCAP_SPORT attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, IFLA_IPTUN_ENCAP_DPORT, htobe16(t->fou_destination_port)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_ENCAP_DPORT attribute: %m"); + return r; } if (netdev->kind == NETDEV_KIND_SIT) { if (t->sixrd_prefixlen > 0) { r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_6RD_PREFIX, &t->sixrd_prefix); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_6RD_PREFIX attribute: %m"); + return r; /* u16 is deliberate here, even though we're passing a netmask that can never be >128. The kernel is * expecting to receive the prefixlen as a u16. */ r = sd_netlink_message_append_u16(m, IFLA_IPTUN_6RD_PREFIXLEN, t->sixrd_prefixlen); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_6RD_PREFIXLEN attribute: %m"); + return r; } if (t->isatap >= 0) { @@ -256,11 +274,11 @@ static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_ne r = sd_netlink_message_append_u16(m, IFLA_IPTUN_FLAGS, flags); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_FLAGS attribute: %m"); + return r; } } - return r; + return 0; } static int netdev_gre_erspan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { @@ -294,13 +312,13 @@ static int netdev_gre_erspan_fill_message_create(NetDev *netdev, Link *link, sd_ if (link || t->assign_to_loopback) { r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link ? link->ifindex : LOOPBACK_IFINDEX); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m"); + return r; } if (netdev->kind == NETDEV_KIND_ERSPAN) { r = sd_netlink_message_append_u32(m, IFLA_GRE_ERSPAN_INDEX, t->erspan_index); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_ERSPAN_INDEX attribute: %m"); + return r; } r = tunnel_get_local_address(t, link, &local); @@ -309,23 +327,23 @@ static int netdev_gre_erspan_fill_message_create(NetDev *netdev, Link *link, sd_ r = sd_netlink_message_append_in_addr(m, IFLA_GRE_LOCAL, &local.in); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LOCAL attribute: %m"); + return r; r = sd_netlink_message_append_in_addr(m, IFLA_GRE_REMOTE, &t->remote.in); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_REMOTE attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_GRE_TTL, t->ttl); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TTL attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_GRE_TOS, t->tos); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TOS attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_GRE_PMTUDISC, t->pmtudisc); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_PMTUDISC attribute: %m"); + return r; if (t->key != 0) { ikey = okey = htobe32(t->key); @@ -353,35 +371,35 @@ static int netdev_gre_erspan_fill_message_create(NetDev *netdev, Link *link, sd_ r = sd_netlink_message_append_u32(m, IFLA_GRE_IKEY, ikey); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_IKEY attribute: %m"); + return r; r = sd_netlink_message_append_u32(m, IFLA_GRE_OKEY, okey); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_OKEY attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, IFLA_GRE_IFLAGS, iflags); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_IFLAGS attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, IFLA_GRE_OFLAGS, oflags); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_OFLAGS, attribute: %m"); + return r; if (t->fou_tunnel) { r = sd_netlink_message_append_u16(m, IFLA_GRE_ENCAP_TYPE, t->fou_encap_type); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_ENCAP_TYPE attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, IFLA_GRE_ENCAP_SPORT, htobe16(t->encap_src_port)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_ENCAP_SPORT attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, IFLA_GRE_ENCAP_DPORT, htobe16(t->fou_destination_port)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_ENCAP_DPORT attribute: %m"); + return r; } - return r; + return 0; } static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { @@ -406,7 +424,7 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl if (link || t->assign_to_loopback) { r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link ? link->ifindex : LOOPBACK_IFINDEX); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m"); + return r; } r = tunnel_get_local_address(t, link, &local); @@ -415,25 +433,25 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_LOCAL, &local.in6); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LOCAL attribute: %m"); + return r; r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_REMOTE, &t->remote.in6); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_REMOTE attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_GRE_TTL, t->ttl); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TTL attribute: %m"); + return r; if (t->ipv6_flowlabel != _NETDEV_IPV6_FLOWLABEL_INVALID) { r = sd_netlink_message_append_u32(m, IFLA_GRE_FLOWINFO, t->ipv6_flowlabel); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_FLOWINFO attribute: %m"); + return r; } r = sd_netlink_message_append_u32(m, IFLA_GRE_FLAGS, t->flags); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_FLAGS attribute: %m"); + return r; if (t->key != 0) { ikey = okey = htobe32(t->key); @@ -453,21 +471,21 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl r = sd_netlink_message_append_u32(m, IFLA_GRE_IKEY, ikey); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_IKEY attribute: %m"); + return r; r = sd_netlink_message_append_u32(m, IFLA_GRE_OKEY, okey); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_OKEY attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, IFLA_GRE_IFLAGS, iflags); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_IFLAGS attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, IFLA_GRE_OFLAGS, oflags); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_OFLAGS, attribute: %m"); + return r; - return r; + return 0; } static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { @@ -489,7 +507,7 @@ static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink if (link || t->assign_to_loopback) { r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link ? link->ifindex : LOOPBACK_IFINDEX); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VTI_LINK attribute: %m"); + return r; } if (t->key != 0) @@ -501,11 +519,11 @@ static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink r = sd_netlink_message_append_u32(m, IFLA_VTI_IKEY, ikey); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VTI_IKEY attribute: %m"); + return r; r = sd_netlink_message_append_u32(m, IFLA_VTI_OKEY, okey); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VTI_OKEY attribute: %m"); + return r; r = tunnel_get_local_address(t, link, &local); if (r < 0) @@ -513,13 +531,13 @@ static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink r = netlink_message_append_in_addr_union(m, IFLA_VTI_LOCAL, t->family, &local); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VTI_LOCAL attribute: %m"); + return r; r = netlink_message_append_in_addr_union(m, IFLA_VTI_REMOTE, t->family, &t->remote); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VTI_REMOTE attribute: %m"); + return r; - return r; + return 0; } static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { @@ -538,7 +556,7 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl if (link || t->assign_to_loopback) { r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link ? link->ifindex : LOOPBACK_IFINDEX); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); + return r; } r = tunnel_get_local_address(t, link, &local); @@ -547,20 +565,20 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_LOCAL, &local.in6); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m"); + return r; r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in6); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m"); + return r; if (t->ipv6_flowlabel != _NETDEV_IPV6_FLOWLABEL_INVALID) { r = sd_netlink_message_append_u32(m, IFLA_IPTUN_FLOWINFO, t->ipv6_flowlabel); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_FLOWINFO attribute: %m"); + return r; } if (t->copy_dscp) @@ -572,12 +590,12 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl if (t->encap_limit != 0) { r = sd_netlink_message_append_u8(m, IFLA_IPTUN_ENCAP_LIMIT, t->encap_limit); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_ENCAP_LIMIT attribute: %m"); + return r; } r = sd_netlink_message_append_u32(m, IFLA_IPTUN_FLAGS, t->flags); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_FLAGS attribute: %m"); + return r; switch (t->ip6tnl_mode) { case NETDEV_IP6_TNL_MODE_IP6IP6: @@ -594,9 +612,9 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PROTO, proto); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_PROTO attribute: %m"); + return r; - return r; + return 0; } static int netdev_tunnel_is_ready_to_create(NetDev *netdev, Link *link) { diff --git a/src/network/netdev/veth.c b/src/network/netdev/veth.c index c946e81fc0..fb00e6667f 100644 --- a/src/network/netdev/veth.c +++ b/src/network/netdev/veth.c @@ -24,12 +24,12 @@ static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_netlin r = sd_netlink_message_open_container(m, VETH_INFO_PEER); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append VETH_INFO_PEER attribute: %m"); + return r; if (v->ifname_peer) { r = sd_netlink_message_append_string(m, IFLA_IFNAME, v->ifname_peer); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to add netlink interface name: %m"); + return r; } r = netdev_generate_hw_addr(netdev, NULL, v->ifname_peer, &v->hw_addr_peer, &hw_addr); @@ -40,20 +40,20 @@ static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_netlin log_netdev_debug(netdev, "Using MAC address for peer: %s", HW_ADDR_TO_STR(&hw_addr)); r = netlink_message_append_hw_addr(m, IFLA_ADDRESS, &hw_addr); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_ADDRESS attribute: %m"); + return r; } if (netdev->mtu != 0) { r = sd_netlink_message_append_u32(m, IFLA_MTU, netdev->mtu); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_MTU attribute: %m"); + return r; } r = sd_netlink_message_close_container(m); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m"); + return r; - return r; + return 0; } static int netdev_veth_verify(NetDev *netdev, const char *filename) { diff --git a/src/network/netdev/vlan.c b/src/network/netdev/vlan.c index af3e77963e..3f9f594759 100644 --- a/src/network/netdev/vlan.c +++ b/src/network/netdev/vlan.c @@ -24,12 +24,12 @@ static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlin r = sd_netlink_message_append_u16(req, IFLA_VLAN_ID, v->id); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_ID attribute: %m"); + return r; if (v->protocol >= 0) { r = sd_netlink_message_append_u16(req, IFLA_VLAN_PROTOCOL, htobe16(v->protocol)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_PROTOCOL attribute: %m"); + return r; } if (v->gvrp != -1) { @@ -54,24 +54,24 @@ static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlin r = sd_netlink_message_append_data(req, IFLA_VLAN_FLAGS, &flags, sizeof(struct ifla_vlan_flags)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_FLAGS attribute: %m"); + return r; if (!set_isempty(v->egress_qos_maps)) { struct ifla_vlan_qos_mapping *m; r = sd_netlink_message_open_container(req, IFLA_VLAN_EGRESS_QOS); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not open container IFLA_VLAN_EGRESS_QOS: %m"); + return r; SET_FOREACH(m, v->egress_qos_maps) { r = sd_netlink_message_append_data(req, IFLA_VLAN_QOS_MAPPING, m, sizeof(struct ifla_vlan_qos_mapping)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_QOS_MAPPING attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not close container IFLA_VLAN_EGRESS_QOS: %m"); + return r; } if (!set_isempty(v->ingress_qos_maps)) { @@ -79,17 +79,17 @@ static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlin r = sd_netlink_message_open_container(req, IFLA_VLAN_INGRESS_QOS); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not open container IFLA_VLAN_INGRESS_QOS: %m"); + return r; SET_FOREACH(m, v->ingress_qos_maps) { r = sd_netlink_message_append_data(req, IFLA_VLAN_QOS_MAPPING, m, sizeof(struct ifla_vlan_qos_mapping)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_QOS_MAPPING attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not close container IFLA_VLAN_INGRESS_QOS: %m"); + return r; } return 0; diff --git a/src/network/netdev/vrf.c b/src/network/netdev/vrf.c index b1b6707441..9f75eb63cf 100644 --- a/src/network/netdev/vrf.c +++ b/src/network/netdev/vrf.c @@ -20,9 +20,9 @@ static int netdev_vrf_fill_message_create(NetDev *netdev, Link *link, sd_netlink r = sd_netlink_message_append_u32(m, IFLA_VRF_TABLE, v->table); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VRF_TABLE attribute: %m"); + return r; - return r; + return 0; } const NetDevVTable vrf_vtable = { diff --git a/src/network/netdev/vxcan.c b/src/network/netdev/vxcan.c index a0ba048eb1..83269b0707 100644 --- a/src/network/netdev/vxcan.c +++ b/src/network/netdev/vxcan.c @@ -19,19 +19,19 @@ static int netdev_vxcan_fill_message_create(NetDev *netdev, Link *link, sd_netli r = sd_netlink_message_open_container(m, VXCAN_INFO_PEER); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append VXCAN_INFO_PEER attribute: %m"); + return r; if (v->ifname_peer) { r = sd_netlink_message_append_string(m, IFLA_IFNAME, v->ifname_peer); if (r < 0) - return log_netdev_error_errno(netdev, r, "Failed to add vxcan netlink interface peer name: %m"); + return r; } r = sd_netlink_message_close_container(m); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append VXCAN_INFO_PEER attribute: %m"); + return r; - return r; + return 0; } static int netdev_vxcan_verify(NetDev *netdev, const char *filename) { @@ -44,10 +44,9 @@ static int netdev_vxcan_verify(NetDev *netdev, const char *filename) { assert(v); - if (!v->ifname_peer) { - log_netdev_warning(netdev, "VxCan NetDev without peer name configured in %s. Ignoring", filename); - return -EINVAL; - } + if (!v->ifname_peer) + return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL), + "VxCan NetDev without peer name configured in %s. Ignoring", filename); return 0; } diff --git a/src/network/netdev/vxlan.c b/src/network/netdev/vxlan.c index addeb907dd..bdedf3e7a9 100644 --- a/src/network/netdev/vxlan.c +++ b/src/network/netdev/vxlan.c @@ -51,7 +51,7 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_netli if (v->vni <= VXLAN_VID_MAX) { r = sd_netlink_message_append_u32(m, IFLA_VXLAN_ID, v->vni); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_ID attribute: %m"); + return r; } if (in_addr_is_set(v->group_family, &v->group)) { @@ -60,19 +60,19 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_netli else r = sd_netlink_message_append_in6_addr(m, IFLA_VXLAN_GROUP6, &v->group.in6); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_GROUP attribute: %m"); + return r; } else if (in_addr_is_set(v->remote_family, &v->remote)) { if (v->remote_family == AF_INET) r = sd_netlink_message_append_in_addr(m, IFLA_VXLAN_GROUP, &v->remote.in); else r = sd_netlink_message_append_in6_addr(m, IFLA_VXLAN_GROUP6, &v->remote.in6); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_GROUP attribute: %m"); + return r; } r = vxlan_get_local_address(v, link, &local_family, &local); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not find local address: %m"); + return r; if (in_addr_is_set(local_family, &local)) { if (local_family == AF_INET) @@ -80,84 +80,84 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_netli else r = sd_netlink_message_append_in6_addr(m, IFLA_VXLAN_LOCAL6, &local.in6); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_LOCAL attribute: %m"); + return r; } r = sd_netlink_message_append_u32(m, IFLA_VXLAN_LINK, link ? link->ifindex : 0); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_LINK attribute: %m"); + return r; if (v->inherit) { r = sd_netlink_message_append_flag(m, IFLA_VXLAN_TTL_INHERIT); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_TTL_INHERIT attribute: %m"); + return r; } else { r = sd_netlink_message_append_u8(m, IFLA_VXLAN_TTL, v->ttl); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_TTL attribute: %m"); + return r; } if (v->tos != 0) { r = sd_netlink_message_append_u8(m, IFLA_VXLAN_TOS, v->tos); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_TOS attribute: %m"); + return r; } r = sd_netlink_message_append_u8(m, IFLA_VXLAN_LEARNING, v->learning); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_LEARNING attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_VXLAN_RSC, v->route_short_circuit); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_RSC attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_VXLAN_PROXY, v->arp_proxy); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_PROXY attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_VXLAN_L2MISS, v->l2miss); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_L2MISS attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_VXLAN_L3MISS, v->l3miss); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_L3MISS attribute: %m"); + return r; if (v->fdb_ageing != 0) { r = sd_netlink_message_append_u32(m, IFLA_VXLAN_AGEING, v->fdb_ageing / USEC_PER_SEC); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_AGEING attribute: %m"); + return r; } if (v->max_fdb != 0) { r = sd_netlink_message_append_u32(m, IFLA_VXLAN_LIMIT, v->max_fdb); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_LIMIT attribute: %m"); + return r; } r = sd_netlink_message_append_u8(m, IFLA_VXLAN_UDP_CSUM, v->udpcsum); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_CSUM attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, v->udp6zerocsumtx); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_TX attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, v->udp6zerocsumrx); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_RX attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_VXLAN_REMCSUM_TX, v->remote_csum_tx); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_REMCSUM_TX attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, IFLA_VXLAN_REMCSUM_RX, v->remote_csum_rx); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_REMCSUM_RX attribute: %m"); + return r; r = sd_netlink_message_append_u16(m, IFLA_VXLAN_PORT, htobe16(v->dest_port)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_PORT attribute: %m"); + return r; if (v->port_range.low != 0 || v->port_range.high != 0) { struct ifla_vxlan_port_range port_range; @@ -167,32 +167,32 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_netli r = sd_netlink_message_append_data(m, IFLA_VXLAN_PORT_RANGE, &port_range, sizeof(port_range)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_PORT_RANGE attribute: %m"); + return r; } r = sd_netlink_message_append_u32(m, IFLA_VXLAN_LABEL, htobe32(v->flow_label)); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_LABEL attribute: %m"); + return r; if (v->group_policy) { r = sd_netlink_message_append_flag(m, IFLA_VXLAN_GBP); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_GBP attribute: %m"); + return r; } if (v->generic_protocol_extension) { r = sd_netlink_message_append_flag(m, IFLA_VXLAN_GPE); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_GPE attribute: %m"); + return r; } if (v->df != _NETDEV_VXLAN_DF_INVALID) { r = sd_netlink_message_append_u8(m, IFLA_VXLAN_DF, v->df); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_DF attribute: %m"); + return r; } - return r; + return 0; } int config_parse_vxlan_address( diff --git a/src/network/netdev/xfrm.c b/src/network/netdev/xfrm.c index 4b7e73b37a..05844b8321 100644 --- a/src/network/netdev/xfrm.c +++ b/src/network/netdev/xfrm.c @@ -18,11 +18,11 @@ static int xfrm_fill_message_create(NetDev *netdev, Link *link, sd_netlink_messa r = sd_netlink_message_append_u32(message, IFLA_XFRM_LINK, link ? link->ifindex : LOOPBACK_IFINDEX); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_XFRM_LINK: %m"); + return r; r = sd_netlink_message_append_u32(message, IFLA_XFRM_IF_ID, x->if_id); if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_XFRM_IF_ID: %m"); + return r; return 0; } diff --git a/src/network/networkd-bridge-fdb.c b/src/network/networkd-bridge-fdb.c index 1298727a72..a0024f62d4 100644 --- a/src/network/networkd-bridge-fdb.c +++ b/src/network/networkd-bridge-fdb.c @@ -121,68 +121,51 @@ static int bridge_fdb_configure_handler(sd_netlink *rtnl, sd_netlink_message *m, } /* send a request to the kernel to add a FDB entry in its static MAC table. */ -static int bridge_fdb_configure(const BridgeFDB *fdb, Link *link, link_netlink_message_handler_t callback) { - _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; +static int bridge_fdb_configure_message(const BridgeFDB *fdb, Link *link, sd_netlink_message *req) { int r; assert(fdb); assert(link); - assert(link->manager); - assert(link->manager->rtnl); - assert(callback); - - /* create new RTM message */ - r = sd_rtnl_message_new_neigh(link->manager->rtnl, &req, RTM_NEWNEIGH, link->ifindex, AF_BRIDGE); - if (r < 0) - return log_link_error_errno(link, r, "Could not create RTM_NEWNEIGH message: %m"); r = sd_rtnl_message_neigh_set_flags(req, fdb->ntf_flags); if (r < 0) - return log_link_error_errno(link, r, "Could not set neighbor flags: %m"); + return r; /* only NUD_PERMANENT state supported. */ r = sd_rtnl_message_neigh_set_state(req, NUD_NOARP | NUD_PERMANENT); if (r < 0) - return log_link_error_errno(link, r, "Could not set neighbor state: %m"); + return r; r = sd_netlink_message_append_data(req, NDA_LLADDR, &fdb->mac_addr, sizeof(fdb->mac_addr)); if (r < 0) - return log_link_error_errno(link, r, "Could not append NDA_LLADDR attribute: %m"); + return r; /* VLAN Id is optional. We'll add VLAN Id only if it's specified. */ if (fdb->vlan_id > 0) { r = sd_netlink_message_append_u16(req, NDA_VLAN, fdb->vlan_id); if (r < 0) - return log_link_error_errno(link, r, "Could not append NDA_VLAN attribute: %m"); + return r; } if (fdb->outgoing_ifindex > 0) { r = sd_netlink_message_append_u32(req, NDA_IFINDEX, fdb->outgoing_ifindex); if (r < 0) - return log_link_error_errno(link, r, "Could not append NDA_IFINDEX attribute: %m"); + return r; } if (in_addr_is_set(fdb->family, &fdb->destination_addr)) { r = netlink_message_append_in_addr_union(req, NDA_DST, fdb->family, &fdb->destination_addr); if (r < 0) - return log_link_error_errno(link, r, "Could not append NDA_DST attribute: %m"); + return r; } if (fdb->vni <= VXLAN_VID_MAX) { r = sd_netlink_message_append_u32(req, NDA_VNI, fdb->vni); if (r < 0) - return log_link_error_errno(link, r, "Could not append NDA_VNI attribute: %m"); + return r; } - /* send message to the kernel to update its internal static MAC table. */ - r = netlink_call_async(link->manager->rtnl, NULL, req, callback, - 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 1; + return 0; } int link_request_static_bridge_fdb(Link *link) { @@ -238,15 +221,36 @@ static bool bridge_fdb_is_ready_to_configure(BridgeFDB *fdb, Link *link) { } int request_process_bridge_fdb(Request *req) { + Link *link; + int r; + assert(req); - assert(req->link); assert(req->fdb); assert(req->type == REQUEST_TYPE_BRIDGE_FDB); + assert_se(link = req->link); - if (!bridge_fdb_is_ready_to_configure(req->fdb, req->link)) + if (!bridge_fdb_is_ready_to_configure(req->fdb, link)) return 0; - return bridge_fdb_configure(req->fdb, req->link, req->netlink_handler); + /* create new RTM message */ + _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; + r = sd_rtnl_message_new_neigh(link->manager->rtnl, &m, RTM_NEWNEIGH, link->ifindex, AF_BRIDGE); + if (r < 0) + return log_link_error_errno(link, r, "Could not allocate netlink message: %m"); + + r = bridge_fdb_configure_message(req->fdb, link, m); + if (r < 0) + return log_link_error_errno(link, r, "Could not create netlink message: %m"); + + /* send message to the kernel to update its internal static MAC table. */ + r = netlink_call_async(link->manager->rtnl, NULL, m, req->netlink_handler, + link_netlink_destroy_callback, link); + if (r < 0) + return log_link_error_errno(link, r, "Could not send netlink message: %m"); + + link_ref(link); + + return 1; } void network_drop_invalid_bridge_fdb_entries(Network *network) { diff --git a/src/network/networkd-bridge-vlan.c b/src/network/networkd-bridge-vlan.c index 3153bf6984..36e3610a8f 100644 --- a/src/network/networkd-bridge-vlan.c +++ b/src/network/networkd-bridge-vlan.c @@ -65,11 +65,9 @@ int bridge_vlan_append_info( for (int k = 0; k < BRIDGE_VLAN_BITMAP_LEN; k++) { uint32_t untagged_map = br_untagged_bitmap[k]; uint32_t vid_map = br_vid_bitmap[k]; - unsigned base_bit; - int i; + unsigned base_bit = k * 32; + int i = -1; - base_bit = k * 32; - i = -1; done = false; do { int j = find_next_bit(i, vid_map); @@ -106,14 +104,14 @@ int bridge_vlan_append_info( r = sd_netlink_message_append_data(req, IFLA_BRIDGE_VLAN_INFO, &br_vlan, sizeof(br_vlan)); if (r < 0) - return log_link_error_errno(link, r, "Could not append IFLA_BRIDGE_VLAN_INFO attribute: %m"); + return r; } else { br_vlan.vid = begin; br_vlan.flags |= BRIDGE_VLAN_INFO_RANGE_BEGIN; r = sd_netlink_message_append_data(req, IFLA_BRIDGE_VLAN_INFO, &br_vlan, sizeof(br_vlan)); if (r < 0) - return log_link_error_errno(link, r, "Could not append IFLA_BRIDGE_VLAN_INFO attribute: %m"); + return r; br_vlan.vid = end; br_vlan.flags &= ~BRIDGE_VLAN_INFO_RANGE_BEGIN; @@ -121,7 +119,7 @@ int bridge_vlan_append_info( r = sd_netlink_message_append_data(req, IFLA_BRIDGE_VLAN_INFO, &br_vlan, sizeof(br_vlan)); if (r < 0) - return log_link_error_errno(link, r, "Could not append IFLA_BRIDGE_VLAN_INFO attribute: %m"); + return r; } if (done) diff --git a/src/network/networkd-can.c b/src/network/networkd-can.c index 7a0a6e5522..205179d112 100644 --- a/src/network/networkd-can.c +++ b/src/network/networkd-can.c @@ -21,15 +21,15 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) { r = sd_netlink_message_set_flags(m, NLM_F_REQUEST | NLM_F_ACK); if (r < 0) - return log_link_debug_errno(link, r, "Could not set netlink flags: %m"); + return r; r = sd_netlink_message_open_container(m, IFLA_LINKINFO); if (r < 0) - return log_link_debug_errno(link, r, "Failed to open IFLA_LINKINFO container: %m"); + return r; r = sd_netlink_message_open_container_union(m, IFLA_INFO_DATA, link->kind); if (r < 0) - return log_link_debug_errno(link, r, "Could not open IFLA_INFO_DATA container: %m"); + return r; if (link->network->can_bitrate > 0) { struct can_bittiming bt = { @@ -46,7 +46,7 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) { r = sd_netlink_message_append_data(m, IFLA_CAN_BITTIMING, &bt, sizeof(bt)); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_CAN_BITTIMING attribute: %m"); + return r; } else if (link->network->can_time_quanta_ns > 0) { struct can_bittiming bt = { .tq = link->network->can_time_quanta_ns, @@ -59,7 +59,7 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) { log_link_debug(link, "Setting time quanta = %"PRIu32" nsec", bt.tq); r = sd_netlink_message_append_data(m, IFLA_CAN_BITTIMING, &bt, sizeof(bt)); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_CAN_BITTIMING attribute: %m"); + return r; } if (link->network->can_data_bitrate > 0) { @@ -77,7 +77,7 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) { r = sd_netlink_message_append_data(m, IFLA_CAN_DATA_BITTIMING, &bt, sizeof(bt)); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_CAN_DATA_BITTIMING attribute: %m"); + return r; } else if (link->network->can_data_time_quanta_ns > 0) { struct can_bittiming bt = { .tq = link->network->can_data_time_quanta_ns, @@ -90,7 +90,7 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) { log_link_debug(link, "Setting data time quanta = %"PRIu32" nsec", bt.tq); r = sd_netlink_message_append_data(m, IFLA_CAN_DATA_BITTIMING, &bt, sizeof(bt)); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_CAN_DATA_BITTIMING attribute: %m"); + return r; } if (link->network->can_restart_us > 0) { @@ -104,7 +104,7 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) { log_link_debug(link, "Setting restart = %s", FORMAT_TIMESPAN(restart_ms * 1000, MSEC_PER_SEC)); r = sd_netlink_message_append_u32(m, IFLA_CAN_RESTART_MS, restart_ms); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_CAN_RESTART_MS attribute: %m"); + return r; } if (link->network->can_control_mode_mask != 0) { @@ -115,7 +115,7 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) { r = sd_netlink_message_append_data(m, IFLA_CAN_CTRLMODE, &cm, sizeof(cm)); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_CAN_CTRLMODE attribute: %m"); + return r; } if (link->network->can_termination_set) { @@ -123,16 +123,16 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) { r = sd_netlink_message_append_u16(m, IFLA_CAN_TERMINATION, link->network->can_termination); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_CAN_TERMINATION attribute: %m"); + return r; } r = sd_netlink_message_close_container(m); if (r < 0) - return log_link_debug_errno(link, r, "Failed to close IFLA_INFO_DATA container: %m"); + return r; r = sd_netlink_message_close_container(m); if (r < 0) - return log_link_debug_errno(link, r, "Failed to close IFLA_LINKINFO container: %m"); + return r; return 0; } diff --git a/src/network/networkd-neighbor.c b/src/network/networkd-neighbor.c index 1766095e53..26b7385497 100644 --- a/src/network/networkd-neighbor.c +++ b/src/network/networkd-neighbor.c @@ -175,6 +175,24 @@ static void log_neighbor_debug(const Neighbor *neighbor, const char *str, const HW_ADDR_TO_STR(&neighbor->ll_addr), strna(dst)); } +static int neighbor_configure_message(Neighbor *neighbor, Link *link, sd_netlink_message *req) { + int r; + + r = sd_rtnl_message_neigh_set_state(req, NUD_PERMANENT); + if (r < 0) + return r; + + r = netlink_message_append_hw_addr(req, NDA_LLADDR, &neighbor->ll_addr); + if (r < 0) + return r; + + r = netlink_message_append_in_addr_union(req, NDA_DST, neighbor->family, &neighbor->in_addr); + if (r < 0) + return r; + + return 0; +} + static int neighbor_configure( Neighbor *neighbor, Link *link, @@ -195,24 +213,16 @@ static int neighbor_configure( r = sd_rtnl_message_new_neigh(link->manager->rtnl, &req, RTM_NEWNEIGH, link->ifindex, neighbor->family); if (r < 0) - return log_link_error_errno(link, r, "Could not allocate RTM_NEWNEIGH message: %m"); + return log_link_error_errno(link, r, "Could not allocate netlink message: %m"); - r = sd_rtnl_message_neigh_set_state(req, NUD_PERMANENT); + r = neighbor_configure_message(neighbor, link, req); if (r < 0) - return log_link_error_errno(link, r, "Could not set state: %m"); - - r = netlink_message_append_hw_addr(req, NDA_LLADDR, &neighbor->ll_addr); - if (r < 0) - return log_link_error_errno(link, r, "Could not append NDA_LLADDR attribute: %m"); - - r = netlink_message_append_in_addr_union(req, NDA_DST, neighbor->family, &neighbor->in_addr); - if (r < 0) - return log_link_error_errno(link, r, "Could not append NDA_DST attribute: %m"); + return log_link_error_errno(link, r, "Could not create netlink message: %m"); r = netlink_call_async(link->manager->rtnl, NULL, req, callback, link_netlink_destroy_callback, link); if (r < 0) - return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); + return log_link_error_errno(link, r, "Could not send netlink message: %m"); link_ref(link); diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index ee7a535075..f0697a66af 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -617,7 +617,7 @@ static int route_set_netlink_message(const Route *route, sd_netlink_message *req if (route->gw_family == route->family) { r = netlink_message_append_in_addr_union(req, RTA_GATEWAY, route->gw_family, &route->gw); if (r < 0) - return log_link_error_errno(link, r, "Could not append RTA_GATEWAY attribute: %m"); + return r; } else { RouteVia rtvia = { .family = route->gw_family, @@ -626,57 +626,57 @@ static int route_set_netlink_message(const Route *route, sd_netlink_message *req r = sd_netlink_message_append_data(req, RTA_VIA, &rtvia, sizeof(rtvia)); if (r < 0) - return log_link_error_errno(link, r, "Could not append RTA_VIA attribute: %m"); + return r; } } if (route->dst_prefixlen > 0) { r = netlink_message_append_in_addr_union(req, RTA_DST, route->family, &route->dst); if (r < 0) - return log_link_error_errno(link, r, "Could not append RTA_DST attribute: %m"); + return r; r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen); if (r < 0) - return log_link_error_errno(link, r, "Could not set destination prefix length: %m"); + return r; } if (route->src_prefixlen > 0) { r = netlink_message_append_in_addr_union(req, RTA_SRC, route->family, &route->src); if (r < 0) - return log_link_error_errno(link, r, "Could not append RTA_SRC attribute: %m"); + return r; r = sd_rtnl_message_route_set_src_prefixlen(req, route->src_prefixlen); if (r < 0) - return log_link_error_errno(link, r, "Could not set source prefix length: %m"); + return r; } if (in_addr_is_set(route->family, &route->prefsrc)) { r = netlink_message_append_in_addr_union(req, RTA_PREFSRC, route->family, &route->prefsrc); if (r < 0) - return log_link_error_errno(link, r, "Could not append RTA_PREFSRC attribute: %m"); + return r; } r = sd_rtnl_message_route_set_scope(req, route->scope); if (r < 0) - return log_link_error_errno(link, r, "Could not set scope: %m"); + return r; r = sd_rtnl_message_route_set_flags(req, route->flags & RTNH_F_ONLINK); if (r < 0) - return log_link_error_errno(link, r, "Could not set flags: %m"); + return r; if (route->table < 256) { r = sd_rtnl_message_route_set_table(req, route->table); if (r < 0) - return log_link_error_errno(link, r, "Could not set route table: %m"); + return r; } else { r = sd_rtnl_message_route_set_table(req, RT_TABLE_UNSPEC); if (r < 0) - return log_link_error_errno(link, r, "Could not set route table: %m"); + return r; /* Table attribute to allow more than 256. */ r = sd_netlink_message_append_u32(req, RTA_TABLE, route->table); if (r < 0) - return log_link_error_errno(link, r, "Could not append RTA_TABLE attribute: %m"); + return r; } if (!route_type_is_reject(route) && @@ -686,22 +686,22 @@ static int route_set_netlink_message(const Route *route, sd_netlink_message *req r = sd_netlink_message_append_u32(req, RTA_OIF, link->ifindex); if (r < 0) - return log_link_error_errno(link, r, "Could not append RTA_OIF attribute: %m"); + return r; } if (route->nexthop_id > 0) { r = sd_netlink_message_append_u32(req, RTA_NH_ID, route->nexthop_id); if (r < 0) - return log_link_error_errno(link, r, "Could not append RTA_NH_ID attribute: %m"); + return r; } r = sd_netlink_message_append_u8(req, RTA_PREF, route->pref); if (r < 0) - return log_link_error_errno(link, r, "Could not append RTA_PREF attribute: %m"); + return r; r = sd_netlink_message_append_u32(req, RTA_PRIORITY, route->priority); if (r < 0) - return log_link_error_errno(link, r, "Could not append RTA_PRIORITY attribute: %m"); + return r; return 0; } @@ -743,7 +743,7 @@ int route_remove(Route *route) { RTM_DELROUTE, route->family, route->protocol); if (r < 0) - return log_link_error_errno(link, r, "Could not create RTM_DELROUTE message: %m"); + return log_link_error_errno(link, r, "Could not create netlink message: %m"); if (route->family == AF_INET && route->nexthop_id > 0 && route->type == RTN_BLACKHOLE) /* When IPv4 route has nexthop id and the nexthop type is blackhole, even though kernel @@ -762,12 +762,12 @@ int route_remove(Route *route) { r = route_set_netlink_message(route, req, link); if (r < 0) - return r; + return log_error_errno(r, "Could not fill netlink message: %m"); r = netlink_call_async(manager->rtnl, NULL, req, route_remove_handler, link ? link_netlink_destroy_callback : NULL, link); if (r < 0) - return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); + return log_link_error_errno(link, r, "Could not send netlink message: %m"); link_ref(link); @@ -1179,7 +1179,7 @@ static int route_configure( RTM_NEWROUTE, route->family, route->protocol); if (r < 0) - return log_link_error_errno(link, r, "Could not create RTM_NEWROUTE message: %m"); + return log_link_error_errno(link, r, "Could not create netlink message: %m"); r = sd_rtnl_message_route_set_type(req, route->type); if (r < 0) @@ -1187,7 +1187,7 @@ static int route_configure( r = route_set_netlink_message(route, req, link); if (r < 0) - return r; + return log_error_errno(r, "Could not fill netlink message: %m"); if (route->lifetime_usec != USEC_INFINITY) { r = sd_netlink_message_append_u32(req, RTA_EXPIRES, diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index 90086f35a7..a2e72a7d7c 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -449,116 +449,116 @@ static int routing_policy_rule_set_netlink_message(const RoutingPolicyRule *rule if (rule->from_prefixlen > 0) { r = netlink_message_append_in_addr_union(m, FRA_SRC, rule->family, &rule->from); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_SRC attribute: %m"); + return r; r = sd_rtnl_message_routing_policy_rule_set_fib_src_prefixlen(m, rule->from_prefixlen); if (r < 0) - return log_link_error_errno(link, r, "Could not set source prefix length: %m"); + return r; } if (rule->to_prefixlen > 0) { r = netlink_message_append_in_addr_union(m, FRA_DST, rule->family, &rule->to); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_DST attribute: %m"); + return r; r = sd_rtnl_message_routing_policy_rule_set_fib_dst_prefixlen(m, rule->to_prefixlen); if (r < 0) - return log_link_error_errno(link, r, "Could not set destination prefix length: %m"); + return r; } r = sd_netlink_message_append_u32(m, FRA_PRIORITY, rule->priority); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_PRIORITY attribute: %m"); + return r; if (rule->tos > 0) { r = sd_rtnl_message_routing_policy_rule_set_tos(m, rule->tos); if (r < 0) - return log_link_error_errno(link, r, "Could not set IP rule TOS: %m"); + return r; } if (rule->table < 256) { r = sd_rtnl_message_routing_policy_rule_set_table(m, rule->table); if (r < 0) - return log_link_error_errno(link, r, "Could not set IP rule table: %m"); + return r; } else { r = sd_rtnl_message_routing_policy_rule_set_table(m, RT_TABLE_UNSPEC); if (r < 0) - return log_link_error_errno(link, r, "Could not set IP rule table: %m"); + return r; r = sd_netlink_message_append_u32(m, FRA_TABLE, rule->table); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_TABLE attribute: %m"); + return r; } if (rule->fwmark > 0) { r = sd_netlink_message_append_u32(m, FRA_FWMARK, rule->fwmark); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_FWMARK attribute: %m"); + return r; r = sd_netlink_message_append_u32(m, FRA_FWMASK, rule->fwmask); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_FWMASK attribute: %m"); + return r; } if (rule->iif) { r = sd_netlink_message_append_string(m, FRA_IIFNAME, rule->iif); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_IIFNAME attribute: %m"); + return r; } if (rule->oif) { r = sd_netlink_message_append_string(m, FRA_OIFNAME, rule->oif); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_OIFNAME attribute: %m"); + return r; } r = sd_netlink_message_append_u8(m, FRA_IP_PROTO, rule->ipproto); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_IP_PROTO attribute: %m"); + return r; r = sd_netlink_message_append_u8(m, FRA_PROTOCOL, rule->protocol); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_PROTOCOL attribute: %m"); + return r; if (rule->sport.start != 0 || rule->sport.end != 0) { r = sd_netlink_message_append_data(m, FRA_SPORT_RANGE, &rule->sport, sizeof(rule->sport)); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_SPORT_RANGE attribute: %m"); + return r; } if (rule->dport.start != 0 || rule->dport.end != 0) { r = sd_netlink_message_append_data(m, FRA_DPORT_RANGE, &rule->dport, sizeof(rule->dport)); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_DPORT_RANGE attribute: %m"); + return r; } if (rule->uid_range.start != UID_INVALID && rule->uid_range.end != UID_INVALID) { r = sd_netlink_message_append_data(m, FRA_UID_RANGE, &rule->uid_range, sizeof(rule->uid_range)); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_UID_RANGE attribute: %m"); + return r; } if (rule->invert_rule) { r = sd_rtnl_message_routing_policy_rule_set_flags(m, FIB_RULE_INVERT); if (r < 0) - return log_link_error_errno(link, r, "Could not append FIB_RULE_INVERT attribute: %m"); + return r; } if (rule->suppress_prefixlen >= 0) { r = sd_netlink_message_append_u32(m, FRA_SUPPRESS_PREFIXLEN, (uint32_t) rule->suppress_prefixlen); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_SUPPRESS_PREFIXLEN attribute: %m"); + return r; } if (rule->suppress_ifgroup >= 0) { r = sd_netlink_message_append_u32(m, FRA_SUPPRESS_IFGROUP, (uint32_t) rule->suppress_ifgroup); if (r < 0) - return log_link_error_errno(link, r, "Could not append FRA_SUPPRESS_IFGROUP attribute: %m"); + return r; } r = sd_rtnl_message_routing_policy_rule_set_fib_type(m, rule->type); if (r < 0) - return log_link_error_errno(link, r, "Could not append FIB rule type attribute: %m"); + return r; return 0; } @@ -588,17 +588,17 @@ static int routing_policy_rule_remove(RoutingPolicyRule *rule) { r = sd_rtnl_message_new_routing_policy_rule(rule->manager->rtnl, &m, RTM_DELRULE, rule->family); if (r < 0) - return log_error_errno(r, "Could not allocate RTM_DELRULE message: %m"); + return log_error_errno(r, "Could not allocate netlink message: %m"); r = routing_policy_rule_set_netlink_message(rule, m, NULL); if (r < 0) - return r; + return log_error_errno(r, "Could not create netlink message: %m"); r = netlink_call_async(rule->manager->rtnl, NULL, m, routing_policy_rule_remove_handler, NULL, NULL); if (r < 0) - return log_error_errno(r, "Could not send rtnetlink message: %m"); + return log_error_errno(r, "Could not send netlink message: %m"); routing_policy_rule_enter_removing(rule); return 0; @@ -624,16 +624,16 @@ static int routing_policy_rule_configure( r = sd_rtnl_message_new_routing_policy_rule(link->manager->rtnl, &m, RTM_NEWRULE, rule->family); if (r < 0) - return log_link_error_errno(link, r, "Could not allocate RTM_NEWRULE message: %m"); + return log_link_error_errno(link, r, "Could not allocate netlink message: %m"); r = routing_policy_rule_set_netlink_message(rule, m, link); if (r < 0) - return r; + return log_error_errno(r, "Could not create netlink message: %m"); r = netlink_call_async(link->manager->rtnl, NULL, m, callback, link_netlink_destroy_callback, link); if (r < 0) - return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); + return log_link_error_errno(link, r, "Could not send netlink message: %m"); link_ref(link); diff --git a/src/network/networkd-setlink.c b/src/network/networkd-setlink.c index b9fd1d749e..3fbc910aa2 100644 --- a/src/network/networkd-setlink.c +++ b/src/network/networkd-setlink.c @@ -219,214 +219,189 @@ static int link_set_mtu_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *l return 0; } -static int link_configure( +static int link_configure_fill_message( Link *link, + sd_netlink_message *req, SetLinkOperation op, - void *userdata, - link_netlink_message_handler_t callback) { - - _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; + void *userdata) { int r; - assert(link); - assert(link->manager); - assert(link->manager->rtnl); - assert(link->network); - assert(op >= 0 && op < _SET_LINK_OPERATION_MAX); - assert(callback); - - log_link_debug(link, "Setting %s", set_link_operation_to_string(op)); - - if (op == SET_LINK_BOND) { - r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_NEWLINK, link->master_ifindex); - if (r < 0) - return log_link_debug_errno(link, r, "Could not allocate RTM_NEWLINK message: %m"); - } else if (IN_SET(op, SET_LINK_CAN, SET_LINK_IPOIB)) { - r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_NEWLINK, link->ifindex); - if (r < 0) - return log_link_debug_errno(link, r, "Could not allocate RTM_NEWLINK message: %m"); - } else { - r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex); - if (r < 0) - return log_link_debug_errno(link, r, "Could not allocate RTM_SETLINK message: %m"); - } - switch (op) { case SET_LINK_ADDRESS_GENERATION_MODE: r = sd_netlink_message_open_container(req, IFLA_AF_SPEC); if (r < 0) - return log_link_debug_errno(link, r, "Could not open IFLA_AF_SPEC container: %m"); + return r; r = sd_netlink_message_open_container(req, AF_INET6); if (r < 0) - return log_link_debug_errno(link, r, "Could not open AF_INET6 container: %m"); + return r; r = sd_netlink_message_append_u8(req, IFLA_INET6_ADDR_GEN_MODE, PTR_TO_UINT8(userdata)); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_INET6_ADDR_GEN_MODE attribute: %m"); + return r; r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_debug_errno(link, r, "Could not close AF_INET6 container: %m"); + return r; r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_debug_errno(link, r, "Could not close IFLA_AF_SPEC container: %m"); + return r; break; case SET_LINK_BOND: r = sd_netlink_message_set_flags(req, NLM_F_REQUEST | NLM_F_ACK); if (r < 0) - return log_link_debug_errno(link, r, "Could not set netlink message flags: %m"); + return r; r = sd_netlink_message_open_container(req, IFLA_LINKINFO); if (r < 0) - return log_link_debug_errno(link, r, "Could not open IFLA_LINKINFO container: %m"); + return r; r = sd_netlink_message_open_container_union(req, IFLA_INFO_DATA, "bond"); if (r < 0) - return log_link_debug_errno(link, r, "Could not open IFLA_INFO_DATA container: %m"); + return r; if (link->network->active_slave) { r = sd_netlink_message_append_u32(req, IFLA_BOND_ACTIVE_SLAVE, link->ifindex); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_BOND_ACTIVE_SLAVE attribute: %m"); + return r; } if (link->network->primary_slave) { r = sd_netlink_message_append_u32(req, IFLA_BOND_PRIMARY, link->ifindex); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_BOND_PRIMARY attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_debug_errno(link, r, "Could not close IFLA_INFO_DATA container: %m"); + return r; r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_debug_errno(link, r, "Could not close IFLA_LINKINFO container: %m"); + return r; break; case SET_LINK_BRIDGE: r = sd_rtnl_message_link_set_family(req, AF_BRIDGE); if (r < 0) - return log_link_debug_errno(link, r, "Could not set message family: %m"); + return r; r = sd_netlink_message_open_container(req, IFLA_PROTINFO); if (r < 0) - return log_link_debug_errno(link, r, "Could not open IFLA_PROTINFO container: %m"); + return r; 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_debug_errno(link, r, "Could not append IFLA_BRPORT_GUARD attribute: %m"); + return r; } if (link->network->hairpin >= 0) { r = sd_netlink_message_append_u8(req, IFLA_BRPORT_MODE, link->network->hairpin); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_BRPORT_MODE attribute: %m"); + return r; } 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_debug_errno(link, r, "Could not append IFLA_BRPORT_FAST_LEAVE attribute: %m"); + return r; } 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_debug_errno(link, r, "Could not append IFLA_BRPORT_PROTECT attribute: %m"); + return r; } 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_debug_errno(link, r, "Could not append IFLA_BRPORT_UNICAST_FLOOD attribute: %m"); + return r; } 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_debug_errno(link, r, "Could not append IFLA_BRPORT_MCAST_FLOOD attribute: %m"); + return r; } 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_debug_errno(link, r, "Could not append IFLA_BRPORT_MCAST_TO_UCAST attribute: %m"); + return r; } 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_debug_errno(link, r, "Could not append IFLA_BRPORT_NEIGH_SUPPRESS attribute: %m"); + return r; } if (link->network->learning >= 0) { r = sd_netlink_message_append_u8(req, IFLA_BRPORT_LEARNING, link->network->learning); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_BRPORT_LEARNING attribute: %m"); + return r; } 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_debug_errno(link, r, "Could not append IFLA_BRPORT_PROXYARP attribute: %m"); + return r; } 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_debug_errno(link, r, "Could not append IFLA_BRPORT_PROXYARP_WIFI attribute: %m"); + return r; } if (link->network->cost != 0) { r = sd_netlink_message_append_u32(req, IFLA_BRPORT_COST, link->network->cost); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_BRPORT_COST attribute: %m"); + return r; } 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_debug_errno(link, r, "Could not append IFLA_BRPORT_PRIORITY attribute: %m"); + return r; } 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_debug_errno(link, r, "Could not append IFLA_BRPORT_MULTICAST_ROUTER attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_debug_errno(link, r, "Could not close IFLA_PROTINFO container: %m"); + return r; break; case SET_LINK_BRIDGE_VLAN: r = sd_rtnl_message_link_set_family(req, AF_BRIDGE); if (r < 0) - return log_link_debug_errno(link, r, "Could not set message family: %m"); + return r; r = sd_netlink_message_open_container(req, IFLA_AF_SPEC); if (r < 0) - return log_link_debug_errno(link, r, "Could not open IFLA_AF_SPEC container: %m"); + return r; if (link->master_ifindex <= 0) { /* master needs BRIDGE_FLAGS_SELF flag */ r = sd_netlink_message_append_u16(req, IFLA_BRIDGE_FLAGS, BRIDGE_FLAGS_SELF); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_BRIDGE_FLAGS attribute: %m"); + return r; } r = bridge_vlan_append_info(link, req, link->network->pvid, link->network->br_vid_bitmap, link->network->br_untagged_bitmap); if (r < 0) - return log_link_debug_errno(link, r, "Could not append VLANs: %m"); + return r; r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_debug_errno(link, r, "Could not close IFLA_AF_SPEC container: %m"); + return r; break; case SET_LINK_CAN: @@ -459,19 +434,19 @@ static int link_configure( r = sd_rtnl_message_link_set_flags(req, ifi_flags, ifi_change); if (r < 0) - return log_link_debug_errno(link, r, "Could not set link flags: %m"); + return r; break; } case SET_LINK_GROUP: r = sd_netlink_message_append_u32(req, IFLA_GROUP, (uint32_t) link->network->group); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_GROUP attribute: %m"); + return r; break; case SET_LINK_MAC: r = netlink_message_append_hw_addr(req, IFLA_ADDRESS, &link->requested_hw_addr); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_ADDRESS attribute: %m"); + return r; break; case SET_LINK_IPOIB: r = ipoib_set_netlink_message(link, req); @@ -481,21 +456,55 @@ static int link_configure( case SET_LINK_MASTER: r = sd_netlink_message_append_u32(req, IFLA_MASTER, PTR_TO_UINT32(userdata)); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_MASTER attribute: %m"); + return r; break; case SET_LINK_MTU: r = sd_netlink_message_append_u32(req, IFLA_MTU, PTR_TO_UINT32(userdata)); if (r < 0) - return log_link_debug_errno(link, r, "Could not append IFLA_MTU attribute: %m"); + return r; break; default: assert_not_reached(); } + return 0; +} + +static int link_configure( + Link *link, + SetLinkOperation op, + void *userdata, + link_netlink_message_handler_t callback) { + + _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; + int r; + + assert(link); + assert(link->manager); + assert(link->manager->rtnl); + assert(link->network); + assert(op >= 0 && op < _SET_LINK_OPERATION_MAX); + assert(callback); + + log_link_debug(link, "Setting %s", set_link_operation_to_string(op)); + + if (op == SET_LINK_BOND) + r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_NEWLINK, link->master_ifindex); + else if (IN_SET(op, SET_LINK_CAN, SET_LINK_IPOIB)) + r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_NEWLINK, link->ifindex); + else + r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex); + if (r < 0) + return log_link_debug_errno(link, r, "Could not allocate netlink message: %m"); + + r = link_configure_fill_message(link, req, op, userdata); + if (r < 0) + return log_link_debug_errno(link, r, "Could not create netlink message: %m"); + r = netlink_call_async(link->manager->rtnl, NULL, req, callback, link_netlink_destroy_callback, link); if (r < 0) - return log_link_debug_errno(link, r, "Could not send RTM_SETLINK message: %m"); + return log_link_debug_errno(link, r, "Could not send netlink message: %m"); link_ref(link); return 0; diff --git a/src/network/tc/cake.c b/src/network/tc/cake.c index b4cbc4f970..d52151e75d 100644 --- a/src/network/tc/cake.c +++ b/src/network/tc/cake.c @@ -39,88 +39,88 @@ static int cake_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) assert(qdisc); assert(req); - c = CAKE(qdisc); + assert_se(c = CAKE(qdisc)); r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "cake"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; if (c->bandwidth > 0) { r = sd_netlink_message_append_u64(req, TCA_CAKE_BASE_RATE64, c->bandwidth); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CAKE_BASE_RATE64 attribute: %m"); + return r; } if (c->autorate >= 0) { r = sd_netlink_message_append_u32(req, TCA_CAKE_AUTORATE, c->autorate); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CAKE_AUTORATE attribute: %m"); + return r; } if (c->overhead_set) { r = sd_netlink_message_append_s32(req, TCA_CAKE_OVERHEAD, c->overhead); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CAKE_OVERHEAD attribute: %m"); + return r; } if (c->mpu > 0) { r = sd_netlink_message_append_u32(req, TCA_CAKE_MPU, c->mpu); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CAKE_MPU attribute: %m"); + return r; } if (c->compensation_mode >= 0) { r = sd_netlink_message_append_u32(req, TCA_CAKE_ATM, c->compensation_mode); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CAKE_ATM attribute: %m"); + return r; } if (c->raw > 0) { /* TCA_CAKE_RAW attribute is mostly a flag, not boolean. */ r = sd_netlink_message_append_u32(req, TCA_CAKE_RAW, 0); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CAKE_RAW attribute: %m"); + return r; } if (c->flow_isolation_mode >= 0) { r = sd_netlink_message_append_u32(req, TCA_CAKE_FLOW_MODE, c->flow_isolation_mode); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CAKE_FLOW_MODE attribute: %m"); + return r; } if (c->nat >= 0) { r = sd_netlink_message_append_u32(req, TCA_CAKE_NAT, c->nat); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CAKE_NAT attribute: %m"); + return r; } if (c->preset >= 0) { r = sd_netlink_message_append_u32(req, TCA_CAKE_DIFFSERV_MODE, c->preset); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CAKE_DIFFSERV_MODE attribute: %m"); + return r; } if (c->fwmark > 0) { r = sd_netlink_message_append_u32(req, TCA_CAKE_FWMARK, c->fwmark); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CAKE_FWMARK attribute: %m"); + return r; } if (c->wash >= 0) { r = sd_netlink_message_append_u32(req, TCA_CAKE_WASH, c->wash); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CAKE_WASH attribute: %m"); + return r; } if (c->split_gso >= 0) { r = sd_netlink_message_append_u32(req, TCA_CAKE_SPLIT_GSO, c->split_gso); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CAKE_SPLIT_GSO attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; return 0; } diff --git a/src/network/tc/codel.c b/src/network/tc/codel.c index 33f40d87d4..23351bf3d1 100644 --- a/src/network/tc/codel.c +++ b/src/network/tc/codel.c @@ -31,45 +31,45 @@ static int controlled_delay_fill_message(Link *link, QDisc *qdisc, sd_netlink_me assert(qdisc); assert(req); - cd = CODEL(qdisc); + assert_se(cd = CODEL(qdisc)); r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "codel"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; if (cd->packet_limit > 0) { r = sd_netlink_message_append_u32(req, TCA_CODEL_LIMIT, cd->packet_limit); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CODEL_LIMIT attribute: %m"); + return r; } if (cd->interval_usec > 0) { r = sd_netlink_message_append_u32(req, TCA_CODEL_INTERVAL, cd->interval_usec); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CODEL_INTERVAL attribute: %m"); + return r; } if (cd->target_usec > 0) { r = sd_netlink_message_append_u32(req, TCA_CODEL_TARGET, cd->target_usec); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CODEL_TARGET attribute: %m"); + return r; } if (cd->ecn >= 0) { r = sd_netlink_message_append_u32(req, TCA_CODEL_ECN, cd->ecn); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CODEL_ECN attribute: %m"); + return r; } if (cd->ce_threshold_usec != USEC_INFINITY) { r = sd_netlink_message_append_u32(req, TCA_CODEL_CE_THRESHOLD, cd->ce_threshold_usec); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_CODEL_CE_THRESHOLD attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; return 0; } diff --git a/src/network/tc/drr.c b/src/network/tc/drr.c index ab67b0ad3e..742a56f8c9 100644 --- a/src/network/tc/drr.c +++ b/src/network/tc/drr.c @@ -23,21 +23,21 @@ static int drr_class_fill_message(Link *link, TClass *tclass, sd_netlink_message assert(tclass); assert(req); - drr = TCLASS_TO_DRR(tclass); + assert_se(drr = TCLASS_TO_DRR(tclass)); r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "drr"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; if (drr->quantum > 0) { r = sd_netlink_message_append_u32(req, TCA_DRR_QUANTUM, drr->quantum); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_DRR_QUANTUM, attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; return 0; } diff --git a/src/network/tc/ets.c b/src/network/tc/ets.c index f8dd1adabc..c4d594cd1b 100644 --- a/src/network/tc/ets.c +++ b/src/network/tc/ets.c @@ -20,57 +20,57 @@ static int enhanced_transmission_selection_fill_message(Link *link, QDisc *qdisc assert(qdisc); assert(req); - ets = ETS(qdisc); + assert_se(ets = ETS(qdisc)); r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "ets"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; r = sd_netlink_message_append_u8(req, TCA_ETS_NBANDS, ets->n_bands); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_ETS_NBANDS attribute: %m"); + return r; if (ets->n_strict > 0) { r = sd_netlink_message_append_u8(req, TCA_ETS_NSTRICT, ets->n_strict); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_ETS_NSTRICT attribute: %m"); + return r; } if (ets->n_quanta > 0) { r = sd_netlink_message_open_container(req, TCA_ETS_QUANTA); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_ETS_QUANTA: %m"); + return r; for (unsigned i = 0; i < ets->n_quanta; i++) { r = sd_netlink_message_append_u32(req, TCA_ETS_QUANTA_BAND, ets->quanta[i]); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_ETS_QUANTA_BAND attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_ETS_QUANTA: %m"); + return r; } if (ets->n_prio > 0) { r = sd_netlink_message_open_container(req, TCA_ETS_PRIOMAP); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_ETS_PRIOMAP: %m"); + return r; for (unsigned i = 0; i < ets->n_prio; i++) { r = sd_netlink_message_append_u8(req, TCA_ETS_PRIOMAP_BAND, ets->prio[i]); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_ETS_PRIOMAP_BAND attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_ETS_PRIOMAP: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; return 0; } diff --git a/src/network/tc/fifo.c b/src/network/tc/fifo.c index 3dd7f0b5f4..4f6e8fa613 100644 --- a/src/network/tc/fifo.c +++ b/src/network/tc/fifo.c @@ -11,7 +11,6 @@ #include "string-util.h" static int fifo_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { - struct tc_fifo_qopt opt = {}; FirstInFirstOut *fifo; int r; @@ -21,23 +20,22 @@ static int fifo_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) switch(qdisc->kind) { case QDISC_KIND_PFIFO: - fifo = PFIFO(qdisc); + assert_se(fifo = PFIFO(qdisc)); break; case QDISC_KIND_BFIFO: - fifo = BFIFO(qdisc); + assert_se(fifo = BFIFO(qdisc)); break; case QDISC_KIND_PFIFO_HEAD_DROP: - fifo = PFIFO_HEAD_DROP(qdisc); + assert_se(fifo = PFIFO_HEAD_DROP(qdisc)); break; default: assert_not_reached(); } - opt.limit = fifo->limit; - - r = sd_netlink_message_append_data(req, TCA_OPTIONS, &opt, sizeof(struct tc_fifo_qopt)); + const struct tc_fifo_qopt opt = { .limit = fifo->limit }; + r = sd_netlink_message_append_data(req, TCA_OPTIONS, &opt, sizeof(opt)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_OPTIONS attribute: %m"); + return r; return 0; } diff --git a/src/network/tc/fq-codel.c b/src/network/tc/fq-codel.c index 7c61cf2ac6..42dfd632a2 100644 --- a/src/network/tc/fq-codel.c +++ b/src/network/tc/fq-codel.c @@ -33,63 +33,63 @@ static int fair_queueing_controlled_delay_fill_message(Link *link, QDisc *qdisc, assert(qdisc); assert(req); - fqcd = FQ_CODEL(qdisc); + assert_se(fqcd = FQ_CODEL(qdisc)); r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "fq_codel"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; if (fqcd->packet_limit > 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_LIMIT, fqcd->packet_limit); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_LIMIT attribute: %m"); + return r; } if (fqcd->flows > 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_FLOWS, fqcd->flows); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_FLOWS attribute: %m"); + return r; } if (fqcd->quantum > 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_QUANTUM, fqcd->quantum); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_QUANTUM attribute: %m"); + return r; } if (fqcd->interval_usec > 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_INTERVAL, fqcd->interval_usec); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_INTERVAL attribute: %m"); + return r; } if (fqcd->target_usec > 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_TARGET, fqcd->target_usec); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_TARGET attribute: %m"); + return r; } if (fqcd->ecn >= 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_ECN, fqcd->ecn); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_ECN attribute: %m"); + return r; } if (fqcd->ce_threshold_usec != USEC_INFINITY) { r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_CE_THRESHOLD, fqcd->ce_threshold_usec); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_CE_THRESHOLD attribute: %m"); + return r; } if (fqcd->memory_limit != UINT32_MAX) { r = sd_netlink_message_append_u32(req, TCA_FQ_CODEL_MEMORY_LIMIT, fqcd->memory_limit); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_CODEL_MEMORY_LIMIT attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; return 0; } diff --git a/src/network/tc/fq-pie.c b/src/network/tc/fq-pie.c index c7d7623b47..d4a9d5966a 100644 --- a/src/network/tc/fq-pie.c +++ b/src/network/tc/fq-pie.c @@ -18,21 +18,21 @@ static int fq_pie_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req assert(qdisc); assert(req); - fq_pie = FQ_PIE(qdisc); + assert_se(fq_pie = FQ_PIE(qdisc)); r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "fq_pie"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; if (fq_pie->packet_limit > 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_PIE_LIMIT, fq_pie->packet_limit); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_PIE_PLIMIT attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; return 0; } diff --git a/src/network/tc/fq.c b/src/network/tc/fq.c index d10a863495..1e69a66d7b 100644 --- a/src/network/tc/fq.c +++ b/src/network/tc/fq.c @@ -32,46 +32,46 @@ static int fair_queueing_fill_message(Link *link, QDisc *qdisc, sd_netlink_messa assert(qdisc); assert(req); - fq = FQ(qdisc); + assert_se(fq = FQ(qdisc)); r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "fq"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; if (fq->packet_limit > 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_PLIMIT, fq->packet_limit); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_PLIMIT attribute: %m"); + return r; } if (fq->flow_limit > 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_FLOW_PLIMIT, fq->flow_limit); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_FLOW_PLIMIT attribute: %m"); + return r; } if (fq->quantum > 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_QUANTUM, fq->quantum); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_QUANTUM attribute: %m"); + return r; } if (fq->initial_quantum > 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_INITIAL_QUANTUM, fq->initial_quantum); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_INITIAL_QUANTUM attribute: %m"); + return r; } if (fq->pacing >= 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_RATE_ENABLE, fq->pacing); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_RATE_ENABLE attribute: %m"); + return r; } if (fq->max_rate > 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_FLOW_MAX_RATE, fq->max_rate); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_FLOW_MAX_RATE attribute: %m"); + return r; } if (fq->buckets > 0) { @@ -80,24 +80,24 @@ static int fair_queueing_fill_message(Link *link, QDisc *qdisc, sd_netlink_messa l = log2u(fq->buckets); r = sd_netlink_message_append_u32(req, TCA_FQ_BUCKETS_LOG, l); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_BUCKETS_LOG attribute: %m"); + return r; } if (fq->orphan_mask > 0) { r = sd_netlink_message_append_u32(req, TCA_FQ_ORPHAN_MASK, fq->orphan_mask); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_ORPHAN_MASK attribute: %m"); + return r; } if (fq->ce_threshold_usec != USEC_INFINITY) { r = sd_netlink_message_append_u32(req, TCA_FQ_CE_THRESHOLD, fq->ce_threshold_usec); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_FQ_CE_THRESHOLD attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; return 0; } diff --git a/src/network/tc/gred.c b/src/network/tc/gred.c index ce26e62450..96281e6bd4 100644 --- a/src/network/tc/gred.c +++ b/src/network/tc/gred.c @@ -24,32 +24,31 @@ static int generic_random_early_detection_init(QDisc *qdisc) { static int generic_random_early_detection_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { GenericRandomEarlyDetection *gred; - struct tc_gred_sopt opt = {}; int r; assert(link); assert(qdisc); assert(req); - gred = GRED(qdisc); - - opt.DPs = gred->virtual_queues; - opt.def_DP = gred->default_virtual_queue; + assert_se(gred = GRED(qdisc)); - if (gred->grio >= 0) - opt.grio = gred->grio; + const struct tc_gred_sopt opt = { + .DPs = gred->virtual_queues, + .def_DP = gred->default_virtual_queue, + .grio = gred->grio, + }; r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "gred"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; - r = sd_netlink_message_append_data(req, TCA_GRED_DPS, &opt, sizeof(struct tc_gred_sopt)); + r = sd_netlink_message_append_data(req, TCA_GRED_DPS, &opt, sizeof(opt)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_GRED_DPS attribute: %m"); + return r; r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; return 0; } diff --git a/src/network/tc/hhf.c b/src/network/tc/hhf.c index 68a4b45710..aac4feff45 100644 --- a/src/network/tc/hhf.c +++ b/src/network/tc/hhf.c @@ -19,21 +19,21 @@ static int heavy_hitter_filter_fill_message(Link *link, QDisc *qdisc, sd_netlink assert(qdisc); assert(req); - hhf = HHF(qdisc); + assert_se(hhf = HHF(qdisc)); r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "hhf"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; if (hhf->packet_limit > 0) { r = sd_netlink_message_append_u32(req, TCA_HHF_BACKLOG_LIMIT, hhf->packet_limit); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_HHF_BACKLOG_LIMIT attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; return 0; } diff --git a/src/network/tc/htb.c b/src/network/tc/htb.c index 14fb1f92e3..78fcd3f05f 100644 --- a/src/network/tc/htb.c +++ b/src/network/tc/htb.c @@ -16,31 +16,31 @@ static int hierarchy_token_bucket_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { HierarchyTokenBucket *htb; - struct tc_htb_glob opt = { - .version = 3, - }; int r; assert(link); assert(qdisc); assert(req); - htb = HTB(qdisc); + assert_se(htb = HTB(qdisc)); - opt.rate2quantum = htb->rate_to_quantum; - opt.defcls = htb->default_class; + struct tc_htb_glob opt = { + .version = 3, + .rate2quantum = htb->rate_to_quantum, + .defcls = htb->default_class, + }; r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "htb"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; r = sd_netlink_message_append_data(req, TCA_HTB_INIT, &opt, sizeof(opt)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_HTB_INIT attribute: %m"); + return r; r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; return 0; } @@ -171,7 +171,6 @@ const QDiscVTable htb_vtable = { static int hierarchy_token_bucket_class_fill_message(Link *link, TClass *tclass, sd_netlink_message *req) { HierarchyTokenBucketClass *htb; - struct tc_htb_opt opt = {}; uint32_t rtab[256], ctab[256]; int r; @@ -179,62 +178,65 @@ static int hierarchy_token_bucket_class_fill_message(Link *link, TClass *tclass, assert(tclass); assert(req); - htb = TCLASS_TO_HTB(tclass); + assert_se(htb = TCLASS_TO_HTB(tclass)); - opt.prio = htb->priority; - opt.quantum = htb->quantum; - opt.rate.rate = (htb->rate >= (1ULL << 32)) ? ~0U : htb->rate; - opt.ceil.rate = (htb->ceil_rate >= (1ULL << 32)) ? ~0U : htb->ceil_rate; - opt.rate.overhead = htb->overhead; - opt.ceil.overhead = htb->overhead; + struct tc_htb_opt opt = { + .prio = htb->priority, + .quantum = htb->quantum, + .rate.rate = (htb->rate >= (1ULL << 32)) ? ~0U : htb->rate, + .ceil.rate = (htb->ceil_rate >= (1ULL << 32)) ? ~0U : htb->ceil_rate, + .rate.overhead = htb->overhead, + .ceil.overhead = htb->overhead, + }; r = tc_transmit_time(htb->rate, htb->buffer, &opt.buffer); if (r < 0) - return log_link_error_errno(link, r, "Failed to calculate buffer size: %m"); + return log_link_debug_errno(link, r, "Failed to calculate buffer size: %m"); r = tc_transmit_time(htb->ceil_rate, htb->ceil_buffer, &opt.cbuffer); if (r < 0) - return log_link_error_errno(link, r, "Failed to calculate ceil buffer size: %m"); + return log_link_debug_errno(link, r, "Failed to calculate ceil buffer size: %m"); r = tc_fill_ratespec_and_table(&opt.rate, rtab, htb->mtu); if (r < 0) - return log_link_error_errno(link, r, "Failed to calculate rate table: %m"); + return log_link_debug_errno(link, r, "Failed to calculate rate table: %m"); r = tc_fill_ratespec_and_table(&opt.ceil, ctab, htb->mtu); if (r < 0) - return log_link_error_errno(link, r, "Failed to calculate ceil rate table: %m"); + return log_link_debug_errno(link, r, "Failed to calculate ceil rate table: %m"); r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "htb"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; r = sd_netlink_message_append_data(req, TCA_HTB_PARMS, &opt, sizeof(opt)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_HTB_PARMS attribute: %m"); + return r; if (htb->rate >= (1ULL << 32)) { r = sd_netlink_message_append_u64(req, TCA_HTB_RATE64, htb->rate); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_HTB_RATE64 attribute: %m"); + return r; } if (htb->ceil_rate >= (1ULL << 32)) { r = sd_netlink_message_append_u64(req, TCA_HTB_CEIL64, htb->ceil_rate); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_HTB_CEIL64 attribute: %m"); + return r; } r = sd_netlink_message_append_data(req, TCA_HTB_RTAB, rtab, sizeof(rtab)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_HTB_RTAB attribute: %m"); + return r; r = sd_netlink_message_append_data(req, TCA_HTB_CTAB, ctab, sizeof(ctab)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_HTB_CTAB attribute: %m"); + return r; r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; + return 0; } diff --git a/src/network/tc/netem.c b/src/network/tc/netem.c index 2d86d53125..d4c452675e 100644 --- a/src/network/tc/netem.c +++ b/src/network/tc/netem.c @@ -14,9 +14,6 @@ #include "tc-util.h" static int network_emulator_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { - struct tc_netem_qopt opt = { - .limit = 1000, - }; NetworkEmulator *ne; int r; @@ -24,16 +21,13 @@ static int network_emulator_fill_message(Link *link, QDisc *qdisc, sd_netlink_me assert(qdisc); assert(req); - ne = NETEM(qdisc); - - if (ne->limit > 0) - opt.limit = ne->limit; + assert_se(ne = NETEM(qdisc)); - if (ne->loss > 0) - opt.loss = ne->loss; - - if (ne->duplicate > 0) - opt.duplicate = ne->duplicate; + struct tc_netem_qopt opt = { + .limit = ne->limit > 0 ? ne->limit : 1000, + .loss = ne->loss, + .duplicate = ne->duplicate, + }; if (ne->delay != USEC_INFINITY) { r = tc_time_to_tick(ne->delay, &opt.latency); @@ -47,9 +41,9 @@ static int network_emulator_fill_message(Link *link, QDisc *qdisc, sd_netlink_me return log_link_error_errno(link, r, "Failed to calculate jitter in TCA_OPTION: %m"); } - r = sd_netlink_message_append_data(req, TCA_OPTIONS, &opt, sizeof(struct tc_netem_qopt)); + r = sd_netlink_message_append_data(req, TCA_OPTIONS, &opt, sizeof(opt)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_OPTION attribute: %m"); + return r; return 0; } diff --git a/src/network/tc/pie.c b/src/network/tc/pie.c index 4fcfe625b4..1b1a457f46 100644 --- a/src/network/tc/pie.c +++ b/src/network/tc/pie.c @@ -18,21 +18,21 @@ static int pie_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { assert(qdisc); assert(req); - pie = PIE(qdisc); + assert_se(pie = PIE(qdisc)); r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "pie"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; if (pie->packet_limit > 0) { r = sd_netlink_message_append_u32(req, TCA_PIE_LIMIT, pie->packet_limit); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_PIE_PLIMIT attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; return 0; } diff --git a/src/network/tc/qdisc.c b/src/network/tc/qdisc.c index 2e0f0a12eb..995df2fc86 100644 --- a/src/network/tc/qdisc.c +++ b/src/network/tc/qdisc.c @@ -184,16 +184,16 @@ int qdisc_configure(Link *link, QDisc *qdisc) { r = sd_rtnl_message_new_qdisc(link->manager->rtnl, &req, RTM_NEWQDISC, qdisc->family, link->ifindex); if (r < 0) - return log_link_error_errno(link, r, "Could not create RTM_NEWQDISC message: %m"); + return log_link_debug_errno(link, r, "Could not create RTM_NEWQDISC message: %m"); r = sd_rtnl_message_set_qdisc_parent(req, qdisc->parent); if (r < 0) - return log_link_error_errno(link, r, "Could not create tcm_parent message: %m"); + return r; if (qdisc->handle != TC_H_UNSPEC) { r = sd_rtnl_message_set_qdisc_handle(req, qdisc->handle); if (r < 0) - return log_link_error_errno(link, r, "Could not set tcm_handle message: %m"); + return r; } if (QDISC_VTABLE(qdisc)) { @@ -204,7 +204,7 @@ int qdisc_configure(Link *link, QDisc *qdisc) { } else { r = sd_netlink_message_append_string(req, TCA_KIND, QDISC_VTABLE(qdisc)->tca_kind); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_KIND attribute: %m"); + return r; } if (QDISC_VTABLE(qdisc)->fill_message) { @@ -215,12 +215,12 @@ int qdisc_configure(Link *link, QDisc *qdisc) { } else { r = sd_netlink_message_append_string(req, TCA_KIND, qdisc->tca_kind); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_KIND attribute: %m"); + return r; } r = netlink_call_async(link->manager->rtnl, NULL, req, qdisc_handler, link_netlink_destroy_callback, link); if (r < 0) - return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); + return log_link_debug_errno(link, r, "Could not send netlink message: %m"); link_ref(link); link->tc_messages++; diff --git a/src/network/tc/qfq.c b/src/network/tc/qfq.c index d2e7b875ef..51aef03210 100644 --- a/src/network/tc/qfq.c +++ b/src/network/tc/qfq.c @@ -25,27 +25,28 @@ static int quick_fair_queueing_class_fill_message(Link *link, TClass *tclass, sd assert(tclass); assert(req); - qfq = TCLASS_TO_QFQ(tclass); + assert_se(qfq = TCLASS_TO_QFQ(tclass)); r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "qfq"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; if (qfq->weight > 0) { r = sd_netlink_message_append_u32(req, TCA_QFQ_WEIGHT, qfq->weight); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_QFQ_WEIGHT attribute: %m"); + return r; } if (qfq->max_packet > 0) { r = sd_netlink_message_append_u32(req, TCA_QFQ_LMAX, qfq->max_packet); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_QFQ_LMAX attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; + return 0; } diff --git a/src/network/tc/sfb.c b/src/network/tc/sfb.c index a4ca4884b1..88b3ce55bd 100644 --- a/src/network/tc/sfb.c +++ b/src/network/tc/sfb.c @@ -13,7 +13,15 @@ static int stochastic_fair_blue_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { StochasticFairBlue *sfb; - struct tc_sfb_qopt opt = { + int r; + + assert(link); + assert(qdisc); + assert(req); + + assert_se(sfb = SFB(qdisc)); + + const struct tc_sfb_qopt opt = { .rehash_interval = 600*1000, .warmup_time = 60*1000, .penalty_rate = 10, @@ -22,28 +30,20 @@ static int stochastic_fair_blue_fill_message(Link *link, QDisc *qdisc, sd_netlin .decrement = (SFB_MAX_PROB + 10000) / 20000, .max = 25, .bin_size = 20, + .limit = sfb->packet_limit, }; - int r; - - assert(link); - assert(qdisc); - assert(req); - - sfb = SFB(qdisc); - - opt.limit = sfb->packet_limit; r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "sfb"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; - r = sd_netlink_message_append_data(req, TCA_SFB_PARMS, &opt, sizeof(struct tc_sfb_qopt)); + r = sd_netlink_message_append_data(req, TCA_SFB_PARMS, &opt, sizeof(opt)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_SFB_PARMS attribute: %m"); + return r; r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; return 0; } diff --git a/src/network/tc/sfq.c b/src/network/tc/sfq.c index f67ffc186d..45cc54d396 100644 --- a/src/network/tc/sfq.c +++ b/src/network/tc/sfq.c @@ -13,20 +13,21 @@ static int stochastic_fairness_queueing_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { StochasticFairnessQueueing *sfq; - struct tc_sfq_qopt_v1 opt = {}; int r; assert(link); assert(qdisc); assert(req); - sfq = SFQ(qdisc); + assert_se(sfq = SFQ(qdisc)); - opt.v0.perturb_period = sfq->perturb_period / USEC_PER_SEC; + const struct tc_sfq_qopt_v1 opt = { + .v0.perturb_period = sfq->perturb_period / USEC_PER_SEC, + }; - r = sd_netlink_message_append_data(req, TCA_OPTIONS, &opt, sizeof(struct tc_sfq_qopt_v1)); + r = sd_netlink_message_append_data(req, TCA_OPTIONS, &opt, sizeof(opt)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_OPTIONS attribute: %m"); + return r; return 0; } diff --git a/src/network/tc/tbf.c b/src/network/tc/tbf.c index 1d1bc6f0e9..2aca8c1f13 100644 --- a/src/network/tc/tbf.c +++ b/src/network/tc/tbf.c @@ -17,7 +17,6 @@ static int token_bucket_filter_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { uint32_t rtab[256], ptab[256]; - struct tc_tbf_qopt opt = {}; TokenBucketFilter *tbf; int r; @@ -25,10 +24,13 @@ static int token_bucket_filter_fill_message(Link *link, QDisc *qdisc, sd_netlink assert(qdisc); assert(req); - tbf = TBF(qdisc); + assert_se(tbf = TBF(qdisc)); - opt.rate.rate = tbf->rate >= (1ULL << 32) ? ~0U : tbf->rate; - opt.peakrate.rate = tbf->peak_rate >= (1ULL << 32) ? ~0U : tbf->peak_rate; + struct tc_tbf_qopt opt = { + .rate.rate = tbf->rate >= (1ULL << 32) ? ~0U : tbf->rate, + .peakrate.rate = tbf->peak_rate >= (1ULL << 32) ? ~0U : tbf->peak_rate, + .rate.mpu = tbf->mpu, + }; if (tbf->limit > 0) opt.limit = tbf->limit; @@ -43,69 +45,67 @@ static int token_bucket_filter_fill_message(Link *link, QDisc *qdisc, sd_netlink opt.limit = lim; } - opt.rate.mpu = tbf->mpu; - r = tc_fill_ratespec_and_table(&opt.rate, rtab, tbf->mtu); if (r < 0) - return log_link_error_errno(link, r, "Failed to calculate ratespec: %m"); + return log_link_debug_errno(link, r, "Failed to calculate ratespec: %m"); r = tc_transmit_time(opt.rate.rate, tbf->burst, &opt.buffer); if (r < 0) - return log_link_error_errno(link, r, "Failed to calculate buffer size: %m"); + return log_link_debug_errno(link, r, "Failed to calculate buffer size: %m"); if (opt.peakrate.rate > 0) { opt.peakrate.mpu = tbf->mpu; r = tc_fill_ratespec_and_table(&opt.peakrate, ptab, tbf->mtu); if (r < 0) - return log_link_error_errno(link, r, "Failed to calculate ratespec: %m"); + return log_link_debug_errno(link, r, "Failed to calculate ratespec: %m"); r = tc_transmit_time(opt.peakrate.rate, tbf->mtu, &opt.mtu); if (r < 0) - return log_link_error_errno(link, r, "Failed to calculate mtu size: %m"); + return log_link_debug_errno(link, r, "Failed to calculate mtu size: %m"); } r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "tbf"); if (r < 0) - return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m"); + return r; - r = sd_netlink_message_append_data(req, TCA_TBF_PARMS, &opt, sizeof(struct tc_tbf_qopt)); + r = sd_netlink_message_append_data(req, TCA_TBF_PARMS, &opt, sizeof(opt)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_TBF_PARMS attribute: %m"); + return r; r = sd_netlink_message_append_data(req, TCA_TBF_BURST, &tbf->burst, sizeof(tbf->burst)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_TBF_BURST attribute: %m"); + return r; if (tbf->rate >= (1ULL << 32)) { r = sd_netlink_message_append_u64(req, TCA_TBF_RATE64, tbf->rate); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_TBF_RATE64 attribute: %m"); + return r; } r = sd_netlink_message_append_data(req, TCA_TBF_RTAB, rtab, sizeof(rtab)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_TBF_RTAB attribute: %m"); + return r; if (opt.peakrate.rate > 0) { if (tbf->peak_rate >= (1ULL << 32)) { r = sd_netlink_message_append_u64(req, TCA_TBF_PRATE64, tbf->peak_rate); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_TBF_PRATE64 attribute: %m"); + return r; } r = sd_netlink_message_append_u32(req, TCA_TBF_PBURST, tbf->mtu); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_TBF_PBURST attribute: %m"); + return r; r = sd_netlink_message_append_data(req, TCA_TBF_PTAB, ptab, sizeof(ptab)); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_TBF_PTAB attribute: %m"); + return r; } r = sd_netlink_message_close_container(req); if (r < 0) - return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m"); + return r; return 0; } diff --git a/src/network/tc/tc.c b/src/network/tc/tc.c index a3cfed53fa..8f76809c7d 100644 --- a/src/network/tc/tc.c +++ b/src/network/tc/tc.c @@ -52,7 +52,7 @@ int link_configure_traffic_control(Link *link) { ORDERED_HASHMAP_FOREACH(tc, link->network->tc_by_section) { r = traffic_control_configure(link, tc); if (r < 0) - return r; + return log_link_error_errno(link, r, "Could not create send configuration message: %m"); } if (link->tc_messages == 0) diff --git a/src/network/tc/tclass.c b/src/network/tc/tclass.c index d8145997f0..10bffd65c6 100644 --- a/src/network/tc/tclass.c +++ b/src/network/tc/tclass.c @@ -139,21 +139,21 @@ int tclass_configure(Link *link, TClass *tclass) { r = sd_rtnl_message_new_tclass(link->manager->rtnl, &req, RTM_NEWTCLASS, AF_UNSPEC, link->ifindex); if (r < 0) - return log_link_error_errno(link, r, "Could not create RTM_NEWTCLASS message: %m"); + return log_link_debug_errno(link, r, "Could not create RTM_NEWTCLASS message: %m"); r = sd_rtnl_message_set_tclass_parent(req, tclass->parent); if (r < 0) - return log_link_error_errno(link, r, "Could not create tcm_parent message: %m"); + return r; if (tclass->classid != TC_H_UNSPEC) { r = sd_rtnl_message_set_tclass_handle(req, tclass->classid); if (r < 0) - return log_link_error_errno(link, r, "Could not set tcm_handle message: %m"); + return r; } r = sd_netlink_message_append_string(req, TCA_KIND, TCLASS_VTABLE(tclass)->tca_kind); if (r < 0) - return log_link_error_errno(link, r, "Could not append TCA_KIND attribute: %m"); + return r; if (TCLASS_VTABLE(tclass)->fill_message) { r = TCLASS_VTABLE(tclass)->fill_message(link, tclass, req); @@ -163,7 +163,7 @@ int tclass_configure(Link *link, TClass *tclass) { r = netlink_call_async(link->manager->rtnl, NULL, req, tclass_handler, link_netlink_destroy_callback, link); if (r < 0) - return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); + return log_link_debug_errno(link, r, "Could not send netlink message: %m"); link_ref(link); link->tc_messages++; diff --git a/src/test/test-bpf-foreign-programs.c b/src/test/test-bpf-foreign-programs.c index 1765dc7a9b..8c3f76e9ec 100644 --- a/src/test/test-bpf-foreign-programs.c +++ b/src/test/test-bpf-foreign-programs.c @@ -289,11 +289,11 @@ int main(int argc, char *argv[]) { (void) setrlimit_closest(RLIMIT_MEMLOCK, &rl); if (!can_memlock()) - return log_tests_skipped("Can't use mlock(), skipping."); + return log_tests_skipped("Can't use mlock()"); r = cg_all_unified(); if (r <= 0) - return log_tests_skipped("Unified hierarchy is required, skipping."); + return log_tests_skipped("Unified hierarchy is required"); r = enter_cgroup_subroot(NULL); if (r == -ENOMEDIUM) diff --git a/src/test/test-bpf-lsm.c b/src/test/test-bpf-lsm.c index 3022767295..60d1789a0a 100644 --- a/src/test/test-bpf-lsm.c +++ b/src/test/test-bpf-lsm.c @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) { (void) setrlimit_closest(RLIMIT_MEMLOCK, &rl); if (!can_memlock()) - return log_tests_skipped("Can't use mlock(), skipping."); + return log_tests_skipped("Can't use mlock()"); r = lsm_bpf_supported(); if (r <= 0) diff --git a/src/test/test-socket-bind.c b/src/test/test-socket-bind.c index ecad86baeb..f4197aaf3c 100644 --- a/src/test/test-socket-bind.c +++ b/src/test/test-socket-bind.c @@ -120,14 +120,14 @@ int main(int argc, char *argv[]) { (void) setrlimit_closest(RLIMIT_MEMLOCK, &rl); if (!can_memlock()) - return log_tests_skipped("Can't use mlock(), skipping."); + return log_tests_skipped("Can't use mlock()"); r = bpf_socket_bind_supported(); if (r <= 0) - return log_tests_skipped("socket-bind is not supported, skipping."); + return log_tests_skipped("socket-bind is not supported"); if (find_netcat_executable(&netcat_path) != 0) - return log_tests_skipped("Can not find netcat executable, skipping."); + return log_tests_skipped("Can not find netcat executable"); r = enter_cgroup_subroot(NULL); if (r == -ENOMEDIUM) |