00001 /* 00002 * $Id$ 00003 * 00004 * nonce-count (nc) tracking 00005 * 00006 * Copyright (C) 2008 iptelorg GmbH 00007 * 00008 * This file is part of ser, a free SIP server. 00009 * 00010 * ser is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version 00014 * 00015 * ser is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 */ 00024 /* 00025 * Defines: 00026 * USE_NC - if not defined no NC specific code will be compiled 00027 */ 00028 /* 00029 * History: 00030 * -------- 00031 * 2008-07-04 initial version (andrei) 00032 */ 00033 00034 00035 #ifndef _nc_h 00036 #define _nc_h 00037 00038 extern int nc_enabled; 00039 00040 /* instead of storing only the 2^k size we store also k 00041 * for faster operations */ 00042 extern unsigned nc_array_k; /* array size bits (k in 2^k) */ 00043 extern unsigned nc_array_size; /* 2^k == 1<<nc_array_bits */ 00044 00045 #ifdef USE_NC 00046 00047 #include "nid.h" /* nid_t */ 00048 #include "../../atomic_ops.h" 00049 00050 00051 /* default number of maximum in-flight nonces */ 00052 #define DEFAULT_NC_ARRAY_SIZE 1024*1024 /* uses 1Mb of memory */ 00053 #define MIN_NC_ARRAY_SIZE 102400 /* warn if size < 100k */ 00054 #define MAX_NC_ARRAY_SIZE 1024*1024*1024 /* warn if size > 1Gb */ 00055 00056 #define MIN_NC_ARRAY_PARTITION 65536 /* warn if a partition is < 65k */ 00057 00058 00059 typedef unsigned char nc_t; 00060 00061 int init_nonce_count(); 00062 void destroy_nonce_count(); 00063 00064 00065 enum nc_check_ret{ 00066 NC_OK=0, NC_INV_POOL=-1, NC_ID_OVERFLOW=-2, NC_TOO_BIG=-3, 00067 NC_REPLAY=-4 00068 }; 00069 00070 /* check if nonce-count nc w/ index i is expected/valid and record its 00071 * value */ 00072 enum nc_check_ret nc_check_val(nid_t i, unsigned pool, unsigned int nc); 00073 00074 /* re-init the stored nc for nonce id in pool pool_no */ 00075 nid_t nc_new(nid_t id, unsigned char pool_no); 00076 00077 #endif /* USE_NC */ 00078 #endif /* _nc_h */ 00079
1.7.1