The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1989, 1990, 1991, 1993, 1994 |
| 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 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame^] | 22 | /* \summary: IPv6 Routing Information Protocol (RIPng) printer */ |
| 23 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 24 | #ifdef HAVE_CONFIG_H |
| 25 | #include "config.h" |
| 26 | #endif |
| 27 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame^] | 28 | #include <netdissect-stdinc.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 29 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame^] | 30 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 31 | #include "addrtoname.h" |
| 32 | #include "extract.h" |
| 33 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 34 | /* |
| 35 | * Copyright (C) 1995, 1996, 1997 and 1998 WIDE Project. |
| 36 | * All rights reserved. |
| 37 | * |
| 38 | * Redistribution and use in source and binary forms, with or without |
| 39 | * modification, are permitted provided that the following conditions |
| 40 | * are met: |
| 41 | * 1. Redistributions of source code must retain the above copyright |
| 42 | * notice, this list of conditions and the following disclaimer. |
| 43 | * 2. Redistributions in binary form must reproduce the above copyright |
| 44 | * notice, this list of conditions and the following disclaimer in the |
| 45 | * documentation and/or other materials provided with the distribution. |
| 46 | * 3. Neither the name of the project nor the names of its contributors |
| 47 | * may be used to endorse or promote products derived from this software |
| 48 | * without specific prior written permission. |
| 49 | * |
| 50 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND |
| 51 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 52 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 53 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
| 54 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 55 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 56 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 57 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 58 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 59 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 60 | * SUCH DAMAGE. |
| 61 | */ |
| 62 | #define RIP6_VERSION 1 |
| 63 | |
| 64 | #define RIP6_REQUEST 1 |
| 65 | #define RIP6_RESPONSE 2 |
| 66 | |
| 67 | struct netinfo6 { |
| 68 | struct in6_addr rip6_dest; |
| 69 | uint16_t rip6_tag; |
| 70 | uint8_t rip6_plen; |
| 71 | uint8_t rip6_metric; |
| 72 | }; |
| 73 | |
| 74 | struct rip6 { |
| 75 | uint8_t rip6_cmd; |
| 76 | uint8_t rip6_vers; |
| 77 | uint8_t rip6_res1[2]; |
| 78 | union { |
| 79 | struct netinfo6 ru6_nets[1]; |
| 80 | char ru6_tracefile[1]; |
| 81 | } rip6un; |
| 82 | #define rip6_nets rip6un.ru6_nets |
| 83 | #define rip6_tracefile rip6un.ru6_tracefile |
| 84 | }; |
| 85 | |
| 86 | #define HOPCNT_INFINITY6 16 |
| 87 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 88 | #if !defined(IN6_IS_ADDR_UNSPECIFIED) && !defined(_MSC_VER) /* MSVC inline */ |
| 89 | static int IN6_IS_ADDR_UNSPECIFIED(const struct in6_addr *addr) |
| 90 | { |
| 91 | static const struct in6_addr in6addr_any; /* :: */ |
| 92 | return (memcmp(addr, &in6addr_any, sizeof(*addr)) == 0); |
| 93 | } |
| 94 | #endif |
| 95 | |
| 96 | static int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 97 | rip6_entry_print(netdissect_options *ndo, register const struct netinfo6 *ni, int metric) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 98 | { |
| 99 | int l; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 100 | l = ND_PRINT((ndo, "%s/%d", ip6addr_string(ndo, &ni->rip6_dest), ni->rip6_plen)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 101 | if (ni->rip6_tag) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 102 | l += ND_PRINT((ndo, " [%d]", EXTRACT_16BITS(&ni->rip6_tag))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 103 | if (metric) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 104 | l += ND_PRINT((ndo, " (%d)", ni->rip6_metric)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 105 | return l; |
| 106 | } |
| 107 | |
| 108 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 109 | ripng_print(netdissect_options *ndo, const u_char *dat, unsigned int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 110 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame^] | 111 | register const struct rip6 *rp = (const struct rip6 *)dat; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 112 | register const struct netinfo6 *ni; |
| 113 | register u_int amt; |
| 114 | register u_int i; |
| 115 | int j; |
| 116 | int trunc; |
| 117 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 118 | if (ndo->ndo_snapend < dat) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 119 | return; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 120 | amt = ndo->ndo_snapend - dat; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 121 | i = min(length, amt); |
| 122 | if (i < (sizeof(struct rip6) - sizeof(struct netinfo6))) |
| 123 | return; |
| 124 | i -= (sizeof(struct rip6) - sizeof(struct netinfo6)); |
| 125 | |
| 126 | switch (rp->rip6_cmd) { |
| 127 | |
| 128 | case RIP6_REQUEST: |
| 129 | j = length / sizeof(*ni); |
| 130 | if (j == 1 |
| 131 | && rp->rip6_nets->rip6_metric == HOPCNT_INFINITY6 |
| 132 | && IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 133 | ND_PRINT((ndo, " ripng-req dump")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 134 | break; |
| 135 | } |
| 136 | if (j * sizeof(*ni) != length - 4) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 137 | ND_PRINT((ndo, " ripng-req %d[%u]:", j, length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 138 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 139 | ND_PRINT((ndo, " ripng-req %d:", j)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 140 | trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); |
| 141 | for (ni = rp->rip6_nets; i >= sizeof(*ni); |
| 142 | i -= sizeof(*ni), ++ni) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 143 | if (ndo->ndo_vflag > 1) |
| 144 | ND_PRINT((ndo, "\n\t")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 145 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 146 | ND_PRINT((ndo, " ")); |
| 147 | rip6_entry_print(ndo, ni, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 148 | } |
| 149 | break; |
| 150 | case RIP6_RESPONSE: |
| 151 | j = length / sizeof(*ni); |
| 152 | if (j * sizeof(*ni) != length - 4) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 153 | ND_PRINT((ndo, " ripng-resp %d[%u]:", j, length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 154 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 155 | ND_PRINT((ndo, " ripng-resp %d:", j)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 156 | trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); |
| 157 | for (ni = rp->rip6_nets; i >= sizeof(*ni); |
| 158 | i -= sizeof(*ni), ++ni) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 159 | if (ndo->ndo_vflag > 1) |
| 160 | ND_PRINT((ndo, "\n\t")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 161 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 162 | ND_PRINT((ndo, " ")); |
| 163 | rip6_entry_print(ndo, ni, ni->rip6_metric); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 164 | } |
| 165 | if (trunc) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 166 | ND_PRINT((ndo, "[|ripng]")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 167 | break; |
| 168 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 169 | ND_PRINT((ndo, " ripng-%d ?? %u", rp->rip6_cmd, length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 170 | break; |
| 171 | } |
| 172 | if (rp->rip6_vers != RIP6_VERSION) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 173 | ND_PRINT((ndo, " [vers %d]", rp->rip6_vers)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 174 | } |