Commit Graph

73 Commits

Author SHA1 Message Date
martin 44b17951f2 Avoid using m_clget() on a mbuf already in use, especially when we
need the data in the mbuf later and m_clget() changes some fields
overlaid to regular mbuf data. Instead, rearange code a bit, create
data into a new allocated buffer and and use MEXTADD to attach it to
the mbuf, if the mbuf internal space is not sufficient.

This fixes a crash on sparc64 (and probably all other archs where
sizeof(int) != sizeof(struct file *)) when running
regress/sys/kern/unfdpass.

Idea for solution from Matt Thomas, with additional input from YAMAMOTO
Takashi.
2003-12-29 22:08:02 +00:00
matt 7bf0959ab7 Restore a change that made AF_LOCAL sockets block on connect(2) until
accepted.  However, this time this behavor is not the default.  Instead
it must enabled by using the LOCAL_CONNWAIT socket option on either the
connecting or accepting socket.
2003-11-29 10:02:42 +00:00
perry 6032efb56d Revert a change that altered the semantics of AF_LOCAL sockets. Sadly
this made us API incompatible with other Unixes.
2003-11-29 06:08:29 +00:00
hannken a3a898ff0f Add the gating of system calls that cause modifications to the underlying
file system.
The function vfs_write_suspend stops all new write operations to a file
system, allows any file system modifying system calls already in progress
to complete, then sync's the file system to disk and returns. The
function vfs_write_resume allows the suspended write operations to
complete.

From FreeBSD with slight modifications.

Approved by: Frank van der Linden <fvdl@netbsd.org>
2003-10-15 11:28:59 +00:00
matt d7506a7151 Fix typo. 2003-09-03 22:20:34 +00:00
matt ecf95073f1 Change the behavor of AF_LOCAL connect() to sleep until the server has
accepted the connection.  This can prevent a client from overwhelming a
server.
2003-09-03 21:30:12 +00:00
agc aad01611e7 Move UCB-licensed code from 4-clause to 3-clause licence.
Patches provided by Joel Baker in PR 22364, verified by myself.
2003-08-07 16:26:28 +00:00
jdolecek b178c0d519 back rev 1.63 (the linux hack) off - no compat specific code
in generic code, please

we need to massage the passed linux cmsg anyway, linux uses different
alignment for CMSG_DATA on at least some architectures
2003-07-24 07:30:48 +00:00
itojun f874ab05b3 backout previous, there was a comment on LINUX_SOL_SOCKET=1 2003-07-23 22:17:54 +00:00
itojun 8e4006214d #define LINUX_SOL_SOCKET 1, so that we can answer "what the hell is this 1?"
at ease.
2003-07-23 21:42:31 +00:00
christos 8c26e4c591 From Todd Vierling: Accept level == 1 for linux compat. 2003-07-23 19:24:48 +00:00
fvdl d5aece61d6 Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
2003-06-29 22:28:00 +00:00
darrenr 960df3c8d1 Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records.  The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
2003-06-28 14:20:43 +00:00
christos 6dbb5081d5 RP/21088: Jesse Off: Return ENOBUFS instead of EINVAL when sbappend fails. 2003-04-10 18:55:11 +00:00
matt 65e5548a17 Add MBUFTRACE kernel option.
Do a little mbuf rework while here.  Change all uses of MGET*(*, M_WAIT, *)
to m_get*(M_WAIT, *).  These are not performance critical and making them
call m_get saves considerable space.  Add m_clget analogue of MCLGET and
make corresponding change for M_WAIT uses.
Modify netinet, gem, fxp, tulip, nfs to support MBUFTRACE.
Begin to change netstat to use sysctl.
2003-02-26 06:31:08 +00:00
pk f82deea4bf Fix a simple_lock() mismatch in unp_internalize().
We may need to merge the passes over the files contained in the message
as noted by enami tsugutomo on tech-smp.
2003-02-25 09:56:15 +00:00
pk 2931081a79 Make updating a file's reference and use count MP-safe. 2003-02-23 14:37:32 +00:00
itojun a1a2fcda1e no need for error check after MEXTMALLOC - jdolecek 2002-11-25 08:31:58 +00:00
itojun 387ba53bc6 MEXTMALLOC() can fail even if M_WAITOK, if arg is too big for malloc(). 2002-11-25 06:32:37 +00:00
matt 48bbf5f234 Use the queue macros from <sys/queue.h> instead of referring to the queue
members directly.  Use *_FOREACH whenever possible.
2002-09-04 01:32:31 +00:00
lukem adc783d537 add RCSIDs 2001-11-12 15:25:01 +00:00
thorpej e45efd967f Deprecate the "m_act" alias of "m_nextpkt" (m_act is a historical
name), and just use m_nextpkt everywhere.
2001-10-18 20:17:24 +00:00
thorpej 80cc38a1af Fix a partial construction problem that can cause race conditions
between creation of a file descriptor and close(2) when using kernel
assisted threads.  What we do is stick descriptors in the table, but
mark them as "larval".  This causes essentially everything to treat
it as a non-existent descriptor, except for fdalloc(), which sees a
filled slot so that it won't (incorrectly) allocate it again.  When
a descriptor is fully constructed, the code that has constructed it
marks it as "mature" (which actually clears the "larval" flag), and
things continue to work as normal.

While here, gather all the code that gets a descriptor from the table
into a fd_getfile() function, and call it, rather than having the
same (sometimes incorrect) code copied all over the place.
2001-06-14 20:32:41 +00:00
thorpej d9b3317e3e Rework fdalloc() even further: split fdalloc() into fdalloc() and
fdexpand().  The former will return ENOSPC if there is not space
in the current filedesc table.  The latter performs the expansion
of the filedesc table.  This means that fdalloc() won't ever block,
and it gives callers an opportunity to clean up before the
potentially-blocking fdexpand() call.

Update all fdalloc() callers to deal with the need-to-fdexpand() case.

Rewrite unp_externalize() to use fdalloc() and fdexpand() in a
safe way, using an algorithm suggested by Bill Sommerfeld:
- Use a temporary array of integers to hold the new filedesc table
  indexes.  This allows us to repeat the loop if necessary.
- Loop through the array of file *'s, assigning them to filedesc table
  slots.  If fdalloc() indicates expansion is necessary, undo the
  assignments we've done so far, expand, and retry the whole process.
- Once all file *'s have been assigned to slots, update the f_msgcount
  and unp_rights counters.
- Right before we return, copy the temporary integer array to the message
  buffer, and trim the length as before.
Note that once locking is added to the filedesc array, this entire
operation will be `atomic', in that the lock will be held while
file *'s are assigned to embryonic table slots, thus preventing anything
else from using them.
2001-06-07 01:29:16 +00:00
thorpej c55795d055 Change fdalloc() to return ERESTART if we had to reallocate the
descriptor array, which may have blocked.  Change callers of
fdalloc() to restart whatever they\'re doing if this condition
happens.  (XXX unp_externalize() needs some work, but that will
be tackled later.)

Change finishdup() to close the descriptor in the `new\' slot if
one exists, and change sys_dup2() accordingly.

Closes a race condition when using kernel-assisted user threads.

While here, garbage-collect UF_MAPPED -- it is not used anywhere.
2001-06-06 17:00:00 +00:00
thorpej 0a3a6e34f8 Oops, missed a couple of places where CMSG_*() should be used. No
functional change in this case, but the code is now correct.
2000-06-05 16:29:45 +00:00
thorpej 724a90318e - Fix file descriptor passing AGAIN. This has apparently been broken
on LP64 systems (and probably the SPARC) since the __cmsg_alignbytes()
  changes went in.
- Change file descriptor passing to use CMSG_DATA(), not (cm + 1).  This
  pretty much has to be done in order to make it work properly on LP64,
  and considering that it's been broken this long...
- Use CMSG_SPACE() to determine the mbuf length needed for a given
  control message, and CMSG_LEN() to stash in the cmsg_len member.
2000-06-05 06:06:07 +00:00
augustss 264f1d27c6 Get rid of register declarations. 2000-03-30 09:27:11 +00:00
thorpej bbf19ba181 Um, hi, let's initialize pointers before we use them. 1999-06-17 23:17:45 +00:00
thorpej e3669c3393 Add "use counting" to file entries. When closing a file, and it's reference
count is 0, wait for use count to drain before finishing the close.

This is necessary in order for multiple processes to safely share file
descriptor tables.
1999-05-05 20:01:01 +00:00
thorpej 4913e22a19 Fix alignment problem in the garbage-collection code path. 1999-05-05 19:05:43 +00:00
thorpej 16936c9565 Break cdir/rdir/cmask info out of struct filedesc, and put it in a new
substructure, `cwdinfo'.  Implement optional sharing of this substructure.

This is required for clone(2).
1999-04-30 18:42:58 +00:00
mrg 48c12bfeed revert previous. oops. 1999-04-21 02:37:07 +00:00
mrg 58540a2274 properly test the msgsz as "msgsz - len". from PR#7386 1999-04-21 02:31:49 +00:00
sommerfe 098b6f8e8a Disallow descriptor-passing of descriptors which are open on
directories which aren't under the recipient's root.

Clean up of many error conditions involving descriptor passing, to
eliminate infinite loops, panics, premature garbage collection of
sockets, and descriptor leaks:
 - Avoid letting unp_gc() see descriptors with a refcount of zero by
removing them from the socket's queue before releasing them.
 - Avoid socket leak in PRU_ABORT (this will also gc descriptors queued
on a not-yet accepted socket when the accepting socket goes away).
 - Put in block comment explaining how unp_gc() should work.
 - Correctly manage unp_defer count so we don't get stuck in an infinite
loop with nothing to do.
 - Don't tie MARK and DEFER bits so closely together.
 - Mark descriptors queued on not-yet-accepted sockets as well.
 - Don't call sorflush on non-socket, it doesn't work very well.
 - Deal with discard of NULL file pointer.
 - Hopefully cause GC to converge faster by only deferring sockets in
unp_mark().
1999-03-22 17:54:38 +00:00
thorpej 943f7cd0e7 In unp_internalize(), add a comment explaining why we must ALIGN() the
data after the cmsghdr when accessing internalized SCM_RIGHTS messages
(i.e. array of struct file *s).  The historic interface does not align
the externalized SCM_RIGHTS messages (i.e. array of ints).
1998-12-21 23:12:19 +00:00
thorpej 992f3b8ea7 Fix a fencepost error in unp_scan() which caused a bad pointer deref on
the SPARC platform only (ILP32 but ALIGNBYTES of 7), due to a missing
ALIGN().
1998-12-21 23:03:02 +00:00
perry 275d1554aa Abolition of bcopy, ovbcopy, bcmp, and bzero, phase one.
bcopy(x, y, z) ->  memcpy(y, x, z)
ovbcopy(x, y, z) -> memmove(y, x, z)
   bcmp(x, y, z) ->  memcmp(x, y, z)
  bzero(x, y)    ->  memset(x, 0, y)
1998-08-04 04:03:10 +00:00
perry 730baa7431 fix sizeofs so they comply with the KNF style guide. yes, it is pedantic. 1998-07-31 22:50:48 +00:00
lukem 786b86d71b use AF_LOCAL instead of AF_UNIX 1998-07-18 05:04:35 +00:00
thorpej 4c50a37133 Back out previous, I botched something. 1998-07-16 00:46:50 +00:00
thorpej b20c7bf68c For SOCK_STREAM, provide the socket credentials to the accepter as soon as
the client connects.
1998-07-10 22:15:47 +00:00
fvdl e5bc90f40c Merge with Lite2 + local changes 1998-03-01 02:20:01 +00:00
thorpej cc22126721 Implement passing credentials as ancillary data on Unix domain sockets,
enabled with the LOCAL_CREDS socket option on the listener.  Semantics are
similar to BSD/OS's:
- Creds are available with first data on SOCK_STREAM, and with every datagram
  on SOCK_DGRAM.
- It is not possible to forge credentials.

Different in that:
- Different credential data structure (ours does not rely on the format
  of internal kernel data structures, and does not pass the login name).
- We can pass creds and file descriptors at the same time (this does not
  work in BSD/OS).

Luke Mewburn <lukem@netbsd.org> gets credit for inspiring me to implement
this.  :-)
1998-01-07 22:57:09 +00:00
thorpej e918c058f1 Fix passing of multiple file descriptors (was broken when code was made
64-bit safe).
1998-01-07 04:03:38 +00:00
christos 3f60774556 PR/4280: Chris Jones: Sending more than one fd over AF_UNIX sockets causes
panic. Bug in the fd -> struct file * conversion...
1997-10-17 17:35:08 +00:00
thorpej 1351e629b3 Several small changes to eliminate kludginess in dealing with unix domain
socket names:
- In unp_setsockaddr() and unp_setpeeraddr(), if the socket name can't
  fit into a single mbuf, allocate enough external storage space to
  hold it.
- In unp_bind() and unp_connect(), perform a similar operation, but allocate
  one extra byte, and ensure that the pathname is nul-terminated.
Many thanks to enami tsugutomo <enami@cv.sony.co.jp> for the sanity
checking.
1997-06-26 06:06:40 +00:00
thorpej a149ed59e4 Eliminate use of dtom() in the handing of UNIX domain sockets. Add an
"unp_addrlen" member to the unpcb, and use it when copying the socket
name.  This eliminates that last uses of dtom() in the system.
1997-06-24 19:12:53 +00:00
kleink 9827bd6dc6 When fstat(2)ing a file descriptor of a local communications domain socket,
fill the socket's creation time into the stat structure's st_[acm]time fields:
POSIX requires this behavior for pipe(2). N.B.: updating the st_[am]time fields
when reading/writing the pipe is neither required nor implemented, though.
1997-05-15 17:01:04 +00:00
cgd 319b64a8f7 Internalize and externalize file descriptors being passed via local domain
socket control messages correctly, without assuming that sizeof(int) ==
sizeof(pointer).  Fixes PR#3183.
1997-04-10 01:51:21 +00:00