Example #1
0
int
main(int argc, char *argv[])
{
	char *filename;
	sa_family_t af;

	if (argc != 3)
		usage();

	af = strncmp(argv[1], "inet6", 5) ? AF_INET : AF_INET6;
	filename = argv[2];

	rtable_init();
	if (rtable_add(0))
		errx(1, "can't add rtable\n");

	do_from_file(0, af, filename, route_insert);
	do_from_file(0, af, filename, route_lookup);

	rtable_walk(0, af, rtentry_dump, NULL);

	do_from_file(0, af, filename, route_delete);

	return (0);
}
Example #2
0
int
rtable_add(u_int id)	/* must be called at splsoftnet */
{
	void	*p, *q;

	if (id > RT_TABLEID_MAX)
		return (-1);

	if (id == 0 || id > rtbl_id_max) {
		size_t	newlen = sizeof(void *) * (id+1);
		size_t	newlen2 = sizeof(u_int) * (id+1);

		if ((p = malloc(newlen, M_RTABLE, M_NOWAIT|M_ZERO)) == NULL)
			return (-1);
		if ((q = malloc(newlen2, M_RTABLE, M_NOWAIT|M_ZERO)) == NULL) {
			free(p, M_RTABLE);
			return (-1);
		}
		if (rt_tables) {
			bcopy(rt_tables, p, sizeof(void *) * (rtbl_id_max+1));
			bcopy(rt_tab2dom, q, sizeof(u_int) * (rtbl_id_max+1));
			free(rt_tables, M_RTABLE);
		}
		rt_tables = p;
		rt_tab2dom = q;
		rtbl_id_max = id;
	}

	if (rt_tables[id] != NULL)	/* already exists */
		return (-1);

	rt_tab2dom[id] = 0;	/* use main table/domain by default */
	return (rtable_init(&rt_tables[id]));
}
Example #3
0
int
rtable_add(u_int id)	/* must be called at splsoftnet */
{
	void	*p;

	if (id > RT_TABLEID_MAX)
		return (-1);

	if (id == 0 || id > rtbl_id_max) {
		size_t	newlen = sizeof(void *) * (id+1);

		if ((p = malloc(newlen, M_RTABLE, M_NOWAIT)) == NULL)
			return (-1);
		bzero(p, newlen);
		if (id > 0) {
			bcopy(rt_tables, p, sizeof(void *) * (rtbl_id_max+1));
			free(rt_tables, M_RTABLE);
		}
		rt_tables = p;
		rtbl_id_max = id;
	}

	if (rt_tables[id] != NULL)	/* already exists */
		return (-1);

	return (rtable_init(&rt_tables[id]));
}