]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: FOU netdev add support to configure peer port
authorSusant Sahani <ssahani@gmail.com>
Thu, 16 May 2019 06:46:19 +0000 (12:16 +0530)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 18 May 2019 01:25:36 +0000 (10:25 +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 0b0fff1f654ebe6b843308ef20d8258666965b6d..c746ed31f82b25e5df2b507f81475657bf0e8ae0 100644 (file)
           for delivery to the real destination. This option is mandatory.</para>
         </listitem>
         </varlistentry>
+      <varlistentry>
+        <term><varname>PeerPort=</varname></term>
+        <listitem>
+          <para>Specifies the peer port number. Defaults to unset. Note that when peer port is set <literal>Peer=</literal> address is mandotory.</para>
+        </listitem>
+        </varlistentry>
       <varlistentry>
         <term><varname>Protocol=</varname></term>
         <listitem>
       <varlistentry>
         <term><varname>Peer=</varname></term>
         <listitem>
-          <para>Configures peer IP address.</para>
+          <para>Configures peer IP address. Note that when peer address is set <literal>PeerPort=</literal> is mandotory.</para>
         </listitem>
       </varlistentry>
       <varlistentry>
index 6ce2e5aec9ac6f525f699bc18647e4038e52ebd5..772f3db5e7b483584695b788ba5268966bc19cc7 100644 (file)
@@ -47,6 +47,12 @@ 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_PORT attribute: %m");
 
+        if (IN_SET(t->peer_family, AF_INET, AF_INET6)) {
+                r = sd_netlink_message_append_u16(m, FOU_ATTR_PEER_PORT, htobe16(t->peer_port));
+                if (r < 0)
+                        return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_PEER_PORT attribute: %m");
+        }
+
         switch (t->fou_encap_type) {
         case NETDEV_FOO_OVER_UDP_ENCAP_DIRECT:
                 encap_type = FOU_ENCAP_DIRECT;
@@ -74,7 +80,7 @@ static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message **r
                 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 {
+        } else if (t->local_family == AF_INET6) {
                 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");
@@ -84,7 +90,7 @@ static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message **r
                 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 {
+        } else if (t->peer_family == AF_INET6){
                 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");
@@ -233,6 +239,14 @@ static int netdev_fou_tunnel_verify(NetDev *netdev, const char *filename) {
                 assert_not_reached("Invalid fou encap type");
         }
 
+        if (t->peer_family == AF_UNSPEC && t->peer_port > 0)
+                return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
+                                              "FooOverUDP peer port is set but peer address not configured in %s. Rejecting configuration.",
+                                              filename);
+        else if (t->peer_family != AF_UNSPEC && t->peer_port == 0)
+                return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
+                                              "FooOverUDP peer port not set but peer address is configured in %s. Rejecting configuration.",
+                                              filename);
         return 0;
 }
 
index 0402239c6931381cc076e06d3b9a52da7cb945ca..6304e6b54927ea7ac6bae6d417ce376d90190a9f 100644 (file)
@@ -21,6 +21,7 @@ typedef struct FouTunnel {
         uint8_t fou_protocol;
 
         uint16_t port;
+        uint16_t peer_port;
 
         int local_family;
         int peer_family;
index 0e712c55ae4ea05b73ad482b9afaf46725ff5d52..6a6d9dc7520bcad9779c8dfcd1e8d50e8a841d16 100644 (file)
@@ -81,6 +81,7 @@ 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.PeerPort,                      config_parse_ip_port,                      0,                             offsetof(FouTunnel, peer_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)
index 2f152cbd6de03007ff5dcb7af16f129eebf3186e..d2e10c71bd1a92adedc6f82bbad892be0ac26043 100644 (file)
@@ -140,6 +140,7 @@ DynamicTransmitLoadBalancing=
 [FooOverUDP]
 Protocol=
 Port=
+PeerPort=
 Encapsulation=
 Local=
 Peer=