networkd-link: parse linkinfo to get kind
This commit is contained in:
parent
d643a60a9e
commit
6cad256dbe
|
@ -396,7 +396,7 @@ static int link_update_flags(Link *link, sd_netlink_message *m) {
|
||||||
static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
|
static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
|
||||||
_cleanup_link_unref_ Link *link = NULL;
|
_cleanup_link_unref_ Link *link = NULL;
|
||||||
uint16_t type;
|
uint16_t type;
|
||||||
const char *ifname;
|
const char *ifname, *kind = NULL;
|
||||||
int r, ifindex;
|
int r, ifindex;
|
||||||
unsigned short iftype;
|
unsigned short iftype;
|
||||||
|
|
||||||
|
@ -404,6 +404,15 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
|
||||||
assert(message);
|
assert(message);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
|
/* check for link kind */
|
||||||
|
r = sd_netlink_message_enter_container(message, IFLA_LINKINFO);
|
||||||
|
if (r == 0) {
|
||||||
|
(void)sd_netlink_message_read_string(message, IFLA_INFO_KIND, &kind);
|
||||||
|
r = sd_netlink_message_exit_container(message);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
r = sd_netlink_message_get_type(message, &type);
|
r = sd_netlink_message_get_type(message, &type);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
@ -438,6 +447,12 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
|
||||||
if (!link->ifname)
|
if (!link->ifname)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
if (kind) {
|
||||||
|
link->kind = strdup(kind);
|
||||||
|
if (!link->kind)
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
r = sd_netlink_message_read_ether_addr(message, IFLA_ADDRESS, &link->mac);
|
r = sd_netlink_message_read_ether_addr(message, IFLA_ADDRESS, &link->mac);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_link_debug_errno(link, r, "MAC address not found for new device, continuing without");
|
log_link_debug_errno(link, r, "MAC address not found for new device, continuing without");
|
||||||
|
@ -515,6 +530,9 @@ static void link_free(Link *link) {
|
||||||
|
|
||||||
free(link->ifname);
|
free(link->ifname);
|
||||||
|
|
||||||
|
if (link->kind)
|
||||||
|
free(link->kind);
|
||||||
|
|
||||||
(void)unlink(link->state_file);
|
(void)unlink(link->state_file);
|
||||||
free(link->state_file);
|
free(link->state_file);
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ typedef struct Link {
|
||||||
|
|
||||||
int ifindex;
|
int ifindex;
|
||||||
char *ifname;
|
char *ifname;
|
||||||
|
char *kind;
|
||||||
unsigned short iftype;
|
unsigned short iftype;
|
||||||
char *state_file;
|
char *state_file;
|
||||||
struct ether_addr mac;
|
struct ether_addr mac;
|
||||||
|
|
Loading…
Reference in a new issue