print-atm.c (98527) | print-atm.c (127675) |
---|---|
1/* 2 * Copyright (c) 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 4 unchanged lines hidden (view full) --- 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * | 1/* 2 * Copyright (c) 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 4 unchanged lines hidden (view full) --- 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * |
21 * $FreeBSD: head/contrib/tcpdump/print-atm.c 98527 2002-06-21 00:49:02Z fenner $ | 21 * $FreeBSD: head/contrib/tcpdump/print-atm.c 127675 2004-03-31 14:57:24Z bms $ |
22 */ 23#ifndef lint | 22 */ 23#ifndef lint |
24static const char rcsid[] = 25 "@(#) $Header: /tcpdump/master/tcpdump/print-atm.c,v 1.21 2001/07/05 18:54:14 guy Exp $ (LBL)"; | 24static const char rcsid[] _U_ = 25 "@(#) $Header: /tcpdump/master/tcpdump/print-atm.c,v 1.33.2.2 2003/11/16 08:51:11 guy Exp $ (LBL)"; |
26#endif 27 28#ifdef HAVE_CONFIG_H 29#include "config.h" 30#endif 31 | 26#endif 27 28#ifdef HAVE_CONFIG_H 29#include "config.h" 30#endif 31 |
32#include <sys/param.h> 33#include <sys/time.h> 34#include <sys/socket.h> | 32#include <tcpdump-stdinc.h> |
35 | 33 |
36#include <netinet/in.h> 37 | |
38#include <stdio.h> 39#include <pcap.h> | 34#include <stdio.h> 35#include <pcap.h> |
36#include <string.h> |
|
40 41#include "interface.h" | 37 38#include "interface.h" |
39#include "extract.h" |
|
42#include "addrtoname.h" 43#include "ethertype.h" | 40#include "addrtoname.h" 41#include "ethertype.h" |
42#include "atm.h" 43#include "atmuni31.h" 44#include "llc.h" |
|
44 | 45 |
46#include "ether.h" 47 |
|
45/* | 48/* |
46 * This is the top level routine of the printer. 'p' is the points 47 * to the LLC/SNAP header of the packet, 'tvp' is the timestamp, 48 * 'length' is the length of the packet off the wire, and 'caplen' | 49 * Print an RFC 1483 LLC-encapsulated ATM frame. 50 */ 51static void 52atm_llc_print(const u_char *p, int length, int caplen) 53{ 54 u_short extracted_ethertype; 55 56 if (!llc_print(p, length, caplen, NULL, NULL, 57 &extracted_ethertype)) { 58 /* ether_type not known, print raw packet */ 59 if (extracted_ethertype) { 60 printf("(LLC %s) ", 61 etherproto_string(htons(extracted_ethertype))); 62 } 63 if (!xflag && !qflag) 64 default_print(p, caplen); 65 } 66} 67 68/* 69 * Given a SAP value, generate the LLC header value for a UI packet 70 * with that SAP as the source and destination SAP. 71 */ 72#define LLC_UI_HDR(sap) ((sap)<<16 | (sap<<8) | 0x03) 73 74/* 75 * This is the top level routine of the printer. 'p' points 76 * to the LLC/SNAP header of the packet, 'h->ts' is the timestamp, 77 * 'h->length' is the length of the packet off the wire, and 'h->caplen' |
49 * is the number of bytes actually captured. 50 */ | 78 * is the number of bytes actually captured. 79 */ |
51void 52atm_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) | 80u_int 81atm_if_print(const struct pcap_pkthdr *h, const u_char *p) |
53{ 54 u_int caplen = h->caplen; 55 u_int length = h->len; | 82{ 83 u_int caplen = h->caplen; 84 u_int length = h->len; |
56 u_short ethertype, extracted_ethertype; | 85 u_int32_t llchdr; 86 u_int hdrlen = 0; |
57 | 87 |
58 ++infodelay; 59 ts_print(&h->ts); 60 | |
61 if (caplen < 8) { 62 printf("[|atm]"); | 88 if (caplen < 8) { 89 printf("[|atm]"); |
63 goto out; | 90 return (caplen); |
64 } | 91 } |
65 66 if (p[4] == 0xaa || p[5] == 0xaa || p[6] == 0x03) { 67 /* if first 4 bytes are cookie/vpci */ 68 if (eflag) { 69 printf("%04x ", 70 p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]); 71 } 72 p += 4; 73 length -= 4; 74 caplen -= 4; 75 } 76 else if (p[0] != 0xaa || p[1] != 0xaa || p[2] != 0x03) { 77 /*XXX assume 802.6 MAC header from fore driver */ | 92 /* 93 * Extract the presumed LLC header into a variable, for quick 94 * testing. 95 * Then check for a header that's neither a header for a SNAP 96 * packet nor an RFC 2684 routed NLPID-formatted PDU nor 97 * an 802.2-but-no-SNAP IP packet. 98 */ 99 llchdr = EXTRACT_24BITS(p); 100 if (llchdr != LLC_UI_HDR(LLCSAP_SNAP) && 101 llchdr != LLC_UI_HDR(LLCSAP_ISONS) && 102 llchdr != LLC_UI_HDR(LLCSAP_IP)) { 103 /* 104 * XXX - assume 802.6 MAC header from Fore driver. 105 * 106 * Unfortunately, the above list doesn't check for 107 * all known SAPs, doesn't check for headers where 108 * the source and destination SAP aren't the same, 109 * and doesn't check for non-UI frames. It also 110 * runs the risk of an 802.6 MAC header that happens 111 * to begin with one of those values being 112 * incorrectly treated as an 802.2 header. 113 * 114 * So is that Fore driver still around? And, if so, 115 * is it still putting 802.6 MAC headers on ATM 116 * packets? If so, could it be changed to use a 117 * new DLT_IEEE802_6 value if we added it? 118 */ |
78 if (eflag) | 119 if (eflag) |
79 printf("%04x%04x %04x%04x ", 80 p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3], 81 p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7], 82 p[8] << 24 | p[9] << 16 | p[10] << 8 | p[11], 83 p[12] << 24 | p[13] << 16 | p[14] << 8 | p[15]); | 120 printf("%08x%08x %08x%08x ", 121 EXTRACT_32BITS(p), 122 EXTRACT_32BITS(p+4), 123 EXTRACT_32BITS(p+8), 124 EXTRACT_32BITS(p+12)); |
84 p += 20; 85 length -= 20; 86 caplen -= 20; | 125 p += 20; 126 length -= 20; 127 caplen -= 20; |
128 hdrlen += 20; |
|
87 } | 129 } |
88 ethertype = p[6] << 8 | p[7]; | 130 atm_llc_print(p, length, caplen); 131 return (hdrlen); 132} 133 134/* 135 * ATM signalling. 136 */ 137static struct tok msgtype2str[] = { 138 { CALL_PROCEED, "Call_proceeding" }, 139 { CONNECT, "Connect" }, 140 { CONNECT_ACK, "Connect_ack" }, 141 { SETUP, "Setup" }, 142 { RELEASE, "Release" }, 143 { RELEASE_DONE, "Release_complete" }, 144 { RESTART, "Restart" }, 145 { RESTART_ACK, "Restart_ack" }, 146 { STATUS, "Status" }, 147 { STATUS_ENQ, "Status_enquiry" }, 148 { ADD_PARTY, "Add_party" }, 149 { ADD_PARTY_ACK, "Add_party_ack" }, 150 { ADD_PARTY_REJ, "Add_party_reject" }, 151 { DROP_PARTY, "Drop_party" }, 152 { DROP_PARTY_ACK, "Drop_party_ack" }, 153 { 0, NULL } 154}; 155 156static void 157sig_print(const u_char *p, int caplen) 158{ 159 bpf_u_int32 call_ref; 160 161 if (caplen < PROTO_POS) { 162 printf("[|atm]"); 163 return; 164 } 165 if (p[PROTO_POS] == Q2931) { 166 /* 167 * protocol:Q.2931 for User to Network Interface 168 * (UNI 3.1) signalling 169 */ 170 printf("Q.2931"); 171 if (caplen < MSG_TYPE_POS) { 172 printf(" [|atm]"); 173 return; 174 } 175 printf(":%s ", 176 tok2str(msgtype2str, "msgtype#%d", p[MSG_TYPE_POS])); 177 178 if (caplen < CALL_REF_POS+3) { 179 printf("[|atm]"); 180 return; 181 } 182 call_ref = EXTRACT_24BITS(&p[CALL_REF_POS]); 183 printf("CALL_REF:0x%06x", call_ref); 184 } else { 185 /* SCCOP with some unknown protocol atop it */ 186 printf("SSCOP, proto %d ", p[PROTO_POS]); 187 } 188} 189 190/* 191 * Print an ATM PDU (such as an AAL5 PDU). 192 */ 193void 194atm_print(u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length, 195 u_int caplen) 196{ |
89 if (eflag) | 197 if (eflag) |
90 printf("%02x %02x %02x %02x-%02x-%02x %04x: ", 91 p[0], p[1], p[2], /* dsap/ssap/ctrl */ 92 p[3], p[4], p[5], /* manufacturer's code */ 93 ethertype); | 198 printf("VPI:%u VCI:%u ", vpi, vci); |
94 | 199 |
95 /* 96 * Some printers want to get back at the ethernet addresses, 97 * and/or check that they're not walking off the end of the packet. 98 * Rather than pass them all the way down, we set these globals. 99 */ 100 packetp = p; 101 snapend = p + caplen; | 200 if (vpi == 0) { 201 switch (vci) { |
102 | 202 |
103 length -= 8; 104 caplen -= 8; 105 p += 8; | 203 case PPC: 204 sig_print(p, caplen); 205 return; |
106 | 206 |
107 switch (ethertype) { | 207 case BCC: 208 printf("broadcast sig: "); 209 return; |
108 | 210 |
109 case ETHERTYPE_IP: 110 ip_print(p, length); 111 break; | 211 case OAMF4SC: 212 printf("oamF4(segment): "); 213 return; |
112 | 214 |
113#ifdef INET6 114 case ETHERTYPE_IPV6: 115 ip6_print(p, length); 116 break; 117#endif /*INET6*/ | 215 case OAMF4EC: 216 printf("oamF4(end): "); 217 return; |
118 | 218 |
119 /*XXX this probably isn't right */ 120 case ETHERTYPE_ARP: 121 case ETHERTYPE_REVARP: 122 arp_print(p, length, caplen); 123 break; 124#ifdef notyet 125 case ETHERTYPE_DN: 126 decnet_print(p, length, caplen); 127 break; | 219 case METAC: 220 printf("meta: "); 221 return; |
128 | 222 |
129 case ETHERTYPE_ATALK: 130 if (vflag) 131 fputs("et1 ", stdout); 132 atalk_print(p, length); 133 break; | 223 case ILMIC: 224 printf("ilmi: "); 225 snmp_print(p, length); 226 return; 227 } 228 } |
134 | 229 |
135 case ETHERTYPE_AARP: 136 aarp_print(p, length); 137 break; | 230 switch (traftype) { |
138 | 231 |
139 case ETHERTYPE_LAT: 140 case ETHERTYPE_MOPRC: 141 case ETHERTYPE_MOPDL: 142 /* default_print for now */ 143#endif | 232 case ATM_LLC: |
144 default: | 233 default: |
145 /* ether_type not known, forward it to llc_print */ 146 if (!eflag) 147 printf("%02x %02x %02x %02x-%02x-%02x %04x: ", 148 packetp[0], packetp[1], packetp[2], /* dsap/ssap/ctrl */ 149 packetp[3], packetp[4], packetp[5], /* manufacturer's code */ 150 ethertype); 151 if (!xflag && !qflag) { 152 extracted_ethertype = 0; 153 /* default_print(p, caplen); */ 154 llc_print(p-8,length+8,caplen+8,"000000","000000", &extracted_ethertype); 155 } | 234 /* 235 * Assumes traffic is LLC if unknown. 236 */ 237 atm_llc_print(p, length, caplen); 238 break; 239 240 case ATM_LANE: 241 lane_print(p, length, caplen); 242 break; |
156 } | 243 } |
157 if (xflag) 158 default_print(p, caplen); 159 out: 160 putchar('\n'); 161 --infodelay; 162 if (infoprint) 163 info(0); | |
164} | 244} |