1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

network/netdev: check family of received NEWLINK message

For safety. No functional change, just refactoring and preparation for
later commits.
This commit is contained in:
Yu Watanabe 2024-09-09 22:46:27 +09:00
parent 72fd133dca
commit 5d7de25052

View File

@ -351,7 +351,7 @@ int netdev_set_ifindex(NetDev *netdev, sd_netlink_message *message) {
const char *kind;
const char *received_kind;
const char *received_name;
int r, ifindex;
int r, ifindex, family;
assert(netdev);
assert(message);
@ -363,6 +363,13 @@ int netdev_set_ifindex(NetDev *netdev, sd_netlink_message *message) {
if (type != RTM_NEWLINK)
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL), "Cannot set ifindex from unexpected rtnl message type.");
r = sd_rtnl_message_get_family(message, &family);
if (r < 0)
return log_netdev_warning_errno(netdev, r, "Failed to get family from received rtnl message: %m");
if (family != AF_UNSPEC)
return 0; /* IFLA_LINKINFO is only contained in the message with AF_UNSPEC. */
r = sd_rtnl_message_link_get_ifindex(message, &ifindex);
if (r < 0) {
log_netdev_error_errno(netdev, r, "Could not get ifindex: %m");