diff options
author | cvs2svn <cvs2svn@FreeBSD.org> | 1999-02-20 11:18:01 +0000 |
---|---|---|
committer | cvs2svn <cvs2svn@FreeBSD.org> | 1999-02-20 11:18:01 +0000 |
commit | 0c669098d078c88cf703bade2263846b39e01d83 (patch) | |
tree | af685067b54ffd21bae722c45e9b44585e122fed /contrib/tcpdump | |
parent | cfc42b58f229425374e675f86614cf26ffa356e4 (diff) | |
download | FreeBSD-src-0c669098d078c88cf703bade2263846b39e01d83.zip FreeBSD-src-0c669098d078c88cf703bade2263846b39e01d83.tar.gz |
This commit was manufactured by cvs2svn to create branch
'VENDOR-tcpdump'.
Diffstat (limited to 'contrib/tcpdump')
-rw-r--r-- | contrib/tcpdump/nfs.h | 446 | ||||
-rw-r--r-- | contrib/tcpdump/print-fr.c | 423 | ||||
-rw-r--r-- | contrib/tcpdump/print-token.c | 165 | ||||
-rw-r--r-- | contrib/tcpdump/token.h | 43 |
4 files changed, 1077 insertions, 0 deletions
diff --git a/contrib/tcpdump/nfs.h b/contrib/tcpdump/nfs.h new file mode 100644 index 0000000..045ebb1 --- /dev/null +++ b/contrib/tcpdump/nfs.h @@ -0,0 +1,446 @@ +/* $NetBSD: nfs.h,v 1.1 1996/05/23 22:49:53 fvdl Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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 BY THE REGENTS 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 REGENTS 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. + * + * @(#)nfsproto.h 8.2 (Berkeley) 3/30/95 + */ + +/* + * nfs definitions as per the Version 2 and 3 specs + */ + +/* + * Constants as defined in the Sun NFS Version 2 and 3 specs. + * "NFS: Network File System Protocol Specification" RFC1094 + * and in the "NFS: Network File System Version 3 Protocol + * Specification" + */ + +#define NFS_PORT 2049 +#define NFS_PROG 100003 +#define NFS_VER2 2 +#define NFS_VER3 3 +#define NFS_V2MAXDATA 8192 +#define NFS_MAXDGRAMDATA 16384 +#define NFS_MAXDATA 32768 +#define NFS_MAXPATHLEN 1024 +#define NFS_MAXNAMLEN 255 +#define NFS_MAXPKTHDR 404 +#define NFS_MAXPACKET (NFS_MAXPKTHDR + NFS_MAXDATA) +#define NFS_MINPACKET 20 +#define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */ + +/* Stat numbers for rpc returns (version 2 and 3) */ +#define NFS_OK 0 +#define NFSERR_PERM 1 +#define NFSERR_NOENT 2 +#define NFSERR_IO 5 +#define NFSERR_NXIO 6 +#define NFSERR_ACCES 13 +#define NFSERR_EXIST 17 +#define NFSERR_XDEV 18 /* Version 3 only */ +#define NFSERR_NODEV 19 +#define NFSERR_NOTDIR 20 +#define NFSERR_ISDIR 21 +#define NFSERR_INVAL 22 /* Version 3 only */ +#define NFSERR_FBIG 27 +#define NFSERR_NOSPC 28 +#define NFSERR_ROFS 30 +#define NFSERR_MLINK 31 /* Version 3 only */ +#define NFSERR_NAMETOL 63 +#define NFSERR_NOTEMPTY 66 +#define NFSERR_DQUOT 69 +#define NFSERR_STALE 70 +#define NFSERR_REMOTE 71 /* Version 3 only */ +#define NFSERR_WFLUSH 99 /* Version 2 only */ +#define NFSERR_BADHANDLE 10001 /* The rest Version 3 only */ +#define NFSERR_NOT_SYNC 10002 +#define NFSERR_BAD_COOKIE 10003 +#define NFSERR_NOTSUPP 10004 +#define NFSERR_TOOSMALL 10005 +#define NFSERR_SERVERFAULT 10006 +#define NFSERR_BADTYPE 10007 +#define NFSERR_JUKEBOX 10008 +#define NFSERR_TRYLATER NFSERR_JUKEBOX +#define NFSERR_STALEWRITEVERF 30001 /* Fake return for nfs_commit() */ + +#define NFSERR_RETVOID 0x20000000 /* Return void, not error */ +#define NFSERR_AUTHERR 0x40000000 /* Mark an authentication error */ +#define NFSERR_RETERR 0x80000000 /* Mark an error return for V3 */ + +/* Sizes in bytes of various nfs rpc components */ +#define NFSX_UNSIGNED 4 + +/* specific to NFS Version 2 */ +#define NFSX_V2FH 32 +#define NFSX_V2FATTR 68 +#define NFSX_V2SATTR 32 +#define NFSX_V2COOKIE 4 +#define NFSX_V2STATFS 20 + +/* specific to NFS Version 3 */ +#if 0 +#define NFSX_V3FH (sizeof (fhandle_t)) /* size this server uses */ +#endif +#define NFSX_V3FHMAX 64 /* max. allowed by protocol */ +#define NFSX_V3FATTR 84 +#define NFSX_V3SATTR 60 /* max. all fields filled in */ +#define NFSX_V3SRVSATTR (sizeof (struct nfsv3_sattr)) +#define NFSX_V3POSTOPATTR (NFSX_V3FATTR + NFSX_UNSIGNED) +#define NFSX_V3WCCDATA (NFSX_V3POSTOPATTR + 8 * NFSX_UNSIGNED) +#define NFSX_V3COOKIEVERF 8 +#define NFSX_V3WRITEVERF 8 +#define NFSX_V3CREATEVERF 8 +#define NFSX_V3STATFS 52 +#define NFSX_V3FSINFO 48 +#define NFSX_V3PATHCONF 24 + +/* variants for both versions */ +#define NFSX_FH(v3) ((v3) ? (NFSX_V3FHMAX + NFSX_UNSIGNED) : \ + NFSX_V2FH) +#define NFSX_SRVFH(v3) ((v3) ? NFSX_V3FH : NFSX_V2FH) +#define NFSX_FATTR(v3) ((v3) ? NFSX_V3FATTR : NFSX_V2FATTR) +#define NFSX_PREOPATTR(v3) ((v3) ? (7 * NFSX_UNSIGNED) : 0) +#define NFSX_POSTOPATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : 0) +#define NFSX_POSTOPORFATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : \ + NFSX_V2FATTR) +#define NFSX_WCCDATA(v3) ((v3) ? NFSX_V3WCCDATA : 0) +#define NFSX_WCCORFATTR(v3) ((v3) ? NFSX_V3WCCDATA : NFSX_V2FATTR) +#define NFSX_SATTR(v3) ((v3) ? NFSX_V3SATTR : NFSX_V2SATTR) +#define NFSX_COOKIEVERF(v3) ((v3) ? NFSX_V3COOKIEVERF : 0) +#define NFSX_WRITEVERF(v3) ((v3) ? NFSX_V3WRITEVERF : 0) +#define NFSX_READDIR(v3) ((v3) ? (5 * NFSX_UNSIGNED) : \ + (2 * NFSX_UNSIGNED)) +#define NFSX_STATFS(v3) ((v3) ? NFSX_V3STATFS : NFSX_V2STATFS) + +/* nfs rpc procedure numbers (before version mapping) */ +#define NFSPROC_NULL 0 +#define NFSPROC_GETATTR 1 +#define NFSPROC_SETATTR 2 +#define NFSPROC_LOOKUP 3 +#define NFSPROC_ACCESS 4 +#define NFSPROC_READLINK 5 +#define NFSPROC_READ 6 +#define NFSPROC_WRITE 7 +#define NFSPROC_CREATE 8 +#define NFSPROC_MKDIR 9 +#define NFSPROC_SYMLINK 10 +#define NFSPROC_MKNOD 11 +#define NFSPROC_REMOVE 12 +#define NFSPROC_RMDIR 13 +#define NFSPROC_RENAME 14 +#define NFSPROC_LINK 15 +#define NFSPROC_READDIR 16 +#define NFSPROC_READDIRPLUS 17 +#define NFSPROC_FSSTAT 18 +#define NFSPROC_FSINFO 19 +#define NFSPROC_PATHCONF 20 +#define NFSPROC_COMMIT 21 + +/* And leasing (nqnfs) procedure numbers (must be last) */ +#define NQNFSPROC_GETLEASE 22 +#define NQNFSPROC_VACATED 23 +#define NQNFSPROC_EVICTED 24 + +#define NFSPROC_NOOP 25 +#define NFS_NPROCS 26 + +/* Actual Version 2 procedure numbers */ +#define NFSV2PROC_NULL 0 +#define NFSV2PROC_GETATTR 1 +#define NFSV2PROC_SETATTR 2 +#define NFSV2PROC_NOOP 3 +#define NFSV2PROC_ROOT NFSV2PROC_NOOP /* Obsolete */ +#define NFSV2PROC_LOOKUP 4 +#define NFSV2PROC_READLINK 5 +#define NFSV2PROC_READ 6 +#define NFSV2PROC_WRITECACHE NFSV2PROC_NOOP /* Obsolete */ +#define NFSV2PROC_WRITE 8 +#define NFSV2PROC_CREATE 9 +#define NFSV2PROC_REMOVE 10 +#define NFSV2PROC_RENAME 11 +#define NFSV2PROC_LINK 12 +#define NFSV2PROC_SYMLINK 13 +#define NFSV2PROC_MKDIR 14 +#define NFSV2PROC_RMDIR 15 +#define NFSV2PROC_READDIR 16 +#define NFSV2PROC_STATFS 17 + +/* + * Constants used by the Version 3 protocol for various RPCs + */ +#define NFSV3SATTRTIME_DONTCHANGE 0 +#define NFSV3SATTRTIME_TOSERVER 1 +#define NFSV3SATTRTIME_TOCLIENT 2 + +#define NFSV3ATTRTIME_NMODES 3 + +#define NFSV3ACCESS_READ 0x01 +#define NFSV3ACCESS_LOOKUP 0x02 +#define NFSV3ACCESS_MODIFY 0x04 +#define NFSV3ACCESS_EXTEND 0x08 +#define NFSV3ACCESS_DELETE 0x10 +#define NFSV3ACCESS_EXECUTE 0x20 + +#define NFSV3WRITE_UNSTABLE 0 +#define NFSV3WRITE_DATASYNC 1 +#define NFSV3WRITE_FILESYNC 2 + +#define NFSV3WRITE_NMODES 3 + +#define NFSV3CREATE_UNCHECKED 0 +#define NFSV3CREATE_GUARDED 1 +#define NFSV3CREATE_EXCLUSIVE 2 + +#define NFSV3CREATE_NMODES 3 + +#define NFSV3FSINFO_LINK 0x01 +#define NFSV3FSINFO_SYMLINK 0x02 +#define NFSV3FSINFO_HOMOGENEOUS 0x08 +#define NFSV3FSINFO_CANSETTIME 0x10 + +/* Conversion macros */ +#define vtonfsv2_mode(t,m) \ + txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : \ + MAKEIMODE((t), (m))) +#define vtonfsv3_mode(m) txdr_unsigned((m) & 07777) +#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_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, + NFSOCK=6, NFFIFO=7 } nfstype; + +/* Structs for common parts of the rpc's */ +/* + * File Handle (32 bytes for version 2), variable up to 64 for version 3. + * File Handles of up to NFS_SMALLFH in size are stored directly in the + * nfs node, whereas larger ones are malloc'd. (This never happens when + * NFS_SMALLFH is set to 64.) + * NFS_SMALLFH should be in the range of 32 to 64 and be divisible by 4. + */ +#ifndef NFS_SMALLFH +#define NFS_SMALLFH 64 +#endif +union nfsfh { +/* fhandle_t fh_generic; */ + u_char fh_bytes[NFS_SMALLFH]; +}; +typedef union nfsfh nfsfh_t; + +struct nfsv2_time { + u_int32_t nfsv2_sec; + u_int32_t nfsv2_usec; +}; +typedef struct nfsv2_time nfstime2; + +struct nfsv3_time { + u_int32_t nfsv3_sec; + u_int32_t nfsv3_nsec; +}; +typedef struct nfsv3_time nfstime3; + +/* + * Quads are defined as arrays of 2 longs to ensure dense packing for the + * protocol and to facilitate xdr conversion. + */ +struct nfs_uquad { + u_int32_t nfsuquad[2]; +}; +typedef struct nfs_uquad nfsuint64; + +/* + * Used to convert between two u_longs and a u_quad_t. + */ +union nfs_quadconvert { + u_int32_t lval[2]; + u_quad_t qval; +}; +typedef union nfs_quadconvert nfsquad_t; + +/* + * NFS Version 3 special file number. + */ +struct nfsv3_spec { + u_int32_t specdata1; + u_int32_t specdata2; +}; +typedef struct nfsv3_spec nfsv3spec; + +/* + * File attributes and setable attributes. These structures cover both + * NFS version 2 and the version 3 protocol. Note that the union is only + * used so that one pointer can refer to both variants. These structures + * go out on the wire and must be densely packed, so no quad data types + * are used. (all fields are longs or u_longs or structures of same) + * NB: You can't do sizeof(struct nfs_fattr), you must use the + * NFSX_FATTR(v3) macro. + */ +struct nfs_fattr { + 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_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; + } fa_nfsv2; + struct { + nfsuint64 nfsv3fa_size; + nfsuint64 nfsv3fa_used; + nfsv3spec nfsv3fa_rdev; + nfsuint64 nfsv3fa_fsid; + nfsuint64 nfsv3fa_fileid; + nfstime3 nfsv3fa_atime; + nfstime3 nfsv3fa_mtime; + nfstime3 nfsv3fa_ctime; + } fa_nfsv3; + } fa_un; +}; + +/* and some ugly defines for accessing union components */ +#define fa2_size fa_un.fa_nfsv2.nfsv2fa_size +#define fa2_blocksize fa_un.fa_nfsv2.nfsv2fa_blocksize +#define fa2_rdev fa_un.fa_nfsv2.nfsv2fa_rdev +#define fa2_blocks fa_un.fa_nfsv2.nfsv2fa_blocks +#define fa2_fsid fa_un.fa_nfsv2.nfsv2fa_fsid +#define fa2_fileid fa_un.fa_nfsv2.nfsv2fa_fileid +#define fa2_atime fa_un.fa_nfsv2.nfsv2fa_atime +#define fa2_mtime fa_un.fa_nfsv2.nfsv2fa_mtime +#define fa2_ctime fa_un.fa_nfsv2.nfsv2fa_ctime +#define fa3_size fa_un.fa_nfsv3.nfsv3fa_size +#define fa3_used fa_un.fa_nfsv3.nfsv3fa_used +#define fa3_rdev fa_un.fa_nfsv3.nfsv3fa_rdev +#define fa3_fsid fa_un.fa_nfsv3.nfsv3fa_fsid +#define fa3_fileid fa_un.fa_nfsv3.nfsv3fa_fileid +#define fa3_atime fa_un.fa_nfsv3.nfsv3fa_atime +#define fa3_mtime fa_un.fa_nfsv3.nfsv3fa_mtime +#define fa3_ctime fa_un.fa_nfsv3.nfsv3fa_ctime + +struct nfsv2_sattr { + 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; +}; + +/* + * NFS Version 3 sattr structure for the new node creation case. + */ +struct nfsv3_sattr { + 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_t sa_mtimetype; + nfstime3 sa_mtime; +}; + +struct nfs_statfs { + union { + struct { + 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; + nfsuint64 nfsv3sf_fbytes; + nfsuint64 nfsv3sf_abytes; + nfsuint64 nfsv3sf_tfiles; + nfsuint64 nfsv3sf_ffiles; + nfsuint64 nfsv3sf_afiles; + u_int32_t nfsv3sf_invarsec; + } sf_nfsv3; + } sf_un; +}; + +#define sf_tsize sf_un.sf_nfsv2.nfsv2sf_tsize +#define sf_bsize sf_un.sf_nfsv2.nfsv2sf_bsize +#define sf_blocks sf_un.sf_nfsv2.nfsv2sf_blocks +#define sf_bfree sf_un.sf_nfsv2.nfsv2sf_bfree +#define sf_bavail sf_un.sf_nfsv2.nfsv2sf_bavail +#define sf_tbytes sf_un.sf_nfsv3.nfsv3sf_tbytes +#define sf_fbytes sf_un.sf_nfsv3.nfsv3sf_fbytes +#define sf_abytes sf_un.sf_nfsv3.nfsv3sf_abytes +#define sf_tfiles sf_un.sf_nfsv3.nfsv3sf_tfiles +#define sf_ffiles sf_un.sf_nfsv3.nfsv3sf_ffiles +#define sf_afiles sf_un.sf_nfsv3.nfsv3sf_afiles +#define sf_invarsec sf_un.sf_nfsv3.nfsv3sf_invarsec + +struct nfsv3_fsinfo { + 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_t fs_properties; +}; + +struct nfsv3_pathconf { + 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/contrib/tcpdump/print-fr.c b/contrib/tcpdump/print-fr.c new file mode 100644 index 0000000..f082488 --- /dev/null +++ b/contrib/tcpdump/print-fr.c @@ -0,0 +1,423 @@ +/* + * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996 + * 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 char rcsid[] = + "@(#)$Header: /cvs/juniper/src/freebsd/contrib/tcpdump/print-fr.c,v 1.2 1997/07/18 20:24:15 boonmark Exp $ (LBL)"; +#endif + +#ifdef PPP +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> +#include <sys/file.h> +#include <sys/ioctl.h> + +#if __STDC__ +struct mbuf; +struct rtentry; +#endif +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> + +#include <ctype.h> +#include <netdb.h> +#include <pcap.h> +#include <signal.h> +#include <stdio.h> + +#include <netinet/if_ether.h> +#include "ethertype.h" + +#include <net/ppp_defs.h> +#include "interface.h" +#include "addrtoname.h" + + +void q933_print(); + +#define FR_EA_BIT(p) ((p)&0x1) +#define FR_DLCI(b0,b1) ((((b0)&0xFC)<<2)+(((b1)&0xF0)>>4)) + +struct fr_nlpids { + u_short id; + char *name; +}; + +/* find out how many bytes are there in a frame */ +int +fr_addr_len(const u_char *p) +{ + int i=0; + + while (!FR_EA_BIT(p[i]) && i++ && !FR_EA_BIT(p[i+1])) i++; + return (i+1); +} + +/* the following is for framerelay */ +#define NLPID_LEN 1 /* NLPID is one byte long */ +#define NLPID_Q933 0x08 +#define NLPID_CLNP 0x81 +#define NLPID_ESIS 0x82 +#define NLPID_ISIS 0x83 +#define NLPID_CONS 0x84 +#define NLPID_IDRP 0x85 +#define NLPID_X25_ESIS 0x8a +#define NLPID_IP 0xcc + + +static struct fr_nlpids fr_nlpids[256]; +static fr_nlpid_flag =0; + +void init_fr_nlpids() +{ + int i; + + if (!fr_nlpid_flag) { + for (i=0; i < 256; i++) { + fr_nlpids[i].id = 0; + fr_nlpids[i].name = "Not Specified"; + } + fr_nlpids[NLPID_Q933].name = "Q.933"; + fr_nlpids[NLPID_CLNP].name = "CLNP"; + fr_nlpids[NLPID_ESIS].name = "ESIS"; + fr_nlpids[NLPID_ISIS].name = "ISIS"; + fr_nlpids[NLPID_CONS].name = "CONS"; + fr_nlpids[NLPID_IDRP].name = "IDRP"; + fr_nlpids[NLPID_X25_ESIS].name = "X25_ESIS"; + fr_nlpids[NLPID_IP].name = "IP"; + } + fr_nlpid_flag = 1; +} + +/* Framerelay packet structure */ + +/* + +---------------------------+ + | flag (7E hexadecimal) | + +---------------------------+ + | Q.922 Address* | + +-- --+ + | | + +---------------------------+ + | Control (UI = 0x03) | + +---------------------------+ + | Optional Pad (0x00) | + +---------------------------+ + | NLPID | + +---------------------------+ + | . | + | . | + | . | + | Data | + | . | + | . | + +---------------------------+ + | Frame Check Sequence | + +-- . --+ + | (two octets) | + +---------------------------+ + | flag (7E hexadecimal) | + +---------------------------+ + + * Q.922 addresses, as presently defined, are two octets and + contain a 10-bit DLCI. In some networks Q.922 addresses + may optionally be increased to three or four octets. + +*/ + +#define FR_PROTOCOL(p) fr_protocol((p)) + +int +fr_hdrlen(const u_char *p) +{ + int hlen; + hlen = fr_addr_len(p)+1; /* addr_len + 0x03 + padding */ + if( p[hlen] ) + return hlen; + else + return hlen+1; +} + +#define LAYER2_LEN(p) (fr_hdrlen((p))+NLPID_LEN) + +int +fr_protocol(const u_char *p) +{ + int hlen; + + hlen = fr_addr_len(p) + 1; + if (p[hlen]) /* check for padding */ + return p[hlen]; + else + return p[hlen+1]; +} + +void +fr_hdlc_print(const u_char *p, int length) +{ + int proto; + int i; + int hlen; + + proto = FR_PROTOCOL(p); + + init_fr_nlpids(); + /* this is kinda kludge since it assumed that DLCI is two bytes. */ + printf("%4d %02x%02x=DLCI(%d) ", length, p[0], p[1], FR_DLCI(p[0],p[1])); + printf("%02x %6s: ", proto, fr_nlpids[proto].name); +} + + + +void +fr_if_print(u_char *user, const struct pcap_pkthdr *h, + register const u_char *p) +{ + register u_int length = h->len; + register u_int caplen = h->caplen; + int frame_relay = 0, + proto = FR_PROTOCOL(p); + + + ts_print(&h->ts); + + if (caplen < fr_hdrlen(p)) { + printf("[|fr]"); + goto out; + } + + /* + * Some printers want to get back at the link level addresses, + * and/or check that they're not walking off the end of the packet. + * Rather than pass them all the way down, we set these globals. + */ + packetp = p; + snapend = p + caplen; + + if (eflag) + fr_hdlc_print(p, length); + + length = length - (fr_hdrlen(p) + NLPID_LEN); + + + switch(FR_PROTOCOL(p)) { + case NLPID_IP: + case ETHERTYPE_IP: + ip_print((const u_char *)(p + LAYER2_LEN(p)), length); + break; + case NLPID_CLNP: + case NLPID_ESIS: + case NLPID_ISIS: + isoclns_print((const u_char *)(p + LAYER2_LEN(p)), length, + caplen, "000000", "000000"); + break; + case NLPID_Q933: + q933_print((const u_char *)(p + LAYER2_LEN(p)), length); + break; + default: + if(!eflag) + fr_hdlc_print(p, length); + if(!xflag) + default_print((const u_char *)(p + LAYER2_LEN(p)), + caplen - LAYER2_LEN(p)); + } + + if (xflag) + default_print((const u_char *)(p + LAYER2_LEN(p)), + caplen - LAYER2_LEN(p)); +out: + putchar('\n'); +} +#else +#include <sys/types.h> +#include <sys/time.h> + +#include <stdio.h> + +#include "interface.h" +void +fr_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +{ + error("not configured for ppp"); + /* NOTREACHED */ +} +#endif + +/* + * Q.933 decoding portion for framerelay specific. + */ + +/* Q.933 packet format + Format of Other Protocols + using Q.933 NLPID + +-------------------------------+ + | Q.922 Address | + +---------------+---------------+ + |Control 0x03 | NLPID 0x08 | + +---------------+---------------+ + | L2 Protocol ID | + | octet 1 | octet 2 | + +-------------------------------+ + | L3 Protocol ID | + | octet 2 | octet 2 | + +-------------------------------+ + | Protocol Data | + +-------------------------------+ + | FCS | + +-------------------------------+ + */ + +/* L2 (Octet 1)- Call Reference Usually is 0x0 */ + +/* + * L2 (Octet 2)- Message Types definition 1 byte long. + */ +/* Call Establish */ +#define MSG_TYPE_ESC_TO_NATIONAL 0x00 +#define MSG_TYPE_ALERT 0x01 +#define MSG_TYPE_CALL_PROCEEDING 0x02 +#define MSG_TYPE_CONNECT 0x07 +#define MSG_TYPE_CONNECT_ACK 0x0F +#define MSG_TYPE_PROGRESS 0x03 +#define MSG_TYPE_SETUP 0x05 +/* Call Clear */ +#define MSG_TYPE_DISCONNECT 0x45 +#define MSG_TYPE_RELEASE 0x4D +#define MSG_TYPE_RELEASE_COMPLETE 0x5A +#define MSG_TYPE_RESTART 0x46 +#define MSG_TYPE_RESTART_ACK 0x4E +/* Status */ +#define MSG_TYPE_STATUS 0x7D +#define MSG_TYPE_STATUS_ENQ 0x75 + +#define ONE_BYTE_IE_MASK 0xF0 + +/* See L2 protocol ID picture above */ +struct q933_header { + u_char call_ref; /* usually is 0 for framerelay PVC */ + u_char msg_type; +}; + +#define REPORT_TYPE_IE 0x01 +#define LINK_VERIFY_IE_91 0x19 +#define LINK_VERIFY_IE_94 0x03 +#define PVC_STATUS_IE 0x07 + +#define MAX_IE_SIZE + +struct common_ie_header { + u_char ie_id; + u_char ie_len; +}; + +#define FULL_STATUS 0 +#define LINK_VERIFY 1 +#define ASYNC_PVC 2 + + +void +q933_print(const u_char *p, int length) +{ + struct q933_header *header = (struct q933_header *)(p+1); + const u_char *ptemp = p; + int ie_type, ie_len; + char *decode_str, temp_str[255]; + struct common_ie_header *ie_p; + + + /* printing out header part */ + printf("Call Ref: %02x, MSG Type: %02x", + header->call_ref, header->msg_type); + switch(header->msg_type) { + case MSG_TYPE_STATUS: + decode_str = "STATUS REPLY"; + break; + case MSG_TYPE_STATUS_ENQ: + decode_str = "STATUS ENQUIRY"; + break; + default: + decode_str = "UNKNOWN MSG Type"; + } + printf(" %s\n", decode_str); + + length = length - 3; + ptemp = ptemp + 3; + + /* Loop through the rest of IE */ + while( length > 0 ) { + if( ptemp[0] & ONE_BYTE_IE_MASK ) { + ie_len = 1; + printf("\t\tOne byte IE: %02x, Content %02x\n", + (*ptemp & 0x70)>>4, (*ptemp & 0x0F)); + length--; + ptemp++; + } + else { /* Multi-byte IE */ + ie_p = (struct common_ie_header *)ptemp; + switch (ie_p->ie_id) { + case REPORT_TYPE_IE: + switch(ptemp[2]) { + case FULL_STATUS: + decode_str = "FULL STATUS"; + break; + case LINK_VERIFY: + decode_str = "LINK VERIFY"; + break; + case ASYNC_PVC: + decode_str = "Async PVC Status"; + break; + default: + decode_str = "Reserved Value"; + } + break; + case LINK_VERIFY_IE_91: + case LINK_VERIFY_IE_94: + sprintf(temp_str,"TX Seq: %3d, RX Seq: %3d", + ptemp[2], ptemp[3]); + decode_str = temp_str; + break; + case PVC_STATUS_IE: + sprintf(temp_str,"DLCI %d: status %s %s", + ((ptemp[2]&0x3f)<<4)+ ((ptemp[3]&0x78)>>3), + ptemp[4] & 0x8 ?"new,":" ", + ptemp[4] & 0x2 ?"Active":"Inactive"); + break; + default: + decode_str = "Non-decoded Value"; + } + printf("\t\tIE: %02X Len: %d, %s\n", + ie_p->ie_id, ie_p->ie_len, decode_str); + length = length - ie_p->ie_len - 2; + ptemp = ptemp + ie_p->ie_len + 2; + } + } + +} + + + + + + diff --git a/contrib/tcpdump/print-token.c b/contrib/tcpdump/print-token.c new file mode 100644 index 0000000..e1dff5b --- /dev/null +++ b/contrib/tcpdump/print-token.c @@ -0,0 +1,165 @@ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 + * 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. + * + * Hacked version of print-ether.c Larry Lile <lile@stdio.com> + */ +#ifndef lint +static const char rcsid[] = + "@(#) $Header$"; +#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 "token.h" + +#include <netinet/in.h> +#include <net/ethernet.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 <netinet/tcpip.h> + +#include <stdio.h> +#include <pcap.h> + +#include "interface.h" +#include "addrtoname.h" +#include "ethertype.h" +#include "llc.h" + +const u_char *packetp; +const u_char *snapend; + +static inline void +token_print(register const u_char *bp, u_int length) +{ + register const struct token_header *tp; + register const struct llc *lp; + u_short ether_type; + + tp = (const struct token_header *)bp; + lp = (struct llc *)(bp + TOKEN_HDR_LEN); + if (IS_SOURCE_ROUTED) + lp = (struct llc *)(bp + TOKEN_HDR_LEN + RIF_LENGTH); + + /* + * Ethertype on ethernet is a short, but ethertype in an llc-snap has + * been defined as 2 u_chars. This is a stupid little hack to fix + * this for now but something better should be done using ntohs() + * XXX + */ + ether_type = ((u_short)lp->ethertype[1] << 16) | lp->ethertype[0]; + + if (qflag) + (void)printf("%s %s %d: ", + etheraddr_string(ESRC(tp)), + etheraddr_string(EDST(tp)), + length); + else + (void)printf("%s %s %s %d: ", + etheraddr_string(ESRC(tp)), + etheraddr_string(EDST(tp)), + etherproto_string(ether_type), + length); +} + +/* + * This is the top level routine of the printer. 'p' is the points + * to the ether header of the packet, 'tvp' is the timestamp, + * 'length' is the length of the packet off the wire, and 'caplen' + * is the number of bytes actually captured. + */ +void +token_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +{ + u_int caplen = h->caplen; + u_int length = h->len; + struct token_header *tp; + u_short ether_type; + extern u_short extracted_ethertype; + u_int route_len = 0; + struct llc *lp; + + tp = (struct token_header *)p; + + ts_print(&h->ts); + + if (caplen < TOKEN_HDR_LEN) { + printf("[|token-ring]"); + goto out; + } + + if (eflag) + token_print(p, length); + + /* + * Some printers want to get back at the ethernet addresses, + * and/or check that they're not walking off the end of the packet. + * Rather than pass them all the way down, we set these globals. + */ + tp = (struct token_header *)p; + + /* Adjust for source routing information in the MAC header */ + if (IS_SOURCE_ROUTED) { + route_len = RIF_LENGTH; + } + + /* Set pointer to llc header, adjusted for routing information */ + lp = (struct llc *)(p + TOKEN_HDR_LEN + route_len); + + packetp = p; + snapend = p + caplen; + + /* Skip over token ring MAC header */ + length -= TOKEN_HDR_LEN + route_len; + caplen -= TOKEN_HDR_LEN + route_len; + p += TOKEN_HDR_LEN + route_len; + + ether_type = ntohs((int)lp->ethertype); + + extracted_ethertype = 0; + /* Try to print the LLC-layer header & higher layers */ + if (llc_print(p, length, caplen, ESRC(tp), EDST(tp)) == 0) { + /* ether_type not known, print raw packet */ + if (!eflag) + token_print((u_char *)tp, length); + if (extracted_ethertype) { + printf("(LLC %s) ", + etherproto_string(htons(extracted_ethertype))); + } + if (!xflag && !qflag) + default_print(p, caplen); + } + if (xflag) + default_print(p, caplen); + out: + putchar('\n'); +} diff --git a/contrib/tcpdump/token.h b/contrib/tcpdump/token.h new file mode 100644 index 0000000..6f28a1e --- /dev/null +++ b/contrib/tcpdump/token.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 1998, Larry Lile + * 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 unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + +#define TOKEN_HDR_LEN 14 +#define IS_SOURCE_ROUTED (tp->ether_shost[0] & 0x80) +#define RIF_LENGTH ((ntohs(tp->rcf) & 0x1f00) >> 8) +#define TOKEN_RING_MAC_LEN 6 +#define ROUTING_SEGMENT_MAX 16 + +struct token_header { + u_char ac; + u_char fc; + u_char ether_dhost[TOKEN_RING_MAC_LEN]; + u_char ether_shost[TOKEN_RING_MAC_LEN]; + u_short rcf; + u_short rseg[ROUTING_SEGMENT_MAX]; +}; + |