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_dstlistnode.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_pool.h" 1441edb306SCy Schubert 1541edb306SCy Schubert 1641edb306SCy Schubert int 17*efeb8bffSCy Schubert load_dstlistnode(int role, char *name, ipf_dstnode_t *node, 18*efeb8bffSCy Schubert ioctlfunc_t iocfunc) 1941edb306SCy Schubert { 2041edb306SCy Schubert iplookupop_t op; 2141edb306SCy Schubert frdest_t *dst; 2241edb306SCy Schubert char *what; 2341edb306SCy Schubert int err; 2441edb306SCy Schubert 2541edb306SCy Schubert if (pool_open() == -1) 2641edb306SCy Schubert return -1; 2741edb306SCy Schubert 2841edb306SCy Schubert dst = calloc(1, sizeof(*dst) + node->ipfd_dest.fd_name); 2941edb306SCy Schubert if (dst == NULL) 3041edb306SCy Schubert return -1; 3141edb306SCy Schubert 3241edb306SCy Schubert op.iplo_unit = role; 3341edb306SCy Schubert op.iplo_type = IPLT_DSTLIST; 3441edb306SCy Schubert op.iplo_arg = 0; 3541edb306SCy Schubert op.iplo_struct = dst; 3641edb306SCy Schubert op.iplo_size = sizeof(*dst); 3741edb306SCy Schubert if (node->ipfd_dest.fd_name >= 0) 3841edb306SCy Schubert op.iplo_size += node->ipfd_dest.fd_name; 3941edb306SCy Schubert (void) strncpy(op.iplo_name, name, sizeof(op.iplo_name)); 4041edb306SCy Schubert 4141edb306SCy Schubert dst->fd_addr = node->ipfd_dest.fd_addr; 4241edb306SCy Schubert dst->fd_type = node->ipfd_dest.fd_type; 4341edb306SCy Schubert dst->fd_name = node->ipfd_dest.fd_name; 4441edb306SCy Schubert if (node->ipfd_dest.fd_name >= 0) 4541edb306SCy Schubert bcopy(node->ipfd_names, (char *)dst + sizeof(*dst), 4641edb306SCy Schubert node->ipfd_dest.fd_name); 4741edb306SCy Schubert 4841edb306SCy Schubert if ((opts & OPT_REMOVE) == 0) { 4941edb306SCy Schubert what = "add"; 5041edb306SCy Schubert err = pool_ioctl(iocfunc, SIOCLOOKUPADDNODE, &op); 5141edb306SCy Schubert } else { 5241edb306SCy Schubert what = "delete"; 5341edb306SCy Schubert err = pool_ioctl(iocfunc, SIOCLOOKUPDELNODE, &op); 5441edb306SCy Schubert } 5541edb306SCy Schubert free(dst); 5641edb306SCy Schubert 5741edb306SCy Schubert if (err != 0) { 5841edb306SCy Schubert if ((opts & OPT_DONOTHING) == 0) { 5941edb306SCy Schubert char msg[80]; 6041edb306SCy Schubert 6141edb306SCy Schubert (void) snprintf(msg, sizeof(msg), "%s lookup node", what); 6241edb306SCy Schubert return ipf_perror_fd(pool_fd(), iocfunc, msg); 6341edb306SCy Schubert } 6441edb306SCy Schubert } 6541edb306SCy Schubert 6641edb306SCy Schubert return 0; 6741edb306SCy Schubert } 68