modules_s/pike/ip_tree.h

00001 /* 
00002  * $Id$
00003  *
00004  *
00005  * Copyright (C) 2001-2003 FhG Fokus
00006  *
00007  * This file is part of ser, a free SIP server.
00008  *
00009  * ser is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version
00013  *
00014  * For a license to use the ser software under conditions
00015  * other than those described here, or to purchase support for this
00016  * software, please contact iptel.org by e-mail at the following addresses:
00017  *    info@iptel.org
00018  *
00019  * ser is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU General Public License 
00025  * along with this program; if not, write to the Free Software 
00026  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  *
00028  * History:
00029  * --------
00030  *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
00031  *              on darwin (andrei)
00032  *  2004-11-05  adaptiv init lock (bogdan)
00033  *  2005-06-02  flags added to ip_node structure (bogdan)
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