1 /* $OpenBSD: print-igrp.c,v 1.5 2009/10/27 23:59:55 deraadt Exp $ */ 2 3 /* 4 * Copyright (c) 1996, 1997 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that: (1) source code distributions 9 * retain the above copyright notice and this paragraph in its entirety, (2) 10 * distributions including binary code include the above copyright notice and 11 * this paragraph in its entirety in the documentation or other materials 12 * provided with the distribution, and (3) all advertising materials mentioning 13 * features or use of this software display the following acknowledgement: 14 * ``This product includes software developed by the University of California, 15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 16 * the University nor the names of its contributors may be used to endorse 17 * or promote products derived from this software without specific prior 18 * written permission. 19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 22 * 23 * Initial contribution from Francis Dupont (francis.dupont@inria.fr) 24 */ 25 26 #include <sys/param.h> 27 #include <sys/types.h> /* concession to AIX */ 28 #include <sys/socket.h> 29 30 #include <netinet/in.h> 31 #include <netinet/in_systm.h> 32 #include <netinet/ip.h> 33 #include <netinet/ip_var.h> 34 #include <netinet/udp.h> 35 #include <netinet/udp_var.h> 36 37 #include <errno.h> 38 #include <stdio.h> 39 40 #include "interface.h" 41 #include "addrtoname.h" 42 #include "igrp.h" 43 #include "extract.h" /* must come after interface.h */ 44 45 static void 46 igrp_entry_print(register struct igrprte *igr, register int is_interior, 47 register int is_exterior) 48 { 49 register u_int delay, bandwidth; 50 u_int metric, mtu; 51 52 if (is_interior) 53 printf(" *.%d.%d.%d", igr->igr_net[0], 54 igr->igr_net[1], igr->igr_net[2]); 55 else if (is_exterior) 56 printf(" X%d.%d.%d.0", igr->igr_net[0], 57 igr->igr_net[1], igr->igr_net[2]); 58 else 59 printf(" %d.%d.%d.0", igr->igr_net[0], 60 igr->igr_net[1], igr->igr_net[2]); 61 62 delay = EXTRACT_24BITS(igr->igr_dly); 63 bandwidth = EXTRACT_24BITS(igr->igr_bw); 64 metric = bandwidth + delay; 65 if (metric > 0xffffff) 66 metric = 0xffffff; 67 mtu = EXTRACT_16BITS(igr->igr_mtu); 68 69 printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops", 70 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth, 71 igr->igr_rel, igr->igr_ld, metric, 72 mtu, igr->igr_hct); 73 } 74 75 static struct tok op2str[] = { 76 { IGRP_UPDATE, "update" }, 77 { IGRP_REQUEST, "request" }, 78 { 0, NULL } 79 }; 80 81 void 82 igrp_print(register const u_char *bp, u_int length, register const u_char *bp2) 83 { 84 register struct igrphdr *hdr; 85 register struct ip *ip; 86 register u_char *cp; 87 u_int nint, nsys, next; 88 89 hdr = (struct igrphdr *)bp; 90 ip = (struct ip *)bp2; 91 cp = (u_char *)(hdr + 1); 92 (void)printf("%s > %s: igrp: ", 93 ipaddr_string(&ip->ip_src), 94 ipaddr_string(&ip->ip_dst)); 95 96 /* Header */ 97 TCHECK(*hdr); 98 nint = EXTRACT_16BITS(&hdr->ig_ni); 99 nsys = EXTRACT_16BITS(&hdr->ig_ns); 100 next = EXTRACT_16BITS(&hdr->ig_nx); 101 102 (void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)", 103 tok2str(op2str, "op-#%d", hdr->ig_op), 104 hdr->ig_v, 105 hdr->ig_ed, 106 EXTRACT_16BITS(&hdr->ig_as), 107 nint, 108 nsys, 109 next); 110 111 length -= sizeof(*hdr); 112 while (length >= IGRP_RTE_SIZE) { 113 if (nint > 0) { 114 TCHECK2(*cp, IGRP_RTE_SIZE); 115 igrp_entry_print((struct igrprte *)cp, 1, 0); 116 --nint; 117 } else if (nsys > 0) { 118 TCHECK2(*cp, IGRP_RTE_SIZE); 119 igrp_entry_print((struct igrprte *)cp, 0, 0); 120 --nsys; 121 } else if (next > 0) { 122 TCHECK2(*cp, IGRP_RTE_SIZE); 123 igrp_entry_print((struct igrprte *)cp, 0, 1); 124 --next; 125 } else { 126 (void)printf("[extra bytes %d]", length); 127 break; 128 } 129 cp += IGRP_RTE_SIZE; 130 length -= IGRP_RTE_SIZE; 131 } 132 if (nint == 0 && nsys == 0 && next == 0) 133 return; 134 trunc: 135 fputs("[|igrp]", stdout); 136 } 137