mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-26 23:37:22 +00:00
network: port ipv4 to new list type
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
parent
19202d882b
commit
2ec31bbde7
@ -790,7 +790,6 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
|
||||
{
|
||||
__do_free char *addr = NULL;
|
||||
__do_free struct lxc_inetdev *inetdev = NULL;
|
||||
__do_free struct lxc_list *list = NULL;
|
||||
int ret;
|
||||
struct lxc_netdev *netdev = data;
|
||||
char *cursor, *slash;
|
||||
@ -806,10 +805,6 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
|
||||
if (!inetdev)
|
||||
return ret_errno(ENOMEM);
|
||||
|
||||
list = lxc_list_new();
|
||||
if (!list)
|
||||
return ret_errno(ENOMEM);
|
||||
|
||||
addr = strdup(value);
|
||||
if (!addr)
|
||||
return ret_errno(ENOMEM);
|
||||
@ -856,10 +851,8 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
|
||||
inetdev->bcast.s_addr |= htonl(INADDR_BROADCAST >> shift);
|
||||
}
|
||||
|
||||
list->elem = inetdev;
|
||||
lxc_list_add_tail(&netdev->ipv4, list);
|
||||
list_add_tail(&inetdev->head, &netdev->ipv4_list);
|
||||
move_ptr(inetdev);
|
||||
move_ptr(list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -5730,15 +5723,14 @@ static int clr_config_net_ipv4_address(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);
|
||||
|
||||
lxc_list_for_each_safe(cur, &netdev->ipv4, next) {
|
||||
lxc_list_del(cur);
|
||||
free(cur->elem);
|
||||
free(cur);
|
||||
list_for_each_entry_safe(inetdev, ninetdev, &netdev->ipv4_list, head) {
|
||||
list_del(&inetdev->head);
|
||||
free(inetdev);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -6304,12 +6296,12 @@ static int get_config_net_ipv4_gateway(const char *key, char *retv, int inlen,
|
||||
static int get_config_net_ipv4_address(const char *key, char *retv, int inlen,
|
||||
struct lxc_conf *c, void *data)
|
||||
{
|
||||
int fulllen = 0;
|
||||
struct lxc_netdev *netdev = data;
|
||||
int len;
|
||||
size_t listlen;
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
struct lxc_list *it;
|
||||
int fulllen = 0;
|
||||
struct lxc_netdev *netdev = data;
|
||||
struct lxc_inetdev *inetdev;
|
||||
|
||||
if (!netdev)
|
||||
return ret_errno(EINVAL);
|
||||
@ -6319,13 +6311,12 @@ static int get_config_net_ipv4_address(const char *key, char *retv, int inlen,
|
||||
else
|
||||
memset(retv, 0, inlen);
|
||||
|
||||
listlen = lxc_list_len(&netdev->ipv4);
|
||||
listlen = list_len(&netdev->ipv4_list);
|
||||
|
||||
lxc_list_for_each(it, &netdev->ipv4) {
|
||||
struct lxc_inetdev *i = it->elem;
|
||||
if (!inet_ntop(AF_INET, &i->addr, buf, sizeof(buf)))
|
||||
list_for_each_entry(inetdev, &netdev->ipv4_list, 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" : "");
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ static struct lxc_netdev *lxc_network_add(struct list_head *head, int idx, bool
|
||||
if (!netdev)
|
||||
return ret_set_errno(NULL, ENOMEM);
|
||||
|
||||
lxc_list_init(&netdev->ipv4);
|
||||
INIT_LIST_HEAD(&netdev->ipv4_list);
|
||||
lxc_list_init(&netdev->ipv6);
|
||||
|
||||
/* give network a unique index */
|
||||
@ -343,8 +343,7 @@ void lxc_log_configured_netdevs(const struct lxc_conf *conf)
|
||||
TRACE("ipv4 gateway: %s", bufinet4);
|
||||
}
|
||||
|
||||
lxc_list_for_each_safe(cur, &netdev->ipv4, next) {
|
||||
inet4dev = cur->elem;
|
||||
list_for_each_entry(inet4dev, &netdev->ipv4_list, head) {
|
||||
inet_ntop(AF_INET, &inet4dev->addr, bufinet4,
|
||||
sizeof(bufinet4));
|
||||
TRACE("ipv4 addr: %s", bufinet4);
|
||||
@ -398,6 +397,7 @@ void lxc_clear_netdev(struct lxc_netdev *netdev)
|
||||
{
|
||||
struct lxc_list *cur, *next;
|
||||
struct list_head head;
|
||||
struct lxc_inetdev *inetdev, *ninetdev;
|
||||
ssize_t idx;
|
||||
|
||||
if (!netdev)
|
||||
@ -411,10 +411,9 @@ void lxc_clear_netdev(struct lxc_netdev *netdev)
|
||||
free_disarm(netdev->mtu);
|
||||
|
||||
free_disarm(netdev->ipv4_gateway);
|
||||
lxc_list_for_each_safe(cur, &netdev->ipv4, next) {
|
||||
lxc_list_del(cur);
|
||||
free(cur->elem);
|
||||
free(cur);
|
||||
list_for_each_entry_safe(inetdev, ninetdev, &netdev->ipv4_list, head) {
|
||||
list_del(&inetdev->head);
|
||||
free(inetdev);
|
||||
}
|
||||
|
||||
free_disarm(netdev->ipv6_gateway);
|
||||
@ -446,7 +445,7 @@ void lxc_clear_netdev(struct lxc_netdev *netdev)
|
||||
head = netdev->head;
|
||||
memset(netdev, 0, sizeof(struct lxc_netdev));
|
||||
netdev->head = head;
|
||||
lxc_list_init(&netdev->ipv4);
|
||||
INIT_LIST_HEAD(&netdev->ipv4_list);
|
||||
lxc_list_init(&netdev->ipv6);
|
||||
netdev->type = -1;
|
||||
netdev->idx = idx;
|
||||
|
@ -216,16 +216,18 @@ static int lxc_setup_ipv6_routes(struct lxc_list *ip, int ifindex)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int setup_ipv4_addr_routes(struct lxc_list *ip, int ifindex)
|
||||
static int setup_ipv4_addr_routes(struct lxc_netdev *netdev)
|
||||
{
|
||||
struct lxc_list *iterator;
|
||||
int err;
|
||||
struct lxc_inetdev *inetdev;
|
||||
int ifindex;
|
||||
|
||||
lxc_list_for_each(iterator, ip) {
|
||||
struct lxc_inetdev *inetdev = iterator->elem;
|
||||
if (netdev->type != LXC_NET_VETH)
|
||||
return ret_errno(EINVAL);
|
||||
|
||||
ifindex = netdev->priv.veth_attr.ifindex;
|
||||
list_for_each_entry(inetdev, &netdev->ipv4_list, head) {
|
||||
err = lxc_ipv4_dest_add(ifindex, &inetdev->addr, 32);
|
||||
|
||||
if (err)
|
||||
return log_error_errno(-1, err, "Failed to setup ipv4 address route for network device with eifindex %d", ifindex);
|
||||
}
|
||||
@ -817,7 +819,7 @@ static int netdev_configure_server_veth(struct lxc_handler *handler, struct lxc_
|
||||
}
|
||||
|
||||
/* setup ipv4 address routes on the host interface */
|
||||
err = setup_ipv4_addr_routes(&netdev->ipv4, netdev->priv.veth_attr.ifindex);
|
||||
err = setup_ipv4_addr_routes(netdev);
|
||||
if (err) {
|
||||
SYSERROR("Failed to setup ip address routes for network device \"%s\"", veth1);
|
||||
goto out_delete;
|
||||
@ -3229,7 +3231,7 @@ static int lxc_setup_l2proxy(struct lxc_netdev *netdev) {
|
||||
|
||||
|
||||
/* If IPv4 addresses are specified, then check that sysctl is configured correctly. */
|
||||
if (!lxc_list_empty(&netdev->ipv4)) {
|
||||
if (!list_empty(&netdev->ipv4_list)) {
|
||||
/* Check for net.ipv4.conf.[link].forwarding=1 */
|
||||
if (lxc_is_ip_forwarding_enabled(netdev->link, AF_INET) < 0)
|
||||
return log_error_errno(-1, EINVAL, "Requires sysctl net.ipv4.conf.%s.forwarding=1", netdev->link);
|
||||
@ -3258,8 +3260,7 @@ static int lxc_setup_l2proxy(struct lxc_netdev *netdev) {
|
||||
return log_error_errno(-1, EINVAL, "Failed to retrieve ifindex for \"%s\" routing cleanup", loop_device);
|
||||
}
|
||||
|
||||
lxc_list_for_each_safe(cur, &netdev->ipv4, next) {
|
||||
inet4dev = cur->elem;
|
||||
list_for_each_entry(inet4dev, &netdev->ipv4_list, head) {
|
||||
if (!inet_ntop(AF_INET, &inet4dev->addr, bufinet4, sizeof(bufinet4)))
|
||||
return ret_set_errno(-1, -errno);
|
||||
|
||||
@ -3378,8 +3379,7 @@ static int lxc_delete_l2proxy(struct lxc_netdev *netdev) {
|
||||
}
|
||||
}
|
||||
|
||||
lxc_list_for_each_safe(cur, &netdev->ipv4, next) {
|
||||
inet4dev = cur->elem;
|
||||
list_for_each_entry(inet4dev, &netdev->ipv4_list, head) {
|
||||
if (lxc_delete_ipv4_l2proxy(&inet4dev->addr, netdev->link, lo_ifindex) < 0)
|
||||
errCount++;
|
||||
}
|
||||
@ -3810,16 +3810,15 @@ static int setup_hw_addr(char *hwaddr, const char *ifname)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int setup_ipv4_addr(struct lxc_list *ip, int ifindex)
|
||||
static int setup_ipv4_addr(struct lxc_netdev *netdev)
|
||||
{
|
||||
struct lxc_list *iterator;
|
||||
int ifindex = netdev->ifindex;
|
||||
int err;
|
||||
struct lxc_inetdev *inet4dev;
|
||||
|
||||
lxc_list_for_each(iterator, ip) {
|
||||
struct lxc_inetdev *inetdev = iterator->elem;
|
||||
|
||||
err = lxc_ipv4_addr_add(ifindex, &inetdev->addr,
|
||||
&inetdev->bcast, inetdev->prefix);
|
||||
list_for_each_entry(inet4dev, &netdev->ipv4_list, head) {
|
||||
err = lxc_ipv4_addr_add(ifindex, &inet4dev->addr,
|
||||
&inet4dev->bcast, inet4dev->prefix);
|
||||
if (err)
|
||||
return log_error_errno(-1, -err, "Failed to setup ipv4 address for network device with ifindex %d", ifindex);
|
||||
}
|
||||
@ -3855,7 +3854,7 @@ static int lxc_network_setup_in_child_namespaces_common(struct lxc_netdev *netde
|
||||
return log_error_errno(-1, errno, "Failed to setup hw address for network device \"%s\"", netdev->name);
|
||||
|
||||
/* setup ipv4 addresses on the interface */
|
||||
if (setup_ipv4_addr(&netdev->ipv4, netdev->ifindex))
|
||||
if (setup_ipv4_addr(netdev))
|
||||
return log_error_errno(-1, errno, "Failed to setup ip addresses for network device \"%s\"", netdev->name);
|
||||
|
||||
/* setup ipv6 addresses on the interface */
|
||||
@ -3879,7 +3878,7 @@ static int lxc_network_setup_in_child_namespaces_common(struct lxc_netdev *netde
|
||||
if (!(netdev->flags & IFF_UP))
|
||||
return log_error(-1, "Cannot add ipv4 gateway for network device \"%s\" when not bringing up the interface", netdev->name);
|
||||
|
||||
if (lxc_list_empty(&netdev->ipv4))
|
||||
if (list_empty(&netdev->ipv4_list))
|
||||
return log_error(-1, "Cannot add ipv4 gateway for network device \"%s\" when not assigning an address", netdev->name);
|
||||
|
||||
/* Setup device route if ipv4_gateway_dev is enabled */
|
||||
|
@ -39,6 +39,7 @@ struct lxc_inetdev {
|
||||
struct in_addr addr;
|
||||
struct in_addr bcast;
|
||||
unsigned int prefix;
|
||||
struct list_head head;
|
||||
};
|
||||
|
||||
struct lxc_route {
|
||||
@ -171,7 +172,7 @@ struct lxc_netdev {
|
||||
char *hwaddr;
|
||||
char *mtu;
|
||||
union netdev_p priv;
|
||||
struct lxc_list ipv4;
|
||||
struct list_head ipv4_list;
|
||||
struct lxc_list ipv6;
|
||||
bool ipv4_gateway_auto;
|
||||
bool ipv4_gateway_dev;
|
||||
|
Loading…
Reference in New Issue
Block a user