10046b040SSven Eckelmann /* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: 2c6c8fea2SSven Eckelmann * 3c6c8fea2SSven Eckelmann * Marek Lindner, Simon Wunderlich 4c6c8fea2SSven Eckelmann * 5c6c8fea2SSven Eckelmann * This program is free software; you can redistribute it and/or 6c6c8fea2SSven Eckelmann * modify it under the terms of version 2 of the GNU General Public 7c6c8fea2SSven Eckelmann * License as published by the Free Software Foundation. 8c6c8fea2SSven Eckelmann * 9c6c8fea2SSven Eckelmann * This program is distributed in the hope that it will be useful, but 10c6c8fea2SSven Eckelmann * WITHOUT ANY WARRANTY; without even the implied warranty of 11c6c8fea2SSven Eckelmann * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12c6c8fea2SSven Eckelmann * General Public License for more details. 13c6c8fea2SSven Eckelmann * 14c6c8fea2SSven Eckelmann * You should have received a copy of the GNU General Public License 15ebf38fb7SAntonio Quartulli * along with this program; if not, see <http://www.gnu.org/licenses/>. 16c6c8fea2SSven Eckelmann */ 17c6c8fea2SSven Eckelmann 18c6c8fea2SSven Eckelmann #ifndef _NET_BATMAN_ADV_ORIGINATOR_H_ 19c6c8fea2SSven Eckelmann #define _NET_BATMAN_ADV_ORIGINATOR_H_ 20c6c8fea2SSven Eckelmann 211e2c2a4fSSven Eckelmann #include "main.h" 221e2c2a4fSSven Eckelmann 231e2c2a4fSSven Eckelmann #include <linux/compiler.h> 241e2c2a4fSSven Eckelmann #include <linux/if_ether.h> 251e2c2a4fSSven Eckelmann #include <linux/jhash.h> 267c124391SSven Eckelmann #include <linux/kref.h> 271e2c2a4fSSven Eckelmann #include <linux/rculist.h> 281e2c2a4fSSven Eckelmann #include <linux/rcupdate.h> 291e2c2a4fSSven Eckelmann #include <linux/stddef.h> 301e2c2a4fSSven Eckelmann #include <linux/types.h> 311e2c2a4fSSven Eckelmann 327aadf889SMarek Lindner #include "hash.h" 337aadf889SMarek Lindner 341e2c2a4fSSven Eckelmann struct seq_file; 351e2c2a4fSSven Eckelmann 36bbad0a5eSAntonio Quartulli int batadv_compare_orig(const struct hlist_node *node, const void *data2); 3756303d34SSven Eckelmann int batadv_originator_init(struct batadv_priv *bat_priv); 3856303d34SSven Eckelmann void batadv_originator_free(struct batadv_priv *bat_priv); 3956303d34SSven Eckelmann void batadv_purge_orig_ref(struct batadv_priv *bat_priv); 405d967310SSven Eckelmann void batadv_orig_node_put(struct batadv_orig_node *orig_node); 41bbad0a5eSAntonio Quartulli struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv, 426b5e971aSSven Eckelmann const u8 *addr); 43cef63419SMarek Lindner struct batadv_hardif_neigh_node * 44cef63419SMarek Lindner batadv_hardif_neigh_get(const struct batadv_hard_iface *hard_iface, 45cef63419SMarek Lindner const u8 *neigh_addr); 46cef63419SMarek Lindner void 47cef63419SMarek Lindner batadv_hardif_neigh_free_ref(struct batadv_hardif_neigh_node *hardif_neigh); 4856303d34SSven Eckelmann struct batadv_neigh_node * 493f32f8a6SMarek Lindner batadv_neigh_node_new(struct batadv_orig_node *orig_node, 503f32f8a6SMarek Lindner struct batadv_hard_iface *hard_iface, 513f32f8a6SMarek Lindner const u8 *neigh_addr); 5225bb2509SSven Eckelmann void batadv_neigh_node_put(struct batadv_neigh_node *neigh_node); 5356303d34SSven Eckelmann struct batadv_neigh_node * 547351a482SSimon Wunderlich batadv_orig_router_get(struct batadv_orig_node *orig_node, 557351a482SSimon Wunderlich const struct batadv_hard_iface *if_outgoing); 5689652331SSimon Wunderlich struct batadv_neigh_ifinfo * 5789652331SSimon Wunderlich batadv_neigh_ifinfo_new(struct batadv_neigh_node *neigh, 5889652331SSimon Wunderlich struct batadv_hard_iface *if_outgoing); 5989652331SSimon Wunderlich struct batadv_neigh_ifinfo * 6089652331SSimon Wunderlich batadv_neigh_ifinfo_get(struct batadv_neigh_node *neigh, 6189652331SSimon Wunderlich struct batadv_hard_iface *if_outgoing); 62*044fa3aeSSven Eckelmann void batadv_neigh_ifinfo_put(struct batadv_neigh_ifinfo *neigh_ifinfo); 637351a482SSimon Wunderlich 647587405aSMarek Lindner int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset); 657587405aSMarek Lindner 667351a482SSimon Wunderlich struct batadv_orig_ifinfo * 677351a482SSimon Wunderlich batadv_orig_ifinfo_get(struct batadv_orig_node *orig_node, 687351a482SSimon Wunderlich struct batadv_hard_iface *if_outgoing); 697351a482SSimon Wunderlich struct batadv_orig_ifinfo * 707351a482SSimon Wunderlich batadv_orig_ifinfo_new(struct batadv_orig_node *orig_node, 717351a482SSimon Wunderlich struct batadv_hard_iface *if_outgoing); 727351a482SSimon Wunderlich void batadv_orig_ifinfo_free_ref(struct batadv_orig_ifinfo *orig_ifinfo); 737351a482SSimon Wunderlich 747d211efcSSven Eckelmann int batadv_orig_seq_print_text(struct seq_file *seq, void *offset); 75cb1c92ecSSimon Wunderlich int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset); 7656303d34SSven Eckelmann int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface, 7756303d34SSven Eckelmann int max_if_num); 7856303d34SSven Eckelmann int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface, 7956303d34SSven Eckelmann int max_if_num); 807ea7b4a1SAntonio Quartulli struct batadv_orig_node_vlan * 817ea7b4a1SAntonio Quartulli batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node, 827ea7b4a1SAntonio Quartulli unsigned short vid); 837ea7b4a1SAntonio Quartulli struct batadv_orig_node_vlan * 847ea7b4a1SAntonio Quartulli batadv_orig_node_vlan_get(struct batadv_orig_node *orig_node, 857ea7b4a1SAntonio Quartulli unsigned short vid); 867ea7b4a1SAntonio Quartulli void batadv_orig_node_vlan_free_ref(struct batadv_orig_node_vlan *orig_vlan); 87c6c8fea2SSven Eckelmann 889cfc7bd6SSven Eckelmann /* hashfunction to choose an entry in a hash table of given size 899cfc7bd6SSven Eckelmann * hash algorithm from http://en.wikipedia.org/wiki/Hash_table 909cfc7bd6SSven Eckelmann */ 916b5e971aSSven Eckelmann static inline u32 batadv_choose_orig(const void *data, u32 size) 92c6c8fea2SSven Eckelmann { 936b5e971aSSven Eckelmann u32 hash = 0; 94c6c8fea2SSven Eckelmann 9536fd61cbSSven Eckelmann hash = jhash(data, ETH_ALEN, hash); 96c6c8fea2SSven Eckelmann return hash % size; 97c6c8fea2SSven Eckelmann } 98c6c8fea2SSven Eckelmann 9956303d34SSven Eckelmann static inline struct batadv_orig_node * 10056303d34SSven Eckelmann batadv_orig_hash_find(struct batadv_priv *bat_priv, const void *data) 1017aadf889SMarek Lindner { 1025bf74e9cSSven Eckelmann struct batadv_hashtable *hash = bat_priv->orig_hash; 1037aadf889SMarek Lindner struct hlist_head *head; 10456303d34SSven Eckelmann struct batadv_orig_node *orig_node, *orig_node_tmp = NULL; 1057aadf889SMarek Lindner int index; 1067aadf889SMarek Lindner 1077aadf889SMarek Lindner if (!hash) 1087aadf889SMarek Lindner return NULL; 1097aadf889SMarek Lindner 110da641193SSven Eckelmann index = batadv_choose_orig(data, hash->size); 1117aadf889SMarek Lindner head = &hash->table[index]; 1127aadf889SMarek Lindner 1137aadf889SMarek Lindner rcu_read_lock(); 114b67bfe0dSSasha Levin hlist_for_each_entry_rcu(orig_node, head, hash_entry) { 1151eda58bfSSven Eckelmann if (!batadv_compare_eth(orig_node, data)) 1167aadf889SMarek Lindner continue; 1177aadf889SMarek Lindner 1187c124391SSven Eckelmann if (!kref_get_unless_zero(&orig_node->refcount)) 1197b36e8eeSMarek Lindner continue; 1207b36e8eeSMarek Lindner 1217aadf889SMarek Lindner orig_node_tmp = orig_node; 1227aadf889SMarek Lindner break; 1237aadf889SMarek Lindner } 1247aadf889SMarek Lindner rcu_read_unlock(); 1257aadf889SMarek Lindner 1267aadf889SMarek Lindner return orig_node_tmp; 1277aadf889SMarek Lindner } 1287aadf889SMarek Lindner 129c6c8fea2SSven Eckelmann #endif /* _NET_BATMAN_ADV_ORIGINATOR_H_ */ 130