History log of /netbsd-current/sys/net/if_ethersubr.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.326 02-Nov-2023 yamaguchi

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.


Revision tags: netbsd-10-base
# 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.


Revision tags: bouyer-sunxi-drm-base
# 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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.324 20-Oct-2023 msaitoh

Print error message when the multicast bit is set in the MAC address.


Revision tags: netbsd-10-base
# 1.323 15-Nov-2022 roy

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.


Revision tags: bouyer-sunxi-drm-base
# 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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.323 15-Nov-2022 roy

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.


Revision tags: bouyer-sunxi-drm-base
# 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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: bouyer-sunxi-drm-base
# 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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 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


Revision tags: cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.292 14-Feb-2021 roy

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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.292 14-Feb-2021 roy

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


Revision tags: thorpej-futex-base
# 1.289 26-Sep-2020 roy

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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: thorpej-futex-base
# 1.289 26-Sep-2020 roy

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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.289 26-Sep-2020 roy

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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.284 30-Apr-2020 riastradh

Convert ether_input from rnd_initial_entropy to entropy_epoch().


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406
# 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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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).


Revision tags: ad-namecache-base3
# 1.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.282 29-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1
# 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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: ad-namecache-base phil-wifi-20191119
# 1.280 16-Oct-2019 christos

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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.280 16-Oct-2019 christos

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.


Revision tags: netbsd-9-base
# 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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: netbsd-9-base
# 1.276 17-Jul-2019 msaitoh

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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.277 01-Oct-2019 msaitoh

Increment if_iqdrops when dropping an oversized frame.


Revision tags: netbsd-9-base
# 1.276 17-Jul-2019 msaitoh

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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.276 17-Jul-2019 msaitoh

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.


Revision tags: phil-wifi-20190609
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.270 14-Jun-2018 yamaguchi

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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.270 14-Jun-2018 yamaguchi

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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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


Revision tags: isaki-audio2-base
# 1.273 04-Feb-2019 mrg

add or adjust fallthru comments.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.272 21-Dec-2018 msaitoh

Add SIOCSETHERCAP. It's used to change ec_capenable.


Revision tags: pgoyette-compat-1126
# 1.271 15-Nov-2018 maxv

Remove the 't' argument from m_tag_find().


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.270 14-Jun-2018 yamaguchi

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.


Revision tags: pgoyette-compat-0521
# 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.


Revision tags: pgoyette-compat-0502
# 1.265 29-Apr-2018 maxv

Remove references to m_copy in comments.


# 1.264 26-Apr-2018 maxv

m_copy -> m_copym


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: tls-maxphys-base-20171202
# 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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: nick-nhusb-base-20170825
# 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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.242 06-Apr-2017 ozaki-r

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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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


Revision tags: perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.242 06-Apr-2017 ozaki-r

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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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


Revision tags: prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.242 06-Apr-2017 ozaki-r

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.


Revision tags: pgoyette-localcount-20170320
# 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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4; 1.204.6;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 1.235 13-Jan-2017 msaitoh

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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: nick-nhusb-base-20170204
# 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.


Revision tags: bouyer-socketcan-base
# 1.235 13-Jan-2017 msaitoh

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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

branches: 1.204.2; 1.204.4;
Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: bouyer-socketcan-base
# 1.235 13-Jan-2017 msaitoh

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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.235 13-Jan-2017 msaitoh

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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: pgoyette-localcount-20170107
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104
# 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@


Revision tags: nick-nhusb-base-20161004
# 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@


Revision tags: localcount-20160914 pgoyette-localcount-20160806
# 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.


Revision tags: pgoyette-localcount-20160726
# 1.226 25-Jul-2016 rjs

Restore correct test for return value from aarpresolve().


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 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


Revision tags: nick-nhusb-base-20160529
# 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.


Revision tags: nick-nhusb-base-20160422
# 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


Revision tags: nick-nhusb-base-20160319
# 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!


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 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.


Revision tags: nick-nhusb-base-20150406
# 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.


Revision tags: nick-nhusb-base
# 1.205 28-Nov-2014 ozaki-r

branches: 1.205.2;
Remove dead codes and make if_free_sadl static

No functional change.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-maxphys-base
# 1.204 10-Aug-2014 tls

Merge tls-earlyentropy branch into HEAD.


Revision tags: tls-earlyentropy-base
# 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.


Revision tags: rmind-smpnet-nbase rmind-smpnet-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.196 25-Feb-2014 pooka

branches: 1.196.2;
If the in6 domain was not attached, do not attempt to process IPv6 packets.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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.


Revision tags: agc-symver-base
# 1.194 01-Mar-2013 joerg

branches: 1.194.6;
Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 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


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5
# 1.189 11-May-2012 chs

in ether_ifdetach(), clear if_mowner before releasing what it points to.
fixes PR 42982.


Revision tags: jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.188 16-Jun-2011 kefren

branches: 1.188.2; 1.188.6; 1.188.8;
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 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.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base
# 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?)


Revision tags: matt-mips64-premerge-20101231
# 1.184 17-Nov-2010 dyoung

Cosmetic: fix indentation.


Revision tags: uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1
# 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.


Revision tags: yamt-nfs-mp-base9 uebayasi-xip-base
# 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.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 jym-xensuspend-nbase
# 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@.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 jym-xensuspend-base
# 1.171 28-Apr-2009 dyoung

Let this build with 'no options INET'.

(I don't know why I bothered, either.)


Revision tags: nick-hppapmap-base3 nick-hppapmap-base2 haad-dm-base2 haad-nbase2 ad-audiomp2-base nick-hppapmap-base haad-dm-base mjf-devfs2-base
# 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.


Revision tags: matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2 wrstuden-revivesa-base
# 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.


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: nick-net80211-sync-base hpcarm-cleanup-base
# 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)


Revision tags: mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.160 19-Jan-2008 dyoung

Add default handling of SIOCSIFMEDIA/SIOCGIFMEDIA.


Revision tags: matt-armv6-base
# 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.


Revision tags: vmlocking2-base3
# 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.


Revision tags: yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase yamt-x86pmap-base4 bouyer-xenamd64-base yamt-x86pmap-base3 jmcneill-pm-base reinoud-bufcleanup-base vmlocking-base
# 1.156 08-Oct-2007 ad

branches: 1.156.4; 1.156.6; 1.156.10;
Use the softint API.


Revision tags: yamt-x86pmap-base2 yamt-x86pmap-base
# 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).


Revision tags: nick-csl-alignment-base5
# 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.


Revision tags: matt-mips64-base
# 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.


Revision tags: nick-csl-alignment-base
# 1.150 14-Jul-2007 ad

branches: 1.150.2;
Generic soft interrupts are mandatory.


Revision tags: mjf-ufs-trans-base
# 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.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base
# 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.


Revision tags: ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge newlock2-nbase newlock2-base
# 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


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4
# 1.141 10-Dec-2006 is

explain XID constants, and fix a wrong one


# 1.140 10-Dec-2006 is

comment on llc class


Revision tags: yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2 yamt-splraiseipl-base yamt-pdpolicy-base9 rpaulo-netinet-merge-pcb-base
# 1.136 07-Sep-2006 dogcow

branches: 1.136.2; 1.136.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7
# 1.135 05-Aug-2006 pavel

defflag PPPOE_SERVER and PPPOE_TERM_UNKNOWN_SESSIONS.


Revision tags: yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base
# 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


Revision tags: yamt-pdpolicy-base5 simonb-timecounters-base
# 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.)


Revision tags: elad-kernelauth-base
# 1.130 15-Apr-2006 christos

Coverity CID 1145: Protect against NULL deref.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base
# 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.


Revision tags: yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 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.


Revision tags: kent-audio2-base
# 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


Revision tags: yamt-km-base4 yamt-km-base3
# 1.121 18-Mar-2005 yamt

add agr(4), a pseudo network device driver for link aggregation.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.120 26-Feb-2005 perry

branches: 1.120.2; 1.120.4; 1.120.6;
nuke trailing whitespace


Revision tags: yamt-km-base2
# 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.


Revision tags: yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 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


Revision tags: fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.99 11-Sep-2002 itojun

KNF - return is not a function.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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.


Revision tags: eeh-devprop-base newlock-base
# 1.92 05-Mar-2002 itojun

bring in latest ALTQ from kjc. ALTQify some of the drivers.


Revision tags: ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.89 17-Oct-2001 itojun

unifdef OLDIP6OUTPUT


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base
# 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.


Revision tags: thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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().


Revision tags: netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base
# 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).


Revision tags: minoura-xpg4dl-base
# 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.


Revision tags: chs-ubc2-newbase
# 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.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 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...)


Revision tags: comdex-fall-1999-base fvdl-softdep-base
# 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.


Revision tags: chs-ubc2-base
# 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.


Revision tags: netbsd-1-4-RELEASE netbsd-1-4-base
# 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.


Revision tags: kenh-if-detach-base chs-ubc-base
# 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.


Revision tags: eeh-paddr_t-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base marc-pcmcia-base
# 1.26 02-Oct-1997 is

Reimplement a test for broadcast addresses advertized, which was left out
when rewriting the ARP system.


Revision tags: thorpej-signal-base marc-pcmcia-bp
# 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.


Revision tags: is-newarp-before-merge is-newarp-base
# 1.21 13-Oct-1996 christos

branches: 1.21.4;
backout previous kprintf change


# 1.20 10-Oct-1996 christos

- printf -> kprintf, sprintf -> ksprintf


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: magnum-base netbsd-0-9-patch-001 netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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