Merge tag 'v3.10.69' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / batman-adv / originator.h
CommitLineData
0b873931 1/* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
c6c8fea2
SE
2 *
3 * Marek Lindner, Simon Wunderlich
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * 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., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA
c6c8fea2
SE
18 */
19
20#ifndef _NET_BATMAN_ADV_ORIGINATOR_H_
21#define _NET_BATMAN_ADV_ORIGINATOR_H_
22
7aadf889
ML
23#include "hash.h"
24
56303d34
SE
25int batadv_originator_init(struct batadv_priv *bat_priv);
26void batadv_originator_free(struct batadv_priv *bat_priv);
27void batadv_purge_orig_ref(struct batadv_priv *bat_priv);
28void batadv_orig_node_free_ref(struct batadv_orig_node *orig_node);
72822225 29void batadv_orig_node_free_ref_now(struct batadv_orig_node *orig_node);
56303d34
SE
30struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv,
31 const uint8_t *addr);
32struct batadv_neigh_node *
33batadv_neigh_node_new(struct batadv_hard_iface *hard_iface,
34 const uint8_t *neigh_addr, uint32_t seqno);
35void batadv_neigh_node_free_ref(struct batadv_neigh_node *neigh_node);
36struct batadv_neigh_node *
37batadv_orig_node_get_router(struct batadv_orig_node *orig_node);
7d211efc 38int batadv_orig_seq_print_text(struct seq_file *seq, void *offset);
56303d34
SE
39int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
40 int max_if_num);
41int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
42 int max_if_num);
c6c8fea2
SE
43
44
9cfc7bd6
SE
45/* hashfunction to choose an entry in a hash table of given size
46 * hash algorithm from http://en.wikipedia.org/wiki/Hash_table
47 */
da641193 48static inline uint32_t batadv_choose_orig(const void *data, uint32_t size)
c6c8fea2 49{
747e4221 50 const unsigned char *key = data;
c6c8fea2
SE
51 uint32_t hash = 0;
52 size_t i;
53
54 for (i = 0; i < 6; i++) {
55 hash += key[i];
56 hash += (hash << 10);
57 hash ^= (hash >> 6);
58 }
59
60 hash += (hash << 3);
61 hash ^= (hash >> 11);
62 hash += (hash << 15);
63
64 return hash % size;
65}
66
56303d34
SE
67static inline struct batadv_orig_node *
68batadv_orig_hash_find(struct batadv_priv *bat_priv, const void *data)
7aadf889 69{
5bf74e9c 70 struct batadv_hashtable *hash = bat_priv->orig_hash;
7aadf889 71 struct hlist_head *head;
56303d34 72 struct batadv_orig_node *orig_node, *orig_node_tmp = NULL;
7aadf889
ML
73 int index;
74
75 if (!hash)
76 return NULL;
77
da641193 78 index = batadv_choose_orig(data, hash->size);
7aadf889
ML
79 head = &hash->table[index];
80
81 rcu_read_lock();
b67bfe0d 82 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
1eda58bf 83 if (!batadv_compare_eth(orig_node, data))
7aadf889
ML
84 continue;
85
7b36e8ee
ML
86 if (!atomic_inc_not_zero(&orig_node->refcount))
87 continue;
88
7aadf889 89 orig_node_tmp = orig_node;
7aadf889
ML
90 break;
91 }
92 rcu_read_unlock();
93
94 return orig_node_tmp;
95}
96
c6c8fea2 97#endif /* _NET_BATMAN_ADV_ORIGINATOR_H_ */