xref: /titanic_50/usr/src/cmd/ipf/lib/common/remove_poolnode.c (revision 03831d35f7499c87d51205817c93e9a8d42c4bae)
1 /*
2  * Copyright (C) 2002 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id: remove_poolnode.c,v 1.1 2003/04/13 06:40:14 darrenr Exp $
7  */
8 
9 #include <fcntl.h>
10 #include <sys/ioctl.h>
11 #include "ipf.h"
12 
13 #if SOLARIS2 >= 10
14 #include "ip_lookup.h"
15 #include "ip_htable.h"
16 #else
17 #include "netinet/ip_lookup.h"
18 #include "netinet/ip_htable.h"
19 #endif
20 
21 static int poolfd = -1;
22 
23 
24 int remove_poolnode(unit, name, node, iocfunc)
25 int unit;
26 char *name;
27 ip_pool_node_t *node;
28 ioctlfunc_t iocfunc;
29 {
30 	ip_pool_node_t pn;
31 	iplookupop_t op;
32 
33 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
34 		poolfd = open(IPLOOKUP_NAME, O_RDWR);
35 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
36 		return -1;
37 
38 	op.iplo_unit = unit;
39 	op.iplo_type = IPLT_POOL;
40 	op.iplo_arg = 0;
41 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
42 	op.iplo_struct = &pn;
43 	op.iplo_size = sizeof(pn);
44 
45 	bzero((char *)&pn, sizeof(pn));
46 	bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr,
47 	      sizeof(pn.ipn_addr));
48 	bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask,
49 	      sizeof(pn.ipn_mask));
50 	pn.ipn_info = node->ipn_info;
51 	strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name));
52 
53 	if ((*iocfunc)(poolfd, SIOCLOOKUPDELNODE, &op)) {
54 		if ((opts & OPT_DONOTHING) == 0) {
55 			perror("remove_pool:SIOCLOOKUPDELNODE");
56 			return -1;
57 		}
58 	}
59 
60 	return 0;
61 }
62