xref: /titanic_41/usr/src/cmd/ipf/lib/common/remove_poolnode.c (revision 0bb073995ac5a95bd35f2dd790df1ea3d8c2d507)
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.3 2003/11/22 10:14:36 darrenr Exp $
7  */
8 
9 #include <fcntl.h>
10 #include <sys/ioctl.h>
11 #include "ipf.h"
12 #include "netinet/ip_lookup.h"
13 #include "netinet/ip_pool.h"
14 
15 static int poolfd = -1;
16 
17 
18 int remove_poolnode(unit, name, node, iocfunc)
19 int unit;
20 char *name;
21 ip_pool_node_t *node;
22 ioctlfunc_t iocfunc;
23 {
24 	ip_pool_node_t pn;
25 	iplookupop_t op;
26 
27 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
28 		poolfd = open(IPLOOKUP_NAME, O_RDWR);
29 	if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0))
30 		return -1;
31 
32 	op.iplo_unit = unit;
33 	op.iplo_type = IPLT_POOL;
34 	op.iplo_arg = 0;
35 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
36 	op.iplo_struct = &pn;
37 	op.iplo_size = sizeof(pn);
38 
39 	bzero((char *)&pn, sizeof(pn));
40 	bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr,
41 	      sizeof(pn.ipn_addr));
42 	bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask,
43 	      sizeof(pn.ipn_mask));
44 	pn.ipn_info = node->ipn_info;
45 	strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name));
46 
47 	if ((*iocfunc)(poolfd, SIOCLOOKUPDELNODE, &op)) {
48 		if ((opts & OPT_DONOTHING) == 0) {
49 			perror("remove_pool:SIOCLOOKUPDELNODE");
50 			return -1;
51 		}
52 	}
53 
54 	return 0;
55 }
56