Home | History | Annotate | Line # | Download | only in dist
print-ripng.c revision 1.1.1.7
      1      1.1  christos /*
      2      1.1  christos  * Copyright (c) 1989, 1990, 1991, 1993, 1994
      3      1.1  christos  *	The Regents of the University of California.  All rights reserved.
      4      1.1  christos  *
      5      1.1  christos  * Redistribution and use in source and binary forms, with or without
      6      1.1  christos  * modification, are permitted provided that: (1) source code distributions
      7      1.1  christos  * retain the above copyright notice and this paragraph in its entirety, (2)
      8      1.1  christos  * distributions including binary code include the above copyright notice and
      9      1.1  christos  * this paragraph in its entirety in the documentation or other materials
     10      1.1  christos  * provided with the distribution, and (3) all advertising materials mentioning
     11      1.1  christos  * features or use of this software display the following acknowledgement:
     12      1.1  christos  * ``This product includes software developed by the University of California,
     13      1.1  christos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
     14      1.1  christos  * the University nor the names of its contributors may be used to endorse
     15      1.1  christos  * or promote products derived from this software without specific prior
     16      1.1  christos  * written permission.
     17      1.1  christos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
     18      1.1  christos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
     19      1.1  christos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     20      1.1  christos  */
     21      1.1  christos 
     22  1.1.1.5       spz /* \summary: IPv6 Routing Information Protocol (RIPng) printer */
     23  1.1.1.5       spz 
     24  1.1.1.7  christos /* specification: RFC 2080 */
     25  1.1.1.7  christos 
     26      1.1  christos #ifdef HAVE_CONFIG_H
     27  1.1.1.7  christos #include <config.h>
     28      1.1  christos #endif
     29      1.1  christos 
     30  1.1.1.7  christos #include "netdissect-stdinc.h"
     31      1.1  christos 
     32  1.1.1.4  christos #include "netdissect.h"
     33      1.1  christos #include "addrtoname.h"
     34      1.1  christos #include "extract.h"
     35      1.1  christos 
     36  1.1.1.3  christos /*
     37  1.1.1.3  christos  * Copyright (C) 1995, 1996, 1997 and 1998 WIDE Project.
     38  1.1.1.3  christos  * All rights reserved.
     39  1.1.1.3  christos  *
     40  1.1.1.3  christos  * Redistribution and use in source and binary forms, with or without
     41  1.1.1.3  christos  * modification, are permitted provided that the following conditions
     42  1.1.1.3  christos  * are met:
     43  1.1.1.3  christos  * 1. Redistributions of source code must retain the above copyright
     44  1.1.1.3  christos  *    notice, this list of conditions and the following disclaimer.
     45  1.1.1.3  christos  * 2. Redistributions in binary form must reproduce the above copyright
     46  1.1.1.3  christos  *    notice, this list of conditions and the following disclaimer in the
     47  1.1.1.3  christos  *    documentation and/or other materials provided with the distribution.
     48  1.1.1.3  christos  * 3. Neither the name of the project nor the names of its contributors
     49  1.1.1.3  christos  *    may be used to endorse or promote products derived from this software
     50  1.1.1.3  christos  *    without specific prior written permission.
     51  1.1.1.3  christos  *
     52  1.1.1.3  christos  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     53  1.1.1.3  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54  1.1.1.3  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55  1.1.1.3  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     56  1.1.1.3  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57  1.1.1.3  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58  1.1.1.3  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59  1.1.1.3  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60  1.1.1.3  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61  1.1.1.3  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     62  1.1.1.3  christos  * SUCH DAMAGE.
     63  1.1.1.3  christos  */
     64  1.1.1.3  christos #define	RIP6_VERSION	1
     65  1.1.1.3  christos 
     66  1.1.1.3  christos #define	RIP6_REQUEST	1
     67  1.1.1.3  christos #define	RIP6_RESPONSE	2
     68  1.1.1.3  christos 
     69  1.1.1.3  christos struct netinfo6 {
     70  1.1.1.7  christos 	nd_ipv6		rip6_dest;
     71  1.1.1.7  christos 	nd_uint16_t	rip6_tag;
     72  1.1.1.7  christos 	nd_uint8_t	rip6_plen;
     73  1.1.1.7  christos 	nd_uint8_t	rip6_metric;
     74  1.1.1.3  christos };
     75  1.1.1.3  christos 
     76  1.1.1.3  christos struct	rip6 {
     77  1.1.1.7  christos 	nd_uint8_t	rip6_cmd;
     78  1.1.1.7  christos 	nd_uint8_t	rip6_vers;
     79  1.1.1.7  christos 	nd_byte		rip6_res1[2];
     80  1.1.1.7  christos 	struct netinfo6	rip6_nets[1];
     81  1.1.1.3  christos };
     82  1.1.1.3  christos 
     83  1.1.1.3  christos #define	HOPCNT_INFINITY6	16
     84  1.1.1.3  christos 
     85  1.1.1.7  christos static int ND_IN6_IS_ADDR_UNSPECIFIED(const nd_ipv6 *addr)
     86      1.1  christos {
     87  1.1.1.7  christos     static const nd_ipv6 in6addr_any_val = { 0 };        /* :: */
     88  1.1.1.7  christos     return (memcmp(addr, &in6addr_any_val, sizeof(*addr)) == 0);
     89      1.1  christos }
     90      1.1  christos 
     91  1.1.1.7  christos static void
     92  1.1.1.7  christos rip6_entry_print(netdissect_options *ndo,
     93  1.1.1.7  christos                  const struct netinfo6 *ni, const u_int print_metric)
     94      1.1  christos {
     95  1.1.1.7  christos 	uint16_t tag;
     96  1.1.1.7  christos 	uint8_t metric;
     97  1.1.1.7  christos 
     98  1.1.1.7  christos 	ND_PRINT("%s/%u", GET_IP6ADDR_STRING(ni->rip6_dest),
     99  1.1.1.7  christos 	         GET_U_1(ni->rip6_plen));
    100  1.1.1.7  christos 	tag = GET_BE_U_2(ni->rip6_tag);
    101  1.1.1.7  christos 	if (tag)
    102  1.1.1.7  christos 		ND_PRINT(" [%u]", tag);
    103  1.1.1.7  christos 	metric = GET_U_1(ni->rip6_metric);
    104  1.1.1.7  christos 	if (metric && print_metric)
    105  1.1.1.7  christos 		ND_PRINT(" (%u)", metric);
    106      1.1  christos }
    107      1.1  christos 
    108      1.1  christos void
    109  1.1.1.3  christos ripng_print(netdissect_options *ndo, const u_char *dat, unsigned int length)
    110      1.1  christos {
    111  1.1.1.7  christos 	const struct rip6 *rp = (const struct rip6 *)dat;
    112  1.1.1.7  christos 	uint8_t cmd, vers;
    113  1.1.1.7  christos 	const struct netinfo6 *ni;
    114  1.1.1.6  christos 	unsigned int length_left;
    115  1.1.1.6  christos 	u_int j;
    116      1.1  christos 
    117  1.1.1.7  christos 	ndo->ndo_protocol = "ripng";
    118  1.1.1.7  christos 	vers = GET_U_1(rp->rip6_vers);
    119  1.1.1.7  christos 	if (vers != RIP6_VERSION) {
    120  1.1.1.7  christos 		nd_print_protocol(ndo);
    121  1.1.1.7  christos 		ND_PRINT(" [version %u, must be %u]", vers, RIP6_VERSION);
    122  1.1.1.7  christos 		goto invalid;
    123  1.1.1.7  christos 	}
    124  1.1.1.7  christos 	cmd = GET_U_1(rp->rip6_cmd);
    125  1.1.1.7  christos 	switch (cmd) {
    126      1.1  christos 
    127      1.1  christos 	case RIP6_REQUEST:
    128  1.1.1.6  christos 		length_left = length;
    129  1.1.1.6  christos 		if (length_left < (sizeof(struct rip6) - sizeof(struct netinfo6)))
    130  1.1.1.7  christos 			goto invalid;
    131  1.1.1.6  christos 		length_left -= (sizeof(struct rip6) - sizeof(struct netinfo6));
    132  1.1.1.7  christos 		j = length_left / sizeof(*ni);
    133  1.1.1.6  christos 		if (j == 1) {
    134  1.1.1.7  christos 			if (GET_U_1(rp->rip6_nets->rip6_metric) == HOPCNT_INFINITY6
    135  1.1.1.7  christos 			    && ND_IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) {
    136  1.1.1.7  christos 				ND_PRINT(" ripng-req dump");
    137  1.1.1.6  christos 				break;
    138  1.1.1.6  christos 			}
    139      1.1  christos 		}
    140  1.1.1.6  christos 		if (j * sizeof(*ni) != length_left)
    141  1.1.1.7  christos 			ND_PRINT(" ripng-req %u[%u]:", j, length);
    142      1.1  christos 		else
    143  1.1.1.7  christos 			ND_PRINT(" ripng-req %u:", j);
    144  1.1.1.6  christos 		for (ni = rp->rip6_nets; length_left >= sizeof(*ni);
    145  1.1.1.6  christos 		    length_left -= sizeof(*ni), ++ni) {
    146  1.1.1.3  christos 			if (ndo->ndo_vflag > 1)
    147  1.1.1.7  christos 				ND_PRINT("\n\t");
    148      1.1  christos 			else
    149  1.1.1.7  christos 				ND_PRINT(" ");
    150  1.1.1.7  christos 			rip6_entry_print(ndo, ni, FALSE);
    151      1.1  christos 		}
    152  1.1.1.6  christos 		if (length_left != 0)
    153  1.1.1.7  christos 			goto invalid;
    154      1.1  christos 		break;
    155      1.1  christos 	case RIP6_RESPONSE:
    156  1.1.1.6  christos 		length_left = length;
    157  1.1.1.6  christos 		if (length_left < (sizeof(struct rip6) - sizeof(struct netinfo6)))
    158  1.1.1.7  christos 			goto invalid;
    159  1.1.1.6  christos 		length_left -= (sizeof(struct rip6) - sizeof(struct netinfo6));
    160  1.1.1.6  christos 		j = length_left / sizeof(*ni);
    161  1.1.1.6  christos 		if (j * sizeof(*ni) != length_left)
    162  1.1.1.7  christos 			ND_PRINT(" ripng-resp %u[%u]:", j, length);
    163      1.1  christos 		else
    164  1.1.1.7  christos 			ND_PRINT(" ripng-resp %u:", j);
    165  1.1.1.6  christos 		for (ni = rp->rip6_nets; length_left >= sizeof(*ni);
    166  1.1.1.6  christos 		    length_left -= sizeof(*ni), ++ni) {
    167  1.1.1.3  christos 			if (ndo->ndo_vflag > 1)
    168  1.1.1.7  christos 				ND_PRINT("\n\t");
    169      1.1  christos 			else
    170  1.1.1.7  christos 				ND_PRINT(" ");
    171  1.1.1.7  christos 			rip6_entry_print(ndo, ni, TRUE);
    172      1.1  christos 		}
    173  1.1.1.6  christos 		if (length_left != 0)
    174  1.1.1.7  christos 			goto invalid;
    175      1.1  christos 		break;
    176      1.1  christos 	default:
    177  1.1.1.7  christos 		ND_PRINT(" ripng-%u ?? %u", cmd, length);
    178  1.1.1.7  christos 		goto invalid;
    179      1.1  christos 	}
    180  1.1.1.6  christos 	return;
    181  1.1.1.6  christos 
    182  1.1.1.7  christos invalid:
    183  1.1.1.7  christos 	nd_print_invalid(ndo);
    184      1.1  christos }
    185