From 0b1fe966e5c8ad8ce7f4f158837ad5616c34e408 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 26 Feb 2021 12:36:09 +0100 Subject: [PATCH] network: make callback naming consistent and understandable Signed-off-by: Christian Brauner --- src/lxc/network.c | 112 +++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 55 deletions(-) diff --git a/src/lxc/network.c b/src/lxc/network.c index d6b504107..594e8403e 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -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) @@ -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; @@ -455,7 +457,7 @@ out_delete: 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; @@ -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; @@ -679,7 +681,7 @@ on_error: 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; @@ -753,7 +755,7 @@ on_error: 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; @@ -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[] = { @@ -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]; @@ -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[] = { @@ -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[] = { @@ -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[] = { @@ -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[] = { @@ -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[] = { @@ -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[] = { @@ -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) @@ -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"); } @@ -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) -- 2.47.3