void conf_brcfg(FILE *output, int ifs, struct if_nameindex *ifn_list, char *ifname) { struct if_nameindex *br_ifnp; char tmp_str[TMPSIZ]; long l_tmp; if ((l_tmp = bridge_cfg(ifs, ifname, PRIORITY)) != -1 && l_tmp != DEFAULT_PRIORITY) fprintf(output, " priority %lu\n", l_tmp); if ((l_tmp = bridge_cfg(ifs, ifname, HELLOTIME)) != -1 && l_tmp != DEFAULT_HELLOTIME) fprintf(output, " hellotime %lu\n", l_tmp); if ((l_tmp = bridge_cfg(ifs, ifname, FWDDELAY)) != -1 && l_tmp != DEFAULT_FWDDELAY) fprintf(output, " fwddelay %lu\n", l_tmp); if ((l_tmp = bridge_cfg(ifs, ifname, MAXAGE)) != -1 && l_tmp != DEFAULT_MAXAGE) fprintf(output, " maxage %lu\n", l_tmp); if ((l_tmp = bridge_cfg(ifs, ifname, MAXADDR)) != -1 && l_tmp != DEFAULT_MAXADDR) fprintf(output, " maxaddr %lu\n", l_tmp); if ((l_tmp = bridge_cfg(ifs, ifname, TIMEOUT)) != -1 && l_tmp != DEFAULT_TIMEOUT) fprintf(output, " timeout %lu\n", l_tmp); if (bridge_list(ifs, ifname, NULL, tmp_str, TMPSIZ, MEMBER)) fprintf(output, " member %s\n", tmp_str); if (bridge_list(ifs, ifname, NULL, tmp_str, TMPSIZ, STP)) fprintf(output, " stp %s\n", tmp_str); if (bridge_list(ifs, ifname, NULL, tmp_str, TMPSIZ, SPAN)) fprintf(output, " span %s\n", tmp_str); if (bridge_list(ifs, ifname, NULL, tmp_str, TMPSIZ, NOLEARNING)) fprintf(output, " no learning %s\n", tmp_str); if (bridge_list(ifs, ifname, NULL, tmp_str, TMPSIZ, NODISCOVER)) fprintf(output, " no discover %s\n", tmp_str); if (bridge_list(ifs, ifname, NULL, tmp_str, TMPSIZ, BLOCKNONIP)) fprintf(output, " blocknonip %s\n", tmp_str); if (bridge_list(ifs, ifname, " ", tmp_str, TMPSIZ, CONF_IFPRIORITY)) fprintf(output, "%s", tmp_str); if (bridge_list(ifs, ifname, " ", tmp_str, TMPSIZ, CONF_IFCOST)) fprintf(output, "%s", tmp_str); bridge_confaddrs(ifs, ifname, " static ", output); for (br_ifnp = ifn_list; br_ifnp->if_name != NULL; br_ifnp++) /* try all interface names for member rules */ bridge_rules(ifs, ifname, br_ifnp->if_name, " rule ", output); }
void bridge_list(char *delim) { struct ifbreq *reqp; struct ifbifconf bifc; int i, len = 8192; char buf[sizeof(reqp->ifbr_ifsname) + 1], *inbuf = NULL, *inb; while (1) { bifc.ifbic_len = len; inb = realloc(inbuf, len); if (inb == NULL) err(1, "malloc"); bifc.ifbic_buf = inbuf = inb; strlcpy(bifc.ifbic_name, name, sizeof(bifc.ifbic_name)); if (ioctl(s, SIOCBRDGIFS, &bifc) < 0) err(1, "%s", name); if (bifc.ifbic_len + sizeof(*reqp) < len) break; len *= 2; } for (i = 0; i < bifc.ifbic_len / sizeof(*reqp); i++) { reqp = bifc.ifbic_req + i; strlcpy(buf, reqp->ifbr_ifsname, sizeof(buf)); printf("%s%s ", delim, buf); printb("flags", reqp->ifbr_ifsflags, IFBIFBITS); printf("\n"); if (reqp->ifbr_ifsflags & IFBIF_SPAN) continue; printf("\t\t"); printf("port %u ifpriority %u ifcost %u", reqp->ifbr_portno, reqp->ifbr_priority, reqp->ifbr_path_cost); if (reqp->ifbr_ifsflags & IFBIF_STP) printf(" %s role %s", stpstates[reqp->ifbr_state], stproles[reqp->ifbr_role]); printf("\n"); bridge_rules(buf, 0); } free(bifc.ifbic_buf); }