- struct nl_cb *cb = nl_cb_alloc(NL_CB_DEFAULT);
- struct nl_msg *msg;
- struct ifinfomsg ifi = {
- .ifi_family = AF_UNSPEC,
- .ifi_index = 0,
- };
- struct if_check_data chk = {
- .dev = dev,
- .pending = 1,
- };
- int ret = 1;
-
- msg = nlmsg_alloc_simple(RTM_GETLINK, 0);
- if (!msg || nlmsg_append(msg, &ifi, sizeof(ifi), 0) ||
- nla_put_string(msg, IFLA_IFNAME, dev->ifname))
- goto out;
-
- nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_if_check_valid, &chk);
- nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, cb_if_check_ack, &chk);
- nl_cb_err(cb, NL_CB_CUSTOM, cb_if_check_error, &chk);
-
- nl_send_auto_complete(sock_rtnl, msg);
- while (chk.pending > 0)
- nl_recvmsgs(sock_rtnl, cb);
-
- nlmsg_free(msg);
- ret = chk.pending;
-
-out:
- nl_cb_put(cb);
- return ret;