]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Netlink: move OS-specific headers and defines to sysdep
authorAlexander Chernikov <melifaro@FreeBSD.org>
Fri, 16 Dec 2022 18:20:05 +0000 (19:20 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Fri, 16 Dec 2022 18:21:51 +0000 (19:21 +0100)
Minor changes from committer.

sysdep/bsd-netlink/netlink-sys.h [new file with mode: 0644]
sysdep/cf/bsd-netlink.h
sysdep/cf/linux.h
sysdep/linux/netlink-sys.h [new file with mode: 0644]
sysdep/linux/netlink.c

diff --git a/sysdep/bsd-netlink/netlink-sys.h b/sysdep/bsd-netlink/netlink-sys.h
new file mode 100644 (file)
index 0000000..a6e5052
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ *     Netlink FreeBSD-specific functions
+ *
+ *     (c) 2022 Alexander Chernikov <melifaro@FreeBSD.org>
+ *
+ *     Can be freely distributed and used under the terms of the GNU GPL.
+ */
+
+#ifndef _BIRD_NETLINK_SYS_H_
+#define _BIRD_NETLINK_SYS_H_
+
+#include <netlink/netlink.h>
+#include <netlink/netlink_route.h>
+
+#ifndef        AF_MPLS
+#define        AF_MPLS 39
+#endif
+
+#ifndef        SO_RCVBUFFORCE
+#define        SO_RCVBUFFORCE  SO_RCVBUF
+#endif
+
+static inline int
+netlink_error_to_os(int error)
+{
+       return (error);
+}
+
+#endif
index 09149dc4940c92e4a08e687c2d599950e5f289db..6929786780ba85d9052dad7185f7b80c4a1c3987 100644 (file)
 
 #define CONFIG_INCLUDE_SYSIO_H "sysdep/bsd/sysio.h"
 #define CONFIG_INCLUDE_KRTSYS_H "sysdep/linux/krt-sys.h"
-
-#define        CONFIG_FREEBSD_NETLINK
-
-#ifndef        AF_MPLS
-#define        AF_MPLS 39
-#endif
-
-#ifndef        SO_RCVBUFFORCE
-#define        SO_RCVBUFFORCE  SO_RCVBUF
-#endif
+#define CONFIG_INCLUDE_NLSYS_H "sysdep/bsd-netlink/netlink-sys.h"
 
 /*
 Link: sysdep/unix
index 85598c10248bcf619b45fa0681795a5b9d650780..9c37dd8a61d6ec7f9ae0b866111d1c821bd20cea 100644 (file)
@@ -16,6 +16,7 @@
 
 #define CONFIG_INCLUDE_SYSIO_H "sysdep/linux/sysio.h"
 #define CONFIG_INCLUDE_KRTSYS_H "sysdep/linux/krt-sys.h"
+#define CONFIG_INCLUDE_NLSYS_H "sysdep/linux/netlink-sys.h"
 
 #define CONFIG_LINUX_NETLINK
 
diff --git a/sysdep/linux/netlink-sys.h b/sysdep/linux/netlink-sys.h
new file mode 100644 (file)
index 0000000..4c99307
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ *     BIRD -- Linux Netlink Interface
+ *
+ *     (c) 1999--2000 Martin Mares <mj@ucw.cz>
+ *
+ *     Can be freely distributed and used under the terms of the GNU GPL.
+ */
+
+#ifndef _BIRD_NETLINK_SYS_H_
+#define _BIRD_NETLINK_SYS_H_
+
+#include <asm/types.h>
+#include <linux/if.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+
+#ifdef HAVE_MPLS_KERNEL
+#include <linux/lwtunnel.h>
+#endif
+
+#ifndef MSG_TRUNC                      /* Hack: Several versions of glibc miss this one :( */
+#define MSG_TRUNC 0x20
+#endif
+
+#ifndef IFA_FLAGS
+#define IFA_FLAGS 8
+#endif
+
+#ifndef IFF_LOWER_UP
+#define IFF_LOWER_UP 0x10000
+#endif
+
+#ifndef RTA_TABLE
+#define RTA_TABLE  15
+#endif
+
+#ifndef RTA_VIA
+#define RTA_VIA         18
+#endif
+
+#ifndef RTA_NEWDST
+#define RTA_NEWDST  19
+#endif
+
+#ifndef RTA_ENCAP_TYPE
+#define RTA_ENCAP_TYPE 21
+#endif
+
+#ifndef RTA_ENCAP
+#define RTA_ENCAP  22
+#endif
+
+#ifndef NETLINK_GET_STRICT_CHK
+#define NETLINK_GET_STRICT_CHK 12
+#endif
+
+static inline int
+netlink_error_to_os(int error)
+{
+       return -error;
+}
+
+#endif
index dcb2591179129a35361ac2d5b936491ac04ea92f..7f0d4736898a3b2ad33bf2fdf69301206d01df65 100644 (file)
 #include "lib/hash.h"
 #include "conf/conf.h"
 
-#ifdef CONFIG_LINUX_NETLINK
-#include <asm/types.h>
-#include <linux/if.h>
-#include <linux/netlink.h>
-#include <linux/rtnetlink.h>
-#endif
-#ifdef CONFIG_FREEBSD_NETLINK
-#include <netlink/netlink.h>
-#include <netlink/netlink_route.h>
-#endif
-
-#ifdef HAVE_MPLS_KERNEL
-#include <linux/lwtunnel.h>
-#endif
-
-#ifndef MSG_TRUNC                      /* Hack: Several versions of glibc miss this one :( */
-#define MSG_TRUNC 0x20
-#endif
-
-#ifndef IFA_FLAGS
-#define IFA_FLAGS 8
-#endif
-
-#ifndef IFF_LOWER_UP
-#define IFF_LOWER_UP 0x10000
-#endif
-
-#ifndef RTA_TABLE
-#define RTA_TABLE  15
-#endif
-
-#ifndef RTA_VIA
-#define RTA_VIA         18
-#endif
-
-#ifndef RTA_NEWDST
-#define RTA_NEWDST  19
-#endif
-
-#ifndef RTA_ENCAP_TYPE
-#define RTA_ENCAP_TYPE 21
-#endif
-
-#ifndef RTA_ENCAP
-#define RTA_ENCAP  22
-#endif
-
-#ifndef NETLINK_GET_STRICT_CHK
-#define NETLINK_GET_STRICT_CHK 12
-#endif
+#include CONFIG_INCLUDE_NLSYS_H
 
 #define krt_ipv4(p) ((p)->af == AF_INET)
 
@@ -320,7 +271,7 @@ nl_error(struct nlmsghdr *h, int ignore_esrch)
       return ENOBUFS;
     }
   e = (struct nlmsgerr *) NLMSG_DATA(h);
-  ec = -e->error;
+  ec = netlink_error_to_os(e->error);
   if (ec && !(ignore_esrch && (ec == ESRCH)))
     log_rl(&rl_netlink_err, L_WARN "Netlink: %s", strerror(ec));
   return ec;