Index: head/contrib/tcpdump/interface.h =================================================================== --- head/contrib/tcpdump/interface.h (revision 281937) +++ head/contrib/tcpdump/interface.h (revision 281938) @@ -1,220 +1,218 @@ /* * Copyright (c) 1988-2002 * 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: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef tcpdump_interface_h #define tcpdump_interface_h #ifdef HAVE_OS_PROTO_H #include "os-proto.h" #endif /* snprintf et al */ #include #if HAVE_STDINT_H #include #endif #if !defined(HAVE_SNPRINTF) int snprintf(char *, size_t, const char *, ...) #ifdef __ATTRIBUTE___FORMAT_OK __attribute__((format(printf, 3, 4))) #endif /* __ATTRIBUTE___FORMAT_OK */ ; #endif /* !defined(HAVE_SNPRINTF) */ #if !defined(HAVE_VSNPRINTF) int vsnprintf(char *, size_t, const char *, va_list) #ifdef __ATTRIBUTE___FORMAT_OK __attribute__((format(printf, 3, 0))) #endif /* __ATTRIBUTE___FORMAT_OK */ ; #endif /* !defined(HAVE_VSNPRINTF) */ #ifndef HAVE_STRLCAT extern size_t strlcat(char *, const char *, size_t); #endif #ifndef HAVE_STRLCPY extern size_t strlcpy(char *, const char *, size_t); #endif #ifndef HAVE_STRDUP extern char *strdup(const char *); #endif #ifndef HAVE_STRSEP extern char *strsep(char **, const char *); #endif #define PT_VAT 1 /* Visual Audio Tool */ #define PT_WB 2 /* distributed White Board */ #define PT_RPC 3 /* Remote Procedure Call */ #define PT_RTP 4 /* Real-Time Applications protocol */ #define PT_RTCP 5 /* Real-Time Applications control protocol */ #define PT_SNMP 6 /* Simple Network Management Protocol */ #define PT_CNFP 7 /* Cisco NetFlow protocol */ #define PT_TFTP 8 /* trivial file transfer protocol */ #define PT_AODV 9 /* Ad-hoc On-demand Distance Vector Protocol */ #define PT_CARP 10 /* Common Address Redundancy Protocol */ #define PT_RADIUS 11 /* RADIUS authentication Protocol */ #define PT_ZMTP1 12 /* ZeroMQ Message Transport Protocol 1.0 */ #define PT_VXLAN 13 /* Virtual eXtensible Local Area Network */ #define PT_PGM 14 /* [UDP-encapsulated] Pragmatic General Multicast */ #define PT_PGM_ZMTP1 15 /* ZMTP/1.0 inside PGM (native or UDP-encapsulated) */ #define PT_LMP 16 /* Link Management Protocol */ #define ESRC(ep) ((ep)->ether_shost) #define EDST(ep) ((ep)->ether_dhost) #ifndef NTOHL #define NTOHL(x) (x) = ntohl(x) #define NTOHS(x) (x) = ntohs(x) #define HTONL(x) (x) = htonl(x) #define HTONS(x) (x) = htons(x) #endif #endif extern char *program_name; /* used to generate self-identifying messages */ extern int32_t thiszone; /* seconds offset from gmt to local time */ /* * True if "l" bytes of "var" were captured. * * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large * that "snapend - (l)" underflows. * * The check is for <= rather than < because "l" might be 0. */ #define TTEST2(var, l) (snapend - (l) <= snapend && \ (const u_char *)&(var) <= snapend - (l)) /* True if "var" was captured */ #define TTEST(var) TTEST2(var, sizeof(var)) /* Bail if "l" bytes of "var" were not captured */ #define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc /* Bail if "var" was not captured */ #define TCHECK(var) TCHECK2(var, sizeof(var)) extern int mask2plen(uint32_t); extern const char *tok2strary_internal(const char **, int, const char *, int); #define tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i) extern void error(const char *, ...) __attribute__((noreturn)) #ifdef __ATTRIBUTE___FORMAT_OK __attribute__((format (printf, 1, 2))) #endif /* __ATTRIBUTE___FORMAT_OK */ ; extern void warning(const char *, ...) #ifdef __ATTRIBUTE___FORMAT_OK __attribute__((format (printf, 1, 2))) #endif /* __ATTRIBUTE___FORMAT_OK */ ; extern char *read_infile(char *); extern char *copy_argv(char **); extern const char *dnname_string(u_short); extern const char *dnnum_string(u_short); /* checksum routines */ extern void init_checksum(void); extern uint16_t verify_crc10_cksum(uint16_t, const u_char *, int); extern uint16_t create_osi_cksum(const uint8_t *, int, int); /* The printer routines. */ #include -extern void pfsync_ip_print(const u_char *, u_int); - extern char *q922_string(const u_char *); extern char *smb_errstr(int, int); extern const char *nt_errstr(uint32_t); #ifdef INET6 extern int mask62plen(const u_char *); #endif /*INET6*/ struct cksum_vec { const uint8_t *ptr; int len; }; extern uint16_t in_cksum(const struct cksum_vec *, int); extern uint16_t in_cksum_shouldbe(uint16_t, uint16_t); #ifndef HAVE_BPF_DUMP struct bpf_program; extern void bpf_dump(const struct bpf_program *, int); #endif #include "netdissect.h" /* forward compatibility */ #ifndef NETDISSECT_REWORKED extern netdissect_options *gndo; #define bflag gndo->ndo_bflag #define eflag gndo->ndo_eflag #define fflag gndo->ndo_fflag #define jflag gndo->ndo_jflag #define Kflag gndo->ndo_Kflag #define nflag gndo->ndo_nflag #define Nflag gndo->ndo_Nflag #define Oflag gndo->ndo_Oflag #define pflag gndo->ndo_pflag #define qflag gndo->ndo_qflag #define Rflag gndo->ndo_Rflag #define sflag gndo->ndo_sflag #define Sflag gndo->ndo_Sflag #define tflag gndo->ndo_tflag #define Uflag gndo->ndo_Uflag #define uflag gndo->ndo_uflag #define vflag gndo->ndo_vflag #define xflag gndo->ndo_xflag #define Xflag gndo->ndo_Xflag #define Cflag gndo->ndo_Cflag #define Gflag gndo->ndo_Gflag #define Aflag gndo->ndo_Aflag #define Bflag gndo->ndo_Bflag #define Iflag gndo->ndo_Iflag #define suppress_default_print gndo->ndo_suppress_default_print #define packettype gndo->ndo_packettype #define sigsecret gndo->ndo_sigsecret #define Wflag gndo->ndo_Wflag #define WflagChars gndo->ndo_WflagChars #define Cflag_count gndo->ndo_Cflag_count #define Gflag_count gndo->ndo_Gflag_count #define Gflag_time gndo->ndo_Gflag_time #define Hflag gndo->ndo_Hflag #define snaplen gndo->ndo_snaplen #define snapend gndo->ndo_snapend extern void default_print(const u_char *, u_int); #endif Index: head/contrib/tcpdump/netdissect.h =================================================================== --- head/contrib/tcpdump/netdissect.h (revision 281937) +++ head/contrib/tcpdump/netdissect.h (revision 281938) @@ -1,599 +1,601 @@ /* * Copyright (c) 1988-1997 * The Regents of the University of California. All rights reserved. * * Copyright (c) 1998-2012 Michael Richardson * The TCPDUMP project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef netdissect_h #define netdissect_h #ifdef HAVE_OS_PROTO_H #include "os-proto.h" #endif #include #ifndef HAVE___ATTRIBUTE__ #define __attribute__(x) #endif /* snprintf et al */ #include #include "ip.h" /* struct ip for nextproto4_cksum() */ #if !defined(HAVE_SNPRINTF) int snprintf (char *str, size_t sz, const char *format, ...) #ifdef __ATTRIBUTE___FORMAT_OK __attribute__((format (printf, 3, 4))) #endif /* __ATTRIBUTE___FORMAT_OK */ ; #endif /* !defined(HAVE_SNPRINTF) */ #if !defined(HAVE_VSNPRINTF) int vsnprintf (char *str, size_t sz, const char *format, va_list ap) #ifdef __ATTRIBUTE___FORMAT_OK __attribute__((format (printf, 3, 0))) #endif /* __ATTRIBUTE___FORMAT_OK */ ; #endif /* !defined(HAVE_SNPRINTF) */ #ifndef HAVE_STRLCAT extern size_t strlcat (char *, const char *, size_t); #endif #ifndef HAVE_STRLCPY extern size_t strlcpy (char *, const char *, size_t); #endif #ifndef HAVE_STRDUP extern char *strdup (const char *str); #endif #ifndef HAVE_STRSEP extern char *strsep(char **, const char *); #endif struct tok { u_int v; /* value */ const char *s; /* string */ }; #define TOKBUFSIZE 128 extern const char *tok2strbuf(const struct tok *, const char *, u_int, char *buf, size_t bufsize); /* tok2str is deprecated */ extern const char *tok2str(const struct tok *, const char *, int); extern char *bittok2str(const struct tok *, const char *, int); extern char *bittok2str_nosep(const struct tok *, const char *, int); typedef struct netdissect_options netdissect_options; struct netdissect_options { int ndo_aflag; /* translate network and broadcast addresses */ int ndo_bflag; /* print 4 byte ASes in ASDOT notation */ int ndo_eflag; /* print ethernet header */ int ndo_fflag; /* don't translate "foreign" IP address */ int ndo_Kflag; /* don't check TCP checksums */ int ndo_nflag; /* leave addresses as numbers */ int ndo_Nflag; /* remove domains from printed host names */ int ndo_qflag; /* quick (shorter) output */ int ndo_Rflag; /* print sequence # field in AH/ESP*/ int ndo_sflag; /* use the libsmi to translate OIDs */ int ndo_Sflag; /* print raw TCP sequence numbers */ int ndo_tflag; /* print packet arrival time */ int ndo_Uflag; /* "unbuffered" output of dump files */ int ndo_uflag; /* Print undecoded NFS handles */ int ndo_vflag; /* verbose */ int ndo_xflag; /* print packet in hex */ int ndo_Xflag; /* print packet in hex/ascii */ int ndo_Aflag; /* print packet only in ascii observing TAB, * LF, CR and SPACE as graphical chars */ int ndo_Bflag; /* buffer size */ int ndo_Iflag; /* rfmon (monitor) mode */ int ndo_Oflag; /* run filter code optimizer */ int ndo_dlt; /* if != -1, ask libpcap for the DLT it names*/ int ndo_jflag; /* packet time stamp source */ int ndo_pflag; /* don't go promiscuous */ int ndo_Cflag; /* rotate dump files after this many bytes */ int ndo_Cflag_count; /* Keep track of which file number we're writing */ int ndo_Gflag; /* rotate dump files after this many seconds */ int ndo_Gflag_count; /* number of files created with Gflag rotation */ time_t ndo_Gflag_time; /* The last time_t the dump file was rotated. */ int ndo_Wflag; /* recycle output files after this number of files */ int ndo_WflagChars; int ndo_Hflag; /* dissect 802.11s draft mesh standard */ int ndo_packet_number; /* print a packet number in the beginning of line */ int ndo_suppress_default_print; /* don't use default_print() for unknown packet types */ int ndo_tstamp_precision; /* requested time stamp precision */ const char *ndo_dltname; char *ndo_espsecret; struct sa_list *ndo_sa_list_head; /* used by print-esp.c */ struct sa_list *ndo_sa_default; char *ndo_sigsecret; /* Signature verification secret key */ struct esp_algorithm *ndo_espsecret_xform; /* cache of decoded */ char *ndo_espsecret_key; int ndo_packettype; /* as specified by -T */ char *ndo_program_name; /*used to generate self-identifying messages */ int32_t ndo_thiszone; /* seconds offset from gmt to local time */ int ndo_snaplen; /*global pointers to beginning and end of current packet (during printing) */ const u_char *ndo_packetp; const u_char *ndo_snapend; /* bookkeeping for ^T output */ int ndo_infodelay; /* pointer to void function to output stuff */ void (*ndo_default_print)(netdissect_options *, register const u_char *bp, register u_int length); void (*ndo_info)(netdissect_options *, int verbose); int (*ndo_printf)(netdissect_options *, const char *fmt, ...) #ifdef __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS __attribute__ ((format (printf, 2, 3))) #endif ; void (*ndo_error)(netdissect_options *, const char *fmt, ...) #ifdef __ATTRIBUTE___NORETURN_OK_FOR_FUNCTION_POINTERS __attribute__ ((noreturn)) #endif /* __ATTRIBUTE___NORETURN_OK_FOR_FUNCTION_POINTERS */ #ifdef __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS __attribute__ ((format (printf, 2, 3))) #endif /* __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS */ ; void (*ndo_warning)(netdissect_options *, const char *fmt, ...) #ifdef __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS __attribute__ ((format (printf, 2, 3))) #endif ; }; #define PT_VAT 1 /* Visual Audio Tool */ #define PT_WB 2 /* distributed White Board */ #define PT_RPC 3 /* Remote Procedure Call */ #define PT_RTP 4 /* Real-Time Applications protocol */ #define PT_RTCP 5 /* Real-Time Applications control protocol */ #define PT_SNMP 6 /* Simple Network Management Protocol */ #define PT_CNFP 7 /* Cisco NetFlow protocol */ #define PT_TFTP 8 /* trivial file transfer protocol */ #define PT_AODV 9 /* Ad-hoc On-demand Distance Vector Protocol */ #define PT_CARP 10 /* Common Address Redundancy Protocol */ #define PT_RADIUS 11 /* RADIUS authentication Protocol */ #define PT_ZMTP1 12 /* ZeroMQ Message Transport Protocol 1.0 */ #define PT_VXLAN 13 /* Virtual eXtensible Local Area Network */ #define PT_PGM 14 /* [UDP-encapsulated] Pragmatic General Multicast */ #define PT_PGM_ZMTP1 15 /* ZMTP/1.0 inside PGM (native or UDP-encapsulated) */ #define PT_LMP 16 /* Link Management Protocol */ #ifndef min #define min(a,b) ((a)>(b)?(b):(a)) #endif #ifndef max #define max(a,b) ((b)>(a)?(b):(a)) #endif /* * Maximum snapshot length. This should be enough to capture the full * packet on most network interfaces. * * * Somewhat arbitrary, but chosen to be: * * 1) big enough for maximum-size Linux loopback packets (65549) * and some USB packets captured with USBPcap: * * http://desowin.org/usbpcap/ * * (> 131072, < 262144) * * and * * 2) small enough not to cause attempts to allocate huge amounts of * memory; some applications might use the snapshot length in a * savefile header to control the size of the buffer they allocate, * so a size of, say, 2^31-1 might not work well. * * XXX - does it need to be bigger still? */ #define MAXIMUM_SNAPLEN 262144 /* * The default snapshot length is the maximum. */ #define DEFAULT_SNAPLEN MAXIMUM_SNAPLEN #define ESRC(ep) ((ep)->ether_shost) #define EDST(ep) ((ep)->ether_dhost) #ifndef NTOHL #define NTOHL(x) (x) = ntohl(x) #define NTOHS(x) (x) = ntohs(x) #define HTONL(x) (x) = htonl(x) #define HTONS(x) (x) = htons(x) #endif /* * True if "l" bytes of "var" were captured. * * The "ndo->ndo_snapend - (l) <= ndo->ndo_snapend" checks to make sure * "l" isn't so large that "ndo->ndo_snapend - (l)" underflows. * * The check is for <= rather than < because "l" might be 0. */ #define ND_TTEST2(var, l) (ndo->ndo_snapend - (l) <= ndo->ndo_snapend && \ (const u_char *)&(var) <= ndo->ndo_snapend - (l)) /* True if "var" was captured */ #define ND_TTEST(var) ND_TTEST2(var, sizeof(var)) /* Bail if "l" bytes of "var" were not captured */ #define ND_TCHECK2(var, l) if (!ND_TTEST2(var, l)) goto trunc /* Bail if "var" was not captured */ #define ND_TCHECK(var) ND_TCHECK2(var, sizeof(var)) #define ND_PRINT(STUFF) (*ndo->ndo_printf)STUFF #define ND_DEFAULTPRINT(ap, length) (*ndo->ndo_default_print)(ndo, ap, length) extern void ts_print(netdissect_options *, const struct timeval *); extern void relts_print(netdissect_options *, int); extern int fn_print(netdissect_options *, const u_char *, const u_char *); extern int fn_printn(netdissect_options *, const u_char *, u_int, const u_char *); extern int fn_printzp(netdissect_options *, const u_char *, u_int, const u_char *); extern const char *tok2str(const struct tok *, const char *, int); #if 0 extern char *read_infile(netdissect_options *, char *); extern char *copy_argv(netdissect_options *, char **); #endif /* * Locale-independent macros for testing character properties and * stripping the 8th bit from characters. Assumed to be handed * a value between 0 and 255, i.e. don't hand them a char, as * those might be in the range -128 to 127. */ #define ND_ISASCII(c) (!((c) & 0x80)) /* value is an ASCII code point */ #define ND_ISPRINT(c) ((c) >= 0x20 && (c) <= 0x7E) #define ND_ISGRAPH(c) ((c) > 0x20 && (c) <= 0x7E) #define ND_TOASCII(c) ((c) & 0x7F) extern void safeputchar(netdissect_options *, const u_char); extern void safeputs(netdissect_options *, const u_char *, const u_int); #ifdef LBL_ALIGN /* * The processor doesn't natively handle unaligned loads, * and the compiler might "helpfully" optimize memcpy() * and memcmp(), when handed pointers that would normally * be properly aligned, into sequences that assume proper * alignment. * * Do copies and compares of possibly-unaligned data by * calling routines that wrap memcpy() and memcmp(), to * prevent that optimization. */ extern void unaligned_memcpy(void *, const void *, size_t); extern int unaligned_memcmp(const void *, const void *, size_t); #define UNALIGNED_MEMCPY(p, q, l) unaligned_memcpy((p), (q), (l)) #define UNALIGNED_MEMCMP(p, q, l) unaligned_memcmp((p), (q), (l)) #else /* * The procesor natively handles unaligned loads, so just use memcpy() * and memcmp(), to enable those optimizations. */ #define UNALIGNED_MEMCPY(p, q, l) memcpy((p), (q), (l)) #define UNALIGNED_MEMCMP(p, q, l) memcmp((p), (q), (l)) #endif #define PLURAL_SUFFIX(n) \ (((n) != 1) ? "s" : "") #if 0 extern const char *dnname_string(netdissect_options *, u_short); extern const char *dnnum_string(netdissect_options *, u_short); #endif /* The printer routines. */ #include typedef u_int (*if_ndo_printer)(struct netdissect_options *ndo, const struct pcap_pkthdr *, const u_char *); typedef u_int (*if_printer)(const struct pcap_pkthdr *, const u_char *); extern if_ndo_printer lookup_ndo_printer(int); extern if_printer lookup_printer(int); extern void eap_print(netdissect_options *,const u_char *, u_int); extern int esp_print(netdissect_options *, const u_char *bp, const int length, const u_char *bp2, int *nhdr, int *padlen); extern void arp_print(netdissect_options *,const u_char *, u_int, u_int); extern void tipc_print(netdissect_options *, const u_char *, u_int, u_int); extern void msnlb_print(netdissect_options *, const u_char *); extern void icmp6_print(netdissect_options *ndo, const u_char *, u_int, const u_char *, int); extern void isakmp_print(netdissect_options *,const u_char *, u_int, const u_char *); extern void isakmp_rfc3948_print(netdissect_options *,const u_char *, u_int, const u_char *); extern void ip_print(netdissect_options *,const u_char *, u_int); extern void ip_print_inner(netdissect_options *ndo, const u_char *bp, u_int length, u_int nh, const u_char *bp2); extern void rrcp_print(netdissect_options *,const u_char *, u_int); extern void loopback_print(netdissect_options *, const u_char *, const u_int); extern void carp_print(netdissect_options *, const u_char *, u_int, int); extern void ether_print(netdissect_options *, const u_char *, u_int, u_int, void (*)(netdissect_options *, const u_char *), const u_char *); extern u_int ether_if_print(netdissect_options *, const struct pcap_pkthdr *,const u_char *); extern u_int netanalyzer_if_print(netdissect_options *, const struct pcap_pkthdr *,const u_char *); extern u_int netanalyzer_transparent_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern int ethertype_print(netdissect_options *,u_short, const u_char *, u_int, u_int); extern int print_unknown_data(netdissect_options *,const u_char *, const char *,int); extern void ascii_print(netdissect_options *, const u_char *, u_int); extern void hex_print_with_offset(netdissect_options *, const char *ident, const u_char *cp, u_int, u_int); extern void hex_print(netdissect_options *,const char *ident, const u_char *cp,u_int); extern void hex_and_ascii_print_with_offset(netdissect_options *, const char *, const u_char *, u_int, u_int); extern void hex_and_ascii_print(netdissect_options *, const char *, const u_char *, u_int); extern int ah_print(netdissect_options *, register const u_char *); extern void beep_print(netdissect_options *, const u_char *, u_int); extern void dtp_print(netdissect_options *, const u_char *, u_int); extern u_int cip_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern int ipcomp_print(netdissect_options *, register const u_char *, int *); extern u_int ipfc_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void udld_print(netdissect_options *, const u_char *, u_int); extern void hsrp_print(netdissect_options *, const u_char *, u_int); extern void igrp_print(netdissect_options *, const u_char *, u_int); extern void msdp_print(netdissect_options *, const u_char *, u_int); extern u_int null_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void mobile_print(netdissect_options *, const u_char *, u_int); extern u_int ap1394_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int bt_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void lane_print(netdissect_options *, const u_char *, u_int, u_int); extern u_int lane_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void otv_print(netdissect_options *, const u_char *, u_int); extern void ahcp_print(netdissect_options *, const u_char *, const u_int); extern void vxlan_print(netdissect_options *, const u_char *, u_int); extern u_int arcnet_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int arcnet_linux_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void bfd_print(netdissect_options *, const u_char *, u_int, u_int); extern void gre_print(netdissect_options *, const u_char *, u_int); extern int vjc_print(netdissect_options *, register const char *, u_short); extern void ipN_print(netdissect_options *, const u_char *, u_int); extern u_int raw_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int usb_linux_48_byte_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int usb_linux_64_byte_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int symantec_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int chdlc_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int chdlc_print(netdissect_options *, register const u_char *, u_int); extern void zmtp1_print(netdissect_options *, const u_char *, u_int); extern void zmtp1_print_datagram(netdissect_options *, const u_char *, const u_int); extern void ipx_print(netdissect_options *, const u_char *, u_int); extern void mpls_print(netdissect_options *, const u_char *, u_int); extern u_int pppoe_print(netdissect_options *, const u_char *, u_int); extern u_int pppoe_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void sunrpcrequest_print(netdissect_options *, const u_char *, u_int, const u_char *); extern u_int pflog_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int token_print(netdissect_options *, const u_char *, u_int, u_int); extern u_int token_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void vqp_print(netdissect_options *, register const u_char *, register u_int); extern void zephyr_print(netdissect_options *, const u_char *, int); extern void fddi_print(netdissect_options *, const u_char *, u_int, u_int); extern u_int fddi_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void mpcp_print(netdissect_options *, const u_char *, u_int); extern void rpki_rtr_print(netdissect_options *, const u_char *, u_int); extern u_int sll_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void dccp_print(netdissect_options *, const u_char *, const u_char *, u_int); extern int llc_print(netdissect_options *, const u_char *, u_int, u_int, const u_char *, const u_char *, u_short *); extern int snap_print(netdissect_options *, const u_char *, u_int, u_int, u_int); extern void eigrp_print(netdissect_options *, const u_char *, u_int); extern void stp_print(netdissect_options *, const u_char *, u_int); extern void l2tp_print(netdissect_options *, const u_char *, u_int); extern void udp_print(netdissect_options *, const u_char *, u_int, const u_char *, int); extern void icmp_print(netdissect_options *, const u_char *, u_int, const u_char *, int); extern void openflow_print(netdissect_options *, const u_char *, const u_int); extern void telnet_print(netdissect_options *, const u_char *, u_int); extern void slow_print(netdissect_options *, const u_char *, u_int); extern void radius_print(netdissect_options *, const u_char *, u_int); extern void lmp_print(netdissect_options *, const u_char *, u_int); extern u_int fr_print(netdissect_options *, register const u_char *, u_int); extern u_int mfr_print(netdissect_options *, register const u_char *, u_int); extern u_int fr_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int mfr_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void q933_print(netdissect_options *, const u_char *, u_int); extern void igmp_print(netdissect_options *, const u_char *, u_int); extern void rip_print(netdissect_options *, const u_char *, u_int); extern void lwapp_control_print(netdissect_options *, const u_char *, u_int, int); extern void lwapp_data_print(netdissect_options *, const u_char *, u_int); extern void pgm_print(netdissect_options *, const u_char *, u_int, const u_char *); extern void pptp_print(netdissect_options *, const u_char *); extern void ldp_print(netdissect_options *, const u_char *, u_int); extern void wb_print(netdissect_options *, const void *, u_int); extern int oam_print(netdissect_options *, const u_char *, u_int, u_int); extern void atm_print(netdissect_options *, u_int, u_int, u_int, const u_char *, u_int, u_int); extern u_int sunatm_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int atm_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void vtp_print(netdissect_options *, const u_char *, u_int); extern int mptcp_print(netdissect_options *, const u_char *, u_int, u_char); extern void ntp_print(netdissect_options *, const u_char *, u_int); extern void cnfp_print(netdissect_options *, const u_char *, const u_char *); extern void dvmrp_print(netdissect_options *, const u_char *, u_int); extern void egp_print(netdissect_options *, const u_char *, u_int); extern u_int enc_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int sl_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int sl_bsdos_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void tftp_print(netdissect_options *, const u_char *, u_int); extern void vrrp_print(netdissect_options *, const u_char *, u_int, const u_char *, int); extern void pimv1_print(netdissect_options *, const u_char *, u_int); extern void cisco_autorp_print(netdissect_options *, const u_char *, u_int); extern void pim_print(netdissect_options *, const u_char *, u_int, u_int); extern const u_char * ns_nprint (netdissect_options *, register const u_char *, register const u_char *); extern void ns_print(netdissect_options *, const u_char *, u_int, int); extern void bootp_print(netdissect_options *, const u_char *, u_int); extern void sflow_print(netdissect_options *, const u_char *, u_int); extern void aodv_print(netdissect_options *, const u_char *, u_int, int); extern void sctp_print(netdissect_options *, const u_char *, const u_char *, u_int); extern char *bgp_vpn_rd_print (netdissect_options *, const u_char *); extern void bgp_print(netdissect_options *, const u_char *, int); extern void olsr_print(netdissect_options *, const u_char *, u_int, int); extern void forces_print(netdissect_options *, const u_char *, u_int); extern void lspping_print(netdissect_options *, const u_char *, u_int); extern void isoclns_print(netdissect_options *, const u_char *, u_int, u_int); extern void krb_print(netdissect_options *, const u_char *); extern void cdp_print(netdissect_options *, const u_char *, u_int, u_int); extern void atalk_print(netdissect_options *, const u_char *, u_int); extern u_int ltalk_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int llap_print(netdissect_options *, const u_char *, u_int); extern void aarp_print(netdissect_options *, const u_char *, u_int); extern u_int juniper_atm1_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int juniper_atm2_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int juniper_mfr_print(netdissect_options *, const struct pcap_pkthdr *, register const u_char *); extern u_int juniper_mlfr_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int juniper_mlppp_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int juniper_pppoe_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int juniper_pppoe_atm_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int juniper_ggsn_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int juniper_es_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int juniper_monitor_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int juniper_services_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int juniper_ether_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int juniper_ppp_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int juniper_frelay_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int juniper_chdlc_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void snmp_print(netdissect_options *, const u_char *, u_int); extern void rx_print(netdissect_options *, register const u_char *, int, int, int, u_char *); extern void nfsreply_print(netdissect_options *, const u_char *, u_int, const u_char *); extern void nfsreply_print_noaddr(netdissect_options *, const u_char *, u_int, const u_char *); extern void nfsreq_print_noaddr(netdissect_options *, const u_char *, u_int, const u_char *); extern void sip_print(netdissect_options *, const u_char *, u_int); extern void syslog_print(netdissect_options *, const u_char *, u_int); extern void lwres_print(netdissect_options *, const u_char *, u_int); extern void cfm_print(netdissect_options *, const u_char *, u_int); extern void nbt_tcp_print(netdissect_options *, const u_char *, int); extern void nbt_udp137_print(netdissect_options *, const u_char *, int); extern void nbt_udp138_print(netdissect_options *, const u_char *, int); extern void smb_tcp_print(netdissect_options *, const u_char *, int); extern void netbeui_print(netdissect_options *, u_short, const u_char *, int); extern void ipx_netbios_print(netdissect_options *, const u_char *, u_int); extern void print_data(netdissect_options *, const unsigned char *, int); extern void decnet_print(netdissect_options *, const u_char *, u_int, u_int); extern void tcp_print(netdissect_options *, const u_char *, u_int, const u_char *, int); extern void ospf_print(netdissect_options *, const u_char *, u_int, const u_char *); extern int ospf_print_te_lsa(netdissect_options *, const uint8_t *, u_int); extern int ospf_print_grace_lsa(netdissect_options *, const uint8_t *, u_int); extern u_int ppp_print(netdissect_options *, register const u_char *, u_int); extern u_int ppp_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int ppp_hdlc_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int ppp_bsdos_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern void lldp_print(netdissect_options *, const u_char *, u_int); extern void rsvp_print(netdissect_options *, const u_char *, u_int); extern void timed_print(netdissect_options *, const u_char *); extern void m3ua_print(netdissect_options *, const u_char *, const u_int); extern void aoe_print(netdissect_options *, const u_char *, const u_int); +extern void pfsync_ip_print(netdissect_options *, const u_char *, u_int); + /* stuff that has not yet been rototiled */ #if 0 extern void ascii_print(netdissect_options *,u_int); extern void default_print(netdissect_options *,const u_char *, u_int); extern char *smb_errstr(netdissect_options *,int, int); extern const char *nt_errstr(netdissect_options *, uint32_t); #endif extern u_int ipnet_if_print(netdissect_options *,const struct pcap_pkthdr *, const u_char *); extern u_int ppi_if_print(netdissect_options *,const struct pcap_pkthdr *, const u_char *); extern u_int nflog_if_print(netdissect_options *,const struct pcap_pkthdr *, const u_char *); extern u_int ieee802_15_4_if_print(netdissect_options *,const struct pcap_pkthdr *, const u_char *); extern u_int pktap_if_print(netdissect_options *,const struct pcap_pkthdr *, const u_char *); extern u_int ieee802_11_radio_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int ieee802_11_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int ieee802_11_radio_avs_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); extern u_int prism_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); #ifdef INET6 extern void ip6_print(netdissect_options *,const u_char *, u_int); extern int frag6_print(netdissect_options *, const u_char *, const u_char *); extern int rt6_print(netdissect_options *, const u_char *, const u_char *); extern int hbhopt_print(netdissect_options *, const u_char *); extern int dstopt_print(netdissect_options *, const u_char *); extern void ripng_print(netdissect_options *, const u_char *, unsigned int); extern int mobility_print(netdissect_options *, const u_char *, const u_char *); extern void dhcp6_print(netdissect_options *, const u_char *, u_int); extern void ospf6_print(netdissect_options *, const u_char *, u_int); extern void babel_print(netdissect_options *, const u_char *, u_int); #endif /*INET6*/ #if 0 struct cksum_vec { const uint8_t *ptr; int len; }; extern uint16_t in_cksum(const struct cksum_vec *, int); extern uint16_t in_cksum_shouldbe(uint16_t, uint16_t); #endif extern int nextproto4_cksum(netdissect_options *ndo, const struct ip *, const uint8_t *, u_int, u_int, u_int); extern int decode_prefix4(netdissect_options *ndo, const u_char *, u_int, char *, u_int); #ifdef INET6 extern int decode_prefix6(netdissect_options *ndo, const u_char *, u_int, char *, u_int); #endif extern void esp_print_decodesecret(netdissect_options *ndo); extern int esp_print_decrypt_buffer_by_ikev2(netdissect_options *ndo, int initiator, u_char spii[8], u_char spir[8], u_char *buf, u_char *end); extern void geonet_print(netdissect_options *ndo,const u_char *eth_hdr,const u_char *geo_pck, u_int len); extern void calm_fast_print(netdissect_options *ndo,const u_char *eth_hdr,const u_char *calm_pck, u_int len); #endif /* netdissect_h */ Index: head/contrib/tcpdump/print-ip.c =================================================================== --- head/contrib/tcpdump/print-ip.c (revision 281937) +++ head/contrib/tcpdump/print-ip.c (revision 281938) @@ -1,717 +1,717 @@ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 * 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: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the University of California, * Lawrence Berkeley Laboratory and its contributors.'' 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * $FreeBSD$ */ #define NETDISSECT_REWORKED #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "interface.h" #include "addrtoname.h" #include "extract.h" /* must come after interface.h */ #include "ip.h" #include "ipproto.h" static const char tstr[] = "[|ip]"; static const struct tok ip_option_values[] = { { IPOPT_EOL, "EOL" }, { IPOPT_NOP, "NOP" }, { IPOPT_TS, "timestamp" }, { IPOPT_SECURITY, "security" }, { IPOPT_RR, "RR" }, { IPOPT_SSRR, "SSRR" }, { IPOPT_LSRR, "LSRR" }, { IPOPT_RA, "RA" }, { IPOPT_RFC1393, "traceroute" }, { 0, NULL } }; /* * print the recorded route in an IP RR, LSRR or SSRR option. */ static void ip_printroute(netdissect_options *ndo, register const u_char *cp, u_int length) { register u_int ptr; register u_int len; if (length < 3) { ND_PRINT((ndo, " [bad length %u]", length)); return; } if ((length + 1) & 3) ND_PRINT((ndo, " [bad length %u]", length)); ptr = cp[2] - 1; if (ptr < 3 || ((ptr + 1) & 3) || ptr > length + 1) ND_PRINT((ndo, " [bad ptr %u]", cp[2])); for (len = 3; len < length; len += 4) { ND_PRINT((ndo, " %s", ipaddr_string(ndo, &cp[len]))); if (ptr > len) ND_PRINT((ndo, ",")); } } /* * If source-routing is present and valid, return the final destination. * Otherwise, return IP destination. * * This is used for UDP and TCP pseudo-header in the checksum * calculation. */ static uint32_t ip_finddst(netdissect_options *ndo, const struct ip *ip) { int length; int len; const u_char *cp; uint32_t retval; cp = (const u_char *)(ip + 1); length = (IP_HL(ip) << 2) - sizeof(struct ip); for (; length > 0; cp += len, length -= len) { int tt; ND_TCHECK(*cp); tt = *cp; if (tt == IPOPT_EOL) break; else if (tt == IPOPT_NOP) len = 1; else { ND_TCHECK(cp[1]); len = cp[1]; if (len < 2) break; } ND_TCHECK2(*cp, len); switch (tt) { case IPOPT_SSRR: case IPOPT_LSRR: if (len < 7) break; UNALIGNED_MEMCPY(&retval, cp + len - 4, 4); return retval; } } trunc: UNALIGNED_MEMCPY(&retval, &ip->ip_dst.s_addr, sizeof(uint32_t)); return retval; } /* * Compute a V4-style checksum by building a pseudoheader. */ int nextproto4_cksum(netdissect_options *ndo, const struct ip *ip, const uint8_t *data, u_int len, u_int covlen, u_int next_proto) { struct phdr { uint32_t src; uint32_t dst; u_char mbz; u_char proto; uint16_t len; } ph; struct cksum_vec vec[2]; /* pseudo-header.. */ ph.len = htons((uint16_t)len); ph.mbz = 0; ph.proto = next_proto; UNALIGNED_MEMCPY(&ph.src, &ip->ip_src.s_addr, sizeof(uint32_t)); if (IP_HL(ip) == 5) UNALIGNED_MEMCPY(&ph.dst, &ip->ip_dst.s_addr, sizeof(uint32_t)); else ph.dst = ip_finddst(ndo, ip); vec[0].ptr = (const uint8_t *)(void *)&ph; vec[0].len = sizeof(ph); vec[1].ptr = data; vec[1].len = covlen; return (in_cksum(vec, 2)); } static void ip_printts(netdissect_options *ndo, register const u_char *cp, u_int length) { register u_int ptr; register u_int len; int hoplen; const char *type; if (length < 4) { ND_PRINT((ndo, "[bad length %u]", length)); return; } ND_PRINT((ndo, " TS{")); hoplen = ((cp[3]&0xF) != IPOPT_TS_TSONLY) ? 8 : 4; if ((length - 4) & (hoplen-1)) ND_PRINT((ndo, "[bad length %u]", length)); ptr = cp[2] - 1; len = 0; if (ptr < 4 || ((ptr - 4) & (hoplen-1)) || ptr > length + 1) ND_PRINT((ndo, "[bad ptr %u]", cp[2])); switch (cp[3]&0xF) { case IPOPT_TS_TSONLY: ND_PRINT((ndo, "TSONLY")); break; case IPOPT_TS_TSANDADDR: ND_PRINT((ndo, "TS+ADDR")); break; /* * prespecified should really be 3, but some ones might send 2 * instead, and the IPOPT_TS_PRESPEC constant can apparently * have both values, so we have to hard-code it here. */ case 2: ND_PRINT((ndo, "PRESPEC2.0")); break; case 3: /* IPOPT_TS_PRESPEC */ ND_PRINT((ndo, "PRESPEC")); break; default: ND_PRINT((ndo, "[bad ts type %d]", cp[3]&0xF)); goto done; } type = " "; for (len = 4; len < length; len += hoplen) { if (ptr == len) type = " ^ "; ND_PRINT((ndo, "%s%d@%s", type, EXTRACT_32BITS(&cp[len+hoplen-4]), hoplen!=8 ? "" : ipaddr_string(ndo, &cp[len]))); type = " "; } done: ND_PRINT((ndo, "%s", ptr == len ? " ^ " : "")); if (cp[3]>>4) ND_PRINT((ndo, " [%d hops not recorded]} ", cp[3]>>4)); else ND_PRINT((ndo, "}")); } /* * print IP options. */ static void ip_optprint(netdissect_options *ndo, register const u_char *cp, u_int length) { register u_int option_len; const char *sep = ""; for (; length > 0; cp += option_len, length -= option_len) { u_int option_code; ND_PRINT((ndo, "%s", sep)); sep = ","; ND_TCHECK(*cp); option_code = *cp; ND_PRINT((ndo, "%s", tok2str(ip_option_values,"unknown %u",option_code))); if (option_code == IPOPT_NOP || option_code == IPOPT_EOL) option_len = 1; else { ND_TCHECK(cp[1]); option_len = cp[1]; if (option_len < 2) { ND_PRINT((ndo, " [bad length %u]", option_len)); return; } } if (option_len > length) { ND_PRINT((ndo, " [bad length %u]", option_len)); return; } ND_TCHECK2(*cp, option_len); switch (option_code) { case IPOPT_EOL: return; case IPOPT_TS: ip_printts(ndo, cp, option_len); break; case IPOPT_RR: /* fall through */ case IPOPT_SSRR: case IPOPT_LSRR: ip_printroute(ndo, cp, option_len); break; case IPOPT_RA: if (option_len < 4) { ND_PRINT((ndo, " [bad length %u]", option_len)); break; } ND_TCHECK(cp[3]); if (EXTRACT_16BITS(&cp[2]) != 0) ND_PRINT((ndo, " value %u", EXTRACT_16BITS(&cp[2]))); break; case IPOPT_NOP: /* nothing to print - fall through */ case IPOPT_SECURITY: default: break; } } return; trunc: ND_PRINT((ndo, "%s", tstr)); } #define IP_RES 0x8000 static const struct tok ip_frag_values[] = { { IP_MF, "+" }, { IP_DF, "DF" }, { IP_RES, "rsvd" }, /* The RFC3514 evil ;-) bit */ { 0, NULL } }; struct ip_print_demux_state { const struct ip *ip; const u_char *cp; u_int len, off; u_char nh; int advance; }; static void ip_print_demux(netdissect_options *ndo, struct ip_print_demux_state *ipds) { struct protoent *proto; struct cksum_vec vec[1]; again: switch (ipds->nh) { case IPPROTO_AH: ipds->nh = *ipds->cp; ipds->advance = ah_print(ndo, ipds->cp); if (ipds->advance <= 0) break; ipds->cp += ipds->advance; ipds->len -= ipds->advance; goto again; case IPPROTO_ESP: { int enh, padlen; ipds->advance = esp_print(ndo, ipds->cp, ipds->len, (const u_char *)ipds->ip, &enh, &padlen); if (ipds->advance <= 0) break; ipds->cp += ipds->advance; ipds->len -= ipds->advance + padlen; ipds->nh = enh & 0xff; goto again; } case IPPROTO_IPCOMP: { int enh; ipds->advance = ipcomp_print(ndo, ipds->cp, &enh); if (ipds->advance <= 0) break; ipds->cp += ipds->advance; ipds->len -= ipds->advance; ipds->nh = enh & 0xff; goto again; } case IPPROTO_SCTP: sctp_print(ndo, ipds->cp, (const u_char *)ipds->ip, ipds->len); break; case IPPROTO_DCCP: dccp_print(ndo, ipds->cp, (const u_char *)ipds->ip, ipds->len); break; case IPPROTO_TCP: /* pass on the MF bit plus the offset to detect fragments */ tcp_print(ndo, ipds->cp, ipds->len, (const u_char *)ipds->ip, ipds->off & (IP_MF|IP_OFFMASK)); break; case IPPROTO_UDP: /* pass on the MF bit plus the offset to detect fragments */ udp_print(ndo, ipds->cp, ipds->len, (const u_char *)ipds->ip, ipds->off & (IP_MF|IP_OFFMASK)); break; case IPPROTO_ICMP: /* pass on the MF bit plus the offset to detect fragments */ icmp_print(ndo, ipds->cp, ipds->len, (const u_char *)ipds->ip, ipds->off & (IP_MF|IP_OFFMASK)); break; case IPPROTO_PIGP: /* * XXX - the current IANA protocol number assignments * page lists 9 as "any private interior gateway * (used by Cisco for their IGRP)" and 88 as * "EIGRP" from Cisco. * * Recent BSD headers define * IP_PROTO_PIGP as 9 and IP_PROTO_IGRP as 88. * We define IP_PROTO_PIGP as 9 and * IP_PROTO_EIGRP as 88; those names better * match was the current protocol number * assignments say. */ igrp_print(ndo, ipds->cp, ipds->len); break; case IPPROTO_EIGRP: eigrp_print(ndo, ipds->cp, ipds->len); break; case IPPROTO_ND: ND_PRINT((ndo, " nd %d", ipds->len)); break; case IPPROTO_EGP: egp_print(ndo, ipds->cp, ipds->len); break; case IPPROTO_OSPF: ospf_print(ndo, ipds->cp, ipds->len, (const u_char *)ipds->ip); break; case IPPROTO_IGMP: igmp_print(ndo, ipds->cp, ipds->len); break; case IPPROTO_IPV4: /* DVMRP multicast tunnel (ip-in-ip encapsulation) */ ip_print(ndo, ipds->cp, ipds->len); if (! ndo->ndo_vflag) { ND_PRINT((ndo, " (ipip-proto-4)")); return; } break; #ifdef INET6 case IPPROTO_IPV6: /* ip6-in-ip encapsulation */ ip6_print(ndo, ipds->cp, ipds->len); break; #endif /*INET6*/ case IPPROTO_RSVP: rsvp_print(ndo, ipds->cp, ipds->len); break; case IPPROTO_GRE: /* do it */ gre_print(ndo, ipds->cp, ipds->len); break; case IPPROTO_MOBILE: mobile_print(ndo, ipds->cp, ipds->len); break; case IPPROTO_PIM: vec[0].ptr = ipds->cp; vec[0].len = ipds->len; pim_print(ndo, ipds->cp, ipds->len, in_cksum(vec, 1)); break; case IPPROTO_VRRP: if (ndo->ndo_packettype == PT_CARP) { if (ndo->ndo_vflag) ND_PRINT((ndo, "carp %s > %s: ", ipaddr_string(ndo, &ipds->ip->ip_src), ipaddr_string(ndo, &ipds->ip->ip_dst))); carp_print(ndo, ipds->cp, ipds->len, ipds->ip->ip_ttl); } else { if (ndo->ndo_vflag) ND_PRINT((ndo, "vrrp %s > %s: ", ipaddr_string(ndo, &ipds->ip->ip_src), ipaddr_string(ndo, &ipds->ip->ip_dst))); vrrp_print(ndo, ipds->cp, ipds->len, (const u_char *)ipds->ip, ipds->ip->ip_ttl); } break; case IPPROTO_PGM: pgm_print(ndo, ipds->cp, ipds->len, (const u_char *)ipds->ip); break; #if defined(HAVE_NET_PFVAR_H) case IPPROTO_PFSYNC: - pfsync_ip_print(ipds->cp, ipds->len); + pfsync_ip_print(ndo, ipds->cp, ipds->len); break; #endif default: if (ndo->ndo_nflag==0 && (proto = getprotobynumber(ipds->nh)) != NULL) ND_PRINT((ndo, " %s", proto->p_name)); else ND_PRINT((ndo, " ip-proto-%d", ipds->nh)); ND_PRINT((ndo, " %d", ipds->len)); break; } } void ip_print_inner(netdissect_options *ndo, const u_char *bp, u_int length, u_int nh, const u_char *bp2) { struct ip_print_demux_state ipd; ipd.ip = (const struct ip *)bp2; ipd.cp = bp; ipd.len = length; ipd.off = 0; ipd.nh = nh; ipd.advance = 0; ip_print_demux(ndo, &ipd); } /* * print an IP datagram. */ void ip_print(netdissect_options *ndo, const u_char *bp, u_int length) { struct ip_print_demux_state ipd; struct ip_print_demux_state *ipds=&ipd; const u_char *ipend; u_int hlen; struct cksum_vec vec[1]; uint16_t sum, ip_sum; struct protoent *proto; ipds->ip = (const struct ip *)bp; ND_TCHECK(ipds->ip->ip_vhl); if (IP_V(ipds->ip) != 4) { /* print version if != 4 */ ND_PRINT((ndo, "IP%u ", IP_V(ipds->ip))); if (IP_V(ipds->ip) == 6) ND_PRINT((ndo, ", wrong link-layer encapsulation")); } else if (!ndo->ndo_eflag) ND_PRINT((ndo, "IP ")); ND_TCHECK(*ipds->ip); if (length < sizeof (struct ip)) { ND_PRINT((ndo, "truncated-ip %u", length)); return; } hlen = IP_HL(ipds->ip) * 4; if (hlen < sizeof (struct ip)) { ND_PRINT((ndo, "bad-hlen %u", hlen)); return; } ipds->len = EXTRACT_16BITS(&ipds->ip->ip_len); if (length < ipds->len) ND_PRINT((ndo, "truncated-ip - %u bytes missing! ", ipds->len - length)); if (ipds->len < hlen) { #ifdef GUESS_TSO if (ipds->len) { ND_PRINT((ndo, "bad-len %u", ipds->len)); return; } else { /* we guess that it is a TSO send */ ipds->len = length; } #else ND_PRINT((ndo, "bad-len %u", ipds->len)); return; #endif /* GUESS_TSO */ } /* * Cut off the snapshot length to the end of the IP payload. */ ipend = bp + ipds->len; if (ipend < ndo->ndo_snapend) ndo->ndo_snapend = ipend; ipds->len -= hlen; ipds->off = EXTRACT_16BITS(&ipds->ip->ip_off); if (ndo->ndo_vflag) { ND_PRINT((ndo, "(tos 0x%x", (int)ipds->ip->ip_tos)); /* ECN bits */ if (ipds->ip->ip_tos & 0x03) { switch (ipds->ip->ip_tos & 0x03) { case 1: ND_PRINT((ndo, ",ECT(1)")); break; case 2: ND_PRINT((ndo, ",ECT(0)")); break; case 3: ND_PRINT((ndo, ",CE")); } } if (ipds->ip->ip_ttl >= 1) ND_PRINT((ndo, ", ttl %u", ipds->ip->ip_ttl)); /* * for the firewall guys, print id, offset. * On all but the last stick a "+" in the flags portion. * For unfragmented datagrams, note the don't fragment flag. */ ND_PRINT((ndo, ", id %u, offset %u, flags [%s], proto %s (%u)", EXTRACT_16BITS(&ipds->ip->ip_id), (ipds->off & 0x1fff) * 8, bittok2str(ip_frag_values, "none", ipds->off&0xe000), tok2str(ipproto_values,"unknown",ipds->ip->ip_p), ipds->ip->ip_p)); ND_PRINT((ndo, ", length %u", EXTRACT_16BITS(&ipds->ip->ip_len))); if ((hlen - sizeof(struct ip)) > 0) { ND_PRINT((ndo, ", options (")); ip_optprint(ndo, (u_char *)(ipds->ip + 1), hlen - sizeof(struct ip)); ND_PRINT((ndo, ")")); } if (!ndo->ndo_Kflag && (u_char *)ipds->ip + hlen <= ndo->ndo_snapend) { vec[0].ptr = (const uint8_t *)(void *)ipds->ip; vec[0].len = hlen; sum = in_cksum(vec, 1); if (sum != 0) { ip_sum = EXTRACT_16BITS(&ipds->ip->ip_sum); ND_PRINT((ndo, ", bad cksum %x (->%x)!", ip_sum, in_cksum_shouldbe(ip_sum, sum))); } } ND_PRINT((ndo, ")\n ")); } /* * If this is fragment zero, hand it to the next higher * level protocol. */ if ((ipds->off & 0x1fff) == 0) { ipds->cp = (const u_char *)ipds->ip + hlen; ipds->nh = ipds->ip->ip_p; if (ipds->nh != IPPROTO_TCP && ipds->nh != IPPROTO_UDP && ipds->nh != IPPROTO_SCTP && ipds->nh != IPPROTO_DCCP) { ND_PRINT((ndo, "%s > %s: ", ipaddr_string(ndo, &ipds->ip->ip_src), ipaddr_string(ndo, &ipds->ip->ip_dst))); } ip_print_demux(ndo, ipds); } else { /* Ultra quiet now means that all this stuff should be suppressed */ if (ndo->ndo_qflag > 1) return; /* * if this isn't the first frag, we're missing the * next level protocol header. print the ip addr * and the protocol. */ if (ipds->off & 0x1fff) { ND_PRINT((ndo, "%s > %s:", ipaddr_string(ndo, &ipds->ip->ip_src), ipaddr_string(ndo, &ipds->ip->ip_dst))); if (!ndo->ndo_nflag && (proto = getprotobynumber(ipds->ip->ip_p)) != NULL) ND_PRINT((ndo, " %s", proto->p_name)); else ND_PRINT((ndo, " ip-proto-%d", ipds->ip->ip_p)); } } return; trunc: ND_PRINT((ndo, "%s", tstr)); return; } void ipN_print(netdissect_options *ndo, register const u_char *bp, register u_int length) { struct ip hdr; if (length < 4) { ND_PRINT((ndo, "truncated-ip %d", length)); return; } memcpy (&hdr, bp, 4); switch (IP_V(&hdr)) { case 4: ip_print (ndo, bp, length); return; #ifdef INET6 case 6: ip6_print (ndo, bp, length); return; #endif default: ND_PRINT((ndo, "unknown ip %d", IP_V(&hdr))); return; } } /* * Local Variables: * c-style: whitesmith * c-basic-offset: 8 * End: */ Index: head/contrib/tcpdump/print-pfsync.c =================================================================== --- head/contrib/tcpdump/print-pfsync.c (revision 281937) +++ head/contrib/tcpdump/print-pfsync.c (revision 281938) @@ -1,450 +1,456 @@ /* * Copyright (c) 2012 Gleb Smirnoff * Copyright (c) 2002 Michael Shalayeff * Copyright (c) 2001 Daniel Hartmeier * 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR OR HIS RELATIVES 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 MIND, 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. * * $OpenBSD: print-pfsync.c,v 1.38 2012/09/19 13:50:36 mikeb Exp $ * $OpenBSD: pf_print_state.c,v 1.11 2012/07/08 17:48:37 lteo Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include /* XXX */ #include #define TCPSTATES #include #include #include "interface.h" #include "addrtoname.h" -static void pfsync_print(struct pfsync_header *, const u_char *, u_int); -static void print_src_dst(const struct pfsync_state_peer *, +static void pfsync_print(netdissect_options *, struct pfsync_header *, + const u_char *, u_int); +static void print_src_dst(netdissect_options *, + const struct pfsync_state_peer *, const struct pfsync_state_peer *, uint8_t); -static void print_state(struct pfsync_state *); +static void print_state(netdissect_options *, struct pfsync_state *); #ifdef notyet void pfsync_if_print(u_char *user, const struct pcap_pkthdr *h, register const u_char *p) { u_int caplen = h->caplen; ts_print(&h->ts); if (caplen < PFSYNC_HDRLEN) { - printf("[|pfsync]"); + ND_PRINT((ndo, "[|pfsync]")); goto out; } pfsync_print((struct pfsync_header *)p, p + sizeof(struct pfsync_header), caplen - sizeof(struct pfsync_header)); out: if (xflag) { default_print((const u_char *)p, caplen); } - putchar('\n'); + safeputchar(ndo, '\n'); } #endif /* notyet */ void -pfsync_ip_print(const u_char *bp, u_int len) +pfsync_ip_print(netdissect_options *ndo , const u_char *bp, u_int len) { struct pfsync_header *hdr = (struct pfsync_header *)bp; if (len < PFSYNC_HDRLEN) - printf("[|pfsync]"); + ND_PRINT((ndo, "[|pfsync]")); else - pfsync_print(hdr, bp + sizeof(struct pfsync_header), + pfsync_print(ndo, hdr, bp + sizeof(struct pfsync_header), len - sizeof(struct pfsync_header)); } struct pfsync_actions { const char *name; size_t len; - void (*print)(const void *); + void (*print)(netdissect_options *, const void *); }; -static void pfsync_print_clr(const void *); -static void pfsync_print_state(const void *); -static void pfsync_print_ins_ack(const void *); -static void pfsync_print_upd_c(const void *); -static void pfsync_print_upd_req(const void *); -static void pfsync_print_del_c(const void *); -static void pfsync_print_bus(const void *); -static void pfsync_print_tdb(const void *); +static void pfsync_print_clr(netdissect_options *, const void *); +static void pfsync_print_state(netdissect_options *, const void *); +static void pfsync_print_ins_ack(netdissect_options *, const void *); +static void pfsync_print_upd_c(netdissect_options *, const void *); +static void pfsync_print_upd_req(netdissect_options *, const void *); +static void pfsync_print_del_c(netdissect_options *, const void *); +static void pfsync_print_bus(netdissect_options *, const void *); +static void pfsync_print_tdb(netdissect_options *, const void *); struct pfsync_actions actions[] = { { "clear all", sizeof(struct pfsync_clr), pfsync_print_clr }, { "insert", sizeof(struct pfsync_state), pfsync_print_state }, { "insert ack", sizeof(struct pfsync_ins_ack), pfsync_print_ins_ack }, { "update", sizeof(struct pfsync_ins_ack), pfsync_print_state }, { "update compressed", sizeof(struct pfsync_upd_c), pfsync_print_upd_c }, { "request uncompressed", sizeof(struct pfsync_upd_req), pfsync_print_upd_req }, { "delete", sizeof(struct pfsync_state), pfsync_print_state }, { "delete compressed", sizeof(struct pfsync_del_c), pfsync_print_del_c }, { "frag insert", 0, NULL }, { "frag delete", 0, NULL }, { "bulk update status", sizeof(struct pfsync_bus), pfsync_print_bus }, { "tdb", 0, pfsync_print_tdb }, { "eof", 0, NULL }, }; static void -pfsync_print(struct pfsync_header *hdr, const u_char *bp, u_int len) +pfsync_print(netdissect_options *ndo, struct pfsync_header *hdr, + const u_char *bp, u_int len) { struct pfsync_subheader *subh; int count, plen, i; u_int alen; plen = ntohs(hdr->len); - printf("PFSYNCv%d len %d", hdr->version, plen); + ND_PRINT((ndo, "PFSYNCv%d len %d", hdr->version, plen)); if (hdr->version != PFSYNC_VERSION) return; plen -= sizeof(*hdr); while (plen > 0) { if (len < sizeof(*subh)) break; subh = (struct pfsync_subheader *)bp; bp += sizeof(*subh); len -= sizeof(*subh); plen -= sizeof(*subh); if (subh->action >= PFSYNC_ACT_MAX) { - printf("\n act UNKNOWN id %d", subh->action); + ND_PRINT((ndo, "\n act UNKNOWN id %d", + subh->action)); return; } count = ntohs(subh->count); - printf("\n %s count %d", actions[subh->action].name, count); + ND_PRINT((ndo, "\n %s count %d", actions[subh->action].name, + count)); alen = actions[subh->action].len; if (subh->action == PFSYNC_ACT_EOF) return; if (actions[subh->action].print == NULL) { - printf("\n unimplemented action %hhu", subh->action); + ND_PRINT((ndo, "\n unimplemented action %hhu", + subh->action)); return; } for (i = 0; i < count; i++) { if (len < alen) { len = 0; break; } if (vflag) - actions[subh->action].print(bp); + actions[subh->action].print(ndo, bp); bp += alen; len -= alen; plen -= alen; } } if (plen > 0) { - printf("\n ..."); + ND_PRINT((ndo, "\n ...")); return; } if (plen < 0) { - printf("\n invalid header length"); + ND_PRINT((ndo, "\n invalid header length")); return; } if (len > 0) - printf("\n invalid packet length"); + ND_PRINT((ndo, "\n invalid packet length")); } static void -pfsync_print_clr(const void *bp) +pfsync_print_clr(netdissect_options *ndo, const void *bp) { const struct pfsync_clr *clr = bp; - printf("\n\tcreatorid: %08x", htonl(clr->creatorid)); + ND_PRINT((ndo, "\n\tcreatorid: %08x", htonl(clr->creatorid))); if (clr->ifname[0] != '\0') - printf(" interface: %s", clr->ifname); + ND_PRINT((ndo, " interface: %s", clr->ifname)); } static void -pfsync_print_state(const void *bp) +pfsync_print_state(netdissect_options *ndo, const void *bp) { struct pfsync_state *st = (struct pfsync_state *)bp; - putchar('\n'); - print_state(st); + safeputchar(ndo, '\n'); + print_state(ndo, st); } static void -pfsync_print_ins_ack(const void *bp) +pfsync_print_ins_ack(netdissect_options *ndo, const void *bp) { const struct pfsync_ins_ack *iack = bp; - printf("\n\tid: %016jx creatorid: %08x", (uintmax_t )be64toh(iack->id), - ntohl(iack->creatorid)); + ND_PRINT((ndo, "\n\tid: %016jx creatorid: %08x", + (uintmax_t)be64toh(iack->id), ntohl(iack->creatorid))); } static void -pfsync_print_upd_c(const void *bp) +pfsync_print_upd_c(netdissect_options *ndo, const void *bp) { const struct pfsync_upd_c *u = bp; - printf("\n\tid: %016jx creatorid: %08x", (uintmax_t )be64toh(u->id), - ntohl(u->creatorid)); + ND_PRINT((ndo, "\n\tid: %016jx creatorid: %08x", + (uintmax_t)be64toh(u->id), ntohl(u->creatorid))); if (vflag > 2) { - printf("\n\tTCP? :"); - print_src_dst(&u->src, &u->dst, IPPROTO_TCP); + ND_PRINT((ndo, "\n\tTCP? :")); + print_src_dst(ndo, &u->src, &u->dst, IPPROTO_TCP); } } static void -pfsync_print_upd_req(const void *bp) +pfsync_print_upd_req(netdissect_options *ndo, const void *bp) { const struct pfsync_upd_req *ur = bp; - printf("\n\tid: %016jx creatorid: %08x", (uintmax_t )be64toh(ur->id), - ntohl(ur->creatorid)); + ND_PRINT((ndo, "\n\tid: %016jx creatorid: %08x", + (uintmax_t)be64toh(ur->id), ntohl(ur->creatorid))); } static void -pfsync_print_del_c(const void *bp) +pfsync_print_del_c(netdissect_options *ndo, const void *bp) { const struct pfsync_del_c *d = bp; - printf("\n\tid: %016jx creatorid: %08x", (uintmax_t )be64toh(d->id), - ntohl(d->creatorid)); + ND_PRINT((ndo, "\n\tid: %016jx creatorid: %08x", + (uintmax_t)be64toh(d->id), ntohl(d->creatorid))); } static void -pfsync_print_bus(const void *bp) +pfsync_print_bus(netdissect_options *ndo, const void *bp) { const struct pfsync_bus *b = bp; uint32_t endtime; int min, sec; const char *status; endtime = ntohl(b->endtime); sec = endtime % 60; endtime /= 60; min = endtime % 60; endtime /= 60; switch (b->status) { case PFSYNC_BUS_START: status = "start"; break; case PFSYNC_BUS_END: status = "end"; break; default: status = "UNKNOWN"; break; } - printf("\n\tcreatorid: %08x age: %.2u:%.2u:%.2u status: %s", - htonl(b->creatorid), endtime, min, sec, status); + ND_PRINT((ndo, "\n\tcreatorid: %08x age: %.2u:%.2u:%.2u status: %s", + htonl(b->creatorid), endtime, min, sec, status)); } static void -pfsync_print_tdb(const void *bp) +pfsync_print_tdb(netdissect_options *ndo, const void *bp) { const struct pfsync_tdb *t = bp; - printf("\n\tspi: 0x%08x rpl: %ju cur_bytes: %ju", + ND_PRINT((ndo, "\n\tspi: 0x%08x rpl: %ju cur_bytes: %ju", ntohl(t->spi), (uintmax_t )be64toh(t->rpl), - (uintmax_t )be64toh(t->cur_bytes)); + (uintmax_t )be64toh(t->cur_bytes))); } static void -print_host(struct pf_addr *addr, uint16_t port, sa_family_t af, - const char *proto) +print_host(netdissect_options *ndo, struct pf_addr *addr, uint16_t port, + sa_family_t af, const char *proto) { char buf[48]; if (inet_ntop(af, addr, buf, sizeof(buf)) == NULL) - printf("?"); + ND_PRINT((ndo, "?")); else - printf("%s", buf); + ND_PRINT((ndo, "%s", buf)); if (port) - printf(".%hu", ntohs(port)); + ND_PRINT((ndo, ".%hu", ntohs(port))); } static void -print_seq(const struct pfsync_state_peer *p) +print_seq(netdissect_options *ndo, const struct pfsync_state_peer *p) { if (p->seqdiff) - printf("[%u + %u](+%u)", ntohl(p->seqlo), - ntohl(p->seqhi) - ntohl(p->seqlo), ntohl(p->seqdiff)); + ND_PRINT((ndo, "[%u + %u](+%u)", ntohl(p->seqlo), + ntohl(p->seqhi) - ntohl(p->seqlo), ntohl(p->seqdiff))); else - printf("[%u + %u]", ntohl(p->seqlo), - ntohl(p->seqhi) - ntohl(p->seqlo)); + ND_PRINT((ndo, "[%u + %u]", ntohl(p->seqlo), + ntohl(p->seqhi) - ntohl(p->seqlo))); } static void -print_src_dst(const struct pfsync_state_peer *src, +print_src_dst(netdissect_options *ndo, const struct pfsync_state_peer *src, const struct pfsync_state_peer *dst, uint8_t proto) { if (proto == IPPROTO_TCP) { if (src->state <= TCPS_TIME_WAIT && dst->state <= TCPS_TIME_WAIT) - printf(" %s:%s", tcpstates[src->state], - tcpstates[dst->state]); + ND_PRINT((ndo, " %s:%s", tcpstates[src->state], + tcpstates[dst->state])); else if (src->state == PF_TCPS_PROXY_SRC || dst->state == PF_TCPS_PROXY_SRC) - printf(" PROXY:SRC"); + ND_PRINT((ndo, " PROXY:SRC")); else if (src->state == PF_TCPS_PROXY_DST || dst->state == PF_TCPS_PROXY_DST) - printf(" PROXY:DST"); + ND_PRINT((ndo, " PROXY:DST")); else - printf(" ", - src->state, dst->state); + ND_PRINT((ndo, " ", + src->state, dst->state)); if (vflag > 1) { - printf("\n\t"); - print_seq(src); + ND_PRINT((ndo, "\n\t")); + print_seq(ndo, src); if (src->wscale && dst->wscale) - printf(" wscale %u", - src->wscale & PF_WSCALE_MASK); - printf(" "); - print_seq(dst); + ND_PRINT((ndo, " wscale %u", + src->wscale & PF_WSCALE_MASK)); + ND_PRINT((ndo, " ")); + print_seq(ndo, dst); if (src->wscale && dst->wscale) - printf(" wscale %u", - dst->wscale & PF_WSCALE_MASK); + ND_PRINT((ndo, " wscale %u", + dst->wscale & PF_WSCALE_MASK)); } } else if (proto == IPPROTO_UDP && src->state < PFUDPS_NSTATES && dst->state < PFUDPS_NSTATES) { const char *states[] = PFUDPS_NAMES; - printf(" %s:%s", states[src->state], states[dst->state]); + ND_PRINT((ndo, " %s:%s", states[src->state], states[dst->state])); } else if (proto != IPPROTO_ICMP && src->state < PFOTHERS_NSTATES && dst->state < PFOTHERS_NSTATES) { /* XXX ICMP doesn't really have state levels */ const char *states[] = PFOTHERS_NAMES; - printf(" %s:%s", states[src->state], states[dst->state]); + ND_PRINT((ndo, " %s:%s", states[src->state], states[dst->state])); } else { - printf(" %u:%u", src->state, dst->state); + ND_PRINT((ndo, " %u:%u", src->state, dst->state)); } } static void -print_state(struct pfsync_state *s) +print_state(netdissect_options *ndo, struct pfsync_state *s) { struct pfsync_state_peer *src, *dst; struct pfsync_state_key *sk, *nk; int min, sec; if (s->direction == PF_OUT) { src = &s->src; dst = &s->dst; sk = &s->key[PF_SK_STACK]; nk = &s->key[PF_SK_WIRE]; if (s->proto == IPPROTO_ICMP || s->proto == IPPROTO_ICMPV6) sk->port[0] = nk->port[0]; } else { src = &s->dst; dst = &s->src; sk = &s->key[PF_SK_WIRE]; nk = &s->key[PF_SK_STACK]; if (s->proto == IPPROTO_ICMP || s->proto == IPPROTO_ICMPV6) sk->port[1] = nk->port[1]; } - printf("\t%s ", s->ifname); - printf("proto %u ", s->proto); + ND_PRINT((ndo, "\t%s ", s->ifname)); + ND_PRINT((ndo, "proto %u ", s->proto)); - print_host(&nk->addr[1], nk->port[1], s->af, NULL); + print_host(ndo, &nk->addr[1], nk->port[1], s->af, NULL); if (PF_ANEQ(&nk->addr[1], &sk->addr[1], s->af) || nk->port[1] != sk->port[1]) { - printf(" ("); - print_host(&sk->addr[1], sk->port[1], s->af, NULL); - printf(")"); + ND_PRINT((ndo, " (")); + print_host(ndo, &sk->addr[1], sk->port[1], s->af, NULL); + ND_PRINT((ndo, ")")); } if (s->direction == PF_OUT) - printf(" -> "); + ND_PRINT((ndo, " -> ")); else - printf(" <- "); - print_host(&nk->addr[0], nk->port[0], s->af, NULL); + ND_PRINT((ndo, " <- ")); + print_host(ndo, &nk->addr[0], nk->port[0], s->af, NULL); if (PF_ANEQ(&nk->addr[0], &sk->addr[0], s->af) || nk->port[0] != sk->port[0]) { - printf(" ("); - print_host(&sk->addr[0], sk->port[0], s->af, NULL); - printf(")"); + ND_PRINT((ndo, " (")); + print_host(ndo, &sk->addr[0], sk->port[0], s->af, NULL); + ND_PRINT((ndo, ")")); } - print_src_dst(src, dst, s->proto); + print_src_dst(ndo, src, dst, s->proto); if (vflag > 1) { uint64_t packets[2]; uint64_t bytes[2]; uint32_t creation = ntohl(s->creation); uint32_t expire = ntohl(s->expire); sec = creation % 60; creation /= 60; min = creation % 60; creation /= 60; - printf("\n\tage %.2u:%.2u:%.2u", creation, min, sec); + ND_PRINT((ndo, "\n\tage %.2u:%.2u:%.2u", creation, min, sec)); sec = expire % 60; expire /= 60; min = expire % 60; expire /= 60; - printf(", expires in %.2u:%.2u:%.2u", expire, min, sec); + ND_PRINT((ndo, ", expires in %.2u:%.2u:%.2u", expire, min, sec)); bcopy(s->packets[0], &packets[0], sizeof(uint64_t)); bcopy(s->packets[1], &packets[1], sizeof(uint64_t)); bcopy(s->bytes[0], &bytes[0], sizeof(uint64_t)); bcopy(s->bytes[1], &bytes[1], sizeof(uint64_t)); - printf(", %ju:%ju pkts, %ju:%ju bytes", + ND_PRINT((ndo, ", %ju:%ju pkts, %ju:%ju bytes", be64toh(packets[0]), be64toh(packets[1]), - be64toh(bytes[0]), be64toh(bytes[1])); + be64toh(bytes[0]), be64toh(bytes[1]))); if (s->anchor != ntohl(-1)) - printf(", anchor %u", ntohl(s->anchor)); + ND_PRINT((ndo, ", anchor %u", ntohl(s->anchor))); if (s->rule != ntohl(-1)) - printf(", rule %u", ntohl(s->rule)); + ND_PRINT((ndo, ", rule %u", ntohl(s->rule))); } if (vflag > 1) { uint64_t id; bcopy(&s->id, &id, sizeof(uint64_t)); - printf("\n\tid: %016jx creatorid: %08x", - (uintmax_t )be64toh(id), ntohl(s->creatorid)); + ND_PRINT((ndo, "\n\tid: %016jx creatorid: %08x", + (uintmax_t )be64toh(id), ntohl(s->creatorid))); } }