Home | History | Annotate | Line # | Download | only in lib
load_dstlist.c revision 1.1
      1 /*	$NetBSD: load_dstlist.c,v 1.1 2012/03/23 21:20:08 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 2010 by Darren Reed.
      5  *
      6  * See the IPFILTER.LICENCE file for details on licencing.
      7  *
      8  * Id: load_dstlist.c,v 1.1.2.2 2012/01/26 05:44:26 darren_r Exp
      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_dstlist.h"
     16 
     17 
     18 int
     19 load_dstlist(dst, iocfunc, nodes)
     20 	ippool_dst_t *dst;
     21 	ioctlfunc_t iocfunc;
     22 	ipf_dstnode_t *nodes;
     23 {
     24 	iplookupop_t op;
     25 	ipf_dstnode_t *a;
     26 	ippool_dst_t dest;
     27 
     28 	if (dst->ipld_name[0] == '\0')
     29 		return -1;
     30 
     31 	if (pool_open() == -1)
     32 		return -1;
     33 
     34 	op.iplo_unit = dst->ipld_unit;
     35 	op.iplo_type = IPLT_DSTLIST;
     36 	op.iplo_arg = 0;
     37 	strncpy(op.iplo_name, dst->ipld_name, sizeof(op.iplo_name));
     38 	op.iplo_size = sizeof(dest);
     39 	op.iplo_struct = &dest;
     40 	bzero((char *)&dest, sizeof(dest));
     41 	dest.ipld_unit = dst->ipld_unit;
     42 	dest.ipld_policy = dst->ipld_policy;
     43 	dest.ipld_flags = dst->ipld_flags;
     44 	strncpy(dest.ipld_name, dst->ipld_name, sizeof(dest.ipld_name));
     45 
     46 	if ((opts & OPT_REMOVE) == 0) {
     47 		if (pool_ioctl(iocfunc, SIOCLOOKUPADDTABLE, &op))
     48 			if ((opts & OPT_DONOTHING) == 0) {
     49 				perror("load_dstlist:SIOCLOOKUPADDTABLE");
     50 				return -1;
     51 			}
     52 	}
     53 
     54 	if ((opts & OPT_VERBOSE) != 0) {
     55 		dest.ipld_dests = dst->ipld_dests;
     56 		printdstlist(&dest, bcopywrap, dest.ipld_name, opts, nodes, NULL);
     57 		dest.ipld_dests = NULL;
     58 	}
     59 
     60 	for (a = nodes; a != NULL; a = a->ipfd_next)
     61 		load_dstlistnode(dst->ipld_unit, dest.ipld_name, a, 0, iocfunc);
     62 
     63 	if ((opts & OPT_REMOVE) != 0) {
     64 		if (pool_ioctl(iocfunc, SIOCLOOKUPDELTABLE, &op))
     65 			if ((opts & OPT_DONOTHING) == 0) {
     66 				perror("load_dstlist:SIOCLOOKUPDELTABLE");
     67 				return -1;
     68 			}
     69 	}
     70 	return 0;
     71 }
     72