Commit 5fbc1598 authored by Antonio Quartulli's avatar Antonio Quartulli Committed by Marek Lindner

batman-adv: unify flags for tt_change/tt_local_entry/tt_global_entry

The tt_local_entry structure now has a 'flags' field. This helps to
unify the flags format to all the client related structures (tt_global_entry
and tt_change). The 'never_purge' field is now encoded in the 'flags' one.
To optimise the usage of this field, its length has been increased to 16bit
in order to use the eight leading bits (from 0 to 7) to store flags that
have to be sent on the wire, while the eight ending ones are used for local
computation only.

Moreover 'enum tt_change_flags' is now called 'enum tt_client_flags' and the
defined values apply to the tt_local_entry, tt_global_entry and the tt_change
'flags' field.
Signed-off-by: default avatarAntonio Quartulli <ordex@autistici.org>
Signed-off-by: default avatarMarek Lindner <lindner_marek@yahoo.de>
parent 43676ab5
...@@ -78,10 +78,13 @@ enum tt_query_flags { ...@@ -78,10 +78,13 @@ enum tt_query_flags {
TT_FULL_TABLE = 1 << 2 TT_FULL_TABLE = 1 << 2
}; };
/* TT_CHANGE flags */ /* TT_CLIENT flags.
enum tt_change_flags { * Flags from 1 to 1 << 7 are sent on the wire, while flags from 1 << 8 to
TT_CHANGE_DEL = 0x01, * 1 << 15 are used for local computation only */
TT_CLIENT_ROAM = 0x02 enum tt_client_flags {
TT_CLIENT_DEL = 1 << 0,
TT_CLIENT_ROAM = 1 << 1,
TT_CLIENT_NOPURGE = 1 << 8
}; };
struct batman_packet { struct batman_packet {
......
...@@ -211,13 +211,12 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr) ...@@ -211,13 +211,12 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr)
memcpy(tt_local_entry->addr, addr, ETH_ALEN); memcpy(tt_local_entry->addr, addr, ETH_ALEN);
tt_local_entry->last_seen = jiffies; tt_local_entry->last_seen = jiffies;
tt_local_entry->flags = NO_FLAGS;
atomic_set(&tt_local_entry->refcount, 2); atomic_set(&tt_local_entry->refcount, 2);
/* the batman interface mac address should never be purged */ /* the batman interface mac address should never be purged */
if (compare_eth(addr, soft_iface->dev_addr)) if (compare_eth(addr, soft_iface->dev_addr))
tt_local_entry->never_purge = 1; tt_local_entry->flags |= TT_CLIENT_NOPURGE;
else
tt_local_entry->never_purge = 0;
hash_add(bat_priv->tt_local_hash, compare_ltt, choose_orig, hash_add(bat_priv->tt_local_hash, compare_ltt, choose_orig,
tt_local_entry, &tt_local_entry->hash_entry); tt_local_entry, &tt_local_entry->hash_entry);
...@@ -387,7 +386,7 @@ void tt_local_remove(struct bat_priv *bat_priv, const uint8_t *addr, ...@@ -387,7 +386,7 @@ void tt_local_remove(struct bat_priv *bat_priv, const uint8_t *addr,
if (!tt_local_entry) if (!tt_local_entry)
goto out; goto out;
tt_local_event(bat_priv, TT_CHANGE_DEL, tt_local_entry->addr, roaming); tt_local_event(bat_priv, TT_CLIENT_DEL, tt_local_entry->addr, roaming);
tt_local_del(bat_priv, tt_local_entry, message); tt_local_del(bat_priv, tt_local_entry, message);
out: out:
if (tt_local_entry) if (tt_local_entry)
...@@ -410,14 +409,14 @@ static void tt_local_purge(struct bat_priv *bat_priv) ...@@ -410,14 +409,14 @@ static void tt_local_purge(struct bat_priv *bat_priv)
spin_lock_bh(list_lock); spin_lock_bh(list_lock);
hlist_for_each_entry_safe(tt_local_entry, node, node_tmp, hlist_for_each_entry_safe(tt_local_entry, node, node_tmp,
head, hash_entry) { head, hash_entry) {
if (tt_local_entry->never_purge) if (tt_local_entry->flags & TT_CLIENT_NOPURGE)
continue; continue;
if (!is_out_of_time(tt_local_entry->last_seen, if (!is_out_of_time(tt_local_entry->last_seen,
TT_LOCAL_TIMEOUT * 1000)) TT_LOCAL_TIMEOUT * 1000))
continue; continue;
tt_local_event(bat_priv, TT_CHANGE_DEL, tt_local_event(bat_priv, TT_CLIENT_DEL,
tt_local_entry->addr, false); tt_local_entry->addr, false);
atomic_dec(&bat_priv->num_local_tt); atomic_dec(&bat_priv->num_local_tt);
bat_dbg(DBG_TT, bat_priv, "Deleting local " bat_dbg(DBG_TT, bat_priv, "Deleting local "
...@@ -1335,7 +1334,7 @@ static void _tt_update_changes(struct bat_priv *bat_priv, ...@@ -1335,7 +1334,7 @@ static void _tt_update_changes(struct bat_priv *bat_priv,
int i; int i;
for (i = 0; i < tt_num_changes; i++) { for (i = 0; i < tt_num_changes; i++) {
if ((tt_change + i)->flags & TT_CHANGE_DEL) if ((tt_change + i)->flags & TT_CLIENT_DEL)
tt_global_del(bat_priv, orig_node, tt_global_del(bat_priv, orig_node,
(tt_change + i)->addr, (tt_change + i)->addr,
"tt removed by changes", "tt removed by changes",
......
...@@ -30,8 +30,7 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr); ...@@ -30,8 +30,7 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr);
void tt_local_remove(struct bat_priv *bat_priv, void tt_local_remove(struct bat_priv *bat_priv,
const uint8_t *addr, const char *message, bool roaming); const uint8_t *addr, const char *message, bool roaming);
int tt_local_seq_print_text(struct seq_file *seq, void *offset); int tt_local_seq_print_text(struct seq_file *seq, void *offset);
void tt_global_add_orig(struct bat_priv *bat_priv, void tt_global_add_orig(struct bat_priv *bat_priv, struct orig_node *orig_node,
struct orig_node *orig_node,
const unsigned char *tt_buff, int tt_buff_len); const unsigned char *tt_buff, int tt_buff_len);
int tt_global_add(struct bat_priv *bat_priv, int tt_global_add(struct bat_priv *bat_priv,
struct orig_node *orig_node, const unsigned char *addr, struct orig_node *orig_node, const unsigned char *addr,
......
...@@ -224,7 +224,7 @@ struct socket_packet { ...@@ -224,7 +224,7 @@ struct socket_packet {
struct tt_local_entry { struct tt_local_entry {
uint8_t addr[ETH_ALEN]; uint8_t addr[ETH_ALEN];
unsigned long last_seen; unsigned long last_seen;
char never_purge; uint16_t flags;
atomic_t refcount; atomic_t refcount;
struct rcu_head rcu; struct rcu_head rcu;
struct hlist_node hash_entry; struct hlist_node hash_entry;
...@@ -234,7 +234,7 @@ struct tt_global_entry { ...@@ -234,7 +234,7 @@ struct tt_global_entry {
uint8_t addr[ETH_ALEN]; uint8_t addr[ETH_ALEN];
struct orig_node *orig_node; struct orig_node *orig_node;
uint8_t ttvn; uint8_t ttvn;
uint8_t flags; /* only TT_GLOBAL_ROAM is used */ uint16_t flags; /* only TT_GLOBAL_ROAM is used */
unsigned long roam_at; /* time at which TT_GLOBAL_ROAM was set */ unsigned long roam_at; /* time at which TT_GLOBAL_ROAM was set */
atomic_t refcount; atomic_t refcount;
struct rcu_head rcu; struct rcu_head rcu;
......
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