]> git.proxmox.com Git - mirror_lxc.git/commit - src/include/netns_ifaddrs.c
network: add netns_getifaddrs() implementation
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 23 Sep 2018 13:29:22 +0000 (15:29 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 23 Sep 2018 19:19:35 +0000 (21:19 +0200)
commitcc6119a0334a0debf43c4d2dffc9f549a67e315d
tree0743ed6664d7dccedb6a7a0626f39b740070a9fe
parent7e270c97f1e042beda573b99427863701538c5b2
network: add netns_getifaddrs() implementation

This commit introduces my concept of a network namespace aware
getifaddrs(), i.e. netns_getifaddrs(). This presupposes a kernel that
carries my IF{L}A_TARGET_NETNSID patches:

struct netns_ifaddrs {
        struct netns_ifaddrs *ifa_next;

        /* Can - but shouldn't be - NULL. */
        char *ifa_name;

        /* This field is not present struct ifaddrs. */
        int ifa_ifindex;

        unsigned ifa_flags;

        /* This field is not present struct ifaddrs. */
        int ifa_mtu;

        /* This field is not present struct ifaddrs. */
        int ifa_prefixlen;

        struct sockaddr *ifa_addr;
        struct sockaddr *ifa_netmask;
        union {
                struct sockaddr *ifu_broadaddr;
                struct sockaddr *ifu_dstaddr;
        } ifa_ifu;

        /* If you don't know what this is for don't touch it. */
        void *ifa_data;
};

which is a superset of struct ifaddrs. It contains additional
information such as the mtu, ifindex of the interface and the prefix
length of the address.
Note that the field ordering is different. So don't get any ideas of
using memcpy() to copy from an old struct ifaddrs into a struct
netns_ifaddrs.

int netns_getifaddrs(struct netns_ifaddrs **ifap, __s32 netns_id, bool *netnsid_aware)

takes a network namespace identifier as argument which identifies the
target network namespace.
If successfull, i.e. netns_getifaddrs() returns 0, callers should check
the bool *netnsid_aware return argument. If it is true then
RTM_GET{ADDR,LINK} requests are fully netnsid aware. If it is false then
they are not and the information returned in struct netns_ifaddrs does
*not* contain correct information about the target network namespace
identified by netnsid.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/include/ifaddrs.c [deleted file]
src/include/ifaddrs.h [deleted file]
src/include/netns_ifaddrs.c [new file with mode: 0644]
src/include/netns_ifaddrs.h [new file with mode: 0644]
src/lxc/Makefile.am
src/lxc/macro.h
src/lxc/network.c
src/lxc/nl.c
src/lxc/nl.h