2 * Copyright (C) 2002 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * $Id: load_pool.c,v 1.14.2.2 2005/02/01 02:44:06 darrenr Exp $
8 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
9 * Use is subject to license terms.
11 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
15 #include <sys/ioctl.h>
17 #include "netinet/ip_lookup.h"
18 #include "netinet/ip_pool.h"
21 static int poolfd
= -1;
24 int load_pool(plp
, iocfunc
)
32 if ((poolfd
== -1) && ((opts
& OPT_DONOTHING
) == 0))
33 poolfd
= open(IPLOOKUP_NAME
, O_RDWR
);
34 if ((poolfd
== -1) && ((opts
& OPT_DONOTHING
) == 0))
36 if (setzone(poolfd
) != 0) {
41 op
.iplo_unit
= plp
->ipo_unit
;
42 op
.iplo_type
= IPLT_POOL
;
44 strncpy(op
.iplo_name
, plp
->ipo_name
, sizeof(op
.iplo_name
));
45 op
.iplo_size
= sizeof(pool
);
46 op
.iplo_struct
= &pool
;
47 bzero((char *)&pool
, sizeof(pool
));
48 strncpy(pool
.ipo_name
, plp
->ipo_name
, sizeof(pool
.ipo_name
));
49 if (*plp
->ipo_name
== '\0')
50 op
.iplo_arg
|= IPOOL_ANON
;
52 if ((opts
& OPT_REMOVE
) == 0) {
53 if ((*iocfunc
)(poolfd
, SIOCLOOKUPADDTABLE
, &op
))
54 if ((opts
& OPT_DONOTHING
) == 0) {
55 perror("load_pool:SIOCLOOKUPADDTABLE");
60 if ((opts
& OPT_VERBOSE
) != 0) {
61 pool
.ipo_list
= plp
->ipo_list
;
62 printpool(&pool
, bcopywrap
, pool
.ipo_name
, opts
);
66 for (a
= plp
->ipo_list
; a
!= NULL
; a
= a
->ipn_next
)
67 load_poolnode(plp
->ipo_unit
, plp
->ipo_name
, a
, iocfunc
);
69 if ((opts
& OPT_REMOVE
) != 0) {
70 if ((*iocfunc
)(poolfd
, SIOCLOOKUPDELTABLE
, &op
))
71 if ((opts
& OPT_DONOTHING
) == 0) {
72 perror("load_pool:SIOCLOOKUPDELTABLE");