]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: FOU tunnel support Local and Peer tunnel addresses 12576/head
authorSusant Sahani <ssahani@gmail.com>
Wed, 15 May 2019 09:17:18 +0000 (14:47 +0530)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 16 May 2019 01:24:48 +0000 (10:24 +0900)
man/systemd.netdev.xml
src/network/netdev/fou-tunnel.c
src/network/netdev/fou-tunnel.h
src/network/netdev/netdev-gperf.gperf
test/fuzz/fuzz-netdev-parser/directives.netdev

index 42632a6540ec6212833ee5d925015a29097bc417..baef86c8b77a100240e96d8694eb6869a63b6011 100644 (file)
           <varname>Encapsulation=GenericUDPEncapsulation</varname>, this must not be specified.</para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term><varname>Peer=</varname></term>
+        <listitem>
+          <para>Configures peer IP address.</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><varname>Local=</varname></term>
+        <listitem>
+          <para>Configures local IP address.</para>
+        </listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
   <refsect1>
index b5d4690f2149db1b326c22d716458fc2b537538f..6ce2e5aec9ac6f525f699bc18647e4038e52ebd5 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
+#include <linux/fou.h>
 #include <net/if.h>
 #include <netinet/in.h>
 #include <linux/ip.h>
@@ -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;
 
index a93d2dc02f711e05188ed06cc909ea6a1b736e89..0402239c6931381cc076e06d3b9a52da7cb945ca 100644 (file)
@@ -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);
index e18d746befc9248182b85035af22e8881b51e769..1e97e577747a151f3354585633dc51d19dded814 100644 (file)
@@ -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)
index 0b332a6e7a280f07c20b0fc718f817bfe616e17e..94bc06651dc811feb4e7e79335749d957ad73063 100644 (file)
@@ -141,6 +141,8 @@ DynamicTransmitLoadBalancing=
 Protocol=
 Port=
 Encapsulation=
+Local=
+Peer=
 [Tap]
 MultiQueue=
 OneQueue=