1*4541d682Sthorpej.\" $NetBSD: ethersubr.9,v 1.28 2020/01/20 18:38:18 thorpej Exp $ 258018783Sis.\" 32c7fa23cSis.\" Copyright (c) 1997 The NetBSD Foundation, Inc. 458018783Sis.\" All rights reserved. 558018783Sis.\" 6dc068e0dSis.\" This code is derived from software contributed to The NetBSD Foundation 7dc068e0dSis.\" by Ignatios Souvatzis. 8dc068e0dSis.\" 958018783Sis.\" Redistribution and use in source and binary forms, with or without 1058018783Sis.\" modification, are permitted provided that the following conditions 1158018783Sis.\" are met: 1258018783Sis.\" 1. Redistributions of source code must retain the above copyright 1358018783Sis.\" notice, this list of conditions and the following disclaimer. 1458018783Sis.\" 2. Redistributions in binary form must reproduce the above copyright 1558018783Sis.\" notice, this list of conditions and the following disclaimer in the 1658018783Sis.\" documentation and/or other materials provided with the distribution. 1758018783Sis.\" 18dc068e0dSis.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19dc068e0dSis.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20dc068e0dSis.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21dc068e0dSis.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22dc068e0dSis.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23dc068e0dSis.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24dc068e0dSis.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25dc068e0dSis.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26dc068e0dSis.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27dc068e0dSis.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28dc068e0dSis.\" POSSIBILITY OF SUCH DAMAGE. 2958018783Sis.\" 30*4541d682Sthorpej.Dd January 19, 2020 3158018783Sis.Dt ETHERSUBR 9 32e4c16bfbSgarbled.Os 3358018783Sis.Sh NAME 34ccbf3f5dSmikel.Nm ethersubr , 356be07a67Smrg.Nm ether_ifattach , 366be07a67Smrg.Nm ether_addmulti , 376be07a67Smrg.Nm ether_delmulti , 386be07a67Smrg.Nm ETHER_FIRST_MULTI , 396be07a67Smrg.Nm ETHER_NEXT_MULTI , 40*4541d682Sthorpej.Nm ETHER_IS_MULTICAST 41*4541d682Sthorpej.Nd Ethernet driver support functions and macros 4258018783Sis.Sh SYNOPSIS 43472351e1Swiz.In net/if_ether.h 4458018783Sis.Ft void 45fd18408bSperry.Fn ether_ifattach "struct ifnet *ifp" "uint8_t *lla" 4658018783Sis.Ft int 47594712b2Sdyoung.Fn ether_addmulti "const struct sockaddr *sa" "struct ethercom *ec" 4858018783Sis.Ft int 49594712b2Sdyoung.Fn ether_delmulti "const struct sockaddr *sa" "struct ethercom *ec" 5058018783Sis.Ft void 5158018783Sis.Fn ETHER_FIRST_MULTI "struct ether_multistep step" "struct ethercom *ec" "struct ether_multi *enm" 5258018783Sis.Ft void 5358018783Sis.Fn ETHER_NEXT_MULTI "struct ether_multistep step" "struct ether_multi *enm" 5458018783Sis.Ft int 55fd18408bSperry.Fn ETHER_IS_MULTICAST "uint8_t *addr" 5658018783Sis.Sh DESCRIPTION 5758018783SisThe 5858018783Sis.Nm 5958018783Sisfunctions provide the interface between the 6058018783Sis.Nm 616bb98532Smycroftmodule and the network drivers which need Ethernet support. 626bb98532SmycroftSuch drivers must request the 636bb98532Smycroft.Ar ether 646bb98532Smycroftattribute in their 656bb98532Smycroft.Ar files 666bb98532Smycroftdeclaration and call the appropriate functions as specified below. 670e3b2908Slukem.Pp 6858018783SisNote that you also need the 69ccbf3f5dSmikel.Xr arp 9 7058018783Sisstuff to support IPv4 on your hardware. 7158018783Sis.Bl -tag -width compact 727f238516Sjruoho.It Fn ether_ifattach "ifp" "lla" 73ccbf3f5dSmikelPerform the device-independent, but Ethernet-specific initialization of 7458018783Sisthe interface pointed to by 7558018783Sis.Fa ifp . 760e3b2908Slukem.Pp 7758018783SisAmong other duties, this function creates a record for the link level 78ccbf3f5dSmikeladdress in the interface's address list and records the link level address 7958018783Sispointed to by 8058018783Sis.Fa lla 8158018783Sisthere. 82b79bd95dSozaki-rDrivers can initialize the link level address by themselves by calling 83b79bd95dSozaki-rthe function with 84b79bd95dSozaki-r.Fa lla 8581f31009Swizas 8681f31009Swiz.Dv NULL 8781f31009Swizand calling 88b79bd95dSozaki-r.Fn if_set_sadl . 890e3b2908Slukem.Pp 90c6660bc8SjruohoThis function must be called from the driver's attach function. 917f238516Sjruoho.It Fn ether_addmulti "sa" "ec" 927f238516Sjruoho.It Fn ether_delmulti "sa" "ec" 93ccbf3f5dSmikelAdd 94ccbf3f5dSmikel.Pq Fn ether_addmulti 95ccbf3f5dSmikelor delete 96ccbf3f5dSmikel.Pq Fn ether_delmulti 9758018783Sisthe address described by the 98594712b2Sdyoung.Fa sa 9958018783Sispointer to the Ethernet multicast list belonging to 10058018783Sis.Fa ec . 1010e3b2908Slukem.Pp 102ccbf3f5dSmikelThese functions must be called from the driver's ioctl function to 103ccbf3f5dSmikelhandle 104ccbf3f5dSmikel.Dv SIOCADDMULTI 105ccbf3f5dSmikeland 106ccbf3f5dSmikel.Dv SIOCDELMULTI 1076bb98532Smycroftrequests. 108c6660bc8SjruohoIf these return 109ccbf3f5dSmikel.Er ENETRESET , 110ccbf3f5dSmikelthe hardware multicast filter must be reinitialized. 1110e3b2908Slukem.Pp 112ccbf3f5dSmikelThese functions accept 113ccbf3f5dSmikel.Dv AF_UNSPEC 114ccbf3f5dSmikeladdresses, which are interpreted as Ethernet addresses, or 115ccbf3f5dSmikel.Dv AF_INET 1166bb98532Smycroftaddresses. 1176bb98532SmycroftIn the latter case, 118ccbf3f5dSmikel.Dv INADDR_ANY 119ccbf3f5dSmikelis mapped to a range describing all the Ethernet address 12058018783Sisspace reserved for IPv4 multicast addresses. 1210e3b2908Slukem.Pp 122c6660bc8SjruohoThe 12358018783Sis.Fn ether_addmulti 124ccbf3f5dSmikelreturns 125ccbf3f5dSmikel.Er EAFNOSUPPORT 126ccbf3f5dSmikelif an unsupported address family is specified, 127ccbf3f5dSmikel.Er EINVAL 128ccbf3f5dSmikelif a non-multicast address is specified, or 129ccbf3f5dSmikel.Er ENETRESET 130ccbf3f5dSmikelif 13158018783Sisthe multicast list really changed and the driver should synchronize 13258018783Sisits hardware filter with it. 1330e3b2908Slukem.Pp 134c6660bc8SjruohoThe 13558018783Sis.Fn ether_delmulti 136ccbf3f5dSmikelreturns, in addition to the above errors, 137ccbf3f5dSmikel.Er ENXIO 138ccbf3f5dSmikelif the specified address 13958018783Siscan't be found in the list of multicast addresses. 1407f238516Sjruoho.It Fn ETHER_NEXT_MULTI "step" "enm" 141c6660bc8SjruohoA macro to step through all of the 142c6660bc8Sjruoho.Em ether_multi 143c6660bc8Sjruohorecords, one at a time. 14458018783SisThe current position is remembered in 14558018783Sis.Fa step , 14658018783Siswhich the caller must provide. 1477f238516Sjruoho.It Fn ETHER_FIRST_MULTI "step" "ec" "enm" 148c6660bc8SjruohoA macro that must be called to initialize 14958018783Sis.Fa step 150770eef21Swizand get the first record. 151770eef21SwizBoth macros return a 152ccbf3f5dSmikel.Dv NULL 15358018783Sis.Fa enm 15458018783Siswhen there are no remaining records. 1557f238516Sjruoho.It Fn ETHER_IS_MULTICAST "addr" 156c6660bc8SjruohoA macro that returns 1, if 15758018783Sis.Fa addr 15858018783Sispoints to an Ethernet/FDDI multicast (or broadcast) address. 15958018783Sis.El 160b68f9ed2Sis.Sh CODE REFERENCES 161ccbf3f5dSmikelEthernet support functions are declared in 1625e015e5eSjoerg.In net/if_ether.h 16358018783Sisand defined (if not implemented as macro) in 16405859157Swiz.Pa sys/net/if_ethersubr.c . 1654119c8fbSwiz.Sh SEE ALSO 1664119c8fbSwiz.Xr arp 9 1674119c8fbSwiz.Sh HISTORY 1684119c8fbSwizRewritten to attach to the new ARP system in 1694119c8fbSwiz.Nx 1.3 . 1704119c8fbSwiz.Sh AUTHORS 1714119c8fbSwizUCB CSRG (original implementation) 1724119c8fbSwiz.Pp 17381f31009Swiz.An Ignatios Souvatzis 17481f31009Swiz(support for new ARP system) 175