From patchwork Mon Dec 6 10:15:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Eckert X-Patchwork-Id: 1563868 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=C1TusSwn; 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 4J6zzX4xQlz9s1l for ; Mon, 6 Dec 2021 21:23:36 +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=hZye2sOa/LNlYsJoX5fTus//rWySH1NmT7Yk5Z2kRsw=; b=C1TusSwnQfh3Ad Q2tJdtCITb0MlnkrftVeApu49iysxKJriKOyB58+V3a/47zldxSFsend6UDon9BUp0VEjvAVfHTOA MbNytw87au1PNEEl5mwGRQKx626SBMKgW8BLs5fnzQW+Crui+IgjAPwoxxHqVmXBa3Cwqmt5EzCXI YEMfsgKkw3DP/G5ImNPVE75ZMpBwSq9hDXiKZmP+PAzPwl75rgCUnCRkUBcliDHvflQGuoyeAddcb THG4Bq51QpDHIBjANsc3SSyf88wsdnb9cHRKbEppFU+6fx13j/O8IcdhskyIEZ4OF9JhX89RU61zG yb38hUL6l89zBbV86dpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muB2X-003J1k-FC; Mon, 06 Dec 2021 10:16:09 +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 1muB2T-003J10-KE for openwrt-devel@lists.openwrt.org; Mon, 06 Dec 2021 10:16:07 +0000 Received: from [127.0.0.1] (helo=localhost) by relay.expurgate.net with smtp (Exim 4.92) (envelope-from ) id 1muB2P-0007UK-09; Mon, 06 Dec 2021 11:16:01 +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 1muB2O-0004IX-2v; Mon, 06 Dec 2021 11:16:00 +0100 Received: from securemail.tdt.de (localhost [127.0.0.1]) by securemail.tdt.de (Postfix) with ESMTP id 3D99D240043; Mon, 6 Dec 2021 11:15:59 +0100 (CET) Received: from mail.dev.tdt.de (unknown [10.2.4.42]) by securemail.tdt.de (Postfix) with ESMTP id C83F9240041; Mon, 6 Dec 2021 11:15:58 +0100 (CET) Received: from localhost.localdomain (unknown [10.2.3.40]) by mail.dev.tdt.de (Postfix) with ESMTPSA id 3DF522100D; Mon, 6 Dec 2021 11:15:58 +0100 (CET) From: Florian Eckert To: dedeckeh@gmail.com, nbd@nbd.name, Eckert.Florian@googlemail.com Cc: openwrt-devel@lists.openwrt.org Subject: [PATCH] netifd: system-linux: add dev_type info for ubus network.device status Date: Mon, 6 Dec 2021 11:15:46 +0100 Message-ID: <20211206101546.830-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-ID: 151534::1638785760-000037BC-1B00F590/0/0 X-purgate-type: clean X-purgate: clean X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211206_021605_867479_439E5A6E X-CRM114-Status: GOOD ( 13.83 ) 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. This is stored in the sysfs under '/sys/class/net//type' as a number and can be queried. This commit adds this information as a string to the ubus. 'ubus call network.device status' { ... "eth0": { "dev_type": "ETHER", ... } 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. This is stored in the sysfs under '/sys/class/net//type' as a number and can be queried. This commit adds this information as a string to the ubus. 'ubus call network.device status' { ... "eth0": { "dev_type": "ETHER", ... } Signed-off-by: Florian Eckert --- system-linux.c | 21 +++++++++++++++++++++ system.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/system-linux.c b/system-linux.c index e768853..4ac34cc 100644 --- a/system-linux.c +++ b/system-linux.c @@ -2395,6 +2395,17 @@ system_if_force_external(const char *ifname) return stat(dev_sysfs_path(ifname, "phy80211"), &s) == 0; } +static inline unsigned short netdev_type_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; +} + int system_if_dump_info(struct device *dev, struct blob_buf *b) { @@ -2402,6 +2413,9 @@ system_if_dump_info(struct device *dev, struct blob_buf *b) struct ifreq ifr; char *s; void *c; + unsigned short dev_type = 0; + int i; + char buf[10]; memset(&ecmd, 0, sizeof(ecmd)); memset(&ifr, 0, sizeof(ifr)); @@ -2430,6 +2444,13 @@ system_if_dump_info(struct device *dev, struct blob_buf *b) blobmsg_add_u8(b, "autoneg", !!ecmd.autoneg); } + if (!system_get_dev_sysfs("type", dev->ifname, buf, sizeof(buf))) { + dev_type = strtoul(buf, NULL, 0); + i = netdev_type_pos(dev_type); + blobmsg_add_string(b, "dev_type", netdev_type_name[i]); + netifd_log_message(L_CRIT, "Interface type %s detected\n", netdev_type_name[i]); + } + return 0; } diff --git a/system.h b/system.h index 1f7037d..fdd8a64 100644 --- 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", "ETHER", "EETHER", "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", "IEEE80211_PRISM", + "IEEE80211_RADIOTAP", "PHONET", "PHONET_PIPE", + "IEEE802154", "VOID", "NONE" +}; + enum tunnel_param { TUNNEL_ATTR_TYPE, TUNNEL_ATTR_REMOTE,