[lxc-devel] Getting complex data (structs) from a container (net ns) in API

Serge E. Hallyn serge at hallyn.com
Wed Feb 14 15:51:28 UTC 2018


Quoting Rafał Miłecki (rafal at milecki.pl):
> Hi,
> 
> currently lxccontainer's API has two functions for getting net info:
> char** (*get_interfaces)(struct lxc_container *c);
> char** (*get_ips)(struct lxc_container *c, const char* interface,
> const char* family, int scope);
> 
> I'd like to get more detailed info about container's interfaces like a
> list of interfaces with IPs (and maybe MAC) for each of them. Let's say:
> 
> struct lxc_interface {
> 	struct lxc_interface *next;
> 	const char name[IFNAMSIZ];
> 	uint8_t mac_addr[ETH_ALEN];
> 	char **ips;
> };
> 
> struct lxc_interface *(*get_interfaces_info)(struct lxc_container *c);
> 
> The problem is passing data between net's namespace (container) and a
> host. IPs and interface names are passed using a pipe as their format is
> quite trivial. Passing a whole struct is a bigger problem that I don't
> know how to handle.
> 
> 1) Passing struct over a pipe would require some serialization tricks.
> 
> 2) Shared memory could be used while fork()ing (e.g. mmap or shmget) but
> not trivial, because shared memory can't be dynamically reallocated as
> needed for building a list of interfaces in a child process.
> 
> 3) Threads aren't currently used by LXC tools, so I'm not sure if they
> are acceptable.
> 
> These are the only ideas I got.
> 
> Do you find any of above solutions applicable or maybe you have a better
> one?

1) is the most usual way for us, where we do the serialization ourselves.
Detail the precise list of information you think should be there, create
a struct for it, and put a version at the top (so we can add info later).

shmem could be interesting for better performance.

-serge


More information about the lxc-devel mailing list