]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ipfilter/lib/load_dstlist.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ipfilter / lib / load_dstlist.c
1 /*
2  * Copyright (C) 2012 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id: load_dstlist.c,v 1.1.2.5 2012/07/22 08:04:24 darren_r 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_dstlist.h"
14
15
16 int
17 load_dstlist(dst, iocfunc, nodes)
18         ippool_dst_t *dst;
19         ioctlfunc_t iocfunc;
20         ipf_dstnode_t *nodes;
21 {
22         iplookupop_t op;
23         ipf_dstnode_t *a;
24         ippool_dst_t dest;
25
26         if (dst->ipld_name[0] == '\0')
27                 return -1;
28
29         if (pool_open() == -1)
30                 return -1;
31
32         op.iplo_unit = dst->ipld_unit;
33         op.iplo_type = IPLT_DSTLIST;
34         op.iplo_arg = 0;
35         strncpy(op.iplo_name, dst->ipld_name, sizeof(op.iplo_name));
36         op.iplo_size = sizeof(dest);
37         op.iplo_struct = &dest;
38         bzero((char *)&dest, sizeof(dest));
39         dest.ipld_unit = dst->ipld_unit;
40         dest.ipld_policy = dst->ipld_policy;
41         dest.ipld_flags = dst->ipld_flags;
42         strncpy(dest.ipld_name, dst->ipld_name, sizeof(dest.ipld_name));
43
44         if ((opts & OPT_REMOVE) == 0) {
45                 if (pool_ioctl(iocfunc, SIOCLOOKUPADDTABLE, &op))
46                         if ((opts & OPT_DONOTHING) == 0) {
47                                 return ipf_perror_fd(pool_fd(), iocfunc,
48                                                   "add destination list table");
49                         }
50         }
51
52         if ((opts & OPT_VERBOSE) != 0) {
53                 dest.ipld_dests = dst->ipld_dests;
54                 printdstlist(&dest, bcopywrap, dest.ipld_name, opts, nodes, NULL);
55                 dest.ipld_dests = NULL;
56         }
57
58         for (a = nodes; a != NULL; a = a->ipfd_next)
59                 load_dstlistnode(dst->ipld_unit, dest.ipld_name, a, iocfunc);
60
61         if ((opts & OPT_REMOVE) != 0) {
62                 if (pool_ioctl(iocfunc, SIOCLOOKUPDELTABLE, &op))
63                         if ((opts & OPT_DONOTHING) == 0) {
64                                 return ipf_perror_fd(pool_fd(), iocfunc,
65                                               "delete destination list table");
66                         }
67         }
68         return 0;
69 }