Commit Graph

2702 Commits

Author SHA1 Message Date
ozaki-r
a84874a1a0 Remove an ifnet object from the global list before destructing it 2015-11-20 08:10:36 +00:00
christos
88b3ee5eb5 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.
2015-11-19 16:23:54 +00:00
knakahara
fd06f20054 fix CID 980463 2015-11-11 03:57:57 +00:00
knakahara
e96c855269 fix panic after "ifconfig gifX tunnel src dst" failed for the reason of address pair duplication.
e.g.
    ====================
    # ifconfig gif0 create
    # ifconfig gif0 tunnel 192.168.0.1 192.168.0.2
    # ifconfig gif0 inet 172.16.0.1/24 172.16.0.2
    # route add 10.1.0.0/24 172.16.0.1

    # ifconfig gif1 create
    # ifconfig gif1 tunnel 192.168.0.1 192.168.0.3

    # ifconfig gif0 tunnel 192.168.0.1 192.168.0.3
    ifconfig: SIOCSLIFPHYADDR: Can't assign requested address # expected
    # ping 10.1.0.1
    (panic)
    ====================
2015-11-11 02:57:17 +00:00
christos
04542e546d correct mistake in previous 2015-11-10 18:22:46 +00:00
christos
fa11598f4c CID 980463: Provide common error path for rollback. Remove extra check for
success.
2015-11-10 17:59:37 +00:00
ozaki-r
e7339922fb Improve lock traces and add reference traces 2015-11-05 06:50:51 +00:00
christos
805ab1e001 Simplify even further and fix non-modular kernels:
We cannot use the init at attach() trick, because other npf ext modules
will load before the attach function is called on non modular kernels.
2015-10-29 15:19:43 +00:00
christos
c0dba4ec09 remove bogus KASSERT, there are error paths that don't satisfy this.
XXX: should improve error reporting to userland.
2015-10-28 01:54:10 +00:00
christos
32f4b28226 modules don't define MODULAR. 2015-10-27 19:58:09 +00:00
christos
afd95c9bf1 simplify (and fix) logic. 2015-10-27 19:31:55 +00:00
maxv
2f8be1878d Harmless alloc inconsistency; make sure the exact same argument is given to
kmem_alloc/kmem_free. Found by Brainy.
2015-10-20 14:46:45 +00:00
ozaki-r
e4a5751875 Stop using softnet_lock (fix possible deadlock)
Using softnet_lock for mutual exclusion between lltable_free and
arptimer was wrong and had an issue causing a deadlock between
them;  lltable_free waits arptimer completion by calling
callout_halt with softnet_lock that is held in arptimer, however
lltable_free also holds llentry's lock that is also held in
arptimer so arptimer never obtain the lock and both never go
forward eventually.  We have to pass llentry's lock to
callout_halt instead.
2015-10-20 07:35:15 +00:00
martin
d041befd31 Ifdef npf_init() the same way as all it's callers are protected. 2015-10-19 09:28:24 +00:00
christos
a6022a4b9e Fix the code so that it works in all 3 cases: non-modular, modular/builtin,
modular/filesystem. In the non-modular case we initialize through attach.
In the modular/builtin case we define the module to be class misc so it
attaches late (after percpu is initialized) since driver modules attach
too early.  In the modular/filesystem case we define it to be a driver
module since we autoload it via /dev/npf open.
2015-10-19 00:29:57 +00:00
jmcneill
f0bb3f7042 Defer initialization of built-in npf module until other pseudo-devices
are initialized. MODULE_CLASS_DRIVER modules are now initialized before
autoconfiguration starts, but npf_init has a dependency on percpu(9) which
doesn't work until CPUs have attached (at least on ARM).
2015-10-18 20:39:53 +00:00
christos
635094c1f5 needs to be driver, otherwise it will not load! 2015-10-18 18:48:01 +00:00
jmcneill
4e97921379 mark this MODULE_CLASS_MISC as npf_init cannot run when builtin driver modules are initialized 2015-10-17 13:53:40 +00:00
christos
d522fec9f5 PR/49386: Ryota Ozaki: Add a mutex for bpf creation/removal to avoid races.
Add M_CANFAIL to malloc.
2015-10-14 19:40:09 +00:00
rjs
8c2654abca Add core networking support for SCTP. 2015-10-13 21:28:34 +00:00
roy
222d6fab6a 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.
2015-10-13 12:33:07 +00:00
ozaki-r
6a74db0c04 Fix LLE_TRY_UPGRADE when GATEWAY
It's expected to return a value.
2015-10-09 01:50:09 +00:00
roy
e600c51d95 Remove rt_ifa_localrequest().
In it's place, use rtrequest1() inside rt_ifa_addlocal() and
rtdeletemsg() inside rt_ifa_remlocal().

This removes the need for INET/INET6 specific code and allows
greater control over the creation of the local address route.
2015-10-07 09:44:26 +00:00
ozaki-r
ef5da9a970 Enqueue frames to a curcpu's pktqueue
Currently RX can run on a CPU other than CPU#0, so always enqueuing
to a pktqueue of CPU#0 makes no sense. Let's use a curcpu's pktqueue,
although bridge_foward softint doesn't run in parallel without
NET_MPSAFE.

This is a temporal solution. We need a fundamental solution.
2015-10-07 08:48:04 +00:00
ozaki-r
0e7ec84c8c Fix typo 2015-10-02 03:08:26 +00:00
ozaki-r
99284d7cc5 Make GATEWAY (fastforward) work again
With GATEWAY (fastforward), the whole forwarding processing runs in
hardware interrupt context. So we cannot use rwlock for lltable and
llentry in that case.

This change replaces rwlock with mutex(IPL_NET) for lltable and llentry
when GATEWAY is enabled. We need to tweak locking only around rtree
in lltable_free. Other than that, what we need to do is to change macros
for locks.

I hope fastforward runs in softint some day in the future...
2015-09-30 07:12:32 +00:00
ozaki-r
ad91e721ff Remove extra opt_gateway.h 2015-09-30 06:25:59 +00:00
ozaki-r
fc47734756 Tweak mutex_enter(softnet_lock) position
The previous code took locks the following order:
- LLE_WLOCKs
- mutex_enter(softnet_lock)
- LLE_WUNLOCKs
- mutex_exit(softnet_lock)

This fix moves mutex_enter(softnet_lock) before LLE_WLOCKs.
2015-09-28 07:55:26 +00:00
ozaki-r
30818f7132 Fix race condition on la_rt between lltable_free and other places touching la_rt
We have to touch la_rt always with holding softnet_lock. And we have to
use callout_halt with softnet_lock instead of callout_stop for
la_timer (arptimer) because arptimer holds softnet_lock inside it.

This fix may solve a kernel panic christos@ encountered.
2015-09-09 01:26:50 +00:00
dholland
1fbab01a93 More on PR 41200: headers that declare ioctls should include sys/ioccom.h.
This covers (I think) all the MI headers outside of external/ (and dist/).
2015-09-06 06:00:59 +00:00
dholland
0be2106b75 Uses _IOR/_IOW/etc. and thus needs sys/ioccom.h. PR 41200 2015-09-05 20:01:21 +00:00
ozaki-r
5392bf8aeb Add refcnt constraint checks for debugging
It's useful to know where the constraint is violated (by extra rtfree).
It's enabled only if DEBUG because it's heavy (O(n)).
2015-09-03 02:04:31 +00:00
ozaki-r
54c4f3b688 Do rt_refcnt++ when set a rtentry to another rtentry's rt_gwroute
And also do rtfree when deref a rtentry from rt_gwroute.
2015-09-02 11:35:11 +00:00
pooka
1d2b607cca #if __NetBSD__ -> #if defined(__NetBSD__) 2015-08-31 12:57:45 +00:00
ozaki-r
8997ac8f09 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.
2015-08-31 08:05:20 +00:00
ozaki-r
879526da38 Hook up lltable/llentry with the kernel (and rumpkernel)
It is built and initialized on bootup, but there is no user for now.

Most codes in in.c are imported from FreeBSD as well as lltable/llentry.
2015-08-31 08:02:44 +00:00
ozaki-r
85e26631cc Import lltable/llentry from FreeBSD
lltable/llentry is new L2 nexthop cache data structures that
store caches in each interface (struct ifnet). It is imported
to replace the current ARP cache implementation that uses the
global list with the big kernel lock, and provide fine-grain
locking for cache operations. It is also planned to replace
NDP caches.

The code is based on FreeBSD's lltable/llentry as of r286629
and tweaked for NetBSD.
2015-08-31 07:56:58 +00:00
ozaki-r
3aedc74443 Make rt_refcnt take into account rt_timer 2015-08-31 06:25:15 +00:00
rjs
34d5c6e6a9 Don't set M_PROTO1 in mbuf flags.
This was left over from the old usage of gif(4) with bridges.
2015-08-28 14:23:18 +00:00
pooka
1c4a50f192 sprinkle _KERNEL_OPT 2015-08-24 22:21:26 +00:00
ozaki-r
8a0c9bd6b5 Add an assertion; if rtcache has an rtentry, its refcnt must be > 0 2015-08-24 04:44:54 +00:00
christos
e7ae23fd9e include "ioconf.h" to get the 'void <driver>attach(int count);' prototype. 2015-08-20 14:40:16 +00:00
uebayasi
17ee3e05f5 Honor pseudo attach decl generated by config(1). 2015-08-20 11:18:53 +00:00
ozaki-r
c1f0857176 Remove extra rt_refcnt++ in rtalloc1
rtrequest has already done it. So we don't need to do it once more.

This fixes regressed behavior of ARP cache expiration which an expired
cache doesn't disappear.
2015-08-13 10:14:26 +00:00
ozaki-r
e12cf6b309 Move rtfree to a common place
This change also plugs a missing rtfree on an error path.
2015-08-13 07:59:05 +00:00
ozaki-r
972f005299 Tidy up header inclusions 2015-08-12 02:20:31 +00:00
ozaki-r
55140c1926 Use time_uptime instead of time_second to avoid time leaps
Some codes in sys/net* use time_second to manage time periods such as
cache expirations. However, time_second doesn't increase monotonically
and can leap by say settimeofday(2) according to time_second(9). We
should use time_uptime instead of it to avoid such time leaps.

This change replaces time_second with time_uptime. Additionally it
converts a time based on time_uptime to a time based on time_second
when the kernel passes the time to userland programs that expect
the latter, and vice versa.

Note that we shouldn't leak time_uptime to other hosts over the
netowrk. My investigation shows there is no such leak:
http://mail-index.netbsd.org/tech-net/2015/08/06/msg005332.html

Discussed on tech-kern and tech-net.
2015-08-07 08:11:33 +00:00
ozaki-r
18566c8cca Fix PR 48104
So far bridge cannot receive frames via a member interface when the frames
come from another member interface. So when we assign an IP address to
a member interface, hosts connected to another member interface cannot
ping to the IP address. That behavior isn't expected. See PR 48104 for
more realistic examples of this issue.

The change does:
- drop M_PROMISC before ether_input, which allows a bridge member interface
  to receive a frame coming from another bridge member interface
- receive broadcast/multicast frames via all bridge member interfaces,
  which is required to receive IPv6 multicast packets destined to a
  multicast group belonging to a bridge member interface that is different
  from a packet arrival interface

roy@ helped testing of the fix, thanks!
2015-07-23 10:52:34 +00:00
ozaki-r
9eae87d0c8 Reform use of rt_refcnt
rt_refcnt of rtentry was used in bad manners, for example, direct rt_refcnt++
and rt_refcnt-- outside route.c, "rt->rt_refcnt++; rtfree(rt);" idiom, and
touching rt after rt->rt_refcnt--.

These abuses seem to be needed because rt_refcnt manages only references
between rtentry and doesn't take care of references during packet processing
(IOW references from local variables). In order to reduce the above abuses,
the latter cases should be counted by rt_refcnt as well as the former cases.

This change improves consistency of use of rt_refcnt:
- rtentry is always accessed with rt_refcnt incremented
- rtentry's rt_refcnt is decremented after use (rtfree is always used instead
  of rt_refcnt--)
- functions returning rtentry increment its rt_refcnt (and caller rtfree it)

Note that rt_refcnt prevents rtentry from being freed but doesn't prevent
rtentry from being updated. Toward MP-safe, we need to provide another
protection for rtentry, e.g., locks. (Or introduce a better data structure
allowing concurrent readers during updates.)
2015-07-17 02:21:08 +00:00
ozaki-r
f2abd6a2e3 Move rt_gwroute operation out of stripoutput
We should do it in ip_hresolv_needed.
2015-07-14 08:44:59 +00:00