1 /* 2 * Copyright (C) 2012 by Darren Reed. 3 * 4 * See the IPFILTER.LICENCE file for details on licencing. 5 * 6 * $Id: load_dstlistnode.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_pool.h" 14 15 16 int 17 load_dstlistnode(role, name, node, iocfunc) 18 int role; 19 char *name; 20 ipf_dstnode_t *node; 21 ioctlfunc_t iocfunc; 22 { 23 iplookupop_t op; 24 frdest_t *dst; 25 char *what; 26 int err; 27 28 if (pool_open() == -1) 29 return -1; 30 31 dst = calloc(1, sizeof(*dst) + node->ipfd_dest.fd_name); 32 if (dst == NULL) 33 return -1; 34 35 op.iplo_unit = role; 36 op.iplo_type = IPLT_DSTLIST; 37 op.iplo_arg = 0; 38 op.iplo_struct = dst; 39 op.iplo_size = sizeof(*dst); 40 if (node->ipfd_dest.fd_name >= 0) 41 op.iplo_size += node->ipfd_dest.fd_name; 42 (void) strncpy(op.iplo_name, name, sizeof(op.iplo_name)); 43 44 dst->fd_addr = node->ipfd_dest.fd_addr; 45 dst->fd_type = node->ipfd_dest.fd_type; 46 dst->fd_name = node->ipfd_dest.fd_name; 47 if (node->ipfd_dest.fd_name >= 0) 48 bcopy(node->ipfd_names, (char *)dst + sizeof(*dst), 49 node->ipfd_dest.fd_name); 50 51 if ((opts & OPT_REMOVE) == 0) { 52 what = "add"; 53 err = pool_ioctl(iocfunc, SIOCLOOKUPADDNODE, &op); 54 } else { 55 what = "delete"; 56 err = pool_ioctl(iocfunc, SIOCLOOKUPDELNODE, &op); 57 } 58 free(dst); 59 60 if (err != 0) { 61 if ((opts & OPT_DONOTHING) == 0) { 62 char msg[80]; 63 64 (void) snprintf(msg, sizeof(msg), "%s lookup node", what); 65 return ipf_perror_fd(pool_fd(), iocfunc, msg); 66 } 67 } 68 69 return 0; 70 } 71