1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (C) 2002 by Darren Reed.
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * See the IPFILTER.LICENCE file for details on licencing.
5*7c478bd9Sstevel@tonic-gate  *
6*7c478bd9Sstevel@tonic-gate  * $Id: remove_pool.c,v 1.1 2003/04/13 06:40:14 darrenr Exp $
7*7c478bd9Sstevel@tonic-gate  */
8*7c478bd9Sstevel@tonic-gate 
9*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
10*7c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
11*7c478bd9Sstevel@tonic-gate #include "ipf.h"
12*7c478bd9Sstevel@tonic-gate #include "netinet/ip_lookup.h"
13*7c478bd9Sstevel@tonic-gate #include "netinet/ip_htable.h"
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate static int poolfd = -1;
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate 
remove_pool(poolp,iocfunc)18*7c478bd9Sstevel@tonic-gate int remove_pool(poolp, iocfunc)
19*7c478bd9Sstevel@tonic-gate ip_pool_t *poolp;
20*7c478bd9Sstevel@tonic-gate ioctlfunc_t iocfunc;
21*7c478bd9Sstevel@tonic-gate {
22*7c478bd9Sstevel@tonic-gate 	iplookupop_t op;
23*7c478bd9Sstevel@tonic-gate 	ip_pool_t pool;
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
26*7c478bd9Sstevel@tonic-gate 		poolfd = open(IPLOOKUP_NAME, O_RDWR);
27*7c478bd9Sstevel@tonic-gate 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
28*7c478bd9Sstevel@tonic-gate 		return -1;
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate 	op.iplo_type = IPLT_POOL;
31*7c478bd9Sstevel@tonic-gate 	op.iplo_unit = poolp->ipo_unit;
32*7c478bd9Sstevel@tonic-gate 	strncpy(op.iplo_name, poolp->ipo_name, sizeof(op.iplo_name));
33*7c478bd9Sstevel@tonic-gate 	op.iplo_size = sizeof(pool);
34*7c478bd9Sstevel@tonic-gate 	op.iplo_struct = &pool;
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate 	bzero((char *)&pool, sizeof(pool));
37*7c478bd9Sstevel@tonic-gate 	pool.ipo_unit = poolp->ipo_unit;
38*7c478bd9Sstevel@tonic-gate 	strncpy(pool.ipo_name, poolp->ipo_name, sizeof(pool.ipo_name));
39*7c478bd9Sstevel@tonic-gate 	pool.ipo_flags = poolp->ipo_flags;
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate 	if ((*iocfunc)(poolfd, SIOCLOOKUPDELTABLE, &op))
42*7c478bd9Sstevel@tonic-gate 		if ((opts & OPT_DONOTHING) == 0) {
43*7c478bd9Sstevel@tonic-gate 			perror("remove_pool:SIOCLOOKUPDELTABLE");
44*7c478bd9Sstevel@tonic-gate 			return -1;
45*7c478bd9Sstevel@tonic-gate 		}
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate 	return 0;
48*7c478bd9Sstevel@tonic-gate }
49