mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 23:21:22 +03:00
networkd: add shared parser for mud urls
The same buggy code was triplicated…
This commit is contained in:
parent
bc1f27ff55
commit
89fa9a6b7b
@ -5,7 +5,6 @@
|
||||
#include <linux/if.h>
|
||||
#include <linux/if_arp.h>
|
||||
|
||||
#include "escape.h"
|
||||
#include "alloc-util.h"
|
||||
#include "dhcp-client-internal.h"
|
||||
#include "hostname-setup.h"
|
||||
@ -26,7 +25,6 @@
|
||||
#include "string-table.h"
|
||||
#include "strv.h"
|
||||
#include "sysctl-util.h"
|
||||
#include "web-util.h"
|
||||
|
||||
static int dhcp4_request_address_and_routes(Link *link, bool announce);
|
||||
static int dhcp4_remove_all(Link *link);
|
||||
@ -1733,34 +1731,12 @@ int config_parse_dhcp_mud_url(
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_free_ char *unescaped = NULL;
|
||||
Network *network = data;
|
||||
ssize_t l;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(network);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
network->dhcp_mudurl = mfree(network->dhcp_mudurl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
l = cunescape(rvalue, 0, &unescaped);
|
||||
if (l < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, l,
|
||||
"Failed to Failed to unescape MUD URL, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!http_url_is_valid(unescaped) || strlen(unescaped) > 255) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"Failed to parse MUD URL '%s', ignoring: %m", rvalue);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return free_and_strdup_warn(&network->dhcp_mudurl, unescaped);
|
||||
return config_parse_mud_url(unit, filename, line, section, section_line, lvalue, ltype, rvalue,
|
||||
&network->dhcp_mudurl);
|
||||
}
|
||||
|
||||
int config_parse_dhcp_fallback_lease_lifetime(const char *unit,
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include "sd-dhcp6-client.h"
|
||||
|
||||
#include "escape.h"
|
||||
#include "hashmap.h"
|
||||
#include "hostname-setup.h"
|
||||
#include "hostname-util.h"
|
||||
@ -24,7 +23,6 @@
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
#include "radv-internal.h"
|
||||
#include "web-util.h"
|
||||
|
||||
bool link_dhcp6_with_address_enabled(Link *link) {
|
||||
if (!link_dhcp6_enabled(link))
|
||||
@ -1812,33 +1810,12 @@ int config_parse_dhcp6_mud_url(
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_free_ char *unescaped = NULL;
|
||||
Network *network = data;
|
||||
ssize_t l;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(network);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
network->dhcp6_mudurl = mfree(network->dhcp6_mudurl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
l = cunescape(rvalue, 0, &unescaped);
|
||||
if (l < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, l,
|
||||
"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_WARNING, filename, line, 0,
|
||||
"Failed to parse MUD URL '%s', ignoring: %m", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return free_and_replace(network->dhcp6_mudurl, unescaped);
|
||||
return config_parse_mud_url(unit, filename, line, section, section_line, lvalue, ltype, rvalue,
|
||||
&network->dhcp6_mudurl);
|
||||
}
|
||||
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp6_client_start_mode, dhcp6_client_start_mode, DHCP6ClientStartMode,
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "env-file.h"
|
||||
#include "escape.h"
|
||||
#include "fd-util.h"
|
||||
#include "hostname-util.h"
|
||||
#include "missing_network.h"
|
||||
@ -21,7 +20,6 @@
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "unaligned.h"
|
||||
#include "web-util.h"
|
||||
|
||||
/* The LLDP spec calls this "txFastInit", see 9.2.5.19 */
|
||||
#define LLDP_TX_FAST_INIT 4U
|
||||
@ -428,29 +426,12 @@ int config_parse_lldp_mud(
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_free_ char *unescaped = NULL;
|
||||
Network *n = data;
|
||||
ssize_t l;
|
||||
Network *network = data;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(network);
|
||||
|
||||
l = cunescape(rvalue, 0, &unescaped);
|
||||
if (l < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, l,
|
||||
"Failed to Failed to unescape LLDP MUD URL, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!http_url_is_valid(unescaped) || strlen(unescaped) > 255) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"Failed to parse LLDP MUD URL '%s', ignoring: %m", rvalue);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return free_and_replace(n->lldp_mud, unescaped);
|
||||
return config_parse_mud_url(unit, filename, line, section, section_line, lvalue, ltype, rvalue,
|
||||
&network->lldp_mud);
|
||||
}
|
||||
|
||||
static const char * const lldp_emit_table[_LLDP_EMIT_MAX] = {
|
||||
|
@ -2,12 +2,13 @@
|
||||
|
||||
#include "condition.h"
|
||||
#include "conf-parser.h"
|
||||
#include "escape.h"
|
||||
#include "networkd-link.h"
|
||||
#include "networkd-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
#include "web-util.h"
|
||||
|
||||
static const char* const address_family_table[_ADDRESS_FAMILY_MAX] = {
|
||||
[ADDRESS_FAMILY_NO] = "no",
|
||||
@ -161,6 +162,41 @@ int config_parse_ip_masquerade(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_mud_url(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *section,
|
||||
unsigned section_line,
|
||||
const char *lvalue,
|
||||
int ltype,
|
||||
const char *rvalue,
|
||||
char **ret) {
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(ret);
|
||||
|
||||
_cleanup_free_ char *unescaped = NULL;
|
||||
ssize_t l;
|
||||
|
||||
l = cunescape(rvalue, 0, &unescaped);
|
||||
if (l < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, l,
|
||||
"Failed to unescape MUD URL, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (l > UINT8_MAX || !http_url_is_valid(unescaped)) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"Invalid MUD URL, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return free_and_replace(*ret, unescaped);
|
||||
}
|
||||
|
||||
/* Router lifetime can be set with netlink interface since kernel >= 4.5
|
||||
* so for the supported kernel we don't need to expire routes in userspace */
|
||||
int kernel_route_expiration_supported(void) {
|
||||
|
@ -23,6 +23,17 @@ CONFIG_PARSER_PROTOTYPE(config_parse_link_local_address_family);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_address_family_with_kernel);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ip_masquerade);
|
||||
|
||||
int config_parse_mud_url(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *section,
|
||||
unsigned section_line,
|
||||
const char *lvalue,
|
||||
int ltype,
|
||||
const char *rvalue,
|
||||
char **ret);
|
||||
|
||||
const char *address_family_to_string(AddressFamily b) _const_;
|
||||
AddressFamily address_family_from_string(const char *s) _pure_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user