From patchwork Thu Dec 9 15:18:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Eckert X-Patchwork-Id: 1565805 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=bMt5BQ32; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J8yRg5Wkmz9s5P for ; Fri, 10 Dec 2021 02:21:19 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=ToPl1E/T3b/hBxd0eszTxzQPrpLhLu4yTx3e2nEowdo=; b=bMt5BQ32KjFdpA p+hSoOxWuohF61gsxl9MFH/YEN+RsgMtCqtDb1GvCh3j735JOXW9qL8SwhQGQqnfm6HcaUnb6LVje i4Re5ptkqZEgGlOnY6EQnIMLTMMHfpOYZPjA1bmVPnXP2ozF0vrcqaVeolNO42auS0L084elhMHoM N4PA6F8jyPz1+EGFBamhe5J2c1QDkKoh2N4NHJN/MUMCOlukh7erzLXZ6WTSJjCrad04dQIMAmCfu tx61Ec6JlId8Ar0bPuuckHRmLTEyv07f+ojEl9LK97qYq9lN+0b6mTxXFoj0Co3C3NHysJuruX144 GIhf+xiWO4Z9xVE8gSzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvLBz-00GUg3-IB; Thu, 09 Dec 2021 15:18:43 +0000 Received: from mxout70.expurgate.net ([194.37.255.70]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvLBt-00GUdu-75 for openwrt-devel@lists.openwrt.org; Thu, 09 Dec 2021 15:18:41 +0000 Received: from [127.0.0.1] (helo=localhost) by relay.expurgate.net with smtp (Exim 4.92) (envelope-from ) id 1mvLBj-0002Rh-5b; Thu, 09 Dec 2021 16:18:27 +0100 Received: from [195.243.126.94] (helo=securemail.tdt.de) by relay.expurgate.net with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mvLBh-0006kF-NF; Thu, 09 Dec 2021 16:18:25 +0100 Received: from securemail.tdt.de (localhost [127.0.0.1]) by securemail.tdt.de (Postfix) with ESMTP id 27206240041; Thu, 9 Dec 2021 16:18:25 +0100 (CET) Received: from mail.dev.tdt.de (unknown [10.2.4.42]) by securemail.tdt.de (Postfix) with ESMTP id AF6A6240040; Thu, 9 Dec 2021 16:18:24 +0100 (CET) Received: from localhost.localdomain (unknown [10.2.3.40]) by mail.dev.tdt.de (Postfix) with ESMTPSA id 18B5D23B67; Thu, 9 Dec 2021 16:18:24 +0100 (CET) From: Florian Eckert To: jo@mein.io, dedeckeh@gmail.com, nbd@nbd.name, Eckert.Florian@googlemail.com Cc: openwrt-devel@lists.openwrt.org Subject: [PATCH v3] netifd: add devtype to ubus call Date: Thu, 9 Dec 2021 16:18:19 +0100 Message-ID: <20211209151819.5835-1-fe@dev.tdt.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.dev.tdt.de X-purgate-type: clean X-purgate: clean X-purgate-ID: 151534::1639063106-000037BC-B7973992/0/0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211209_071837_458464_9E05D424 X-CRM114-Status: GOOD ( 16.54 ) X-Spam-Score: -0.7 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Every network device has a type. There is no standard interface here. The type can be determined either from the file '/sys/class/net//uevent' or, if no information is found there, from the fi [...] Content analysis details: (-0.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [194.37.255.70 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Every network device has a type. There is no standard interface here. The type can be determined either from the file '/sys/class/net//uevent' or, if no information is found there, from the file '/sys/class/net//type'. This new function first checks whether there is a DEVTYPE= sring in the 'uevent' file and uses it. If it does not find this information, the 'type' is used as a fallback and mapped the number to a character sequence. This new 'devtype' information can be found in the network.device ubus call. Command: ubus call network.device status Output: { "eth0": { "devtype": "ethernet", Signed-off-by: Florian Eckert --- v2: - Remove debug log output v3: - Use the information mainly from file 'uevnet'. - If 'uevent' does not provide the information use file 'type' ...-system-linux-add-interface-protocol.patch | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 package/network/config/netifd/patches/001-system-linux-add-interface-protocol.patch diff --git a/package/network/config/netifd/patches/001-system-linux-add-interface-protocol.patch b/package/network/config/netifd/patches/001-system-linux-add-interface-protocol.patch new file mode 100644 index 0000000000..62662b3df3 --- /dev/null +++ b/package/network/config/netifd/patches/001-system-linux-add-interface-protocol.patch @@ -0,0 +1,107 @@ +--- a/system-linux.c ++++ b/system-linux.c +@@ -2395,6 +2395,50 @@ system_if_force_external(const char *ifn + return stat(dev_sysfs_path(ifname, "phy80211"), &s) == 0; + } + ++static inline unsigned short ++system_netdevtype_to_pos(unsigned short dev_type) ++{ ++ int i; ++ ++ for (i = 0; i < ARRAY_SIZE(netdev_type_number); i++) ++ if (netdev_type_number[i] == dev_type) ++ return i; ++ /* the last key is used by default */ ++ return ARRAY_SIZE(netdev_type_number) - 1; ++} ++ ++static void ++system_add_devtype(struct blob_buf *b, const char *ifname) ++{ ++ char buf[100]; ++ bool found = false; ++ ++ if (!system_get_dev_sysfs("uevent", ifname, buf, sizeof(buf))) { ++ const char *info = "DEVTYPE="; ++ char* context = NULL; ++ const char *line = strtok_r(buf, "\r\n", &context); ++ while( line != NULL ) { ++ char *index = strstr(line, info); ++ if(index != NULL) { ++ blobmsg_add_string(b, "devtype", index + strlen(info)); ++ found = true; ++ break; ++ } ++ line = strtok_r(NULL, "\r\n", &context); ++ } ++ } ++ ++ if (!found) { ++ int i; ++ unsigned short number = 0; ++ if (!system_get_dev_sysfs("type", ifname, buf, sizeof(buf))) { ++ number = strtoul(buf, NULL, 0); ++ i = system_netdevtype_to_pos(number); ++ blobmsg_add_string(b, "devtype", netdev_type_name[i]); ++ } ++ } ++} ++ + int + system_if_dump_info(struct device *dev, struct blob_buf *b) + { +@@ -2430,6 +2474,8 @@ system_if_dump_info(struct device *dev, + blobmsg_add_u8(b, "autoneg", !!ecmd.autoneg); + } + ++ system_add_devtype(b, dev->ifname); ++ + return 0; + } + +--- a/system.h ++++ b/system.h +@@ -23,6 +23,42 @@ + #include "iprule.h" + #include "utils.h" + ++static const unsigned short netdev_type_number[] = { ++ ARPHRD_NETROM, ARPHRD_ETHER, ARPHRD_EETHER, ARPHRD_AX25, ++ ARPHRD_PRONET, ARPHRD_CHAOS, ARPHRD_IEEE802, ARPHRD_ARCNET, ++ ARPHRD_APPLETLK, ARPHRD_DLCI, ARPHRD_ATM, ARPHRD_METRICOM, ++ ARPHRD_IEEE1394, ARPHRD_EUI64, ARPHRD_INFINIBAND, ARPHRD_SLIP, ++ ARPHRD_CSLIP, ARPHRD_SLIP6, ARPHRD_CSLIP6, ARPHRD_RSRVD, ++ ARPHRD_ADAPT, ARPHRD_ROSE, ARPHRD_X25, ARPHRD_HWX25, ++ ARPHRD_PPP, ARPHRD_CISCO, ARPHRD_LAPB, ARPHRD_DDCMP, ++ ARPHRD_RAWHDLC, ARPHRD_TUNNEL, ARPHRD_TUNNEL6, ARPHRD_FRAD, ++ ARPHRD_SKIP, ARPHRD_LOOPBACK, ARPHRD_LOCALTLK, ARPHRD_FDDI, ++ ARPHRD_BIF, ARPHRD_SIT, ARPHRD_IPDDP, ARPHRD_IPGRE, ++ ARPHRD_PIMREG, ARPHRD_HIPPI, ARPHRD_ASH, ARPHRD_ECONET, ++ ARPHRD_IRDA, ARPHRD_FCPP, ARPHRD_FCAL, ARPHRD_FCPL, ++ ARPHRD_FCFABRIC, ARPHRD_IEEE80211, ARPHRD_IEEE80211_PRISM, ++ ARPHRD_IEEE80211_RADIOTAP, ARPHRD_PHONET, ARPHRD_PHONET_PIPE, ++ ARPHRD_IEEE802154, ARPHRD_VOID, ARPHRD_NONE ++}; ++ ++static const char *const netdev_type_name[] = { ++ "netrom", "ethernet", "eethernet", "ax25", ++ "pronet", "chaos", "ieee802", "arcnet", ++ "appletlk", "dlci", "atm", "metricom", ++ "ieee1394", "eui64", "infiniband", "slip", ++ "cslip", "slip6", "cslip6", "rsrvd", ++ "adapt", "rose", "x25", "hwx25", ++ "ppp", "cisco", "lapb", "ddcmp", ++ "rawhdlc", "tunnel", "tunnel6", "frad", ++ "skip", "loopback", "localtlk", "fddi", ++ "bif", "sit", "ipddp", "ipgre", ++ "pimreg", "hippi", "ash", "econet", ++ "irda", "fcpp", "fcal", "fcpl", ++ "fcfabric", "ieee80211", "ie80211-prism", ++ "ieee80211-radiotap", "phonet", "phonet-pipe", ++ "ieee802154", "void", "none" ++}; ++ + enum tunnel_param { + TUNNEL_ATTR_TYPE, + TUNNEL_ATTR_REMOTE,