Commit Graph

203 Commits

Author SHA1 Message Date
ozaki-r
07e20941bc Remove unnecessary LLE_REMREF
The code around it was copied from arptimer, but LLE_REMREF
is unnecessary because it is needed only for arptimer that
is called after LLE_ADDREF.

This is a possible fix for PR#50548, PR#50702 and PR#50704.
2016-01-25 10:15:38 +00:00
riastradh
7c7b1739c8 Revert previous: ran cvs commit when I meant cvs diff. Sorry!
Hit up-arrow one too few times.
2016-01-21 15:41:29 +00:00
riastradh
b41d562bd0 Give proper prototype to ip_output. 2016-01-21 15:27:48 +00:00
riastradh
65a8f527af Eliminate struct protosw::pr_output.
You can't use this unless you know what it is a priori: the formal
prototype is variadic, and the different instances (e.g., ip_output,
route_output) have different real prototypes.

Convert the only user of it, raw_send in net/raw_cb.c, to take an
explicit callback argument.  Convert the only instances of it,
route_output and key_output, to such explicit callbacks for raw_send.
Use assertions to make sure the conversion to explicit callbacks is
warranted.

Discussed on tech-net with no objections:
https://mail-index.netbsd.org/tech-net/2016/01/16/msg005484.html
2016-01-20 21:43:59 +00:00
ozaki-r
d52244fae3 Make revarprequest static 2016-01-05 05:37:06 +00:00
ozaki-r
66d9895f20 Fix memory leak of llentry#la_opaque
llentry#la_opaque which is for token ring is allocated in arp.c
and freed in arp.c when freeing llentry. However, llentry can be
freed from other places, e.g., lltable_free. In such cases,
la_opaque is never freed.

To fix that, add a new callback (lle_ll_free) to llentry and
register a destruction function of la_opque to it. On freeing a
llentry, we can surely free la_opque via the callback.
2015-12-17 02:38:33 +00:00
ozaki-r
213b8d3cc6 Fix token_rif extractions from llentry 2015-12-16 05:44:59 +00:00
ozaki-r
871888c540 Introduce arp_settimer
No functional change.
2015-12-11 01:15:00 +00:00
ozaki-r
cefec21119 Get rid of a big block in in_arpinput
No functional change.
2015-11-30 06:45:38 +00:00
ozaki-r
53e3e4714d Restore softnet_lock and KERNEL_LOCK for rtrequest and rtfree
We still need them for rt operations.
2015-11-19 03:03:04 +00:00
ozaki-r
e72fec577e Fix db_print_llinfo
rt_llinfo is now struct llentry.
2015-11-06 08:55:49 +00:00
ozaki-r
60defe31a6 Fix inappropriate rt_flags check
It depended on either RTF_CLONED or RTF_CLONING must be set, however,
the assumption didn't meet for userland problems that create a route
via RTM_ADD.

This fixes an issue that running rarpd causes the following kernel panic
reported by nonaka@:
  panic: kernel diagnostic assertion "(la->la_flags & LLE_STATIC) == 0"
  failed: file "/usr/src/sys/netinet/if_arp.c", line 1339
2015-11-06 08:38:43 +00:00
ozaki-r
847c251da6 Stop callout in arp_rtrequest(RTM_DELETE)
This change fixes arptimer panic after removing an interface
(say by drvctl -d), which is reported by Takahiro Hayashi.

This change also fixes llentry's reference counting; we have
to take into account rtentry#rt_llinfo as well as arptimer.
2015-10-20 07:46:59 +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
roy
a2d314543b In the event of an error within arpresolve(), delete the cloned route
otherwise it would never be deleted.
2015-10-14 11:22:55 +00:00
roy
b0f4622d81 Save and clear the la route while we have a write lock 2015-10-14 11:17:57 +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
roy
9ba2bef003 Move the NOARP check up a bit so that it works when an la is created
but hasn't been resolved yet.
Fixes PR kern/17611.
2015-10-13 11:13:37 +00:00
roy
b61ebcc9c7 Simplify la handling in arpresolve() by asking arplookup() not to create
a la. If a la is needed arpresolve() will then create it or mark the
current la as writable.
2015-10-13 09:33:35 +00:00
roy
620387577c Create a temporary define involving IFF_STATICARP if we have it
instead of just testing for __FreeBSD__.
No functional change.

ok: ozaki-r@
2015-10-08 08:17:37 +00:00
ozaki-r
98c468dd77 Create an llentry after fixing an interface to store
In case of RTF_LOCAL routes, we change an output interface
of a route from original one to lo0ifp. An llentry also
has to be stored to lo0ifp in such cases.

Problem reported by roy@
2015-10-07 00:33:27 +00:00
ozaki-r
a7ed97a295 Fix arplookup logic
It should first lookup and then create an entry if not found (and if
creation is requested).
2015-10-05 08:17:31 +00:00
roy
f3b0c038a1 If, for whatever reason, a local interface route is removed and then
re-added, mark it as a local route.

While here, if changing the route to go via the loopback interface
remove any inherited MTU value.
2015-09-11 10:33:32 +00:00
ozaki-r
4c03bf20c9 Remove wrong KASSERT in arptfree
la_rt can be NULL because arptimer that calls arptfree doesn't always
free llentry so llentry can remain with la_rt == NULL. So we instead
check whether la_rt is NULL or not and do arptfree if not.

This fixes PR kern/50184 (confirmed by martin@) and
PR kern/50186 (maybe).
2015-09-09 01:24:01 +00:00
ozaki-r
c2ed920b63 Revert v1.176 for further proper fix 2015-09-09 01:22:28 +00:00
ozaki-r
6c5982b876 CID 1322880: remove unnecessary m != NULL checks 2015-09-07 01:18:27 +00:00
ozaki-r
d5ad433b2c CID 1322878: simplify log output flow 2015-09-07 01:17:37 +00:00
christos
00158cce6d XXX: Disable KASSERT for now since locking is broken for interface removals. 2015-09-02 09:28:13 +00:00
ozaki-r
7dc37e542b Remove obsolete global variables and sysctl MIBs 2015-08-31 08:06:30 +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
pooka
1c4a50f192 sprinkle _KERNEL_OPT 2015-08-24 22:21:26 +00:00
ozaki-r
f818671bf4 Move insane goto label 2015-08-12 07:13:14 +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
bd4fe18031 Make global variables static 2015-07-15 08:49:15 +00:00
ozaki-r
423491c235 Replace NARC with NARCNET to follow renaming at 2007
Hmm, is anyone using this?
2015-05-22 07:44:46 +00:00
ozaki-r
b41c75c271 Use LIST_FOREACH{,_SAFE}
The first loop doesn't remove any items in it, so we can use
LIST_FOREACH instead of LIST_FOREACH_SAFE.
2015-05-21 09:29:51 +00:00
ozaki-r
442b227d9f Use NULL instead of 0 for pointers 2015-05-21 09:27:10 +00:00
ozaki-r
2c0e34375a Make arp_init, in_revarpinput and revarprequest static 2015-05-21 09:26:18 +00:00
roy
f45d868787 Separate ARP handling DAD from inet.
This is done by signalling the intent to try tentative addresses
and then clearing the intent once the address is setup.
When the ARP handler is installed (arp_ifinit) then it adds
dad start and stop functions to the address which are used instead
of calling ARP directly.
2015-05-16 12:12:46 +00:00
justin
f5df4fc799 Rename delay variable as it shadows a global on arm. 2015-05-03 10:44:04 +00:00
roy
505639d2f3 Add IPv4 address flags IN_IFF_TENTATIVE, IN_IFF_DUPLICATED and
IN_IFF_DETATCHED to mimic the IPv6 address behaviour.
Add SIOCGIFAFLAG_IN ioctl to retrieve the address flag via the
ifreq structure.
Add IPv4 DAD detection via the ARP methods described in RFC 5227.
Add sysctls net.inet.ip.dad_count and net.inet.arp.debug.

Discussed on tech-net@
2015-05-02 14:41:32 +00:00
roy
a37502b2b6 Add RTF_BROADCAST to mark routes used for the broadcast address when
they are created on the fly. This makes it clear what the route is for
and allows an optimisation in ip_output() by avoiding a call to
in_broadcast() because most of the time we do talk to a host.
It also avoids a needless allocation for the storage of llinfo_arp and
thus vanishes from arp(8) - it showed as incomplete anyway so this
is a nice side effect.

Guard against this and routes marked with RTF_BLACKHOLE in
ip_fastforward().
While here, guard against routes marked with RTF_BLACKHOLE in
ip6_fastforward().
RTF_BROADCAST is IPv4 only, so don't bother checking that here.
2015-03-23 18:33:17 +00:00
roy
42900924fd Introduce the routing flag RTF_LOCAL to track local address routes.
Add functions rt_ifa_addlocal() and rt_ifa_remlocal() to add and remove
local routes for the address and announce the new address and route
to the routing socket.

Add in_ifaddlocal() and in_ifremlocal() to use these functions.
Rename in6_if{add,rem}loop() to in6_if{add,rem}local() and use these
functions.

rtinit() no longer announces the address, just the network route for the
address. As such, calls to rt_newaddrmsg() have been removed from
in_addprefix() and in_scrubprefix().

This solves the problem of potentially more than one announcement, or no
announcement at all for the address in certain situations.
2015-02-26 09:54:46 +00:00
christos
cb8dda3c0e Add sysctl to selectively log arp packets from unknown network. (Adrien URBAN). 2014-11-13 16:11:18 +00:00
matt
8f413cecf4 Deanonymize structure for llinfo_arp. 2014-09-05 06:02:11 +00:00
ozaki-r
f71f52bb9b Call ifp->if_output in revarprequest with KERNEL_LOCK held
Otherwise, it hits KASSERT(KERNEL_LOCKED_P()) in ether_output
when nfs_boot fails and tries RARP.
2014-06-03 01:24:32 +00:00
rmind
39bd8dee77 Add struct pr_usrreqs with a pr_generic function and prepare for the
dismantling of pr_usrreq in the protocols; no functional change intended.
PRU_ATTACH/PRU_DETACH changes will follow soon.

Bump for struct protosw.  Welcome to 6.99.62!
2014-05-18 14:46:15 +00:00
gdt
91dff1f8f3 revarprequest: Avoid leaking mbuf.
In revarprequest, an mbuf could perhaps be leaked in an error path.
My reading of the code is that this is not possible, because ar_pro is
set to ETHERNET_IP, and ar_tha can only be null in the 1394 case.
But, better to have the free call anyway; ar_tha does not have a
documented interface contract :-)

Pointed out by Maxime Villard.
2014-04-12 12:24:50 +00:00
pooka
4f6fb3bf35 Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.
2014-02-25 18:30:08 +00:00
liamjfoy
e3d3462211 Remove dead variable 2012-01-02 22:17:11 +00:00