1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-31 16:21:26 +03:00

networkd: unify handling of stacked netdevs

This commit is contained in:
Tom Gundersen 2014-07-28 12:10:37 +02:00
parent ae06ab1014
commit 6a0a2f860f
4 changed files with 28 additions and 125 deletions

View File

@ -1770,7 +1770,7 @@ static int netdev_join_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata
} }
static int link_enter_join_netdev(Link *link) { static int link_enter_join_netdev(Link *link) {
NetDev *vlan, *macvlan, *vxlan; NetDev *netdev;
Iterator i; Iterator i;
int r; int r;
@ -1784,10 +1784,7 @@ static int link_enter_join_netdev(Link *link) {
if (!link->network->bridge && if (!link->network->bridge &&
!link->network->bond && !link->network->bond &&
!link->network->tunnel && hashmap_isempty(link->network->stacked_netdevs))
hashmap_isempty(link->network->vlans) &&
hashmap_isempty(link->network->macvlans) &&
hashmap_isempty(link->network->vxlans))
return link_joined(link); return link_joined(link);
if (link->network->bond) { if (link->network->bond) {
@ -1836,82 +1833,19 @@ static int link_enter_join_netdev(Link *link) {
link->enslaving ++; link->enslaving ++;
} }
if (link->network->tunnel) { HASHMAP_FOREACH(netdev, link->network->stacked_netdevs, i) {
log_struct_link(LOG_DEBUG, link, log_struct_link(LOG_DEBUG, link,
"MESSAGE=%-*s: enslaving by '%s'", "MESSAGE=%-*s: enslaving by '%s'",
IFNAMSIZ, IFNAMSIZ,
link->ifname, link->network->tunnel->ifname, link->ifname, netdev->ifname, NETDEVIF(netdev), NULL);
NETDEVIF(link->network->tunnel),
NULL);
r = netdev_join(link->network->tunnel, link, &netdev_join_handler); r = netdev_join(netdev, link, &netdev_join_handler);
if (r < 0) { if (r < 0) {
log_struct_link(LOG_WARNING, link, log_struct_link(LOG_WARNING, link,
"MESSAGE=%-*s: could not join netdev '%s': %s", "MESSAGE=%-*s: could not join netdev '%s': %s",
IFNAMSIZ, IFNAMSIZ,
link->ifname, link->network->tunnel->ifname, strerror(-r), link->ifname, netdev->ifname, strerror(-r),
NETDEVIF(link->network->tunnel), NETDEVIF(netdev), NULL);
NULL);
link_enter_failed(link);
return r;
}
link->enslaving ++;
}
HASHMAP_FOREACH(vlan, link->network->vlans, i) {
log_struct_link(LOG_DEBUG, link,
"MESSAGE=%-*s: enslaving by '%s'",
IFNAMSIZ,
link->ifname, vlan->ifname, NETDEVIF(vlan), NULL);
r = netdev_join(vlan, link, &netdev_join_handler);
if (r < 0) {
log_struct_link(LOG_WARNING, link,
"MESSAGE=%-*s: could not join netdev '%s': %s",
IFNAMSIZ,
link->ifname, vlan->ifname, strerror(-r),
NETDEVIF(vlan), NULL);
link_enter_failed(link);
return r;
}
link->enslaving ++;
}
HASHMAP_FOREACH(macvlan, link->network->macvlans, i) {
log_struct_link(LOG_DEBUG, link,
"MESSAGE=%-*s: enslaving by '%s'",
IFNAMSIZ,
link->ifname, macvlan->ifname, NETDEVIF(macvlan), NULL);
r = netdev_join(macvlan, link, &netdev_join_handler);
if (r < 0) {
log_struct_link(LOG_WARNING, link,
"MESSAGE=%-*s: could not join netdev '%s': %s",
IFNAMSIZ,
link->ifname, macvlan->ifname, strerror(-r),
NETDEVIF(macvlan), NULL);
link_enter_failed(link);
return r;
}
link->enslaving ++;
}
HASHMAP_FOREACH(vxlan, link->network->vxlans, i) {
log_struct_link(LOG_DEBUG, link,
"MESSAGE=%*s: enslaving by '%s'",
IFNAMSIZ,
link->ifname, vxlan->ifname, NETDEVIF(vxlan), NULL);
r = netdev_join(vxlan, link, &netdev_join_handler);
if (r < 0) {
log_struct_link(LOG_WARNING, link,
"MESSAGE=%*s: could not join netdev '%s': %s",
IFNAMSIZ,
link->ifname, vxlan->ifname, strerror(-r),
NETDEVIF(vxlan), NULL);
link_enter_failed(link); link_enter_failed(link);
return r; return r;
} }

View File

@ -27,9 +27,10 @@ Match.Architecture, config_parse_net_condition, CONDITION_ARCHI
Network.Description, config_parse_string, 0, offsetof(Network, description) Network.Description, config_parse_string, 0, offsetof(Network, description)
Network.Bridge, config_parse_netdev, 0, offsetof(Network, bridge) Network.Bridge, config_parse_netdev, 0, offsetof(Network, bridge)
Network.Bond, config_parse_netdev, 0, offsetof(Network, bond) Network.Bond, config_parse_netdev, 0, offsetof(Network, bond)
Network.VLAN, config_parse_netdev, 0, offsetof(Network, vlans) Network.VLAN, config_parse_netdev, 0, 0
Network.MACVLAN, config_parse_netdev, 0, offsetof(Network, macvlans) Network.MACVLAN, config_parse_netdev, 0, 0
Network.VXLAN, config_parse_netdev, 0, offsetof(Network, vxlans) Network.VXLAN, config_parse_netdev, 0, 0
Network.Tunnel, config_parse_tunnel, 0, 0
Network.DHCP, config_parse_dhcp, 0, offsetof(Network, dhcp) Network.DHCP, config_parse_dhcp, 0, offsetof(Network, dhcp)
Network.DHCPServer, config_parse_bool, 0, offsetof(Network, dhcp_server) Network.DHCPServer, config_parse_bool, 0, offsetof(Network, dhcp_server)
Network.IPv4LL, config_parse_bool, 0, offsetof(Network, ipv4ll) Network.IPv4LL, config_parse_bool, 0, offsetof(Network, ipv4ll)
@ -38,7 +39,6 @@ Network.Address, config_parse_address, 0,
Network.Gateway, config_parse_gateway, 0, 0 Network.Gateway, config_parse_gateway, 0, 0
Network.DNS, config_parse_strv, 0, offsetof(Network, dns) Network.DNS, config_parse_strv, 0, offsetof(Network, dns)
Network.NTP, config_parse_strv, 0, offsetof(Network, ntp) Network.NTP, config_parse_strv, 0, offsetof(Network, ntp)
Network.Tunnel, config_parse_tunnel, 0, offsetof(Network, tunnel)
Address.Address, config_parse_address, 0, 0 Address.Address, config_parse_address, 0, 0
Address.Peer, config_parse_address, 0, 0 Address.Peer, config_parse_address, 0, 0
Address.Broadcast, config_parse_broadcast, 0, 0 Address.Broadcast, config_parse_broadcast, 0, 0

View File

@ -62,16 +62,8 @@ static int network_load_one(Manager *manager, const char *filename) {
LIST_HEAD_INIT(network->static_addresses); LIST_HEAD_INIT(network->static_addresses);
LIST_HEAD_INIT(network->static_routes); LIST_HEAD_INIT(network->static_routes);
network->vlans = hashmap_new(string_hash_func, string_compare_func); network->stacked_netdevs = hashmap_new(string_hash_func, string_compare_func);
if (!network->vlans) if (!network->stacked_netdevs)
return log_oom();
network->macvlans = hashmap_new(string_hash_func, string_compare_func);
if (!network->macvlans)
return log_oom();
network->vxlans = hashmap_new(string_hash_func, string_compare_func);
if (!network->vxlans)
return log_oom(); return log_oom();
network->addresses_by_section = hashmap_new(uint64_hash_func, uint64_compare_func); network->addresses_by_section = hashmap_new(uint64_hash_func, uint64_compare_func);
@ -178,19 +170,9 @@ void network_free(Network *network) {
netdev_unref(network->bond); netdev_unref(network->bond);
netdev_unref(network->tunnel); HASHMAP_FOREACH(netdev, network->stacked_netdevs, i)
HASHMAP_FOREACH(netdev, network->vlans, i)
netdev_unref(netdev); netdev_unref(netdev);
hashmap_free(network->vlans); hashmap_free(network->stacked_netdevs);
HASHMAP_FOREACH(netdev, network->macvlans, i)
netdev_unref(netdev);
hashmap_free(network->macvlans);
HASHMAP_FOREACH(netdev, network->vxlans, i)
netdev_unref(netdev);
hashmap_free(network->vxlans);
while ((route = network->static_routes)) while ((route = network->static_routes))
route_free(route); route_free(route);
@ -338,7 +320,9 @@ int config_parse_netdev(const char *unit,
break; break;
case NETDEV_KIND_VLAN: case NETDEV_KIND_VLAN:
r = hashmap_put(network->vlans, netdev->ifname, netdev); case NETDEV_KIND_MACVLAN:
case NETDEV_KIND_VXLAN:
r = hashmap_put(network->stacked_netdevs, netdev->ifname, netdev);
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL, log_syntax(unit, LOG_ERR, filename, line, EINVAL,
"Can not add VLAN '%s' to network: %s", "Can not add VLAN '%s' to network: %s",
@ -346,26 +330,6 @@ int config_parse_netdev(const char *unit,
return 0; return 0;
} }
break;
case NETDEV_KIND_MACVLAN:
r = hashmap_put(network->macvlans, netdev->ifname, netdev);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
"Can not add MACVLAN '%s' to network: %s",
rvalue, strerror(-r));
return 0;
}
break;
case NETDEV_KIND_VXLAN:
r = hashmap_put(network->vxlans, netdev->ifname, netdev);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
"Can not add VXLAN '%s' to network: %s",
rvalue, strerror(-r));
return 0;
}
break; break;
default: default:
assert_not_reached("Can not parse NetDev"); assert_not_reached("Can not parse NetDev");
@ -411,7 +375,15 @@ int config_parse_tunnel(const char *unit,
return 0; return 0;
} }
network->tunnel = netdev; r = hashmap_put(network->stacked_netdevs, netdev->ifname, netdev);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
"Can not add VLAN '%s' to network: %s",
rvalue, strerror(-r));
return 0;
}
netdev_ref(netdev);
return 0; return 0;
} }

View File

@ -81,10 +81,7 @@ struct Network {
char *description; char *description;
NetDev *bridge; NetDev *bridge;
NetDev *bond; NetDev *bond;
NetDev *tunnel; Hashmap *stacked_netdevs;
Hashmap *vlans;
Hashmap *macvlans;
Hashmap *vxlans;
DHCPSupport dhcp; DHCPSupport dhcp;
bool dhcp_dns; bool dhcp_dns;
bool dhcp_ntp; bool dhcp_ntp;