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