ethtool: update to 6.1
[openwrt/openwrt.git] / package / network / utils / ethtool / patches / 100-uapi-Bring-in-if-h.patch
1 From: Florian Fainelli <f.fainelli@gmail.com>
2 To: netdev@vger.kernel.org
3 Subject: [PATCH ethtool v2 1/3] uapi: Bring in if.h
4 Date: Sat, 14 Jan 2023 08:34:09 -0800
5
6 Bring in if.h from commit eec517cdb481 ("net: Add IF_OPER_TESTING") as
7 well as uapi/linux/hdlc/ioctl.h. Ensure that we define all of the
8 necessary guards to provide updated definitions of ifmap, ifreq and
9 IFNAMSIZ. This resolves build issues with kernel headers < 4.11 which
10 lacked 2618be7dccf8739b89e1906b64bd8d551af351e6 ("uapi: fix linux/if.h
11 userspace compilation errors").
12
13 Fixes: 1fa60003a8b8 ("misc: header includes cleanup")
14 Reported-by: Markus Mayer <mmayer@broadcom.com>
15 Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
16 ---
17 Makefile.am | 6 +-
18 internal.h | 7 +-
19 uapi/linux/hdlc/ioctl.h | 94 +++++++++++++
20 uapi/linux/if.h | 296 ++++++++++++++++++++++++++++++++++++++++
21 4 files changed, 397 insertions(+), 6 deletions(-)
22 create mode 100644 uapi/linux/hdlc/ioctl.h
23 create mode 100644 uapi/linux/if.h
24
25 --- a/Makefile.am
26 +++ b/Makefile.am
27 @@ -7,7 +7,8 @@ EXTRA_DIST = LICENSE ethtool.8 ethtool.s
28
29 sbin_PROGRAMS = ethtool
30 ethtool_SOURCES = ethtool.c uapi/linux/ethtool.h internal.h \
31 - uapi/linux/net_tstamp.h rxclass.c common.c common.h \
32 + uapi/linux/net_tstamp.h uapi/linux/if.h uapi/linux/hdlc/ioctl.h \
33 + rxclass.c common.c common.h \
34 json_writer.c json_writer.h json_print.c json_print.h \
35 list.h
36 if ETHTOOL_ENABLE_PRETTY_DUMP
37 @@ -43,7 +44,8 @@ ethtool_SOURCES += \
38 netlink/desc-rtnl.c netlink/cable_test.c netlink/tunnels.c \
39 uapi/linux/ethtool_netlink.h \
40 uapi/linux/netlink.h uapi/linux/genetlink.h \
41 - uapi/linux/rtnetlink.h uapi/linux/if_link.h
42 + uapi/linux/rtnetlink.h uapi/linux/if_link.h \
43 + uapi/linux/if.h uapi/linux/hdlc/ioctl.h
44 AM_CPPFLAGS += @MNL_CFLAGS@
45 LDADD += @MNL_LIBS@
46 endif
47 --- a/internal.h
48 +++ b/internal.h
49 @@ -21,6 +21,9 @@
50 #include <unistd.h>
51 #include <endian.h>
52 #include <sys/ioctl.h>
53 +#define __UAPI_DEF_IF_IFNAMSIZ 1
54 +#define __UAPI_DEF_IF_IFMAP 1
55 +#define __UAPI_DEF_IF_IFREQ 1
56 #include <linux/if.h>
57
58 #include "json_writer.h"
59 @@ -52,10 +55,6 @@ typedef int32_t s32;
60 #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
61 #endif
62
63 -#ifndef ALTIFNAMSIZ
64 -#define ALTIFNAMSIZ 128
65 -#endif
66 -
67 #include <linux/ethtool.h>
68 #include <linux/net_tstamp.h>
69
70 --- /dev/null
71 +++ b/uapi/linux/hdlc/ioctl.h
72 @@ -0,0 +1,94 @@
73 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
74 +#ifndef __HDLC_IOCTL_H__
75 +#define __HDLC_IOCTL_H__
76 +
77 +
78 +#define GENERIC_HDLC_VERSION 4 /* For synchronization with sethdlc utility */
79 +
80 +#define CLOCK_DEFAULT 0 /* Default setting */
81 +#define CLOCK_EXT 1 /* External TX and RX clock - DTE */
82 +#define CLOCK_INT 2 /* Internal TX and RX clock - DCE */
83 +#define CLOCK_TXINT 3 /* Internal TX and external RX clock */
84 +#define CLOCK_TXFROMRX 4 /* TX clock derived from external RX clock */
85 +
86 +
87 +#define ENCODING_DEFAULT 0 /* Default setting */
88 +#define ENCODING_NRZ 1
89 +#define ENCODING_NRZI 2
90 +#define ENCODING_FM_MARK 3
91 +#define ENCODING_FM_SPACE 4
92 +#define ENCODING_MANCHESTER 5
93 +
94 +
95 +#define PARITY_DEFAULT 0 /* Default setting */
96 +#define PARITY_NONE 1 /* No parity */
97 +#define PARITY_CRC16_PR0 2 /* CRC16, initial value 0x0000 */
98 +#define PARITY_CRC16_PR1 3 /* CRC16, initial value 0xFFFF */
99 +#define PARITY_CRC16_PR0_CCITT 4 /* CRC16, initial 0x0000, ITU-T version */
100 +#define PARITY_CRC16_PR1_CCITT 5 /* CRC16, initial 0xFFFF, ITU-T version */
101 +#define PARITY_CRC32_PR0_CCITT 6 /* CRC32, initial value 0x00000000 */
102 +#define PARITY_CRC32_PR1_CCITT 7 /* CRC32, initial value 0xFFFFFFFF */
103 +
104 +#define LMI_DEFAULT 0 /* Default setting */
105 +#define LMI_NONE 1 /* No LMI, all PVCs are static */
106 +#define LMI_ANSI 2 /* ANSI Annex D */
107 +#define LMI_CCITT 3 /* ITU-T Annex A */
108 +#define LMI_CISCO 4 /* The "original" LMI, aka Gang of Four */
109 +
110 +#ifndef __ASSEMBLY__
111 +
112 +typedef struct {
113 + unsigned int clock_rate; /* bits per second */
114 + unsigned int clock_type; /* internal, external, TX-internal etc. */
115 + unsigned short loopback;
116 +} sync_serial_settings; /* V.35, V.24, X.21 */
117 +
118 +typedef struct {
119 + unsigned int clock_rate; /* bits per second */
120 + unsigned int clock_type; /* internal, external, TX-internal etc. */
121 + unsigned short loopback;
122 + unsigned int slot_map;
123 +} te1_settings; /* T1, E1 */
124 +
125 +typedef struct {
126 + unsigned short encoding;
127 + unsigned short parity;
128 +} raw_hdlc_proto;
129 +
130 +typedef struct {
131 + unsigned int t391;
132 + unsigned int t392;
133 + unsigned int n391;
134 + unsigned int n392;
135 + unsigned int n393;
136 + unsigned short lmi;
137 + unsigned short dce; /* 1 for DCE (network side) operation */
138 +} fr_proto;
139 +
140 +typedef struct {
141 + unsigned int dlci;
142 +} fr_proto_pvc; /* for creating/deleting FR PVCs */
143 +
144 +typedef struct {
145 + unsigned int dlci;
146 + char master[IFNAMSIZ]; /* Name of master FRAD device */
147 +}fr_proto_pvc_info; /* for returning PVC information only */
148 +
149 +typedef struct {
150 + unsigned int interval;
151 + unsigned int timeout;
152 +} cisco_proto;
153 +
154 +typedef struct {
155 + unsigned short dce; /* 1 for DCE (network side) operation */
156 + unsigned int modulo; /* modulo (8 = basic / 128 = extended) */
157 + unsigned int window; /* frame window size */
158 + unsigned int t1; /* timeout t1 */
159 + unsigned int t2; /* timeout t2 */
160 + unsigned int n2; /* frame retry counter */
161 +} x25_hdlc_proto;
162 +
163 +/* PPP doesn't need any info now - supply length = 0 to ioctl */
164 +
165 +#endif /* __ASSEMBLY__ */
166 +#endif /* __HDLC_IOCTL_H__ */
167 --- /dev/null
168 +++ b/uapi/linux/if.h
169 @@ -0,0 +1,296 @@
170 +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
171 +/*
172 + * INET An implementation of the TCP/IP protocol suite for the LINUX
173 + * operating system. INET is implemented using the BSD Socket
174 + * interface as the means of communication with the user level.
175 + *
176 + * Global definitions for the INET interface module.
177 + *
178 + * Version: @(#)if.h 1.0.2 04/18/93
179 + *
180 + * Authors: Original taken from Berkeley UNIX 4.3, (c) UCB 1982-1988
181 + * Ross Biro
182 + * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
183 + *
184 + * This program is free software; you can redistribute it and/or
185 + * modify it under the terms of the GNU General Public License
186 + * as published by the Free Software Foundation; either version
187 + * 2 of the License, or (at your option) any later version.
188 + */
189 +#ifndef _LINUX_IF_H
190 +#define _LINUX_IF_H
191 +
192 +#include <linux/libc-compat.h> /* for compatibility with glibc */
193 +#include <linux/types.h> /* for "__kernel_caddr_t" et al */
194 +#include <linux/socket.h> /* for "struct sockaddr" et al */
195 + /* for "__user" et al */
196 +
197 +#include <sys/socket.h> /* for struct sockaddr. */
198 +
199 +#if __UAPI_DEF_IF_IFNAMSIZ
200 +#define IFNAMSIZ 16
201 +#endif /* __UAPI_DEF_IF_IFNAMSIZ */
202 +#define IFALIASZ 256
203 +#define ALTIFNAMSIZ 128
204 +#include <linux/hdlc/ioctl.h>
205 +
206 +/* For glibc compatibility. An empty enum does not compile. */
207 +#if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 || \
208 + __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0
209 +/**
210 + * enum net_device_flags - &struct net_device flags
211 + *
212 + * These are the &struct net_device flags, they can be set by drivers, the
213 + * kernel and some can be triggered by userspace. Userspace can query and
214 + * set these flags using userspace utilities but there is also a sysfs
215 + * entry available for all dev flags which can be queried and set. These flags
216 + * are shared for all types of net_devices. The sysfs entries are available
217 + * via /sys/class/net/<dev>/flags. Flags which can be toggled through sysfs
218 + * are annotated below, note that only a few flags can be toggled and some
219 + * other flags are always preserved from the original net_device flags
220 + * even if you try to set them via sysfs. Flags which are always preserved
221 + * are kept under the flag grouping @IFF_VOLATILE. Flags which are __volatile__
222 + * are annotated below as such.
223 + *
224 + * You should have a pretty good reason to be extending these flags.
225 + *
226 + * @IFF_UP: interface is up. Can be toggled through sysfs.
227 + * @IFF_BROADCAST: broadcast address valid. Volatile.
228 + * @IFF_DEBUG: turn on debugging. Can be toggled through sysfs.
229 + * @IFF_LOOPBACK: is a loopback net. Volatile.
230 + * @IFF_POINTOPOINT: interface is has p-p link. Volatile.
231 + * @IFF_NOTRAILERS: avoid use of trailers. Can be toggled through sysfs.
232 + * Volatile.
233 + * @IFF_RUNNING: interface RFC2863 OPER_UP. Volatile.
234 + * @IFF_NOARP: no ARP protocol. Can be toggled through sysfs. Volatile.
235 + * @IFF_PROMISC: receive all packets. Can be toggled through sysfs.
236 + * @IFF_ALLMULTI: receive all multicast packets. Can be toggled through
237 + * sysfs.
238 + * @IFF_MASTER: master of a load balancer. Volatile.
239 + * @IFF_SLAVE: slave of a load balancer. Volatile.
240 + * @IFF_MULTICAST: Supports multicast. Can be toggled through sysfs.
241 + * @IFF_PORTSEL: can set media type. Can be toggled through sysfs.
242 + * @IFF_AUTOMEDIA: auto media select active. Can be toggled through sysfs.
243 + * @IFF_DYNAMIC: dialup device with changing addresses. Can be toggled
244 + * through sysfs.
245 + * @IFF_LOWER_UP: driver signals L1 up. Volatile.
246 + * @IFF_DORMANT: driver signals dormant. Volatile.
247 + * @IFF_ECHO: echo sent packets. Volatile.
248 + */
249 +enum net_device_flags {
250 +/* for compatibility with glibc net/if.h */
251 +#if __UAPI_DEF_IF_NET_DEVICE_FLAGS
252 + IFF_UP = 1<<0, /* sysfs */
253 + IFF_BROADCAST = 1<<1, /* __volatile__ */
254 + IFF_DEBUG = 1<<2, /* sysfs */
255 + IFF_LOOPBACK = 1<<3, /* __volatile__ */
256 + IFF_POINTOPOINT = 1<<4, /* __volatile__ */
257 + IFF_NOTRAILERS = 1<<5, /* sysfs */
258 + IFF_RUNNING = 1<<6, /* __volatile__ */
259 + IFF_NOARP = 1<<7, /* sysfs */
260 + IFF_PROMISC = 1<<8, /* sysfs */
261 + IFF_ALLMULTI = 1<<9, /* sysfs */
262 + IFF_MASTER = 1<<10, /* __volatile__ */
263 + IFF_SLAVE = 1<<11, /* __volatile__ */
264 + IFF_MULTICAST = 1<<12, /* sysfs */
265 + IFF_PORTSEL = 1<<13, /* sysfs */
266 + IFF_AUTOMEDIA = 1<<14, /* sysfs */
267 + IFF_DYNAMIC = 1<<15, /* sysfs */
268 +#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS */
269 +#if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
270 + IFF_LOWER_UP = 1<<16, /* __volatile__ */
271 + IFF_DORMANT = 1<<17, /* __volatile__ */
272 + IFF_ECHO = 1<<18, /* __volatile__ */
273 +#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
274 +};
275 +#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 || __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0 */
276 +
277 +/* for compatibility with glibc net/if.h */
278 +#if __UAPI_DEF_IF_NET_DEVICE_FLAGS
279 +#define IFF_UP IFF_UP
280 +#define IFF_BROADCAST IFF_BROADCAST
281 +#define IFF_DEBUG IFF_DEBUG
282 +#define IFF_LOOPBACK IFF_LOOPBACK
283 +#define IFF_POINTOPOINT IFF_POINTOPOINT
284 +#define IFF_NOTRAILERS IFF_NOTRAILERS
285 +#define IFF_RUNNING IFF_RUNNING
286 +#define IFF_NOARP IFF_NOARP
287 +#define IFF_PROMISC IFF_PROMISC
288 +#define IFF_ALLMULTI IFF_ALLMULTI
289 +#define IFF_MASTER IFF_MASTER
290 +#define IFF_SLAVE IFF_SLAVE
291 +#define IFF_MULTICAST IFF_MULTICAST
292 +#define IFF_PORTSEL IFF_PORTSEL
293 +#define IFF_AUTOMEDIA IFF_AUTOMEDIA
294 +#define IFF_DYNAMIC IFF_DYNAMIC
295 +#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS */
296 +
297 +#if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
298 +#define IFF_LOWER_UP IFF_LOWER_UP
299 +#define IFF_DORMANT IFF_DORMANT
300 +#define IFF_ECHO IFF_ECHO
301 +#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
302 +
303 +#define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|IFF_ECHO|\
304 + IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT)
305 +
306 +#define IF_GET_IFACE 0x0001 /* for querying only */
307 +#define IF_GET_PROTO 0x0002
308 +
309 +/* For definitions see hdlc.h */
310 +#define IF_IFACE_V35 0x1000 /* V.35 serial interface */
311 +#define IF_IFACE_V24 0x1001 /* V.24 serial interface */
312 +#define IF_IFACE_X21 0x1002 /* X.21 serial interface */
313 +#define IF_IFACE_T1 0x1003 /* T1 telco serial interface */
314 +#define IF_IFACE_E1 0x1004 /* E1 telco serial interface */
315 +#define IF_IFACE_SYNC_SERIAL 0x1005 /* can't be set by software */
316 +#define IF_IFACE_X21D 0x1006 /* X.21 Dual Clocking (FarSite) */
317 +
318 +/* For definitions see hdlc.h */
319 +#define IF_PROTO_HDLC 0x2000 /* raw HDLC protocol */
320 +#define IF_PROTO_PPP 0x2001 /* PPP protocol */
321 +#define IF_PROTO_CISCO 0x2002 /* Cisco HDLC protocol */
322 +#define IF_PROTO_FR 0x2003 /* Frame Relay protocol */
323 +#define IF_PROTO_FR_ADD_PVC 0x2004 /* Create FR PVC */
324 +#define IF_PROTO_FR_DEL_PVC 0x2005 /* Delete FR PVC */
325 +#define IF_PROTO_X25 0x2006 /* X.25 */
326 +#define IF_PROTO_HDLC_ETH 0x2007 /* raw HDLC, Ethernet emulation */
327 +#define IF_PROTO_FR_ADD_ETH_PVC 0x2008 /* Create FR Ethernet-bridged PVC */
328 +#define IF_PROTO_FR_DEL_ETH_PVC 0x2009 /* Delete FR Ethernet-bridged PVC */
329 +#define IF_PROTO_FR_PVC 0x200A /* for reading PVC status */
330 +#define IF_PROTO_FR_ETH_PVC 0x200B
331 +#define IF_PROTO_RAW 0x200C /* RAW Socket */
332 +
333 +/* RFC 2863 operational status */
334 +enum {
335 + IF_OPER_UNKNOWN,
336 + IF_OPER_NOTPRESENT,
337 + IF_OPER_DOWN,
338 + IF_OPER_LOWERLAYERDOWN,
339 + IF_OPER_TESTING,
340 + IF_OPER_DORMANT,
341 + IF_OPER_UP,
342 +};
343 +
344 +/* link modes */
345 +enum {
346 + IF_LINK_MODE_DEFAULT,
347 + IF_LINK_MODE_DORMANT, /* limit upward transition to dormant */
348 + IF_LINK_MODE_TESTING, /* limit upward transition to testing */
349 +};
350 +
351 +/*
352 + * Device mapping structure. I'd just gone off and designed a
353 + * beautiful scheme using only loadable modules with arguments
354 + * for driver options and along come the PCMCIA people 8)
355 + *
356 + * Ah well. The get() side of this is good for WDSETUP, and it'll
357 + * be handy for debugging things. The set side is fine for now and
358 + * being very small might be worth keeping for clean configuration.
359 + */
360 +
361 +/* for compatibility with glibc net/if.h */
362 +#if __UAPI_DEF_IF_IFMAP
363 +struct ifmap {
364 + unsigned long mem_start;
365 + unsigned long mem_end;
366 + unsigned short base_addr;
367 + unsigned char irq;
368 + unsigned char dma;
369 + unsigned char port;
370 + /* 3 bytes spare */
371 +};
372 +#endif /* __UAPI_DEF_IF_IFMAP */
373 +
374 +struct if_settings {
375 + unsigned int type; /* Type of physical device or protocol */
376 + unsigned int size; /* Size of the data allocated by the caller */
377 + union {
378 + /* {atm/eth/dsl}_settings anyone ? */
379 + raw_hdlc_proto *raw_hdlc;
380 + cisco_proto *cisco;
381 + fr_proto *fr;
382 + fr_proto_pvc *fr_pvc;
383 + fr_proto_pvc_info *fr_pvc_info;
384 + x25_hdlc_proto *x25;
385 +
386 + /* interface settings */
387 + sync_serial_settings *sync;
388 + te1_settings *te1;
389 + } ifs_ifsu;
390 +};
391 +
392 +/*
393 + * Interface request structure used for socket
394 + * ioctl's. All interface ioctl's must have parameter
395 + * definitions which begin with ifr_name. The
396 + * remainder may be interface specific.
397 + */
398 +
399 +/* for compatibility with glibc net/if.h */
400 +#if __UAPI_DEF_IF_IFREQ
401 +struct ifreq {
402 +#define IFHWADDRLEN 6
403 + union
404 + {
405 + char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
406 + } ifr_ifrn;
407 +
408 + union {
409 + struct sockaddr ifru_addr;
410 + struct sockaddr ifru_dstaddr;
411 + struct sockaddr ifru_broadaddr;
412 + struct sockaddr ifru_netmask;
413 + struct sockaddr ifru_hwaddr;
414 + short ifru_flags;
415 + int ifru_ivalue;
416 + int ifru_mtu;
417 + struct ifmap ifru_map;
418 + char ifru_slave[IFNAMSIZ]; /* Just fits the size */
419 + char ifru_newname[IFNAMSIZ];
420 + void * ifru_data;
421 + struct if_settings ifru_settings;
422 + } ifr_ifru;
423 +};
424 +#endif /* __UAPI_DEF_IF_IFREQ */
425 +
426 +#define ifr_name ifr_ifrn.ifrn_name /* interface name */
427 +#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
428 +#define ifr_addr ifr_ifru.ifru_addr /* address */
429 +#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-p lnk */
430 +#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
431 +#define ifr_netmask ifr_ifru.ifru_netmask /* interface net mask */
432 +#define ifr_flags ifr_ifru.ifru_flags /* flags */
433 +#define ifr_metric ifr_ifru.ifru_ivalue /* metric */
434 +#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
435 +#define ifr_map ifr_ifru.ifru_map /* device map */
436 +#define ifr_slave ifr_ifru.ifru_slave /* slave device */
437 +#define ifr_data ifr_ifru.ifru_data /* for use by interface */
438 +#define ifr_ifindex ifr_ifru.ifru_ivalue /* interface index */
439 +#define ifr_bandwidth ifr_ifru.ifru_ivalue /* link bandwidth */
440 +#define ifr_qlen ifr_ifru.ifru_ivalue /* Queue length */
441 +#define ifr_newname ifr_ifru.ifru_newname /* New name */
442 +#define ifr_settings ifr_ifru.ifru_settings /* Device/proto settings*/
443 +
444 +/*
445 + * Structure used in SIOCGIFCONF request.
446 + * Used to retrieve interface configuration
447 + * for machine (useful for programs which
448 + * must know all networks accessible).
449 + */
450 +
451 +/* for compatibility with glibc net/if.h */
452 +#if __UAPI_DEF_IF_IFCONF
453 +struct ifconf {
454 + int ifc_len; /* size of buffer */
455 + union {
456 + char *ifcu_buf;
457 + struct ifreq *ifcu_req;
458 + } ifc_ifcu;
459 +};
460 +#endif /* __UAPI_DEF_IF_IFCONF */
461 +
462 +#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
463 +#define ifc_req ifc_ifcu.ifcu_req /* array of structures */
464 +
465 +#endif /* _LINUX_IF_H */