print-igrp.c revision 39297
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#ifndef lint
25static const char rcsid[] =
26    "@(#) $Header: print-igrp.c,v 1.8 97/05/28 12:52:47 leres Exp $ (LBL)";
27#endif
28
29#include <sys/param.h>
30#include <sys/types.h>			/* concession to AIX */
31#include <sys/socket.h>
32
33#include <netinet/in.h>
34#include <netinet/in_systm.h>
35#include <netinet/ip.h>
36#include <netinet/ip_var.h>
37#include <netinet/udp.h>
38#include <netinet/udp_var.h>
39
40#include <errno.h>
41#include <stdio.h>
42
43#include "interface.h"
44#include "addrtoname.h"
45#include "igrp.h"
46#include "extract.h"			/* must come after interface.h */
47
48static void
49igrp_entry_print(register struct igrprte *igr, register int is_interior,
50    register int is_exterior)
51{
52	register u_int delay, bandwidth;
53	u_int metric, mtu;
54
55	if (is_interior)
56		printf(" *.%d.%d.%d", igr->igr_net[0],
57		    igr->igr_net[1], igr->igr_net[2]);
58	else if (is_exterior)
59		printf(" X%d.%d.%d.0", igr->igr_net[0],
60		    igr->igr_net[1], igr->igr_net[2]);
61	else
62		printf(" %d.%d.%d.0", igr->igr_net[0],
63		    igr->igr_net[1], igr->igr_net[2]);
64
65	delay = EXTRACT_24BITS(igr->igr_dly);
66	bandwidth = EXTRACT_24BITS(igr->igr_bw);
67	metric = bandwidth + delay;
68	if (metric > 0xffffff)
69		metric = 0xffffff;
70	mtu = EXTRACT_16BITS(igr->igr_mtu);
71
72	printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops",
73	    10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
74	    igr->igr_rel, igr->igr_ld, metric,
75	    mtu, igr->igr_hct);
76}
77
78static struct tok op2str[] = {
79	{ IGRP_UPDATE,		"update" },
80	{ IGRP_REQUEST,		"request" },
81	{ 0,			NULL }
82};
83
84void
85igrp_print(register const u_char *bp, u_int length, register const u_char *bp2)
86{
87	register struct igrphdr *hdr;
88	register struct ip *ip;
89	register u_char *cp;
90	u_int nint, nsys, next;
91
92	hdr = (struct igrphdr *)bp;
93	ip = (struct ip *)bp2;
94	cp = (u_char *)(hdr + 1);
95        (void)printf("%s > %s: igrp: ",
96	    ipaddr_string(&ip->ip_src),
97	    ipaddr_string(&ip->ip_dst));
98
99	/* Header */
100	TCHECK(*hdr);
101	nint = EXTRACT_16BITS(&hdr->ig_ni);
102	nsys = EXTRACT_16BITS(&hdr->ig_ns);
103	next = EXTRACT_16BITS(&hdr->ig_nx);
104
105	(void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)",
106	    tok2str(op2str, "op-#%d", hdr->ig_op),
107	    hdr->ig_v,
108	    hdr->ig_ed,
109	    EXTRACT_16BITS(&hdr->ig_as),
110	    nint,
111	    nsys,
112	    next);
113
114	length -= sizeof(*hdr);
115	while (length >= IGRP_RTE_SIZE) {
116		if (nint > 0) {
117			TCHECK2(*cp, IGRP_RTE_SIZE);
118			igrp_entry_print((struct igrprte *)cp, 1, 0);
119			--nint;
120		} else if (nsys > 0) {
121			TCHECK2(*cp, IGRP_RTE_SIZE);
122			igrp_entry_print((struct igrprte *)cp, 0, 0);
123			--nsys;
124		} else if (next > 0) {
125			TCHECK2(*cp, IGRP_RTE_SIZE);
126			igrp_entry_print((struct igrprte *)cp, 0, 1);
127			--next;
128		} else {
129			(void)printf("[extra bytes %d]", length);
130			break;
131		}
132		cp += IGRP_RTE_SIZE;
133		length -= IGRP_RTE_SIZE;
134	}
135	if (nint == 0 && nsys == 0 && next == 0)
136		return;
137trunc:
138	fputs("[|igrp]", stdout);
139}
140