141edb306SCy Schubert /*
241edb306SCy Schubert * Copyright (C) 2012 by Darren Reed.
341edb306SCy Schubert *
441edb306SCy Schubert * See the IPFILTER.LICENCE file for details on licencing.
541edb306SCy Schubert *
641edb306SCy Schubert * $Id: load_dstlist.c,v 1.1.2.5 2012/07/22 08:04:24 darren_r Exp $
741edb306SCy Schubert */
841edb306SCy Schubert
941edb306SCy Schubert #include <fcntl.h>
1041edb306SCy Schubert #include <sys/ioctl.h>
1141edb306SCy Schubert #include "ipf.h"
1241edb306SCy Schubert #include "netinet/ip_lookup.h"
1341edb306SCy Schubert #include "netinet/ip_dstlist.h"
1441edb306SCy Schubert
1541edb306SCy Schubert
1641edb306SCy Schubert int
load_dstlist(ippool_dst_t * dst,ioctlfunc_t iocfunc,ipf_dstnode_t * nodes)17efeb8bffSCy Schubert load_dstlist(ippool_dst_t *dst, ioctlfunc_t iocfunc, ipf_dstnode_t *nodes)
1841edb306SCy Schubert {
1941edb306SCy Schubert iplookupop_t op;
2041edb306SCy Schubert ipf_dstnode_t *a;
2141edb306SCy Schubert ippool_dst_t dest;
2241edb306SCy Schubert
2341edb306SCy Schubert if (dst->ipld_name[0] == '\0')
24*2582ae57SCy Schubert return (-1);
2541edb306SCy Schubert
2641edb306SCy Schubert if (pool_open() == -1)
27*2582ae57SCy Schubert return (-1);
2841edb306SCy Schubert
2941edb306SCy Schubert op.iplo_unit = dst->ipld_unit;
3041edb306SCy Schubert op.iplo_type = IPLT_DSTLIST;
3141edb306SCy Schubert op.iplo_arg = 0;
3241edb306SCy Schubert strncpy(op.iplo_name, dst->ipld_name, sizeof(op.iplo_name));
3341edb306SCy Schubert op.iplo_size = sizeof(dest);
3441edb306SCy Schubert op.iplo_struct = &dest;
3541edb306SCy Schubert bzero((char *)&dest, sizeof(dest));
3641edb306SCy Schubert dest.ipld_unit = dst->ipld_unit;
3741edb306SCy Schubert dest.ipld_policy = dst->ipld_policy;
3841edb306SCy Schubert dest.ipld_flags = dst->ipld_flags;
3941edb306SCy Schubert strncpy(dest.ipld_name, dst->ipld_name, sizeof(dest.ipld_name));
4041edb306SCy Schubert
4141edb306SCy Schubert if ((opts & OPT_REMOVE) == 0) {
4241edb306SCy Schubert if (pool_ioctl(iocfunc, SIOCLOOKUPADDTABLE, &op))
4341edb306SCy Schubert if ((opts & OPT_DONOTHING) == 0) {
44*2582ae57SCy Schubert return (ipf_perror_fd(pool_fd(), iocfunc,
45*2582ae57SCy Schubert "add destination list table"));
4641edb306SCy Schubert }
4741edb306SCy Schubert }
4841edb306SCy Schubert
4941edb306SCy Schubert if ((opts & OPT_VERBOSE) != 0) {
5041edb306SCy Schubert dest.ipld_dests = dst->ipld_dests;
5141edb306SCy Schubert printdstlist(&dest, bcopywrap, dest.ipld_name, opts, nodes, NULL);
5241edb306SCy Schubert dest.ipld_dests = NULL;
5341edb306SCy Schubert }
5441edb306SCy Schubert
5541edb306SCy Schubert for (a = nodes; a != NULL; a = a->ipfd_next)
5641edb306SCy Schubert load_dstlistnode(dst->ipld_unit, dest.ipld_name, a, iocfunc);
5741edb306SCy Schubert
5841edb306SCy Schubert if ((opts & OPT_REMOVE) != 0) {
5941edb306SCy Schubert if (pool_ioctl(iocfunc, SIOCLOOKUPDELTABLE, &op))
6041edb306SCy Schubert if ((opts & OPT_DONOTHING) == 0) {
61*2582ae57SCy Schubert return (ipf_perror_fd(pool_fd(), iocfunc,
62*2582ae57SCy Schubert "delete destination list table"));
6341edb306SCy Schubert }
6441edb306SCy Schubert }
65*2582ae57SCy Schubert return (0);
6641edb306SCy Schubert }
67