Commit Graph

121 Commits

Author SHA1 Message Date
dyoung 453e5e8a7d Cosmetic: join two lines. 2007-11-28 02:40:21 +00:00
dyoung 42e892e3d8 Pass the mbuf type (e.g., MT_SONAME, MT_SOOPTS) as the second
argument to getsockmbuf().
2007-11-24 07:49:03 +00:00
dyoung 8fd9837dcc Fix a bunch of locking bugs ("Mutex error: lockdebug_barrier: spin
lock held"): only hold a mutex briefly at the top and bottom of
gre_ioctl().  Use splnet() to synchronize reconfiguration with
network interrupts.
2007-11-24 07:43:32 +00:00
ad efe07d555b Use the softint_* API. 2007-11-07 00:19:54 +00:00
ad a2a3828545 machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h 2007-10-19 11:59:34 +00:00
ad 451aacda90 Merge file descriptor locking, cwdi locking and cross-call changes
from the vmlocking branch.
2007-10-08 15:12:05 +00:00
dyoung 1dc4f12dca Change some ints to bools. 2007-10-06 03:35:14 +00:00
dyoung 2c54ff5913 Good-bye, kernel thread, we don't need you any longer. 2007-10-06 03:30:25 +00:00
dyoung 32fddb3293 Cosmetic: KNF. Litter the code with fewer #if NBPFILTER > 0. 2007-10-05 05:15:58 +00:00
dyoung 944a024048 Remove a lot of dead code. Move gre_do_send() code into greintr(),
and move gre_do_recv() code into gre_receive().  Get rid of some
unused event counters.
2007-10-05 04:55:10 +00:00
dyoung 60149b1ce8 Work in progress: use a raw socket for GRE in IP encapsulation
instead of adding/subtracting our own IPv4 header.

There are many benefits:  gre(4) needn't grok the outer encapsulation
header any longer, so this simplifies the gre(4) code.  The IP
stack needn't grok GRE, so it is simplified, too.  gre(4) will
benefit from optimizations in the socket code.  Eventually, gre(4)
will gain an IPv6 encapsulation with very few new lines of code.

There is a small performance loss.  A 133 MHz, 486-class AMD Elan
sinks/sources a TCP stream over GRE with about 93% the throughput
of the old code.  TCP throughput on a 266 MHz, 586-class AMD Geode
is about 96% the throughput of the old code.  A 175-MHz ADM5120
(MIPS) only sinks a TCP stream over GRE at about 90% of the old
code; I am still investigating that.

I produced stripped-down versions of sosend() and soreceive() for
gre(4) to use.  They are guaranteed not to block, so they can be
called from a software interrupt and from a socket upcall,
respectively.

A kernel thread is no longer necessary for socket transmit/receive,
but I didn't get around to removing it, yet.

Thanks to Matt Thomas for suggesting the use of stripped-down socket
code and software interrupts, and to Andrew Doran for advice and
answers concerning software interrupts, threads, and performance.
2007-10-05 03:28:12 +00:00
dyoung 7cf94b5474 Rename gre_socreate1() -> gre_socreate(). 2007-09-08 04:34:02 +00:00
dyoung da055795a8 Delete unused variable. 2007-09-02 07:03:22 +00:00
dyoung c87aad4f08 Simplify code, add debug statements, and fix a bug that could
soclose() a UDP socket that a struct file still pointed at.
2007-09-02 07:01:41 +00:00
dyoung 76b1df3703 Get rid of struct oifreq/ifreq compat code, because ifioctl() has
taken care of this for us.
2007-09-02 01:50:58 +00:00
dyoung 0af5ef16d6 Be consistent: use the prefix sc_ for all members of the gre_softc. 2007-09-02 01:49:49 +00:00
dyoung e44b703953 Move sc_fp & sc_newfp from struct gre_softc to struct gre_soparm. 2007-08-30 05:54:07 +00:00
dyoung 7ac92eed2a Remove out-of-date debug message and comment. 2007-08-30 05:14:32 +00:00
dyoung 17038010cb Do not hold the mutex as much in gre_thread1(). Move initial mutex
acquisition and final release out into gre_thread().  This will
fix a locking bug that LOCKDEBUG exposed: holding a spinlock over
an sosend() call is a no-no.

Cosmetic: join some lines, remove some unnecessary curly braces.
2007-08-30 04:58:25 +00:00
dyoung e7e5e02759 Overhaul gre(4), especially the GRE in UDP bits:
* Create the kernel thread in gre_clone_create() instead of trying
  to create it in gre_ioctl().  (Thanks ad@ for suggesting it, and
  pointing out that I can't kthread_create while I hold a spin
  lock.)  Run the thread always, but put it to sleep while the
  gre(4) is not in UDP mode.

* Use sockaddr_in_init().

* Move some thread state off of the stack and into the softc.

* Extract subroutines gre_do_recv(), gre_do_send(), and gre_reconf()
  from gre_thread1(), making the code more readable.
2007-08-24 23:38:31 +00:00
skd d4509b0376 Clean up net compat ioctls, and clean up handling of wireless ioctls. 2007-08-20 04:49:40 +00:00
joerg b2dde09db1 Explicitly assert that the protocol out pr_ctloutput before calling it. 2007-08-14 16:03:48 +00:00
seanb 7a700a611e - Check IFF_RUNNING | IFF_UP in gre_output() correctly. 2007-08-14 13:36: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
christos d81aadc176 Move the nasty ifdefs in one place. Requested by ad and dyoung. 2007-05-30 21:02:02 +00:00
christos 781021f65e fix unused variable. 2007-05-29 23:32:41 +00:00
xtraeme 967c5e0168 Initialize oifr to fix build with COMPAT_40. 2007-05-29 22:05:01 +00:00
christos 20bfd9898e Add a sockaddr_storage member to "struct ifreq" maintaining backwards
compatibility with the older ioctls. This avoids stack smashing and
abuse of "struct sockaddr" when ioctls placed "struct sockaddr_foo's" that
were longer than "struct sockaddr".
XXX: Some of the emulations might be broken; I tried to add code for
them but I did not test them.
2007-05-29 21:32:27 +00:00
dyoung d9b62cfaed Switch from spl(9) to mutex(9) and condvar(9).
Fix a defect in the locking of file descriptors as we delegate a
UDP socket from userland to the kernel.  Move sc_fp out of sc_soparm.
Synchronize access to sc_fp by gre_ioctl() and the kernel thread
using a condition variable.  For simplicity's sake, make it the
kernel helper thread's responsibility to close its UDP socket.
2007-05-06 02:47:52 +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 3ce5c94b0e In gre_clone_destroy(), free the route cache after calling if_detach(),
because if_detach() may cause us to transmit a packet, which
ordinarily entails reloading the route cache.  This fixes a bug
where the kernel would panic later in rtflush().  Thanks Michael
Earnhart for reporting the bug.

In gre_output(), do not leak mbufs.
2007-04-14 22:41:42 +00:00
dyoung be7bb25d74 Make all debug messages use GRE_DPRINTF(). Get rid of a redundant
if_ierrors++.  Change (type *)0 to NULL.  Get rid of unnecessary
casts to void *.
2007-03-21 03:18:08 +00:00
dyoung 271d77fa58 If we do not recognize the protocol of a received packet, then
increase ifi_noproto.  If the GRE header contains routing options,
increase the input-error count, ifi_ierrors.

While I am here, make some cosmetic changes: remove unnecessary
'proto' argument from gre_input3().  Shorten some staircases.
2007-03-21 01:56:05 +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
dyoung 2bc5758505 Cosmetic: remove gratuitous () from return statements. 2007-02-23 06:13:24 +00:00
dyoung 6917e4364d If we enter gre_output() without a route in the cache, call
rtcache_init() to try to fill the cache.  rtcache_check() was not
sufficient.
2007-02-23 06:10:40 +00:00
dyoung 9020519740 Destroy route cache before destroying the interface. 2007-02-23 04:20:02 +00:00
dyoung 5493f188c7 KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.

Cosmetic: don't open-code TAILQ_FOREACH().

Cosmetic: change types of variables to avoid oodles of casts: in
   in6_src.c, avoid casts by changing several route_in6 pointers
   to struct route pointers.  Remove unnecessary casts to caddr_t
   elsewhere.

Pave the way for eliminating address family-specific route caches:
   soon, struct route will not embed a sockaddr, but it will hold
   a reference to an external sockaddr, instead.  We will set the
   destination sockaddr using rtcache_setdst().  (I created a stub
   for it, but it isn't used anywhere, yet.)  rtcache_free() will
   free the sockaddr.  I have extracted from rtcache_free() a helper
   subroutine, rtcache_clear().  rtcache_clear() will "forget" a
   cached route, but it will not forget the destination by releasing
   the sockaddr.  I use rtcache_clear() instead of rtcache_free()
   in rtcache_update(), because rtcache_update() is not supposed
   to forget the destination.

Constify:

   1 Introduce const accessor for route->ro_dst, rtcache_getdst().

   2 Constify the 'dst' argument to ifnet->if_output().  This
     led me to constify a lot of code called by output routines.

   3 Constify the sockaddr argument to protosw->pr_ctlinput.  This
     led me to constify a lot of code called by ctlinput routines.

   4 Introduce const macros for converting from a generic sockaddr
     to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
     satocsin, et cetera.
2007-02-17 22:34:07 +00:00
dyoung 2115f7da2f Fix the check for a routing loop. 2007-01-26 19:32:32 +00:00
dyoung 832c31b2c6 Mark some shared variables as volatile. 2007-01-26 03:01:32 +00:00
joerg eb04733c4e Introduce new helper functions to abstract the route caching.
rtcache_init and rtcache_init_noclone lookup ro_dst and store
the result in ro_rt, taking care of the reference counting and
calling the domain specific route cache.
rtcache_free checks if a route was cashed and frees the reference.
rtcache_copy copies ro_dst of the given struct route, checking that
enough space is available and incrementing the reference count of the
cached rtentry if necessary.
rtcache_check validates that the cached route is still up. If it isn't,
it tries to look it up again. Afterwards ro_rt is either a valid again
or NULL.
rtcache_copy is used internally.

Adjust to callers of rtalloc/rtflush in the tree to check the sanity of
ro_dst first (if necessary). If it doesn't fit the expectations, free
the cache, otherwise check if the cached route is still valid. After
that combination, a single check for ro_rt == NULL is enough to decide
whether a new lookup needs to be done with a different ro_dst.
Make the route checking in gre stricter by repeating the loop check
after revalidation.
Remove some unused RADIX_MPATH code in in6_src.c. The logic is slightly
changed here to first validate the route and check RTF_GATEWAY
afterwards. This is sementically equivalent though.
etherip doesn't need sc_route_expire similiar to the gif changes from
dyoung@ earlier.

Based on the earlier patch from dyoung@, reviewed and discussed with
him.
2006-12-15 21:18:52 +00:00
christos 5abf774808 initialize error, cause gcc3 says so. 2006-12-10 23:12:37 +00:00
dyoung cf7bb443ac Straggler from last: convert to rtflush(). 2006-12-09 06:32:58 +00:00
dyoung 627864e36f Per discussion on tech-net@, discard the address-munging hack that
let one create a tunnel with equal inner and outer destination IP
numbers.  Update gre(4) documentation for this change.

Extract subroutine  gre_update_route() from gre_compute_route(),
and always call it in gre_output() to freshen the route for
tunnel-encapsulated packets.
2006-12-04 02:40:15 +00:00
dyoung 31730224f4 In gre_clone_destroy,
1 use splnet() to synchronize gre clone destruction with interrupts,
  and
2 wait to call if_detach() until after joining the gre kernel
  thread.
2006-12-04 01:49:47 +00:00
dyoung 33f672908d Correct the length of the TTL argument to setsockopt(IPPROTO_IP,
IP_TTL).
2006-11-16 22:58:00 +00:00
dyoung 641edc65f1 Cosmetic: s/g_proto/sc_proto/. Remove superfluous parentheses and
curly braces.
2006-11-16 22:26:35 +00:00
christos 168cd830d2 __unused removal on arguments; approved by core. 2006-11-16 01:32:37 +00:00
dyoung 0787046d01 Change lengthy ((struct sockaddr_in *)x) to satosin(x). 2006-11-04 07:13:19 +00:00
dyoung f6cb813915 Remove unused variables. 2006-11-04 06:41:48 +00:00