From owner-svn-src-stable-12@freebsd.org Wed May 22 05:37:31 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E62B315A1165; Wed, 22 May 2019 05:37:30 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8D3D66C665; Wed, 22 May 2019 05:37:30 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4302A18F74; Wed, 22 May 2019 05:37:30 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x4M5bUY1000264; Wed, 22 May 2019 05:37:30 GMT (envelope-from dchagin@FreeBSD.org) Received: (from dchagin@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x4M5bUxR000263; Wed, 22 May 2019 05:37:30 GMT (envelope-from dchagin@FreeBSD.org) Message-Id: <201905220537.x4M5bUxR000263@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dchagin set sender to dchagin@FreeBSD.org using -f From: Dmitry Chagin Date: Wed, 22 May 2019 05:37:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r348096 - stable/12/sys/compat/linsysfs X-SVN-Group: stable-12 X-SVN-Commit-Author: dchagin X-SVN-Commit-Paths: stable/12/sys/compat/linsysfs X-SVN-Commit-Revision: 348096 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 8D3D66C665 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.97)[-0.974,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 May 2019 05:37:31 -0000 Author: dchagin Date: Wed May 22 05:37:29 2019 New Revision: 348096 URL: https://svnweb.freebsd.org/changeset/base/348096 Log: MFC r347204: Adds sys/class/net devices to linsysfs. Only two interfaces are created eth0 and lo and they expose the following properties: address, addr_len, flags, ifindex, mty, tx_queue_len and type. Initial patch developed by Carlos Neira in 2017 and finished by me. MFC r347218: Remove wrong copyright line. Discussed with Carlos Neira. Modified: stable/12/sys/compat/linsysfs/linsysfs.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/compat/linsysfs/linsysfs.c ============================================================================== --- stable/12/sys/compat/linsysfs/linsysfs.c Wed May 22 05:35:35 2019 (r348095) +++ stable/12/sys/compat/linsysfs/linsysfs.c Wed May 22 05:37:29 2019 (r348096) @@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -44,7 +45,11 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include +#include +#include #include #include @@ -64,6 +69,146 @@ atoi(const char *str) return (int)strtol(str, (char **)NULL, 10); } +static int +linsysfs_ifnet_addr(PFS_FILL_ARGS) +{ + struct l_sockaddr lsa; + struct ifnet *ifp; + + ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL); + if (ifp == NULL) + return (ENOENT); + if (linux_ifhwaddr(ifp, &lsa) != 0) + return (ENOENT); + sbuf_printf(sb, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", + lsa.sa_data[0], lsa.sa_data[1], lsa.sa_data[2], + lsa.sa_data[3], lsa.sa_data[4], lsa.sa_data[5]); + return (0); +} + +static int +linsysfs_ifnet_addrlen(PFS_FILL_ARGS) +{ + + sbuf_printf(sb, "%d\n", LINUX_IFHWADDRLEN); + return (0); +} + +static int +linsysfs_ifnet_flags(PFS_FILL_ARGS) +{ + struct ifnet *ifp; + unsigned short flags; + + ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL); + if (ifp == NULL) + return (ENOENT); + linux_ifflags(ifp, &flags); + sbuf_printf(sb, "0x%x\n", flags); + return (0); +} + +static int +linsysfs_ifnet_ifindex(PFS_FILL_ARGS) +{ + struct ifnet *ifp; + + ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL); + if (ifp == NULL) + return (ENOENT); + sbuf_printf(sb, "%u\n", ifp->if_index); + return (0); +} + +static int +linsysfs_ifnet_mtu(PFS_FILL_ARGS) +{ + struct ifnet *ifp; + + ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL); + if (ifp == NULL) + return (ENOENT); + sbuf_printf(sb, "%u\n", ifp->if_mtu); + return (0); +} + +static int +linsysfs_ifnet_tx_queue_len(PFS_FILL_ARGS) +{ + + /* XXX */ + sbuf_printf(sb, "1000\n"); + return (0); +} + +static int +linsysfs_ifnet_type(PFS_FILL_ARGS) +{ + struct l_sockaddr lsa; + struct ifnet *ifp; + + ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL); + if (ifp == NULL) + return (ENOENT); + if (linux_ifhwaddr(ifp, &lsa) != 0) + return (ENOENT); + sbuf_printf(sb, "%d\n", lsa.sa_family); + return (0); +} + +static void +linsysfs_listnics(struct pfs_node *dir) +{ + struct pfs_node *nic; + struct pfs_node *lo; + + nic = pfs_create_dir(dir, "eth0", NULL, NULL, NULL, 0); + + pfs_create_file(nic, "address", &linsysfs_ifnet_addr, + NULL, NULL, NULL, PFS_RD); + + pfs_create_file(nic, "addr_len", &linsysfs_ifnet_addrlen, + NULL, NULL, NULL, PFS_RD); + + pfs_create_file(nic, "flags", &linsysfs_ifnet_flags, + NULL, NULL, NULL, PFS_RD); + + pfs_create_file(nic, "ifindex", &linsysfs_ifnet_ifindex, + NULL, NULL, NULL, PFS_RD); + + pfs_create_file(nic, "mtu", &linsysfs_ifnet_mtu, + NULL, NULL, NULL, PFS_RD); + + pfs_create_file(nic, "tx_queue_len", &linsysfs_ifnet_tx_queue_len, + NULL, NULL, NULL, PFS_RD); + + pfs_create_file(nic, "type", &linsysfs_ifnet_type, + NULL, NULL, NULL, PFS_RD); + + lo = pfs_create_dir(dir, "lo", NULL, NULL, NULL, 0); + + pfs_create_file(lo, "address", &linsysfs_ifnet_addr, + NULL, NULL, NULL, PFS_RD); + + pfs_create_file(lo, "addr_len", &linsysfs_ifnet_addrlen, + NULL, NULL, NULL, PFS_RD); + + pfs_create_file(lo, "flags", &linsysfs_ifnet_flags, + NULL, NULL, NULL, PFS_RD); + + pfs_create_file(lo, "ifindex", &linsysfs_ifnet_ifindex, + NULL, NULL, NULL, PFS_RD); + + pfs_create_file(lo, "mtu", &linsysfs_ifnet_mtu, + NULL, NULL, NULL, PFS_RD); + + pfs_create_file(lo, "tx_queue_len", &linsysfs_ifnet_tx_queue_len, + NULL, NULL, NULL, PFS_RD); + + pfs_create_file(lo, "type", &linsysfs_ifnet_type, + NULL, NULL, NULL, PFS_RD); +} + /* * Filler function for proc_name */ @@ -475,6 +620,7 @@ linsysfs_init(PFS_INIT_ARGS) struct pfs_node *drm; struct pfs_node *pci; struct pfs_node *scsi; + struct pfs_node *net; struct pfs_node *devdir, *chardev; devclass_t devclass; device_t dev; @@ -488,6 +634,9 @@ linsysfs_init(PFS_INIT_ARGS) scsi = pfs_create_dir(class, "scsi_host", NULL, NULL, NULL, 0); drm = pfs_create_dir(class, "drm", NULL, NULL, NULL, 0); + /* /sys/class/net/.. */ + net = pfs_create_dir(class, "net", NULL, NULL, NULL, 0); + /* /sys/dev/... */ devdir = pfs_create_dir(root, "dev", NULL, NULL, NULL, 0); chardev = pfs_create_dir(devdir, "char", NULL, NULL, NULL, 0); @@ -514,6 +663,7 @@ linsysfs_init(PFS_INIT_ARGS) NULL, NULL, NULL, PFS_RD); linsysfs_listcpus(cpu); + linsysfs_listnics(net); return (0); }