diff options
author | Susant Sahani <ssahani@users.noreply.github.com> | 2017-08-31 16:51:03 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-08-31 18:51:03 +0200 |
commit | 4d7fa6de3b767f0cca6992b2e926f9020ff2bea4 (patch) | |
tree | 4c986e30f8dfe0c17511f012fd2e6fc6c5744482 | |
parent | 99f5f8e256600fb143b1c0d6b1a0813d02f4d9c7 (diff) | |
download | systemd-4d7fa6de3b767f0cca6992b2e926f9020ff2bea4.tar.gz |
networkd: Allow tunnels to be created without .network (#6701)
Now we don't support tunnels to be created without a .network file
that is we need a interface index.
This work allows tunnel to be created without a ifindex.
Closes #6695
-rw-r--r-- | man/systemd.netdev.xml | 8 | ||||
-rw-r--r-- | src/network/netdev/netdev-gperf.gperf | 1 | ||||
-rw-r--r-- | src/network/netdev/netdev.c | 41 | ||||
-rw-r--r-- | src/network/netdev/tunnel.c | 67 | ||||
-rw-r--r-- | src/network/netdev/tunnel.h | 1 |
5 files changed, 88 insertions, 30 deletions
diff --git a/man/systemd.netdev.xml b/man/systemd.netdev.xml index 1040562202..9c4015e621 100644 --- a/man/systemd.netdev.xml +++ b/man/systemd.netdev.xml @@ -847,6 +847,14 @@ </para> </listitem> </varlistentry> + <varlistentry> + <term><varname>Independent=</varname></term> + <listitem> + <para>A boolean. When true tunnel does not require .network file. Created as "tunnel@NONE". + Defaults to <literal>false</literal>. + </para> + </listitem> + </varlistentry> </variablelist> </refsect1> <refsect1> diff --git a/src/network/netdev/netdev-gperf.gperf b/src/network/netdev/netdev-gperf.gperf index ab28caf05d..230dc1b885 100644 --- a/src/network/netdev/netdev-gperf.gperf +++ b/src/network/netdev/netdev-gperf.gperf @@ -56,6 +56,7 @@ Tunnel.Mode, config_parse_ip6tnl_mode, 0, Tunnel.IPv6FlowLabel, config_parse_ipv6_flowlabel, 0, offsetof(Tunnel, ipv6_flowlabel) Tunnel.CopyDSCP, config_parse_bool, 0, offsetof(Tunnel, copy_dscp) Tunnel.EncapsulationLimit, config_parse_encap_limit, 0, offsetof(Tunnel, encap_limit) +Tunnel.Independent, config_parse_bool, 0, offsetof(Tunnel, independent) Peer.Name, config_parse_ifname, 0, offsetof(Veth, ifname_peer) Peer.MACAddress, config_parse_hwaddr, 0, offsetof(Veth, mac_peer) VXLAN.Id, config_parse_uint64, 0, offsetof(VxLan, id) diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c index 43884581ca..1cf72bf6d2 100644 --- a/src/network/netdev/netdev.c +++ b/src/network/netdev/netdev.c @@ -601,6 +601,7 @@ static int netdev_load_one(Manager *manager, const char *filename) { _cleanup_free_ NetDev *netdev_raw = NULL; _cleanup_fclose_ FILE *file = NULL; const char *dropin_dirname; + bool independent = false; int r; assert(manager); @@ -704,13 +705,51 @@ static int netdev_load_one(Manager *manager, const char *filename) { case NETDEV_CREATE_INDEPENDENT: r = netdev_create(netdev, NULL, NULL); if (r < 0) - return 0; + return r; + + break; + default: + break; + } + switch (netdev->kind) { + case NETDEV_KIND_IPIP: + independent = IPIP(netdev)->independent; + break; + case NETDEV_KIND_GRE: + independent = GRE(netdev)->independent; + break; + case NETDEV_KIND_GRETAP: + independent = GRETAP(netdev)->independent; + break; + case NETDEV_KIND_IP6GRE: + independent = IP6GRE(netdev)->independent; + break; + case NETDEV_KIND_IP6GRETAP: + independent = IP6GRETAP(netdev)->independent; + break; + case NETDEV_KIND_SIT: + independent = SIT(netdev)->independent; + break; + case NETDEV_KIND_VTI: + independent = VTI(netdev)->independent; + break; + case NETDEV_KIND_VTI6: + independent = VTI6(netdev)->independent; + break; + case NETDEV_KIND_IP6TNL: + independent = IP6TNL(netdev)->independent; break; default: break; } + if (independent) { + r = netdev_create(netdev, NULL, NULL); + if (r < 0) + return r; + } + netdev = NULL; return 0; diff --git a/src/network/netdev/tunnel.c b/src/network/netdev/tunnel.c index 67f4fab400..64d87e5e07 100644 --- a/src/network/netdev/tunnel.c +++ b/src/network/netdev/tunnel.c @@ -51,14 +51,16 @@ static int netdev_ipip_fill_message_create(NetDev *netdev, Link *link, sd_netlin int r; assert(netdev); - assert(link); assert(m); assert(t); assert(IN_SET(t->family, AF_INET, AF_UNSPEC)); - r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); - if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); + if (link) { + r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); + + } r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in); if (r < 0) @@ -84,14 +86,16 @@ static int netdev_sit_fill_message_create(NetDev *netdev, Link *link, sd_netlink int r; assert(netdev); - assert(link); assert(m); assert(t); assert(IN_SET(t->family, AF_INET, AF_UNSPEC)); - r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); - if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); + if (link) { + r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); + + } r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in); if (r < 0) @@ -125,12 +129,13 @@ static int netdev_gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink assert(t); assert(IN_SET(t->family, AF_INET, AF_UNSPEC)); - assert(link); assert(m); - r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex); - if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m"); + if (link) { + r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m"); + } r = sd_netlink_message_append_in_addr(m, IFLA_GRE_LOCAL, &t->local.in); if (r < 0) @@ -168,12 +173,13 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl assert(t); assert(t->family == AF_INET6); - assert(link); assert(m); - r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex); - if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m"); + if (link) { + r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m"); + } r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_LOCAL, &t->local.in6); if (r < 0) @@ -205,7 +211,6 @@ static int netdev_vti_fill_message_key(NetDev *netdev, Link *link, sd_netlink_me Tunnel *t; int r; - assert(link); assert(m); if (netdev->kind == NETDEV_KIND_VTI) @@ -243,9 +248,11 @@ static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink assert(t); assert(t->family == AF_INET); - r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex); - if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); + if (link) { + r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); + } r = netdev_vti_fill_message_key(netdev, link, m); if (r < 0) @@ -267,14 +274,15 @@ static int netdev_vti6_fill_message_create(NetDev *netdev, Link *link, sd_netlin int r; assert(netdev); - assert(link); assert(m); assert(t); assert(t->family == AF_INET6); - r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex); - if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); + if (link) { + r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); + } r = netdev_vti_fill_message_key(netdev, link, m); if (r < 0) @@ -297,14 +305,15 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl int r; assert(netdev); - assert(link); assert(m); assert(t); assert(t->family == AF_INET6); - r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); - if (r < 0) - return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); + if (link) { + r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); + } r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_LOCAL, &t->local.in6); if (r < 0) @@ -568,7 +577,7 @@ int config_parse_encap_limit(const char* unit, const char *section, unsigned section_line, const char *lvalue, - int ltype, + int ltype, const char *rvalue, void *data, void *userdata) { diff --git a/src/network/netdev/tunnel.h b/src/network/netdev/tunnel.h index d78c6135ee..53690d9075 100644 --- a/src/network/netdev/tunnel.h +++ b/src/network/netdev/tunnel.h @@ -60,6 +60,7 @@ typedef struct Tunnel { bool pmtudisc; bool copy_dscp; + bool independent; } Tunnel; DEFINE_NETDEV_CAST(IPIP, Tunnel); |