1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * Portions of this source code were derived from Berkeley 4.3 BSD
32  * under license from the Regents of the University of California.
33  */
34 
35 /*
36  * Routing Table Management Daemon
37  */
38 #include "defs.h"
39 
40 /*
41  * Find the interface with given name.
42  */
43 struct interface *
if_ifwithname(char * name)44 if_ifwithname(char *name)
45 {
46 	struct interface *ifp;
47 
48 	for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next) {
49 		if (ifp->int_name != NULL &&
50 		    strcmp(ifp->int_name, name) == 0)
51 			break;
52 	}
53 	return (ifp);
54 }
55 
56 /*
57  * An interface has declared itself down - remove it completely
58  * from our routing tables but keep the interface structure around.
59  */
60 void
if_purge(struct interface * pifp)61 if_purge(struct interface *pifp)
62 {
63 	rtpurgeif(pifp);
64 	pifp->int_flags &= ~RIP6_IFF_UP;
65 }
66 
67 static void
if_dump2(FILE * fp)68 if_dump2(FILE *fp)
69 {
70 	struct interface *ifp;
71 	char buf1[INET6_ADDRSTRLEN];
72 	static struct bits {
73 		uint_t	t_bits;
74 		char	*t_name;
75 	} flagbits[] = {
76 		/* BEGIN CSTYLED */
77 		{ RIP6_IFF_UP,		"UP" },
78 		{ RIP6_IFF_POINTOPOINT,	"POINTOPOINT" },
79 		{ RIP6_IFF_MARKED,	"MARKED" },
80 		{ RIP6_IFF_NORTEXCH,	"NORTEXCH" },
81 		{ RIP6_IFF_PRIVATE,	"PRIVATE" },
82 		{ 0,			NULL }
83 		/* END CSTYLED */
84 	};
85 	struct bits *p;
86 	char c;
87 	boolean_t first;
88 
89 	for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next) {
90 		(void) fprintf(fp, "interface %s:\n",
91 		    (ifp->int_name != NULL) ? ifp->int_name : "(noname)");
92 
93 		(void) fprintf(fp, "\tflags ");
94 		c = ' ';
95 		for (first = _B_TRUE, p = flagbits; p->t_bits > 0; p++) {
96 			if ((ifp->int_flags & p->t_bits) == 0)
97 				continue;
98 			(void) fprintf(fp, "%c%s", c, p->t_name);
99 			if (first) {
100 				c = '|';
101 				first = _B_FALSE;
102 			}
103 		}
104 		if (first)
105 			(void) fprintf(fp, " 0");
106 
107 		(void) fprintf(fp, "\n\tpackets received %d\n",
108 		    ifp->int_ipackets);
109 		(void) fprintf(fp, "\tpackets sent %d\n", ifp->int_opackets);
110 		(void) fprintf(fp, "\ttransitions %d\n", ifp->int_transitions);
111 		if ((ifp->int_flags & RIP6_IFF_UP) == 0)
112 			continue;
113 		if (ifp->int_flags & RIP6_IFF_POINTOPOINT) {
114 			(void) fprintf(fp, "\tlocal %s\n",
115 			    inet_ntop(AF_INET6, (void *)&ifp->int_addr, buf1,
116 				sizeof (buf1)));
117 			(void) fprintf(fp, "\tremote %s\n",
118 			    inet_ntop(AF_INET6, (void *)&ifp->int_dstaddr, buf1,
119 				sizeof (buf1)));
120 		} else {
121 			(void) fprintf(fp, "\tprefix %s/%d\n",
122 			    inet_ntop(AF_INET6, (void *)&ifp->int_addr, buf1,
123 				sizeof (buf1)),
124 			    ifp->int_prefix_length);
125 		}
126 		(void) fprintf(fp, "\tmetric %d\n", ifp->int_metric);
127 		(void) fprintf(fp, "\tmtu %d\n", ifp->int_mtu);
128 	}
129 	(void) fflush(fp);
130 }
131 
132 void
if_dump(void)133 if_dump(void)
134 {
135 	if (ftrace != NULL)
136 		if_dump2(ftrace);
137 	else
138 		if_dump2(stderr);
139 }
140