]> The Tcpdump Group git mirrors - tcpdump/blob - print-igrp.c
Merge branch 'master' of git+ssh://bpf.tcpdump.org/tcpdump/master/git/tcpdump
[tcpdump] / print-igrp.c
1 /*
2 * Copyright (c) 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
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
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 * Initial contribution from Francis Dupont (francis.dupont@inria.fr)
22 */
23
24 #ifndef lint
25 static const char rcsid[] _U_ =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-igrp.c,v 1.21 2005-04-20 21:01:56 guy Exp $ (LBL)";
27 #endif
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <tcpdump-stdinc.h>
34
35 #include <stdio.h>
36
37 #include "interface.h"
38 #include "addrtoname.h"
39 #include "ip.h"
40 #include "extract.h" /* must come after interface.h */
41
42 /* Cisco IGRP definitions */
43
44 /* IGRP Header */
45
46 struct igrphdr {
47 u_int8_t ig_vop; /* protocol version number / opcode */
48 #define IGRP_V(x) (((x) & 0xf0) >> 4)
49 #define IGRP_OP(x) ((x) & 0x0f)
50 u_int8_t ig_ed; /* edition number */
51 u_int16_t ig_as; /* autonomous system number */
52 u_int16_t ig_ni; /* number of subnet in local net */
53 u_int16_t ig_ns; /* number of networks in AS */
54 u_int16_t ig_nx; /* number of networks ouside AS */
55 u_int16_t ig_sum; /* checksum of IGRP header & data */
56 };
57
58 #define IGRP_UPDATE 1
59 #define IGRP_REQUEST 2
60
61 /* IGRP routing entry */
62
63 struct igrprte {
64 u_int8_t igr_net[3]; /* 3 significant octets of IP address */
65 u_int8_t igr_dly[3]; /* delay in tens of microseconds */
66 u_int8_t igr_bw[3]; /* bandwidth in units of 1 kb/s */
67 u_int8_t igr_mtu[2]; /* MTU in octets */
68 u_int8_t igr_rel; /* percent packets successfully tx/rx */
69 u_int8_t igr_ld; /* percent of channel occupied */
70 u_int8_t igr_hct; /* hop count */
71 };
72
73 #define IGRP_RTE_SIZE 14 /* don't believe sizeof ! */
74
75 static void
76 igrp_entry_print(register struct igrprte *igr, register int is_interior,
77 register int is_exterior)
78 {
79 register u_int delay, bandwidth;
80 u_int metric, mtu;
81
82 if (is_interior)
83 printf(" *.%d.%d.%d", igr->igr_net[0],
84 igr->igr_net[1], igr->igr_net[2]);
85 else if (is_exterior)
86 printf(" X%d.%d.%d.0", igr->igr_net[0],
87 igr->igr_net[1], igr->igr_net[2]);
88 else
89 printf(" %d.%d.%d.0", igr->igr_net[0],
90 igr->igr_net[1], igr->igr_net[2]);
91
92 delay = EXTRACT_24BITS(igr->igr_dly);
93 bandwidth = EXTRACT_24BITS(igr->igr_bw);
94 metric = bandwidth + delay;
95 if (metric > 0xffffff)
96 metric = 0xffffff;
97 mtu = EXTRACT_16BITS(igr->igr_mtu);
98
99 printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops",
100 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
101 igr->igr_rel, igr->igr_ld, metric,
102 mtu, igr->igr_hct);
103 }
104
105 static const struct tok op2str[] = {
106 { IGRP_UPDATE, "update" },
107 { IGRP_REQUEST, "request" },
108 { 0, NULL }
109 };
110
111 void
112 igrp_print(register const u_char *bp, u_int length, const u_char *bp2 _U_)
113 {
114 register struct igrphdr *hdr;
115 register u_char *cp;
116 u_int nint, nsys, next;
117
118 hdr = (struct igrphdr *)bp;
119 cp = (u_char *)(hdr + 1);
120 (void)printf("igrp:");
121
122 /* Header */
123 TCHECK(*hdr);
124 nint = EXTRACT_16BITS(&hdr->ig_ni);
125 nsys = EXTRACT_16BITS(&hdr->ig_ns);
126 next = EXTRACT_16BITS(&hdr->ig_nx);
127
128 (void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)",
129 tok2str(op2str, "op-#%d", IGRP_OP(hdr->ig_vop)),
130 IGRP_V(hdr->ig_vop),
131 hdr->ig_ed,
132 EXTRACT_16BITS(&hdr->ig_as),
133 nint,
134 nsys,
135 next);
136
137 length -= sizeof(*hdr);
138 while (length >= IGRP_RTE_SIZE) {
139 if (nint > 0) {
140 TCHECK2(*cp, IGRP_RTE_SIZE);
141 igrp_entry_print((struct igrprte *)cp, 1, 0);
142 --nint;
143 } else if (nsys > 0) {
144 TCHECK2(*cp, IGRP_RTE_SIZE);
145 igrp_entry_print((struct igrprte *)cp, 0, 0);
146 --nsys;
147 } else if (next > 0) {
148 TCHECK2(*cp, IGRP_RTE_SIZE);
149 igrp_entry_print((struct igrprte *)cp, 0, 1);
150 --next;
151 } else {
152 (void)printf(" [extra bytes %d]", length);
153 break;
154 }
155 cp += IGRP_RTE_SIZE;
156 length -= IGRP_RTE_SIZE;
157 }
158 if (nint == 0 && nsys == 0 && next == 0)
159 return;
160 trunc:
161 fputs(" [|igrp]", stdout);
162 }