int len = RTA_LENGTH(alen);
struct rtattr *rta;
+ errno = EMSGSIZE;
if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen)
return -1;
struct nlmsghdr *hdr;
struct rtgenmsg *msg;
int saved_errno;
- __s32 ns_id = -1;
- __u32 netns_fd = fd;
+ const __s32 ns_id = -1;
+ const __u32 netns_fd = fd;
ret = netlink_open(&nlh, NETLINK_ROUTE);
if (ret < 0)
hdr->nlmsg_seq = RTM_NEWNSID;
msg->rtgen_family = AF_UNSPEC;
- addattr(hdr, 1024, __LXC_NETNSA_FD, &netns_fd, sizeof(netns_fd));
- addattr(hdr, 1024, __LXC_NETNSA_NSID, &ns_id, sizeof(ns_id));
+ ret = addattr(hdr, 1024, __LXC_NETNSA_FD, &netns_fd, sizeof(netns_fd));
+ if (ret < 0)
+ goto on_error;
+
+ ret = addattr(hdr, 1024, __LXC_NETNSA_NSID, &ns_id, sizeof(ns_id));
+ if (ret < 0)
+ goto on_error;
ret = __netlink_transaction(&nlh, hdr, hdr);
+
+on_error:
saved_errno = errno;
netlink_close(&nlh);
errno = saved_errno;
- if (ret < 0)
- return -1;
- return 0;
+ return ret;
}
static int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
int ret;
ssize_t len;
char buf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
- NLMSG_ALIGN(sizeof(struct rtgenmsg)) + NLMSG_ALIGN(1024)];
+ NLMSG_ALIGN(sizeof(struct rtgenmsg)) +
+ NLMSG_ALIGN(1024)];
struct rtattr *tb[__LXC_NETNSA_MAX + 1];
struct nl_handler nlh;
struct nlmsghdr *hdr;
hdr->nlmsg_seq = RTM_GETNSID;
msg->rtgen_family = AF_UNSPEC;
- addattr(hdr, 1024, __LXC_NETNSA_FD, &netns_fd, sizeof(netns_fd));
+ ret = addattr(hdr, 1024, __LXC_NETNSA_FD, &netns_fd, sizeof(netns_fd));
+ if (ret == 0)
+ ret = __netlink_transaction(&nlh, hdr, hdr);
- ret = __netlink_transaction(&nlh, hdr, hdr);
saved_errno = errno;
netlink_close(&nlh);
errno = saved_errno;
if (ret < 0)
return -1;
+ errno = EINVAL;
msg = NLMSG_DATA(hdr);
len = hdr->nlmsg_len - NLMSG_SPACE(sizeof(*msg));
if (len < 0)