Skip to content

Commit

Permalink
network: make callback naming consistent and understandable
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 26, 2021
1 parent 80f2eda commit 0b1fe96
Showing 1 changed file with 57 additions and 55 deletions.
112 changes: 57 additions & 55 deletions src/lxc/network.c
Expand Up @@ -46,8 +46,10 @@

lxc_log_define(network, lxc);

typedef int (*instantiate_cb)(struct lxc_handler *, struct lxc_netdev *);
typedef int (*instantiate_ns_cb)(struct lxc_netdev *);
typedef int (*netdev_configure_server_cb)(struct lxc_handler *, struct lxc_netdev *);
typedef int (*netdev_configure_container_cb)(struct lxc_netdev *);
typedef int (*netdev_shutdown_server_cb)(struct lxc_handler *, struct lxc_netdev *);

static const char loop_device[] = "lo";

static int lxc_ip_route_dest(__u16 nlmsg_type, int family, int ifindex, void *dest, unsigned int netmask)
Expand Down Expand Up @@ -240,7 +242,7 @@ static int lxc_is_ip_forwarding_enabled(const char *ifname, int family)
return lxc_read_file_expect(path, buf, 1, "1");
}

static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_configure_server_veth(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
int err;
unsigned int mtu = 1500;
Expand Down Expand Up @@ -455,7 +457,7 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
return -1;
}

static int instantiate_macvlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_configure_server_macvlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
char peer[IFNAMSIZ];
int err;
Expand Down Expand Up @@ -605,7 +607,7 @@ static int lxc_ipvlan_create(const char *parent, const char *name, int mode, int
return netlink_transaction(nlh_ptr, nlmsg, answer);
}

static int instantiate_ipvlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_configure_server_ipvlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
char peer[IFNAMSIZ];
int err;
Expand Down Expand Up @@ -679,7 +681,7 @@ static int instantiate_ipvlan(struct lxc_handler *handler, struct lxc_netdev *ne
return -1;
}

static int instantiate_vlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_configure_server_vlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
char peer[IFNAMSIZ];
int err;
Expand Down Expand Up @@ -753,7 +755,7 @@ static int instantiate_vlan(struct lxc_handler *handler, struct lxc_netdev *netd
return -1;
}

static int instantiate_phys(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_configure_server_phys(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
int err, mtu_orig = 0;

Expand Down Expand Up @@ -823,7 +825,7 @@ static int instantiate_phys(struct lxc_handler *handler, struct lxc_netdev *netd
return 0;
}

static int instantiate_empty(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_configure_server_empty(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
int ret;
char *argv[] = {
Expand All @@ -843,23 +845,23 @@ static int instantiate_empty(struct lxc_handler *handler, struct lxc_netdev *net
return 0;
}

static int instantiate_none(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_configure_server_none(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
netdev->ifindex = 0;
return 0;
}

static instantiate_cb netdev_conf[LXC_NET_MAXCONFTYPE + 1] = {
[LXC_NET_VETH] = instantiate_veth,
[LXC_NET_MACVLAN] = instantiate_macvlan,
[LXC_NET_IPVLAN] = instantiate_ipvlan,
[LXC_NET_VLAN] = instantiate_vlan,
[LXC_NET_PHYS] = instantiate_phys,
[LXC_NET_EMPTY] = instantiate_empty,
[LXC_NET_NONE] = instantiate_none,
static netdev_configure_server_cb netdev_configure_server[LXC_NET_MAXCONFTYPE + 1] = {
[LXC_NET_VETH] = netdev_configure_server_veth,
[LXC_NET_MACVLAN] = netdev_configure_server_macvlan,
[LXC_NET_IPVLAN] = netdev_configure_server_ipvlan,
[LXC_NET_VLAN] = netdev_configure_server_vlan,
[LXC_NET_PHYS] = netdev_configure_server_phys,
[LXC_NET_EMPTY] = netdev_configure_server_empty,
[LXC_NET_NONE] = netdev_configure_server_none,
};

static int __instantiate_ns_common(struct lxc_netdev *netdev)
static int __netdev_configure_container_common(struct lxc_netdev *netdev)
{
char current_ifname[IFNAMSIZ];

Expand Down Expand Up @@ -901,53 +903,53 @@ static int __instantiate_ns_common(struct lxc_netdev *netdev)
return 0;
}

static int instantiate_ns_veth(struct lxc_netdev *netdev)
static int netdev_configure_container_veth(struct lxc_netdev *netdev)
{

return __instantiate_ns_common(netdev);
return __netdev_configure_container_common(netdev);
}

static int instantiate_ns_macvlan(struct lxc_netdev *netdev)
static int netdev_configure_container_macvlan(struct lxc_netdev *netdev)
{
return __instantiate_ns_common(netdev);
return __netdev_configure_container_common(netdev);
}

static int instantiate_ns_ipvlan(struct lxc_netdev *netdev)
static int netdev_configure_container_ipvlan(struct lxc_netdev *netdev)
{
return __instantiate_ns_common(netdev);
return __netdev_configure_container_common(netdev);
}

static int instantiate_ns_vlan(struct lxc_netdev *netdev)
static int netdev_configure_container_vlan(struct lxc_netdev *netdev)
{
return __instantiate_ns_common(netdev);
return __netdev_configure_container_common(netdev);
}

static int instantiate_ns_phys(struct lxc_netdev *netdev)
static int netdev_configure_container_phys(struct lxc_netdev *netdev)
{
return __instantiate_ns_common(netdev);
return __netdev_configure_container_common(netdev);
}

static int instantiate_ns_empty(struct lxc_netdev *netdev)
static int netdev_configure_container_empty(struct lxc_netdev *netdev)
{
return 0;
}

static int instantiate_ns_none(struct lxc_netdev *netdev)
static int netdev_configure_container_none(struct lxc_netdev *netdev)
{
return 0;
}

static instantiate_ns_cb netdev_ns_conf[LXC_NET_MAXCONFTYPE + 1] = {
[LXC_NET_VETH] = instantiate_ns_veth,
[LXC_NET_MACVLAN] = instantiate_ns_macvlan,
[LXC_NET_IPVLAN] = instantiate_ns_ipvlan,
[LXC_NET_VLAN] = instantiate_ns_vlan,
[LXC_NET_PHYS] = instantiate_ns_phys,
[LXC_NET_EMPTY] = instantiate_ns_empty,
[LXC_NET_NONE] = instantiate_ns_none,
static netdev_configure_container_cb netdev_configure_container[LXC_NET_MAXCONFTYPE + 1] = {
[LXC_NET_VETH] = netdev_configure_container_veth,
[LXC_NET_MACVLAN] = netdev_configure_container_macvlan,
[LXC_NET_IPVLAN] = netdev_configure_container_ipvlan,
[LXC_NET_VLAN] = netdev_configure_container_vlan,
[LXC_NET_PHYS] = netdev_configure_container_phys,
[LXC_NET_EMPTY] = netdev_configure_container_empty,
[LXC_NET_NONE] = netdev_configure_container_none,
};

static int shutdown_veth(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_shutdown_server_veth(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
int ret;
char *argv[] = {
Expand All @@ -974,7 +976,7 @@ static int shutdown_veth(struct lxc_handler *handler, struct lxc_netdev *netdev)
return 0;
}

static int shutdown_macvlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_shutdown_server_macvlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
int ret;
char *argv[] = {
Expand All @@ -994,7 +996,7 @@ static int shutdown_macvlan(struct lxc_handler *handler, struct lxc_netdev *netd
return 0;
}

static int shutdown_ipvlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_shutdown_server_ipvlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
int ret;
char *argv[] = {
Expand All @@ -1014,7 +1016,7 @@ static int shutdown_ipvlan(struct lxc_handler *handler, struct lxc_netdev *netde
return 0;
}

static int shutdown_vlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_shutdown_server_vlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
int ret;
char *argv[] = {
Expand All @@ -1034,7 +1036,7 @@ static int shutdown_vlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
return 0;
}

static int shutdown_phys(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_shutdown_server_phys(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
int ret;
char *argv[] = {
Expand All @@ -1054,7 +1056,7 @@ static int shutdown_phys(struct lxc_handler *handler, struct lxc_netdev *netdev)
return 0;
}

static int shutdown_empty(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_shutdown_server_empty(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
int ret;
char *argv[] = {
Expand All @@ -1073,19 +1075,19 @@ static int shutdown_empty(struct lxc_handler *handler, struct lxc_netdev *netdev
return 0;
}

static int shutdown_none(struct lxc_handler *handler, struct lxc_netdev *netdev)
static int netdev_shutdown_server_none(struct lxc_handler *handler, struct lxc_netdev *netdev)
{
return 0;
}

static instantiate_cb netdev_deconf[LXC_NET_MAXCONFTYPE + 1] = {
[LXC_NET_VETH] = shutdown_veth,
[LXC_NET_MACVLAN] = shutdown_macvlan,
[LXC_NET_IPVLAN] = shutdown_ipvlan,
[LXC_NET_VLAN] = shutdown_vlan,
[LXC_NET_PHYS] = shutdown_phys,
[LXC_NET_EMPTY] = shutdown_empty,
[LXC_NET_NONE] = shutdown_none,
static netdev_shutdown_server_cb netdev_deconf[LXC_NET_MAXCONFTYPE + 1] = {
[LXC_NET_VETH] = netdev_shutdown_server_veth,
[LXC_NET_MACVLAN] = netdev_shutdown_server_macvlan,
[LXC_NET_IPVLAN] = netdev_shutdown_server_ipvlan,
[LXC_NET_VLAN] = netdev_shutdown_server_vlan,
[LXC_NET_PHYS] = netdev_shutdown_server_phys,
[LXC_NET_EMPTY] = netdev_shutdown_server_empty,
[LXC_NET_NONE] = netdev_shutdown_server_none,
};

static int lxc_netdev_move_by_index_fd(int ifindex, int fd, const char *ifname)
Expand Down Expand Up @@ -3063,7 +3065,7 @@ static int lxc_create_network_priv(struct lxc_handler *handler)
return log_error_errno(-1, errno, "Failed to setup l2proxy");
}

if (netdev_conf[netdev->type](handler, netdev))
if (netdev_configure_server[netdev->type](handler, netdev))
return log_error_errno(-1, errno, "Failed to create network device");
}

Expand Down Expand Up @@ -3527,7 +3529,7 @@ int lxc_setup_network_in_child_namespaces(const struct lxc_conf *conf,
struct lxc_netdev *netdev = iterator->elem;
int ret;

ret = netdev_ns_conf[netdev->type](netdev);
ret = netdev_configure_container[netdev->type](netdev);
if (!ret)
ret = lxc_network_setup_in_child_namespaces_common(netdev);
if (ret)
Expand Down

0 comments on commit 0b1fe96

Please sign in to comment.