The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 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 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 24 | /* \summary: Interior Gateway Routing Protocol (IGRP) printer */ |
| 25 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 26 | #ifdef HAVE_CONFIG_H |
| 27 | #include "config.h" |
| 28 | #endif |
| 29 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 30 | #include <netdissect-stdinc.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 31 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 32 | #include "netdissect.h" |
| 33 | #include "extract.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 34 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 35 | /* Cisco IGRP definitions */ |
| 36 | |
| 37 | /* IGRP Header */ |
| 38 | |
| 39 | struct igrphdr { |
| 40 | uint8_t ig_vop; /* protocol version number / opcode */ |
| 41 | #define IGRP_V(x) (((x) & 0xf0) >> 4) |
| 42 | #define IGRP_OP(x) ((x) & 0x0f) |
| 43 | uint8_t ig_ed; /* edition number */ |
| 44 | uint16_t ig_as; /* autonomous system number */ |
| 45 | uint16_t ig_ni; /* number of subnet in local net */ |
| 46 | uint16_t ig_ns; /* number of networks in AS */ |
| 47 | uint16_t ig_nx; /* number of networks ouside AS */ |
| 48 | uint16_t ig_sum; /* checksum of IGRP header & data */ |
| 49 | }; |
| 50 | |
| 51 | #define IGRP_UPDATE 1 |
| 52 | #define IGRP_REQUEST 2 |
| 53 | |
| 54 | /* IGRP routing entry */ |
| 55 | |
| 56 | struct igrprte { |
| 57 | uint8_t igr_net[3]; /* 3 significant octets of IP address */ |
| 58 | uint8_t igr_dly[3]; /* delay in tens of microseconds */ |
| 59 | uint8_t igr_bw[3]; /* bandwidth in units of 1 kb/s */ |
| 60 | uint8_t igr_mtu[2]; /* MTU in octets */ |
| 61 | uint8_t igr_rel; /* percent packets successfully tx/rx */ |
| 62 | uint8_t igr_ld; /* percent of channel occupied */ |
| 63 | uint8_t igr_hct; /* hop count */ |
| 64 | }; |
| 65 | |
| 66 | #define IGRP_RTE_SIZE 14 /* don't believe sizeof ! */ |
| 67 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 68 | static void |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 69 | igrp_entry_print(netdissect_options *ndo, register const struct igrprte *igr, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 70 | register int is_interior, register int is_exterior) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 71 | { |
| 72 | register u_int delay, bandwidth; |
| 73 | u_int metric, mtu; |
| 74 | |
| 75 | if (is_interior) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 76 | ND_PRINT((ndo, " *.%d.%d.%d", igr->igr_net[0], |
| 77 | igr->igr_net[1], igr->igr_net[2])); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 78 | else if (is_exterior) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 79 | ND_PRINT((ndo, " X%d.%d.%d.0", igr->igr_net[0], |
| 80 | igr->igr_net[1], igr->igr_net[2])); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 81 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 82 | ND_PRINT((ndo, " %d.%d.%d.0", igr->igr_net[0], |
| 83 | igr->igr_net[1], igr->igr_net[2])); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 84 | |
| 85 | delay = EXTRACT_24BITS(igr->igr_dly); |
| 86 | bandwidth = EXTRACT_24BITS(igr->igr_bw); |
| 87 | metric = bandwidth + delay; |
| 88 | if (metric > 0xffffff) |
| 89 | metric = 0xffffff; |
| 90 | mtu = EXTRACT_16BITS(igr->igr_mtu); |
| 91 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 92 | ND_PRINT((ndo, " d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 93 | 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth, |
| 94 | igr->igr_rel, igr->igr_ld, metric, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 95 | mtu, igr->igr_hct)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 96 | } |
| 97 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 98 | static const struct tok op2str[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 99 | { IGRP_UPDATE, "update" }, |
| 100 | { IGRP_REQUEST, "request" }, |
| 101 | { 0, NULL } |
| 102 | }; |
| 103 | |
| 104 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 105 | igrp_print(netdissect_options *ndo, register const u_char *bp, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 106 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 107 | register const struct igrphdr *hdr; |
| 108 | register const u_char *cp; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 109 | u_int nint, nsys, next; |
| 110 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 111 | hdr = (const struct igrphdr *)bp; |
| 112 | cp = (const u_char *)(hdr + 1); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 113 | ND_PRINT((ndo, "igrp:")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 114 | |
| 115 | /* Header */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 116 | ND_TCHECK(*hdr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 117 | nint = EXTRACT_16BITS(&hdr->ig_ni); |
| 118 | nsys = EXTRACT_16BITS(&hdr->ig_ns); |
| 119 | next = EXTRACT_16BITS(&hdr->ig_nx); |
| 120 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 121 | ND_PRINT((ndo, " %s V%d edit=%d AS=%d (%d/%d/%d)", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 122 | tok2str(op2str, "op-#%d", IGRP_OP(hdr->ig_vop)), |
| 123 | IGRP_V(hdr->ig_vop), |
| 124 | hdr->ig_ed, |
| 125 | EXTRACT_16BITS(&hdr->ig_as), |
| 126 | nint, |
| 127 | nsys, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 128 | next)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 129 | |
| 130 | length -= sizeof(*hdr); |
| 131 | while (length >= IGRP_RTE_SIZE) { |
| 132 | if (nint > 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 133 | ND_TCHECK2(*cp, IGRP_RTE_SIZE); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 134 | igrp_entry_print(ndo, (const struct igrprte *)cp, 1, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 135 | --nint; |
| 136 | } else if (nsys > 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 137 | ND_TCHECK2(*cp, IGRP_RTE_SIZE); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 138 | igrp_entry_print(ndo, (const struct igrprte *)cp, 0, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 139 | --nsys; |
| 140 | } else if (next > 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 141 | ND_TCHECK2(*cp, IGRP_RTE_SIZE); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 142 | igrp_entry_print(ndo, (const struct igrprte *)cp, 0, 1); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 143 | --next; |
| 144 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 145 | ND_PRINT((ndo, " [extra bytes %d]", length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 146 | break; |
| 147 | } |
| 148 | cp += IGRP_RTE_SIZE; |
| 149 | length -= IGRP_RTE_SIZE; |
| 150 | } |
| 151 | if (nint == 0 && nsys == 0 && next == 0) |
| 152 | return; |
| 153 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 154 | ND_PRINT((ndo, " [|igrp]")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 155 | } |