xref: /freebsd/contrib/tcpdump/print-igrp.c (revision 4edb46e9a85ca35d3bed523171d11a748861ce82)
14edb46e9SPaul Traina /*
24edb46e9SPaul Traina  * Copyright (c) 1996
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 
244edb46e9SPaul Traina #ifndef lint
254edb46e9SPaul Traina static char rcsid[] =
264edb46e9SPaul Traina "@(#) $Header: print-igrp.c,v 1.4 96/07/23 14:04:55 leres Exp $ (LBL)";
274edb46e9SPaul Traina #endif
284edb46e9SPaul Traina 
294edb46e9SPaul Traina #include <sys/param.h>
304edb46e9SPaul Traina #include <sys/socket.h>
314edb46e9SPaul Traina 
324edb46e9SPaul Traina #include <netinet/in.h>
334edb46e9SPaul Traina #include <netinet/in_systm.h>
344edb46e9SPaul Traina #include <netinet/ip.h>
354edb46e9SPaul Traina #include <netinet/ip_var.h>
364edb46e9SPaul Traina #include <netinet/udp.h>
374edb46e9SPaul Traina #include <netinet/udp_var.h>
384edb46e9SPaul Traina 
394edb46e9SPaul Traina #include <errno.h>
404edb46e9SPaul Traina #include <stdio.h>
414edb46e9SPaul Traina 
424edb46e9SPaul Traina #include "addrtoname.h"
434edb46e9SPaul Traina #include "interface.h"
444edb46e9SPaul Traina #include "igrp.h"
454edb46e9SPaul Traina #include "extract.h"			/* must come after interface.h */
464edb46e9SPaul Traina 
474edb46e9SPaul Traina static void
484edb46e9SPaul Traina igrp_entry_print(register struct igrprte *igr, register int is_interior,
494edb46e9SPaul Traina     register int is_exterior)
504edb46e9SPaul Traina {
514edb46e9SPaul Traina 	register u_int delay, bandwidth;
524edb46e9SPaul Traina 	u_int metric, mtu;
534edb46e9SPaul Traina 
544edb46e9SPaul Traina 	if (is_interior)
554edb46e9SPaul Traina 		printf(" *.%d.%d.%d", igr->igr_net[0],
564edb46e9SPaul Traina 		    igr->igr_net[1], igr->igr_net[2]);
574edb46e9SPaul Traina 	else if (is_exterior)
584edb46e9SPaul Traina 		printf(" X%d.%d.%d.0", igr->igr_net[0],
594edb46e9SPaul Traina 		    igr->igr_net[1], igr->igr_net[2]);
604edb46e9SPaul Traina 	else
614edb46e9SPaul Traina 		printf(" %d.%d.%d.0", igr->igr_net[0],
624edb46e9SPaul Traina 		    igr->igr_net[1], igr->igr_net[2]);
634edb46e9SPaul Traina 
644edb46e9SPaul Traina 	delay = EXTRACT_24BITS(igr->igr_dly);
654edb46e9SPaul Traina 	bandwidth = EXTRACT_24BITS(igr->igr_bw);
664edb46e9SPaul Traina 	metric = bandwidth + delay;
674edb46e9SPaul Traina 	if (metric > 0xffffff)
684edb46e9SPaul Traina 		metric = 0xffffff;
694edb46e9SPaul Traina 	mtu = EXTRACT_16BITS(igr->igr_mtu);
704edb46e9SPaul Traina 
714edb46e9SPaul Traina 	printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops",
724edb46e9SPaul Traina 	    10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
734edb46e9SPaul Traina 	    igr->igr_rel, igr->igr_ld, metric,
744edb46e9SPaul Traina 	    mtu, igr->igr_hct);
754edb46e9SPaul Traina }
764edb46e9SPaul Traina 
774edb46e9SPaul Traina static struct tok op2str[] = {
784edb46e9SPaul Traina 	{ IGRP_UPDATE,		"update" },
794edb46e9SPaul Traina 	{ IGRP_REQUEST,		"request" },
804edb46e9SPaul Traina 	{ 0,			NULL }
814edb46e9SPaul Traina };
824edb46e9SPaul Traina 
834edb46e9SPaul Traina void
844edb46e9SPaul Traina igrp_print(register const u_char *bp, u_int length, register const u_char *bp2)
854edb46e9SPaul Traina {
864edb46e9SPaul Traina 	register struct igrphdr *hdr;
874edb46e9SPaul Traina 	register struct ip *ip;
884edb46e9SPaul Traina 	register u_char *cp;
894edb46e9SPaul Traina 	u_int nint, nsys, next;
904edb46e9SPaul Traina 
914edb46e9SPaul Traina 	hdr = (struct igrphdr *)bp;
924edb46e9SPaul Traina 	ip = (struct ip *)bp2;
934edb46e9SPaul Traina 	cp = (u_char *)(hdr + 1);
944edb46e9SPaul Traina         (void)printf("%s > %s: igrp: ",
954edb46e9SPaul Traina 	    ipaddr_string(&ip->ip_src),
964edb46e9SPaul Traina 	    ipaddr_string(&ip->ip_dst));
974edb46e9SPaul Traina 
984edb46e9SPaul Traina 	/* Header */
994edb46e9SPaul Traina 	TCHECK(*hdr);
1004edb46e9SPaul Traina 	nint = EXTRACT_16BITS(&hdr->ig_ni);
1014edb46e9SPaul Traina 	nsys = EXTRACT_16BITS(&hdr->ig_ns);
1024edb46e9SPaul Traina 	next = EXTRACT_16BITS(&hdr->ig_nx);
1034edb46e9SPaul Traina 
1044edb46e9SPaul Traina 	(void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)",
1054edb46e9SPaul Traina 	    tok2str(op2str, "op-#%d", hdr->ig_op),
1064edb46e9SPaul Traina 	    hdr->ig_v,
1074edb46e9SPaul Traina 	    hdr->ig_ed,
1084edb46e9SPaul Traina 	    EXTRACT_16BITS(&hdr->ig_as),
1094edb46e9SPaul Traina 	    nint,
1104edb46e9SPaul Traina 	    nsys,
1114edb46e9SPaul Traina 	    next);
1124edb46e9SPaul Traina 
1134edb46e9SPaul Traina 	length -= sizeof(*hdr);
1144edb46e9SPaul Traina 	while (length >= IGRP_RTE_SIZE) {
1154edb46e9SPaul Traina 		if (nint > 0) {
1164edb46e9SPaul Traina 			TCHECK2(*cp, IGRP_RTE_SIZE);
1174edb46e9SPaul Traina 			igrp_entry_print((struct igrprte *)cp, 1, 0);
1184edb46e9SPaul Traina 			--nint;
1194edb46e9SPaul Traina 		} else if (nsys > 0) {
1204edb46e9SPaul Traina 			TCHECK2(*cp, IGRP_RTE_SIZE);
1214edb46e9SPaul Traina 			igrp_entry_print((struct igrprte *)cp, 0, 0);
1224edb46e9SPaul Traina 			--nsys;
1234edb46e9SPaul Traina 		} else if (next > 0) {
1244edb46e9SPaul Traina 			TCHECK2(*cp, IGRP_RTE_SIZE);
1254edb46e9SPaul Traina 			igrp_entry_print((struct igrprte *)cp, 0, 1);
1264edb46e9SPaul Traina 			--next;
1274edb46e9SPaul Traina 		} else {
1284edb46e9SPaul Traina 			(void)printf("[extra bytes %d]", length);
1294edb46e9SPaul Traina 			break;
1304edb46e9SPaul Traina 		}
1314edb46e9SPaul Traina 		cp += IGRP_RTE_SIZE;
1324edb46e9SPaul Traina 		length -= IGRP_RTE_SIZE;
1334edb46e9SPaul Traina 	}
1344edb46e9SPaul Traina 	if (nint == 0 && nsys == 0 && next == 0)
1354edb46e9SPaul Traina 		return;
1364edb46e9SPaul Traina trunc:
1374edb46e9SPaul Traina 	fputs("[|igrp]", stdout);
1384edb46e9SPaul Traina }
139