version 1.177.2.1, 2009/01/19 13:19:40 |
version 1.177.4.3, 2009/05/03 13:18:55 |
|
|
/* $NetBSD$ */ |
/* $NetBSD$ */ |
|
|
/*- |
/*- |
* Copyright (c) 2002, 2007, 2008 The NetBSD Foundation, Inc. |
* Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc. |
* All rights reserved. |
* All rights reserved. |
* |
* |
* This code is derived from software contributed to The NetBSD Foundation |
* This code is derived from software contributed to The NetBSD Foundation |
* by Jason R. Thorpe of Wasabi Systems, Inc. |
* by Jason R. Thorpe of Wasabi Systems, Inc, and by Andrew Doran. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* modification, are permitted provided that the following conditions |
|
|
#include <sys/cdefs.h> |
#include <sys/cdefs.h> |
__KERNEL_RCSID(0, "$NetBSD$"); |
__KERNEL_RCSID(0, "$NetBSD$"); |
|
|
#include "opt_compat_netbsd.h" |
|
#include "opt_sock_counters.h" |
#include "opt_sock_counters.h" |
#include "opt_sosend_loan.h" |
#include "opt_sosend_loan.h" |
#include "opt_mbuftrace.h" |
#include "opt_mbuftrace.h" |
Line 93 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 92 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <sys/mutex.h> |
#include <sys/mutex.h> |
#include <sys/condvar.h> |
#include <sys/condvar.h> |
|
|
#ifdef COMPAT_50 |
|
#include <compat/sys/time.h> |
|
#include <compat/sys/socket.h> |
|
#endif |
|
|
|
#include <uvm/uvm.h> |
#include <uvm/uvm.h> |
|
|
MALLOC_DEFINE(M_SOOPTS, "soopts", "socket options"); |
MALLOC_DEFINE(M_SOOPTS, "soopts", "socket options"); |
Line 156 static kcondvar_t socurkva_cv; |
|
Line 150 static kcondvar_t socurkva_cv; |
|
static size_t sodopendfree(void); |
static size_t sodopendfree(void); |
static size_t sodopendfreel(void); |
static size_t sodopendfreel(void); |
|
|
static void sysctl_kern_somaxkva_setup(void); |
|
static struct sysctllog *socket_sysctllog; |
|
|
|
static vsize_t |
static vsize_t |
sokvareserve(struct socket *so, vsize_t len) |
sokvareserve(struct socket *so, vsize_t len) |
{ |
{ |
|
|
soinit(void) |
soinit(void) |
{ |
{ |
|
|
sysctl_kern_somaxkva_setup(); |
|
|
|
mutex_init(&so_pendfree_lock, MUTEX_DEFAULT, IPL_VM); |
mutex_init(&so_pendfree_lock, MUTEX_DEFAULT, IPL_VM); |
softnet_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE); |
softnet_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE); |
cv_init(&socurkva_cv, "sokva"); |
cv_init(&socurkva_cv, "sokva"); |
Line 680 soclose(struct socket *so) |
|
Line 669 soclose(struct socket *so) |
|
if ((so->so_state & SS_ISDISCONNECTING) && so->so_nbio) |
if ((so->so_state & SS_ISDISCONNECTING) && so->so_nbio) |
goto drop; |
goto drop; |
while (so->so_state & SS_ISCONNECTED) { |
while (so->so_state & SS_ISCONNECTED) { |
error = sowait(so, so->so_linger * hz); |
error = sowait(so, true, so->so_linger * hz); |
if (error) |
if (error) |
break; |
break; |
} |
} |
Line 1547 soshutdown(struct socket *so, int how) |
|
Line 1536 soshutdown(struct socket *so, int how) |
|
return error; |
return error; |
} |
} |
|
|
|
int |
|
sodrain(struct socket *so) |
|
{ |
|
int error; |
|
|
|
solock(so); |
|
so->so_state |= SS_ISDRAINING; |
|
cv_broadcast(&so->so_cv); |
|
error = soshutdown(so, SHUT_RDWR); |
|
sounlock(so); |
|
|
|
return error; |
|
} |
|
|
void |
void |
sorflush(struct socket *so) |
sorflush(struct socket *so) |
{ |
{ |
Line 1582 sorflush(struct socket *so) |
|
Line 1585 sorflush(struct socket *so) |
|
static int |
static int |
sosetopt1(struct socket *so, const struct sockopt *sopt) |
sosetopt1(struct socket *so, const struct sockopt *sopt) |
{ |
{ |
int error = EINVAL, optval, opt; |
int error, optval; |
struct linger l; |
struct linger l; |
struct timeval tv; |
struct timeval tv; |
|
|
switch ((opt = sopt->sopt_name)) { |
switch (sopt->sopt_name) { |
|
|
case SO_ACCEPTFILTER: |
case SO_ACCEPTFILTER: |
error = accept_filt_setopt(so, sopt); |
error = accept_filt_setopt(so, sopt); |
Line 1619 sosetopt1(struct socket *so, const struc |
|
Line 1622 sosetopt1(struct socket *so, const struc |
|
case SO_REUSEPORT: |
case SO_REUSEPORT: |
case SO_OOBINLINE: |
case SO_OOBINLINE: |
case SO_TIMESTAMP: |
case SO_TIMESTAMP: |
#ifdef SO_OTIMESTAMP |
|
case SO_OTIMESTAMP: |
|
#endif |
|
error = sockopt_getint(sopt, &optval); |
error = sockopt_getint(sopt, &optval); |
solock(so); |
solock(so); |
if (error) |
if (error) |
break; |
break; |
if (optval) |
if (optval) |
so->so_options |= opt; |
so->so_options |= sopt->sopt_name; |
else |
else |
so->so_options &= ~opt; |
so->so_options &= ~sopt->sopt_name; |
break; |
break; |
|
|
case SO_SNDBUF: |
case SO_SNDBUF: |
Line 1650 sosetopt1(struct socket *so, const struc |
|
Line 1650 sosetopt1(struct socket *so, const struc |
|
break; |
break; |
} |
} |
|
|
switch (opt) { |
switch (sopt->sopt_name) { |
case SO_SNDBUF: |
case SO_SNDBUF: |
if (sbreserve(&so->so_snd, (u_long)optval, so) == 0) { |
if (sbreserve(&so->so_snd, (u_long)optval, so) == 0) { |
error = ENOBUFS; |
error = ENOBUFS; |
Line 1687 sosetopt1(struct socket *so, const struc |
|
Line 1687 sosetopt1(struct socket *so, const struc |
|
} |
} |
break; |
break; |
|
|
#ifdef COMPAT_50 |
|
case SO_OSNDTIMEO: |
|
case SO_ORCVTIMEO: { |
|
struct timeval50 otv; |
|
error = sockopt_get(sopt, &otv, sizeof(otv)); |
|
if (error) |
|
break; |
|
timeval50_to_timeval(&otv, &tv); |
|
opt = opt == SO_OSNDTIMEO ? SO_SNDTIMEO : SO_RCVTIMEO; |
|
error = 0; |
|
/*FALLTHROUGH*/ |
|
} |
|
#endif /* COMPAT_50 */ |
|
|
|
case SO_SNDTIMEO: |
case SO_SNDTIMEO: |
case SO_RCVTIMEO: |
case SO_RCVTIMEO: |
if (error) |
error = sockopt_get(sopt, &tv, sizeof(tv)); |
error = sockopt_get(sopt, &tv, sizeof(tv)); |
|
solock(so); |
solock(so); |
if (error) |
if (error) |
break; |
break; |
Line 1718 sosetopt1(struct socket *so, const struc |
|
Line 1703 sosetopt1(struct socket *so, const struc |
|
if (optval == 0 && tv.tv_usec != 0) |
if (optval == 0 && tv.tv_usec != 0) |
optval = 1; |
optval = 1; |
|
|
switch (opt) { |
switch (sopt->sopt_name) { |
case SO_SNDTIMEO: |
case SO_SNDTIMEO: |
so->so_snd.sb_timeo = optval; |
so->so_snd.sb_timeo = optval; |
break; |
break; |
Line 1791 so_setsockopt(struct lwp *l, struct sock |
|
Line 1776 so_setsockopt(struct lwp *l, struct sock |
|
static int |
static int |
sogetopt1(struct socket *so, struct sockopt *sopt) |
sogetopt1(struct socket *so, struct sockopt *sopt) |
{ |
{ |
int error, optval, opt; |
int error, optval; |
struct linger l; |
struct linger l; |
struct timeval tv; |
struct timeval tv; |
|
|
switch ((opt = sopt->sopt_name)) { |
switch (sopt->sopt_name) { |
|
|
case SO_ACCEPTFILTER: |
case SO_ACCEPTFILTER: |
error = accept_filt_getopt(so, sopt); |
error = accept_filt_getopt(so, sopt); |
Line 1817 sogetopt1(struct socket *so, struct sock |
|
Line 1802 sogetopt1(struct socket *so, struct sock |
|
case SO_BROADCAST: |
case SO_BROADCAST: |
case SO_OOBINLINE: |
case SO_OOBINLINE: |
case SO_TIMESTAMP: |
case SO_TIMESTAMP: |
#ifdef SO_OTIMESTAMP |
error = sockopt_setint(sopt, |
case SO_OTIMESTAMP: |
(so->so_options & sopt->sopt_name) ? 1 : 0); |
#endif |
|
error = sockopt_setint(sopt, (so->so_options & opt) ? 1 : 0); |
|
break; |
break; |
|
|
case SO_TYPE: |
case SO_TYPE: |
Line 1848 sogetopt1(struct socket *so, struct sock |
|
Line 1831 sogetopt1(struct socket *so, struct sock |
|
error = sockopt_setint(sopt, so->so_rcv.sb_lowat); |
error = sockopt_setint(sopt, so->so_rcv.sb_lowat); |
break; |
break; |
|
|
#ifdef COMPAT_50 |
|
case SO_OSNDTIMEO: |
|
case SO_ORCVTIMEO: { |
|
struct timeval50 otv; |
|
|
|
optval = (opt == SO_OSNDTIMEO ? |
|
so->so_snd.sb_timeo : so->so_rcv.sb_timeo); |
|
|
|
otv.tv_sec = optval / hz; |
|
otv.tv_usec = (optval % hz) * tick; |
|
|
|
error = sockopt_set(sopt, &otv, sizeof(otv)); |
|
break; |
|
} |
|
#endif /* COMPAT_50 */ |
|
|
|
case SO_SNDTIMEO: |
case SO_SNDTIMEO: |
case SO_RCVTIMEO: |
case SO_RCVTIMEO: |
optval = (opt == SO_SNDTIMEO ? |
optval = (sopt->sopt_name == SO_SNDTIMEO ? |
so->so_snd.sb_timeo : so->so_rcv.sb_timeo); |
so->so_snd.sb_timeo : so->so_rcv.sb_timeo); |
|
|
tv.tv_sec = optval / hz; |
tv.tv_sec = optval / hz; |
Line 2076 sohasoutofband(struct socket *so) |
|
Line 2043 sohasoutofband(struct socket *so) |
|
{ |
{ |
|
|
fownsignal(so->so_pgid, SIGURG, POLL_PRI, POLLPRI|POLLRDBAND, so); |
fownsignal(so->so_pgid, SIGURG, POLL_PRI, POLLPRI|POLLRDBAND, so); |
selnotify(&so->so_rcv.sb_sel, POLLPRI | POLLRDBAND, 0); |
selnotify(&so->so_rcv.sb_sel, POLLPRI | POLLRDBAND, NOTE_SUBMIT); |
} |
} |
|
|
static void |
static void |
Line 2307 sysctl_kern_somaxkva(SYSCTLFN_ARGS) |
|
Line 2274 sysctl_kern_somaxkva(SYSCTLFN_ARGS) |
|
return (error); |
return (error); |
} |
} |
|
|
static void |
SYSCTL_SETUP(sysctl_kern_somaxkva_setup, "sysctl kern.somaxkva setup") |
sysctl_kern_somaxkva_setup() |
|
{ |
{ |
|
|
KASSERT(socket_sysctllog == NULL); |
sysctl_createv(clog, 0, NULL, NULL, |
sysctl_createv(&socket_sysctllog, 0, NULL, NULL, |
|
CTLFLAG_PERMANENT, |
CTLFLAG_PERMANENT, |
CTLTYPE_NODE, "kern", NULL, |
CTLTYPE_NODE, "kern", NULL, |
NULL, 0, NULL, 0, |
NULL, 0, NULL, 0, |
CTL_KERN, CTL_EOL); |
CTL_KERN, CTL_EOL); |
|
|
sysctl_createv(&socket_sysctllog, 0, NULL, NULL, |
sysctl_createv(clog, 0, NULL, NULL, |
CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
CTLTYPE_INT, "somaxkva", |
CTLTYPE_INT, "somaxkva", |
SYSCTL_DESCR("Maximum amount of kernel memory to be " |
SYSCTL_DESCR("Maximum amount of kernel memory to be " |