Commit Graph

1033 Commits

Author SHA1 Message Date
dyoung 5204966a96 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.
2007-08-26 22:59:08 +00:00
dyoung bd98464c6f Don't call rtcache_check() from the fast-forward code, which runs
at IPL_NET, because rtcache_check() may read the forwarding table.
Elsewhere, the kernel only blocks interrupts at priority IPL_SOFTNET
and below while it modifies the forwarding table, so rtcache_check()
could be reading the table in an inconsistent state.  Use
rtcache_done(), instead.

XXX netinet/ip_flow.c and netinet6/ip6_flow.c are virtually identical.
XXX They should share code.
2007-08-20 19:42:34 +00:00
dyoung ddf36c7b8b Constify. bcopy -> memcpy. 2007-08-10 22:44:05 +00:00
dyoung d7d71cd2b5 Constify. 2007-08-10 22:43:26 +00:00
dyoung 27de48611a Avoid writing past the end of the buffer [lldst, lldst + dstsize)
in nd6_storelladdr().

Use sockaddr_dl_setaddr().  Constify some sockaddr_dl's.  Constify
a sockaddr argument to nd6_na_output().  Change SDL() to "standard"
satocsdl() or satosdl().  Change SIN6() to satocsin6() or satosin6().

bcmp -> memcmp, bcopy -> memcpy.
2007-08-07 04:35:42 +00:00
dyoung d406df3438 Remove dead code. 2007-08-07 02:17:21 +00:00
dyoung 08e6f22226 Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:

        Introduce rt_walktree() for walking the routing table and
        applying a function to each rtentry.  Replace most
        rn_walktree() calls with it.

        Use rt_getkey()/rt_setkey() to get/set a route's destination.
        Keep a pointer to the sockaddr key in the rtentry, so that
        rtentry users do not have to grovel in the radix_node for
        the key.

        Add a RTM_GET method to rtrequest.  Use that instead of
        radix_node lookups in, e.g., carp(4).

Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).

Cosmetic:

        Constify.  KNF.  Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
        et cetera.  Use NULL instead of 0 for null pointers.  Use
        __arraycount().  Reduce gratuitous parenthesization.

        Stop using variadic arguments for rip6_output(), it is
        unnecessary.

        Remove the unnecessary rtentry member rt_genmask and the
        code to maintain it, since nothing actually used it.

        Make rt_maskedcopy() easier to read by using meaningful variable
        names.

        Extract a subroutine intern_netmask() for looking up a netmask in
        the masks table.

        Start converting backslash-ridden IPv6 macros in
        sys/netinet6/in6_var.h into inline subroutines that one
        can read without special eyeglasses.

One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.

I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.

Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-19 20:48:52 +00:00
christos 04ecc134a7 fix printf format. 2007-07-10 18:25:50 +00:00
ad 88ab7da936 Merge some of the less invasive changes from the vmlocking branch:
- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
2007-07-09 20:51:58 +00:00
gdt 413bfc8b37 ipsec4_splithdr: If m_len is too short, printf and drop it instead of
panicing.  Perhaps should be a pullup instead.  This happens very
occasionally on an ultrasparc with tunnel-mode ESP.
2007-07-09 19:11:05 +00:00
christos 681a7e5524 Add functions to do mapped address conversions from FreeBSD. 2007-06-28 21:03:47 +00:00
dyoung 3cfc66e506 Persuasive programming: check M_UNWRITABLE(m, len) instead of
m->m_len<len before pulling up, because that helps make it clear
that we m_pullup() in order to guarantee that the contiguous region
is *writable*.
2007-06-13 05:03:19 +00:00
dyoung ab5517c0d4 Convert from rn_walktree() to rt_walktree(). While I am here,
de-__P().
2007-06-09 03:25:32 +00:00
alc 3a676de695 don't increment `ip6stat.ip6s_noroute' here, it has already been done in
in6_src:in6_selectroute().

ok dyoung@
2007-06-02 23:26:26 +00:00
cube 8b523203e0 Tyop. 2007-05-27 16:58:17 +00:00
christos 68a6db0f0b fix typos in previous 2007-05-23 17:32:46 +00:00
christos 72cfe7327b Ansify + add a few comments, from Karl Sjödahl 2007-05-23 17:14:59 +00:00
yamt c8a34d8e58 remove net.inet6.ip6.rht0 sysctl.
it's too dangerous compared to its benefit.

strongly requested by itojun@.  ok'ed by core@.
2007-05-17 11:48:42 +00:00
dyoung 1db31a59af Fix the memory leak reported in kern/36337. Thanks Matthias Scheler
for the heads-up.  My fix is based on the following patches from
FreeBSD, however, I extracted the code into a subroutine,
nd6_llinfo_release_pkts():

http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/netinet6/nd6.c.diff?r1=1.48.2.18;r2=1.48.2.19
http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/netinet6/nd6_nbr.c.diff?r1=1.29.2.8;r2=1.29.2.9
2007-05-17 00:53:26 +00:00
dyoung e1d4e2922e In AppleTalk, IPv4, and IPv6 routing domains, help sockaddr_cmp()
avoid an indirect function call by comparing the family, length,
and bytes [dom->dom_sa_cmpofs, dom->dom_sa_cmpofs + dom->dom_sa_cmplen),
corresponding to the the sockaddrs' "address" members.

For ISO, actually use sockaddr_iso_cmp, for a change.  Thanks to
yamt@ for pointing out my error.
2007-05-06 02:56:37 +00:00
dyoung d91019e5e5 Use rtcache_lookup2(), and fix cache hit/miss accounting.
While I am here, introduce an rtentry pointer, 'rt', and set it
equal to ip6_forward.ro_rt.  Replace several occurrences of
'ip6_forward.ro_rt' with 'rt'.
2007-05-06 02:29:33 +00:00
yamt 10d3aa5cdf from kame:
> Revision 1.371
> Thu May 3 22:07:39 2007 UTC (47 hours, 7 minutes ago) by itojun
>
> drop packets with more than 1 routing headers.
> from claudio@openbsd

(and increment ifs6_in_hdrerr on ip6s_toomanyhdr.)
2007-05-05 21:23:50 +00:00
dyoung 8b646d9bb9 Remove obsolete files netinet/in_route.[ch]. 2007-05-02 22:39:03 +00:00
dyoung 72f0a6dfb0 Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.

The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing.  Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.

Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously.  Of course, all design oversights and bugs are
mine.

DETAILS

1 I added to each address family a pool of sockaddrs.  I have
  introduced routines for allocating, copying, and duplicating,
  and freeing sockaddrs:

        struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
        struct sockaddr *sockaddr_copy(struct sockaddr *dst,
                                       const struct sockaddr *src);
        struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
        void sockaddr_free(struct sockaddr *sa);

  sockaddr_alloc() returns either a sockaddr from the pool belonging
  to the specified family, or NULL if the pool is exhausted.  The
  returned sockaddr has the right size for that family; sa_family
  and sa_len fields are initialized to the family and sockaddr
  length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
  sockaddr_in).  sockaddr_free() puts the given sockaddr back into
  its family's pool.

  sockaddr_dup() and sockaddr_copy() work analogously to strdup()
  and strcpy(), respectively.  sockaddr_copy() KASSERTs that the
  family of the destination and source sockaddrs are alike.

  The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
  passed directly to pool_get(9).

2 I added routines for initializing sockaddrs in each address
  family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
  etc.  They are fairly self-explanatory.

3 structs route_in6 and route_iso are no more.  All protocol families
  use struct route.  I have changed the route cache, 'struct route',
  so that it does not contain storage space for a sockaddr.  Instead,
  struct route points to a sockaddr coming from the pool the sockaddr
  belongs to.  I added a new method to struct route, rtcache_setdst(),
  for setting the cache destination:

        int rtcache_setdst(struct route *, const struct sockaddr *);

  rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
  available to create the sockaddr storage.

  It is now possible for rtcache_getdst() to return NULL if, say,
  rtcache_setdst() failed.  I check the return value for NULL
  everywhere in the kernel.

4 Each routing domain (struct domain) has a list of live route
  caches, dom_rtcache.  rtflushall(sa_family_t af) looks up the
  domain indicated by 'af', walks the domain's list of route caches
  and invalidates each one.
2007-05-02 20:40:22 +00:00
dyoung 60ead1a452 Back out last. To compile, it depends on changes that I am not
ready to commit, yet.
2007-04-25 20:40:20 +00:00
dyoung e82cadce1c Remove unused member 'm6_route' from struct mif6. 2007-04-25 01:12:46 +00:00
dyoung 4f86563948 Constify. 2007-04-25 00:24:05 +00:00
christos 30921e7925 fix typo. 2007-04-22 20:06:07 +00:00
christos 08cd17ec8b Disable processing of routing header type 0 packets since they can be used
of DoS attacks. Provide a sysctl to re-enable them (net.inet6.ip6.rht0).

Information from:
	http://www.secdev.org/conf/IPv6_RH_security-csw07.pdf
2007-04-22 19:47:41 +00:00
liamjfoy 72a3be8fc7 use size_t for indexes
ok christos@
2007-04-05 18:12:49 +00:00
degroote 40cf3d18fa Make an exact match when we are looking for a cached sp for an unconnected
socket. If we don't make an exact match, we may use a cached rule which
has lower priority than a rule that would otherwise have matched the
packet.

Code submitted by Karl Knutsson in PR/36051
2007-03-25 12:46:42 +00:00
liamjfoy 64f6a30122 Minor change - be a little more consistant in sysctl handlers names 2007-03-24 00:42:14 +00:00
liamjfoy ac43382f1f Don't call ip*flow_reap if we're just looking up maxflows 2007-03-24 00:27:58 +00:00
macallan cc085574cb caddr_t -> void * 2007-03-23 17:35:02 +00:00
liamjfoy a3580ff06f Add a new sysctl net.inet6.ip6.hashsize to control the hash table size.
The sysctl handler will ensure this value is a power of 2

ok dyoung@
2007-03-23 14:24:22 +00:00
dyoung 95b277379f In nd6_rtrequest(), when we lookup/create a route whose destination
is equal to one of the host's IPv6 addresses, do not stop at setting
the route's interface to lo0, but also clear the route's RTF_CLONED
flag, if it is present, so that ip6_input() will accept packets
sent to that destination.  This is necessary because ip6_input()
will not accept a packet if it looks up the packet's destination
and finds a route with RTF_CLONED set.

I believe this will help IPv6 networking survive '/etc/rc.d/network
restart'.  See the problem report, kern/33279.
2007-03-17 06:32:46 +00:00
dyoung ab751193cc Don't open-code TAILQ_FOREACH(). KNF: Fix K&R prototypes and
parameter-type declarations.
2007-03-15 23:39:51 +00:00
dyoung 833cc39940 In nd6_lookup, shorten a staircase. KNF: change return (expr); to
return expr; throughout.  Fix K&R prototypes and parameter type
declarations.
2007-03-15 23:35:25 +00:00
dyoung f1c68f17f4 Bark if we cannot assign a link-local address. While I am here,
fix the grammar in a comment.
2007-03-15 23:26:04 +00:00
dyoung e75050de27 KNF: compare pointer w/ NULL, don't "check truth". Fix K&R parameter
types declaration.
2007-03-15 23:22:30 +00:00
ad 59d979c5f1 Pass an ipl argument to pool_init/POOL_INIT to be used when initializing
the pool's lock.
2007-03-12 18:18:22 +00:00
liamjfoy d0d904ff73 Use ip6flowtable when looking up 2007-03-08 17:09:15 +00:00
liamjfoy 8aa640dadd Add IPv6 Fast Forward - the IPv4 counterpart:
If ip6_forward successfully forwards a packet, a cache, in this case a
ip6flow struct entry, will be created. ether_input and friends will
then be able to call ip6flow_fastforward with the packet which will then
be passed to if_output (unless an issue is found - in that case the packet
is passed back to ip6_input).

ok matt@ christos@ dyoung@ and joerg@
2007-03-07 22:20:04 +00:00
liamjfoy f9af4def67 Fix some style issues - no functional change 2007-03-06 12:12:24 +00:00
christos 53524e44ef Kill caddr_t; there will be some MI fallout, but it will be fixed shortly. 2007-03-04 05:59:00 +00:00
degroote 768d7886ca Initialize fast_ipsec entry in the protocol switch with structure
initializers as other entries.
2007-02-27 22:19:05 +00:00
dyoung fef0ee84d5 Cosmetic: remove extraneous () on return statements, break a line
in two, join lines, compare pointers with NULL instead of testing
their "truth."
2007-02-22 09:30:33 +00:00
dyoung c4e796de1c Cosmetic: use TAILQ_FOREACH(). Remove extraneous () from return
statements.
2007-02-22 08:52:57 +00:00
dyoung 09fc9f4d08 Cosmetic: use TAILQ_FOREACH(). Join lines. 2007-02-22 08:43:43 +00:00
dyoung d3f547d96d Cosmetic: use __arraycount. In ip6_input, move type of parameter
into parentheses.
2007-02-22 08:39:27 +00:00