1139743Simp/*	$NetBSD: remove_hash.c,v 1.1.1.2 2007/04/14 20:17:31 martin Exp $	*/
243412Snewton
343412Snewton/*
443412Snewton * Copyright (C) 2003 by Darren Reed.
543412Snewton *
643412Snewton * See the IPFILTER.LICENCE file for details on licencing.
743412Snewton *
843412Snewton * Id: remove_hash.c,v 1.1.4.1 2006/06/16 17:21:16 darrenr Exp
943412Snewton */
1043412Snewton
1143412Snewton#include <fcntl.h>
1243412Snewton#include <sys/ioctl.h>
1343412Snewton#include "ipf.h"
1443412Snewton#include "netinet/ip_lookup.h"
1543412Snewton#include "netinet/ip_htable.h"
1643412Snewton
1743412Snewtonstatic int hashfd = -1;
1843412Snewton
1943412Snewton
2043412Snewtonint remove_hash(iphp, iocfunc)
2143412Snewtoniphtable_t *iphp;
2243412Snewtonioctlfunc_t iocfunc;
2343412Snewton{
2443412Snewton	iplookupop_t op;
2543412Snewton	iphtable_t iph;
2643412Snewton
2743412Snewton	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
2843412Snewton		hashfd = open(IPLOOKUP_NAME, O_RDWR);
2943412Snewton	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
3043412Snewton		return -1;
31101709Srwatson
32116174Sobrien	op.iplo_type = IPLT_HASH;
33116174Sobrien	op.iplo_unit = iphp->iph_unit;
34116174Sobrien	strncpy(op.iplo_name, iphp->iph_name, sizeof(op.iplo_name));
3543412Snewton	if (*op.iplo_name == '\0')
36263233Srwatson		op.iplo_arg = IPHASH_ANON;
3743412Snewton	op.iplo_size = sizeof(iph);
3843412Snewton	op.iplo_struct = &iph;
3943412Snewton
4043412Snewton	bzero((char *)&iph, sizeof(iph));
4176166Smarkm	iph.iph_unit = iphp->iph_unit;
42141486Sjhb	iph.iph_type = iphp->iph_type;
4343412Snewton	strncpy(iph.iph_name, iphp->iph_name, sizeof(iph.iph_name));
4476166Smarkm	iph.iph_flags = iphp->iph_flags;
4576166Smarkm
46164033Srwatson	if ((*iocfunc)(hashfd, SIOCLOOKUPDELTABLE, &op))
4776166Smarkm		if ((opts & OPT_DONOTHING) == 0) {
4876166Smarkm			perror("remove_hash:SIOCLOOKUPDELTABLE");
49134266Sjhb			return -1;
5076166Smarkm		}
5143412Snewton
5243412Snewton	return 0;
5343412Snewton}
5443412Snewton