From f6cc1de1a989130fdc61d148024f76865a141d4c Mon Sep 17 00:00:00 2001 From: Jamal Hadi Salim Date: Tue, 15 Dec 2009 10:14:27 +0100 Subject: [PATCH] Introduce per netdev priv structure Some devices like veth or vlans have a bit of extra details that are specific to them. Example veth.pair and vlan.vlanid. Separate them from the common so we can update cleanly in the future. Signed-off-by: Jamal Hadi Salim Acked-by: Daniel Lezcano Signed-off-by: Daniel Lezcano --- src/lxc/conf.c | 8 ++++---- src/lxc/conf.h | 9 ++++++--- src/lxc/confile.c | 8 ++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 3550f3866..dce57b577 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -834,8 +834,8 @@ static int instanciate_veth(struct lxc_netdev *netdev) char veth1buf[IFNAMSIZ], *veth1; char veth2[IFNAMSIZ]; - if (netdev->pair) - veth1 = netdev->pair; + if (netdev->priv.pair) + veth1 = netdev->priv.pair; else { snprintf(veth1buf, sizeof(veth1buf), "vethXXXXXX"); mktemp(veth1buf); @@ -939,9 +939,9 @@ static int instanciate_vlan(struct lxc_netdev *netdev) return -1; } - snprintf(peer, sizeof(peer), "vlan%d",netdev->vlan_attr.vid); + snprintf(peer, sizeof(peer), "vlan%d",netdev->priv.vlan_attr.vid); - if (lxc_vlan_create(netdev->link, peer, netdev->vlan_attr.vid)) { + if (lxc_vlan_create(netdev->link, peer, netdev->priv.vlan_attr.vid)) { ERROR("failed to create vlan interface '%s' on '%s'", peer, netdev->link); return -1; diff --git a/src/lxc/conf.h b/src/lxc/conf.h index 3f9aac0b4..8e01d921f 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -78,11 +78,15 @@ struct ifla_vlan { ushort pad; }; +union netdev_p { + char *pair; + struct ifla_vlan vlan_attr; +}; + /* * Defines a structure to configure a network device * @link : lxc.network.link, name of bridge or host iface to attach if any * @name : lxc.network.name, name of iface on the container side - * @pair : lxc.network.pair, name of host-side iface in case of veth etc * @flags : flag of the network device (IFF_UP, ... ) * @ipv4 : a list of ipv4 addresses to be set on the network device * @ipv6 : a list of ipv6 addresses to be set on the network device @@ -93,10 +97,9 @@ struct lxc_netdev { int ifindex; char *link; char *name; - char *pair; char *hwaddr; char *mtu; - struct ifla_vlan vlan_attr; + union netdev_p priv; struct lxc_list ipv4; struct lxc_list ipv6; }; diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 386af368b..3593b9a88 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -76,10 +76,10 @@ static struct config config[] = { { "lxc.network.flags", config_network_flags }, { "lxc.network.link", config_network_link }, { "lxc.network.name", config_network_name }, - { "lxc.network.pair", config_network_pair }, + { "lxc.network.veth.pair", config_network_pair }, { "lxc.network.hwaddr", config_network_hwaddr }, { "lxc.network.mtu", config_network_mtu }, - { "lxc.network.vlanid", config_network_vlanid }, + { "lxc.network.vlan.id", config_network_vlanid }, { "lxc.network.ipv4", config_network_ipv4 }, { "lxc.network.ipv6", config_network_ipv6 }, }; @@ -237,7 +237,7 @@ static int config_network_pair(const char *key, char *value, if (!netdev) return -1; - return network_ifname(&netdev->pair, value); + return network_ifname(&netdev->priv.pair, value); } static int config_network_hwaddr(const char *key, char *value, @@ -267,7 +267,7 @@ static int config_network_vlanid(const char *key, char *value, if (!netdev) return -1; - if (get_u16(&netdev->vlan_attr.vid, value, 0)) + if (get_u16(&netdev->priv.vlan_attr.vid, value, 0)) return -1; return 0;