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