xref: /titanic_50/usr/src/cmd/cmd-inet/usr.lib/in.ripngd/if.c (revision 20c794b39650d115e17a15983b6b82e46238cf45)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
36 
37 /*
38  * Routing Table Management Daemon
39  */
40 #include "defs.h"
41 
42 /*
43  * Find the interface with given name.
44  */
45 struct interface *
46 if_ifwithname(char *name)
47 {
48 	struct interface *ifp;
49 
50 	for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next) {
51 		if (ifp->int_name != NULL &&
52 		    strcmp(ifp->int_name, name) == 0)
53 			break;
54 	}
55 	return (ifp);
56 }
57 
58 /*
59  * An interface has declared itself down - remove it completely
60  * from our routing tables but keep the interface structure around.
61  */
62 void
63 if_purge(struct interface *pifp)
64 {
65 	rtpurgeif(pifp);
66 	pifp->int_flags &= ~RIP6_IFF_UP;
67 }
68 
69 static void
70 if_dump2(FILE *fp)
71 {
72 	struct interface *ifp;
73 	char buf1[INET6_ADDRSTRLEN];
74 	static struct bits {
75 		uint_t	t_bits;
76 		char	*t_name;
77 	} flagbits[] = {
78 		/* BEGIN CSTYLED */
79 		{ RIP6_IFF_UP,		"UP" },
80 		{ RIP6_IFF_POINTOPOINT,	"POINTOPOINT" },
81 		{ RIP6_IFF_MARKED,	"MARKED" },
82 		{ RIP6_IFF_NORTEXCH,	"NORTEXCH" },
83 		{ RIP6_IFF_PRIVATE,	"PRIVATE" },
84 		{ 0,			NULL }
85 		/* END CSTYLED */
86 	};
87 	struct bits *p;
88 	char c;
89 	boolean_t first;
90 
91 	for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next) {
92 		(void) fprintf(fp, "interface %s:\n",
93 		    (ifp->int_name != NULL) ? ifp->int_name : "(noname)");
94 
95 		(void) fprintf(fp, "\tflags ");
96 		c = ' ';
97 		for (first = _B_TRUE, p = flagbits; p->t_bits > 0; p++) {
98 			if ((ifp->int_flags & p->t_bits) == 0)
99 				continue;
100 			(void) fprintf(fp, "%c%s", c, p->t_name);
101 			if (first) {
102 				c = '|';
103 				first = _B_FALSE;
104 			}
105 		}
106 		if (first)
107 			(void) fprintf(fp, " 0");
108 
109 		(void) fprintf(fp, "\n\tpackets received %d\n",
110 		    ifp->int_ipackets);
111 		(void) fprintf(fp, "\tpackets sent %d\n", ifp->int_opackets);
112 		(void) fprintf(fp, "\ttransitions %d\n", ifp->int_transitions);
113 		if ((ifp->int_flags & RIP6_IFF_UP) == 0)
114 			continue;
115 		if (ifp->int_flags & RIP6_IFF_POINTOPOINT) {
116 			(void) fprintf(fp, "\tlocal %s\n",
117 			    inet_ntop(AF_INET6, (void *)&ifp->int_addr, buf1,
118 				sizeof (buf1)));
119 			(void) fprintf(fp, "\tremote %s\n",
120 			    inet_ntop(AF_INET6, (void *)&ifp->int_dstaddr, buf1,
121 				sizeof (buf1)));
122 		} else {
123 			(void) fprintf(fp, "\tprefix %s/%d\n",
124 			    inet_ntop(AF_INET6, (void *)&ifp->int_addr, buf1,
125 				sizeof (buf1)),
126 			    ifp->int_prefix_length);
127 		}
128 		(void) fprintf(fp, "\tmetric %d\n", ifp->int_metric);
129 		(void) fprintf(fp, "\tmtu %d\n", ifp->int_mtu);
130 	}
131 	(void) fflush(fp);
132 }
133 
134 void
135 if_dump(void)
136 {
137 	if (ftrace != NULL)
138 		if_dump2(ftrace);
139 	else
140 		if_dump2(stderr);
141 }
142