From 7df5c6ba904c81fd27acba480400d06110e97ab5 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 31 Mar 2019 22:35:44 +0900 Subject: network: make FooOverUDP.Protocol= support name of ipproto --- src/network/netdev/fou-tunnel.c | 38 +++++++++++++++++++++++++++++++++++ src/network/netdev/fou-tunnel.h | 1 + src/network/netdev/netdev-gperf.gperf | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/network/netdev/fou-tunnel.c b/src/network/netdev/fou-tunnel.c index 73adceea9d..2d4481e060 100644 --- a/src/network/netdev/fou-tunnel.c +++ b/src/network/netdev/fou-tunnel.c @@ -5,6 +5,7 @@ #include #include "conf-parser.h" +#include "ip-protocol-list.h" #include "missing.h" #include "netdev/fou-tunnel.h" #include "netlink-util.h" @@ -112,6 +113,43 @@ static int netdev_fou_tunnel_create(NetDev *netdev) { return 0; } +int config_parse_ip_protocol( + 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) { + + uint8_t *protocol = data; + int r; + + assert(filename); + assert(section); + assert(lvalue); + assert(rvalue); + assert(data); + + assert_cc(IPPROTO_MAX-1 <= UINT8_MAX); + + r = parse_ip_protocol(rvalue); + if (r < 0) { + r = safe_atou8(rvalue, protocol); + if (r < 0) + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to parse IP protocol '%s' for Foo over UDP tunnel, " + "ignoring assignment: %m", rvalue); + return 0; + } + + *protocol = r; + 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 b8abed19bd..0e3fd7dd76 100644 --- a/src/network/netdev/fou-tunnel.h +++ b/src/network/netdev/fou-tunnel.h @@ -34,3 +34,4 @@ const char *fou_encap_type_to_string(FooOverUDPEncapType d) _const_; 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); diff --git a/src/network/netdev/netdev-gperf.gperf b/src/network/netdev/netdev-gperf.gperf index 1677e937b6..fcd2ec2097 100644 --- a/src/network/netdev/netdev-gperf.gperf +++ b/src/network/netdev/netdev-gperf.gperf @@ -75,7 +75,7 @@ Tunnel.IPv6RapidDeploymentPrefix, config_parse_6rd_prefix, 0, Tunnel.ERSPANIndex, config_parse_uint32, 0, offsetof(Tunnel, erspan_index) Tunnel.SerializeTunneledPackets, config_parse_tristate, 0, offsetof(Tunnel, gre_erspan_sequence) Tunnel.ISATAP, config_parse_tristate, 0, offsetof(Tunnel, isatap) -FooOverUDP.Protocol, config_parse_uint8, 0, offsetof(FouTunnel, fou_protocol) +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) L2TP.TunnelId, config_parse_l2tp_tunnel_id, 0, offsetof(L2tpTunnel, tunnel_id) -- cgit v1.2.1