int br_refresh() { struct bridge *b; b = bridge_list; while (b != NULL) { struct bridge *bnext; bnext = b->next; br_nuke_bridge(b); b = bnext; } return br_make_bridge_list(); }
int br_make_bridge_list() { int err; int i; int ifindices[32]; int num; num = br_ioctl(BRCTL_GET_BRIDGES, (unsigned long)ifindices, 32); if (num < 0) return errno; bridge_list = NULL; for (i=0;i<num;i++) { struct bridge *br; br = malloc(sizeof(struct bridge)); memset(br, 0, sizeof(struct bridge)); br->ifindex = ifindices[i]; br->firstport = NULL; br->next = bridge_list; bridge_list = br; if ((err = br_read_info(br)) != 0) goto error_out; if ((err = br_make_port_list(br)) != 0) goto error_out; } return 0; error_out: while (bridge_list != NULL) { struct bridge *nxt; nxt = bridge_list->next; br_nuke_bridge(bridge_list); bridge_list = nxt; } return err; }
int br_make_bridge_list() { int i; int err; int ifindices[1024]; int num; num = br_ioctl(BRCTL_GET_BRIDGES, (unsigned long)ifindices, 1024); if (num < 0) return errno; bridge_list = NULL; for (i=0;i<num;i++) { struct bridge *br; br = br_create_bridge_by_index(ifindices[i]); if (!br) { goto error_out; } br->next = bridge_list; bridge_list = br; } return 0; error_out: while (bridge_list != NULL) { struct bridge *nxt; nxt = bridge_list->next; br_nuke_bridge(bridge_list); bridge_list = nxt; } return err; }
struct bridge *br_create_bridge_by_index(int index) { struct bridge *br; int err; br = malloc(sizeof(struct bridge)); if (!br) { return NULL; } memset(br, 0, sizeof(struct bridge)); br->ifindex = index; br->firstport = NULL; if ((err = br_read_info(br)) != 0) goto error_out; if ((err = br_make_port_list(br)) != 0) goto error_out; return br; error_out: br_nuke_bridge(br); return NULL; }