1 /*
2 * Copyright (C) 2002 by Darren Reed.
3 *
4 * See the IPFILTER.LICENCE file for details on licencing.
5 *
6 * $Id: load_hashnode.c,v 1.2.4.1 2004/03/06 14:33:28 darrenr Exp $
7 *
8 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
9 * Use is subject to license terms.
10 */
11
12 #pragma ident "%Z%%M% %I% %E% SMI"
13
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
20 static int hashfd = -1;
21
22
load_hashnode(unit,name,node,iocfunc)23 int load_hashnode(unit, name, node, iocfunc)
24 int unit;
25 char *name;
26 iphtent_t *node;
27 ioctlfunc_t iocfunc;
28 {
29 iplookupop_t op;
30 iphtent_t ipe;
31 int err;
32
33 if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
34 hashfd = open(IPLOOKUP_NAME, O_RDWR);
35 if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
36 return -1;
37
38 op.iplo_type = IPLT_HASH;
39 op.iplo_unit = unit;
40 op.iplo_arg = 0;
41 op.iplo_size = sizeof(ipe);
42 op.iplo_struct = &ipe;
43 strncpy(op.iplo_name, name, sizeof(op.iplo_name));
44
45 bzero((char *)&ipe, sizeof(ipe));
46 ipe.ipe_family = node->ipe_family;
47 bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
48 sizeof(ipe.ipe_addr));
49 bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
50 sizeof(ipe.ipe_mask));
51 bcopy((char *)&node->ipe_group, (char *)&ipe.ipe_group,
52 sizeof(ipe.ipe_group));
53
54 if ((opts & OPT_REMOVE) == 0)
55 err = (*iocfunc)(hashfd, SIOCLOOKUPADDNODE, &op);
56 else
57 err = (*iocfunc)(hashfd, SIOCLOOKUPDELNODE, &op);
58
59 if (err != 0)
60 if (!(opts & OPT_DONOTHING)) {
61 perror("load_hash:SIOCLOOKUP*NODE");
62 return -1;
63 }
64 return 0;
65 }
66