]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ipfilter/lib/remove_poolnode.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ipfilter / lib / remove_poolnode.c
1 /*      $FreeBSD$       */
2
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * $Id$
9  */
10
11 #include <fcntl.h>
12 #include <sys/ioctl.h>
13 #include "ipf.h"
14 #include "netinet/ip_lookup.h"
15 #include "netinet/ip_pool.h"
16
17
18 int
19 remove_poolnode(unit, name, node, iocfunc)
20         int unit;
21         char *name;
22         ip_pool_node_t *node;
23         ioctlfunc_t iocfunc;
24 {
25         ip_pool_node_t pn;
26         iplookupop_t op;
27
28         if (pool_open() == -1)
29                 return -1;
30
31         op.iplo_unit = unit;
32         op.iplo_type = IPLT_POOL;
33         op.iplo_arg = 0;
34         strncpy(op.iplo_name, name, sizeof(op.iplo_name));
35         op.iplo_struct = &pn;
36         op.iplo_size = sizeof(pn);
37
38         bzero((char *)&pn, sizeof(pn));
39         bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr,
40               sizeof(pn.ipn_addr));
41         bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask,
42               sizeof(pn.ipn_mask));
43         pn.ipn_info = node->ipn_info;
44         strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name));
45
46         if (pool_ioctl(iocfunc, SIOCLOOKUPDELNODE, &op)) {
47                 if ((opts & OPT_DONOTHING) == 0) {
48                         return ipf_perror_fd(pool_fd(), iocfunc,
49                                              "remove lookup pool node");
50                 }
51         }
52
53         return 0;
54 }