summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authortuexen <tuexen@FreeBSD.org>2016-07-24 14:50:16 +0000
committertuexen <tuexen@FreeBSD.org>2016-07-24 14:50:16 +0000
commit39957276ecb5c9ba6ee716252ccd42d87bf38b80 (patch)
treea148d4cafbdcb3395be30594f3c982a3ecdfc79d /usr.bin
parentd962282f9d8ffeb4d2ee88155ecb9477283f76d2 (diff)
downloadFreeBSD-src-39957276ecb5c9ba6ee716252ccd42d87bf38b80.zip
FreeBSD-src-39957276ecb5c9ba6ee716252ccd42d87bf38b80.tar.gz
MFC r302904:
Fix a bug which results in a core dump when running netstat with the -W option and having a listening SCTP socket. The bug was introduced in r279122 when adding support for libxo. MFC r302907: When calling netstat -Laptcp the local address values are not aligned with the corresponding entry in the table header. r295136 increased the value width from 14 to 32 without the corresponding change to the table header. This commit adds the change to the table header width. MFC r302917: Ensure that the -a, -W, -L options for SCTP behave similar as for TCP. MFC r302928: Address a potential memory leak found a the clang static code analyzer running on the userland stack. MFC r302930: Don't free a data chunk twice. Found by the clang static code analyzer running for the userland stack. MFC r302935: Deal with a portential memory allocation failure, which was reported by the clang static code analyzer. Joint work with rrs@. MFC r302942: Add missing sctps_reasmusrmsgs counter. Joint work with rrs@. MFC r302945: Don't duplicate code for SCTP, just use the ones used for UDP and TCP. This fixes a bug with link local addresses. This will require and upcoming change in the kernel to bring SCTP to the same behaviour as UDP and TCP. MFC r302949: Fix the PR-SCTP behaviour. This is done by rrs@. MFC r302950: Add a constant required by RFC 7496. MFC r303024: netstat and sockstat expect the IPv6 link local addresses to have an embedded scope. So don't recover. MFC r303025: Use correct order of conditions to avoid NULL deref. MFC r303073: Fix a bug in deferred stream reset processing which results in using a length field before it is set. Thanks to Taylor Brandstetter for reporting the issue and providing a fix. Approved by: re (kib)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/netstat/inet.c6
-rw-r--r--usr.bin/netstat/sctp.c98
2 files changed, 14 insertions, 90 deletions
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c
index 54ab56f..6f912ac 100644
--- a/usr.bin/netstat/inet.c
+++ b/usr.bin/netstat/inet.c
@@ -418,10 +418,10 @@ protopr(u_long off, const char *name, int af1, int proto)
"Tcpcb");
if (Lflag)
xo_emit((Aflag && !Wflag) ?
- "{T:/%-5.5s} {T:/%-14.14s} {T:/%-18.18s}" :
+ "{T:/%-5.5s} {T:/%-32.32s} {T:/%-18.18s}" :
((!Wflag || af1 == AF_INET) ?
- "{T:/%-5.5s} {T:/%-14.14s} {T:/%-22.22s}" :
- "{T:/%-5.5s} {T:/%-14.14s} {T:/%-45.45s}"),
+ "{T:/%-5.5s} {T:/%-32.32s} {T:/%-22.22s}" :
+ "{T:/%-5.5s} {T:/%-32.32s} {T:/%-45.45s}"),
"Proto", "Listen", "Local Address");
else if (Tflag)
xo_emit((Aflag && !Wflag) ?
diff --git a/usr.bin/netstat/sctp.c b/usr.bin/netstat/sctp.c
index 0ab933a..fd133e3 100644
--- a/usr.bin/netstat/sctp.c
+++ b/usr.bin/netstat/sctp.c
@@ -104,93 +104,14 @@ struct xraddr_entry {
LIST_ENTRY(xraddr_entry) xraddr_entries;
};
-/*
- * Construct an Internet address representation.
- * If numeric_addr has been supplied, give
- * numeric value, otherwise try for symbolic name.
- */
#ifdef INET
-static char *
-inetname(struct in_addr *inp)
-{
- char *cp;
- static char line[MAXHOSTNAMELEN];
- struct hostent *hp;
- struct netent *np;
-
- cp = 0;
- if (!numeric_addr && inp->s_addr != INADDR_ANY) {
- int net = inet_netof(*inp);
- int lna = inet_lnaof(*inp);
-
- if (lna == INADDR_ANY) {
- np = getnetbyaddr(net, AF_INET);
- if (np)
- cp = np->n_name;
- }
- if (cp == NULL) {
- hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET);
- if (hp) {
- cp = hp->h_name;
- trimdomain(cp, strlen(cp));
- }
- }
- }
- if (inp->s_addr == INADDR_ANY)
- strcpy(line, "*");
- else if (cp) {
- strlcpy(line, cp, sizeof(line));
- } else {
- inp->s_addr = ntohl(inp->s_addr);
-#define C(x) ((u_int)((x) & 0xff))
- sprintf(line, "%u.%u.%u.%u", C(inp->s_addr >> 24),
- C(inp->s_addr >> 16), C(inp->s_addr >> 8), C(inp->s_addr));
- inp->s_addr = htonl(inp->s_addr);
- }
- return (line);
-}
+char *
+inetname(struct in_addr *inp);
#endif
#ifdef INET6
-static char ntop_buf[INET6_ADDRSTRLEN];
-
-static char *
-inet6name(struct in6_addr *in6p)
-{
- char *cp;
- static char line[50];
- struct hostent *hp;
- static char domain[MAXHOSTNAMELEN];
- static int first = 1;
-
- if (first && !numeric_addr) {
- first = 0;
- if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
- (cp = strchr(domain, '.')))
- (void) strcpy(domain, cp + 1);
- else
- domain[0] = 0;
- }
- cp = 0;
- if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
- hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
- if (hp) {
- if ((cp = strchr(hp->h_name, '.')) &&
- !strcmp(cp + 1, domain))
- *cp = 0;
- cp = hp->h_name;
- }
- }
- if (IN6_IS_ADDR_UNSPECIFIED(in6p))
- strcpy(line, "*");
- else if (cp)
- strcpy(line, cp);
- else
- sprintf(line, "%s",
- inet_ntop(AF_INET6, (void *)in6p, ntop_buf,
- sizeof(ntop_buf)));
- return (line);
-}
+char *
+inet6name(struct in6_addr *in6p);
#endif
static void
@@ -447,7 +368,8 @@ sctp_process_inpcb(struct xsctp_inpcb *xinpcb,
first = 0;
}
xladdr = (struct xsctp_laddr *)(buf + *offset);
- if (Lflag && !is_listening) {
+ if ((!aflag && is_listening) ||
+ (Lflag && !is_listening)) {
sctp_skip_xinpcb_ifneed(buf, buflen, offset);
return;
}
@@ -513,8 +435,10 @@ retry:
xo_open_instance("local-address");
if (xladdr_total == 0) {
- xo_emit("{:protocol/%-6.6s/%s} {:type/%-5.5s/%s} ",
- pname, tname);
+ if (!Lflag) {
+ xo_emit("{:protocol/%-6.6s/%s} "
+ "{:type/%-5.5s/%s} ", pname, tname);
+ }
} else {
xo_emit("\n");
xo_emit(Lflag ? "{P:/%-21.21s} " : "{P:/%-12.12s} ",
@@ -529,7 +453,7 @@ retry:
"{:state/CLOSED}", " ");
} else {
xo_emit("{P:/%-45.45s} "
- "{:state:LISTEN}", " ");
+ "{:state/LISTEN}", " ");
}
} else {
if (process_closed) {
OpenPOWER on IntegriCloud