Home | History | Annotate | Download | only in net
History log of /src/sys/net/if_ethersubr.c
RevisionDateAuthorComments
 1.331  21-Sep-2025  christos Centralize all the "can't handle af%d\n", messages in one place and provide
more context. Now I get ad-nauseam:
ether_output: wm1: can't handle af18 (link: link#2)
 1.330  23-Apr-2025  joe cleaar trailig whitespace
 1.329  28-Sep-2024  mlelstv count illegal slow protocol subtype as protocol error instead of generic
error.
 1.328  28-Sep-2024  mlelstv comment, whitespace.
 1.327  05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.326  02-Nov-2023  yamaguchi branches: 1.326.2; 1.326.4;
Use ether_bpf_mtap only when the device supports vlan harware tagging

The function is bpf_mtap() for ethernet devices and *currently*
it is just handling VLAN tag stripped by the hardware.
 1.325  02-Nov-2023  yamaguchi Added NULL check
 1.324  20-Oct-2023  msaitoh Print error message when the multicast bit is set in the MAC address.
 1.323  15-Nov-2022  roy branches: 1.323.2;
arp: Validate ARP source hardware address matches Ethernet source

RFC 5227 section 1.1 states that for a DaD ARP probe the sender hardware
address must match the hardware address of the interface sending the
packet.

We can now verify this by checking the mbuf tag PACKET_TAG_ETHERNET_SRC.

This fixes an obsure issue where an old router was sending out bogus
ARP probes.

Thanks to Ryo Shimizu <ryo@nerv.org> for the re-implementation.
 1.322  15-Nov-2022  roy Revert prior.
 1.321  14-Nov-2022  roy net: Store a pointer to the Layer 2 Sender Hardware address in mbuf

The BSD networking stack is designed around passing a mbuf down the chain
and each layer removes the part it's interested in before passing it to
the next. This makes it easy for each layer to do it's work,
but non trivial to work backwards.

As such we now store a pointer to the Senders Hardware address in the
mbuf packet header so that protocols can perform any required validation.
 1.320  03-Sep-2022  thorpej Garbage-collect the remaining vestiges of netisr.
 1.319  03-Sep-2022  thorpej Convert MPLS from a legacy netisr to pktqueue.
 1.318  03-Sep-2022  thorpej Convert NETATALK from a legacy netisr to pktqueue.
 1.317  03-Sep-2022  thorpej Convert ARP from a legacy netisr to pktqueue.
 1.316  03-Sep-2022  thorpej Only use configured RPS hash functions for IPv4 and IPv6 packets.

This is NFC change now because only IPv4 and IPv6 use pktqueue,
but that will change in future commits.
 1.315  20-Jun-2022  martin Avoid unused variable
 1.314  20-Jun-2022  yamaguchi bpf(4): added support for VLAN hardware offloading of ethernet devices
 1.313  20-Jun-2022  yamaguchi bridge(4): support VLAN frames stripped by hardware tagging
 1.312  20-Jun-2022  yamaguchi Handling frames that vlan id is 0 as non-VLAN frames
even if a vlan tag is stripped by harware offloading
 1.311  04-Apr-2022  yamaguchi Move input processing of lagg(4) before ether_input
to get rid of dependence.

This implementation is similar with that of bridge(4).
 1.310  31-Dec-2021  riastradh ethersubr(9): Assert IFNET_LOCKED in ether_ioctl_reinit.

Changes to if_flags are nontrivial configuration changes that require
the long-term ioctl lock.
 1.309  31-Dec-2021  riastradh sys: Use if_init wrapper function.

Exception: Not in kern_pmf.c, for the kind of silly reason that it
avoids having kern_pmf.c refer to symbols defined only in net; this
avoids a pain in the rump.
 1.308  31-Dec-2021  riastradh sys: Use if_stop wrapper function.

Exception: Not in kern_pmf.c, for the kind of silly reason that it
avoids having kern_pmf.c refer to symbols defined only in net; this
avoids a pain in the rump.
 1.307  10-Dec-2021  msaitoh Add comment to clarify.
 1.306  30-Nov-2021  yamaguchi Move net/agr/ieee8023_slowprotocols.h to net/ether_slowprotocols.h

Definitions related to slowprotocols are duplicated between
agr/ieee8023ad_slowprotocols.h and lagg/if_lagg_lacp.h
Therefore, the contents are moved to added file.

Note: currently, there are just LACP and Marker protocol,
however slowprotocols is independent of them.
 1.305  25-Nov-2021  msaitoh Better counting for ierrors, iqdrops and noproto in ether_input().

- Use if_noproto for unknown or unsupported protocols.
- Use if_ierrors for wrong mbuf or oversized frame.
 1.304  15-Nov-2021  yamaguchi introduced APIs to configure VLAN TAG to ethernet devices
 1.303  08-Nov-2021  christos Don't classify dropped packets that we don't understand as errors, for
example etype 0x88CA (TIPC (Transparent Inter Process Communication,)
or 0x893A (IEEE 1905).
Classify them as dropped like Linux does (FreeBSD just ignores them). From RVP.
 1.302  25-Oct-2021  ryo frame's vlan tag must be ntohs()'ed.
VLAN 0 Priority tag was misrecognized on non vlan-hwtagging interfaces.
 1.301  11-Oct-2021  knakahara Make pktq_rps_hash() pluggable for each interface type. Reviewed by gdt@n.o, thorpej@n.o, and riastradh@n.o, thanks.
 1.300  30-Sep-2021  yamaguchi lagg: Register lagg_ifdetach to ether_ifdetach hook
 1.299  30-Sep-2021  yamaguchi vlan: Register vlan_ifdetach to ether_ifdetach hook
 1.298  30-Sep-2021  yamaguchi bridge: Register bridge_ifdetach to ether_ifdetach hook
 1.297  30-Sep-2021  yamaguchi Provide a hook point called when ether_ifdetach is called
 1.296  30-Sep-2021  yamaguchi net: obsolete ifnet::if_link_state_chenged
that was used for updating link-state of vlan I/F

The obsoleted function is replaced with
ifnet::if_linkstate_hooks
 1.295  30-Sep-2021  yamaguchi vlan: Register the callback to update link-state of vlan I/F
to link-state change hook

The callback is registered in every vlan I/F even if the parent
interface is the same. Therefore it is not needed to search the
vlan I/F by the parent interface unlike the previous callback.
 1.294  30-Sep-2021  yamaguchi Replace ifnet::if_agriprivate with ifnet::if_lagg

agr(4) and lagg(4) can not be used on the same interface so that
if_agrprivate and if_lagg are not used at the same time.
For resolve this wasteful, if_lagg is used in not only lagg(4)
but also agr(4).

After this modification, if_lagg has 3 states:
1. if_lagg == NULL
- Both agr(4) and lagg(4) are not running on the interface
2. if_lagg != NULL && ifp->if_type != IFT_IEEE8023ADLAG
- agr(4) is running on the I/F
3. if_lagg != NULL && ifp->if_type == IFT_IEEE8023ADLAG
- lagg(4) is running on the I/F
 1.293  17-May-2021  yamaguchi Add a new link-aggregation pseudo interface named lagg(4)

- FreeBSD's lagg(4) based implementation
- MP-safe and MP-scalable
 1.292  14-Feb-2021  roy branches: 1.292.4; 1.292.6;
if_ether: revert prior alignment checks

Apparently not needed as our drivers ensure this.
 1.291  13-Feb-2021  roy Prior alignment fixes should not use an offset
 1.290  13-Feb-2021  roy if_ether: Ensure that ether_header is aligned
 1.289  26-Sep-2020  roy branches: 1.289.2;
vlan: match the interface link state with that of the parent

Now addresses on a vlan will detach and undergo duplicate address
dectection on link state changes just as on a standard interface.
 1.288  28-Aug-2020  ozaki-r ether: count dropped packets on output
 1.287  28-Aug-2020  ozaki-r ether: count dropped packets on input
 1.286  28-Aug-2020  ozaki-r ether: separate handling of LLC frames as ether_input_llc (NFCI)
 1.285  28-Aug-2020  ozaki-r net: introduce IFQ_ENQUEUE_ISR to assemble packet queuing routines (NFCI)
 1.284  30-Apr-2020  riastradh Convert ether_input from rnd_initial_entropy to entropy_epoch().
 1.283  15-Mar-2020  thorpej Add and use a new function, mowner_init_owner(), that initializes an
MBUFTRACE mowner structure (so that providers of it don't have to
grovel the internals).
 1.282  29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.281  16-Jan-2020  kardel use the CARP interface for arp/nd instead of the carp parent interface.
this provides the correct source mac address for the packets.

there are routers out there that cache the source mac during
nd and then subsequently bypass/miss packet filters on carp
interfaces as they send to the parent interface mac instead of the
correct carp interface mac.
 1.280  16-Oct-2019  christos branches: 1.280.2;
Add and use __FPTRCAST, requested by uwe@
 1.279  16-Oct-2019  christos Add void * function pointer casts. There are different ways to "fix" those
warnings:
1. this one: add a void * cast (which I think is the least intrusive)
2. add pragmas to elide the warning
3. add intermediate inline conversion functions
4. change the called function prototypes, adding unused arguments and
converting some of the pointer arguments to void *.
5. make the functions varyadic (which defeats the purpose of checking)
6. pass command line flags to elide the warning
I did try 3 and 4 and I was not pleased with the result (sys_ptrace_common.c)
(3) added too much code and defines, and (4) made the regular use clumsy.
 1.278  02-Oct-2019  msaitoh Print oversized frame's message only when DIAGNOSTIC is set. The message
is not so important because we increment if_iqdrops now.
 1.277  01-Oct-2019  msaitoh Increment if_iqdrops when dropping an oversized frame.
 1.276  17-Jul-2019  msaitoh branches: 1.276.2;
Implement VLAN hardware filter function(ETHERCAP_VLAN_HWFILTER).
First proposed by jmcneill in 2017 and modified by me.

How to use:

- Set callback function:

ether_set_vlan_cb(struct ethercom *, ether_vlancb_t)

- Callback. This function is called when a vlan is attached/detached to the
parent interface:

int (*ether_vlancb_t)(struct ethercom *ec, uint16_t vlanid, bool set);

- ifconfig(8)

ifconfig ixg0 [-]vlan-hwfilter

Note that ETHERCAP_VLAN_HWFILTER is set by default on ixg(4) because
the PF driver usually enable "all block" filter by default.
 1.275  29-May-2019  msaitoh Even if we don't use MII(4), use the common path of SIOC[GS]IFMEDIA in
sys/net/if_ethersubr.c if we can.
- Add ec_ifmedia into struct ethercom.
- ec_mii in struct ethercom is kept and used as it is. It might be used in
future. Note that some Ethernet drivers which _DOESN'T_ use mii(4) use
ec_mii for keeping the if_media. Those should be changed in future.
 1.274  15-May-2019  ozaki-r Store IFF_ALLMULTI in ec_flags instead of if_flags to avoid data races

IFF_ALLMULTI is set/unset to if_flags via if_mcast_op. To avoid data races on
if_flags, IFNET_LOCK was added for if_mcast_op. Unfortunately it produces
a deadlock so we want to remove added IFNET_LOCK by avoiding the data races by
another approach.

This fix introduces ec_flags to struct ethercom and stores IFF_ALLMULTI to it.
ec_flags is protected by ETHER_LOCK and thus IFNET_LOCK is no longer necessary
for if_mcast_op. Note that the fix is applied only to MP-safe drivers that
the data races matter.

In the kernel, IFF_ALLMULTI is set by a driver and used by the driver itself.
So changing the storing place doesn't break anything. One exception is
ioctl(SIOCGIFFLAGS); we have to include IFF_ALLMULTI in a result if needed to
export the flag as well as before.

A upcoming commit will remove IFNET_LOCK.

PR kern/54189
 1.273  04-Feb-2019  mrg add or adjust fallthru comments.
 1.272  21-Dec-2018  msaitoh Add SIOCSETHERCAP. It's used to change ec_capenable.
 1.271  15-Nov-2018  maxv Remove the 't' argument from m_tag_find().
 1.270  14-Jun-2018  yamaguchi branches: 1.270.2;
Use ether_lookup_multi() instead of the macro

ok ozaki-r@
 1.269  12-Jun-2018  ozaki-r Check if ether_ifdetach is called without INET_LOCK
 1.268  29-May-2018  maxv Remove an XXX of mine, actually it's fine. While here also remove a
misleading printf.
 1.267  29-May-2018  maxv Replace KASSERT by m_pullup. While the ethernet header is always there
when the packet was received on a physical interface, it may not be if
the packet was received over L2TP/EtherIP.

In particular, if the inner ethernet header ends up on two separate IP
fragments. Here the KASSERT is triggered, and on !DIAGNOSTIC we corrupt
memory.

Note that this is a widespread problem: a lot of L2 code was written with
the assumption that "most" headers are present in the first mbuf.
Obviously, that's not true if L2 encapsulation is being used.
 1.266  09-May-2018  maxv Replace
m_copym(m, 0, M_COPYALL, M_DONTWAIT)
by
m_copypacket(m, M_DONTWAIT)
when it is clear that we are copying a packet (that has M_PKTHDR) and not
a raw mbuf chain.
 1.265  29-Apr-2018  maxv Remove references to m_copy in comments.
 1.264  26-Apr-2018  maxv m_copy -> m_copym
 1.263  09-Apr-2018  maxv Replace KASSERTMSG by a real check. L2 encapsulation protocols (at least
L2TP) don't ensure the LLC is there, and in !DIAGNOSTIC configurations
m_copydata will crash. Tested with L2TP.
 1.262  09-Apr-2018  maxv Add KASSERT. The input point expects struct ether_header to be there.

Now, I'm wondering whether it can be triggered by L2 encapsulation
protocols - they may not provide a contiguous area.
 1.261  09-Apr-2018  maxv Minor stylistic changes, add XXX and fix typo. No functional change.
 1.260  13-Feb-2018  maxv branches: 1.260.2;
Make the arpresolve branch more readable, fix typo, fix XXX (which I
added), add missing pserialize_read_exit (which I forgot).
 1.259  13-Feb-2018  maxv Remove KERNEL_LOCK around the MPLS code. It's not needed, since we're only
touching the tag of the mbuf - the tag belongs only to the mbuf, and the
mbuf is not shared.

ok knakahara@
 1.258  12-Feb-2018  maxv Fix typo, and add a comment about MPLS.
 1.257  19-Jan-2018  nakayama Fix inverted logic.
 1.256  15-Jan-2018  maxv Style, and fix a bug in the AppleTalk path: we're doing
M_PREPEND(M_DONTWAIT), but we forgot to NULL-check the mbuf afterwards.
 1.255  15-Jan-2018  maxv Fix two bugs in altq_etherclassify. When scanning the mbuf chain we need
to make sure that m_next is not NULL, otherwise NULL deref. After that,
we must not touch m->m_pkthdr, given that 'm' may not be the first mbuf
of the chain anymore.

Declare mtop, and add a KASSERT to make sure it has M_PKTHDR set.
 1.254  15-Jan-2018  maxv Fix a bug in the VLAN path: there's an inverted logic, the mbuf needs to
be bigger than struct ether_vlan_header, not smaller.

Meanwhile add a KASSERT in the LLC path.
 1.253  15-Jan-2018  maxv Style, make the code more readable, and add a KASSERT (we expect the mbuf
to have M_PKTHDR set).
 1.252  15-Jan-2018  maxv Several fixes:
- Style and typos
- Use kmem_zalloc, in case there is a padding between the fields of
the structures
- Use ETHER_ADDR_LEN instead of a hard-coded '6'
- kmem_alloc(KM_SLEEP) can't fail
- Simplify ether_aton_r
- Use mutex_obj_free, not to leak memory
 1.251  15-Jan-2018  maxv Fix the net.ether.multicast sysctl. If there is no multicast address
don't kmem_alloc(0) (which panics the kernel), and if the number of
multicast addresses has decreased don't copyout uninitialized kernel
data.
 1.250  09-Dec-2017  maxv style
 1.249  09-Dec-2017  maxv Make sure we have an llc structure in the packet, and don't read past the
end of the mbuf if we don't. I'm wondering whether we should not pull up
instead, but whatever.
 1.248  06-Dec-2017  ozaki-r Use kmem_alloc instead of kmem_intr_alloc in ether_addmulti

ether_addmulti is now not called in softint thanks to wqinput that
pulled input routines of ICMP out of softint.
 1.247  22-Nov-2017  msaitoh - Modify ether_ioctl() for readability. No functional change.
- KNF
 1.246  16-Nov-2017  ozaki-r Unify IFEF_*_MPSAFE into IFEF_MPSAFE

There are already two flags for if_output and if_start, however, it seems such
MPSAFE flags are eventually needed for all if_XXX operations. Having discrete
flags for each operation is wasteful of if_extflags bits. So let's unify
the flags into one: IFEF_MPSAFE.

Fortunately IFEF_*_MPSAFE flags have never been included in any releases, so
we can change them without breaking backward compatibility of the releases
(though the kernel version of -current should be bumped).

Note that if an interface have both MP-safe and non-MP-safe operations at a
time, we have to set the IFEF_MPSAFE flag and let callees of non-MP-safe
opeartions take the kernel lock.

Proposed on tech-kern@ and tech-net@
 1.245  26-Oct-2017  msaitoh Use macro(ETHER_LOCK() and ETHER_UNLOCK()). No functional change.
 1.244  26-Sep-2017  knakahara VLAN ID uses pkthdr instead of mtag now. Contributed by s-yamaguchi@IIJ.

I just commit by proxy. Reviewed by joerg@n.o and christos@n.o, thanks.
See http://mail-index.netbsd.org/tech-net/2017/09/26/msg006459.html

XXX need pullup to -8 branch
 1.243  23-Jul-2017  para kmem_intr_free kmem_intr_[z]alloced memory

the underlying pools are the same but api-wise those should match
 1.242  06-Apr-2017  ozaki-r branches: 1.242.6;
Revert "Make sure to hold if_ioctl_lock when calling ifp->if_ioctl"

As per pgoyette@ and riastradh@ requests; we shouldn't decide to
hold a lock based on if the lock is held or not.
 1.241  05-Apr-2017  ozaki-r Make sure to hold if_ioctl_lock when calling ifp->if_ioctl

Unfortunately callers of ifp->if_ioctl (if_addr_init, if_flags_set
and if_mcast_op) may or may not hold if_ioctl_lock, so we have to
hold the lock only if it's not held.
 1.240  24-Mar-2017  ozaki-r Remove KERNEL_LOCK for arpresolve in ether_output

Because arpresolve should be already MP-safe.
 1.239  21-Feb-2017  ozaki-r Sweep unnecessary malloc.h inclusions
 1.238  14-Feb-2017  ozaki-r Do ND in L2_output in the same manner as arpresolve

The benefits of this change are:
- The flow is consistent with IPv4 (and FreeBSD and OpenBSD)
- old: ip6_output => nd6_output (do ND if needed) => L2_output (lookup a stored cache)
- new: ip6_output => L2_output (lookup a cache. Do ND if cache not found)
- We can remove some workarounds in nd6_output
- We can move L2 specific operations to their own place
- The performance slightly improves because one cache lookup is reduced
 1.237  12-Feb-2017  skrll Remove redundant splnet/splx calls - ec_lock is IPL_NET.
 1.236  24-Jan-2017  maxv Don't forget to free the mbuf when we decide not to reply to an ARP
request. This obviously is a terrible bug, since it allows a remote sender
to DoS the system with specially-crafted requests sent in a loop.
 1.235  13-Jan-2017  msaitoh branches: 1.235.2;
Fix a bug that the parent interface's callback wasn't called when the vlan
interface is configured. A callback function uses VLAN_ATTACHED() function
which check ec->ec_nvlans, the value should be incremented before calling the
callback. This bug was added in if_vlan.c rev. 1.83 (2015/11/19).
 1.234  10-Jan-2017  ozaki-r Enable some sysctl knobs on rump kernels for ifmcstat
 1.233  10-Jan-2017  ozaki-r Replace adaptive mutex for ethercom with spin one

Unfortunately even wm(4) doesn't allow adaptive mutex because wm(4)
tries to hold it with holding its own spin mutex.
 1.232  31-Dec-2016  ozaki-r Use kmem_intr_alloc instead of kmem_alloc

ether_addmulti still can be called in softint.

Fix PR kern/51755
 1.231  28-Dec-2016  ozaki-r Protect ec_multi* with mutex

The data can be accessed from sysctl, ioctl, interface watchdog
(if_slowtimo) and interrupt handlers. We need to protect the data against
parallel accesses from them.

Currently the mutex is applied to some drivers, we need to apply it to all
drivers in the future.

Note that the mutex is adaptive one for ease of implementation but some
drivers access the data in interrupt context so we cannot apply the mutex
to every drivers as is. We have two options: one is to replace the mutex
with a spin one, which requires some additional works (see
ether_multicast_sysctl), and the other is to modify the drivers to access
the data not in interrupt context somehow.
 1.230  28-Dec-2016  ozaki-r Use ether_ifattach in carp_clone_create instead of C&P code

carp_clone_destroy calls ether_ifdetach so not calling ether_ifattach is
inconsistent. If we add something pair of initialization and destruction
to ether_ifattach and ether_ifdetach (e.g., mutex_init/mutex_destroy),
ether_ifdetach of carp_clone_destroy won't work. So use ether_ifattach.

In order to do so, make ether_ifattach accept the 2nd argument (lla) as
NULL to allow carp to initialize its link level address by itself.
 1.229  18-Oct-2016  ozaki-r Don't hold global locks if NET_MPSAFE is enabled

If NET_MPSAFE is enabled, don't hold KERNEL_LOCK and softnet_lock in
part of the network stack such as IP forwarding paths. The aim of the
change is to make it easy to test the network stack without the locks
and reduce our local diffs.

By default (i.e., if NET_MPSAFE isn't enabled), the locks are held
as they used to be.

Reviewed by knakahara@
 1.228  03-Oct-2016  ozaki-r Fix race condition on ifqueue used by traditional netisr

If a underlying network device driver supports MSI/MSI-X, RX interrupts
can be delivered to arbitrary CPUs. This means that Layer 2 subroutines
such as ether_input (softint) and subsequent Layer 3 subroutines (softint)
which are called via traditional netisr can be dispatched on an arbitrary
CPU. Layer 2 subroutines now run without any locks (expected) and so a
Layer 2 subroutine and a Layer 3 subroutine can run in parallel.

There is a shared data between a Layer 2 routine and a Layer 3 routine,
that is ifqueue and IF_ENQUEUE (from L2) and IF_DEQUEUE (from L3) on it
are racy now.

To fix the race condition, use ifqueue#ifq_lock to protect ifqueue
instead of splnet that is meaningless now.

The same race condition exists in route_intr. Fix it as well.

Reviewed by knakahara@
 1.227  01-Aug-2016  ozaki-r Apply pserialize and psref to struct ifaddr and its variants

This change makes struct ifaddr and its variants (in_ifaddr and in6_ifaddr)
MP-safe by using pserialize and psref. At this moment, pserialize_perform
and psref_target_destroy are disabled because (1) we don't need them
because of softnet_lock (2) they cause a deadlock because of softnet_lock.
So we'll enable them when we remove softnet_lock in the future.
 1.226  25-Jul-2016  rjs Restore correct test for return value from aarpresolve().
 1.225  21-Jun-2016  knakahara branches: 1.225.2;
fix ATF net/carp failure
 1.224  20-Jun-2016  knakahara make ether_output() MP-safe, so that if_ether can enable IFEF_OUTPUT_MPSAFE.

making MP-scalable is future work.
 1.223  16-Jun-2016  ozaki-r Use if_get_byindex instead of if_byindex for MP-safe
 1.222  28-Apr-2016  ozaki-r Constify rtentry of if_output

We no longer need to change rtentry below if_output.

The change makes it clear where rtentries are changed (or not)
and helps forthcoming locking (os psrefing) rtentries.
 1.221  20-Apr-2016  knakahara IFQ_ENQUEUE refactor (3/3) : eliminate pktattr argument from IFQ_ENQUEUE caller
 1.220  20-Apr-2016  knakahara IFQ_ENQUEUE refactor (2/3) : eliminate pktattr argument from altq implemantation
 1.219  20-Apr-2016  knakahara IFQ_ENQUEUE refactor (1/3) : add altq_pktattr fields to m_pkthdr

Reviewed by joerg@n.o and tls@n.o, thanks.
 1.218  15-Apr-2016  ozaki-r Hide PPPoE variables from if_ethersubr.c

This improves modularity of if_pppoe.

From s-yamaguchi@IIJ
 1.217  07-Apr-2016  christos - tidy up error messages
- add a length argument to arpresolve()
- add KASSERT for overflow
 1.216  09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.215  19-Nov-2015  christos Add handling of VLAN packets in if_bridge where the parent interface supports
them (Jean-Jacques.Puig@espci.fr). Factor out the vlan_mtu enabling and
disabling code.
 1.214  13-Oct-2015  roy arpresolve() now returns 0 on success otherwise an error code.
Callers of arpresolve() now pass the error code back to their caller,
masking out EWOULDBLOCK.

This allows applications such as ping(8) to display a suitable error
condition.
 1.213  31-Aug-2015  ozaki-r Replace ARP cache (llinfo) with lltable/llentry

Highlights of the change are:
- Use llentry instead of llinfo to manage ARP caches
- ARP specific data are stored in the hashed list
of an interface instead of the global list (llinfo_arp)
- Fine-grain locking on llentry
- arptimer (callout) per ARP cache
- the global timer callout with the big locks can be
removed (though softnet_lock is still required for now)
- net.inet.arp.prune is now obsoleted
- it was the interval of the global timer callout
- net.inet.arp.refresh is now obsoleted
- it was a parameter that prevents expiration of active caches
- Removed to simplify the timer logic, but we may be able to
restore the feature if really needed

Proposed on tech-kern and tech-net.
 1.212  24-Aug-2015  pooka sprinkle _KERNEL_OPT
 1.211  12-Aug-2015  ozaki-r Tidy up header inclusions
 1.210  04-Jun-2015  ozaki-r Pull out route lookups from L2 output routines

Route lookups for routes of RTF_GATEWAY were done in L2 output
routines such as ether_output, but they should be done in L3
i.e., before L2 output routines. This change places the lookups
between L3 output routines (say ip_output) and the L2 output
routines.

The change is based on dyoung's patch submitted in the thread:
https://mail-index.netbsd.org/tech-net/2013/02/01/msg003847.html
You can find out detailed investigations by dyoung about the
issue in there.

Note that the change introduces a workaround for MPLS. ether_output
knew that it needs to fill the ethertype of a frame as MPLS,
based on a tag of an original route (rtentry), but now we don't
pass it to ehter_output. So we have to tell that in another way.
We use mtag to do so for now, which introduces some overhead.
We should fix it somehow in the future.

Discussed on tech-kern and tech-net.
 1.209  25-May-2015  ozaki-r Remove leftover IPX-related stuffs

No objection on tech-kern and tech-net.
 1.208  20-May-2015  ozaki-r Remove leftover use of AF_NS and NS option

Unnecessary NETISR_NS is also removed.
 1.207  13-Apr-2015  riastradh Include <sys/rndsource.h> for rnd_add_data.
 1.206  03-Apr-2015  ozaki-r Don't grab KERNEL_LOCK during if_output when NET_MPSAFE

The change makes L3 MP-safe work easy. At this point
we deal with only IP forwarding.

No functional change when NET_MPSAFE isn't enabled.
 1.205  28-Nov-2014  ozaki-r branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.
 1.204  10-Aug-2014  tls branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.
 1.203  28-Jul-2014  ozaki-r Add a mutex for global variables of if_ethersubr.c

To initialize the mutex, we introduce etherinit that is called from ifinit1.
 1.202  30-Jun-2014  ozaki-r Schedule pppoe_softintr only when a packet is enqueued
 1.201  17-Jun-2014  ozaki-r Restructure ether_input and bridge_input

The network stack of NetBSD is well organized and
layered. A packet reception is processed from a
lower layer to an upper layer one by one. However,
ether_input and bridge_input are not structured so.
bridge_input is called inside ether_input.

The new structure replaces ifnet#if_input of a bridge
member with bridge_input when the member is attached.
So a packet goes straight on a packet reception via
a bridge, bridge_input => ether_input => ip_input.

The change is part of a patch of Lloyd Parkes submitted
in PR 48104. Unlike the patch, the change doesn't
intend to change the behavior of the packet processing.
Another patch will fix PR 48104.
 1.200  10-Jun-2014  joerg Introduce new sysctls for obtaining interface-specific addresses:
- net.sdl for the active link-layer adddress (the MAC)
- net.ether.multicast for the Ethernet multicast addresses
- net.inet6.multicast for the IPv6 multicast groups
- net.inet6.multicast_kludge for temporarily removed multicast groups

Use this sysctls for replacing the kmem grovelling in ifmcstat(8).
 1.199  05-Jun-2014  rmind - Implement pktqueue interface for lockless IP input queue.
- Replace ipintrq and ip6intrq with the pktqueue mechanism.
- Eliminate kernel-lock from ipintr() and ip6intr().
- Some preparation work to push softnet_lock out of ipintr().

Discussed on tech-net.
 1.198  15-May-2014  msaitoh Usually schednetisr() is called after enqueueing a packet with IF_ENQUEUE().
In some functions, they do it in reverse order. It's not a bug because
the pair is protected with splnet()/splx(s). It's not good for readability
and someone might mistake when modifing a code. Yes, I'm one of the person :-(

Save a NETISR_* value in a variable and call schednetisr() after enqueue
a packet for readability and future modification.
 1.197  13-May-2014  bouyer Make sure *(if_output)() is called with KERNEL_LOCK held.
Add some KASSERT for this.
See http://mail-index.netbsd.org/tech-net/2014/04/09/msg004511.html
for details.
 1.196  25-Feb-2014  pooka branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.
 1.195  29-Jun-2013  rmind - Rewrite parts of pfil(9): use array to store hooks and thus be more cache
friendly (there are only few hooks in the system). Make the structures
opaque and the interface more strict.
- Remove PFIL_HOOKS option by making pfil(9) mandatory.
 1.194  01-Mar-2013  joerg branches: 1.194.6;
Retire OSI network stack. OK core@
 1.193  31-Oct-2012  msaitoh Add SIOCGETHERCAP ioctl.
There was no way to know the setting of ec_capabilities and ec_capenable
other than grepping the source.

See http://mail-index.netbsd.org/tech-kern/2010/07/28/msg008613.html
 1.192  11-Oct-2012  christos PR/47058: Antti Kantee: If the ipv6 flow code modifies the mbuf, pass the
change up to the caller.
 1.191  05-Oct-2012  matt When setting a link address, don't bring up the interface automatically.
 1.190  17-Jul-2012  christos branches: 1.190.2;
PR/46587: Roger Pau Monne: Prevent panic on shutdown on bridge teardown ->
ifpromisc-> if_ioctl -> if_init. Idea from dyoung.
XXX: Pullup to 6.
 1.189  11-May-2012  chs in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.
 1.188  16-Jun-2011  kefren branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)
 1.187  24-May-2011  matt branches: 1.187.2;
Add code to auto-deencapsulate 0 tagged VLANs.
 1.186  25-Apr-2011  yamt use ETHER_IS_MULTICAST macro. no functional changes.
 1.185  12-Jan-2011  tsutsui branches: 1.185.2;
Fix off by one in ether_aton_r(). Noticed by "arp info overwritten" warning.
(how could it be missed for months?)
 1.184  17-Nov-2010  dyoung Cosmetic: fix indentation.
 1.183  27-Jun-2010  kefren Don't assume that rt_tag family is AF_MPLS but verify it.
This way rt_tag can be used for other future work also, not only MPLS
 1.182  26-Jun-2010  kefren Add MPLS support, proposed on tech-net@ a couple of days ago

Welcome to 5.99.33
 1.181  19-May-2010  christos delint previous
 1.180  19-May-2010  christos Replace ether_nonstatic_aton with a
- better named one
- not suffering from buffer oveflow
- simpler
- handling different separators
- returning error codes for errors

Some ideas from one posted on tech-net by Jonathan A. Kollasch
 1.179  19-May-2010  jakllsch Changes to ether_nonstatic_aton():

Be more leinent on input string format. Each nibble pair may optionally be
followed by any of ':', '-', '.' or ' '.

Make source string const and work on a temporary copy. The caller may not
expect their string to be destroyed.
 1.178  05-May-2010  dyoung Constify some ether_output() arguments so that it's clear that they
can never be re-assigned.
 1.177  05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.176  19-Jan-2010  pooka branches: 1.176.2; 1.176.4;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.175  28-Nov-2009  mbalmer Fix function name that was changed by mistake in the previous whitespace
commit.
 1.174  28-Nov-2009  isaki white space -> tab.
 1.173  20-Nov-2009  christos ar_tha() can return NULL; treat this as an error.
 1.172  29-May-2009  darran Add vlan support and hardware offload capabilities to agr.
These changes allow vlans to be layered above agr, with the attach
and detach propogated to the member ports in the aggregation.
Note the agr interface must be up before the vlan is attached.

Adds SIOCINITIFADDR support to the wm driver for setting the AF_LINK
address, necessary for agr to be able to set the mac addresses of each
port to the agr address (i.e. so it can receive all intended traffic
at the hardware level).

Adds support for disabling the LACP protocol by setting LINK1 on the agr
interface (e.g. ifconfig agr0 link1).

In consultation with tls@.
 1.171  28-Apr-2009  dyoung Let this build with 'no options INET'.

(I don't know why I bothered, either.)
 1.170  07-Nov-2008  dyoung branches: 1.170.4;
*** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.169  23-Jul-2008  dyoung branches: 1.169.2; 1.169.4; 1.169.6; 1.169.8;
Fix this another way: add the missing case statement.
 1.168  23-Jul-2008  gmcgarry Back out rev 1.163 which broke the logic for SIOCSIFFLAGS. PR#38976.
 1.167  13-May-2008  dyoung branches: 1.167.2; 1.167.4;
Delete unreachable SIOCSIFADDR/AF_LINK case.
 1.166  11-May-2008  dyoung Where applicable, s/0/NULL/, s/Bcmp/memcmp/. Remove a gratuitous
cast from a call to nd6_storelladdr().
 1.165  09-May-2008  rumble Nix a tautological return introduced in 1.129.
 1.164  15-Mar-2008  matt branches: 1.164.2; 1.164.4; 1.164.6;
Make sure M_PROMISC isn't already set, before we need to see if we are going
to see if we need to set M_PROMISC.
Assume the interface is not CARP'ed.
 1.163  12-Mar-2008  dyoung Make some cosmetic changes:

Use fewer 'error = ...; break;' statements and more 'return
...;'

Make the SIOCSIFFLAGS case more clear by using a switch
statement instead of an if-else if-else chain.

Shorten a staircase, and remove two unnecessary curly
braces.
 1.162  20-Feb-2008  matt branches: 1.162.2; 1.162.6;
s/u_\(int[0-9]*_t\)/u\1/g
(change u_int*_t to uint*_t)
 1.161  07-Feb-2008  dyoung Start patching up the kernel so that a network driver always has
the opportunity to handle an ioctl before generic ifioctl handling
occurs. This will ease extending the kernel and sharing of code
between drivers.

First steps: Make the signature of ifioctl_common() match struct
ifinet->if_ioctl. Convert SIOCSIFCAP and SIOCSIFMTU to the new
ifioctl() regime, throughout the kernel.
 1.160  19-Jan-2008  dyoung Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.
 1.159  02-Jan-2008  dyoung Fix XEN2_DOMU (and amd64?) builds: move ether_mediastatus(),
ether_mediachange() to their own module that we compile only if
the kernel configuration demands support for both MII buses and
ethernet. Thanks to Tom Spindler for suggesting that these routines
move to dev/mii/.
 1.158  31-Dec-2007  dyoung Add media-handling code for several ethernet drivers with MII buses
to share.
 1.157  20-Dec-2007  dyoung Constify struct ifnet->if_sadl and every use throughout the tree.
Add if_set_sadl() that both sets the link-layer address length and
replaces the current link-layer address with a new one, and use it
throughout the tree.
 1.156  08-Oct-2007  ad branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.
 1.155  19-Sep-2007  dyoung branches: 1.155.2;
Constify sockaddr argument to ether_multiaddr(). Change struct
ifreq * arguments to ether_addmulti() and ether_delmulti() to const
struct sockaddr *, since ether_{add,del}multi() only ever read the
sockaddr ifreq member, ifr_addr. Update uses in carp(4) and in
vlan(4).
 1.154  30-Aug-2007  dyoung Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.

Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.

Avoid using sizeof(struct sockaddr_dl) in the kernel.

Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.

Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().

Constify: LLADDR() -> CLLADDR().

Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
 1.153  26-Aug-2007  dyoung branches: 1.153.2;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).

Use sockaddr_dl_setaddr() in a few places.
 1.152  07-Aug-2007  dyoung branches: 1.152.2;
Constify.
 1.151  21-Jul-2007  dyoung branches: 1.151.4;
Use NULL instead of 0 for null pointers.
 1.150  14-Jul-2007  ad branches: 1.150.2;
Generic soft interrupts are mandatory.
 1.149  29-May-2007  christos Add a sockaddr_storage member to "struct ifreq" maintaining backwards
compatibility with the older ioctls. This avoids stack smashing and
abuse of "struct sockaddr" when ioctls placed "struct sockaddr_foo's" that
were longer than "struct sockaddr".
XXX: Some of the emulations might be broken; I tried to add code for
them but I did not test them.
 1.148  07-Mar-2007  liamjfoy branches: 1.148.2; 1.148.4;
Add IPv6 Fast Forward - the IPv4 counterpart:

If ip6_forward successfully forwards a packet, a cache, in this case a
ip6flow struct entry, will be created. ether_input and friends will
then be able to call ip6flow_fastforward with the packet which will then
be passed to if_output (unless an issue is found - in that case the packet
is passed back to ip6_input).

ok matt@ christos@ dyoung@ and joerg@
 1.147  04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.146  20-Feb-2007  dyoung Remove extraneous parentheses. bcopy -> memcpy.
 1.145  17-Feb-2007  dyoung KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.

Cosmetic: don't open-code TAILQ_FOREACH().

Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.

Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.

Constify:

1 Introduce const accessor for route->ro_dst, rtcache_getdst().

2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.

3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.

4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
 1.144  29-Jan-2007  bouyer branches: 1.144.2;
Drop M_PROMISC before passing the packet to a carp device, for the same
reason it's dropped before passing to bridge: when a vlan interface is
in promisc mode, it will loop the packet back to ether_input() with
M_PROMISC set, and when carp calls ether_input again the flag is still
there and the packet is dropped. If the carp interface doesn't take
the packet M_PROMISC is set just after is needed anyway.
Tested on a box with multiple carp on vlans, no comments about this patch
on tech-net@
 1.143  27-Jan-2007  cbiere Use a plain memcpy() instead of alignment- and endian-specific hacks.
 1.142  06-Jan-2007  bouyer Don't define dropanyway: label unless ISO or NETATALK is defined. Fix
kern/35364 by Gene ENonymous
 1.141  10-Dec-2006  is explain XID constants, and fix a wrong one
 1.140  10-Dec-2006  is comment on llc class
 1.139  01-Dec-2006  is branches: 1.139.2;
Remove an overlapping struct copy from ether_input, which caused address
corruption for incoming netiso packets with recent (at least NetBSD-3 and
later) compilers. This is done in a way that the copy is avoided totally.
Code path tested with tcp+udp/ipv4+ipv6, arp and ISO cltp/clnp.
Visually ok'd by Christos@.
 1.138  24-Nov-2006  rpaulo The change I committed to etherip was wrong. ether_snprintf doesn't make
sense when chaning the MAC address of the virtual interface as pointed
out by Hans himself.
So, introduce ether_nonstatic_aton() and make etherip(4) and tap(4) use it.
 1.137  23-Nov-2006  rpaulo New EtherIP driver based on tap(4) and gif(4) by Hans Rosenfeld.
Notable changes:
* Fixes PR 34268.
* Separates the code from gif(4) (which is more cleaner).
* Allows the usage of STP (Spanning Tree Protocol).
* Removed EtherIP implementation from gif(4)/tap(4).

Some input from Christos.
 1.136  07-Sep-2006  dogcow branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.135  05-Aug-2006  pavel defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.
 1.134  07-Jun-2006  kardel merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html
 1.133  18-May-2006  liamjfoy branches: 1.133.2;
Integrate Common Address Redundancy Procotol (CARP) from OpenBSD

'pseudo-device carp'

Thanks to: joerg@ christos@ riz@ and others who tested
Ok: core@
 1.132  14-May-2006  elad integrate kauth.
 1.131  12-May-2006  mrg since ar_tha() can return NULL, don't pass it directly to functions
that expect real addresses. explicitly KASSERT() that it is not
NULL in the kernel and just avoid using it userland.

(the kernel could be more defensive about this, but, until now it
would have just crashed anyway.)
 1.130  15-Apr-2006  christos Coverity CID 1145: Protect against NULL deref.
 1.129  16-Mar-2006  christos branches: 1.129.2;
Add a new function called ether_snprintf() which takes an external buffer
and a length. The buffer should be 3 * addrlen.
Remove local tap_ether_sprintf(), and use ether_snprintf() instead.
 1.128  11-Dec-2005  thorpej branches: 1.128.4; 1.128.6; 1.128.8; 1.128.10;
ANSI function decls and application of static.
 1.127  11-Dec-2005  christos merge ktrace-lwp.
 1.126  10-Jun-2005  bouyer branches: 1.126.2;
As ether_input() is always called at IPL_NET, there is no need to
protect the IF_* operations with splnet()/splx().
 1.125  29-May-2005  christos - sprinkle const
- remove unneeded casts
- use more mem*() instead of b*() funcs.
 1.124  17-May-2005  christos Yes, it was a cool trick >20 years ago to use "0123456789abcdef"[a] to
implement, xtoa(), but I think defining the samestring 50 times is a bit
too much. Defined HEXDIGITS and hexdigits in subr_prf.c and use it...
 1.123  02-May-2005  matt rate limit the printfs for oversized ethernet packets.
 1.122  31-Mar-2005  christos factor out the interface queueing code into two functions. One used by
the non point-to-point interfaces that has one queue, and one used by
the point to point interfaces that has two queues. No functional changes.
XXX: The ALTQ stuff makes the code ugly.
XXX: More cleanup to come
 1.121  18-Mar-2005  yamt add agr(4), a pseudo network device driver for link aggregation.
 1.120  26-Feb-2005  perry branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace
 1.119  31-Jan-2005  kim Add RFC 3378 EtherIP support, ported from OpenBSD to NetBSD by
Hans Rosenfeld (rosenfeld at grumpf.hope-2000.org)

This change makes it possible to add gif interfaces to bridges, which
will then send and receive IP protocol 97 packets. Packets are Ethernet
frames with an EtherIP header prepended.
 1.118  08-Jan-2005  yamt branches: 1.118.2; 1.118.4;
constify broadcastaddr.
 1.117  08-Jan-2005  yamt remove an unused member, enm_ec from ether_multi.
 1.116  24-Jun-2004  jonathan Rename MBUFTRACE helper function m_claim() to m_claimm(),
for consistency with M_FREE() and m_freem(). Affected files:

sys/mbuf.h
kern/uipc_socket2.c
kern/uipc_mbuf.c
net/if_ethersubr.c
netatalk/ddp_input.c
nfs/nfs_socket.c
 1.115  06-Jun-2004  dyoung Resolve kern/25721 by detaching ethernet(-like) devices from a
bridge in ether_ifdetach.
 1.114  30-Oct-2003  simonb branches: 1.114.2;
Remove some assigned-to but otherwise unused variables.
 1.113  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.112  23-Jun-2003  martin branches: 1.112.2;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.111  11-Jun-2003  martin Add NETATALK to the list to check if we bail because no ARP is configured.
 1.110  11-Jun-2003  martin Fix typpo in #error message. Noted by Pawel Chwalowski in PR 21853.
 1.109  23-May-2003  itojun don't call if_free_sadl() until very end of if_detach() logic. many of
routing table manipulation code assumes the presense of AF_LINK sockaddr.
should fix PR 21581
 1.108  16-May-2003  itojun use strlcpy
 1.107  02-May-2003  itojun KNF
 1.106  25-Mar-2003  bouyer Make promiscous mode work on vlans: introduce a new link-layer m_flag
M_PROMISC. In ether_input(), flag packets comming from an interface in
promiscous mode which are not for us M_PROMISC instead of droping them.
Drop M_PROMISC packets which are not passed to vlan_input(). M_PROMISC
packets passed to vlan_input() will be looped back to ether_input()
the M_PROMISC flag will be handled appropriately.
Clear M_PROMISC before giving the packet to bridge, as bridge has its own
checks for local MAC addresses.
This also makes bridges on vlan working.
 1.105  02-Mar-2003  aymeric ignore multicast PPPoE packets ASAP.
This improves performance a lot on slow machines behind a cable modem.
Protect it with PPPOE_SERVER as a reminder that this will have to be changed
if we add PPPoE server code in the kernel one day.
 1.104  26-Feb-2003  matt Add MBUFTRACE kernel option.
Do a little mbuf rework while here. Change all uses of MGET*(*, M_WAIT, *)
to m_get*(M_WAIT, *). These are not performance critical and making them
call m_get saves considerable space. Add m_clget analogue of MCLGET and
make corresponding change for M_WAIT uses.
Modify netinet, gem, fxp, tulip, nfs to support MBUFTRACE.
Begin to change netstat to use sysctl.
 1.103  03-Feb-2003  thorpej Test callout_pending(), not callout_active(), and eliminate now-unnecessary
callout_deactivate() calls.
 1.102  22-Jan-2003  jmmv Fix typo: realy -> really. Okay'ed by wiz.
 1.101  17-Jan-2003  itojun switch from kame-based m_aux mbuf auxiliary data, to openbsd m_tag
implementation. it will simplify porting across *bsd (such as kame/altq),
and make us more synchronized. from Joel Wilsson
 1.100  12-Jan-2003  jdolecek Ethernet multicast entries are malloc'd M_IFMADDR, and thus should
be freed as M_IFMADDR too.
Fix supplied in PR kern/19037 by Sean Boudreau
 1.99  11-Sep-2002  itojun KNF - return is not a function.
 1.98  26-Aug-2002  thorpej Fix some signed/unsigned comparison warnings from GCC 3.3.
 1.97  20-Aug-2002  kristerw Make it compile for the __NO_STRICT_ALIGNMENT case.
 1.96  19-Aug-2002  thorpej In ether_output(), don't bother calling memcpy() to plop the ethertype
into the packet: On system with no strict alignment constraints, just
assign the value, and on others, do an inline 2 byte copy.
 1.95  18-May-2002  itojun branches: 1.95.2;
sync with KAME.
- make altq_etherclassify() able to handle packets whose ethernet header
is in a separate mbuf. closes netbsd PR 16559
 1.94  27-Apr-2002  enami branches: 1.94.2;
Use ETHER_HDR_LEN instead of 14.
 1.93  07-Apr-2002  martin XXX Explicitly make this fail to compile with a proper warning if we
do not have ARP configured.

This can be caused by configurations including bridge, ppppoe or vlan but
no ethernet interfaces - which does not make sense. We should add a way
to config(8) to issue this kind of warnings.
 1.92  05-Mar-2002  itojun bring in latest ALTQ from kjc. ALTQify some of the drivers.
 1.91  28-Feb-2002  thorpej Don't call m_aux_find() to find a VLAN tag unless VLANs are configured
on the interface.
 1.90  12-Nov-2001  lukem add RCSIDs
 1.89  17-Oct-2001  itojun unifdef OLDIP6OUTPUT
 1.88  25-Jul-2001  thorpej Duh, braino in last -- only kick the interface if we actually set
the MTU.
 1.87  25-Jul-2001  thorpej If we change the MTU, kick the interface; it may have to reprogram
registers for the new MTU.
 1.86  29-Jun-2001  thorpej branches: 1.86.2;
When setting an address on an interface, for address families which
do not require changing the link-level address, only (*if_init)()
if the interface is not already RUNNING.
 1.85  14-Jun-2001  itojun change the meaning of ifnet.if_lastchange to meet RFC1573 ifLastChange.
follows BSD/OS practice and ucd-snmp code (FreeBSD does it for specific
interfaces only).

was: if_lastchange get updated on every packet transmission/receipt.
now: if_lastchange get updated when IFF_UP is changed.
 1.84  12-Jun-2001  thorpej On a non-simplex interface, check incoming multicast (this catches
the broadcast case as well) to see if they came from us, and drop
them if they did.

This fixed IPv6 DAD on non-simplex interfaces, e.g. the Seeq 8003
found on my SGI Indy.
 1.83  03-Jun-2001  thorpej Consider the configured MTU of the interface when determining
if a packet is too large.
 1.82  03-Jun-2001  thorpej Add a capability bit that indicates support for Gigabit Ethernet
jumbo frames, and use it in SIOCSIFMTU.
 1.81  29-Apr-2001  martin Add an in-kernel PPPoE (ppp over ethernet, RFC 2516) implementation,
based on the existing net/if_spppsubr.c stuff.

While there are completely userland (bpf based) implementations available,
those have a vastly larger per packet overhead thus causing major CPU
overhead and higher latency. On an i386 base router, running a 486DX at 50MHz
my line (768kBit/s downstream) was limited to something (varying) between 10
and 20 kByte/s effective download rate. With this implementation I get full
bandwidth (~85kByte/s).

This is client side only. Arguably the right way to add full PPPoE support
(including server side) would be a variation of the ppp line discipline and
appropriate modifications to pppd. I promise every help I can give to anyone
doing that - but I needed this realy fast. Besids, on low memory NAT boxes
with typically a single PPPoE connection, this implementation is more
lightweight than a pppd based one, which nicely fits my needs.
 1.80  27-Apr-2001  marcus STDC cleanup: label not allowed just before end of block.
 1.79  13-Apr-2001  thorpej Remove the use of splimp() from the NetBSD kernel. splnet()
and only splnet() is allowed for the protection of data structures
used by network devices.
 1.78  11-Apr-2001  thorpej Add hooks for bridging.
 1.77  10-Apr-2001  thorpej Process pfil hooks for Ethernet input and output.
 1.76  07-Apr-2001  thorpej Add altq_etherclassify(), a slight hack modified from the kame/freebsd4
tree, which allows a packet with Ethernet headers already present to
run through the ALTQ packet classifier. This is needed in order to
suport ALTQ on VLAN and bridge devices.
 1.75  17-Jan-2001  thorpej branches: 1.75.2;
Fix a rather annoying problem where the sockaddr_dl which holds
the link level name for the interface (ifp->if_sadl) is allocated
before ifp->if_addrlen is initialized, which could lead to allocating
too little space for the link level address.

Do this by splitting allocation of the link level name out of
if_attach() and into if_alloc_sadl(), which is normally called
by functions like ether_ifattach(). Network interfaces which
don't have a link-specific attach routine must call if_alloc_sadl()
themselves (example: gif).

Link level names are freed by if_free_sadl(), which can be called
from e.g. ether_ifdetach(). Drivers never need call if_free_sadl()
themselves as if_detach() will do it if it is not already done.

While here, add the ability to pass an AF_LINK address to
SIOCSIFADDR in ether_ioctl() (this is what caused me to notice
the problem that the above fixes).
 1.74  26-Dec-2000  augustss Simplify case statement a tiny bit.
 1.73  18-Dec-2000  thorpej Fill in if_dlt.
 1.72  13-Dec-2000  thorpej Add ALTQ glue.
 1.71  12-Dec-2000  thorpej Adapt to bpfattach() changes, and further centralize the bpfattach()
and bpfdetach() calls into link-type subroutines where possible.
 1.70  17-Nov-2000  bouyer Supports hardware 802.1q VLAN tagging, per discussion on tech-net. The tag is
stored in a m_aux mbuf defined by AF_LINK, ETHERTYPE_VLAN.
Thanks to Jason & Itojun for the feedback.
 1.69  15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.68  15-Oct-2000  matt When discarding oversized frame, say how long it was.
 1.67  15-Oct-2000  itojun suppress warning on nd6_storelladdr failure. the failure could happen
easily when we have routing table with too many entries. sync with kame.
 1.66  11-Oct-2000  thorpej Implement ether_ioctl(), ioctl operations common to all Ethernet
interfaces.
 1.65  04-Oct-2000  enami Free mbuf when dropping VLAN frame due to no configured vlan interface.
 1.64  03-Oct-2000  thorpej When an Ethernet interface detaches, unconfigure any VLANs associated
with it.
 1.63  03-Oct-2000  thorpej Improve the VLAN support, in particular, handling of MTU:
- Add a macro to compute the max frame length based on Ethertype
and presence of FCS, and use it to validate the packet size
in ether_input().
- Add capabilites to struct ethercom, and allow hardware drivers
to specify that they can handle the larger hardware MTU that
VLANs require in order to strictly conform to 802.1Q.
- Make ether_ifdetach() clear out the link address and free all of
the Ethernet multicast structures.

Also, rearrange the VLAN driver itself in preparation to supporting
other hardware types, including FDDI (which has 802.1Q VLAN capability).
 1.62  01-Oct-2000  thorpej Make the previous code path simpler (and possible easier for the
compiler to optimize), based on fddi_input().
 1.61  01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.60  28-Sep-2000  enami Factor out and give a name to the common functionality to translate
sockaddr which represents a multicast address into an Ethernet address
or range of Etherenet addresses.
 1.59  27-Sep-2000  thorpej Glue VLANs into ether_input().
 1.58  17-Jun-2000  matt branches: 1.58.2;
Ansify before committing my next change.
 1.57  14-Jun-2000  mycroft Check the multicast bit in the header mbuf while interrupts are still blocked.
Otherwise we can run off into space if the packet was sent immediately and the
mbuf freed.
Pointed out by Boris Popov (not on our lists).
 1.56  12-May-2000  thorpej branches: 1.56.2;
- Fix a bug in the double-loop version of ether_crc32_le() -- we're not't
supposed to bubble carry through.
- Disable the double-loop version of ether_crc32_le() and add a
table-driven version of ether_crc32_le() -- the table-driven
version is faster.
 1.55  12-Apr-2000  itojun revisit in6_ifattach().
- be persistent on initializing interfaces, even if there's manually-
assigned linklocal, multicast/whatever initialization is necessary.
- do not cache mac addr in the kernel. grab mac addr from existing cards
(this is important when you swap ethernet cards back and forth)
now ppp6 works just fine!

call in6_ifattach() on ATM PVC interface to assign link-local, using
hardware MAC address as seed.

(the change is in sync with kame tree).
 1.54  06-Mar-2000  thorpej On second thought, only set a default baudrate for "ethernet" if one
isn't set already.
 1.53  06-Mar-2000  thorpej - Initialize ifp->if_baudrate to a sensible value when the interface is
attached.
- Add ether_crc32_be() and ether_crc_le(), common functions for computing
the Ethernet CRC on arbitrary length buffers. Nothing uses them yet,
and these should be double-checked and probably re-implemented as
table-driven functions.
 1.52  01-Feb-2000  thorpej First-draft if_detach() implementation, originally from Bill Studnemund,
although this version has been changed somewhat:
- reference counting on ifaddrs isn't as complete as Bill's original
work was. This is hard to get right, and we should attack one
protocol at a time.
- This doesn't do reference counting or dynamic allocation of ifnets yet.
- This version introduces a new PRU -- PRU_PURGEADDR, which is used to
purge an ifaddr from a protocol. The old method Bill used didn't work
on all protocols, and it only worked on some because it was Very Lucky.

This mostly works ... i.e. works for my USB Ethernet, except for a dangling
ifaddr reference left by the IPv6 code; have not yet tracked this down.
 1.51  13-Dec-1999  itojun sync IPv6 part with latest KAME tree. IPsec part is left unmodified
due to massive changes in KAME side.
- IPv6 output goes through nd6_output
- faith can capture IPv4 packets as well - you can run IPv4-to-IPv6 translator
using heavily modified DNS servers
- per-interface statistics (required for IPv6 MIB)
- interface autoconfig is revisited
- udp input handling has a big change for mapped address support.
- introduce in4_cksum() for non-overwriting checksumming
- introduce m_pulldown()
- neighbor discovery cleanups/improvements
- netinet/in.h strictly conforms to RFC2553 (no extra defs visible to userland)
- IFA_STATS is fixed a bit (not tested)
- and more more more.

TODO:
- cleanup os-independency #ifdef
- avoid rcvif dual use (for IPsec) to help ifdetach

(sorry for jumbo commit, I can't separate this any more...)
 1.50  12-Oct-1999  matt branches: 1.50.2;
Fix appletalk over ethernet.
 1.49  21-Sep-1999  matt branches: 1.49.2;
Make NETATALK over FDDI.
 1.48  15-Sep-1999  is We only need the ether_ipmulticast_min and _max addresses if we have INET
compiled in.
 1.47  13-Sep-1999  itojun - Call in{,6}_pcbdetach if ipsec initialization is failed during PRU_ATTACH.
This situation happens on severe memory shortage. We may need more
improvements here and there.
- Grab IEEE802 address from IFT_ETHER card, even if the card is
inserted after bootup time. Is there any other card that can be
inserted afterwards? pcmcia fddi card? :-P
- RFC2373 u bit handling suggests that we SHOULD NOT copy interface id from
ethernet card to pseudo interface, when ethernet card has IEEE802/EUI64
with u bit != 0 (this means that IEEE802/EUI64 is not universally unique).
Do not use such address as, for example, interface id for gif interface.
(I have such an ethernet card myself)
This may change interface id for your gif interface. be careful upgrading
rc files.

(sync with recent KAME)
 1.46  05-Aug-1999  thorpej M_HASCRC -> M_HASFCS, as suggested by Christoph Badura.
 1.45  04-Aug-1999  thorpej In ether_input(), if M_HASCRC is set, trim the CRC off the packet.
 1.44  01-Jul-1999  itojun IPv6 kernel code, based on KAME/NetBSD 1.4, SNAP kit 19990628.
(Sorry for a big commit, I can't separate this into several pieces...)
Pls check sys/netinet6/TODO and sys/netinet6/IMPLEMENTATION for details.

- sys/kern: do not assume single mbuf, accept chained mbuf on passing
data from userland to kernel (or other way round).
- "midway" ATM card: ATM PVC pseudo device support, like those done in ALTQ
package (ftp://ftp.csl.sony.co.jp/pub/kjc/).
- sys/netinet/tcp*: IPv4/v6 dual stack tcp support.
- sys/netinet/{ip6,icmp6}.h, sys/net/pfkeyv2.h: IETF document assumes those
file to be there so we patch it up.
- sys/netinet: IPsec additions are here and there.
- sys/netinet6/*: most of IPv6 code sits here.
- sys/netkey: IPsec key management code
- dev/pci/pcidevs: regen

In my understanding no code here is subject to export control so it
should be safe.
 1.43  17-Jun-1999  bouyer mbuf should be allocated with M_DONTWAIT in ether_output(). This caused panics
when routing atalk.
 1.42  18-May-1999  thorpej Rework layer 2 protocol input routines. Instead of calling e.g. ether_input()
directly, call the function pointer (*if_input)(ifp, m). The input routine
expects the packet header to be at the head of the packet, and will adjust
as necessary. Privatize the layer 2 input and output routines, allowing
*_ifattach() to set them up as appropriate.
 1.41  10-Mar-1999  thorpej branches: 1.41.2; 1.41.4; 1.41.6;
Const poison ether_ifattach().
 1.40  10-Mar-1999  thorpej Const poison ether_sprintf().
 1.39  10-Dec-1998  christos IPX fixes.
 1.38  13-Oct-1998  kim branches: 1.38.4;
Use ETHERTYPE_ATALK instead of ETHERTYPE_AT. The former seems more common.
Our other constants also use "ATALK".

Added many new ETHERTYPE constants to sys/net/ethertypes.h, including the
ones from libpcap and tcpdump "ethertype.h" files.
 1.37  05-Jul-1998  jonathan defopt NS, NSIP.
 1.36  05-Jul-1998  jonathan defopt ISO TPIP.
 1.35  05-Jul-1998  jonathan defopt LLC
 1.34  05-Jul-1998  jonathan defopt CCITT.
 1.33  05-Jul-1998  jonathan defopt INET, NETATALK.
 1.32  04-May-1998  christos Add IPX bits.
 1.31  30-Apr-1998  thorpej In ether_output(), if the socket address family is pseudo_AF_HDRCMPLT,
use the Ethernet source address speficied in the sockaddr rather than
the interface's Ethernet address, and then fall through to the AF_UNSPEC
case. From Greg Smith <greg@nas.nasa.gov>.
 1.30  29-Apr-1998  matt Add support for "fast" forwarding. Add hooks in if_ethersubr.c and
if_fddisubr.c to fastpath IP forwarding. If ip_forward successfully
forwards a packet, it will create a cache (ipflow) entry. ether_input
and fddi_input will first call ipflow_fastforward with the received
packet and if the packet passes enough tests, it will be forwarded (the
ttl is decremented and the cksum is adjusted incrementally).
 1.29  26-Apr-1998  mrg remove some register.
 1.28  24-Mar-1998  kleink register -> register int
 1.27  01-Mar-1998  fvdl Merge with Lite2 + local changes
 1.26  02-Oct-1997  is Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.
 1.25  03-Apr-1997  christos branches: 1.25.4;
Update for argument change in at_ifawithnet
 1.24  03-Apr-1997  christos PR/3444: Erik Bertelsen: Eliminate warnings when -UINET
 1.23  02-Apr-1997  christos Add netatalk stubs.
 1.22  15-Mar-1997  is New ARP system, supports IPv4 over any hardware link.

Some of the stuff (e.g., rarpd, bootpd, dhcpd etc., libsa) still will
only support Ethernet. Tcpdump itself should be ok, but libpcap needs
lot of work.

For the detailed change history, look at the commit log entries for
the is-newarp branch.
 1.21  13-Oct-1996  christos branches: 1.21.4;
backout previous kprintf change
 1.20  10-Oct-1996  christos - printf -> kprintf, sprintf -> ksprintf
 1.19  07-May-1996  thorpej Changed struct ifnet to have a pointer to the softc of the underlying
device and a printable "external name" (name + unit number), thus eliminating
if_name and if_unit. Updated interface to (*if_watchdog)() and (*if_reset)()
to take a struct ifnet *, rather than a unit number.
 1.18  13-Feb-1996  christos Net prototypes
 1.17  24-Dec-1995  mycroft Avoid extra byte-swapping in average cases.
 1.16  24-Dec-1995  mycroft Remove old comment regarding trailers.
 1.15  29-Sep-1995  phil Move a #include to outside the #ifdef INET so it will compile without
INET defined.
 1.14  19-Aug-1995  mycroft Garbage collect useless `off' and `len' variables.
 1.13  12-Jun-1995  mycroft Various cleanup, including:
* Convert several data structures to use queue.h.
* Split in_pcbnotify() into two parts; one for notifying a specific PCB, and
one for notifying all PCBs for a particular foreign address.
 1.12  07-Apr-1995  mycroft Set if_output in ether_ifattach().
 1.11  05-Apr-1995  mycroft Make OSI and X.25 work on little-endian machines.
 1.10  08-Mar-1995  cgd fixed sized types, where appropriate. when casting pointers to
integers to do math on them, cast to long. ioctl commands are
u_longs.
 1.9  29-Jun-1994  cgd New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'
 1.8  13-May-1994  mycroft Update to 4.4-Lite networking code, with a few local changes.
 1.7  18-Apr-1994  glass revised nfs diskless support. uses bootp+rpc to gather parameters
 1.6  02-Feb-1994  hpeyerl Multicast is no longer optional
 1.5  23-Jan-1994  deraadt ether_output() & ether_input() take ether_type as a net-short.
AF_UNSPEC does not swap byte order of ether_type.
NOTE: this requires driver changes
 1.4  17-Dec-1993  mycroft From magnum branch:
Remove Jolitz's netisr kluge. Make sure cpl == 0 really means base priority.
Other minor cleanup.
 1.3  06-Dec-1993  hpeyerl multicast support.
>From Chris Maeda, cmaeda@cs.washington.edu
These patches are derived from the IP Multicast patches for BSDI.
 1.2  20-May-1993  cgd branches: 1.2.4;
add rcs ids to everything, and clean up headers
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3  01-Mar-1998  fvdl Import some files that were changed after Lite2
 1.1.1.2  01-Mar-1998  fvdl Import 4.4BSD-Lite for reference
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.2  29-Oct-1993  mycroft #include machine/cpu.h
 1.2.4.1  16-Oct-1993  mycroft Nuke references to machine/mtpr.h.
 1.21.4.5  09-Mar-1997  is netinet/if_ether.h -> netinet/if_inarp.h
 1.21.4.4  18-Feb-1997  is Having converted everything, remove the struct ether_arp definition completely.
Some small cleanup.
STILLTODO: some sanity checks of the (now) variable link level address length
in incoming packets..
 1.21.4.3  12-Feb-1997  is Changed arprequest() to use AF_ARP sockaddr and NOT build its own Ethernet
header. Added some missing pieces in ether_output() to support this.
 1.21.4.2  11-Feb-1997  is - Add macros, to if_arp.h:struct arphdr, to access an ARP messages' variable
fields based on the ar_hln and ar_pln fields.
- Add AR_ARP case to ether_output, using the ar_tha() macro defined above.
 1.21.4.1  07-Feb-1997  is Snapshot of new ARP code.

Our old ARP code was hardwired for 6-byte length medium
addresses, while the protocol is designed for any size.

This snapshot contains a first hack at getting rid of
Ethernet specific data structures. The ep driver is updated
(and tested on the PCI bus), the iy and fpa drivers have been
updated, but not real life tested yet.

If you want to test this with other drivers, you have to update
them first yourself, and probably tag the relevant directories.
Better contact me if you want to do this.
 1.25.4.1  14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.38.4.1  11-Dec-1998  kenh The beginnings of interface detach support. Still some bugs, but mostly
works for me.

This work was originally by Bill Studenmund, and cleaned up by me.
 1.41.6.2  30-Nov-1999  itojun bring in latest KAME (as of 19991130, KAME/NetBSD141) into kame branch
just for reference purposes.
This commit includes 1.4 -> 1.4.1 sync for kame branch.

The branch does not compile at all (due to the lack of ALTQ and some other
source code). Please do not try to modify the branch, this is just for
referenre purposes.

synchronization to latest KAME will take place on HEAD branch soon.
 1.41.6.1  28-Jun-1999  itojun KAME/NetBSD 1.4 SNAP kit, dated 19990628.

NOTE: this branch (kame) is used just for refernce. this may not compile
due to multiple reasons.
 1.41.4.2  01-Jul-1999  thorpej Sync w/ -current.
 1.41.4.1  21-Jun-1999  thorpej Sync w/ -current.
 1.41.2.1  24-Jun-1999  perry pullup 1.42->1.43 (bouyer): allocate mbuf with M_DONTWAIT in ether_output()
 1.49.2.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.50.2.6  21-Apr-2001  bouyer Sync with HEAD
 1.50.2.5  18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.50.2.4  05-Jan-2001  bouyer Sync with HEAD
 1.50.2.3  13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.50.2.2  22-Nov-2000  bouyer Sync with HEAD.
 1.50.2.1  20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
 1.56.2.1  22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.58.2.2  07-Jun-2001  he Pull up revision 1.83 (via patch, requested by thorpej):
Consider the configured MTU of the interface when determining
if a packet is too large.
 1.58.2.1  31-Dec-2000  jhawk Pull up revisions 1.59-1.60, 1.62-1.65, 1.70 via patch (requested by bouyer):
Add support for 802.1Q virtual LANs.
 1.75.2.13  17-Jan-2003  thorpej Sync with HEAD.
 1.75.2.12  15-Jan-2003  thorpej Sync with HEAD.
 1.75.2.11  17-Sep-2002  nathanw Catch up to -current.
 1.75.2.10  26-Aug-2002  nathanw Sync with rev 1.98 of -current.
 1.75.2.9  19-Aug-2002  thorpej Sync with trunk.
 1.75.2.8  20-Jun-2002  nathanw Catch up to -current.
 1.75.2.7  17-Apr-2002  nathanw Catch up to -current.
 1.75.2.6  01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.75.2.5  14-Nov-2001  nathanw Catch up to -current.
 1.75.2.4  22-Oct-2001  nathanw Catch up to -current.
 1.75.2.3  24-Aug-2001  nathanw Catch up with -current.
 1.75.2.2  21-Jun-2001  nathanw Catch up to -current.
 1.75.2.1  09-Apr-2001  nathanw Catch up with -current.
 1.86.2.6  10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.86.2.5  06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.86.2.4  23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.86.2.3  16-Mar-2002  jdolecek Catch up with -current.
 1.86.2.2  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.86.2.1  03-Aug-2001  lukem update to -current
 1.94.2.2  29-Aug-2002  gehenna catch up with -current.
 1.94.2.1  30-May-2002  gehenna Catch up with -current.
 1.95.2.5  30-Jun-2003  grant Pull up revision 1.106 (requested by bouyer in ticket #1356):

Make promiscous mode work on vlans: introduce a new link-layer m_flag
M_PROMISC. In ether_input(), flag packets comming from an interface in
promiscous mode which are not for us M_PROMISC instead of droping them.
Drop M_PROMISC packets which are not passed to vlan_input(). M_PROMISC
packets passed to vlan_input() will be looped back to ether_input()
the M_PROMISC flag will be handled appropriately.
Clear M_PROMISC before giving the packet to bridge, as bridge has its
own checks for local MAC addresses.
This also makes bridges on vlan working.
 1.95.2.4  24-Jun-2003  grant Apply patch (requested by itojun in ticket #1325):

don't call if_free_sadl() until very end of if_detach() logic. many of
routing table manipulation code assumes the presense of AF_LINK sockaddr.
should fix PR 21581
 1.95.2.3  02-Jun-2003  tron Pull up revision 1.105 (requested by aymeric in ticket #1188):
ignore multicast PPPoE packets ASAP.
This improves performance a lot on slow machines behind a cable modem.
Protect it with PPPOE_SERVER as a reminder that this will have to be changed
if we add PPPoE server code in the kernel one day.
 1.95.2.2  26-Jan-2003  jmc Pullup revisions 1.101-1.102 (requested by jmmv in ticket #1102)
Fix typo: realy -> really. Okay'ed by wiz.
 1.95.2.1  19-Nov-2002  tron Pull up revision 1.96-1.97 (requested by thorpej in ticket #702):
In ether_output(), don't bother calling memcpy() to plop the ethertype
into the packet: On system with no strict alignment constraints, just
assign the value, and on others, do an inline 2 byte copy.
 1.112.2.8  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.112.2.7  01-Apr-2005  skrll Sync with HEAD.
 1.112.2.6  04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.112.2.5  04-Feb-2005  skrll Sync with HEAD.
 1.112.2.4  17-Jan-2005  skrll Sync with HEAD.
 1.112.2.3  21-Sep-2004  skrll Fix the sync with head I botched.
 1.112.2.2  18-Sep-2004  skrll Sync with HEAD.
 1.112.2.1  03-Aug-2004  skrll Sync with HEAD
 1.114.2.2  14-Jul-2004  tron Pull up revision 1.116 (requested by jonathan in ticket #648):
Rename MBUFTRACE helper function m_claim() to m_claimm(),
for consistency with M_FREE() and m_freem(). Affected files:
sys/mbuf.h
kern/uipc_socket2.c
kern/uipc_mbuf.c
net/if_ethersubr.c
netatalk/ddp_input.c
nfs/nfs_socket.c
 1.114.2.1  07-Jun-2004  jdc Pull up revision 1.115 (requested by dyoung in ticket #448).

Resolve kern/25721 by detaching ethernet(-like) devices from a
bridge in ether_ifdetach.
 1.118.4.2  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.118.4.1  12-Feb-2005  yamt sync with head.
 1.118.2.1  29-Apr-2005  kent sync with -current
 1.120.6.1  08-Jan-2007  ghen Pull up following revision(s) (requested by bouyer in ticket #1623):
sys/net/if_ethersubr.c: revision 1.142 via patch
Don't define dropanyway: label unless ISO or NETATALK is defined. Fix
kern/35364 by Gene ENonymous
 1.120.4.1  08-Jan-2007  ghen Pull up following revision(s) (requested by bouyer in ticket #1623):
sys/net/if_ethersubr.c: revision 1.142 via patch
Don't define dropanyway: label unless ISO or NETATALK is defined. Fix
kern/35364 by Gene ENonymous
 1.120.2.2  08-Jan-2007  ghen Pull up following revision(s) (requested by bouyer in ticket #1623):
sys/net/if_ethersubr.c: revision 1.142 via patch
Don't define dropanyway: label unless ISO or NETATALK is defined. Fix
kern/35364 by Gene ENonymous
 1.120.2.1  02-Dec-2006  bouyer Pull up following revision(s) (requested by is in ticket #1597):
sys/net/if_ethersubr.c: revision 1.139 via patch
sys/netiso/clnp_input.c: revision 1.31
Remove an overlapping struct copy from ether_input, which caused address
corruption for incoming netiso packets with recent (at least NetBSD-3 and
later) compilers. This is done in a way that the copy is avoided totally.
Code path tested with tcp+udp/ipv4+ipv6, arp and ISO cltp/clnp.
Visually ok'd by Christos@.
 1.126.2.9  17-Mar-2008  yamt sync with head.
 1.126.2.8  27-Feb-2008  yamt sync with head.
 1.126.2.7  11-Feb-2008  yamt sync with head.
 1.126.2.6  21-Jan-2008  yamt sync with head
 1.126.2.5  27-Oct-2007  yamt sync with head.
 1.126.2.4  03-Sep-2007  yamt sync with head.
 1.126.2.3  26-Feb-2007  yamt sync with head.
 1.126.2.2  30-Dec-2006  yamt sync with head.
 1.126.2.1  21-Jun-2006  yamt sync with head.
 1.128.10.2  06-May-2006  christos - Move kauth_cred_t declaration to <sys/types.h>
- Cleanup struct ucred; forward declarations that are unused.
- Don't include <sys/kauth.h> in any header, but include it in the c files
that need it.

Approved by core.
 1.128.10.1  19-Apr-2006  elad sync with head.
 1.128.8.5  14-Sep-2006  yamt sync with head.
 1.128.8.4  11-Aug-2006  yamt sync with head
 1.128.8.3  26-Jun-2006  yamt sync with head.
 1.128.8.2  24-May-2006  yamt sync with head.
 1.128.8.1  01-Apr-2006  yamt sync with head.
 1.128.6.3  01-Jun-2006  kardel Sync with head.
 1.128.6.2  22-Apr-2006  simonb Sync with head.
 1.128.6.1  04-Feb-2006  simonb Adapt for timecounters: mostly use get*time(), use bintime's for timeout
calculations and use "time_second" instead of "time.tv_sec".
 1.128.4.1  09-Sep-2006  rpaulo sync with head
 1.129.2.1  24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.133.2.1  19-Jun-2006  chap Sync with head.
 1.136.4.2  18-Dec-2006  yamt sync with head.
 1.136.4.1  10-Dec-2006  yamt sync with head.
 1.136.2.2  01-Feb-2007  ad Sync with head.
 1.136.2.1  12-Jan-2007  ad Sync with head.
 1.139.2.2  27-Feb-2007  riz Pull up following revision(s) (requested by bouyer in ticket #465):
sys/net/if_ethersubr.c: revision 1.144
Drop M_PROMISC before passing the packet to a carp device, for the same
reason it's dropped before passing to bridge: when a vlan interface is
in promisc mode, it will loop the packet back to ether_input() with
M_PROMISC set, and when carp calls ether_input again the flag is still
there and the packet is dropped. If the carp interface doesn't take
the packet M_PROMISC is set just after is needed anyway.
Tested on a box with multiple carp on vlans, no comments about this patch
on tech-net@
 1.139.2.1  08-Jan-2007  tron Pull up following revision(s) (requested by bouyer in ticket #337):
sys/net/if_ethersubr.c: revision 1.142
Don't define dropanyway: label unless ISO or NETATALK is defined. Fix
kern/35364 by Gene ENonymous
 1.144.2.2  12-Mar-2007  rmind Sync with HEAD.
 1.144.2.1  27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.148.4.1  11-Jul-2007  mjf Sync with head.
 1.148.2.5  09-Oct-2007  ad Sync with head.
 1.148.2.4  20-Aug-2007  ad Sync with HEAD.
 1.148.2.3  15-Jul-2007  ad Sync with head.
 1.148.2.2  17-Jun-2007  ad - Increase the number of thread priorities from 128 to 256. How the space
is set up is to be revisited.
- Implement soft interrupts as kernel threads. A generic implementation
is provided, with hooks for fast-path MD code that can run the interrupt
threads over the top of other threads executing in the kernel.
- Split vnode::v_flag into three fields, depending on how the flag is
locked (by the interlock, by the vnode lock, by the file system).
- Miscellaneous locking fixes and improvements.
 1.148.2.1  09-Jun-2007  ad Sync with head.
 1.150.2.2  03-Sep-2007  skrll Sync with HEAD.
 1.150.2.1  15-Aug-2007  skrll Sync with HEAD.
 1.151.4.4  26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.151.4.3  02-Oct-2007  joerg Sync with HEAD.
 1.151.4.2  03-Sep-2007  jmcneill Sync with HEAD.
 1.151.4.1  09-Aug-2007  jmcneill Sync with HEAD.
 1.152.2.2  07-Aug-2007  dyoung Constify.
 1.152.2.1  07-Aug-2007  dyoung file if_ethersubr.c was added on branch matt-mips64 on 2007-08-07 04:37:45 +0000
 1.153.2.3  23-Mar-2008  matt sync with HEAD
 1.153.2.2  09-Jan-2008  matt sync with HEAD
 1.153.2.1  06-Nov-2007  matt sync with HEAD
 1.155.2.1  14-Oct-2007  yamt sync with head.
 1.156.10.2  20-Jan-2008  bouyer Sync with HEAD
 1.156.10.1  02-Jan-2008  bouyer Sync with HEAD
 1.156.6.1  26-Dec-2007  ad Sync with head.
 1.156.4.1  18-Feb-2008  mjf Sync with HEAD.
 1.162.6.4  17-Jan-2009  mjf Sync with HEAD.
 1.162.6.3  28-Sep-2008  mjf Sync with HEAD.
 1.162.6.2  02-Jun-2008  mjf Sync with HEAD.
 1.162.6.1  03-Apr-2008  mjf Sync with HEAD.
 1.162.2.1  24-Mar-2008  keiichi sync with head.
 1.164.6.2  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.164.6.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.164.4.5  11-Aug-2010  yamt sync with head.
 1.164.4.4  11-Mar-2010  yamt sync with head
 1.164.4.3  20-Jun-2009  yamt sync with head
 1.164.4.2  04-May-2009  yamt sync with head.
 1.164.4.1  16-May-2008  yamt sync with head.
 1.164.2.1  18-May-2008  yamt sync with head.
 1.167.4.2  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.167.4.1  19-Oct-2008  haad Sync with HEAD.
 1.167.2.1  28-Jul-2008  simonb Sync with head.
 1.169.8.1  21-Apr-2010  matt sync to netbsd-5
 1.169.6.1  21-Nov-2009  snj Pull up following revision(s) (requested by christos in ticket #1156):
sys/net/if_arcsubr.c: revision 1.61
sys/net/if_ethersubr.c: revision 1.173
sys/net/if_fddisubr.c: revision 1.78
sys/net/if_tokensubr.c: revision 1.58 via patch
sys/netinet/if_arp.c: revision 1.149
ar_tha() can return NULL; treat this as an error.
 1.169.4.2  21-Nov-2009  snj Pull up following revision(s) (requested by christos in ticket #1156):
sys/net/if_arcsubr.c: revision 1.61
sys/net/if_ethersubr.c: revision 1.173
sys/net/if_fddisubr.c: revision 1.78
sys/net/if_tokensubr.c: revision 1.58 via patch
sys/netinet/if_arp.c: revision 1.149
ar_tha() can return NULL; treat this as an error.
 1.169.4.1  05-Jun-2009  snj Pull up following revision(s) (requested by 792):
sys/dev/pci/if_wm.c: revision 1.175 via patch
sys/net/if_ethersubr.c: revision 1.172 via patch
sys/net/agr/ieee8023ad_lacp.c: revision 1.9 via patch
sys/net/agr/if_agr.c: revision 1.23 via patch
sys/net/agr/if_agrether.c: revision 1.7 via patch
sys/net/agr/if_agrvar_impl.h: revision 1.8 via patch
Add vlan support and hardware offload capabilities to agr.
These changes allow vlans to be layered above agr, with the attach
and detach propogated to the member ports in the aggregation.
Note the agr interface must be up before the vlan is attached.
Adds SIOCSIFADDR support to the wm driver for setting the AF_LINK
address, necessary for agr to be able to set the mac addresses of each
port to the agr address (i.e. so it can receive all intended traffic
at the hardware level).
Adds support for disabling the LACP protocol by setting LINK1 on the agr
interface (e.g. ifconfig agr0 link1).
In consultation with tls@.
 1.169.2.1  19-Jan-2009  skrll Sync with HEAD.
 1.170.4.2  23-Jul-2009  jym Sync with HEAD.
 1.170.4.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.176.4.4  31-May-2011  rmind sync with head
 1.176.4.3  05-Mar-2011  rmind sync with head
 1.176.4.2  03-Jul-2010  rmind sync with head
 1.176.4.1  30-May-2010  rmind sync with head
 1.176.2.2  17-Aug-2010  uebayasi Sync with HEAD.
 1.176.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.185.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.187.2.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.188.8.5  05-Feb-2017  snj Pull up following revision(s) (requested by maxv in ticket #1429):
sys/net/if_arcsubr.c: revision 1.76 via patch
sys/net/if_ecosubr.c: revision 1.50 via patch
sys/net/if_ethersubr.c: revision 1.236 via patch
sys/net/if_fddisubr.c: revision 1.104 via patch
sys/net/if_tokensubr.c: revision 1.80 via patch
Don't forget to free the mbuf when we decide not to reply to an ARP
request. This obviously is a terrible bug, since it allows a remote sender
to DoS the system with specially-crafted requests sent in a loop.
 1.188.8.4  03-Jun-2014  msaitoh Pull up following revision(s) (requested by bouyer in ticket #1067):
sys/dist/ipf/netinet/ip_fil_netbsd.c 1.9 via patch
sys/net/if_ethersubr.c 1.197 via patch
sys/net/if_loop.c 1.77 via patch
sys/net/if_vlan.c 1.70 via patch
sys/netinet/if_arp.c 1.158
sys/netinet/ip_carp.c 1.54 via patch
sys/netinet6/ip6_flow.c 1.23 via patch
sys/netinet6/nd6.c 1.150 via patch
sys/rump/librump/rumpkern/klock.c 1.4

Make sure *(if_output)() is called with KERNEL_LOCK held to avoid mbuf leak.
See http://mail-index.netbsd.org/tech-net/2014/04/09/msg004511.html
for details. For netinet6, the problem report, fix and test were done
by njoly@ on current-users@
 1.188.8.3  31-Oct-2012  riz branches: 1.188.8.3.2;
Pull up following revision(s) (requested by christos in ticket #638):
sys/net/if_ppp.c: revision 1.137
sys/netinet6/ip6_flow.c: revision 1.20
sys/net/if_fddisubr.c: revision 1.82
sys/net/if_ethersubr.c: revision 1.192
sys/netinet6/in6_var.h: revision 1.66
sys/net/if_atmsubr.c: revision 1.50
PR/47058: Antti Kantee: If the ipv6 flow code modifies the mbuf, pass the
change up to the caller.
 1.188.8.2  20-Aug-2012  riz branches: 1.188.8.2.4;
Pull up following revision(s) (requested by christos in ticket #517):
sys/net/if_ethersubr.c: revision 1.190
PR/46587: Roger Pau Monne: Prevent panic on shutdown on bridge teardown ->
ifpromisc-> if_ioctl -> if_init. Idea from dyoung.
XXX: Pullup to 6.
 1.188.8.1  18-May-2012  riz Pull up following revision(s) (requested by chs in ticket #258):
sys/net/if_ethersubr.c: revision 1.189
in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.
 1.188.8.3.2.2  05-Feb-2017  snj Pull up following revision(s) (requested by maxv in ticket #1429):
sys/net/if_arcsubr.c: revision 1.76 via patch
sys/net/if_ecosubr.c: revision 1.50 via patch
sys/net/if_ethersubr.c: revision 1.236 via patch
sys/net/if_fddisubr.c: revision 1.104 via patch
sys/net/if_tokensubr.c: revision 1.80 via patch
Don't forget to free the mbuf when we decide not to reply to an ARP
request. This obviously is a terrible bug, since it allows a remote sender
to DoS the system with specially-crafted requests sent in a loop.
 1.188.8.3.2.1  18-Jun-2014  msaitoh Pull up following revision(s) (requested by bouyer in ticket #1067):
sys/dist/ipf/netinet/ip_fil_netbsd.c 1.9 via patch
sys/net/if_ethersubr.c 1.197 via patch
sys/net/if_loop.c 1.77 via patch
sys/net/if_vlan.c 1.70 via patch
sys/netinet/if_arp.c 1.158
sys/netinet/ip_carp.c 1.54 via patch
sys/netinet6/ip6_flow.c 1.23 via patch
sys/netinet6/nd6.c 1.150 via patch
sys/rump/librump/rumpkern/klock.c 1.4

Make sure *(if_output)() is called with KERNEL_LOCK held to avoid mbuf leak.
See http://mail-index.netbsd.org/tech-net/2014/04/09/msg004511.html
for details. For netinet6, the problem report, fix and test were done
by njoly@ on current-users@
 1.188.8.2.4.2  05-Feb-2017  snj Pull up following revision(s) (requested by maxv in ticket #1429):
sys/net/if_arcsubr.c: revision 1.76 via patch
sys/net/if_ecosubr.c: revision 1.50 via patch
sys/net/if_ethersubr.c: revision 1.236 via patch
sys/net/if_fddisubr.c: revision 1.104 via patch
sys/net/if_tokensubr.c: revision 1.80 via patch
Don't forget to free the mbuf when we decide not to reply to an ARP
request. This obviously is a terrible bug, since it allows a remote sender
to DoS the system with specially-crafted requests sent in a loop.
 1.188.8.2.4.1  18-Jun-2014  msaitoh Pull up following revision(s) (requested by bouyer in ticket #1067):
sys/dist/ipf/netinet/ip_fil_netbsd.c 1.9 via patch
sys/net/if_ethersubr.c 1.197 via patch
sys/net/if_loop.c 1.77 via patch
sys/net/if_vlan.c 1.70 via patch
sys/netinet/if_arp.c 1.158
sys/netinet/ip_carp.c 1.54 via patch
sys/netinet6/ip6_flow.c 1.23 via patch
sys/netinet6/nd6.c 1.150 via patch
sys/rump/librump/rumpkern/klock.c 1.4

Make sure *(if_output)() is called with KERNEL_LOCK held to avoid mbuf leak.
See http://mail-index.netbsd.org/tech-net/2014/04/09/msg004511.html
for details. For netinet6, the problem report, fix and test were done
by njoly@ on current-users@
 1.188.6.1  02-Jun-2012  mrg sync to latest -current.
 1.188.2.4  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.188.2.3  16-Jan-2013  yamt sync with (a bit old) head
 1.188.2.2  30-Oct-2012  yamt sync with head
 1.188.2.1  23-May-2012  yamt sync with head.
 1.190.2.4  03-Dec-2017  jdolecek update from HEAD
 1.190.2.3  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.190.2.2  23-Jun-2013  tls resync from head
 1.190.2.1  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.194.6.2  18-May-2014  rmind sync with head
 1.194.6.1  28-Aug-2013  rmind sync with head
 1.196.2.2  10-Aug-2014  tls Rebase.
 1.196.2.1  07-Apr-2014  tls Increase unpredictability of early output: mix in the headers of the
first 100 Ethernet packets received by the system (if we are really
short of entropy, keep mixing them though we don't count any entropy from
them; such systems are particularly likely to have guessable outputs).
 1.204.6.1  13-Mar-2017  skrll Sync with netbsd-7-1-RELEASE
 1.204.4.1  05-Feb-2017  snj Pull up following revision(s) (requested by maxv in ticket #1355):
sys/net/if_arcsubr.c: revision 1.76 via patch
sys/net/if_ecosubr.c: revision 1.50 via patch
sys/net/if_ethersubr.c: revision 1.236 via patch
sys/net/if_fddisubr.c: revision 1.104 via patch
sys/net/if_tokensubr.c: revision 1.80 via patch
Don't forget to free the mbuf when we decide not to reply to an ARP
request. This obviously is a terrible bug, since it allows a remote sender
to DoS the system with specially-crafted requests sent in a loop.
 1.204.2.2  24-Sep-2017  snj Pull up following revision(s) (requested by manu in ticket #1409):
sys/arch/xen/xen/if_xennet_xenbus.c: 1.65
sys/arch/xen/xen/xennetback_xenbus.c: 1.53, 1.56 via patch
sys/net/if_bridge.c: 1.105
sys/net/if_ether.h: 1.65
sys/net/if_ethersubr.c: 1.215, 1.235
sys/net/if_vlan.c: 1.76, 1.77, 1.83, 1.88, 1.94
Protect vlan_unconfig with a mutex
It is not thread-safe but is likely to be executed in concurrent.
See PR 49264 for more detail.
--
Tweak vlan_unconfig
No functional change.
--
Add handling of VLAN packets in if_bridge where the parent interface supports
them (Jean-Jacques.Puig%espci.fr@localhost). Factor out the vlan_mtu enabling and
disabling code.
--
Enable the VLAN mtu capability and check for the adjusted packet size
(Jean-Jacques.Puig at espci.fr).
Factor out the packet-size checking function for clarity.
--
Don't increment the reference count only when it was 0...
From Jean-Jacques.Puig
--
Account for the CRC len (Jean-Jacques.Puig)
--
Fix a bug that the parent interface's callback wasn't called when the vlan
interface is configured. A callback function uses VLAN_ATTACHED() function
which check ec->ec_nvlans, the value should be incremented before calling the
callback. This bug was added in if_vlan.c rev. 1.83 (2015/11/19).
 1.204.2.1  05-Feb-2017  snj Pull up following revision(s) (requested by maxv in ticket #1355):
sys/net/if_arcsubr.c: revision 1.76 via patch
sys/net/if_ecosubr.c: revision 1.50 via patch
sys/net/if_ethersubr.c: revision 1.236 via patch
sys/net/if_fddisubr.c: revision 1.104 via patch
sys/net/if_tokensubr.c: revision 1.80 via patch
Don't forget to free the mbuf when we decide not to reply to an ARP
request. This obviously is a terrible bug, since it allows a remote sender
to DoS the system with specially-crafted requests sent in a loop.
 1.205.2.12  28-Aug-2017  skrll Sync with HEAD
 1.205.2.11  05-Feb-2017  skrll Sync with HEAD
 1.205.2.10  05-Dec-2016  skrll Sync with HEAD
 1.205.2.9  05-Oct-2016  skrll Sync with HEAD
 1.205.2.8  09-Jul-2016  skrll Sync with HEAD
 1.205.2.7  29-May-2016  skrll Sync with HEAD
 1.205.2.6  22-Apr-2016  skrll Sync with HEAD
 1.205.2.5  19-Mar-2016  skrll Sync with HEAD
 1.205.2.4  27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.205.2.3  22-Sep-2015  skrll Sync with HEAD
 1.205.2.2  06-Jun-2015  skrll Sync with HEAD
 1.205.2.1  06-Apr-2015  skrll Sync with HEAD
 1.225.2.6  26-Apr-2017  pgoyette Sync with HEAD
 1.225.2.5  20-Mar-2017  pgoyette Sync with HEAD
 1.225.2.4  07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.225.2.3  04-Nov-2016  pgoyette Sync with HEAD
 1.225.2.2  06-Aug-2016  pgoyette Sync with HEAD
 1.225.2.1  26-Jul-2016  pgoyette Sync with HEAD
 1.235.2.1  21-Apr-2017  bouyer Sync with HEAD
 1.242.6.10  10-Oct-2022  martin Pull up following revision(s) (requested by msaitoh in ticket #1770):

sys/net/if_ethersubr.c: revision 1.254

Fix a bug in the VLAN path: there's an inverted logic, the mbuf needs to
be bigger than struct ether_vlan_header, not smaller.

Meanwhile add a KASSERT in the LLC path.
 1.242.6.9  27-Oct-2021  martin Fix merge mishap from previous (ticket #1704)
 1.242.6.8  25-Oct-2021  martin Pull up following revision(s) (requested by ryo in ticket #1704):

sys/net/if_ethersubr.c: revision 1.302

frame's vlan tag must be ntohs()'ed.

VLAN 0 Priority tag was misrecognized on non vlan-hwtagging interfaces.
 1.242.6.7  08-Oct-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1402):

sys/net/if_ethersubr.c: revision 1.277

Increment if_iqdrops when dropping an oversized frame.
 1.242.6.6  08-Oct-2019  martin Pull up following revision(s) (requested by ozaki-r in ticket #1401):

sys/net/if_ethersubr.c: revision 1.255

Fix two bugs in altq_etherclassify. When scanning the mbuf chain we need
to make sure that m_next is not NULL, otherwise NULL deref. After that,
we must not touch m->m_pkthdr, given that 'm' may not be the first mbuf
of the chain anymore.

Declare mtop, and add a KASSERT to make sure it has M_PKTHDR set.
 1.242.6.5  13-Mar-2018  martin Pull up following revision(s) (requested by ozaki-r in ticket #628):
sys/net/if_ethersubr.c: revision 1.250
sys/net/if_ethersubr.c: revision 1.251
sys/net/if_ethersubr.c: revision 1.252
sys/net/if_ethersubr.c: revision 1.248
Use kmem_alloc instead of kmem_intr_alloc in ether_addmulti

ether_addmulti is now not called in softint thanks to wqinput that
pulled input routines of ICMP out of softint.

style

Fix the net.ether.multicast sysctl. If there is no multicast address
don't kmem_alloc(0) (which panics the kernel), and if the number of
multicast addresses has decreased don't copyout uninitialized kernel
data.

Several fixes:
- Style and typos
- Use kmem_zalloc, in case there is a padding between the fields of
the structures
- Use ETHER_ADDR_LEN instead of a hard-coded '6'
- kmem_alloc(KM_SLEEP) can't fail
- Simplify ether_aton_r
- Use mutex_obj_free, not to leak memory
 1.242.6.4  08-Mar-2018  martin Pull up following revision(s) (requested by msaitoh in ticket #618):
sys/net/if_ethersubr.c: revision 1.245
sys/net/if_ethersubr.c: revision 1.247

Use macro(ETHER_LOCK() and ETHER_UNLOCK()). No functional change.

- Modify ether_ioctl() for readability. No functional change.

- KNF
 1.242.6.3  09-Jan-2018  snj Pull up following revision(s) (requested by maxv in ticket #480):
sys/net/if_ethersubr.c: revision 1.249
Make sure we have an llc structure in the packet, and don't read past the
end of the mbuf if we don't. I'm wondering whether we should not pull up
instead, but whatever.
 1.242.6.2  02-Jan-2018  snj Pull up following revision(s) (requested by ozaki-r in ticket #456):
sys/arch/arm/sunxi/sunxi_emac.c: 1.9
sys/dev/ic/dwc_gmac.c: 1.43-1.44
sys/dev/pci/if_iwm.c: 1.75
sys/dev/pci/if_wm.c: 1.543
sys/dev/pci/ixgbe/ixgbe.c: 1.112
sys/dev/pci/ixgbe/ixv.c: 1.74
sys/kern/sys_socket.c: 1.75
sys/net/agr/if_agr.c: 1.43
sys/net/bpf.c: 1.219
sys/net/if.c: 1.397, 1.399, 1.401-1.403, 1.406-1.410, 1.412-1.416
sys/net/if.h: 1.242-1.247, 1.250, 1.252-1.257
sys/net/if_bridge.c: 1.140 via patch, 1.142-1.146
sys/net/if_etherip.c: 1.40
sys/net/if_ethersubr.c: 1.243, 1.246
sys/net/if_faith.c: 1.57
sys/net/if_gif.c: 1.132
sys/net/if_l2tp.c: 1.15, 1.17
sys/net/if_loop.c: 1.98-1.101
sys/net/if_media.c: 1.35
sys/net/if_pppoe.c: 1.131-1.132
sys/net/if_spppsubr.c: 1.176-1.177
sys/net/if_tun.c: 1.142
sys/net/if_vlan.c: 1.107, 1.109, 1.114-1.121
sys/net/npf/npf_ifaddr.c: 1.3
sys/net/npf/npf_os.c: 1.8-1.9
sys/net/rtsock.c: 1.230
sys/netcan/if_canloop.c: 1.3-1.5
sys/netinet/if_arp.c: 1.255
sys/netinet/igmp.c: 1.65
sys/netinet/in.c: 1.210-1.211
sys/netinet/in_pcb.c: 1.180
sys/netinet/ip_carp.c: 1.92, 1.94
sys/netinet/ip_flow.c: 1.81
sys/netinet/ip_input.c: 1.362
sys/netinet/ip_mroute.c: 1.147
sys/netinet/ip_output.c: 1.283, 1.285, 1.287
sys/netinet6/frag6.c: 1.61
sys/netinet6/in6.c: 1.251, 1.255
sys/netinet6/in6_pcb.c: 1.162
sys/netinet6/ip6_flow.c: 1.35
sys/netinet6/ip6_input.c: 1.183
sys/netinet6/ip6_output.c: 1.196
sys/netinet6/mld6.c: 1.90
sys/netinet6/nd6.c: 1.239-1.240
sys/netinet6/nd6_nbr.c: 1.139
sys/netinet6/nd6_rtr.c: 1.136
sys/netipsec/ipsec_output.c: 1.65
sys/rump/net/lib/libnetinet/netinet_component.c: 1.9-1.10
kmem_intr_free kmem_intr_[z]alloced memory
the underlying pools are the same but api-wise those should match
Unify IFEF_*_MPSAFE into IFEF_MPSAFE
There are already two flags for if_output and if_start, however, it seems such
MPSAFE flags are eventually needed for all if_XXX operations. Having discrete
flags for each operation is wasteful of if_extflags bits. So let's unify
the flags into one: IFEF_MPSAFE.
Fortunately IFEF_*_MPSAFE flags have never been included in any releases, so
we can change them without breaking backward compatibility of the releases
(though the kernel version of -current should be bumped).
Note that if an interface have both MP-safe and non-MP-safe operations at a
time, we have to set the IFEF_MPSAFE flag and let callees of non-MP-safe
opeartions take the kernel lock.
Proposed on tech-kern@ and tech-net@
Provide macros for softnet_lock and KERNEL_LOCK hiding NET_MPSAFE switch
It reduces C&P codes such as "#ifndef NET_MPSAFE KERNEL_LOCK(1, NULL); ..."
scattered all over the source code and makes it easy to identify remaining
KERNEL_LOCK and/or softnet_lock that are held even if NET_MPSAFE.
No functional change
Hold KERNEL_LOCK on if_ioctl selectively based on IFEF_MPSAFE
If IFEF_MPSAFE is set, hold the lock and otherwise don't hold.
This change requires additions of KERNEL_LOCK to subsequence functions from
if_ioctl such as ifmedia_ioctl and ifioctl_common to protect non-MP-safe
components.
Proposed on tech-kern@ and tech-net@
Ensure to hold if_ioctl_lock when calling if_flags_set
Fix locking against myself on ifpromisc
vlan_unconfig_locked could be called with holding if_ioctl_lock.
Ensure to not turn on IFF_RUNNING of an interface until its initialization completes
And ensure to turn off it before destruction as per IFF_RUNNING's description
"resource allocated". (The description is a bit doubtful though, I believe the
change is still proper.)
Ensure to hold if_ioctl_lock on if_up and if_down
One exception for if_down is if_detach; in the case the lock isn't needed
because it's guaranteed that no other one can access ifp at that point.
Make if_link_queue MP-safe if IFEF_MPSAFE
if_link_queue is a queue to store events of link state changes, which is
used to pass events from (typically) an interrupt handler to
if_link_state_change softint. The queue was protected by KERNEL_LOCK so far,
but if IFEF_MPSAFE is enabled, it becomes unsafe because (perhaps) an interrupt
handler of an interface with IFEF_MPSAFE doesn't take KERNEL_LOCK. Protect it
by a spin mutex.
Additionally with this change KERNEL_LOCK of if_link_state_change softint is
omitted if NET_MPSAFE is enabled.
Note that the spin mutex is now ifp->if_snd.ifq_lock as well as the case of
if_timer (see the comment).
Use IFADDR_WRITER_FOREACH instead of IFADDR_READER_FOREACH
At that point no other one modifies the list so IFADDR_READER_FOREACH
is unnecessary. Use of IFADDR_READER_FOREACH is harmless in general though,
if we try to detect contract violations of pserialize, using it violates
the contract. So avoid using it makes life easy.
Ensure to call if_addr_init with holding if_ioctl_lock
Get rid of outdated comments
Fix build of kernels without ether
By throwing out if_enable_vlan_mtu and if_disable_vlan_mtu that
created a unnecessary dependency from if.c to if_ethersubr.c.
PR kern/52790
Rename IFNET_LOCK to IFNET_GLOBAL_LOCK
IFNET_LOCK will be used in another lock, if_ioctl_lock (might be renamed then).
Wrap if_ioctl_lock with IFNET_* macros (NFC)
Also if_ioctl_lock perhaps needs to be renamed to something because it's now
not just for ioctl...
Reorder some destruction routines in if_detach
- Destroy if_ioctl_lock at the end of the if_detach because it's used in various
destruction routines
- Move psref_target_destroy after pr_purgeif because we want to use psref in
pr_purgeif (otherwise destruction procedures can be tricky)
Ensure to call if_mcast_op with holding IFNET_LOCK
Note that CARP doesn't deal with IFNET_LOCK yet.
Remove IFNET_GLOBAL_LOCK where it's unnecessary because IFNET_LOCK is held
Describe which lock is used to protect each member variable of struct ifnet
Requested by skrll@
Write a guideline for converting an interface to IFEF_MPSAFE
Requested by skrll@
Note that IFNET_LOCK must not be held in softint
Don't set IFEF_MPSAFE unless NET_MPSAFE at this point
Because recent investigations show that interfaces with IFEF_MPSAFE need to
follow additional restrictions to work with the flag safely. We should enable it
on an interface by default only if the interface surely satisfies the
restrictions, which are described in if.h.
Note that enabling IFEF_MPSAFE solely gains a few benefit on performance because
the network stack is still serialized by the big kernel locks by default.
 1.242.6.1  24-Oct-2017  snj Pull up following revision(s) (requested by knakahara in ticket #302):
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.30-1.31
sys/arch/x86/pci/if_vmx.c: 1.20
sys/dev/ic/i82557.c: 1.148
sys/dev/ic/rtl8169.c: 1.152
sys/dev/pci/cxgb/cxgb_sge.c: 1.5
sys/dev/pci/if_age.c: 1.51
sys/dev/pci/if_alc.c: 1.25
sys/dev/pci/if_ale.c: 1.23
sys/dev/pci/if_bge.c: 1.311
sys/dev/pci/if_bge.c: 1.312
sys/dev/pci/if_bnx.c: 1.62
sys/dev/pci/if_jme.c: 1.32
sys/dev/pci/if_nfe.c: 1.64
sys/dev/pci/if_sip.c: 1.167
sys/dev/pci/if_stge.c: 1.63-1.64
sys/dev/pci/if_ti.c: 1.102
sys/dev/pci/if_txp.c: 1.48
sys/dev/pci/if_vge.c: 1.61
sys/dev/pci/if_wm.c: 1.538
sys/dev/pci/ixgbe/ix_txrx.c: 1.29 via patch
sys/net/agr/if_agrether_hash.c: 1.4
sys/net/if_ether.h: 1.67-1.68
sys/net/if_ethersubr.c: 1.244
sys/net/if_vlan.c: 1.100
sys/net80211/ieee80211_input.c: 1.89
sys/net80211/ieee80211_output.c: 1.59
sys/sys/mbuf.h: 1.171
VLAN ID uses pkthdr instead of mtag now. Contributed by s-yamaguchi@IIJ.
I just commit by proxy. Reviewed by joerg@n.o and christos@n.o, thanks.
See http://mail-index.netbsd.org/tech-net/2017/09/26/msg006459.html
--
only get vtag when we have vtag like the other drivers.
--
- only get the vtag if we have it like the other drivers
- mask the hardware vlan tag
--
- add a constant for the vlan mask.
- enforce that we have a tag before we get it.
only get vtag when we have vtag like the other drivers.
like if_bge.c:1.312 and if_stge.c:1.64.
fixed by s-yamaguchi@IIJ, thanks.
 1.260.2.6  26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.260.2.5  26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.260.2.4  25-Jun-2018  pgoyette Sync with HEAD
 1.260.2.3  21-May-2018  pgoyette Sync with HEAD
 1.260.2.2  02-May-2018  pgoyette Synch with HEAD
 1.260.2.1  16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.270.2.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.270.2.1  10-Jun-2019  christos Sync with HEAD
 1.276.2.2  25-Oct-2021  martin Pull up following revision(s) (requested by ryo in ticket #1369):

sys/net/if_ethersubr.c: revision 1.302

frame's vlan tag must be ntohs()'ed.

VLAN 0 Priority tag was misrecognized on non vlan-hwtagging interfaces.
 1.276.2.1  08-Oct-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #292):

sys/net/if_ethersubr.c: revision 1.277
sys/net/if_ethersubr.c: revision 1.278

Increment if_iqdrops when dropping an oversized frame.

-

Print oversized frame's message only when DIAGNOSTIC is set. The message
is not so important because we increment if_iqdrops now.
 1.280.2.2  29-Feb-2020  ad Sync with head.
 1.280.2.1  17-Jan-2020  ad Sync with head.
 1.289.2.1  03-Apr-2021  thorpej Sync with HEAD.
 1.292.6.1  31-May-2021  cjep sync with head
 1.292.4.1  17-Jun-2021  thorpej Sync w/ HEAD.
 1.323.2.1  03-Nov-2023  martin Pull up following revision(s) (requested by yamaguchi in ticket #455):
sys/dev/pci/ixgbe/ixgbe.c: revision 1.347
sys/net/if_l2tp.c: revision 1.49
tests/net/if_vlan/t_vlan.sh: revision 1.25
sys/net/if_vlan.c: revision 1.171
sys/net/if_ethersubr.c: revision 1.326
sys/dev/pci/ixgbe/ixv.c: revision 1.194
Use ether_bpf_mtap only when the device supports vlan harware tagging
The function is bpf_mtap() for ethernet devices and *currently*
it is just handling VLAN tag stripped by the hardware.
l2tp(4): use ether_ifattach() to initialize ethercom
Support vlan(4) over l2tp(4)
Added the test for vlan over l2tp
 1.326.4.1  02-Aug-2025  perseant Sync with HEAD
 1.326.2.1  11-Nov-2023  thorpej branches: 1.326.2.1.2;
Mostly de-tangle ifnet::if_snd from ifaltq, in a way that's minimally-
invasive to the ALTQ code itself.

The point of this is to lay the groundwork for future changes to ifqueue,
which among other benefits, will also hide the ALTQ ABI from drivers.
 1.326.2.1.2.2  16-Nov-2023  thorpej Clean up the locking protocol around altq_etherclassify(). It's no longer
required to acquire KERNEL_LOCK *just* because ALTQ is compiled into the
kernel; you only have to acquire it if ALTQ is enabled on the interface
in question.
 1.326.2.1.2.1  15-Nov-2023  thorpej Rename ifq_enqueue() -> if_enqueue(), ifq_enqueue2() -> if_enqueue2().

RSS XML Feed