[systemd-commits] 7 commits - Makefile.am man/systemd.netdev.xml src/network src/udev
Tom Gundersen
tomegun at kemper.freedesktop.org
Thu Jul 3 02:16:56 PDT 2014
Makefile.am | 3
man/systemd.netdev.xml | 115 ++++++++++++++++++++
src/network/networkd-address.c | 6 +
src/network/networkd-dummy.c | 2
src/network/networkd-link.c | 21 ---
src/network/networkd-macvlan.c | 158 +++++++++++++++++++++++++++
src/network/networkd-netdev-gperf.gperf | 10 +
src/network/networkd-netdev.c | 184 +++++++++++++-------------------
src/network/networkd-route.c | 4
src/network/networkd-tunnel.c | 54 ++++++++-
src/network/networkd-tuntap.c | 157 +++++++++++++++++++++++++++
src/network/networkd-vlan.c | 147 +++++++++++++++++++++++++
src/network/networkd.h | 20 ++-
src/udev/net/link-config.c | 10 +
14 files changed, 752 insertions(+), 139 deletions(-)
New commits:
commit 6ef892fc05791a6609489df7b5d1b081819c5de9
Author: Tom Gundersen <teg at jklm.no>
Date: Thu Jul 3 10:55:59 2014 +0200
networkd: netdev - move tunnel address parsing to networkd-tunnel.c
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index a810be0..a8c1ea3 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -244,35 +244,6 @@ static int netdev_create_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userda
return 1;
}
-int config_parse_tunnel_address(const char *unit,
- const char *filename,
- unsigned line,
- const char *section,
- unsigned section_line,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) {
- NetDev *n = userdata;
- union in_addr_union *addr = data;
- int r;
-
- assert(filename);
- assert(lvalue);
- assert(rvalue);
- assert(data);
-
- r = net_parse_inaddr(rvalue, &n->family, addr);
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Tunnel address is invalid, ignoring assignment: %s", rvalue);
- return 0;
- }
-
- return 0;
-}
-
static int netdev_create(NetDev *netdev) {
_cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
const char *kind;
diff --git a/src/network/networkd-tunnel.c b/src/network/networkd-tunnel.c
index bd12259..7341487 100644
--- a/src/network/networkd-tunnel.c
+++ b/src/network/networkd-tunnel.c
@@ -30,6 +30,7 @@
#include "network-internal.h"
#include "util.h"
#include "missing.h"
+#include "conf-parser.h"
static int netdev_fill_ipip_rtnl_message(Link *link, sd_rtnl_message *m) {
@@ -535,3 +536,32 @@ int netdev_create_tunnel(NetDev *netdev, Link *link, sd_rtnl_message_handler_t c
return 0;
}
+
+int config_parse_tunnel_address(const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+ NetDev *n = userdata;
+ union in_addr_union *addr = data;
+ int r;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ r = net_parse_inaddr(rvalue, &n->family, addr);
+ if (r < 0) {
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+ "Tunnel address is invalid, ignoring assignment: %s", rvalue);
+ return 0;
+ }
+
+ return 0;
+}
commit 4826dd6850478ddec604787756db26c1ab2c106f
Author: Tom Gundersen <teg at jklm.no>
Date: Thu Jul 3 10:52:42 2014 +0200
networkd: tunnels - make tunnel address parsing generic
It had a bug in the typing, fix that and also make it save the address family so we
can print proper error messages.
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index cc85e53..a810be0 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -254,8 +254,8 @@ int config_parse_tunnel_address(const char *unit,
const char *rvalue,
void *data,
void *userdata) {
- NetDev *n = data;
- unsigned char family = AF_INET;
+ NetDev *n = userdata;
+ union in_addr_union *addr = data;
int r;
assert(filename);
@@ -263,13 +263,14 @@ int config_parse_tunnel_address(const char *unit,
assert(rvalue);
assert(data);
- r = net_parse_inaddr(rvalue, &family, n);
+ r = net_parse_inaddr(rvalue, &n->family, addr);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
"Tunnel address is invalid, ignoring assignment: %s", rvalue);
return 0;
}
- return 0;
+
+ return 0;
}
static int netdev_create(NetDev *netdev) {
@@ -607,9 +608,41 @@ static int netdev_load_one(Manager *manager, const char *filename) {
return r;
}
- if (netdev->kind == _NETDEV_KIND_INVALID) {
+ switch (netdev->kind) {
+ case _NETDEV_KIND_INVALID:
log_warning("NetDev without Kind configured in %s. Ignoring", filename);
return 0;
+ case NETDEV_KIND_VLAN:
+ if (netdev->vlanid > VLANID_MAX) {
+ log_warning("VLAN without valid Id configured in %s. Ignoring", filename);
+ return 0;
+ }
+ break;
+ case NETDEV_KIND_VXLAN:
+ if (netdev->vxlanid > VXLAN_VID_MAX) {
+ log_warning("VXLAN without valid Id configured in %s. Ignoring", filename);
+ return 0;
+ }
+ break;
+ case NETDEV_KIND_IPIP:
+ case NETDEV_KIND_GRE:
+ case NETDEV_KIND_SIT:
+ case NETDEV_KIND_VTI:
+ if (netdev->local.in.s_addr == INADDR_ANY) {
+ log_warning("Tunnel without local address configured in %s. Ignoring", filename);
+ return 0;
+ }
+ if (netdev->remote.in.s_addr == INADDR_ANY) {
+ log_warning("Tunnel without remote address configured in %s. Ignoring", filename);
+ return 0;
+ }
+ if (netdev->family != AF_INET) {
+ log_warning("Tunnel with invalid address family configured in %s. Ignoring", filename);
+ return 0;
+ }
+ break;
+ default:
+ break;
}
if (!netdev->ifname) {
@@ -617,16 +650,6 @@ static int netdev_load_one(Manager *manager, const char *filename) {
return 0;
}
- if (netdev->kind == NETDEV_KIND_VLAN && netdev->vlanid > VLANID_MAX) {
- log_warning("VLAN without valid Id configured in %s. Ignoring", filename);
- return 0;
- }
-
- if (netdev->kind == NETDEV_KIND_VXLAN && netdev->vxlanid > VXLAN_VID_MAX) {
- log_warning("VXLAN without valid Id configured in %s. Ignoring", filename);
- return 0;
- }
-
if (netdev->kind != NETDEV_KIND_VLAN && netdev->vlanid <= VLANID_MAX) {
log_warning("VLAN Id configured for a %s in %s. Ignoring",
netdev_kind_to_string(netdev->kind), filename);
diff --git a/src/network/networkd-tunnel.c b/src/network/networkd-tunnel.c
index cffa564..bd12259 100644
--- a/src/network/networkd-tunnel.c
+++ b/src/network/networkd-tunnel.c
@@ -43,6 +43,8 @@ static int netdev_fill_ipip_rtnl_message(Link *link, sd_rtnl_message *m) {
netdev = link->network->tunnel;
+ assert(netdev->family == AF_INET);
+
r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
if (r < 0) {
log_error_netdev(netdev,
@@ -96,7 +98,7 @@ static int netdev_fill_ipip_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &netdev->local);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &netdev->local.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_IPTUN_LOCAL attribute: %s",
@@ -104,7 +106,7 @@ static int netdev_fill_ipip_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &netdev->remote);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &netdev->remote.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_IPTUN_REMOTE attribute: %s",
@@ -150,6 +152,8 @@ static int netdev_fill_sit_rtnl_message(Link *link, sd_rtnl_message *m) {
netdev = link->network->tunnel;
+ assert(netdev->family == AF_INET);
+
r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
if (r < 0) {
log_error_netdev(netdev,
@@ -203,7 +207,7 @@ static int netdev_fill_sit_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &netdev->local);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &netdev->local.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_IPTUN_LOCAL attribute: %s",
@@ -211,7 +215,7 @@ static int netdev_fill_sit_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &netdev->remote);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &netdev->remote.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_IPTUN_REMOTE attribute: %s",
@@ -265,6 +269,8 @@ static int netdev_fill_ipgre_rtnl_message(Link *link, sd_rtnl_message *m) {
netdev = link->network->tunnel;
+ assert(netdev->family == AF_INET);
+
r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
if (r < 0) {
log_error_netdev(netdev,
@@ -318,7 +324,7 @@ static int netdev_fill_ipgre_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_GRE_LOCAL, &netdev->local);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_GRE_LOCAL, &netdev->local.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_GRE_LOCAL attribute: %s",
@@ -326,7 +332,7 @@ static int netdev_fill_ipgre_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_GRE_REMOTE, &netdev->remote);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_GRE_REMOTE, &netdev->remote.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_GRE_REMOTE attribute: %s",
@@ -380,6 +386,8 @@ static int netdev_fill_vti_rtnl_message(Link *link, sd_rtnl_message *m) {
netdev = link->network->tunnel;
+ assert(netdev->family == AF_INET);
+
r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
if (r < 0) {
log_error_netdev(netdev,
@@ -433,7 +441,7 @@ static int netdev_fill_vti_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_VTI_LOCAL, &netdev->local);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_VTI_LOCAL, &netdev->local.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_IPTUN_LOCAL attribute: %s",
@@ -441,7 +449,7 @@ static int netdev_fill_vti_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
- r = sd_rtnl_message_append_in_addr(m, IFLA_VTI_REMOTE, &netdev->remote);
+ r = sd_rtnl_message_append_in_addr(m, IFLA_VTI_REMOTE, &netdev->remote.in);
if (r < 0) {
log_error_netdev(netdev,
"Could not append IFLA_IPTUN_REMOTE attribute: %s",
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 67ca41b..6a00175 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -134,9 +134,10 @@ struct NetDev {
unsigned ttl;
unsigned tos;
- struct in_addr local;
- struct in_addr remote;
- struct in_addr group;
+ unsigned char family;
+ union in_addr_union local;
+ union in_addr_union remote;
+ union in_addr_union group;
LIST_HEAD(netdev_enslave_callback, callbacks);
};
commit 30ae9dfda3788cdfaf1b84d124dbc7feb638c77b
Author: Susant Sahani <susant at redhat.com>
Date: Thu Jul 3 13:34:11 2014 +0530
networkd: Introduce tun/tap device
This patch introduces TUN/TAP device creation support
to networkd.
Example conf to create a tap device:
file: tap.netdev
------------------
[NetDev]
Name=tap-test
Kind=tap
[Tap]
OneQueue=true
MultiQueue=true
PacketInfo=true
User=sus
Group=sus
------------------
Test:
1. output of ip link
tap-test: tap pi one_queue UNKNOWN_FLAGS:900 user 1000 group 1000
id:
uid=1000(sus) gid=10(wheel) groups=10(wheel),1000(sus)
context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
Modifications:
Added:
1. file networkd-tuntap.c
3. netdev kind NETDEV_KIND_TUN and NETDEV_KIND_TAP
2. Tun and Tap Sections and config params to parse
conf and gperf conf parameters
[tomegun: tweak the 'kind' checking for received ifindex]
diff --git a/Makefile.am b/Makefile.am
index cc3b7fd..672e93f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4535,6 +4535,7 @@ libsystemd_networkd_core_la_SOURCES = \
src/network/networkd-vlan.c \
src/network/networkd-macvlan.c \
src/network/networkd-dummy.c \
+ src/network/networkd-tuntap.c \
src/network/networkd-network.c \
src/network/networkd-address.c \
src/network/networkd-route.c \
diff --git a/man/systemd.netdev.xml b/man/systemd.netdev.xml
index 5d033e7..a57ba7a 100644
--- a/man/systemd.netdev.xml
+++ b/man/systemd.netdev.xml
@@ -340,6 +340,112 @@
</variablelist>
</refsect1>
<refsect1>
+ <title>[TUN] Section Options</title>
+
+ <para>The <literal>[TUN]</literal> section only applies for netdevs of kind
+ <literal>tun</literal>, and accepts the following keys:</para>
+
+ <variablelist class='network-directives'>
+ <varlistentry>
+ <term><varname>OneQueue=</varname></term>
+ <listitem><para>Takes a boolean argument. Configures whether
+ to enable disable one queue . it determines whether all packets
+ queue at the device (enabled), or a fixed number queue at the device and
+ the rest at the "qdisc". Defaults to <literal>no</literal>.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><varname>MultiQueue=</varname></term>
+ <listitem><para>Takes a boolean argument. Configures whether the
+ to disable or disable . Linux supports multiqueue tuntap which can
+ uses multiple file descriptors (queues) to parallelize
+ packets sending or receiving. The device allocation is the same as before,
+ and if user wants to create multiple queues. Defaults to
+ <literal>no</literal>.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><varname>PacketInfo=</varname></term>
+ <listitem><para>Takes a boolean argument. Configures whether the
+ to enable or disable . PacketInfo tells the kernel to not provide packet
+ information. The purpose of PacketInfo is to tell the kernel that packets
+ will be "pure" IP packets, with no added bytes. Otherwise (if PacketInfo is unset),
+ 4 extra bytes are added to the beginning of the packet (2 flag bytes and 2 protocol bytes).
+ Defaults to <literal>no</literal>.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><varname>User=</varname></term>
+ <listitem><para>User to be allowed to access this device. Give ownership to unprivileged users,
+ so that /dev/net/tun device to be usable by this user.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><varname>Group=</varname></term>
+ <listitem><para>Group to be allowed to access this device. Give ownership to unprivileged group,
+ so that /dev/net/tun device to be usable by this group.</para>
+ </listitem>
+ </varlistentry>
+
+ </variablelist>
+
+ </refsect1>
+
+ <refsect1>
+ <title>[TAP] Section Options</title>
+
+ <para>The <literal>[TAP]</literal> section only applies for netdevs of kind
+ <literal>tap</literal>, and accepts the following keys:</para>
+ </refsect1>
+
+ <variablelist class='network-directives'>
+ <varlistentry>
+ <term><varname>OneQueue=</varname></term>
+ <listitem><para>Takes a boolean argument. Configures whether
+ to enable disable one queue . it determines whether all packets
+ queue at the device (enabled), or a fixed number queue at the device and
+ the rest at the "qdisc". Defaults to <literal>no</literal>.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><varname>MultiQueue=</varname></term>
+ <listitem><para>Takes a boolean argument. Configures whether the
+ to disable or disable . From version 3.8, Linux supports multiqueue
+ tuntap which can uses multiple file descriptors (queues) to parallelize
+ packets sending or receiving. The device allocation is the same as before,
+ and if user wants to create multiple queues. Defaults to
+ <literal>no</literal>.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><varname>PacketInfo=</varname></term>
+ <listitem><para>Takes a boolean argument. Configures whether the
+ to enable or disable . PacketInfo tells the kernel to not provide packet
+ information. The purpose of PacketInfo is to tell the kernel that packets
+ will be "pure" IP packets, with no added bytes. Otherwise (if PacketInfo is unset),
+ 4 extra bytes are added to the beginning of the packet (2 flag bytes and 2 protocol bytes).
+ Defaults to <literal>no</literal>.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><varname>User=</varname></term>
+ <listitem><para>User to be allowed to access this device. Give ownership to unprivileged users,
+ so that /dev/net/tun device to be usable by this user.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><varname>Group=</varname></term>
+ <listitem><para>Group to be allowed to access this device. Give ownership to unprivileged group,
+ so that /dev/net/tun device to be usable by this group.</para>
+ </listitem>
+ </varlistentry>
+
+ </variablelist>
+
+
+ <refsect1>
<title>Example</title>
<example>
<title>/etc/systemd/network/bridge.netdev</title>
@@ -374,6 +480,15 @@ Local=192.168.223.238
Remote=192.169.224.239
TTL=64</programlisting>
</example>
+ <example>
+ <title>/etc/systemd/network/tap.netdev</title>
+ <programlisting>[NetDev]
+Name=tap-test
+Kind=tap
+
+[Tap]
+MultiQueue=true
+PacketInfo=true</programlisting> </example>
<example>
<title>/etc/systemd/network/sit.netdev</title>
diff --git a/src/network/networkd-netdev-gperf.gperf b/src/network/networkd-netdev-gperf.gperf
index 9125e1d..5955f51 100644
--- a/src/network/networkd-netdev-gperf.gperf
+++ b/src/network/networkd-netdev-gperf.gperf
@@ -38,3 +38,13 @@ VXLAN.Group, config_parse_tunnel_address, 0,
VXLAN.TOS, config_parse_unsigned, 0, offsetof(NetDev, tos)
VXLAN.TTL, config_parse_unsigned, 0, offsetof(NetDev, ttl)
VXLAN.MacLearning, config_parse_bool, 0, offsetof(NetDev, learning)
+Tun.OneQueue, config_parse_bool, 0, offsetof(NetDev, one_queue)
+Tun.MultiQueue, config_parse_bool, 0, offsetof(NetDev, multi_queue)
+Tun.PacketInfo, config_parse_bool, 0, offsetof(NetDev, packet_info)
+Tun.User, config_parse_string, 0, offsetof(NetDev, user_name)
+Tun.Group, config_parse_string, 0, offsetof(NetDev, group_name)
+Tap.OneQueue, config_parse_bool, 0, offsetof(NetDev, one_queue)
+Tap.MultiQueue, config_parse_bool, 0, offsetof(NetDev, multi_queue)
+Tap.PacketInfo, config_parse_bool, 0, offsetof(NetDev, packet_info)
+Tap.User, config_parse_string, 0, offsetof(NetDev, user_name)
+Tap.Group, config_parse_string, 0, offsetof(NetDev, group_name)
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index eaa8bed..cc85e53 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -41,6 +41,8 @@ static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
[NETDEV_KIND_VETH] = "veth",
[NETDEV_KIND_VTI] = "vti",
[NETDEV_KIND_DUMMY] = "dummy",
+ [NETDEV_KIND_TUN] = "tun",
+ [NETDEV_KIND_TAP] = "tap",
};
DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind);
@@ -86,6 +88,8 @@ static void netdev_free(NetDev *netdev) {
free(netdev->ifname_peer);
free(netdev->mac);
free(netdev->mac_peer);
+ free(netdev->user_name);
+ free(netdev->group_name);
condition_free_list(netdev->match_host);
condition_free_list(netdev->match_virt);
@@ -484,15 +488,21 @@ int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *message) {
return r;
}
- kind = netdev_kind_to_string(netdev->kind);
- if (!kind) {
- log_error_netdev(netdev, "Could not get kind");
- netdev_enter_failed(netdev);
- return -EINVAL;
+ if (netdev->kind == NETDEV_KIND_TAP)
+ /* the kernel does not distinguish between tun and tap */
+ kind = "tun";
+ else {
+ kind = netdev_kind_to_string(netdev->kind);
+ if (!kind) {
+ log_error_netdev(netdev, "Could not get kind");
+ netdev_enter_failed(netdev);
+ return -EINVAL;
+ }
}
if (!streq(kind, received_kind)) {
- log_error_netdev(netdev, "Received newlink with wrong KIND %s, "
+ log_error_netdev(netdev,
+ "Received newlink with wrong KIND %s, "
"expected %s", received_kind, kind);
netdev_enter_failed(netdev);
return r;
@@ -589,7 +599,7 @@ static int netdev_load_one(Manager *manager, const char *filename) {
netdev->learning = 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) {
@@ -695,6 +705,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..19dc2ad
--- /dev/null
+++ b/src/network/networkd-tuntap.c
@@ -0,0 +1,157 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Susant Sahani <susant at 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;
+
+ if (netdev->one_queue)
+ ifr->ifr_flags |= IFF_ONE_QUEUE;
+
+ if (netdev->multi_queue)
+ ifr->ifr_flags |= IFF_MULTI_QUEUE;
+
+ strncpy(ifr->ifr_name, netdev->ifname, IFNAMSIZ-1);
+
+ return 0;
+}
+
+static int netdev_tuntap_add(NetDev *netdev, struct ifreq *ifr) {
+ _cleanup_close_ int fd;
+ const char *user;
+ const char *group;
+ uid_t uid;
+ gid_t gid;
+ int r = 0;
+
+ fd = open(TUN_DEV, O_RDWR);
+ if (fd < 0) {
+ log_error_netdev(netdev,
+ "Failed to open tun dev: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = ioctl(fd, TUNSETIFF, ifr);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "TUNSETIFF failed on tun dev: %s",
+ strerror(-r));
+ return r;
+ }
+
+ if(netdev->user_name) {
+
+ user = netdev->user_name;
+
+ r = get_user_creds(&user, &uid, NULL, NULL, NULL);
+ if (r < 0) {
+ log_error("Cannot resolve user name %s: %s",
+ netdev->user_name, strerror(-r));
+ return 0;
+ }
+
+ r = ioctl(fd, TUNSETOWNER, uid);
+ if ( r < 0) {
+ log_error_netdev(netdev,
+ "TUNSETOWNER failed on tun dev: %s",
+ strerror(-r));
+ }
+ }
+
+ if(netdev->group_name) {
+
+ group = netdev->group_name;
+
+ r = get_group_creds(&group, &gid);
+ if (r < 0) {
+ log_error("Cannot resolve group name %s: %s",
+ netdev->group_name, strerror(-r));
+ return 0;
+ }
+
+ r = ioctl(fd, TUNSETGROUP, gid);
+ if( r < 0) {
+ log_error_netdev(netdev,
+ "TUNSETGROUP failed on tun dev: %s",
+ strerror(-r));
+ return r;
+ }
+
+ }
+
+ r = ioctl(fd, TUNSETPERSIST, 1);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "TUNSETPERSIST failed on tun dev: %s",
+ strerror(-r));
+ return r;
+ }
+
+ return r;
+}
+
+int netdev_create_tuntap(NetDev *netdev) {
+ struct ifreq ifr;
+ int r;
+
+ assert(netdev);
+ assert(netdev->ifname);
+
+ switch(netdev->kind) {
+ case NETDEV_KIND_TUN:
+ case NETDEV_KIND_TAP:
+ break;
+ default:
+ return -ENOTSUP;
+ }
+
+ r = netdev_fill_tuntap_message(netdev, &ifr);
+ if(r < 0)
+ return r;
+
+ log_debug_netdev(netdev, "Creating tuntap netdev: %s",
+ netdev_kind_to_string(netdev->kind));
+
+ return netdev_tuntap_add(netdev, &ifr);
+}
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 0ba9ee5..67ca41b 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -82,6 +82,8 @@ typedef enum NetDevKind {
NETDEV_KIND_VETH,
NETDEV_KIND_VTI,
NETDEV_KIND_DUMMY,
+ NETDEV_KIND_TUN,
+ NETDEV_KIND_TAP,
_NETDEV_KIND_MAX,
_NETDEV_KIND_INVALID = -1
} NetDevKind;
@@ -110,6 +112,8 @@ struct NetDev {
char *description;
char *ifname;
char *ifname_peer;
+ char *user_name;
+ char *group_name;
size_t mtu;
struct ether_addr *mac;
struct ether_addr *mac_peer;
@@ -124,6 +128,10 @@ struct NetDev {
bool tunnel_pmtudisc;
bool learning;
+ bool one_queue;
+ bool multi_queue;
+ bool packet_info;
+
unsigned ttl;
unsigned tos;
struct in_addr local;
@@ -359,6 +367,7 @@ int netdev_create_vxlan(NetDev *netdev, Link *link, sd_rtnl_message_handler_t ca
int netdev_create_vlan(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback);
int netdev_create_macvlan(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback);
int netdev_create_dummy(NetDev *netdev, sd_rtnl_message_handler_t callback);
+int netdev_create_tuntap(NetDev *netdev);
const char *netdev_kind_to_string(NetDevKind d) _const_;
NetDevKind netdev_kind_from_string(const char *d) _pure_;
commit 866ee3682213789f85b877700457fdca05695a0e
Author: Tom Gundersen <teg at jklm.no>
Date: Thu Jul 3 09:57:27 2014 +0200
udev: net_setup_link - add a bit more logging
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 7a9d01b..b8650a6 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -92,14 +92,20 @@ static int link_config_ctx_connect(link_config_ctx *ctx) {
if (ctx->ethtool_fd == -1) {
r = ethtool_connect(&ctx->ethtool_fd);
- if (r < 0)
+ if (r < 0) {
+ log_warning("link_config: could not connect to ethtool: %s",
+ strerror(-r));
return r;
+ }
}
if (!ctx->rtnl) {
r = sd_rtnl_open(&ctx->rtnl, 0);
- if (r < 0)
+ if (r < 0) {
+ log_warning("link_config: could not connect to rtnl: %s",
+ strerror(-r));
return r;
+ }
}
return 0;
commit ad0774e61e436d052f93549fc7fd367ade069286
Author: Tom Gundersen <teg at jklm.no>
Date: Thu Jul 3 09:55:59 2014 +0200
networkd: netdev - drop the link callbacks after calling them once
We should never call them again, so make sure they are cleaned up correctly.
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index 0861ff3..eaa8bed 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -192,7 +192,8 @@ static int netdev_enslave_ready(NetDev *netdev, Link* link, sd_rtnl_message_hand
}
static int netdev_enter_ready(NetDev *netdev) {
- netdev_enslave_callback *callback;
+ netdev_enslave_callback *callback, *callback_next;
+ int r;
assert(netdev);
assert(netdev->ifname);
@@ -204,10 +205,16 @@ static int netdev_enter_ready(NetDev *netdev) {
log_info_netdev(netdev, "netdev ready");
- LIST_FOREACH(callbacks, callback, netdev->callbacks) {
+ LIST_FOREACH_SAFE(callbacks, callback, callback_next, netdev->callbacks) {
/* enslave the links that were attempted to be enslaved before the
* link was ready */
- netdev_enslave_ready(netdev, callback->link, callback->callback);
+ r = netdev_enslave_ready(netdev, callback->link, callback->callback);
+ if (r < 0)
+ return r;
+
+ LIST_REMOVE(callbacks, netdev->callbacks, callback);
+ link_unref(callback->link);
+ free(callback);
}
return 0;
commit 563c69c6b2c2bd691352ef522cb9ec95c08a0c63
Author: Tom Gundersen <teg at jklm.no>
Date: Thu Jul 3 09:43:31 2014 +0200
networkd: netdev - take ref immediately after calling out
Keeping the refcounting next to the sd_bus_call_async() makes it easier to check.
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 76febc7..1ba2108 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -144,6 +144,8 @@ int address_drop(Address *address, Link *link,
return r;
}
+ link_ref(link);
+
return 0;
}
@@ -225,6 +227,8 @@ int address_update(Address *address, Link *link,
return r;
}
+ link_ref(link);
+
return 0;
}
@@ -373,6 +377,8 @@ int address_configure(Address *address, Link *link,
return r;
}
+ link_ref(link);
+
return 0;
}
diff --git a/src/network/networkd-dummy.c b/src/network/networkd-dummy.c
index 5232524..80fe41b 100644
--- a/src/network/networkd-dummy.c
+++ b/src/network/networkd-dummy.c
@@ -112,6 +112,8 @@ int netdev_create_dummy(NetDev *netdev, sd_rtnl_message_handler_t callback) {
return r;
}
+ netdev_ref(netdev);
+
log_debug_netdev(netdev, "Creating dummy netdev.");
netdev->state = NETDEV_STATE_CREATING;
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 660efed..14c0417 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -436,7 +436,6 @@ static int link_set_dhcp_routes(Link *link) {
return r;
}
- link_ref(link);
link->route_messages ++;
}
@@ -468,7 +467,6 @@ static int link_enter_set_routes(Link *link) {
return r;
}
- link_ref(link);
link->route_messages ++;
}
@@ -503,7 +501,6 @@ static int link_enter_set_routes(Link *link) {
return r;
}
- link_ref(link);
link->route_messages ++;
}
}
@@ -551,7 +548,6 @@ static int link_enter_set_routes(Link *link) {
return r;
}
- link_ref(link);
link->route_messages ++;
route->family = AF_INET;
@@ -566,7 +562,6 @@ static int link_enter_set_routes(Link *link) {
return r;
}
- link_ref(link);
link->route_messages ++;
}
@@ -663,7 +658,6 @@ static int link_enter_set_addresses(Link *link) {
return r;
}
- link_ref(link);
link->addr_messages ++;
}
@@ -699,7 +693,6 @@ static int link_enter_set_addresses(Link *link) {
return r;
}
- link_ref(link);
link->addr_messages ++;
}
}
@@ -760,7 +753,6 @@ static int link_enter_set_addresses(Link *link) {
return r;
}
- link_ref(link);
link->addr_messages ++;
}
@@ -957,7 +949,6 @@ static int dhcp_lease_lost(Link *link) {
route->dst_prefixlen = routes[i].dst_prefixlen;
route_drop(route, link, &route_drop_handler);
- link_ref(link);
}
}
}
@@ -978,7 +969,6 @@ static int dhcp_lease_lost(Link *link) {
route_gw->scope = RT_SCOPE_LINK;
route_drop(route_gw, link, &route_drop_handler);
- link_ref(link);
}
r = route_new_dynamic(&route);
@@ -987,7 +977,6 @@ static int dhcp_lease_lost(Link *link) {
route->in_addr.in = gateway;
route_drop(route, link, &route_drop_handler);
- link_ref(link);
}
}
@@ -1000,7 +989,6 @@ static int dhcp_lease_lost(Link *link) {
address->prefixlen = prefixlen;
address_drop(address, link, &address_drop_handler);
- link_ref(link);
}
if (link->network->dhcp_mtu) {
@@ -1267,7 +1255,6 @@ static int ipv4ll_address_update(Link *link, bool deprecate) {
address->broadcast.s_addr = address->in_addr.in.s_addr | htonl(0xfffffffflu >> address->prefixlen);
address_update(address, link, &address_update_handler);
- link_ref(link);
}
return 0;
@@ -1300,7 +1287,6 @@ static int ipv4ll_address_lost(Link *link) {
address->scope = RT_SCOPE_LINK;
address_drop(address, link, &address_drop_handler);
- link_ref(link);
r = route_new_dynamic(&route);
if (r < 0) {
@@ -1314,7 +1300,6 @@ static int ipv4ll_address_lost(Link *link) {
route->metrics = 99;
route_drop(route, link, &route_drop_handler);
- link_ref(link);
}
return 0;
@@ -1810,7 +1795,6 @@ static int link_enter_enslave(Link *link) {
return r;
}
- link_ref(link);
link->enslaving ++;
}
@@ -1834,7 +1818,6 @@ static int link_enter_enslave(Link *link) {
return r;
}
- link_ref(link);
link->enslaving ++;
}
@@ -1858,7 +1841,6 @@ static int link_enter_enslave(Link *link) {
return r;
}
- link_ref(link);
link->enslaving ++;
}
@@ -1879,7 +1861,6 @@ static int link_enter_enslave(Link *link) {
return r;
}
- link_ref(link);
link->enslaving ++;
}
@@ -1900,7 +1881,6 @@ static int link_enter_enslave(Link *link) {
return r;
}
- link_ref(link);
link->enslaving ++;
}
@@ -1921,7 +1901,6 @@ static int link_enter_enslave(Link *link) {
return r;
}
- link_ref(link);
link->enslaving ++;
}
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index c80e943..0861ff3 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -184,6 +184,8 @@ static int netdev_enslave_ready(NetDev *netdev, Link* link, sd_rtnl_message_hand
return r;
}
+ link_ref(link);
+
log_debug_netdev(netdev, "enslaving link '%s'", link->ifname);
return 0;
@@ -393,6 +395,7 @@ int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callbac
cb->callback = callback;
cb->link = link;
+ link_ref(link);
LIST_PREPEND(callbacks, netdev->callbacks, cb);
}
@@ -678,8 +681,6 @@ static int netdev_load_one(Manager *manager, const char *filename) {
if (r < 0)
return r;
- netdev_ref(netdev);
-
break;
case NETDEV_KIND_BRIDGE:
case NETDEV_KIND_BOND:
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
index d0a04ec..acfe3f0 100644
--- a/src/network/networkd-route.c
+++ b/src/network/networkd-route.c
@@ -164,6 +164,8 @@ int route_drop(Route *route, Link *link,
return r;
}
+ link_ref(link);
+
return 0;
}
@@ -235,6 +237,8 @@ int route_configure(Route *route, Link *link,
return r;
}
+ link_ref(link);
+
return 0;
}
commit 0372cb2bd2342fa5c5585c666f79159a8341f4a6
Author: Tom Gundersen <teg at jklm.no>
Date: Thu Jul 3 09:38:33 2014 +0200
networkd: split out vlan and macvlan handling
diff --git a/Makefile.am b/Makefile.am
index d2edf3d..cc3b7fd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4532,6 +4532,8 @@ libsystemd_networkd_core_la_SOURCES = \
src/network/networkd-tunnel.c \
src/network/networkd-veth.c \
src/network/networkd-vxlan.c \
+ src/network/networkd-vlan.c \
+ src/network/networkd-macvlan.c \
src/network/networkd-dummy.c \
src/network/networkd-network.c \
src/network/networkd-address.c \
diff --git a/src/network/networkd-macvlan.c b/src/network/networkd-macvlan.c
new file mode 100644
index 0000000..9227144
--- /dev/null
+++ b/src/network/networkd-macvlan.c
@@ -0,0 +1,158 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2013 Tom Gundersen <teg at jklm.no>
+
+ 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 <net/if.h>
+
+#include "networkd.h"
+#include "network-internal.h"
+#include "conf-parser.h"
+#include "list.h"
+
+static const char* const macvlan_mode_table[_NETDEV_MACVLAN_MODE_MAX] = {
+ [NETDEV_MACVLAN_MODE_PRIVATE] = "private",
+ [NETDEV_MACVLAN_MODE_VEPA] = "vepa",
+ [NETDEV_MACVLAN_MODE_BRIDGE] = "bridge",
+ [NETDEV_MACVLAN_MODE_PASSTHRU] = "passthru",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(macvlan_mode, MacVlanMode);
+DEFINE_CONFIG_PARSE_ENUM(config_parse_macvlan_mode, macvlan_mode, MacVlanMode, "Failed to parse macvlan mode");
+
+int netdev_create_macvlan(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback) {
+ _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
+ const char *kind;
+ int r;
+
+ assert(netdev);
+ assert(netdev->kind == NETDEV_KIND_MACVLAN);
+ assert(link);
+ assert(callback);
+ assert(netdev->ifname);
+ assert(netdev->manager);
+ assert(netdev->manager->rtnl);
+
+ r = sd_rtnl_message_new_link(netdev->manager->rtnl, &req, RTM_NEWLINK, 0);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not allocate RTM_NEWLINK message: %s",
+ strerror(-r));
+ return r;
+ }
+
+ if (link) {
+ r = sd_rtnl_message_append_u32(req, IFLA_LINK, link->ifindex);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_LINK attribute: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
+ r = sd_rtnl_message_append_string(req, IFLA_IFNAME, netdev->ifname);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_IFNAME attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ if (netdev->mtu) {
+ r = sd_rtnl_message_append_u32(req, IFLA_MTU, netdev->mtu);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_MTU attribute: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
+ if (netdev->mac) {
+ r = sd_rtnl_message_append_ether_addr(req, IFLA_ADDRESS, netdev->mac);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Colud not append IFLA_ADDRESS attribute: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
+ r = sd_rtnl_message_open_container(req, IFLA_LINKINFO);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not open IFLA_LINKINFO container: %s",
+ strerror(-r));
+ return r;
+ }
+
+ kind = netdev_kind_to_string(netdev->kind);
+ if (!kind) {
+ log_error_netdev(netdev, "Invalid kind");
+ return -EINVAL;
+ }
+
+ r = sd_rtnl_message_open_container_union(req, IFLA_INFO_DATA, kind);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not open IFLA_INFO_DATA container: %s",
+ strerror(-r));
+ return r;
+ }
+
+ if (netdev->macvlan_mode != _NETDEV_MACVLAN_MODE_INVALID) {
+ r = sd_rtnl_message_append_u32(req, IFLA_MACVLAN_MODE, netdev->macvlan_mode);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_MACVLAN_MODE attribute: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
+ r = sd_rtnl_message_close_container(req);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not close IFLA_INFO_DATA container %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_close_container(req);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not close IFLA_LINKINFO container %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_call_async(netdev->manager->rtnl, req, callback, link, 0, NULL);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not send rtnetlink message: %s", strerror(-r));
+ return r;
+ }
+
+ log_debug_netdev(netdev, "creating netdev");
+
+ netdev->state = NETDEV_STATE_CREATING;
+
+ return 0;
+}
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index 2fff962..c80e943 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -29,8 +29,6 @@
#include "list.h"
#include "siphash24.h"
-#define VLANID_MAX 4094
-
static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
[NETDEV_KIND_BRIDGE] = "bridge",
[NETDEV_KIND_BOND] = "bond",
@@ -48,16 +46,6 @@ static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind);
DEFINE_CONFIG_PARSE_ENUM(config_parse_netdev_kind, netdev_kind, NetDevKind, "Failed to parse netdev kind");
-static const char* const macvlan_mode_table[_NETDEV_MACVLAN_MODE_MAX] = {
- [NETDEV_MACVLAN_MODE_PRIVATE] = "private",
- [NETDEV_MACVLAN_MODE_VEPA] = "vepa",
- [NETDEV_MACVLAN_MODE_BRIDGE] = "bridge",
- [NETDEV_MACVLAN_MODE_PASSTHRU] = "passthru",
-};
-
-DEFINE_STRING_TABLE_LOOKUP(macvlan_mode, MacVlanMode);
-DEFINE_CONFIG_PARSE_ENUM(config_parse_macvlan_mode, macvlan_mode, MacVlanMode, "Failed to parse macvlan mode");
-
static void netdev_cancel_callbacks(NetDev *netdev) {
_cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
netdev_enslave_callback *callback;
@@ -271,14 +259,12 @@ int config_parse_tunnel_address(const char *unit,
return 0;
}
-static int netdev_create(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback) {
+static int netdev_create(NetDev *netdev) {
_cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
const char *kind;
int r;
assert(netdev);
- assert(!(netdev->kind == NETDEV_KIND_VLAN || netdev->kind == NETDEV_KIND_MACVLAN) ||
- (link && callback));
assert(netdev->ifname);
assert(netdev->manager);
assert(netdev->manager->rtnl);
@@ -291,16 +277,6 @@ static int netdev_create(NetDev *netdev, Link *link, sd_rtnl_message_handler_t c
return r;
}
- if (link) {
- r = sd_rtnl_message_append_u32(req, IFLA_LINK, link->ifindex);
- if (r < 0) {
- log_error_netdev(netdev,
- "Could not append IFLA_LINK attribute: %s",
- strerror(-r));
- return r;
- }
- }
-
r = sd_rtnl_message_append_string(req, IFLA_IFNAME, netdev->ifname);
if (r < 0) {
log_error_netdev(netdev,
@@ -351,26 +327,6 @@ static int netdev_create(NetDev *netdev, Link *link, sd_rtnl_message_handler_t c
return r;
}
- if (netdev->vlanid <= VLANID_MAX) {
- r = sd_rtnl_message_append_u16(req, IFLA_VLAN_ID, netdev->vlanid);
- if (r < 0) {
- log_error_netdev(netdev,
- "Could not append IFLA_VLAN_ID attribute: %s",
- strerror(-r));
- return r;
- }
- }
-
- if (netdev->macvlan_mode != _NETDEV_MACVLAN_MODE_INVALID) {
- r = sd_rtnl_message_append_u32(req, IFLA_MACVLAN_MODE, netdev->macvlan_mode);
- if (r < 0) {
- log_error_netdev(netdev,
- "Could not append IFLA_MACVLAN_MODE attribute: %s",
- strerror(-r));
- return r;
- }
- }
-
r = sd_rtnl_message_close_container(req);
if (r < 0) {
log_error_netdev(netdev,
@@ -387,18 +343,15 @@ static int netdev_create(NetDev *netdev, Link *link, sd_rtnl_message_handler_t c
return r;
}
- if (link)
- r = sd_rtnl_call_async(netdev->manager->rtnl, req, callback, link, 0, NULL);
- else {
- r = sd_rtnl_call_async(netdev->manager->rtnl, req, &netdev_create_handler, netdev, 0, NULL);
-
- netdev_ref(netdev);
- } if (r < 0) {
+ r = sd_rtnl_call_async(netdev->manager->rtnl, req, &netdev_create_handler, netdev, 0, NULL);
+ if (r < 0) {
log_error_netdev(netdev,
"Could not send rtnetlink message: %s", strerror(-r));
return r;
}
+ netdev_ref(netdev);
+
log_debug_netdev(netdev, "creating netdev");
netdev->state = NETDEV_STATE_CREATING;
@@ -412,8 +365,9 @@ int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callbac
switch(netdev->kind) {
case NETDEV_KIND_VLAN:
+ return netdev_create_vlan(netdev, link, callback);
case NETDEV_KIND_MACVLAN:
- return netdev_create(netdev, link, callback);
+ return netdev_create_macvlan(netdev, link, callback);
case NETDEV_KIND_VXLAN:
return netdev_create_vxlan(netdev, link, callback);
case NETDEV_KIND_IPIP:
@@ -729,7 +683,7 @@ static int netdev_load_one(Manager *manager, const char *filename) {
break;
case NETDEV_KIND_BRIDGE:
case NETDEV_KIND_BOND:
- r = netdev_create(netdev, NULL, NULL);
+ r = netdev_create(netdev);
if (r < 0)
return r;
break;
diff --git a/src/network/networkd-vlan.c b/src/network/networkd-vlan.c
new file mode 100644
index 0000000..1d812fd
--- /dev/null
+++ b/src/network/networkd-vlan.c
@@ -0,0 +1,147 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2013 Tom Gundersen <teg at jklm.no>
+
+ 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 <net/if.h>
+
+#include "networkd.h"
+#include "network-internal.h"
+#include "list.h"
+
+int netdev_create_vlan(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback) {
+ _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
+ const char *kind;
+ int r;
+
+ assert(netdev);
+ assert(netdev->kind == NETDEV_KIND_VLAN);
+ assert(link);
+ assert(callback);
+ assert(netdev->ifname);
+ assert(netdev->manager);
+ assert(netdev->manager->rtnl);
+
+ r = sd_rtnl_message_new_link(netdev->manager->rtnl, &req, RTM_NEWLINK, 0);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not allocate RTM_NEWLINK message: %s",
+ strerror(-r));
+ return r;
+ }
+
+ if (link) {
+ r = sd_rtnl_message_append_u32(req, IFLA_LINK, link->ifindex);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_LINK attribute: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
+ r = sd_rtnl_message_append_string(req, IFLA_IFNAME, netdev->ifname);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_IFNAME attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ if (netdev->mtu) {
+ r = sd_rtnl_message_append_u32(req, IFLA_MTU, netdev->mtu);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_MTU attribute: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
+ if (netdev->mac) {
+ r = sd_rtnl_message_append_ether_addr(req, IFLA_ADDRESS, netdev->mac);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Colud not append IFLA_ADDRESS attribute: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
+ r = sd_rtnl_message_open_container(req, IFLA_LINKINFO);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not open IFLA_LINKINFO container: %s",
+ strerror(-r));
+ return r;
+ }
+
+ kind = netdev_kind_to_string(netdev->kind);
+ if (!kind) {
+ log_error_netdev(netdev, "Invalid kind");
+ return -EINVAL;
+ }
+
+ r = sd_rtnl_message_open_container_union(req, IFLA_INFO_DATA, kind);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not open IFLA_INFO_DATA container: %s",
+ strerror(-r));
+ return r;
+ }
+
+ if (netdev->vlanid <= VLANID_MAX) {
+ r = sd_rtnl_message_append_u16(req, IFLA_VLAN_ID, netdev->vlanid);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_VLAN_ID attribute: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
+ r = sd_rtnl_message_close_container(req);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not close IFLA_INFO_DATA container %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_close_container(req);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not close IFLA_LINKINFO container %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_call_async(netdev->manager->rtnl, req, callback, link, 0, NULL);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not send rtnetlink message: %s", strerror(-r));
+ return r;
+ }
+
+ log_debug_netdev(netdev, "creating netdev");
+
+ netdev->state = NETDEV_STATE_CREATING;
+
+ return 0;
+}
diff --git a/src/network/networkd.h b/src/network/networkd.h
index e0232af..0ba9ee5 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -339,6 +339,8 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
/* NetDev */
+#define VLANID_MAX 4094
+
int netdev_load(Manager *manager);
void netdev_drop(NetDev *netdev);
@@ -354,6 +356,8 @@ int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t cb);
int netdev_create_tunnel(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback);
int netdev_create_veth(NetDev *netdev, sd_rtnl_message_handler_t callback);
int netdev_create_vxlan(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback);
+int netdev_create_vlan(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback);
+int netdev_create_macvlan(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback);
int netdev_create_dummy(NetDev *netdev, sd_rtnl_message_handler_t callback);
const char *netdev_kind_to_string(NetDevKind d) _const_;
More information about the systemd-commits
mailing list