diff options
author | Bob Beck <beck@cvs.openbsd.org> | 1998-06-10 03:40:08 +0000 |
---|---|---|
committer | Bob Beck <beck@cvs.openbsd.org> | 1998-06-10 03:40:08 +0000 |
commit | 33c10bd9ae8695bfa1ca5e5ee23b7654d248285d (patch) | |
tree | 917fe14afd7a04106d7c0521117552d0e95f9afd /sys | |
parent | ebce71cde9046b12ed797121c51fbdb204dd49eb (diff) |
New TCPCTL_IDENT sysctl for identd without kmem insanity.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/netinet/tcp_usrreq.c | 60 | ||||
-rw-r--r-- | sys/netinet/tcp_var.h | 11 |
2 files changed, 67 insertions, 4 deletions
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index f1f2cd1cb4f..f9259a4aa96 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.21 1998/05/18 21:11:09 provos Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.22 1998/06/10 03:40:07 beck Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -82,6 +82,8 @@ extern int tcptv_keep_init; /* from in_pcb.c */ extern struct baddynamicports baddynamicports; +static int tcp_ident __P((void *, size_t *, void *, size_t)); + /* * Process a TCP user request for TCP tb. If this is a send request * then m is the mbuf chain of send data. If this is a timer expiration @@ -578,6 +580,59 @@ tcp_usrclosed(tp) } /* + * Look up a socket for ident.. + */ + +static int +tcp_ident(oldp, oldlenp, newp, newlen) + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; +{ + int error = 0, s; + tcp_ident_mapping tir; + struct inpcb *inp; + struct sockaddr_in *fin, *lin; + + + if (oldp == NULL || newp != NULL || newlen != 0) + return (EINVAL); + if (*oldlenp < sizeof(tir)) + return (ENOMEM); + if ((error = copyin (oldp, &tir, sizeof (tir))) != 0 ) + return (error); + if (tir.faddr.sa_len != sizeof (struct sockaddr) + || (tir.faddr.sa_family != AF_INET)) + return (EINVAL); + fin = (struct sockaddr_in *) &tir.faddr; + lin = (struct sockaddr_in *) &tir.laddr; + + + s = splsoftnet (); + inp = in_pcbhashlookup (&tcbtable, fin->sin_addr, fin->sin_port, + lin->sin_addr, lin->sin_port); + if (inp == NULL) { + ++tcpstat.tcps_pcbhashmiss; + inp = in_pcblookup (&tcbtable, fin->sin_addr, fin->sin_port, + lin->sin_addr, lin->sin_port, 0); + } + if (inp != NULL && (inp->inp_socket->so_state & SS_CONNECTOUT)) { + tir.ruid = inp->inp_socket->so_ruid; + tir.euid = inp->inp_socket->so_euid; + } else { + tir.ruid = -1; + tir.euid = -1; + } + splx(s); + + *oldlenp = sizeof (tir); + error = copyout ((void *)&tir, oldp, sizeof (tir)); + return (error); +} + + +/* * Sysctl for tcp variables. */ int @@ -623,7 +678,8 @@ tcp_sysctl(name, namelen, oldp, oldlenp, newp, newlen) case TCPCTL_SENDSPACE: return (sysctl_int(oldp, oldlenp, newp, newlen,&tcp_sendspace)); - + case TCPCTL_IDENT: + return (tcp_ident(oldp, oldlenp, newp, newlen)); default: return (ENOPROTOOPT); } diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 89c24a90815..b0572fb81f5 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_var.h,v 1.10 1998/03/18 02:37:49 angelos Exp $ */ +/* $OpenBSD: tcp_var.h,v 1.11 1998/06/10 03:40:05 beck Exp $ */ /* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ /* @@ -240,7 +240,8 @@ struct tcpstat { #define TCPCTL_BADDYNAMIC 6 /* return bad dynamic port bitmap */ #define TCPCTL_RECVSPACE 7 /* receive buffer space */ #define TCPCTL_SENDSPACE 8 /* send buffer space */ -#define TCPCTL_MAXID 9 +#define TCPCTL_IDENT 9 /* get connection owner */ +#define TCPCTL_MAXID 10 #define TCPCTL_NAMES { \ { 0, 0 }, \ @@ -252,8 +253,14 @@ struct tcpstat { { "baddynamic", CTLTYPE_STRUCT }, \ { "recvspace", CTLTYPE_INT }, \ { "sendspace", CTLTYPE_INT }, \ + { "ident", CTLTYPE_STRUCT }, \ } +struct tcp_ident_mapping { + struct sockaddr faddr, laddr; + int euid, ruid; +}; + #ifdef _KERNEL struct inpcbtable tcbtable; /* head of queue of active tcpcb's */ struct tcpstat tcpstat; /* tcp statistics */ |