1 /* $FreeBSD$ */ 2 3 /* 4 * Copyright (C) 2012 by Darren Reed. 5 * 6 * See the IPFILTER.LICENCE file for details on licencing. 7 * 8 * $Id$ 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_htable.h" 16 17 18 int 19 load_hashnode(int unit, char *name, iphtent_t *node, int ttl, 20 ioctlfunc_t iocfunc) 21 { 22 iplookupop_t op; 23 iphtent_t ipe; 24 char *what; 25 int err; 26 27 if (pool_open() == -1) 28 return (-1); 29 30 op.iplo_type = IPLT_HASH; 31 op.iplo_unit = unit; 32 op.iplo_arg = 0; 33 op.iplo_size = sizeof(ipe); 34 op.iplo_struct = &ipe; 35 strncpy(op.iplo_name, name, sizeof(op.iplo_name)); 36 37 bzero((char *)&ipe, sizeof(ipe)); 38 ipe.ipe_family = node->ipe_family; 39 ipe.ipe_die = ttl; 40 bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr, 41 sizeof(ipe.ipe_addr)); 42 bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask, 43 sizeof(ipe.ipe_mask)); 44 bcopy((char *)&node->ipe_group, (char *)&ipe.ipe_group, 45 sizeof(ipe.ipe_group)); 46 47 if ((opts & OPT_REMOVE) == 0) { 48 what = "add"; 49 err = pool_ioctl(iocfunc, SIOCLOOKUPADDNODE, &op); 50 } else { 51 what = "delete"; 52 err = pool_ioctl(iocfunc, SIOCLOOKUPDELNODE, &op); 53 } 54 55 if (err != 0) 56 if (!(opts & OPT_DONOTHING)) { 57 char msg[80]; 58 59 snprintf(msg, sizeof(msg), "%s node from lookup hash table", what); 60 return (ipf_perror_fd(pool_fd(), iocfunc, msg)); 61 } 62 return (0); 63 } 64