10f74e101Schristos /* 20f74e101Schristos * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994 30f74e101Schristos * The Regents of the University of California. All rights reserved. 40f74e101Schristos * 50f74e101Schristos * Redistribution and use in source and binary forms, with or without 60f74e101Schristos * modification, are permitted provided that: (1) source code distributions 70f74e101Schristos * retain the above copyright notice and this paragraph in its entirety, (2) 80f74e101Schristos * distributions including binary code include the above copyright notice and 90f74e101Schristos * this paragraph in its entirety in the documentation or other materials 100f74e101Schristos * provided with the distribution, and (3) all advertising materials mentioning 110f74e101Schristos * features or use of this software display the following acknowledgement: 120f74e101Schristos * ``This product includes software developed by the University of California, 130f74e101Schristos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 140f74e101Schristos * the University nor the names of its contributors may be used to endorse 150f74e101Schristos * or promote products derived from this software without specific prior 160f74e101Schristos * written permission. 170f74e101Schristos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 180f74e101Schristos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 190f74e101Schristos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 200f74e101Schristos */ 210f74e101Schristos 2211b3aaa1Schristos #include <sys/cdefs.h> 230f74e101Schristos #ifndef lint 24*26ba0b50Schristos __RCSID("$NetBSD: print-rt6.c,v 1.9 2024/09/02 16:15:32 christos Exp $"); 250f74e101Schristos #endif 260f74e101Schristos 27dc860a36Sspz /* \summary: IPv6 routing header printer */ 28dc860a36Sspz 29c74ad251Schristos #include <config.h> 300f74e101Schristos 31c74ad251Schristos #include "netdissect-stdinc.h" 320f74e101Schristos 33fdccd7e4Schristos #include "netdissect.h" 340f74e101Schristos #include "addrtoname.h" 350f74e101Schristos #include "extract.h" 360f74e101Schristos 3772c96ff3Schristos #include "ip6.h" 3872c96ff3Schristos 390f74e101Schristos int 40c74ad251Schristos rt6_print(netdissect_options *ndo, const u_char *bp, const u_char *bp2 _U_) 410f74e101Schristos { 42c74ad251Schristos const struct ip6_rthdr *dp; 43c74ad251Schristos const struct ip6_rthdr0 *dp0; 44c74ad251Schristos const struct ip6_srh *srh; 45c74ad251Schristos u_int i, len, type; 46c74ad251Schristos const u_char *p; 470f74e101Schristos 48c74ad251Schristos ndo->ndo_protocol = "rt6"; 49c74ad251Schristos 50c74ad251Schristos nd_print_protocol_caps(ndo); 51fdccd7e4Schristos dp = (const struct ip6_rthdr *)bp; 520f74e101Schristos 53c74ad251Schristos len = GET_U_1(dp->ip6r_len); 54c74ad251Schristos ND_PRINT(" (len=%u", len); /*)*/ 55c74ad251Schristos type = GET_U_1(dp->ip6r_type); 56c74ad251Schristos ND_PRINT(", type=%u", type); 57c74ad251Schristos if (type == IPV6_RTHDR_TYPE_0) 58c74ad251Schristos ND_PRINT(" [Deprecated]"); 59c74ad251Schristos ND_PRINT(", segleft=%u", GET_U_1(dp->ip6r_segleft)); 600f74e101Schristos 61c74ad251Schristos switch (type) { 620f74e101Schristos case IPV6_RTHDR_TYPE_0: 630f74e101Schristos case IPV6_RTHDR_TYPE_2: /* Mobile IPv6 ID-20 */ 64fdccd7e4Schristos dp0 = (const struct ip6_rthdr0 *)dp; 650f74e101Schristos 66c74ad251Schristos if (GET_BE_U_4(dp0->ip6r0_reserved) || ndo->ndo_vflag) { 67c74ad251Schristos ND_PRINT(", rsv=0x%0x", 68c74ad251Schristos GET_BE_U_4(dp0->ip6r0_reserved)); 690f74e101Schristos } 700f74e101Schristos 71c74ad251Schristos if (len % 2 == 1) { 72*26ba0b50Schristos ND_PRINT(" [length %u]", len); 73c74ad251Schristos goto invalid; 74c74ad251Schristos } 750f74e101Schristos len >>= 1; 76c74ad251Schristos p = (const u_char *) dp0->ip6r0_addr; 770f74e101Schristos for (i = 0; i < len; i++) { 78c74ad251Schristos ND_PRINT(", [%u]%s", i, GET_IP6ADDR_STRING(p)); 79c74ad251Schristos p += 16; 800f74e101Schristos } 810f74e101Schristos /*(*/ 82c74ad251Schristos ND_PRINT(") "); 83c74ad251Schristos return((GET_U_1(dp0->ip6r0_len) + 1) << 3); 840f74e101Schristos break; 85c74ad251Schristos case IPV6_RTHDR_TYPE_4: 86c74ad251Schristos srh = (const struct ip6_srh *)dp; 87c74ad251Schristos ND_PRINT(", last-entry=%u", GET_U_1(srh->srh_last_ent)); 88c74ad251Schristos 89c74ad251Schristos if (GET_U_1(srh->srh_flags) || ndo->ndo_vflag) { 90c74ad251Schristos ND_PRINT(", flags=0x%0x", 91c74ad251Schristos GET_U_1(srh->srh_flags)); 920f74e101Schristos } 930f74e101Schristos 94c74ad251Schristos ND_PRINT(", tag=%x", GET_BE_U_2(srh->srh_tag)); 95c74ad251Schristos 96c74ad251Schristos if (len % 2 == 1) { 97c74ad251Schristos ND_PRINT(" (invalid length %u)", len); 98c74ad251Schristos goto invalid; 99c74ad251Schristos } 100c74ad251Schristos len >>= 1; 101c74ad251Schristos p = (const u_char *) srh->srh_segments; 102c74ad251Schristos for (i = 0; i < len; i++) { 103c74ad251Schristos ND_PRINT(", [%u]%s", i, GET_IP6ADDR_STRING(p)); 104c74ad251Schristos p += 16; 105c74ad251Schristos } 106c74ad251Schristos /*(*/ 107c74ad251Schristos ND_PRINT(") "); 108c74ad251Schristos return((GET_U_1(srh->srh_len) + 1) << 3); 109c74ad251Schristos break; 110c74ad251Schristos default: 111c74ad251Schristos ND_PRINT(" (unknown type)"); 112c74ad251Schristos goto invalid; 113c74ad251Schristos } 114c74ad251Schristos 115c74ad251Schristos invalid: 116c74ad251Schristos nd_print_invalid(ndo); 1170f74e101Schristos return -1; 1180f74e101Schristos } 119