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

Rafał Miłecki rafal at milecki.pl
Fri Jan 19 19:00:12 UTC 2018


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?


More information about the lxc-devel mailing list