From: Christian Brauner Date: Fri, 27 Aug 2021 08:30:55 +0000 (+0200) Subject: network: port ipv4 routes to new list type X-Git-Tag: lxc-5.0.0~99^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=303707f67b01bdce3077add6c3ce53fa4fc284b9;p=thirdparty%2Flxc.git network: port ipv4 routes to new list type Signed-off-by: Christian Brauner --- diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 482d91987..4ea679114 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -412,7 +412,7 @@ static int set_config_net_type(const char *key, const char *value, if (strequal(value, "veth")) { netdev->type = LXC_NET_VETH; - lxc_list_init(&netdev->priv.veth_attr.ipv4_routes); + INIT_LIST_HEAD(&netdev->priv.veth_attr.ipv4_routes); lxc_list_init(&netdev->priv.veth_attr.ipv6_routes); lxc_list_init(&netdev->priv.veth_attr.vlan_tagged_ids); if (!lxc_veth_flag_to_mode(netdev->priv.veth_attr.mode)) @@ -900,7 +900,6 @@ static int set_config_net_veth_ipv4_route(const char *key, const char *value, { __do_free char *valdup = NULL; __do_free struct lxc_inetdev *inetdev = NULL; - __do_free struct lxc_list *list = NULL; int ret; char *netmask, *slash; struct lxc_netdev *netdev = data; @@ -918,12 +917,6 @@ static int set_config_net_veth_ipv4_route(const char *key, const char *value, if (!inetdev) return ret_errno(ENOMEM); - list = lxc_list_new(); - if (!list) - return ret_errno(ENOMEM); - - list->elem = inetdev; - valdup = strdup(value); if (!valdup) return ret_errno(ENOMEM); @@ -947,9 +940,8 @@ static int set_config_net_veth_ipv4_route(const char *key, const char *value, if (!ret || ret < 0) return ret_errno(EINVAL); - lxc_list_add_tail(&netdev->priv.veth_attr.ipv4_routes, list); + list_add_tail(&inetdev->head, &netdev->priv.veth_attr.ipv4_routes); move_ptr(inetdev); - move_ptr(list); return 0; } @@ -5733,7 +5725,7 @@ static int clr_config_net_veth_ipv4_route(const char *key, struct lxc_conf *lxc_conf, void *data) { struct lxc_netdev *netdev = data; - struct lxc_list *cur, *next; + struct lxc_inetdev *inetdev, *ninetdev; if (!netdev) return ret_errno(EINVAL); @@ -5741,10 +5733,9 @@ static int clr_config_net_veth_ipv4_route(const char *key, if (netdev->type != LXC_NET_VETH) return 0; - lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv4_routes, next) { - lxc_list_del(cur); - free(cur->elem); - free(cur); + list_for_each_entry_safe(inetdev, ninetdev, &netdev->priv.veth_attr.ipv4_routes, head) { + list_del(&inetdev->head); + free(inetdev); } return 0; @@ -6321,7 +6312,7 @@ static int get_config_net_veth_ipv4_route(const char *key, char *retv, int inlen int len; size_t listlen; char buf[INET_ADDRSTRLEN]; - struct lxc_list *it; + struct lxc_inetdev *inetdev; int fulllen = 0; struct lxc_netdev *netdev = data; @@ -6336,13 +6327,11 @@ static int get_config_net_veth_ipv4_route(const char *key, char *retv, int inlen else memset(retv, 0, inlen); - listlen = lxc_list_len(&netdev->priv.veth_attr.ipv4_routes); - - lxc_list_for_each(it, &netdev->priv.veth_attr.ipv4_routes) { - struct lxc_inetdev *i = it->elem; - if (!inet_ntop(AF_INET, &i->addr, buf, sizeof(buf))) + listlen = list_len(&netdev->priv.veth_attr.ipv4_routes); + list_for_each_entry(inetdev, &netdev->priv.veth_attr.ipv4_routes, head) { + if (!inet_ntop(AF_INET, &inetdev->addr, buf, sizeof(buf))) return -errno; - strprint(retv, inlen, "%s/%u%s", buf, i->prefix, + strprint(retv, inlen, "%s/%u%s", buf, inetdev->prefix, (listlen-- > 1) ? "\n" : ""); } diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c index 4fca889c8..ac05a8e16 100644 --- a/src/lxc/confile_utils.c +++ b/src/lxc/confile_utils.c @@ -368,8 +368,7 @@ void lxc_log_configured_netdevs(const struct lxc_conf *conf) } if (netdev->type == LXC_NET_VETH) { - lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv4_routes, next) { - inet4dev = cur->elem; + list_for_each_entry(inet4dev, &netdev->priv.veth_attr.ipv4_routes, head) { if (!inet_ntop(AF_INET, &inet4dev->addr, bufinet4, sizeof(bufinet4))) { ERROR("Invalid ipv4 veth route"); return; @@ -423,10 +422,9 @@ void lxc_clear_netdev(struct lxc_netdev *netdev) } if (netdev->type == LXC_NET_VETH) { - lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv4_routes, next) { - lxc_list_del(cur); - free(cur->elem); - free(cur); + list_for_each_entry_safe(inetdev, ninetdev, &netdev->priv.veth_attr.ipv4_routes, head) { + list_del(&inetdev->head); + free(inetdev); } lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv6_routes, next) { diff --git a/src/lxc/network.c b/src/lxc/network.c index 1f120fdda..71f5cdcbd 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -184,14 +184,13 @@ static int lxc_ipv6_dest_del(int ifindex, struct in6_addr *dest, unsigned int ne return lxc_ip_route_dest(RTM_DELROUTE, AF_INET6, ifindex, dest, netmask); } -static int lxc_setup_ipv4_routes(struct lxc_list *ip, int ifindex) +static int setup_ipv4_routes(struct lxc_netdev *netdev) { - struct lxc_list *iterator; + int ifindex = netdev->priv.veth_attr.ifindex; + struct lxc_inetdev *inetdev; int err; - lxc_list_for_each(iterator, ip) { - struct lxc_inetdev *inetdev = iterator->elem; - + list_for_each_entry(inetdev, &netdev->priv.veth_attr.ipv4_routes, head) { err = lxc_ipv4_dest_add(ifindex, &inetdev->addr, inetdev->prefix); if (err) return log_error_errno(-1, -err, "Failed to setup ipv4 route for network device with ifindex %d", ifindex); @@ -747,7 +746,7 @@ static int netdev_configure_server_veth(struct lxc_handler *handler, struct lxc_ } /* setup ipv4 routes on the host interface */ - if (lxc_setup_ipv4_routes(&netdev->priv.veth_attr.ipv4_routes, netdev->priv.veth_attr.ifindex)) { + if (setup_ipv4_routes(netdev)) { ERROR("Failed to setup ipv4 routes for network device \"%s\"", veth1); goto out_delete; } diff --git a/src/lxc/network.h b/src/lxc/network.h index 5532618c0..f8cec79fc 100644 --- a/src/lxc/network.h +++ b/src/lxc/network.h @@ -42,10 +42,6 @@ struct lxc_inetdev { struct list_head head; }; -struct lxc_route { - struct in_addr addr; -}; - /* * Defines the structure to configure an ipv6 address * @flags : set the address up @@ -80,7 +76,7 @@ struct ifla_veth { char pair[IFNAMSIZ]; char veth1[IFNAMSIZ]; int ifindex; - struct lxc_list ipv4_routes; + struct list_head ipv4_routes; struct lxc_list ipv6_routes; int mode; /* bridge, router */ short vlan_id;