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