• Home
  • Raw
  • Download

Lines Matching +full:pull +full:- +full:up +full:- +full:adv

1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2011-2018 B.A.T.M.A.N. contributors:
19 #include "distributed-arp-table.h"
53 #include "hard-interface.h"
59 #include "soft-interface.h"
60 #include "translation-table.h"
66 * batadv_dat_start_timer() - initialise the DAT periodic worker
71 INIT_DELAYED_WORK(&bat_priv->dat.work, batadv_dat_purge); in batadv_dat_start_timer()
72 queue_delayed_work(batadv_event_workqueue, &bat_priv->dat.work, in batadv_dat_start_timer()
77 * batadv_dat_entry_release() - release dat_entry from lists and queue for free
91 * batadv_dat_entry_put() - decrement the dat_entry refcounter and possibly
97 kref_put(&dat_entry->refcount, batadv_dat_entry_release); in batadv_dat_entry_put()
101 * batadv_dat_to_purge() - check whether a dat_entry has to be purged or not
108 return batadv_has_timed_out(dat_entry->last_update, in batadv_dat_to_purge()
113 * __batadv_dat_purge() - delete entries from the DAT local storage
132 if (!bat_priv->dat.hash) in __batadv_dat_purge()
135 for (i = 0; i < bat_priv->dat.hash->size; i++) { in __batadv_dat_purge()
136 head = &bat_priv->dat.hash->table[i]; in __batadv_dat_purge()
137 list_lock = &bat_priv->dat.hash->list_locks[i]; in __batadv_dat_purge()
148 hlist_del_rcu(&dat_entry->hash_entry); in __batadv_dat_purge()
156 * batadv_dat_purge() - periodic task that deletes old entries from the local
175 * batadv_compare_dat() - comparing function used in the local DAT hash table
190 * batadv_arp_hw_src() - extract the hw_src field from an ARP packet
200 addr = (u8 *)(skb->data + hdr_size); in batadv_arp_hw_src()
207 * batadv_arp_ip_src() - extract the ip_src field from an ARP packet
219 * batadv_arp_hw_dst() - extract the hw_dst field from an ARP packet
231 * batadv_arp_ip_dst() - extract the ip_dst field from an ARP packet
243 * batadv_hash_dat() - compute the hash value for an IP address
257 key = (const unsigned char *)&dat->ip; in batadv_hash_dat()
258 for (i = 0; i < sizeof(dat->ip); i++) { in batadv_hash_dat()
264 vid = htons(dat->vid); in batadv_hash_dat()
266 for (i = 0; i < sizeof(dat->vid); i++) { in batadv_hash_dat()
280 * batadv_dat_entry_hash_find() - look for a given dat_entry in the local hash
294 struct batadv_hashtable *hash = bat_priv->dat.hash; in batadv_dat_entry_hash_find()
303 index = batadv_hash_dat(&to_find, hash->size); in batadv_dat_entry_hash_find()
304 head = &hash->table[index]; in batadv_dat_entry_hash_find()
308 if (dat_entry->ip != ip) in batadv_dat_entry_hash_find()
311 if (!kref_get_unless_zero(&dat_entry->refcount)) in batadv_dat_entry_hash_find()
323 * batadv_dat_entry_add() - add a new dat entry or update it if already exists
338 if (!batadv_compare_eth(dat_entry->mac_addr, mac_addr)) in batadv_dat_entry_add()
339 ether_addr_copy(dat_entry->mac_addr, mac_addr); in batadv_dat_entry_add()
340 dat_entry->last_update = jiffies; in batadv_dat_entry_add()
343 &dat_entry->ip, dat_entry->mac_addr, in batadv_dat_entry_add()
352 dat_entry->ip = ip; in batadv_dat_entry_add()
353 dat_entry->vid = vid; in batadv_dat_entry_add()
354 ether_addr_copy(dat_entry->mac_addr, mac_addr); in batadv_dat_entry_add()
355 dat_entry->last_update = jiffies; in batadv_dat_entry_add()
356 kref_init(&dat_entry->refcount); in batadv_dat_entry_add()
358 kref_get(&dat_entry->refcount); in batadv_dat_entry_add()
359 hash_added = batadv_hash_add(bat_priv->dat.hash, batadv_compare_dat, in batadv_dat_entry_add()
361 &dat_entry->hash_entry); in batadv_dat_entry_add()
370 &dat_entry->ip, dat_entry->mac_addr, batadv_print_vid(vid)); in batadv_dat_entry_add()
380 * batadv_dbg_arp() - print a debug message containing all the ARP packet
401 "ARP MSG = [src: %pM-%pI4 dst: %pM-%pI4]\n", in batadv_dbg_arp()
408 unicast_4addr_packet = (struct batadv_unicast_4addr_packet *)skb->data; in batadv_dbg_arp()
410 switch (unicast_4addr_packet->u.packet_type) { in batadv_dbg_arp()
418 unicast_4addr_packet->src); in batadv_dbg_arp()
419 switch (unicast_4addr_packet->subtype) { in batadv_dbg_arp()
435 unicast_4addr_packet->u.packet_type); in batadv_dbg_arp()
440 orig_addr = bcast_pkt->orig; in batadv_dbg_arp()
448 unicast_4addr_packet->u.packet_type); in batadv_dbg_arp()
462 * batadv_is_orig_node_eligible() - check whether a node can be a DHT candidate
485 if (!test_bit(BATADV_ORIG_CAPA_HAS_DAT, &candidate->capabilities)) in batadv_is_orig_node_eligible()
507 batadv_compare_eth(candidate->orig, max_orig_node->orig)) in batadv_is_orig_node_eligible()
516 * batadv_choose_next_candidate() - select the next DHT candidate
520 * @ip_key: key to look up in the DHT
531 struct batadv_hashtable *hash = bat_priv->orig_hash; in batadv_choose_next_candidate()
543 for (i = 0; i < hash->size; i++) { in batadv_choose_next_candidate()
544 head = &hash->table[i]; in batadv_choose_next_candidate()
549 tmp_max = BATADV_DAT_ADDR_MAX - orig_node->dat_addr + in batadv_choose_next_candidate()
558 if (!kref_get_unless_zero(&orig_node->refcount)) in batadv_choose_next_candidate()
573 select, max_orig_node->orig, max_orig_node->dat_addr, in batadv_choose_next_candidate()
580 * batadv_dat_select_candidates() - select the nodes which the DHT message has
583 * @ip_dst: ipv4 to look up in the DHT
601 if (!bat_priv->orig_hash) in batadv_dat_select_candidates()
626 * batadv_dat_send_data() - send a payload to the selected candidates
702 * batadv_dat_tvlv_container_update() - update the dat tvlv container after dat
710 dat_mode = atomic_read(&bat_priv->distributed_arp_table); in batadv_dat_tvlv_container_update()
724 * batadv_dat_status_update() - update the dat tvlv container after dat
736 * batadv_dat_tvlv_ogm_handler_v1() - process incoming dat tvlv container
749 clear_bit(BATADV_ORIG_CAPA_HAS_DAT, &orig->capabilities); in batadv_dat_tvlv_ogm_handler_v1()
751 set_bit(BATADV_ORIG_CAPA_HAS_DAT, &orig->capabilities); in batadv_dat_tvlv_ogm_handler_v1()
755 * batadv_dat_hash_free() - free the local DAT hash table
760 if (!bat_priv->dat.hash) in batadv_dat_hash_free()
765 batadv_hash_destroy(bat_priv->dat.hash); in batadv_dat_hash_free()
767 bat_priv->dat.hash = NULL; in batadv_dat_hash_free()
771 * batadv_dat_init() - initialise the DAT internals
778 if (bat_priv->dat.hash) in batadv_dat_init()
781 bat_priv->dat.hash = batadv_hash_new(1024); in batadv_dat_init()
783 if (!bat_priv->dat.hash) in batadv_dat_init()
784 return -ENOMEM; in batadv_dat_init()
796 * batadv_dat_free() - free the DAT internals
804 cancel_delayed_work_sync(&bat_priv->dat.work); in batadv_dat_free()
811 * batadv_dat_cache_seq_print_text() - print the local DAT hash table
819 struct net_device *net_dev = (struct net_device *)seq->private; in batadv_dat_cache_seq_print_text()
821 struct batadv_hashtable *hash = bat_priv->dat.hash; in batadv_dat_cache_seq_print_text()
833 seq_printf(seq, "Distributed ARP Table (%s):\n", net_dev->name); in batadv_dat_cache_seq_print_text()
835 " IPv4 MAC VID last-seen\n"); in batadv_dat_cache_seq_print_text()
837 for (i = 0; i < hash->size; i++) { in batadv_dat_cache_seq_print_text()
838 head = &hash->table[i]; in batadv_dat_cache_seq_print_text()
842 last_seen_jiffies = jiffies - dat_entry->last_update; in batadv_dat_cache_seq_print_text()
849 &dat_entry->ip, dat_entry->mac_addr, in batadv_dat_cache_seq_print_text()
850 batadv_print_vid(dat_entry->vid), in batadv_dat_cache_seq_print_text()
864 * batadv_dat_cache_dump_entry() - dump one entry of the DAT cache table to a
883 return -ENOBUFS; in batadv_dat_cache_dump_entry()
885 msecs = jiffies_to_msecs(jiffies - dat_entry->last_update); in batadv_dat_cache_dump_entry()
888 dat_entry->ip) || in batadv_dat_cache_dump_entry()
890 dat_entry->mac_addr) || in batadv_dat_cache_dump_entry()
891 nla_put_u16(msg, BATADV_ATTR_DAT_CACHE_VID, dat_entry->vid) || in batadv_dat_cache_dump_entry()
894 return -EMSGSIZE; in batadv_dat_cache_dump_entry()
902 * batadv_dat_cache_dump_bucket() - dump one bucket of the DAT cache table to
929 return -EMSGSIZE; in batadv_dat_cache_dump_bucket()
941 * batadv_dat_cache_dump() - dump DAT cache table to a netlink socket
950 int portid = NETLINK_CB(cb->skb).portid; in batadv_dat_cache_dump()
951 struct net *net = sock_net(cb->skb->sk); in batadv_dat_cache_dump()
955 int bucket = cb->args[0]; in batadv_dat_cache_dump()
957 int idx = cb->args[1]; in batadv_dat_cache_dump()
961 ifindex = batadv_netlink_get_ifindex(cb->nlh, in batadv_dat_cache_dump()
964 return -EINVAL; in batadv_dat_cache_dump()
968 ret = -ENODEV; in batadv_dat_cache_dump()
973 hash = bat_priv->dat.hash; in batadv_dat_cache_dump()
976 if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) { in batadv_dat_cache_dump()
977 ret = -ENOENT; in batadv_dat_cache_dump()
981 while (bucket < hash->size) { in batadv_dat_cache_dump()
982 head = &hash->table[bucket]; in batadv_dat_cache_dump()
985 cb->nlh->nlmsg_seq, head, in batadv_dat_cache_dump()
993 cb->args[0] = bucket; in batadv_dat_cache_dump()
994 cb->args[1] = idx; in batadv_dat_cache_dump()
996 ret = msg->len; in batadv_dat_cache_dump()
1009 * batadv_arp_get_type() - parse an ARP packet and gets the type
1025 /* pull the ethernet header */ in batadv_arp_get_type()
1029 ethhdr = (struct ethhdr *)(skb->data + hdr_size); in batadv_arp_get_type()
1031 if (ethhdr->h_proto != htons(ETH_P_ARP)) in batadv_arp_get_type()
1034 /* pull the ARP payload */ in batadv_arp_get_type()
1036 arp_hdr_len(skb->dev)))) in batadv_arp_get_type()
1039 arphdr = (struct arphdr *)(skb->data + hdr_size + ETH_HLEN); in batadv_arp_get_type()
1042 if (arphdr->ar_hrd != htons(ARPHRD_ETHER)) in batadv_arp_get_type()
1045 if (arphdr->ar_pro != htons(ETH_P_IP)) in batadv_arp_get_type()
1048 if (arphdr->ar_hln != ETH_ALEN) in batadv_arp_get_type()
1051 if (arphdr->ar_pln != 4) in batadv_arp_get_type()
1070 if (arphdr->ar_op != htons(ARPOP_REQUEST)) { in batadv_arp_get_type()
1077 type = ntohs(arphdr->ar_op); in batadv_arp_get_type()
1083 * batadv_dat_get_vid() - extract the VLAN identifier from skb if any
1085 * @hdr_size: the size of the batman-adv header encapsulating the packet
1109 * batadv_dat_arp_create_reply() - create an ARP Reply
1129 skb = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_dst, bat_priv->soft_iface, in batadv_dat_arp_create_reply()
1144 * batadv_dat_snoop_outgoing_arp_request() - snoop the ARP request and try to
1162 struct net_device *soft_iface = bat_priv->soft_iface; in batadv_dat_snoop_outgoing_arp_request()
1166 if (!atomic_read(&bat_priv->distributed_arp_table)) in batadv_dat_snoop_outgoing_arp_request()
1192 * Moreover, if the soft-interface is enslaved into a bridge, an in batadv_dat_snoop_outgoing_arp_request()
1196 if (batadv_is_my_client(bat_priv, dat_entry->mac_addr, vid)) { in batadv_dat_snoop_outgoing_arp_request()
1207 dat_entry->mac_addr, vid)) { in batadv_dat_snoop_outgoing_arp_request()
1210 dat_entry->mac_addr); in batadv_dat_snoop_outgoing_arp_request()
1216 dat_entry->mac_addr, in batadv_dat_snoop_outgoing_arp_request()
1221 skb_new->protocol = eth_type_trans(skb_new, soft_iface); in batadv_dat_snoop_outgoing_arp_request()
1225 skb->len + ETH_HLEN + hdr_size); in batadv_dat_snoop_outgoing_arp_request()
1242 * batadv_dat_snoop_incoming_arp_request() - snoop the ARP request and try to
1262 if (!atomic_read(&bat_priv->distributed_arp_table)) in batadv_dat_snoop_incoming_arp_request()
1284 dat_entry->mac_addr, hw_src, vid); in batadv_dat_snoop_incoming_arp_request()
1312 * batadv_dat_snoop_outgoing_arp_reply() - snoop the ARP reply and fill the DHT
1325 if (!atomic_read(&bat_priv->distributed_arp_table)) in batadv_dat_snoop_outgoing_arp_reply()
1352 * batadv_dat_snoop_incoming_arp_reply() - snoop the ARP reply and fill the
1371 if (!atomic_read(&bat_priv->distributed_arp_table)) in batadv_dat_snoop_incoming_arp_reply()
1394 if (dat_entry && batadv_compare_eth(hw_src, dat_entry->mac_addr)) { in batadv_dat_snoop_incoming_arp_reply()
1395 … bat_priv, "Doubled ARP reply removed: ARP MSG = [src: %pM-%pI4 dst: %pM-%pI4]; dat_entry: %pM-%pI… in batadv_dat_snoop_incoming_arp_reply()
1397 dat_entry->mac_addr, &dat_entry->ip); in batadv_dat_snoop_incoming_arp_reply()
1438 /* if dropped == false -> deliver to the interface */ in batadv_dat_snoop_incoming_arp_reply()
1443 * batadv_dat_drop_broadcast_packet() - check if an ARP request has to be
1460 if (!atomic_read(&bat_priv->distributed_arp_table)) in batadv_dat_drop_broadcast_packet()
1469 vid = batadv_dat_get_vid(forw_packet->skb, &hdr_size); in batadv_dat_drop_broadcast_packet()
1471 type = batadv_arp_get_type(bat_priv, forw_packet->skb, hdr_size); in batadv_dat_drop_broadcast_packet()
1475 ip_dst = batadv_arp_ip_dst(forw_packet->skb, hdr_size); in batadv_dat_drop_broadcast_packet()