summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-09-18 20:59:34 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-09-18 20:59:34 +0200
commit91eaa90b818b8d8fbc7a77eae0c2eba4d0cf59e4 (patch)
treeca98936ba5c624fc46e2a3ff87507ef44a0b1edb
parentnetwork/neighbor: use struct in_addr_data (diff)
downloadsystemd-91eaa90b818b8d8fbc7a77eae0c2eba4d0cf59e4.tar.xz
systemd-91eaa90b818b8d8fbc7a77eae0c2eba4d0cf59e4.zip
network/neighbor: introduce generic Neighbor section parser
-rw-r--r--src/network/networkd-neighbor.c53
-rw-r--r--src/network/networkd-neighbor.h10
-rw-r--r--src/network/networkd-network-gperf.gperf6
3 files changed, 19 insertions, 50 deletions
diff --git a/src/network/networkd-neighbor.c b/src/network/networkd-neighbor.c
index aaf823ac01..9a03e12448 100644
--- a/src/network/networkd-neighbor.c
+++ b/src/network/networkd-neighbor.c
@@ -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;
-}
diff --git a/src/network/networkd-neighbor.h b/src/network/networkd-neighbor.h
index 0d67879a24..c306e407d3 100644
--- a/src/network/networkd-neighbor.h
+++ b/src/network/networkd-neighbor.h
@@ -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);
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index 9f23542493..9fda6960e0 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -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