From bcae271764d18e570a5fca382eeea748add4af62 Mon Sep 17 00:00:00 2001 From: "/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org" Date: Sun, 20 Jan 2008 23:51:23 +0000 Subject: Based on patch from Max Kellermann : merge mod_alarm() into add_alarm(), remove alarm_set_expiration() --- ChangeLog | 1 + include/alarm.h | 11 +---------- src/alarm.c | 16 ++++------------ src/cache_timer.c | 5 ++--- src/sync-alarm.c | 17 +++++++---------- src/sync-ftfw.c | 6 ++---- 6 files changed, 17 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 815da0d..2dad662 100644 --- a/ChangeLog +++ b/ChangeLog @@ -88,6 +88,7 @@ o remove capability code and rely on the error returned by the syscall o major simplification of the logging infrastructure o use fputs() instead of fprintf() in log.c o improve error message if netlink initialization fails +o merge mod_alarm() into add_alarm(), remove alarm_set_expiration() version 0.9.5 (2007/07/29) ------------------------------ diff --git a/include/alarm.h b/include/alarm.h index 2f78885..f0bbb95 100644 --- a/include/alarm.h +++ b/include/alarm.h @@ -14,13 +14,6 @@ struct alarm_list { void (*function)(struct alarm_list *a, void *data); }; -static inline void -set_alarm_expiration(struct alarm_list *t, long tv_sec, long tv_usec) -{ - t->tv.tv_sec = tv_sec; - t->tv.tv_usec = tv_usec; -} - int init_alarm_hash(void); void destroy_alarm_hash(void); @@ -29,12 +22,10 @@ void init_alarm(struct alarm_list *t, void *data, void (*fcn)(struct alarm_list *a, void *data)); -void add_alarm(struct alarm_list *alarm); +void add_alarm(struct alarm_list *alarm, unsigned long sc, unsigned long usc); void del_alarm(struct alarm_list *alarm); -void mod_alarm(struct alarm_list *alarm, unsigned long sc, unsigned long usc); - int get_next_alarm_run(struct timeval *next_alarm); int do_alarm_run(struct timeval *next_alarm); diff --git a/src/alarm.c b/src/alarm.c index 13a790e..2190bb6 100644 --- a/src/alarm.c +++ b/src/alarm.c @@ -52,10 +52,13 @@ __add_alarm(struct alarm_list *alarm) list_add_tail(&alarm->head, &alarm_hash[i]); } -void add_alarm(struct alarm_list *alarm) +void add_alarm(struct alarm_list *alarm, unsigned long sc, unsigned long usc) { struct timeval tv; + del_alarm(alarm); + alarm->tv.tv_sec = sc; + alarm->tv.tv_usec = usc; gettimeofday(&tv, NULL); timeradd(&alarm->tv, &tv, &alarm->tv); __add_alarm(alarm); @@ -71,17 +74,6 @@ void del_alarm(struct alarm_list *alarm) } } -void mod_alarm(struct alarm_list *alarm, unsigned long sc, unsigned long usc) -{ - struct timeval tv; - - set_alarm_expiration(alarm, sc, usc); - gettimeofday(&tv, NULL); - timeradd(&alarm->tv, &tv, &alarm->tv); - list_del(&alarm->head); - __add_alarm(alarm); -} - static int calculate_next_run(struct timeval *cand, struct timeval *tv, diff --git a/src/cache_timer.c b/src/cache_timer.c index 0fbba14..86bb8fc 100644 --- a/src/cache_timer.c +++ b/src/cache_timer.c @@ -37,14 +37,13 @@ static void timer_add(struct us_conntrack *u, void *data) struct alarm_list *alarm = data; init_alarm(alarm, u, timeout); - set_alarm_expiration(alarm, CONFIG(cache_timeout), 0); - add_alarm(alarm); + add_alarm(alarm, CONFIG(cache_timeout), 0); } static void timer_update(struct us_conntrack *u, void *data) { struct alarm_list *alarm = data; - mod_alarm(alarm, CONFIG(cache_timeout), 0); + add_alarm(alarm, CONFIG(cache_timeout), 0); } static void timer_destroy(struct us_conntrack *u, void *data) diff --git a/src/sync-alarm.c b/src/sync-alarm.c index 9ab9d96..1f164b2 100644 --- a/src/sync-alarm.c +++ b/src/sync-alarm.c @@ -36,11 +36,9 @@ static void refresher(struct alarm_list *a, void *data) debug_ct(u->ct, "persistence update"); init_alarm(a, u, refresher); - set_alarm_expiration(a, - random() % CONFIG(refresh) + 1, - ((random() % 5 + 1) * 200000) - 1); - - add_alarm(a); + add_alarm(a, + random() % CONFIG(refresh) + 1, + ((random() % 5 + 1) * 200000) - 1); net = BUILD_NETMSG(u->ct, NFCT_Q_UPDATE); len = prepare_send_netmsg(STATE_SYNC(mcast_client), net); @@ -52,16 +50,15 @@ static void cache_alarm_add(struct us_conntrack *u, void *data) struct alarm_list *alarm = data; init_alarm(alarm, u, refresher); - set_alarm_expiration(alarm, - random() % CONFIG(refresh) + 1, - ((random() % 5 + 1) * 200000) - 1); - add_alarm(alarm); + add_alarm(alarm, + random() % CONFIG(refresh) + 1, + ((random() % 5 + 1) * 200000) - 1); } static void cache_alarm_update(struct us_conntrack *u, void *data) { struct alarm_list *alarm = data; - mod_alarm(alarm, random() % CONFIG(refresh) + 1, random() % 999999 + 1); + add_alarm(alarm, random() % CONFIG(refresh) + 1, random() % 999999 + 1); } static void cache_alarm_destroy(struct us_conntrack *u, void *data) diff --git a/src/sync-ftfw.c b/src/sync-ftfw.c index 004dd21..dc3bf44 100644 --- a/src/sync-ftfw.c +++ b/src/sync-ftfw.c @@ -90,8 +90,7 @@ static void do_alive_alarm(struct alarm_list *a, void *data) tx_queue_add_ctlmsg(NET_F_ALIVE, 0, 0); init_alarm(&alive_alarm, NULL, do_alive_alarm); - set_alarm_expiration(&alive_alarm, 1, 0); - add_alarm(&alive_alarm); + add_alarm(&alive_alarm, 1, 0); } static int ftfw_init(void) @@ -113,8 +112,7 @@ static int ftfw_init(void) /* XXX: alive message expiration configurable */ init_alarm(&alive_alarm, NULL, do_alive_alarm); - set_alarm_expiration(&alive_alarm, 1, 0); - add_alarm(&alive_alarm); + add_alarm(&alive_alarm, 1, 0); return 0; } -- cgit v1.2.3