Skip to content

Commit 4502a61

Browse files
ssahaniyuwata
authored andcommitted
networkd: FOU tunnel support Local and Peer tunnel addresses
1 parent 397a74d commit 4502a61

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

man/systemd.netdev.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,18 @@
12981298
<varname>Encapsulation=GenericUDPEncapsulation</varname>, this must not be specified.</para>
12991299
</listitem>
13001300
</varlistentry>
1301+
<varlistentry>
1302+
<term><varname>Peer=</varname></term>
1303+
<listitem>
1304+
<para>Configures peer IP address.</para>
1305+
</listitem>
1306+
</varlistentry>
1307+
<varlistentry>
1308+
<term><varname>Local=</varname></term>
1309+
<listitem>
1310+
<para>Configures local IP address.</para>
1311+
</listitem>
1312+
</varlistentry>
13011313
</variablelist>
13021314
</refsect1>
13031315
<refsect1>

src/network/netdev/fou-tunnel.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* SPDX-License-Identifier: LGPL-2.1+ */
22

3+
#include <linux/fou.h>
34
#include <net/if.h>
45
#include <netinet/in.h>
56
#include <linux/ip.h>
@@ -69,6 +70,26 @@ static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message **r
6970
if (r < 0)
7071
return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_IPPROTO attribute: %m");
7172

73+
if (t->local_family == AF_INET) {
74+
r = sd_netlink_message_append_in_addr(m, FOU_ATTR_LOCAL_V4, &t->local.in);
75+
if (r < 0)
76+
return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_LOCAL_V4 attribute: %m");
77+
} else {
78+
r = sd_netlink_message_append_in6_addr(m, FOU_ATTR_LOCAL_V6, &t->local.in6);
79+
if (r < 0)
80+
return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_LOCAL_V6 attribute: %m");
81+
}
82+
83+
if (t->peer_family == AF_INET) {
84+
r = sd_netlink_message_append_in_addr(m, FOU_ATTR_PEER_V4, &t->peer.in);
85+
if (r < 0)
86+
return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_PEER_V4 attribute: %m");
87+
} else {
88+
r = sd_netlink_message_append_in6_addr(m, FOU_ATTR_PEER_V6, &t->peer.in6);
89+
if (r < 0)
90+
return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_PEER_V6 attribute: %m");
91+
}
92+
7293
*ret = TAKE_PTR(m);
7394
return 0;
7495
}
@@ -150,6 +171,41 @@ int config_parse_ip_protocol(
150171
return 0;
151172
}
152173

174+
int config_parse_fou_tunnel_address(
175+
const char *unit,
176+
const char *filename,
177+
unsigned line,
178+
const char *section,
179+
unsigned section_line,
180+
const char *lvalue,
181+
int ltype,
182+
const char *rvalue,
183+
void *data,
184+
void *userdata) {
185+
186+
union in_addr_union *addr = data;
187+
FouTunnel *t = userdata;
188+
int r, *f;
189+
190+
assert(filename);
191+
assert(lvalue);
192+
assert(rvalue);
193+
assert(data);
194+
195+
if (streq(lvalue, "Local"))
196+
f = &t->local_family;
197+
else
198+
f = &t->peer_family;
199+
200+
r = in_addr_from_string_auto(rvalue, f, addr);
201+
if (r < 0)
202+
log_syntax(unit, LOG_ERR, filename, line, r,
203+
"Foo over UDP tunnel '%s' address is invalid, ignoring assignment: %s",
204+
lvalue, rvalue);
205+
206+
return 0;
207+
}
208+
153209
static int netdev_fou_tunnel_verify(NetDev *netdev, const char *filename) {
154210
FouTunnel *t;
155211

src/network/netdev/fou-tunnel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ typedef struct FouTunnel {
2222

2323
uint16_t port;
2424

25+
int local_family;
26+
int peer_family;
27+
2528
FooOverUDPEncapType fou_encap_type;
29+
union in_addr_union local;
30+
union in_addr_union peer;
2631
} FouTunnel;
2732

2833
DEFINE_NETDEV_CAST(FOU, FouTunnel);
@@ -33,3 +38,4 @@ FooOverUDPEncapType fou_encap_type_from_string(const char *d) _pure_;
3338

3439
CONFIG_PARSER_PROTOTYPE(config_parse_fou_encap_type);
3540
CONFIG_PARSER_PROTOTYPE(config_parse_ip_protocol);
41+
CONFIG_PARSER_PROTOTYPE(config_parse_fou_tunnel_address);

src/network/netdev/netdev-gperf.gperf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ Tunnel.ISATAP, config_parse_tristate,
7979
FooOverUDP.Protocol, config_parse_ip_protocol, 0, offsetof(FouTunnel, fou_protocol)
8080
FooOverUDP.Encapsulation, config_parse_fou_encap_type, 0, offsetof(FouTunnel, fou_encap_type)
8181
FooOverUDP.Port, config_parse_ip_port, 0, offsetof(FouTunnel, port)
82+
FooOverUDP.Local, config_parse_fou_tunnel_address, 0, offsetof(FouTunnel, local)
83+
FooOverUDP.Peer, config_parse_fou_tunnel_address, 0, offsetof(FouTunnel, peer)
8284
L2TP.TunnelId, config_parse_l2tp_tunnel_id, 0, offsetof(L2tpTunnel, tunnel_id)
8385
L2TP.PeerTunnelId, config_parse_l2tp_tunnel_id, 0, offsetof(L2tpTunnel, peer_tunnel_id)
8486
L2TP.UDPSourcePort, config_parse_ip_port, 0, offsetof(L2tpTunnel, l2tp_udp_sport)

test/fuzz/fuzz-netdev-parser/directives.netdev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ DynamicTransmitLoadBalancing=
141141
Protocol=
142142
Port=
143143
Encapsulation=
144+
Local=
145+
Peer=
144146
[Tap]
145147
MultiQueue=
146148
OneQueue=

0 commit comments

Comments
 (0)