summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2019-07-19 09:48:49 +0900
committerGitHub <noreply@github.com>2019-07-19 09:48:49 +0900
commit0161f0ca368b93c1feb653013377a021452e6650 (patch)
treef8456550c24ef6960262fde2f0f4620dadeb7f16
parent27e64442f829c653ff7a057cd5d12e0f422d545b (diff)
parentfb2ba3305bf46236ef84781fd15d791f50ea32b7 (diff)
downloadsystemd-0161f0ca368b93c1feb653013377a021452e6650.tar.gz
Merge pull request #13100 from 1848/neigh_ipv6
networkd: Neighbor IPv6 support for LinkLayerAddress
-rw-r--r--src/libsystemd/sd-netlink/netlink-types.c2
-rw-r--r--src/network/networkd-neighbor.c25
-rw-r--r--src/network/networkd-neighbor.h9
-rw-r--r--test/test-network/conf/25-neighbor-ip-dummy.network1
-rw-r--r--test/test-network/conf/25-neighbor-ipv6.network11
-rwxr-xr-xtest/test-network/systemd-networkd-tests.py13
6 files changed, 36 insertions, 25 deletions
diff --git a/src/libsystemd/sd-netlink/netlink-types.c b/src/libsystemd/sd-netlink/netlink-types.c
index 5e4d8a94a0..3dab56c73d 100644
--- a/src/libsystemd/sd-netlink/netlink-types.c
+++ b/src/libsystemd/sd-netlink/netlink-types.c
@@ -663,7 +663,7 @@ static const NLTypeSystem rtnl_route_type_system = {
static const NLType rtnl_neigh_types[] = {
[NDA_DST] = { .type = NETLINK_TYPE_IN_ADDR },
- [NDA_LLADDR] = { /* struct ether_addr or struct in_addr */ },
+ [NDA_LLADDR] = { /* struct ether_addr, struct in_addr, or struct in6_addr */ },
[NDA_CACHEINFO] = { .type = NETLINK_TYPE_CACHE_INFO, .size = sizeof(struct nda_cacheinfo) },
[NDA_PROBES] = { .type = NETLINK_TYPE_U32 },
[NDA_VLAN] = { .type = NETLINK_TYPE_U16 },
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);
};
diff --git a/test/test-network/conf/25-neighbor-ip-dummy.network b/test/test-network/conf/25-neighbor-ip-dummy.network
index d99d97298a..e02c55e3a0 100644
--- a/test/test-network/conf/25-neighbor-ip-dummy.network
+++ b/test/test-network/conf/25-neighbor-ip-dummy.network
@@ -4,3 +4,4 @@ Name=dummy98
[Network]
IPv6AcceptRA=no
Tunnel=gretun97
+Tunnel=ip6gretun97
diff --git a/test/test-network/conf/25-neighbor-ipv6.network b/test/test-network/conf/25-neighbor-ipv6.network
new file mode 100644
index 0000000000..322f73965d
--- /dev/null
+++ b/test/test-network/conf/25-neighbor-ipv6.network
@@ -0,0 +1,11 @@
+[Match]
+Name=ip6gretun97
+
+[Network]
+IPv6AcceptRA=no
+Address=2001:db8:0:f102::16/64
+LinkLocalAddressing=no
+
+[Neighbor]
+Address=2001:db8:0:f102::17
+LinkLayerAddress=2a00:ffde:4567:edde::4988
diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py
index 9ef9b023e9..2f13bc2bbb 100755
--- a/test/test-network/systemd-networkd-tests.py
+++ b/test/test-network/systemd-networkd-tests.py
@@ -1388,6 +1388,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
'dummy98',
'dummy99',
'gretun97',
+ 'ip6gretun97',
'test1'
]
@@ -1405,8 +1406,10 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
'25-fibrule-invert.network',
'25-fibrule-port-range.network',
'25-gre-tunnel-remote-any.netdev',
+ '25-ip6gre-tunnel-remote-any.netdev',
'25-ipv6-address-label-section.network',
'25-neighbor-section.network',
+ '25-neighbor-ipv6.network',
'25-neighbor-ip-dummy.network',
'25-neighbor-ip.network',
'25-link-local-addressing-no.network',
@@ -1667,15 +1670,19 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
self.assertRegex(output, '2004:da8:1::1.*00:00:5e:00:02:66.*PERMANENT')
def test_neighbor_gre(self):
- copy_unit_to_networkd_unit_path('25-neighbor-ip.network', '25-neighbor-ip-dummy.network',
- '12-dummy.netdev', '25-gre-tunnel-remote-any.netdev')
+ copy_unit_to_networkd_unit_path('25-neighbor-ip.network', '25-neighbor-ipv6.network', '25-neighbor-ip-dummy.network',
+ '12-dummy.netdev', '25-gre-tunnel-remote-any.netdev', '25-ip6gre-tunnel-remote-any.netdev')
start_networkd()
- self.wait_online(['dummy98:degraded', 'gretun97:routable'], timeout='40s')
+ self.wait_online(['dummy98:degraded', 'gretun97:routable', 'ip6gretun97:routable'], timeout='40s')
output = check_output('ip neigh list dev gretun97')
print(output)
self.assertRegex(output, '10.0.0.22 lladdr 10.65.223.239 PERMANENT')
+ output = check_output('ip neigh list dev ip6gretun97')
+ print(output)
+ self.assertRegex(output, '2001:db8:0:f102::17 lladdr 2a:?00:ff:?de:45:?67:ed:?de:[0:]*:49:?88 PERMANENT')
+
def test_link_local_addressing(self):
copy_unit_to_networkd_unit_path('25-link-local-addressing-yes.network', '11-dummy.netdev',
'25-link-local-addressing-no.network', '12-dummy.netdev')