[lxc-devel] [lxc/master] network: type fixes lxc_netns_set_nsid()

brauner on Github lxc-bot at linuxcontainers.org
Thu Aug 9 17:55:10 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 437 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180809/6535b584/attachment.bin>
-------------- next part --------------
From 1cc84f44adba5a68a502c799e18ec2f593efb0b3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 9 Aug 2018 19:53:03 +0200
Subject: [PATCH] network: type fixes lxc_netns_set_nsid()

The kernel expects a __s32 for NETNSA_NSID and a __u32 for NETNSA_FD.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/network.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/lxc/network.c b/src/lxc/network.c
index 277133513..d0824690f 100644
--- a/src/lxc/network.c
+++ b/src/lxc/network.c
@@ -3164,7 +3164,7 @@ void lxc_delete_network(struct lxc_handler *handler)
 		DEBUG("Deleted network devices");
 }
 
-int addattr(struct nlmsghdr *n, int maxlen, int type, const void *data, int alen)
+int addattr(struct nlmsghdr *n, size_t maxlen, int type, const void *data, size_t alen)
 {
 	int len = RTA_LENGTH(alen);
 	struct rtattr *rta;
@@ -3184,11 +3184,11 @@ int addattr(struct nlmsghdr *n, int maxlen, int type, const void *data, int alen
 
 /* Attributes of RTM_NEWNSID/RTM_GETNSID messages */
 enum {
-	LXC_NETNSA_NONE,
-#define LXC_NETNSA_NSID_NOT_ASSIGNED -1
-	LXC_NETNSA_NSID,
-	LXC_NETNSA_PID,
-	LXC_NETNSA_FD,
+	__LXC_NETNSA_NONE,
+#define __LXC_NETNSA_NSID_NOT_ASSIGNED -1
+	__LXC_NETNSA_NSID,
+	__LXC_NETNSA_PID,
+	__LXC_NETNSA_FD,
 	__LXC_NETNSA_MAX,
 };
 
@@ -3202,7 +3202,8 @@ int lxc_netns_set_nsid(int fd)
 	struct nlmsghdr *l_hdr;
 	struct rtgenmsg *l_msg;
 	struct sockaddr_nl l_addr;
-	int nsid = -1;
+	__s32 ns_id = -1;
+	__u32 netns_fd = fd;
 
 	ret = netlink_open(&nlh, NETLINK_ROUTE);
 	if (ret < 0)
@@ -3219,8 +3220,8 @@ int lxc_netns_set_nsid(int fd)
 	l_hdr->nlmsg_seq = RTM_NEWNSID;
 	l_msg->rtgen_family = AF_UNSPEC;
 
-	addattr(l_hdr, 1024, LXC_NETNSA_FD, &fd, sizeof(__u32));
-	addattr(l_hdr, 1024, LXC_NETNSA_NSID, &nsid, sizeof(__u32));
+	addattr(l_hdr, 1024, __LXC_NETNSA_FD, &netns_fd, sizeof(netns_fd));
+	addattr(l_hdr, 1024, __LXC_NETNSA_NSID, &ns_id, sizeof(ns_id));
 
 	memset(&l_addr, 0, sizeof(l_addr));
 	l_addr.nl_family = AF_NETLINK;


More information about the lxc-devel mailing list