00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef _IP_TREE_H
00037 #define _IP_TREE_H
00038
00039
00040 #include <stdio.h>
00041 #include "../../locking.h"
00042 #include "timer.h"
00043
00044
00045 #define NEW_NODE (1<<0)
00046 #define RED_NODE (1<<1)
00047 #define NO_UPDATE (1<<2)
00048
00049 #define MAX_IP_BRANCHES 256
00050
00051 #define PREV_POS 0
00052 #define CURR_POS 1
00053
00054
00055 #define NODE_EXPIRED_FLAG (1<<0)
00056 #define NODE_INTIMER_FLAG (1<<1)
00057
00061 #define NODE_IPLEAF_FLAG (1<<2)
00062
00063 struct ip_node
00064 {
00065 unsigned int expires;
00066 unsigned int leaf_hits[2];
00067 unsigned int hits[2];
00068 unsigned char byte;
00069 unsigned char branch;
00070 volatile unsigned short flags;
00071 struct list_link timer_ll;
00072 struct ip_node *prev;
00073 struct ip_node *next;
00074 struct ip_node *kids;
00075 };
00076
00077 typedef enum {
00078 NODE_STATUS_OK = 0,
00079 NODE_STATUS_WARM = 1,
00080 NODE_STATUS_HOT = 2,
00081 NODE_STATUS_ALL = 3
00082 } node_status_t;
00083 node_status_t node_status(struct ip_node *node);
00084 extern char *node_status_array[];
00085
00086 struct ip_tree
00087 {
00088 struct entry {
00089 struct ip_node *node;
00090 int lock_idx;
00091 } entries[MAX_IP_BRANCHES];
00092 unsigned int max_hits;
00093 gen_lock_set_t *entry_lock_set;
00094 };
00095
00096
00097 #define ll2ipnode(ptr) \
00098 ((struct ip_node*)((char *)(ptr)-\
00099 (unsigned long)(&((struct ip_node*)0)->timer_ll)))
00100
00101
00102 int init_ip_tree(unsigned int);
00103 void destroy_ip_tree();
00104 unsigned int get_max_hits();
00105
00106 struct ip_node* mark_node( unsigned char *ip, int ip_len,
00107 struct ip_node **father, unsigned char *flag);
00108 void remove_node(struct ip_node *node);
00109
00110 void print_tree( FILE *f);
00111
00112 void lock_tree_branch(unsigned char b);
00113 void unlock_tree_branch(unsigned char b);
00114 struct ip_node* get_tree_branch(unsigned char b);
00115
00116
00117
00118 #endif