load_hashnode.c revision 153881
1/* $FreeBSD: head/contrib/ipfilter/lib/load_hashnode.c 153881 2005-12-30 11:52:26Z guido $ */ 2 3/* 4 * Copyright (C) 2002 by Darren Reed. 5 * 6 * See the IPFILTER.LICENCE file for details on licencing. 7 * 8 * $Id: load_hashnode.c,v 1.2.4.1 2004/03/06 14:33:28 darrenr 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_htable.h" 16 17static int hashfd = -1; 18 19 20int load_hashnode(unit, name, node, iocfunc) 21int unit; 22char *name; 23iphtent_t *node; 24ioctlfunc_t iocfunc; 25{ 26 iplookupop_t op; 27 iphtent_t ipe; 28 int err; 29 30 if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0)) 31 hashfd = open(IPLOOKUP_NAME, O_RDWR); 32 if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0)) 33 return -1; 34 35 op.iplo_type = IPLT_HASH; 36 op.iplo_unit = unit; 37 op.iplo_arg = 0; 38 op.iplo_size = sizeof(ipe); 39 op.iplo_struct = &ipe; 40 strncpy(op.iplo_name, name, sizeof(op.iplo_name)); 41 42 bzero((char *)&ipe, sizeof(ipe)); 43 bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr, 44 sizeof(ipe.ipe_addr)); 45 bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask, 46 sizeof(ipe.ipe_mask)); 47 bcopy((char *)&node->ipe_group, (char *)&ipe.ipe_group, 48 sizeof(ipe.ipe_group)); 49 50 if ((opts & OPT_REMOVE) == 0) 51 err = (*iocfunc)(hashfd, SIOCLOOKUPADDNODE, &op); 52 else 53 err = (*iocfunc)(hashfd, SIOCLOOKUPDELNODE, &op); 54 55 if (err != 0) 56 if (!(opts & OPT_DONOTHING)) { 57 perror("load_hash:SIOCLOOKUP*NODE"); 58 return -1; 59 } 60 return 0; 61} 62