xref: /onnv-gate/usr/src/cmd/ipf/lib/common/load_hashnode.c (revision 637:3bfca5eeee8e)
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  *
60Sstevel@tonic-gate  * $Id: load_hashnode.c,v 1.2 2003/04/26 04:55:11 darrenr Exp $
7*637Sml37995  *
8*637Sml37995  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
9*637Sml37995  * Use is subject to license terms.
100Sstevel@tonic-gate  */
110Sstevel@tonic-gate 
12*637Sml37995 #pragma ident	"%Z%%M%	%I%	%E% SMI"
13*637Sml37995 
140Sstevel@tonic-gate #include <fcntl.h>
150Sstevel@tonic-gate #include <sys/ioctl.h>
160Sstevel@tonic-gate #include "ipf.h"
170Sstevel@tonic-gate 
180Sstevel@tonic-gate #if SOLARIS2 >= 10
190Sstevel@tonic-gate #include "ip_lookup.h"
200Sstevel@tonic-gate #include "ip_htable.h"
210Sstevel@tonic-gate #else
220Sstevel@tonic-gate #include "netinet/ip_lookup.h"
230Sstevel@tonic-gate #include "netinet/ip_htable.h"
240Sstevel@tonic-gate #endif
250Sstevel@tonic-gate 
260Sstevel@tonic-gate static int hashfd = -1;
270Sstevel@tonic-gate 
280Sstevel@tonic-gate 
290Sstevel@tonic-gate int load_hashnode(unit, name, node, iocfunc)
300Sstevel@tonic-gate int unit;
310Sstevel@tonic-gate char *name;
320Sstevel@tonic-gate iphtent_t *node;
330Sstevel@tonic-gate ioctlfunc_t iocfunc;
340Sstevel@tonic-gate {
350Sstevel@tonic-gate 	iplookupop_t op;
360Sstevel@tonic-gate 	iphtent_t ipe;
370Sstevel@tonic-gate 
380Sstevel@tonic-gate 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
390Sstevel@tonic-gate 		hashfd = open(IPLOOKUP_NAME, O_RDWR);
400Sstevel@tonic-gate 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
410Sstevel@tonic-gate 		return -1;
420Sstevel@tonic-gate 
430Sstevel@tonic-gate 	op.iplo_type = IPLT_HASH;
440Sstevel@tonic-gate 	op.iplo_unit = unit;
450Sstevel@tonic-gate 	op.iplo_arg = 0;
460Sstevel@tonic-gate 	op.iplo_size = sizeof(ipe);
470Sstevel@tonic-gate 	op.iplo_struct = &ipe;
480Sstevel@tonic-gate 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
490Sstevel@tonic-gate 
500Sstevel@tonic-gate 	bzero((char *)&ipe, sizeof(ipe));
51*637Sml37995 	ipe.ipe_family = node->ipe_family;
520Sstevel@tonic-gate 	bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
530Sstevel@tonic-gate 	      sizeof(ipe.ipe_addr));
540Sstevel@tonic-gate 	bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
550Sstevel@tonic-gate 	      sizeof(ipe.ipe_mask));
560Sstevel@tonic-gate 	bcopy((char *)&node->ipe_group, (char *)&ipe.ipe_group,
570Sstevel@tonic-gate 	      sizeof(ipe.ipe_group));
580Sstevel@tonic-gate 
590Sstevel@tonic-gate 	if ((*iocfunc)(hashfd, SIOCLOOKUPADDNODE, &op))
600Sstevel@tonic-gate 		if (!(opts & OPT_DONOTHING)) {
610Sstevel@tonic-gate 			perror("load_hash:SIOCLOOKUPADDNODE");
620Sstevel@tonic-gate 			return -1;
630Sstevel@tonic-gate 		}
640Sstevel@tonic-gate 	return 0;
650Sstevel@tonic-gate }
66