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