From f6281d498c0bfde2b1b8e4c041803aa138a1c9e1 Mon Sep 17 00:00:00 2001 From: Jan Rafaj Date: Mon, 12 Oct 2009 00:01:29 +0200 Subject: [PATCH] pknock: use kernel's get_seconds() directly instead of wrapper Use kernel's get_seconds() directly instead of the get_epoch_minute() wrapper. Signed-off-by: Jan Rafaj --- extensions/pknock/xt_pknock.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/extensions/pknock/xt_pknock.c b/extensions/pknock/xt_pknock.c index 090b0ab..f9a9ade 100644 --- a/extensions/pknock/xt_pknock.c +++ b/extensions/pknock/xt_pknock.c @@ -43,7 +43,7 @@ enum status { }; /** - * @login_min: the login epoch minute + * @login_sec: seconds at login since the epoch */ struct peer { struct list_head head; @@ -52,7 +52,7 @@ struct peer { uint32_t accepted_knock_count; enum status status; unsigned long timestamp; - int login_min; + unsigned long login_sec; }; /** @@ -148,14 +148,6 @@ pknock_hash(const void *key, uint32_t len, uint32_t initval, uint32_t max) return jhash(key, len, initval) % max; } -/** - * @return: the epoch minute - */ -static inline unsigned int get_epoch_minute(void) -{ - return get_seconds() / 60; -} - /** * Alloc a hashtable with n buckets. * @@ -341,7 +333,7 @@ is_time_exceeded(const struct peer *peer, unsigned int max_time) static inline bool has_logged_during_this_minute(const struct peer *peer) { - return peer != NULL && peer->login_min == get_epoch_minute(); + return peer != NULL && peer->login_sec / 60 == get_seconds() / 60; } /** @@ -578,7 +570,7 @@ static struct peer *new_peer(__be32 ip, uint8_t proto) peer->ip = ip; peer->proto = proto; peer->timestamp = jiffies/HZ; - peer->login_min = 0; + peer->login_sec = 0; reset_knock_status(peer); return peer; @@ -753,7 +745,7 @@ has_secret(const unsigned char *secret, unsigned int secret_len, uint32_t ipsrc, memset(result, 0, sizeof(result)); memset(hexresult, 0, hexa_size); - epoch_min = get_epoch_minute(); + epoch_min = get_seconds() / 60; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) sg_init_table(sg, ARRAY_SIZE(sg)); @@ -867,11 +859,11 @@ update_peer(struct peer *peer, const struct xt_pknock_mtinfo *info, peer->status = ST_ALLOWED; pk_debug("ALLOWED", peer); + peer->login_sec = get_seconds(); if (nl_multicast_group > 0) msg_to_userspace_nl(info, peer, nl_multicast_group); - peer->login_min = get_epoch_minute(); return true; }