00001 /* 00002 * $Id$ 00003 * 00004 * Copyright (C) 2006 iptelorg GmbH 00005 * 00006 * This file is part of ser, a free SIP server. 00007 * 00008 * ser 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 * For a license to use the ser software under conditions 00014 * other than those described here, or to purchase support for this 00015 * software, please contact iptel.org by e-mail at the following addresses: 00016 * info@iptel.org 00017 * 00018 * ser is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License 00024 * along with this program; if not, write to the Free Software 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00026 * 00027 */ 00028 00029 #ifndef _IM_HASH_H 00030 #define _IM_HASH_H 00031 00032 #include "../../ip_addr.h" 00033 #include "../../locking.h" 00034 00035 /* linked list of entries */ 00036 typedef struct im_entry { 00037 struct ip_addr ip; 00038 unsigned short port; 00039 str avp_val; 00040 unsigned int mark; 00041 00042 struct im_entry *next; 00043 } im_entry_t; 00044 00045 /* hash table for the entries */ 00046 typedef struct im_hash { 00047 im_entry_t **entries; 00048 00049 gen_lock_t read_lock; /* lock for reader_count variable */ 00050 gen_lock_t write_lock; /* lock for writer processes */ 00051 int reader_count; /* number of reader processes */ 00052 int writer_demand; /* writer processes set this flag */ 00053 } im_hash_t; 00054 00055 /* global variable for DB cache */ 00056 extern im_hash_t *IM_HASH; 00057 00058 /* parse ipv4 or ipv6 address 00059 */ 00060 int parse_ip(str *s, struct ip_addr *ip, unsigned short *port); 00061 00062 /* hash function for ipmatch hash table 00063 * in case of ipv4: 00064 * summarizes the 4 unsigned char values 00065 * in case of ipv6: 00066 * summarizes the 1st, 5th, 9th, and 13th unsigned char values 00067 */ 00068 unsigned int im_hash(struct ip_addr *ip); 00069 00070 /* init global IM_HASH structure */ 00071 int init_im_hash(void); 00072 00073 /* free memory allocated for the global cache */ 00074 void destroy_im_hash(void); 00075 00076 /* create a new impatch hash table */ 00077 im_entry_t **new_im_hash(void); 00078 00079 /* free the memory allocated for an ipmatch hash table, 00080 * and purge out entries 00081 */ 00082 void free_im_hash(im_entry_t **hash); 00083 00084 /* free the memory allocated for an ipmatch hash table, 00085 * but do not purge out entries 00086 */ 00087 void delete_im_hash(im_entry_t **hash); 00088 00089 /* create a new ipmatch entry and insert it into the hash table 00090 * return value 00091 * 0: success 00092 * -1: error 00093 */ 00094 int insert_im_hash(char *ip, char *avp_val, unsigned int mark, 00095 im_entry_t **hash); 00096 00097 #endif /* _IM_HASH_H */
1.7.1