1
2/*
3 * Copyright (C) 2012 by Darren Reed.
4 *
5 * See the IPFILTER.LICENCE file for details on licencing.
6 *
7 * $Id$
8 */
9
10#include <fcntl.h>
11#include <sys/ioctl.h>
12#include "ipf.h"
13#include "netinet/ip_lookup.h"
14#include "netinet/ip_htable.h"
15
16
17int
18remove_hashnode(int unit, char *name, iphtent_t *node, ioctlfunc_t iocfunc)
19{
20	iplookupop_t op;
21	iphtent_t ipe;
22
23	if (pool_open() == -1)
24		return (-1);
25
26	op.iplo_type = IPLT_HASH;
27	op.iplo_unit = unit;
28	op.iplo_size = sizeof(ipe);
29	op.iplo_struct = &ipe;
30	op.iplo_arg = 0;
31	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
32
33	bzero((char *)&ipe, sizeof(ipe));
34	bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
35	      sizeof(ipe.ipe_addr));
36	bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
37	      sizeof(ipe.ipe_mask));
38
39	if (opts & OPT_DEBUG) {
40		printf("\t%s - ", inet_ntoa(ipe.ipe_addr.in4));
41		printf("%s\n", inet_ntoa(ipe.ipe_mask.in4));
42	}
43
44	if (pool_ioctl(iocfunc, SIOCLOOKUPDELNODE, &op)) {
45		if (!(opts & OPT_DONOTHING)) {
46			return (ipf_perror_fd(pool_fd(), iocfunc,
47					     "remove lookup hash node"));
48		}
49	}
50	return (0);
51}
52