mirror of
https://github.com/systemd/systemd.git
synced 2025-03-21 02:50:18 +03:00
networkd: add support for macvtap
This patch add support for macvtap. see http://virt.kernelnewbies.org/MacVTap
This commit is contained in:
parent
d13125752d
commit
f33ff02b1a
@ -29,6 +29,7 @@ NetDev.MTUBytes, config_parse_iec_size, 0,
|
||||
NetDev.MACAddress, config_parse_hwaddr, 0, offsetof(NetDev, mac)
|
||||
VLAN.Id, config_parse_uint64, 0, offsetof(VLan, id)
|
||||
MACVLAN.Mode, config_parse_macvlan_mode, 0, offsetof(MacVlan, mode)
|
||||
MACVTAP.Mode, config_parse_macvlan_mode, 0, offsetof(MacVlan, mode)
|
||||
IPVLAN.Mode, config_parse_ipvlan_mode, 0, offsetof(IPVlan, mode)
|
||||
Tunnel.Local, config_parse_tunnel_address, 0, offsetof(Tunnel, local)
|
||||
Tunnel.Remote, config_parse_tunnel_address, 0, offsetof(Tunnel, remote)
|
||||
|
@ -35,14 +35,20 @@ DEFINE_STRING_TABLE_LOOKUP(macvlan_mode, MacVlanMode);
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_macvlan_mode, macvlan_mode, MacVlanMode, "Failed to parse macvlan mode");
|
||||
|
||||
static int netdev_macvlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
|
||||
MacVlan *m = MACVLAN(netdev);
|
||||
MacVlan *m;
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
assert(m);
|
||||
assert(link);
|
||||
assert(netdev->ifname);
|
||||
|
||||
if (netdev->kind == NETDEV_KIND_MACVLAN)
|
||||
m = MACVLAN(netdev);
|
||||
else
|
||||
m = MACVTAP(netdev);
|
||||
|
||||
assert(m);
|
||||
|
||||
if (m->mode != _NETDEV_MACVLAN_MODE_INVALID) {
|
||||
r = sd_netlink_message_append_u32(req, IFLA_MACVLAN_MODE, m->mode);
|
||||
if (r < 0)
|
||||
@ -53,14 +59,28 @@ static int netdev_macvlan_fill_message_create(NetDev *netdev, Link *link, sd_net
|
||||
}
|
||||
|
||||
static void macvlan_init(NetDev *n) {
|
||||
MacVlan *m = MACVLAN(n);
|
||||
MacVlan *m;
|
||||
|
||||
assert(n);
|
||||
|
||||
if (n->kind == NETDEV_KIND_MACVLAN)
|
||||
m = MACVLAN(n);
|
||||
else
|
||||
m = MACVTAP(n);
|
||||
|
||||
assert(m);
|
||||
|
||||
m->mode = _NETDEV_MACVLAN_MODE_INVALID;
|
||||
}
|
||||
|
||||
const NetDevVTable macvtap_vtable = {
|
||||
.object_size = sizeof(MacVlan),
|
||||
.init = macvlan_init,
|
||||
.sections = "Match\0NetDev\0MACVTAP\0",
|
||||
.fill_message_create = netdev_macvlan_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
};
|
||||
|
||||
const NetDevVTable macvlan_vtable = {
|
||||
.object_size = sizeof(MacVlan),
|
||||
.init = macvlan_init,
|
||||
|
@ -41,6 +41,7 @@ struct MacVlan {
|
||||
};
|
||||
|
||||
extern const NetDevVTable macvlan_vtable;
|
||||
extern const NetDevVTable macvtap_vtable;
|
||||
|
||||
const char *macvlan_mode_to_string(MacVlanMode d) _const_;
|
||||
MacVlanMode macvlan_mode_from_string(const char *d) _pure_;
|
||||
|
@ -34,6 +34,7 @@ const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX] = {
|
||||
[NETDEV_KIND_BOND] = &bond_vtable,
|
||||
[NETDEV_KIND_VLAN] = &vlan_vtable,
|
||||
[NETDEV_KIND_MACVLAN] = &macvlan_vtable,
|
||||
[NETDEV_KIND_MACVTAP] = &macvtap_vtable,
|
||||
[NETDEV_KIND_IPVLAN] = &ipvlan_vtable,
|
||||
[NETDEV_KIND_VXLAN] = &vxlan_vtable,
|
||||
[NETDEV_KIND_IPIP] = &ipip_vtable,
|
||||
@ -56,6 +57,7 @@ static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
|
||||
[NETDEV_KIND_BOND] = "bond",
|
||||
[NETDEV_KIND_VLAN] = "vlan",
|
||||
[NETDEV_KIND_MACVLAN] = "macvlan",
|
||||
[NETDEV_KIND_MACVTAP] = "macvtap",
|
||||
[NETDEV_KIND_IPVLAN] = "ipvlan",
|
||||
[NETDEV_KIND_VXLAN] = "vxlan",
|
||||
[NETDEV_KIND_IPIP] = "ipip",
|
||||
|
@ -40,6 +40,7 @@ typedef enum NetDevKind {
|
||||
NETDEV_KIND_BOND,
|
||||
NETDEV_KIND_VLAN,
|
||||
NETDEV_KIND_MACVLAN,
|
||||
NETDEV_KIND_MACVTAP,
|
||||
NETDEV_KIND_IPVLAN,
|
||||
NETDEV_KIND_VXLAN,
|
||||
NETDEV_KIND_IPIP,
|
||||
@ -161,6 +162,7 @@ DEFINE_CAST(BRIDGE, Bridge);
|
||||
DEFINE_CAST(BOND, Bond);
|
||||
DEFINE_CAST(VLAN, VLan);
|
||||
DEFINE_CAST(MACVLAN, MacVlan);
|
||||
DEFINE_CAST(MACVTAP, MacVlan);
|
||||
DEFINE_CAST(IPVLAN, IPVlan);
|
||||
DEFINE_CAST(VXLAN, VxLan);
|
||||
DEFINE_CAST(IPIP, Tunnel);
|
||||
|
@ -31,6 +31,7 @@ Network.Bridge, config_parse_netdev, 0
|
||||
Network.Bond, config_parse_netdev, 0, offsetof(Network, bond)
|
||||
Network.VLAN, config_parse_netdev, 0, 0
|
||||
Network.MACVLAN, config_parse_netdev, 0, 0
|
||||
Network.MACVTAP, config_parse_netdev, 0, 0
|
||||
Network.IPVLAN, config_parse_netdev, 0, 0
|
||||
Network.VXLAN, config_parse_netdev, 0, 0
|
||||
Network.Tunnel, config_parse_tunnel, 0, 0
|
||||
|
@ -428,6 +428,7 @@ int config_parse_netdev(const char *unit,
|
||||
break;
|
||||
case NETDEV_KIND_VLAN:
|
||||
case NETDEV_KIND_MACVLAN:
|
||||
case NETDEV_KIND_MACVTAP:
|
||||
case NETDEV_KIND_IPVLAN:
|
||||
case NETDEV_KIND_VXLAN:
|
||||
r = hashmap_put(network->stacked_netdevs, netdev->ifname, netdev);
|
||||
|
Loading…
x
Reference in New Issue
Block a user