remove_hashnode.c revision 170268
1/* $FreeBSD: head/contrib/ipfilter/lib/remove_hashnode.c 170268 2007-06-04 02:54:36Z darrenr $ */ 2 3/* 4 * Copyright (C) 2003 by Darren Reed. 5 * 6 * See the IPFILTER.LICENCE file for details on licencing. 7 * 8 * $Id: remove_hashnode.c,v 1.1.4.1 2006/06/16 17:21:16 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 remove_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 29 if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0)) 30 hashfd = open(IPLOOKUP_NAME, O_RDWR); 31 if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0)) 32 return -1; 33 34 op.iplo_type = IPLT_HASH; 35 op.iplo_unit = unit; 36 op.iplo_size = sizeof(ipe); 37 op.iplo_struct = &ipe; 38 op.iplo_arg = 0; 39 strncpy(op.iplo_name, name, sizeof(op.iplo_name)); 40 41 bzero((char *)&ipe, sizeof(ipe)); 42 bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr, 43 sizeof(ipe.ipe_addr)); 44 bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask, 45 sizeof(ipe.ipe_mask)); 46 47 if (opts & OPT_DEBUG) { 48 printf("\t%s - ", inet_ntoa(ipe.ipe_addr.in4)); 49 printf("%s\n", inet_ntoa(ipe.ipe_mask.in4)); 50 } 51 52 if ((*iocfunc)(hashfd, SIOCLOOKUPDELNODE, &op)) 53 if (!(opts & OPT_DONOTHING)) { 54 perror("remove_hash:SIOCLOOKUPDELNODE"); 55 return -1; 56 } 57 return 0; 58} 59