summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author1848 <nomail>2019-07-17 19:43:35 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-07-19 07:14:58 +0900
commitf9ab224eb8eba3e52ecb49695894433dee5184ea (patch)
treeb964c542a3f3e873f286828fd7edf4efd6def554 /src
parent34d2f9204cf80cc003ef16b619457e79d0ba1c01 (diff)
downloadsystemd-f9ab224eb8eba3e52ecb49695894433dee5184ea.tar.gz
systemd-f9ab224eb8eba3e52ecb49695894433dee5184ea.tar.bz2
systemd-f9ab224eb8eba3e52ecb49695894433dee5184ea.zip
network: Added neighbor lladdr support for IPv6
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-neighbor.c25
-rw-r--r--src/network/networkd-neighbor.h9
2 files changed, 13 insertions, 21 deletions
diff --git a/src/network/networkd-neighbor.c b/src/network/networkd-neighbor.c
index 9af29e526b..191f6e3320 100644
--- a/src/network/networkd-neighbor.c
+++ b/src/network/networkd-neighbor.c
@@ -59,7 +59,6 @@ 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);
@@ -130,10 +129,7 @@ int neighbor_configure(Neighbor *neighbor, Link *link, link_netlink_message_hand
if (r < 0)
return log_error_errno(r, "Could not set flags: %m");
- 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));
+ r = sd_netlink_message_append_data(req, NDA_LLADDR, &neighbor->lladdr, neighbor->lladdr_size);
if (r < 0)
return log_error_errno(r, "Could not append NDA_LLADDR attribute: %m");
@@ -162,7 +158,7 @@ int neighbor_section_verify(Neighbor *neighbor) {
"Ignoring [Neighbor] section from line %u.",
neighbor->section->filename, neighbor->section->line);
- if (neighbor->lladdr_type < 0)
+ if (neighbor->lladdr_size == 0)
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: Neighbor section without LinkLayerAddress= configured. "
"Ignoring [Neighbor] section from line %u.",
@@ -222,7 +218,7 @@ int config_parse_neighbor_lladdr(
Network *network = userdata;
_cleanup_(neighbor_free_or_set_invalidp) Neighbor *n = NULL;
- int r;
+ int family, r;
assert(filename);
assert(section);
@@ -236,14 +232,16 @@ int config_parse_neighbor_lladdr(
r = ether_addr_from_string(rvalue, &n->lladdr.mac);
if (r >= 0)
- n->lladdr_type = NEIGHBOR_LLADDR_MAC;
+ n->lladdr_size = sizeof(n->lladdr.mac);
else {
- r = in_addr_from_string(AF_INET, rvalue, &n->lladdr.ip);
+ r = in_addr_from_string_auto(rvalue, &family, &n->lladdr.ip);
if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, r, "Neighbor LinkLayerAddress= is invalid, ignoring assignment: %s", rvalue);
+ 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->lladdr_size = family == AF_INET ? sizeof(n->lladdr.ip.in) : sizeof(n->lladdr.ip.in6);
}
TAKE_PTR(n);
@@ -279,11 +277,12 @@ int config_parse_neighbor_hwaddr(
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);
+ log_syntax(unit, LOG_ERR, filename, line, r,
+ "Neighbor MACAddress= is invalid, ignoring assignment: %s", rvalue);
return 0;
}
- n->lladdr_type = NEIGHBOR_LLADDR_MAC;
+ n->lladdr_size = sizeof(n->lladdr.mac);
TAKE_PTR(n);
return 0;
diff --git a/src/network/networkd-neighbor.h b/src/network/networkd-neighbor.h
index 1405ac25e2..09ccb55274 100644
--- a/src/network/networkd-neighbor.h
+++ b/src/network/networkd-neighbor.h
@@ -15,13 +15,6 @@ 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;
@@ -33,7 +26,7 @@ struct Neighbor {
struct ether_addr mac;
union in_addr_union ip;
} lladdr;
- NeighborLLAddressType lladdr_type;
+ size_t lladdr_size;
LIST_FIELDS(Neighbor, neighbors);
};