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