diff options
author | Jakob Schlyter <jakob@cvs.openbsd.org> | 2000-04-26 21:35:45 +0000 |
---|---|---|
committer | Jakob Schlyter <jakob@cvs.openbsd.org> | 2000-04-26 21:35:45 +0000 |
commit | 2dd23c23770ee72b2c221e1b8ddf74531cf67e15 (patch) | |
tree | 6bc2e589e5c398c416d7cd4014d0d050bdcea861 /usr.sbin/tcpdump | |
parent | 7ffa8e1885137bf28c6c378169c6dc323b6dbbe2 (diff) |
INET6
DHCP/BOOTP
tcp & udp checksum detection
numerous bugfixes
Diffstat (limited to 'usr.sbin/tcpdump')
44 files changed, 3734 insertions, 189 deletions
diff --git a/usr.sbin/tcpdump/Makefile b/usr.sbin/tcpdump/Makefile index 50db817e3a2..7cc3d144ce9 100644 --- a/usr.sbin/tcpdump/Makefile +++ b/usr.sbin/tcpdump/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.20 2000/01/16 12:08:10 jakob Exp $ +# $OpenBSD: Makefile,v 1.21 2000/04/26 21:35:36 jakob Exp $ # # Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 # The Regents of the University of California. All rights reserved. @@ -42,7 +42,8 @@ SRCS= tcpdump.c addrtoname.c \ util.c bpf_dump.c parsenfsfh.c version.c machdep.c print-igrp.c \ print-gre.c print-radius.c print-enc.c print-cnfp.c \ print-ipsec.c print-ike.c print-raw.c print-l2tp.c print-mobile.c \ - print-bgp.c \ + print-ip6.c print-ip6opts.c print-icmp6.c print-dhcp6.c print-frag6.c \ + print-bgp.c print-ospf6.c print-ripng.c print-rt6.c \ gmt2local.c savestr.c setsignal.c AWKS = atime.awk packetdat.awk send-ack.awk stime.awk diff --git a/usr.sbin/tcpdump/addrtoname.c b/usr.sbin/tcpdump/addrtoname.c index 07c513f590f..4e638d1753c 100644 --- a/usr.sbin/tcpdump/addrtoname.c +++ b/usr.sbin/tcpdump/addrtoname.c @@ -23,7 +23,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/addrtoname.c,v 1.11 2000/02/07 13:35:53 itojun Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/addrtoname.c,v 1.12 2000/04/26 21:35:37 jakob Exp $ (LBL)"; #endif #include <sys/types.h> @@ -49,9 +49,6 @@ struct rtentry; #include <netdb.h> #include <pcap.h> #include <pcap-namedb.h> -#ifdef HAVE_MALLOC_H -#include <malloc.h> -#endif #ifdef HAVE_MEMORY_H #include <memory.h> #endif @@ -105,11 +102,13 @@ struct enamemem { u_short e_addr2; char *e_name; u_char *e_nsap; /* used only for nsaptable[] */ +#define e_bs e_nsap /* for bytestringtable */ struct enamemem *e_nxt; }; struct enamemem enametable[HASHNAMESIZE]; struct enamemem nsaptable[HASHNAMESIZE]; +struct enamemem bytestringtable[HASHNAMESIZE]; struct protoidmem { u_int32_t p_oui; @@ -195,7 +194,7 @@ getname(const u_char *ap) break; case 2: -#if BYTE_ORDER == BIG_ENDIAN +#ifdef WORDS_BIGENDIAN addr = ((u_int32_t)*(u_short *)ap << 16) | (u_int32_t)*(u_short *)(ap + 2); #else @@ -205,7 +204,7 @@ getname(const u_char *ap) break; default: -#if BYTE_ORDER == BIG_ENDIAN +#ifdef WORDS_BIGENDIAN addr = ((u_int32_t)ap[0] << 24) | ((u_int32_t)ap[1] << 16) | ((u_int32_t)ap[2] << 8) | @@ -361,6 +360,51 @@ lookup_emem(const u_char *ep) return tp; } +/* + * Find the hash node that corresponds to the bytestring 'bs' + * with length 'nlen' + */ + +static inline struct enamemem * +lookup_bytestring(register const u_char *bs, const int nlen) +{ + struct enamemem *tp; + register u_int i, j, k; + + if (nlen >= 6) { + k = (bs[0] << 8) | bs[1]; + j = (bs[2] << 8) | bs[3]; + i = (bs[4] << 8) | bs[5]; + } else if (nlen >= 4) { + k = (bs[0] << 8) | bs[1]; + j = (bs[2] << 8) | bs[3]; + i = 0; + } else + i = j = k = 0; + + tp = &bytestringtable[(i ^ j) & (HASHNAMESIZE-1)]; + while (tp->e_nxt) + if (tp->e_addr0 == i && + tp->e_addr1 == j && + tp->e_addr2 == k && + bcmp((char *)bs, (char *)(tp->e_bs), nlen) == 0) + return tp; + else + tp = tp->e_nxt; + + tp->e_addr0 = i; + tp->e_addr1 = j; + tp->e_addr2 = k; + + tp->e_bs = (u_char *) calloc(1, nlen + 1); + bcopy(bs, tp->e_bs, nlen); + tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp)); + if (tp->e_nxt == NULL) + error("lookup_bytestring: calloc"); + + return tp; +} + /* Find the hash node that corresponds the NSAP 'nsap' */ static inline struct enamemem * @@ -445,7 +489,7 @@ etheraddr_string(register const u_char *ep) return (tp->e_name); #ifdef HAVE_ETHER_NTOHOST if (!nflag) { - char buf[128]; + char buf[MAXHOSTNAMELEN + 1]; if (ether_ntohost(buf, (struct ether_addr *)ep) == 0) { tp->e_name = savestr(buf); return (tp->e_name); @@ -468,6 +512,36 @@ etheraddr_string(register const u_char *ep) } char * +linkaddr_string(const u_char *ep, const int len) +{ + register u_int i, j; + register char *cp; + register struct enamemem *tp; + + if (len == 6) /* XXX not totally correct... */ + return etheraddr_string(ep); + + tp = lookup_bytestring(ep, len); + if (tp->e_name) + return (tp->e_name); + + tp->e_name = cp = (char *)malloc(len*3); + if (tp->e_name == NULL) + error("linkaddr_string: malloc"); + if ((j = *ep >> 4) != 0) + *cp++ = hex[j]; + *cp++ = hex[*ep++ & 0xf]; + for (i = len-1; i > 0 ; --i) { + *cp++ = ':'; + if ((j = *ep >> 4) != 0) + *cp++ = hex[j]; + *cp++ = hex[*ep++ & 0xf]; + } + *cp = '\0'; + return (tp->e_name); +} + +char * etherproto_string(u_short port) { register char *cp; @@ -713,7 +787,7 @@ init_etherarray(void) register struct etherlist *el; register struct enamemem *tp; #ifdef HAVE_ETHER_NTOHOST - char name[256]; + char name[MAXHOSTNAMELEN + 1]; #else register struct pcap_etherent *ep; register FILE *fp; diff --git a/usr.sbin/tcpdump/addrtoname.h b/usr.sbin/tcpdump/addrtoname.h index bd35301ec91..af877d7a3e8 100644 --- a/usr.sbin/tcpdump/addrtoname.h +++ b/usr.sbin/tcpdump/addrtoname.h @@ -18,11 +18,19 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/addrtoname.h,v 1.7 2000/01/16 12:07:29 jakob Exp $ (LBL) + * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/addrtoname.h,v 1.8 2000/04/26 21:35:37 jakob Exp $ (LBL) */ -/* Name to address translation routines. */ +#ifndef BYTE_ORDER +#error "No byte order defined" +#endif +#if BYTE_ORDER == BIG_ENDIAN +#define WORDS_BIGENDIAN +#endif /* BYTE_ORDER */ + +/* Name to address translation routines. */ +extern char *linkaddr_string(const u_char *, const int); extern char *etheraddr_string(const u_char *); extern char *etherproto_string(u_short); extern char *tcpport_string(u_short); diff --git a/usr.sbin/tcpdump/bootp.h b/usr.sbin/tcpdump/bootp.h index 8db301b826b..9c6bc5fbe2d 100644 --- a/usr.sbin/tcpdump/bootp.h +++ b/usr.sbin/tcpdump/bootp.h @@ -1,4 +1,4 @@ -/* @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/bootp.h,v 1.5 1996/12/12 16:22:58 bitblt Exp $ (LBL) */ +/* @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/bootp.h,v 1.6 2000/04/26 21:35:38 jakob Exp $ (LBL) */ /* * Bootstrap Protocol (BOOTP). RFC951 and RFC1048. * @@ -27,7 +27,7 @@ struct bootp { unsigned char bp_hops; /* gateway hops */ u_int32_t bp_xid; /* transaction ID */ unsigned short bp_secs; /* seconds since boot began */ - unsigned short bp_unused; + unsigned short bp_flags; /* flags: 0x8000 is broadcast */ struct in_addr bp_ciaddr; /* client IP address */ struct in_addr bp_yiaddr; /* 'your' IP address */ struct in_addr bp_siaddr; /* server IP address */ @@ -86,7 +86,74 @@ struct bootp { #define TAG_SWAP_SERVER ((unsigned char) 16) #define TAG_ROOTPATH ((unsigned char) 17) #define TAG_EXTPATH ((unsigned char) 18) - +/* RFC2132 */ +#define TAG_IP_FORWARD ((unsigned char) 19) +#define TAG_NL_SRCRT ((unsigned char) 20) +#define TAG_PFILTERS ((unsigned char) 21) +#define TAG_REASS_SIZE ((unsigned char) 22) +#define TAG_DEF_TTL ((unsigned char) 23) +#define TAG_MTU_TIMEOUT ((unsigned char) 24) +#define TAG_MTU_TABLE ((unsigned char) 25) +#define TAG_INT_MTU ((unsigned char) 26) +#define TAG_LOCAL_SUBNETS ((unsigned char) 27) +#define TAG_BROAD_ADDR ((unsigned char) 28) +#define TAG_DO_MASK_DISC ((unsigned char) 29) +#define TAG_SUPPLY_MASK ((unsigned char) 30) +#define TAG_DO_RDISC ((unsigned char) 31) +#define TAG_RTR_SOL_ADDR ((unsigned char) 32) +#define TAG_STATIC_ROUTE ((unsigned char) 33) +#define TAG_USE_TRAILERS ((unsigned char) 34) +#define TAG_ARP_TIMEOUT ((unsigned char) 35) +#define TAG_ETH_ENCAP ((unsigned char) 36) +#define TAG_TCP_TTL ((unsigned char) 37) +#define TAG_TCP_KEEPALIVE ((unsigned char) 38) +#define TAG_KEEPALIVE_GO ((unsigned char) 39) +#define TAG_NIS_DOMAIN ((unsigned char) 40) +#define TAG_NIS_SERVERS ((unsigned char) 41) +#define TAG_NTP_SERVERS ((unsigned char) 42) +#define TAG_VENDOR_OPTS ((unsigned char) 43) +#define TAG_NETBIOS_NS ((unsigned char) 44) +#define TAG_NETBIOS_DDS ((unsigned char) 45) +#define TAG_NETBIOS_NODE ((unsigned char) 46) +#define TAG_NETBIOS_SCOPE ((unsigned char) 47) +#define TAG_XWIN_FS ((unsigned char) 48) +#define TAG_XWIN_DM ((unsigned char) 49) +#define TAG_NIS_P_DOMAIN ((unsigned char) 64) +#define TAG_NIS_P_SERVERS ((unsigned char) 65) +#define TAG_MOBILE_HOME ((unsigned char) 68) +#define TAG_SMPT_SERVER ((unsigned char) 69) +#define TAG_POP3_SERVER ((unsigned char) 70) +#define TAG_NNTP_SERVER ((unsigned char) 71) +#define TAG_WWW_SERVER ((unsigned char) 72) +#define TAG_FINGER_SERVER ((unsigned char) 73) +#define TAG_IRC_SERVER ((unsigned char) 74) +#define TAG_STREETTALK_SRVR ((unsigned char) 75) +#define TAG_STREETTALK_STDA ((unsigned char) 76) +/* DHCP options */ +#define TAG_REQUESTED_IP ((unsigned char) 50) +#define TAG_IP_LEASE ((unsigned char) 51) +#define TAG_OPT_OVERLOAD ((unsigned char) 52) +#define TAG_TFTP_SERVER ((unsigned char) 66) +#define TAG_BOOTFILENAME ((unsigned char) 67) +#define TAG_DHCP_MESSAGE ((unsigned char) 53) +#define TAG_SERVER_ID ((unsigned char) 54) +#define TAG_PARM_REQUEST ((unsigned char) 55) +#define TAG_MESSAGE ((unsigned char) 56) +#define TAG_MAX_MSG_SIZE ((unsigned char) 57) +#define TAG_RENEWAL_TIME ((unsigned char) 58) +#define TAG_REBIND_TIME ((unsigned char) 59) +#define TAG_VENDOR_CLASS ((unsigned char) 60) +#define TAG_CLIENT_ID ((unsigned char) 61) + +/* DHCP Message types (values for TAG_DHCP_MESSAGE option) */ +#define DHCPDISCOVER 1 +#define DHCPOFFER 2 +#define DHCPREQUEST 3 +#define DHCPDECLINE 4 +#define DHCPACK 5 +#define DHCPNAK 6 +#define DHCPRELEASE 7 +#define DHCPINFORM 8 /* diff --git a/usr.sbin/tcpdump/dhcp6.h b/usr.sbin/tcpdump/dhcp6.h new file mode 100644 index 00000000000..1dd1b13082b --- /dev/null +++ b/usr.sbin/tcpdump/dhcp6.h @@ -0,0 +1,193 @@ +/* $OpenBSD: dhcp6.h,v 1.1 2000/04/26 21:35:38 jakob Exp $ */ + +/* + * Copyright (C) 1998 and 1999 WIDE Project. + * 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. + * 3. Neither the name of the project 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 PROJECT 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 PROJECT 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. + */ +/* + * draft-ietf-dhc-dhcpv6-14 + */ + +#ifndef __DHCP6_H_DEFINED +#define __DHCP6_H_DEFINED + +/* Error Values */ +#define DH6ERR_FAILURE 16 +#define DH6ERR_AUTHFAIL 17 +#define DH6ERR_POORLYFORMED 18 +#define DH6ERR_UNAVAIL 19 +#define DH6ERR_NOBINDING 20 +#define DH6ERR_INVALIDSOURCE 21 +#define DH6ERR_NOSERVER 23 +#define DH6ERR_ICMPERROR 64 + +/* Message type */ +#define DH6_SOLICIT 1 +#define DH6_ADVERT 2 +#define DH6_REQUEST 3 +#define DH6_REPLY 4 +#define DH6_RELEASE 5 +#define DH6_RECONFIG 6 + +/* Predefined addresses */ +#define DH6ADDR_ALLAGENT "ff02::1:2" +#define DH6ADDR_ALLSERVER "ff05::1:3" +#define DH6ADDR_ALLRELAY "ff05::1:4" +#define DH6PORT_DOWNSTREAM "546" +#define DH6PORT_UPSTREAM "547" + +/* Protocol constants */ +#define ADV_CLIENT_WAIT 2 /* sec */ +#define DEFAULT_SOLICIT_HOPCOUNT 4 +#define SERVER_MIN_ADV_DELAY 100 /* msec */ +#define SERVER_MAX_ADV_DELAY 1000 /* msec */ +#define REPLY_MSG_TIMEOUT 2 /* sec */ +#define REQUEST_MSG_MIN_RETRANS 10 /* retransmissions */ +#define RECONF_MSG_MIN_RETRANS 10 /* retransmissions */ +#define RECONF_MSG_RETRANS_INTERVAL 12 /* sec */ +#define RECONF_MMSG_MIN_RESP 2 /* sec */ +#define RECONF_MMSG_MAX_RESP 10 /* sec */ +#define RECONF_MULTICAST_REQUEST_WAIT 120 /* sec */ +#define MIN_SOLICIT_DELAY 1 /* sec */ +#define MAX_SOLICIT_DELAY 5 /* sec */ +#define XID_TIMEOUT 600 /* sec */ + +/* DHCP6 base packet format */ +struct dhcp6_solicit { + u_int8_t dh6sol_msgtype; /* DH6_SOLICIT */ + u_int8_t dh6sol_flags; +#define DH6SOL_CLOSE 0x80 + u_int8_t dh6sol_pad; + u_int8_t dh6sol_prefixsiz; /* prefix-size */ + struct in6_addr dh6sol_cliaddr; /* client's lladdr */ + struct in6_addr dh6sol_relayaddr; /* relay agent's lladdr */ +}; + +/* NOTE: dhcpv6-12 and dhcpv6-13+n are not compatible at all */ +struct dhcp6_advert { + u_int8_t dh6adv_msgtype; /* DH6_ADVERT */ + u_int8_t dh6adv_flags; +#define DH6ADV_SERVPRESENT 0x80 + u_int8_t dh6adv_pad; + u_int8_t dh6adv_pref; + struct in6_addr dh6adv_cliaddr; /* client's lladdr */ + struct in6_addr dh6adv_relayaddr; /* relay agent's (non-ll) addr */ + struct in6_addr dh6adv_serveraddr; /* server's addr */ + /* extensions */ +}; + +struct dhcp6_request { + u_int8_t dh6req_msgtype; /* DH6_REQUEST */ + u_int8_t dh6req_flags; +#define DH6REQ_CLOSE 0x80 +#define DH6REQ_SERVPRESENT 0x40 +#define DH6REQ_REBOOT 0x20 + u_int16_t dh6req_xid; /* transaction-ID */ + struct in6_addr dh6req_cliaddr; /* client's lladdr */ + struct in6_addr dh6req_relayaddr; /* relay agent's (non-ll) addr */ + /* struct in6_addr dh6req_serveraddr; optional: server's addr */ + /* extensions */ +}; + +struct dhcp6_reply { + u_int8_t dh6rep_msgtype; /* DH6_REPLY */ + u_int8_t dh6rep_flagandstat; +#define DH6REP_CLIPRESENT 0x80 +#define DH6REP_STATMASK 0x7f + u_int16_t dh6rep_xid; /* transaction-ID */ + /* struct in6_addr dh6rep_cliaddr; optional: client's lladdr */ + /* extensions */ +}; + +struct dhcp6_release { + u_int8_t dh6rel_msgtype; /* DH6_RELEASE */ + u_int8_t dh6rel_flags; +#define DH6REL_DIRECT 0x80 + u_int16_t dh6rel_xid; /* transaction-ID */ + struct in6_addr dh6rel_cliaddr; /* client's lladdr */ + struct in6_addr dh6rel_relayaddr; /* relay agent's (non-ll) addr */ + struct in6_addr dh6rel_reladdr; /* server's addr to be released */ + /* extensions */ +}; + +struct dhcp6_reconfig { + u_int8_t dh6cfg_msgtype; /* DH6_RECONFIG */ + u_int8_t dh6cfg_flags; +#define DH6REP_NOREPLY 0x80 + u_int16_t dh6cfg_xid; /* transaction-ID */ + struct in6_addr dh6cfg_servaddr; /* server's addr */ + /* extensions */ +}; + +union dhcp6 { + u_int8_t dh6_msgtype; + struct dhcp6_solicit dh6_sol; + struct dhcp6_advert dh6_adv; + struct dhcp6_request dh6_req; + struct dhcp6_reply dh6_rep; + struct dhcp6_release dh6_rel; + struct dhcp6_reconfig dh6_cfg; +}; + +/* DHCP6 extension */ +struct dhcp6e_ipaddr { + u_int16_t dh6eip_type; + u_int16_t dh6eip_len; + u_int8_t dh6eip_status; +#define DH6EX_IP_SUCCESS 0 /* request granted, no errors */ +#define DH6EX_IP_SECFAIL 18 /* Security parameters failed */ +#define DH6EX_IP_AAAAFAIL 20 /* AAAA Record Parameter Problem */ +#define DH6EX_IP_PTRFAIL 21 /* PTR Record Parameter Problem */ +#define DH6EX_IP_PARAMFAIL 22 /* Unable to honor required params */ +#define DH6EX_IP_DNSNAMEFAIL 23 /* DNS name string error */ +#define DH6EX_IP_NODYNDNS 24 /* dynDNS Not Implemented */ +#define DH6EX_IP_NOAUTHDNS 25 /* Authoritative DNS Server not found */ +#define DH6EX_IP_DNSFORMFAIL 33 /* DNS format error */ +#define DH6EX_IP_SERVFAIL 34 /* dynDNS unavailable at this time */ +#define DH6EX_IP_NXDOMAIN 35 /* name does not exist */ +#define DH6EX_IP_NOTIMP 36 /* DNS does not support the Opcode */ +#define DH6EX_IP_REFUSED 37 /* DNS refuses specified operation */ +#define DH6EX_IP_YXDOMAIN 38 /* name does not exist */ +#define DH6EX_IP_YXRRSET 39 /* RRset does not exist */ +#define DH6EX_IP_NXRRSET 40 /* RRset does not exist */ +#define DH6EX_IP_NOTAUTH 41 /* non authoritative name server */ +#define DH6EX_IP_NOTZONE 42 /* prerequisite out of zone */ + u_int8_t dh6eip_flags; +#define DH6EX_IP_CLIANTADDR 0x80 /* C: cliant's addr */ +#define DH6EX_IP_LIFETIME 0x40 /* L: preferred/valid lifetime */ +#define DH6EX_IP_FORCEOPTS 0x20 /* Q: options are mandatory */ +#define DH6EX_IP_AAAA 0x10 /* A: DNS dynamic update for AAAA */ +#define DH6EX_IP_PTR 0x08 /* P: DNS dynamic update for PTR*/ + u_int8_t dh6eip_pad; + u_int8_t dh6eip_prefixlen; + /* struct in6_addr: client's address (if C bit = 1) */ + /* u_int: preferred lifetime (if L bit = 1) */ + /* u_int: valid lifetime (if L bit = 1) */ + /* string: DNS name */ +}; + +#endif /*__DHCP6_H_DEFINED*/ diff --git a/usr.sbin/tcpdump/dhcp6opt.h b/usr.sbin/tcpdump/dhcp6opt.h new file mode 100644 index 00000000000..3b0ab033241 --- /dev/null +++ b/usr.sbin/tcpdump/dhcp6opt.h @@ -0,0 +1,82 @@ +/* $OpenBSD: dhcp6opt.h,v 1.1 2000/04/26 21:35:38 jakob Exp $ */ + +/* + * Copyright (C) 1998 and 1999 WIDE Project. + * 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. + * 3. Neither the name of the project 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 PROJECT 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 PROJECT 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. + */ + +/* + * draft-ietf-dhc-v6exts-11 + */ + +#ifndef __DHCP6OPT_H_DEFINED +#define __DHCP6OPT_H_DEFINED + +#define OL6_N -1 +#define OL6_16N -2 +#define OL6_Z -3 + +#define OT6_NONE 0 +#define OT6_V6 1 +#define OT6_STR 2 +#define OT6_NUM 3 + +struct dhcp6_opt { + u_int code; + int len; + char *name; + int type; +}; + +/* index to parameters */ +#define DH6T_CLIENT_ADV_WAIT 1 /* milliseconds */ +#define DH6T_DEFAULT_SOLICIT_HOPCOUNT 2 /* times */ +#define DH6T_SERVER_MIN_ADV_DELAY 3 /* milliseconds */ +#define DH6T_SERVER_MAX_ADV_DELAY 4 /* milliseconds */ +#define DH6T_REQUEST_MSG_MIN_RETRANS 5 /* retransmissions */ +#define DH6T_REPLY_MSG_TIMEOUT 6 /* milliseconds */ +#define DH6T_REPLY_MSG_RETRANS_INTERVAL 7 /* milliseconds */ +#define DH6T_RECONF_MSG_TIMEOUT 8 /* milliseconds */ +#define DH6T_RECONF_MSG_MIN_RETRANS 9 /* retransmissions */ +#define DH6T_RECONF_MSG_RETRANS_INTERVAL 10 /* milliseconds */ +#define DH6T_RECONF_MMSG_MIN_RESP 11 /* milliseconds */ +#define DH6T_RECONF_MMSG_MAX_RESP 12 /* milliseconds */ +#define DH6T_MIN_SOLICIT_DELAY 13 /* milliseconds */ +#define DH6T_MAX_SOLICIT_DELAY 14 /* milliseconds */ +#define DH6T_XID_TIMEOUT 15 /* milliseconds */ +#define DH6T_RECONF_MULTICAST_REQUEST_WAIT 16 /* milliseconds */ + +#if 0 +extern struct dhcp6_opt *dh6o_pad; +extern struct dhcp6_opt *dh6o_end; +extern int dhcp6_param[]; +extern void dhcp6opttab_init __P((void)); +extern struct dhcp6_opt *dhcp6opttab_byname __P((char *)); +extern struct dhcp6_opt *dhcp6opttab_bycode __P((u_int)); +#endif + +#endif /*__DHCP6OPT_H_DEFINED*/ diff --git a/usr.sbin/tcpdump/ethertype.h b/usr.sbin/tcpdump/ethertype.h index 5307817849b..daa407e7ebc 100644 --- a/usr.sbin/tcpdump/ethertype.h +++ b/usr.sbin/tcpdump/ethertype.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/ethertype.h,v 1.7 2000/01/16 12:32:16 jakob Exp $ (LBL) + * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/ethertype.h,v 1.8 2000/04/26 21:35:38 jakob Exp $ (LBL) */ /* Types missing from some systems */ @@ -71,9 +71,6 @@ #ifndef ETHERTYPE_AARP #define ETHERTYPE_AARP 0x80f3 #endif -#ifndef ETHERTYPE_VLAN -#define ETHERTYPE_VLAN 0x8100 -#endif #ifndef ETHERTYPE_LOOPBACK #define ETHERTYPE_LOOPBACK 0x9000 #endif diff --git a/usr.sbin/tcpdump/igrp.h b/usr.sbin/tcpdump/igrp.h index 02d86e014ba..cc6088a8217 100644 --- a/usr.sbin/tcpdump/igrp.h +++ b/usr.sbin/tcpdump/igrp.h @@ -3,7 +3,7 @@ /* IGRP Header */ struct igrphdr { -#if BYTE_ORDER == BIG_ENDIAN +#ifdef WORDS_BIGENDIAN u_char ig_v:4; /* protocol version number */ u_char ig_op:4; /* opcode */ #else diff --git a/usr.sbin/tcpdump/interface.h b/usr.sbin/tcpdump/interface.h index 03c5ba962b9..c687cc2bf17 100644 --- a/usr.sbin/tcpdump/interface.h +++ b/usr.sbin/tcpdump/interface.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/interface.h,v 1.15 2000/01/16 11:43:57 jakob Exp $ (LBL) + * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/interface.h,v 1.16 2000/04/26 21:35:38 jakob Exp $ (LBL) */ #ifndef tcpdump_interface_h @@ -45,6 +45,7 @@ extern int Sflag; /* print raw TCP sequence numbers */ extern int tflag; /* print packet arrival time */ extern int vflag; /* verbose */ extern int xflag; /* print packet in hex */ +extern int Xflag; /* print packet in hex/ascii */ extern int packettype; /* as specified by -T */ #define PT_VAT 1 /* Visual Audio Tool */ @@ -61,6 +62,7 @@ extern int packettype; /* as specified by -T */ #define max(a,b) ((b)>(a)?(b):(a)) #endif +#ifndef INET6 /* * The default snapshot length. This value allows most printers to print * useful information while keeping the amount of unwanted data down. @@ -68,6 +70,9 @@ extern int packettype; /* as specified by -T */ * 14 bytes of data (assuming no ip options). */ #define DEFAULT_SNAPLEN 68 +#else +#define DEFAULT_SNAPLEN 96 +#endif /* INET6 */ #define SACK_SNAPLEN 94 #ifndef BIG_ENDIAN @@ -214,3 +219,15 @@ extern void wb_print(const void *, u_int); extern void esp_print(const u_char *, u_int, const u_char *); extern void radius_print(const u_char *, u_int); +#ifdef INET6 +extern void ip6_print(const u_char *, int); +extern void ip6_opt_print(const u_char *, int); +extern int hbhopt_print(const u_char *); +extern int dstopt_print(const u_char *); +extern int frag6_print(const u_char *, const u_char *); +extern void icmp6_print(const u_char *, const u_char *); +extern void ripng_print(const u_char *, int); +extern int rt6_print(const u_char *, const u_char *); +extern void ospf6_print(const u_char *, u_int); +extern void dhcp6_print(const u_char *, u_int, u_short, u_short); +#endif /*INET6*/ diff --git a/usr.sbin/tcpdump/machdep.c b/usr.sbin/tcpdump/machdep.c index 3e63de74500..3fd511567a1 100644 --- a/usr.sbin/tcpdump/machdep.c +++ b/usr.sbin/tcpdump/machdep.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/machdep.c,v 1.3 1999/09/16 20:58:45 brad Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/machdep.c,v 1.4 2000/04/26 21:35:38 jakob Exp $ (LBL)"; #endif #include <sys/types.h> @@ -39,7 +39,7 @@ abort_on_misalignment(char *ebuf) static int buf[2] = { SSIN_UACPROC, UAC_SIGBUS }; if (setsysinfo(SSI_NVPAIRS, (caddr_t)buf, 1, 0, 0) < 0) { - (void)sprintf(ebuf, "setsysinfo: errno %d", errno); + (void)sprintf(ebuf, "setsysinfo: %s", pcap_strerror(errno)); return (-1); } #endif diff --git a/usr.sbin/tcpdump/nfs.h b/usr.sbin/tcpdump/nfs.h index 0ffa071605b..23a3830400e 100644 --- a/usr.sbin/tcpdump/nfs.h +++ b/usr.sbin/tcpdump/nfs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs.h,v 1.2 1996/07/13 11:01:12 mickey Exp $ */ +/* $OpenBSD: nfs.h,v 1.3 2000/04/26 21:35:39 jakob Exp $ */ /* $NetBSD: nfs.h,v 1.1 1996/05/23 22:49:53 fvdl Exp $ */ /* @@ -241,8 +241,8 @@ #define nfstov_mode(a) (fxdr_unsigned(u_int16_t, (a))&07777) #define vtonfsv2_type(a) txdr_unsigned(nfsv2_type[((int32_t)(a))]) #define vtonfsv3_type(a) txdr_unsigned(nfsv3_type[((int32_t)(a))]) -#define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(u_int32,(a))&0x7] -#define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(u_int32,(a))&0x7] +#define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(u_int32_t,(a))&0x7] +#define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(u_int32_t,(a))&0x7] /* File types */ typedef enum { NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5, @@ -266,14 +266,14 @@ union nfsfh { typedef union nfsfh nfsfh_t; struct nfsv2_time { - u_int32 nfsv2_sec; - u_int32 nfsv2_usec; + u_int32_t nfsv2_sec; + u_int32_t nfsv2_usec; }; typedef struct nfsv2_time nfstime2; struct nfsv3_time { - u_int32 nfsv3_sec; - u_int32 nfsv3_nsec; + u_int32_t nfsv3_sec; + u_int32_t nfsv3_nsec; }; typedef struct nfsv3_time nfstime3; @@ -282,7 +282,7 @@ typedef struct nfsv3_time nfstime3; * protocol and to facilitate xdr conversion. */ struct nfs_uquad { - u_int32 nfsuquad[2]; + u_int32_t nfsuquad[2]; }; typedef struct nfs_uquad nfsuint64; @@ -290,7 +290,7 @@ typedef struct nfs_uquad nfsuint64; * Used to convert between two u_longs and a u_quad_t. */ union nfs_quadconvert { - u_int32 lval[2]; + u_int32_t lval[2]; u_quad_t qval; }; typedef union nfs_quadconvert nfsquad_t; @@ -299,8 +299,8 @@ typedef union nfs_quadconvert nfsquad_t; * NFS Version 3 special file number. */ struct nfsv3_spec { - u_int32 specdata1; - u_int32 specdata2; + u_int32_t specdata1; + u_int32_t specdata2; }; typedef struct nfsv3_spec nfsv3spec; @@ -314,19 +314,19 @@ typedef struct nfsv3_spec nfsv3spec; * NFSX_FATTR(v3) macro. */ struct nfs_fattr { - u_int32 fa_type; - u_int32 fa_mode; - u_int32 fa_nlink; - u_int32 fa_uid; - u_int32 fa_gid; + u_int32_t fa_type; + u_int32_t fa_mode; + u_int32_t fa_nlink; + u_int32_t fa_uid; + u_int32_t fa_gid; union { struct { - u_int32 nfsv2fa_size; - u_int32 nfsv2fa_blocksize; - u_int32 nfsv2fa_rdev; - u_int32 nfsv2fa_blocks; - u_int32 nfsv2fa_fsid; - u_int32 nfsv2fa_fileid; + u_int32_t nfsv2fa_size; + u_int32_t nfsv2fa_blocksize; + u_int32_t nfsv2fa_rdev; + u_int32_t nfsv2fa_blocks; + u_int32_t nfsv2fa_fsid; + u_int32_t nfsv2fa_fileid; nfstime2 nfsv2fa_atime; nfstime2 nfsv2fa_mtime; nfstime2 nfsv2fa_ctime; @@ -364,10 +364,10 @@ struct nfs_fattr { #define fa3_ctime fa_un.fa_nfsv3.nfsv3fa_ctime struct nfsv2_sattr { - u_int32 sa_mode; - u_int32 sa_uid; - u_int32 sa_gid; - u_int32 sa_size; + u_int32_t sa_mode; + u_int32_t sa_uid; + u_int32_t sa_gid; + u_int32_t sa_size; nfstime2 sa_atime; nfstime2 sa_mtime; }; @@ -376,28 +376,28 @@ struct nfsv2_sattr { * NFS Version 3 sattr structure for the new node creation case. */ struct nfsv3_sattr { - u_int32 sa_modeset; - u_int32 sa_mode; - u_int32 sa_uidset; - u_int32 sa_uid; - u_int32 sa_gidset; - u_int32 sa_gid; - u_int32 sa_sizeset; - u_int32 sa_size; - u_int32 sa_atimetype; + u_int32_t sa_modeset; + u_int32_t sa_mode; + u_int32_t sa_uidset; + u_int32_t sa_uid; + u_int32_t sa_gidset; + u_int32_t sa_gid; + u_int32_t sa_sizeset; + u_int32_t sa_size; + u_int32_t sa_atimetype; nfstime3 sa_atime; - u_int32 sa_mtimetype; + u_int32_t sa_mtimetype; nfstime3 sa_mtime; }; struct nfs_statfs { union { struct { - u_int32 nfsv2sf_tsize; - u_int32 nfsv2sf_bsize; - u_int32 nfsv2sf_blocks; - u_int32 nfsv2sf_bfree; - u_int32 nfsv2sf_bavail; + u_int32_t nfsv2sf_tsize; + u_int32_t nfsv2sf_bsize; + u_int32_t nfsv2sf_blocks; + u_int32_t nfsv2sf_bfree; + u_int32_t nfsv2sf_bavail; } sf_nfsv2; struct { nfsuint64 nfsv3sf_tbytes; @@ -406,7 +406,7 @@ struct nfs_statfs { nfsuint64 nfsv3sf_tfiles; nfsuint64 nfsv3sf_ffiles; nfsuint64 nfsv3sf_afiles; - u_int32 nfsv3sf_invarsec; + u_int32_t nfsv3sf_invarsec; } sf_nfsv3; } sf_un; }; @@ -425,23 +425,23 @@ struct nfs_statfs { #define sf_invarsec sf_un.sf_nfsv3.nfsv3sf_invarsec struct nfsv3_fsinfo { - u_int32 fs_rtmax; - u_int32 fs_rtpref; - u_int32 fs_rtmult; - u_int32 fs_wtmax; - u_int32 fs_wtpref; - u_int32 fs_wtmult; - u_int32 fs_dtpref; + u_int32_t fs_rtmax; + u_int32_t fs_rtpref; + u_int32_t fs_rtmult; + u_int32_t fs_wtmax; + u_int32_t fs_wtpref; + u_int32_t fs_wtmult; + u_int32_t fs_dtpref; nfsuint64 fs_maxfilesize; nfstime3 fs_timedelta; - u_int32 fs_properties; + u_int32_t fs_properties; }; struct nfsv3_pathconf { - u_int32 pc_linkmax; - u_int32 pc_namemax; - u_int32 pc_notrunc; - u_int32 pc_chownrestricted; - u_int32 pc_caseinsensitive; - u_int32 pc_casepreserving; + u_int32_t pc_linkmax; + u_int32_t pc_namemax; + u_int32_t pc_notrunc; + u_int32_t pc_chownrestricted; + u_int32_t pc_caseinsensitive; + u_int32_t pc_casepreserving; }; diff --git a/usr.sbin/tcpdump/ospf6.h b/usr.sbin/tcpdump/ospf6.h new file mode 100644 index 00000000000..c1e8c228121 --- /dev/null +++ b/usr.sbin/tcpdump/ospf6.h @@ -0,0 +1,282 @@ +/* $OpenBSD: ospf6.h,v 1.1 2000/04/26 21:35:39 jakob Exp $ */ + +/* + * Copyright (c) 1991, 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. + * + * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu) + */ +#define OSPF_TYPE_UMD 0 /* UMd's special monitoring packets */ +#define OSPF_TYPE_HELLO 1 /* Hello */ +#define OSPF_TYPE_DB 2 /* Database Description */ +#define OSPF_TYPE_LSR 3 /* Link State Request */ +#define OSPF_TYPE_LSU 4 /* Link State Update */ +#define OSPF_TYPE_LSA 5 /* Link State Ack */ +#define OSPF_TYPE_MAX 6 + +/* Options *_options */ +#define OSPF6_OPTION_V6 0x01 /* V6 bit: A bit for peeping tom */ +#define OSPF6_OPTION_E 0x02 /* E bit: External routes advertised */ +#define OSPF6_OPTION_MC 0x04 /* MC bit: Multicast capable */ +#define OSPF6_OPTION_N 0x08 /* N bit: For type-7 LSA */ +#define OSPF6_OPTION_R 0x10 /* R bit: Router bit */ +#define OSPF6_OPTION_DC 0x20 /* DC bit: Demand circuits */ + + +/* db_flags */ +#define OSPF6_DB_INIT 0x04 /* */ +#define OSPF6_DB_MORE 0x02 +#define OSPF6_DB_MASTER 0x01 + +/* ls_type */ +#define LS_TYPE_ROUTER 1 /* router link */ +#define LS_TYPE_NETWORK 2 /* network link */ +#define LS_TYPE_INTER_AP 3 /* Inter-Area-Prefix */ +#define LS_TYPE_INTER_AR 4 /* Inter-Area-Router */ +#define LS_TYPE_ASE 5 /* ASE */ +#define LS_TYPE_GROUP 6 /* Group membership */ +#define LS_TYPE_TYPE7 7 /* Type 7 LSA */ +#define LS_TYPE_LINK 8 /* Link LSA */ +#define LS_TYPE_INTRA_AP 9 /* Intra-Area-Prefix */ +#define LS_TYPE_MAX 10 +#define LS_TYPE_MASK 0x1fff + +#define LS_SCOPE_LINKLOCAL 0x0000 +#define LS_SCOPE_AREA 0x2000 +#define LS_SCOPE_AS 0x4000 +#define LS_SCOPE_MASK 0x6000 + +/************************************************* + * + * is the above a bug in the documentation? + * + *************************************************/ + + +/* rla_link.link_type */ +#define RLA_TYPE_ROUTER 1 /* point-to-point to another router */ +#define RLA_TYPE_TRANSIT 2 /* connection to transit network */ +#define RLA_TYPE_VIRTUAL 4 /* virtual link */ + +/* rla_flags */ +#define RLA_FLAG_B 0x01 +#define RLA_FLAG_E 0x02 +#define RLA_FLAG_V 0x04 +#define RLA_FLAG_W 0x08 + +/* sla_tosmetric breakdown */ +#define SLA_MASK_TOS 0x7f000000 +#define SLA_MASK_METRIC 0x00ffffff +#define SLA_SHIFT_TOS 24 + +/* asla_tosmetric breakdown */ +#define ASLA_FLAG_EXTERNAL 0x80000000 +#define ASLA_MASK_TOS 0x7f000000 +#define ASLA_SHIFT_TOS 24 +#define ASLA_MASK_METRIC 0x00ffffff + +/* multicast vertex type */ +#define MCLA_VERTEX_ROUTER 1 +#define MCLA_VERTEX_NETWORK 2 + +typedef u_int32_t rtrid_t; + +/* link state advertisement header */ +struct lsa_hdr { + u_int16_t ls_age; + u_int16_t ls_type; + rtrid_t ls_stateid; + rtrid_t ls_router; + u_int32_t ls_seq; + u_int16_t ls_chksum; + u_int16_t ls_length; +} ; + +struct lsa_prefix { + u_int8_t lsa_p_len; + u_int8_t lsa_p_opt; + u_int16_t lsa_p_mbz; + u_int8_t lsa_p_prefix[4]; +}; + +/* link state advertisement */ +struct lsa { + struct lsa_hdr ls_hdr; + + /* Link state types */ + union { + /* Router links advertisements */ + struct { + union { + u_int8_t flg; + u_int32_t opt; + } rla_flgandopt; +#define rla_flags rla_flgandopt.flg +#define rla_options rla_flgandopt.opt + struct rlalink { + u_int8_t link_type; + u_int8_t link_zero[1]; + u_int16_t link_metric; + u_int32_t link_ifid; + u_int32_t link_nifid; + rtrid_t link_nrtid; + } rla_link[1]; /* may repeat */ + } un_rla; + + /* Network links advertisements */ + struct { + u_int32_t nla_options; + rtrid_t nla_router[1]; /* may repeat */ + } un_nla; + + /* Inter Area Prefix LSA */ + struct { + u_int32_t inter_ap_metric; + struct lsa_prefix inter_ap_prefix[1]; + } un_inter_ap; + +#if 0 + /* Summary links advertisements */ + struct { + struct in_addr sla_mask; + u_int32_t sla_tosmetric[1]; /* may repeat */ + } un_sla; + + /* AS external links advertisements */ + struct { + struct in_addr asla_mask; + struct aslametric { + u_int32_t asla_tosmetric; + struct in_addr asla_forward; + struct in_addr asla_tag; + } asla_metric[1]; /* may repeat */ + } un_asla; + + /* Multicast group membership */ + struct mcla { + u_int32_t mcla_vtype; + struct in_addr mcla_vid; + } un_mcla[1]; +#endif + + /* Type 7 LSA */ + + /* Link LSA */ + struct llsa { + union { + u_int8_t pri; + u_int32_t opt; + } llsa_priandopt; +#define llsa_priority llsa_priandopt.pri +#define llsa_options llsa_priandopt.opt + struct in6_addr llsa_lladdr; + u_int32_t llsa_nprefix; + struct lsa_prefix llsa_prefix[1]; + } un_llsa; + + /* Intra-Area-Prefix */ + struct { + u_int16_t intra_ap_nprefix; + u_int16_t intra_ap_lstype; + rtrid_t intra_ap_lsid; + rtrid_t intra_ap_rtid; + struct lsa_prefix intra_ap_prefix[1]; + } un_intra_ap; + } lsa_un; +} ; + + +/* + * TOS metric struct (will be 0 or more in router links update) + */ +struct tos_metric { + u_int8_t tos_type; + u_int8_t tos_zero; + u_int16_t tos_metric; +} ; + +#define OSPF_AUTH_SIZE 8 + +/* + * the main header + */ +struct ospf6hdr { + u_int8_t ospf6_version; + u_int8_t ospf6_type; + u_int16_t ospf6_len; + rtrid_t ospf6_routerid; + rtrid_t ospf6_areaid; + u_int16_t ospf6_chksum; + u_int8_t ospf6_instanceid; + u_int8_t ospf6_rsvd; + union { + + /* Hello packet */ + struct { + u_int32_t hello_ifid; + union { + u_int8_t pri; + u_int32_t opt; + } hello_priandopt; +#define hello_priority hello_priandopt.pri +#define hello_options hello_priandopt.opt + u_int16_t hello_helloint; + u_int16_t hello_deadint; + rtrid_t hello_dr; + rtrid_t hello_bdr; + rtrid_t hello_neighbor[1]; /* may repeat */ + } un_hello; + + /* Database Description packet */ + struct { + u_int32_t db_options; + u_int16_t db_mtu; + u_int8_t db_mbz; + u_int8_t db_flags; + u_int32_t db_seq; + struct lsa_hdr db_lshdr[1]; /* may repeat */ + } un_db; + + /* Link State Request */ + struct lsr { + u_int16_t ls_mbz; + u_int16_t ls_type; + rtrid_t ls_stateid; + rtrid_t ls_router; + } un_lsr[1]; /* may repeat */ + + /* Link State Update */ + struct { + u_int32_t lsu_count; + struct lsa lsu_lsa[1]; /* may repeat */ + } un_lsu; + + /* Link State Acknowledgement */ + struct { + struct lsa_hdr lsa_lshdr[1]; /* may repeat */ + } un_lsa ; + } ospf6_un ; +} ; + +#define ospf6_hello ospf6_un.un_hello +#define ospf6_db ospf6_un.un_db +#define ospf6_lsr ospf6_un.un_lsr +#define ospf6_lsu ospf6_un.un_lsu +#define ospf6_lsa ospf6_un.un_lsa + diff --git a/usr.sbin/tcpdump/print-atalk.c b/usr.sbin/tcpdump/print-atalk.c index de1301b6df6..d648ab59989 100644 --- a/usr.sbin/tcpdump/print-atalk.c +++ b/usr.sbin/tcpdump/print-atalk.c @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-atalk.c,v 1.13 2000/04/03 05:43:42 itojun Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-atalk.c,v 1.14 2000/04/26 21:35:39 jakob Exp $ (LBL)"; #endif #include <sys/param.h> @@ -194,7 +194,7 @@ aarp_print(register const u_char *bp, u_int length) printf("aarp "); ap = (const struct aarp *)bp; if (ntohs(ap->htype) == 1 && ntohs(ap->ptype) == ETHERTYPE_ATALK && - ap->halen == 6 && ap->palen == 4) + ap->halen == 6 && ap->palen == 4 ) switch (ntohs(ap->op)) { case 1: /* request */ @@ -214,7 +214,7 @@ aarp_print(register const u_char *bp, u_int length) } (void)printf("len %u op %u htype %u ptype %#x halen %u palen %u", length, ntohs(ap->op), ntohs(ap->htype), ntohs(ap->ptype), - ap->halen, ap->palen ); + ap->halen, ap->palen); } static void diff --git a/usr.sbin/tcpdump/print-atm.c b/usr.sbin/tcpdump/print-atm.c index 93541c8c63c..f8b2609b84e 100644 --- a/usr.sbin/tcpdump/print-atm.c +++ b/usr.sbin/tcpdump/print-atm.c @@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-atm.c,v 1.4 1999/09/16 20:58:45 brad Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-atm.c,v 1.5 2000/04/26 21:35:39 jakob Exp $ (LBL)"; #endif #include <sys/param.h> @@ -41,7 +41,6 @@ struct rtentry; #include <netinet/udp.h> #include <netinet/udp_var.h> #include <netinet/tcp.h> -#include <netinet/tcpip.h> #include <stdio.h> #include <pcap.h> @@ -106,6 +105,12 @@ atm_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) ip_print(p, length); break; +#ifdef INET6 + case ETHERTYPE_IPV6: + ip6_print(p, length); + break; +#endif /*INET6*/ + /*XXX this probably isn't right */ case ETHERTYPE_ARP: case ETHERTYPE_REVARP: diff --git a/usr.sbin/tcpdump/print-bgp.c b/usr.sbin/tcpdump/print-bgp.c index 7be61b285b8..8baaec38995 100644 --- a/usr.sbin/tcpdump/print-bgp.c +++ b/usr.sbin/tcpdump/print-bgp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-bgp.c,v 1.1 2000/01/16 11:43:57 jakob Exp $ */ +/* $OpenBSD: print-bgp.c,v 1.2 2000/04/26 21:35:39 jakob Exp $ */ /* * Copyright (C) 1999 WIDE Project. @@ -380,7 +380,7 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len) printf(" invalid len"); break; } - for (i = 0; i < len; i++) { + for (i = 0; i < len; i += 4) { u_int32_t comm; comm = (u_int32_t)ntohl(*(u_int32_t *)&p[i]); switch (comm) { @@ -395,7 +395,7 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len) break; default: printf(" (AS #%d value 0x%04x)", - (comm >> 16) & 0xffff, comm & 0xfffff); + (comm >> 16) & 0xffff, comm & 0xffff); break; } } diff --git a/usr.sbin/tcpdump/print-bootp.c b/usr.sbin/tcpdump/print-bootp.c index 2312eba66b0..651151f622f 100644 --- a/usr.sbin/tcpdump/print-bootp.c +++ b/usr.sbin/tcpdump/print-bootp.c @@ -22,7 +22,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-bootp.c,v 1.9 1999/09/16 20:58:46 brad Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-bootp.c,v 1.10 2000/04/26 21:35:39 jakob Exp $ (LBL)"; #endif #include <sys/param.h> @@ -100,6 +100,8 @@ bootp_print(register const u_char *cp, u_int length, printf(" xid:0x%x", (u_int32_t)ntohl(bp->bp_xid)); if (bp->bp_secs) printf(" secs:%d", ntohs(bp->bp_secs)); + if (bp->bp_flags) + printf(" flags:0x%x", ntohs(bp->bp_flags)); /* Client's ip address */ TCHECK(bp->bp_ciaddr); @@ -148,7 +150,7 @@ bootp_print(register const u_char *cp, u_int length, } putchar('"'); } - TCHECK2(bp->bp_file[0], 1); /* check first char only */ + TCHECK2(bp->bp_sname[0], 1); /* check first char only */ if (*bp->bp_file) { printf(" file \""); if (fn_print(bp->bp_file, snapend)) { @@ -205,6 +207,63 @@ static struct tok tag2str[] = { { TAG_SWAP_SERVER, "iSS" }, { TAG_ROOTPATH, "aRP" }, { TAG_EXTPATH, "aEP" }, +/* RFC2132 tags */ + { TAG_IP_FORWARD, "BIPF" }, + { TAG_NL_SRCRT, "BSRT" }, + { TAG_PFILTERS, "pPF" }, + { TAG_REASS_SIZE, "sRSZ" }, + { TAG_DEF_TTL, "bTTL" }, + { TAG_MTU_TIMEOUT, "lMA" }, + { TAG_MTU_TABLE, "sMT" }, + { TAG_INT_MTU, "sMTU" }, + { TAG_LOCAL_SUBNETS, "BLSN" }, + { TAG_BROAD_ADDR, "iBR" }, + { TAG_DO_MASK_DISC, "BMD" }, + { TAG_SUPPLY_MASK, "BMS" }, + { TAG_DO_RDISC, "BRD" }, + { TAG_RTR_SOL_ADDR, "iRSA" }, + { TAG_STATIC_ROUTE, "pSR" }, + { TAG_USE_TRAILERS, "BUT" }, + { TAG_ARP_TIMEOUT, "lAT" }, + { TAG_ETH_ENCAP, "BIE" }, + { TAG_TCP_TTL, "bTT" }, + { TAG_TCP_KEEPALIVE, "lKI" }, + { TAG_KEEPALIVE_GO, "BKG" }, + { TAG_NIS_DOMAIN, "aYD" }, + { TAG_NIS_SERVERS, "iYS" }, + { TAG_NTP_SERVERS, "iNTP" }, + { TAG_VENDOR_OPTS, "bVO" }, + { TAG_NETBIOS_NS, "iWNS" }, + { TAG_NETBIOS_DDS, "iWDD" }, + { TAG_NETBIOS_NODE, "bWNT" }, + { TAG_NETBIOS_SCOPE, "aWSC" }, + { TAG_XWIN_FS, "iXFS" }, + { TAG_XWIN_DM, "iXDM" }, + { TAG_NIS_P_DOMAIN, "sN+D" }, + { TAG_NIS_P_SERVERS, "iN+S" }, + { TAG_MOBILE_HOME, "iMH" }, + { TAG_SMPT_SERVER, "iSMTP" }, + { TAG_POP3_SERVER, "iPOP3" }, + { TAG_NNTP_SERVER, "iNNTP" }, + { TAG_WWW_SERVER, "iWWW" }, + { TAG_FINGER_SERVER, "iFG" }, + { TAG_IRC_SERVER, "iIRC" }, + { TAG_STREETTALK_SRVR, "iSTS" }, + { TAG_STREETTALK_STDA, "iSTDA" }, + { TAG_REQUESTED_IP, "iRQ" }, + { TAG_IP_LEASE, "lLT" }, + { TAG_OPT_OVERLOAD, "bOO" }, + { TAG_TFTP_SERVER, "aTFTP" }, + { TAG_BOOTFILENAME, "aBF" }, + { TAG_DHCP_MESSAGE, " DHCP" }, + { TAG_SERVER_ID, "iSID" }, + { TAG_PARM_REQUEST, "bPR" }, + { TAG_MESSAGE, "aMSG" }, + { TAG_MAX_MSG_SIZE, "sMSZ" }, + { TAG_RENEWAL_TIME, "lRN" }, + { TAG_REBIND_TIME, "lRB" }, + { TAG_VENDOR_CLASS, "bVC" }, + { TAG_CLIENT_ID, "bCID" }, { 0, NULL } }; @@ -246,6 +305,35 @@ rfc1048_print(register const u_char *bp, register u_int length) return; } + if (tag == TAG_DHCP_MESSAGE && len == 1) { + c = *bp++; + switch (c) { + case DHCPDISCOVER: printf("DISCOVER"); break; + case DHCPOFFER: printf("OFFER"); break; + case DHCPREQUEST: printf("REQUEST"); break; + case DHCPDECLINE: printf("DECLINE"); break; + case DHCPACK: printf("ACK"); break; + case DHCPNAK: printf("NACK"); break; + case DHCPRELEASE: printf("RELEASE"); break; + case DHCPINFORM: printf("INFORM"); break; + default: printf("%u", c); break; + } + continue; + } + + if (tag == TAG_PARM_REQUEST) { + first = 1; + while (len-- > 0) { + c = *bp++; + cp = tok2str(tag2str, "?%d", c); + if (!first) + putchar('+'); + printf("%s", cp + 1); + first = 0; + } + continue; + } + /* Print data */ size = len; if (c == '?') { @@ -286,6 +374,22 @@ rfc1048_print(register const u_char *bp, register u_int length) } break; + case 'p': + /* IP address pairs */ + while (size >= 2*sizeof(ul)) { + if (!first) + putchar(','); + memcpy((char *)&ul, (char *)bp, sizeof(ul)); + printf("(%s:", ipaddr_string(&ul)); + bp += sizeof(ul); + memcpy((char *)&ul, (char *)bp, sizeof(ul)); + printf("%s)", ipaddr_string(&ul)); + bp += sizeof(ul); + size -= 2*sizeof(ul); + first = 0; + } + break; + case 's': /* shorts */ while (size >= sizeof(us)) { @@ -299,6 +403,28 @@ rfc1048_print(register const u_char *bp, register u_int length) } break; + case 'B': + /* boolean */ + while (size > 0) { + if (!first) + putchar(','); + switch (*bp) { + case 0: + putchar('N'); + break; + case 1: + putchar('Y'); + break; + default: + printf("%d?", *bp); + break; + } + ++bp; + --size; + first = 0; + } + break; + case 'b': default: /* Bytes */ diff --git a/usr.sbin/tcpdump/print-dhcp6.c b/usr.sbin/tcpdump/print-dhcp6.c new file mode 100644 index 00000000000..96df730f1b4 --- /dev/null +++ b/usr.sbin/tcpdump/print-dhcp6.c @@ -0,0 +1,340 @@ +/* $OpenBSD: print-dhcp6.c,v 1.1 2000/04/26 21:35:39 jakob Exp $ */ + +/* + * Copyright (C) 1998 and 1999 WIDE Project. + * 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. + * 3. Neither the name of the project 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 PROJECT 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 PROJECT 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. + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-dhcp6.c,v 1.1 2000/04/26 21:35:39 jakob Exp $"; +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> + +#if __STDC__ +struct mbuf; +struct rtentry; +#endif +#include <net/if.h> + +#include <netinet/in.h> + +#include <ctype.h> +#ifdef HAVE_MEMORY_H +#include <memory.h> +#endif +#include <stdio.h> +#include <string.h> +#include <arpa/inet.h> + +#include "interface.h" +#include "addrtoname.h" +#include "dhcp6.h" +#include "dhcp6opt.h" + +#if 0 +static void dhcp6opttab_init __P((void)); +static struct dhcp6_opt *dhcp6opttab_byname __P((char *)); +#endif +static struct dhcp6_opt *dhcp6opttab_bycode __P((u_int)); + +static char tstr[] = " [|dhcp6]"; + +static struct dhcp6_opt dh6opttab[] = { + /* IP Address Extension */ + { 1, OL6_N, "IP Address", OT6_NONE, }, + + /* General Extension */ + { 2, 4, "Time Offset", OT6_NUM, }, + { 3, OL6_N, "IEEE 1003.1 POSIX Timezone", OT6_STR, }, + { 6, OL6_16N, "Domain Name Server", OT6_V6, }, + { 10, OL6_N, "Domain Name", OT6_STR, }, + + /* Application and Service Parameters */ + { 16, OL6_N, "Directory Agent", OT6_NONE, }, + { 17, OL6_N, "Service Scope" , OT6_NONE, }, + { 18, OL6_16N, "Network Time Protocol Servers", OT6_V6, }, + { 19, OL6_N, "NIS Domain", OT6_STR, }, + { 20, OL6_16N, "NIS Servers", OT6_V6, }, + { 21, OL6_N, "NIS+ Domain", OT6_STR, }, + { 22, OL6_16N, "NIS+ Servers", OT6_V6, }, + + /* TCP Parameters */ + { 32, 4, "TCP Keepalive Interval", OT6_NUM, }, + + /* DHCPv6 Extensions */ + { 40, 4, "Maximum DHCPv6 Message Size", OT6_NUM, }, + { 41, OL6_N, "DHCP Retransmission and Configuration Parameter", + OT6_NONE, }, + { 48, OL6_N, "Platform Specific Information", OT6_NONE, }, + { 49, OL6_N, "Platform Class Identifier", OT6_STR, }, + { 64, OL6_N, "Class Identifier", OT6_STR, }, + { 66, 16, "Reconfigure Multicast Address", OT6_V6, }, + { 67, 16, "Renumber DHCPv6 Server Address", + OT6_V6, }, + { 68, OL6_N, "DHCP Relay ICMP Error Message", OT6_NONE, }, + { 84, OL6_N, "Client-Server Authentication", OT6_NONE, }, + { 85, 4, "Client Key Selection", OT6_NUM, }, + + /* End Extension */ + { 65536, OL6_Z, "End", OT6_NONE, }, + + { 0 }, +}; + +#if 0 +static struct dhcp6_opt *dh6o_pad; +static struct dhcp6_opt *dh6o_end; + +static void +dhcp6opttab_init() +{ + dh6o_pad = dhcp6opttab_bycode(0); + dh6o_end = dhcp6opttab_bycode(65536); +} +#endif + +#if 0 +static struct dhcp6_opt * +dhcp6opttab_byname(name) + char *name; +{ + struct dhcp6_opt *p; + + for (p = dh6opttab; p->code; p++) + if (strcmp(name, p->name) == 0) + return p; + return NULL; +} +#endif + +static struct dhcp6_opt * +dhcp6opttab_bycode(code) + u_int code; +{ + struct dhcp6_opt *p; + + for (p = dh6opttab; p->code; p++) + if (p->code == code) + return p; + return NULL; +} + +static void +dhcp6ext_print(u_char *cp, u_char *ep) +{ + u_int16_t code, len; + struct dhcp6_opt *p; + char buf[BUFSIZ]; + int i; + + if (cp == ep) + return; + printf(" "); + while (cp < ep) { + code = ntohs(*(u_int16_t *)&cp[0]); + if (code != 65535) + len = ntohs(*(u_int16_t *)&cp[2]); + else + len = 0; + p = dhcp6opttab_bycode(code); + if (p == NULL) { + printf("(unknown, len=%d)", len); + cp += len + 4; + continue; + } + + /* sanity check on length */ + switch (p->len) { + case OL6_N: + break; + case OL6_16N: + if (len % 16 != 0) + goto trunc; + break; + case OL6_Z: + if (len != 0) + goto trunc; + break; + default: + if (len != p->len) + goto trunc; + break; + } + if (cp + 4 + len > ep) { + printf("[|%s]", p->name); + return; + } + + printf("(%s, ", p->name); + switch (p->type) { + case OT6_V6: + for (i = 0; i < len; i += 16) { + inet_ntop(AF_INET6, &cp[4 + i], buf, + sizeof(buf)); + if (i != 0) + printf(","); + printf("%s", buf); + } + break; + case OT6_STR: + memset(&buf, 0, sizeof(buf)); + strncpy(buf, &cp[4], len); + printf("%s", buf); + break; + case OT6_NUM: + printf("%d", (u_int32_t)ntohl(*(u_int32_t *)&cp[4])); + break; + default: + for (i = 0; i < len; i++) + printf("%02x", cp[4 + i] & 0xff); + } + printf(")"); + cp += len + 4; + } + return; + +trunc: + printf("[|dhcp6ext]"); +} + +/* + * Print dhcp6 requests + */ +void +dhcp6_print(register const u_char *cp, u_int length, + u_short sport, u_short dport) +{ + union dhcp6 *dh6; + u_char *ep; + u_char *extp; + + printf("dhcp6"); + + ep = (u_char *)snapend; + + dh6 = (union dhcp6 *)cp; + TCHECK(dh6->dh6_msgtype); + switch (dh6->dh6_msgtype) { + case DH6_SOLICIT: + if (vflag && TTEST(dh6->dh6_sol.dh6sol_relayaddr)) { + printf(" solicit("); + if ((dh6->dh6_sol.dh6sol_flags & DH6SOL_CLOSE) != 0) + printf("C"); + if (dh6->dh6_sol.dh6sol_flags != 0) + printf(" "); + printf("cliaddr=%s", + ip6addr_string(&dh6->dh6_sol.dh6sol_cliaddr)); + printf(" relayaddr=%s", + ip6addr_string(&dh6->dh6_sol.dh6sol_relayaddr)); + printf(")"); + } else + printf(" solicit"); + break; + case DH6_ADVERT: + if (!(vflag && TTEST(dh6->dh6_adv.dh6adv_serveraddr))) { + printf(" advert"); + break; + } + printf(" advert("); + if ((dh6->dh6_adv.dh6adv_flags & DH6ADV_SERVPRESENT) != 0) + printf("S"); + if (dh6->dh6_adv.dh6adv_flags != 0) + printf(" "); + printf("pref=%u", dh6->dh6_adv.dh6adv_pref); + printf(" cliaddr=%s", + ip6addr_string(&dh6->dh6_adv.dh6adv_cliaddr)); + printf(" relayaddr=%s", + ip6addr_string(&dh6->dh6_adv.dh6adv_relayaddr)); + printf(" servaddr=%s", + ip6addr_string(&dh6->dh6_adv.dh6adv_serveraddr)); + extp = (u_char *)((&dh6->dh6_adv) + 1); + dhcp6ext_print(extp, ep); + printf(")"); + break; + case DH6_REQUEST: + if (!(vflag && TTEST(dh6->dh6_req.dh6req_relayaddr))) { + printf(" request"); + break; + } + printf(" request("); + if ((dh6->dh6_req.dh6req_flags & DH6REQ_CLOSE) != 0) + printf("C"); + if ((dh6->dh6_req.dh6req_flags & DH6REQ_SERVPRESENT) != 0) + printf("S"); + if ((dh6->dh6_req.dh6req_flags & DH6REQ_REBOOT) != 0) + printf("R"); + if (dh6->dh6_req.dh6req_flags != 0) + printf(" "); + printf("xid=0x%04x", dh6->dh6_req.dh6req_xid); + printf(" cliaddr=%s", + ip6addr_string(&dh6->dh6_req.dh6req_cliaddr)); + printf(" relayaddr=%s", + ip6addr_string(&dh6->dh6_req.dh6req_relayaddr)); + extp = (char *)((&dh6->dh6_req) + 1); + if ((dh6->dh6_req.dh6req_flags & DH6REQ_SERVPRESENT) != 0) { + printf(" servaddr=%s", ip6addr_string(extp)); + extp += 16; + } + dhcp6ext_print(extp, ep); + printf(")"); + break; + case DH6_REPLY: + if (!(vflag && TTEST(dh6->dh6_rep.dh6rep_xid))) { + printf(" reply"); + break; + } + printf(" reply("); + if ((dh6->dh6_rep.dh6rep_flagandstat & DH6REP_CLIPRESENT) != 0) + printf("C"); + if (dh6->dh6_rep.dh6rep_flagandstat != 0) + printf(" "); + printf("stat=0x%02x", + dh6->dh6_rep.dh6rep_flagandstat & DH6REP_STATMASK); + extp = (u_char *)((&dh6->dh6_rep) + 1); + if ((dh6->dh6_rep.dh6rep_flagandstat & DH6REP_CLIPRESENT) != 0) { + printf(" cliaddr=%s", ip6addr_string(extp)); + extp += 16; + } + dhcp6ext_print(extp, ep); + printf(")"); + break; + case DH6_RELEASE: + printf(" release"); + break; + case DH6_RECONFIG: + printf(" reconfig"); + break; + } + return; + +trunc: + printf("%s", tstr); +} diff --git a/usr.sbin/tcpdump/print-domain.c b/usr.sbin/tcpdump/print-domain.c index e9960d201b6..1b37f0930b1 100644 --- a/usr.sbin/tcpdump/print-domain.c +++ b/usr.sbin/tcpdump/print-domain.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-domain.c,v 1.9 2000/01/16 12:43:58 jakob Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-domain.c,v 1.10 2000/04/26 21:35:40 jakob Exp $ (LBL)"; #endif #include <sys/param.h> @@ -42,7 +42,6 @@ struct rtentry; #include <netinet/udp.h> #include <netinet/udp_var.h> #include <netinet/tcp.h> -#include <netinet/tcpip.h> #ifdef NOERROR #undef NOERROR /* Solaris sucks */ @@ -53,6 +52,7 @@ struct rtentry; #include <arpa/nameser.h> #include <stdio.h> +#include <string.h> #include "interface.h" #include "addrtoname.h" @@ -172,8 +172,11 @@ ns_nprint(register const u_char *cp, register const u_char *bp) register u_int i; register const u_char *rp; register int compress; + int chars_processed; + int data_size = snapend - bp; i = *cp++; + chars_processed = 1; rp = cp + i; if ((i & INDIR_MASK) == INDIR_MASK) { rp = cp + 1; @@ -185,13 +188,29 @@ ns_nprint(register const u_char *cp, register const u_char *bp) if ((i & INDIR_MASK) == INDIR_MASK) { cp = bp + (((i << 8) | *cp) & 0x3fff); i = *cp++; + chars_processed++; + + /* + * If we've looked at every character in + * the message, this pointer will make + * us look at some character again, + * which means we're looping. + */ + if (chars_processed >= data_size) { + fn_printn(cp, 6, "<LOOP>"); + if (!compress) + rp += i + 1; + return (rp); + } continue; } if (fn_printn(cp, i, snapend)) break; cp += i; + chars_processed += i; putchar('.'); i = *cp++; + chars_processed++; if (!compress) rp += i + 1; } diff --git a/usr.sbin/tcpdump/print-dvmrp.c b/usr.sbin/tcpdump/print-dvmrp.c index 52a257cc40b..290e89ddd64 100644 --- a/usr.sbin/tcpdump/print-dvmrp.c +++ b/usr.sbin/tcpdump/print-dvmrp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-dvmrp.c,v 1.2 1996/12/12 16:22:39 bitblt Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-dvmrp.c,v 1.3 2000/04/26 21:35:40 jakob Exp $ (LBL)"; #endif #include <sys/param.h> @@ -35,7 +35,6 @@ static const char rcsid[] = #include <netinet/udp.h> #include <netinet/udp_var.h> #include <netinet/tcp.h> -#include <netinet/tcpip.h> #include <stdio.h> #include <string.h> diff --git a/usr.sbin/tcpdump/print-ether.c b/usr.sbin/tcpdump/print-ether.c index 9873fb681ae..986b074ca51 100644 --- a/usr.sbin/tcpdump/print-ether.c +++ b/usr.sbin/tcpdump/print-ether.c @@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ether.c,v 1.14 2000/03/07 18:16:37 chris Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ether.c,v 1.15 2000/04/26 21:35:40 jakob Exp $ (LBL)"; #endif #include <sys/param.h> @@ -41,11 +41,14 @@ struct rtentry; #include <netinet/udp.h> #include <netinet/udp_var.h> #include <netinet/tcp.h> -#include <netinet/tcpip.h> #include <stdio.h> #include <pcap.h> +#ifdef INET6 +#include <netinet/ip6.h> +#endif + #include "interface.h" #include "addrtoname.h" #include "ethertype.h" @@ -166,6 +169,12 @@ recurse: ip_print(p, length); return (1); +#ifdef INET6 + case ETHERTYPE_IPV6: + ip6_print(p, length); + return (1); +#endif /*INET6*/ + case ETHERTYPE_ARP: case ETHERTYPE_REVARP: arp_print(p, length, caplen); diff --git a/usr.sbin/tcpdump/print-fddi.c b/usr.sbin/tcpdump/print-fddi.c index eadc798d802..fdcca5906f2 100644 --- a/usr.sbin/tcpdump/print-fddi.c +++ b/usr.sbin/tcpdump/print-fddi.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-fddi.c,v 1.9 2000/03/07 16:50:42 chris Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-fddi.c,v 1.10 2000/04/26 21:35:40 jakob Exp $ (LBL)"; #endif #ifdef HAVE_FDDI @@ -45,7 +45,6 @@ struct rtentry; #include <ctype.h> #include <netdb.h> #include <pcap.h> -#include <signal.h> #include <stdio.h> #include <string.h> diff --git a/usr.sbin/tcpdump/print-frag6.c b/usr.sbin/tcpdump/print-frag6.c new file mode 100644 index 00000000000..df7e61299b1 --- /dev/null +++ b/usr.sbin/tcpdump/print-frag6.c @@ -0,0 +1,102 @@ +/* $OpenBSD: print-frag6.c,v 1.1 2000/04/26 21:35:40 jakob Exp $ */ + +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994 + * 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 lint +static const char rcsid[] = + "@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)"; +#endif + +#ifdef INET6 + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_icmp.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> + +#include <stdio.h> + +#include <netinet/ip6.h> + +#include "interface.h" +#include "addrtoname.h" + +int +frag6_print(register const u_char *bp, register const u_char *bp2) +{ + register const struct ip6_frag *dp; + register const struct ip6_hdr *ip6; + register const u_char *ep; + +#if 0 +#define TCHECK(var) if ((u_char *)&(var) >= ep - sizeof(var)) goto trunc +#endif + + dp = (struct ip6_frag *)bp; + ip6 = (struct ip6_hdr *)bp2; + + /* 'ep' points to the end of avaible data. */ + ep = snapend; + + TCHECK(dp->ip6f_offlg); + + if (vflag) { + printf("frag (0x%08x:%d|%ld)", + ntohl(dp->ip6f_ident), + ntohs(dp->ip6f_offlg & IP6F_OFF_MASK), + sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen) - + (long)(bp - bp2) - sizeof(struct ip6_frag)); + } else { + printf("frag (%d|%ld)", + ntohs(dp->ip6f_offlg & IP6F_OFF_MASK), + sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen) - + (long)(bp - bp2) - sizeof(struct ip6_frag)); + } + +#if 0 + /* it is meaningless to decode non-first fragment */ + if (ntohs(dp->ip6f_offlg & IP6F_OFF_MASK) != 0) + return 65535; + else +#endif + { + fputs(" ", stdout); + return sizeof(struct ip6_frag); + } +trunc: + fputs("[|frag]", stdout); + return 65535; +#undef TCHECK +} +#endif /* INET6 */ diff --git a/usr.sbin/tcpdump/print-icmp6.c b/usr.sbin/tcpdump/print-icmp6.c new file mode 100644 index 00000000000..f60cb846179 --- /dev/null +++ b/usr.sbin/tcpdump/print-icmp6.c @@ -0,0 +1,572 @@ +/* $OpenBSD: print-icmp6.c,v 1.1 2000/04/26 21:35:40 jakob Exp $ */ + +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994 + * 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 lint +static const char rcsid[] = + "@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)"; +#endif + +#ifdef INET6 + +#include <ctype.h> + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_icmp.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> + +#include <arpa/inet.h> + +#include <stdio.h> + +#include <netinet/ip6.h> +#include <netinet/icmp6.h> + +#include "interface.h" +#include "addrtoname.h" + +void icmp6_opt_print(const u_char *, int); +void mld6_print(const u_char *); + +void +icmp6_print(register const u_char *bp, register const u_char *bp2) +{ + register const struct icmp6_hdr *dp; + register const struct ip6_hdr *ip; + register const char *str; + register const struct ip6_hdr *oip; + register const struct udphdr *ouh; + register int hlen, dport; + register const u_char *ep; + char buf[256]; + int icmp6len; + +#if 0 +#define TCHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) goto trunc +#endif + + dp = (struct icmp6_hdr *)bp; + ip = (struct ip6_hdr *)bp2; + oip = (struct ip6_hdr *)(dp + 1); + str = buf; + /* 'ep' points to the end of avaible data. */ + ep = snapend; + if (ip->ip6_plen) + icmp6len = (ntohs(ip->ip6_plen) + sizeof(struct ip6_hdr) - + (bp - bp2)); + else /* XXX: jumbo payload case... */ + icmp6len = snapend - bp; + +#if 0 + (void)printf("%s > %s: ", + ip6addr_string(&ip->ip6_src), + ip6addr_string(&ip->ip6_dst)); +#endif + + TCHECK(dp->icmp6_code); + switch (dp->icmp6_type) { + case ICMP6_DST_UNREACH: + TCHECK(oip->ip6_dst); + switch (dp->icmp6_code) { + case ICMP6_DST_UNREACH_NOROUTE: + printf("icmp6: %s unreachable route", + ip6addr_string(&oip->ip6_dst)); + break; + case ICMP6_DST_UNREACH_ADMIN: + printf("icmp6: %s unreachable prohibited", + ip6addr_string(&oip->ip6_dst)); + break; +#ifdef ICMP6_DST_UNREACH_BEYONDSCOPE + case ICMP6_DST_UNREACH_BEYONDSCOPE: +#else + case ICMP6_DST_UNREACH_NOTNEIGHBOR: +#endif + printf("icmp6: %s beyond scope of source address %s", + ip6addr_string(&oip->ip6_dst), + ip6addr_string(&oip->ip6_src)); + break; + case ICMP6_DST_UNREACH_ADDR: + printf("icmp6: %s unreachable address", + ip6addr_string(&oip->ip6_dst)); + break; + case ICMP6_DST_UNREACH_NOPORT: + TCHECK(oip->ip6_nxt); + hlen = sizeof(struct ip6_hdr); + ouh = (struct udphdr *)(((u_char *)oip) + hlen); + dport = ntohs(ouh->uh_dport); + switch (oip->ip6_nxt) { + case IPPROTO_TCP: + printf("icmp6: %s tcp port %s unreachable", + ip6addr_string(&oip->ip6_dst), + tcpport_string(dport)); + break; + case IPPROTO_UDP: + printf("icmp6: %s udp port %s unreachable", + ip6addr_string(&oip->ip6_dst), + udpport_string(dport)); + break; + default: + printf("icmp6: %s protocol %d port %d unreachable", + ip6addr_string(&oip->ip6_dst), + oip->ip6_nxt, dport); + break; + } + break; + default: + printf("icmp6: %s unreachable code-#%d", + ip6addr_string(&oip->ip6_dst), + dp->icmp6_code); + break; + } + break; + case ICMP6_PACKET_TOO_BIG: + TCHECK(dp->icmp6_mtu); + printf("icmp6: too big %u\n", (u_int32_t)ntohl(dp->icmp6_mtu)); + break; + case ICMP6_TIME_EXCEEDED: + TCHECK(oip->ip6_dst); + switch (dp->icmp6_code) { + case ICMP6_TIME_EXCEED_TRANSIT: + printf("icmp6: time exceeded in-transit for %s", + ip6addr_string(&oip->ip6_dst)); + break; + case ICMP6_TIME_EXCEED_REASSEMBLY: + printf("icmp6: ip6 reassembly time exceeded"); + break; + default: + printf("icmp6: time exceeded code-#%d", + dp->icmp6_code); + break; + } + break; + case ICMP6_PARAM_PROB: + TCHECK(oip->ip6_dst); + switch (dp->icmp6_code) { + case ICMP6_PARAMPROB_HEADER: + printf("icmp6: parameter problem errorneous - octet %u\n", + (u_int32_t)ntohl(dp->icmp6_pptr)); + break; + case ICMP6_PARAMPROB_NEXTHEADER: + printf("icmp6: parameter problem next header - octet %u\n", + (u_int32_t)ntohl(dp->icmp6_pptr)); + break; + case ICMP6_PARAMPROB_OPTION: + printf("icmp6: parameter problem option - octet %u\n", + (u_int32_t)ntohl(dp->icmp6_pptr)); + break; + default: + printf("icmp6: parameter problem code-#%d", + dp->icmp6_code); + break; + } + break; + case ICMP6_ECHO_REQUEST: + printf("icmp6: echo request"); + break; + case ICMP6_ECHO_REPLY: + printf("icmp6: echo reply"); + break; + case ICMP6_MEMBERSHIP_QUERY: + printf("icmp6: multicast listener query "); + mld6_print((const u_char *)dp); + break; + case ICMP6_MEMBERSHIP_REPORT: + printf("icmp6: multicast listener report "); + mld6_print((const u_char *)dp); + break; + case ICMP6_MEMBERSHIP_REDUCTION: + printf("icmp6: multicast listener done "); + mld6_print((const u_char *)dp); + break; + case ND_ROUTER_SOLICIT: + printf("icmp6: router solicitation "); + if (vflag) { +#define RTSOLLEN 8 + icmp6_opt_print((const u_char *)dp + RTSOLLEN, + icmp6len - RTSOLLEN); + } + break; + case ND_ROUTER_ADVERT: + printf("icmp6: router advertisement"); + if (vflag) { + struct nd_router_advert *p; + + p = (struct nd_router_advert *)dp; + TCHECK(p->nd_ra_retransmit); + printf("(chlim=%d, ", (int)p->nd_ra_curhoplimit); + if (p->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) + printf("M"); + if (p->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) + printf("O"); + if (p->nd_ra_flags_reserved != 0) + printf(" "); + printf("router_ltime=%d, ", ntohs(p->nd_ra_router_lifetime)); + printf("reachable_time=%u, ", + (u_int32_t)ntohl(p->nd_ra_reachable)); + printf("retrans_time=%u)", + (u_int32_t)ntohl(p->nd_ra_retransmit)); +#define RTADVLEN 16 + icmp6_opt_print((const u_char *)dp + RTADVLEN, + icmp6len - RTADVLEN); + } + break; + case ND_NEIGHBOR_SOLICIT: + { + struct nd_neighbor_solicit *p; + p = (struct nd_neighbor_solicit *)dp; + TCHECK(p->nd_ns_target); + printf("icmp6: neighbor sol: who has %s", + ip6addr_string(&p->nd_ns_target)); + if (vflag) { +#define NDSOLLEN 24 + icmp6_opt_print((const u_char *)dp + NDSOLLEN, + icmp6len - NDSOLLEN); + } + } + break; + case ND_NEIGHBOR_ADVERT: + { + struct nd_neighbor_advert *p; + + p = (struct nd_neighbor_advert *)dp; + TCHECK(p->nd_na_target); + printf("icmp6: neighbor adv: tgt is %s", + ip6addr_string(&p->nd_na_target)); + if (vflag) { +#define ND_NA_FLAG_ALL \ + (ND_NA_FLAG_ROUTER|ND_NA_FLAG_SOLICITED|ND_NA_FLAG_OVERRIDE) + /* we don't need ntohl() here. see advanced-api-04. */ + if (p->nd_na_flags_reserved & ND_NA_FLAG_ALL) { +#undef ND_NA_FLAG_ALL + u_int32_t flags; + + flags = p->nd_na_flags_reserved; + printf("("); + if (flags & ND_NA_FLAG_ROUTER) + printf("R"); + if (flags & ND_NA_FLAG_SOLICITED) + printf("S"); + if (flags & ND_NA_FLAG_OVERRIDE) + printf("O"); + printf(")"); + } +#define NDADVLEN 24 + icmp6_opt_print((const u_char *)dp + NDADVLEN, + icmp6len - NDADVLEN); + } + } + break; + case ND_REDIRECT: + { +#define RDR(i) ((struct nd_redirect *)(i)) + char tgtbuf[INET6_ADDRSTRLEN], dstbuf[INET6_ADDRSTRLEN]; + + TCHECK(RDR(dp)->nd_rd_dst); + inet_ntop(AF_INET6, &RDR(dp)->nd_rd_target, + tgtbuf, INET6_ADDRSTRLEN); + inet_ntop(AF_INET6, &RDR(dp)->nd_rd_dst, + dstbuf, INET6_ADDRSTRLEN); + printf("icmp6: redirect %s to %s", dstbuf, tgtbuf); +#define REDIRECTLEN 40 + if (vflag) { + icmp6_opt_print((const u_char *)dp + REDIRECTLEN, + icmp6len - REDIRECTLEN); + } + break; + } + case ICMP6_ROUTER_RENUMBERING: + switch (dp->icmp6_code) { + case ICMP6_ROUTER_RENUMBERING_COMMAND: + printf("icmp6: router renum command"); + break; + case ICMP6_ROUTER_RENUMBERING_RESULT: + printf("icmp6: router renum result"); + break; + default: + printf("icmp6: router renum code-#%d", dp->icmp6_code); + break; + } + break; +#ifdef ICMP6_WRUREQUEST + case ICMP6_WRUREQUEST: /*ICMP6_FQDN_QUERY*/ + { + int siz; + siz = ep - (u_char *)(dp + 1); + if (siz == 4) + printf("icmp6: who-are-you request"); + else { + printf("icmp6: FQDN request"); + if (vflag) { + if (siz < 8) + printf("?(icmp6_data %d bytes)", siz); + else if (8 < siz) + printf("?(extra %d bytes)", siz - 8); + } + } + break; + } +#endif /*ICMP6_WRUREQUEST*/ +#ifdef ICMP6_WRUREPLY + case ICMP6_WRUREPLY: /*ICMP6_FQDN_REPLY*/ + { + enum { UNKNOWN, WRU, FQDN } mode = UNKNOWN; + u_char const *buf; + u_char const *cp = NULL; + + buf = (u_char *)(dp + 1); + + /* fair guess */ + if (buf[12] == ep - buf - 13) + mode = FQDN; + else if (dp->icmp6_code == 1) + mode = FQDN; + + /* wild guess */ + if (mode == UNKNOWN) { + cp = buf + 4; + while (cp < ep) { + if (!isprint(*cp++)) + mode = FQDN; + } + } +#ifndef abs +#define abs(a) ((0 < (a)) ? (a) : -(a)) +#endif + if (mode == UNKNOWN && 2 < abs(buf[12] - (ep - buf - 13))) + mode = WRU; + if (mode == UNKNOWN) + mode = FQDN; + + if (mode == WRU) { + cp = buf + 4; + printf("icmp6: who-are-you reply(\""); + } else if (mode == FQDN) { + cp = buf + 13; + printf("icmp6: FQDN reply(\""); + } + for (; cp < ep; cp++) + printf((isprint(*cp) ? "%c" : "\\%03o"), *cp); + printf("\""); + if (vflag) { + printf(",%s", mode == FQDN ? "FQDN" : "WRU"); + if (mode == FQDN) { + long ttl; + ttl = (long)ntohl(*(u_long *)&buf[8]); + if (dp->icmp6_code == 1) + printf(",TTL=unknown"); + else if (ttl < 0) + printf(",TTL=%ld:invalid", ttl); + else + printf(",TTL=%ld", ttl); + if (buf[12] != ep - buf - 13) { + (void)printf(",invalid namelen:%d/%u", + buf[12], + (unsigned int)(ep - buf - 13)); + } + } + } + printf(")"); + break; + } +#endif /*ICMP6_WRUREPLY*/ + default: + printf("icmp6: type-#%d", dp->icmp6_type); + break; + } + return; +trunc: + fputs("[|icmp6]", stdout); +#if 0 +#undef TCHECK +#endif +} + +void +icmp6_opt_print(register const u_char *bp, int resid) +{ + register const struct nd_opt_hdr *op; + register const struct nd_opt_hdr *opl; /* why there's no struct? */ + register const struct nd_opt_prefix_info *opp; + register const struct icmp6_opts_redirect *opr; + register const struct nd_opt_mtu *opm; + register const u_char *ep; + int opts_len; +#if 0 + register const struct ip6_hdr *ip; + register const char *str; + register const struct ip6_hdr *oip; + register const struct udphdr *ouh; + register int hlen, dport; + char buf[256]; +#endif + +#if 0 +#define TCHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) goto trunc +#endif +#define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return + + op = (struct nd_opt_hdr *)bp; +#if 0 + ip = (struct ip6_hdr *)bp2; + oip = &dp->icmp6_ip6; + str = buf; +#endif + /* 'ep' points to the end of avaible data. */ + ep = snapend; + + ECHECK(op->nd_opt_len); + if (resid <= 0) + return; + switch (op->nd_opt_type) { + case ND_OPT_SOURCE_LINKADDR: + opl = (struct nd_opt_hdr *)op; +#if 1 + if ((u_char *)opl + (opl->nd_opt_len << 3) > ep) + goto trunc; +#else + TCHECK((u_char *)opl + (opl->nd_opt_len << 3) - 1); +#endif + printf("(src lladdr: %s", + etheraddr_string((u_char *)(opl + 1))); + if (opl->nd_opt_len != 1) + printf("!"); + printf(")"); + icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3), + resid - (op->nd_opt_len << 3)); + break; + case ND_OPT_TARGET_LINKADDR: + opl = (struct nd_opt_hdr *)op; +#if 1 + if ((u_char *)opl + (opl->nd_opt_len << 3) > ep) + goto trunc; +#else + TCHECK((u_char *)opl + (opl->nd_opt_len << 3) - 1); +#endif + printf("(tgt lladdr: %s", + etheraddr_string((u_char *)(opl + 1))); + if (opl->nd_opt_len != 1) + printf("!"); + printf(")"); + icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3), + resid - (op->nd_opt_len << 3)); + break; + case ND_OPT_PREFIX_INFORMATION: + opp = (struct nd_opt_prefix_info *)op; + TCHECK(opp->nd_opt_pi_prefix); + printf("(prefix info: "); + if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK) + printf("L"); + if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO) + printf("A"); + if (opp->nd_opt_pi_flags_reserved) + printf(" "); + printf("valid_ltime="); + if ((u_int32_t)ntohl(opp->nd_opt_pi_valid_time) == ~0U) + printf("infinity"); + else { + printf("%u", (u_int32_t)ntohl(opp->nd_opt_pi_valid_time)); + } + printf(", "); + printf("preffered_ltime="); + if ((u_int32_t)ntohl(opp->nd_opt_pi_preferred_time) == ~0U) + printf("infinity"); + else { + printf("%u", (u_int32_t)ntohl(opp->nd_opt_pi_preferred_time)); + } + printf(", "); + printf("prefix=%s/%d", ip6addr_string(&opp->nd_opt_pi_prefix), + opp->nd_opt_pi_prefix_len); + if (opp->nd_opt_pi_len != 4) + printf("!"); + printf(")"); + icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3), + resid - (op->nd_opt_len << 3)); + break; + case ND_OPT_REDIRECTED_HEADER: + opr = (struct icmp6_opts_redirect *)op; + printf("(redirect)"); + /* xxx */ + icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3), + resid - (op->nd_opt_len << 3)); + break; + case ND_OPT_MTU: + opm = (struct nd_opt_mtu *)op; + TCHECK(opm->nd_opt_mtu_mtu); + printf("(mtu: "); + printf("mtu=%u", (u_int32_t)ntohl(opm->nd_opt_mtu_mtu)); + if (opm->nd_opt_mtu_len != 1) + printf("!"); + printf(")"); + icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3), + resid - (op->nd_opt_len << 3)); + break; + default: + opts_len = op->nd_opt_len; + printf("(unknwon opt_type=%d, opt_len=%d)", + op->nd_opt_type, opts_len); + if (opts_len == 0) + opts_len = 1; /* XXX */ + icmp6_opt_print((const u_char *)op + (opts_len << 3), + resid - (opts_len << 3)); + break; + } + return; + trunc: + fputs("[ndp opt]", stdout); + return; +#if 0 +#undef TCHECK +#endif +#undef ECHECK +} + +void +mld6_print(register const u_char *bp) +{ + register struct mld6_hdr *mp = (struct mld6_hdr *)bp; + register const u_char *ep; + + /* 'ep' points to the end of avaible data. */ + ep = snapend; + + if ((u_char *)mp + sizeof(*mp) > ep) + return; + + printf("max resp delay: %d ", ntohs(mp->mld6_maxdelay)); + printf("addr: %s", ip6addr_string(&mp->mld6_addr)); + + return; +} +#endif /* INET6 */ diff --git a/usr.sbin/tcpdump/print-ip.c b/usr.sbin/tcpdump/print-ip.c index f7fa0f230b9..6df450b4119 100644 --- a/usr.sbin/tcpdump/print-ip.c +++ b/usr.sbin/tcpdump/print-ip.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ip.c,v 1.9 2000/01/16 11:20:14 jakob Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ip.c,v 1.10 2000/04/26 21:35:40 jakob Exp $ (LBL)"; #endif #include <sys/param.h> @@ -456,6 +456,24 @@ ip_print(register const u_char *bp, register u_int length) } break; +#ifdef INET6 +#ifndef IP6PROTO_ENCAP +#define IP6PROTO_ENCAP 41 +#endif + case IP6PROTO_ENCAP: + /* ip6-in-ip encapsulation */ + if (vflag) + (void)printf("%s > %s: ", + ipaddr_string(&ip->ip_src), + ipaddr_string(&ip->ip_dst)); + ip6_print(cp, len); + if (! vflag) { + printf(" (encap)"); + return; + } + break; +#endif /*INET6*/ + #ifndef IPPROTO_GRE #define IPPROTO_GRE 47 #endif diff --git a/usr.sbin/tcpdump/print-ip6.c b/usr.sbin/tcpdump/print-ip6.c new file mode 100644 index 00000000000..83affc87c75 --- /dev/null +++ b/usr.sbin/tcpdump/print-ip6.c @@ -0,0 +1,201 @@ +/* $OpenBSD: print-ip6.c,v 1.1 2000/04/26 21:35:41 jakob Exp $ */ + +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 + * 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 lint +static const char rcsid[] = + "@(#) /master/usr.sbin/tcpdump/tcpdump/print-ip.c,v 2.1 1995/02/03 18:14:45 polk Exp (LBL)"; +#endif + +#ifdef INET6 + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> + +#include <stdio.h> +#ifdef __STDC__ +#include <stdlib.h> +#endif +#include <unistd.h> + +#include "interface.h" +#include "addrtoname.h" + +#include <netinet/ip6.h> + +/* + * print an IP6 datagram. + */ +void +ip6_print(register const u_char *bp, register int length) +{ + register const struct ip6_hdr *ip6; + register int hlen; + register int len; + register const u_char *cp; + int nh; + u_int flow; + + ip6 = (const struct ip6_hdr *)bp; + +#ifdef TCPDUMP_ALIGN + /* + * The IP header is not word aligned, so copy into abuf. + * This will never happen with BPF. It does happen raw packet + * dumps from -r. + */ + if ((int)ip & (sizeof(long)-1)) { + static u_char *abuf; + + if (abuf == 0) + abuf = (u_char *)malloc(snaplen); + bcopy((char *)ip, (char *)abuf, min(length, snaplen)); + snapend += abuf - (u_char *)ip; + packetp = abuf; + ip = (struct ip6_hdr *)abuf; + } +#endif + if ((u_char *)(ip6 + 1) > snapend) { + printf("[|ip6]"); + return; + } + if (length < sizeof (struct ip6_hdr)) { + (void)printf("truncated-ip6 %d", length); + return; + } + hlen = sizeof(struct ip6_hdr); + + len = ntohs(ip6->ip6_plen); + if (length < len + hlen) + (void)printf("truncated-ip6 - %d bytes missing!", + len + hlen - length); + + cp = (const u_char *)ip6; + nh = ip6->ip6_nxt; + while (cp < snapend) { + cp += hlen; + + if (cp == (u_char *)(ip6 + 1) + && nh != IPPROTO_TCP && nh != IPPROTO_UDP) { + (void)printf("%s > %s: ", ip6addr_string(&ip6->ip6_src), + ip6addr_string(&ip6->ip6_dst)); + } + + switch (nh) { + case IPPROTO_HOPOPTS: + hlen = hbhopt_print(cp); + nh = *cp; + break; + case IPPROTO_DSTOPTS: + hlen = dstopt_print(cp); + nh = *cp; + break; + case IPPROTO_FRAGMENT: + hlen = frag6_print(cp, (const u_char *)ip6); + if (snapend <= cp + hlen) + goto end; + nh = *cp; + break; + case IPPROTO_ROUTING: + hlen = rt6_print(cp, (const u_char *)ip6); + nh = *cp; + break; + case IPPROTO_TCP: + tcp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp), + (const u_char *)ip6); + goto end; + case IPPROTO_UDP: + udp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp), + (const u_char *)ip6); + goto end; + case IPPROTO_ICMPV6: + icmp6_print(cp, (const u_char *)ip6); + goto end; + case IPPROTO_PIM: + (void)printf("PIM"); + pim_print(cp, len); + goto end; +#ifndef IPPROTO_OSPF +#define IPPROTO_OSPF 89 +#endif + case IPPROTO_OSPF: + ospf6_print(cp, len); + goto end; + case IPPROTO_IPV6: + ip6_print(cp, len); + goto end; +#ifndef IPPROTO_IPV4 +#define IPPROTO_IPV4 4 +#endif + case IPPROTO_IPV4: + ip_print(cp, len); + goto end; + case IPPROTO_NONE: + (void)printf("no next header"); + goto end; + + default: + (void)printf("ip-proto-%d %d", ip6->ip6_nxt, len); + goto end; + } + } + + end: + + flow = ntohl(ip6->ip6_flow); +#if 0 + /* rfc1883 */ + if (flow & 0x0f000000) + (void)printf(" [pri 0x%x]", (flow & 0x0f000000) >> 24); + if (flow & 0x00ffffff) + (void)printf(" [flowlabel 0x%x]", flow & 0x00ffffff); +#else + /* RFC 2460 */ + if (flow & 0x0ff00000) + (void)printf(" [class 0x%x]", (flow & 0x0ff00000) >> 20); + if (flow & 0x000fffff) + (void)printf(" [flowlabel 0x%x]", flow & 0x000fffff); +#endif + + if (ip6->ip6_hlim <= 1) + (void)printf(" [hlim %d]", (int)ip6->ip6_hlim); + + if (vflag) { + printf(" ("); + (void)printf("len %d", len); + if (ip6->ip6_hlim > 1) + (void)printf(", hlim %d", (int)ip6->ip6_hlim); + printf(")"); + } +} + +#endif /* INET6 */ diff --git a/usr.sbin/tcpdump/print-ip6opts.c b/usr.sbin/tcpdump/print-ip6opts.c new file mode 100644 index 00000000000..bb28cb784a7 --- /dev/null +++ b/usr.sbin/tcpdump/print-ip6opts.c @@ -0,0 +1,155 @@ +/* $OpenBSD: print-ip6opts.c,v 1.1 2000/04/26 21:35:41 jakob Exp $ */ + +/* + * Copyright (C) 1998 WIDE Project. + * 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. + * 3. Neither the name of the project 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 PROJECT 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 PROJECT 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. + */ + +#ifdef INET6 +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <netinet/in.h> +#include <netinet/ip6.h> + +#include <stdio.h> + +#include "interface.h" +#include "addrtoname.h" + +void +ip6_opt_print(const u_char *bp, int len) +{ + int i; + int optlen; + + for (i = 0; i < len; i += optlen) { + switch (bp[i]) { + case IP6OPT_PAD1: + optlen = 1; + break; + case IP6OPT_PADN: + if (len - i < IP6OPT_MINLEN) { + printf("(padn: trunc)"); + goto trunc; + } + optlen = bp[i + 1] + 2; + break; + case IP6OPT_RTALERT: + if (len - i < IP6OPT_RTALERT_LEN) { + printf("(rtalert: trunc)"); + goto trunc; + } + if (bp[i + 1] != IP6OPT_RTALERT_LEN - 2) { + printf("(rtalert: invalid len %d)", bp[i + 1]); + goto trunc; + } + printf("(rtalert: 0x%04x) ", ntohs(*(u_short *)&bp[i + 2])); + optlen = IP6OPT_RTALERT_LEN; + break; + case IP6OPT_JUMBO: + if (len - i < IP6OPT_JUMBO_LEN) { + printf("(jumbo: trunc)"); + goto trunc; + } + if (bp[i + 1] != IP6OPT_JUMBO_LEN - 2) { + printf("(jumbo: invalid len %d)", bp[i + 1]); + goto trunc; + } + printf("(jumbo: %u) ", (u_int32_t)ntohl(*(u_int *)&bp[i + 2])); + optlen = IP6OPT_JUMBO_LEN; + break; + default: + if (len - i < IP6OPT_MINLEN) { + printf("(type %d: trunc)", bp[i]); + goto trunc; + } + printf("(type 0x%02x: len=%d) ", bp[i], bp[i + 1]); + optlen = bp[i + 1] + 2; + break; + } + } + +#if 0 +end: +#endif + return; + +trunc: + printf("[trunc] "); +} + +int +hbhopt_print(register const u_char *bp) +{ + const struct ip6_hbh *dp = (struct ip6_hbh *)bp; + register const u_char *ep; + int hbhlen = 0; + + /* 'ep' points to the end of avaible data. */ + ep = snapend; + TCHECK(dp->ip6h_len); + hbhlen = (int)((dp->ip6h_len + 1) << 3); + TCHECK2(dp, hbhlen); + printf("HBH "); + if (vflag) + ip6_opt_print((const u_char *)dp + sizeof(*dp), hbhlen - sizeof(*dp)); + + return(hbhlen); + + trunc: + fputs("[|HBH]", stdout); + return(hbhlen); +} + +int +dstopt_print(register const u_char *bp) +{ + const struct ip6_dest *dp = (struct ip6_dest *)bp; + register const u_char *ep; + int dstoptlen = 0; + + /* 'ep' points to the end of avaible data. */ + ep = snapend; + TCHECK(dp->ip6d_len); + dstoptlen = (int)((dp->ip6d_len + 1) << 3); + TCHECK2(dp, dstoptlen); + printf("DSTOPT "); + if (vflag) { + ip6_opt_print((const u_char *)dp + sizeof(*dp), + dstoptlen - sizeof(*dp)); + } + + return(dstoptlen); + + trunc: + fputs("[|DSTOPT]", stdout); + return(dstoptlen); +} +#endif /* INET6 */ diff --git a/usr.sbin/tcpdump/print-ipsec.c b/usr.sbin/tcpdump/print-ipsec.c index eacb24c4a60..474e234ef44 100644 --- a/usr.sbin/tcpdump/print-ipsec.c +++ b/usr.sbin/tcpdump/print-ipsec.c @@ -26,7 +26,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ipsec.c,v 1.3 1999/10/29 09:44:07 ho Exp $ (XXX)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ipsec.c,v 1.4 2000/04/26 21:35:41 jakob Exp $ (XXX)"; #endif #include <sys/param.h> @@ -42,9 +42,6 @@ static const char rcsid[] = #include <netinet/tcp.h> #include <netinet/tcpip.h> -#ifdef HAVE_MALLOC_H -#include <malloc.h> -#endif #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/usr.sbin/tcpdump/print-ipx.c b/usr.sbin/tcpdump/print-ipx.c index ff1eca43e19..82a00dd12b6 100644 --- a/usr.sbin/tcpdump/print-ipx.c +++ b/usr.sbin/tcpdump/print-ipx.c @@ -24,7 +24,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ipx.c,v 1.5 1996/12/12 16:22:35 bitblt Exp $"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ipx.c,v 1.6 2000/04/26 21:35:41 jakob Exp $"; #endif #include <sys/param.h> @@ -38,7 +38,6 @@ static const char rcsid[] = #include <netinet/udp.h> #include <netinet/udp_var.h> #include <netinet/tcp.h> -#include <netinet/tcpip.h> #ifdef __STDC__ #include <stdlib.h> diff --git a/usr.sbin/tcpdump/print-isoclns.c b/usr.sbin/tcpdump/print-isoclns.c index 1347db5bc0a..5713b806d40 100644 --- a/usr.sbin/tcpdump/print-isoclns.c +++ b/usr.sbin/tcpdump/print-isoclns.c @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-isoclns.c,v 1.7 1999/07/28 20:41:36 jakob Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-isoclns.c,v 1.8 2000/04/26 21:35:41 jakob Exp $ (LBL)"; #endif #include <sys/types.h> @@ -160,7 +160,7 @@ esis_print(const u_char *p, u_int length) printf(" bad pkt!"); else { printf(" too short for esis header %d:", li); - while (--length >= 0) + while (--length != 0) printf("%02X", *p++); } return; @@ -220,11 +220,27 @@ esis_print(const u_char *p, u_int length) li = ep - p; break; } -#if 0 - case ESIS_ESH: - printf(" esh"); + case ESIS_ESH: { + const u_char *nsap; + int i, nnsaps; + + nnsaps = *p++; + + /* print NSAPs */ + for (i = 0; i < nnsaps; i++) { + nsap = p; + p += *p + 1; + if (p > ep) { + printf(" [bad li]"); + return; + } + if (p > snapend) + return; + printf(" nsap %s", isonsap_string(nsap)); + } + li = ep - p; break; -#endif + } case ESIS_ISH: { const u_char *is; @@ -235,7 +251,7 @@ esis_print(const u_char *p, u_int length) } if (p > snapend) return; - printf(" %s", isonsap_string(is)); + printf(" net %s", isonsap_string(is)); li = ep - p; break; } @@ -286,32 +302,34 @@ static int osi_cksum(register const u_char *p, register u_int len, const u_char *toff, u_char *cksum, u_char *off) { - int x, y, f = (len - ((toff - p) + 1)); - int32_t c0 = 0, c1 = 0; + const u_char *ep; + int c0, c1; + int n; if ((cksum[0] = off[0]) == 0 && (cksum[1] = off[1]) == 0) return 0; - off[0] = off[1] = 0; - while ((int)--len >= 0) { - c0 += *p++; + n = toff - p + 1; + c0 = c1 = 0; + ep = p + len; + for (; p < toff; p++) { + c0 = (c0 + *p); c1 += c0; - c0 %= 255; - c1 %= 255; } - x = (c0 * f - c1); - if (x < 0) - x = 255 - (-x % 255); - else - x %= 255; - y = -1 * (x + c0); - if (y < 0) - y = 255 - (-y % 255); - else - y %= 255; - - off[0] = x; - off[1] = y; + + /* skip cksum bytes */ + p += 2; + c1 += c0; c1 += c0; + + for (; p < ep; p++) { + c0 = (c0 + *p); + c1 += c0; + } + + c1 = (((c0 * (len - n)) - c1) % 255); + cksum[0] = (u_char) ((c1 < 0) ? c1 + 255 : c1); + c1 = (-(int) (c1 + c0)) % 255; + cksum[1] = (u_char) (c1 < 0 ? c1 + 255 : c1); return (off[0] != cksum[0] || off[1] != cksum[1]); } diff --git a/usr.sbin/tcpdump/print-krb.c b/usr.sbin/tcpdump/print-krb.c index 8afa301aef4..63a551aabf7 100644 --- a/usr.sbin/tcpdump/print-krb.c +++ b/usr.sbin/tcpdump/print-krb.c @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-krb.c,v 1.4 1999/09/16 18:03:14 brad Exp $"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-krb.c,v 1.5 2000/04/26 21:35:41 jakob Exp $"; #endif #include <sys/param.h> @@ -206,14 +206,14 @@ krb4_print(const u_char *cp) case AUTH_MSG_KDC_REQUEST: if ((cp = krb4_print_hdr(cp)) == NULL) return; - cp += 4; /* ctime */ - TCHECK2(cp, 0); - printf(" %dmin ", *cp++ * 5); - TCHECK2(cp, 0); - PRINT; - TCHECK2(cp, 0); - putchar('.'); PRINT; - break; + cp += 4; /* ctime */ + TCHECK2(cp, 0); + printf(" %dmin ", *cp++ * 5); + TCHECK2(cp, 0); + PRINT; + TCHECK2(cp, 0); + putchar('.'); PRINT; + break; case AUTH_MSG_APPL_REQUEST: cp += 2; diff --git a/usr.sbin/tcpdump/print-netbios.c b/usr.sbin/tcpdump/print-netbios.c index ec7f219e1bc..b94e6e99f28 100644 --- a/usr.sbin/tcpdump/print-netbios.c +++ b/usr.sbin/tcpdump/print-netbios.c @@ -24,7 +24,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-netbios.c,v 1.2 1996/12/12 16:22:32 bitblt Exp $"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-netbios.c,v 1.3 2000/04/26 21:35:41 jakob Exp $"; #endif #include <sys/param.h> @@ -37,7 +37,6 @@ static const char rcsid[] = #include <netinet/udp.h> #include <netinet/udp_var.h> #include <netinet/tcp.h> -#include <netinet/tcpip.h> #ifdef __STDC__ #include <stdlib.h> diff --git a/usr.sbin/tcpdump/print-null.c b/usr.sbin/tcpdump/print-null.c index 6a6ca9cb4e9..bba644129e8 100644 --- a/usr.sbin/tcpdump/print-null.c +++ b/usr.sbin/tcpdump/print-null.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-null.c,v 1.10 1999/09/16 20:58:47 brad Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-null.c,v 1.11 2000/04/26 21:35:42 jakob Exp $ (LBL)"; #endif #include <sys/param.h> @@ -44,12 +44,15 @@ struct rtentry; #include <netinet/udp.h> #include <netinet/udp_var.h> #include <netinet/tcp.h> -#include <netinet/tcpip.h> #include <pcap.h> #include <stdio.h> #include <string.h> +#ifdef INET6 +#include <netinet/ip6.h> +#endif + #include "interface.h" #include "addrtoname.h" @@ -64,8 +67,12 @@ struct rtentry; #define NULL_HDRLEN 4 static void -null_print(const u_char *p, u_int length, u_int family) +null_print(const u_char *p, const struct ip *ip, u_int length) { + u_int family; + + memcpy((char *)&family, (char *)p, sizeof(family)); + if (nflag) { /* XXX just dump the header */ return; @@ -76,6 +83,12 @@ null_print(const u_char *p, u_int length, u_int family) printf("ip: "); break; +#ifdef INET6 + case AF_INET6: + printf("ip6: "); + break; +#endif + case AF_NS: printf("ns: "); break; @@ -91,8 +104,7 @@ null_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) { u_int length = h->len; u_int caplen = h->caplen; - u_int family; - const u_char *pkt; + const struct ip *ip; ts_print(&h->ts); @@ -104,25 +116,24 @@ null_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) packetp = p; snapend = p + caplen; - pkt = p + NULL_HDRLEN; length -= NULL_HDRLEN; - memcpy((char *)&family, (char *)p, sizeof(family)); + ip = (struct ip *)(p + NULL_HDRLEN); if (eflag) - null_print(p, length, family); + null_print(p, ip, length); - switch (ntohl(family)) { - case AF_INET: - ip_print(pkt, length); - break; - case AF_APPLETALK: - atalk_print(pkt, length); - break; - } +#ifndef INET6 + ip_print((const u_char *)ip, length); +#else + if (ip->ip_v == IPVERSION) + ip_print((const u_char *)ip, length); + else if (ip->ip_v == 6) + ip6_print((const u_char *)ip, length); +#endif /*INET6*/ if (xflag) - default_print(pkt, caplen - NULL_HDRLEN); + default_print((const u_char *)ip, caplen - NULL_HDRLEN); putchar('\n'); } diff --git a/usr.sbin/tcpdump/print-ospf.c b/usr.sbin/tcpdump/print-ospf.c index 0443993dc66..26737b8edba 100644 --- a/usr.sbin/tcpdump/print-ospf.c +++ b/usr.sbin/tcpdump/print-ospf.c @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ospf.c,v 1.6 1999/07/28 20:41:36 jakob Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ospf.c,v 1.7 2000/04/26 21:35:42 jakob Exp $ (LBL)"; #endif #include <sys/param.h> @@ -507,9 +507,11 @@ ospf_print(register const u_char *bp, register u_int length, op = (struct ospfhdr *)bp; ip = (struct ip *)bp2; /* Print the source and destination address */ +#if 0 (void) printf("%s > %s:", ipaddr_string(&ip->ip_src), ipaddr_string(&ip->ip_dst)); +#endif /* XXX Before we do anything else, strip off the MD5 trailer */ TCHECK(op->ospf_authtype); diff --git a/usr.sbin/tcpdump/print-ospf6.c b/usr.sbin/tcpdump/print-ospf6.c new file mode 100644 index 00000000000..6e85c91d302 --- /dev/null +++ b/usr.sbin/tcpdump/print-ospf6.c @@ -0,0 +1,667 @@ +/* $OpenBSD: print-ospf6.c,v 1.1 2000/04/26 21:35:42 jakob Exp $ */ + + +/* + * Copyright (c) 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. + * + * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu) + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ospf6.c,v 1.1 2000/04/26 21:35:42 jakob Exp $ (LBL)"; +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> + +#include <ctype.h> +#include <stdio.h> +#include <string.h> + +#include "interface.h" +#include "addrtoname.h" + +#include "ospf6.h" + +struct bits { + u_int32_t bit; + const char *str; +}; + +static const struct bits ospf6_option_bits[] = { + { OSPF6_OPTION_V6, "V6" }, + { OSPF6_OPTION_E, "E" }, + { OSPF6_OPTION_MC, "MC" }, + { OSPF6_OPTION_N, "N" }, + { OSPF6_OPTION_R, "R" }, + { OSPF6_OPTION_DC, "DC" }, + { 0, NULL } +}; + +static const struct bits ospf6_rla_flag_bits[] = { + { RLA_FLAG_B, "B" }, + { RLA_FLAG_E, "E" }, + { RLA_FLAG_V, "V" }, + { RLA_FLAG_W, "W" }, + { 0, NULL } +}; + +static struct tok type2str[] = { + { OSPF_TYPE_UMD, "umd" }, + { OSPF_TYPE_HELLO, "hello" }, + { OSPF_TYPE_DB, "dd" }, + { OSPF_TYPE_LSR, "ls_req" }, + { OSPF_TYPE_LSU, "ls_upd" }, + { OSPF_TYPE_LSA, "ls_ack" }, + { 0, NULL } +}; + +static char tstr[] = " [|ospf]"; + +/* Forwards */ +static inline void ospf6_print_seqage(u_int32_t, time_t); +static inline void ospf6_print_bits(const struct bits *, u_char); +static void ospf6_print_ls_type(u_int, const rtrid_t *, + const rtrid_t *, const char *); +static int ospf6_print_lshdr(const struct lsa_hdr *); +static int ospf6_print_lsa(const struct lsa *); +static int ospf6_decode_v3(const struct ospf6hdr *, const u_char *); + +static inline void +ospf6_print_seqage(register u_int32_t seq, register time_t us) +{ + register time_t sec = us % 60; + register time_t mins = (us / 60) % 60; + register time_t hour = us / 3600; + + printf(" S %X age ", seq); + if (hour) + printf("%u:%02u:%02u", + (u_int32_t) hour, (u_int32_t) mins, (u_int32_t) sec); + else if (mins) + printf("%u:%02u", (u_int32_t) mins, (u_int32_t) sec); + else + printf("%u", (u_int32_t) sec); +} + + +static inline void +ospf6_print_bits(register const struct bits *bp, register u_char options) +{ + register char sep = ' '; + + do { + if (options & bp->bit) { + printf("%c%s", sep, bp->str); + sep = '/'; + } + } while ((++bp)->bit); +} + +static void +ospf6_print_ls_type(register u_int ls_type, + register const rtrid_t *ls_stateid, + register const rtrid_t *ls_router, register const char *fmt) +{ + char *scope; + + switch (ls_type & LS_SCOPE_MASK) { + case LS_SCOPE_LINKLOCAL: + scope = "linklocal-"; + break; + case LS_SCOPE_AREA: + scope = "area-"; + break; + case LS_SCOPE_AS: + scope = "AS-"; + break; + default: + scope = ""; + break; + } + + switch (ls_type & LS_TYPE_MASK) { + case LS_TYPE_ROUTER: + printf(" %srtr %s", scope, ipaddr_string(ls_router)); + break; + + case LS_TYPE_NETWORK: + printf(" %snet dr %s if %s", scope, + ipaddr_string(ls_router), + ipaddr_string(ls_stateid)); + break; + + case LS_TYPE_INTER_AP: + printf(" %sinter-area-prefix %s abr %s", scope, + ipaddr_string(ls_stateid), + ipaddr_string(ls_router)); + break; + + case LS_TYPE_INTER_AR: + printf(" %sinter-area-router %s rtr %s", scope, + ipaddr_string(ls_router), + ipaddr_string(ls_stateid)); + break; + + case LS_TYPE_ASE: + printf(" %sase %s asbr %s", scope, + ipaddr_string(ls_stateid), + ipaddr_string(ls_router)); + break; + + case LS_TYPE_GROUP: + printf(" %sgroup %s rtr %s", scope, + ipaddr_string(ls_stateid), + ipaddr_string(ls_router)); + break; + + case LS_TYPE_TYPE7: + printf(" %stype7 %s rtr %s", scope, + ipaddr_string(ls_stateid), + ipaddr_string(ls_router)); + break; + + case LS_TYPE_LINK: + printf(" %slink %s rtr %s", scope, + ipaddr_string(ls_stateid), + ipaddr_string(ls_router)); + break; + + case LS_TYPE_INTRA_AP: + printf(" %sintra-area-prefix %s rtr %s", scope, + ipaddr_string(ls_stateid), + ipaddr_string(ls_router)); + break; + + default: + printf(" %s", scope); + printf(fmt, ls_type); + break; + } + +} + +static int +ospf6_print_lshdr(register const struct lsa_hdr *lshp) +{ + + TCHECK(lshp->ls_type); + printf(" {"); /* } (ctags) */ + + TCHECK(lshp->ls_seq); + ospf6_print_seqage(ntohl(lshp->ls_seq), ntohs(lshp->ls_age)); + ospf6_print_ls_type(ntohs(lshp->ls_type), &lshp->ls_stateid, + &lshp->ls_router, "ls_type %d"); + + return (0); +trunc: + return (1); +} + +static int +ospf6_print_lsaprefix(register const struct lsa_prefix *lsapp) +{ + int k; + struct in6_addr prefix; + + TCHECK(*lsapp); + k = (lsapp->lsa_p_len + 31) / 32; + if (k * 4 > sizeof(struct in6_addr)) { + printf("??prefixlen %d??", lsapp->lsa_p_len); + goto trunc; + } + memset(&prefix, 0, sizeof(prefix)); + memcpy(&prefix, lsapp->lsa_p_prefix, k * 4); + printf(" %s/%d", ip6addr_string(&prefix), + lsapp->lsa_p_len); + if (lsapp->lsa_p_opt) + printf("(opt=%x)", lsapp->lsa_p_opt); + return sizeof(*lsapp) - 4 + k * 4; + +trunc: + return -1; +} + + +/* + * Print a single link state advertisement. If truncated return 1, else 0. + */ +static int +ospf6_print_lsa(register const struct lsa *lsap) +{ + register const u_char *ls_end; + register const struct rlalink *rlp; +#if 0 + register const struct tos_metric *tosp; +#endif + register const rtrid_t *ap; +#if 0 + register const struct aslametric *almp; + register const struct mcla *mcp; +#endif + register const struct llsa *llsap; + register const struct lsa_prefix *lsapp; +#if 0 + register const u_int32_t *lp; +#endif + register int j, k; + + if (ospf6_print_lshdr(&lsap->ls_hdr)) + return (1); + TCHECK(lsap->ls_hdr.ls_length); + ls_end = (u_char *)lsap + ntohs(lsap->ls_hdr.ls_length); + switch (ntohs(lsap->ls_hdr.ls_type)) { + case LS_TYPE_ROUTER | LS_SCOPE_AREA: + TCHECK(lsap->lsa_un.un_rla.rla_flags); + ospf6_print_bits(ospf6_rla_flag_bits, + lsap->lsa_un.un_rla.rla_flags); + TCHECK(lsap->lsa_un.un_rla.rla_options); + ospf6_print_bits(ospf6_option_bits, + ntohl(lsap->lsa_un.un_rla.rla_options)); + + TCHECK(lsap->lsa_un.un_rla.rla_link); + rlp = lsap->lsa_un.un_rla.rla_link; + while (rlp + sizeof(*rlp) <= (struct rlalink *)ls_end) { + TCHECK(*rlp); + printf(" {"); /* } (ctags) */ + switch (rlp->link_type) { + + case RLA_TYPE_VIRTUAL: + printf(" virt"); + /* Fall through */ + + case RLA_TYPE_ROUTER: + printf(" nbrid %s nbrif %s if %s", + ipaddr_string(&rlp->link_nrtid), + ipaddr_string(&rlp->link_nifid), + ipaddr_string(&rlp->link_ifid)); + break; + + case RLA_TYPE_TRANSIT: + printf(" dr %s drif %s if %s", + ipaddr_string(&rlp->link_nrtid), + ipaddr_string(&rlp->link_nifid), + ipaddr_string(&rlp->link_ifid)); + break; + + default: + /* { (ctags) */ + printf(" ??RouterLinksType 0x%02x?? }", + rlp->link_type); + return (0); + } + printf(" metric %d", ntohs(rlp->link_metric)); + /* { (ctags) */ + printf(" }"); + rlp++; + } + break; + + case LS_TYPE_NETWORK | LS_SCOPE_AREA: + TCHECK(lsap->lsa_un.un_nla.nla_options); + ospf6_print_bits(ospf6_option_bits, + ntohl(lsap->lsa_un.un_nla.nla_options)); + printf(" rtrs"); + ap = lsap->lsa_un.un_nla.nla_router; + while ((u_char *)ap < ls_end) { + TCHECK(*ap); + printf(" %s", ipaddr_string(ap)); + ++ap; + } + break; + + case LS_TYPE_INTER_AP | LS_SCOPE_AREA: + TCHECK(lsap->lsa_un.un_inter_ap.inter_ap_metric); + printf(" metric %u", + (u_int32_t)ntohl(lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC); + lsapp = lsap->lsa_un.un_inter_ap.inter_ap_prefix; + while (lsapp + sizeof(lsapp) <= (struct lsa_prefix *)ls_end) { + k = ospf6_print_lsaprefix(lsapp); + if (k < 0) + goto trunc; + lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k); + } + break; + +#if 0 + case LS_TYPE_SUM_ABR: + TCHECK(lsap->lsa_un.un_sla.sla_tosmetric); + lp = lsap->lsa_un.un_sla.sla_tosmetric; + while ((u_char *)lp < ls_end) { + register u_int32_t ul; + + TCHECK(*lp); + ul = ntohl(*lp); + printf(" tos %d metric %d", + (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS, + ul & SLA_MASK_METRIC); + ++lp; + } + break; + + case LS_TYPE_ASE: + TCHECK(lsap->lsa_un.un_nla.nla_mask); + printf(" mask %s", + ipaddr_string(&lsap->lsa_un.un_asla.asla_mask)); + + TCHECK(lsap->lsa_un.un_sla.sla_tosmetric); + almp = lsap->lsa_un.un_asla.asla_metric; + while ((u_char *)almp < ls_end) { + register u_int32_t ul; + + TCHECK(almp->asla_tosmetric); + ul = ntohl(almp->asla_tosmetric); + printf(" type %d tos %d metric %d", + (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1, + (ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS, + (ul & ASLA_MASK_METRIC)); + TCHECK(almp->asla_forward); + if (almp->asla_forward.s_addr) { + printf(" forward %s", + ipaddr_string(&almp->asla_forward)); + } + TCHECK(almp->asla_tag); + if (almp->asla_tag.s_addr) { + printf(" tag %s", + ipaddr_string(&almp->asla_tag)); + } + ++almp; + } + break; + + case LS_TYPE_GROUP: + /* Multicast extensions as of 23 July 1991 */ + mcp = lsap->lsa_un.un_mcla; + while ((u_char *)mcp < ls_end) { + TCHECK(mcp->mcla_vid); + switch (ntohl(mcp->mcla_vtype)) { + + case MCLA_VERTEX_ROUTER: + printf(" rtr rtrid %s", + ipaddr_string(&mcp->mcla_vid)); + break; + + case MCLA_VERTEX_NETWORK: + printf(" net dr %s", + ipaddr_string(&mcp->mcla_vid)); + break; + + default: + printf(" ??VertexType %u??", + (u_int32_t)ntohl(mcp->mcla_vtype)); + break; + } + ++mcp; + } +#endif + + case LS_TYPE_LINK: + /* Link LSA */ + llsap = &lsap->lsa_un.un_llsa; + TCHECK(llsap->llsa_options); + ospf6_print_bits(ospf6_option_bits, ntohl(llsap->llsa_options)); + TCHECK(llsap->llsa_nprefix); + printf(" pri %d lladdr %s npref %d", llsap->llsa_priority, + ip6addr_string(&llsap->llsa_lladdr), + (u_int32_t)ntohl(llsap->llsa_nprefix)); + lsapp = llsap->llsa_prefix; + for (j = 0; j < ntohl(llsap->llsa_nprefix); j++) { + k = ospf6_print_lsaprefix(lsapp); + if (k < 0) + goto trunc; + lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k); + } + break; + + case LS_TYPE_INTRA_AP | LS_SCOPE_AREA: + /* Intra-Area-Prefix LSA */ + TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_rtid); + ospf6_print_ls_type( + ntohs(lsap->lsa_un.un_intra_ap.intra_ap_lstype), + &lsap->lsa_un.un_intra_ap.intra_ap_lsid, + &lsap->lsa_un.un_intra_ap.intra_ap_rtid, + "LinkStateType %d"); + TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_nprefix); + printf(" npref %d", + ntohs(lsap->lsa_un.un_intra_ap.intra_ap_nprefix)); + + lsapp = lsap->lsa_un.un_intra_ap.intra_ap_prefix; + for (j = 0; + j < ntohs(lsap->lsa_un.un_intra_ap.intra_ap_nprefix); + j++) { + k = ospf6_print_lsaprefix(lsapp); + if (k < 0) + goto trunc; + lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k); + } + break; + + default: + printf(" ??LinkStateType 0x%04x??", + ntohs(lsap->ls_hdr.ls_type)); + } + + /* { (ctags) */ + fputs(" }", stdout); + return (0); +trunc: + fputs(" }", stdout); + return (1); +} + +static int +ospf6_decode_v3(register const struct ospf6hdr *op, + register const u_char *dataend) +{ + register const rtrid_t *ap; + register const struct lsr *lsrp; + register const struct lsa_hdr *lshp; + register const struct lsa *lsap; + register char sep; + register int i; + + switch (op->ospf6_type) { + + case OSPF_TYPE_UMD: + /* + * Rob Coltun's special monitoring packets; + * do nothing + */ + break; + + case OSPF_TYPE_HELLO: + if (vflag) { + TCHECK(op->ospf6_hello.hello_deadint); + ospf6_print_bits(ospf6_option_bits, + ntohl(op->ospf6_hello.hello_options)); + printf(" ifid %s pri %d int %d dead %u", + ipaddr_string(&op->ospf6_hello.hello_ifid), + op->ospf6_hello.hello_priority, + ntohs(op->ospf6_hello.hello_helloint), + ntohs(op->ospf6_hello.hello_deadint)); + } + TCHECK(op->ospf6_hello.hello_dr); + if (op->ospf6_hello.hello_dr != 0) + printf(" dr %s", + ipaddr_string(&op->ospf6_hello.hello_dr)); + TCHECK(op->ospf6_hello.hello_bdr); + if (op->ospf6_hello.hello_bdr != 0) + printf(" bdr %s", + ipaddr_string(&op->ospf6_hello.hello_bdr)); + if (vflag) { + printf(" nbrs"); + ap = op->ospf6_hello.hello_neighbor; + while ((u_char *)ap < dataend) { + TCHECK(*ap); + printf(" %s", ipaddr_string(ap)); + ++ap; + } + } + break; /* HELLO */ + + case OSPF_TYPE_DB: + TCHECK(op->ospf6_db.db_options); + ospf6_print_bits(ospf6_option_bits, + ntohl(op->ospf6_db.db_options)); + sep = ' '; + TCHECK(op->ospf6_db.db_flags); + if (op->ospf6_db.db_flags & OSPF6_DB_INIT) { + printf("%cI", sep); + sep = '/'; + } + if (op->ospf6_db.db_flags & OSPF6_DB_MORE) { + printf("%cM", sep); + sep = '/'; + } + if (op->ospf6_db.db_flags & OSPF6_DB_MASTER) { + printf("%cMS", sep); + sep = '/'; + } + TCHECK(op->ospf6_db.db_seq); + printf(" mtu %u S %X", ntohs(op->ospf6_db.db_mtu), + (u_int32_t)ntohl(op->ospf6_db.db_seq)); + + if (vflag) { + /* Print all the LS adv's */ + lshp = op->ospf6_db.db_lshdr; + + while (!ospf6_print_lshdr(lshp)) { + /* { (ctags) */ + printf(" }"); + ++lshp; + } + } + break; + + case OSPF_TYPE_LSR: + if (vflag) { + lsrp = op->ospf6_lsr; + while ((u_char *)lsrp < dataend) { + TCHECK(*lsrp); + printf(" {"); /* } (ctags) */ + ospf6_print_ls_type(ntohs(lsrp->ls_type), + &lsrp->ls_stateid, + &lsrp->ls_router, + "LinkStateType %d"); + /* { (ctags) */ + printf(" }"); + ++lsrp; + } + } + break; + + case OSPF_TYPE_LSU: + if (vflag) { + lsap = op->ospf6_lsu.lsu_lsa; + TCHECK(op->ospf6_lsu.lsu_count); + i = ntohl(op->ospf6_lsu.lsu_count); + while (i--) { + if (ospf6_print_lsa(lsap)) + goto trunc; + lsap = (struct lsa *)((u_char *)lsap + + ntohs(lsap->ls_hdr.ls_length)); + } + } + break; + + + case OSPF_TYPE_LSA: + if (vflag) { + lshp = op->ospf6_lsa.lsa_lshdr; + + while (!ospf6_print_lshdr(lshp)) { + /* { (ctags) */ + printf(" }"); + ++lshp; + } + } + break; + + default: + printf("v3 type %d", op->ospf6_type); + break; + } + return (0); +trunc: + return (1); +} + +void +ospf6_print(register const u_char *bp, register u_int length) +{ + register const struct ospf6hdr *op; + register const u_char *dataend; + register const char *cp; + + op = (struct ospf6hdr *)bp; + + /* If the type is valid translate it, or just print the type */ + /* value. If it's not valid, say so and return */ + TCHECK(op->ospf6_type); + cp = tok2str(type2str, "type%d", op->ospf6_type); + printf(" OSPFv%d-%s %d:", op->ospf6_version, cp, length); + if (*cp == 't') + return; + + TCHECK(op->ospf6_len); + if (length != ntohs(op->ospf6_len)) { + printf(" [len %d]", ntohs(op->ospf6_len)); + return; + } + dataend = bp + length; + + /* Print the routerid if it is not the same as the source */ + TCHECK(op->ospf6_routerid); + printf(" rtrid %s", ipaddr_string(&op->ospf6_routerid)); + + TCHECK(op->ospf6_areaid); + if (op->ospf6_areaid != 0) + printf(" area %s", ipaddr_string(&op->ospf6_areaid)); + else + printf(" backbone"); + TCHECK(op->ospf6_instanceid); + if (op->ospf6_instanceid) + printf(" instance %u", op->ospf6_instanceid); + + /* Do rest according to version. */ + switch (op->ospf6_version) { + + case 3: + /* ospf version 3 */ + if (ospf6_decode_v3(op, dataend)) + goto trunc; + break; + + default: + printf(" ospf [version %d]", op->ospf6_version); + break; + } /* end switch on version */ + + return; +trunc: + fputs(tstr, stdout); +} diff --git a/usr.sbin/tcpdump/print-raw.c b/usr.sbin/tcpdump/print-raw.c index debabf358ed..cdb93a1d366 100644 --- a/usr.sbin/tcpdump/print-raw.c +++ b/usr.sbin/tcpdump/print-raw.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-raw.c,v 1.1 1999/09/16 17:27:59 brad Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-raw.c,v 1.2 2000/04/26 21:35:42 jakob Exp $ (LBL)"; #endif #include <sys/param.h> @@ -44,7 +44,6 @@ struct rtentry; #include <netinet/udp.h> #include <netinet/udp_var.h> #include <netinet/tcp.h> -#include <netinet/tcpip.h> #include <pcap.h> #include <stdio.h> diff --git a/usr.sbin/tcpdump/print-rip.c b/usr.sbin/tcpdump/print-rip.c index 0f14f24eb41..283245f6d02 100644 --- a/usr.sbin/tcpdump/print-rip.c +++ b/usr.sbin/tcpdump/print-rip.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-rip.c,v 1.5 1996/12/12 16:22:28 bitblt Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-rip.c,v 1.6 2000/04/26 21:35:42 jakob Exp $ (LBL)"; #endif #include <sys/param.h> @@ -100,8 +100,10 @@ rip_print(const u_char *dat, u_int length) register int i, j, trunc; i = min(length, snapend - dat) - sizeof(*rp); - if (i < 0) + if (i < 0) { + printf(" [|rip]"); return; + } rp = (struct rip *)dat; switch (rp->rip_cmd) { @@ -116,7 +118,7 @@ rip_print(const u_char *dat, u_int length) printf(" rip-resp %d[%d]:", j, length); else printf(" rip-resp %d:", j); - trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); + trunc = (i / sizeof(*ni)) != j; ni = (struct rip_netinfo *)(rp + 1); for (; (i -= sizeof(*ni)) >= 0; ++ni) rip_entry_print(rp->rip_vers, ni); diff --git a/usr.sbin/tcpdump/print-ripng.c b/usr.sbin/tcpdump/print-ripng.c new file mode 100644 index 00000000000..dda0af337ae --- /dev/null +++ b/usr.sbin/tcpdump/print-ripng.c @@ -0,0 +1,125 @@ +/* $OpenBSD: print-ripng.c,v 1.1 2000/04/26 21:35:42 jakob Exp $ */ + +/* + * Copyright (c) 1989, 1990, 1991, 1993, 1994 + * 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 lint +static const char rcsid[] = + "@(#) /master/usr.sbin/tcpdump/tcpdump/print-rip.c,v 2.1 1995/02/03 18:15:05 polk Exp (LBL)"; +#endif + +#ifdef INET6 + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> + +#include <errno.h> +#include <stdio.h> + +#include <netinet/ip6.h> + +#include "route6d.h" +#include "interface.h" +#include "addrtoname.h" + +static int +rip6_entry_print(register const struct netinfo6 *ni, int metric) +{ + int l; + l = printf("%s/%d", ip6addr_string(&ni->rip6_dest), ni->rip6_plen); + if (ni->rip6_tag) + l += printf(" [%d]", ntohs(ni->rip6_tag)); + if (metric) + l += printf(" (%d)", ni->rip6_metric); + return l; +} + +void +ripng_print(const u_char *dat, int length) +{ + register const struct rip6 *rp = (struct rip6 *)dat; + register const struct netinfo6 *ni; + register int amt = snapend - dat; + register int i = min(length, amt) - + (sizeof(struct rip6) - sizeof(struct netinfo6)); + int j; + int trunc; + + if (i < 0) + return; + + switch (rp->rip6_cmd) { + + case RIP6_REQUEST: + j = length / sizeof(*ni); + if (j == 1 + && rp->rip6_nets->rip6_metric == HOPCNT_INFINITY6 + && IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) { + printf(" ripng-req dump"); + break; + } + if (j * sizeof(*ni) != length - 4) + printf(" ripng-req %d[%d]:", j, length); + else + printf(" ripng-req %d:", j); + trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); + for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) { + if (vflag) + printf("\n\t"); + else + printf(" "); + rip6_entry_print(ni, 0); + } + break; + case RIP6_RESPONSE: + j = length / sizeof(*ni); + if (j * sizeof(*ni) != length - 4) + printf(" ripng-resp %d[%d]:", j, length); + else + printf(" ripng-resp %d:", j); + trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); + for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) { + if (vflag) + printf("\n\t"); + else + printf(" "); + rip6_entry_print(ni, ni->rip6_metric); + } + if (trunc) + printf("[|rip]"); + break; + default: + printf(" ripng-%d ?? %d", rp->rip6_cmd, length); + break; + } + if (rp->rip6_vers != RIP6_VERSION) + printf(" [vers %d]", rp->rip6_vers); +} +#endif /* INET6 */ diff --git a/usr.sbin/tcpdump/print-rt6.c b/usr.sbin/tcpdump/print-rt6.c new file mode 100644 index 00000000000..324cb07090b --- /dev/null +++ b/usr.sbin/tcpdump/print-rt6.c @@ -0,0 +1,121 @@ +/* $OpenBSD: print-rt6.c,v 1.1 2000/04/26 21:35:42 jakob Exp $ */ + + +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994 + * 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 lint +static const char rcsid[] = + "@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)"; +#endif + +#ifdef INET6 + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_icmp.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> + +#include <stdio.h> + +#include <netinet/ip6.h> + +#include "interface.h" +#include "addrtoname.h" + +int +rt6_print(register const u_char *bp, register const u_char *bp2) +{ + register const struct ip6_rthdr *dp; + register const struct ip6_rthdr0 *dp0; + register const struct ip6_hdr *ip; + register const u_char *ep; + int i, len; + + dp = (struct ip6_rthdr *)bp; + ip = (struct ip6_hdr *)bp2; + len = dp->ip6r_len; + + /* 'ep' points to the end of avaible data. */ + ep = snapend; + +#if 0 + printf("%s > %s: ", + ip6addr_string(&ip->ip6_src), + ip6addr_string(&ip->ip6_dst)); +#endif + + TCHECK(dp->ip6r_segleft); + + printf("srcrt (len=%d, ", dp->ip6r_len); + printf("type=%d, ", dp->ip6r_type); + printf("segleft=%d, ", dp->ip6r_segleft); + + switch (dp->ip6r_type) { + case IPV6_RTHDR_TYPE_0: + dp0 = (struct ip6_rthdr0 *)dp; + + TCHECK(dp0->ip6r0_reserved); + if (dp0->ip6r0_reserved || vflag) { + printf("rsv=0x%0x, ", + (u_int32_t)ntohl(dp0->ip6r0_reserved)); + } + + if (len % 2 == 1) + goto trunc; + len >>= 1; + for (i = 0; i < len; i++) { + struct in6_addr *addr; + + addr = ((struct in6_addr *)(dp0 + 1)) + i; + if ((u_char *)addr > ep - sizeof(*addr)) + goto trunc; + + printf("[%d]%s", i, ip6addr_string((u_char *)addr)); + if (i != len - 1) + printf(", "); + + } + printf(")"); + return((dp0->ip6r0_len + 1) << 3); + break; + default: + goto trunc; + break; + } + + trunc: + fputs("[|srcrt]", stdout); + return 65535; /* XXX */ +} +#endif /* INET6 */ diff --git a/usr.sbin/tcpdump/print-sl.c b/usr.sbin/tcpdump/print-sl.c index 536204120c6..3aab1b1d90a 100644 --- a/usr.sbin/tcpdump/print-sl.c +++ b/usr.sbin/tcpdump/print-sl.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-sl.c,v 1.8 1999/09/16 20:58:47 brad Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-sl.c,v 1.9 2000/04/26 21:35:43 jakob Exp $ (LBL)"; #endif #ifdef HAVE_NET_SLIP_H @@ -42,11 +42,8 @@ struct rtentry; #include <netinet/in_systm.h> #include <netinet/ip.h> #include <netinet/if_ether.h> -#include <netinet/ip_var.h> #include <netinet/udp.h> -#include <netinet/udp_var.h> #include <netinet/tcp.h> -#include <netinet/tcpip.h> #include <net/slcompress.h> #include <net/slip.h> @@ -54,7 +51,6 @@ struct rtentry; #include <ctype.h> #include <netdb.h> #include <pcap.h> -#include <signal.h> #include <stdio.h> #include "interface.h" @@ -105,7 +101,18 @@ sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) if (eflag) sliplink_print(p, ip, length); - ip_print((u_char *)ip, length); + switch (ip->ip_v) { + case 4: + ip_print((u_char *)ip, length); + break; +#ifdef INET6 + case 6: + ip6_print((u_char *)ip, length); + break; +#endif + default: + printf ("ip v%d", ip->ip_v); + } if (xflag) default_print((u_char *)ip, caplen - SLIP_HDRLEN); diff --git a/usr.sbin/tcpdump/print-snmp.c b/usr.sbin/tcpdump/print-snmp.c index ca011e863d4..12f0c2a423d 100644 --- a/usr.sbin/tcpdump/print-snmp.c +++ b/usr.sbin/tcpdump/print-snmp.c @@ -42,13 +42,16 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-snmp.c,v 1.6 1999/09/16 20:58:47 brad Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-snmp.c,v 1.7 2000/04/26 21:35:43 jakob Exp $ (LBL)"; #endif #include <sys/param.h> #include <sys/time.h> #include <ctype.h> +#ifdef HAVE_MEMORY_H +#include <memory.h> +#endif #include <stdio.h> #include <string.h> diff --git a/usr.sbin/tcpdump/print-tcp.c b/usr.sbin/tcpdump/print-tcp.c index c0646b9dee3..71c2d665596 100644 --- a/usr.sbin/tcpdump/print-tcp.c +++ b/usr.sbin/tcpdump/print-tcp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-tcp.c,v 1.10 2000/01/16 11:43:58 jakob Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-tcp.c,v 1.11 2000/04/26 21:35:43 jakob Exp $ (LBL)"; #endif #include <sys/param.h> @@ -34,15 +34,23 @@ static const char rcsid[] = #include <netinet/tcp.h> #include <netinet/tcpip.h> +#include <rpc/rpc.h> + #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> +#ifdef INET6 +#include <netinet/ip6.h> +#endif + #include "interface.h" #include "addrtoname.h" #include "extract.h" +#include "nfs.h" + /* Compatibility */ #ifndef TCPOPT_WSCALE #define TCPOPT_WSCALE 3 /* window scale factor (rfc1072) */ @@ -85,8 +93,13 @@ static const char rcsid[] = #endif struct tha { +#ifndef INET6 struct in_addr src; struct in_addr dst; +#else + struct in6_addr src; + struct in6_addr dst; +#endif /*INET6*/ u_int port; }; @@ -104,7 +117,51 @@ struct tcp_seq_hash { static struct tcp_seq_hash tcp_seq_hash[TSEQ_HASHSIZE]; -#define NETBIOS_SSN_PORT 139 +static int tcp_cksum(register const struct ip *ip, + register const struct tcphdr *tp, + register int len) +{ + int i, tlen; + union phu { + struct phdr { + u_int32_t src; + u_int32_t dst; + u_char mbz; + u_char proto; + u_int16_t len; + } ph; + u_int16_t pa[6]; + } phu; + register const u_int16_t *sp; + u_int32_t sum; + tlen = ntohs(ip->ip_len) - ((const char *)tp-(const char*)ip); + + /* pseudo-header.. */ + phu.ph.len = htons(tlen); + phu.ph.mbz = 0; + phu.ph.proto = ip->ip_p; + memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t)); + memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t)); + + sp = &phu.pa[0]; + sum = sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]; + + sp = (const u_int16_t *)tp; + + for (i=0; i<(tlen&~1); i+= 2) + sum += *sp++; + + if (tlen & 1) { + sum += htons( (*(const char *)sp) << 8); + } + + while (sum > 0xffff) + sum = (sum & 0xffff) + (sum >> 16); + sum = ~sum & 0xffff; + + return (sum); +} + void tcp_print(register const u_char *bp, register u_int length, @@ -117,11 +174,20 @@ tcp_print(register const u_char *bp, register u_int length, register char ch; register struct tcp_seq_hash *th; register int rev; - u_short sport, dport, win, urp; - u_int32_t seq, ack; + u_int16_t sport, dport, win, urp; + tcp_seq seq, ack; +#ifdef INET6 + register const struct ip6_hdr *ip6; +#endif tp = (struct tcphdr *)bp; ip = (struct ip *)bp2; +#ifdef INET6 + if (ip->ip_v == 6) + ip6 = (struct ip6_hdr *)bp2; + else + ip6 = NULL; +#endif /*INET6*/ ch = '\0'; TCHECK(*tp); if (length < sizeof(*tp)) { @@ -135,10 +201,55 @@ tcp_print(register const u_char *bp, register u_int length, ack = ntohl(tp->th_ack); win = ntohs(tp->th_win); urp = ntohs(tp->th_urp); + hlen = tp->th_off * 4; - (void)printf("%s.%s > %s.%s: ", - ipaddr_string(&ip->ip_src), tcpport_string(sport), - ipaddr_string(&ip->ip_dst), tcpport_string(dport)); + /* + * If data present and NFS port used, assume NFS. + * Pass offset of data plus 4 bytes for RPC TCP msg length + * to NFS print routines. + */ + if (!qflag) { + u_int len = length - hlen; + if ((u_char *)tp + 4 + sizeof(struct rpc_msg) <= snapend && + dport == NFS_PORT) { + nfsreq_print((u_char *)tp + hlen + 4, len, + (u_char *)ip); + return; + } + else if ((u_char *)tp + 4 + sizeof(struct rpc_msg) <= snapend && + sport == NFS_PORT) { + nfsreply_print((u_char *)tp + hlen + 4, len, + (u_char *)ip); + return; + } + } + +#ifdef INET6 + if (ip6) { + if (ip6->ip6_nxt == IPPROTO_TCP) { + (void)printf("%s.%s > %s.%s: ", + ip6addr_string(&ip6->ip6_src), + tcpport_string(sport), + ip6addr_string(&ip6->ip6_dst), + tcpport_string(dport)); + } else { + (void)printf("%s > %s: ", + tcpport_string(sport), tcpport_string(dport)); + } + } else +#endif /*INET6*/ + { + if (ip->ip_p == IPPROTO_TCP) { + (void)printf("%s.%s > %s.%s: ", + ipaddr_string(&ip->ip_src), + tcpport_string(sport), + ipaddr_string(&ip->ip_dst), + tcpport_string(dport)); + } else { + (void)printf("%s > %s: ", + tcpport_string(sport), tcpport_string(dport)); + } + } if (qflag) { (void)printf("tcp %d", length - tp->th_off * 4); @@ -169,6 +280,49 @@ tcp_print(register const u_char *bp, register u_int length, * collating order so there's only one entry for * both directions). */ +#ifdef INET6 + bzero(&tha, sizeof(tha)); + rev = 0; + if (ip6) { + if (sport > dport) { + rev = 1; + } else if (sport == dport) { + int i; + + for (i = 0; i < 4; i++) { + if (((u_int32_t *)(&ip6->ip6_src))[i] > + ((u_int32_t *)(&ip6->ip6_dst))[i]) { + rev = 1; + break; + } + } + } + if (rev) { + tha.src = ip6->ip6_dst; + tha.dst = ip6->ip6_src; + tha.port = dport << 16 | sport; + } else { + tha.dst = ip6->ip6_dst; + tha.src = ip6->ip6_src; + tha.port = sport << 16 | dport; + } + } else { + if (sport > dport || + (sport == dport && + ip->ip_src.s_addr > ip->ip_dst.s_addr)) { + rev = 1; + } + if (rev) { + *(struct in_addr *)&tha.src = ip->ip_dst; + *(struct in_addr *)&tha.dst = ip->ip_src; + tha.port = dport << 16 | sport; + } else { + *(struct in_addr *)&tha.dst = ip->ip_dst; + *(struct in_addr *)&tha.src = ip->ip_src; + tha.port = sport << 16 | dport; + } + } +#else if (sport < dport || (sport == dport && ip->ip_src.s_addr < ip->ip_dst.s_addr)) { @@ -180,6 +334,7 @@ tcp_print(register const u_char *bp, register u_int length, tha.port = dport << 16 | sport; rev = 1; } +#endif for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE]; th->nxt; th = th->nxt) @@ -212,9 +367,22 @@ tcp_print(register const u_char *bp, register u_int length, (void)printf(" [bad hdr length]"); return; } + + if (ip->ip_v == 4 && vflag) { + int sum; + if (TTEST2(tp->th_sport, length)) { + sum = tcp_cksum(ip, tp, length); + if (sum != 0) + (void)printf(" [bad tcp cksum %x!]", sum); + else + (void)printf(" [tcp sum ok]"); + } + } + length -= hlen; if (length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) - (void)printf(" %u:%u(%d)", seq, seq + length, length); + (void)printf(" %lu:%lu(%d)", (long) seq, (long) (seq + length), + length); if (flags & TH_ACK) (void)printf(" ack %u", ack); diff --git a/usr.sbin/tcpdump/print-udp.c b/usr.sbin/tcpdump/print-udp.c index 041c3f7852c..618edef600a 100644 --- a/usr.sbin/tcpdump/print-udp.c +++ b/usr.sbin/tcpdump/print-udp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-udp.c,v 1.11 2000/01/16 10:54:58 jakob Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-udp.c,v 1.12 2000/04/26 21:35:43 jakob Exp $ (LBL)"; #endif #include <sys/param.h> @@ -51,6 +51,10 @@ static const char rcsid[] = #include <stdio.h> +#ifdef INET6 +#include <netinet/ip6.h> +#endif + #include "interface.h" #include "addrtoname.h" #include "appletalk.h" @@ -284,6 +288,53 @@ rtcp_print(const u_char *hdr, const u_char *ep) return (hdr + len); } +static int udp_cksum(register const struct ip *ip, + register const struct udphdr *up, + register int len) +{ + int i, tlen; + union phu { + struct phdr { + u_int32_t src; + u_int32_t dst; + u_char mbz; + u_char proto; + u_int16_t len; + } ph; + u_int16_t pa[6]; + } phu; + register const u_int16_t *sp; + u_int32_t sum; + tlen = ntohs(ip->ip_len) - ((const char *)up-(const char*)ip); + + /* pseudo-header.. */ + phu.ph.len = htons(tlen); + phu.ph.mbz = 0; + phu.ph.proto = ip->ip_p; + memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t)); + memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t)); + + sp = &phu.pa[0]; + sum = sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]; + + sp = (const u_int16_t *)up; + + for (i=0; i<(tlen&~1); i+= 2) + sum += *sp++; + + if (tlen & 1) { + sum += htons( (*(const char *)sp) << 8); + } + + while (sum > 0xffff) + sum = (sum & 0xffff) + (sum >> 16); + sum = ~sum & 0xffff; + + return (sum); +} + + + /* XXX probably should use getservbyname() and cache answers */ #define TFTP_PORT 69 /*XXX*/ #define KERBEROS_PORT 88 /*XXX*/ @@ -295,15 +346,18 @@ rtcp_print(const u_char *hdr, const u_char *ep) #define KERBEROS_SEC_PORT 750 /*XXX*/ #define L2TP_PORT 1701 /*XXX*/ #define ISAKMP_PORT 500 /*XXX*/ -#define ISAKMP_UPORT1 7500 /*XXX*/ -#define ISAKMP_UPORT2 8500 /*XXX*/ #define NETBIOS_NS_PORT 137 /*XXX*/ #define NETBIOS_DGRAM_PORT 138 /*XXX*/ #define OLD_RADIUS_AUTH_PORT 1645 #define OLD_RADIUS_ACCT_PORT 1646 #define RADIUS_AUTH_PORT 1812 #define RADIUS_ACCT_PORT 1813 - + +#ifdef INET6 +#define RIPNG_PORT 521 /*XXX*/ +#define DHCP6_PORT1 546 /*XXX*/ +#define DHCP6_PORT2 547 /*XXX*/ +#endif void udp_print(register const u_char *bp, u_int length, register const u_char *bp2) @@ -312,12 +366,21 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) register const struct ip *ip; register const u_char *cp; register const u_char *ep = bp + length; - u_short sport, dport, ulen; + u_int16_t sport, dport, ulen; +#ifdef INET6 + register const struct ip6_hdr *ip6; +#endif if (ep > snapend) ep = snapend; up = (struct udphdr *)bp; ip = (struct ip *)bp2; +#ifdef INET6 + if (ip->ip_v == 6) + ip6 = (struct ip6_hdr *)bp2; + else + ip6 = NULL; +#endif /*INET6*/ cp = (u_char *)(up + 1); if (cp > snapend) { printf("[|udp]"); @@ -425,9 +488,51 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) return; } } +#if 0 (void)printf("%s.%s > %s.%s:", ipaddr_string(&ip->ip_src), udpport_string(sport), ipaddr_string(&ip->ip_dst), udpport_string(dport)); +#else +#ifdef INET6 + if (ip6) { + if (ip6->ip6_nxt == IPPROTO_UDP) { + (void)printf("%s.%s > %s.%s: ", + ip6addr_string(&ip6->ip6_src), + udpport_string(sport), + ip6addr_string(&ip6->ip6_dst), + udpport_string(dport)); + } else { + (void)printf("%s > %s: ", + udpport_string(sport), udpport_string(dport)); + } + } else +#endif /*INET6*/ + { + if (ip->ip_p == IPPROTO_UDP) { + (void)printf("%s.%s > %s.%s: ", + ipaddr_string(&ip->ip_src), + udpport_string(sport), + ipaddr_string(&ip->ip_dst), + udpport_string(dport)); + } else { + (void)printf("%s > %s: ", + udpport_string(sport), udpport_string(dport)); + } + } +#endif + + if (ip->ip_v == 4 && vflag) { + int sum = up->uh_sum; + if (sum == 0) { + (void)printf(" [no cksum]"); + } else if (TTEST2(cp[0], length)) { + sum = udp_cksum(ip, up, length); + if (sum != 0) + (void)printf(" [bad udp cksum %x!]", sum); + else + (void)printf(" [udp sum ok]"); + } + } if (!qflag) { #define ISPORT(p) (dport == (p) || sport == (p)) @@ -448,9 +553,7 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) krb_print((const void *)(up + 1), length); else if (ISPORT(L2TP_PORT)) l2tp_print((const u_char *)(up + 1), length); - else if (ISPORT(ISAKMP_PORT) || - ISPORT(ISAKMP_UPORT1) || - ISPORT(ISAKMP_UPORT2)) + else if (ISPORT(ISAKMP_PORT)) isakmp_print((const u_char *)(up + 1), length); else if (ISPORT(OLD_RADIUS_AUTH_PORT) || ISPORT(OLD_RADIUS_ACCT_PORT) || @@ -459,6 +562,14 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) radius_print((const u_char *)(up + 1), length); else if (dport == 3456) vat_print((const void *)(up + 1), length, up); +#ifdef INET6 + else if (ISPORT(RIPNG_PORT)) + ripng_print((const u_char *)(up + 1), length); + else if (ISPORT(DHCP6_PORT1) || ISPORT(DHCP6_PORT2)) { + dhcp6_print((const u_char *)(up + 1), length, + sport, dport); + } +#endif /*INET6*/ /* * Kludge in test for whiteboard packets. */ diff --git a/usr.sbin/tcpdump/route6d.h b/usr.sbin/tcpdump/route6d.h new file mode 100644 index 00000000000..ae658136cbd --- /dev/null +++ b/usr.sbin/tcpdump/route6d.h @@ -0,0 +1,47 @@ +/* $OpenBSD: route6d.h,v 1.1 2000/04/26 21:35:43 jakob Exp $ */ + +#define RIP6_VERSION 1 + +#define RIP6_REQUEST 1 +#define RIP6_RESPONSE 2 + +struct netinfo6 { + struct in6_addr rip6_dest; + u_short rip6_tag; + u_char rip6_plen; + u_char rip6_metric; +}; + +struct rip6 { + u_char rip6_cmd; + u_char rip6_vers; + u_char rip6_res1[2]; + union { + struct netinfo6 ru6_nets[1]; + char ru6_tracefile[1]; + } rip6un; +#define rip6_nets rip6un.ru6_nets +#define rip6_tracefile rip6un.ru6_tracefile +}; + +#define HOPCNT_INFINITY6 16 +#define MAXRTE 24 +#define NEXTHOP_METRIC 0xff + +#ifndef DEBUG +#define SUPPLY_INTERVAL6 30 +#define RIP_LIFETIME 180 +#define RIP_HOLDDOWN 120 +#define RIP_TRIG_INTERVAL6 5 +#define RIP_TRIG_INTERVAL6_MIN 1 +#else +/* only for debugging; can not wait for 30sec to appear a bug */ +#define SUPPLY_INTERVAL6 10 +#define RIP_LIFETIME 60 +#define RIP_HOLDDOWN 40 +#define RIP_TRIG_INTERVAL6 5 +#define RIP_TRIG_INTERVAL6_MIN 1 +#endif + +#define RIP6_PORT 521 +#define RIP6_DEST "ff02::9" diff --git a/usr.sbin/tcpdump/tcpdump.c b/usr.sbin/tcpdump/tcpdump.c index 272b2ce5007..40a435f9010 100644 --- a/usr.sbin/tcpdump/tcpdump.c +++ b/usr.sbin/tcpdump/tcpdump.c @@ -24,7 +24,7 @@ static const char copyright[] = "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997\n\ The Regents of the University of California. All rights reserved.\n"; static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/tcpdump.c,v 1.16 2000/03/26 05:24:25 ericj Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/tcpdump.c,v 1.17 2000/04/26 21:35:44 jakob Exp $ (LBL)"; #endif /* @@ -283,6 +283,9 @@ main(int argc, char **argv) /* NOTREACHED */ } + if (aflag && nflag) + error("-a and -n options are incompatible"); + if (tflag > 0) thiszone = gmt2local(0); |