static int br_cmd_showstp(int argc, char *const* argv) { struct bridge_info info; if (br_get_bridge_info(argv[1], &info)) { fprintf(stderr, "%s: can't get info %s\n", argv[1], strerror(errno)); return 1; } br_dump_info(argv[1], &info); return 0; }
static int show_bridge(const char *name, void *arg) { struct bridge_info info; fprintf(stdout, "%s\t\t", name); fflush(stdout); if (br_get_bridge_info(name, &info)) { fprintf(stderr, "can't get info %s\n", strerror(errno)); return 1; } br_dump_bridge_id((unsigned char *)&info.bridge_id); fprintf(stdout, "\t%s\t\t", info.stp_enabled ? "yes" : "no"); br_dump_interface_list(name); return 0; }
static int br_cmd_showigmp(int argc, char *const* argv) { const char *brname = argv[1]; #define CHUNK 128 int i, n; struct mc_fdb_entry *fdb = NULL; int offset = 0; struct bridge_info info; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36) u_int8_t group_addr_t[64] = {0}; #endif if (br_get_bridge_info(argv[1], &info)) { fprintf(stderr, "%s: can't get info %s\n", argv[1], strerror(errno)); return 1; } #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) printf("IGMP snooping enabled: %s\n", info.igmpsnoop_enabled?"yes":"no"); #else printf("Snooping enabled: %s\n", info.igmpsnoop_enabled?"yes":"no"); #endif printf("quickleave: %s\n", info.igmpsnoop_quickleave?"yes":"no"); #if !defined(TCSUPPORT_IGMPSNOOPING_ENHANCE) printf("routeportflag: %s\n", info.igmpsnoop_routeportflag?"on":"off"); #endif printf("debug: %s\n", info.igmpsnoop_dbg?"yes":"no"); printf("ageing time="); br_show_timer(&info.igmpsnoop_ageing_time); printf("\n\n"); br_dump_igmp_info(argv[1], &info); printf("\n"); for(;;) { fdb = realloc(fdb, (offset + CHUNK) * sizeof(struct mc_fdb_entry)); if (!fdb) { fprintf(stderr, "Out of memory\n"); return 1; } n = br_read_mc_fdb(brname, fdb+offset, offset, CHUNK); if (n == 0) break; if (n < 0) { fprintf(stderr, "read of forward table failed: %s\n", strerror(errno)); return 1; } offset += n; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36) if(n < CHUNK) break; #endif } qsort(fdb, offset, sizeof(struct mc_fdb_entry), compare_fdbs); #ifdef TCSUPPORT_IGMP_SNOOPING_V3 printf("port no group addr host addr src addr filter mode ageing timer\n"); #else printf("port no\tgroup addr\t\treporter\t\tageing timer\n"); #endif for (i = 0; i < offset; i++) { const struct mc_fdb_entry *f = fdb + i; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36) memset(group_addr_t, 0, 64); #endif #ifdef TCSUPPORT_IGMP_SNOOPING_V3 printf("%3i", f->port_no); #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36) if(f->version == 6) { printf(" [%s] ", f->group_addr); printf(" [%s] ", f->src_addr); printf("%2s ",(f->filter_mode == MCAST_EXCLUDE)?"EX":"IN"); printf("\thostMac:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x ", f->host_addr[0], f->host_addr[1], f->host_addr[2], f->host_addr[3], f->host_addr[4], f->host_addr[5]); printf("\tgroupMac:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x ", f->group_mac[0], f->group_mac[1], f->group_mac[2], f->group_mac[3], f->group_mac[4], f->group_mac[5]); } else{ #endif printf("%16s ", f->group_addr); printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x ", f->host_addr[0], f->host_addr[1], f->host_addr[2], f->host_addr[3], f->host_addr[4], f->host_addr[5]); printf("%16s ", f->src_addr); printf("%2s ",(f->filter_mode == MCAST_EXCLUDE)?"EX":"IN"); #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36) } #endif #else printf("%3i\t", f->port_no); printf("%16s\t", f->group_addr); printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\t", f->host_addr[0], f->host_addr[1], f->host_addr[2], f->host_addr[3], f->host_addr[4], f->host_addr[5]); #endif br_show_timer(&f->ageing_timer_value); printf("\n"); } return 0; }