/* * printpolicy(sock) * * Queries the kernel for the current address selection policy using * the open socket sock, and prints the result. Returns EXIT_FAILURE * if the table cannot be obtained, or EXIT_SUCCESS if the table is * obtained and printed successfully. */ static int printpolicy(int sock) { ip6_asp_t policy[KERN_POLICY_SIZE]; ip6_asp_t *policy_ptr = policy; int count, policy_index; char prefixstr[INET6_ADDRSTRLEN + sizeof ("/128")]; if ((count = strioctl(sock, SIOCGIP6ADDRPOLICY, policy_ptr, KERN_POLICY_SIZE * sizeof (ip6_asp_t))) < 0) { perror("SIOCGIP6ADDRPOLICY"); return (EXIT_FAILURE); } if (count > KERN_POLICY_SIZE) { policy_ptr = malloc(count * sizeof (ip6_asp_t)); if (policy_ptr == NULL) { perror("malloc"); return (EXIT_FAILURE); } if ((count = strioctl(sock, SIOCGIP6ADDRPOLICY, policy_ptr, count * sizeof (ip6_asp_t))) < 0) { perror("SIOCGIP6ADDRPOLICY"); return (EXIT_FAILURE); } } if (count == 0) { /* * There should always at least be a default entry in the * policy table, so the minimum acceptable value of * policy_count is 1. */ (void) fprintf(stderr, gettext("%s: ERROR: " "IPv6 address selection policy is empty.\n"), myname); return (EXIT_FAILURE); } /* * The format printed here must also be parsable by parseconf(), * since we expect users to be able to redirect this output to * a usable configuration file if need be. */ (void) printf("# Prefix " " Precedence Label\n"); for (policy_index = 0; policy_index < count; policy_index++) { (void) snprintf(prefixstr, sizeof (prefixstr), "%s/%d", inet_ntop(AF_INET6, &policy_ptr[policy_index].ip6_asp_prefix, prefixstr, sizeof (prefixstr)), ip_mask_to_plen_v6(&policy_ptr[policy_index].ip6_asp_mask)); (void) printf("%-45s %10d %s\n", prefixstr, policy_ptr[policy_index].ip6_asp_precedence, policy_ptr[policy_index].ip6_asp_label); } if (policy_ptr != policy) free(policy_ptr); return (EXIT_SUCCESS); }
static int netstat_irev6_cb(uintptr_t kaddr, const void *walk_data, void *cb_data) { const ire_t *ire = walk_data; uint_t *opts = cb_data; const in6_addr_t *gatep; char deststr[ADDR_V6_WIDTH + 5]; char flags[10], intf[LIFNAMSIZ + 1]; int masklen; if (ire->ire_ipversion != IPV6_VERSION) return (WALK_NEXT); /* Skip certain IREs by default */ if (!(*opts & NETSTAT_ALL) && (ire->ire_type & (IRE_BROADCAST|IRE_LOCAL|IRE_MULTICAST|IRE_NOROUTE|IRE_IF_CLONE))) return (WALK_NEXT); if (*opts & NETSTAT_FIRST) { *opts &= ~NETSTAT_FIRST; mdb_printf("\n%<u>%s Table: IPv6%</u>\n", (*opts & NETSTAT_VERBOSE) ? "IRE" : "Routing"); if (*opts & NETSTAT_VERBOSE) { mdb_printf("%<u>%-?s %-*s %-*s If PMTU Rtt Ref " "Flags Out In/Fwd%</u>\n", "Address", ADDR_V6_WIDTH+4, "Destination/Mask", ADDR_V6_WIDTH, "Gateway"); } else { mdb_printf("%<u>%-?s %-*s %-*s Flags Ref Use If" "%</u>\n", "Address", ADDR_V6_WIDTH+4, "Destination/Mask", ADDR_V6_WIDTH, "Gateway"); } } gatep = &ire->ire_gateway_addr_v6; masklen = ip_mask_to_plen_v6(&ire->ire_mask_v6); (void) mdb_snprintf(deststr, sizeof (deststr), "%N/%d", &ire->ire_addr_v6, masklen); get_ireflags(ire, flags); get_ifname(ire, intf); if (*opts & NETSTAT_VERBOSE) { mdb_printf("%?p %-*s %-*N %-5s %5u%c %5u %3u %-5s %6u %u\n", kaddr, ADDR_V6_WIDTH+4, deststr, ADDR_V6_WIDTH, gatep, intf, 0, ' ', ire->ire_metrics.iulp_rtt, ire->ire_refcnt, flags, ire->ire_ob_pkt_count, ire->ire_ib_pkt_count); } else { mdb_printf("%?p %-*s %-*N %-5s %3u %6u %s\n", kaddr, ADDR_V6_WIDTH+4, deststr, ADDR_V6_WIDTH, gatep, flags, ire->ire_refcnt, ire->ire_ob_pkt_count + ire->ire_ib_pkt_count, intf); } return (WALK_NEXT); }