1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (C) 2007-2018 B.A.T.M.A.N. contributors: 3 * 4 * Marek Lindner, Simon Wunderlich 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of version 2 of the GNU General Public 8 * License as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef _NET_BATMAN_ADV_ORIGINATOR_H_ 20 #define _NET_BATMAN_ADV_ORIGINATOR_H_ 21 22 #include "main.h" 23 24 #include <linux/compiler.h> 25 #include <linux/if_ether.h> 26 #include <linux/jhash.h> 27 #include <linux/types.h> 28 29 struct netlink_callback; 30 struct seq_file; 31 struct sk_buff; 32 33 bool batadv_compare_orig(const struct hlist_node *node, const void *data2); 34 int batadv_originator_init(struct batadv_priv *bat_priv); 35 void batadv_originator_free(struct batadv_priv *bat_priv); 36 void batadv_purge_orig_ref(struct batadv_priv *bat_priv); 37 void batadv_orig_node_put(struct batadv_orig_node *orig_node); 38 struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv, 39 const u8 *addr); 40 struct batadv_hardif_neigh_node * 41 batadv_hardif_neigh_get(const struct batadv_hard_iface *hard_iface, 42 const u8 *neigh_addr); 43 void 44 batadv_hardif_neigh_put(struct batadv_hardif_neigh_node *hardif_neigh); 45 struct batadv_neigh_node * 46 batadv_neigh_node_get_or_create(struct batadv_orig_node *orig_node, 47 struct batadv_hard_iface *hard_iface, 48 const u8 *neigh_addr); 49 void batadv_neigh_node_put(struct batadv_neigh_node *neigh_node); 50 struct batadv_neigh_node * 51 batadv_orig_router_get(struct batadv_orig_node *orig_node, 52 const struct batadv_hard_iface *if_outgoing); 53 struct batadv_neigh_ifinfo * 54 batadv_neigh_ifinfo_new(struct batadv_neigh_node *neigh, 55 struct batadv_hard_iface *if_outgoing); 56 struct batadv_neigh_ifinfo * 57 batadv_neigh_ifinfo_get(struct batadv_neigh_node *neigh, 58 struct batadv_hard_iface *if_outgoing); 59 void batadv_neigh_ifinfo_put(struct batadv_neigh_ifinfo *neigh_ifinfo); 60 61 int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb); 62 int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset); 63 64 struct batadv_orig_ifinfo * 65 batadv_orig_ifinfo_get(struct batadv_orig_node *orig_node, 66 struct batadv_hard_iface *if_outgoing); 67 struct batadv_orig_ifinfo * 68 batadv_orig_ifinfo_new(struct batadv_orig_node *orig_node, 69 struct batadv_hard_iface *if_outgoing); 70 void batadv_orig_ifinfo_put(struct batadv_orig_ifinfo *orig_ifinfo); 71 72 int batadv_orig_seq_print_text(struct seq_file *seq, void *offset); 73 int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb); 74 int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset); 75 struct batadv_orig_node_vlan * 76 batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node, 77 unsigned short vid); 78 struct batadv_orig_node_vlan * 79 batadv_orig_node_vlan_get(struct batadv_orig_node *orig_node, 80 unsigned short vid); 81 void batadv_orig_node_vlan_put(struct batadv_orig_node_vlan *orig_vlan); 82 83 /** 84 * batadv_choose_orig() - Return the index of the orig entry in the hash table 85 * @data: mac address of the originator node 86 * @size: the size of the hash table 87 * 88 * Return: the hash index where the object represented by @data should be 89 * stored at. 90 */ 91 static inline u32 batadv_choose_orig(const void *data, u32 size) 92 { 93 u32 hash = 0; 94 95 hash = jhash(data, ETH_ALEN, hash); 96 return hash % size; 97 } 98 99 struct batadv_orig_node * 100 batadv_orig_hash_find(struct batadv_priv *bat_priv, const void *data); 101 102 #endif /* _NET_BATMAN_ADV_ORIGINATOR_H_ */ 103