17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * Copyright (C) 2002 by Darren Reed.
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * See the IPFILTER.LICENCE file for details on licencing.
57c478bd9Sstevel@tonic-gate *
6ab25eeb5Syz155240 * $Id: load_hashnode.c,v 1.2.4.1 2004/03/06 14:33:28 darrenr Exp $
77663b816Sml37995 *
8ab25eeb5Syz155240 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
97663b816Sml37995 * Use is subject to license terms.
10*94bdecd9SRob Gulewich *
11*94bdecd9SRob Gulewich * Copyright (c) 2014, Joyent, Inc. All rights reserved.
127c478bd9Sstevel@tonic-gate */
137c478bd9Sstevel@tonic-gate
147c478bd9Sstevel@tonic-gate #include <fcntl.h>
157c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
167c478bd9Sstevel@tonic-gate #include "ipf.h"
177c478bd9Sstevel@tonic-gate #include "netinet/ip_lookup.h"
187c478bd9Sstevel@tonic-gate #include "netinet/ip_htable.h"
19*94bdecd9SRob Gulewich #include "ipfzone.h"
207c478bd9Sstevel@tonic-gate
217c478bd9Sstevel@tonic-gate static int hashfd = -1;
227c478bd9Sstevel@tonic-gate
237c478bd9Sstevel@tonic-gate
load_hashnode(unit,name,node,iocfunc)247c478bd9Sstevel@tonic-gate int load_hashnode(unit, name, node, iocfunc)
257c478bd9Sstevel@tonic-gate int unit;
267c478bd9Sstevel@tonic-gate char *name;
277c478bd9Sstevel@tonic-gate iphtent_t *node;
287c478bd9Sstevel@tonic-gate ioctlfunc_t iocfunc;
297c478bd9Sstevel@tonic-gate {
307c478bd9Sstevel@tonic-gate iplookupop_t op;
317c478bd9Sstevel@tonic-gate iphtent_t ipe;
32ab25eeb5Syz155240 int err;
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
357c478bd9Sstevel@tonic-gate hashfd = open(IPLOOKUP_NAME, O_RDWR);
367c478bd9Sstevel@tonic-gate if ((hashfd == -1) && ((opts & OPT_DONOTHING) == 0))
377c478bd9Sstevel@tonic-gate return -1;
38*94bdecd9SRob Gulewich if (setzone(hashfd) != 0) {
39*94bdecd9SRob Gulewich close(hashfd);
40*94bdecd9SRob Gulewich return -1;
41*94bdecd9SRob Gulewich }
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate op.iplo_type = IPLT_HASH;
447c478bd9Sstevel@tonic-gate op.iplo_unit = unit;
457c478bd9Sstevel@tonic-gate op.iplo_arg = 0;
467c478bd9Sstevel@tonic-gate op.iplo_size = sizeof(ipe);
477c478bd9Sstevel@tonic-gate op.iplo_struct = &ipe;
487c478bd9Sstevel@tonic-gate strncpy(op.iplo_name, name, sizeof(op.iplo_name));
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate bzero((char *)&ipe, sizeof(ipe));
517663b816Sml37995 ipe.ipe_family = node->ipe_family;
527c478bd9Sstevel@tonic-gate bcopy((char *)&node->ipe_addr, (char *)&ipe.ipe_addr,
537c478bd9Sstevel@tonic-gate sizeof(ipe.ipe_addr));
547c478bd9Sstevel@tonic-gate bcopy((char *)&node->ipe_mask, (char *)&ipe.ipe_mask,
557c478bd9Sstevel@tonic-gate sizeof(ipe.ipe_mask));
567c478bd9Sstevel@tonic-gate bcopy((char *)&node->ipe_group, (char *)&ipe.ipe_group,
577c478bd9Sstevel@tonic-gate sizeof(ipe.ipe_group));
587c478bd9Sstevel@tonic-gate
59ab25eeb5Syz155240 if ((opts & OPT_REMOVE) == 0)
60ab25eeb5Syz155240 err = (*iocfunc)(hashfd, SIOCLOOKUPADDNODE, &op);
61ab25eeb5Syz155240 else
62ab25eeb5Syz155240 err = (*iocfunc)(hashfd, SIOCLOOKUPDELNODE, &op);
63ab25eeb5Syz155240
64ab25eeb5Syz155240 if (err != 0)
657c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING)) {
66ab25eeb5Syz155240 perror("load_hash:SIOCLOOKUP*NODE");
677c478bd9Sstevel@tonic-gate return -1;
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate return 0;
707c478bd9Sstevel@tonic-gate }
71