xref: /freebsd/share/man/man4/ng_ether.4 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
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.\"
3579ddde08SGleb Smirnoff.Dd June 23, 2011
3695d7878cSArchie Cobbs.Dt NG_ETHER 4
373d45e180SRuslan Ermilov.Os
38a6086278SArchie Cobbs.Sh NAME
39a6086278SArchie Cobbs.Nm ng_ether
40a6086278SArchie Cobbs.Nd Ethernet netgraph node type
41a6086278SArchie Cobbs.Sh SYNOPSIS
4232eef9aeSRuslan Ermilov.In netgraph/ng_ether.h
43a6086278SArchie Cobbs.Sh DESCRIPTION
44a6086278SArchie CobbsThe
45111e172dSRuslan Ermilov.Nm ether
46a6086278SArchie Cobbsnetgraph node type allows Ethernet interfaces to interact with
47a6086278SArchie Cobbsthe
48a6086278SArchie Cobbs.Xr netgraph 4
49b3fed38dSArchie Cobbsnetworking subsystem.
50b3fed38dSArchie CobbsOnce the
51b3fed38dSArchie Cobbs.Nm
52111e172dSRuslan Ermilovmodule is loaded into the kernel, a node is automatically created
53b3fed38dSArchie Cobbsfor each Ethernet interface in the system.
54b3fed38dSArchie CobbsEach node will attempt to name itself with the same name
55b3fed38dSArchie Cobbsas the associated interface.
56a6086278SArchie Cobbs.Pp
57b3fed38dSArchie CobbsThree hooks are supported:
58111e172dSRuslan Ermilov.Va lower , upper ,
59b3fed38dSArchie Cobbsand
60111e172dSRuslan Ermilov.Va orphans .
61b3fed38dSArchie CobbsThe hook name
62111e172dSRuslan Ermilov.Va divert
63b3fed38dSArchie Cobbsmay be used as an alias for
64111e172dSRuslan Ermilov.Va lower ,
65b3fed38dSArchie Cobbsand is provided for backward compatibility.
66111e172dSRuslan ErmilovIn reality, the two names represent the same hook.
67a6086278SArchie Cobbs.Pp
68b3fed38dSArchie CobbsThe
69111e172dSRuslan Ermilov.Va lower
70b3fed38dSArchie Cobbshook is a connection to the raw Ethernet device.
71111e172dSRuslan ErmilovWhen connected, all incoming packets are forwarded to this hook,
72111e172dSRuslan Ermilovinstead of being passed to the kernel for upper layer processing.
73b3fed38dSArchie CobbsWriting to this hook results in a raw Ethernet frame being transmitted
74b3fed38dSArchie Cobbsby the device.
75b3fed38dSArchie CobbsNormal outgoing packets are not affected by
76111e172dSRuslan Ermilov.Va lower
77b3fed38dSArchie Cobbsbeing connected.
78b3fed38dSArchie Cobbs.Pp
79b3fed38dSArchie CobbsThe
80111e172dSRuslan Ermilov.Va upper
81b3fed38dSArchie Cobbshook is a connection to the upper protocol layers.
82111e172dSRuslan ErmilovWhen connected, all outgoing packets are forwarded to this hook,
83111e172dSRuslan Ermilovinstead of being transmitted by the device.
84b3fed38dSArchie CobbsWriting to this hook results in a raw Ethernet frame being received by
85b3fed38dSArchie Cobbsthe kernel just as if it had come in over the wire.
86b3fed38dSArchie CobbsNormal incoming packets are not affected by
87111e172dSRuslan Ermilov.Va upper
88b3fed38dSArchie Cobbsbeing connected.
89b3fed38dSArchie Cobbs.Pp
90b3fed38dSArchie CobbsThe
91111e172dSRuslan Ermilov.Va orphans
92b3fed38dSArchie Cobbshook is equivalent to
93111e172dSRuslan Ermilov.Va lower ,
94b3fed38dSArchie Cobbsexcept that only unrecognized packets (that would otherwise be discarded)
951a292b80SArchie Cobbsare written to the hook, while other normal incoming traffic is unaffected.
961a292b80SArchie CobbsUnrecognized packets written to
971a292b80SArchie Cobbs.Va upper
981a292b80SArchie Cobbswill be forwarded back out to
99111e172dSRuslan Ermilov.Va orphans
1001a292b80SArchie Cobbsif connected.
101b3fed38dSArchie Cobbs.Pp
102b3fed38dSArchie CobbsIn all cases, frames are raw Ethernet frames with the standard
103a6086278SArchie Cobbs14 byte Ethernet header (but no checksum).
104b3fed38dSArchie Cobbs.Pp
105b3fed38dSArchie CobbsWhen no hooks are connected,
106111e172dSRuslan Ermilov.Va upper
107b3fed38dSArchie Cobbsand
108111e172dSRuslan Ermilov.Va lower
109b3fed38dSArchie Cobbsare in effect connected together,
110b3fed38dSArchie Cobbsso that packets flow normally upwards and downwards.
111a6086278SArchie Cobbs.Sh HOOKS
112a6086278SArchie CobbsThis node type supports the following hooks:
113111e172dSRuslan Ermilov.Bl -tag -width ".Va orphans"
114111e172dSRuslan Ermilov.It Va lower
115b3fed38dSArchie CobbsConnection to the lower device link layer.
116111e172dSRuslan Ermilov.It Va upper
117b3fed38dSArchie CobbsConnection to the upper protocol layers.
118111e172dSRuslan Ermilov.It Va orphans
119b3fed38dSArchie CobbsLike
120111e172dSRuslan Ermilov.Va lower ,
121b3fed38dSArchie Cobbsbut only receives unrecognized packets.
122a6086278SArchie Cobbs.El
123a6086278SArchie Cobbs.Sh CONTROL MESSAGES
124b3fed38dSArchie CobbsThis node type supports the generic control messages, plus the following:
125c60bda17SJoel Dahl.Bl -tag -width foo
126c60bda17SJoel Dahl.It Dv NGM_ETHER_GET_IFNAME Pq Ic getifname
127111e172dSRuslan ErmilovReturns the name of the associated interface as a
128111e172dSRuslan Ermilov.Dv NUL Ns -terminated
129111e172dSRuslan Ermilov.Tn ASCII
130111e172dSRuslan Ermilovstring.
131b3fed38dSArchie CobbsNormally this is the same as the name of the node.
132c60bda17SJoel Dahl.It Dv NGM_ETHER_GET_IFINDEX Pq Ic getifindex
133b3fed38dSArchie CobbsReturns the global index of the associated interface as a 32 bit integer.
134c60bda17SJoel Dahl.It Dv NGM_ETHER_GET_ENADDR Pq Ic getenaddr
1351623d682SArchie CobbsReturns the device's unique six byte Ethernet address.
136c60bda17SJoel Dahl.It Dv NGM_ETHER_SET_ENADDR Pq Ic setenaddr
13781e88a06SArchie CobbsSets the device's unique six byte Ethernet address.
13881e88a06SArchie CobbsThis control message is equivalent to using the
13981e88a06SArchie Cobbs.Dv SIOCSIFLLADDR
14081e88a06SArchie Cobbs.Xr ioctl 2
14181e88a06SArchie Cobbssystem call.
142c60bda17SJoel Dahl.It Dv NGM_ETHER_SET_PROMISC Pq Ic setpromisc
1431623d682SArchie CobbsEnable or disable promiscuous mode.
1441623d682SArchie CobbsThis message includes a single 32 bit integer flag that enables or
1451623d682SArchie Cobbsdisables promiscuous mode on the interface.
146111e172dSRuslan ErmilovAny non-zero value enables promiscuous mode.
147c60bda17SJoel Dahl.It Dv NGM_ETHER_GET_PROMISC Pq Ic getpromisc
14881e88a06SArchie CobbsGet the current value of the node's promiscuous flag.
14981e88a06SArchie CobbsThe returned value is always either one or zero.
15081e88a06SArchie CobbsNote that this flag reflects the node's own promiscuous setting
15181e88a06SArchie Cobbsand does not necessarily reflect the promiscuous state of the actual
15281e88a06SArchie Cobbsinterface, which can be affected by other means (e.g.,
15381e88a06SArchie Cobbs.Xr bpf 4 ) .
154c60bda17SJoel Dahl.It Dv NGM_ETHER_SET_AUTOSRC Pq Ic setautosrc
1551623d682SArchie CobbsSets the automatic source address override flag.
156320089a0SArchie CobbsThis message includes a single 32 bit integer flag that causes
1571623d682SArchie Cobbsall outgoing packets to have their source Ethernet
1581623d682SArchie Cobbsaddress field overwritten with the device's unique Ethernet address.
1591623d682SArchie CobbsIf this flag is set to zero, the source address in outgoing packets
1601623d682SArchie Cobbsis not modified.
161019a5076SGleb SmirnoffThe default setting for this flag is disabled.
162c60bda17SJoel Dahl.It Dv NGM_ETHER_GET_AUTOSRC Pq Ic getautosrc
16381e88a06SArchie CobbsGet the current value of the node's source address override flag.
16481e88a06SArchie CobbsThe returned value is always either one or zero.
165c60bda17SJoel Dahl.It Dv NGM_ETHER_ADD_MULTI Pq Ic addmulti
166ec63861dSGleb SmirnoffJoin Ethernet multicast group.
167ec63861dSGleb SmirnoffThis control message is equivalent to using the
168ec63861dSGleb Smirnoff.Dv SIOCADDMULTI
169ec63861dSGleb Smirnoff.Xr ioctl 2
170ec63861dSGleb Smirnoffsystem call.
171c60bda17SJoel Dahl.It Dv NGM_ETHER_DEL_MULTI Pq Ic delmulti
172ec63861dSGleb SmirnoffLeave Ethernet multicast group.
173ec63861dSGleb SmirnoffThis control message is equivalent to using the
174ec63861dSGleb Smirnoff.Dv SIOCDELMULTI
175ec63861dSGleb Smirnoff.Xr ioctl 2
176ec63861dSGleb Smirnoffsystem call.
177c60bda17SJoel Dahl.It Dv NGM_ETHER_DETACH Pq Ic detach
17899af2516SGleb SmirnoffDetach from underlying Ethernet interface and shut down node.
179b3fed38dSArchie Cobbs.El
180a6086278SArchie Cobbs.Sh SHUTDOWN
181111e172dSRuslan ErmilovUpon receipt of the
182a6086278SArchie Cobbs.Dv NGM_SHUTDOWN
1831623d682SArchie Cobbscontrol message, all hooks are disconnected, promiscuous mode is disabled,
1841623d682SArchie Cobbsbut the node is not removed.
18599af2516SGleb SmirnoffNode can be shut down only using
18699af2516SGleb Smirnoff.Dv NGM_ETHER_DETACH
18799af2516SGleb Smirnoffcontrol message.
188111e172dSRuslan ErmilovIf the interface itself is detached (e.g., because of PC Card removal), the
189b3fed38dSArchie Cobbsnode disappears as well.
190251c176fSRuslan Ermilov.Sh EXAMPLES
191b3fed38dSArchie CobbsThis command dumps all unrecognized packets received by the
192111e172dSRuslan Ermilov.Dq Li fxp0
193111e172dSRuslan Ermilovinterface to standard output decoded in hex and
194111e172dSRuslan Ermilov.Tn ASCII :
195111e172dSRuslan Ermilov.Pp
196111e172dSRuslan Ermilov.Dl "nghook -a fxp0: orphans"
197b3fed38dSArchie Cobbs.Pp
198b3fed38dSArchie CobbsThis command sends the contents of
199111e172dSRuslan Ermilov.Pa sample.pkt
200b3fed38dSArchie Cobbsout the interface
201111e172dSRuslan Ermilov.Dq Li fxp0 :
202111e172dSRuslan Ermilov.Pp
203111e172dSRuslan Ermilov.Dl "cat sample.pkt | nghook fxp0: orphans"
204b3fed38dSArchie Cobbs.Pp
205b3fed38dSArchie CobbsThese commands insert an
206b3fed38dSArchie Cobbs.Xr ng_tee 4
207111e172dSRuslan Ermilovnode between the
208111e172dSRuslan Ermilov.Va lower
209111e172dSRuslan Ermilovand
210111e172dSRuslan Ermilov.Va upper
211111e172dSRuslan Ermilovprotocol layers, which can be used for
212b3fed38dSArchie Cobbstracing packet flow, statistics, etc.:
213b3fed38dSArchie Cobbs.Bd -literal -offset indent
214b3fed38dSArchie Cobbsngctl mkpeer fxp0: tee lower right
215b3fed38dSArchie Cobbsngctl connect fxp0: lower upper left
216ac4a79b0SArchie Cobbs.Ed
2179cbda590SRuslan Ermilov.Sh SEE ALSO
2189cbda590SRuslan Ermilov.Xr arp 4 ,
2199cbda590SRuslan Ermilov.Xr netgraph 4 ,
2209cbda590SRuslan Ermilov.Xr netintro 4 ,
2219cbda590SRuslan Ermilov.Xr ifconfig 8 ,
2229cbda590SRuslan Ermilov.Xr ngctl 8 ,
2239cbda590SRuslan Ermilov.Xr nghook 8
2249cbda590SRuslan Ermilov.Sh AUTHORS
225*6c899950SBaptiste Daroussin.An Julian Elischer Aq Mt julian@FreeBSD.org
226*6c899950SBaptiste Daroussin.An Archie Cobbs Aq Mt archie@FreeBSD.org
22773cf2c30SArchie Cobbs.Sh BUGS
22873cf2c30SArchie CobbsThe automatic KLD module loading mechanism that works for most
229111e172dSRuslan Ermilovother Netgraph node types does not work for the
230111e172dSRuslan Ermilov.Nm ether
23173cf2c30SArchie Cobbsnode type,
23273cf2c30SArchie Cobbsbecause
233111e172dSRuslan Ermilov.Nm ether
23473cf2c30SArchie Cobbsnodes are not created on demand; instead, they are created when
23573cf2c30SArchie CobbsEthernet interfaces are attached or when the KLD is first loaded.
23673cf2c30SArchie CobbsTherefore, if the KLD is not statically compiled into the kernel,
23773cf2c30SArchie Cobbsit is necessary to load the KLD manually in order to bring the
238111e172dSRuslan Ermilov.Nm ether
23973cf2c30SArchie Cobbsnodes into existence.
240