From 4502a61c8a8061025a30a501d4b6cd144bb142e2 Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Wed, 15 May 2019 14:47:18 +0530 Subject: [PATCH] networkd: FOU tunnel support Local and Peer tunnel addresses --- man/systemd.netdev.xml | 12 ++++ src/network/netdev/fou-tunnel.c | 56 +++++++++++++++++++ src/network/netdev/fou-tunnel.h | 6 ++ src/network/netdev/netdev-gperf.gperf | 2 + .../fuzz/fuzz-netdev-parser/directives.netdev | 2 + 5 files changed, 78 insertions(+) diff --git a/man/systemd.netdev.xml b/man/systemd.netdev.xml index 42632a6540e..baef86c8b77 100644 --- a/man/systemd.netdev.xml +++ b/man/systemd.netdev.xml @@ -1298,6 +1298,18 @@ Encapsulation=GenericUDPEncapsulation, this must not be specified. + + Peer= + + Configures peer IP address. + + + + Local= + + Configures local IP address. + + diff --git a/src/network/netdev/fou-tunnel.c b/src/network/netdev/fou-tunnel.c index b5d4690f214..6ce2e5aec9a 100644 --- a/src/network/netdev/fou-tunnel.c +++ b/src/network/netdev/fou-tunnel.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ +#include #include #include #include @@ -69,6 +70,26 @@ static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message **r if (r < 0) return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_IPPROTO attribute: %m"); + if (t->local_family == AF_INET) { + r = sd_netlink_message_append_in_addr(m, FOU_ATTR_LOCAL_V4, &t->local.in); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_LOCAL_V4 attribute: %m"); + } else { + r = sd_netlink_message_append_in6_addr(m, FOU_ATTR_LOCAL_V6, &t->local.in6); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_LOCAL_V6 attribute: %m"); + } + + if (t->peer_family == AF_INET) { + r = sd_netlink_message_append_in_addr(m, FOU_ATTR_PEER_V4, &t->peer.in); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_PEER_V4 attribute: %m"); + } else { + r = sd_netlink_message_append_in6_addr(m, FOU_ATTR_PEER_V6, &t->peer.in6); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_PEER_V6 attribute: %m"); + } + *ret = TAKE_PTR(m); return 0; } @@ -150,6 +171,41 @@ int config_parse_ip_protocol( return 0; } +int config_parse_fou_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) { + + union in_addr_union *addr = data; + FouTunnel *t = userdata; + int r, *f; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + if (streq(lvalue, "Local")) + f = &t->local_family; + else + f = &t->peer_family; + + r = in_addr_from_string_auto(rvalue, f, addr); + if (r < 0) + log_syntax(unit, LOG_ERR, filename, line, r, + "Foo over UDP tunnel '%s' address is invalid, ignoring assignment: %s", + lvalue, rvalue); + + return 0; +} + static int netdev_fou_tunnel_verify(NetDev *netdev, const char *filename) { FouTunnel *t; diff --git a/src/network/netdev/fou-tunnel.h b/src/network/netdev/fou-tunnel.h index a93d2dc02f7..0402239c693 100644 --- a/src/network/netdev/fou-tunnel.h +++ b/src/network/netdev/fou-tunnel.h @@ -22,7 +22,12 @@ typedef struct FouTunnel { uint16_t port; + int local_family; + int peer_family; + FooOverUDPEncapType fou_encap_type; + union in_addr_union local; + union in_addr_union peer; } FouTunnel; DEFINE_NETDEV_CAST(FOU, FouTunnel); @@ -33,3 +38,4 @@ FooOverUDPEncapType fou_encap_type_from_string(const char *d) _pure_; CONFIG_PARSER_PROTOTYPE(config_parse_fou_encap_type); CONFIG_PARSER_PROTOTYPE(config_parse_ip_protocol); +CONFIG_PARSER_PROTOTYPE(config_parse_fou_tunnel_address); diff --git a/src/network/netdev/netdev-gperf.gperf b/src/network/netdev/netdev-gperf.gperf index e18d746befc..1e97e577747 100644 --- a/src/network/netdev/netdev-gperf.gperf +++ b/src/network/netdev/netdev-gperf.gperf @@ -79,6 +79,8 @@ Tunnel.ISATAP, config_parse_tristate, FooOverUDP.Protocol, config_parse_ip_protocol, 0, offsetof(FouTunnel, fou_protocol) FooOverUDP.Encapsulation, config_parse_fou_encap_type, 0, offsetof(FouTunnel, fou_encap_type) FooOverUDP.Port, config_parse_ip_port, 0, offsetof(FouTunnel, port) +FooOverUDP.Local, config_parse_fou_tunnel_address, 0, offsetof(FouTunnel, local) +FooOverUDP.Peer, config_parse_fou_tunnel_address, 0, offsetof(FouTunnel, peer) L2TP.TunnelId, config_parse_l2tp_tunnel_id, 0, offsetof(L2tpTunnel, tunnel_id) L2TP.PeerTunnelId, config_parse_l2tp_tunnel_id, 0, offsetof(L2tpTunnel, peer_tunnel_id) L2TP.UDPSourcePort, config_parse_ip_port, 0, offsetof(L2tpTunnel, l2tp_udp_sport) diff --git a/test/fuzz/fuzz-netdev-parser/directives.netdev b/test/fuzz/fuzz-netdev-parser/directives.netdev index 0b332a6e7a2..94bc06651dc 100644 --- a/test/fuzz/fuzz-netdev-parser/directives.netdev +++ b/test/fuzz/fuzz-netdev-parser/directives.netdev @@ -141,6 +141,8 @@ DynamicTransmitLoadBalancing= Protocol= Port= Encapsulation= +Local= +Peer= [Tap] MultiQueue= OneQueue=