};
DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind);
@@ -221,6 +223,7 @@ static int netdev_enter_ready(NetDev *netdev) {
return 0;
}
+
static int netdev_create_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void
*userdata) {
NetDev *netdev = userdata;
int r;
@@ -521,11 +524,19 @@ int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message
*message) {
return -EINVAL;
}
- if (!streq(kind, received_kind)) {
- log_error_netdev(netdev, "Received newlink with wrong KIND %s,
"
- "expected %s", received_kind, kind);
- netdev_enter_failed(netdev);
- return r;
+ switch(netdev->kind) {
+ case NETDEV_KIND_TUN:
+ case NETDEV_KIND_TAP:
+ break;
+ default:
+ if (!streq(kind, received_kind)) {
+ log_error_netdev(netdev,
+ "Received newlink with wrong KIND %s,
"
+ "expected %s", received_kind, kind);
+ netdev_enter_failed(netdev);
+ return r;
+ }
+ break;
}
netdev->ifindex = ifindex;
@@ -617,9 +628,10 @@ static int netdev_load_one(Manager *manager, const char
*filename) {
netdev->vxlanid = VXLAN_VID_MAX + 1;
netdev->tunnel_pmtudisc = true;
netdev->learning = true;
+ netdev->packet_info = true;
r = config_parse(NULL, filename, file,
- "Match\0NetDev\0VLAN\0MACVLAN\0VXLAN\0Tunnel\0Peer\0",
+
"Match\0NetDev\0VLAN\0MACVLAN\0VXLAN\0Tunnel\0Peer\0Tun\0Tap\0",
config_item_perf_lookup, (void*)
network_netdev_gperf_lookup,
false, false, netdev);
if (r < 0) {
@@ -719,6 +731,14 @@ static int netdev_load_one(Manager *manager, const char
*filename) {
if (r < 0)
return r;
break;
+
+ case NETDEV_KIND_TUN:
+ case NETDEV_KIND_TAP:
+ r = netdev_create_tuntap(netdev);
+ if (r < 0)
+ return r;
+ break;
+
default:
break;
}
diff --git a/src/network/networkd-tuntap.c b/src/network/networkd-tuntap.c
new file mode 100644
index 0000000..7c1840c
--- /dev/null
+++ b/src/network/networkd-tuntap.c
@@ -0,0 +1,101 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Susant Sahani <sus...@redhat.com>
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <linux/if_tun.h>
+
+#include "networkd.h"
+
+#define TUN_DEV "/dev/net/tun"
+
+
+static int netdev_fill_tuntap_message(NetDev *netdev, struct ifreq *ifr) {
+
+ assert(netdev);
+ assert(ifr);
+
+ memset(ifr, 0, sizeof(*ifr));
+ if(netdev->kind != NETDEV_KIND_TAP)
+ ifr->ifr_flags |= IFF_TUN;
+ else
+ ifr->ifr_flags |= IFF_TAP;
+
+ if(!netdev->packet_info)
+ ifr->ifr_flags &= ~IFF_NO_PI;
+ else
+ ifr->ifr_flags |= IFF_NO_PI;