Commit Graph

187 Commits

Author SHA1 Message Date
rwatson
fa95682921 Merge ipx_usrreq.c:1.56 from HEAD to RELENG_6:
Make this compile without INVARIANTS.
2006-06-08 23:36:39 +00:00
rwatson
de2494a01d Merge README:1.8 from HEAD to RELENG_6:
Add a simple netipx TODO list to the end of README, since there are a
  number of problems with netipx that I have not yet resolved, and I
  don't want them lost track of.
2006-06-08 23:36:03 +00:00
rwatson
42b5ee0134 Merge ipx_input.c:1.55 from HEAD to RELENG_6:
Canonicalize copyright order in one more file that contains my
  copyright.
2006-06-08 23:35:42 +00:00
rwatson
c17170d981 Merge spx_usrreq.c:1.82 from HEAD to RELENG_6:
In spx_output(), use M_DONTWAIT instead of M_TRYWAIT, as we hold the
  ipxpcb mutex.  Contrary to the comment, even in 4.x this was unsafe,
  as parallel use of the socket by another process would result in pcb
  corruption if the mbuf allocation slept.
2006-06-08 23:35:16 +00:00
rwatson
f853872905 Merge spx_usrreq.c:1.81 from HEAD to RELENG_6:
In spx_input(), change a '&&' to a '||', as the spx trace code is able
  to handle a NULL 'cb' here.
2006-06-08 23:34:43 +00:00
rwatson
10b7eb98dd Merge spx_usrreq.c:1.80 from HEAD to RELENG_6:
In spx_accept, assert ipxp != NULL, not == NULL.
2006-06-08 23:33:58 +00:00
rwatson
d17fc2ac36 Merge spx_usrreq.c:1.79 from HEAD to RELENG_6:
In various SPX protocol entry points from the socket layer, check
  IPXP_DROPPED before continuing, and return EINVAL or ECONNRESET if
  it is flagged.  It's unclear why each situation should be one or
  the other, but it is copied from netinet which has the same bugs.
2006-06-08 23:33:24 +00:00
rwatson
2df45add94 Merge ipx_pcb.h:1.26, spx_usrreq.c:1.78 from HEAD to RELENG_6:
Add a new ipxpcb flag, IPXP_SPX, which is set on ipxpcb's to mark them
  as belonging to SPX.  This replaces the implicit assumption that the cb
  pointer for non-SPX pcb's will be NULL.  This isn't required in TCP/IP
  as different pcb lists are maintained for different IP protocols; IPX
  stores all pcbs on the same global ipxpcb_list.

  Foot provided by:       gnn
2006-06-08 23:32:42 +00:00
rwatson
0c607a85c6 Merge spx_usrreq.c:1.77 from HEAD to RELENG_6:
Restore original formulation of SPX segment queue draining during SPX
  PCB detach.
2006-06-08 23:31:47 +00:00
rwatson
0fb4154318 Merge ipx_pcb.c:1.45, ipx_pcb.h:1.25, ipx_usrreq.c:1.53, spx_usrreq.c:1.76
from HEAD to RELENG_6:

  Rework IPX/SPX socket and pcb reference model:

  - Introduce invariant that all IPX/SPX sockets will have valid so_pcb
    pointers to ipxpcb structures, and that for SPX, the control block
    pointer will always be valid.  Don't attempt to free the socket or
    pcb at various odd points, such as disconnect.

  - Add a new ipxpcb flag, IPXP_DROPPED, which will be set in place of
    freeing PCB's so that this invariant can be maintained.  This flag
    is now checked instead of a NULL check in various socket protocol
    calls.

  - Introduce many assertions that this invariant holds.

  - Various pieces of code, such as the SPX timer code, no longer needs
    to jump through hoops in case it frees a PCB while running.

  - Break out ipx_pcbfree() from ipx_pcbdetach().  Likewise
    spx_pcbdetach().

  - Comment on some SMP-related limitations to the SPX code.

  - Update copyrights.
2006-06-08 23:31:16 +00:00
rwatson
97f7b74500 Merge spx_usrreq.c:1.75 from HEAD to RELENG_6:
Restructure spx_attach() to properly free memory in the event that one
  of its allocations fails.  Allocate the ipxp last so as to avoid having
  to free it if another allocation goes wrong.

  Normalize retrieval of ipxp and cb from socket in spx_sp_attach(), and
  add assertions.
2006-06-08 23:28:55 +00:00
rwatson
1f464a1347 Merge spx_usrreq.c:1.74 from HEAD to RELENG_6:
Don't bother restoring host byte order of mbuf fields when we're just
  about to free the mbuf in the spx_input() error path.
2006-06-08 23:22:47 +00:00
rwatson
d5fff948ad Merge spx_usrreq.c:1.73 from HEAD to RELENG_6:
In spx_ctloutput(), acquire the ipxp lock around read operations,
  especially reads of spx header structures, which will now be cached
  in the stack until they can be copied out after releasing the lock.
  Panic if a bad socket option direction is passed in by the caller.
2006-06-08 23:22:02 +00:00
rwatson
b60fd3c465 Merge spx_usrreq.c:1.72 from HEAD to RELENG_6:
Slight style reformatting of spx_timers() comments; panic if an
  unrecognized timer is passed into the function.
2006-06-08 23:21:25 +00:00
rwatson
12b89b7e1c Merge ipx_pcb.c:1.44, spx_usrreq.c:1.71 from HEAD to RELENG_6:
Clean up and style(9) SPX code prior to significant functional changes
  being committed:

  - Wrap comments more evenly on right border.
  - Clean up braces.

  Also, along similar lines:

  - Assert some pointers are non-NULL before dereferencing them.
  - Remove one assertion that looks, on face value, poor.
2006-06-08 23:20:37 +00:00
rwatson
42cd5f7b8b Merge spx_usrreq.c:1.70 from HEAD to RELENG_6:
Protect spx_iss using its own mutex, spx_mtx, rather than piggy-backing
  on the global IPX mutex, which is not held at all necessary strategic
  points.
2006-06-08 23:18:40 +00:00
rwatson
1cf5c31809 Merge spx_usrreq.c:1.69 from HEAD to RELENG_6:
Move definition of spxrexmtthresh to top of file with other global
  variables.
2006-06-08 23:18:01 +00:00
rwatson
34b8bc8d25 Merge spx_usrreq.c:1.68 from HEAD to RELENG_6:
Canonicalize, update copyright.
  Remove 'register'.
  Use ANSI prototypes, not K&R.
2006-06-08 23:17:29 +00:00
rwatson
828233b8f9 Merge ipx_input.c:1.53, spx_usrreq.c:1.66 from HEAD to RELENG_6:
Admit to ourselves that we don't actually implement pr_ctlinput() for
  IPX or SPX, as the code in the implementing functions is essentially
  a no-op.  Replace with a comment indicating we don't implement these
  currently.
2006-06-08 23:15:28 +00:00
rwatson
322724cc00 Merge spx_usrreq.c:1.65 from HEAD to RELENG_6:
In spx_attach() and spx_detach(), there is no need to check whether the
  ipxpcb is NULL or not: in attach it will be, and on detach it won't be.
  If for any reason these invariants don't hold true, panicking is a good
  idea.

  Noticed by:     Coverity Prevent analysis tool
2006-06-08 23:12:22 +00:00
rwatson
1c3e4ff79e Merge README:1.7 from HEAD to RELENG_6:
Update copyright to 2006, comment on my contribution to this code in the
  style of previous contributors.
2006-06-08 23:05:53 +00:00
rwatson
482ab51a1e Merge ipx_input.c:1.54 from HEAD to RELENG_6:
Comment that raw output filter code for IPX should run in a netisr so as
  to avoid recursing the socket code, as this input path can run in the
  call stack of an output path.
2006-06-08 23:05:19 +00:00
rwatson
be1414f73b Merge ipx_pcb.h:1.24, spx_usrreq.c:1.67 from HEAD to RELENG_6:
Move spx_savesi from being a global variable to an automatically allocated
  variable on the spx_input() stack.  It's not very large, and this will
  avoid parallelism issues when spx_input() runs in more than one thread at
  a time.
2006-06-08 23:04:44 +00:00
rwatson
1c31d03e4c Merge ip_ip.c:1.43,1.44 from HEAD to RELENG_6:
When the kernel is compiled with options IPXIP, run the network stack
   with Giant, as there is current unsafety in the IPX tunneled over IP
   code.  There have been no reports of trouble, but there probably would
   be if anyone were running this code at high speed on SMP systems.

   Include kernel.h to get NET_NEEDS_GIANT() definition, which for some
   reason compiled fine here.  I may be running with other include file
   changes locally.

Approved by:	re (kensmith)
2006-03-29 12:42:43 +00:00
rwatson
4b660c6658 Merge ipx_input.c:1.52 from HEAD to RELENG_6:
Remove dead code associated with 'mcopy' in ipx_forward(): at no point
  are the contents of the forwarded mbuf ever copied into mcopy, so there's
  no need to have mcopy, conditionally look at mcopy, or conditionally free
  it.

  Noticed by:     Coverity Prevent analysis tool

Approved by:	re (scottl)
2006-02-14 21:35:07 +00:00
ru
539591f019 MFC: Use sparse initializers for "struct domain" and "struct protosw". 2005-11-16 10:31:23 +00:00
brooks
567ba9b00a Stop embedding struct ifnet at the top of driver softcs. Instead the
struct ifnet or the layer 2 common structure it was embedded in have
been replaced with a struct ifnet pointer to be filled by a call to the
new function, if_alloc(). The layer 2 common structure is also allocated
via if_alloc() based on the interface type. It is hung off the new
struct ifnet member, if_l2com.

This change removes the size of these structures from the kernel ABI and
will allow us to better manage them as interfaces come and go.

Other changes of note:
 - Struct arpcom is no longer referenced in normal interface code.
   Instead the Ethernet address is accessed via the IFP2ENADDR() macro.
   To enforce this ac_enaddr has been renamed to _ac_enaddr.
 - The second argument to ether_ifattach is now always the mac address
   from driver private storage rather than sometimes being ac_enaddr.

Reviewed by:	sobomax, sam
2005-06-10 16:49:24 +00:00
rwatson
46520b8295 Back out ipx.h:1.18, which introduced a Linux API compatibility field in
the ipx_net data structure.  Doing so introduced a stronger alignment
requirement for the address structure, which in turn propagated into
other dependent data structures, which turns out not to be suported by
the available IPX source code.  As a result, a number of user space
applications, such as IPX routing components, failed to operate
correctly.

RELENG_5_3 candidate?

PRs:		74059, 80266
Pointy hat to:	bms
Fix by:		bde
Tested by:	Keith White <Keith dot White at site dot uottawa dot ca>
MFC after:	1 week
Suffering:	great
2005-05-27 12:25:42 +00:00
rwatson
91d6fda379 Update copyright: parts of the netipx implementation are covered by a
2005 copyright.

MFC after:	3 days
2005-04-10 18:05:46 +00:00
rwatson
f6ea4e33f9 Compare (mbuf *) with NULL, not 0.
MFC after:	3 days
2005-04-10 18:05:02 +00:00
rwatson
2aa0dd4e37 Marginally reformat my copyright statement to remove the spurious ','. 2005-03-10 14:19:31 +00:00
rwatson
26df80bf2c In the current world order, solisten() implements the state transition of
a socket from a regular socket to a listening socket able to accept new
connections.  As part of this state transition, solisten() calls into the
protocol to update protocol-layer state.  There were several bugs in this
implementation that could result in a race wherein a TCP SYN received
in the interval between the protocol state transition and the shortly
following socket layer transition would result in a panic in the TCP code,
as the socket would be in the TCPS_LISTEN state, but the socket would not
have the SO_ACCEPTCONN flag set.

This change does the following:

- Pushes the socket state transition from the socket layer solisten() to
  to socket "library" routines called from the protocol.  This permits
  the socket routines to be called while holding the protocol mutexes,
  preventing a race exposing the incomplete socket state transition to TCP
  after the TCP state transition has completed.  The check for a socket
  layer state transition is performed by solisten_proto_check(), and the
  actual transition is performed by solisten_proto().

- Holds the socket lock for the duration of the socket state test and set,
  and over the protocol layer state transition, which is now possible as
  the socket lock is acquired by the protocol layer, rather than vice
  versa.  This prevents additional state related races in the socket
  layer.

This permits the dual transition of socket layer and protocol layer state
to occur while holding locks for both layers, making the two changes
atomic with respect to one another.  Similar changes are likely require
elsewhere in the socket/protocol code.

Reported by:		Peter Holm <peter@holm.cc>
Review and fixes from:	emax, Antoine Brodin <antoine.brodin@laposte.net>
Philosophical head nod:	gnn
2005-02-21 21:58:17 +00:00
rwatson
17c4ed7d82 Mark the IPX netisr as MPSAFE so that inbound IPX traffic is processed
without Giant, and can be directly dispatched in the ithread when
net.isr.enable is turned on.

MFC after:	4 weeks
2005-01-09 07:34:55 +00:00
rwatson
4c896149a5 Recent changes have locked down most of the highly dynamic data
structures in IPX/SPX -- primarily, sequence numbering, PCB lists,
and PCBs for IPX raw sockets, IPX datagram sockets, and IPX/SPX.
As such, remove remove NET_NEEDS_GIANT() for IPX, and remove the
assertion of Giant in the ipxintr() IPX input path.

Note that IPX/SPX is not fully MPSAFE, and that there are some
problems with IPX/SPX locking that will require some further work.
However, it is now safe enough to run in general without the Giant
lock.

MFC after:	4 weeks
2005-01-09 05:34:37 +00:00
rwatson
29ba9d8b8d Use the IPX PCB list mutex and IPX PCB mutexes to lock down the SPX
portion of IPX/SPX:

- Protect IPX PCB lists with the IPX PCB list mutex, in particular
  when calling PCB and PCB list manipulation routines in ipx_pcb.c.
- Protect both IPX PCB state and SPX PCB state using the IPX PCB
  mutex.
- Generally annotate locking, as well as adding liberal use of lock
  assertions to document locking requirements.
- Where possible, use unlocked reads when reading integer or smaller
  sized socket options on SPX sockets.
- De-spl throughout.

Notes:

- spx_input() expects both the list mutex and PCB mutex to be held
  on entry, but will release both on return.  Because sonewconn() is
  called from spx_input(), it may actually drop one PCB lock and
  acquire another during generation of a new connection, meaning the
  caller is not in a position to unlock the PCB mutex.

MFC after:	3 weeks
2005-01-09 05:31:16 +00:00
rwatson
751d9ba04a Clean up return handling for a number of SPX-related routines that
were derived from more complex TCP versions of the same:

- spx_close(), spx_disconnect(), spx_drop(), and spx_usrclosed() all
  always free's the spxpcb invalidating the argument, so a return
  value is not required to indicate if it has.
- Annotate that the cb arguments to each of these functions is
  invalidated via a comment.
- When tearing down a pcb due to sonewconn() having failed, mark the
  cb as NULL; later, when deciding whether to store trace information
  due to SO_DEBUG, check that cb is not NULL before dereferencing or
  a NULL pointer dereference may occur.

MFC after:	3 weeks
2005-01-09 05:25:02 +00:00
rwatson
1845f530cb Protect ipx_pexseq with the IPX PCB list mutex.
When processing socket options against IPX PCBs, generally protect
PCB fields using the IPX PCB mutex.  Where possible, use unlocked
reads on integer values to avoid locking overhead.

MFC after:	3 weeks
2005-01-09 05:15:59 +00:00
rwatson
056eceb470 Acquire or assert the IPX PCB list lock or IPX PCB lock during various
protocol methods relating to IPX.  Conditionally acquire the PCB list
lock in the send operation only if the socket requires binding in order
to use the requested address.

Remove spl's generally no longer required during these accesses.

MFC after:	3 weeks
2005-01-09 05:13:14 +00:00
rwatson
09474340cc Assert or acquire the IPX PCB list lock or IPX PCB locks throughout
the IPX-related PCB routines.  In general, the list lock is required
to iterate the PCB list, either for read or write; the PCB lock is
required to access or modify a PCB.  To change the binding of a PCB,
both locks must be held.

MFC after:	3 weeks
2005-01-09 05:10:43 +00:00
rwatson
c7ec30d9b7 Hold the IPX PCB mutex around calls to ipx_input() in the IPX input
path.

MFC after:	3 weeks
2005-01-09 05:08:47 +00:00
rwatson
cfbc0538b8 Hold the global IPX PCB list mutex in the IPX input path when walking
the IPX PCB list.

MFC after:	3 weeks
2005-01-09 05:06:19 +00:00
rwatson
a6ab698ab0 Introduce a global mutex, ipxpcb_list_mtx, to protect the global
IPX PCB lists.  Add macros to initialize, destroy, lock, unlock,
and assert the mutex.  Initialize the mutex when IPX is started.

Add per-IPX PCB mutexes, ipxp_mtx in struct ipxpcb, to protect
per-PCB IPX/SPX state.  Add macros to initialize, destroy, lock,
unlock, and assert the mutex.  Initialize the mutex when a new
PCB is allocated; destroy it when the PCB is free'd.

MFC after:	2 weeks
2005-01-09 05:00:41 +00:00
rwatson
dbe7c51df6 In ipx_setsockaddr(), use M_WAITOK instead of M_NOWAIT so that the
call always succeeds, avoiding causing the caller to return success
even though the returned *sockaddr is NULL.

MFC after:	2 weeks
2005-01-09 04:47:42 +00:00
rwatson
6307978aa0 Eliminate jump to 'bad' label in order to clean up the ipx_input()
return/unwind path for locking work.

MFC after:	2 weeks
2005-01-09 04:39:16 +00:00
imp
a50ffc2912 /* -> /*- for license, minor formatting changes 2005-01-07 01:45:51 +00:00
rwatson
6ea7cec670 Garbage collect unused ipx_abort().
Spell NULL right in a KASSERT() panic message.

MFC after:	1 week
2005-01-03 12:54:31 +00:00
rwatson
032f856b7e Acquire the socket buffer receive lock in spx_rcvoob() to permit
multiple reads of receive buffer state to be performed atomically.
2005-01-02 15:38:47 +00:00
rwatson
07800ca5f1 Increase the coverage scope of the receive socket buffer lock in
spx_reass() to increase atomicity across multiple operations on the
socket buffer when iterating over the SPX fragment reassembly list
for the ipxpcb, as well a to reduce the number of locking operations.
2005-01-02 15:36:16 +00:00
rwatson
56df19b4b3 Explicitly lock the send socket buffer in spx_reass() to cover the drop
record loop for ACK'd data, rather than relying on lokcing in
sbdroprecord() and sowwakeup(), reducing the number of lock operations
as well as eliminating a possible race against the head of the send
buffer mbuf chain.  Use the _locked variants of sbdroprecord() and
sowwakeup().
2005-01-02 15:33:13 +00:00
rwatson
b45de8ac1b Restructure ipx_input() return code to match similar code in netinet,
avoiding a goto.
2005-01-02 15:29:29 +00:00