conf-parser: move config_parse_ip_protocol() from network/netdev/fou-tunnel.c

The function is generic enough. Currently it is used at only one place.
But it will be used at another place.
This commit is contained in:
Yu Watanabe
2024-08-25 06:18:46 +09:00
parent 6db311fdc8
commit f7a1e57e1f
5 changed files with 39 additions and 43 deletions
-41
View File
@@ -142,47 +142,6 @@ 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) {
assert(filename);
assert(section);
assert(lvalue);
assert(rvalue);
uint8_t *proto = ASSERT_PTR(data);
int r;
r = parse_ip_protocol_full(rvalue, /* relaxed= */ true);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to parse '%s=%s', ignoring: %m",
lvalue, rvalue);
return 0;
}
if (r > UINT8_MAX) {
/* linux/fou.h defines the netlink field as one byte, so we need to reject
* protocols numbers that don't fit in one byte. */
log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid '%s=%s', allowed range is 0..255, ignoring.",
lvalue, rvalue);
return 0;
}
*proto = r;
return 0;
}
int config_parse_fou_tunnel_address(
const char *unit,
const char *filename,
-1
View File
@@ -38,5 +38,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);
CONFIG_PARSER_PROTOTYPE(config_parse_fou_tunnel_address);
+1 -1
View File
@@ -99,7 +99,7 @@ Tunnel.ERSPANHardwareId, config_parse_erspan_hwid,
Tunnel.SerializeTunneledPackets, config_parse_tristate, 0, offsetof(Tunnel, gre_erspan_sequence)
Tunnel.ISATAP, config_parse_tristate, 0, offsetof(Tunnel, isatap)
Tunnel.External, config_parse_bool, 0, offsetof(Tunnel, external)
FooOverUDP.Protocol, config_parse_ip_protocol, 0, offsetof(FouTunnel, fou_protocol)
FooOverUDP.Protocol, config_parse_ip_protocol, /* relax = */ true, 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)