Export the contents of the syncache to netstat.
Approved by: re (kensmith) MFC after: 2 weeks
This commit is contained in:
parent
4693e424a7
commit
c325962b47
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=171605
@ -78,6 +78,7 @@
|
||||
#include <netinet/tcp_var.h>
|
||||
#include <netinet6/tcp6_var.h>
|
||||
#include <netinet/tcpip.h>
|
||||
#include <netinet/tcp_syncache.h>
|
||||
#ifdef TCPDEBUG
|
||||
#include <netinet/tcp_debug.h>
|
||||
#endif /* TCPDEBUG */
|
||||
|
@ -82,6 +82,7 @@
|
||||
#include <netinet/tcp_seq.h>
|
||||
#include <netinet/tcp_timer.h>
|
||||
#include <netinet/tcp_var.h>
|
||||
#include <netinet/tcp_syncache.h>
|
||||
#ifdef INET6
|
||||
#include <netinet6/tcp6_var.h>
|
||||
#endif
|
||||
@ -876,7 +877,7 @@ tcp_notify(struct inpcb *inp, int error)
|
||||
static int
|
||||
tcp_pcblist(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
int error, i, n;
|
||||
int error, i, m, n, pcb_count;
|
||||
struct inpcb *inp, **inp_list;
|
||||
inp_gen_t gencnt;
|
||||
struct xinpgen xig;
|
||||
@ -886,9 +887,10 @@ tcp_pcblist(SYSCTL_HANDLER_ARGS)
|
||||
* resource-intensive to repeat twice on every request.
|
||||
*/
|
||||
if (req->oldptr == NULL) {
|
||||
m = syncache_pcbcount();
|
||||
n = tcbinfo.ipi_count;
|
||||
req->oldidx = 2 * (sizeof xig)
|
||||
+ (n + n/8) * sizeof(struct xtcpcb);
|
||||
+ ((m + n) + n/8) * sizeof(struct xtcpcb);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -903,19 +905,25 @@ tcp_pcblist(SYSCTL_HANDLER_ARGS)
|
||||
n = tcbinfo.ipi_count;
|
||||
INP_INFO_RUNLOCK(&tcbinfo);
|
||||
|
||||
m = syncache_pcbcount();
|
||||
|
||||
error = sysctl_wire_old_buffer(req, 2 * (sizeof xig)
|
||||
+ n * sizeof(struct xtcpcb));
|
||||
+ (n + m) * sizeof(struct xtcpcb));
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
xig.xig_len = sizeof xig;
|
||||
xig.xig_count = n;
|
||||
xig.xig_count = n + m;
|
||||
xig.xig_gen = gencnt;
|
||||
xig.xig_sogen = so_gencnt;
|
||||
error = SYSCTL_OUT(req, &xig, sizeof xig);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
error = syncache_pcblist(req, m, &pcb_count);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
inp_list = malloc(n * sizeof *inp_list, M_TEMP, M_WAITOK);
|
||||
if (inp_list == NULL)
|
||||
return (ENOMEM);
|
||||
@ -991,7 +999,7 @@ tcp_pcblist(SYSCTL_HANDLER_ARGS)
|
||||
INP_INFO_RLOCK(&tcbinfo);
|
||||
xig.xig_gen = tcbinfo.ipi_gencnt;
|
||||
xig.xig_sogen = so_gencnt;
|
||||
xig.xig_count = tcbinfo.ipi_count;
|
||||
xig.xig_count = tcbinfo.ipi_count + pcb_count;
|
||||
INP_INFO_RUNLOCK(&tcbinfo);
|
||||
error = SYSCTL_OUT(req, &xig, sizeof xig);
|
||||
}
|
||||
|
@ -76,6 +76,7 @@
|
||||
#include <netinet/tcp_seq.h>
|
||||
#include <netinet/tcp_timer.h>
|
||||
#include <netinet/tcp_var.h>
|
||||
#include <netinet/tcp_syncache.h>
|
||||
#ifdef INET6
|
||||
#include <netinet6/tcp6_var.h>
|
||||
#endif
|
||||
@ -1551,3 +1552,76 @@ syncookie_lookup(struct in_conninfo *inc, struct syncache_head *sch,
|
||||
|
||||
return (sc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the current number of syncache entries. This number
|
||||
* will probably change before you get around to calling
|
||||
* syncache_pcblist.
|
||||
*/
|
||||
|
||||
int
|
||||
syncache_pcbcount(void)
|
||||
{
|
||||
struct syncache_head *sch;
|
||||
int count, i;
|
||||
|
||||
for (count = 0, i = 0; i < tcp_syncache.hashsize; i++) {
|
||||
/* No need to lock for a read. */
|
||||
sch = &tcp_syncache.hashbase[i];
|
||||
count += sch->sch_length;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Exports the syncache entries to userland so that netstat can display
|
||||
* them alongside the other sockets. This function is intended to be
|
||||
* called only from tcp_pcblist.
|
||||
*
|
||||
* Due to concurrency on an active system, the number of pcbs exported
|
||||
* may have no relation to max_pcbs. max_pcbs merely indicates the
|
||||
* amount of space the caller allocated for this function to use.
|
||||
*/
|
||||
int
|
||||
syncache_pcblist(struct sysctl_req *req, int max_pcbs, int *pcbs_exported)
|
||||
{
|
||||
struct xtcpcb xt;
|
||||
struct syncache *sc;
|
||||
struct syncache_head *sch;
|
||||
int count, error, i;
|
||||
|
||||
for (count = 0, error = 0, i = 0; i < tcp_syncache.hashsize; i++) {
|
||||
sch = &tcp_syncache.hashbase[i];
|
||||
SCH_LOCK(sch);
|
||||
TAILQ_FOREACH(sc, &sch->sch_bucket, sc_hash) {
|
||||
if (count >= max_pcbs) {
|
||||
SCH_UNLOCK(sch);
|
||||
goto exit;
|
||||
}
|
||||
bzero(&xt, sizeof(xt));
|
||||
xt.xt_len = sizeof(xt);
|
||||
if (sc->sc_inc.inc_isipv6)
|
||||
xt.xt_inp.inp_vflag = INP_IPV6;
|
||||
else
|
||||
xt.xt_inp.inp_vflag = INP_IPV4;
|
||||
bcopy(&sc->sc_inc, &xt.xt_inp.inp_inc, sizeof (struct in_conninfo));
|
||||
xt.xt_tp.t_inpcb = &xt.xt_inp;
|
||||
xt.xt_tp.t_state = TCPS_SYN_RECEIVED;
|
||||
xt.xt_socket.xso_protocol = IPPROTO_TCP;
|
||||
xt.xt_socket.xso_len = sizeof (struct xsocket);
|
||||
xt.xt_socket.so_type = SOCK_STREAM;
|
||||
xt.xt_socket.so_state = SS_ISCONNECTING;
|
||||
error = SYSCTL_OUT(req, &xt, sizeof xt);
|
||||
if (error) {
|
||||
SCH_UNLOCK(sch);
|
||||
goto exit;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
SCH_UNLOCK(sch);
|
||||
}
|
||||
exit:
|
||||
*pcbs_exported = count;
|
||||
return error;
|
||||
}
|
||||
|
||||
|
49
sys/netinet/tcp_syncache.h
Normal file
49
sys/netinet/tcp_syncache.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*-
|
||||
* Copyright (c) 1982, 1986, 1993, 1994, 1995
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)tcp_var.h 8.4 (Berkeley) 5/24/95
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETINET_TCP_SYNCACHE_H_
|
||||
#define _NETINET_TCP_SYNCACHE_H_
|
||||
#ifdef _KERNEL
|
||||
|
||||
void syncache_init(void);
|
||||
void syncache_unreach(struct in_conninfo *, struct tcphdr *);
|
||||
int syncache_expand(struct in_conninfo *, struct tcpopt *,
|
||||
struct tcphdr *, struct socket **, struct mbuf *);
|
||||
void syncache_add(struct in_conninfo *, struct tcpopt *,
|
||||
struct tcphdr *, struct inpcb *, struct socket **, struct mbuf *);
|
||||
void syncache_chkrst(struct in_conninfo *, struct tcphdr *);
|
||||
void syncache_badack(struct in_conninfo *);
|
||||
int syncache_pcbcount(void);
|
||||
int syncache_pcblist(struct sysctl_req *req, int max_pcbs, int *pcbs_exported);
|
||||
|
||||
#endif /* _KERNEL */
|
||||
#endif /* _NETINET_TCP_SYNCACHE_H_ */
|
@ -557,14 +557,6 @@ void tcp_timer_activate(struct tcpcb *, int, u_int);
|
||||
int tcp_timer_active(struct tcpcb *, int);
|
||||
void tcp_trace(short, short, struct tcpcb *, void *, struct tcphdr *, int);
|
||||
void tcp_xmit_bandwidth_limit(struct tcpcb *tp, tcp_seq ack_seq);
|
||||
void syncache_init(void);
|
||||
void syncache_unreach(struct in_conninfo *, struct tcphdr *);
|
||||
int syncache_expand(struct in_conninfo *, struct tcpopt *,
|
||||
struct tcphdr *, struct socket **, struct mbuf *);
|
||||
void syncache_add(struct in_conninfo *, struct tcpopt *,
|
||||
struct tcphdr *, struct inpcb *, struct socket **, struct mbuf *);
|
||||
void syncache_chkrst(struct in_conninfo *, struct tcphdr *);
|
||||
void syncache_badack(struct in_conninfo *);
|
||||
/*
|
||||
* All tcp_hc_* functions are IPv4 and IPv6 (via in_conninfo)
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user