mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
network: rename Neighbor.MACAddress= to Neighbor.LinkLayerAddress=
And make it support IPv4 address. Closes #13015.
This commit is contained in:
parent
49808e0e2d
commit
b956364db0
@ -1016,9 +1016,9 @@
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><varname>MACAddress=</varname></term>
|
||||
<term><varname>LinkLayerAddress=</varname></term>
|
||||
<listitem>
|
||||
<para>The hardware address of the neighbor.</para>
|
||||
<para>The link layer address (MAC address or IP address) of the neighbor.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
@ -59,6 +59,7 @@ static int neighbor_new_static(Network *network, const char *filename, unsigned
|
||||
*neighbor = (Neighbor) {
|
||||
.network = network,
|
||||
.family = AF_UNSPEC,
|
||||
.lladdr_type = _NEIGHBOR_LLADDR_INVALID,
|
||||
};
|
||||
|
||||
LIST_APPEND(neighbors, network->neighbors, neighbor);
|
||||
@ -117,8 +118,8 @@ int neighbor_configure(Neighbor *neighbor, Link *link, link_netlink_message_hand
|
||||
|
||||
if (neighbor->family == AF_UNSPEC)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Neighbor without Address= configured");
|
||||
if (!neighbor->mac_configured)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Neighbor without MACAddress= configured");
|
||||
if (neighbor->lladdr_type < 0)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Neighbor without LinkLayerAddress= configured");
|
||||
|
||||
r = sd_rtnl_message_new_neigh(link->manager->rtnl, &req, RTM_NEWNEIGH,
|
||||
link->ifindex, neighbor->family);
|
||||
@ -133,7 +134,10 @@ int neighbor_configure(Neighbor *neighbor, Link *link, link_netlink_message_hand
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not set flags: %m");
|
||||
|
||||
r = sd_netlink_message_append_data(req, NDA_LLADDR, &neighbor->mac, sizeof(neighbor->mac));
|
||||
if (neighbor->lladdr_type == NEIGHBOR_LLADDR_MAC)
|
||||
r = sd_netlink_message_append_data(req, NDA_LLADDR, &neighbor->lladdr.mac, sizeof(neighbor->lladdr.mac));
|
||||
else
|
||||
r = sd_netlink_message_append_data(req, NDA_LLADDR, &neighbor->lladdr.ip.in, sizeof(neighbor->lladdr.ip.in));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append NDA_LLADDR attribute: %m");
|
||||
|
||||
@ -152,16 +156,17 @@ int neighbor_configure(Neighbor *neighbor, Link *link, link_netlink_message_hand
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_neighbor_address(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) {
|
||||
int config_parse_neighbor_address(
|
||||
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 = userdata;
|
||||
_cleanup_(neighbor_free_or_set_invalidp) Neighbor *n = NULL;
|
||||
@ -188,16 +193,17 @@ int config_parse_neighbor_address(const char *unit,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_neighbor_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) {
|
||||
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) {
|
||||
|
||||
Network *network = userdata;
|
||||
_cleanup_(neighbor_free_or_set_invalidp) Neighbor *n = NULL;
|
||||
@ -213,13 +219,56 @@ int config_parse_neighbor_hwaddr(const char *unit,
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = ether_addr_from_string(rvalue, &n->mac);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, r, "Neighbor MACAddress is invalid, ignoring assignment: %s", rvalue);
|
||||
return 0;
|
||||
r = ether_addr_from_string(rvalue, &n->lladdr.mac);
|
||||
if (r >= 0)
|
||||
n->lladdr_type = NEIGHBOR_LLADDR_MAC;
|
||||
else {
|
||||
r = in_addr_from_string(AF_INET, rvalue, &n->lladdr.ip);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, r, "Neighbor LinkLayerAddress= is invalid, ignoring assignment: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
n->lladdr_type = NEIGHBOR_LLADDR_IP;
|
||||
}
|
||||
|
||||
n->mac_configured = true;
|
||||
TAKE_PTR(n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_neighbor_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) {
|
||||
|
||||
Network *network = userdata;
|
||||
_cleanup_(neighbor_free_or_set_invalidp) Neighbor *n = NULL;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(section);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
r = neighbor_new_static(network, filename, section_line, &n);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = ether_addr_from_string(rvalue, &n->lladdr.mac);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, r, "Neighbor MACAddress= is invalid, ignoring assignment: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
n->lladdr_type = NEIGHBOR_LLADDR_MAC;
|
||||
TAKE_PTR(n);
|
||||
|
||||
return 0;
|
||||
|
@ -15,6 +15,13 @@ typedef struct Neighbor Neighbor;
|
||||
#include "networkd-network.h"
|
||||
#include "networkd-util.h"
|
||||
|
||||
typedef enum {
|
||||
NEIGHBOR_LLADDR_MAC,
|
||||
NEIGHBOR_LLADDR_IP,
|
||||
_NEIGHBOR_LLADDR_MAX,
|
||||
_NEIGHBOR_LLADDR_INVALID = -1,
|
||||
} NeighborLLAddressType;
|
||||
|
||||
struct Neighbor {
|
||||
Network *network;
|
||||
Link *link;
|
||||
@ -22,8 +29,11 @@ struct Neighbor {
|
||||
|
||||
int family;
|
||||
union in_addr_union in_addr;
|
||||
bool mac_configured;
|
||||
struct ether_addr mac;
|
||||
union {
|
||||
struct ether_addr mac;
|
||||
union in_addr_union ip;
|
||||
} lladdr;
|
||||
NeighborLLAddressType lladdr_type;
|
||||
|
||||
LIST_FIELDS(Neighbor, neighbors);
|
||||
};
|
||||
@ -36,3 +46,4 @@ int neighbor_configure(Neighbor *neighbor, Link *link, link_netlink_message_hand
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_neighbor_address);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_neighbor_hwaddr);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_neighbor_lladdr);
|
||||
|
@ -108,7 +108,8 @@ Address.Scope, config_parse_address_scope,
|
||||
IPv6AddressLabel.Prefix, config_parse_address_label_prefix, 0, 0
|
||||
IPv6AddressLabel.Label, config_parse_address_label, 0, 0
|
||||
Neighbor.Address, config_parse_neighbor_address, 0, 0
|
||||
Neighbor.MACAddress, config_parse_neighbor_hwaddr, 0, 0
|
||||
Neighbor.LinkLayerAddress, config_parse_neighbor_lladdr, 0, 0
|
||||
Neighbor.MACAddress, config_parse_neighbor_hwaddr, 0, 0 /* deprecated */
|
||||
RoutingPolicyRule.TypeOfService, config_parse_routing_policy_rule_tos, 0, 0
|
||||
RoutingPolicyRule.Priority, config_parse_routing_policy_rule_priority, 0, 0
|
||||
RoutingPolicyRule.Table, config_parse_routing_policy_rule_table, 0, 0
|
||||
|
@ -223,6 +223,7 @@ Managed=
|
||||
OtherInformation=
|
||||
[Neighbor]
|
||||
Address=
|
||||
LinkLayerAddress=
|
||||
MACAddress=
|
||||
[IPv6AddressLabel]
|
||||
Label=
|
||||
|
Loading…
Reference in New Issue
Block a user