diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-11-06 04:40:29 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-11-09 08:00:49 +0100 |
commit | 8e30e5fcd41d8a2a16e01803998152babe202d68 (patch) | |
tree | 97756eafb9338c287d6950e5e3312a3994d5dbb0 /src/network/netdev/geneve.c | |
parent | network/netdev: update comment (diff) | |
download | systemd-8e30e5fcd41d8a2a16e01803998152babe202d68.tar.xz systemd-8e30e5fcd41d8a2a16e01803998152babe202d68.zip |
network: geneve: use fill_message_create
Diffstat (limited to 'src/network/netdev/geneve.c')
-rw-r--r-- | src/network/netdev/geneve.c | 76 |
1 files changed, 4 insertions, 72 deletions
diff --git a/src/network/netdev/geneve.c b/src/network/netdev/geneve.c index 1bffbc9586..46f5ea41c8 100644 --- a/src/network/netdev/geneve.c +++ b/src/network/netdev/geneve.c @@ -25,65 +25,15 @@ static const char* const geneve_df_table[_NETDEV_GENEVE_DF_MAX] = { DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(geneve_df, GeneveDF, NETDEV_GENEVE_DF_YES); DEFINE_CONFIG_PARSE_ENUM(config_parse_geneve_df, geneve_df, GeneveDF, "Failed to parse Geneve IPDoNotFragment= setting"); -/* callback for geneve netdev's created without a backing Link */ -static int geneve_netdev_create_handler(sd_netlink *rtnl, sd_netlink_message *m, NetDev *netdev) { - int r; - - assert(netdev); - assert(netdev->state != _NETDEV_STATE_INVALID); - - r = sd_netlink_message_get_errno(m); - if (r == -EEXIST) - log_netdev_info(netdev, "Geneve netdev exists, using existing without changing its parameters"); - else if (r < 0) { - log_netdev_warning_errno(netdev, r, "Geneve netdev could not be created: %m"); - netdev_enter_failed(netdev); - - return 1; - } - - log_netdev_debug(netdev, "Geneve created"); - - return 1; -} - -static int netdev_geneve_create(NetDev *netdev) { - _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; +static int netdev_geneve_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { Geneve *v; int r; assert(netdev); + assert(m); v = GENEVE(netdev); - 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"); - - if (netdev->mac) { - r = sd_netlink_message_append_ether_addr(m, IFLA_ADDRESS, netdev->mac); - if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_ADDRESS attribute: %m"); - } - - 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"); - } - - 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"); - - 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"); - if (v->id <= GENEVE_VID_MAX) { r = sd_netlink_message_append_u32(m, IFLA_GENEVE_ID, v->id); if (r < 0) @@ -143,25 +93,7 @@ static int netdev_geneve_create(NetDev *netdev) { return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_DF attribute: %m"); } - 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"); - - r = sd_netlink_message_close_container(m); - if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINKINFO attribute: %m"); - - r = netlink_call_async(netdev->manager->rtnl, NULL, m, geneve_netdev_create_handler, - netdev_destroy_callback, netdev); - if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m"); - - netdev_ref(netdev); - netdev->state = NETDEV_STATE_CREATING; - - log_netdev_debug(netdev, "Creating"); - - return r; + return 0; } int config_parse_geneve_vni( @@ -357,7 +289,7 @@ const NetDevVTable geneve_vtable = { .object_size = sizeof(Geneve), .init = geneve_init, .sections = NETDEV_COMMON_SECTIONS "GENEVE\0", - .create = netdev_geneve_create, + .fill_message_create = netdev_geneve_fill_message_create, .create_type = NETDEV_CREATE_INDEPENDENT, .config_verify = netdev_geneve_verify, .generate_mac = true, |