if (groups)
nl_join_groups(sock, groups);
- if (nl_connect(sock, protocol))
+ if (nl_connect(sock, protocol)) {
+ nl_socket_free(sock);
return NULL;
+ }
return sock;
}
struct clear_data *clr = arg;
struct nlmsghdr *hdr = nlmsg_hdr(msg);
bool (*cb)(struct nlmsghdr *, int ifindex);
- int type;
+ int type, ret;
switch(clr->type) {
case RTM_GETADDR:
D(SYSTEM, "Remove %s from device %s\n",
type == RTM_DELADDR ? "an address" : "a route",
clr->dev->ifname);
+
memcpy(nlmsg_hdr(clr->msg), hdr, hdr->nlmsg_len);
hdr = nlmsg_hdr(clr->msg);
hdr->nlmsg_type = type;
hdr->nlmsg_flags = NLM_F_REQUEST;
nl_socket_disable_auto_ack(sock_rtnl);
- nl_send_auto_complete(sock_rtnl, clr->msg);
+ ret = nl_send_auto_complete(sock_rtnl, clr->msg);
+ if (ret < 0) {
+ if (type == RTM_DELRULE)
+ D(SYSTEM, "Error deleting a rule: %d\n", ret);
+ else
+ D(SYSTEM, "Error deleting %s from device '%s': %d\n",
+ type == RTM_DELADDR ? "an address" : "a route",
+ clr->dev->ifname, ret);
+ }
+
nl_socket_enable_auto_ack(sock_rtnl);
return NL_SKIP;
int flags = NLM_F_DUMP;
int pending = 1;
+ if (!cb)
+ return;
+
clr.af = af;
clr.dev = dev;
clr.type = type;
return;
}
- if (!cb)
- return;
-
clr.msg = nlmsg_alloc_simple(type, flags);
if (!clr.msg)
goto out;
nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, cb_finish_event, &pending);
nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &pending);
- nl_send_auto_complete(sock_rtnl, clr.msg);
+ if (nl_send_auto_complete(sock_rtnl, clr.msg) < 0)
+ goto free;
+
while (pending > 0)
nl_recvmsgs(sock_rtnl, cb);
+free:
nlmsg_free(clr.msg);
out:
nl_cb_put(cb);
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);
+ ret = nl_send_auto_complete(sock_rtnl, msg);
+ if (ret < 0)
+ goto free;
+
while (chk.pending > 0)
nl_recvmsgs(sock_rtnl, cb);