networkd: add support for macvtap
authorSusant Sahani <ssahani@gmail.com>
Mon, 27 Jul 2015 05:48:28 +0000 (11:18 +0530)
committerSusant Sahani <ssahani@gmail.com>
Mon, 27 Jul 2015 05:48:28 +0000 (11:18 +0530)
This patch add support for macvtap.

see http://virt.kernelnewbies.org/MacVTap

src/network/networkd-netdev-gperf.gperf
src/network/networkd-netdev-macvlan.c
src/network/networkd-netdev-macvlan.h
src/network/networkd-netdev.c
src/network/networkd-netdev.h
src/network/networkd-network-gperf.gperf
src/network/networkd-network.c

index be76022..403f810 100644 (file)
@@ -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)
index c2c5649..e17de79 100644 (file)
@@ -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,
index d61efc1..c491bfa 100644 (file)
@@ -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_;
index 6949b40..cd31387 100644 (file)
@@ -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",
index a004f2f..19fb5bb 100644 (file)
@@ -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);
index 83224d7..8735b39 100644 (file)
@@ -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
index d8f4262..e3593fc 100644 (file)
@@ -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);