mirror of
https://github.com/systemd/systemd.git
synced 2025-08-29 01:49:55 +03:00
network/neighbor: introduce generic Neighbor section parser
This commit is contained in:
@ -728,7 +728,7 @@ int network_drop_invalid_neighbors(Network *network) {
|
||||
}
|
||||
|
||||
|
||||
int config_parse_neighbor_address(
|
||||
int config_parse_neighbor_section(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
@ -740,6 +740,11 @@ int config_parse_neighbor_address(
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
static const ConfigSectionParser table[_NEIGHBOR_CONF_PARSER_MAX] = {
|
||||
[NEIGHBOR_DESTINATION_ADDRESS] = { .parser = config_parse_in_addr_data, .ltype = 0, .offset = offsetof(Neighbor, dst_addr), },
|
||||
[NEIGHBOR_LINK_LAYER_ADDRESS] = { .parser = config_parse_hw_addr, .ltype = 0, .offset = offsetof(Neighbor, ll_addr), },
|
||||
};
|
||||
|
||||
_cleanup_(neighbor_unref_or_set_invalidp) Neighbor *neighbor = NULL;
|
||||
Network *network = ASSERT_PTR(userdata);
|
||||
int r;
|
||||
@ -750,53 +755,11 @@ int config_parse_neighbor_address(
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
r = config_parse_in_addr_data(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &neighbor->dst_addr, NULL);
|
||||
r = config_section_parse(table, ELEMENTSOF(table),
|
||||
unit, filename, line, section, section_line, lvalue, ltype, rvalue, neighbor);
|
||||
if (r <= 0) /* 0 means non-critical error, but the section will be ignored. */
|
||||
return r;
|
||||
|
||||
TAKE_PTR(neighbor);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_neighbor_lladdr(
|
||||
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_(neighbor_unref_or_set_invalidp) Neighbor *n = NULL;
|
||||
Network *network = ASSERT_PTR(userdata);
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(section);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
r = neighbor_new_static(network, filename, section_line, &n);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
n->ll_addr = HW_ADDR_NULL;
|
||||
TAKE_PTR(n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = parse_hw_addr(rvalue, &n->ll_addr);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Neighbor %s= is invalid, ignoring assignment: %s",
|
||||
lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
TAKE_PTR(n);
|
||||
return 0;
|
||||
}
|
||||
|
@ -45,5 +45,11 @@ int manager_rtnl_process_neighbor(sd_netlink *rtnl, sd_netlink_message *message,
|
||||
|
||||
DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(Neighbor, neighbor);
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_neighbor_address);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_neighbor_lladdr);
|
||||
typedef enum NeighborConfParserType {
|
||||
NEIGHBOR_DESTINATION_ADDRESS,
|
||||
NEIGHBOR_LINK_LAYER_ADDRESS,
|
||||
_NEIGHBOR_CONF_PARSER_MAX,
|
||||
_NEIGHBOR_CONF_PARSER_INVALID = -EINVAL,
|
||||
} NeighborConfParserType;
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_neighbor_section);
|
||||
|
@ -173,9 +173,9 @@ Address.NetLabel, config_parse_address_section,
|
||||
Address.NFTSet, config_parse_address_section, ADDRESS_NFT_SET, 0
|
||||
IPv6AddressLabel.Prefix, config_parse_ipv6_address_label_section, IPV6_ADDRESS_LABEL_PREFIX, 0
|
||||
IPv6AddressLabel.Label, config_parse_ipv6_address_label_section, IPV6_ADDRESS_LABEL, 0
|
||||
Neighbor.Address, config_parse_neighbor_address, 0, 0
|
||||
Neighbor.LinkLayerAddress, config_parse_neighbor_lladdr, 0, 0
|
||||
Neighbor.MACAddress, config_parse_neighbor_lladdr, 0, 0 /* deprecated */
|
||||
Neighbor.Address, config_parse_neighbor_section, NEIGHBOR_DESTINATION_ADDRESS, 0
|
||||
Neighbor.LinkLayerAddress, config_parse_neighbor_section, NEIGHBOR_LINK_LAYER_ADDRESS, 0
|
||||
Neighbor.MACAddress, config_parse_neighbor_section, NEIGHBOR_LINK_LAYER_ADDRESS, 0 /* deprecated */
|
||||
RoutingPolicyRule.TypeOfService, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_TOS, 0
|
||||
RoutingPolicyRule.Priority, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_PRIORITY, 0
|
||||
RoutingPolicyRule.GoTo, config_parse_routing_policy_rule, ROUTING_POLICY_RULE_GOTO, 0
|
||||
|
Reference in New Issue
Block a user