]> The Tcpdump Group git mirrors - tcpdump/blob - print-igrp.c
Squelch a Coverity warning.
[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 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <netdissect-stdinc.h>
29
30 #include "netdissect.h"
31 #include "extract.h"
32
33 /* Cisco IGRP definitions */
34
35 /* IGRP Header */
36
37 struct igrphdr {
38 uint8_t ig_vop; /* protocol version number / opcode */
39 #define IGRP_V(x) (((x) & 0xf0) >> 4)
40 #define IGRP_OP(x) ((x) & 0x0f)
41 uint8_t ig_ed; /* edition number */
42 uint16_t ig_as; /* autonomous system number */
43 uint16_t ig_ni; /* number of subnet in local net */
44 uint16_t ig_ns; /* number of networks in AS */
45 uint16_t ig_nx; /* number of networks ouside AS */
46 uint16_t ig_sum; /* checksum of IGRP header & data */
47 };
48
49 #define IGRP_UPDATE 1
50 #define IGRP_REQUEST 2
51
52 /* IGRP routing entry */
53
54 struct igrprte {
55 uint8_t igr_net[3]; /* 3 significant octets of IP address */
56 uint8_t igr_dly[3]; /* delay in tens of microseconds */
57 uint8_t igr_bw[3]; /* bandwidth in units of 1 kb/s */
58 uint8_t igr_mtu[2]; /* MTU in octets */
59 uint8_t igr_rel; /* percent packets successfully tx/rx */
60 uint8_t igr_ld; /* percent of channel occupied */
61 uint8_t igr_hct; /* hop count */
62 };
63
64 #define IGRP_RTE_SIZE 14 /* don't believe sizeof ! */
65
66 static void
67 igrp_entry_print(netdissect_options *ndo, register const struct igrprte *igr,
68 register int is_interior, register int is_exterior)
69 {
70 register u_int delay, bandwidth;
71 u_int metric, mtu;
72
73 if (is_interior)
74 ND_PRINT((ndo, " *.%d.%d.%d", igr->igr_net[0],
75 igr->igr_net[1], igr->igr_net[2]));
76 else if (is_exterior)
77 ND_PRINT((ndo, " X%d.%d.%d.0", igr->igr_net[0],
78 igr->igr_net[1], igr->igr_net[2]));
79 else
80 ND_PRINT((ndo, " %d.%d.%d.0", igr->igr_net[0],
81 igr->igr_net[1], igr->igr_net[2]));
82
83 delay = EXTRACT_24BITS(igr->igr_dly);
84 bandwidth = EXTRACT_24BITS(igr->igr_bw);
85 metric = bandwidth + delay;
86 if (metric > 0xffffff)
87 metric = 0xffffff;
88 mtu = EXTRACT_16BITS(igr->igr_mtu);
89
90 ND_PRINT((ndo, " d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops",
91 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
92 igr->igr_rel, igr->igr_ld, metric,
93 mtu, igr->igr_hct));
94 }
95
96 static const struct tok op2str[] = {
97 { IGRP_UPDATE, "update" },
98 { IGRP_REQUEST, "request" },
99 { 0, NULL }
100 };
101
102 void
103 igrp_print(netdissect_options *ndo, register const u_char *bp, u_int length)
104 {
105 register const struct igrphdr *hdr;
106 register const u_char *cp;
107 u_int nint, nsys, next;
108
109 hdr = (const struct igrphdr *)bp;
110 cp = (const u_char *)(hdr + 1);
111 ND_PRINT((ndo, "igrp:"));
112
113 /* Header */
114 ND_TCHECK(*hdr);
115 nint = EXTRACT_16BITS(&hdr->ig_ni);
116 nsys = EXTRACT_16BITS(&hdr->ig_ns);
117 next = EXTRACT_16BITS(&hdr->ig_nx);
118
119 ND_PRINT((ndo, " %s V%d edit=%d AS=%d (%d/%d/%d)",
120 tok2str(op2str, "op-#%d", IGRP_OP(hdr->ig_vop)),
121 IGRP_V(hdr->ig_vop),
122 hdr->ig_ed,
123 EXTRACT_16BITS(&hdr->ig_as),
124 nint,
125 nsys,
126 next));
127
128 length -= sizeof(*hdr);
129 while (length >= IGRP_RTE_SIZE) {
130 if (nint > 0) {
131 ND_TCHECK2(*cp, IGRP_RTE_SIZE);
132 igrp_entry_print(ndo, (const struct igrprte *)cp, 1, 0);
133 --nint;
134 } else if (nsys > 0) {
135 ND_TCHECK2(*cp, IGRP_RTE_SIZE);
136 igrp_entry_print(ndo, (const struct igrprte *)cp, 0, 0);
137 --nsys;
138 } else if (next > 0) {
139 ND_TCHECK2(*cp, IGRP_RTE_SIZE);
140 igrp_entry_print(ndo, (const struct igrprte *)cp, 0, 1);
141 --next;
142 } else {
143 ND_PRINT((ndo, " [extra bytes %d]", length));
144 break;
145 }
146 cp += IGRP_RTE_SIZE;
147 length -= IGRP_RTE_SIZE;
148 }
149 if (nint == 0 && nsys == 0 && next == 0)
150 return;
151 trunc:
152 ND_PRINT((ndo, " [|igrp]"));
153 }