From 78f29a1e5c3d4e8445008a6e0aebabe9ed0af0fe Mon Sep 17 00:00:00 2001
From: Nicolas Escande <nescande@freebox.fr>
Date: Fri, 17 Jun 2022 08:44:28 +0200
Subject: [PATCH 6/7] add error code for ENOBUFS

When the kernel tries to send messages to an application, if the application is
to slow to read the previously send messages, the kernel may not have enough
space in the socket receive buffer to put it's message and returns ENOBUFS.

In the case of a cache for example it means that you have missed some events and
that you have an inconsistent view of the kernel.

Previously this ENOBUFS error was returned in nl stack as a NLE_NOMEM, making it
impossible to handle it gracefully. Now we have a dedicated NLE_MISSED error
that explicitely reflect the fact that we missed messages from the kernel. Upper
layer apps will be able to specifically react to this error pattern.
---
 include/netlink/errno.h | 3 ++-
 lib/error.c             | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/netlink/errno.h b/include/netlink/errno.h
index 6a5b4de..1e98e85 100644
--- a/include/netlink/errno.h
+++ b/include/netlink/errno.h
@@ -45,8 +45,9 @@ extern "C" {
 #define NLE_IMMUTABLE		32
 #define NLE_DUMP_INTR		33
 #define NLE_ATTRSIZE		34
+#define NLE_MISSED		35
 
-#define NLE_MAX		NLE_ATTRSIZE
+#define NLE_MAX		NLE_MISSED
 
 extern const char *	nl_geterror(int);
 extern void		nl_perror(int, const char *);
diff --git a/lib/error.c b/lib/error.c
index bd0b92d..b37a3b2 100644
--- a/lib/error.c
+++ b/lib/error.c
@@ -42,6 +42,7 @@ static const char *errmsg[NLE_MAX+1] = {
 [NLE_IMMUTABLE]		= "Immutable attribute",
 [NLE_DUMP_INTR]		= "Dump inconsistency detected, interrupted",
 [NLE_ATTRSIZE]		= "Attribute max length exceeded",
+[NLE_MISSED]            = "Kernel reported missed message ",
 };
 
 /**
@@ -94,7 +95,7 @@ int nl_syserr2nlerr(int error)
 	case EFAULT:		return NLE_INVAL;
 	case EACCES:		return NLE_NOACCESS;
 	case EINVAL:		return NLE_INVAL;
-	case ENOBUFS:		return NLE_NOMEM;
+	case ENOBUFS:		return NLE_MISSED;
 	case ENOMEM:		return NLE_NOMEM;
 	case EAFNOSUPPORT:	return NLE_AF_NOSUPPORT;
 	case EPROTONOSUPPORT:	return NLE_PROTO_MISMATCH;
-- 
2.37.1

