From patchwork Sun Sep 19 13:30:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Baechle X-Patchwork-Id: 12505547 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.4 required=3.0 tests=BAYES_00,DATE_IN_PAST_24_48, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8DB9C433EF for ; Mon, 20 Sep 2021 14:36:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D145560F5D for ; Mon, 20 Sep 2021 14:36:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240461AbhITOhp (ORCPT ); Mon, 20 Sep 2021 10:37:45 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:56277 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbhITOhm (ORCPT ); Mon, 20 Sep 2021 10:37:42 -0400 Received: from h7.dl5rb.org.uk (p5790756f.dip0.t-ipconnect.de [87.144.117.111]) (Authenticated sender: ralf@linux-mips.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id DCDCE200005; Mon, 20 Sep 2021 14:36:13 +0000 (UTC) Received: from h7.dl5rb.org.uk (localhost [127.0.0.1]) by h7.dl5rb.org.uk (8.16.1/8.16.1) with ESMTPS id 18KEaC1A1202527 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 20 Sep 2021 16:36:12 +0200 Received: (from ralf@localhost) by h7.dl5rb.org.uk (8.16.1/8.16.1/Submit) id 18KEaCoi1202526; Mon, 20 Sep 2021 16:36:12 +0200 Message-Id: <354e26b327e861129b66e414faa7cc9f34524109.1632059758.git.ralf@linux-mips.org> In-Reply-To: References: From: Ralf Baechle Date: Sun, 19 Sep 2021 15:30:26 +0200 Subject: [PATCH v2 1/6] AX.25: Add ax25_ntop implementation. To: Stephen Hemminger Cc: netdev@vger.kernel.org, linux-hams@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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. Signed-off-by: Ralf Baechle --- Makefile | 3 ++ include/utils.h | 2 ++ lib/ax25_ntop.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 lib/ax25_ntop.c diff --git a/Makefile b/Makefile index 5bc11477..551f528b 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/include/utils.h b/include/utils.h index c9849461..947ab5c3 100644 --- a/include/utils.h +++ b/include/utils.h @@ -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); diff --git a/lib/ax25_ntop.c b/lib/ax25_ntop.c new file mode 100644 index 00000000..48098581 --- /dev/null +++ b/lib/ax25_ntop.c @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#include +#include +#include + +#include "utils.h" + +/* + * 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. + */ + +static const char *ax25_ntop1(const ax25_address *src, char *dst, + socklen_t size) +{ + char c, *s; + int n; + + for (n = 0, s = dst; n < 6; n++) { + c = (src->ax25_call[n] >> 1) & 0x7f; + if (c != ' ') + *s++ = c; + } + + *s++ = '-'; + + n = ((src->ax25_call[6] >> 1) & 0x0f); + if (n > 9) { + *s++ = '1'; + n -= 10; + } + + *s++ = n + '0'; + *s++ = '\0'; + + if (*dst == '\0' || *dst == '-') { + dst[0] = '*'; + dst[1] = '\0'; + } + + return dst; +} + +const char *ax25_ntop(int af, const void *addr, char *buf, socklen_t buflen) +{ + switch (af) { + case AF_AX25: + errno = 0; + return ax25_ntop1((ax25_address *)addr, buf, buflen); + + default: + errno = EAFNOSUPPORT; + } + + return NULL; +} From patchwork Sun Sep 19 13:30:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Baechle X-Patchwork-Id: 12505549 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.4 required=3.0 tests=BAYES_00,DATE_IN_PAST_24_48, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAD40C433F5 for ; Mon, 20 Sep 2021 14:36:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD9E4610CE for ; Mon, 20 Sep 2021 14:36:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240497AbhITOhr (ORCPT ); Mon, 20 Sep 2021 10:37:47 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:46035 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231952AbhITOhm (ORCPT ); Mon, 20 Sep 2021 10:37:42 -0400 Received: from h7.dl5rb.org.uk (p5790756f.dip0.t-ipconnect.de [87.144.117.111]) (Authenticated sender: ralf@linux-mips.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 23D48240013; Mon, 20 Sep 2021 14:36:13 +0000 (UTC) Received: from h7.dl5rb.org.uk (localhost [127.0.0.1]) by h7.dl5rb.org.uk (8.16.1/8.16.1) with ESMTPS id 18KEaCgK1202531 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 20 Sep 2021 16:36:12 +0200 Received: (from ralf@localhost) by h7.dl5rb.org.uk (8.16.1/8.16.1/Submit) id 18KEaCuJ1202530; Mon, 20 Sep 2021 16:36:12 +0200 Message-Id: In-Reply-To: References: From: Ralf Baechle Date: Sun, 19 Sep 2021 15:30:26 +0200 Subject: [PATCH v2 2/6] AX.25: Print decoded addresses rather than hex numbers. To: Stephen Hemminger Cc: netdev@vger.kernel.org, linux-hams@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Before 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 Signed-off-by: Ralf Baechle --- lib/ll_addr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ll_addr.c b/lib/ll_addr.c index 00b562ae..910e6daf 100644 --- a/lib/ll_addr.c +++ b/lib/ll_addr.c @@ -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) From patchwork Sun Sep 19 13:30:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Baechle X-Patchwork-Id: 12505553 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.4 required=3.0 tests=BAYES_00,DATE_IN_PAST_24_48, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13DB8C433FE for ; Mon, 20 Sep 2021 14:36:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED5C160F5D for ; Mon, 20 Sep 2021 14:36:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240569AbhITOhz (ORCPT ); Mon, 20 Sep 2021 10:37:55 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:58347 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233406AbhITOhm (ORCPT ); Mon, 20 Sep 2021 10:37:42 -0400 Received: from h7.dl5rb.org.uk (p5790756f.dip0.t-ipconnect.de [87.144.117.111]) (Authenticated sender: ralf@linux-mips.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 5F9141BF213; Mon, 20 Sep 2021 14:36:13 +0000 (UTC) Received: from h7.dl5rb.org.uk (localhost [127.0.0.1]) by h7.dl5rb.org.uk (8.16.1/8.16.1) with ESMTPS id 18KEaCcA1202535 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 20 Sep 2021 16:36:12 +0200 Received: (from ralf@localhost) by h7.dl5rb.org.uk (8.16.1/8.16.1/Submit) id 18KEaCLY1202534; Mon, 20 Sep 2021 16:36:12 +0200 Message-Id: <1eb184007b7b07ad0d4c42cbd58be265eb3c67b7.1632059758.git.ralf@linux-mips.org> In-Reply-To: References: From: Ralf Baechle Date: Sun, 19 Sep 2021 15:30:26 +0200 Subject: [PATCH v2 3/6] NETROM: Add netrom_ntop implementation. To: Stephen Hemminger Cc: netdev@vger.kernel.org, linux-hams@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org NETROM uses AX.25 addresses so this is a simple wrapper around ax25_ntop1. Signed-off-by: Ralf Baechle --- 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 diff --git a/Makefile b/Makefile index 551f528b..df894d54 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/include/utils.h b/include/utils.h index 947ab5c3..6ab2fa74 100644 --- a/include/utils.h +++ b/include/utils.h @@ -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); diff --git a/lib/ax25_ntop.c b/lib/ax25_ntop.c index 48098581..cfd0e04b 100644 --- a/lib/ax25_ntop.c +++ b/lib/ax25_ntop.c @@ -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; diff --git a/lib/netrom_ntop.c b/lib/netrom_ntop.c new file mode 100644 index 00000000..3dd6cb0b --- /dev/null +++ b/lib/netrom_ntop.c @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include +#include + +#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; +} From patchwork Sun Sep 19 13:30:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Baechle X-Patchwork-Id: 12505577 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.4 required=3.0 tests=BAYES_00,DATE_IN_PAST_24_48, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 331C4C433F5 for ; Mon, 20 Sep 2021 14:44:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1580860F46 for ; Mon, 20 Sep 2021 14:44:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240529AbhITOpw (ORCPT ); Mon, 20 Sep 2021 10:45:52 -0400 Received: from mslow1.mail.gandi.net ([217.70.178.240]:40559 "EHLO mslow1.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236888AbhITOpv (ORCPT ); Mon, 20 Sep 2021 10:45:51 -0400 Received: from relay9-d.mail.gandi.net (unknown [217.70.183.199]) by mslow1.mail.gandi.net (Postfix) with ESMTP id B3B0FCDE71; Mon, 20 Sep 2021 14:36:37 +0000 (UTC) Received: from h7.dl5rb.org.uk (p5790756f.dip0.t-ipconnect.de [87.144.117.111]) (Authenticated sender: ralf@linux-mips.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 13583FF804; Mon, 20 Sep 2021 14:36:14 +0000 (UTC) Received: from h7.dl5rb.org.uk (localhost [127.0.0.1]) by h7.dl5rb.org.uk (8.16.1/8.16.1) with ESMTPS id 18KEaDh61202539 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 20 Sep 2021 16:36:13 +0200 Received: (from ralf@localhost) by h7.dl5rb.org.uk (8.16.1/8.16.1/Submit) id 18KEaDQ51202538; Mon, 20 Sep 2021 16:36:13 +0200 Message-Id: <140fac95627e5a66f9482b6ce550173cef61bab3.1632059758.git.ralf@linux-mips.org> In-Reply-To: References: From: Ralf Baechle Date: Sun, 19 Sep 2021 15:30:26 +0200 Subject: [PATCH v2 4/6] NETROM: Print decoded addresses rather than hex numbers. To: Stephen Hemminger Cc: netdev@vger.kernel.org, linux-hams@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org NETROM 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. Signed-off-by: Ralf Baechle --- lib/ll_addr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ll_addr.c b/lib/ll_addr.c index 910e6daf..46e30c79 100644 --- a/lib/ll_addr.c +++ b/lib/ll_addr.c @@ -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) From patchwork Sun Sep 19 13:30:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Baechle X-Patchwork-Id: 12505551 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.4 required=3.0 tests=BAYES_00,DATE_IN_PAST_24_48, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04769C433F5 for ; Mon, 20 Sep 2021 14:36:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4BF260F5D for ; Mon, 20 Sep 2021 14:36:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240521AbhITOhx (ORCPT ); Mon, 20 Sep 2021 10:37:53 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:33213 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237264AbhITOhm (ORCPT ); Mon, 20 Sep 2021 10:37:42 -0400 Received: from h7.dl5rb.org.uk (p5790756f.dip0.t-ipconnect.de [87.144.117.111]) (Authenticated sender: ralf@linux-mips.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 8941B1BF214; Mon, 20 Sep 2021 14:36:14 +0000 (UTC) Received: from h7.dl5rb.org.uk (localhost [127.0.0.1]) by h7.dl5rb.org.uk (8.16.1/8.16.1) with ESMTPS id 18KEaDxf1202543 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 20 Sep 2021 16:36:13 +0200 Received: (from ralf@localhost) by h7.dl5rb.org.uk (8.16.1/8.16.1/Submit) id 18KEaDRg1202542; Mon, 20 Sep 2021 16:36:13 +0200 Message-Id: In-Reply-To: References: From: Ralf Baechle Date: Sun, 19 Sep 2021 15:30:26 +0200 Subject: [PATCH v2 5/6] ROSE: Add rose_ntop implementation. To: Stephen Hemminger Cc: netdev@vger.kernel.org, linux-hams@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org ROSE addresses are ten digit numbers, basically like North American telephone numbers. Signed-off-by: Ralf Baechle --- Makefile | 3 +++ include/utils.h | 2 ++ lib/rose_ntop.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 lib/rose_ntop.c diff --git a/Makefile b/Makefile index df894d54..5eddd504 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/include/utils.h b/include/utils.h index 6ab2fa74..b6c468e9 100644 --- a/include/utils.h +++ b/include/utils.h @@ -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); diff --git a/lib/rose_ntop.c b/lib/rose_ntop.c new file mode 100644 index 00000000..c9ba712c --- /dev/null +++ b/lib/rose_ntop.c @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "rt_names.h" +#include "utils.h" + +static const char *rose_ntop1(const rose_address *src, char *dst, + socklen_t size) +{ + char *p = dst; + int i; + + if (size < 10) + return NULL; + + for (i = 0; i < 5; i++) { + *p++ = '0' + ((src->rose_addr[i] >> 4) & 0xf); + *p++ = '0' + ((src->rose_addr[i] ) & 0xf); + } + + if (size == 10) + return dst; + + *p = '\0'; + + return dst; +} + +const char *rose_ntop(int af, const void *addr, char *buf, socklen_t buflen) +{ + switch (af) { + case AF_ROSE: + errno = 0; + return rose_ntop1((rose_address *)addr, buf, buflen); + + default: + errno = EAFNOSUPPORT; + } + + return NULL; +} From patchwork Sun Sep 19 13:30:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Baechle X-Patchwork-Id: 12505555 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.4 required=3.0 tests=BAYES_00,DATE_IN_PAST_24_48, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24B44C433F5 for ; Mon, 20 Sep 2021 14:36:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0344C610CE for ; Mon, 20 Sep 2021 14:36:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240533AbhITOh4 (ORCPT ); Mon, 20 Sep 2021 10:37:56 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:56953 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237382AbhITOhm (ORCPT ); Mon, 20 Sep 2021 10:37:42 -0400 Received: from h7.dl5rb.org.uk (p5790756f.dip0.t-ipconnect.de [87.144.117.111]) (Authenticated sender: ralf@linux-mips.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id BCA6624000B; Mon, 20 Sep 2021 14:36:14 +0000 (UTC) Received: from h7.dl5rb.org.uk (localhost [127.0.0.1]) by h7.dl5rb.org.uk (8.16.1/8.16.1) with ESMTPS id 18KEaDJc1202547 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 20 Sep 2021 16:36:13 +0200 Received: (from ralf@localhost) by h7.dl5rb.org.uk (8.16.1/8.16.1/Submit) id 18KEaDQh1202546; Mon, 20 Sep 2021 16:36:13 +0200 Message-Id: <66f18d42c5b54b47110d323b62b2bca09f960282.1632059758.git.ralf@linux-mips.org> In-Reply-To: References: From: Ralf Baechle Date: Sun, 19 Sep 2021 15:30:26 +0200 Subject: [PATCH v2 6/6] ROSE: Print decoded addresses rather than hex numbers. To: Stephen Hemminger Cc: netdev@vger.kernel.org, linux-hams@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org NETROM 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 Signed-off-by: Ralf Baechle --- lib/ll_addr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ll_addr.c b/lib/ll_addr.c index 46e30c79..d6fd736b 100644 --- a/lib/ll_addr.c +++ b/lib/ll_addr.c @@ -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)