Darren Reed | da0443e | 2006-06-15 16:17:17 +0000 | [diff] [blame] | 1 | /* |
Darren Reed | c4af1f3 | 2007-08-20 10:15:33 +0000 | [diff] [blame] | 2 | * Copyright (C) 2003-2004 by Darren Reed. |
Darren Reed | da0443e | 2006-06-15 16:17:17 +0000 | [diff] [blame] | 3 | * |
| 4 | * See the IPFILTER.LICENCE file for details on licencing. |
| 5 | * |
| 6 | * $Id$ |
| 7 | */ |
| 8 | |
| 9 | #include <fcntl.h> |
| 10 | #include <sys/ioctl.h> |
| 11 | #include "ipf.h" |
| 12 | #include "netinet/ip_lookup.h" |
| 13 | #include "netinet/ip_pool.h" |
| 14 | |
| 15 | static int poolfd = -1; |
| 16 | |
| 17 | |
| 18 | int load_poolnode(role, name, node, iocfunc) |
Martti Kuparinen | 74b6c5c | 2007-10-25 12:55:40 +0000 | [diff] [blame] | 19 | int role; |
| 20 | char *name; |
| 21 | ip_pool_node_t *node; |
| 22 | ioctlfunc_t iocfunc; |
Darren Reed | da0443e | 2006-06-15 16:17:17 +0000 | [diff] [blame] | 23 | { |
| 24 | ip_pool_node_t pn; |
| 25 | iplookupop_t op; |
Darren Reed | d4718fc | 2006-06-15 17:00:40 +0000 | [diff] [blame] | 26 | int err; |
Darren Reed | da0443e | 2006-06-15 16:17:17 +0000 | [diff] [blame] | 27 | |
| 28 | if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0)) |
| 29 | poolfd = open(IPLOOKUP_NAME, O_RDWR); |
| 30 | if ((poolfd == -1) && ((opts & OPT_DONOTHING) == 0)) |
| 31 | return -1; |
| 32 | |
| 33 | op.iplo_unit = role; |
| 34 | op.iplo_type = IPLT_POOL; |
| 35 | op.iplo_arg = 0; |
| 36 | op.iplo_struct = &pn; |
| 37 | op.iplo_size = sizeof(pn); |
| 38 | strncpy(op.iplo_name, name, sizeof(op.iplo_name)); |
| 39 | |
| 40 | bzero((char *)&pn, sizeof(pn)); |
| 41 | bcopy((char *)&node->ipn_addr, (char *)&pn.ipn_addr, |
| 42 | sizeof(pn.ipn_addr)); |
| 43 | bcopy((char *)&node->ipn_mask, (char *)&pn.ipn_mask, |
| 44 | sizeof(pn.ipn_mask)); |
| 45 | pn.ipn_info = node->ipn_info; |
| 46 | strncpy(pn.ipn_name, node->ipn_name, sizeof(pn.ipn_name)); |
| 47 | |
Darren Reed | d4718fc | 2006-06-15 17:00:40 +0000 | [diff] [blame] | 48 | if ((opts & OPT_REMOVE) == 0) |
| 49 | err = (*iocfunc)(poolfd, SIOCLOOKUPADDNODE, &op); |
| 50 | else |
| 51 | err = (*iocfunc)(poolfd, SIOCLOOKUPDELNODE, &op); |
| 52 | |
| 53 | if (err != 0) { |
Darren Reed | da0443e | 2006-06-15 16:17:17 +0000 | [diff] [blame] | 54 | if ((opts & OPT_DONOTHING) == 0) { |
Darren Reed | c4af1f3 | 2007-08-20 10:15:33 +0000 | [diff] [blame] | 55 | perror("load_poolnode:SIOCLOOKUP*NODE"); |
Darren Reed | da0443e | 2006-06-15 16:17:17 +0000 | [diff] [blame] | 56 | return -1; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return 0; |
| 61 | } |