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
53 kref_put(&tvlv_handler->refcount, batadv_tvlv_handler_release); in batadv_tvlv_handler_put()
57 * batadv_tvlv_handler_get() - retrieve tvlv handler from the tvlv handler list
58 * based on the provided type and version (both need to match)
72 &bat_priv->tvlv.handler_list, list) { in batadv_tvlv_handler_get()
73 if (tvlv_handler_tmp->type != type) in batadv_tvlv_handler_get()
76 if (tvlv_handler_tmp->version != version) in batadv_tvlv_handler_get()
79 if (!kref_get_unless_zero(&tvlv_handler_tmp->refcount)) in batadv_tvlv_handler_get()
91 * batadv_tvlv_container_release() - release tvlv from lists and free
103 * batadv_tvlv_container_put() - decrement the tvlv container refcounter and
109 kref_put(&tvlv->refcount, batadv_tvlv_container_release); in batadv_tvlv_container_put()
113 * batadv_tvlv_container_get() - retrieve tvlv container from the tvlv container
114 * list based on the provided type and version (both need to match)
129 lockdep_assert_held(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_get()
131 hlist_for_each_entry(tvlv_tmp, &bat_priv->tvlv.container_list, list) { in batadv_tvlv_container_get()
132 if (tvlv_tmp->tvlv_hdr.type != type) in batadv_tvlv_container_get()
135 if (tvlv_tmp->tvlv_hdr.version != version) in batadv_tvlv_container_get()
138 kref_get(&tvlv_tmp->refcount); in batadv_tvlv_container_get()
147 * batadv_tvlv_container_list_size() - calculate the size of the tvlv container
161 lockdep_assert_held(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_list_size()
163 hlist_for_each_entry(tvlv, &bat_priv->tvlv.container_list, list) { in batadv_tvlv_container_list_size()
165 tvlv_len += ntohs(tvlv->tvlv_hdr.len); in batadv_tvlv_container_list_size()
172 * batadv_tvlv_container_remove() - remove tvlv container from the tvlv
183 lockdep_assert_held(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_remove()
188 hlist_del(&tvlv->list); in batadv_tvlv_container_remove()
196 * batadv_tvlv_container_unregister() - unregister tvlv container based on the
207 spin_lock_bh(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_unregister()
210 spin_unlock_bh(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_unregister()
214 * batadv_tvlv_container_register() - register tvlv type, version and content
238 tvlv_new->tvlv_hdr.version = version; in batadv_tvlv_container_register()
239 tvlv_new->tvlv_hdr.type = type; in batadv_tvlv_container_register()
240 tvlv_new->tvlv_hdr.len = htons(tvlv_value_len); in batadv_tvlv_container_register()
242 memcpy(tvlv_new + 1, tvlv_value, ntohs(tvlv_new->tvlv_hdr.len)); in batadv_tvlv_container_register()
243 INIT_HLIST_NODE(&tvlv_new->list); in batadv_tvlv_container_register()
244 kref_init(&tvlv_new->refcount); in batadv_tvlv_container_register()
246 spin_lock_bh(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_register()
250 kref_get(&tvlv_new->refcount); in batadv_tvlv_container_register()
251 hlist_add_head(&tvlv_new->list, &bat_priv->tvlv.container_list); in batadv_tvlv_container_register()
252 spin_unlock_bh(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_register()
259 * batadv_tvlv_realloc_packet_buff() - reallocate packet buffer to accommodate
260 * requested packet size
261 * @packet_buff: packet buffer
262 * @packet_buff_len: packet buffer size
263 * @min_packet_len: requested packet minimum size
264 * @additional_packet_len: requested additional packet size on top of minimum
267 * Return: true of the packet buffer could be changed to the requested size,
292 * batadv_tvlv_container_ogm_append() - append tvlv container content to given
293 * OGM packet buffer
295 * @packet_buff: ogm packet buffer
296 * @packet_buff_len: ogm packet buffer size including ogm header and tvlv
300 * The ogm packet might be enlarged or shrunk depending on the current size
301 * and the size of the to-be-appended tvlv containers.
315 spin_lock_bh(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_ogm_append()
329 hlist_for_each_entry(tvlv, &bat_priv->tvlv.container_list, list) { in batadv_tvlv_container_ogm_append()
331 tvlv_hdr->type = tvlv->tvlv_hdr.type; in batadv_tvlv_container_ogm_append()
332 tvlv_hdr->version = tvlv->tvlv_hdr.version; in batadv_tvlv_container_ogm_append()
333 tvlv_hdr->len = tvlv->tvlv_hdr.len; in batadv_tvlv_container_ogm_append()
335 memcpy(tvlv_value, tvlv + 1, ntohs(tvlv->tvlv_hdr.len)); in batadv_tvlv_container_ogm_append()
336 tvlv_value = (u8 *)tvlv_value + ntohs(tvlv->tvlv_hdr.len); in batadv_tvlv_container_ogm_append()
340 spin_unlock_bh(&bat_priv->tvlv.container_list_lock); in batadv_tvlv_container_ogm_append()
345 * batadv_tvlv_call_handler() - parse the given tvlv buffer to call the
349 * @ogm_source: flag indicating whether the tvlv is an ogm or a unicast packet
350 * @orig_node: orig node emitting the ogm packet
351 * @src: source mac address of the unicast packet
352 * @dst: destination mac address of the unicast packet
370 if (!tvlv_handler->ogm_handler) in batadv_tvlv_call_handler()
376 tvlv_handler->ogm_handler(bat_priv, orig_node, in batadv_tvlv_call_handler()
379 tvlv_handler->flags |= BATADV_TVLV_HANDLER_OGM_CALLED; in batadv_tvlv_call_handler()
387 if (!tvlv_handler->unicast_handler) in batadv_tvlv_call_handler()
390 return tvlv_handler->unicast_handler(bat_priv, src, in batadv_tvlv_call_handler()
399 * batadv_tvlv_containers_process() - parse the given tvlv buffer to call the
402 * @ogm_source: flag indicating whether the tvlv is an ogm or a unicast packet
403 * @orig_node: orig node emitting the ogm packet
404 * @src: source mac address of the unicast packet
405 * @dst: destination mac address of the unicast packet
426 tvlv_value_cont_len = ntohs(tvlv_hdr->len); in batadv_tvlv_containers_process()
428 tvlv_value_len -= sizeof(*tvlv_hdr); in batadv_tvlv_containers_process()
434 tvlv_hdr->type, in batadv_tvlv_containers_process()
435 tvlv_hdr->version); in batadv_tvlv_containers_process()
444 tvlv_value_len -= tvlv_value_cont_len; in batadv_tvlv_containers_process()
452 &bat_priv->tvlv.handler_list, list) { in batadv_tvlv_containers_process()
453 if ((tvlv_handler->flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND) && in batadv_tvlv_containers_process()
454 !(tvlv_handler->flags & BATADV_TVLV_HANDLER_OGM_CALLED)) in batadv_tvlv_containers_process()
455 tvlv_handler->ogm_handler(bat_priv, orig_node, in batadv_tvlv_containers_process()
458 tvlv_handler->flags &= ~BATADV_TVLV_HANDLER_OGM_CALLED; in batadv_tvlv_containers_process()
466 * batadv_tvlv_ogm_receive() - process an incoming ogm and call the appropriate
469 * @batadv_ogm_packet: ogm packet containing the tvlv containers
470 * @orig_node: orig node emitting the ogm packet
482 tvlv_value_len = ntohs(batadv_ogm_packet->tvlv_len); in batadv_tvlv_ogm_receive()
493 * batadv_tvlv_handler_register() - register tvlv handler based on the provided
500 * source & destination of the unicast packet as well as the tvlv content
520 spin_lock_bh(&bat_priv->tvlv.handler_list_lock); in batadv_tvlv_handler_register()
524 spin_unlock_bh(&bat_priv->tvlv.handler_list_lock); in batadv_tvlv_handler_register()
531 spin_unlock_bh(&bat_priv->tvlv.handler_list_lock); in batadv_tvlv_handler_register()
535 tvlv_handler->ogm_handler = optr; in batadv_tvlv_handler_register()
536 tvlv_handler->unicast_handler = uptr; in batadv_tvlv_handler_register()
537 tvlv_handler->type = type; in batadv_tvlv_handler_register()
538 tvlv_handler->version = version; in batadv_tvlv_handler_register()
539 tvlv_handler->flags = flags; in batadv_tvlv_handler_register()
540 kref_init(&tvlv_handler->refcount); in batadv_tvlv_handler_register()
541 INIT_HLIST_NODE(&tvlv_handler->list); in batadv_tvlv_handler_register()
543 kref_get(&tvlv_handler->refcount); in batadv_tvlv_handler_register()
544 hlist_add_head_rcu(&tvlv_handler->list, &bat_priv->tvlv.handler_list); in batadv_tvlv_handler_register()
545 spin_unlock_bh(&bat_priv->tvlv.handler_list_lock); in batadv_tvlv_handler_register()
552 * batadv_tvlv_handler_unregister() - unregister tvlv handler based on the
568 spin_lock_bh(&bat_priv->tvlv.handler_list_lock); in batadv_tvlv_handler_unregister()
569 hlist_del_rcu(&tvlv_handler->list); in batadv_tvlv_handler_unregister()
570 spin_unlock_bh(&bat_priv->tvlv.handler_list_lock); in batadv_tvlv_handler_unregister()
575 * batadv_tvlv_unicast_send() - send a unicast packet with tvlv payload to the
578 * @src: source mac address of the unicast packet
579 * @dst: destination mac address of the unicast packet
607 skb->priority = TC_PRIO_CONTROL; in batadv_tvlv_unicast_send()
611 unicast_tvlv_packet->packet_type = BATADV_UNICAST_TVLV; in batadv_tvlv_unicast_send()
612 unicast_tvlv_packet->version = BATADV_COMPAT_VERSION; in batadv_tvlv_unicast_send()
613 unicast_tvlv_packet->ttl = BATADV_TTL; in batadv_tvlv_unicast_send()
614 unicast_tvlv_packet->reserved = 0; in batadv_tvlv_unicast_send()
615 unicast_tvlv_packet->tvlv_len = htons(tvlv_len); in batadv_tvlv_unicast_send()
616 unicast_tvlv_packet->align = 0; in batadv_tvlv_unicast_send()
617 ether_addr_copy(unicast_tvlv_packet->src, src); in batadv_tvlv_unicast_send()
618 ether_addr_copy(unicast_tvlv_packet->dst, dst); in batadv_tvlv_unicast_send()
622 tvlv_hdr->version = version; in batadv_tvlv_unicast_send()
623 tvlv_hdr->type = type; in batadv_tvlv_unicast_send()
624 tvlv_hdr->len = htons(tvlv_value_len); in batadv_tvlv_unicast_send()