Lines Matching defs:pii
43 static void phyint_inst_insert(struct phyint_instance *pii);
44 static void phyint_inst_print(struct phyint_instance *pii);
51 static void logint_insert(struct phyint_instance *pii, struct logint *li);
52 static struct logint *logint_lookup(struct phyint_instance *pii, char *li_name);
55 static void target_insert(struct phyint_instance *pii, struct target *tg);
56 static struct target *target_first(struct phyint_instance *pii);
57 static struct target *target_select_best(struct phyint_instance *pii);
60 static void reset_pii_probes(struct phyint_instance *pii, struct target *tg);
62 static boolean_t phyint_inst_v6_sockinit(struct phyint_instance *pii);
63 static boolean_t phyint_inst_v4_sockinit(struct phyint_instance *pii);
347 phyint_inst_insert(struct phyint_instance *pii)
351 AF_STR(pii->pii_af), pii->pii_name);
357 pii->pii_next = phyint_instances;
358 pii->pii_prev = NULL;
360 phyint_instances->pii_prev = pii;
361 phyint_instances = pii;
423 struct phyint_instance *pii;
425 pii = calloc(1, sizeof (struct phyint_instance));
426 if (pii == NULL) {
435 pii->pii_phyint = pi;
437 pi->pi_v4 = pii;
439 pi->pi_v6 = pii;
441 pii->pii_in_use = 1;
442 pii->pii_probe_sock = -1;
443 pii->pii_snxt = 1;
444 pii->pii_af = af;
445 pii->pii_fd_hrtime = gethrtime() +
447 pii->pii_flags = pi->pi_flags;
450 phyint_inst_insert(pii);
451 return (pii);
604 struct phyint_instance *pii;
609 pii = NULL;
754 pii = phyint_inst_create(pi, af);
755 if (pii == NULL) {
803 return (pii);
816 phyint_inst_sockinit(struct phyint_instance *pii)
823 AF_STR(pii->pii_af), pii->pii_name);
826 assert(pii->pii_probe_logint != NULL);
827 assert(pii->pii_probe_logint->li_flags & IFF_UP);
828 assert(pii->pii_probe_logint->li_flags & IFF_NOFAILOVER);
829 assert(pii->pii_af == AF_INET || pii->pii_af == AF_INET6);
834 if (pii->pii_probe_sock != -1)
835 close_probe_socket(pii, _B_TRUE);
841 pg = pii->pii_phyint->pi_group;
852 if (pii->pii_af == AF_INET6)
853 success = phyint_inst_v6_sockinit(pii);
855 success = phyint_inst_v4_sockinit(pii);
857 if (success && (poll_add(pii->pii_probe_sock) == 0))
861 if (pii->pii_probe_sock != -1)
862 close_probe_socket(pii, _B_FALSE);
872 phyint_inst_v6_sockinit(struct phyint_instance *pii)
892 pii->pii_probe_sock = socket(pii->pii_af, SOCK_RAW, IPPROTO_ICMPV6);
893 if (pii->pii_probe_sock < 0) {
894 logperror_pii(pii, "phyint_inst_v6_sockinit: socket");
901 if ((flags = fcntl(pii->pii_probe_sock, F_GETFL, 0)) == -1) {
902 logperror_pii(pii, "phyint_inst_v6_sockinit: fcntl"
906 if (fcntl(pii->pii_probe_sock, F_SETFL,
908 logperror_pii(pii, "phyint_inst_v6_sockinit: fcntl"
916 testaddr.sin6_addr = pii->pii_probe_logint->li_addr;
918 if (bind(pii->pii_probe_sock, (struct sockaddr *)&testaddr,
920 logperror_pii(pii, "phyint_inst_v6_sockinit: IPv6 bind");
924 if (setsockopt(pii->pii_probe_sock, IPPROTO_IPV6, IPV6_MULTICAST_IF,
925 (char *)&pii->pii_ifindex, sizeof (uint_t)) < 0) {
926 logperror_pii(pii, "phyint_inst_v6_sockinit: setsockopt"
931 if (setsockopt(pii->pii_probe_sock, IPPROTO_IPV6, IPV6_BOUND_IF,
932 &pii->pii_ifindex, sizeof (uint_t)) < 0) {
933 logperror_pii(pii, "phyint_inst_v6_sockinit: setsockopt"
938 if (setsockopt(pii->pii_probe_sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS,
940 logperror_pii(pii, "phyint_inst_v6_sockinit: setsockopt"
945 if (setsockopt(pii->pii_probe_sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
947 logperror_pii(pii, "phyint_inst_v6_sockinit: setsockopt"
952 if (setsockopt(pii->pii_probe_sock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
954 logperror_pii(pii, "phyint_inst_v6_sockinit: setsockopt"
965 if (setsockopt(pii->pii_probe_sock, IPPROTO_ICMPV6, ICMP6_FILTER,
967 logperror_pii(pii, "phyint_inst_v6_sockinit: setsockopt"
973 if (setsockopt(pii->pii_probe_sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT,
975 logperror_pii(pii, "phyint_inst_v6_sockinit: setsockopt"
981 if (setsockopt(pii->pii_probe_sock, SOL_SOCKET, SO_TIMESTAMP,
983 logperror_pii(pii, "phyint_inst_v6_sockinit: setsockopt"
996 phyint_inst_v4_sockinit(struct phyint_instance *pii)
1015 pii->pii_probe_sock = socket(pii->pii_af, SOCK_RAW, IPPROTO_ICMP);
1016 if (pii->pii_probe_sock < 0) {
1017 logperror_pii(pii, "phyint_inst_v4_sockinit: socket");
1024 if ((flags = fcntl(pii->pii_probe_sock, F_GETFL, 0)) == -1) {
1025 logperror_pii(pii, "phyint_inst_v4_sockinit: fcntl"
1029 if (fcntl(pii->pii_probe_sock, F_SETFL,
1031 logperror_pii(pii, "phyint_inst_v4_sockinit: fcntl"
1039 IN6_V4MAPPED_TO_INADDR(&pii->pii_probe_logint->li_addr,
1042 if (bind(pii->pii_probe_sock, (struct sockaddr *)&testaddr,
1044 logperror_pii(pii, "phyint_inst_v4_sockinit: IPv4 bind");
1048 if (setsockopt(pii->pii_probe_sock, IPPROTO_IP, IP_BOUND_IF,
1049 &pii->pii_ifindex, sizeof (uint_t)) < 0) {
1050 logperror_pii(pii, "phyint_inst_v4_sockinit: setsockopt"
1055 if (setsockopt(pii->pii_probe_sock, IPPROTO_IP, IP_MULTICAST_IF,
1057 logperror_pii(pii, "phyint_inst_v4_sockinit: setsockopt"
1062 if (setsockopt(pii->pii_probe_sock, IPPROTO_IP, IP_TTL,
1064 logperror_pii(pii, "phyint_inst_v4_sockinit: setsockopt"
1069 if (setsockopt(pii->pii_probe_sock, IPPROTO_IP, IP_MULTICAST_LOOP,
1071 logperror_pii(pii, "phyint_inst_v4_sockinit: setsockopt"
1076 if (setsockopt(pii->pii_probe_sock, IPPROTO_IP, IP_MULTICAST_TTL,
1078 logperror_pii(pii, "phyint_inst_v4_sockinit: setsockopt"
1083 if (setsockopt(pii->pii_probe_sock, SOL_SOCKET, SO_TIMESTAMP, &on,
1085 logperror_pii(pii, "phyint_inst_v4_sockinit: setsockopt"
1211 phyint_inst_update_from_k(struct phyint_instance *pii)
1217 pi = pii->pii_phyint;
1221 AF_STR(pii->pii_af), pi->pi_name);
1231 ifsock = (pii->pii_af == AF_INET) ? ifsock_v4 : ifsock_v6;
1236 logperror_pii(pii, "phyint_inst_update_from_k:"
1264 logperror_pii(pii, "phyint_inst_update_from_k:"
1294 logperror_pii(pii, "phyint_inst_update_from_k: "
1554 phyint_inst_delete(struct phyint_instance *pii)
1556 struct phyint *pi = pii->pii_phyint;
1562 AF_STR(pii->pii_af), pi->pi_name);
1569 while (pii->pii_targets != NULL)
1570 target_delete(pii->pii_targets);
1576 while (pii->pii_logint != NULL)
1577 logint_delete(pii->pii_logint);
1582 if (pii->pii_probe_sock != -1)
1583 close_probe_socket(pii, _B_TRUE);
1589 assert(phyint_instances == pii || pii->pii_prev != NULL);
1590 if (pii->pii_prev == NULL) {
1592 phyint_instances = pii->pii_next;
1594 pii->pii_prev->pii_next = pii->pii_next;
1596 if (pii->pii_next != NULL)
1597 pii->pii_next->pii_prev = pii->pii_prev;
1598 pii->pii_next = NULL;
1599 pii->pii_prev = NULL;
1606 if (pii->pii_af == AF_INET)
1614 free(pii);
1618 phyint_inst_print(struct phyint_instance *pii)
1626 if (pii->pii_phyint == NULL) {
1627 logdebug("pii->pi_phyint NULL can't print\n");
1633 AF_STR(pii->pii_af), pii->pii_name, pii->pii_ifindex,
1634 pii->pii_state, pii->pii_phyint->pi_flags, pii->pii_probe_sock,
1635 pii->pii_in_use);
1637 for (li = pii->pii_logint; li != NULL; li = li->li_next)
1641 for (tg = pii->pii_targets; tg != NULL; tg = tg->tg_next)
1644 if (pii->pii_targets == NULL)
1647 if (pii->pii_target_next != NULL) {
1648 logdebug("pi_target_next %s %s\n", AF_STR(pii->pii_af),
1649 pr_addr(pii->pii_af, pii->pii_target_next->tg_address,
1655 if (pii->pii_rtt_target_next != NULL) {
1656 logdebug("pi_rtt_target_next %s %s\n", AF_STR(pii->pii_af),
1657 pr_addr(pii->pii_af, pii->pii_rtt_target_next->tg_address,
1663 if (pii->pii_targets != NULL) {
1664 most_recent = PROBE_INDEX_PREV(pii->pii_probe_next);
1668 if (pii->pii_probes[i].pr_target != NULL) {
1670 pr_addr(pii->pii_af,
1671 pii->pii_probes[i].pr_target->tg_address,
1678 pii->pii_probes[i].pr_hrtime_start,
1679 pii->pii_probes[i].pr_status,
1680 pii->pii_probes[i].pr_hrtime_ackproc,
1681 pii->pii_probes[i].pr_time_lost);
1692 logint_lookup(struct phyint_instance *pii, char *name)
1698 AF_STR(pii->pii_af), name);
1701 for (li = pii->pii_logint; li != NULL; li = li->li_next) {
1713 logint_insert(struct phyint_instance *pii, struct logint *li)
1715 li->li_next = pii->pii_logint;
1717 if (pii->pii_logint != NULL)
1718 pii->pii_logint->li_prev = li;
1719 pii->pii_logint = li;
1720 li->li_phyint_inst = pii;
1727 logint_create(struct phyint_instance *pii, char *name)
1733 AF_STR(pii->pii_af), pii->pii_name, name);
1744 logint_insert(pii, li);
1752 logint_init_from_k(struct phyint_instance *pii, char *li_name)
1770 AF_STR(pii->pii_af), li_name);
1774 ifsock = (pii->pii_af == AF_INET) ? ifsock_v4 : ifsock_v6;
1786 logperror_pii(pii, "logint_init_from_k: "
1798 li = logint_lookup(pii, li_name);
1800 li = logint_create(pii, li_name);
1831 if (pii->pii_af == AF_INET) {
1862 if (pii->pii_probe_logint == li) {
1876 if (pii->pii_probe_sock != -1)
1877 close_probe_socket(pii, _B_TRUE);
1878 pii->pii_probe_logint = NULL;
1888 li->li_subnet_len = (pii->pii_af == AF_INET) ?
1902 AF_STR(pii->pii_af), pii->pii_name, li->li_name,
1903 pr_addr(pii->pii_af, testaddr, abuf, sizeof (abuf)));
1913 struct phyint_instance *pii;
1915 pii = li->li_phyint_inst;
1916 assert(pii != NULL);
1922 af = pii->pii_af;
1930 assert(pii->pii_logint == li || li->li_prev != NULL);
1935 pii->pii_logint = li->li_next;
1948 if (pii->pii_probe_logint == li) {
1949 if (pii->pii_probe_sock != -1)
1950 close_probe_socket(pii, _B_TRUE);
1951 pii->pii_probe_logint = NULL;
2012 target_lookup(struct phyint_instance *pii, struct in6_addr addr)
2020 AF_STR(pii->pii_af), pii->pii_name,
2021 pr_addr(pii->pii_af, addr, abuf, sizeof (abuf)));
2024 for (tg = pii->pii_targets; tg != NULL; tg = tg->tg_next) {
2038 struct phyint_instance *pii = tg->tg_phyint_inst;
2048 assert(pii->pii_targets == tg || tg->tg_prev != NULL);
2049 assert(pii->pii_targets != NULL);
2059 tg = pii->pii_targets;
2068 assert(pii->pii_targets_are_routers);
2069 if (pii->pii_ntargets < MAX_PROBE_TARGETS) {
2074 pii->pii_ntargets++;
2080 assert(pii->pii_targets_are_routers);
2090 assert(pii->pii_targets_are_routers);
2119 target_select_best(struct phyint_instance *pii)
2130 for (tg = pii->pii_targets; tg != NULL; tg = tg->tg_next) {
2182 target_activate_all(struct phyint_instance *pii)
2186 assert(pii->pii_ntargets == 0);
2187 assert(pii->pii_target_next == NULL);
2188 assert(pii->pii_rtt_target_next == NULL);
2189 assert(pii->pii_targets_are_routers);
2191 while (pii->pii_ntargets < MIN_PROBE_TARGETS) {
2192 tg = target_select_best(pii);
2201 pii->pii_ntargets++;
2202 if (pii->pii_target_next == NULL) {
2203 pii->pii_target_next = tg;
2204 pii->pii_rtt_target_next = tg;
2210 target_first(struct phyint_instance *pii)
2214 for (tg = pii->pii_targets; tg != NULL; tg = tg->tg_next) {
2227 target_create(struct phyint_instance *pii, struct in6_addr addr,
2238 AF_STR(pii->pii_af), pii->pii_name,
2239 pr_addr(pii->pii_af, addr, abuf, sizeof (abuf)));
2247 li = pii->pii_probe_logint;
2260 if (pii->pii_targets != NULL) {
2261 assert(pii->pii_ntargets <= MAX_PROBE_TARGETS);
2263 if (!pii->pii_targets_are_routers) {
2269 while (pii->pii_targets != NULL)
2270 target_delete(pii->pii_targets);
2279 if (pii->pii_targets_are_routers ||
2280 pii->pii_ntargets == MAX_PROBE_TARGETS)
2291 tg->tg_phyint_inst = pii;
2302 if (pii->pii_targets == NULL) {
2303 assert(pii->pii_ntargets == 0);
2304 assert(pii->pii_target_next == NULL);
2305 assert(pii->pii_rtt_target_next == NULL);
2306 pii->pii_targets_are_routers = is_router ? 1 : 0;
2309 if (pii->pii_ntargets == MAX_PROBE_TARGETS) {
2310 assert(pii->pii_targets_are_routers);
2311 assert(pii->pii_target_next != NULL);
2312 assert(pii->pii_rtt_target_next != NULL);
2315 if (pii->pii_ntargets == 0) {
2316 assert(pii->pii_target_next == NULL);
2317 pii->pii_target_next = tg;
2318 pii->pii_rtt_target_next = tg;
2320 pii->pii_ntargets++;
2324 target_insert(pii, tg);
2332 pi = pii->pii_phyint;
2333 if (pi->pi_state == PI_NOTARGETS && PROBE_CAPABLE(pii)) {
2342 * Add the target address named by `addr' to phyint instance `pii' if it does
2347 target_add(struct phyint_instance *pii, struct in6_addr addr,
2352 if (pii == NULL)
2355 tg = target_lookup(pii, addr);
2364 if (tg == NULL || (is_router && !pii->pii_targets_are_routers))
2365 target_create(pii, addr, is_router);
2375 target_insert(struct phyint_instance *pii, struct target *tg)
2377 tg->tg_next = pii->pii_targets;
2381 pii->pii_targets = tg;
2391 struct phyint_instance *pii;
2394 pii = tg->tg_phyint_inst;
2395 af = pii->pii_af;
2401 AF_STR(af), pii->pii_name,
2409 assert(pii->pii_targets == tg || tg->tg_prev != NULL);
2415 reset_pii_probes(pii, tg);
2422 pii->pii_targets = tg->tg_next;
2434 pii->pii_ntargets--;
2440 if (pii->pii_target_next == tg)
2441 pii->pii_target_next = target_first(pii);
2443 if (pii->pii_rtt_target_next == tg)
2444 pii->pii_rtt_target_next = target_first(pii);
2450 * the next active target pii->pii_target_next == NULL
2452 if (pii->pii_ntargets != 0) {
2453 assert(pii->pii_target_next != NULL);
2454 assert(pii->pii_rtt_target_next != NULL);
2455 assert(pii->pii_target_next->tg_status == TG_ACTIVE);
2456 assert(pii->pii_rtt_target_next->tg_status == TG_ACTIVE);
2461 assert(pii->pii_target_next == NULL);
2462 assert(pii->pii_rtt_target_next == NULL);
2464 if (pii->pii_targets_are_routers) {
2469 target_activate_all(pii);
2471 if (pii->pii_ntargets != 0) {
2472 assert(pii->pii_target_next != NULL);
2473 assert(pii->pii_rtt_target_next != NULL);
2474 assert(pii->pii_target_next->tg_status == TG_ACTIVE);
2475 assert(pii->pii_rtt_target_next->tg_status ==
2487 assert(pii->pii_targets == NULL);
2488 pii->pii_targets_are_routers = _B_FALSE;
2489 clear_pii_probe_stats(pii);
2490 pii_other = phyint_inst_other(pii);
2498 if (!PROBE_CAPABLE(pii_other) && LINK_UP(pii->pii_phyint) &&
2499 pii->pii_phyint->pi_state != PI_OFFLINE)
2500 phyint_chstate(pii->pii_phyint, PI_NOTARGETS);
2514 struct phyint_instance *pii;
2520 pii = pi->pi_v4;
2521 if (pii != NULL && !pii->pii_targets_are_routers) {
2524 * empty, target_delete() will set pii->pii_targets
2527 while (pii->pii_targets != NULL)
2528 target_delete(pii->pii_targets);
2530 pii = pi->pi_v6;
2531 if (pii != NULL && !pii->pii_targets_are_routers) {
2534 * empty, target_delete() will set pii->pii_targets
2537 while (pii->pii_targets != NULL)
2538 target_delete(pii->pii_targets);
2550 reset_pii_probes(struct phyint_instance *pii, struct target *tg)
2555 if (pii->pii_probes[i].pr_target == tg) {
2556 if (pii->pii_probes[i].pr_status == PR_UNACKED) {
2557 probe_chstate(&pii->pii_probes[i], pii,
2560 pii->pii_probes[i].pr_target = NULL;
2569 clear_pii_probe_stats(struct phyint_instance *pii)
2571 bzero(pii->pii_probes, sizeof (struct probe_stats) * PROBE_STATS_COUNT);
2573 pii->pii_probe_next = 0;
2606 struct phyint_instance *pii;
2608 for (pii = phyint_instances; pii != NULL; pii = pii->pii_next) {
2609 phyint_inst_print(pii);
2668 phyint_inst_other(struct phyint_instance *pii)
2670 if (pii->pii_af == AF_INET)
2671 return (pii->pii_phyint->pi_v6);
2673 return (pii->pii_phyint->pi_v4);
2817 * Return the external IPMP target mode associated with phyint instance `pii'.
2820 iftargmode(struct phyint_instance *pii)
2822 if (!PROBE_ENABLED(pii))
2824 else if (pii->pii_targets_are_routers)
2851 * Store the test address used on phyint instance `pii' in `ssp'. If there's
2855 iftestaddr(struct phyint_instance *pii, struct sockaddr_storage *ssp)
2857 if (PROBE_ENABLED(pii))
2858 addr2storage(pii->pii_af, &pii->pii_probe_logint->li_addr, ssp);
2908 * on phyint instance `pii'. Returns 0 on success, -1 on failure.
2911 probe_state_event(struct probe_stats *pr, struct phyint_instance *pii)
2929 errno = nvlist_add_string(nvl, IPMP_IF_NAME, pii->pii_phyint->pi_name);
2961 addr2storage(pii->pii_af, &tg->tg_address, &ss);
2963 addr2storage(pii->pii_af, &in6addr_any, &ss);
3267 * Store the target information associated with phyint instance `pii' into a
3272 gettarginfo(struct phyint_instance *pii, const char *name,
3280 if (PROBE_CAPABLE(pii)) {
3281 targs = alloca(pii->pii_ntargets * sizeof (*targs));
3282 tg = pii->pii_target_next;
3285 assert(ntarg < pii->pii_ntargets);
3286 addr2storage(pii->pii_af, &tg->tg_address,
3290 tg = pii->pii_targets;
3291 } while (tg != pii->pii_target_next);
3293 assert(ntarg == pii->pii_ntargets);
3296 *targinfopp = ipmp_targinfo_create(name, iftestaddr(pii, &ss),
3297 iftargmode(pii), ntarg, targs);