From nobody Fri Jan 14 13:37:02 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 51BEE19662A7; Fri, 14 Jan 2022 13:37:05 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jb2Qm00Z8z4x0q; Fri, 14 Jan 2022 13:37:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642167424; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PwdPqxDuO9WBTuFx1UKFsD0kUS6SZBbm+vWSnLsNT1E=; b=xMeJEgnGQTsGa9/EtNmYLhwncmCM83iWbX+NSWma9n/WG+B/Br0mxv4qVQt++DAxIWS502 aKWnnfTXRnTwn5z/nhNxCAIghKkfqKB1/w85NNPhOkFj19Z8d9jdo34+58TeILv5Hw/DNE iUSYR2mK+dOykFEhtzec0CBJoW3PbwyJ4tFQpUOrk1AYf6Gcqqs4fanhiYhG/zyJAFs6Zg QmEppR5CqJZyLWDKHy8jD5m9SOleukCsMKVO89mvQQAmZJ09vt/u5KLgzD2uwDvE+Hufyc jx9/VlMV6KmyO1fx7pPQ9jZ42ls9VGaoO0s5YluetFJwGg7X9Vjr5MBi3WS3Rw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BC6EC14C13; Fri, 14 Jan 2022 13:37:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20EDb2AA023808; Fri, 14 Jan 2022 13:37:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20EDb2wm023807; Fri, 14 Jan 2022 13:37:02 GMT (envelope-from git) Date: Fri, 14 Jan 2022 13:37:02 GMT Message-Id: <202201141337.20EDb2wm023807@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Emmanuel Vadot Subject: git: 1a86aab86af0 - stable/13 - Add ETHER_ALIGN support to ng_device(4). List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1a86aab86af08a402e81b0216ca9fc34d2461c4a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642167424; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PwdPqxDuO9WBTuFx1UKFsD0kUS6SZBbm+vWSnLsNT1E=; b=CuOAr14jx3VFSE0hNp2wcAEBLBAr2gF0JCimSa4pmo/0abvYODmElXMKhQ1I5P7BpVsV9n br251KTD3YQgkHwf5BuO7ui5LFYlmyTZP7+sSILFWOBN9cTbw4vqQwS9dGgq1FA5IheI4D qsupFjqnUw5Lmp/9ZNrPuINTk57juAR46jlA7ELxn+KheTlGZ0IP7wLqOeqmdymZM9thCy QG31HG3jXvQvXMdyiZGIXWRFgeUzu0M6MDfBZP6+Y1pjOcomk/AxOzc54xx6Lyva1Notcy eUZc3osshDktMYW2wmogqsGFplL2KYIonnxkOCAKqs0kCbNsYMHwdPc+KCqKqg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642167424; a=rsa-sha256; cv=none; b=bE40M0u5pjUw4wOY42Ja7I6GbUNhW2DvAYx6bY+TNIUNR1Led+t6UOWMEFwMsvRqBuHplZ dQyt5NnIZE3UoO6xBBp4FjkiEyp5KIh0kz3B4cAV+A/t/iFLPYprFb6vxswb6Dc9Q1B9MI 8ElmrNAWyfaNj5mrS9L+10RMnNzu0VA083y2XW/NWE7m8iXc4RfM2MhsiUnU/Q27YAij/K 0WSHJBtwWRivLibeyRlah2WGkmsM4fJ24Y27WZ/1Upfqr468sK55e9eeyMHRvohV71msuK KDXBn3cQLI8+yNAYj08bGU6Gk40ORqG68DS4zPF2eOr+z/wO4BM/Gwoa0fhWlQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=1a86aab86af08a402e81b0216ca9fc34d2461c4a commit 1a86aab86af08a402e81b0216ca9fc34d2461c4a Author: Ian Lepore AuthorDate: 2021-11-09 14:34:06 +0000 Commit: Emmanuel Vadot CommitDate: 2022-01-14 13:28:43 +0000 Add ETHER_ALIGN support to ng_device(4). This adds a new ng_device command, NGM_DEVICE_ETHERALIGN, which has no associated args. After the command arrives, the device begins adjusting all packets sent out its hook to have ETHER_ALIGN bytes of padding at the beginning of the packet. The ETHER_ALIGN padding is added only when running on an architecture that requires strict alignment of IP headers (based on the __NO_STRICT_ALIGNMENT macro, which is only #define'd on x86 as of this writing). This also adds ascii <-> binary command translation to ng_device, both for the existing NGM_DEVICE_GET_DEVNAME and the new ETHERALIGN command. This also gives a name to every ng_device node when it is constructed, using the cdev device name (ngd0, ngd1, etc). This makes it easier to address command msgs to the device using ngctl(8). Reviewed by: donner, ray, adrian Differential Revision: https://reviews.freebsd.org/D32905 MFC after: 1 week (cherry picked from commit 44aae623ab858387301358b9b054cd229ce41068) --- share/man/man4/ng_device.4 | 16 ++++++++++++---- sys/netgraph/ng_device.c | 39 ++++++++++++++++++++++++++++++++++++++- sys/netgraph/ng_device.h | 1 + 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/share/man/man4/ng_device.4 b/share/man/man4/ng_device.4 index 5374e646dbef..8b1ee32b8536 100644 --- a/share/man/man4/ng_device.4 +++ b/share/man/man4/ng_device.4 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd October 19, 2004 +.Dd November 8, 2021 .Dt NG_DEVICE 4 .Os .Sh NAME @@ -48,7 +48,7 @@ etc. .Pp The first node is created as .Pa /dev/ngd0 , -all subsequent nodes +subsequent nodes are .Pa /dev/ngd1 , /dev/ngd2 , etc. .Sh HOOKS @@ -64,10 +64,18 @@ will be forwarded to the hook. .Sh CONTROL MESSAGES The .Nm device -node supports one non-generic control message: +node supports the generic control messages, plus the following: .Bl -tag -width 3n .It Dv NGM_DEVICE_GET_DEVNAME -Returns device name corresponding to a node. +Returns the device name corresponding to the node. +.It Dv NGM_DEVICE_ETHERALIGN +Apply the system ETHER_ALIGN offset to mbufs sent out the node's hook, +if running on an architecture that requires strict alignment. +Use this option when the data being injected via the device node ultimately +ends up being fed into the protocol stack as ethernet packets (e.g., via +an +.Xr ng_eiface 4 +node). .El .\" Additionally, the node accepts .\" .Xr ioctl 2 Ns s diff --git a/sys/netgraph/ng_device.c b/sys/netgraph/ng_device.c index ff62f7f44a35..032867ee4bf6 100644 --- a/sys/netgraph/ng_device.c +++ b/sys/netgraph/ng_device.c @@ -50,10 +50,12 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -63,6 +65,7 @@ #include #include #include +#include #define ERROUT(x) do { error = (x); goto done; } while (0) @@ -75,6 +78,25 @@ static ng_newhook_t ng_device_newhook; static ng_rcvdata_t ng_device_rcvdata; static ng_disconnect_t ng_device_disconnect; +/* List of commands and how to convert arguments to/from ASCII. */ +static const struct ng_cmdlist ng_device_cmds[] = { + { + NGM_DEVICE_COOKIE, + NGM_DEVICE_GET_DEVNAME, + "getdevname", + NULL, + &ng_parse_string_type + }, + { + NGM_DEVICE_COOKIE, + NGM_DEVICE_ETHERALIGN, + "etheralign", + NULL, + NULL + }, + { 0 } +}; + /* Netgraph type */ static struct ng_type ngd_typestruct = { .version = NG_ABI_VERSION, @@ -86,6 +108,7 @@ static struct ng_type ngd_typestruct = { .newhook = ng_device_newhook, .rcvdata = ng_device_rcvdata, .disconnect = ng_device_disconnect, + .cmdlist = ng_device_cmds, }; NETGRAPH_INIT(device, &ngd_typestruct); @@ -97,6 +120,7 @@ struct ngd_private { struct cdev *ngddev; struct mtx ngd_mtx; int unit; + int ether_align; uint16_t flags; #define NGDF_OPEN 0x0001 #define NGDF_RWAIT 0x0002 @@ -194,6 +218,11 @@ ng_device_constructor(node_p node) /* XXX: race here? */ priv->ngddev->si_drv1 = priv; + /* Give this node the same name as the device (if possible). */ + if (ng_name_node(node, devtoname(priv->ngddev)) != 0) + log(LOG_WARNING, "%s: can't acquire netgraph name\n", + devtoname(priv->ngddev)); + return(0); } @@ -226,6 +255,13 @@ ng_device_rcvmsg(node_p node, item_p item, hook_p lasthook) strlcpy((char *)resp->data, dn, strlen(dn) + 1); break; + case NGM_DEVICE_ETHERALIGN: + /* Use ETHER_ALIGN on arches that require it. */ +#ifndef __NO_STRICT_ALIGNMENT + priv->ether_align = ETHER_ALIGN; +#endif + break; + default: error = EINVAL; break; @@ -468,7 +504,8 @@ ngdwrite(struct cdev *dev, struct uio *uio, int flag) if (uio->uio_resid < 0 || uio->uio_resid > IP_MAXPACKET) return (EIO); - if ((m = m_uiotombuf(uio, M_NOWAIT, 0, 0, M_PKTHDR)) == NULL) + m = m_uiotombuf(uio, M_NOWAIT, 0, priv->ether_align, M_PKTHDR); + if (m == NULL) return (ENOBUFS); NET_EPOCH_ENTER(et); diff --git a/sys/netgraph/ng_device.h b/sys/netgraph/ng_device.h index 00877b7452b3..e8f8bfd62687 100644 --- a/sys/netgraph/ng_device.h +++ b/sys/netgraph/ng_device.h @@ -39,6 +39,7 @@ /* Netgraph control messages */ enum { NGM_DEVICE_GET_DEVNAME, + NGM_DEVICE_ETHERALIGN, }; #if 0