1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SNOOP_H 28 #define _SNOOP_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" /* SunOS */ 31 32 #include <rpc/types.h> 33 #include <sys/pfmod.h> 34 #include <sys/time.h> 35 #include <sys/types.h> 36 #include <sys/socket.h> 37 #include <net/if.h> 38 #include <netinet/in.h> 39 #include <netinet/if_ether.h> 40 #include <netinet/in_systm.h> 41 #include <netinet/ip.h> 42 #include <netinet/ip6.h> 43 #include <netinet/ip_icmp.h> 44 #include <netinet/icmp6.h> 45 #include <net/pppoe.h> 46 47 #ifdef __cplusplus 48 extern "C" { 49 #endif 50 51 /* 52 * Flags to control packet info display 53 */ 54 #define F_NOW 0x00000001 /* display in realtime */ 55 #define F_SUM 0x00000002 /* display summary line */ 56 #define F_ALLSUM 0x00000004 /* display all summary lines */ 57 #define F_DTAIL 0x00000008 /* display detail lines */ 58 #define F_TIME 0x00000010 /* display time */ 59 #define F_ATIME 0x00000020 /* display absolute time */ 60 #define F_RTIME 0x00000040 /* display relative time */ 61 #define F_DROPS 0x00000080 /* display drops */ 62 #define F_LEN 0x00000100 /* display pkt length */ 63 #define F_NUM 0x00000200 /* display pkt number */ 64 #define F_WHO 0x00000400 /* display src/dst */ 65 66 #define MAXLINE (1088) /* max len of detail line */ 67 68 #define MAX_HDRTRAILER (64) /* max hdr/trailer packet slack */ 69 70 /* 71 * The RPC XID cache structure. 72 * When analyzing RPC protocols we 73 * have to cache the xid of the RPC 74 * request together with the program 75 * number, proc, version etc since this 76 * information is missing in the reply 77 * packet. Using the xid in the reply 78 * we can lookup this previously stashed 79 * information in the cache. 80 * 81 * For RPCSEC_GSS flavor, some special processing is 82 * needed for the argument interpretation based on its 83 * control procedure and service type. This information 84 * is stored in the cache table during interpretation of 85 * the rpc header and will be referenced later when the rpc 86 * argument is interpreted. 87 */ 88 #define XID_CACHE_SIZE 256 89 struct cache_struct { 90 int xid_num; /* RPC transaction id */ 91 int xid_frame; /* Packet number */ 92 int xid_prog; /* RPC program number */ 93 int xid_vers; /* RPC version number */ 94 int xid_proc; /* RPC procedure number */ 95 unsigned int xid_gss_proc; /* control procedure */ 96 int xid_gss_service; /* none, integ, priv */ 97 } xid_cache[XID_CACHE_SIZE]; 98 99 100 /* 101 * The following macros advance the pointer passed to them. They 102 * assume they are given a char *. 103 */ 104 #define GETINT8(v, ptr) { \ 105 (v) = (*(ptr)++); \ 106 } 107 108 #define GETINT16(v, ptr) { \ 109 (v) = *(ptr)++ << 8; \ 110 (v) |= *(ptr)++; \ 111 } 112 113 #define GETINT32(v, ptr) { \ 114 (v) = *(ptr)++ << 8; \ 115 (v) |= *(ptr)++; (v) <<= 8; \ 116 (v) |= *(ptr)++; (v) <<= 8; \ 117 (v) |= *(ptr)++; \ 118 } 119 120 /* 121 * Used to print nested protocol layers. For example, an ip datagram included 122 * in an icmp error, or a PPP packet included in an LCP protocol reject.. 123 */ 124 extern char *prot_nest_prefix; 125 126 extern char *get_sum_line(void); 127 extern char *get_detail_line(int, int); 128 extern struct timeval prev_time; 129 extern char *getflag(int, int, char *, char *); 130 extern void show_header(char *, char *, int); 131 extern void xdr_init(char *, int); 132 extern char *get_line(int, int); 133 extern int get_line_remain(void); 134 extern char getxdr_char(void); 135 extern char showxdr_char(char *); 136 extern uchar_t getxdr_u_char(void); 137 extern uchar_t showxdr_u_char(char *); 138 extern short getxdr_short(void); 139 extern short showxdr_short(char *); 140 extern ushort_t getxdr_u_short(void); 141 extern ushort_t showxdr_u_short(char *); 142 extern long getxdr_long(void); 143 extern long showxdr_long(char *); 144 extern ulong_t getxdr_u_long(void); 145 extern ulong_t showxdr_u_long(char *); 146 extern longlong_t getxdr_longlong(void); 147 extern longlong_t showxdr_longlong(char *); 148 extern ulonglong_t getxdr_u_longlong(void); 149 extern ulonglong_t showxdr_u_longlong(char *); 150 extern char *getxdr_opaque(char *, int); 151 extern char *getxdr_string(char *, int); 152 extern char *showxdr_string(int, char *); 153 extern char *getxdr_bytes(uint_t *); 154 extern void xdr_skip(int); 155 extern int getxdr_pos(void); 156 extern void setxdr_pos(int); 157 extern char *getxdr_context(char *, int); 158 extern char *showxdr_context(char *); 159 extern enum_t getxdr_enum(void); 160 extern void show_space(void); 161 extern void show_trailer(void); 162 extern char *getxdr_date(void); 163 extern char *showxdr_date(char *); 164 extern char *getxdr_date_ns(void); 165 char *format_time(int64_t sec, uint32_t nsec); 166 extern char *showxdr_date_ns(char *); 167 extern char *getxdr_hex(int); 168 extern char *showxdr_hex(int, char *); 169 extern bool_t getxdr_bool(void); 170 extern bool_t showxdr_bool(char *); 171 extern char *concat_args(char **, int); 172 extern int pf_compile(char *, int); 173 extern void compile(char *, int); 174 extern void load_names(char *); 175 extern void cap_open_read(char *); 176 extern void cap_open_write(char *); 177 extern void cap_read(int, int, int, void (*)(), int); 178 extern void cap_close(void); 179 extern int check_device(char **, int *); 180 extern void initdevice(char *, ulong_t, ulong_t, struct timeval *, 181 struct Pf_ext_packetfilt *, int); 182 extern void net_read(int, int, void (*)(), int); 183 extern void click(int); 184 extern void show_pktinfo(int, int, char *, char *, struct timeval *, 185 struct timeval *, int, int); 186 extern void show_line(char *); 187 extern char *getxdr_time(void); 188 extern char *showxdr_time(char *); 189 extern char *addrtoname(int, void *); 190 extern char *show_string(const char *, int, int); 191 extern void pr_err(char *, ...); 192 extern void check_retransmit(char *, ulong_t); 193 extern char *nameof_prog(int); 194 extern char *getproto(int); 195 extern uint8_t print_ipv6_extensions(int, uint8_t **, uint8_t *, int *, int *); 196 extern void protoprint(int, int, ulong_t, int, int, int, char *, int); 197 extern char *getportname(int, in_port_t); 198 199 extern void interpret_arp(int, struct arphdr *, int); 200 extern void interpret_bparam(int, int, int, int, int, char *, int); 201 extern void interpret_dns(int, int, const uchar_t *, int); 202 extern void interpret_mount(int, int, int, int, int, char *, int); 203 extern void interpret_nfs(int, int, int, int, int, char *, int); 204 extern void interpret_nfs3(int, int, int, int, int, char *, int); 205 extern void interpret_nfs4(int, int, int, int, int, char *, int); 206 extern void interpret_nfs4_cb(int, int, int, int, int, char *, int); 207 extern void interpret_nfs_acl(int, int, int, int, int, char *, int); 208 extern void interpret_nis(int, int, int, int, int, char *, int); 209 extern void interpret_nisbind(int, int, int, int, int, char *, int); 210 extern void interpret_nisp_cb(int, int, int, int, int, char *, int); 211 extern void interpret_nisplus(int, int, int, int, int, char *, int); 212 extern void interpret_nlm(int, int, int, int, int, char *, int); 213 extern void interpret_pmap(int, int, int, int, int, char *, int); 214 extern int interpret_reserved(int, int, in_port_t, in_port_t, char *, int); 215 extern void interpret_rquota(int, int, int, int, int, char *, int); 216 extern void interpret_rstat(int, int, int, int, int, char *, int); 217 extern void interpret_solarnet_fw(int, int, int, int, int, char *, int); 218 extern void interpret_ldap(int, char *, int, int, int); 219 extern void interpret_icmp(int, struct icmp *, int, int); 220 extern void interpret_icmpv6(int, icmp6_t *, int, int); 221 extern int interpret_ip(int, struct ip *, int); 222 extern int interpret_ipv6(int, ip6_t *, int); 223 extern int interpret_ppp(int, uchar_t *, int); 224 extern int interpret_pppoe(int, poep_t *, int); 225 extern void init_ldap(void); 226 extern boolean_t arp_for_ether(char *, struct ether_addr *); 227 extern char *ether_ouiname(uint32_t); 228 char *tohex(char *p, int len); 229 extern char *printether(struct ether_addr *); 230 extern char *print_ethertype(int); 231 232 /* 233 * Describes characteristics of the Media Access Layer. 234 * The mac_type is one of the supported DLPI media 235 * types (see <sys/dlpi.h>). 236 * The mtu_size is the size of the largest frame. 237 * The header length is returned by a function to 238 * allow for variable header size - for ethernet it's 239 * just a constant 14 octets. 240 * The interpreter is the function that "knows" how 241 * to interpret the frame. 242 */ 243 typedef struct interface { 244 uint_t mac_type; 245 uint_t mtu_size; 246 uint_t (*header_len)(char *); 247 uint_t (*interpreter)(int, char *, int, int); 248 uint_t mac_hdr_fixed_size; 249 } interface_t; 250 251 #define IF_HDR_FIXED 0 252 #define IF_HDR_VAR 1 253 254 extern interface_t INTERFACES[], *interface; 255 extern char *device; 256 257 extern char *dlc_header; 258 259 /* 260 * Global error recovery routine: used to reset snoop variables after 261 * catastrophic failure. 262 */ 263 void snoop_recover(void); 264 265 /* 266 * Global alarm handler structure for managing multiple alarms within 267 * snoop. 268 */ 269 static struct snoop_handler; 270 typedef struct snoop_handler { 271 struct snoop_handler *s_next; /* next alarm handler */ 272 time_t s_time; /* time to fire */ 273 void (*s_handler)(); /* alarm handler */ 274 } snoop_handler_t; 275 276 #define SNOOP_MAXRECOVER 20 /* maxium number of recoveries */ 277 #define SNOOP_ALARM_GRAN 3 /* alarm() timeout multiplier */ 278 279 /* 280 * Global alarm handler management routine. 281 */ 282 extern int snoop_alarm(int s_sec, void (*s_handler)()); 283 284 #ifdef __cplusplus 285 } 286 #endif 287 288 #endif /* _SNOOP_H */ 289