]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
network: port ipv4 routes to new list type
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 27 Aug 2021 08:30:55 +0000 (10:30 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 27 Aug 2021 08:30:55 +0000 (10:30 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile.c
src/lxc/confile_utils.c
src/lxc/network.c
src/lxc/network.h

index 482d91987c91110d19d636d41e8ed9ba3ee1b18c..4ea679114defb75eb90f65b91e900bfa09c54011 100644 (file)
@@ -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" : "");
        }
 
index 4fca889c8d2513e9cf4066c7b0bd5abfedd41c27..ac05a8e167097cb10ac55e7fdf0200dc26549035 100644 (file)
@@ -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) {
index 1f120fdda2e90222e0571913fb097021119f10ec..71f5cdcbdcfebdb230df2486f7560f8c4b9900fc 100644 (file)
@@ -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;
        }
index 5532618c0e4b16dee424e3d3087edc8a14b228d1..f8cec79fcddeeebae0e199969c3158843c63cf61 100644 (file)
@@ -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;