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 2003 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 #include "defs.h"
28*7c478bd9Sstevel@tonic-gate #include "tables.h"
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate static void print_opt(struct nd_opt_hdr *opt, int len);
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate void
print_route_sol(char * str,struct phyint * pi,struct nd_router_solicit * rs,int len,struct sockaddr_in6 * addr)33*7c478bd9Sstevel@tonic-gate print_route_sol(char *str, struct phyint *pi,
34*7c478bd9Sstevel@tonic-gate struct nd_router_solicit *rs, int len, struct sockaddr_in6 *addr)
35*7c478bd9Sstevel@tonic-gate {
36*7c478bd9Sstevel@tonic-gate struct nd_opt_hdr *opt;
37*7c478bd9Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "%s %s (%d bytes) on %s\n", str,
40*7c478bd9Sstevel@tonic-gate inet_ntop(addr->sin6_family, (void *)&addr->sin6_addr,
41*7c478bd9Sstevel@tonic-gate abuf, sizeof (abuf)),
42*7c478bd9Sstevel@tonic-gate len, pi->pi_name);
43*7c478bd9Sstevel@tonic-gate
44*7c478bd9Sstevel@tonic-gate len -= sizeof (*rs);
45*7c478bd9Sstevel@tonic-gate opt = (struct nd_opt_hdr *)&rs[1];
46*7c478bd9Sstevel@tonic-gate print_opt(opt, len);
47*7c478bd9Sstevel@tonic-gate }
48*7c478bd9Sstevel@tonic-gate
49*7c478bd9Sstevel@tonic-gate void
print_route_adv(char * str,struct phyint * pi,struct nd_router_advert * ra,int len,struct sockaddr_in6 * addr)50*7c478bd9Sstevel@tonic-gate print_route_adv(char *str, struct phyint *pi,
51*7c478bd9Sstevel@tonic-gate struct nd_router_advert *ra, int len, struct sockaddr_in6 *addr)
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate struct nd_opt_hdr *opt;
54*7c478bd9Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "%s %s (%d bytes) on %s\n", str,
57*7c478bd9Sstevel@tonic-gate inet_ntop(addr->sin6_family, (void *)&addr->sin6_addr,
58*7c478bd9Sstevel@tonic-gate abuf, sizeof (abuf)),
59*7c478bd9Sstevel@tonic-gate len, pi->pi_name);
60*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tMax hop limit: %u\n", ra->nd_ra_curhoplimit);
61*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tManaged address configuration: %s\n",
62*7c478bd9Sstevel@tonic-gate (ra->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) ?
63*7c478bd9Sstevel@tonic-gate "Set" : "Not set");
64*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tOther configuration flag: %s\n",
65*7c478bd9Sstevel@tonic-gate (ra->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) ?
66*7c478bd9Sstevel@tonic-gate "Set" : "Not set");
67*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tRouter lifetime: %u\n",
68*7c478bd9Sstevel@tonic-gate ntohs(ra->nd_ra_router_lifetime));
69*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tReachable timer: %u\n",
70*7c478bd9Sstevel@tonic-gate ntohl(ra->nd_ra_reachable));
71*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tReachable retrans timer: %u\n",
72*7c478bd9Sstevel@tonic-gate ntohl(ra->nd_ra_retransmit));
73*7c478bd9Sstevel@tonic-gate
74*7c478bd9Sstevel@tonic-gate len -= sizeof (*ra);
75*7c478bd9Sstevel@tonic-gate opt = (struct nd_opt_hdr *)&ra[1];
76*7c478bd9Sstevel@tonic-gate print_opt(opt, len);
77*7c478bd9Sstevel@tonic-gate }
78*7c478bd9Sstevel@tonic-gate
79*7c478bd9Sstevel@tonic-gate static void
print_opt(struct nd_opt_hdr * opt,int len)80*7c478bd9Sstevel@tonic-gate print_opt(struct nd_opt_hdr *opt, int len)
81*7c478bd9Sstevel@tonic-gate {
82*7c478bd9Sstevel@tonic-gate struct nd_opt_prefix_info *po;
83*7c478bd9Sstevel@tonic-gate struct nd_opt_mtu *mo;
84*7c478bd9Sstevel@tonic-gate struct nd_opt_lla *lo;
85*7c478bd9Sstevel@tonic-gate int optlen;
86*7c478bd9Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
87*7c478bd9Sstevel@tonic-gate char llabuf[BUFSIZ];
88*7c478bd9Sstevel@tonic-gate
89*7c478bd9Sstevel@tonic-gate while (len >= sizeof (struct nd_opt_hdr)) {
90*7c478bd9Sstevel@tonic-gate optlen = opt->nd_opt_len * 8;
91*7c478bd9Sstevel@tonic-gate if (optlen == 0) {
92*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "Zero length option!\n");
93*7c478bd9Sstevel@tonic-gate break;
94*7c478bd9Sstevel@tonic-gate }
95*7c478bd9Sstevel@tonic-gate switch (opt->nd_opt_type) {
96*7c478bd9Sstevel@tonic-gate case ND_OPT_PREFIX_INFORMATION:
97*7c478bd9Sstevel@tonic-gate po = (struct nd_opt_prefix_info *)opt;
98*7c478bd9Sstevel@tonic-gate if (optlen != sizeof (*po) ||
99*7c478bd9Sstevel@tonic-gate optlen > len)
100*7c478bd9Sstevel@tonic-gate break;
101*7c478bd9Sstevel@tonic-gate
102*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tPrefix: %s/%u\n",
103*7c478bd9Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&po->nd_opt_pi_prefix,
104*7c478bd9Sstevel@tonic-gate abuf, sizeof (abuf)),
105*7c478bd9Sstevel@tonic-gate po->nd_opt_pi_prefix_len);
106*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\t\tOn link flag:%s\n",
107*7c478bd9Sstevel@tonic-gate (po->nd_opt_pi_flags_reserved &
108*7c478bd9Sstevel@tonic-gate ND_OPT_PI_FLAG_ONLINK) ?
109*7c478bd9Sstevel@tonic-gate "Set" : "Not set");
110*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\t\tAuto addrconf flag:%s\n",
111*7c478bd9Sstevel@tonic-gate (po->nd_opt_pi_flags_reserved &
112*7c478bd9Sstevel@tonic-gate ND_OPT_PI_FLAG_AUTO) ?
113*7c478bd9Sstevel@tonic-gate "Set" : "Not set");
114*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\t\tValid time: %u\n",
115*7c478bd9Sstevel@tonic-gate ntohl(po->nd_opt_pi_valid_time));
116*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\t\tPreferred time: %u\n",
117*7c478bd9Sstevel@tonic-gate ntohl(po->nd_opt_pi_preferred_time));
118*7c478bd9Sstevel@tonic-gate break;
119*7c478bd9Sstevel@tonic-gate case ND_OPT_MTU:
120*7c478bd9Sstevel@tonic-gate mo = (struct nd_opt_mtu *)opt;
121*7c478bd9Sstevel@tonic-gate if (optlen != sizeof (*mo) ||
122*7c478bd9Sstevel@tonic-gate optlen > len)
123*7c478bd9Sstevel@tonic-gate break;
124*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tMTU: %d\n",
125*7c478bd9Sstevel@tonic-gate ntohl(mo->nd_opt_mtu_mtu));
126*7c478bd9Sstevel@tonic-gate break;
127*7c478bd9Sstevel@tonic-gate case ND_OPT_SOURCE_LINKADDR:
128*7c478bd9Sstevel@tonic-gate lo = (struct nd_opt_lla *)opt;
129*7c478bd9Sstevel@tonic-gate if (optlen < 8 ||
130*7c478bd9Sstevel@tonic-gate optlen > len)
131*7c478bd9Sstevel@tonic-gate break;
132*7c478bd9Sstevel@tonic-gate (void) fmt_lla(llabuf, sizeof (llabuf),
133*7c478bd9Sstevel@tonic-gate lo->nd_opt_lla_hdw_addr,
134*7c478bd9Sstevel@tonic-gate optlen - sizeof (nd_opt_hdr_t));
135*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tSource LLA: len %d <%s>\n",
136*7c478bd9Sstevel@tonic-gate optlen - sizeof (nd_opt_hdr_t),
137*7c478bd9Sstevel@tonic-gate llabuf);
138*7c478bd9Sstevel@tonic-gate break;
139*7c478bd9Sstevel@tonic-gate case ND_OPT_TARGET_LINKADDR:
140*7c478bd9Sstevel@tonic-gate lo = (struct nd_opt_lla *)opt;
141*7c478bd9Sstevel@tonic-gate if (optlen < 8||
142*7c478bd9Sstevel@tonic-gate optlen > len)
143*7c478bd9Sstevel@tonic-gate break;
144*7c478bd9Sstevel@tonic-gate (void) fmt_lla(llabuf, sizeof (llabuf),
145*7c478bd9Sstevel@tonic-gate lo->nd_opt_lla_hdw_addr,
146*7c478bd9Sstevel@tonic-gate optlen - sizeof (nd_opt_hdr_t));
147*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tTarget LLA: len %d <%s>\n",
148*7c478bd9Sstevel@tonic-gate optlen - sizeof (nd_opt_hdr_t),
149*7c478bd9Sstevel@tonic-gate llabuf);
150*7c478bd9Sstevel@tonic-gate break;
151*7c478bd9Sstevel@tonic-gate case ND_OPT_REDIRECTED_HEADER:
152*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tRedirected header option!\n");
153*7c478bd9Sstevel@tonic-gate break;
154*7c478bd9Sstevel@tonic-gate default:
155*7c478bd9Sstevel@tonic-gate logmsg(LOG_DEBUG, "Unknown option %d (0x%x)\n",
156*7c478bd9Sstevel@tonic-gate opt->nd_opt_type, opt->nd_opt_type);
157*7c478bd9Sstevel@tonic-gate break;
158*7c478bd9Sstevel@tonic-gate }
159*7c478bd9Sstevel@tonic-gate opt = (struct nd_opt_hdr *)((char *)opt + optlen);
160*7c478bd9Sstevel@tonic-gate len -= optlen;
161*7c478bd9Sstevel@tonic-gate }
162*7c478bd9Sstevel@tonic-gate }
163*7c478bd9Sstevel@tonic-gate
164*7c478bd9Sstevel@tonic-gate char *
fmt_lla(char * llabuf,int bufsize,uchar_t * lla,int llalen)165*7c478bd9Sstevel@tonic-gate fmt_lla(char *llabuf, int bufsize, uchar_t *lla, int llalen)
166*7c478bd9Sstevel@tonic-gate {
167*7c478bd9Sstevel@tonic-gate int i;
168*7c478bd9Sstevel@tonic-gate char *cp = llabuf;
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate for (i = 0; i < llalen; i++) {
171*7c478bd9Sstevel@tonic-gate if (i == llalen - 1) /* Last byte? */
172*7c478bd9Sstevel@tonic-gate (void) snprintf(cp, bufsize, "%02x", lla[i] & 0xFF);
173*7c478bd9Sstevel@tonic-gate else
174*7c478bd9Sstevel@tonic-gate (void) snprintf(cp, bufsize, "%02x:", lla[i] & 0xFF);
175*7c478bd9Sstevel@tonic-gate bufsize -= strlen(cp);
176*7c478bd9Sstevel@tonic-gate cp += strlen(cp);
177*7c478bd9Sstevel@tonic-gate }
178*7c478bd9Sstevel@tonic-gate return (llabuf);
179*7c478bd9Sstevel@tonic-gate }
180