Changeset View
Changeset View
Standalone View
Standalone View
sbin/pfctl/pf_print_state.c
| Show All 35 Lines | |||||
| __FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
| #include <sys/types.h> | #include <sys/types.h> | ||||
| #include <sys/socket.h> | #include <sys/socket.h> | ||||
| #include <sys/endian.h> | #include <sys/endian.h> | ||||
| #include <net/if.h> | #include <net/if.h> | ||||
| #define TCPSTATES | #define TCPSTATES | ||||
| #include <netinet/tcp_fsm.h> | #include <netinet/tcp_fsm.h> | ||||
| #include <netinet/sctp.h> | |||||
| #include <net/pfvar.h> | #include <net/pfvar.h> | ||||
| #include <arpa/inet.h> | #include <arpa/inet.h> | ||||
| #include <netdb.h> | #include <netdb.h> | ||||
| #include <stdint.h> | #include <stdint.h> | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| ▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | print_seq(struct pfctl_state_peer *p) | ||||
| if (p->seqdiff) | if (p->seqdiff) | ||||
| printf("[%u + %u](+%u)", p->seqlo, | printf("[%u + %u](+%u)", p->seqlo, | ||||
| p->seqhi - p->seqlo, p->seqdiff); | p->seqhi - p->seqlo, p->seqdiff); | ||||
| else | else | ||||
| printf("[%u + %u]", p->seqlo, | printf("[%u + %u]", p->seqlo, | ||||
| p->seqhi - p->seqlo); | p->seqhi - p->seqlo); | ||||
| } | } | ||||
| static const char * | |||||
| sctp_state_name(int state) | |||||
| { | |||||
| switch (state) { | |||||
| case SCTP_CLOSED: | |||||
| return ("CLOSED"); | |||||
| case SCTP_BOUND: | |||||
| return ("BOUND"); | |||||
| case SCTP_LISTEN: | |||||
| return ("LISTEN"); | |||||
| case SCTP_COOKIE_WAIT: | |||||
| return ("COOKIE_WAIT"); | |||||
| case SCTP_COOKIE_ECHOED: | |||||
| return ("COOKIE_ECHOED"); | |||||
| case SCTP_ESTABLISHED: | |||||
| return ("ESTABLISHED"); | |||||
| case SCTP_SHUTDOWN_SENT: | |||||
| return ("SHUTDOWN_SENT"); | |||||
| case SCTP_SHUTDOWN_RECEIVED: | |||||
| return ("SHUTDOWN_RECEIVED"); | |||||
| case SCTP_SHUTDOWN_ACK_SENT: | |||||
| return ("SHUTDOWN_ACK_SENT"); | |||||
| case SCTP_SHUTDOWN_PENDING: | |||||
| return ("SHUTDOWN_PENDING"); | |||||
| default: | |||||
| return ("?"); | |||||
| } | |||||
| } | |||||
| void | void | ||||
| print_state(struct pfctl_state *s, int opts) | print_state(struct pfctl_state *s, int opts) | ||||
| { | { | ||||
| struct pfctl_state_peer *src, *dst; | struct pfctl_state_peer *src, *dst; | ||||
| struct pfctl_state_key *key, *sk, *nk; | struct pfctl_state_key *key, *sk, *nk; | ||||
| const char *protoname; | const char *protoname; | ||||
| int min, sec; | int min, sec; | ||||
| sa_family_t af; | sa_family_t af; | ||||
| ▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | if (opts & PF_OPT_VERBOSE) { | ||||
| dst->wscale & PF_WSCALE_MASK); | dst->wscale & PF_WSCALE_MASK); | ||||
| printf("\n"); | printf("\n"); | ||||
| } | } | ||||
| } else if (proto == IPPROTO_UDP && src->state < PFUDPS_NSTATES && | } else if (proto == IPPROTO_UDP && src->state < PFUDPS_NSTATES && | ||||
| dst->state < PFUDPS_NSTATES) { | dst->state < PFUDPS_NSTATES) { | ||||
| const char *states[] = PFUDPS_NAMES; | const char *states[] = PFUDPS_NAMES; | ||||
| printf(" %s:%s\n", states[src->state], states[dst->state]); | printf(" %s:%s\n", states[src->state], states[dst->state]); | ||||
| } else if (proto == IPPROTO_SCTP) { | |||||
| printf(" %s:%s\n", sctp_state_name(src->state), | |||||
| sctp_state_name(dst->state)); | |||||
| #ifndef INET6 | #ifndef INET6 | ||||
| } else if (proto != IPPROTO_ICMP && src->state < PFOTHERS_NSTATES && | } else if (proto != IPPROTO_ICMP && src->state < PFOTHERS_NSTATES && | ||||
| dst->state < PFOTHERS_NSTATES) { | dst->state < PFOTHERS_NSTATES) { | ||||
| #else | #else | ||||
| } else if (proto != IPPROTO_ICMP && proto != IPPROTO_ICMPV6 && | } else if (proto != IPPROTO_ICMP && proto != IPPROTO_ICMPV6 && | ||||
| src->state < PFOTHERS_NSTATES && dst->state < PFOTHERS_NSTATES) { | src->state < PFOTHERS_NSTATES && dst->state < PFOTHERS_NSTATES) { | ||||
| #endif | #endif | ||||
| /* XXX ICMP doesn't really have state levels */ | /* XXX ICMP doesn't really have state levels */ | ||||
| ▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines | |||||