00001 /* 00002 * $Id$ 00003 * 00004 * one-time nonce support 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_OT_NONCE - if not defined no one-time nonce specific code will be 00027 * compiled 00028 * OTN_CELL_T_LONG - uses unsigned long instead os unsigned int for the 00029 * array cells 00030 */ 00031 /* 00032 * History: 00033 * -------- 00034 * 2008-07-10 initial version (andrei) 00035 */ 00036 00037 00038 #ifndef _ot_nonce_h 00039 #define _ot_nonce_h 00040 00041 extern int otn_enabled; 00042 00043 /* instead of storing only the 2^k size we store also k 00044 * for faster operations */ 00045 extern unsigned otn_in_flight_k; /* maximum in-flight nonces (k in 2^k) */ 00046 extern unsigned otn_in_flight_no ; /* 2^k == 1<<otn_in_flight_no */ 00047 00048 #ifdef USE_OT_NONCE 00049 00050 #include "nid.h" /* nid_t */ 00051 #include "../../atomic_ops.h" 00052 00053 00054 /* default number of maximum in-flight nonces */ 00055 #define DEFAULT_OTN_IN_FLIGHT (1024*1024U) /* 1M nonces => 128k mem. */ 00056 #define MIN_OTN_IN_FLIGHT (128*1024U) /* warn if < then 128k nonces */ 00057 00058 #define MAX_OTN_IN_FLIGHT (2*1024*1024*1024U) /* warn if size > 250Mb */ 00059 00060 #define MIN_OTN_PARTITION 65536U /* warn if < 65k nonces per partition*/ 00061 00062 #ifdef OTN_CELL_T_LONG 00063 typedef unsigned long otn_cell_t; 00064 #else 00065 typedef unsigned int otn_cell_t; 00066 #endif 00067 00068 int init_ot_nonce(); 00069 void destroy_ot_nonce(); 00070 00071 00072 enum otn_check_ret{ 00073 OTN_OK=0, OTN_INV_POOL=-1, OTN_ID_OVERFLOW=-2, OTN_REPLAY=-3 00074 }; 00075 00076 /* check if nonce w/ index i is valid & expected and record receiving it */ 00077 enum otn_check_ret otn_check_id(nid_t i, unsigned pool); 00078 00079 /* re-init the stored nonce state for nonce id in pool pool_no */ 00080 nid_t otn_new(nid_t id, unsigned char pool_no); 00081 00082 #endif /* USE_OT_NONCE */ 00083 #endif /* _ot_nonce_h */ 00084
1.7.1