Commit a04ccd59 authored by Martin Hundebøll's avatar Martin Hundebøll Committed by Marek Lindner

batman-adv: Move is_out_of_time() to main.h for general use

Both translation tables and network coding use timeouts to do house
keeping, so we might as well share the function used to compare a
timestamp+timeout with current time.

For readability and simplicity, the function is renamed to
has_timed_out() and uses time_is_before_jiffies() instead of
time_after().
Signed-off-by: default avatarMartin Hundebøll <martin@hundeboll.net>
Signed-off-by: default avatarMarek Lindner <lindner_marek@yahoo.de>
parent c51f9c09
...@@ -202,6 +202,17 @@ static inline int compare_eth(const void *data1, const void *data2) ...@@ -202,6 +202,17 @@ static inline int compare_eth(const void *data1, const void *data2)
return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
} }
/**
* has_timed_out - compares current time (jiffies) and timestamp + timeout
* @timestamp: base value to compare with (in jiffies)
* @timeout: added to base value before comparing (in milliseconds)
*
* Returns true if current time is after timestamp + timeout
*/
static inline bool has_timed_out(unsigned long timestamp, unsigned int timeout)
{
return time_is_before_jiffies(timestamp + msecs_to_jiffies(timeout));
}
#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
......
...@@ -108,14 +108,6 @@ static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv, ...@@ -108,14 +108,6 @@ static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv,
} }
static bool is_out_of_time(unsigned long starting_time, unsigned long timeout)
{
unsigned long deadline;
deadline = starting_time + msecs_to_jiffies(timeout);
return time_after(jiffies, deadline);
}
static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry) static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry)
{ {
if (atomic_dec_and_test(&tt_local_entry->common.refcount)) if (atomic_dec_and_test(&tt_local_entry->common.refcount))
...@@ -420,8 +412,8 @@ static void tt_local_purge(struct bat_priv *bat_priv) ...@@ -420,8 +412,8 @@ static void tt_local_purge(struct bat_priv *bat_priv)
if (tt_local_entry->common.flags & TT_CLIENT_PENDING) if (tt_local_entry->common.flags & TT_CLIENT_PENDING)
continue; continue;
if (!is_out_of_time(tt_local_entry->last_seen, if (!has_timed_out(tt_local_entry->last_seen,
TT_LOCAL_TIMEOUT * 1000)) TT_LOCAL_TIMEOUT * 1000))
continue; continue;
tt_local_set_pending(bat_priv, tt_local_entry, tt_local_set_pending(bat_priv, tt_local_entry,
...@@ -758,8 +750,8 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv) ...@@ -758,8 +750,8 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv)
common); common);
if (!(tt_global_entry->common.flags & TT_CLIENT_ROAM)) if (!(tt_global_entry->common.flags & TT_CLIENT_ROAM))
continue; continue;
if (!is_out_of_time(tt_global_entry->roam_at, if (!has_timed_out(tt_global_entry->roam_at,
TT_CLIENT_ROAM_TIMEOUT * 1000)) TT_CLIENT_ROAM_TIMEOUT * 1000))
continue; continue;
bat_dbg(DBG_TT, bat_priv, "Deleting global " bat_dbg(DBG_TT, bat_priv, "Deleting global "
...@@ -978,8 +970,8 @@ static void tt_req_purge(struct bat_priv *bat_priv) ...@@ -978,8 +970,8 @@ static void tt_req_purge(struct bat_priv *bat_priv)
spin_lock_bh(&bat_priv->tt_req_list_lock); spin_lock_bh(&bat_priv->tt_req_list_lock);
list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) { list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) {
if (is_out_of_time(node->issued_at, if (has_timed_out(node->issued_at,
TT_REQUEST_TIMEOUT * 1000)) { TT_REQUEST_TIMEOUT * 1000)) {
list_del(&node->list); list_del(&node->list);
kfree(node); kfree(node);
} }
...@@ -997,8 +989,8 @@ static struct tt_req_node *new_tt_req_node(struct bat_priv *bat_priv, ...@@ -997,8 +989,8 @@ static struct tt_req_node *new_tt_req_node(struct bat_priv *bat_priv,
spin_lock_bh(&bat_priv->tt_req_list_lock); spin_lock_bh(&bat_priv->tt_req_list_lock);
list_for_each_entry(tt_req_node_tmp, &bat_priv->tt_req_list, list) { list_for_each_entry(tt_req_node_tmp, &bat_priv->tt_req_list, list) {
if (compare_eth(tt_req_node_tmp, orig_node) && if (compare_eth(tt_req_node_tmp, orig_node) &&
!is_out_of_time(tt_req_node_tmp->issued_at, !has_timed_out(tt_req_node_tmp->issued_at,
TT_REQUEST_TIMEOUT * 1000)) TT_REQUEST_TIMEOUT * 1000))
goto unlock; goto unlock;
} }
...@@ -1591,8 +1583,8 @@ static void tt_roam_purge(struct bat_priv *bat_priv) ...@@ -1591,8 +1583,8 @@ static void tt_roam_purge(struct bat_priv *bat_priv)
spin_lock_bh(&bat_priv->tt_roam_list_lock); spin_lock_bh(&bat_priv->tt_roam_list_lock);
list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) { list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) {
if (!is_out_of_time(node->first_time, if (!has_timed_out(node->first_time,
ROAMING_MAX_TIME * 1000)) ROAMING_MAX_TIME * 1000))
continue; continue;
list_del(&node->list); list_del(&node->list);
...@@ -1619,8 +1611,8 @@ static bool tt_check_roam_count(struct bat_priv *bat_priv, ...@@ -1619,8 +1611,8 @@ static bool tt_check_roam_count(struct bat_priv *bat_priv,
if (!compare_eth(tt_roam_node->addr, client)) if (!compare_eth(tt_roam_node->addr, client))
continue; continue;
if (is_out_of_time(tt_roam_node->first_time, if (has_timed_out(tt_roam_node->first_time,
ROAMING_MAX_TIME * 1000)) ROAMING_MAX_TIME * 1000))
continue; continue;
if (!atomic_dec_not_zero(&tt_roam_node->counter)) if (!atomic_dec_not_zero(&tt_roam_node->counter))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment