Home | History | Annotate | Download | only in net
History log of /src/sys/net/if_vlan.c
RevisionDateAuthorComments
 1.172  29-Jun-2024  riastradh if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.171  02-Nov-2023  yamaguchi branches: 1.171.2;
Support vlan(4) over l2tp(4)
 1.170  20-Jun-2022  yamaguchi branches: 1.170.4;
bridge(4): support VLAN frames stripped by hardware tagging
 1.169  20-Jun-2022  yamaguchi Determine the length of VLAN encapsulation by an interface type,
and remove it from struct ifvlan_linkmib
 1.168  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.167  24-Dec-2021  yamaguchi Fix missing curlwp_bind()

Fixes kern/56556
 1.166  06-Dec-2021  yamaguchi decrease the MTU of vlan(4)
only when ETHERCAP_VLAN_MTU of the parent interface is enabled

This fixed the bug that the MTU of a vlan interface is decreased
when the parent interface already has another vlan interface.
pointed out by tnn@n.o, thanks.
 1.165  15-Nov-2021  yamaguchi introduced APIs to configure VLAN TAG to ethernet devices
 1.164  05-Oct-2021  yamaguchi Replace the list for vlan interfaces with the counter

The list had been used in vlan_ifdetach(), but it is no longer in
use as a linked list by introducing ether_ifdetach hook.
 1.163  30-Sep-2021  yamaguchi vlan: Register vlan_ifdetach to ether_ifdetach hook
 1.162  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.161  17-Jul-2021  hannken Mark vlan_safe_ifpromisc_locked() as "__unused" to appease LLVM.

Maybe completely remove this short helper?
 1.160  15-Jul-2021  yamaguchi vlan: drop tagged outgoing packets

vlan(4) doesn't support Q-in-Q yet.
 1.159  14-Jul-2021  yamaguchi unset IFF_PROMISC at bpf_detach()

Doing "d->bd_promisc = 0" is that bpf_detach() does not call
ifpromisc(ifp, 0). Currently, there is no reason for
this behavior so that it is removed.
In addition to the change, the workaround for it in vlan(4)
is also removed.
 1.158  14-Jul-2021  yamaguchi Make an mbuf writable before un-tagging
 1.157  06-Jul-2021  yamaguchi Drop unicast packets that are not for us
when vlan(4) is not in promisc
 1.156  06-Jul-2021  yamaguchi vlan: added NULL check for the parent interface

The pointer may set to NULL by vlan_unconfig
while packet processing
 1.155  06-Jul-2021  yamaguchi vlan: set the link state to DOWN when its parent detaches
 1.154  16-Jun-2021  riastradh if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around. And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail. (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint. This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken. However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.
 1.153  26-Sep-2020  roy branches: 1.153.6;
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.152  12-Jun-2020  roy Remove in-kernel handling of Router Advertisements

This is much better handled by a user-land tool.
Proposed on tech-net here:
https://mail-index.netbsd.org/tech-net/2020/04/22/msg007766.html

Note that the ioctl SIOCGIFINFO_IN6 no longer sets flags. That now
needs to be done using the pre-existing SIOCSIFINFO_FLAGS ioctl.

Compat is fully provided where it makes sense, but trying to turn on
RA handling will obviously throw an error as it no longer exists.

Note that if you use IPv6 temporary addresses, this now needs to be
turned on in dhcpcd.conf(5) rather than in sysctl.conf(5).
 1.151  01-Feb-2020  riastradh Switch if_vlan to atomic_load/store_*.

Fix missing membar_datadep_consumer -- now atomic_load_consume -- in
vlan_lookup_tag_psref.
 1.150  29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.149  12-Dec-2019  pgoyette branches: 1.149.2;
Rather than keeping a separate mutex, condvar, and pserialize for each
module hook, we can share a common set of synchronization structures.
This cuts the amount of cacheline_aligned data for these structures by
50%.

Note that we still have a per-hook localcount, since we need to count
individual references.

As discussed with riastradh@

Welcome to 9.99.22 !
 1.148  11-Nov-2019  yamaguchi Fix a bug that vlan(4) fragments IPv6 packets
even the MTU > packet length.

The bug is appeared when the mtu is increased on SIOCSETVLAN.

From t-kusaba@IIJ
 1.147  21-Oct-2019  ozaki-r vlan: get rid of unnecessary if_ipackets++ in vlan_input

It's done by if_input() below now.

Pointed out by msaitoh@
 1.146  23-Aug-2019  msaitoh - kmem_alloc(,KM_SLEEP) never return NULL, so remove NULL check.
- VLAN ID is never duplicated, so break the loop when found. Also move
kmen_free() outside of ETHER_LOCK(ec)/ETHER_UNLOCK(ec) to reduce the hold
time. suggested by ozaki-r.
- Whitespace fix.
 1.145  21-Aug-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() suggested by knakahara.
 1.144  20-Aug-2019  msaitoh Fix a bug that VLAN HW "tagging" enable/disable may not refrect correctly.

- Always call ec_vlan_cb() if it exists.
- Some (or all?) ethernet drivers don't enable HW tagging if no any vlan is
attached. ixgbe is one of them. Check the the transition and update
VLAN HW tagging function.

XXX pullup-9
 1.143  20-Aug-2019  msaitoh Add missing IFNET_LOCK() and IFNET_UNLOCK() in vlan_config().

XXX pullup-9
 1.142  20-Aug-2019  msaitoh Check ec_capenable instead of ec_capabilities to control TX side of VLAN HW
tagging correctly.

XXX pullup-9
 1.141  17-Jul-2019  msaitoh branches: 1.141.2;
Implement VLAN hardware filter function(ETHERCAP_VLAN_HWFILTER).
First proposed by jmcneill in 2017 and modified by me.

How to use:

- Set callback function:

ether_set_vlan_cb(struct ethercom *, ether_vlancb_t)

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

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

- ifconfig(8)

ifconfig ixg0 [-]vlan-hwfilter

Note that ETHERCAP_VLAN_HWFILTER is set by default on ixg(4) because
the PF driver usually enable "all block" filter by default.
 1.140  17-Jul-2019  msaitoh KNF. No functional change.
 1.139  09-Jul-2019  msaitoh Don't automatically set ec_capenable's ETHERCAP_VLAN_HWTAGGING bit in
vlan_config() to make it user-controllable. Instead, set the bit in
xxx_attach().
 1.138  25-Jun-2019  msaitoh Simplify "LIST_HEAD();" to make the code more understandable.
No functional change.
 1.137  18-Jun-2019  msaitoh KNF. No functional change.
 1.136  15-May-2019  ozaki-r Get rid of IFNET_LOCK for if_mcast_op to avoid a deadlock

The IFNET_LOCK was added to avoid data races on if_flags for IFF_ALLMULTI.
Unfortunatetly it caused a deadlock instead. A known scenario causing a
deadlock is to occur the following two operations concurrently: (a) a removal of
an IP adddres assigned to an interface and (b) a manipulation of multicast
groups to the interface. The resource dependency graph is like this:
softnet_lock => IFNET_LOCK => psref_target_destroy => softint => softnet_lock

Thanks to the previous commit that avoids data races on if_flags for
IFF_ALLMULTI by another approach, we can remove IFNET_LOCK and defuse the
deadlock.

PR kern/54189
 1.135  26-Apr-2019  pgoyette Some more empty-string --> NULL conversions for module dependencies
 1.134  23-Mar-2019  pgoyette Replace compile-time checking for vlan code with a module hook.

Should resolve the errors reported on irc when booting a kernel which
has agr without vlan:


[ 1.0000000] WARNING: module error: built-in module if_agr can't find builtin dependency `if_vlan'
[ 1.0000000] WARNING: module error: built-in module if_agr prerequisite if_vlan failed, error 2
 1.133  19-Oct-2018  knakahara Fix panic when doing ioctl to multiple pseudo interfaces. Pointed out by k-goda@IIJ.

XXX pullup-8
 1.132  18-Oct-2018  knakahara fix panic when do ifconfig -vlanif and ifconfig vlanif again. advised by ozaki-r@.

e.g. do the following commands.
====================
# ifconfig vlan0 create
# ifconfig vlan0 vlan 100 vlanif wm0
# ifconfig vlan0 -vlanif wm0
# ifconfig vlan0 vlan 100 vlanif wm0
====================

ATF net/if_vlan do this type of test, however it cannot detect this bug.
Because the shmif(4)'s ifp->if_hwdl is always NULL as shmif(4)'s ethernet
address is set U/L bit.
See: https://nxr.netbsd.org/xref/src/sys/net/if_ethersubr.c#997
 1.131  03-Aug-2018  jmcneill Use a different psz for a different lock. Patch from riastradh, reviewed
by ozaki-r.
 1.130  26-Jun-2018  msaitoh branches: 1.130.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.129  14-Jun-2018  yamaguchi Fix to check whether the address has been added before delete

The list named ifv_mc_listhead saves multicast addresses that
are added through SIOCADDMULTI. Each nodes added to the list
are used for deleting the related address from a parent I/F
when remove the configuration of parent I/F.
In carp(4) and OpenBSD's vlan(4), the lists is used to check
a parameter of SIOCDELMULTI in addition to the use.
Based on them, the check is added to vlan(4)

ok ozaki-r@
 1.128  14-Jun-2018  yamaguchi Add the lock to refer the list included in ethercom for safety

The lock is already held while adding and deleting
ok ozaki-r@
 1.127  14-Jun-2018  yamaguchi Use ether_lookup_multi() instead of the macro

ok ozaki-r@
 1.126  12-Jun-2018  ozaki-r vlan: call ether_ifdetach without IFNET_LOCK

Fix PR kern/53357
 1.125  16-Mar-2018  tih Fix the handling of the state returned from pfil_run_hooks().

pfil_run_hooks() invokes any registered packet filters on the packet
being handled. It may return a (non-zero) errno, indicating that a
filter has decided that the packet should be discarded, and has freed
the mbuf. While a non-error (0) return usually means that the packet
should be processed normally, a filter may still free the mbuf if the
packet is a fragment, and the filter is holding it for reassembly and
future evaluation. Therefore, there must be separate tests for the
return value and for a possible discarded packet. (See pfil(9).)

OK: christos, martin
 1.124  15-Jan-2018  maxv branches: 1.124.2;
Mostly style, and add a bunch of KASSERTs.
 1.123  15-Jan-2018  maxv Style, improve comment, and add KASSERTs on the assumptions.
 1.122  14-Jan-2018  maxv If cnt == 0, don't kmem_alloc(0). Found by Mootja.

Looking at the code, I also find it suspicious that we read
ifv->ifv_mib->ifvm_p directly without making sure ifv_mib != NULL.
 1.121  19-Dec-2017  ozaki-r Don't set IFEF_MPSAFE unless NET_MPSAFE at this point

Because recent investigations show that interfaces with IFEF_MPSAFE need to
follow additional restrictions to work with the flag safely. We should enable it
on an interface by default only if the interface surely satisfies the
restrictions, which are described in if.h.

Note that enabling IFEF_MPSAFE solely gains a few benefit on performance because
the network stack is still serialized by the big kernel locks by default.
 1.120  15-Dec-2017  ozaki-r Ensure to call if_mcast_op with holding IFNET_LOCK

Note that CARP doesn't deal with IFNET_LOCK yet.
 1.119  11-Dec-2017  ozaki-r Wrap if_ioctl_lock with IFNET_* macros (NFC)

Also if_ioctl_lock perhaps needs to be renamed to something because it's now
not just for ioctl...
 1.118  08-Dec-2017  ozaki-r Fix build of kernels without ether

By throwing out if_enable_vlan_mtu and if_disable_vlan_mtu that
created a unnecessary dependency from if.c to if_ethersubr.c.

PR kern/52790
 1.117  06-Dec-2017  ozaki-r Ensure to hold if_ioctl_lock on if_up and if_down

One exception for if_down is if_detach; in the case the lock isn't needed
because it's guaranteed that no other one can access ifp at that point.
 1.116  06-Dec-2017  ozaki-r Ensure to not turn on IFF_RUNNING of an interface until its initialization completes

And ensure to turn off it before destruction as per IFF_RUNNING's description
"resource allocated". (The description is a bit doubtful though, I believe the
change is still proper.)
 1.115  06-Dec-2017  ozaki-r Fix locking against myself on ifpromisc

vlan_unconfig_locked could be called with holding if_ioctl_lock.
 1.114  06-Dec-2017  ozaki-r Ensure to hold if_ioctl_lock when calling if_flags_set
 1.113  27-Nov-2017  jmcneill kern/52765: npf cannot do port forwarding on vlan interfaces

Add pfil hooks support to vlan(4), from christos@
 1.112  22-Nov-2017  msaitoh s/65535/4095/ in the comment. Pointed out by christos. Thanks.
 1.111  22-Nov-2017  msaitoh Return EINVAL in vlan_config() when a VLAN ID is 0 or 65535. The spec states
0 and 65535 are reserved.
 1.110  22-Nov-2017  msaitoh No functional change:
- u_int16_t -> uint16_t
- u_short -> uint16_t
- tag_hash_func -> vlan_tag_hash
- 0 -> NULL because vlr_parent is a pointer.
 1.109  22-Nov-2017  ozaki-r Hold KERNEL_LOCK on if_ioctl selectively based on IFEF_MPSAFE

If IFEF_MPSAFE is set, hold the lock and otherwise don't hold.

This change requires additions of KERNEL_LOCK to subsequence functions from
if_ioctl such as ifmedia_ioctl and ifioctl_common to protect non-MP-safe
components.

Proposed on tech-kern@ and tech-net@
 1.108  22-Nov-2017  msaitoh Fix a bug that a vlan packet which has priority or CFI bit in the tag causes
panic.
 1.107  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.106  30-Oct-2017  ozaki-r Set IFEF_NO_LINK_STATE_CHANGE flag to pseudo devices that don't use if_link_state_change
 1.105  23-Oct-2017  msaitoh If if_initialize() failed in the attach function, free resources and return.
 1.104  19-Oct-2017  knakahara fix vlan panic when vlan is re-configured without destroy.

E.g. the following operation causes this panic.
====================
# ifconfig vlan0 create
# ifconfig vlan0 vlan 1 vlanif ixg3
# ifconfig vlan1 create
# ifconfig vlan1 vlan 1 vlanif ixg2
# ifconfig vlan1 -vlanif
# ifconfig vlan1 vlan 1 vlanif ixg2

panic: kernel diagnostic assertion "new->ple_next == NULL" failed: file "/git/netbsd-src/sys/sys/pslist.h", line 118
====================

Pointed out and tested by msaitoh@n.o, fixed by s-yamaguchi@IIJ, thanks.

XXX need pullup-8
 1.103  12-Oct-2017  ozaki-r Set IFEF_START_MPSAFE by default

Because vlan_start is already MP-safe, there is no reason to not do so.

Acked by s-yamaguchi@IIJ
 1.102  11-Oct-2017  msaitoh Remove accidentally added code (for VLAN hardware filter).
 1.101  11-Oct-2017  msaitoh Check if VLAN ID isn't duplicated on a same parent interface and return
EEXIST if it failed.
 1.100  26-Sep-2017  knakahara VLAN ID uses pkthdr instead of mtag now. Contributed by s-yamaguchi@IIJ.

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

XXX need pullup to -8 branch
 1.99  09-Aug-2017  knakahara Fix vlan(4) obytes counter. Implemented by s-yamaguchi@IIJ, thanks.
 1.98  07-Jun-2017  knakahara vlan(4) MP-ify. contributed by s-yamaguchi@IIJ, thanks.

XXX Pull-ups needed for netbsd-8 branch
 1.97  29-May-2017  ozaki-r branches: 1.97.2;
Call in6_ifdetach only if in6_present (for rump)

Otherwise ifconfig -vlanif causes a panic on a rump_server without
the netinet6 library.

Reported by s-yamaguchi@IIJ
 1.96  15-Mar-2017  ozaki-r Fix memory leak in vlan_start
 1.95  23-Jan-2017  ozaki-r Fix typo in a comment
 1.94  13-Jan-2017  msaitoh branches: 1.94.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.93  15-Dec-2016  ozaki-r Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.92  28-Nov-2016  joerg Don't check parent capabilities when a parent interface hasn't been
assigned.
 1.91  07-Aug-2016  christos modularize some more drivers and merge the module glue
 1.90  22-Jun-2016  knakahara branches: 1.90.2;
fix: locking about IFQ_ENQUEUE and ALTQ

- If NET_MPSAFE is not defined, IFQ_LOCK is nop. Currently, that means
IFQ_ENQUEUE() of some paths such as bridge_enqueue() is called parallel
wrongly.
- If ALTQ is enabled, Tx processing should call if_transmit() (= IFQ_ENQUEUE
+ ifp->if_start()) instead of ifp->if_transmit() to call ALTQ_ENQUEUE()
and ALTQ_DEQUEUE().
Furthermore, ALTQ processing is always required KERNEL_LOCK currently.
 1.89  10-Jun-2016  ozaki-r Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.88  09-May-2016  christos Don't increment the reference count only when it was 0...
From Jean-Jacques.Puig
 1.87  28-Apr-2016  knakahara introduce new ifnet MP-scalable sending interface "if_transmit".
 1.86  20-Apr-2016  knakahara IFQ_ENQUEUE refactor (3/3) : eliminate pktattr argument from IFQ_ENQUEUE caller
 1.85  20-Apr-2016  knakahara IFQ_ENQUEUE refactor (2/3) : eliminate pktattr argument from altq implemantation
 1.84  09-Feb-2016  ozaki-r Introduce softint-based if_input

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

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

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

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

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.83  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.82  20-Aug-2015  christos include "ioconf.h" to get the 'void <driver>attach(int count);' prototype.
 1.81  18-Apr-2015  ozaki-r Count up parent's obytes and omcasts counters

PR kern/49837
 1.80  29-Mar-2015  ozaki-r Correct frame padding length

vlan pads a frame with zeros up to 68 bytes
(ETHER_MIN_LEN + ETHER_VLAN_ENCAP_LEN). It expects
that even if the frame is untagged, it keeps 64 bytes
at least. However, it lacks concern about CRC
(4 bytes). So a sending frame can be 72 (68 + 4) bytes.

PR 49788
 1.79  16-Jan-2015  ozaki-r Introduce defflag for NET_MPSAFE
 1.78  11-Oct-2014  ozaki-r branches: 1.78.2;
Execute if_detach within splnet where vlan_unconfig is

With the fix, a ifnet data of vlan can avoid use after free
that results in a fatal page fault.

This problem was found when fixing PR 49264. See
http://mail-index.netbsd.org/netbsd-bugs/2014/10/10/msg038536.html
for more detail.
 1.77  11-Oct-2014  ozaki-r Tweak vlan_unconfig

No functional change.
 1.76  11-Oct-2014  ozaki-r Protect vlan_unconfig with a mutex

It is not thread-safe but is likely to be executed in concurrent.
See PR 49264 for more detail.
 1.75  09-Oct-2014  ozaki-r Do KASSERT(KERNEL_LOCKED_P()) only when NET_MPSAFE off

When NET_MPSAFE, bridge_enqueue calls vlan_start w/o KERNEL_LOCK.
 1.74  15-Sep-2014  ozaki-r Delete link local addresses of a vlan interface when detaching its parent

This fixes PR 49197.
 1.73  15-Sep-2014  ozaki-r Leave promiscuous mode when detaching a parent (ifconfig -vlanif)

We have to call ifpromisc(ifp, 0) for both a VLAN interface
and its parent when they are in promiscuous mode.

PR 49196
 1.72  12-Sep-2014  ozaki-r Call if_input of vlan interface itself, not parent's one

And also we need to drop M_PROMISC before calling if_input;
it was originally at just before bridge_input in ether_input.

Then we can bridge vlan interfaces again.
 1.71  12-Sep-2014  ozaki-r Restore vlan_ioctl overwritten by ether_ifdetach in vlan_unconfig

This fixes PR 49112.
 1.70  13-May-2014  bouyer branches: 1.70.2;
Make sure *(if_output)() is called with KERNEL_LOCK held.
Add some KASSERT for this.
See http://mail-index.netbsd.org/tech-net/2014/04/09/msg004511.html
for details.
 1.69  19-Oct-2011  dyoung branches: 1.69.8; 1.69.12; 1.69.14; 1.69.16; 1.69.22; 1.69.26;
Use if_flags_set() and if_mcast_op().
 1.68  19-Oct-2011  dyoung Use if_mcast_op() and if_flags_set() instead of calling ifp->if_ioctl().
 1.67  08-Apr-2011  sborrill PR kern/38871

Fix LAN on bge(4), alc(4). Flag VLAN capability in ec_capenable as used by network
card drivers.
 1.66  05-Apr-2010  joerg branches: 1.66.2;
Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.65  28-Feb-2010  darran branches: 1.65.2;
Propagate the IFCAP_TSOv6 property also.
 1.64  19-Jan-2010  pooka branches: 1.64.2;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

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

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.63  01-Apr-2009  darran Also inherit the parent's TCP segmentation offload capability.
Note the vlan interface does not see updates to the parents capabilities
so if, for example, TSO is on in both, then turned off in the parent it
will remain on in the vlan interface.
 1.62  17-Dec-2008  cegger branches: 1.62.2;
kill MALLOC and FREE macros.
 1.61  07-Nov-2008  dyoung *** Summary ***

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

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

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

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

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Let ifioctl_common() handle SIOCGIFADDR.

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

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

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.60  11-Oct-2008  bouyer branches: 1.60.2; 1.60.4; 1.60.8;
Make SIOCSIFCAP work again on vlan interfaces: first check that the
capability is enabled on parent, then call ifioctl_common().
 1.59  15-Jun-2008  christos branches: 1.59.2;
- add if_alloc (ours just mallocs), and if_initname and use them (from FreeBSD)
- kill memsets where M_ZERO can be used.
 1.58  28-Apr-2008  martin branches: 1.58.2; 1.58.4;
Remove clause 3 and 4 from TNF licenses
 1.57  20-Feb-2008  matt branches: 1.57.6; 1.57.8; 1.57.10;
s/u_\(int[0-9]*_t\)/u\1/g
(change u_int*_t to uint*_t)
 1.56  07-Feb-2008  dyoung Start patching up the kernel so that a network driver always has
the opportunity to handle an ioctl before generic ifioctl handling
occurs. This will ease extending the kernel and sharing of code
between drivers.

First steps: Make the signature of ifioctl_common() match struct
ifinet->if_ioctl. Convert SIOCSIFCAP and SIOCSIFMTU to the new
ifioctl() regime, throughout the kernel.
 1.55  19-Sep-2007  dyoung branches: 1.55.6;
Constify sockaddr argument to ether_multiaddr(). Change struct
ifreq * arguments to ether_addmulti() and ether_delmulti() to const
struct sockaddr *, since ether_{add,del}multi() only ever read the
sockaddr ifreq member, ifr_addr. Update uses in carp(4) and in
vlan(4).
 1.54  26-Aug-2007  dyoung branches: 1.54.2;
Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).

Use sockaddr_dl_setaddr() in a few places.
 1.53  04-Mar-2007  christos branches: 1.53.2; 1.53.10; 1.53.14;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.52  16-Nov-2006  christos branches: 1.52.4;
__unused removal on arguments; approved by core.
 1.51  25-Oct-2006  elad Kill some KAUTH_GENERIC_ISSUSER uses.
 1.50  12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.49  23-Jul-2006  ad branches: 1.49.4; 1.49.6;
Use the LWP cached credentials where sane.
 1.48  14-May-2006  elad integrate kauth.
 1.47  11-Dec-2005  christos branches: 1.47.4; 1.47.6; 1.47.8; 1.47.10; 1.47.12;
merge ktrace-lwp.
 1.46  02-May-2005  yamt branches: 1.46.2;
split IFCAP_CSUM_xxx to IFCAP_CSUM_xxx_Rx and IFCAP_CSUM_xxx_Tx.
 1.45  17-Mar-2005  yamt vlan_input: add a missing EVL_VLANOFTAG in the case of hw offloading.
 1.44  26-Feb-2005  perry branches: 1.44.2;
nuke trailing whitespace
 1.43  21-Feb-2005  christos Re-arrange code slightly to avoid code duplication and allow to bail
out faster without doing de-capsulation work. From FreeBSD.
 1.42  04-Dec-2004  peter branches: 1.42.4; 1.42.6;
Change ifc_destroy to return an int instead of void, so that it
can pass back errors to ifconfig.
 1.41  08-Jul-2004  mycroft If the parent interface is not IFF_RUNNING, do not call its start function.
This prevent a variety of fun panics, and therefore fixes PR 12932, PR 17561,
and PR 18376...

XXX
...however this is most definitely a hack. The real problem here is that there
is no callback to notify a "client" interface like vlan when a "parent"
interface's status changes, and therefore the vlan interface is always
IFF_RUNNING. This allows packets to be queued on vlan interface at any time.
We can't simply leave the packets on the vlan interface, either, because there
is no callback to dequeue them. And last, since it's always IFF_RUNNING, if
we just *toss* the packets, we lose gratuitous ARPs and DAD packets.

"This needs work," but at least it no longer bleeds.
 1.40  23-Apr-2004  simonb s/the the/the/ (only in sources that aren't regularly imported from
elsewhere).
 1.39  21-Apr-2004  itojun kill sprintf, use snprintf
 1.38  05-Dec-2003  scw branches: 1.38.2;
To cater for VLAN-aware layer 2 ethernet switches which may need to strip
the tag before forwarding the packet, make sure the packet+tag is at least
68 bytes long.

This is necessary because our parent will only pad to 64 bytes (ETHER_MIN_LEN)
and some switches will not pad by themselves after deleting a tag.
 1.37  02-Oct-2003  itojun need to use m_freem(), not m_free(). from iij seil team
 1.36  09-Sep-2003  drochner Fix vlan tag sending in the ETHERCAP_VLAN_HWTAGGING case.
Makes my "txp" work and fixes "bge" -- PR kern/20363 by Scott Ellis.
 1.35  17-Jan-2003  itojun branches: 1.35.2;
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.34  11-Jun-2002  pooka fix a few typos in comments
 1.33  12-Nov-2001  lukem branches: 1.33.8; 1.33.10;
add RCSIDs
 1.32  12-Jun-2001  thorpej branches: 1.32.2;
If the parent interface can do hardware-assisted VLAN encapsulation,
then propagate its hardware-assisted checksumming flags.
 1.31  07-Apr-2001  thorpej Add ALTQ support (both for the VLAN interface itself, as well as for
being a VLAN on a ALTQ'ified interface).
 1.30  29-Jan-2001  thorpej branches: 1.30.2;
Start out with a link name that says "802.1Q VLAN", and inherit the
parent interface's as usual once we attach to the parent. When we
detach from the parent, reset our link name to the "802.1Q VLAN" name.
 1.29  28-Jan-2001  itojun call if_alloc_sadl(). without it the following operation causes kernel panic:
# ifconfig vlan0 create
# ifconfig vlan0
 1.28  17-Jan-2001  thorpej If no link level name is assigned, return EADDRNOTAVAIL on
SIOCGIFADDR.
 1.27  16-Jan-2001  thorpej No need to reference ifnet_addrs[].
 1.26  18-Dec-2000  thorpej branches: 1.26.2;
Small cosmetic change.
 1.25  18-Dec-2000  thorpej We now support hw vlan tag support in network interfaces, so remote it
from the TODO list.
 1.24  17-Nov-2000  bouyer branches: 1.24.2;
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.23  15-Nov-2000  bouyer Per discussion with Jason, change flags filter to
(IFF_UP | IFF_BROADCAST | IFF_RUNNING | IFF_ALLMULTI | IFF_SIMPLEX)
Also, put the ifp->if_opackets++ at the rigth place so that the counter is
incremented even when the parent is OACTIVE.
Fix a bug in vlan_input where the ethernet src and dst addrs would not be
correct because we only memmove() only ifv->ifv_encaplen instead of
sizeof(struct ether_header).
 1.22  15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.21  12-Nov-2000  bouyer In vlan_config(), filter flags inherited from parent interface to
(IFF_UP | IFF_BROADCAST | IFF_RUNNING | IFF_ALLMULTI | IFF_SIMPLEX)
Without this, if the parent is OACTIVE of PROMISC at config time, we
loose.
 1.20  10-Nov-2000  enami Don't return uninitialized value.
 1.19  10-Nov-2000  enami Don't unlink and deallocate ether_multi here. ether_ifdetach will do it.
 1.18  10-Nov-2000  enami Define struct member correctly. This fixes a panic due to overwrite of stack.
 1.17  09-Nov-2000  thorpej Implement promiscuous mode.
 1.16  15-Oct-2000  bouyer Don't try to handle SIOCSIFADDR/SIOCADDMULTI/SIOCDELMULTI if a vlan/vlanif
hasn't been configured (prevent a panic in arp_ifinit when setting an
IP addr with no vlan/vlanif).
 1.15  10-Oct-2000  ad Remove defunct bpfdetach()/ether_ifdetach() calls.
 1.14  04-Oct-2000  enami Cosmetic changes.
 1.13  04-Oct-2000  enami Remove redundant assignment.
 1.12  03-Oct-2000  thorpej Pop one off the TODO list.
 1.11  03-Oct-2000  thorpej When an Ethernet interface detaches, unconfigure any VLANs associated
with it.
 1.10  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.9  02-Oct-2000  ad htons -> ntohs. From Alan Barrett <apb@cequrux.com>.
 1.8  28-Sep-2000  ad Add an item to the TODO list.
 1.7  28-Sep-2000  enami Don't unconfigure if it is already unconfigured.
 1.6  28-Sep-2000  enami Fix think-o in previous; don't do the same test twice.
 1.5  28-Sep-2000  enami Port the multicast handling to NetBSD correctly.
 1.4  28-Sep-2000  enami s/6/ETHER_ADDR_LEN/
 1.3  28-Sep-2000  enami Remove unnecessary test.
 1.2  28-Sep-2000  enami Remove unnecessary function decl.
 1.1  27-Sep-2000  thorpej Support for 802.1Q Virtual LANs. Derived and cleaned up by
Andy Doran <ad@netbsd.org> from the FreeBSD/OpenBSD implementation.
A few minor changes to how it all hooks into the system by me.
 1.24.2.7  21-Apr-2001  bouyer Sync with HEAD
 1.24.2.6  11-Feb-2001  bouyer Sync with HEAD.
 1.24.2.5  18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.24.2.4  05-Jan-2001  bouyer Sync with HEAD
 1.24.2.3  22-Nov-2000  bouyer Sync with HEAD.
 1.24.2.2  20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
 1.24.2.1  17-Nov-2000  bouyer file if_vlan.c was added on branch thorpej_scsipi on 2000-11-20 18:10:08 +0000
 1.26.2.3  07-Apr-2004  jmc Pullup rev 1.37 (requested by itojun in ticket #93)

Need to use m_freem(), not m_free().
 1.26.2.2  31-Dec-2000  jhawk Pull up revisions 1.1-1.14, 1.16-1.21, 1.23-1.26 (new) (requested by bouyer):
Add support for 802.1Q virtual LANs.
 1.26.2.1  18-Dec-2000  jhawk file if_vlan.c was added on branch netbsd-1-5 on 2000-12-31 20:14:32 +0000
 1.30.2.8  17-Jan-2003  thorpej Sync with HEAD.
 1.30.2.7  12-Jul-2002  nathanw No longer need to pull in lwp.h; proc.h pulls it in for us.
 1.30.2.6  24-Jun-2002  nathanw Curproc->curlwp renaming.

Change uses of "curproc->l_proc" back to "curproc", which is more like the
original use. Bare uses of "curproc" are now "curlwp".

"curproc" is now #defined in proc.h as ((curlwp) ? (curlwp)->l_proc) : NULL)
so that it is always safe to reference curproc (*de*referencing curproc
is another story, but that's always been true).
 1.30.2.5  20-Jun-2002  nathanw Catch up to -current.
 1.30.2.4  14-Nov-2001  nathanw Catch up to -current.
 1.30.2.3  21-Jun-2001  nathanw Catch up to -current.
 1.30.2.2  09-Apr-2001  nathanw Catch up with -current.
 1.30.2.1  05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.32.2.2  23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.32.2.1  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.33.10.1  02-Oct-2003  tron Pull up revision 1.37 (requested by itojun in ticket #1499):
need to use m_freem(), not m_free(). from iij seil team
 1.33.8.1  20-Jun-2002  gehenna catch up with -current.
 1.35.2.7  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.35.2.6  01-Apr-2005  skrll Sync with HEAD.
 1.35.2.5  04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.35.2.4  18-Dec-2004  skrll Sync with HEAD.
 1.35.2.3  21-Sep-2004  skrll Fix the sync with head I botched.
 1.35.2.2  18-Sep-2004  skrll Sync with HEAD.
 1.35.2.1  03-Aug-2004  skrll Sync with HEAD
 1.38.2.1  23-Jul-2004  he Pull up revision 1.41 (requested by mycroft in ticket #697):
If the parent interface is not IFF_RUNNING, do not call
its start function. This prevents a variety of panics,
and therefore fixes PR#12932, PR#17561, and PR#18376.
 1.42.6.1  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.42.4.1  29-Apr-2005  kent sync with -current
 1.44.2.1  30-Mar-2005  tron Pull up revision 1.45 (requested by yamt in ticket #70):
vlan_input: add a missing EVL_VLANOFTAG in the case of hw offloading.
 1.46.2.6  27-Feb-2008  yamt sync with head.
 1.46.2.5  11-Feb-2008  yamt sync with head.
 1.46.2.4  27-Oct-2007  yamt sync with head.
 1.46.2.3  03-Sep-2007  yamt sync with head.
 1.46.2.2  30-Dec-2006  yamt sync with head.
 1.46.2.1  21-Jun-2006  yamt sync with head.
 1.47.12.1  24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.47.10.3  06-May-2006  christos - Move kauth_cred_t declaration to <sys/types.h>
- Cleanup struct ucred; forward declarations that are unused.
- Don't include <sys/kauth.h> in any header, but include it in the c files
that need it.

Approved by core.
 1.47.10.2  10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.47.10.1  08-Mar-2006  elad Adapt to kernel authorization KPI.
 1.47.8.2  11-Aug-2006  yamt sync with head
 1.47.8.1  24-May-2006  yamt sync with head.
 1.47.6.1  01-Jun-2006  kardel Sync with head.
 1.47.4.1  09-Sep-2006  rpaulo sync with head
 1.49.6.2  10-Dec-2006  yamt sync with head.
 1.49.6.1  22-Oct-2006  yamt sync with head
 1.49.4.1  18-Nov-2006  ad Sync with head.
 1.52.4.1  12-Mar-2007  rmind Sync with HEAD.
 1.53.14.2  02-Oct-2007  joerg Sync with HEAD.
 1.53.14.1  03-Sep-2007  jmcneill Sync with HEAD.
 1.53.10.1  03-Sep-2007  skrll Sync with HEAD.
 1.53.2.1  09-Oct-2007  ad Sync with head.
 1.54.2.2  23-Mar-2008  matt sync with HEAD
 1.54.2.1  06-Nov-2007  matt sync with HEAD
 1.55.6.1  18-Feb-2008  mjf Sync with HEAD.
 1.57.10.4  11-Aug-2010  yamt sync with head.
 1.57.10.3  11-Mar-2010  yamt sync with head
 1.57.10.2  04-May-2009  yamt sync with head.
 1.57.10.1  16-May-2008  yamt sync with head.
 1.57.8.2  17-Jun-2008  yamt sync with head.
 1.57.8.1  18-May-2008  yamt sync with head.
 1.57.6.3  17-Jan-2009  mjf Sync with HEAD.
 1.57.6.2  29-Jun-2008  mjf Sync with HEAD.
 1.57.6.1  02-Jun-2008  mjf Sync with HEAD.
 1.58.4.1  18-Jun-2008  simonb Sync with head.
 1.58.2.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.59.2.2  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.59.2.1  19-Oct-2008  haad Sync with HEAD.
 1.60.8.1  21-Apr-2010  matt sync to netbsd-5
 1.60.4.1  03-May-2009  snj Pull up following revision(s) (requested by darran in ticket #644):
sys/net/if_vlan.c: revision 1.63
Also inherit the parent's TCP segmentation offload capability.
Note the vlan interface does not see updates to the parents capabilities
so if, for example, TSO is on in both, then turned off in the parent it
will remain on in the vlan interface.
 1.60.2.2  28-Apr-2009  skrll Sync with HEAD.
 1.60.2.1  19-Jan-2009  skrll Sync with HEAD.
 1.62.2.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.64.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.65.2.2  21-Apr-2011  rmind sync with head
 1.65.2.1  30-May-2010  rmind sync with head
 1.66.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.69.26.1  10-Aug-2014  tls Rebase.
 1.69.22.1  18-Jun-2014  msaitoh Pull up following revision(s) (requested by bouyer in ticket #1067):
sys/dist/ipf/netinet/ip_fil_netbsd.c 1.9 via patch
sys/net/if_ethersubr.c 1.197 via patch
sys/net/if_loop.c 1.77 via patch
sys/net/if_vlan.c 1.70 via patch
sys/netinet/if_arp.c 1.158
sys/netinet/ip_carp.c 1.54 via patch
sys/netinet6/ip6_flow.c 1.23 via patch
sys/netinet6/nd6.c 1.150 via patch
sys/rump/librump/rumpkern/klock.c 1.4

Make sure *(if_output)() is called with KERNEL_LOCK held to avoid mbuf leak.
See http://mail-index.netbsd.org/tech-net/2014/04/09/msg004511.html
for details. For netinet6, the problem report, fix and test were done
by njoly@ on current-users@
 1.69.16.1  18-May-2014  rmind sync with head
 1.69.14.1  18-Jun-2014  msaitoh Pull up following revision(s) (requested by bouyer in ticket #1067):
sys/dist/ipf/netinet/ip_fil_netbsd.c 1.9 via patch
sys/net/if_ethersubr.c 1.197 via patch
sys/net/if_loop.c 1.77 via patch
sys/net/if_vlan.c 1.70 via patch
sys/netinet/if_arp.c 1.158
sys/netinet/ip_carp.c 1.54 via patch
sys/netinet6/ip6_flow.c 1.23 via patch
sys/netinet6/nd6.c 1.150 via patch
sys/rump/librump/rumpkern/klock.c 1.4

Make sure *(if_output)() is called with KERNEL_LOCK held to avoid mbuf leak.
See http://mail-index.netbsd.org/tech-net/2014/04/09/msg004511.html
for details. For netinet6, the problem report, fix and test were done
by njoly@ on current-users@
 1.69.12.2  03-Dec-2017  jdolecek update from HEAD
 1.69.12.1  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.69.8.4  24-Apr-2015  msaitoh Pull up following revision(s) (requested by ozaki-r in ticket #1295):
sys/net/if_vlan.c: revision 1.81
Count up parent's obytes and omcasts counters
PR kern/49837
 1.69.8.3  16-Apr-2015  msaitoh Pull up following revision(s) (requested by ozaki-r in ticket #1286):
sys/net/if_vlan.c: revision 1.80
Correct frame padding length
vlan pads a frame with zeros up to 68 bytes
(ETHER_MIN_LEN + ETHER_VLAN_ENCAP_LEN). It expects
that even if the frame is untagged, it keeps 64 bytes
at least. However, it lacks concern about CRC
(4 bytes). So a sending frame can be 72 (68 + 4) bytes.
PR 49788
 1.69.8.2  03-Nov-2014  msaitoh Pull up following revision(s) (requested by ozaki-r in ticket #1156):
sbin/ifconfig/vlan.c: revision 1.14
sbin/ifconfig/ifconfig.8: revision 1.108
sys/net/if_vlan.c: revision 1.71
sys/net/if_vlan.c: revision 1.73
sys/net/if_vlan.c: revision 1.74
- PR#49114: Write about -vlanif in ifconfig.8.
Add -vlanif to the help message of ifconfig.
- PR#49196: Leave promiscuous mode when detaching a parent (ifconfig -vlanif)
We have to call ifpromisc(ifp, 0) for both a VLAN interface
and its parent when they are in promiscuous mode.
- PR#49197: Delete link local addresses of a vlan interface when detaching its
parent.
- PR#49112: Restore vlan_ioctl overwritten by ether_ifdetach in vlan_unconfig
 1.69.8.1  03-Jun-2014  msaitoh Pull up following revision(s) (requested by bouyer in ticket #1067):
sys/dist/ipf/netinet/ip_fil_netbsd.c 1.9 via patch
sys/net/if_ethersubr.c 1.197 via patch
sys/net/if_loop.c 1.77 via patch
sys/net/if_vlan.c 1.70 via patch
sys/netinet/if_arp.c 1.158
sys/netinet/ip_carp.c 1.54 via patch
sys/netinet6/ip6_flow.c 1.23 via patch
sys/netinet6/nd6.c 1.150 via patch
sys/rump/librump/rumpkern/klock.c 1.4

Make sure *(if_output)() is called with KERNEL_LOCK held to avoid mbuf leak.
See http://mail-index.netbsd.org/tech-net/2014/04/09/msg004511.html
for details. For netinet6, the problem report, fix and test were done
by njoly@ on current-users@
 1.70.2.5  24-Sep-2017  snj Pull up following revision(s) (requested by manu in ticket #1409):
sys/arch/xen/xen/if_xennet_xenbus.c: 1.65
sys/arch/xen/xen/xennetback_xenbus.c: 1.53, 1.56 via patch
sys/net/if_bridge.c: 1.105
sys/net/if_ether.h: 1.65
sys/net/if_ethersubr.c: 1.215, 1.235
sys/net/if_vlan.c: 1.76, 1.77, 1.83, 1.88, 1.94
Protect vlan_unconfig with a mutex
It is not thread-safe but is likely to be executed in concurrent.
See PR 49264 for more detail.
--
Tweak vlan_unconfig
No functional change.
--
Add handling of VLAN packets in if_bridge where the parent interface supports
them (Jean-Jacques.Puig%espci.fr@localhost). Factor out the vlan_mtu enabling and
disabling code.
--
Enable the VLAN mtu capability and check for the adjusted packet size
(Jean-Jacques.Puig at espci.fr).
Factor out the packet-size checking function for clarity.
--
Don't increment the reference count only when it was 0...
From Jean-Jacques.Puig
--
Account for the CRC len (Jean-Jacques.Puig)
--
Fix a bug that the parent interface's callback wasn't called when the vlan
interface is configured. A callback function uses VLAN_ATTACHED() function
which check ec->ec_nvlans, the value should be incremented before calling the
callback. This bug was added in if_vlan.c rev. 1.83 (2015/11/19).
 1.70.2.4  03-Dec-2016  martin Pull up following revision(s) (requested by joerg in ticket #1279):
sys/net/if_vlan.c: revision 1.92
Don't check parent capabilities when a parent interface hasn't been
assigned.
 1.70.2.3  23-Apr-2015  snj branches: 1.70.2.3.2; 1.70.2.3.4;
Pull up following revision(s) (requested by ozaki-r in ticket #710):
sys/net/if_vlan.c: revision 1.81
Count up parent's obytes and omcasts counters
PR kern/49837
 1.70.2.2  04-Apr-2015  martin Pull up following revision(s) (requested by ozaki-r in ticket #653):
sys/net/if_vlan.c: revision 1.80
Correct frame padding length
vlan pads a frame with zeros up to 68 bytes
(ETHER_MIN_LEN + ETHER_VLAN_ENCAP_LEN). It expects
that even if the frame is untagged, it keeps 64 bytes
at least. However, it lacks concern about CRC
(4 bytes). So a sending frame can be 72 (68 + 4) bytes.
PR 49788
 1.70.2.1  22-Sep-2014  martin Pull up following revision(s) (requested by ozaki-r in ticket #108):
sbin/ifconfig/vlan.c: revision 1.14
sbin/ifconfig/ifconfig.8: revision 1.108
sys/net/if_vlan.c: revision 1.71-1.74

Document -vlanif in ifconfig.8 and in usage measseg (PR 49114).
Leave promiscuous mode when detaching a parent (PR 49196) and
delete link local addresses (49197).
Restore vlan_ioctl overwritten by ether_ifdetach in vlan_unconfig
(PR 49112).
Call if_input of vlan interface itself, not parent one.
This allows bridging vlan interfaces again.
 1.70.2.3.4.1  18-Jan-2017  skrll Sync with netbsd-5
 1.70.2.3.2.1  03-Dec-2016  martin Pull up following revision(s) (requested by joerg in ticket #1279):
sys/net/if_vlan.c: revision 1.92
Don't check parent capabilities when a parent interface hasn't been
assigned.
 1.78.2.12  28-Aug-2017  skrll Sync with HEAD
 1.78.2.11  05-Feb-2017  skrll Sync with HEAD
 1.78.2.10  05-Dec-2016  skrll Sync with HEAD
 1.78.2.9  05-Oct-2016  skrll Sync with HEAD
 1.78.2.8  09-Jul-2016  skrll Sync with HEAD
 1.78.2.7  29-May-2016  skrll Sync with HEAD
 1.78.2.6  22-Apr-2016  skrll Sync with HEAD
 1.78.2.5  19-Mar-2016  skrll Sync with HEAD
 1.78.2.4  27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.78.2.3  22-Sep-2015  skrll Sync with HEAD
 1.78.2.2  06-Jun-2015  skrll Sync with HEAD
 1.78.2.1  06-Apr-2015  skrll Sync with HEAD
 1.90.2.2  20-Mar-2017  pgoyette Sync with HEAD
 1.90.2.1  07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.94.2.1  21-Apr-2017  bouyer Sync with HEAD
 1.97.2.18  13-Nov-2019  martin Pull up following revision(s) (requested by yamaguchi in ticket #1434):

sys/net/if_vlan.c: revision 1.148

Fix a bug that vlan(4) fragments IPv6 packets
even the MTU > packet length.

The bug is appeared when the mtu is increased on SIOCSETVLAN.
From t-kusaba@IIJ
 1.97.2.17  24-Oct-2019  martin Pull up following revision(s) (requested by ozaki-r in ticket #1411):

sys/net/if_vlan.c: revision 1.147

vlan: get rid of unnecessary if_ipackets++ in vlan_input

It's done by if_input() below now.
Pointed out by msaitoh@
 1.97.2.16  22-Oct-2018  martin Additionally pull up r1.131 for ticket #1066 (requested by knakahara):

Use a different psz for a different lock. Patch from riastradh, reviewed
by ozaki-r.
 1.97.2.15  21-Oct-2018  martin Pull up following revision(s) (requested by knakahara in ticket #1066):

sys/net/if_vlan.c: revision 1.133
sys/net/if_gif.h: revision 1.32
sys/net/if_ipsec.c: revision 1.18
sys/net/if_ipsec.h: revision 1.4
sys/net/if_gif.c: revision 1.144
sys/net/if_l2tp.h: revision 1.6
sys/net/if_l2tp.c: revision 1.30

Fix panic when doing ioctl to multiple pseudo interfaces. Pointed out by k-goda@IIJ.

XXX pullup-8
 1.97.2.14  12-Jun-2018  snj Pull up following revision(s) (requested by ozaki-r in ticket #876):
sys/net/if_vlan.c: 1.126
tests/net/if_vlan/t_vlan.sh: 1.9
vlan: call ether_ifdetach without IFNET_LOCK
Fix PR kern/53357
--
Add tests of vlan with bridge
The tests trigger a panic reported in PR kern/53357.
 1.97.2.13  06-May-2018  martin Pull up following revision(s) (requested by spz in ticket #813):

sys/net/if_vlan.c: revision 1.122

If cnt == 0, don't kmem_alloc(0). Found by Mootja.

Looking at the code, I also find it suspicious that we read
ifv->ifv_mib->ifvm_p directly without making sure ifv_mib != NULL.
 1.97.2.12  14-Apr-2018  martin Pull up following revision(s) (requested by ryo in ticket #752):

sys/net/if_vlan.c: revision 1.125

Fix the handling of the state returned from pfil_run_hooks().

pfil_run_hooks() invokes any registered packet filters on the packet
being handled. It may return a (non-zero) errno, indicating that a
filter has decided that the packet should be discarded, and has freed
the mbuf. While a non-error (0) return usually means that the packet
should be processed normally, a filter may still free the mbuf if the
packet is a fragment, and the filter is holding it for reassembly and
future evaluation. Therefore, there must be separate tests for the
return value and for a possible discarded packet. (See pfil(9).)

OK: christos, martin
 1.97.2.11  02-Jan-2018  snj Pull up following revision(s) (requested by ozaki-r in ticket #456):
sys/arch/arm/sunxi/sunxi_emac.c: 1.9
sys/dev/ic/dwc_gmac.c: 1.43-1.44
sys/dev/pci/if_iwm.c: 1.75
sys/dev/pci/if_wm.c: 1.543
sys/dev/pci/ixgbe/ixgbe.c: 1.112
sys/dev/pci/ixgbe/ixv.c: 1.74
sys/kern/sys_socket.c: 1.75
sys/net/agr/if_agr.c: 1.43
sys/net/bpf.c: 1.219
sys/net/if.c: 1.397, 1.399, 1.401-1.403, 1.406-1.410, 1.412-1.416
sys/net/if.h: 1.242-1.247, 1.250, 1.252-1.257
sys/net/if_bridge.c: 1.140 via patch, 1.142-1.146
sys/net/if_etherip.c: 1.40
sys/net/if_ethersubr.c: 1.243, 1.246
sys/net/if_faith.c: 1.57
sys/net/if_gif.c: 1.132
sys/net/if_l2tp.c: 1.15, 1.17
sys/net/if_loop.c: 1.98-1.101
sys/net/if_media.c: 1.35
sys/net/if_pppoe.c: 1.131-1.132
sys/net/if_spppsubr.c: 1.176-1.177
sys/net/if_tun.c: 1.142
sys/net/if_vlan.c: 1.107, 1.109, 1.114-1.121
sys/net/npf/npf_ifaddr.c: 1.3
sys/net/npf/npf_os.c: 1.8-1.9
sys/net/rtsock.c: 1.230
sys/netcan/if_canloop.c: 1.3-1.5
sys/netinet/if_arp.c: 1.255
sys/netinet/igmp.c: 1.65
sys/netinet/in.c: 1.210-1.211
sys/netinet/in_pcb.c: 1.180
sys/netinet/ip_carp.c: 1.92, 1.94
sys/netinet/ip_flow.c: 1.81
sys/netinet/ip_input.c: 1.362
sys/netinet/ip_mroute.c: 1.147
sys/netinet/ip_output.c: 1.283, 1.285, 1.287
sys/netinet6/frag6.c: 1.61
sys/netinet6/in6.c: 1.251, 1.255
sys/netinet6/in6_pcb.c: 1.162
sys/netinet6/ip6_flow.c: 1.35
sys/netinet6/ip6_input.c: 1.183
sys/netinet6/ip6_output.c: 1.196
sys/netinet6/mld6.c: 1.90
sys/netinet6/nd6.c: 1.239-1.240
sys/netinet6/nd6_nbr.c: 1.139
sys/netinet6/nd6_rtr.c: 1.136
sys/netipsec/ipsec_output.c: 1.65
sys/rump/net/lib/libnetinet/netinet_component.c: 1.9-1.10
kmem_intr_free kmem_intr_[z]alloced memory
the underlying pools are the same but api-wise those should match
Unify IFEF_*_MPSAFE into IFEF_MPSAFE
There are already two flags for if_output and if_start, however, it seems such
MPSAFE flags are eventually needed for all if_XXX operations. Having discrete
flags for each operation is wasteful of if_extflags bits. So let's unify
the flags into one: IFEF_MPSAFE.
Fortunately IFEF_*_MPSAFE flags have never been included in any releases, so
we can change them without breaking backward compatibility of the releases
(though the kernel version of -current should be bumped).
Note that if an interface have both MP-safe and non-MP-safe operations at a
time, we have to set the IFEF_MPSAFE flag and let callees of non-MP-safe
opeartions take the kernel lock.
Proposed on tech-kern@ and tech-net@
Provide macros for softnet_lock and KERNEL_LOCK hiding NET_MPSAFE switch
It reduces C&P codes such as "#ifndef NET_MPSAFE KERNEL_LOCK(1, NULL); ..."
scattered all over the source code and makes it easy to identify remaining
KERNEL_LOCK and/or softnet_lock that are held even if NET_MPSAFE.
No functional change
Hold KERNEL_LOCK on if_ioctl selectively based on IFEF_MPSAFE
If IFEF_MPSAFE is set, hold the lock and otherwise don't hold.
This change requires additions of KERNEL_LOCK to subsequence functions from
if_ioctl such as ifmedia_ioctl and ifioctl_common to protect non-MP-safe
components.
Proposed on tech-kern@ and tech-net@
Ensure to hold if_ioctl_lock when calling if_flags_set
Fix locking against myself on ifpromisc
vlan_unconfig_locked could be called with holding if_ioctl_lock.
Ensure to not turn on IFF_RUNNING of an interface until its initialization completes
And ensure to turn off it before destruction as per IFF_RUNNING's description
"resource allocated". (The description is a bit doubtful though, I believe the
change is still proper.)
Ensure to hold if_ioctl_lock on if_up and if_down
One exception for if_down is if_detach; in the case the lock isn't needed
because it's guaranteed that no other one can access ifp at that point.
Make if_link_queue MP-safe if IFEF_MPSAFE
if_link_queue is a queue to store events of link state changes, which is
used to pass events from (typically) an interrupt handler to
if_link_state_change softint. The queue was protected by KERNEL_LOCK so far,
but if IFEF_MPSAFE is enabled, it becomes unsafe because (perhaps) an interrupt
handler of an interface with IFEF_MPSAFE doesn't take KERNEL_LOCK. Protect it
by a spin mutex.
Additionally with this change KERNEL_LOCK of if_link_state_change softint is
omitted if NET_MPSAFE is enabled.
Note that the spin mutex is now ifp->if_snd.ifq_lock as well as the case of
if_timer (see the comment).
Use IFADDR_WRITER_FOREACH instead of IFADDR_READER_FOREACH
At that point no other one modifies the list so IFADDR_READER_FOREACH
is unnecessary. Use of IFADDR_READER_FOREACH is harmless in general though,
if we try to detect contract violations of pserialize, using it violates
the contract. So avoid using it makes life easy.
Ensure to call if_addr_init with holding if_ioctl_lock
Get rid of outdated comments
Fix build of kernels without ether
By throwing out if_enable_vlan_mtu and if_disable_vlan_mtu that
created a unnecessary dependency from if.c to if_ethersubr.c.
PR kern/52790
Rename IFNET_LOCK to IFNET_GLOBAL_LOCK
IFNET_LOCK will be used in another lock, if_ioctl_lock (might be renamed then).
Wrap if_ioctl_lock with IFNET_* macros (NFC)
Also if_ioctl_lock perhaps needs to be renamed to something because it's now
not just for ioctl...
Reorder some destruction routines in if_detach
- Destroy if_ioctl_lock at the end of the if_detach because it's used in various
destruction routines
- Move psref_target_destroy after pr_purgeif because we want to use psref in
pr_purgeif (otherwise destruction procedures can be tricky)
Ensure to call if_mcast_op with holding IFNET_LOCK
Note that CARP doesn't deal with IFNET_LOCK yet.
Remove IFNET_GLOBAL_LOCK where it's unnecessary because IFNET_LOCK is held
Describe which lock is used to protect each member variable of struct ifnet
Requested by skrll@
Write a guideline for converting an interface to IFEF_MPSAFE
Requested by skrll@
Note that IFNET_LOCK must not be held in softint
Don't set IFEF_MPSAFE unless NET_MPSAFE at this point
Because recent investigations show that interfaces with IFEF_MPSAFE need to
follow additional restrictions to work with the flag safely. We should enable it
on an interface by default only if the interface surely satisfies the
restrictions, which are described in if.h.
Note that enabling IFEF_MPSAFE solely gains a few benefit on performance because
the network stack is still serialized by the big kernel locks by default.
 1.97.2.10  10-Dec-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #427):
sys/arch/amiga/dev/if_bah_zbus.c: 1.17
sys/arch/arm/broadcom/bcm53xx_eth.c: 1.30
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.32
sys/arch/usermode/dev/if_veth.c: 1.9
sys/dev/ic/an.c: 1.66
sys/dev/ic/athn.c: 1.17
sys/dev/ic/atw.c: 1.162
sys/dev/ic/bwi.c: 1.33
sys/dev/ic/dwc_gmac.c: 1.41-1.42
sys/dev/ic/malo.c: 1.10
sys/dev/ic/rt2560.c: 1.31
sys/dev/ic/rt2661.c: 1.36
sys/dev/ic/rt2860.c: 1.29
sys/dev/ic/rtw.c: 1.127
sys/dev/ic/rtwvar.h: 1.46
sys/dev/ic/smc90cx6.c: 1.71
sys/dev/ic/smc90cx6var.h: 1.12
sys/dev/ic/wi.c: 1.244
sys/dev/pci/if_ipw.c: 1.66
sys/dev/pci/if_iwi.c: 1.104
sys/dev/pci/if_iwm.c: 1.76
sys/dev/pci/if_iwn.c: 1.86
sys/dev/pci/if_rtwn.c: 1.13
sys/dev/pci/if_wm.c: 1.541
sys/dev/pci/if_wpi.c: 1.79
sys/dev/pci/ixgbe/ixgbe.c: 1.106
sys/dev/pci/ixgbe/ixv.c: 1.73 via patch
sys/dev/pcmcia/if_malo_pcmcia.c: 1.15
sys/dev/scsipi/if_se.c: 1.95
sys/dev/usb/if_upl.c: 1.60
sys/net/if.c: 1.396
sys/net/if.h: 1.241
sys/net/if_arc.h: 1.23
sys/net/if_arcsubr.c: 1.78
sys/net/if_bridge.c: 1.136-1.137
sys/net/if_etherip.c: 1.39
sys/net/if_faith.c: 1.56
sys/net/if_gif.c: 1.131
sys/net/if_loop.c: 1.96
sys/net/if_mpls.c: 1.30
sys/net/if_pppoe.c: 1.129
sys/net/if_srt.c: 1.27
sys/net/if_stf.c: 1.102
sys/net/if_tap.c: 1.100
sys/net/if_vlan.c: 1.105
sys/netinet/ip_carp.c: 1.91
sys/rump/net/lib/libshmif/if_shmem.c: 1.73-1.74
sys/rump/net/lib/libvirtif/if_virt.c: 1.55-1.56
if_initalize() and if_attach() failed when resource allocation failed
(e.g. allocating softint). Without this change, it panics. It's bad because
resource shortage really occured when a lot of pseudo interface is created.
To avoid this problem, don't panic and change return value of if_initialize()
and if_attach() to int. Caller fanction will be recover from error cleanly by
checking the return value.
Return if bah_attach_subr() failed.
If if_attach() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF
If error occured in bcmeth_ccb_attach(), free resources and return.
If error occured in pq3etsec_attach(), free resources and return.
If error occured in the attach function, free resources and return.
- If if_initialize() failed in athn_attach(), free resources and return.
- Add missing pmf_event_deregister() in athn_detach().
- Free resources correctly on some errors in atw_attach().
- Use apint*() insread of printf() in the attach function.
If if_initialize() failed in the attach function, return.
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
- If if_initialize() failed in the attach function, free resources and return.
- ifp is always not NULL in iwi_detach(). Check correctly with ifp->if_softc.
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.
If if_initialize() failed in the attach function, free resources and return.
If if_attach() failed in the attach function, free resources and return.
- If if_initialize() failed in the attach function, free resources and return.
- KNF
- If if_attach() failed in the attach function, free resources and return.
- KNF
Fix compile error.
Fix compile error.
We don't need '&mii', but just 'mii' for mii_detach().
Don't free sc_rthash twice
 1.97.2.9  27-Nov-2017  martin Pull up following revision(s) (requested by jmcneill in ticket #398):
sys/net/if_vlan.c: revision 1.113
kern/52765: npf cannot do port forwarding on vlan interfaces
Add pfil hooks support to vlan(4), from christos@
 1.97.2.8  24-Nov-2017  martin Pull up following revision(s) (requested by msaitoh in ticket #389):
sys/net/if_ether.h: revision 1.69
sys/net/if_vlan.c: revision 1.108
sys/dev/pci/if_bge.c: revision 1.313
sys/net/if_vlanvar.h: revision 1.11
sys/net/if_vlanvar.h: revision 1.12
sys/net/if_ether.h: revision 1.70
sys/net/if_vlan.c: revision 1.110
sys/dev/pci/if_wm.c: revision 1.544
sys/dev/pci/if_wmreg.h: revision 1.105
Fix a bug that a vlan packet which has priority or CFI bit in the tag causes
panic.
Revert part of if_bge.c 1.312. It's not required to mask other than VLAN ID
bits in VLAN tag.
Revert if_wmreg.h 1.104 and if_wm.c 1.542. It's not required to mask other
than VLAN ID bits in VLAN tag.
No functional change:
- u_int16_t -> uint16_t
- u_short -> uint16_t
- tag_hash_func -> vlan_tag_hash
- 0 -> NULL because vlr_parent is a pointer.
 1.97.2.7  22-Nov-2017  martin Pull up following revision(s) (requested by msaitoh in ticket #368):
sys/net/if_vlan.c: revision 1.101
sys/net/if_vlan.c: revision 1.102
Check if VLAN ID isn't duplicated on a same parent interface and return
EEXIST if it failed.
Remove accidentally added code (for VLAN hardware filter).
 1.97.2.6  08-Nov-2017  snj Pull up following revision(s) (requested by ozaki-r in ticket #349):
sys/net/if_l2tp.c: revision 1.14
sys/net/if_tap.c: revision 1.101
sys/net/if_tun.c: revision 1.141
sys/net/if_vlan.c: revision 1.106
Set IFEF_NO_LINK_STATE_CHANGE flag to pseudo devices that don't use
if_link_state_change
 1.97.2.5  06-Nov-2017  snj Pull up following revision(s) (requested by knahakara in ticket #340):
sys/net/if_vlan.c: revision 1.104
fix vlan panic when vlan is re-configured without destroy.
E.g. the following operation causes this panic.
====================
# ifconfig vlan0 create
# ifconfig vlan0 vlan 1 vlanif ixg3
# ifconfig vlan1 create
# ifconfig vlan1 vlan 1 vlanif ixg2
# ifconfig vlan1 -vlanif
# ifconfig vlan1 vlan 1 vlanif ixg2
panic: kernel diagnostic assertion "new->ple_next == NULL" failed: file "/git/netbsd-src/sys/sys/pslist.h", line 118
====================
Pointed out and tested by msaitoh@n.o, fixed by s-yamaguchi@IIJ, thanks.
 1.97.2.4  25-Oct-2017  snj Pull up following revision(s) (requested by ozaki-r in ticket #328):
sys/net/if_vlan.c: revision 1.103
Set IFEF_START_MPSAFE by default
Because vlan_start is already MP-safe, there is no reason to not do so.
Acked by s-yamaguchi@IIJ
 1.97.2.3  24-Oct-2017  snj Pull up following revision(s) (requested by knakahara in ticket #302):
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.30-1.31
sys/arch/x86/pci/if_vmx.c: 1.20
sys/dev/ic/i82557.c: 1.148
sys/dev/ic/rtl8169.c: 1.152
sys/dev/pci/cxgb/cxgb_sge.c: 1.5
sys/dev/pci/if_age.c: 1.51
sys/dev/pci/if_alc.c: 1.25
sys/dev/pci/if_ale.c: 1.23
sys/dev/pci/if_bge.c: 1.311
sys/dev/pci/if_bge.c: 1.312
sys/dev/pci/if_bnx.c: 1.62
sys/dev/pci/if_jme.c: 1.32
sys/dev/pci/if_nfe.c: 1.64
sys/dev/pci/if_sip.c: 1.167
sys/dev/pci/if_stge.c: 1.63-1.64
sys/dev/pci/if_ti.c: 1.102
sys/dev/pci/if_txp.c: 1.48
sys/dev/pci/if_vge.c: 1.61
sys/dev/pci/if_wm.c: 1.538
sys/dev/pci/ixgbe/ix_txrx.c: 1.29 via patch
sys/net/agr/if_agrether_hash.c: 1.4
sys/net/if_ether.h: 1.67-1.68
sys/net/if_ethersubr.c: 1.244
sys/net/if_vlan.c: 1.100
sys/net80211/ieee80211_input.c: 1.89
sys/net80211/ieee80211_output.c: 1.59
sys/sys/mbuf.h: 1.171
VLAN ID uses pkthdr instead of mtag now. Contributed by s-yamaguchi@IIJ.
I just commit by proxy. Reviewed by joerg@n.o and christos@n.o, thanks.
See http://mail-index.netbsd.org/tech-net/2017/09/26/msg006459.html
--
only get vtag when we have vtag like the other drivers.
--
- only get the vtag if we have it like the other drivers
- mask the hardware vlan tag
--
- add a constant for the vlan mask.
- enforce that we have a tag before we get it.
only get vtag when we have vtag like the other drivers.
like if_bge.c:1.312 and if_stge.c:1.64.
fixed by s-yamaguchi@IIJ, thanks.
 1.97.2.2  14-Aug-2017  snj Pull up following revision(s) (requested by knakahara in ticket #205):
sys/net/if_vlan.c: revision 1.99
Fix vlan(4) obytes counter. Implemented by s-yamaguchi@IIJ, thanks.
 1.97.2.1  21-Jun-2017  snj Pull up following revision(s) (requested by knakahara in ticket #41):
sys/net/if_vlan.c: revision 1.98
sys/net/if_vlanvar.h: revision 1.10
vlan(4) MP-ify. contributed by s-yamaguchi@IIJ, thanks.
 1.124.2.5  20-Oct-2018  pgoyette Sync with head
 1.124.2.4  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.124.2.3  28-Jul-2018  pgoyette Sync with HEAD
 1.124.2.2  25-Jun-2018  pgoyette Sync with HEAD
 1.124.2.1  22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.130.2.3  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.130.2.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.130.2.1  10-Jun-2019  christos Sync with HEAD
 1.141.2.3  13-Nov-2019  martin Pull up following revision(s) (requested by yamaguchi in ticket #420):

sys/net/if_vlan.c: revision 1.148
tests/net/if_vlan/t_vlan.sh: revision 1.16

Fix a bug that vlan(4) fragments IPv6 packets
even the MTU > packet length.

The bug is appeared when the mtu is increased on SIOCSETVLAN.
From t-kusaba@IIJ

atf: add test cases for MTU that is increased on SIOCSETVLAN
From t-kusaba@IIJ, thanks
 1.141.2.2  23-Oct-2019  martin Pull up following revision(s) (requested by ozaki-r in ticket #367):

sys/net/if_vlan.c: revision 1.147

vlan: get rid of unnecessary if_ipackets++ in vlan_input
It's done by if_input() below now.

Pointed out by msaitoh@
 1.141.2.1  01-Sep-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #133):

sys/dev/pci/ixgbe/ixgbe.c: revision 1.200
sys/dev/pci/ixgbe/ixgbe.c: revision 1.201
sys/dev/pci/ixgbe/ixv.c: revision 1.126
sys/dev/pci/ixgbe/ixv.c: revision 1.127
sys/net/if_vlan.c: revision 1.142
sys/net/if_vlan.c: revision 1.143
sys/net/if_vlan.c: revision 1.144
sys/net/if_vlan.c: revision 1.145
sys/net/if_vlan.c: revision 1.146

Check ec_capenable instead of ec_capabilities to control TX side of VLAN HW
tagging correctly.
XXX pullup-9

Add missing IFNET_LOCK() and IFNET_UNLOCK() in vlan_config().
XXX pullup-9

Fix a bug that VLAN HW "tagging" enable/disable may not reflect correctly.
- Always call ec_vlan_cb() if it exists.
- Some (or all?) ethernet drivers don't enable HW tagging if no any vlan is
attached. ixgbe is one of them. Check the the transition and update
VLAN HW tagging function.
XXX pullup-9

Use ETHER_LOCK()/ETHER_UNLOCK() suggested by knakahara.
- kmem_alloc(,KM_SLEEP) never return NULL, so remove NULL check.
- VLAN ID is never duplicated, so break the loop when found. Also move
kmen_free() outside of ETHER_LOCK(ec)/ETHER_UNLOCK(ec) to reduce the hold
time. suggested by ozaki-r.
- Whitespace fix.
 1.149.2.1  29-Feb-2020  ad Sync with head.
 1.153.6.2  01-Aug-2021  thorpej Sync with HEAD.
 1.153.6.1  17-Jun-2021  thorpej Sync w/ HEAD.
 1.170.4.1  03-Nov-2023  martin Pull up following revision(s) (requested by yamaguchi in ticket #455):
sys/dev/pci/ixgbe/ixgbe.c: revision 1.347
sys/net/if_l2tp.c: revision 1.49
tests/net/if_vlan/t_vlan.sh: revision 1.25
sys/net/if_vlan.c: revision 1.171
sys/net/if_ethersubr.c: revision 1.326
sys/dev/pci/ixgbe/ixv.c: revision 1.194
Use ether_bpf_mtap only when the device supports vlan harware tagging
The function is bpf_mtap() for ethernet devices and *currently*
it is just handling VLAN tag stripped by the hardware.
l2tp(4): use ether_ifattach() to initialize ethercom
Support vlan(4) over l2tp(4)
Added the test for vlan over l2tp
 1.171.2.1  11-Nov-2023  thorpej branches: 1.171.2.1.2;
Mostly de-tangle ifnet::if_snd from ifaltq, in a way that's minimally-
invasive to the ALTQ code itself.

The point of this is to lay the groundwork for future changes to ifqueue,
which among other benefits, will also hide the ALTQ ABI from drivers.
 1.171.2.1.2.2  16-Nov-2023  thorpej if_transmit_lock() and if_enqueue() are equivalent. if_enqueue() is
a better name, so collapse everything down to that and garbage-collect
if_transmit_lock().
 1.171.2.1.2.1  16-Nov-2023  thorpej Clean up the locking protocol around altq_etherclassify(). It's no longer
required to acquire KERNEL_LOCK *just* because ALTQ is compiled into the
kernel; you only have to acquire it if ALTQ is enabled on the interface
in question.

RSS XML Feed