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