struct nl_handler nlh;
struct nlmsghdr *hdr;
struct rtgenmsg *msg;
+ int saved_errno;
__s32 ns_id = -1;
__u32 netns_fd = fd;
addattr(hdr, 1024, __LXC_NETNSA_NSID, &ns_id, sizeof(ns_id));
ret = __netlink_transaction(&nlh, hdr, hdr);
+ saved_errno = errno;
netlink_close(&nlh);
+ errno = saved_errno;
if (ret < 0)
return -1;
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
+#include "config.h"
+
#include <sys/socket.h>
#include <string.h>
#include <stdio.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
+#include "log.h"
#include "nl.h"
+lxc_log_define(nl, lxc);
+
extern size_t nlmsg_len(const struct nlmsg *nlmsg)
{
return nlmsg->nlmsghdr->nlmsg_len - NLMSG_HDRLEN;
if (!ret)
return 0;
- if (msg.msg_flags & MSG_TRUNC && (ret == nlmsghdr->nlmsg_len))
- return -EMSGSIZE;
+ if (msg.msg_flags & MSG_TRUNC && (ret == nlmsghdr->nlmsg_len)) {
+ errno = EMSGSIZE;
+ ret = -1;
+ }
return ret;
}
ret = __netlink_send(handler, request);
if (ret < 0)
- return ret;
+ return -1;
ret = __netlink_recv(handler, answer);
if (ret < 0)
- return ret;
+ return -1;
+ ret = 0;
if (answer->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(answer);
- return err->error;
+ errno = -err->error;
+ if (err->error < 0)
+ ret = -1;
}
- return 0;
+ return ret;
}
extern int netlink_transaction(struct nl_handler *handler,
DEBUG("Preserved net namespace via fd %d", ret);
ret = lxc_netns_set_nsid(handler->nsfd[LXC_NS_NET]);
- if (ret < 0) {
- errno = -ret;
+ if (ret < 0)
SYSERROR("Failed to allocate new network namespace id");
- } else {
+ else
TRACE("Allocated new network namespace id");
- }
}
/* Create the network configuration. */