The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2001 William C. Fenner. |
| 3 | * 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 |
| 7 | * distributions retain the above copyright notice and this paragraph |
| 8 | * in its entirety, and (2) distributions including binary code include |
| 9 | * the above copyright notice and this paragraph in its entirety in |
| 10 | * the documentation or other materials provided with the distribution. |
| 11 | * The name of William C. Fenner may not be used to endorse or |
| 12 | * promote products derived from this software without specific prior |
| 13 | * written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND |
| 14 | * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT |
| 15 | * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 16 | * FOR A PARTICULAR PURPOSE. |
| 17 | */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 18 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 19 | /* \summary: Multicast Source Discovery Protocol (MSDP) printer */ |
| 20 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 21 | #ifdef HAVE_CONFIG_H |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 22 | #include <config.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 23 | #endif |
| 24 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 25 | #include "netdissect-stdinc.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 26 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 27 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 28 | #include "addrtoname.h" |
| 29 | #include "extract.h" |
| 30 | |
| 31 | #define MSDP_TYPE_MAX 7 |
| 32 | |
| 33 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 34 | msdp_print(netdissect_options *ndo, const u_char *sp, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 35 | { |
| 36 | unsigned int type, len; |
| 37 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 38 | ndo->ndo_protocol = "msdp"; |
| 39 | ND_PRINT(": "); |
| 40 | nd_print_protocol(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 41 | /* See if we think we're at the beginning of a compound packet */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 42 | type = GET_U_1(sp); |
| 43 | len = GET_BE_U_2(sp + 1); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 44 | if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX) |
| 45 | goto trunc; /* not really truncated, but still not decodable */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 46 | while (length != 0) { |
| 47 | type = GET_U_1(sp); |
| 48 | len = GET_BE_U_2(sp + 1); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 49 | if (len > 1400 || ndo->ndo_vflag) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 50 | ND_PRINT(" [len %u]", len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 51 | if (len < 3) |
| 52 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 53 | if (length < len) |
| 54 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 55 | sp += 3; |
| 56 | length -= 3; |
| 57 | switch (type) { |
| 58 | case 1: /* IPv4 Source-Active */ |
| 59 | case 3: /* IPv4 Source-Active Response */ |
| 60 | if (type == 1) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 61 | ND_PRINT(" SA"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 62 | else |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 63 | ND_PRINT(" SA-Response"); |
| 64 | ND_PRINT(" %u entries", GET_U_1(sp)); |
| 65 | if ((u_int)((GET_U_1(sp) * 12) + 8) < len) { |
| 66 | ND_PRINT(" [w/data]"); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 67 | if (ndo->ndo_vflag > 1) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 68 | ND_PRINT(" "); |
| 69 | ip_print(ndo, sp + |
| 70 | GET_U_1(sp) * 12 + 8 - 3, |
| 71 | len - (GET_U_1(sp) * 12 + 8)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | break; |
| 75 | case 2: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 76 | ND_PRINT(" SA-Request"); |
| 77 | ND_PRINT(" for %s", GET_IPADDR_STRING(sp + 1)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 78 | break; |
| 79 | case 4: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 80 | ND_PRINT(" Keepalive"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 81 | if (len != 3) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 82 | ND_PRINT("[len=%u] ", len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 83 | break; |
| 84 | case 5: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 85 | ND_PRINT(" Notification"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 86 | break; |
| 87 | default: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 88 | ND_PRINT(" [type=%u len=%u]", type, len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 89 | break; |
| 90 | } |
| 91 | sp += (len - 3); |
| 92 | length -= (len - 3); |
| 93 | } |
| 94 | return; |
| 95 | trunc: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 96 | nd_print_trunc(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 97 | } |