Add support for printing the path state for SCTP association.

This commit is contained in:
Michael Tuexen 2017-09-12 21:36:13 +00:00
parent 7c1b51d6dc
commit e389705ed3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=323507
2 changed files with 46 additions and 6 deletions

View File

@ -153,8 +153,12 @@ The address the foreign end of the socket is bound to (see
The remote UDP encapsulation port number if
.Fl U
is specified (only for SCTP).
.It Li STATE
The protocol state if
.It Li PATH STATE
The path state if
.Fl s
is specified (only for SCTP).
.It Li CONN STATE
The connection state if
.Fl s
is specified (only for SCTP or TCP).
.It Li STACK

View File

@ -97,6 +97,7 @@ static int *ports;
struct addr {
struct sockaddr_storage address;
unsigned int encaps_port;
int state;
struct addr *next;
};
@ -534,6 +535,7 @@ gather_sctp(void)
xraddr->address.sa.sa_family);
}
faddr->encaps_port = xraddr->encaps_port;
faddr->state = xraddr->state;
faddr->next = NULL;
if (prev_faddr == NULL)
sock->faddr = faddr;
@ -939,7 +941,7 @@ check_ports(struct sock *s)
}
static const char *
sctp_state(int state)
sctp_conn_state(int state)
{
switch (state) {
case SCTP_CLOSED:
@ -978,6 +980,25 @@ sctp_state(int state)
}
}
static const char *
sctp_path_state(int state)
{
switch (state) {
case SCTP_UNCONFIRMED:
return "UNCONFIRMED";
break;
case SCTP_ACTIVE:
return "ACTIVE";
break;
case SCTP_INACTIVE:
return "INACTIVE";
break;
default:
return "UNKNOWN";
break;
}
}
static void
displaysock(struct sock *s, int pos)
{
@ -1062,6 +1083,19 @@ displaysock(struct sock *s, int pos)
}
offset += 7;
}
if (opt_s) {
if (faddr != NULL &&
s->proto == IPPROTO_SCTP &&
s->state != SCTP_CLOSED &&
s->state != SCTP_BOUND &&
s->state != SCTP_LISTEN) {
while (pos < offset)
pos += xprintf(" ");
pos += xprintf("%s",
sctp_path_state(faddr->state));
}
offset += 13;
}
if (first) {
if (opt_s) {
if (s->proto == IPPROTO_SCTP ||
@ -1071,7 +1105,7 @@ displaysock(struct sock *s, int pos)
switch (s->proto) {
case IPPROTO_SCTP:
pos += xprintf("%s",
sctp_state(s->state));
sctp_conn_state(s->state));
break;
case IPPROTO_TCP:
if (s->state >= 0 &&
@ -1118,8 +1152,10 @@ display(void)
"LOCAL ADDRESS", "FOREIGN ADDRESS");
if (opt_U)
printf(" %-6s", "ENCAPS");
if (opt_s)
printf(" %-12s", "STATE");
if (opt_s) {
printf(" %-12s", "PATH STATE");
printf(" %-12s", "CONN STATE");
}
if (opt_S)
printf(" %.*s", TCP_FUNCTION_NAME_LEN_MAX, "STACK");
printf("\n");