From b2e0775bc6496572d0a79f06b9c5ca820447a57d Mon Sep 17 00:00:00 2001
From: Rany Hany <rany_hany@riseup.net>
Date: Mon, 13 May 2024 20:38:12 +0300
Subject: [PATCH] iproute2: fix build on GCC 14

Upstream patches:

401-bridge-vlan.c-bridge-vlan.c-fix-build-with-gcc-14-on.patch
402-bpf-fix-warning-from-basename.patch
403-bpf-include-libgen.h-for-basename.patch

The patch (400-rdma-include-libgen.h-for-basename.patch) was not
submitted upstream but just adds a missing include for basename.

Signed-off-by: Rany Hany <rany_hany@riseup.net>
---
 ...0-rdma-include-libgen.h-for-basename.patch | 10 +++
 ...idge-vlan.c-fix-build-with-gcc-14-on.patch | 69 +++++++++++++++++++
 .../402-bpf-fix-warning-from-basename.patch   | 38 ++++++++++
 ...03-bpf-include-libgen.h-for-basename.patch | 23 +++++++
 4 files changed, 140 insertions(+)
 create mode 100644 package/network/utils/iproute2/patches/400-rdma-include-libgen.h-for-basename.patch
 create mode 100644 package/network/utils/iproute2/patches/401-bridge-vlan.c-bridge-vlan.c-fix-build-with-gcc-14-on.patch
 create mode 100644 package/network/utils/iproute2/patches/402-bpf-fix-warning-from-basename.patch
 create mode 100644 package/network/utils/iproute2/patches/403-bpf-include-libgen.h-for-basename.patch

diff --git a/package/network/utils/iproute2/patches/400-rdma-include-libgen.h-for-basename.patch b/package/network/utils/iproute2/patches/400-rdma-include-libgen.h-for-basename.patch
new file mode 100644
index 0000000000..530d2bcffc
--- /dev/null
+++ b/package/network/utils/iproute2/patches/400-rdma-include-libgen.h-for-basename.patch
@@ -0,0 +1,10 @@
+--- a/rdma/rdma.h
++++ b/rdma/rdma.h
+@@ -16,6 +16,7 @@
+ #include <rdma/rdma_user_cm.h>
+ #include <time.h>
+ #include <net/if_arp.h>
++#include <libgen.h>
+ 
+ #include "list.h"
+ #include "utils.h"
diff --git a/package/network/utils/iproute2/patches/401-bridge-vlan.c-bridge-vlan.c-fix-build-with-gcc-14-on.patch b/package/network/utils/iproute2/patches/401-bridge-vlan.c-bridge-vlan.c-fix-build-with-gcc-14-on.patch
new file mode 100644
index 0000000000..a90c9fc80a
--- /dev/null
+++ b/package/network/utils/iproute2/patches/401-bridge-vlan.c-bridge-vlan.c-fix-build-with-gcc-14-on.patch
@@ -0,0 +1,69 @@
+From 53a89bfd86fff1a00cc77cabb8457a03eaa3bc7d Mon Sep 17 00:00:00 2001
+From: Gabi Falk <gabifalk@gmx.com>
+Date: Fri, 10 May 2024 14:36:12 +0000
+Subject: [PATCH] bridge/vlan.c: bridge/vlan.c: fix build with gcc 14 on musl
+ systems
+
+On glibc based systems the definition of 'struct timeval' is pulled in
+with inclusion of <stdlib.h> header, but on musl based systems it
+doesn't work this way.  Missing definition triggers an
+incompatible-pointer-types error with gcc 14 (warning on previous
+versions of gcc):
+
+../include/json_print.h:80:30: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
+   80 | _PRINT_FUNC(tv, const struct timeval *)
+      |                              ^~~~~~~
+../include/json_print.h:50:37: note: in definition of macro '_PRINT_FUNC'
+   50 |                                     type value);                        \
+      |                                     ^~~~
+../include/json_print.h:80:30: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
+   80 | _PRINT_FUNC(tv, const struct timeval *)
+      |                              ^~~~~~~
+../include/json_print.h:55:45: note: in definition of macro '_PRINT_FUNC'
+   55 |                                             type value)                 \
+      |                                             ^~~~
+../include/json_print.h: In function 'print_tv':
+../include/json_print.h:58:48: error: passing argument 5 of 'print_color_tv' from incompatible pointer type [-Wincompatible-pointer-types]
+   58 |                                                value);                  \
+      |                                                ^~~~~
+      |                                                |
+      |                                                const struct timeval *
+
+Signed-off-by: Gabi Falk <gabifalk@gmx.com>
+Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
+---
+ bridge/vlan.c | 1 +
+ bridge/vni.c  | 1 +
+ vdpa/vdpa.c   | 1 +
+ 3 files changed, 3 insertions(+)
+
+--- a/bridge/vlan.c
++++ b/bridge/vlan.c
+@@ -4,6 +4,7 @@
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <sys/socket.h>
++#include <sys/time.h>
+ #include <net/if.h>
+ #include <netinet/in.h>
+ #include <linux/if_bridge.h>
+--- a/bridge/vni.c
++++ b/bridge/vni.c
+@@ -10,6 +10,7 @@
+ #include <string.h>
+ #include <fcntl.h>
+ #include <sys/socket.h>
++#include <sys/time.h>
+ #include <net/if.h>
+ #include <netinet/in.h>
+ #include <linux/if_link.h>
+--- a/vdpa/vdpa.c
++++ b/vdpa/vdpa.c
+@@ -3,6 +3,7 @@
+ #include <stdio.h>
+ #include <getopt.h>
+ #include <errno.h>
++#include <sys/time.h>
+ #include <linux/genetlink.h>
+ #include <linux/if_ether.h>
+ #include <linux/vdpa.h>
diff --git a/package/network/utils/iproute2/patches/402-bpf-fix-warning-from-basename.patch b/package/network/utils/iproute2/patches/402-bpf-fix-warning-from-basename.patch
new file mode 100644
index 0000000000..8b40ffecf6
--- /dev/null
+++ b/package/network/utils/iproute2/patches/402-bpf-fix-warning-from-basename.patch
@@ -0,0 +1,38 @@
+From 69e3b2fadcd32683db2942f31fe41f0fbb2185f8 Mon Sep 17 00:00:00 2001
+From: Stephen Hemminger <stephen@networkplumber.org>
+Date: Sat, 27 Jan 2024 13:58:14 -0800
+Subject: [PATCH] bpf: fix warning from basename()
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The function basename() expects a mutable character string,
+which now causes a warning:
+
+bpf_legacy.c: In function ‘bpf_load_common’:
+bpf_legacy.c:975:38: warning: passing argument 1 of ‘__xpg_basename’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
+  975 |                          basename(cfg->object), cfg->mode == EBPF_PINNED ?
+      |                                   ~~~^~~~~~~~
+In file included from bpf_legacy.c:21:
+/usr/include/libgen.h:34:36: note: expected ‘char *’ but argument is of type ‘const char *’
+   34 | extern char *__xpg_basename (char *__path) __THROW;
+
+Fixes: f20ff2f19552 ("bpf: keep parsed program mode in struct bpf_cfg_in")
+Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
+---
+ lib/bpf_legacy.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+--- a/lib/bpf_legacy.c
++++ b/lib/bpf_legacy.c
+@@ -971,8 +971,8 @@ int bpf_load_common(struct bpf_cfg_in *c
+ 		ops->cbpf_cb(nl, cfg->opcodes, cfg->n_opcodes);
+ 	if (cfg->mode == EBPF_OBJECT || cfg->mode == EBPF_PINNED) {
+ 		snprintf(annotation, sizeof(annotation), "%s:[%s]",
+-			 basename(cfg->object), cfg->mode == EBPF_PINNED ?
+-			 "*fsobj" : cfg->section);
++			 basename(strdupa(cfg->object)),
++			 cfg->mode == EBPF_PINNED ? "*fsobj" : cfg->section);
+ 		ops->ebpf_cb(nl, cfg->prog_fd, annotation);
+ 	}
+ 
diff --git a/package/network/utils/iproute2/patches/403-bpf-include-libgen.h-for-basename.patch b/package/network/utils/iproute2/patches/403-bpf-include-libgen.h-for-basename.patch
new file mode 100644
index 0000000000..c65d94bd75
--- /dev/null
+++ b/package/network/utils/iproute2/patches/403-bpf-include-libgen.h-for-basename.patch
@@ -0,0 +1,23 @@
+From 64ed1886e719f40acb554ac895305acb43f27bea Mon Sep 17 00:00:00 2001
+From: Pedro Tammela <pctammela@mojatatu.com>
+Date: Mon, 22 Jan 2024 18:05:46 -0300
+Subject: [PATCH] bpf: include libgen.h for basename
+
+In musl basename() is only available via libgen.h
+
+Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
+Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
+---
+ lib/bpf_legacy.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/lib/bpf_legacy.c
++++ b/lib/bpf_legacy.c
+@@ -18,6 +18,7 @@
+ #include <stdarg.h>
+ #include <limits.h>
+ #include <assert.h>
++#include <libgen.h>
+ 
+ #ifdef HAVE_ELF
+ #include <libelf.h>
-- 
2.30.2