1 /*        $NetBSD: poolio.c,v 1.2 2012/07/22 14:27:36 darrenr Exp $   */
2 
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * Id: poolio.c,v 1.1.1.2 2012/07/22 13:44:40 darrenr Exp $
9  */
10 
11 #include <fcntl.h>
12 #include <sys/ioctl.h>
13 #include "ipf.h"
14 #include "netinet/ip_lookup.h"
15 #include "netinet/ip_pool.h"
16 
17 static int poolfd = -1;
18 
19 
20 int
pool_open()21 pool_open()
22 {
23 
24           if ((opts & OPT_DONTOPEN) != 0)
25                     return 0;
26 
27           if (poolfd == -1)
28                     poolfd = open(IPLOOKUP_NAME, O_RDWR);
29           return poolfd;
30 }
31 
32 int
pool_ioctl(iocfunc,cmd,ptr)33 pool_ioctl(iocfunc, cmd, ptr)
34           ioctlfunc_t iocfunc;
35           ioctlcmd_t cmd;
36           void *ptr;
37 {
38           return (*iocfunc)(poolfd, cmd, ptr);
39 }
40 
41 
42 void
pool_close()43 pool_close()
44 {
45           if (poolfd != -1) {
46                     close(poolfd);
47                     poolfd = -1;
48           }
49 }
50 
51 int
pool_fd()52 pool_fd()
53 {
54           return poolfd;
55 }
56