| 1 | /* $Id$ */ |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | * Copyright (c) 2001-2007 Aaron Turner. |
|---|
| 5 | * All rights reserved. |
|---|
| 6 | * |
|---|
| 7 | * Redistribution and use in source and binary forms, with or without |
|---|
| 8 | * modification, are permitted provided that the following conditions |
|---|
| 9 | * are met: |
|---|
| 10 | * |
|---|
| 11 | * 1. Redistributions of source code must retain the above copyright |
|---|
| 12 | * notice, this list of conditions and the following disclaimer. |
|---|
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 14 | * notice, this list of conditions and the following disclaimer in the |
|---|
| 15 | * documentation and/or other materials provided with the distribution. |
|---|
| 16 | * 3. Neither the names of the copyright owners nor the names of its |
|---|
| 17 | * contributors may be used to endorse or promote products derived from |
|---|
| 18 | * this software without specific prior written permission. |
|---|
| 19 | * |
|---|
| 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|---|
| 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|---|
| 22 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|---|
| 23 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
|---|
| 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|---|
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
|---|
| 26 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|---|
| 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
|---|
| 28 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|---|
| 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|---|
| 30 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 31 | */ |
|---|
| 32 | |
|---|
| 33 | #ifndef __TREE_H__ |
|---|
| 34 | #define __TREE_H__ |
|---|
| 35 | |
|---|
| 36 | #include "lib/tree.h" |
|---|
| 37 | |
|---|
| 38 | #define TREEPRINTBUFFLEN 2048 |
|---|
| 39 | |
|---|
| 40 | struct tcpr_tree_s { |
|---|
| 41 | RB_ENTRY(tcpr_tree_s) node; |
|---|
| 42 | unsigned long ip; /* ip/network address in network byte order */ |
|---|
| 43 | u_char mac[ETHER_ADDR_LEN]; /* mac address of system */ |
|---|
| 44 | int masklen; /* CIDR network mask length */ |
|---|
| 45 | int server_cnt; /* count # of times this entry was flagged server */ |
|---|
| 46 | int client_cnt; /* flagged client */ |
|---|
| 47 | int type; /* 1 = server, 0 = client, -1 = undefined */ |
|---|
| 48 | }; |
|---|
| 49 | typedef struct tcpr_tree_s tcpr_tree_t; |
|---|
| 50 | |
|---|
| 51 | /* |
|---|
| 52 | * replacement for RB_HEAD() which doesn't actually declare the root |
|---|
| 53 | */ |
|---|
| 54 | struct tcpr_data_tree_s { |
|---|
| 55 | tcpr_tree_t *rbh_root; |
|---|
| 56 | }; |
|---|
| 57 | typedef struct tcpr_data_tree_s tcpr_data_tree_t; |
|---|
| 58 | |
|---|
| 59 | struct tcpr_buildcidr_s { |
|---|
| 60 | int type; /* SERVER|CLIENT|UNKNOWN|ANY */ |
|---|
| 61 | int masklen; /* mask size to use to build the CIDR */ |
|---|
| 62 | }; |
|---|
| 63 | |
|---|
| 64 | typedef struct tcpr_buildcidr_s tcpr_buildcidr_t; |
|---|
| 65 | |
|---|
| 66 | #define DNS_QUERY_FLAG 0x8000 |
|---|
| 67 | |
|---|
| 68 | void add_tree(const unsigned long, const u_char *); |
|---|
| 69 | void add_tree_first(const u_char *); |
|---|
| 70 | tcpr_dir_t check_ip_tree(const int, const unsigned long); |
|---|
| 71 | int process_tree(); |
|---|
| 72 | void tree_calculate(tcpr_data_tree_t *); |
|---|
| 73 | int tree_comp(tcpr_tree_t *, tcpr_tree_t *); |
|---|
| 74 | |
|---|
| 75 | #endif |
|---|
| 76 | |
|---|
| 77 | /* |
|---|
| 78 | Local Variables: |
|---|
| 79 | mode:c |
|---|
| 80 | indent-tabs-mode:nil |
|---|
| 81 | c-basic-offset:4 |
|---|
| 82 | End: |
|---|
| 83 | */ |
|---|
| 84 | |
|---|