iproute2: Add basic AX.25, NETROM and ROSE support.
Subsystems (4)
v2 cover iproute2: Add basic AX.25, NETROM and ROSE support.
net-tools contain support for these three protocol but are deprecated and no longer installed by default by many distributions. Iproute2 otoh has no support at all and will dump the addresses of these protocols which actually are pretty human readable as hex numbers:
# ip link show dev bpq0
3: bpq0: <UP,LOWER_UP> mtu 256 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/ax25 88:98:60:a0:92:40:02 brd a2:a6:a8:40:40:40:00
# ip link show dev nr0
4: nr0: <NOARP,UP,LOWER_UP> mtu 236 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/netrom 88:98:60:a0:92:40:0a brd 00:00:00:00:00:00:00
# ip link show dev rose0
8: rose0: <NOARP,UP,LOWER_UP> mtu 249 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/rose 65:09:33:30:00 brd 00:00:00:00:00This series adds basic support for the three protocols to print addresses:
# ip link show dev bpq0
3: bpq0: <UP,LOWER_UP> mtu 256 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/ax25 DL0PI-1 brd QST-0
# ip link show dev nr0
4: nr0: <NOARP,UP,LOWER_UP> mtu 236 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/netrom DL0PI-5 brd *
# ip link show dev rose0
8: rose0: <NOARP,UP,LOWER_UP> mtu 249 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/rose 6509333000 brd 0000000000Ralf Baechle (6):
AX.25: Add ax25_ntop implementation.
AX.25: Print decoded addresses rather than hex numbers.
NETROM: Add netrom_ntop implementation.
NETROM: Print decoded addresses rather than hex numbers.
ROSE: Add rose_ntop implementation.
ROSE: Print decoded addresses rather than hex numbers.
Changes in v2:
- reset commit dates. The commit dates were still pointing back to the ages of King Tutankhamun though the code is more recent and has been tested based on latest iproute2.
Makefile | 9 ++++++ include/utils.h | 6 ++++ lib/ax25_ntop.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++ lib/ll_addr.c | 6 ++++ lib/netrom_ntop.c | 23 +++++++++++++ lib/rose_ntop.c | 56 ++++++++++++++++++++++++++++++++ 6 files changed, 182 insertions(+) create mode 100644 lib/ax25_ntop.c create mode 100644 lib/netrom_ntop.c create mode 100644 lib/rose_ntop.c
Signature · 24 lines
2.31.1 Ralf Baechle (6): AX.25: Add ax25_ntop implementation. AX.25: Print decoded addresses rather than hex numbers. NETROM: Add netrom_ntop implementation. NETROM: Print decoded addresses rather than hex numbers. ROSE: Add rose_ntop implementation. ROSE: Print decoded addresses rather than hex numbers. Makefile | 9 ++++++ include/utils.h | 6 ++++ lib/ax25_ntop.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++ lib/ll_addr.c | 6 ++++ lib/netrom_ntop.c | 23 +++++++++++++ lib/rose_ntop.c | 56 ++++++++++++++++++++++++++++++++ 6 files changed, 182 insertions(+) create mode 100644 lib/ax25_ntop.c create mode 100644 lib/netrom_ntop.c create mode 100644 lib/rose_ntop.c -- 2.31.1
PATCH v2 1/6 AX.25: Add ax25_ntop implementation.
AX.25 addresses are based on Amateur radio callsigns followed by an SSID like XXXXXX-SS where the callsign is up to 6 characters which are either letters or digits and the SSID is a decimal number in the range 0..15. Amateur radio callsigns are assigned by a country's relevant authorities and are 3..6 characters though a few countries have assigned callsigns longer than that. AX.25 is not able to handle such longer callsigns.
Being based on HDLC AX.25 encodes addresses by shifting them one bit left thus zeroing bit 0, the HDLC extension bit for all but the last bit of a packet's address field but for our purposes here we're not considering the HDLC extension bit that is it will always be zero.
Linux' internal representation of AX.25 addresses in Linux is very similar to this on the on-air or on-the-wire format. The callsign is padded to 6 octets by adding spaces, followed by the SSID octet then all 7 octets are left-shifted by one byte.
This for example turns "LINUX-1" where the callsign is LINUX and SSID is 1 into 98:92:9c:aa:b0:40:02.
--- Makefile | 3 ++ include/utils.h | 2 ++ lib/ax25_ntop.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 lib/ax25_ntop.c
Makefile +3 -0
@@ -40,6 +40,9 @@ DEFINES+=-DCONFDIR=\"$(CONFDIR)\" \ -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \ -DNETNS_ETC_DIR=\"$(NETNS_ETC_DIR)\" +#options for AX.25 +ADDLIB+=ax25_ntop.o + #options for mpls ADDLIB+=mpls_ntop.o mpls_pton.o
include/utils.h +2 -0
@@ -198,6 +198,8 @@ bool matches(const char *prefix, const char *string);int inet_addr_match (const inet_prefix *a,const inet_prefix *b,int bits);int inet_addr_match_rta (const inet_prefix *m,const struct rtattr *rta); +const char *ax25_ntop (int af,const void *addr,char *str,socklen_t len); +const char *mpls_ntop (int af,const void *addr,char *str,size_t len);int mpls_pton (int af,const char *src,void *addr,size_t alen);
lib/ax25_ntop.c new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v2 2/6 AX.25: Print decoded addresses rather than hex numbers.
In reply to Ralf BaechleBefore this, ip would have printed the AX.25 address configured for an AX.25 interface's default addresses as:
link/ax25 98:92:9c:aa:b0:40:02 brd a2:a6:a8:40:40:40:00
which is pretty unreadable. With this commit ip will decode AX.25 addresses like
link/ax25 LINUX-1 brd QST-0
--- lib/ll_addr.c | 2 ++ 1 file changed, 2 insertions(+)
lib/ll_addr.c +2 -0
@@ -39,6 +39,8 @@ const char *ll_addr_n2a(const unsigned char *addr, int alen, int type,if (alen ==16 && (type ==ARPHRD_TUNNEL6 || type ==ARPHRD_IP6GRE ))return inet_ntop (AF_INET6 , addr, buf, blen); +if (alen ==7 && type ==ARPHRD_AX25 ) +return ax25_ntop (AF_AX25 , addr, buf, blen);snprintf (buf, blen,"%02x" , addr[0 ]);for (i =1 , l =2 ; i < alen && l < blen; i++, l +=3 )
Signature · 1 line
2.31.1
PATCH v2 3/6 NETROM: Add netrom_ntop implementation.
In reply to Ralf BaechleNETROM uses AX.25 addresses so this is a simple wrapper around ax25_ntop1.
--- Makefile | 3 +++ include/utils.h | 2 ++ lib/ax25_ntop.c | 22 +++++++++++++++------- lib/netrom_ntop.c | 23 +++++++++++++++++++++++ 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 lib/netrom_ntop.c
Makefile +3 -0
@@ -46,6 +46,9 @@ ADDLIB+=ax25_ntop.o #options for mpls ADDLIB+=mpls_ntop.o mpls_pton.o +#options for NETROM +ADDLIB+=netrom_ntop.o + CC := gcc HOSTCC ?= $(CC) DEFINES += -D_GNU_SOURCE
include/utils.h +2 -0
@@ -203,6 +203,8 @@ const char *ax25_ntop(int af, const void *addr, char *str, socklen_t len);const char *mpls_ntop (int af,const void *addr,char *str,size_t len);int mpls_pton (int af,const char *src,void *addr,size_t alen); +const char *netrom_ntop (int af,const void *addr,char *str,socklen_t len); +extern int __iproute2_hz_internal;int __get_hz (void );
lib/ax25_ntop.c +15 -7
@@ -6,13 +6,22 @@#include "utils.h" +const char *ax25_ntop1 (const ax25_address *src,char *dst,socklen_t size); +/* * AX.25 addresses are based on Amateur radio callsigns followed by an SSID -* like XXXXXX-SS where the callsign is up to 6 characters which are either -* letters or digits and the SSID is a decimal number in the range 0..15. +* like XXXXXX-SS where the callsign consists of up to 6 ASCII characters +* which are either letters or digits and the SSID is a decimal number in the +* range 0..15. * Amateur radio callsigns are assigned by a country's relevant authorities * and are 3..6 characters though a few countries have assigned callsigns * longer than that. AX.25 is not able to handle such longer callsigns. +* There are further restrictions on the format of valid callsigns by +* applicable national and international law. Linux doesn't need to care and +* will happily accept anything that consists of 6 ASCII characters in the +* range of A-Z and 0-9 for a callsign such as the default AX.25 MAC address +* LINUX-1 and the default broadcast address QST-0. +* The SSID is just a number and not encoded in ASCII digits. * * Being based on HDLC AX.25 encodes addresses by shifting them one bit left * thus zeroing bit 0, the HDLC extension bit for all but the last bit of
@@ -22,14 +31,13 @@* Linux' internal representation of AX.25 addresses in Linux is very similar * to this on the on-air or on-the-wire format. The callsign is padded to * 6 octets by adding spaces, followed by the SSID octet then all 7 octets -* are left-shifted by one byte. +* are left-shifted by one bit. * -* This for example turns "LINUX-1" where the callsign is LINUX and SSID is 1 -* into 98:92:9c:aa:b0:40:02. +* For example, for the address "LINUX-1" the callsign is LINUX and SSID is 1 +* the internal format is 98:92:9c:aa:b0:40:02. */ -static const char *ax25_ntop1 (const ax25_address *src,char *dst, -socklen_t size) +const char *ax25_ntop1 (const ax25_address *src,char *dst,socklen_t size) {char c, *s;int n;
lib/netrom_ntop.c new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <sys/socket.h> +#include <errno.h> +#include <linux/ax25.h> + +#include "utils.h" + +const char *ax25_ntop1 (const ax25_address *src,char *dst,socklen_t size); + +const char *netrom_ntop (int af,const void *addr,char *buf,socklen_t buflen) +{ +switch (af) { +case AF_NETROM : + errno =0 ; +return ax25_ntop1 ((ax25_address *)addr, buf, buflen); + +default : + errno =EAFNOSUPPORT ; + } + +return NULL ; +}
Signature · 1 line
2.31.1
PATCH v2 4/6 NETROM: Print decoded addresses rather than hex numbers.
In reply to Ralf BaechleNETROM is an OSI layer 3 protocol sitting on top of AX.25. It also uses AX.25 addresses. Without this commit ip will print NETROM address like
link/generic 98:92:9c:aa:b0:40:02 brd 00:00:00:00:00:00:00
while with this commit the decoded result
link/generic LINUX-1 brd *
is much more eye friendly.
--- lib/ll_addr.c | 2 ++ 1 file changed, 2 insertions(+)
lib/ll_addr.c +2 -0
@@ -41,6 +41,8 @@ const char *ll_addr_n2a(const unsigned char *addr, int alen, int type,return inet_ntop (AF_INET6 , addr, buf, blen);if (alen ==7 && type ==ARPHRD_AX25 )return ax25_ntop (AF_AX25 , addr, buf, blen); +if (alen ==7 && type ==ARPHRD_NETROM ) +return netrom_ntop (AF_NETROM , addr, buf, blen);snprintf (buf, blen,"%02x" , addr[0 ]);for (i =1 , l =2 ; i < alen && l < blen; i++, l +=3 )
Signature · 1 line
2.31.1
PATCH v2 5/6 ROSE: Add rose_ntop implementation.
In reply to Ralf BaechleROSE addresses are ten digit numbers, basically like North American telephone numbers.
--- Makefile | 3 +++ include/utils.h | 2 ++ lib/rose_ntop.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 lib/rose_ntop.c
Makefile +3 -0
@@ -43,6 +43,9 @@ DEFINES+=-DCONFDIR=\"$(CONFDIR)\" \ #options for AX.25 ADDLIB+=ax25_ntop.o +#options for AX.25 +ADDLIB+=rose_ntop.o + #options for mpls ADDLIB+=mpls_ntop.o mpls_pton.o
include/utils.h +2 -0
@@ -200,6 +200,8 @@ int inet_addr_match_rta(const inet_prefix *m, const struct rtattr *rta);const char *ax25_ntop (int af,const void *addr,char *str,socklen_t len); +const char *rose_ntop (int af,const void *addr,char *buf,socklen_t buflen); +const char *mpls_ntop (int af,const void *addr,char *str,size_t len);int mpls_pton (int af,const char *src,void *addr,size_t alen);
lib/rose_ntop.c new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v2 6/6 ROSE: Print decoded addresses rather than hex numbers.
In reply to Ralf BaechleNETROM is a OSI layer 3 protocol sitting on top of AX.25. It uses BCD- encoded 10 digit telephone numbers as addresses. Without this ip will print a ROSE addresses like
link/rose 12:34:56:78:90 brd 00:00:00:00:00
which is readable but ugly. With this applied it ROSE addresses will be printed as
link/rose 1234567890 brd 0000000000
--- lib/ll_addr.c | 2 ++ 1 file changed, 2 insertions(+)
lib/ll_addr.c +2 -0
@@ -43,6 +43,8 @@ const char *ll_addr_n2a(const unsigned char *addr, int alen, int type,return ax25_ntop (AF_AX25 , addr, buf, blen);if (alen ==7 && type ==ARPHRD_NETROM )return netrom_ntop (AF_NETROM , addr, buf, blen); +if (alen ==5 && type ==ARPHRD_ROSE ) +return rose_ntop (AF_ROSE , addr, buf, blen);snprintf (buf, blen,"%02x" , addr[0 ]);for (i =1 , l =2 ; i < alen && l < blen; i++, l +=3 )
Signature · 1 line
2.31.1
David Ahern
AppliedQuoted 17 lines · Ralf Baechle
net-tools contain support for these three protocol but are deprecated and no longer installed by default by many distributions. Iproute2 otoh has no support at all and will dump the addresses of these protocols which actually are pretty human readable as hex numbers:
# ip link show dev bpq0 3: bpq0: <UP,LOWER_UP> mtu 256 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/ax25 88:98:60:a0:92:40:02 brd a2:a6:a8:40:40:40:00 # ip link show dev nr0 4: nr0: <NOARP,UP,LOWER_UP> mtu 236 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/netrom 88:98:60:a0:92:40:0a brd 00:00:00:00:00:00:00 # ip link show dev rose0 8: rose0: <NOARP,UP,LOWER_UP> mtu 249 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/rose 65:09:33:30:00 brd 00:00:00:00:00This series adds basic support for the three protocols to print addresses:
Quoted 7 lines
# ip link show dev bpq0
3: bpq0: <UP,LOWER_UP> mtu 256 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/ax25 DL0PI-1 brd QST-0
# ip link show dev nr0
4: nr0: <NOARP,UP,LOWER_UP> mtu 236 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/netrom DL0PI-5 brd *
# ip link show dev rose0# lines get removed by git; $ is a better prompt for commands
Quoted 3 lines
8: rose0: <NOARP,UP,LOWER_UP> mtu 249 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/rose 6509333000 brd 0000000000
applied to iproute2-next. Thanks,
Quoted 1 line · David Ahern
applied to iproute2-next. Thanks,
Awesome, thanks.
Are you the maintainer of iproute2 these days? Sorry for not cc'ing you - I thought Stephen Hemminger was the guy to mail patches to.
Ralf