1*05b00f60SXin Li /*
2*05b00f60SXin Li * Copyright (c) 1996, 1997
3*05b00f60SXin Li * The Regents of the University of California. All rights reserved.
4*05b00f60SXin Li *
5*05b00f60SXin Li * Redistribution and use in source and binary forms, with or without
6*05b00f60SXin Li * modification, are permitted provided that: (1) source code distributions
7*05b00f60SXin Li * retain the above copyright notice and this paragraph in its entirety, (2)
8*05b00f60SXin Li * distributions including binary code include the above copyright notice and
9*05b00f60SXin Li * this paragraph in its entirety in the documentation or other materials
10*05b00f60SXin Li * provided with the distribution, and (3) all advertising materials mentioning
11*05b00f60SXin Li * features or use of this software display the following acknowledgement:
12*05b00f60SXin Li * ``This product includes software developed by the University of California,
13*05b00f60SXin Li * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14*05b00f60SXin Li * the University nor the names of its contributors may be used to endorse
15*05b00f60SXin Li * or promote products derived from this software without specific prior
16*05b00f60SXin Li * written permission.
17*05b00f60SXin Li * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18*05b00f60SXin Li * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19*05b00f60SXin Li * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20*05b00f60SXin Li *
21*05b00f60SXin Li * Initial contribution from Francis Dupont ([email protected])
22*05b00f60SXin Li */
23*05b00f60SXin Li
24*05b00f60SXin Li /* \summary: Interior Gateway Routing Protocol (IGRP) printer */
25*05b00f60SXin Li
26*05b00f60SXin Li #ifdef HAVE_CONFIG_H
27*05b00f60SXin Li #include <config.h>
28*05b00f60SXin Li #endif
29*05b00f60SXin Li
30*05b00f60SXin Li #include "netdissect-stdinc.h"
31*05b00f60SXin Li
32*05b00f60SXin Li #include "netdissect.h"
33*05b00f60SXin Li #include "extract.h"
34*05b00f60SXin Li
35*05b00f60SXin Li /* Cisco IGRP definitions */
36*05b00f60SXin Li
37*05b00f60SXin Li /* IGRP Header */
38*05b00f60SXin Li
39*05b00f60SXin Li struct igrphdr {
40*05b00f60SXin Li nd_uint8_t ig_vop; /* protocol version number / opcode */
41*05b00f60SXin Li #define IGRP_V(x) (((x) & 0xf0) >> 4)
42*05b00f60SXin Li #define IGRP_OP(x) ((x) & 0x0f)
43*05b00f60SXin Li nd_uint8_t ig_ed; /* edition number */
44*05b00f60SXin Li nd_uint16_t ig_as; /* autonomous system number */
45*05b00f60SXin Li nd_uint16_t ig_ni; /* number of subnet in local net */
46*05b00f60SXin Li nd_uint16_t ig_ns; /* number of networks in AS */
47*05b00f60SXin Li nd_uint16_t ig_nx; /* number of networks outside AS */
48*05b00f60SXin Li nd_uint16_t ig_sum; /* checksum of IGRP header & data */
49*05b00f60SXin Li };
50*05b00f60SXin Li
51*05b00f60SXin Li #define IGRP_UPDATE 1
52*05b00f60SXin Li #define IGRP_REQUEST 2
53*05b00f60SXin Li
54*05b00f60SXin Li /* IGRP routing entry */
55*05b00f60SXin Li
56*05b00f60SXin Li struct igrprte {
57*05b00f60SXin Li nd_byte igr_net[3]; /* 3 significant octets of IP address */
58*05b00f60SXin Li nd_uint24_t igr_dly; /* delay in tens of microseconds */
59*05b00f60SXin Li nd_uint24_t igr_bw; /* bandwidth in units of 1 kb/s */
60*05b00f60SXin Li nd_uint16_t igr_mtu; /* MTU in octets */
61*05b00f60SXin Li nd_uint8_t igr_rel; /* percent packets successfully tx/rx */
62*05b00f60SXin Li nd_uint8_t igr_ld; /* percent of channel occupied */
63*05b00f60SXin Li nd_uint8_t igr_hct; /* hop count */
64*05b00f60SXin Li };
65*05b00f60SXin Li
66*05b00f60SXin Li #define IGRP_RTE_SIZE 14 /* sizeof() is accurate now */
67*05b00f60SXin Li
68*05b00f60SXin Li static void
igrp_entry_print(netdissect_options * ndo,const struct igrprte * igr)69*05b00f60SXin Li igrp_entry_print(netdissect_options *ndo, const struct igrprte *igr)
70*05b00f60SXin Li {
71*05b00f60SXin Li u_int delay, bandwidth;
72*05b00f60SXin Li u_int metric, mtu;
73*05b00f60SXin Li
74*05b00f60SXin Li delay = GET_BE_U_3(igr->igr_dly);
75*05b00f60SXin Li bandwidth = GET_BE_U_3(igr->igr_bw);
76*05b00f60SXin Li metric = ND_MIN(bandwidth + delay, 0xffffff);
77*05b00f60SXin Li mtu = GET_BE_U_2(igr->igr_mtu);
78*05b00f60SXin Li
79*05b00f60SXin Li ND_PRINT(" d=%u b=%u r=%u l=%u M=%u mtu=%u in %u hops",
80*05b00f60SXin Li 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
81*05b00f60SXin Li GET_U_1(igr->igr_rel), GET_U_1(igr->igr_ld), metric,
82*05b00f60SXin Li mtu, GET_U_1(igr->igr_hct));
83*05b00f60SXin Li }
84*05b00f60SXin Li
85*05b00f60SXin Li static const struct tok op2str[] = {
86*05b00f60SXin Li { IGRP_UPDATE, "update" },
87*05b00f60SXin Li { IGRP_REQUEST, "request" },
88*05b00f60SXin Li { 0, NULL }
89*05b00f60SXin Li };
90*05b00f60SXin Li
91*05b00f60SXin Li void
igrp_print(netdissect_options * ndo,const u_char * bp,u_int length)92*05b00f60SXin Li igrp_print(netdissect_options *ndo, const u_char *bp, u_int length)
93*05b00f60SXin Li {
94*05b00f60SXin Li const struct igrphdr *hdr;
95*05b00f60SXin Li const u_char *cp;
96*05b00f60SXin Li u_int nint, nsys, next;
97*05b00f60SXin Li uint16_t cksum;
98*05b00f60SXin Li
99*05b00f60SXin Li ndo->ndo_protocol = "igrp";
100*05b00f60SXin Li hdr = (const struct igrphdr *)bp;
101*05b00f60SXin Li cp = (const u_char *)(hdr + 1);
102*05b00f60SXin Li ND_PRINT("igrp:");
103*05b00f60SXin Li
104*05b00f60SXin Li /* Header */
105*05b00f60SXin Li nint = GET_BE_U_2(hdr->ig_ni);
106*05b00f60SXin Li nsys = GET_BE_U_2(hdr->ig_ns);
107*05b00f60SXin Li next = GET_BE_U_2(hdr->ig_nx);
108*05b00f60SXin Li
109*05b00f60SXin Li ND_PRINT(" %s V%u edit=%u AS=%u (%u/%u/%u)",
110*05b00f60SXin Li tok2str(op2str, "op-#%u", IGRP_OP(GET_U_1(hdr->ig_vop))),
111*05b00f60SXin Li IGRP_V(GET_U_1(hdr->ig_vop)),
112*05b00f60SXin Li GET_U_1(hdr->ig_ed),
113*05b00f60SXin Li GET_BE_U_2(hdr->ig_as),
114*05b00f60SXin Li nint,
115*05b00f60SXin Li nsys,
116*05b00f60SXin Li next);
117*05b00f60SXin Li cksum = GET_BE_U_2(hdr->ig_sum);
118*05b00f60SXin Li if (ndo->ndo_vflag)
119*05b00f60SXin Li ND_PRINT(" checksum=0x%04x", cksum);
120*05b00f60SXin Li
121*05b00f60SXin Li length -= sizeof(*hdr);
122*05b00f60SXin Li while (length >= IGRP_RTE_SIZE) {
123*05b00f60SXin Li const struct igrprte *igr = (const struct igrprte *)cp;
124*05b00f60SXin Li uint8_t net0 = GET_U_1(&igr->igr_net[0]);
125*05b00f60SXin Li uint8_t net1 = GET_U_1(&igr->igr_net[1]);
126*05b00f60SXin Li uint8_t net2 = GET_U_1(&igr->igr_net[2]);
127*05b00f60SXin Li
128*05b00f60SXin Li if (nint > 0) {
129*05b00f60SXin Li ND_PRINT(" *.%u.%u.%u", net0, net1, net2);
130*05b00f60SXin Li igrp_entry_print(ndo, igr);
131*05b00f60SXin Li --nint;
132*05b00f60SXin Li } else if (nsys > 0) {
133*05b00f60SXin Li ND_PRINT(" %u.%u.%u.0", net0, net1, net2);
134*05b00f60SXin Li igrp_entry_print(ndo, igr);
135*05b00f60SXin Li --nsys;
136*05b00f60SXin Li } else if (next > 0) {
137*05b00f60SXin Li ND_PRINT(" X%u.%u.%u.0", net0, net1, net2);
138*05b00f60SXin Li igrp_entry_print(ndo, igr);
139*05b00f60SXin Li --next;
140*05b00f60SXin Li } else {
141*05b00f60SXin Li ND_PRINT(" [extra bytes %u]", length);
142*05b00f60SXin Li break;
143*05b00f60SXin Li }
144*05b00f60SXin Li cp += IGRP_RTE_SIZE;
145*05b00f60SXin Li length -= IGRP_RTE_SIZE;
146*05b00f60SXin Li }
147*05b00f60SXin Li if (nint || nsys || next || length)
148*05b00f60SXin Li nd_print_invalid(ndo);
149*05b00f60SXin Li }
150