1/* 2 * (C) 2006 by Pablo Neira Ayuso <pablo@netfilter.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 */ 18 19#include "cache.h" 20#include "conntrackd.h" 21#include "alarm.h" 22 23#include <stdio.h> 24 25static void timeout(struct alarm_block *a, void *data) 26{ 27 struct cache_object *obj = data; 28 29 cache_del(obj->cache, obj); 30 cache_object_free(obj); 31} 32 33static void timer_add(struct cache_object *obj, void *data) 34{ 35 struct alarm_block *a = data; 36 37 init_alarm(a, obj, timeout); 38 add_alarm(a, CONFIG(cache_timeout), 0); 39} 40 41static void timer_update(struct cache_object *obj, void *data) 42{ 43 struct alarm_block *a = data; 44 add_alarm(a, CONFIG(cache_timeout), 0); 45} 46 47static void timer_destroy(struct cache_object *obj, void *data) 48{ 49 struct alarm_block *a = data; 50 del_alarm(a); 51} 52 53static int timer_dump(struct cache_object *obj, void *data, char *buf, int type) 54{ 55 struct timeval tv, tmp; 56 struct alarm_block *a = data; 57 58 if (type == NFCT_O_XML) 59 return 0; 60 61 if (!alarm_pending(a)) 62 return 0; 63 64 gettimeofday(&tv, NULL); 65 timersub(&a->tv, &tv, &tmp); 66 return sprintf(buf, " [expires in %lds]", tmp.tv_sec); 67} 68 69struct cache_feature timer_feature = { 70 .size = sizeof(struct alarm_block), 71 .add = timer_add, 72 .update = timer_update, 73 .destroy = timer_destroy, 74 .dump = timer_dump 75}; 76