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