xref: /freebsd/contrib/tcpdump/print-igrp.c (revision 0a7e5f1f02aad2ff5fff1c60f44c6975fd07e1d9)
14edb46e9SPaul Traina /*
24644f044SBill Fenner  * Copyright (c) 1996, 1997
34edb46e9SPaul Traina  *	The Regents of the University of California.  All rights reserved.
44edb46e9SPaul Traina  *
54edb46e9SPaul Traina  * Redistribution and use in source and binary forms, with or without
64edb46e9SPaul Traina  * modification, are permitted provided that: (1) source code distributions
74edb46e9SPaul Traina  * retain the above copyright notice and this paragraph in its entirety, (2)
84edb46e9SPaul Traina  * distributions including binary code include the above copyright notice and
94edb46e9SPaul Traina  * this paragraph in its entirety in the documentation or other materials
104edb46e9SPaul Traina  * provided with the distribution, and (3) all advertising materials mentioning
114edb46e9SPaul Traina  * features or use of this software display the following acknowledgement:
124edb46e9SPaul Traina  * ``This product includes software developed by the University of California,
134edb46e9SPaul Traina  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
144edb46e9SPaul Traina  * the University nor the names of its contributors may be used to endorse
154edb46e9SPaul Traina  * or promote products derived from this software without specific prior
164edb46e9SPaul Traina  * written permission.
174edb46e9SPaul Traina  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
184edb46e9SPaul Traina  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
194edb46e9SPaul Traina  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
204edb46e9SPaul Traina  *
214edb46e9SPaul Traina  * Initial contribution from Francis Dupont (francis.dupont@inria.fr)
224edb46e9SPaul Traina  */
234edb46e9SPaul Traina 
243340d773SGleb Smirnoff /* \summary: Interior Gateway Routing Protocol (IGRP) printer */
253340d773SGleb Smirnoff 
26*ee67461eSJoseph Mingrone #include <config.h>
274edb46e9SPaul Traina 
28*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
294edb46e9SPaul Traina 
303340d773SGleb Smirnoff #include "netdissect.h"
313340d773SGleb Smirnoff #include "extract.h"
324edb46e9SPaul Traina 
333c602fabSXin LI /* Cisco IGRP definitions */
343c602fabSXin LI 
353c602fabSXin LI /* IGRP Header */
363c602fabSXin LI 
373c602fabSXin LI struct igrphdr {
38*ee67461eSJoseph Mingrone 	nd_uint8_t ig_vop;	/* protocol version number / opcode */
393c602fabSXin LI #define IGRP_V(x)	(((x) & 0xf0) >> 4)
403c602fabSXin LI #define IGRP_OP(x)	((x) & 0x0f)
41*ee67461eSJoseph Mingrone 	nd_uint8_t ig_ed;	/* edition number */
42*ee67461eSJoseph Mingrone 	nd_uint16_t ig_as;	/* autonomous system number */
43*ee67461eSJoseph Mingrone 	nd_uint16_t ig_ni;	/* number of subnet in local net */
44*ee67461eSJoseph Mingrone 	nd_uint16_t ig_ns;	/* number of networks in AS */
45*ee67461eSJoseph Mingrone 	nd_uint16_t ig_nx;	/* number of networks outside AS */
46*ee67461eSJoseph Mingrone 	nd_uint16_t ig_sum;	/* checksum of IGRP header & data */
473c602fabSXin LI };
483c602fabSXin LI 
493c602fabSXin LI #define IGRP_UPDATE	1
503c602fabSXin LI #define IGRP_REQUEST	2
513c602fabSXin LI 
523c602fabSXin LI /* IGRP routing entry */
533c602fabSXin LI 
543c602fabSXin LI struct igrprte {
55*ee67461eSJoseph Mingrone 	nd_byte igr_net[3];	/* 3 significant octets of IP address */
56*ee67461eSJoseph Mingrone 	nd_uint24_t igr_dly;	/* delay in tens of microseconds */
57*ee67461eSJoseph Mingrone 	nd_uint24_t igr_bw;	/* bandwidth in units of 1 kb/s */
58*ee67461eSJoseph Mingrone 	nd_uint16_t igr_mtu;	/* MTU in octets */
59*ee67461eSJoseph Mingrone 	nd_uint8_t igr_rel;	/* percent packets successfully tx/rx */
60*ee67461eSJoseph Mingrone 	nd_uint8_t igr_ld;	/* percent of channel occupied */
61*ee67461eSJoseph Mingrone 	nd_uint8_t igr_hct;	/* hop count */
623c602fabSXin LI };
633c602fabSXin LI 
64*ee67461eSJoseph Mingrone #define IGRP_RTE_SIZE	14	/* sizeof() is accurate now */
653c602fabSXin LI 
664edb46e9SPaul Traina static void
igrp_entry_print(netdissect_options * ndo,const struct igrprte * igr)67*ee67461eSJoseph Mingrone igrp_entry_print(netdissect_options *ndo, const struct igrprte *igr)
684edb46e9SPaul Traina {
69*ee67461eSJoseph Mingrone 	u_int delay, bandwidth;
704edb46e9SPaul Traina 	u_int metric, mtu;
714edb46e9SPaul Traina 
72*ee67461eSJoseph Mingrone 	delay = GET_BE_U_3(igr->igr_dly);
73*ee67461eSJoseph Mingrone 	bandwidth = GET_BE_U_3(igr->igr_bw);
74*ee67461eSJoseph Mingrone 	metric = ND_MIN(bandwidth + delay, 0xffffff);
75*ee67461eSJoseph Mingrone 	mtu = GET_BE_U_2(igr->igr_mtu);
764edb46e9SPaul Traina 
77*ee67461eSJoseph Mingrone 	ND_PRINT(" d=%u b=%u r=%u l=%u M=%u mtu=%u in %u hops",
784edb46e9SPaul Traina 	    10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
79*ee67461eSJoseph Mingrone 	    GET_U_1(igr->igr_rel), GET_U_1(igr->igr_ld), metric,
80*ee67461eSJoseph Mingrone 	    mtu, GET_U_1(igr->igr_hct));
814edb46e9SPaul Traina }
824edb46e9SPaul Traina 
833c602fabSXin LI static const struct tok op2str[] = {
844edb46e9SPaul Traina 	{ IGRP_UPDATE,		"update" },
854edb46e9SPaul Traina 	{ IGRP_REQUEST,		"request" },
864edb46e9SPaul Traina 	{ 0,			NULL }
874edb46e9SPaul Traina };
884edb46e9SPaul Traina 
894edb46e9SPaul Traina void
igrp_print(netdissect_options * ndo,const u_char * bp,u_int length)90*ee67461eSJoseph Mingrone igrp_print(netdissect_options *ndo, const u_char *bp, u_int length)
914edb46e9SPaul Traina {
92*ee67461eSJoseph Mingrone 	const struct igrphdr *hdr;
93*ee67461eSJoseph Mingrone 	const u_char *cp;
944edb46e9SPaul Traina 	u_int nint, nsys, next;
95*ee67461eSJoseph Mingrone 	uint16_t cksum;
964edb46e9SPaul Traina 
97*ee67461eSJoseph Mingrone 	ndo->ndo_protocol = "igrp";
983340d773SGleb Smirnoff 	hdr = (const struct igrphdr *)bp;
993340d773SGleb Smirnoff 	cp = (const u_char *)(hdr + 1);
100*ee67461eSJoseph Mingrone 	ND_PRINT("igrp:");
1014edb46e9SPaul Traina 
1024edb46e9SPaul Traina 	/* Header */
103*ee67461eSJoseph Mingrone 	nint = GET_BE_U_2(hdr->ig_ni);
104*ee67461eSJoseph Mingrone 	nsys = GET_BE_U_2(hdr->ig_ns);
105*ee67461eSJoseph Mingrone 	next = GET_BE_U_2(hdr->ig_nx);
1064edb46e9SPaul Traina 
107*ee67461eSJoseph Mingrone 	ND_PRINT(" %s V%u edit=%u AS=%u (%u/%u/%u)",
108*ee67461eSJoseph Mingrone 	    tok2str(op2str, "op-#%u", IGRP_OP(GET_U_1(hdr->ig_vop))),
109*ee67461eSJoseph Mingrone 	    IGRP_V(GET_U_1(hdr->ig_vop)),
110*ee67461eSJoseph Mingrone 	    GET_U_1(hdr->ig_ed),
111*ee67461eSJoseph Mingrone 	    GET_BE_U_2(hdr->ig_as),
1124edb46e9SPaul Traina 	    nint,
1134edb46e9SPaul Traina 	    nsys,
114*ee67461eSJoseph Mingrone 	    next);
115*ee67461eSJoseph Mingrone 	cksum = GET_BE_U_2(hdr->ig_sum);
116*ee67461eSJoseph Mingrone 	if (ndo->ndo_vflag)
117*ee67461eSJoseph Mingrone 		ND_PRINT(" checksum=0x%04x", cksum);
1184edb46e9SPaul Traina 
1194edb46e9SPaul Traina 	length -= sizeof(*hdr);
1204edb46e9SPaul Traina 	while (length >= IGRP_RTE_SIZE) {
121*ee67461eSJoseph Mingrone 		const struct igrprte *igr = (const struct igrprte *)cp;
122*ee67461eSJoseph Mingrone 		uint8_t net0 = GET_U_1(&igr->igr_net[0]);
123*ee67461eSJoseph Mingrone 		uint8_t net1 = GET_U_1(&igr->igr_net[1]);
124*ee67461eSJoseph Mingrone 		uint8_t net2 = GET_U_1(&igr->igr_net[2]);
125*ee67461eSJoseph Mingrone 
1264edb46e9SPaul Traina 		if (nint > 0) {
127*ee67461eSJoseph Mingrone 			ND_PRINT(" *.%u.%u.%u", net0, net1, net2);
128*ee67461eSJoseph Mingrone 			igrp_entry_print(ndo, igr);
1294edb46e9SPaul Traina 			--nint;
1304edb46e9SPaul Traina 		} else if (nsys > 0) {
131*ee67461eSJoseph Mingrone 			ND_PRINT(" %u.%u.%u.0", net0, net1, net2);
132*ee67461eSJoseph Mingrone 			igrp_entry_print(ndo, igr);
1334edb46e9SPaul Traina 			--nsys;
1344edb46e9SPaul Traina 		} else if (next > 0) {
135*ee67461eSJoseph Mingrone 			ND_PRINT(" X%u.%u.%u.0", net0, net1, net2);
136*ee67461eSJoseph Mingrone 			igrp_entry_print(ndo, igr);
1374edb46e9SPaul Traina 			--next;
1384edb46e9SPaul Traina 		} else {
139*ee67461eSJoseph Mingrone 			ND_PRINT(" [extra bytes %u]", length);
1404edb46e9SPaul Traina 			break;
1414edb46e9SPaul Traina 		}
1424edb46e9SPaul Traina 		cp += IGRP_RTE_SIZE;
1434edb46e9SPaul Traina 		length -= IGRP_RTE_SIZE;
1444edb46e9SPaul Traina 	}
145*ee67461eSJoseph Mingrone 	if (nint || nsys || next || length)
146*ee67461eSJoseph Mingrone 		nd_print_invalid(ndo);
1474edb46e9SPaul Traina }
148