blob: 64cce07b8fe62da8c36898a9259816d3353c504b [file] [log] [blame]
Sven Eckelmann7db7d9f2017-11-19 15:05:11 +01001/* SPDX-License-Identifier: GPL-2.0 */
Sven Eckelmann6b1aea82018-01-01 00:00:00 +01002/* Copyright (C) 2007-2018 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
Antonio Quartulliebf38fb2013-11-03 20:40:48 +010016 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000017 */
18
19#ifndef _NET_BATMAN_ADV_SEND_H_
20#define _NET_BATMAN_ADV_SEND_H_
21
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020022#include "main.h"
23
24#include <linux/compiler.h>
Linus Lüssing9b4aec62016-11-01 09:44:44 +010025#include <linux/spinlock.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020026#include <linux/types.h>
Sven Eckelmannfec149f2017-12-21 10:17:41 +010027#include <uapi/linux/batadv_packet.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020028
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020029struct sk_buff;
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020030
Sven Eckelmannbd687fe2016-07-17 21:04:00 +020031void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet,
32 bool dropped);
Linus Lüssinga65e5482016-06-20 21:39:54 +020033struct batadv_forw_packet *
34batadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming,
35 struct batadv_hard_iface *if_outgoing,
36 atomic_t *queue_left,
Linus Lüssing99ba18e2017-02-17 11:17:06 +010037 struct batadv_priv *bat_priv,
38 struct sk_buff *skb);
Linus Lüssing9b4aec62016-11-01 09:44:44 +010039bool batadv_forw_packet_steal(struct batadv_forw_packet *packet, spinlock_t *l);
40void batadv_forw_packet_ogmv1_queue(struct batadv_priv *bat_priv,
41 struct batadv_forw_packet *forw_packet,
42 unsigned long send_time);
Linus Lüssinge2d9ba42017-02-17 11:17:07 +010043bool batadv_forw_packet_is_rebroadcast(struct batadv_forw_packet *forw_packet);
Linus Lüssinga65e5482016-06-20 21:39:54 +020044
Martin Hundebølle91ecfc2013-04-20 13:54:39 +020045int batadv_send_skb_to_orig(struct sk_buff *skb,
46 struct batadv_orig_node *orig_node,
47 struct batadv_hard_iface *recv_if);
Antonio Quartulli95d39272016-01-16 16:40:15 +080048int batadv_send_skb_packet(struct sk_buff *skb,
49 struct batadv_hard_iface *hard_iface,
50 const u8 *dst_addr);
51int batadv_send_broadcast_skb(struct sk_buff *skb,
52 struct batadv_hard_iface *hard_iface);
53int batadv_send_unicast_skb(struct sk_buff *skb,
54 struct batadv_neigh_node *neigh_node);
Sven Eckelmann56303d32012-06-05 22:31:31 +020055int batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv,
Sven Eckelmann9455e342012-05-12 02:09:37 +020056 const struct sk_buff *skb,
Linus Lüssing3111bee2016-08-07 12:34:19 +020057 unsigned long delay,
58 bool own_packet);
Sven Eckelmann56303d32012-06-05 22:31:31 +020059void
60batadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
61 const struct batadv_hard_iface *hard_iface);
Martin Hundebøllf097e252013-05-23 16:53:01 +020062bool batadv_send_skb_prepare_unicast_4addr(struct batadv_priv *bat_priv,
63 struct sk_buff *skb,
64 struct batadv_orig_node *orig_node,
65 int packet_subtype);
Linus Lüssing1d8ab8d2014-02-15 17:47:52 +010066int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
67 struct sk_buff *skb, int packet_type,
68 int packet_subtype,
69 struct batadv_orig_node *orig_node,
70 unsigned short vid);
Linus Lüssinge300d312013-07-03 10:40:00 +020071int batadv_send_skb_via_tt_generic(struct batadv_priv *bat_priv,
72 struct sk_buff *skb, int packet_type,
Sven Eckelmann6b5e9712015-05-26 18:34:26 +020073 int packet_subtype, u8 *dst_hint,
Antonio Quartulli6c413b12013-11-05 19:31:08 +010074 unsigned short vid);
Linus Lüssinge300d312013-07-03 10:40:00 +020075int batadv_send_skb_via_gw(struct batadv_priv *bat_priv, struct sk_buff *skb,
76 unsigned short vid);
Martin Hundebøllf097e252013-05-23 16:53:01 +020077
78/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +010079 * batadv_send_skb_via_tt() - send an skb via TT lookup
Martin Hundebøllf097e252013-05-23 16:53:01 +020080 * @bat_priv: the bat priv with all the soft interface information
81 * @skb: the payload to send
Antonio Quartullic5d3a652014-02-15 11:58:01 +010082 * @dst_hint: can be used to override the destination contained in the skb
Antonio Quartullic018ad32013-06-04 12:11:39 +020083 * @vid: the vid to be used to search the translation table
Martin Hundebøllf097e252013-05-23 16:53:01 +020084 *
Linus Lüssinge300d312013-07-03 10:40:00 +020085 * Look up the recipient node for the destination address in the ethernet
86 * header via the translation table. Wrap the given skb into a batman-adv
87 * unicast header. Then send this frame to the according destination node.
88 *
Sven Eckelmann62fe7102015-09-15 19:00:48 +020089 * Return: NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
Martin Hundebøllf097e252013-05-23 16:53:01 +020090 */
Linus Lüssinge300d312013-07-03 10:40:00 +020091static inline int batadv_send_skb_via_tt(struct batadv_priv *bat_priv,
Sven Eckelmann6b5e9712015-05-26 18:34:26 +020092 struct sk_buff *skb, u8 *dst_hint,
Linus Lüssinge300d312013-07-03 10:40:00 +020093 unsigned short vid)
Martin Hundebøllf097e252013-05-23 16:53:01 +020094{
Linus Lüssinge300d312013-07-03 10:40:00 +020095 return batadv_send_skb_via_tt_generic(bat_priv, skb, BATADV_UNICAST, 0,
Antonio Quartulli6c413b12013-11-05 19:31:08 +010096 dst_hint, vid);
Martin Hundebøllf097e252013-05-23 16:53:01 +020097}
98
99/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100100 * batadv_send_skb_via_tt_4addr() - send an skb via TT lookup
Martin Hundebøllf097e252013-05-23 16:53:01 +0200101 * @bat_priv: the bat priv with all the soft interface information
102 * @skb: the payload to send
103 * @packet_subtype: the unicast 4addr packet subtype to use
Antonio Quartullic5d3a652014-02-15 11:58:01 +0100104 * @dst_hint: can be used to override the destination contained in the skb
Antonio Quartullic018ad32013-06-04 12:11:39 +0200105 * @vid: the vid to be used to search the translation table
Martin Hundebøllf097e252013-05-23 16:53:01 +0200106 *
Linus Lüssinge300d312013-07-03 10:40:00 +0200107 * Look up the recipient node for the destination address in the ethernet
108 * header via the translation table. Wrap the given skb into a batman-adv
109 * unicast-4addr header. Then send this frame to the according destination
110 * node.
111 *
Sven Eckelmann62fe7102015-09-15 19:00:48 +0200112 * Return: NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
Martin Hundebøllf097e252013-05-23 16:53:01 +0200113 */
Linus Lüssinge300d312013-07-03 10:40:00 +0200114static inline int batadv_send_skb_via_tt_4addr(struct batadv_priv *bat_priv,
115 struct sk_buff *skb,
116 int packet_subtype,
Sven Eckelmann6b5e9712015-05-26 18:34:26 +0200117 u8 *dst_hint,
Linus Lüssinge300d312013-07-03 10:40:00 +0200118 unsigned short vid)
Martin Hundebøllf097e252013-05-23 16:53:01 +0200119{
Linus Lüssinge300d312013-07-03 10:40:00 +0200120 return batadv_send_skb_via_tt_generic(bat_priv, skb,
121 BATADV_UNICAST_4ADDR,
Antonio Quartulli6c413b12013-11-05 19:31:08 +0100122 packet_subtype, dst_hint, vid);
Martin Hundebøllf097e252013-05-23 16:53:01 +0200123}
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000124
125#endif /* _NET_BATMAN_ADV_SEND_H_ */