Lines Matching +full:packet +full:- +full:based
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2007-2020 B.A.T.M.A.N. contributors:
34 * batadv_tvlv_handler_release() - release tvlv handler from lists and queue for
47 * batadv_tvlv_handler_put() - decrement the tvlv container refcounter and
56 kref_put(&tvlv_handler->refcount, batadv_tvlv_handler_release); in batadv_tvlv_handler_put()
60 * batadv_tvlv_handler_get() - retrieve tvlv handler from the tvlv handler list
61 * based on the provided type and version (both need to match)
75 &bat_priv->tvlv.handler_list, list) { in batadv_tvlv_handler_get()
76 if (tvlv_handler_tmp->type != type) in batadv_tvlv_handler_get()
79 if (tvlv_handler_tmp->version != version) in batadv_tvlv_handler_get()
82 if (!kref_get_unless_zero(&tvlv_handler_tmp->refcount)) in batadv_tvlv_handler_get()
94 * batadv_tvlv_container_release() - release tvlv from lists and free
106 * batadv_tvlv_container_put() - decrement the tvlv container refcounter and
115 kref_put(&tvlv->refcount, batadv_tvlv_container_release); in batadv_tvlv_container_put()
119 * batadv_tvlv_container_get() - retrieve tvlv container from the tvlv container
120 * list based on the provided type and version (both need to match)
135 lockdep_assert_held(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_get()
137 hlist_for_each_entry(tvlv_tmp, &bat_priv->tvlv.container_list, list) { in batadv_tvlv_container_get()
138 if (tvlv_tmp->tvlv_hdr.type != type) in batadv_tvlv_container_get()
141 if (tvlv_tmp->tvlv_hdr.version != version) in batadv_tvlv_container_get()
144 kref_get(&tvlv_tmp->refcount); in batadv_tvlv_container_get()
153 * batadv_tvlv_container_list_size() - calculate the size of the tvlv container
167 lockdep_assert_held(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_list_size()
169 hlist_for_each_entry(tvlv, &bat_priv->tvlv.container_list, list) { in batadv_tvlv_container_list_size()
171 tvlv_len += ntohs(tvlv->tvlv_hdr.len); in batadv_tvlv_container_list_size()
178 * batadv_tvlv_container_remove() - remove tvlv container from the tvlv
189 lockdep_assert_held(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_remove()
194 hlist_del(&tvlv->list); in batadv_tvlv_container_remove()
202 * batadv_tvlv_container_unregister() - unregister tvlv container based on the
213 spin_lock_bh(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_unregister()
216 spin_unlock_bh(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_unregister()
220 * batadv_tvlv_container_register() - register tvlv type, version and content
244 tvlv_new->tvlv_hdr.version = version; in batadv_tvlv_container_register()
245 tvlv_new->tvlv_hdr.type = type; in batadv_tvlv_container_register()
246 tvlv_new->tvlv_hdr.len = htons(tvlv_value_len); in batadv_tvlv_container_register()
248 memcpy(tvlv_new + 1, tvlv_value, ntohs(tvlv_new->tvlv_hdr.len)); in batadv_tvlv_container_register()
249 INIT_HLIST_NODE(&tvlv_new->list); in batadv_tvlv_container_register()
250 kref_init(&tvlv_new->refcount); in batadv_tvlv_container_register()
252 spin_lock_bh(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_register()
256 kref_get(&tvlv_new->refcount); in batadv_tvlv_container_register()
257 hlist_add_head(&tvlv_new->list, &bat_priv->tvlv.container_list); in batadv_tvlv_container_register()
258 spin_unlock_bh(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_register()
265 * batadv_tvlv_realloc_packet_buff() - reallocate packet buffer to accommodate
266 * requested packet size
267 * @packet_buff: packet buffer
268 * @packet_buff_len: packet buffer size
269 * @min_packet_len: requested packet minimum size
270 * @additional_packet_len: requested additional packet size on top of minimum
273 * Return: true of the packet buffer could be changed to the requested size,
298 * batadv_tvlv_container_ogm_append() - append tvlv container content to given
299 * OGM packet buffer
301 * @packet_buff: ogm packet buffer
302 * @packet_buff_len: ogm packet buffer size including ogm header and tvlv
306 * The ogm packet might be enlarged or shrunk depending on the current size
307 * and the size of the to-be-appended tvlv containers.
321 spin_lock_bh(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_ogm_append()
335 hlist_for_each_entry(tvlv, &bat_priv->tvlv.container_list, list) { in batadv_tvlv_container_ogm_append()
337 tvlv_hdr->type = tvlv->tvlv_hdr.type; in batadv_tvlv_container_ogm_append()
338 tvlv_hdr->version = tvlv->tvlv_hdr.version; in batadv_tvlv_container_ogm_append()
339 tvlv_hdr->len = tvlv->tvlv_hdr.len; in batadv_tvlv_container_ogm_append()
341 memcpy(tvlv_value, tvlv + 1, ntohs(tvlv->tvlv_hdr.len)); in batadv_tvlv_container_ogm_append()
342 tvlv_value = (u8 *)tvlv_value + ntohs(tvlv->tvlv_hdr.len); in batadv_tvlv_container_ogm_append()
346 spin_unlock_bh(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_ogm_append()
351 * batadv_tvlv_call_handler() - parse the given tvlv buffer to call the
355 * @ogm_source: flag indicating whether the tvlv is an ogm or a unicast packet
356 * @orig_node: orig node emitting the ogm packet
357 * @src: source mac address of the unicast packet
358 * @dst: destination mac address of the unicast packet
376 if (!tvlv_handler->ogm_handler) in batadv_tvlv_call_handler()
382 tvlv_handler->ogm_handler(bat_priv, orig_node, in batadv_tvlv_call_handler()
385 tvlv_handler->flags |= BATADV_TVLV_HANDLER_OGM_CALLED; in batadv_tvlv_call_handler()
393 if (!tvlv_handler->unicast_handler) in batadv_tvlv_call_handler()
396 return tvlv_handler->unicast_handler(bat_priv, src, in batadv_tvlv_call_handler()
405 * batadv_tvlv_containers_process() - parse the given tvlv buffer to call the
408 * @ogm_source: flag indicating whether the tvlv is an ogm or a unicast packet
409 * @orig_node: orig node emitting the ogm packet
410 * @src: source mac address of the unicast packet
411 * @dst: destination mac address of the unicast packet
432 tvlv_value_cont_len = ntohs(tvlv_hdr->len); in batadv_tvlv_containers_process()
434 tvlv_value_len -= sizeof(*tvlv_hdr); in batadv_tvlv_containers_process()
440 tvlv_hdr->type, in batadv_tvlv_containers_process()
441 tvlv_hdr->version); in batadv_tvlv_containers_process()
450 tvlv_value_len -= tvlv_value_cont_len; in batadv_tvlv_containers_process()
458 &bat_priv->tvlv.handler_list, list) { in batadv_tvlv_containers_process()
459 if ((tvlv_handler->flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND) && in batadv_tvlv_containers_process()
460 !(tvlv_handler->flags & BATADV_TVLV_HANDLER_OGM_CALLED)) in batadv_tvlv_containers_process()
461 tvlv_handler->ogm_handler(bat_priv, orig_node, in batadv_tvlv_containers_process()
464 tvlv_handler->flags &= ~BATADV_TVLV_HANDLER_OGM_CALLED; in batadv_tvlv_containers_process()
472 * batadv_tvlv_ogm_receive() - process an incoming ogm and call the appropriate
475 * @batadv_ogm_packet: ogm packet containing the tvlv containers
476 * @orig_node: orig node emitting the ogm packet
488 tvlv_value_len = ntohs(batadv_ogm_packet->tvlv_len); in batadv_tvlv_ogm_receive()
499 * batadv_tvlv_handler_register() - register tvlv handler based on the provided
506 * source & destination of the unicast packet as well as the tvlv content
526 spin_lock_bh(&bat_priv->tvlv.handler_list_lock); in batadv_tvlv_handler_register()
530 spin_unlock_bh(&bat_priv->tvlv.handler_list_lock); in batadv_tvlv_handler_register()
537 spin_unlock_bh(&bat_priv->tvlv.handler_list_lock); in batadv_tvlv_handler_register()
541 tvlv_handler->ogm_handler = optr; in batadv_tvlv_handler_register()
542 tvlv_handler->unicast_handler = uptr; in batadv_tvlv_handler_register()
543 tvlv_handler->type = type; in batadv_tvlv_handler_register()
544 tvlv_handler->version = version; in batadv_tvlv_handler_register()
545 tvlv_handler->flags = flags; in batadv_tvlv_handler_register()
546 kref_init(&tvlv_handler->refcount); in batadv_tvlv_handler_register()
547 INIT_HLIST_NODE(&tvlv_handler->list); in batadv_tvlv_handler_register()
549 kref_get(&tvlv_handler->refcount); in batadv_tvlv_handler_register()
550 hlist_add_head_rcu(&tvlv_handler->list, &bat_priv->tvlv.handler_list); in batadv_tvlv_handler_register()
551 spin_unlock_bh(&bat_priv->tvlv.handler_list_lock); in batadv_tvlv_handler_register()
558 * batadv_tvlv_handler_unregister() - unregister tvlv handler based on the
574 spin_lock_bh(&bat_priv->tvlv.handler_list_lock); in batadv_tvlv_handler_unregister()
575 hlist_del_rcu(&tvlv_handler->list); in batadv_tvlv_handler_unregister()
576 spin_unlock_bh(&bat_priv->tvlv.handler_list_lock); in batadv_tvlv_handler_unregister()
581 * batadv_tvlv_unicast_send() - send a unicast packet with tvlv payload to the
584 * @src: source mac address of the unicast packet
585 * @dst: destination mac address of the unicast packet
613 skb->priority = TC_PRIO_CONTROL; in batadv_tvlv_unicast_send()
617 unicast_tvlv_packet->packet_type = BATADV_UNICAST_TVLV; in batadv_tvlv_unicast_send()
618 unicast_tvlv_packet->version = BATADV_COMPAT_VERSION; in batadv_tvlv_unicast_send()
619 unicast_tvlv_packet->ttl = BATADV_TTL; in batadv_tvlv_unicast_send()
620 unicast_tvlv_packet->reserved = 0; in batadv_tvlv_unicast_send()
621 unicast_tvlv_packet->tvlv_len = htons(tvlv_len); in batadv_tvlv_unicast_send()
622 unicast_tvlv_packet->align = 0; in batadv_tvlv_unicast_send()
623 ether_addr_copy(unicast_tvlv_packet->src, src); in batadv_tvlv_unicast_send()
624 ether_addr_copy(unicast_tvlv_packet->dst, dst); in batadv_tvlv_unicast_send()
628 tvlv_hdr->version = version; in batadv_tvlv_unicast_send()
629 tvlv_hdr->type = type; in batadv_tvlv_unicast_send()
630 tvlv_hdr->len = htons(tvlv_value_len); in batadv_tvlv_unicast_send()