summaryrefslogtreecommitdiff
path: root/sys/net/if_bridge.c
AgeCommit message (Collapse)Author
2022-01-04Add `ipsec_flows_mtx' mutex(9) to protect `ipsp_ids_*' list andYASUOKA Masahiko
trees. ipsp_ids_lookup() returns `ids' with bumped reference counter. original diff from mvs ok mvs
2021-12-23IPsec is not MP safe yet. To allow forwarding in parallel withoutAlexander Bluhm
dirty hacks, it is better to protect IPsec input and output with kernel lock. Not much is lost as crypto needs the kernel lock anyway. From here we can refine the lock later. Note that there is no kernel lock in the SPD lockup path. Goal is to keep that lock free to allow fast forwarding with non IPsec traffic. tested by Hrvoje Popovski; OK tobhe@
2021-12-03Add TDB reference counting to ipsp_spd_lookup(). If an outputAlexander Bluhm
pointer is passed to the function, it will return a refcounted TDB. The ref happens when ipsp_spd_inp() copies the pointer from ipo->ipo_tdb. The caller of ipsp_spd_lookup() has to unref after using it. tested by Hrvoje Popovski; OK mvs@ tobhe@
2021-12-01Let ipsp_spd_lookup() return an error instead of a TDB. The TDBAlexander Bluhm
is not always needed, but the error value is necessary for the caller. As TDB should be refcounted, it makes not sense to always return it. Pass an output pointer for the TDB which can be NULL. OK mvs@ tobhe@
2021-11-25Implement reference counting for IPsec tdbs. Not all cases areAlexander Bluhm
covered yet, more ref counts to come. The timeouts are protected, so the racy tdb_reaper() gets retired. The tdb_policy_head, onext and inext lists are protected. All gettdb...() functions return a tdb that is ref counted and has to be unrefed later. A flag ensures that tdb_delete() is called only once. Tested by Hrvoje Popovski; OK sthen@ mvs@ tobhe@
2021-11-11Do not call ip_deliver() recursively from IPsec. As there is noAlexander Bluhm
crypto task anymore, it is possible to return the next protocol. Then ip_deliver() will walk the header chain in its loop. IPsec bridge(4) tested by jan@ OK mvs@ tobhe@ jan@
2021-10-23There is an m_pullup() down in AH input. As it may free or changeAlexander Bluhm
the mbuf, the callers must be careful. Although there is no bug, use the common pattern to handle this. Pass down an mbuf pointer mp and let m_pullup() update the pointer in all callers. It looks like the tcp signature functions should not be called. Avoid an mbuf leak and return an error. OK mvs@
2021-07-07tell ether_input() to call pf_test() outside of smr_read sections,Alexandr Nedvedicky
because smr_read sections don't play well with sleeping locks in pf(4). OK bluhm@
2021-06-02use ipv4_check and ipv6_check provided by the network stacks.David Gwynne
this removes the duplication of the check code, and lets the v6 code in particular pick up a lot more sanity checks around valid addresses on the wire. ok bluhm@ sashan@
2021-03-05pass the uint64_t dst ethernet address from ether_input to bridges.David Gwynne
tested on amd64 and sparc64.
2021-03-01Refactor ip_fragment() and ip6_fragment(). Use a mbuf list toAlexander Bluhm
simplify the handling of the fragment list. Now the functions ip_fragment() and ip6_fragment() always consume the mbuf. They free the mbuf and mbuf list in case of an error and take care about the counter. Adjust the code a bit to make v4 and v6 look similar. Fixes a potential mbuf leak when pf_route6() called pf_refragment6() and it failed. Now the mbuf is always freed by ip6_fragment(). OK dlg@ mvs@
2021-02-25we don't have to cast to caddr_t when calling m_copydata anymore.David Gwynne
the first cut of this diff was made with coccinelle using this spatch: @rule@ type caddr_t; expression m, off, len, cp; @@ -m_copydata(m, off, len, (caddr_t)cp) +m_copydata(m, off, len, cp) i had fix it's opinionated idea of formatting by hand though, so i'm not sure it was worth it. ok deraadt@ bluhm@
2021-02-23small adjustment of the deck chairs, no functional change.David Gwynne
2021-02-23use the ipv6 dst addr to look up an ipsec tdb in bridge_ipsec in.David Gwynne
using the ipv6 next protocol header probably doesnt work. it also probably doesnt matter cos i'm not sure anyone uses this feature in bridge. or maybe there isn't anyone who uses ipv6. both are plausible options. hahaha^Wok patrick@
2021-01-28bridge(4): convert ifunit() to if_unit(9)mvs
ok bluhm@ sashan@
2021-01-25We have this sequence in bridge(4) ioctl(2) path:mvs
ifs = ifunit(req->ifbr_ifsname); if (ifs == NULL) { error = ENOENT; break; } if (ifs->if_bridgeidx != ifp->if_index) { error = ESRCH; break; } bif = bridge_getbif(ifs); This sequence repeats 8 times. Also we don't check value returned by bridge_getbig() before use. Newly introduced bridge_getbig() function replaces this sequence. This not only reduces duplicated code but also makes `bif' dereference safe. ok bluhm@
2021-01-08don't check local carp addresses as part of the antispoof checks.David Gwynne
bridge(4) drops packets coming from somewhere else that have a source MAC address that's owned by one of the interfaces that's a member of the bridge. because this check was done with bridge_ourether, it included the addresses of active carp interfaces hanging off these member interfaces. this meant if the local machine is the carp master while another machine is trying to preempt it by sending hellos, the packets from the other machine were dropped because the local one is already the master. carp roles are supposed to move around a l2 network, so another host sending a packet with a carp mac address is actually normal and necessary. found by and fix tested by stsp@ ok stsp@ claudio@
2021-01-02Don't call if_deactivate() in bridge_clone_destroy(). Followingmvs
if_detach() will do this. ok kn@
2020-08-06Allow pf(4) to divert packets from bridge(4) to local socket.Alexander Bluhm
joint work markus@ patrick@ bluhm@
2020-07-30`struct bstp_state' stores pointer to parent `ifnet' as `bs_ifp'.mvs
Replace this pointer by interface index. This allow us to avoid some use after free issues caused by ifioctl() races. ok sashan@
2020-07-22Use interface index instead of pointer to `ifnet' in `struct bstp_port'.mvs
ok yasuoka@
2020-07-22register as a bridge port, not an input handler, on member ifaces.David Gwynne
this is a step toward making all types of bridges coordinate their use of port interfaces, and is a step toward deprecating the interface input handler lists. bridge(4), switch(4), and tpmr(4) now coordinate their access so only one of them can own a port at a time. this has been in snaps as part of a larger diff for over a week.
2020-07-13when adding a non-existent interface as a port, don't try create missing ones.David Gwynne
this was annoying if i made a typo like "ifconfig bridge0 add gre0" instead of "ifconfig bridge0 add egre0" because it would create gre0 and then get upset cos it's not an Ethernet interface. also, it left gre0 lying around. this used to be useful when configuring a bridge on boot because interfaces used to be created when they were configured, and bridges could be configured before some virtual interfaces. however, netstart now creates all necessary interfaces before configuring any of them, so bridge being helpful isn't necessary anymore. ok kn@
2020-06-24kernel: use gettime(9)/getuptime(9) in lieu of time_second(9)/time_uptime(9)cheloha
time_second(9) and time_uptime(9) are widely used in the kernel to quickly get the system UTC or system uptime as a time_t. However, time_t is 64-bit everywhere, so it is not generally safe to use them on 32-bit platforms: you have a split-read problem if your hardware cannot perform atomic 64-bit reads. This patch replaces time_second(9) with gettime(9), a safer successor interface, throughout the kernel. Similarly, time_uptime(9) is replaced with getuptime(9). There is a performance cost on 32-bit platforms in exchange for eliminating the split-read problem: instead of two register reads you now have a lockless read loop to pull the values from the timehands. This is really not *too* bad in the grand scheme of things, but compared to what we were doing before it is several times slower. There is no performance cost on 64-bit (__LP64__) platforms. With input from visa@, dlg@, and tedu@. Several bugs squashed by visa@. ok kettenis@
2020-04-12ifpromisc() requires NET_LOCK(), so acquire the lock when changingVisa Hankala
promiscuous mode from bridge(4). This fixes a regression of r1.332 of sys/net/if_bridge.c. splassert with bridge(4) and vlan(4) reported by David Hill OK mpi@, dlg@
2019-11-06replace the hooks used with if_detachhooks with a task list.David Gwynne
the main semantic change is that things registering detach hooks have to allocate and set a task structure that then gets added to the list. this means if the task is allocated up front (eg, as part of carps softc or bridges port structure), it avoids the possibility that adding a hook can fail. a lot of drivers weren't checking for failure, and unwinding state in the event of failure in other parts was error prone. while doing this i discovered that the list operations have to be in a particular order, but drivers weren't doing that consistently either. this diff wraps the list ops up so you have to seriously go out of your way to screw them up. ive also sprinkled some NET_ASSERT_LOCKED around the list operations so we can make sure there's no potential for the list to be corrupted, especially while it's being run. hrvoje popovski has tested this a bit, and some issues he discovered have been fixed. ok sashan@
2019-07-20When multiple ports share the same MAC, pick the physical one for delivery.Martin Pieuchot
Fix an issue reported by Eygene Ryabinkin where packet where dropped by pf(4) because a vlan(4) interface was picked instead of its underlying em(4). While here do some refactoring to avoid code duplication. Based on a submission from Eygene Ryabinkin <rea at codelabs dot ru>. ok bluhm@, kn@
2019-07-17Introduce ETHER_IS_BROADCAST/ANYADDR/EQ() and use them where appropriate.Martin Pieuchot
ok dlg@, sthen@, millert@
2019-06-09Always return EEXIST if an interface is already part of a bridge.Martin Pieuchot
2019-06-09Remove code for non-Ethernet members, these are no longer supported.Martin Pieuchot
From Eygene Ryabinkin.
2019-05-13Deal with the case where bridge_getbif() can return NULL.Martin Pieuchot
Since `bif' are removed from the interface list before calling smr_barrier() and the hash queue is cleaned up afterward, it is possible to find an ifidx with bridge_rtlookup() that won't match to any `bif'. Fix a panic reported by Hrvoje Popovski, ok visa@
2019-05-12Switch the list of span interfaces and interfaces to SMR.Martin Pieuchot
This removes the KERNEL_LOCK() around the list iteration in bridge_enqueue(). Since the NET_LOCK() isn't protecting any data structure, release it early in all the code paths coming from the Network Stack to prevent possible deadlock situations with smr_barrier(). bridge_input() is still KERNEL_LOCK()ed as well as bridge_filterrule(). ok visa@
2019-05-12pushing NET_LOCK() further down from if_clone_{create,destroy}()Alexandr Nedvedicky
OK mpi@
2019-05-10Move bridge_filterrule() before doing the mbuf copy. Fixes a memory leakClaudio Jeker
when multiple interfaces do MAC filtering. Memory leak reported by Daniel Levai With and OK mpi@
2019-05-03An if_put() was missing in one branch of bridge_process(). ThisAlexander Bluhm
caused a hanging "ifconfig bridge0 destroy" and a subsequent uvm fault. reported and tested by Hrvoje Popovski; OK visa@
2019-04-28Removes the KERNEL_LOCK() from bridge(4)'s output fast-path.Martin Pieuchot
This redefines the ifp <-> bridge relationship. No lock can be currently used across the multiples contexts where the bridge has tentacles to protect a pointer, use an interface index. Tested by various, ok dlg@, visa@
2019-04-15Use timeout_del_barrier(9) instead of timeout_del(9) followed byVisa Hankala
conditional timeout_barrier(9). OK kn@ dlg@
2019-03-31Fix output accounting when bridge(4) is down.Martin Pieuchot
ok visa@
2019-03-12Merge copy/pasted code to export STP states via ioctl into a function.Martin Pieuchot
2019-03-08Do not grab a `bif' pointer again, we already have it.Martin Pieuchot
ok visa@
2019-03-08Move the tag mechanism outside of net/if_bridge.c.Martin Pieuchot
This will help for future (un)locking. ok visa@
2019-02-20Protect the hash table with a mutex.Martin Pieuchot
inputs & ok visa@
2019-02-14Use timeout_barrier() when bringing the bridge(4) down and only executeMartin Pieuchot
the timeout handler if the interface is running. ok claudio@
2019-02-14Remove mpw(4) hacks now that all the world is Ethernet.Martin Pieuchot
2019-01-29Plumbing to simplify upcoming locking.Martin Pieuchot
- Do checks that do not access shared data structures first, they don't need locking and save us some dances. - Use the common !ETHER_IS_MULTICAST() idiom and move some code that won't be executed if the bridge(4) is down. ok bluhm@, visa@
2019-01-23Pass an `ifp' pointer to bridge_ourether().Martin Pieuchot
ok kn@, claudio@, visa@
2019-01-23Only copy packets for span ports if the bridge is UP.Martin Pieuchot
ok claudio@, kn@, visa@
2019-01-17Convert interface lists from TAILQ to SLIST in preparation for fineMartin Pieuchot
grained locking. ok visa@, florian@
2018-12-12Various cleanups:Martin Pieuchot
- Unify the two hooks by passing the same argument - Check for nullity before dereferencing `if_bridgeport', this will matter when we go MP - Use the same pattern to find a member in the ioctl path ok bluhm@, visa@
2018-12-07Stop passing `sc' when it isn't needed and use `ifp' where it's goodMartin Pieuchot
enough. ok sthen@, visa@