From: Guillaume Boutry <[email protected]>
EVPN state is rebuilt from each neighbor dump, even if the dump
fails partway through.
Stage learned neighbors and kernel changes until the dump completes.
Reject observable dump errors and interruption flags, and skip unusable
records with rate-limited warnings.
On failure, rebuild EVPN state from the last complete observations
for that interface, family, type and VNI. A successful empty dump
clears those observations. Kernel write failures do not invalidate
a completed read.
Use link generations to discard cached observations on replacement,
even when the name and ifindex are reused before the next run.
Observed bridge-port removal also invalidates the cache.
Test interrupted and failed dumps, write failures, empty dumps,
independent interfaces, rename and replacement.
Fixes: ad3a0a55b551 ("controller: Support monitoring/updating neighbor entries
through Netlink.")
Assisted-by: GPT-6.2 Sol, Codex
Signed-off-by: Guillaume Boutry <[email protected]>
---
controller/host-if-monitor-stub.c | 6 +-
controller/host-if-monitor.c | 92 ++++---
controller/host-if-monitor.h | 9 +-
controller/neighbor-exchange-netlink.c | 114 +++++---
controller/neighbor-exchange-netlink.h | 2 +-
controller/neighbor-exchange-stub.c | 5 +
controller/neighbor-exchange.c | 97 ++++++-
controller/neighbor-exchange.h | 3 +
controller/ovn-controller.c | 10 +-
tests/system-ovn-netlink.at | 70 +++++
tests/test-ovn-netlink.c | 363 ++++++++++++++++++++++++-
11 files changed, 668 insertions(+), 103 deletions(-)
diff --git a/controller/host-if-monitor-stub.c
b/controller/host-if-monitor-stub.c
index b174cf996..8dd93f9dd 100644
--- a/controller/host-if-monitor-stub.c
+++ b/controller/host-if-monitor-stub.c
@@ -36,8 +36,8 @@ host_if_monitor_update_watches(const struct sset *if_names
OVS_UNUSED)
{
}
-int32_t
-host_if_monitor_ifname_toindex(const char *if_name OVS_UNUSED)
+struct host_if_monitor_link
+host_if_monitor_get_link(const char *if_name OVS_UNUSED)
{
- return 0;
+ return (struct host_if_monitor_link) { 0 };
}
diff --git a/controller/host-if-monitor.c b/controller/host-if-monitor.c
index 7ddf6e455..fa46c493c 100644
--- a/controller/host-if-monitor.c
+++ b/controller/host-if-monitor.c
@@ -19,7 +19,7 @@
#include <net/if.h>
#include "lib/rtnetlink.h"
-#include "lib/simap.h"
+#include "openvswitch/shash.h"
#include "openvswitch/vlog.h"
#include "host-if-monitor.h"
@@ -32,7 +32,9 @@ struct host_if_monitor {
struct nln_notifier *link_notifier;
struct sset watched_interfaces;
- struct simap ifname_to_ifindex;
+ /* Maps interface names to struct host_if_monitor_link. */
+ struct shash links;
+ uint64_t last_link_generation;
bool changes_detected;
};
@@ -40,7 +42,7 @@ struct host_if_monitor {
static struct host_if_monitor monitor = (struct host_if_monitor) {
.link_notifier = NULL,
.watched_interfaces = SSET_INITIALIZER(&monitor.watched_interfaces),
- .ifname_to_ifindex = SIMAP_INITIALIZER(&monitor.ifname_to_ifindex),
+ .links = SHASH_INITIALIZER(&monitor.links),
.changes_detected = false,
};
@@ -65,6 +67,21 @@ host_if_monitor_run(void)
return monitor.changes_detected;
}
+static void
+host_if_monitor_set_link(const char *if_name, int32_t if_index)
+{
+ struct host_if_monitor_link *link = shash_find_data(&monitor.links,
+ if_name);
+ if (!link) {
+ link = xzalloc(sizeof *link);
+ shash_add(&monitor.links, if_name, link);
+ }
+ if (link->if_index != if_index) {
+ link->if_index = if_index;
+ link->generation = ++monitor.last_link_generation;
+ }
+}
+
void
host_if_monitor_update_watches(const struct sset *if_names)
{
@@ -85,10 +102,11 @@ host_if_monitor_update_watches(const struct sset *if_names)
sset_clone(&monitor.watched_interfaces, if_names);
/* Remove mappings for if_names that are not tracked anymore. */
- struct simap_node *sn;
- SIMAP_FOR_EACH_SAFE (sn, &monitor.ifname_to_ifindex) {
- if (!sset_contains(&monitor.watched_interfaces, sn->name)) {
- simap_delete(&monitor.ifname_to_ifindex, sn);
+ struct shash_node *node;
+ SHASH_FOR_EACH_SAFE (node, &monitor.links) {
+ if (!sset_contains(&monitor.watched_interfaces, node->name)) {
+ free(node->data);
+ shash_delete(&monitor.links, node);
}
}
}
@@ -110,8 +128,10 @@ host_if_monitor_update_watches(const struct sset *if_names)
* callback is not called.
*/
SSET_FOR_EACH (if_name, &new_if_names) {
- simap_put(&monitor.ifname_to_ifindex, if_name,
- if_nametoindex(if_name));
+ int32_t if_index = if_nametoindex(if_name);
+ if (if_index) {
+ host_if_monitor_set_link(if_name, if_index);
+ }
}
} else {
if (monitor.link_notifier) {
@@ -124,10 +144,12 @@ host_if_monitor_update_watches(const struct sset
*if_names)
sset_destroy(&new_if_names);
}
-int32_t
-host_if_monitor_ifname_toindex(const char *if_name)
+struct host_if_monitor_link
+host_if_monitor_get_link(const char *if_name)
{
- return simap_get(&monitor.ifname_to_ifindex, if_name);
+ const struct host_if_monitor_link *link = shash_find_data(&monitor.links,
+ if_name);
+ return link ? *link : (struct host_if_monitor_link) { 0 };
}
static void
@@ -137,35 +159,29 @@ if_notifier_cb(const struct rtnetlink_change *change,
void *aux OVS_UNUSED)
return;
}
- /* A rename reports the new name, which might not be watched. Remove
- * mappings for the same index before considering the current name. */
- if (change->nlmsg_type == RTM_NEWLINK) {
- struct simap_node *node;
- SIMAP_FOR_EACH_SAFE (node, &monitor.ifname_to_ifindex) {
- if (node->data == change->if_index
- && strcmp(node->name, change->ifname)) {
- simap_delete(&monitor.ifname_to_ifindex, node);
- monitor.changes_detected = true;
- }
- }
+ if (change->nlmsg_type != RTM_NEWLINK
+ && change->nlmsg_type != RTM_DELLINK) {
+ return;
}
- switch (change->nlmsg_type) {
- case RTM_NEWLINK:
- if ((change->ifi_flags & IFF_UP)
- && sset_find(&monitor.watched_interfaces, change->ifname)) {
- simap_put(&monitor.ifname_to_ifindex,
- change->ifname, change->if_index);
+ /* A rename event names the new link, which may not be watched.
+ * Invalidate the old name by index so its generation cannot restore
+ * observations to an interface that no longer matches the watch. */
+ struct shash_node *node;
+ SHASH_FOR_EACH_SAFE (node, &monitor.links) {
+ const struct host_if_monitor_link *link = node->data;
+ if (link->if_index == change->if_index
+ && (change->nlmsg_type == RTM_DELLINK
+ || strcmp(node->name, change->ifname))) {
+ free(node->data);
+ shash_delete(&monitor.links, node);
monitor.changes_detected = true;
}
- break;
- case RTM_DELLINK:
- if (sset_find(&monitor.watched_interfaces, change->ifname)) {
- simap_find_and_delete(&monitor.ifname_to_ifindex, change->ifname);
- monitor.changes_detected = true;
- }
- break;
- default:
- break;
+ }
+
+ if (change->nlmsg_type == RTM_NEWLINK && (change->ifi_flags & IFF_UP)
+ && sset_contains(&monitor.watched_interfaces, change->ifname)) {
+ host_if_monitor_set_link(change->ifname, change->if_index);
+ monitor.changes_detected = true;
}
}
diff --git a/controller/host-if-monitor.h b/controller/host-if-monitor.h
index a41c5869c..373946645 100644
--- a/controller/host-if-monitor.h
+++ b/controller/host-if-monitor.h
@@ -18,13 +18,18 @@
#include <stdint.h>
#include "lib/sset.h"
-#include "lib/smap.h"
void host_if_monitor_wait(void);
bool host_if_monitor_run(void);
void host_if_monitor_update_watches(const struct sset *if_names);
-int32_t host_if_monitor_ifname_toindex(const char *if_name);
+struct host_if_monitor_link {
+ int32_t if_index;
+ /* Changes when a watched link is removed or replaced. */
+ uint64_t generation;
+};
+
+struct host_if_monitor_link host_if_monitor_get_link(const char *if_name);
#endif /* HOST_IF_MONITOR_H */
diff --git a/controller/neighbor-exchange-netlink.c
b/controller/neighbor-exchange-netlink.c
index 942dee147..fc33c68ff 100644
--- a/controller/neighbor-exchange-netlink.c
+++ b/controller/neighbor-exchange-netlink.c
@@ -14,6 +14,7 @@
*/
#include <config.h>
+#include <errno.h>
#include <stdbool.h>
#include <linux/if_ether.h>
#include <linux/rtnetlink.h>
@@ -44,14 +45,8 @@ VLOG_DEFINE_THIS_MODULE(neighbor_exchange_netlink);
#endif
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
+static struct vlog_rate_limit record_rl = VLOG_RATE_LIMIT_INIT(5, 20);
-/* Inspired from route_table_dump_one_table() in OVS. */
-typedef void ne_table_handle_msg_callback(const struct ne_table_msg *,
- void *aux);
-static void ne_table_dump_one_ifindex(unsigned char address_family,
- int32_t if_index,
- ne_table_handle_msg_callback *,
- void *aux);
struct ne_msg_handle_data {
/* Stores 'struct advertise_neighbor_entry'. */
struct hmapx *neighbors_to_advertise;
@@ -69,7 +64,10 @@ struct ne_msg_handle_data {
enum neighbor_interface_type type;
};
-static void handle_ne_msg(const struct ne_table_msg *, void *data);
+static int ne_table_dump_one_ifindex(uint8_t family, int32_t if_index,
+ struct ne_msg_handle_data *);
+static void handle_ne_msg(const struct ne_nl_received_neigh *,
+ struct ne_msg_handle_data *);
static int ne_table_parse__(struct ofpbuf *, size_t ofs,
const struct nlmsghdr *,
@@ -91,15 +89,20 @@ static int ne_nl_del_neigh(int32_t if_index, uint8_t family,
* (struct ne_nl_received_neigh) that exist in the table associated to
* 'if_index'.
*
+ * Sets 'dump_failed' when the dump is incomplete. In that case, leaves
+ * 'learned_neighbors' and the kernel table unchanged.
+ *
* Returns 0 on success, errno on failure. */
int
ne_nl_sync_neigh(uint8_t family, int32_t if_index,
enum neighbor_interface_type type,
const struct hmap *neighbors,
- struct vector *learned_neighbors)
+ struct vector *learned_neighbors, bool *dump_failed)
{
struct hmapx neighbors_to_advertise =
HMAPX_INITIALIZER(&neighbors_to_advertise);
+ struct vector learned =
+ VECTOR_EMPTY_INITIALIZER(struct ne_nl_received_neigh);
struct vector stale_neighbors =
VECTOR_EMPTY_INITIALIZER(struct ne_nl_received_neigh);
struct advertise_neighbor_entry *an;
@@ -111,12 +114,22 @@ ne_nl_sync_neigh(uint8_t family, int32_t if_index,
struct ne_msg_handle_data data = {
.neighbors_to_advertise = &neighbors_to_advertise,
- .learned_neighbors = learned_neighbors,
+ .learned_neighbors = learned_neighbors ? &learned : NULL,
.stale_neighbors = &stale_neighbors,
.neighbors = neighbors,
.type = type,
};
- ne_table_dump_one_ifindex(family, if_index, handle_ne_msg, &data);
+ ret = ne_table_dump_one_ifindex(family, if_index, &data);
+ *dump_failed = ret != 0;
+ if (ret) {
+ VLOG_WARN_RL(&rl, "Neighbor dump failed for ifindex=%"PRId32
+ " family=%u: %s", if_index, family, ovs_strerror(ret));
+ goto out;
+ }
+ if (!vector_is_empty(&learned)) {
+ vector_push_array(learned_neighbors, vector_get_array(&learned),
+ vector_len(&learned));
+ }
/* Add any remaining neighbors in the neighbors_to_advertise hmapx to the
* system table. */
@@ -168,6 +181,8 @@ ne_nl_sync_neigh(uint8_t family, int32_t if_index,
}
}
+out:
+ vector_destroy(&learned);
hmapx_destroy(&neighbors_to_advertise);
vector_destroy(&stale_neighbors);
return ret;
@@ -225,15 +240,15 @@ ne_is_valid_static_arp(struct ne_nl_received_neigh *ne)
ne->state & NUD_NOARP && ne->flags & NTF_EXT_LEARNED;
}
-static void
-ne_table_dump_one_ifindex(unsigned char address_family, int32_t if_index,
- ne_table_handle_msg_callback *handle_msg_cb,
- void *aux)
+static int
+ne_table_dump_one_ifindex(uint8_t address_family, int32_t if_index,
+ struct ne_msg_handle_data *data)
{
uint64_t reply_stub[NL_DUMP_BUFSIZE / 8];
struct ofpbuf request, reply, buf;
struct ndmsg *rq_msg;
struct nl_dump dump;
+ bool interrupted = false;
uint8_t request_stub[NETNL_REQ_BUFFER_SIZE];
ofpbuf_use_stub(&request, request_stub, sizeof request_stub);
@@ -250,24 +265,45 @@ ne_table_dump_one_ifindex(unsigned char address_family,
int32_t if_index,
ofpbuf_use_stub(&buf, reply_stub, sizeof reply_stub);
while (nl_dump_next(&dump, &reply, &buf)) {
- struct ne_table_msg msg;
+ const struct nlmsghdr *nlmsghdr = ofpbuf_at(&reply, 0, NLMSG_HDRLEN);
+ if (nlmsghdr && (nlmsghdr->nlmsg_flags & NLM_F_DUMP_INTR)) {
+ interrupted = true;
+ }
+ /* Drain this buffer too. It may already contain NLMSG_DONE. */
+ if (interrupted) {
+ continue;
+ }
- if (ne_table_parse(&reply, &msg)) {
- struct nlmsghdr *nlmsghdr = nl_msg_nlmsghdr(&reply);
+ const struct ndmsg *nd = ofpbuf_at(&reply, NLMSG_HDRLEN, sizeof *nd);
+ if (!nlmsghdr || !nd) {
+ VLOG_WARN_RL(&record_rl,
+ "Skipping truncated neighbor dump record");
+ continue;
+ }
- /* Older kernels do not support filtering. If so, we
- * filter ourselves. */
- if (!(nlmsghdr->nlmsg_flags & NLM_F_DUMP_FILTERED)) {
- if (msg.nd.family != address_family
- || (if_index && msg.nd.if_index != if_index)) {
- continue;
- }
- }
- handle_msg_cb(&msg, aux);
+ /* Older kernels may return an unfiltered dump. */
+ if (!(nlmsghdr->nlmsg_flags & NLM_F_DUMP_FILTERED)
+ && (nd->ndm_family != address_family
+ || (if_index && nd->ndm_ifindex != if_index))) {
+ continue;
+ }
+
+ struct ne_table_msg msg;
+ if (!ne_table_parse(&reply, &msg)) {
+ VLOG_WARN_RL(&record_rl,
+ "Skipping unsupported or malformed neighbor record "
+ "for ifindex=%"PRId32" family=%u",
+ nd->ndm_ifindex, nd->ndm_family);
+ continue;
}
+ handle_ne_msg(&msg.nd, data);
}
ofpbuf_uninit(&buf);
- nl_dump_done(&dump);
+ int error = nl_dump_done(&dump);
+ if (!error && (interrupted || (dump.nl_flags & NLM_F_DUMP_INTR))) {
+ error = EINTR;
+ }
+ return error;
}
static int
@@ -376,42 +412,40 @@ ne_table_parse__(struct ofpbuf *buf, size_t ofs, const
struct nlmsghdr *nlmsg,
}
static void
-handle_ne_msg(const struct ne_table_msg *msg, void *data)
+handle_ne_msg(const struct ne_nl_received_neigh *nd,
+ struct ne_msg_handle_data *data)
{
- struct ne_msg_handle_data *handle_data = data;
- const struct ne_nl_received_neigh *nd = &msg->nd;
-
/* OVN only manages VLAN 0 entries. */
if (nd->vlan) {
return;
}
- if (!ne_is_ovn_owned(nd, handle_data->type)) {
- if (!handle_data->learned_neighbors) {
+ if (!ne_is_ovn_owned(nd, data->type)) {
+ if (!data->learned_neighbors) {
return;
}
/* Learn the non-OVN entry. */
- vector_push(handle_data->learned_neighbors, nd);
+ vector_push(data->learned_neighbors, nd);
return;
}
/* This neighbor was presumably added by OVN, see if it's still valid.
* OVN only adds neighbors with port set to 0, all others can be
* removed. */
- if (!nd->port && handle_data->neighbors_to_advertise) {
+ if (!nd->port && data->neighbors_to_advertise) {
struct advertise_neighbor_entry *an =
- advertise_neigh_find(handle_data->neighbors, nd->lladdr,
+ advertise_neigh_find(data->neighbors, nd->lladdr,
&nd->addr);
if (an) {
- hmapx_find_and_delete(handle_data->neighbors_to_advertise, an);
+ hmapx_find_and_delete(data->neighbors_to_advertise, an);
return;
}
}
/* Store the entry for deletion. */
- if (handle_data->stale_neighbors) {
- vector_push(handle_data->stale_neighbors, nd);
+ if (data->stale_neighbors) {
+ vector_push(data->stale_neighbors, nd);
}
}
diff --git a/controller/neighbor-exchange-netlink.h
b/controller/neighbor-exchange-netlink.h
index 0b2dd4199..f25cf4096 100644
--- a/controller/neighbor-exchange-netlink.h
+++ b/controller/neighbor-exchange-netlink.h
@@ -54,7 +54,7 @@ struct ne_table_msg {
int ne_nl_sync_neigh(uint8_t family, int32_t if_index,
enum neighbor_interface_type type,
const struct hmap *neighbors,
- struct vector *learned_neighbors);
+ struct vector *learned_neighbors, bool *dump_failed);
bool ne_is_ovn_owned(const struct ne_nl_received_neigh *nd,
enum neighbor_interface_type type);
diff --git a/controller/neighbor-exchange-stub.c
b/controller/neighbor-exchange-stub.c
index a5420fcff..d2a80d580 100644
--- a/controller/neighbor-exchange-stub.c
+++ b/controller/neighbor-exchange-stub.c
@@ -29,6 +29,11 @@ neighbor_exchange_retry_due(void)
return false;
}
+void
+neighbor_exchange_snapshots_clear(struct hmap *snapshots OVS_UNUSED)
+{
+}
+
void
evpn_remote_vteps_clear(struct hmap *remote_vteps OVS_UNUSED)
{
diff --git a/controller/neighbor-exchange.c b/controller/neighbor-exchange.c
index 4a6328492..61092a579 100644
--- a/controller/neighbor-exchange.c
+++ b/controller/neighbor-exchange.c
@@ -52,6 +52,60 @@ static uint32_t evpn_static_entry_hash(const struct eth_addr
*mac,
* of other engine inputs. */
static long long int neighbor_exchange_retry_at;
+struct neighbor_snapshot {
+ struct hmap_node node;
+ uint64_t link_generation;
+ enum neighbor_family family;
+ enum neighbor_interface_type type;
+ uint32_t vni;
+ struct vector learned;
+ bool seen;
+};
+
+static struct neighbor_snapshot *
+neighbor_snapshot_get(struct hmap *snapshots,
+ const struct neighbor_interface_monitor *nim,
+ uint64_t link_generation)
+{
+ uint32_t hash = hash_3words(nim->family, nim->type, nim->vni);
+ hash = hash_uint64_basis(link_generation, hash);
+ struct neighbor_snapshot *snapshot;
+ HMAP_FOR_EACH_WITH_HASH (snapshot, node, hash, snapshots) {
+ if (snapshot->link_generation == link_generation
+ && snapshot->family == nim->family && snapshot->type == nim->type
+ && snapshot->vni == nim->vni) {
+ return snapshot;
+ }
+ }
+
+ snapshot = xmalloc(sizeof *snapshot);
+ *snapshot = (struct neighbor_snapshot) {
+ .link_generation = link_generation,
+ .family = nim->family,
+ .type = nim->type,
+ .vni = nim->vni,
+ .learned = VECTOR_EMPTY_INITIALIZER(struct ne_nl_received_neigh),
+ };
+ hmap_insert(snapshots, &snapshot->node, hash);
+ return snapshot;
+}
+
+static void
+neighbor_snapshot_destroy(struct neighbor_snapshot *snapshot)
+{
+ vector_destroy(&snapshot->learned);
+ free(snapshot);
+}
+
+void
+neighbor_exchange_snapshots_clear(struct hmap *snapshots)
+{
+ struct neighbor_snapshot *snapshot;
+ HMAP_FOR_EACH_POP (snapshot, node, snapshots) {
+ neighbor_snapshot_destroy(snapshot);
+ }
+}
+
void
neighbor_exchange_run(const struct neighbor_exchange_ctx_in *n_ctx_in,
struct neighbor_exchange_ctx_out *n_ctx_out)
@@ -65,24 +119,42 @@ neighbor_exchange_run(const struct
neighbor_exchange_ctx_in *n_ctx_in,
host_if_monitor_update_watches(&if_names);
sset_destroy(&if_names);
+ evpn_remote_vteps_clear(n_ctx_out->remote_vteps);
+ evpn_static_entries_clear(n_ctx_out->static_fdbs);
+ evpn_static_entries_clear(n_ctx_out->static_arps);
+ vector_clear(n_ctx_out->neighbor_table_watches);
+
bool retry = false;
VECTOR_FOR_EACH (n_ctx_in->monitored_interfaces, nim) {
- int32_t if_index = host_if_monitor_ifname_toindex(nim->if_name);
- if (!if_index) {
+ struct host_if_monitor_link link =
+ host_if_monitor_get_link(nim->if_name);
+ if (!link.if_index) {
continue;
}
struct vector received_neighbors =
VECTOR_EMPTY_INITIALIZER(struct ne_nl_received_neigh);
- int error = ne_nl_sync_neigh(nim->family, if_index, nim->type,
+ bool dump_failed;
+ int error = ne_nl_sync_neigh(nim->family, link.if_index, nim->type,
&nim->announced_neighbors,
- &received_neighbors);
+ &received_neighbors, &dump_failed);
retry |= error != 0;
+ struct neighbor_snapshot *snapshot =
+ neighbor_snapshot_get(n_ctx_out->snapshots, nim, link.generation);
+ snapshot->seen = true;
+ /* A successful empty dump supersedes the previous observations.
+ * Add/delete errors still leave us with a usable dump. */
+ if (!dump_failed) {
+ vector_destroy(&snapshot->learned);
+ snapshot->learned = vector_steal(&received_neighbors);
+ }
+ vector_destroy(&received_neighbors);
+
struct ne_nl_received_neigh *ne;
switch (nim->type) {
case NEIGH_IFACE_BRIDGE:
- VECTOR_FOR_EACH_PTR (&received_neighbors, ne) {
+ VECTOR_FOR_EACH_PTR (&snapshot->learned, ne) {
if (ne_is_valid_static_arp(ne)) {
if (!evpn_static_entry_find(n_ctx_out->static_arps,
ne->lladdr, ne->addr,
@@ -95,7 +167,7 @@ neighbor_exchange_run(const struct neighbor_exchange_ctx_in
*n_ctx_in,
}
break;
case NEIGH_IFACE_VXLAN:
- VECTOR_FOR_EACH_PTR (&received_neighbors, ne) {
+ VECTOR_FOR_EACH_PTR (&snapshot->learned, ne) {
if (ne_is_valid_remote_vtep(ne)) {
uint16_t port = ne->port ? ne->port : DEFAULT_VXLAN_PORT;
if (!evpn_remote_vtep_find(n_ctx_out->remote_vteps,
@@ -123,8 +195,17 @@ neighbor_exchange_run(const struct
neighbor_exchange_ctx_in *n_ctx_in,
OVS_NOT_REACHED();
}
- vector_push(n_ctx_out->neighbor_table_watches, &if_index);
- vector_destroy(&received_neighbors);
+ vector_push(n_ctx_out->neighbor_table_watches, &link.if_index);
+ }
+
+ struct neighbor_snapshot *snapshot;
+ HMAP_FOR_EACH_SAFE (snapshot, node, n_ctx_out->snapshots) {
+ if (!snapshot->seen) {
+ hmap_remove(n_ctx_out->snapshots, &snapshot->node);
+ neighbor_snapshot_destroy(snapshot);
+ } else {
+ snapshot->seen = false;
+ }
}
neighbor_exchange_retry_at = retry ? time_msec() + 1000 : 0;
diff --git a/controller/neighbor-exchange.h b/controller/neighbor-exchange.h
index 935477d7a..dcdb21fd9 100644
--- a/controller/neighbor-exchange.h
+++ b/controller/neighbor-exchange.h
@@ -32,6 +32,8 @@ struct neighbor_exchange_ctx_in {
struct neighbor_exchange_ctx_out {
/* Contains int32_t representing if_index. */
struct vector *neighbor_table_watches;
+ /* Last usable observations for each monitored interface and family. */
+ struct hmap *snapshots;
/* Contains 'struct evpn_remote_vtep'. */
struct hmap *remote_vteps;
/* Contains 'struct evpn_static_entry', remote FDB entries learned through
@@ -68,6 +70,7 @@ struct evpn_static_entry {
void neighbor_exchange_run(const struct neighbor_exchange_ctx_in *,
struct neighbor_exchange_ctx_out *);
bool neighbor_exchange_retry_due(void);
+void neighbor_exchange_snapshots_clear(struct hmap *);
void evpn_remote_vteps_clear(struct hmap *remote_vteps);
void evpn_remote_vtep_list(struct unixctl_conn *, int argc,
const char *argv[], void *data_);
diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c
index 0c414e903..2f9800389 100644
--- a/controller/ovn-controller.c
+++ b/controller/ovn-controller.c
@@ -7093,6 +7093,7 @@ nexthop_exchange_update(struct ed_type_nexthop_exchange
*nhe_data,
}
struct ed_type_neighbor_exchange {
+ struct hmap snapshots;
/* Contains 'struct evpn_remote_vtep'. */
struct hmap remote_vteps;
/* Contains 'struct evpn_static_entry', remote FDB entries learned through
@@ -7109,6 +7110,7 @@ en_neighbor_exchange_init(struct engine_node *node
OVS_UNUSED,
{
struct ed_type_neighbor_exchange *data = xmalloc(sizeof *data);
*data = (struct ed_type_neighbor_exchange) {
+ .snapshots = HMAP_INITIALIZER(&data->snapshots),
.remote_vteps = HMAP_INITIALIZER(&data->remote_vteps),
.static_fdbs = HMAP_INITIALIZER(&data->static_fdbs),
.static_arps = HMAP_INITIALIZER(&data->static_arps),
@@ -7121,6 +7123,8 @@ static void
en_neighbor_exchange_cleanup(void *data_)
{
struct ed_type_neighbor_exchange *data = data_;
+ neighbor_exchange_snapshots_clear(&data->snapshots);
+ hmap_destroy(&data->snapshots);
evpn_remote_vteps_clear(&data->remote_vteps);
evpn_static_entries_clear(&data->static_fdbs);
evpn_static_entries_clear(&data->static_arps);
@@ -7140,16 +7144,12 @@ en_neighbor_exchange_run(struct engine_node *node, void
*data_)
struct ed_type_nexthop_exchange *nhe_data =
engine_get_input_data("nexthop_exchange", node);
- evpn_remote_vteps_clear(&data->remote_vteps);
- evpn_static_entries_clear(&data->static_fdbs);
- evpn_static_entries_clear(&data->static_arps);
- vector_clear(&nt_notify->watches);
-
struct neighbor_exchange_ctx_in n_ctx_in = {
.monitored_interfaces = &neighbor_data->monitored_interfaces,
};
struct neighbor_exchange_ctx_out n_ctx_out = {
.neighbor_table_watches = &nt_notify->watches,
+ .snapshots = &data->snapshots,
.remote_vteps = &data->remote_vteps,
.static_fdbs = &data->static_fdbs,
.static_arps = &data->static_arps,
diff --git a/tests/system-ovn-netlink.at b/tests/system-ovn-netlink.at
index ff2832f2a..f68eeeedc 100644
--- a/tests/system-ovn-netlink.at
+++ b/tests/system-ovn-netlink.at
@@ -5,6 +5,76 @@ AT_KEYWORDS([netlink-neighbors netlink-retry])
check ovstest test-ovn-netlink neighbor-exchange-retry
AT_CLEANUP
+AT_SETUP([sync netlink neighbors - failed dump])
+AT_KEYWORDS([netlink-neighbors netlink-dump-error])
+AT_CHECK([ovstest test-ovn-netlink neighbor-sync-error], [0], [], [ignore])
+AT_CLEANUP
+
+AT_SETUP([sync netlink neighbors - filter unrelated dump records])
+AT_KEYWORDS([netlink-neighbors netlink-dump-error])
+check ovstest test-ovn-netlink neighbor-dump-script other-interface
+check ovstest test-ovn-netlink neighbor-dump-script other-family
+AT_CLEANUP
+
+AT_SETUP([sync netlink neighbors - malformed dump records])
+AT_KEYWORDS([netlink-neighbors netlink-dump-error])
+check ovstest test-ovn-netlink neighbor-dump-script malformed
+check ovstest test-ovn-netlink neighbor-dump-script filtered-malformed
+check ovstest test-ovn-netlink neighbor-dump-script truncated
+AT_CLEANUP
+
+AT_SETUP([sync netlink neighbors - partial dump rollback])
+AT_KEYWORDS([netlink-neighbors netlink-dump-error])
+check ovstest test-ovn-netlink neighbor-dump-script late-error
+check ovstest test-ovn-netlink neighbor-dump-script interrupted
+check ovstest test-ovn-netlink neighbor-dump-script record-interrupted
+check ovstest test-ovn-netlink neighbor-dump-script parse-and-dump-error
+AT_CLEANUP
+
+AT_SETUP([sync netlink neighbors - complete dump publication])
+AT_KEYWORDS([netlink-neighbors netlink-dump-error])
+check ovstest test-ovn-netlink neighbor-dump-script complete
+check ovstest test-ovn-netlink neighbor-dump-script write-error
+AT_CLEANUP
+
+AT_SETUP([sync netlink neighbors - retry failed dumps])
+AT_KEYWORDS([netlink-neighbors netlink-dump-error])
+check ovstest test-ovn-netlink neighbor-exchange-snapshot retry
+AT_CLEANUP
+
+m4_define([NEIGHBOR_SNAPSHOT_SETUP], [
+check ip link add dump-br1 type bridge
+on_exit 'if ip link show dump-br1 >/dev/null 2>&1; then ip link del dump-br1;
fi'
+check ip link add dump-br2 type bridge
+on_exit 'ip link del dump-br2'
+check ip link set dump-br2 up
+check ip neigh replace 192.0.2.2 lladdr 02:00:00:00:00:02 \
+ nud noarp extern_learn dev dump-br2
+])
+
+AT_SETUP([sync netlink neighbors - retain failed interface observations])
+AT_KEYWORDS([netlink-neighbors netlink-dump-error])
+NEIGHBOR_SNAPSHOT_SETUP
+check ovstest test-ovn-netlink neighbor-exchange-snapshot retention
+check ovstest test-ovn-netlink neighbor-exchange-snapshot write-error
+AT_CLEANUP
+
+AT_SETUP([sync netlink neighbors - discard observations on link replacement])
+AT_KEYWORDS([netlink-neighbors netlink-dump-error])
+NEIGHBOR_SNAPSHOT_SETUP
+if_index=$(netlink_if_index dump-br1)
+check ovstest test-ovn-netlink neighbor-exchange-snapshot replace \
+ "ip link del dump-br1 && ip link add dump-br1 index $if_index type bridge
&& \
+ ip link set dump-br1 up"
+AT_CLEANUP
+
+AT_SETUP([sync netlink neighbors - discard observations on link rename])
+AT_KEYWORDS([netlink-neighbors netlink-dump-error])
+NEIGHBOR_SNAPSHOT_SETUP
+on_exit 'if ip link show dump-renamed >/dev/null 2>&1; then ip link del
dump-renamed; fi'
+check ovstest test-ovn-netlink neighbor-exchange-snapshot rename
+AT_CLEANUP
+
AT_SETUP([sync netlink neighbors - learn VXLAN VTEP neighbors])
AT_KEYWORDS([netlink-neighbors])
diff --git a/tests/test-ovn-netlink.c b/tests/test-ovn-netlink.c
index dd5ed46b6..7501b4272 100644
--- a/tests/test-ovn-netlink.c
+++ b/tests/test-ovn-netlink.c
@@ -16,19 +16,22 @@
#include <config.h>
#include <errno.h>
#include <linux/rtnetlink.h>
+#include <net/if.h>
+#include <sys/resource.h>
#include "netlink.h"
#include "netlink-socket.h"
-#include "openvswitch/poll-loop.h"
#include "openvswitch/hmap.h"
+#include "openvswitch/poll-loop.h"
#include "route-table.h"
#include "packets.h"
#include "tests/ovstest.h"
#include "tests/test-utils.h"
+#include "timeval.h"
#include "controller/host-if-monitor.h"
-#include "controller/neighbor-exchange-netlink.h"
#include "controller/neighbor-exchange.h"
+#include "controller/neighbor-exchange-netlink.h"
#include "controller/nexthop-exchange.h"
#include "controller/ovn-netlink-notifier.h"
#include "controller/neighbor.h"
@@ -96,8 +99,7 @@ __wrap_nl_dump_start(struct nl_dump *dump, int protocol,
: RTM_GETNEIGH;
ovs_assert(nl_msg_nlmsghdr(request)->nlmsg_type == type);
dump->nl_flags = 0;
- nl_script.next = 0;
- nl_script.finished = false;
+ ovs_assert(!nl_script.started);
nl_script.started = true;
}
@@ -190,6 +192,338 @@ neighbor_dump_add(uint8_t family, int32_t if_index,
uint16_t state,
header->nlmsg_len = message->size;
}
+static void
+test_neighbor_dump_script(struct ovs_cmdl_context *ctx)
+{
+ const char *scenario = ctx->argv[1];
+ bool complete = !strcmp(scenario, "complete");
+ bool write_error = !strcmp(scenario, "write-error");
+ bool other_interface = !strcmp(scenario, "other-interface");
+ bool other_family = !strcmp(scenario, "other-family");
+ bool malformed = !strcmp(scenario, "malformed");
+ bool filtered = !strcmp(scenario, "filtered-malformed");
+ bool truncated = !strcmp(scenario, "truncated");
+ bool late_error = !strcmp(scenario, "late-error");
+ bool both_errors = !strcmp(scenario, "parse-and-dump-error");
+ bool interrupted = !strcmp(scenario, "interrupted");
+ bool record_interrupted = !strcmp(scenario, "record-interrupted");
+ ovs_assert(complete || write_error || other_interface || other_family
+ || malformed || filtered || truncated || late_error
+ || interrupted || record_interrupted || both_errors);
+
+ struct hmap neighbors = HMAP_INITIALIZER(&neighbors);
+ struct advertise_neighbor_entry desired = {
+ .lladdr = ETH_ADDR_C(02,00,00,00,00,03),
+ .addr = in6_addr_mapped_ipv4(htonl(0xc0000203)),
+ };
+ hmap_insert(&neighbors, &desired.node,
+ advertise_neigh_hash(&desired.lladdr, &desired.addr));
+ struct vector learned =
+ VECTOR_EMPTY_INITIALIZER(struct ne_nl_received_neigh);
+ struct ne_nl_received_neigh sentinel = { .if_index = 17 };
+ vector_push(&learned, &sentinel);
+
+ memset(&nl_script, 0, sizeof nl_script);
+ nl_script.active = true;
+ /* A learned row and an obsolete OVN-owned row precede the fault. A
+ * successful sync must publish the former, add the desired row and
+ * delete the latter; a failed dump must do none of those operations. */
+ neighbor_dump_add(AF_INET, 42, NUD_REACHABLE, 0, 0, ETH_ADDR_LEN, 1);
+ neighbor_dump_add(AF_INET, 42, NUD_NOARP, 0, 0, ETH_ADDR_LEN, 2);
+ if (other_interface || other_family || malformed || filtered
+ || both_errors) {
+ neighbor_dump_add(other_family ? AF_INET6 : AF_INET,
+ other_interface ? 43 : 42, NUD_REACHABLE, 0,
+ filtered ? NLM_F_DUMP_FILTERED : 0,
+ other_interface || other_family ? ETH_ADDR_LEN : 20,
+ 4);
+ } else if (truncated) {
+ struct ofpbuf *message = neighbor_dump_message();
+ ofpbuf_put_zeros(message, sizeof(struct ndmsg) - 1);
+ nl_msg_nlmsghdr(message)->nlmsg_len = message->size;
+ } else if (record_interrupted) {
+ /* Even an unrelated record marks the whole dump interrupted. */
+ neighbor_dump_add(AF_INET, 43, NUD_REACHABLE, 0, NLM_F_DUMP_INTR,
+ ETH_ADDR_LEN, 4);
+ neighbor_dump_add(AF_INET, 42, NUD_REACHABLE, 0, 0, ETH_ADDR_LEN, 5);
+ }
+ nl_script.error = late_error || both_errors ? EINTR : 0;
+ nl_script.done_flags = interrupted ? NLM_F_DUMP_INTR : 0;
+
+ nl_script.transact_error = write_error ? EIO : 0;
+
+ bool dump_failed;
+ int error = ne_nl_sync_neigh(AF_INET, 42, NEIGH_IFACE_UNSPECIFIED,
+ &neighbors, &learned, &dump_failed);
+ ovs_assert(nl_script.started && nl_script.finished);
+ ovs_assert(nl_script.next == nl_script.n_messages);
+ nl_script.active = false;
+ bool success = !(late_error || interrupted || record_interrupted
+ || both_errors);
+ ovs_assert(error == (success ? nl_script.transact_error : EINTR));
+ ovs_assert(dump_failed == !success);
+ ovs_assert(nl_script.adds == (success ? 1 : 0));
+ ovs_assert(nl_script.deletes == (success ? 1 : 0));
+ ovs_assert(hmap_count(&neighbors) == 1);
+ ovs_assert(learned.len == (success ? 2 : 1));
+ const struct ne_nl_received_neigh *rows = learned.buffer;
+ ovs_assert(!memcmp(&rows[0], &sentinel, sizeof sentinel));
+ if (success) {
+ struct eth_addr mac = ETH_ADDR_C(02,00,00,00,00,01);
+ struct in6_addr ip = in6_addr_mapped_ipv4(htonl(0xc0000201));
+ ovs_assert(rows[1].if_index == 42 && rows[1].family == AF_INET);
+ ovs_assert(rows[1].state == NUD_REACHABLE);
+ ovs_assert(eth_addr_equals(rows[1].lladdr, mac));
+ ovs_assert(ipv6_addr_equals(&rows[1].addr, &ip));
+ }
+ for (size_t i = 0; i < nl_script.n_messages; i++) {
+ ofpbuf_uninit(&nl_script.messages[i]);
+ }
+ vector_destroy(&learned);
+ hmap_destroy(&neighbors);
+}
+
+static void
+neighbor_script_reset(int32_t if_index, int error)
+{
+ for (size_t i = 0; i < nl_script.n_messages; i++) {
+ ofpbuf_uninit(&nl_script.messages[i]);
+ }
+ memset(&nl_script, 0, sizeof nl_script);
+ nl_script.active = if_index != 0;
+ nl_script.if_index = if_index;
+ nl_script.error = error;
+}
+
+static bool
+has_static_arp(const struct hmap *arps, uint32_t vni, uint8_t last)
+{
+ struct in6_addr ip = in6_addr_mapped_ipv4(htonl(0xc0000200 | last));
+ struct eth_addr mac = ETH_ADDR_C(02,00,00,00,00,00);
+ mac.ea[5] = last;
+ struct evpn_static_entry *entry;
+ HMAP_FOR_EACH (entry, hmap_node, arps) {
+ if (entry->vni == vni && ipv6_addr_equals(&entry->ip, &ip)
+ && eth_addr_equals(entry->mac, mac)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+static void
+test_neighbor_exchange_snapshot(struct ovs_cmdl_context *ctx)
+{
+ bool check_retry = !strcmp(ctx->argv[1], "retry");
+ bool replace_link = !strcmp(ctx->argv[1], "replace");
+ bool rename_link = !strcmp(ctx->argv[1], "rename");
+ bool write_error = !strcmp(ctx->argv[1], "write-error");
+ ovs_assert(check_retry || replace_link || rename_link || write_error
+ || !strcmp(ctx->argv[1], "retention"));
+ ovs_assert(ctx->argc == (replace_link ? 3 : 2));
+ struct neighbor_interface_monitor first = {
+ .family = NEIGH_AF_INET,
+ .if_name = "dump-br1",
+ .type = NEIGH_IFACE_BRIDGE,
+ .vni = 101,
+ .announced_neighbors = HMAP_INITIALIZER(&first.announced_neighbors),
+ };
+ struct neighbor_interface_monitor second = {
+ .family = NEIGH_AF_INET,
+ .if_name = "dump-br2",
+ .type = NEIGH_IFACE_BRIDGE,
+ .vni = 102,
+ .announced_neighbors = HMAP_INITIALIZER(&second.announced_neighbors),
+ };
+ struct vector interfaces =
+ VECTOR_EMPTY_INITIALIZER(struct neighbor_interface_monitor *);
+ struct neighbor_interface_monitor *mon = &first;
+ vector_push(&interfaces, &mon);
+ if (check_retry) {
+ /* The retry case only needs one dump target. */
+ ovs_strlcpy(first.if_name, "lo", sizeof first.if_name);
+ first.type = NEIGH_IFACE_LOOPBACK;
+ } else {
+ mon = &second;
+ vector_push(&interfaces, &mon);
+ }
+
+ struct hmap snapshots = HMAP_INITIALIZER(&snapshots);
+ struct hmap arps = HMAP_INITIALIZER(&arps);
+ struct hmap fdbs = HMAP_INITIALIZER(&fdbs);
+ struct hmap vteps = HMAP_INITIALIZER(&vteps);
+ struct vector watches = VECTOR_EMPTY_INITIALIZER(int32_t);
+ const struct neighbor_exchange_ctx_in input = {
+ .monitored_interfaces = &interfaces,
+ };
+ struct neighbor_exchange_ctx_out output = {
+ .neighbor_table_watches = &watches,
+ .snapshots = &snapshots,
+ .static_arps = &arps,
+ .static_fdbs = &fdbs,
+ .remote_vteps = &vteps,
+ };
+
+ int32_t if_index = if_nametoindex(first.if_name);
+ ovs_assert(if_index);
+ if (check_retry) {
+ neighbor_script_reset(if_index, EIO);
+
+ long long int now = time_msec();
+ poll_wakeup_at = 0;
+ neighbor_exchange_run(&input, &output);
+ ovs_assert(nl_script.started && nl_script.finished);
+ long long int retry_at = poll_wakeup_at;
+ ovs_assert(retry_at >= now + 1000 && retry_at <= time_msec() + 1000);
+ poll_wakeup_at = 0;
+ ovs_assert(!neighbor_exchange_retry_due());
+ ovs_assert(poll_wakeup_at == retry_at);
+ long long int deadline = time_msec() + 3000;
+ while (!neighbor_exchange_retry_due() && time_msec() < deadline) {
+ poll_timer_wait_until(deadline);
+ poll_block();
+ }
+ ovs_assert(neighbor_exchange_retry_due());
+
+ neighbor_script_reset(if_index, 0);
+ neighbor_exchange_run(&input, &output);
+ ovs_assert(nl_script.started && nl_script.finished);
+ ovs_assert(!neighbor_exchange_retry_due());
+ goto cleanup;
+ }
+
+ /* The second interface uses the real Netlink transport. */
+ neighbor_script_reset(if_index, 0);
+ neighbor_dump_add(AF_INET, if_index, NUD_NOARP, NTF_EXT_LEARNED, 0,
+ ETH_ADDR_LEN, 1);
+ neighbor_exchange_run(&input, &output);
+ ovs_assert(nl_script.started && nl_script.finished);
+ ovs_assert(hmap_count(&arps) == 2
+ && has_static_arp(&arps, 101, 1)
+ && has_static_arp(&arps, 102, 2));
+
+ if (rename_link) {
+ /* Rename a down bridge to a name outside the watch set. */
+ ovs_assert(!system("ip link set dump-br1 name dump-renamed"));
+ ovs_assert(if_nametoindex("dump-renamed") == (uint32_t) if_index);
+ bool changed = host_if_monitor_run();
+ neighbor_script_reset(if_index, EIO);
+ neighbor_exchange_run(&input, &output);
+ ovs_assert(hmap_count(&arps) == 1
+ && has_static_arp(&arps, 102, 2));
+ ovs_assert(changed && !nl_script.started
+ && vector_len(&watches) == 1);
+ goto cleanup;
+ }
+
+ if (replace_link) {
+ /* Consume the deletion and creation in a single monitor run. */
+ ovs_assert(!system(ctx->argv[2]));
+ ovs_assert(host_if_monitor_run());
+ ovs_assert(if_nametoindex(first.if_name) == (uint32_t) if_index);
+ }
+
+ if (write_error) {
+ /* A successful dump replaces the cache even when a delete fails. */
+ neighbor_script_reset(if_index, 0);
+ nl_script.transact_error = EIO;
+ neighbor_dump_add(AF_INET, if_index, NUD_NOARP, NTF_EXT_LEARNED, 0,
+ ETH_ADDR_LEN, 3);
+ neighbor_dump_add(AF_INET, if_index, NUD_NOARP, 0, 0, ETH_ADDR_LEN, 4);
+ poll_wakeup_at = 0;
+ neighbor_exchange_run(&input, &output);
+ ovs_assert(nl_script.started && nl_script.finished);
+ ovs_assert(nl_script.deletes == 1 && !nl_script.adds);
+ ovs_assert(poll_wakeup_at > 0 && !neighbor_exchange_retry_due());
+ ovs_assert(hmap_count(&arps) == 2
+ && has_static_arp(&arps, 101, 3)
+ && has_static_arp(&arps, 102, 2));
+ }
+
+ /* The healthy interface still refreshes. The partial dump must not
+ * publish its observation or write to the kernel. */
+ second.vni = 104;
+ neighbor_script_reset(if_index, EIO);
+ neighbor_dump_add(AF_INET, if_index, NUD_NOARP, NTF_EXT_LEARNED, 0,
+ ETH_ADDR_LEN, 5);
+ neighbor_exchange_run(&input, &output);
+ ovs_assert(nl_script.started && nl_script.finished);
+ ovs_assert(!nl_script.deletes && !nl_script.adds);
+ ovs_assert(hmap_count(&arps) == (replace_link ? 1 : 2)
+ && has_static_arp(&arps, 104, 2));
+ if (!replace_link) {
+ ovs_assert(has_static_arp(&arps, 101, write_error ? 3 : 1));
+ }
+ ovs_assert(vector_len(&watches) == 2);
+
+ /* Scope changes discard the old snapshot even during failure. */
+ first.vni = 103;
+ neighbor_script_reset(if_index, EIO);
+ neighbor_exchange_run(&input, &output);
+ ovs_assert(nl_script.started && nl_script.finished);
+ ovs_assert(hmap_count(&arps) == 1
+ && has_static_arp(&arps, 104, 2));
+
+ /* Recovery publishes fresh data. A complete empty dump withdraws it. */
+ first.vni = 101;
+ neighbor_script_reset(if_index, 0);
+ neighbor_dump_add(AF_INET, if_index, NUD_NOARP, NTF_EXT_LEARNED, 0,
+ ETH_ADDR_LEN, 3);
+ neighbor_exchange_run(&input, &output);
+ ovs_assert(hmap_count(&arps) == 2
+ && has_static_arp(&arps, 101, 3)
+ && has_static_arp(&arps, 104, 2));
+ neighbor_script_reset(if_index, 0);
+ neighbor_exchange_run(&input, &output);
+ ovs_assert(nl_script.started && nl_script.finished);
+ ovs_assert(hmap_count(&arps) == 1
+ && has_static_arp(&arps, 104, 2));
+ ovs_assert(!neighbor_exchange_retry_due());
+
+cleanup:
+ neighbor_script_reset(0, 0);
+ vector_clear(&interfaces);
+ neighbor_exchange_run(&input, &output);
+ ovs_assert(hmap_is_empty(&snapshots) && vector_is_empty(&watches));
+ hmap_destroy(&snapshots);
+ hmap_destroy(&arps);
+ hmap_destroy(&fdbs);
+ hmap_destroy(&vteps);
+ vector_destroy(&watches);
+ vector_destroy(&interfaces);
+ hmap_destroy(&first.announced_neighbors);
+ hmap_destroy(&second.announced_neighbors);
+}
+
+/* A failed dump must not be reported as successful synchronization. */
+static void
+test_neighbor_sync_error(struct ovs_cmdl_context *ctx OVS_UNUSED)
+{
+ struct hmap neighbors = HMAP_INITIALIZER(&neighbors);
+ struct vector learned =
+ VECTOR_EMPTY_INITIALIZER(struct ne_nl_received_neigh);
+ struct ne_nl_received_neigh sentinel = { .if_index = 42 };
+ vector_push(&learned, &sentinel);
+
+ /* This command starts without pooled Netlink sockets. Exhaust its file
+ * descriptor allowance so the real dump fails before receiving data. */
+ struct rlimit original;
+ ovs_assert(!getrlimit(RLIMIT_NOFILE, &original));
+ struct rlimit limited = original;
+ limited.rlim_cur = 0;
+ ovs_assert(!setrlimit(RLIMIT_NOFILE, &limited));
+ bool dump_failed;
+ int error = ne_nl_sync_neigh(AF_INET, 0, NEIGH_IFACE_UNSPECIFIED,
+ &neighbors, &learned, &dump_failed);
+ ovs_assert(!setrlimit(RLIMIT_NOFILE, &original));
+
+ ovs_assert(error == EMFILE && dump_failed);
+ ovs_assert(learned.len == 1);
+ ovs_assert(!memcmp(learned.buffer, &sentinel, sizeof sentinel));
+ vector_destroy(&learned);
+ hmap_destroy(&neighbors);
+}
+
static void
test_neighbor_exchange_retry(struct ovs_cmdl_context *ctx OVS_UNUSED)
{
@@ -211,6 +545,7 @@ test_neighbor_exchange_retry(struct ovs_cmdl_context *ctx
OVS_UNUSED)
VECTOR_EMPTY_INITIALIZER(struct neighbor_interface_monitor *);
struct neighbor_interface_monitor *monp = &mon;
vector_push(&interfaces, &monp);
+ struct hmap snapshots = HMAP_INITIALIZER(&snapshots);
struct hmap arps = HMAP_INITIALIZER(&arps);
struct hmap fdbs = HMAP_INITIALIZER(&fdbs);
struct hmap vteps = HMAP_INITIALIZER(&vteps);
@@ -220,6 +555,7 @@ test_neighbor_exchange_retry(struct ovs_cmdl_context *ctx
OVS_UNUSED)
};
struct neighbor_exchange_ctx_out output = {
.neighbor_table_watches = &watches,
+ .snapshots = &snapshots,
.static_arps = &arps,
.static_fdbs = &fdbs,
.remote_vteps = &vteps,
@@ -231,6 +567,8 @@ test_neighbor_exchange_retry(struct ovs_cmdl_context *ctx
OVS_UNUSED)
neighbor_dump_add(AF_INET, if_index, NUD_NOARP, 0, 0, ETH_ADDR_LEN, 2);
long long int now = time_msec();
poll_wakeup_at = 0;
+ nl_script.started = nl_script.finished = false;
+ nl_script.next = 0;
neighbor_exchange_run(&input, &output);
long long int retry_at = poll_wakeup_at;
ovs_assert(retry_at >= now + 1000 && retry_at <= time_msec() + 1000);
@@ -248,6 +586,8 @@ test_neighbor_exchange_retry(struct ovs_cmdl_context *ctx
OVS_UNUSED)
/* A persistent write error must schedule another bounded retry. */
now = time_msec();
poll_wakeup_at = 0;
+ nl_script.started = nl_script.finished = false;
+ nl_script.next = 0;
neighbor_exchange_run(&input, &output);
retry_at = poll_wakeup_at;
ovs_assert(retry_at >= now + 1000 && retry_at <= time_msec() + 1000);
@@ -258,6 +598,8 @@ test_neighbor_exchange_retry(struct ovs_cmdl_context *ctx
OVS_UNUSED)
/* Another engine input may run synchronization before the deadline. */
nl_script.transact_error = 0;
+ nl_script.started = nl_script.finished = false;
+ nl_script.next = 0;
neighbor_exchange_run(&input, &output);
ovs_assert(nl_script.adds == 3 && nl_script.deletes == 3);
ovs_assert(!neighbor_exchange_retry_due());
@@ -267,6 +609,8 @@ test_neighbor_exchange_retry(struct ovs_cmdl_context *ctx
OVS_UNUSED)
vector_destroy(&watches);
hmap_remove(&mon.announced_neighbors, &desired.node);
hmap_destroy(&mon.announced_neighbors);
+ neighbor_exchange_snapshots_clear(&snapshots);
+ hmap_destroy(&snapshots);
hmap_destroy(&arps);
hmap_destroy(&fdbs);
hmap_destroy(&vteps);
@@ -334,8 +678,10 @@ test_neighbor_sync(struct ovs_cmdl_context *ctx)
advertise_neigh_hash(&ane->lladdr, &ane->addr));
}
+ bool dump_failed;
ovs_assert(ne_nl_sync_neigh(family, if_index, NEIGH_IFACE_UNSPECIFIED,
- &neighbors_to_add, &received_neighbors) == 0);
+ &neighbors_to_add, &received_neighbors,
+ &dump_failed) == 0);
struct ne_nl_received_neigh *ne;
VECTOR_FOR_EACH_PTR (&received_neighbors, ne) {
@@ -432,7 +778,7 @@ test_host_if_monitor(struct ovs_cmdl_context *ctx)
exit(rc);
}
ovs_assert(host_if_monitor_run() == expect_notify);
- printf("%"PRId32"\n", host_if_monitor_ifname_toindex(if_name));
+ printf("%"PRId32"\n", host_if_monitor_get_link(if_name).if_index);
sset_destroy(&if_names);
}
@@ -783,6 +1129,11 @@ test_ovn_netlink(int argc, char *argv[])
{
set_program_name(argv[0]);
static const struct ovs_cmdl_command commands[] = {
+ {"neighbor-exchange-snapshot", NULL, 1, 2,
+ test_neighbor_exchange_snapshot, OVS_RO},
+ {"neighbor-dump-script", NULL, 1, 1,
+ test_neighbor_dump_script, OVS_RO},
+ {"neighbor-sync-error", NULL, 0, 0, test_neighbor_sync_error, OVS_RO},
{"neighbor-sync", NULL, 2, INT_MAX, test_neighbor_sync, OVS_RO},
{"neighbor-table-notify", NULL, 1, 1,
test_neighbor_table_notify, OVS_RO},
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev