From f25e642bca1729bcc84b464b5125c8a214a63f5c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 23 May 2021 16:56:47 +0900 Subject: [PATCH] sd-netlink: rename rtnl_get_link_iftype() -> rtnl_get_link_info() and make it optionally return link flags --- src/libsystemd/sd-netlink/netlink-util.c | 28 ++++++++++++++++++++++-- src/libsystemd/sd-netlink/netlink-util.h | 2 +- src/udev/net/link-config.c | 4 ++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/libsystemd/sd-netlink/netlink-util.c b/src/libsystemd/sd-netlink/netlink-util.c index 78a51cf78d8..868763bb9c0 100644 --- a/src/libsystemd/sd-netlink/netlink-util.c +++ b/src/libsystemd/sd-netlink/netlink-util.c @@ -302,10 +302,18 @@ int rtnl_resolve_link_alternative_name(sd_netlink **rtnl, const char *name) { return ret; } -int rtnl_get_link_iftype(sd_netlink **rtnl, int ifindex, unsigned short *ret) { +int rtnl_get_link_info(sd_netlink **rtnl, int ifindex, unsigned short *ret_iftype, unsigned *ret_flags) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL, *reply = NULL; + unsigned short iftype; + unsigned flags; int r; + assert(rtnl); + assert(ifindex > 0); + + if (!ret_iftype && !ret_flags) + return 0; + if (!*rtnl) { r = sd_netlink_open(rtnl); if (r < 0) @@ -322,7 +330,23 @@ int rtnl_get_link_iftype(sd_netlink **rtnl, int ifindex, unsigned short *ret) { if (r < 0) return r; - return sd_rtnl_message_link_get_type(reply, ret); + if (ret_iftype) { + r = sd_rtnl_message_link_get_type(reply, &iftype); + if (r < 0) + return r; + } + + if (ret_flags) { + r = sd_rtnl_message_link_get_flags(reply, &flags); + if (r < 0) + return r; + } + + if (ret_iftype) + *ret_iftype = iftype; + if (ret_flags) + *ret_flags = flags; + return 0; } int rtnl_message_new_synthetic_error(sd_netlink *rtnl, int error, uint32_t serial, sd_netlink_message **ret) { diff --git a/src/libsystemd/sd-netlink/netlink-util.h b/src/libsystemd/sd-netlink/netlink-util.h index 98bbfa45133..059a5c665aa 100644 --- a/src/libsystemd/sd-netlink/netlink-util.h +++ b/src/libsystemd/sd-netlink/netlink-util.h @@ -92,7 +92,7 @@ int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const int rtnl_set_link_alternative_names_by_ifname(sd_netlink **rtnl, const char *ifname, char * const *alternative_names); int rtnl_delete_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const *alternative_names); int rtnl_resolve_link_alternative_name(sd_netlink **rtnl, const char *name); -int rtnl_get_link_iftype(sd_netlink **rtnl, int ifindex, unsigned short *ret); +int rtnl_get_link_info(sd_netlink **rtnl, int ifindex, unsigned short *ret_iftype, unsigned *ret_flags); int rtnl_log_parse_error(int r); int rtnl_log_create_error(int r); diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 5d2b8c0bcff..35923b272a8 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -240,7 +240,7 @@ bool link_config_should_reload(LinkConfigContext *ctx) { int link_config_get(LinkConfigContext *ctx, sd_device *device, LinkConfig **ret) { unsigned name_assign_type = NET_NAME_UNKNOWN; struct ether_addr permanent_mac = {}; - unsigned short iftype = 0; + unsigned short iftype; LinkConfig *link; const char *name; int ifindex, r; @@ -257,7 +257,7 @@ int link_config_get(LinkConfigContext *ctx, sd_device *device, LinkConfig **ret) if (r < 0) return r; - r = rtnl_get_link_iftype(&ctx->rtnl, ifindex, &iftype); + r = rtnl_get_link_info(&ctx->rtnl, ifindex, &iftype, NULL); if (r < 0) return r; -- 2.47.3