예제 #1
0
void
table_show(int ac, char *av[])
{
	int nbytes, nalloc = 1024;
	void *data = NULL;
	NEXT_ARG;
	if (isdigit(**av)) {
		nbytes = nalloc;
		while (nbytes >= nalloc) {
			nalloc = nalloc * 2 + 256;
			nbytes = nalloc;
			if (data == NULL) {
				if ((data = malloc(nbytes)) == NULL) {
					err(EX_OSERR, "malloc");
				}
			} else if ((data = realloc(data, nbytes)) == NULL) {
				err(EX_OSERR, "realloc");
			}
			/* store table id in the header of data */
			int *head = (int *)data;
			*head = atoi(*av);
			if (*head < 0 || *head > IPFW_TABLES_MAX - 1)
				errx(EX_USAGE, "table id `%d' invalid", *head);
			if (do_get_x(IP_FW_TABLE_SHOW, data, &nbytes) < 0)
				err(EX_OSERR, "do_get_x(IP_FW_TABLE_LIST)");
			struct ipfw_ioc_table *tbl;
			tbl = (struct ipfw_ioc_table *)data;
			table_print(tbl);
		}
	} else {
		errx(EX_USAGE, "ipfw3 table `%s' show invalid", *av);
	}
}
예제 #2
0
void
sync_show_status(int ac, char *av[])
{
	int running, len;
	len = sizeof(running);
	if (do_get_x(IP_FW_SYNC_SHOW_STATUS, &running, &len) < 0) {
		err(EX_OSERR, "getsockopt(IP_FW_SYNC_SHOW_STATUS)");
	}
	if (running & 1) {
		printf("edge is running\n");
	}
	if (running & 2) {
		printf("centre is running\n");
	}
}
예제 #3
0
void
sync_show_config(int ac, char *av[])
{
	void *data = NULL;
	int nalloc = 1000, nbytes;
	nbytes = nalloc;

	while (nbytes >= nalloc) {
		nalloc = nalloc * 2 + 321;
		nbytes = nalloc;
		if (data == NULL) {
			if ((data = malloc(nbytes)) == NULL) {
				err(EX_OSERR, "malloc");
			}
		} else if ((data = realloc(data, nbytes)) == NULL) {
			err(EX_OSERR, "realloc");
		}
		if (do_get_x(IP_FW_SYNC_SHOW_CONF, data, &nbytes) < 0) {
			err(EX_OSERR, "getsockopt(IP_FW_SYNC_SHOW_CONF)");
		}
	}
	struct ipfw_ioc_sync_context *sync_ctx;
	sync_ctx = (struct ipfw_ioc_sync_context *)data;
	if (sync_ctx->edge_port != 0) {
		printf("ipfw3sync edge on %d %s\n", sync_ctx->edge_port,
				sync_ctx->hw_same == 1 ? "all" : "");
	}
	if (sync_ctx->count > 0) {
		struct ipfw_sync_edge *edge;
		int i;

		edge = sync_ctx->edges;
		printf("ipfw3sync centre to %d edge(s)\n", sync_ctx->count);
		for (i = 0; i < sync_ctx->count; i++) {
			struct in_addr in;
			in.s_addr = edge->addr;
			printf("edge on %s:%d\n", inet_ntoa(in), edge->port);
			edge++;
		}
	}

}
예제 #4
0
void
table_list(int ac, char *av[])
{
	struct ipfw_ioc_table *ioc_table;
	int i, count, nbytes, nalloc = 1024;
	void *data = NULL;
	NEXT_ARG;
	if (strcmp(*av, "list") == 0) {
		nbytes = nalloc;
		while (nbytes >= nalloc) {
			nalloc = nalloc * 2 ;
			nbytes = nalloc;
			if ((data = realloc(data, nbytes)) == NULL)
				err(EX_OSERR, "realloc");
			if (do_get_x(IP_FW_TABLE_LIST, data, &nbytes) < 0)
				err(EX_OSERR, "do_get_x(IP_FW_TABLE_LIST)");
		}
		ioc_table = (struct ipfw_ioc_table *)data;
		count = nbytes / sizeof(struct ipfw_ioc_table);
		for (i = 0; i < count; i++, ioc_table++) {
			if (ioc_table->type > 0) {
				printf("table %d",ioc_table->id);
				if (ioc_table->type == 1)
					printf(" type ip");
				else if (ioc_table->type == 2)
					printf(" type mac");
				printf(" count %d",ioc_table->count);
				if (strlen(ioc_table->name) > 0)
					printf(" name %s",ioc_table->name);
				printf("\n");

			}
		}
	} else {
		errx(EX_USAGE, "ipfw3 table `%s' delete invalid", *av);
	}
}