network: port ipv6 routes to new list type

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner 2021-08-27 10:36:48 +02:00
parent 303707f67b
commit 6bf0c06bdd
No known key found for this signature in database
GPG Key ID: 8EB056D53EECB12D
4 changed files with 21 additions and 38 deletions

View File

@ -413,7 +413,7 @@ static int set_config_net_type(const char *key, const char *value,
if (strequal(value, "veth")) {
netdev->type = LXC_NET_VETH;
INIT_LIST_HEAD(&netdev->priv.veth_attr.ipv4_routes);
lxc_list_init(&netdev->priv.veth_attr.ipv6_routes);
INIT_LIST_HEAD(&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))
lxc_veth_mode_to_flag(&netdev->priv.veth_attr.mode, "bridge");
@ -1034,7 +1034,6 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value,
{
__do_free char *valdup = NULL;
__do_free struct lxc_inet6dev *inet6dev = NULL;
__do_free struct lxc_list *list = NULL;
int ret;
char *netmask, *slash;
struct lxc_netdev *netdev = data;
@ -1052,10 +1051,6 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value,
if (!inet6dev)
return ret_errno(ENOMEM);
list = lxc_list_new();
if (!list)
return ret_errno(ENOMEM);
valdup = strdup(value);
if (!valdup)
return ret_errno(ENOMEM);
@ -1079,10 +1074,8 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value,
if (!ret || ret < 0)
return ret_errno(EINVAL);
list->elem = inet6dev;
lxc_list_add_tail(&netdev->priv.veth_attr.ipv6_routes, list);
list_add_tail(&inet6dev->head, &netdev->priv.veth_attr.ipv6_routes);
move_ptr(inet6dev);
move_ptr(list);
return 0;
}
@ -5775,7 +5768,7 @@ static int clr_config_net_veth_ipv6_route(const char *key,
struct lxc_conf *lxc_conf, void *data)
{
struct lxc_netdev *netdev = data;
struct lxc_list *cur, *next;
struct lxc_inet6dev *inet6dev, *ninet6dev;
if (!netdev)
return ret_errno(EINVAL);
@ -5783,10 +5776,9 @@ static int clr_config_net_veth_ipv6_route(const char *key,
if (netdev->type != LXC_NET_VETH)
return 0;
lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv6_routes, next) {
lxc_list_del(cur);
free(cur->elem);
free(cur);
list_for_each_entry_safe(inet6dev, ninet6dev, &netdev->priv.veth_attr.ipv6_routes, head) {
list_del(&inet6dev->head);
free(inet6dev);
}
return 0;
@ -6402,7 +6394,7 @@ static int get_config_net_veth_ipv6_route(const char *key, char *retv, int inlen
int len;
size_t listlen;
char buf[INET6_ADDRSTRLEN];
struct lxc_list *it;
struct lxc_inet6dev *inet6dev;
int fulllen = 0;
struct lxc_netdev *netdev = data;
@ -6417,13 +6409,11 @@ static int get_config_net_veth_ipv6_route(const char *key, char *retv, int inlen
else
memset(retv, 0, inlen);
listlen = lxc_list_len(&netdev->priv.veth_attr.ipv6_routes);
lxc_list_for_each(it, &netdev->priv.veth_attr.ipv6_routes) {
struct lxc_inet6dev *i = it->elem;
if (!inet_ntop(AF_INET6, &i->addr, buf, sizeof(buf)))
listlen = list_len(&netdev->priv.veth_attr.ipv6_routes);
list_for_each_entry(inet6dev, &netdev->priv.veth_attr.ipv6_routes, head) {
if (!inet_ntop(AF_INET6, &inet6dev->addr, buf, sizeof(buf)))
return -errno;
strprint(retv, inlen, "%s/%u%s", buf, i->prefix,
strprint(retv, inlen, "%s/%u%s", buf, inet6dev->prefix,
(listlen-- > 1) ? "\n" : "");
}

View File

@ -377,8 +377,7 @@ void lxc_log_configured_netdevs(const struct lxc_conf *conf)
TRACE("ipv4 veth route: %s/%u", bufinet4, inet4dev->prefix);
}
lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv6_routes, next) {
inet6dev = cur->elem;
list_for_each_entry(inet6dev, &netdev->priv.veth_attr.ipv6_routes, head) {
if (!inet_ntop(AF_INET6, &inet6dev->addr, bufinet6, sizeof(bufinet6))) {
ERROR("Invalid ipv6 veth route");
return;
@ -427,10 +426,9 @@ void lxc_clear_netdev(struct lxc_netdev *netdev)
free(inetdev);
}
lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.ipv6_routes, next) {
lxc_list_del(cur);
free(cur->elem);
free(cur);
list_for_each_entry_safe(inet6dev, ninet6dev, &netdev->priv.veth_attr.ipv6_routes, head) {
list_del(&inet6dev->head);
free(inet6dev);
}
lxc_list_for_each_safe(cur, &netdev->priv.veth_attr.vlan_tagged_ids, next) {

View File

@ -199,14 +199,13 @@ static int setup_ipv4_routes(struct lxc_netdev *netdev)
return 0;
}
static int lxc_setup_ipv6_routes(struct lxc_list *ip, int ifindex)
static int setup_ipv6_routes(struct lxc_netdev *netdev)
{
struct lxc_list *iterator;
int err;
struct lxc_inet6dev *inet6dev;
int ifindex = netdev->priv.veth_attr.ifindex;
lxc_list_for_each(iterator, ip) {
struct lxc_inet6dev *inet6dev = iterator->elem;
list_for_each_entry(inet6dev, &netdev->priv.veth_attr.ipv6_routes, head) {
err = lxc_ipv6_dest_add(ifindex, &inet6dev->addr, inet6dev->prefix);
if (err)
return log_error_errno(-1, -err, "Failed to setup ipv6 route for network device with ifindex %d", ifindex);
@ -752,7 +751,7 @@ static int netdev_configure_server_veth(struct lxc_handler *handler, struct lxc_
}
/* setup ipv6 routes on the host interface */
if (lxc_setup_ipv6_routes(&netdev->priv.veth_attr.ipv6_routes, netdev->priv.veth_attr.ifindex)) {
if (setup_ipv6_routes(netdev)) {
ERROR("Failed to setup ipv6 routes for network device \"%s\"", veth1);
goto out_delete;
}

View File

@ -57,10 +57,6 @@ struct lxc_inet6dev {
struct list_head head;
};
struct lxc_route6 {
struct in6_addr addr;
};
/* Contains information about the host side veth device.
* @pair : Name of the host side veth device.
* If the user requested that the host veth device be created with a
@ -77,7 +73,7 @@ struct ifla_veth {
char veth1[IFNAMSIZ];
int ifindex;
struct list_head ipv4_routes;
struct lxc_list ipv6_routes;
struct list_head ipv6_routes;
int mode; /* bridge, router */
short vlan_id;
bool vlan_id_set;