Lines Matching defs:pi

46 static void phyint_insert(struct phyint *pi, struct phyint_group *pg);
47 static void phyint_delete(struct phyint *pi);
48 static boolean_t phyint_is_usable(struct phyint *pi);
65 static int phyint_state_event(struct phyint_group *pg, struct phyint *pi);
68 static int phyint_group_member_event(struct phyint_group *pg, struct phyint *pi,
71 static int logint_upcount(struct phyint *pi);
92 struct phyint *pi;
97 for (pi = phyints; pi != NULL; pi = pi->pi_next) {
98 if (strncmp(pi->pi_name, name, sizeof (pi->pi_name)) == 0)
101 return (pi);
105 * Lookup a phyint in the group that has the same hardware address as `pi', or
111 phyint_lookup_hwaddr(struct phyint *pi, boolean_t online_only)
115 if (pi->pi_group == phyint_anongroup)
118 for (pi2 = pi->pi_group->pg_phyint; pi2 != NULL; pi2 = pi2->pi_pgnext) {
119 if (pi2 == pi)
132 if (pi2->pi_hwaddrlen == pi->pi_hwaddrlen &&
133 bcmp(pi2->pi_hwaddr, pi->pi_hwaddr, pi->pi_hwaddrlen) == 0)
148 struct phyint *pi = arg;
151 assert((dnip->dni_note & pi->pi_notes) != 0);
161 if (pi->pi_hwaddrlen == dnip->dni_physaddrlen &&
162 bcmp(pi->pi_hwaddr, dnip->dni_physaddr, pi->pi_hwaddrlen) == 0)
165 oduppi = phyint_lookup_hwaddr(pi, _B_FALSE);
166 pi->pi_hwaddrlen = dnip->dni_physaddrlen;
167 (void) memcpy(pi->pi_hwaddr, dnip->dni_physaddr, pi->pi_hwaddrlen);
168 duppi = phyint_lookup_hwaddr(pi, _B_FALSE);
170 if (oduppi != NULL || pi->pi_hwaddrdup) {
177 if (pi->pi_hwaddrdup) {
179 (void) phyint_undo_offline(pi);
186 if (duppi != NULL && !pi->pi_hwaddrdup) {
191 pi->pi_hwaddrdup = _B_TRUE;
192 (void) phyint_offline(pi, 0);
197 * Initialize information about the underlying link for `pi', and set us
201 phyint_link_init(struct phyint *pi)
208 pi->pi_notes = 0;
209 retval = dlpi_open(pi->pi_name, &pi->pi_dh, 0);
211 pi->pi_dh = NULL;
216 pi->pi_hwaddrlen = DLPI_PHYSADDR_MAX;
217 retval = dlpi_get_physaddr(pi->pi_dh, DL_CURR_PHYS_ADDR, pi->pi_hwaddr,
218 &pi->pi_hwaddrlen);
230 retval = dlpi_enabnotify(pi->pi_dh, notes, phyint_link_notify, pi, &id);
232 (void) dlpi_disabnotify(pi->pi_dh, id, NULL);
233 pi->pi_notes |= notes;
241 retval = dlpi_enabnotify(pi->pi_dh, notes, phyint_link_notify, pi, &id);
242 if (retval == DLPI_SUCCESS && poll_add(dlpi_fd(pi->pi_dh)) == 0)
243 pi->pi_notes |= notes;
247 logerr("%s: %s: %s\n", pi->pi_name, errmsg, dlpi_strerror(retval));
248 if (pi->pi_dh != NULL) {
249 dlpi_close(pi->pi_dh);
250 pi->pi_dh = NULL;
256 * Close use of link on `pi'.
259 phyint_link_close(struct phyint *pi)
261 if (pi->pi_notes & DL_NOTE_PHYS_ADDR) {
262 (void) poll_remove(dlpi_fd(pi->pi_dh));
263 pi->pi_notes &= ~DL_NOTE_PHYS_ADDR;
271 dlpi_close(pi->pi_dh);
272 pi->pi_dh = NULL;
279 struct phyint *pi;
286 pi = phyint_lookup(name);
287 if (pi == NULL)
290 return (PHYINT_INSTANCE(pi, af));
313 phyint_insert(struct phyint *pi, struct phyint_group *pg)
316 logdebug("phyint_insert(%s '%s')\n", pi->pi_name, pg->pg_name);
319 pi->pi_next = phyints;
320 pi->pi_prev = NULL;
322 phyints->pi_prev = pi;
323 phyints = pi;
329 pi->pi_pgnext = NULL;
330 pi->pi_pgprev = NULL;
331 pi->pi_group = pg;
333 pi->pi_pgnext = pg->pg_phyint;
334 if (pi->pi_pgnext != NULL)
335 pi->pi_pgnext->pi_pgprev = pi;
336 pg->pg_phyint = pi;
342 (void) phyint_group_member_event(pg, pi, IPMP_IF_ADD);
373 struct phyint *pi;
375 pi = calloc(1, sizeof (struct phyint));
376 if (pi == NULL) {
384 (void) strlcpy(pi->pi_name, pi_name, sizeof (pi->pi_name));
385 pi->pi_taddrthresh = getcurrentsec() + TESTADDR_CONF_TIME;
386 pi->pi_ifindex = ifindex;
387 pi->pi_icmpid = htons(((getpid() & 0xFF) << 8) | (ifindex & 0xFF));
389 pi->pi_state = PI_INIT;
390 pi->pi_flags = PHYINT_FLAGS(flags);
399 INIT_LINK_STATE(pi);
401 if (!phyint_link_init(pi)) {
402 free(pi);
410 phyint_insert(pi, pg);
412 return (pi);
416 * Create a new phyint instance belonging to the phyint 'pi' and address
421 phyint_inst_create(struct phyint *pi, int af)
435 pii->pii_phyint = pi;
437 pi->pi_v4 = pii;
439 pi->pi_v6 = pii;
447 pii->pii_flags = pi->pi_flags;
455 * Change the state of phyint `pi' to state `state'.
458 phyint_chstate(struct phyint *pi, enum pi_state state)
467 if (pi->pi_state == state)
470 pi->pi_state = state;
471 phyint_changed(pi);
475 * Note that `pi' has changed state.
478 phyint_changed(struct phyint *pi)
480 pi->pi_group->pg_sig++;
481 (void) phyint_state_event(pi->pi_group, pi);
603 struct phyint *pi;
610 pi = NULL;
711 pi = phyint_lookup(pi_name);
712 if (pi == NULL) {
713 pi = phyint_create(pi_name, pg, ifindex, flags);
714 if (pi == NULL) {
732 if (pi->pi_ifindex != ifindex) {
733 phyint_inst_delete(PHYINT_INSTANCE(pi, AF_OTHER(af)));
736 assert(PHYINT_INSTANCE(pi, af) == NULL);
743 if (strcmp(pi->pi_group->pg_name, pg_name) != 0) {
744 phyint_inst_delete(PHYINT_INSTANCE(pi,
754 pii = phyint_inst_create(pi, af);
757 "phyint inst %s\n", pi->pi_name);
759 phyint_delete(pi);
779 if (pi->pi_flags & IFF_OFFLINE) {
780 phyint_chstate(pi, PI_OFFLINE);
783 phyint_transition_to_running(pi);
790 if (pi->pi_flags & IFF_STANDBY)
791 phyint_standby_refresh_inactive(pi);
797 if (phyint_lookup_hwaddr(pi, _B_TRUE) != NULL) {
798 pi->pi_hwaddrdup = _B_TRUE;
799 (void) phyint_offline(pi, 0);
1142 struct phyint *pi, *usablepi;
1151 for (pi = pg->pg_phyint; pi != NULL; pi = pi->pi_pgnext) {
1153 if (phyint_is_usable(pi)) {
1155 usablepi = pi;
1215 struct phyint *pi;
1217 pi = pii->pii_phyint;
1221 AF_STR(pii->pii_af), pi->pi_name);
1228 (void) strncpy(lifr.lifr_name, pi->pi_name, sizeof (lifr.lifr_name));
1242 if (lifr.lifr_index != pi->pi_ifindex) {
1251 pi->pi_ifindex, lifr.lifr_index);
1275 if (strcmp(lifr.lifr_groupname, pi->pi_group->pg_name) != 0) {
1300 pi->pi_flags = PHYINT_FLAGS(lifr.lifr_flags);
1301 if (pi->pi_v4 != NULL)
1302 pi->pi_v4->pii_flags = pi->pi_flags;
1303 if (pi->pi_v6 != NULL)
1304 pi->pi_v6->pii_flags = pi->pi_flags;
1310 if (pi->pi_flags & IFF_FAILED) {
1311 if (pi->pi_state == PI_RUNNING)
1312 (void) change_pif_flags(pi, 0, IFF_FAILED);
1314 if (pi->pi_state == PI_FAILED)
1315 (void) change_pif_flags(pi, IFF_FAILED, IFF_INACTIVE);
1327 phyint_delete(struct phyint *pi)
1331 struct phyint_group *pg = pi->pi_group;
1334 logdebug("phyint_delete(%s)\n", pi->pi_name);
1337 assert(pi->pi_v4 == NULL && pi->pi_v6 == NULL);
1342 assert(pg->pg_phyint == pi || pi->pi_pgprev != NULL);
1345 assert(phyints == pi || pi->pi_prev != NULL);
1349 (void) phyint_group_member_event(pg, pi, IPMP_IF_REMOVE);
1351 if (pi->pi_pgprev == NULL) {
1353 pg->pg_phyint = pi->pi_pgnext;
1355 pi->pi_pgprev->pi_pgnext = pi->pi_pgnext;
1357 if (pi->pi_pgnext != NULL)
1358 pi->pi_pgnext->pi_pgprev = pi->pi_pgprev;
1359 pi->pi_pgnext = NULL;
1360 pi->pi_pgprev = NULL;
1366 if (pi->pi_prev == NULL) {
1368 phyints = pi->pi_next;
1370 pi->pi_prev->pi_next = pi->pi_next;
1372 if (pi->pi_next != NULL)
1373 pi->pi_next->pi_prev = pi->pi_prev;
1374 pi->pi_next = NULL;
1375 pi->pi_prev = NULL;
1379 * it was a dup of `pi' -- and if so, online it.
1381 if (!pi->pi_hwaddrdup &&
1382 (pi2 = phyint_lookup_hwaddr(pi, _B_FALSE)) != NULL) {
1403 (pi->pi_flags & (IFF_STANDBY|IFF_INACTIVE)) == IFF_STANDBY)
1404 phyint_activate_another(pi);
1407 phyint_link_close(pi);
1408 free(pi);
1412 * Offline phyint `pi' if at least `minred' usable interfaces remain in the
1416 phyint_offline(struct phyint *pi, uint_t minred)
1421 struct phyint_group *pg = pi->pi_group;
1430 if (pi2 == pi)
1440 was_active = ((pi->pi_flags & IFF_INACTIVE) == 0);
1442 if (!change_pif_flags(pi, IFF_OFFLINE, IFF_INACTIVE))
1455 stop_probing(pi);
1463 if (pi->pi_hwaddrdup) {
1465 "unique in group %s; offlining\n", pi->pi_name,
1468 phyint_link_close(pi);
1475 if (!pi->pi_hwaddrdup &&
1476 (pi2 = phyint_lookup_hwaddr(pi, _B_FALSE)) != NULL) {
1486 phyint_activate_another(pi);
1492 * Undo a previous offline of `pi'. Returns an IPMP error code.
1495 phyint_undo_offline(struct phyint *pi)
1497 if (pi->pi_state != PI_OFFLINE) {
1506 if (pi->pi_dh == NULL && !phyint_link_init(pi)) {
1511 if (phyint_lookup_hwaddr(pi, _B_TRUE) != NULL) {
1512 pi->pi_hwaddrdup = _B_TRUE;
1516 if (pi->pi_hwaddrdup) {
1518 "group %s; onlining\n", pi->pi_name, pi->pi_group->pg_name);
1519 pi->pi_hwaddrdup = _B_FALSE;
1522 if (!change_pif_flags(pi, 0, IFF_OFFLINE))
1534 if (pi->pi_flags & IFF_FAILED) {
1535 phyint_chstate(pi, PI_FAILED);
1538 phyint_transition_to_running(pi);
1545 pi->pi_taddrthresh = getcurrentsec() + TESTADDR_CONF_TIME;
1556 struct phyint *pi = pii->pii_phyint;
1558 assert(pi != NULL);
1562 AF_STR(pii->pii_af), pi->pi_name);
1607 pi->pi_v4 = NULL;
1609 pi->pi_v6 = NULL;
1611 if (pi->pi_v4 == NULL && pi->pi_v6 == NULL)
1612 phyint_delete(pi);
2231 struct phyint *pi;
2332 pi = pii->pii_phyint;
2333 if (pi->pi_state == PI_NOTARGETS && PROBE_CAPABLE(pii)) {
2334 if (pi->pi_flags & IFF_FAILED)
2335 phyint_chstate(pi, PI_FAILED);
2337 phyint_chstate(pi, PI_RUNNING);
2513 struct phyint *pi;
2519 for (pi = pg->pg_phyint; pi != NULL; pi = pi->pi_pgnext) {
2520 pii = pi->pi_v4;
2530 pii = pi->pi_v6;
2639 * Get the number of UP logints on phyint `pi'.
2642 logint_upcount(struct phyint *pi)
2647 if (pi->pi_v4 != NULL) {
2648 for (li = pi->pi_v4->pii_logint; li != NULL; li = li->li_next) {
2654 if (pi->pi_v6 != NULL) {
2655 for (li = pi->pi_v6->pii_logint; li != NULL; li = li->li_next) {
2680 phyint_is_functioning(struct phyint *pi)
2682 if (pi->pi_state == PI_RUNNING)
2684 return (pi->pi_state == PI_NOTARGETS && !(pi->pi_flags & IFF_FAILED));
2691 phyint_is_usable(struct phyint *pi)
2693 if (logint_upcount(pi) == 0)
2695 return (phyint_is_functioning(pi));
2745 * Return the external IPMP state associated with phyint `pi'.
2748 ifstate(struct phyint *pi)
2750 switch (pi->pi_state) {
2755 if (pi->pi_flags & IFF_FAILED)
2769 logerr("ifstate: unknown state %d; aborting\n", pi->pi_state);
2775 * Return the external IPMP interface type associated with phyint `pi'.
2778 iftype(struct phyint *pi)
2780 if (pi->pi_flags & IFF_STANDBY)
2787 * Return the external IPMP link state associated with phyint `pi'.
2790 iflinkstate(struct phyint *pi)
2792 if (!(pi->pi_notes & (DL_NOTE_LINK_UP|DL_NOTE_LINK_DOWN)))
2795 return (LINK_DOWN(pi) ? IPMP_LINK_DOWN : IPMP_LINK_UP);
2799 * Return the external IPMP probe state associated with phyint `pi'.
2802 ifprobestate(struct phyint *pi)
2804 if (!PROBE_ENABLED(pi->pi_v4) && !PROBE_ENABLED(pi->pi_v6))
2807 if (pi->pi_state == PI_FAILED)
2810 if (!PROBE_CAPABLE(pi->pi_v4) && !PROBE_CAPABLE(pi->pi_v6))
2831 * Return the external IPMP flags associated with phyint `pi'.
2834 ifflags(struct phyint *pi)
2838 if (logint_upcount(pi) == 0)
2840 if (pi->pi_flags & IFF_INACTIVE)
2842 if (pi->pi_hwaddrdup)
2844 if (phyint_is_functioning(pi) && flags == 0)
3061 * Generate an ESC_IPMP_GROUP_MEMBER_CHANGE sysevent for phyint `pi' in
3065 phyint_group_member_event(struct phyint_group *pg, struct phyint *pi,
3088 errno = nvlist_add_string(nvl, IPMP_IF_NAME, pi->pi_name);
3092 errno = nvlist_add_uint32(nvl, IPMP_IF_TYPE, iftype(pi));
3096 errno = nvlist_add_uint32(nvl, IPMP_IF_STATE, ifstate(pi));
3109 * Generate an ESC_IPMP_IF_CHANGE sysevent for phyint `pi' in group `pg'.
3113 phyint_state_event(struct phyint_group *pg, struct phyint *pi)
3131 errno = nvlist_add_string(nvl, IPMP_IF_NAME, pi->pi_name);
3135 errno = nvlist_add_uint32(nvl, IPMP_IF_TYPE, iftype(pi));
3139 errno = nvlist_add_uint32(nvl, IPMP_IF_STATE, ifstate(pi));
3178 struct phyint *pi;
3197 for (pi = pg->pg_phyint; pi != NULL; pi = pi->pi_pgnext)
3201 for (i = 0, pi = pg->pg_phyint; pi != NULL; pi = pi->pi_pgnext, i++) {
3203 (void) strlcpy(ifs[i], pi->pi_name, LIFNAMSIZ);
3204 if (PROBE_ENABLED(pi->pi_v4) || PROBE_ENABLED(pi->pi_v6))
3309 struct phyint *pi;
3313 pi = phyint_lookup(ifname);
3314 if (pi == NULL)
3317 if ((retval = gettarginfo(pi->pi_v4, pi->pi_name, &targinfo4)) != 0 ||
3318 (retval = gettarginfo(pi->pi_v6, pi->pi_name, &targinfo6)) != 0)
3321 *ifinfopp = ipmp_ifinfo_create(pi->pi_name, pi->pi_group->pg_name,
3322 ifstate(pi), iftype(pi), iflinkstate(pi), ifprobestate(pi),
3323 ifflags(pi), targinfo4, targinfo6);
3423 struct phyint *pi;
3472 for (pi = phyints; pi != NULL; pi = pi->pi_next) {
3473 retval = getifinfo(pi->pi_name, &ifinfop);