10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * Copyright (C) 2002 by Darren Reed. 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * See the IPFILTER.LICENCE file for details on licencing. 50Sstevel@tonic-gate * 6*2393Syz155240 * $Id: load_hashnode.c,v 1.2.4.1 2004/03/06 14:33:28 darrenr Exp $ 7637Sml37995 * 8*2393Syz155240 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 9637Sml37995 * Use is subject to license terms. 100Sstevel@tonic-gate */ 110Sstevel@tonic-gate 12637Sml37995 #pragma ident "%Z%%M% %I% %E% SMI" 13637Sml37995 140Sstevel@tonic-gate #include <fcntl.h> 150Sstevel@tonic-gate #include <sys/ioctl.h> 160Sstevel@tonic-gate #include "ipf.h" 170Sstevel@tonic-gate #include "netinet/ip_lookup.h" 180Sstevel@tonic-gate #include "netinet/ip_htable.h" 190Sstevel@tonic-gate 200Sstevel@tonic-gate static int hashfd = -1; 210Sstevel@tonic-gate 220Sstevel@tonic-gate 230Sstevel@tonic-gate int load_hashnode(unit, name, node, iocfunc) 240Sstevel@tonic-gate int unit; 250Sstevel@tonic-gate char *name; 260Sstevel@tonic-gate iphtent_t *node; 270Sstevel@tonic-gate ioctlfunc_t iocfunc; 280Sstevel@tonic-gate { 290Sstevel@tonic-gate iplookupop_t op; 300Sstevel@tonic-gate iphtent_t ipe; 31*2393Syz155240 int err; 320Sstevel@tonic-gate 330Sstevel@tonic-gate if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0)) 340Sstevel@tonic-gate hashfd = open(IPLOOKUP_NAME, O_RDWR); 350Sstevel@tonic-gate if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0)) 360Sstevel@tonic-gate return -1; 370Sstevel@tonic-gate 380Sstevel@tonic-gate op.iplo_type = IPLT_HASH; 390Sstevel@tonic-gate op.iplo_unit = unit; 400Sstevel@tonic-gate op.iplo_arg = 0; 410Sstevel@tonic-gate op.iplo_size = sizeof(ipe); 420Sstevel@tonic-gate op.iplo_struct = &ipe; 430Sstevel@tonic-gate strncpy(op.iplo_name, name, sizeof(op.iplo_name)); 440Sstevel@tonic-gate 450Sstevel@tonic-gate bzero((char *)&ipe, sizeof(ipe)); 46637Sml37995 ipe.ipe_family = node->ipe_family; 470Sstevel@tonic-gate bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr, 480Sstevel@tonic-gate sizeof(ipe.ipe_addr)); 490Sstevel@tonic-gate bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask, 500Sstevel@tonic-gate sizeof(ipe.ipe_mask)); 510Sstevel@tonic-gate bcopy((char *)&node->ipe_group, (char *)&ipe.ipe_group, 520Sstevel@tonic-gate sizeof(ipe.ipe_group)); 530Sstevel@tonic-gate 54*2393Syz155240 if ((opts & OPT_REMOVE) == 0) 55*2393Syz155240 err = (*iocfunc)(hashfd, SIOCLOOKUPADDNODE, &op); 56*2393Syz155240 else 57*2393Syz155240 err = (*iocfunc)(hashfd, SIOCLOOKUPDELNODE, &op); 58*2393Syz155240 59*2393Syz155240 if (err != 0) 600Sstevel@tonic-gate if (!(opts & OPT_DONOTHING)) { 61*2393Syz155240 perror("load_hash:SIOCLOOKUP*NODE"); 620Sstevel@tonic-gate return -1; 630Sstevel@tonic-gate } 640Sstevel@tonic-gate return 0; 650Sstevel@tonic-gate } 66