From: Susant Sahani Date: Thu, 31 Aug 2017 16:51:03 +0000 (+0000) Subject: networkd: Allow tunnels to be created without .network (#6701) X-Git-Tag: v235~183 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4d7fa6de3b767f0cca6992b2e926f9020ff2bea4;p=platform%2Fupstream%2Fsystemd.git 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 --- diff --git a/man/systemd.netdev.xml b/man/systemd.netdev.xml index 1040562..9c4015e 100644 --- a/man/systemd.netdev.xml +++ b/man/systemd.netdev.xml @@ -847,6 +847,14 @@ + + Independent= + + A boolean. When true tunnel does not require .network file. Created as "tunnel@NONE". + Defaults to false. + + + diff --git a/src/network/netdev/netdev-gperf.gperf b/src/network/netdev/netdev-gperf.gperf index ab28caf..230dc1b 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 4388458..1cf72bf 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 67f4fab..64d87e5 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 d78c613..53690d9 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);