xref: /illumos-gate/usr/src/cmd/ipf/lib/load_hashnode.c (revision f3ac678143127d4c6c1793fadabb5ded04e127b6)
1*f3ac6781SToomas Soome /*
2*f3ac6781SToomas Soome  * Copyright (C) 2002 by Darren Reed.
3*f3ac6781SToomas Soome  *
4*f3ac6781SToomas Soome  * See the IPFILTER.LICENCE file for details on licencing.
5*f3ac6781SToomas Soome  *
6*f3ac6781SToomas Soome  * $Id: load_hashnode.c,v 1.2.4.1 2004/03/06 14:33:28 darrenr Exp $
7*f3ac6781SToomas Soome  *
8*f3ac6781SToomas Soome  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
9*f3ac6781SToomas Soome  * Use is subject to license terms.
10*f3ac6781SToomas Soome  *
11*f3ac6781SToomas Soome  * Copyright (c) 2014, Joyent, Inc.  All rights reserved.
12*f3ac6781SToomas Soome  */
13*f3ac6781SToomas Soome 
14*f3ac6781SToomas Soome #include <fcntl.h>
15*f3ac6781SToomas Soome #include <sys/ioctl.h>
16*f3ac6781SToomas Soome #include "ipf.h"
17*f3ac6781SToomas Soome #include "netinet/ip_lookup.h"
18*f3ac6781SToomas Soome #include "netinet/ip_htable.h"
19*f3ac6781SToomas Soome #include "ipfzone.h"
20*f3ac6781SToomas Soome 
21*f3ac6781SToomas Soome static int hashfd = -1;
22*f3ac6781SToomas Soome 
23*f3ac6781SToomas Soome 
load_hashnode(unit,name,node,iocfunc)24*f3ac6781SToomas Soome int load_hashnode(unit, name, node, iocfunc)
25*f3ac6781SToomas Soome int unit;
26*f3ac6781SToomas Soome char *name;
27*f3ac6781SToomas Soome iphtent_t *node;
28*f3ac6781SToomas Soome ioctlfunc_t iocfunc;
29*f3ac6781SToomas Soome {
30*f3ac6781SToomas Soome 	iplookupop_t op;
31*f3ac6781SToomas Soome 	iphtent_t ipe;
32*f3ac6781SToomas Soome 	int err;
33*f3ac6781SToomas Soome 
34*f3ac6781SToomas Soome 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
35*f3ac6781SToomas Soome 		hashfd = open(IPLOOKUP_NAME, O_RDWR);
36*f3ac6781SToomas Soome 	if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
37*f3ac6781SToomas Soome 		return -1;
38*f3ac6781SToomas Soome 	if (setzone(hashfd) != 0) {
39*f3ac6781SToomas Soome 		close(hashfd);
40*f3ac6781SToomas Soome 		return -1;
41*f3ac6781SToomas Soome 	}
42*f3ac6781SToomas Soome 
43*f3ac6781SToomas Soome 	op.iplo_type = IPLT_HASH;
44*f3ac6781SToomas Soome 	op.iplo_unit = unit;
45*f3ac6781SToomas Soome 	op.iplo_arg = 0;
46*f3ac6781SToomas Soome 	op.iplo_size = sizeof(ipe);
47*f3ac6781SToomas Soome 	op.iplo_struct = &ipe;
48*f3ac6781SToomas Soome 	strncpy(op.iplo_name, name, sizeof(op.iplo_name));
49*f3ac6781SToomas Soome 
50*f3ac6781SToomas Soome 	bzero((char *)&ipe, sizeof(ipe));
51*f3ac6781SToomas Soome 	ipe.ipe_family = node->ipe_family;
52*f3ac6781SToomas Soome 	bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
53*f3ac6781SToomas Soome 	      sizeof(ipe.ipe_addr));
54*f3ac6781SToomas Soome 	bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
55*f3ac6781SToomas Soome 	      sizeof(ipe.ipe_mask));
56*f3ac6781SToomas Soome 	bcopy((char *)&node->ipe_group, (char *)&ipe.ipe_group,
57*f3ac6781SToomas Soome 	      sizeof(ipe.ipe_group));
58*f3ac6781SToomas Soome 
59*f3ac6781SToomas Soome 	if ((opts & OPT_REMOVE) == 0)
60*f3ac6781SToomas Soome 		err = (*iocfunc)(hashfd, SIOCLOOKUPADDNODE, &op);
61*f3ac6781SToomas Soome 	else
62*f3ac6781SToomas Soome 		err = (*iocfunc)(hashfd, SIOCLOOKUPDELNODE, &op);
63*f3ac6781SToomas Soome 
64*f3ac6781SToomas Soome 	if (err != 0)
65*f3ac6781SToomas Soome 		if (!(opts & OPT_DONOTHING)) {
66*f3ac6781SToomas Soome 			perror("load_hash:SIOCLOOKUP*NODE");
67*f3ac6781SToomas Soome 			return -1;
68*f3ac6781SToomas Soome 		}
69*f3ac6781SToomas Soome 	return 0;
70*f3ac6781SToomas Soome }
71