[PATCH v1] networking/libiproute/iplink.c: fix support for older kernels

Thomas Devoogdt thomas at devoogdt.com
Fri Oct 4 13:32:55 UTC 2024


- The CAN netlink interface has been added in Linux v2.6.31 with only 3 options [1]:

  CAN_CTRLMODE_LOOPBACK    0x1  /* Loopback mode */
  CAN_CTRLMODE_LISTENONLY  0x2  /* Listen-only mode */
  CAN_CTRLMODE_3_SAMPLES   0x4  /* Triple sampling mode */

  So define the other options.

- IFLA_CAN_TERMINATION has been added in Linux 4.11 [2],
  define it for older kernels.

[1] https://github.com/torvalds/linux/blob/v2.6.31/include/linux/can/netlink.h#L80-L82
[2] https://github.com/torvalds/linux/commit/12a6075cabc0d9ffbc0366b44daa22f278606312

Signed-off-by: Thomas Devoogdt <thomas at devoogdt.com>
---
 networking/libiproute/iplink.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c
index bc526d89c..c5cdfb823 100644
--- a/networking/libiproute/iplink.c
+++ b/networking/libiproute/iplink.c
@@ -5,6 +5,8 @@
  *
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
+#include <linux/version.h>
+
 #include <net/if.h>
 /*#include <net/if_packet.h> - not needed? */
 #include <linux/if_packet.h>
@@ -51,6 +53,27 @@ struct ifla_vlan_flags {
 };
 #endif
 
+#if ENABLE_FEATURE_IP_LINK_CAN
+#ifndef CAN_CTRLMODE_ONE_SHOT
+#define CAN_CTRLMODE_ONE_SHOT		0x08	/* One-Shot mode */
+#endif
+#ifndef CAN_CTRLMODE_BERR_REPORTING
+#define CAN_CTRLMODE_BERR_REPORTING	0x10	/* Bus-error reporting */
+#endif
+#ifndef CAN_CTRLMODE_FD
+#define CAN_CTRLMODE_FD				0x20	/* CAN FD mode */
+#endif
+#ifndef CAN_CTRLMODE_PRESUME_ACK
+#define CAN_CTRLMODE_PRESUME_ACK	0x40	/* Ignore missing CAN ACKs */
+#endif
+#ifndef CAN_CTRLMODE_FD_NON_ISO
+#define CAN_CTRLMODE_FD_NON_ISO		0x80	/* CAN FD in non-ISO mode */
+#endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
+#define IFLA_CAN_TERMINATION 11
+#endif
+#endif
+
 /* taken from linux/sockios.h */
 #define SIOCSIFNAME  0x8923  /* set interface name */
 
-- 
2.43.0



More information about the busybox mailing list