From: Guillaume Boutry <[email protected]>
Failed neighbor adds or deletes trigger an immediate wake, causing
a busy loop while the error persists.
Commit 513048b06606 ("controller/route-exchange: Fix route-exchange
retry on error mechanism.") schedules a wake when an operation fails
so the controller retries. Keep that guarantee by scheduling the wake
one second later. Rearm the timer on failure. Other engine inputs
can still trigger an earlier retry. Call synchronization once per
interface and accumulate errors without skipping later interfaces.
Test failed adds and deletes, timer rearming and recovery before
the deadline.
Fixes: a6bd68fe5d38 ("controller: Add I-P to monitor host interfaces and
synchronize neighbors.")
Assisted-by: GPT-6.2 Sol, Codex
Signed-off-by: Guillaume Boutry <[email protected]>
---
controller/neighbor-exchange-stub.c | 6 +-
controller/neighbor-exchange.c | 50 +++---
controller/neighbor-exchange.h | 2 +-
controller/ovn-controller.c | 2 +-
tests/automake.mk | 9 +
tests/system-ovn-netlink.at | 5 +
tests/test-ovn-netlink.c | 248 ++++++++++++++++++++++++++++
7 files changed, 291 insertions(+), 31 deletions(-)
diff --git a/controller/neighbor-exchange-stub.c
b/controller/neighbor-exchange-stub.c
index a1c89ed2b..a5420fcff 100644
--- a/controller/neighbor-exchange-stub.c
+++ b/controller/neighbor-exchange-stub.c
@@ -23,10 +23,10 @@ neighbor_exchange_run(const struct neighbor_exchange_ctx_in
*ctx_in OVS_UNUSED,
{
}
-int
-neighbor_exchange_status_run(void)
+bool
+neighbor_exchange_retry_due(void)
{
- return 0;
+ return false;
}
void
diff --git a/controller/neighbor-exchange.c b/controller/neighbor-exchange.c
index df54969fb..4a6328492 100644
--- a/controller/neighbor-exchange.c
+++ b/controller/neighbor-exchange.c
@@ -25,6 +25,7 @@
#include "openvswitch/vlog.h"
#include "ovn-util.h"
#include "packets.h"
+#include "timeval.h"
#include "vec.h"
#include "unixctl.h"
@@ -47,23 +48,9 @@ static uint32_t evpn_static_entry_hash(const struct eth_addr
*mac,
const struct in6_addr *ip,
uint32_t vni, uint32_t nh_id);
-/* Last neighbor_exchange netlink operation. */
-static int neighbor_exchange_nl_status;
-
-#define CLEAR_NEIGHBOR_EXCHANGE_NL_STATUS() \
- do { \
- neighbor_exchange_nl_status = 0; \
- } while (0)
-
-#define SET_NEIGHBOR_EXCHANGE_NL_STATUS(error) \
- do { \
- if (!neighbor_exchange_nl_status) { \
- neighbor_exchange_nl_status = (error); \
- if (error) { \
- poll_immediate_wake(); \
- } \
- } \
- } while (0)
+/* Retry failed Netlink operations at most once per second in the absence
+ * of other engine inputs. */
+static long long int neighbor_exchange_retry_at;
void
neighbor_exchange_run(const struct neighbor_exchange_ctx_in *n_ctx_in,
@@ -78,20 +65,19 @@ neighbor_exchange_run(const struct neighbor_exchange_ctx_in
*n_ctx_in,
host_if_monitor_update_watches(&if_names);
sset_destroy(&if_names);
- CLEAR_NEIGHBOR_EXCHANGE_NL_STATUS();
+ 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) {
continue;
}
struct vector received_neighbors =
VECTOR_EMPTY_INITIALIZER(struct ne_nl_received_neigh);
- SET_NEIGHBOR_EXCHANGE_NL_STATUS(
- ne_nl_sync_neigh(nim->family, if_index, nim->type,
- &nim->announced_neighbors, &received_neighbors)
- );
+ int error = ne_nl_sync_neigh(nim->family, if_index, nim->type,
+ &nim->announced_neighbors,
+ &received_neighbors);
+ retry |= error != 0;
struct ne_nl_received_neigh *ne;
switch (nim->type) {
@@ -140,12 +126,24 @@ neighbor_exchange_run(const struct
neighbor_exchange_ctx_in *n_ctx_in,
vector_push(n_ctx_out->neighbor_table_watches, &if_index);
vector_destroy(&received_neighbors);
}
+
+ neighbor_exchange_retry_at = retry ? time_msec() + 1000 : 0;
+ if (retry) {
+ poll_timer_wait_until(neighbor_exchange_retry_at);
+ }
}
-int
-neighbor_exchange_status_run(void)
+bool
+neighbor_exchange_retry_due(void)
{
- return neighbor_exchange_nl_status;
+ if (!neighbor_exchange_retry_at) {
+ return false;
+ }
+ if (time_msec() >= neighbor_exchange_retry_at) {
+ return true;
+ }
+ poll_timer_wait_until(neighbor_exchange_retry_at);
+ return false;
}
void
diff --git a/controller/neighbor-exchange.h b/controller/neighbor-exchange.h
index 456ff23df..935477d7a 100644
--- a/controller/neighbor-exchange.h
+++ b/controller/neighbor-exchange.h
@@ -67,7 +67,7 @@ struct evpn_static_entry {
void neighbor_exchange_run(const struct neighbor_exchange_ctx_in *,
struct neighbor_exchange_ctx_out *);
-int neighbor_exchange_status_run(void);
+bool neighbor_exchange_retry_due(void);
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 b2cb0573f..0c414e903 100644
--- a/controller/ovn-controller.c
+++ b/controller/ovn-controller.c
@@ -8960,7 +8960,7 @@ main(int argc, char *argv[])
struct ed_type_neighbor_exchange_status *neigh_res =
engine_get_internal_data(&en_neighbor_exchange_status);
neigh_res->netlink_trigger_run =
- !!neighbor_exchange_status_run();
+ neighbor_exchange_retry_due();
stopwatch_start(CONTROLLER_LOOP_STOPWATCH_NAME,
time_msec());
diff --git a/tests/automake.mk b/tests/automake.mk
index 570d04bf9..6fef874a2 100644
--- a/tests/automake.mk
+++ b/tests/automake.mk
@@ -293,9 +293,18 @@ tests_ovstest_SOURCES = \
northd/test-ipam.c
if HAVE_NETLINK
+# Script Netlink operations and observe retry scheduling only in ovstest.
+tests_ovstest_LDFLAGS = $(AM_LDFLAGS) \
+ -Wl,--wrap=nl_dump_start \
+ -Wl,--wrap=nl_dump_next \
+ -Wl,--wrap=nl_dump_done \
+ -Wl,--wrap=nl_transact \
+ -Wl,--wrap=poll_timer_wait_until_at
+
tests_ovstest_SOURCES += \
controller/host-if-monitor.c \
controller/host-if-monitor.h \
+ controller/neighbor-exchange.c \
controller/neighbor-exchange-netlink.c \
controller/neighbor-exchange-netlink.h \
controller/nexthop-exchange.c \
diff --git a/tests/system-ovn-netlink.at b/tests/system-ovn-netlink.at
index 3dcf20649..ff2832f2a 100644
--- a/tests/system-ovn-netlink.at
+++ b/tests/system-ovn-netlink.at
@@ -1,5 +1,10 @@
AT_BANNER([system-ovn-netlink])
+AT_SETUP([sync netlink neighbors - retry failed writes])
+AT_KEYWORDS([netlink-neighbors netlink-retry])
+check ovstest test-ovn-netlink neighbor-exchange-retry
+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 4e5880b10..dd5ed46b6 100644
--- a/tests/test-ovn-netlink.c
+++ b/tests/test-ovn-netlink.c
@@ -14,7 +14,12 @@
*/
#include <config.h>
+#include <errno.h>
+#include <linux/rtnetlink.h>
+#include "netlink.h"
+#include "netlink-socket.h"
+#include "openvswitch/poll-loop.h"
#include "openvswitch/hmap.h"
#include "route-table.h"
#include "packets.h"
@@ -23,12 +28,253 @@
#include "controller/host-if-monitor.h"
#include "controller/neighbor-exchange-netlink.h"
+#include "controller/neighbor-exchange.h"
#include "controller/nexthop-exchange.h"
#include "controller/ovn-netlink-notifier.h"
#include "controller/neighbor.h"
#include "controller/route.h"
#include "controller/route-exchange-netlink.h"
+/* Script the dump transport and neighbor transactions. The normal
+ * ovstest commands delegate to the real Netlink functions. Production
+ * binaries do not use these linker wrappers. */
+static struct {
+ bool active;
+ bool started;
+ bool current;
+ int32_t if_index;
+ bool finished;
+ struct ofpbuf messages[4];
+ uint16_t request_type;
+ uint16_t done_flags;
+ size_t n_messages;
+ size_t next;
+ int error;
+ int transact_error;
+ unsigned int adds;
+ unsigned int deletes;
+} nl_script;
+
+static _Thread_local long long int poll_wakeup_at;
+
+void __real_poll_timer_wait_until_at(long long int, const char *);
+void __wrap_poll_timer_wait_until_at(long long int, const char *);
+
+void
+__wrap_poll_timer_wait_until_at(long long int when, const char *where)
+{
+ poll_wakeup_at = when;
+ __real_poll_timer_wait_until_at(when, where);
+}
+
+void __real_nl_dump_start(struct nl_dump *, int, const struct ofpbuf *);
+bool __real_nl_dump_next(struct nl_dump *, struct ofpbuf *, struct ofpbuf *);
+int __real_nl_dump_done(struct nl_dump *);
+int __real_nl_transact(int, const struct ofpbuf *, struct ofpbuf **);
+void __wrap_nl_dump_start(struct nl_dump *, int, const struct ofpbuf *);
+bool __wrap_nl_dump_next(struct nl_dump *, struct ofpbuf *, struct ofpbuf *);
+int __wrap_nl_dump_done(struct nl_dump *);
+int __wrap_nl_transact(int, const struct ofpbuf *, struct ofpbuf **);
+
+void
+__wrap_nl_dump_start(struct nl_dump *dump, int protocol,
+ const struct ofpbuf *request)
+{
+ nl_script.current = nl_script.active;
+ if (nl_script.current && nl_script.if_index) {
+ const struct nlattr *attr = nl_attr_find(
+ request, NLMSG_HDRLEN + sizeof(struct ndmsg), NDA_IFINDEX);
+ nl_script.current = attr && (nl_attr_get_u32(attr)
+ == (uint32_t) nl_script.if_index);
+ }
+ if (!nl_script.current) {
+ __real_nl_dump_start(dump, protocol, request);
+ return;
+ }
+ ovs_assert(protocol == NETLINK_ROUTE);
+ uint16_t type = nl_script.request_type ? nl_script.request_type
+ : RTM_GETNEIGH;
+ ovs_assert(nl_msg_nlmsghdr(request)->nlmsg_type == type);
+ dump->nl_flags = 0;
+ nl_script.next = 0;
+ nl_script.finished = false;
+ nl_script.started = true;
+}
+
+bool
+__wrap_nl_dump_next(struct nl_dump *dump, struct ofpbuf *reply,
+ struct ofpbuf *buf)
+{
+ if (!nl_script.current) {
+ return __real_nl_dump_next(dump, reply, buf);
+ }
+ ovs_assert(nl_script.started && !nl_script.finished);
+ if (nl_script.next == nl_script.n_messages) {
+ return false;
+ }
+ *reply = nl_script.messages[nl_script.next++];
+ return true;
+}
+
+int
+__wrap_nl_dump_done(struct nl_dump *dump)
+{
+ if (!nl_script.current) {
+ return __real_nl_dump_done(dump);
+ }
+ ovs_assert(nl_script.started && !nl_script.finished);
+ nl_script.finished = true;
+ dump->nl_flags = nl_script.done_flags;
+ return nl_script.error;
+}
+
+int
+__wrap_nl_transact(int protocol, const struct ofpbuf *request,
+ struct ofpbuf **reply)
+{
+ if (!nl_script.current) {
+ return __real_nl_transact(protocol, request, reply);
+ }
+ ovs_assert(protocol == NETLINK_ROUTE && !reply);
+ const struct ndmsg *nd = ofpbuf_at(request, NLMSG_HDRLEN, sizeof *nd);
+ ovs_assert(nd && nd->ndm_family == AF_INET);
+ ovs_assert(nd->ndm_ifindex == (nl_script.if_index ? nl_script.if_index
+ : 42));
+ switch (nl_msg_nlmsghdr(request)->nlmsg_type) {
+ case RTM_NEWNEIGH:
+ nl_script.adds++;
+ break;
+ case RTM_DELNEIGH:
+ nl_script.deletes++;
+ break;
+ default:
+ OVS_NOT_REACHED();
+ }
+ return nl_script.transact_error;
+}
+
+static struct ofpbuf *
+neighbor_dump_message(void)
+{
+ ovs_assert(nl_script.n_messages < ARRAY_SIZE(nl_script.messages));
+ struct ofpbuf *message =
+ &nl_script.messages[nl_script.n_messages++];
+ ofpbuf_init(message, 128);
+ nl_msg_put_nlmsghdr(message, 0, RTM_NEWNEIGH, 0);
+ return message;
+}
+
+static void
+neighbor_dump_add(uint8_t family, int32_t if_index, uint16_t state,
+ uint8_t nd_flags, uint16_t nl_flags, size_t lladdr_len,
+ uint8_t last)
+{
+ struct ofpbuf *message = neighbor_dump_message();
+ struct ndmsg *nd = ofpbuf_put_zeros(message, sizeof *nd);
+ nd->ndm_family = family;
+ nd->ndm_ifindex = if_index;
+ nd->ndm_state = state;
+ nd->ndm_flags = nd_flags;
+ ovs_be32 ip = htonl(0xc0000200 | last);
+ if (family == AF_INET) {
+ nl_msg_put_be32(message, NDA_DST, ip);
+ } else {
+ struct in6_addr ip6 = in6_addr_mapped_ipv4(ip);
+ nl_msg_put_in6_addr(message, NDA_DST, &ip6);
+ }
+ uint8_t mac[20] = { 0x02, 0, 0, 0, 0, last };
+ ovs_assert(lladdr_len <= sizeof mac);
+ nl_msg_put_unspec(message, NDA_LLADDR, mac, lladdr_len);
+ struct nlmsghdr *header = nl_msg_nlmsghdr(message);
+ header->nlmsg_flags = nl_flags;
+ header->nlmsg_len = message->size;
+}
+
+static void
+test_neighbor_exchange_retry(struct ovs_cmdl_context *ctx OVS_UNUSED)
+{
+ int32_t if_index = if_nametoindex("lo");
+ ovs_assert(if_index);
+ struct neighbor_interface_monitor mon = {
+ .family = NEIGH_AF_INET,
+ .if_name = "lo",
+ .type = NEIGH_IFACE_LOOPBACK,
+ .announced_neighbors = HMAP_INITIALIZER(&mon.announced_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(&mon.announced_neighbors, &desired.node,
+ advertise_neigh_hash(&desired.lladdr, &desired.addr));
+ struct vector interfaces =
+ VECTOR_EMPTY_INITIALIZER(struct neighbor_interface_monitor *);
+ struct neighbor_interface_monitor *monp = &mon;
+ vector_push(&interfaces, &monp);
+ 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,
+ .static_arps = &arps,
+ .static_fdbs = &fdbs,
+ .remote_vteps = &vteps,
+ };
+
+ nl_script.active = true;
+ nl_script.if_index = if_index;
+ nl_script.transact_error = EIO;
+ 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;
+ neighbor_exchange_run(&input, &output);
+ long long int retry_at = poll_wakeup_at;
+ ovs_assert(retry_at >= now + 1000 && retry_at <= time_msec() + 1000);
+ ovs_assert(nl_script.adds == 1 && nl_script.deletes == 1);
+ 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());
+
+ /* A persistent write error must schedule another bounded retry. */
+ now = time_msec();
+ poll_wakeup_at = 0;
+ neighbor_exchange_run(&input, &output);
+ retry_at = poll_wakeup_at;
+ ovs_assert(retry_at >= now + 1000 && retry_at <= time_msec() + 1000);
+ ovs_assert(nl_script.adds == 2 && nl_script.deletes == 2);
+ poll_wakeup_at = 0;
+ ovs_assert(!neighbor_exchange_retry_due());
+ ovs_assert(poll_wakeup_at == retry_at);
+
+ /* Another engine input may run synchronization before the deadline. */
+ nl_script.transact_error = 0;
+ neighbor_exchange_run(&input, &output);
+ ovs_assert(nl_script.adds == 3 && nl_script.deletes == 3);
+ ovs_assert(!neighbor_exchange_retry_due());
+ nl_script.active = false;
+ ofpbuf_uninit(&nl_script.messages[0]);
+ vector_destroy(&interfaces);
+ vector_destroy(&watches);
+ hmap_remove(&mon.announced_neighbors, &desired.node);
+ hmap_destroy(&mon.announced_neighbors);
+ hmap_destroy(&arps);
+ hmap_destroy(&fdbs);
+ hmap_destroy(&vteps);
+ struct sset none = SSET_INITIALIZER(&none);
+ host_if_monitor_update_watches(&none);
+ sset_destroy(&none);
+}
+
static void
test_neighbor_sync(struct ovs_cmdl_context *ctx)
{
@@ -540,6 +786,8 @@ test_ovn_netlink(int argc, char *argv[])
{"neighbor-sync", NULL, 2, INT_MAX, test_neighbor_sync, OVS_RO},
{"neighbor-table-notify", NULL, 1, 1,
test_neighbor_table_notify, OVS_RO},
+ {"neighbor-exchange-retry", NULL, 0, 0,
+ test_neighbor_exchange_retry, OVS_RO},
{"host-if-monitor", NULL, 2, 3, test_host_if_monitor, OVS_RO},
{"route-sync", NULL, 1, INT_MAX, test_route_sync, OVS_RO},
{"route-sync-nhids", NULL, 1, 1, test_route_sync_nhids, OVS_RO},
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev