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 #ifndef _IP_TREE_H
00033 #define _IP_TREE_H
00034
00035
00036 #include <stdio.h>
00037 #include "../../locking.h"
00038 #include "timer.h"
00039
00040
00041 #define NEW_NODE (1<<0)
00042 #define RED_NODE (1<<1)
00043 #define NEWRED_NODE (1<<2)
00044 #define NO_UPDATE (1<<3)
00045
00046 #define MAX_IP_BRANCHES 256
00047
00048 #define PREV_POS 0
00049 #define CURR_POS 1
00050
00051
00052 #define NODE_EXPIRED_FLAG (1<<0)
00053 #define NODE_INTIMER_FLAG (1<<1)
00054 #define NODE_IPLEAF_FLAG (1<<2)
00055 #define NODE_ISRED_FLAG (1<<3)
00056
00057 struct ip_node
00058 {
00059 unsigned int expires;
00060 unsigned short leaf_hits[2];
00061 unsigned short hits[2];
00062 unsigned char byte;
00063 unsigned char branch;
00064 volatile unsigned short flags;
00065 struct list_link timer_ll;
00066 struct ip_node *prev;
00067 struct ip_node *next;
00068 struct ip_node *kids;
00069 };
00070
00071
00072 struct ip_tree
00073 {
00074 struct entry {
00075 struct ip_node *node;
00076 int lock_idx;
00077 } entries[MAX_IP_BRANCHES];
00078 unsigned short max_hits;
00079 gen_lock_set_t *entry_lock_set;
00080 };
00081
00082
00083 #define ll2ipnode(ptr) \
00084 ((struct ip_node*)((char *)(ptr)-\
00085 (unsigned long)(&((struct ip_node*)0)->timer_ll)))
00086
00087
00088 int init_ip_tree(int);
00089 void destroy_ip_tree(void);
00090 struct ip_node* mark_node( unsigned char *ip, int ip_len,
00091 struct ip_node **father, unsigned char *flag);
00092 void remove_node(struct ip_node *node);
00093 int is_node_hot_leaf(struct ip_node *node);
00094
00095 void lock_tree_branch(unsigned char b);
00096 void unlock_tree_branch(unsigned char b);
00097 struct ip_node* get_tree_branch(unsigned char b);
00098
00099
00100
00101 #endif