ip_tree.h

Go to the documentation of this file.
00001 /* 
00002  * $Id: ip_tree.h 5003 2008-09-26 11:01:51Z henningw $
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  * History:
00023  * --------
00024  *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
00025  *              on darwin (andrei)
00026  *  2004-11-05  adaptiv init lock (bogdan)
00027  *  2005-06-02  flags added to ip_node structure (bogdan)
00028  *  2008-04-17  the leaf nodes memorize (via flags) if they are in RED state
00029  *               (detected) or not -> better logging and MI (bogdan)
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

Generated on Wed May 23 08:00:57 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6