libsystemd-network: move config_parse_hwaddr() and config_parse_hwaddrs()
This commit is contained in:
parent
fc27088ae7
commit
0ec2a7a125
|
@ -485,106 +485,6 @@ int config_parse_match_property(
|
|||
}
|
||||
}
|
||||
|
||||
int config_parse_hwaddr(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_ struct ether_addr *n = NULL;
|
||||
struct ether_addr **hwaddr = data;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*hwaddr = mfree(*hwaddr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
n = new0(struct ether_addr, 1);
|
||||
if (!n)
|
||||
return log_oom();
|
||||
|
||||
r = ether_addr_from_string(rvalue, n);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Not a valid MAC address, ignoring assignment: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
free_and_replace(*hwaddr, n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_hwaddrs(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) {
|
||||
|
||||
Set **hwaddrs = data;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
/* Empty assignment resets the list */
|
||||
*hwaddrs = set_free_free(*hwaddrs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *word = NULL;
|
||||
_cleanup_free_ struct ether_addr *n = NULL;
|
||||
|
||||
r = extract_first_word(&p, &word, NULL, 0);
|
||||
if (r == 0)
|
||||
return 0;
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Invalid syntax, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
n = new(struct ether_addr, 1);
|
||||
if (!n)
|
||||
return log_oom();
|
||||
|
||||
r = ether_addr_from_string(word, n);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Not a valid MAC address, ignoring: %s", word);
|
||||
continue;
|
||||
}
|
||||
|
||||
r = set_ensure_put(hwaddrs, ðer_addr_hash_ops, n);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
if (r > 0)
|
||||
TAKE_PTR(n); /* avoid cleanup */
|
||||
}
|
||||
}
|
||||
|
||||
size_t serialize_in_addrs(FILE *f,
|
||||
const struct in_addr *addresses,
|
||||
size_t size,
|
||||
|
|
|
@ -34,8 +34,6 @@ bool net_match_config(Set *match_mac,
|
|||
const struct ether_addr *dev_bssid);
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_net_condition);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_hwaddr);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_hwaddrs);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_match_strv);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_match_ifnames);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_match_property);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "conf-files.h"
|
||||
#include "conf-parser.h"
|
||||
#include "def.h"
|
||||
#include "ether-addr-util.h"
|
||||
#include "extract-word.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
|
@ -24,6 +25,7 @@
|
|||
#include "process-util.h"
|
||||
#include "rlimit-util.h"
|
||||
#include "sd-id128.h"
|
||||
#include "set.h"
|
||||
#include "signal-util.h"
|
||||
#include "socket-util.h"
|
||||
#include "string-util.h"
|
||||
|
@ -1244,4 +1246,106 @@ int config_parse_vlanprotocol(const char* unit,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_hwaddr(
|
||||
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_ struct ether_addr *n = NULL;
|
||||
struct ether_addr **hwaddr = data;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*hwaddr = mfree(*hwaddr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
n = new0(struct ether_addr, 1);
|
||||
if (!n)
|
||||
return log_oom();
|
||||
|
||||
r = ether_addr_from_string(rvalue, n);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Not a valid MAC address, ignoring assignment: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
free_and_replace(*hwaddr, n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_hwaddrs(
|
||||
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) {
|
||||
|
||||
Set **hwaddrs = data;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
/* Empty assignment resets the list */
|
||||
*hwaddrs = set_free_free(*hwaddrs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *word = NULL;
|
||||
_cleanup_free_ struct ether_addr *n = NULL;
|
||||
|
||||
r = extract_first_word(&p, &word, NULL, 0);
|
||||
if (r == 0)
|
||||
return 0;
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Invalid syntax, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
n = new(struct ether_addr, 1);
|
||||
if (!n)
|
||||
return log_oom();
|
||||
|
||||
r = ether_addr_from_string(word, n);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Not a valid MAC address, ignoring: %s", word);
|
||||
continue;
|
||||
}
|
||||
|
||||
r = set_ensure_put(hwaddrs, ðer_addr_hash_ops, n);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
if (r > 0)
|
||||
TAKE_PTR(n); /* avoid cleanup */
|
||||
}
|
||||
}
|
||||
|
||||
DEFINE_CONFIG_PARSE(config_parse_percent, parse_percent, "Failed to parse percent value");
|
||||
|
|
|
@ -147,6 +147,8 @@ CONFIG_PARSER_PROTOTYPE(config_parse_ip_port);
|
|||
CONFIG_PARSER_PROTOTYPE(config_parse_mtu);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_rlimit);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_vlanprotocol);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_hwaddr);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_hwaddrs);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_percent);
|
||||
|
||||
typedef enum Disabled {
|
||||
|
|
Loading…
Reference in a new issue