162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/* Copyright (C) B.A.T.M.A.N. contributors:
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Marek Lindner, Simon Wunderlich
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef _NET_BATMAN_ADV_SEND_H_
862306a36Sopenharmony_ci#define _NET_BATMAN_ADV_SEND_H_
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include "main.h"
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/compiler.h>
1362306a36Sopenharmony_ci#include <linux/skbuff.h>
1462306a36Sopenharmony_ci#include <linux/spinlock.h>
1562306a36Sopenharmony_ci#include <linux/types.h>
1662306a36Sopenharmony_ci#include <uapi/linux/batadv_packet.h>
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_civoid batadv_forw_packet_free(struct batadv_forw_packet *forw_packet,
1962306a36Sopenharmony_ci			     bool dropped);
2062306a36Sopenharmony_cistruct batadv_forw_packet *
2162306a36Sopenharmony_cibatadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming,
2262306a36Sopenharmony_ci			 struct batadv_hard_iface *if_outgoing,
2362306a36Sopenharmony_ci			 atomic_t *queue_left,
2462306a36Sopenharmony_ci			 struct batadv_priv *bat_priv,
2562306a36Sopenharmony_ci			 struct sk_buff *skb);
2662306a36Sopenharmony_cibool batadv_forw_packet_steal(struct batadv_forw_packet *packet, spinlock_t *l);
2762306a36Sopenharmony_civoid batadv_forw_packet_ogmv1_queue(struct batadv_priv *bat_priv,
2862306a36Sopenharmony_ci				    struct batadv_forw_packet *forw_packet,
2962306a36Sopenharmony_ci				    unsigned long send_time);
3062306a36Sopenharmony_cibool batadv_forw_packet_is_rebroadcast(struct batadv_forw_packet *forw_packet);
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ciint batadv_send_skb_to_orig(struct sk_buff *skb,
3362306a36Sopenharmony_ci			    struct batadv_orig_node *orig_node,
3462306a36Sopenharmony_ci			    struct batadv_hard_iface *recv_if);
3562306a36Sopenharmony_ciint batadv_send_skb_packet(struct sk_buff *skb,
3662306a36Sopenharmony_ci			   struct batadv_hard_iface *hard_iface,
3762306a36Sopenharmony_ci			   const u8 *dst_addr);
3862306a36Sopenharmony_ciint batadv_send_broadcast_skb(struct sk_buff *skb,
3962306a36Sopenharmony_ci			      struct batadv_hard_iface *hard_iface);
4062306a36Sopenharmony_ciint batadv_send_unicast_skb(struct sk_buff *skb,
4162306a36Sopenharmony_ci			    struct batadv_neigh_node *neigh_node);
4262306a36Sopenharmony_ciint batadv_forw_bcast_packet(struct batadv_priv *bat_priv,
4362306a36Sopenharmony_ci			     struct sk_buff *skb,
4462306a36Sopenharmony_ci			     unsigned long delay,
4562306a36Sopenharmony_ci			     bool own_packet);
4662306a36Sopenharmony_civoid batadv_send_bcast_packet(struct batadv_priv *bat_priv,
4762306a36Sopenharmony_ci			      struct sk_buff *skb,
4862306a36Sopenharmony_ci			      unsigned long delay,
4962306a36Sopenharmony_ci			      bool own_packet);
5062306a36Sopenharmony_civoid
5162306a36Sopenharmony_cibatadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
5262306a36Sopenharmony_ci				 const struct batadv_hard_iface *hard_iface);
5362306a36Sopenharmony_cibool batadv_send_skb_prepare_unicast_4addr(struct batadv_priv *bat_priv,
5462306a36Sopenharmony_ci					   struct sk_buff *skb,
5562306a36Sopenharmony_ci					   struct batadv_orig_node *orig_node,
5662306a36Sopenharmony_ci					   int packet_subtype);
5762306a36Sopenharmony_ciint batadv_send_skb_unicast(struct batadv_priv *bat_priv,
5862306a36Sopenharmony_ci			    struct sk_buff *skb, int packet_type,
5962306a36Sopenharmony_ci			    int packet_subtype,
6062306a36Sopenharmony_ci			    struct batadv_orig_node *orig_node,
6162306a36Sopenharmony_ci			    unsigned short vid);
6262306a36Sopenharmony_ciint batadv_send_skb_via_tt_generic(struct batadv_priv *bat_priv,
6362306a36Sopenharmony_ci				   struct sk_buff *skb, int packet_type,
6462306a36Sopenharmony_ci				   int packet_subtype, u8 *dst_hint,
6562306a36Sopenharmony_ci				   unsigned short vid);
6662306a36Sopenharmony_ciint batadv_send_skb_via_gw(struct batadv_priv *bat_priv, struct sk_buff *skb,
6762306a36Sopenharmony_ci			   unsigned short vid);
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci/**
7062306a36Sopenharmony_ci * batadv_send_skb_via_tt() - send an skb via TT lookup
7162306a36Sopenharmony_ci * @bat_priv: the bat priv with all the soft interface information
7262306a36Sopenharmony_ci * @skb: the payload to send
7362306a36Sopenharmony_ci * @dst_hint: can be used to override the destination contained in the skb
7462306a36Sopenharmony_ci * @vid: the vid to be used to search the translation table
7562306a36Sopenharmony_ci *
7662306a36Sopenharmony_ci * Look up the recipient node for the destination address in the ethernet
7762306a36Sopenharmony_ci * header via the translation table. Wrap the given skb into a batman-adv
7862306a36Sopenharmony_ci * unicast header. Then send this frame to the according destination node.
7962306a36Sopenharmony_ci *
8062306a36Sopenharmony_ci * Return: NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
8162306a36Sopenharmony_ci */
8262306a36Sopenharmony_cistatic inline int batadv_send_skb_via_tt(struct batadv_priv *bat_priv,
8362306a36Sopenharmony_ci					 struct sk_buff *skb, u8 *dst_hint,
8462306a36Sopenharmony_ci					 unsigned short vid)
8562306a36Sopenharmony_ci{
8662306a36Sopenharmony_ci	return batadv_send_skb_via_tt_generic(bat_priv, skb, BATADV_UNICAST, 0,
8762306a36Sopenharmony_ci					      dst_hint, vid);
8862306a36Sopenharmony_ci}
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci/**
9162306a36Sopenharmony_ci * batadv_send_skb_via_tt_4addr() - send an skb via TT lookup
9262306a36Sopenharmony_ci * @bat_priv: the bat priv with all the soft interface information
9362306a36Sopenharmony_ci * @skb: the payload to send
9462306a36Sopenharmony_ci * @packet_subtype: the unicast 4addr packet subtype to use
9562306a36Sopenharmony_ci * @dst_hint: can be used to override the destination contained in the skb
9662306a36Sopenharmony_ci * @vid: the vid to be used to search the translation table
9762306a36Sopenharmony_ci *
9862306a36Sopenharmony_ci * Look up the recipient node for the destination address in the ethernet
9962306a36Sopenharmony_ci * header via the translation table. Wrap the given skb into a batman-adv
10062306a36Sopenharmony_ci * unicast-4addr header. Then send this frame to the according destination
10162306a36Sopenharmony_ci * node.
10262306a36Sopenharmony_ci *
10362306a36Sopenharmony_ci * Return: NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
10462306a36Sopenharmony_ci */
10562306a36Sopenharmony_cistatic inline int batadv_send_skb_via_tt_4addr(struct batadv_priv *bat_priv,
10662306a36Sopenharmony_ci					       struct sk_buff *skb,
10762306a36Sopenharmony_ci					       int packet_subtype,
10862306a36Sopenharmony_ci					       u8 *dst_hint,
10962306a36Sopenharmony_ci					       unsigned short vid)
11062306a36Sopenharmony_ci{
11162306a36Sopenharmony_ci	return batadv_send_skb_via_tt_generic(bat_priv, skb,
11262306a36Sopenharmony_ci					      BATADV_UNICAST_4ADDR,
11362306a36Sopenharmony_ci					      packet_subtype, dst_hint, vid);
11462306a36Sopenharmony_ci}
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci#endif /* _NET_BATMAN_ADV_SEND_H_ */
117