Exemplo n.º 1
0
static boolean_t
sfunc_addr_outbound(ofmt_arg_t *ofmtarg, char *buf, uint_t bufsize)
{
	ipmpstat_sfunc_arg_t *arg = ofmtarg->ofmt_cbarg;
	int err;
	uint_t i, nactive = 0;
	ipmp_ifinfo_t *ifinfop;
	ipmp_iflist_t *iflistp;
	ipmp_addrinfo_t *adinfop = arg->sa_data;
	ipmp_groupinfo_t *grinfop;

	if (adinfop->ad_state == IPMP_ADDR_DOWN)
		return (B_TRUE);

	/*
	 * If there's no inbound interface for this address, there can't
	 * be any outbound traffic.
	 */
	if (adinfop->ad_binding[0] == '\0')
		return (B_TRUE);

	/*
	 * The address can use any active interface in the group, so
	 * obtain all of those.
	 */
	err = ipmp_getgroupinfo(arg->sa_ih, adinfop->ad_group, &grinfop);
	if (err != IPMP_SUCCESS) {
		warn_ipmperr(err, "cannot get info for group `%s'",
		    adinfop->ad_group);
		return (B_FALSE);
	}

	iflistp = grinfop->gr_iflistp;
	for (i = 0; i < iflistp->il_nif; i++) {
		err = ipmp_getifinfo(arg->sa_ih, iflistp->il_ifs[i], &ifinfop);
		if (err != IPMP_SUCCESS) {
			warn_ipmperr(err, "cannot get info for interface `%s'",
			    iflistp->il_ifs[i]);
			continue;
		}

		if (ifinfop->if_flags & IPMP_IFFLAG_ACTIVE) {
			if (nactive++ != 0)
				(void) strlcat(buf, " ", bufsize);
			(void) strlcat(buf, ifinfop->if_name, bufsize);
		}
		ipmp_freeifinfo(ifinfop);
	}
	ipmp_freegroupinfo(grinfop);
	return (B_TRUE);
}
Exemplo n.º 2
0
/*
 * Nested walker callback function for walk_if().
 */
static void
walk_if_cbfunc(ipmp_handle_t ih, void *infop, void *arg)
{
	int err;
	uint_t i;
	ipmp_groupinfo_t *grinfop = infop;
	ipmp_ifinfo_t *ifinfop;
	ipmp_iflist_t *iflistp = grinfop->gr_iflistp;
	ipmpstat_walkdata_t *iwp = arg;

	for (i = 0; i < iflistp->il_nif; i++) {
		err = ipmp_getifinfo(ih, iflistp->il_ifs[i], &ifinfop);
		if (err != IPMP_SUCCESS) {
			warn_ipmperr(err, "cannot get info for interface `%s'",
			    iflistp->il_ifs[i]);
			continue;
		}
		(*iwp->iw_func)(ih, ifinfop, iwp->iw_funcarg);
		ipmp_freeifinfo(ifinfop);
	}
}
Exemplo n.º 3
0
/*
 * Free all of the resources associated with snapshot `snap'.
 */
void
ipmp_snap_free(ipmp_snap_t *snap)
{
	ipmp_ifinfolist_t	*iflp, *ifnext;
	ipmp_groupinfolist_t	*grlp, *grnext;

	ipmp_freegrouplist(snap->sn_grlistp);

	for (grlp = snap->sn_grinfolistp; grlp != NULL; grlp = grnext) {
		grnext = grlp->grl_next;
		ipmp_freegroupinfo(grlp->grl_grinfop);
		free(grlp);
	}

	for (iflp = snap->sn_ifinfolistp; iflp != NULL; iflp = ifnext) {
		ifnext = iflp->ifl_next;
		ipmp_freeifinfo(iflp->ifl_ifinfop);
		free(iflp);
	}

	free(snap);
}
Exemplo n.º 4
0
static boolean_t
sfunc_group_interfaces(ofmt_arg_t *ofmtarg, char *buf, uint_t bufsize)
{
	ipmpstat_sfunc_arg_t *arg = ofmtarg->ofmt_cbarg;
	int err;
	uint_t i;
	char *active, *inactive, *unusable;
	uint_t nactive = 0, ninactive = 0, nunusable = 0;
	ipmp_groupinfo_t *grinfop = arg->sa_data;
	ipmp_iflist_t *iflistp = grinfop->gr_iflistp;
	ipmp_ifinfo_t *ifinfop;

	active = alloca(bufsize);
	active[0] = '\0';
	inactive = alloca(bufsize);
	inactive[0] = '\0';
	unusable = alloca(bufsize);
	unusable[0] = '\0';

	for (i = 0; i < iflistp->il_nif; i++) {
		err = ipmp_getifinfo(arg->sa_ih, iflistp->il_ifs[i], &ifinfop);
		if (err != IPMP_SUCCESS) {
			warn_ipmperr(err, "cannot get info for interface `%s'",
			    iflistp->il_ifs[i]);
			continue;
		}

		if (ifinfop->if_flags & IPMP_IFFLAG_ACTIVE) {
			if (nactive++ != 0)
				(void) strlcat(active, " ", bufsize);
			(void) strlcat(active, ifinfop->if_name, bufsize);
		} else if (ifinfop->if_flags & IPMP_IFFLAG_INACTIVE) {
			if (ninactive++ != 0)
				(void) strlcat(inactive, " ", bufsize);
			(void) strlcat(inactive, ifinfop->if_name, bufsize);
		} else {
			if (nunusable++ != 0)
				(void) strlcat(unusable, " ", bufsize);
			(void) strlcat(unusable, ifinfop->if_name, bufsize);
		}

		ipmp_freeifinfo(ifinfop);
	}

	(void) strlcpy(buf, active, bufsize);

	if (ninactive > 0) {
		if (nactive != 0)
			(void) strlcat(buf, " ", bufsize);

		(void) strlcat(buf, "(", bufsize);
		(void) strlcat(buf, inactive, bufsize);
		(void) strlcat(buf, ")", bufsize);
	}

	if (nunusable > 0) {
		if (nactive + ninactive != 0)
			(void) strlcat(buf, " ", bufsize);

		(void) strlcat(buf, "[", bufsize);
		(void) strlcat(buf, unusable, bufsize);
		(void) strlcat(buf, "]", bufsize);
	}
	return (B_TRUE);
}