From: Yu Watanabe Date: Mon, 1 Jun 2020 04:18:22 +0000 (+0900) Subject: network: move DHCPv6 related conf parsers to networkd-dhcp6.c X-Git-Tag: v246-rc1~219^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c24dd7395284be83ce7f3ec8ca3a42fc2751000e;p=thirdparty%2Fsystemd.git network: move DHCPv6 related conf parsers to networkd-dhcp6.c --- diff --git a/src/network/networkd-dhcp-common.c b/src/network/networkd-dhcp-common.c index 9b30764c81f..cc0a490b1d1 100644 --- a/src/network/networkd-dhcp-common.c +++ b/src/network/networkd-dhcp-common.c @@ -9,7 +9,6 @@ #include "parse-util.h" #include "string-table.h" #include "strv.h" -#include "web-util.h" int config_parse_dhcp( const char* unit, @@ -296,41 +295,6 @@ int config_parse_iaid(const char *unit, return 0; } -int config_parse_dhcp6_pd_hint( - 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) { - - Network *network = data; - int r; - - assert(filename); - assert(lvalue); - assert(rvalue); - assert(data); - - r = in_addr_prefix_from_string(rvalue, AF_INET6, (union in_addr_union *) &network->dhcp6_pd_address, &network->dhcp6_pd_length); - if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse PrefixDelegationHint=%s, ignoring assignment", rvalue); - return 0; - } - - if (network->dhcp6_pd_length < 1 || network->dhcp6_pd_length > 128) { - log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid prefix length='%d', ignoring assignment", network->dhcp6_pd_length); - network->dhcp6_pd_length = 0; - return 0; - } - - return 0; -} - int config_parse_dhcp_user_class( const char *unit, const char *filename, @@ -446,47 +410,6 @@ int config_parse_dhcp_vendor_class( return 0; } -int config_parse_dhcp6_mud_url( - 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) { - _cleanup_free_ char *unescaped = NULL; - Network *network = data; - int r; - - assert(filename); - assert(lvalue); - assert(rvalue); - - if (isempty(rvalue)) { - network->dhcp6_mudurl = mfree(network->dhcp6_mudurl); - return 0; - } - - r = cunescape(rvalue, 0, &unescaped); - if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, r, - "Failed to Failed to unescape MUD URL, ignoring: %s", rvalue); - return 0; - } - - if (!http_url_is_valid(unescaped) || strlen(unescaped) > UINT8_MAX) { - log_syntax(unit, LOG_ERR, filename, line, 0, - "Failed to parse MUD URL '%s', ignoring: %m", rvalue); - - return 0; - } - - return free_and_replace(network->dhcp6_mudurl, unescaped); -} - int config_parse_dhcp_send_option( const char *unit, const char *filename, diff --git a/src/network/networkd-dhcp-common.h b/src/network/networkd-dhcp-common.h index dd574f1d569..2be9abba62c 100644 --- a/src/network/networkd-dhcp-common.h +++ b/src/network/networkd-dhcp-common.h @@ -49,8 +49,6 @@ CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_ntp); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_sip); CONFIG_PARSER_PROTOTYPE(config_parse_iaid); CONFIG_PARSER_PROTOTYPE(config_parse_section_route_table); -CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_pd_hint); -CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_mud_url); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_user_class); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_vendor_class); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_option); diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index 6a1083fd5c9..f86fdc21036 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -10,6 +10,7 @@ #include "sd-dhcp6-client.h" +#include "escape.h" #include "hashmap.h" #include "hostname-util.h" #include "missing_network.h" @@ -20,6 +21,7 @@ #include "siphash24.h" #include "string-util.h" #include "radv-internal.h" +#include "web-util.h" static int dhcp6_lease_address_acquired(sd_dhcp6_client *client, Link *link); static Link *dhcp6_prefix_get(Manager *m, struct in6_addr *addr); @@ -1077,3 +1079,79 @@ static int dhcp6_assign_delegated_prefix(Link *link, return 0; } + +int config_parse_dhcp6_pd_hint( + 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) { + + Network *network = data; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + r = in_addr_prefix_from_string(rvalue, AF_INET6, (union in_addr_union *) &network->dhcp6_pd_address, &network->dhcp6_pd_length); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse PrefixDelegationHint=%s, ignoring assignment", rvalue); + return 0; + } + + if (network->dhcp6_pd_length < 1 || network->dhcp6_pd_length > 128) { + log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid prefix length='%d', ignoring assignment", network->dhcp6_pd_length); + network->dhcp6_pd_length = 0; + return 0; + } + + return 0; +} + +int config_parse_dhcp6_mud_url( + 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) { + _cleanup_free_ char *unescaped = NULL; + Network *network = data; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + + if (isempty(rvalue)) { + network->dhcp6_mudurl = mfree(network->dhcp6_mudurl); + return 0; + } + + r = cunescape(rvalue, 0, &unescaped); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to Failed to unescape MUD URL, ignoring: %s", rvalue); + return 0; + } + + if (!http_url_is_valid(unescaped) || strlen(unescaped) > UINT8_MAX) { + log_syntax(unit, LOG_ERR, filename, line, 0, + "Failed to parse MUD URL '%s', ignoring: %m", rvalue); + + return 0; + } + + return free_and_replace(network->dhcp6_mudurl, unescaped); +} diff --git a/src/network/networkd-dhcp6.h b/src/network/networkd-dhcp6.h index 26d810f40c3..e7c180897bf 100644 --- a/src/network/networkd-dhcp6.h +++ b/src/network/networkd-dhcp6.h @@ -13,3 +13,6 @@ int dhcp6_configure(Link *link); int dhcp6_request_address(Link *link, int ir); int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link); int dhcp6_prefix_remove(Manager *m, struct in6_addr *addr); + +CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_pd_hint); +CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_mud_url); diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index c6b9cb8ddcf..b3dde3bfac6 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -11,6 +11,7 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"") #include "networkd-dhcp-common.h" #include "networkd-dhcp-server.h" #include "networkd-dhcp4.h" +#include "networkd-dhcp6.h" #include "networkd-ipv4ll.h" #include "networkd-ndisc.h" #include "networkd-network.h"