summaryrefslogtreecommitdiff
path: root/sys/compat/linux/linux_socket.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Merge the remainder of kern_vimage.c and vimage.h into vnet.c andRobert Watson2009-08-011-1/+0
| | | | | | | | | | | | | vnet.h, we now use jails (rather than vimages) as the abstraction for virtualization management, and what remained was specific to virtual network stacks. Minor cleanups are done in the process, and comments updated to reflect these changes. Reviewed by: bz Approved by: re (vimage blanket) Notes: svn path=/head/; revision=196019
* Build on Jeff Roberson's linker-set based dynamic per-CPU allocatorRobert Watson2009-07-141-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (DPCPU), as suggested by Peter Wemm, and implement a new per-virtual network stack memory allocator. Modify vnet to use the allocator instead of monolithic global container structures (vinet, ...). This change solves many binary compatibility problems associated with VIMAGE, and restores ELF symbols for virtualized global variables. Each virtualized global variable exists as a "reference copy", and also once per virtual network stack. Virtualized global variables are tagged at compile-time, placing the in a special linker set, which is loaded into a contiguous region of kernel memory. Virtualized global variables in the base kernel are linked as normal, but those in modules are copied and relocated to a reserved portion of the kernel's vnet region with the help of a the kernel linker. Virtualized global variables exist in per-vnet memory set up when the network stack instance is created, and are initialized statically from the reference copy. Run-time access occurs via an accessor macro, which converts from the current vnet and requested symbol to a per-vnet address. When "options VIMAGE" is not compiled into the kernel, normal global ELF symbols will be used instead and indirection is avoided. This change restores static initialization for network stack global variables, restores support for non-global symbols and types, eliminates the need for many subsystem constructors, eliminates large per-subsystem structures that caused many binary compatibility issues both for monitoring applications (netstat) and kernel modules, removes the per-function INIT_VNET_*() macros throughout the stack, eliminates the need for vnet_symmap ksym(2) munging, and eliminates duplicate definitions of virtualized globals under VIMAGE_GLOBALS. Bump __FreeBSD_version and update UPDATING. Portions submitted by: bz Reviewed by: bz, zec Discussed with: gnn, jamie, jeff, jhb, julian, sam Suggested by: peter Approved by: re (kensmith) Notes: svn path=/head/; revision=195699
* Add forgotten in previous commit flags argument.Dmitry Chagin2009-06-011-2/+2
| | | | | | | | Approved by: kib (mentor) MFC after: 1 month Notes: svn path=/head/; revision=193265
* Implement accept4 syscall.Dmitry Chagin2009-06-011-1/+19
| | | | | | | | Approved by: kib (mentor) MFC after: 1 month Notes: svn path=/head/; revision=193264
* Implement a variation of the accept_common() which takesDmitry Chagin2009-06-011-14/+21
| | | | | | | | | | | | | a flags argument. Do not preserve td_retval before kern_fcntl(F_SETFL) as it does not changed. Approved by: kib (mentor) MFC after: 1 month Notes: svn path=/head/; revision=193263
* Split linux_accept() syscall onto linux_accept_common() which shouldDmitry Chagin2009-06-011-13/+22
| | | | | | | | | | be used by linuxulator and linux_accept() itself. Approved by: kib (mentor) MFC after: 1 month Notes: svn path=/head/; revision=193262
* Implement a variation of the socketpair() syscall which takes a flagsDmitry Chagin2009-05-311-2/+28
| | | | | | | | | | in addition to the type argument. Approved by: kib (mentor) MFC after: 1 month Notes: svn path=/head/; revision=193168
* Move new socket flags handling into a separate function as LinuxDmitry Chagin2009-05-311-15/+23
| | | | | | | | | | introduced more syscalls which uses these flags. Approved by: kib (mentor) MFC after: 1 month Notes: svn path=/head/; revision=193165
* Remove empty lines.Dmitry Chagin2009-05-311-2/+0
| | | | | | | | Approved by: kib (mentor) MFC after: 1 month Notes: svn path=/head/; revision=193164
* Validate user-supplied arguments values.Dmitry Chagin2009-05-191-1/+28
| | | | | | | | | | | | Args argument is a pointer to the structure located in user space in which the socketcall arguments are packed. The structure must be copied to the kernel instead of direct dereferencing. Approved by: kib (mentor) MFC after: 1 week Notes: svn path=/head/; revision=192373
* Implement MSG_CMSG_CLOEXEC flag for linux_recvmsg().Dmitry Chagin2009-05-181-9/+24
| | | | | | | | Approved by: kib (mentor) MFC after: 1 month Notes: svn path=/head/; revision=192284
* Somewhere between 2.6.23 and 2.6.27, Linux added SOCK_CLOEXEC andDmitry Chagin2009-05-161-2/+23
| | | | | | | | | | | | | SOCK_NONBLOCK flags, that allow to save fcntl() calls. Implement a variation of the socket() syscall which takes a flags in addition to the type argument. Approved by: kib (mentor) MFC after: 1 month Notes: svn path=/head/; revision=192206
* Return EINVAL in case when the incorrect or unsupportedDmitry Chagin2009-05-161-0/+2
| | | | | | | | | | | | type argument is specified. Do not map type argument value as its Linux values are identical to FreeBSD values. Approved by: kib (mentor) Notes: svn path=/head/; revision=192205
* Use the protocol family constants for the domain argument validation.Dmitry Chagin2009-05-161-3/+5
| | | | | | | | | | Return immediately when the socket() failed. Approved by: kib (mentor) MFC after: 1 month Notes: svn path=/head/; revision=192204
* Emulate SO_PEERCRED socket option.Dmitry Chagin2009-05-161-1/+20
| | | | | | | | | | | | | Temporarily use 0 for pid member as the FreeBSD does not cache remote UNIX domain socket peer pid. PR: kern/102956 Reviewed by: rwatson Approved by: kib (mentor) MFC after: 1 month Notes: svn path=/head/; revision=192203
* Translate l_timeval arg to native struct timeval inDmitry Chagin2009-05-111-0/+40
| | | | | | | | | | | | | | | linux_setsockopt()/linux_getsockopt() for SO_RCVTIMEO, SO_SNDTIMEO opts as l_timeval has MD members. Remove bogus __packed attribute from l_timeval struct on __amd64__. PR: kern/134276 Submitted by: Thomas Mueller <tmueller sysgo com> Approved by: kib (mentor) MFC after: 2 weeks Notes: svn path=/head/; revision=191989
* Add forgotten linux to bsd flags argument mapping into the linux_recv().Dmitry Chagin2009-05-111-1/+1
| | | | | | | | | | PR: kern/134276 Submitted by: Thomas Mueller <tmueller sysgo com> Approved by: kib (mentor) MFC after: 2 weeks Notes: svn path=/head/; revision=191988
* Return EAFNOSUPPORT instead of EINVAL in case when the incorrect orDmitry Chagin2009-05-071-1/+1
| | | | | | | | | unsupported domain argument is specified. Approved by: kib (mentor) Notes: svn path=/head/; revision=191875
* Rework r191742.Dmitry Chagin2009-05-071-5/+12
| | | | | | | | | | | | | | | | | | Use the protocol family constants for the domain argument validation. Return EAFNOSUPPORT in case when the incorrect domain argument is specified. Return EPROTONOSUPPORT instead of passing values that are not 0 to the BSD layer. Suggested by: rwatson Approved by: kib (mentor) MFC after: 1 month Notes: svn path=/head/; revision=191871
* Linux socketpair() call expects explicit specified protocol forDmitry Chagin2009-05-021-1/+4
| | | | | | | | | | AF_LOCAL domain unlike FreeBSD which expects 0 in this case. Approved by: kib (mentor) MFC after: 1 month Notes: svn path=/head/; revision=191742
* In preparation for turning on options VIMAGE in next commits,Marko Zec2009-04-261-0/+2
| | | | | | | | | | | rearrange / replace / adjust several INIT_VNET_* initializer macros, all of which currently resolve to whitespace. Reviewed by: bz (an older version of the patch) Approved by: julian (mentor) Notes: svn path=/head/; revision=191548
* Rather than using hidden includes (with cicular dependencies),Bjoern A. Zeeb2008-12-021-0/+3
| | | | | | | | | | | | | | directly include only the header files needed. This reduces the unneeded spamming of various headers into lots of files. For now, this leaves us with very few modules including vnet.h and thus needing to depend on opt_route.h. Reviewed by: brooks, gnn, des, zec, imp Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=185571
* Make linux_sendmsg() and linux_recvmsg() work on linux32/amd64.Konstantin Belousov2008-11-291-52/+238
| | | | | | | | | | | Change types used in the linux' struct msghdr and struct cmsghdr definitions to the properly-sized architecture-specific types. Move ancillary data handler from linux_sendit() to linux_sendmsg(). Submitted by: dchagin Notes: svn path=/head/; revision=185442
* Retire the MALLOC and FREE macros. They are an abomination unto style(9).Dag-Erling Smørgrav2008-10-231-3/+3
| | | | | | | MFC after: 3 months Notes: svn path=/head/; revision=184205
* Step 1.5 of importing the network stack virtualization infrastructureMarko Zec2008-10-021-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | from the vimage project, as per plan established at devsummit 08/08: http://wiki.freebsd.org/Image/Notes200808DevSummit Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator macros, and CURVNET_SET() context setting macros, all currently resolving to NOPs. Prepare for virtualization of selected SYSCTL objects by introducing a family of SYSCTL_V_*() macros, currently resolving to their global counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT(). Move selected #defines from sys/sys/vimage.h to newly introduced header files specific to virtualized subsystems (sys/net/vnet.h, sys/netinet/vinet.h etc.). All the changes are verified to have zero functional impact at this point in time by doing MD5 comparision between pre- and post-change object files(*). (*) netipsec/keysock.c did not validate depending on compile time options. Implemented by: julian, bz, brooks, zec Reviewed by: julian, bz, brooks, kris, rwatson, ... Approved by: julian (mentor) Obtained from: //depot/projects/vimage-commit2/... X-MFC after: never Sponsored by: NLnet Foundation, The FreeBSD Foundation Notes: svn path=/head/; revision=183550
* Remove superfluous copyin() of args, structures are already in kernel space.Konstantin Belousov2008-09-091-155/+78
| | | | | | | | Submitted by: dchagin MFC after: 1 week Notes: svn path=/head/; revision=182890
* Commit step 1 of the vimage project, (network stack)Bjoern A. Zeeb2008-08-171-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | virtualization work done by Marko Zec (zec@). This is the first in a series of commits over the course of the next few weeks. Mark all uses of global variables to be virtualized with a V_ prefix. Use macros to map them back to their global names for now, so this is a NOP change only. We hope to have caught at least 85-90% of what is needed so we do not invalidate a lot of outstanding patches again. Obtained from: //depot/projects/vimage-commit2/... Reviewed by: brooks, des, ed, mav, julian, jamie, kris, rwatson, zec, ... (various people I forgot, different versions) md5 (with a bit of help) Sponsored by: NLnet Foundation, The FreeBSD Foundation X-MFC after: never V_Commit_Message_Reviewed_By: more people than the patch Notes: svn path=/head/; revision=181803
* Remove the now-unused NET_{LOCK,UNLOCK,ASSERT}_GIANT() macros, whichRobert Watson2007-08-061-2/+0
| | | | | | | | | | | | | | | | | | previously conditionally acquired Giant based on debug.mpsafenet. As that has now been removed, they are no longer required. Removing them significantly simplifies error-handling in the socket layer, eliminated quite a bit of unwinding of locking in error cases. While here clean up the now unneeded opt_net.h, which previously was used for the NET_WITH_GIANT kernel option. Clean up some related gotos for consistency. Reviewed by: bz, csjp Tested by: kris Approved by: re (kensmith) Notes: svn path=/head/; revision=171744
* Some Linux applications (ping) pass a non-NULL msg_control argument toRobert Watson2007-04-141-0/+10
| | | | | | | | | | | sendmsg() while using a 0-length msg_controllen. This isn't allowed in the FreeBSD system call ABI, so detect this case and set msg_control to NULL. This allows Linux ping to work. Submitted by: rdivacky Notes: svn path=/head/; revision=168711
* Introduce some more SO_ option equivalents from Linux to FreeBSD.Konstantin Belousov2007-02-011-0/+18
| | | | | | | | | | The msg variable in linux_recvmsg() was not initialized. Copy it from userspace. Submitted by: rdivacky Notes: svn path=/head/; revision=166398
* MFp4:Alexander Leidinger2006-09-231-2/+7
| | | | | | | | | | | | | | | | | | - Linux returns ENOPROTOOPT in a case of not supported opt to setsockopt. - Return EISDIR in pread() when arg is a directory. - Return EINVAL instead of EFAULT when namelen is not correct in accept(). - Return EINVAL instead of EACCESS if invalid access mode is entered in access(). - Return EINVAL instead of EADDRNOTAVAIL in a case of bad salen param to bind(). Submitted by: rdivacky Tested with: LTP (vfork01 fails now, but it seems to be a race and not caused by those changes) MFC after: 1 week Notes: svn path=/head/; revision=162585
* Don't free the sockaddr in kern_bind() and kern_connect() as not allJohn Baldwin2006-07-191-1/+4
| | | | | | | | callers pass a sockaddr allocated via malloc() from M_SONAME anymore. Instead, free it in the callers when necessary. Notes: svn path=/head/; revision=160506
* Add a kern_close() so that the ABIs can close a file descriptor w/o havingJohn Baldwin2006-07-081-5/+1
| | | | | | | to populate a close_args struct and change some of the places that do. Notes: svn path=/head/; revision=160190
* Now that we don't have a linuxolator on alpha anymore:Alexander Leidinger2006-05-101-88/+29
| | | | | | | | - unifdef __alpha__ - revert rev. 1.66 of linux_socket.c Notes: svn path=/head/; revision=158415
* Annotate uses of fgetsock() with indications that they should relyRobert Watson2006-04-011-0/+4
| | | | | | | | | | on their existing file descriptor references to sockets, rather than use fgetsock() to retrieve a direct socket reference. MFC after: 3 months Notes: svn path=/head/; revision=157369
* Fix the LINT build on alpha:Alexander Leidinger2006-03-211-32/+82
| | | | | | | | | | - rename some file local structure definitions, the names clash with autogenerated names - on !alpha add some compatibility defines for those renamed structures - make some functions globally visible on alpha Notes: svn path=/head/; revision=156976
* Unbreak COMPAT_LINUX32 option support on amd64.Ruslan Ermilov2006-03-191-0/+1
| | | | | | | Broken by: netchild Notes: svn path=/head/; revision=156874
* Fixup some problems in my previous commit (COMPAT_43).Alexander Leidinger2006-03-181-1/+0
| | | | | | | Pointyhat to: netchild Notes: svn path=/head/; revision=156850
* Get rid of the need of COMPAT_43 in the linuxolator.Alexander Leidinger2006-03-181-15/+84
| | | | | | | | Submitted by: Divacky Roman <xdivac02@stud.fit.vutbr.cz> Obtained from: DragonFly (some parts) Notes: svn path=/head/; revision=156842
* Add \n to log() message.Gleb Smirnoff2005-12-271-1/+1
| | | | | | | Submitted by: Stanislaw Halik <weirdo tehran.lain.pl> Notes: svn path=/head/; revision=153744
* Back out alpha/alpha/trap.c:1.124, osf1_ioctl.c:1.14, osf1_misc.c:1.57,Robert Watson2005-09-281-2/+0
| | | | | | | | | | | | | | | | | | | | | | | osf1_signal.c:1.41, amd64/amd64/trap.c:1.291, linux_socket.c:1.60, svr4_fcntl.c:1.36, svr4_ioctl.c:1.23, svr4_ipc.c:1.18, svr4_misc.c:1.81, svr4_signal.c:1.34, svr4_stat.c:1.21, svr4_stream.c:1.55, svr4_termios.c:1.13, svr4_ttold.c:1.15, svr4_util.h:1.10, ext2_alloc.c:1.43, i386/i386/trap.c:1.279, vm86.c:1.58, unaligned.c:1.12, imgact_elf.c:1.164, ffs_alloc.c:1.133: Now that Giant is acquired in uprintf() and tprintf(), the caller no longer leads to acquire Giant unless it also holds another mutex that would generate a lock order reversal when calling into these functions. Specifically not backed out is the acquisition of Giant in nfs_socket.c and rpcclnt.c, where local mutexes are held and would otherwise violate the lock order with Giant. This aligns this code more with the eventual locking of ttys. Suggested by: bde Notes: svn path=/head/; revision=150663
* Add GIANT_REQUIRED and WITNESS sleep warnings to uprintf() and tprintf(),Robert Watson2005-09-191-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | as they both interact with the tty code (!MPSAFE) and may sleep if the tty buffer is full (per comment). Modify all consumers of uprintf() and tprintf() to hold Giant around calls into these functions. In most cases, this means adding an acquisition of Giant immediately around the function. In some cases (nfs_timer()), it means acquiring Giant higher up in the callout. With these changes, UFS no longer panics on SMP when either blocks are exhausted or inodes are exhausted under load due to races in the tty code when running without Giant. NB: Some reduction in calls to uprintf() in the svr4 code is probably desirable. NB: In the case of nfs_timer(), calling uprintf() while holding a mutex, or even in a callout at all, is a bad idea, and will generate warnings and potential upset. This needs to be fixed, but was a problem before this change. NB: uprintf()/tprintf() sleeping is generally a bad ideas, as is having non-MPSAFE tty code. MFC after: 1 week Notes: svn path=/head/; revision=150335
* Add missing locking to linux_connect() so that it can be marked MP safe:John Baldwin2005-07-091-8/+15
| | | | | | | | | | | | - Conditionally grab Giant around the EISCONN hack at the end based on debug.mpsafenet. - Protect access to so_emuldata via SOCK_LOCK. Reviewed by: rwatson Approved by: re (scottl) Notes: svn path=/head/; revision=147853
* Reject packets larger than IP_MAXPACKET in linux_sendto() for socketsDavid Schultz2005-03-231-2/+3
| | | | | | | | | | | | | | with the IP_HDRINCL option set. Without this change, a Linux process with access to a raw socket could cause a kernel panic. Raw sockets must be created by root, and are generally not consigned to untrusted applications; hence, the security implications of this bug are minimal. I believe this only affects 6-CURRENT on or after 2005-01-30. Found by: Coverity Prevent analysis tool Security: Local DOS Notes: svn path=/head/; revision=144012
* Add kernel-only flag MSG_NOSIGNAL to be used in emulation layers to surpressMaxim Sobolev2005-03-081-27/+4
| | | | | | | | | | | SIGPIPE signal for the duration of the sento-family syscalls. Use it to replace previously added hack in Linux layer based on temporarily setting SO_NOSIGPIPE flag. Suggested by: alfred Notes: svn path=/head/; revision=143295
* Handle MSG_NOSIGNAL flag in linux_send() by setting SO_NOSIGPIPE on socketMaxim Sobolev2005-03-071-2/+25
| | | | | | | | | | | | | | | | | for the duration of the send() call. Such approach may be less than ideal in threading environment, when several threads share the same socket and it might happen that several of them are calling linux_send() at the same time with and without SO_NOSIGPIPE set. However, such race condition is very unlikely in practice, therefore this change provides practical improvement compared to the previous behaviour. PR: kern/76426 Submitted by: Steven Hartland <killing@multiplay.co.uk> MFC after: 3 days Notes: svn path=/head/; revision=143233
* Extend kern_sendit() to take another enum uio_seg argument, which specifiesMaxim Sobolev2005-01-301-24/+20
| | | | | | | | | | where the buffer to send lies and use it to eliminate yet another stackgap in linuxlator. MFC after: 2 weeks Notes: svn path=/head/; revision=141029
* Match the LINUX32's style with existing styleDavid E. O'Brien2005-01-141-4/+4
| | | | | | | | | Submitted by: Jung-uk Kim <jkim@niksun.com> Use positive, not negative logic. Notes: svn path=/head/; revision=140214
* Fix the ABI wrappers to use kern_fcntl() rather than calling fcntl()John Baldwin2004-08-241-11/+4
| | | | | | | | | | | directly. This removes a few more users of the stackgap and also marks the syscalls using these wrappers MP safe where appropriate. Tested on: i386 with linux acroread5 Compiled on: i386, alpha LINT Notes: svn path=/head/; revision=134266
* Don't try to translate the control message unless we're certain it'sDag-Erling Smørgrav2004-08-231-1/+2
| | | | | | | | | | | valid; otherwise a caller could trick us into changing any 32-bit word in kernel memory to LINUX_SOL_SOCKET (0x00000001) if its previous value is SOL_SOCKET (0x0000ffff). MFC after: 3 days Notes: svn path=/head/; revision=134209