^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* Copyright (C) 2007-2020 B.A.T.M.A.N. contributors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Marek Lindner, Simon Wunderlich
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef _NET_BATMAN_ADV_SEND_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define _NET_BATMAN_ADV_SEND_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "main.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <uapi/linux/batadv_packet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) bool dropped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct batadv_forw_packet *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) batadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct batadv_hard_iface *if_outgoing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) atomic_t *queue_left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) bool batadv_forw_packet_steal(struct batadv_forw_packet *packet, spinlock_t *l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) void batadv_forw_packet_ogmv1_queue(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct batadv_forw_packet *forw_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) unsigned long send_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) bool batadv_forw_packet_is_rebroadcast(struct batadv_forw_packet *forw_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) int batadv_send_skb_to_orig(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct batadv_orig_node *orig_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct batadv_hard_iface *recv_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int batadv_send_skb_packet(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct batadv_hard_iface *hard_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) const u8 *dst_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int batadv_send_broadcast_skb(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct batadv_hard_iface *hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int batadv_send_unicast_skb(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct batadv_neigh_node *neigh_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned long delay,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) bool own_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) batadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) const struct batadv_hard_iface *hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) bool batadv_send_skb_prepare_unicast_4addr(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct batadv_orig_node *orig_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int packet_subtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct sk_buff *skb, int packet_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int packet_subtype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct batadv_orig_node *orig_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) unsigned short vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int batadv_send_skb_via_tt_generic(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct sk_buff *skb, int packet_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int packet_subtype, u8 *dst_hint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) unsigned short vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) int batadv_send_skb_via_gw(struct batadv_priv *bat_priv, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) unsigned short vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * batadv_send_skb_via_tt() - send an skb via TT lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * @skb: the payload to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * @dst_hint: can be used to override the destination contained in the skb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * @vid: the vid to be used to search the translation table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * Look up the recipient node for the destination address in the ethernet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * header via the translation table. Wrap the given skb into a batman-adv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * unicast header. Then send this frame to the according destination node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * Return: NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static inline int batadv_send_skb_via_tt(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct sk_buff *skb, u8 *dst_hint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) unsigned short vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return batadv_send_skb_via_tt_generic(bat_priv, skb, BATADV_UNICAST, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) dst_hint, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * batadv_send_skb_via_tt_4addr() - send an skb via TT lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * @skb: the payload to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * @packet_subtype: the unicast 4addr packet subtype to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * @dst_hint: can be used to override the destination contained in the skb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * @vid: the vid to be used to search the translation table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * Look up the recipient node for the destination address in the ethernet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * header via the translation table. Wrap the given skb into a batman-adv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * unicast-4addr header. Then send this frame to the according destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * Return: NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static inline int batadv_send_skb_via_tt_4addr(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int packet_subtype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) u8 *dst_hint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned short vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return batadv_send_skb_via_tt_generic(bat_priv, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) BATADV_UNICAST_4ADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) packet_subtype, dst_hint, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #endif /* _NET_BATMAN_ADV_SEND_H_ */