1b0453382SBill Fenner /* 2b0453382SBill Fenner * Copyright (c) 1989, 1990, 1991, 1993, 1994 3b0453382SBill Fenner * The Regents of the University of California. All rights reserved. 4b0453382SBill Fenner * 5b0453382SBill Fenner * Redistribution and use in source and binary forms, with or without 6b0453382SBill Fenner * modification, are permitted provided that: (1) source code distributions 7b0453382SBill Fenner * retain the above copyright notice and this paragraph in its entirety, (2) 8b0453382SBill Fenner * distributions including binary code include the above copyright notice and 9b0453382SBill Fenner * this paragraph in its entirety in the documentation or other materials 10b0453382SBill Fenner * provided with the distribution, and (3) all advertising materials mentioning 11b0453382SBill Fenner * features or use of this software display the following acknowledgement: 12b0453382SBill Fenner * ``This product includes software developed by the University of California, 13b0453382SBill Fenner * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14b0453382SBill Fenner * the University nor the names of its contributors may be used to endorse 15b0453382SBill Fenner * or promote products derived from this software without specific prior 16b0453382SBill Fenner * written permission. 17b0453382SBill Fenner * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18b0453382SBill Fenner * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19b0453382SBill Fenner * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20b0453382SBill Fenner */ 21b0453382SBill Fenner 223340d773SGleb Smirnoff /* \summary: IPv6 Routing Information Protocol (RIPng) printer */ 233340d773SGleb Smirnoff 24b0453382SBill Fenner #ifdef HAVE_CONFIG_H 25b0453382SBill Fenner #include "config.h" 26b0453382SBill Fenner #endif 27b0453382SBill Fenner 283340d773SGleb Smirnoff #include <netdissect-stdinc.h> 29b0453382SBill Fenner 303340d773SGleb Smirnoff #include "netdissect.h" 31b0453382SBill Fenner #include "addrtoname.h" 325b0fe478SBruce M Simpson #include "extract.h" 33b0453382SBill Fenner 343c602fabSXin LI /* 353c602fabSXin LI * Copyright (C) 1995, 1996, 1997 and 1998 WIDE Project. 363c602fabSXin LI * All rights reserved. 373c602fabSXin LI * 383c602fabSXin LI * Redistribution and use in source and binary forms, with or without 393c602fabSXin LI * modification, are permitted provided that the following conditions 403c602fabSXin LI * are met: 413c602fabSXin LI * 1. Redistributions of source code must retain the above copyright 423c602fabSXin LI * notice, this list of conditions and the following disclaimer. 433c602fabSXin LI * 2. Redistributions in binary form must reproduce the above copyright 443c602fabSXin LI * notice, this list of conditions and the following disclaimer in the 453c602fabSXin LI * documentation and/or other materials provided with the distribution. 463c602fabSXin LI * 3. Neither the name of the project nor the names of its contributors 473c602fabSXin LI * may be used to endorse or promote products derived from this software 483c602fabSXin LI * without specific prior written permission. 493c602fabSXin LI * 503c602fabSXin LI * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 513c602fabSXin LI * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 523c602fabSXin LI * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 533c602fabSXin LI * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 543c602fabSXin LI * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 553c602fabSXin LI * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 563c602fabSXin LI * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 573c602fabSXin LI * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 583c602fabSXin LI * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 593c602fabSXin LI * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 603c602fabSXin LI * SUCH DAMAGE. 613c602fabSXin LI */ 623c602fabSXin LI #define RIP6_VERSION 1 633c602fabSXin LI 643c602fabSXin LI #define RIP6_REQUEST 1 653c602fabSXin LI #define RIP6_RESPONSE 2 663c602fabSXin LI 673c602fabSXin LI struct netinfo6 { 683c602fabSXin LI struct in6_addr rip6_dest; 693c602fabSXin LI uint16_t rip6_tag; 703c602fabSXin LI uint8_t rip6_plen; 713c602fabSXin LI uint8_t rip6_metric; 723c602fabSXin LI }; 733c602fabSXin LI 743c602fabSXin LI struct rip6 { 753c602fabSXin LI uint8_t rip6_cmd; 763c602fabSXin LI uint8_t rip6_vers; 773c602fabSXin LI uint8_t rip6_res1[2]; 783c602fabSXin LI union { 793c602fabSXin LI struct netinfo6 ru6_nets[1]; 803c602fabSXin LI char ru6_tracefile[1]; 813c602fabSXin LI } rip6un; 823c602fabSXin LI #define rip6_nets rip6un.ru6_nets 833c602fabSXin LI #define rip6_tracefile rip6un.ru6_tracefile 843c602fabSXin LI }; 853c602fabSXin LI 863c602fabSXin LI #define HOPCNT_INFINITY6 16 873c602fabSXin LI 881de50e9fSSam Leffler #if !defined(IN6_IS_ADDR_UNSPECIFIED) && !defined(_MSC_VER) /* MSVC inline */ 891de50e9fSSam Leffler static int IN6_IS_ADDR_UNSPECIFIED(const struct in6_addr *addr) 901de50e9fSSam Leffler { 911de50e9fSSam Leffler static const struct in6_addr in6addr_any; /* :: */ 921de50e9fSSam Leffler return (memcmp(addr, &in6addr_any, sizeof(*addr)) == 0); 931de50e9fSSam Leffler } 941de50e9fSSam Leffler #endif 951de50e9fSSam Leffler 96b0453382SBill Fenner static int 973c602fabSXin LI rip6_entry_print(netdissect_options *ndo, register const struct netinfo6 *ni, int metric) 98b0453382SBill Fenner { 99b0453382SBill Fenner int l; 1003c602fabSXin LI l = ND_PRINT((ndo, "%s/%d", ip6addr_string(ndo, &ni->rip6_dest), ni->rip6_plen)); 101b0453382SBill Fenner if (ni->rip6_tag) 1023c602fabSXin LI l += ND_PRINT((ndo, " [%d]", EXTRACT_16BITS(&ni->rip6_tag))); 103b0453382SBill Fenner if (metric) 1043c602fabSXin LI l += ND_PRINT((ndo, " (%d)", ni->rip6_metric)); 105b0453382SBill Fenner return l; 106b0453382SBill Fenner } 107b0453382SBill Fenner 108b0453382SBill Fenner void 1093c602fabSXin LI ripng_print(netdissect_options *ndo, const u_char *dat, unsigned int length) 110b0453382SBill Fenner { 1113340d773SGleb Smirnoff register const struct rip6 *rp = (const struct rip6 *)dat; 112b0453382SBill Fenner register const struct netinfo6 *ni; 113*0bff6a5aSEd Maste unsigned int length_left; 114*0bff6a5aSEd Maste u_int j; 115b0453382SBill Fenner 116*0bff6a5aSEd Maste ND_TCHECK(rp->rip6_cmd); 117b0453382SBill Fenner switch (rp->rip6_cmd) { 118b0453382SBill Fenner 119b0453382SBill Fenner case RIP6_REQUEST: 120*0bff6a5aSEd Maste length_left = length; 121*0bff6a5aSEd Maste if (length_left < (sizeof(struct rip6) - sizeof(struct netinfo6))) 122*0bff6a5aSEd Maste goto trunc; 123*0bff6a5aSEd Maste length_left -= (sizeof(struct rip6) - sizeof(struct netinfo6)); 124*0bff6a5aSEd Maste j = length_left / sizeof(*ni); 125*0bff6a5aSEd Maste if (j == 1) { 126*0bff6a5aSEd Maste ND_TCHECK(rp->rip6_nets); 127*0bff6a5aSEd Maste if (rp->rip6_nets->rip6_metric == HOPCNT_INFINITY6 128b0453382SBill Fenner && IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) { 1293c602fabSXin LI ND_PRINT((ndo, " ripng-req dump")); 130b0453382SBill Fenner break; 131b0453382SBill Fenner } 132*0bff6a5aSEd Maste } 133*0bff6a5aSEd Maste if (j * sizeof(*ni) != length_left) 134*0bff6a5aSEd Maste ND_PRINT((ndo, " ripng-req %u[%u]:", j, length)); 135b0453382SBill Fenner else 136*0bff6a5aSEd Maste ND_PRINT((ndo, " ripng-req %u:", j)); 137*0bff6a5aSEd Maste for (ni = rp->rip6_nets; length_left >= sizeof(*ni); 138*0bff6a5aSEd Maste length_left -= sizeof(*ni), ++ni) { 139*0bff6a5aSEd Maste ND_TCHECK(*ni); 1403c602fabSXin LI if (ndo->ndo_vflag > 1) 1413c602fabSXin LI ND_PRINT((ndo, "\n\t")); 142b0453382SBill Fenner else 1433c602fabSXin LI ND_PRINT((ndo, " ")); 1443c602fabSXin LI rip6_entry_print(ndo, ni, 0); 145b0453382SBill Fenner } 146*0bff6a5aSEd Maste if (length_left != 0) 147*0bff6a5aSEd Maste goto trunc; 148b0453382SBill Fenner break; 149b0453382SBill Fenner case RIP6_RESPONSE: 150*0bff6a5aSEd Maste length_left = length; 151*0bff6a5aSEd Maste if (length_left < (sizeof(struct rip6) - sizeof(struct netinfo6))) 152*0bff6a5aSEd Maste goto trunc; 153*0bff6a5aSEd Maste length_left -= (sizeof(struct rip6) - sizeof(struct netinfo6)); 154*0bff6a5aSEd Maste j = length_left / sizeof(*ni); 155*0bff6a5aSEd Maste if (j * sizeof(*ni) != length_left) 1563c602fabSXin LI ND_PRINT((ndo, " ripng-resp %d[%u]:", j, length)); 157b0453382SBill Fenner else 1583c602fabSXin LI ND_PRINT((ndo, " ripng-resp %d:", j)); 159*0bff6a5aSEd Maste for (ni = rp->rip6_nets; length_left >= sizeof(*ni); 160*0bff6a5aSEd Maste length_left -= sizeof(*ni), ++ni) { 161*0bff6a5aSEd Maste ND_TCHECK(*ni); 1623c602fabSXin LI if (ndo->ndo_vflag > 1) 1633c602fabSXin LI ND_PRINT((ndo, "\n\t")); 164b0453382SBill Fenner else 1653c602fabSXin LI ND_PRINT((ndo, " ")); 1663c602fabSXin LI rip6_entry_print(ndo, ni, ni->rip6_metric); 167b0453382SBill Fenner } 168*0bff6a5aSEd Maste if (length_left != 0) 169*0bff6a5aSEd Maste goto trunc; 170b0453382SBill Fenner break; 171b0453382SBill Fenner default: 1723c602fabSXin LI ND_PRINT((ndo, " ripng-%d ?? %u", rp->rip6_cmd, length)); 173b0453382SBill Fenner break; 174b0453382SBill Fenner } 175*0bff6a5aSEd Maste ND_TCHECK(rp->rip6_vers); 176b0453382SBill Fenner if (rp->rip6_vers != RIP6_VERSION) 1773c602fabSXin LI ND_PRINT((ndo, " [vers %d]", rp->rip6_vers)); 178*0bff6a5aSEd Maste return; 179*0bff6a5aSEd Maste 180*0bff6a5aSEd Maste trunc: 181*0bff6a5aSEd Maste ND_PRINT((ndo, "[|ripng]")); 182*0bff6a5aSEd Maste return; 183b0453382SBill Fenner } 184