void sync_edge_test(int ac, char *av[]) { int i = 0; if(do_set_x(IP_FW_SYNC_EDGE_TEST, &i, sizeof(i)) < 0) { err(EX_UNAVAILABLE, "do_set_x(IP_FW_SYNC_EDGE_CLEAR)"); } }
void sync_centre_clear(int ac, char *av[]) { int i = 0; if(do_set_x(IP_FW_SYNC_CENTRE_CLEAR, &i, sizeof(i)) < 0) { err(EX_UNAVAILABLE, "do_set_x(IP_FW_SYNC_CENTRE_CLEAR)"); } }
void sync_centre_stop(int ac, char *av[]) { int i = 0; if(do_set_x(IP_FW_SYNC_CENTRE_STOP, &i, sizeof(i)) < 0) { err(EX_UNAVAILABLE, "do_set_x(IP_FW_SYNC_CENTRE_STOP"); } }
void sync_edge_stop(int ac, char *av[]) { int i = 0; if(do_set_x(IP_FW_SYNC_EDGE_STOP, &i, sizeof(i)) < 0) { err(EX_UNAVAILABLE, "do_set_x(IP_FW_SYNC_EDGE_STOP)"); } }
void table_append(int ac, char *av[]) { struct ipfw_ioc_table tbl; char *p; int size; NEXT_ARG; if (isdigit(**av)) tbl.id = atoi(*av); else errx(EX_USAGE, "table id `%s' invalid", *av); if (tbl.id < 0 || tbl.id > IPFW_TABLES_MAX - 1) errx(EX_USAGE, "table id `%d' invalid", tbl.id); NEXT_ARG; if (strcmp(*av, "ip") == 0) tbl.type = 1; else if (strcmp(*av, "mac") == 0) tbl.type = 2; else errx(EX_USAGE, "table type `%s' not supported", *av); NEXT_ARG; if (tbl.type == 1) { /* table type ipv4 */ struct ipfw_ioc_table_ip_entry ip_ent; if (!ac) errx(EX_USAGE, "IP address required"); p = strchr(*av, '/'); if (p) { *p++ = '\0'; ip_ent.masklen = atoi(p); if (ip_ent.masklen > 32) errx(EX_DATAERR, "bad width ``%s''", p); } else { ip_ent.masklen = 32; } if (lookup_host(*av, (struct in_addr *)&ip_ent.addr) != 0) errx(EX_NOHOST, "hostname ``%s'' unknown", *av); tbl.ip_ent[0] = ip_ent; size = sizeof(tbl) + sizeof(ip_ent); } else if (tbl.type == 2) { /* table type mac */ struct ipfw_ioc_table_mac_entry mac_ent; if (!ac) errx(EX_USAGE, "MAC address required"); mac_ent.addr = *ether_aton(*av); tbl.mac_ent[0] = mac_ent; size = sizeof(tbl) + sizeof(mac_ent); } if (do_set_x(IP_FW_TABLE_APPEND, &tbl, size) < 0 ) errx(EX_USAGE, "do_set_x(IP_FW_TABLE_APPEND) " "table `%d' append `%s' failed", tbl.id, *av); }
void sync_config_centre(int ac, char *av[]) { struct ipfw_ioc_sync_centre *centre; struct ipfw_sync_edge *edge; struct in_addr addr; char *tok; char *str; int count = 0, step = 10, len, data_len; void *data = NULL; NEXT_ARG; tok = strtok(*av, ","); len = sizeof(int); data_len = len + step * sizeof(struct ipfw_sync_edge); data = malloc(data_len); centre = (struct ipfw_ioc_sync_centre *)data; edge = centre->edges; while (tok != NULL) { str = strchr(tok,':'); if (str != NULL) { *(str++) = '\0'; edge->port = (u_short)strtoul(str, NULL, 0); if (edge->port == 0) { errx(EX_USAGE, "edge `%s:%s' invalid", tok, str); } } else { err(EX_UNAVAILABLE, "dst invalid"); } inet_aton(tok, &addr); edge->addr = addr.s_addr; if (count >= step) { step += 10; data_len = len + step * sizeof(struct ipfw_sync_edge); if ((data = realloc(data, data_len)) == NULL) { err(EX_OSERR, "realloc in config sync centre"); } } tok = strtok (NULL, ","); count++; edge++; } if (count > MAX_EDGES) { err(EX_OSERR,"too much edges"); } centre->count = count; len += count * sizeof(struct ipfw_sync_edge); if(do_set_x(IP_FW_SYNC_CENTRE_CONF, data, len) < 0) { err(EX_UNAVAILABLE, "do_set_x(IP_FW_SYNC_CENTRE_CONF)"); } }
void sync_centre_test(int ac, char *av[]) { int n; NEXT_ARG; if (!isdigit(**av)) { errx(EX_DATAERR, "invalid test number %s\n", *av); } n = atoi(*av); if(do_set_x(IP_FW_SYNC_CENTRE_TEST, &n, sizeof(n)) < 0) { err(EX_UNAVAILABLE, "do_set_x(IP_FW_SYNC_CENTRE_TEST)"); } printf("centre test %d sent\n", n); }
void table_test(int ac, char *av[]) { struct ipfw_ioc_table tbl; int size; NEXT_ARG; if (isdigit(**av)) tbl.id = atoi(*av); else errx(EX_USAGE, "table id `%s' invalid", *av); if (tbl.id < 0 || tbl.id > IPFW_TABLES_MAX - 1) errx(EX_USAGE, "table id `%d' invalid", tbl.id); NEXT_ARG; if (strcmp(*av, "ip") == 0) tbl.type = 1; else if (strcmp(*av, "mac") == 0) tbl.type = 2; else errx(EX_USAGE, "table type `%s' not supported", *av); NEXT_ARG; if (tbl.type == 1) { /* table type ipv4 */ struct ipfw_ioc_table_ip_entry ip_ent; if (lookup_host(*av, (struct in_addr *)&ip_ent.addr) != 0) errx(EX_NOHOST, "hostname ``%s'' unknown", *av); tbl.ip_ent[0] = ip_ent; size = sizeof(tbl) + sizeof(ip_ent); } else if (tbl.type == 2) { /* table type mac */ struct ipfw_ioc_table_mac_entry mac_ent; if (!ac) errx(EX_USAGE, "MAC address required"); mac_ent.addr = *ether_aton(*av); tbl.mac_ent[0] = mac_ent; size = sizeof(tbl) + sizeof(mac_ent); } if (do_set_x(IP_FW_TABLE_TEST, &tbl, size) < 0 ) { printf("NO, %s not exists in table %d\n", *av, tbl.id); } else { printf("YES, %s exists in table %d\n", *av, tbl.id); } }
void table_flush(int ac, char *av[]) { struct ipfw_ioc_table ioc_table; struct ipfw_ioc_table *t = &ioc_table; NEXT_ARG; if (isdigit(**av)) { t->id = atoi(*av); if (t->id < 0 || t->id > IPFW_TABLES_MAX - 1) errx(EX_USAGE, "table id `%d' invalid", t->id); } else { errx(EX_USAGE, "table id `%s' invalid", *av); } if (do_set_x(IP_FW_TABLE_FLUSH, t, sizeof(struct ipfw_ioc_table)) < 0 ) errx(EX_USAGE, "do_set_x(IP_FW_TABLE_FLUSH) " "table `%s' flush failed", *av); }
void table_create(int ac, char *av[]) { struct ipfw_ioc_table ioc_table; struct ipfw_ioc_table *t = &ioc_table; NEXT_ARG; if (ac < 2) errx(EX_USAGE, "table parameters invalid"); if (isdigit(**av)) { t->id = atoi(*av); if (t->id < 0 || t->id > IPFW_TABLES_MAX - 1) errx(EX_USAGE, "table id `%d' invalid", t->id); } else { errx(EX_USAGE, "table id `%s' invalid", *av); } NEXT_ARG; if (strcmp(*av, "ip") == 0) t->type = 1; else if (strcmp(*av, "mac") == 0) t->type = 2; else errx(EX_USAGE, "table type `%s' not supported", *av); NEXT_ARG; memset(t->name, 0, IPFW_TABLE_NAME_LEN); if (ac == 2 && strcmp(*av, "name") == 0) { NEXT_ARG; if (strlen(*av) < IPFW_TABLE_NAME_LEN) { strncpy(t->name, *av, strlen(*av)); } else { errx(EX_USAGE, "table name `%s' too long", *av); } } else if (ac == 1) { errx(EX_USAGE, "table `%s' invalid", *av); } if (do_set_x(IP_FW_TABLE_CREATE, t, sizeof(struct ipfw_ioc_table)) < 0) errx(EX_USAGE, "do_set_x(IP_FW_TABLE_CREATE) " "table `%d' in use", t->id); }
static void table_rename(int ac, char *av[]) { struct ipfw_ioc_table tbl; int size; bzero(&tbl, sizeof(tbl)); NEXT_ARG; if (isdigit(**av)) tbl.id = atoi(*av); else errx(EX_USAGE, "table id `%s' invalid", *av); if (tbl.id < 0 || tbl.id > IPFW_TABLES_MAX - 1) errx(EX_USAGE, "table id `%d' invalid", tbl.id); NEXT_ARG; strlcpy(tbl.name, *av, IPFW_TABLE_NAME_LEN); size = sizeof(tbl); if (do_set_x(IP_FW_TABLE_RENAME, &tbl, size) < 0 ) errx(EX_USAGE, "do_set_x(IP_FW_TABLE_RENAME) " "table `%d' not in use", tbl.id); }
void sync_config_edge(int ac, char *av[]) { struct ipfw_ioc_sync_edge ioc_edge; NEXT_ARG; if (isdigit(**av)) { ioc_edge.port = atoi(*av); if (ioc_edge.port == 0) { errx(EX_USAGE, "invalid edge port `%s'", *av); } NEXT_ARG; if (strcmp(*av, "all") == 0) { ioc_edge.hw_same = 1; } else { ioc_edge.hw_same = 0; } if(do_set_x(IP_FW_SYNC_EDGE_CONF, &ioc_edge, sizeof(ioc_edge)) < 0) { err(EX_UNAVAILABLE, "do_set_x(IP_FW_SYNC_EDGE_CONF)"); } } else { errx(EX_USAGE, "invalid edge port `%s'", *av); } }