141c99275SPeter Avalos /*
241c99275SPeter Avalos * Copyright (c) 1996, 1997
341c99275SPeter Avalos * The Regents of the University of California. All rights reserved.
441c99275SPeter Avalos *
541c99275SPeter Avalos * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos * modification, are permitted provided that: (1) source code distributions
741c99275SPeter Avalos * retain the above copyright notice and this paragraph in its entirety, (2)
841c99275SPeter Avalos * distributions including binary code include the above copyright notice and
941c99275SPeter Avalos * this paragraph in its entirety in the documentation or other materials
1041c99275SPeter Avalos * provided with the distribution, and (3) all advertising materials mentioning
1141c99275SPeter Avalos * features or use of this software display the following acknowledgement:
1241c99275SPeter Avalos * ``This product includes software developed by the University of California,
1341c99275SPeter Avalos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1441c99275SPeter Avalos * the University nor the names of its contributors may be used to endorse
1541c99275SPeter Avalos * or promote products derived from this software without specific prior
1641c99275SPeter Avalos * written permission.
1741c99275SPeter Avalos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1841c99275SPeter Avalos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1941c99275SPeter Avalos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2041c99275SPeter Avalos *
2141c99275SPeter Avalos * Initial contribution from Francis Dupont (francis.dupont@inria.fr)
2241c99275SPeter Avalos */
2341c99275SPeter Avalos
24411677aeSAaron LI /* \summary: Interior Gateway Routing Protocol (IGRP) printer */
2541c99275SPeter Avalos
2641c99275SPeter Avalos #ifdef HAVE_CONFIG_H
27*ed775ee7SAntonio Huete Jimenez #include <config.h>
2841c99275SPeter Avalos #endif
2941c99275SPeter Avalos
30*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
3141c99275SPeter Avalos
32411677aeSAaron LI #include "netdissect.h"
33411677aeSAaron LI #include "extract.h"
3441c99275SPeter Avalos
35411677aeSAaron LI /* Cisco IGRP definitions */
36411677aeSAaron LI
37411677aeSAaron LI /* IGRP Header */
38411677aeSAaron LI
39411677aeSAaron LI struct igrphdr {
40*ed775ee7SAntonio Huete Jimenez nd_uint8_t ig_vop; /* protocol version number / opcode */
41411677aeSAaron LI #define IGRP_V(x) (((x) & 0xf0) >> 4)
42411677aeSAaron LI #define IGRP_OP(x) ((x) & 0x0f)
43*ed775ee7SAntonio Huete Jimenez nd_uint8_t ig_ed; /* edition number */
44*ed775ee7SAntonio Huete Jimenez nd_uint16_t ig_as; /* autonomous system number */
45*ed775ee7SAntonio Huete Jimenez nd_uint16_t ig_ni; /* number of subnet in local net */
46*ed775ee7SAntonio Huete Jimenez nd_uint16_t ig_ns; /* number of networks in AS */
47*ed775ee7SAntonio Huete Jimenez nd_uint16_t ig_nx; /* number of networks ouside AS */
48*ed775ee7SAntonio Huete Jimenez nd_uint16_t ig_sum; /* checksum of IGRP header & data */
49411677aeSAaron LI };
50411677aeSAaron LI
51411677aeSAaron LI #define IGRP_UPDATE 1
52411677aeSAaron LI #define IGRP_REQUEST 2
53411677aeSAaron LI
54411677aeSAaron LI /* IGRP routing entry */
55411677aeSAaron LI
56411677aeSAaron LI struct igrprte {
57*ed775ee7SAntonio Huete Jimenez nd_byte igr_net[3]; /* 3 significant octets of IP address */
58*ed775ee7SAntonio Huete Jimenez nd_uint24_t igr_dly; /* delay in tens of microseconds */
59*ed775ee7SAntonio Huete Jimenez nd_uint24_t igr_bw; /* bandwidth in units of 1 kb/s */
60*ed775ee7SAntonio Huete Jimenez nd_uint16_t igr_mtu; /* MTU in octets */
61*ed775ee7SAntonio Huete Jimenez nd_uint8_t igr_rel; /* percent packets successfully tx/rx */
62*ed775ee7SAntonio Huete Jimenez nd_uint8_t igr_ld; /* percent of channel occupied */
63*ed775ee7SAntonio Huete Jimenez nd_uint8_t igr_hct; /* hop count */
64411677aeSAaron LI };
65411677aeSAaron LI
66*ed775ee7SAntonio Huete Jimenez #define IGRP_RTE_SIZE 14 /* sizeof() is accurate now */
6741c99275SPeter Avalos
6841c99275SPeter Avalos static void
igrp_entry_print(netdissect_options * ndo,const struct igrprte * igr)69*ed775ee7SAntonio Huete Jimenez igrp_entry_print(netdissect_options *ndo, const struct igrprte *igr)
7041c99275SPeter Avalos {
71*ed775ee7SAntonio Huete Jimenez u_int delay, bandwidth;
7241c99275SPeter Avalos u_int metric, mtu;
7341c99275SPeter Avalos
74*ed775ee7SAntonio Huete Jimenez delay = GET_BE_U_3(igr->igr_dly);
75*ed775ee7SAntonio Huete Jimenez bandwidth = GET_BE_U_3(igr->igr_bw);
76*ed775ee7SAntonio Huete Jimenez metric = ND_MIN(bandwidth + delay, 0xffffff);
77*ed775ee7SAntonio Huete Jimenez mtu = GET_BE_U_2(igr->igr_mtu);
7841c99275SPeter Avalos
79*ed775ee7SAntonio Huete Jimenez ND_PRINT(" d=%u b=%u r=%u l=%u M=%u mtu=%u in %u hops",
8041c99275SPeter Avalos 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
81*ed775ee7SAntonio Huete Jimenez GET_U_1(igr->igr_rel), GET_U_1(igr->igr_ld), metric,
82*ed775ee7SAntonio Huete Jimenez mtu, GET_U_1(igr->igr_hct));
8341c99275SPeter Avalos }
8441c99275SPeter Avalos
85411677aeSAaron LI static const struct tok op2str[] = {
8641c99275SPeter Avalos { IGRP_UPDATE, "update" },
8741c99275SPeter Avalos { IGRP_REQUEST, "request" },
8841c99275SPeter Avalos { 0, NULL }
8941c99275SPeter Avalos };
9041c99275SPeter Avalos
9141c99275SPeter Avalos void
igrp_print(netdissect_options * ndo,const u_char * bp,u_int length)92*ed775ee7SAntonio Huete Jimenez igrp_print(netdissect_options *ndo, const u_char *bp, u_int length)
9341c99275SPeter Avalos {
94*ed775ee7SAntonio Huete Jimenez const struct igrphdr *hdr;
95*ed775ee7SAntonio Huete Jimenez const u_char *cp;
9641c99275SPeter Avalos u_int nint, nsys, next;
97*ed775ee7SAntonio Huete Jimenez uint16_t cksum;
9841c99275SPeter Avalos
99*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "igrp";
100411677aeSAaron LI hdr = (const struct igrphdr *)bp;
101411677aeSAaron LI cp = (const u_char *)(hdr + 1);
102*ed775ee7SAntonio Huete Jimenez ND_PRINT("igrp:");
10341c99275SPeter Avalos
10441c99275SPeter Avalos /* Header */
105*ed775ee7SAntonio Huete Jimenez nint = GET_BE_U_2(hdr->ig_ni);
106*ed775ee7SAntonio Huete Jimenez nsys = GET_BE_U_2(hdr->ig_ns);
107*ed775ee7SAntonio Huete Jimenez next = GET_BE_U_2(hdr->ig_nx);
10841c99275SPeter Avalos
109*ed775ee7SAntonio Huete Jimenez ND_PRINT(" %s V%u edit=%u AS=%u (%u/%u/%u)",
110*ed775ee7SAntonio Huete Jimenez tok2str(op2str, "op-#%u", IGRP_OP(GET_U_1(hdr->ig_vop))),
111*ed775ee7SAntonio Huete Jimenez IGRP_V(GET_U_1(hdr->ig_vop)),
112*ed775ee7SAntonio Huete Jimenez GET_U_1(hdr->ig_ed),
113*ed775ee7SAntonio Huete Jimenez GET_BE_U_2(hdr->ig_as),
11441c99275SPeter Avalos nint,
11541c99275SPeter Avalos nsys,
116*ed775ee7SAntonio Huete Jimenez next);
117*ed775ee7SAntonio Huete Jimenez cksum = GET_BE_U_2(hdr->ig_sum);
118*ed775ee7SAntonio Huete Jimenez if (ndo->ndo_vflag)
119*ed775ee7SAntonio Huete Jimenez ND_PRINT(" checksum=0x%04x", cksum);
12041c99275SPeter Avalos
12141c99275SPeter Avalos length -= sizeof(*hdr);
12241c99275SPeter Avalos while (length >= IGRP_RTE_SIZE) {
123*ed775ee7SAntonio Huete Jimenez const struct igrprte *igr = (const struct igrprte *)cp;
124*ed775ee7SAntonio Huete Jimenez uint8_t net0 = GET_U_1(&igr->igr_net[0]);
125*ed775ee7SAntonio Huete Jimenez uint8_t net1 = GET_U_1(&igr->igr_net[1]);
126*ed775ee7SAntonio Huete Jimenez uint8_t net2 = GET_U_1(&igr->igr_net[2]);
127*ed775ee7SAntonio Huete Jimenez
12841c99275SPeter Avalos if (nint > 0) {
129*ed775ee7SAntonio Huete Jimenez ND_PRINT(" *.%u.%u.%u", net0, net1, net2);
130*ed775ee7SAntonio Huete Jimenez igrp_entry_print(ndo, igr);
13141c99275SPeter Avalos --nint;
13241c99275SPeter Avalos } else if (nsys > 0) {
133*ed775ee7SAntonio Huete Jimenez ND_PRINT(" %u.%u.%u.0", net0, net1, net2);
134*ed775ee7SAntonio Huete Jimenez igrp_entry_print(ndo, igr);
13541c99275SPeter Avalos --nsys;
13641c99275SPeter Avalos } else if (next > 0) {
137*ed775ee7SAntonio Huete Jimenez ND_PRINT(" X%u.%u.%u.0", net0, net1, net2);
138*ed775ee7SAntonio Huete Jimenez igrp_entry_print(ndo, igr);
13941c99275SPeter Avalos --next;
14041c99275SPeter Avalos } else {
141*ed775ee7SAntonio Huete Jimenez ND_PRINT(" [extra bytes %u]", length);
14241c99275SPeter Avalos break;
14341c99275SPeter Avalos }
14441c99275SPeter Avalos cp += IGRP_RTE_SIZE;
14541c99275SPeter Avalos length -= IGRP_RTE_SIZE;
14641c99275SPeter Avalos }
147*ed775ee7SAntonio Huete Jimenez if (nint || nsys || next || length)
148*ed775ee7SAntonio Huete Jimenez nd_print_invalid(ndo);
14941c99275SPeter Avalos }
150