summaryrefslogtreecommitdiffstats
path: root/src/network/netdev/fou-tunnel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/netdev/fou-tunnel.c')
-rw-r--r--src/network/netdev/fou-tunnel.c50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/network/netdev/fou-tunnel.c b/src/network/netdev/fou-tunnel.c
index bc4c108a22..cd8f2f8087 100644
--- a/src/network/netdev/fou-tunnel.c
+++ b/src/network/netdev/fou-tunnel.c
@@ -24,30 +24,21 @@ DEFINE_STRING_TABLE_LOOKUP(fou_encap_type, FooOverUDPEncapType);
DEFINE_CONFIG_PARSE_ENUM(config_parse_fou_encap_type, fou_encap_type, FooOverUDPEncapType,
"Failed to parse Encapsulation=");
-static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message **ret) {
- _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
+static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message *m) {
FouTunnel *t;
uint8_t encap_type;
int r;
- assert(netdev);
-
- t = FOU(netdev);
-
- assert(t);
-
- r = sd_genl_message_new(netdev->manager->genl, FOU_GENL_NAME, FOU_CMD_ADD, &m);
- if (r < 0)
- return log_netdev_error_errno(netdev, r, "Failed to allocate generic netlink message: %m");
+ assert_se(t = FOU(netdev));
r = sd_netlink_message_append_u16(m, FOU_ATTR_PORT, htobe16(t->port));
if (r < 0)
- return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_PORT attribute: %m");
+ return r;
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");
+ return r;
}
switch (t->fou_encap_type) {
@@ -63,36 +54,53 @@ static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message **r
r = sd_netlink_message_append_u8(m, FOU_ATTR_TYPE, encap_type);
if (r < 0)
- return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_TYPE attribute: %m");
+ return r;
r = sd_netlink_message_append_u8(m, FOU_ATTR_AF, AF_INET);
if (r < 0)
- return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_AF attribute: %m");
+ return r;
r = sd_netlink_message_append_u8(m, FOU_ATTR_IPPROTO, t->fou_protocol);
if (r < 0)
- return log_netdev_error_errno(netdev, r, "Could not append FOU_ATTR_IPPROTO attribute: %m");
+ return r;
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");
+ return r;
} 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");
+ return r;
}
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");
+ return r;
} 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");
+ return r;
}
+ return 0;
+}
+
+static int netdev_create_fou_tunnel_message(NetDev *netdev, sd_netlink_message **ret) {
+ _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
+ int r;
+
+ assert(netdev);
+
+ r = sd_genl_message_new(netdev->manager->genl, FOU_GENL_NAME, FOU_CMD_ADD, &m);
+ if (r < 0)
+ return log_netdev_error_errno(netdev, r, "Could not allocate netlink message: %m");
+
+ r = netdev_fill_fou_tunnel_message(netdev, m);
+ if (r < 0)
+ return log_netdev_error_errno(netdev, r, "Could not create netlink message: %m");
+
*ret = TAKE_PTR(m);
return 0;
}
@@ -124,7 +132,7 @@ static int netdev_fou_tunnel_create(NetDev *netdev) {
assert(netdev);
assert(FOU(netdev));
- r = netdev_fill_fou_tunnel_message(netdev, &m);
+ r = netdev_create_fou_tunnel_message(netdev, &m);
if (r < 0)
return r;