From 3e0eeb8e33070616adf090acb656d97c716e00b3 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 25 May 2021 06:49:51 +0900 Subject: [PATCH] sd-netlink: do not set route type and table by default for RTM_GETROUTE or friends --- src/libsystemd/sd-netlink/rtnl-message.c | 3 --- src/network/networkd-route.c | 26 +++++++++++------------- src/shared/local-addresses.c | 8 ++++++++ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/libsystemd/sd-netlink/rtnl-message.c b/src/libsystemd/sd-netlink/rtnl-message.c index 5dba9c57342..e771b95e084 100644 --- a/src/libsystemd/sd-netlink/rtnl-message.c +++ b/src/libsystemd/sd-netlink/rtnl-message.c @@ -265,9 +265,6 @@ int sd_rtnl_message_new_route(sd_netlink *rtnl, sd_netlink_message **ret, rtm = NLMSG_DATA((*ret)->hdr); rtm->rtm_family = rtm_family; - rtm->rtm_scope = RT_SCOPE_UNIVERSE; - rtm->rtm_type = RTN_UNICAST; - rtm->rtm_table = RT_TABLE_MAIN; rtm->rtm_protocol = rtm_protocol; return 0; diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 257255d4e62..7d93825813f 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -893,21 +893,19 @@ static int route_set_netlink_message(const Route *route, sd_netlink_message *req if (r < 0) return log_link_error_errno(link, r, "Could not set flags: %m"); - if (route->table != RT_TABLE_MAIN) { - 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"); - } 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"); + 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"); + } 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"); - /* Table attribute to allow more than 256. */ - r = sd_netlink_message_append_data(req, RTA_TABLE, &route->table, sizeof(route->table)); - if (r < 0) - return log_link_error_errno(link, r, "Could not append RTA_TABLE attribute: %m"); - } + /* Table attribute to allow more than 256. */ + r = sd_netlink_message_append_data(req, RTA_TABLE, &route->table, sizeof(route->table)); + if (r < 0) + return log_link_error_errno(link, r, "Could not append RTA_TABLE attribute: %m"); } if (!route_type_is_reject(route) && route->nexthop_id == 0) { diff --git a/src/shared/local-addresses.c b/src/shared/local-addresses.c index f037c5281f4..29ab9241e91 100644 --- a/src/shared/local-addresses.c +++ b/src/shared/local-addresses.c @@ -228,6 +228,14 @@ int local_gateways( if (r < 0) return r; + r = sd_rtnl_message_route_set_type(req, RTN_UNICAST); + if (r < 0) + return r; + + r = sd_rtnl_message_route_set_table(req, RT_TABLE_MAIN); + if (r < 0) + return r; + r = sd_netlink_message_request_dump(req, true); if (r < 0) return r;