1a6086278SArchie Cobbs.\" Copyright (c) 2000 Whistle Communications, Inc. 2a6086278SArchie Cobbs.\" All rights reserved. 3a6086278SArchie Cobbs.\" 4a6086278SArchie Cobbs.\" Subject to the following obligations and disclaimer of warranty, use and 5a6086278SArchie Cobbs.\" redistribution of this software, in source or object code forms, with or 6a6086278SArchie Cobbs.\" without modifications are expressly permitted by Whistle Communications; 7a6086278SArchie Cobbs.\" provided, however, that: 8a6086278SArchie Cobbs.\" 1. Any and all reproductions of the source or object code must include the 9a6086278SArchie Cobbs.\" copyright notice above and the following disclaimer of warranties; and 10a6086278SArchie Cobbs.\" 2. No rights are granted, in any manner or form, to use Whistle 11a6086278SArchie Cobbs.\" Communications, Inc. trademarks, including the mark "WHISTLE 12a6086278SArchie Cobbs.\" COMMUNICATIONS" on advertising, endorsements, or otherwise except as 13a6086278SArchie Cobbs.\" such appears in the above copyright notice or in the software. 14a6086278SArchie Cobbs.\" 15a6086278SArchie Cobbs.\" THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 16a6086278SArchie Cobbs.\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 17a6086278SArchie Cobbs.\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 18a6086278SArchie Cobbs.\" INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 19a6086278SArchie Cobbs.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 20a6086278SArchie Cobbs.\" WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 21a6086278SArchie Cobbs.\" REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 22a6086278SArchie Cobbs.\" SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 23a6086278SArchie Cobbs.\" IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 24a6086278SArchie Cobbs.\" RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 25a6086278SArchie Cobbs.\" WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 26a6086278SArchie Cobbs.\" PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 27a6086278SArchie Cobbs.\" SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 28a6086278SArchie Cobbs.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29a6086278SArchie Cobbs.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30a6086278SArchie Cobbs.\" THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 31a6086278SArchie Cobbs.\" OF SUCH DAMAGE. 32a6086278SArchie Cobbs.\" 33eddc45e7SJeroen Ruigrok van der Werven.\" Author: Archie Cobbs <archie@FreeBSD.org> 34a6086278SArchie Cobbs.\" 35a6086278SArchie Cobbs.\" $FreeBSD$ 36a6086278SArchie Cobbs.\" 37111e172dSRuslan Ermilov.Dd April 21, 2004 3895d7878cSArchie Cobbs.Dt NG_ETHER 4 393d45e180SRuslan Ermilov.Os 40a6086278SArchie Cobbs.Sh NAME 41a6086278SArchie Cobbs.Nm ng_ether 42a6086278SArchie Cobbs.Nd Ethernet netgraph node type 43a6086278SArchie Cobbs.Sh SYNOPSIS 4432eef9aeSRuslan Ermilov.In netgraph/ng_ether.h 45a6086278SArchie Cobbs.Sh DESCRIPTION 46a6086278SArchie CobbsThe 47111e172dSRuslan Ermilov.Nm ether 48a6086278SArchie Cobbsnetgraph node type allows Ethernet interfaces to interact with 49a6086278SArchie Cobbsthe 50a6086278SArchie Cobbs.Xr netgraph 4 51b3fed38dSArchie Cobbsnetworking subsystem. 52b3fed38dSArchie CobbsOnce the 53b3fed38dSArchie Cobbs.Nm 54111e172dSRuslan Ermilovmodule is loaded into the kernel, a node is automatically created 55b3fed38dSArchie Cobbsfor each Ethernet interface in the system. 56b3fed38dSArchie CobbsEach node will attempt to name itself with the same name 57b3fed38dSArchie Cobbsas the associated interface. 58b3fed38dSArchie CobbsAll 59111e172dSRuslan Ermilov.Nm ether 60b3fed38dSArchie Cobbsnodes are persistent for as long as the interface itself exists. 61a6086278SArchie Cobbs.Pp 62b3fed38dSArchie CobbsThree hooks are supported: 63111e172dSRuslan Ermilov.Va lower , upper , 64b3fed38dSArchie Cobbsand 65111e172dSRuslan Ermilov.Va orphans . 66b3fed38dSArchie CobbsThe hook name 67111e172dSRuslan Ermilov.Va divert 68b3fed38dSArchie Cobbsmay be used as an alias for 69111e172dSRuslan Ermilov.Va lower , 70b3fed38dSArchie Cobbsand is provided for backward compatibility. 71111e172dSRuslan ErmilovIn reality, the two names represent the same hook. 72a6086278SArchie Cobbs.Pp 73b3fed38dSArchie CobbsThe 74111e172dSRuslan Ermilov.Va lower 75b3fed38dSArchie Cobbshook is a connection to the raw Ethernet device. 76111e172dSRuslan ErmilovWhen connected, all incoming packets are forwarded to this hook, 77111e172dSRuslan Ermilovinstead of being passed to the kernel for upper layer processing. 78b3fed38dSArchie CobbsWriting to this hook results in a raw Ethernet frame being transmitted 79b3fed38dSArchie Cobbsby the device. 80b3fed38dSArchie CobbsNormal outgoing packets are not affected by 81111e172dSRuslan Ermilov.Va lower 82b3fed38dSArchie Cobbsbeing connected. 83b3fed38dSArchie Cobbs.Pp 84b3fed38dSArchie CobbsThe 85111e172dSRuslan Ermilov.Va upper 86b3fed38dSArchie Cobbshook is a connection to the upper protocol layers. 87111e172dSRuslan ErmilovWhen connected, all outgoing packets are forwarded to this hook, 88111e172dSRuslan Ermilovinstead of being transmitted by the device. 89b3fed38dSArchie CobbsWriting to this hook results in a raw Ethernet frame being received by 90b3fed38dSArchie Cobbsthe kernel just as if it had come in over the wire. 91b3fed38dSArchie CobbsNormal incoming packets are not affected by 92111e172dSRuslan Ermilov.Va upper 93b3fed38dSArchie Cobbsbeing connected. 94b3fed38dSArchie Cobbs.Pp 95b3fed38dSArchie CobbsThe 96111e172dSRuslan Ermilov.Va orphans 97b3fed38dSArchie Cobbshook is equivalent to 98111e172dSRuslan Ermilov.Va lower , 99b3fed38dSArchie Cobbsexcept that only unrecognized packets (that would otherwise be discarded) 100b3fed38dSArchie Cobbsare written to the hook, and normal incoming traffic is unaffected. 101b3fed38dSArchie CobbsAt most one of 102111e172dSRuslan Ermilov.Va orphans 103b3fed38dSArchie Cobbsand 104111e172dSRuslan Ermilov.Va lower 105b3fed38dSArchie Cobbsmay be connected at any time. 106b3fed38dSArchie Cobbs.Pp 107b3fed38dSArchie CobbsIn all cases, frames are raw Ethernet frames with the standard 108a6086278SArchie Cobbs14 byte Ethernet header (but no checksum). 109b3fed38dSArchie Cobbs.Pp 110b3fed38dSArchie CobbsWhen no hooks are connected, 111111e172dSRuslan Ermilov.Va upper 112b3fed38dSArchie Cobbsand 113111e172dSRuslan Ermilov.Va lower 114b3fed38dSArchie Cobbsare in effect connected together, 115b3fed38dSArchie Cobbsso that packets flow normally upwards and downwards. 116a6086278SArchie Cobbs.Sh HOOKS 117a6086278SArchie CobbsThis node type supports the following hooks: 118111e172dSRuslan Ermilov.Bl -tag -width ".Va orphans" 119111e172dSRuslan Ermilov.It Va lower 120b3fed38dSArchie CobbsConnection to the lower device link layer. 121111e172dSRuslan Ermilov.It Va upper 122b3fed38dSArchie CobbsConnection to the upper protocol layers. 123111e172dSRuslan Ermilov.It Va orphans 124b3fed38dSArchie CobbsLike 125111e172dSRuslan Ermilov.Va lower , 126b3fed38dSArchie Cobbsbut only receives unrecognized packets. 127a6086278SArchie Cobbs.El 128a6086278SArchie Cobbs.Sh CONTROL MESSAGES 129b3fed38dSArchie CobbsThis node type supports the generic control messages, plus the following: 130111e172dSRuslan Ermilov.Bl -tag -width indent 131111e172dSRuslan Ermilov.It Dv NGM_ETHER_GET_IFNAME Pq Li getifname 132111e172dSRuslan ErmilovReturns the name of the associated interface as a 133111e172dSRuslan Ermilov.Dv NUL Ns -terminated 134111e172dSRuslan Ermilov.Tn ASCII 135111e172dSRuslan Ermilovstring. 136b3fed38dSArchie CobbsNormally this is the same as the name of the node. 137111e172dSRuslan Ermilov.It Dv NGM_ETHER_GET_IFINDEX Pq Li getifindex 138b3fed38dSArchie CobbsReturns the global index of the associated interface as a 32 bit integer. 139111e172dSRuslan Ermilov.It Dv NGM_ETHER_GET_ENADDR Pq Li getenaddr 1401623d682SArchie CobbsReturns the device's unique six byte Ethernet address. 141111e172dSRuslan Ermilov.It Dv NGM_ETHER_SET_ENADDR Pq Li setenaddr 14281e88a06SArchie CobbsSets the device's unique six byte Ethernet address. 14381e88a06SArchie CobbsThis control message is equivalent to using the 14481e88a06SArchie Cobbs.Dv SIOCSIFLLADDR 14581e88a06SArchie Cobbs.Xr ioctl 2 14681e88a06SArchie Cobbssystem call. 147111e172dSRuslan Ermilov.It Dv NGM_ETHER_SET_PROMISC Pq Li setpromisc 1481623d682SArchie CobbsEnable or disable promiscuous mode. 1491623d682SArchie CobbsThis message includes a single 32 bit integer flag that enables or 1501623d682SArchie Cobbsdisables promiscuous mode on the interface. 151111e172dSRuslan ErmilovAny non-zero value enables promiscuous mode. 152111e172dSRuslan Ermilov.It Dv NGM_ETHER_GET_PROMISC Pq Li getpromisc 15381e88a06SArchie CobbsGet the current value of the node's promiscuous flag. 15481e88a06SArchie CobbsThe returned value is always either one or zero. 15581e88a06SArchie CobbsNote that this flag reflects the node's own promiscuous setting 15681e88a06SArchie Cobbsand does not necessarily reflect the promiscuous state of the actual 15781e88a06SArchie Cobbsinterface, which can be affected by other means (e.g., 15881e88a06SArchie Cobbs.Xr bpf 4 ) . 159111e172dSRuslan Ermilov.It Dv NGM_ETHER_SET_AUTOSRC Pq Li setautosrc 1601623d682SArchie CobbsSets the automatic source address override flag. 161320089a0SArchie CobbsThis message includes a single 32 bit integer flag that causes 1621623d682SArchie Cobbsall outgoing packets to have their source Ethernet 1631623d682SArchie Cobbsaddress field overwritten with the device's unique Ethernet address. 1641623d682SArchie CobbsIf this flag is set to zero, the source address in outgoing packets 1651623d682SArchie Cobbsis not modified. 1661623d682SArchie CobbsThe default setting for this flag is enabled. 167111e172dSRuslan Ermilov.It Dv NGM_ETHER_GET_AUTOSRC Pq Li getautosrc 16881e88a06SArchie CobbsGet the current value of the node's source address override flag. 16981e88a06SArchie CobbsThe returned value is always either one or zero. 170b3fed38dSArchie Cobbs.El 171a6086278SArchie Cobbs.Sh SHUTDOWN 172111e172dSRuslan ErmilovThis node is persistent for as long as the corresponding interface exists. 173111e172dSRuslan ErmilovUpon receipt of the 174a6086278SArchie Cobbs.Dv NGM_SHUTDOWN 1751623d682SArchie Cobbscontrol message, all hooks are disconnected, promiscuous mode is disabled, 176111e172dSRuslan Ermilovand the source address override flag is re-enabled, 1771623d682SArchie Cobbsbut the node is not removed. 178111e172dSRuslan ErmilovIf the interface itself is detached (e.g., because of PC Card removal), the 179b3fed38dSArchie Cobbsnode disappears as well. 180251c176fSRuslan Ermilov.Sh EXAMPLES 181b3fed38dSArchie CobbsThis command dumps all unrecognized packets received by the 182111e172dSRuslan Ermilov.Dq Li fxp0 183111e172dSRuslan Ermilovinterface to standard output decoded in hex and 184111e172dSRuslan Ermilov.Tn ASCII : 185111e172dSRuslan Ermilov.Pp 186111e172dSRuslan Ermilov.Dl "nghook -a fxp0: orphans" 187b3fed38dSArchie Cobbs.Pp 188b3fed38dSArchie CobbsThis command sends the contents of 189111e172dSRuslan Ermilov.Pa sample.pkt 190b3fed38dSArchie Cobbsout the interface 191111e172dSRuslan Ermilov.Dq Li fxp0 : 192111e172dSRuslan Ermilov.Pp 193111e172dSRuslan Ermilov.Dl "cat sample.pkt | nghook fxp0: orphans" 194b3fed38dSArchie Cobbs.Pp 195b3fed38dSArchie CobbsThese commands insert an 196b3fed38dSArchie Cobbs.Xr ng_tee 4 197111e172dSRuslan Ermilovnode between the 198111e172dSRuslan Ermilov.Va lower 199111e172dSRuslan Ermilovand 200111e172dSRuslan Ermilov.Va upper 201111e172dSRuslan Ermilovprotocol layers, which can be used for 202b3fed38dSArchie Cobbstracing packet flow, statistics, etc.: 203b3fed38dSArchie Cobbs.Bd -literal -offset indent 204b3fed38dSArchie Cobbsngctl mkpeer fxp0: tee lower right 205b3fed38dSArchie Cobbsngctl connect fxp0: lower upper left 206ac4a79b0SArchie Cobbs.Ed 20773cf2c30SArchie Cobbs.Sh BUGS 20873cf2c30SArchie CobbsThe automatic KLD module loading mechanism that works for most 209111e172dSRuslan Ermilovother Netgraph node types does not work for the 210111e172dSRuslan Ermilov.Nm ether 21173cf2c30SArchie Cobbsnode type, 21273cf2c30SArchie Cobbsbecause 213111e172dSRuslan Ermilov.Nm ether 21473cf2c30SArchie Cobbsnodes are not created on demand; instead, they are created when 21573cf2c30SArchie CobbsEthernet interfaces are attached or when the KLD is first loaded. 21673cf2c30SArchie CobbsTherefore, if the KLD is not statically compiled into the kernel, 21773cf2c30SArchie Cobbsit is necessary to load the KLD manually in order to bring the 218111e172dSRuslan Ermilov.Nm ether 21973cf2c30SArchie Cobbsnodes into existence. 220a6086278SArchie Cobbs.Sh SEE ALSO 221a6086278SArchie Cobbs.Xr arp 4 , 222a6086278SArchie Cobbs.Xr netgraph 4 , 223a6086278SArchie Cobbs.Xr netintro 4 , 224a6086278SArchie Cobbs.Xr ifconfig 8 , 2255521ff5aSRuslan Ermilov.Xr ngctl 8 , 2265521ff5aSRuslan Ermilov.Xr nghook 8 227b3fed38dSArchie Cobbs.Sh AUTHORS 228d905b0b6SMike Pritchard.An Julian Elischer Aq julian@FreeBSD.org 229b3fed38dSArchie Cobbs.An Archie Cobbs Aq archie@FreeBSD.org 230