blob: 6308c9f0fd96c149f8d825c6f736e2112204a76c [file] [log] [blame]
Sven Eckelmannac79cbb2017-01-01 00:00:00 +01001/* Copyright (C) 2007-2017 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00002 *
3 * Marek Lindner
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
Antonio Quartulliebf38fb2013-11-03 20:40:48 +010015 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000016 */
17
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000018#include "icmp_socket.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020019#include "main.h"
20
21#include <linux/atomic.h>
22#include <linux/compiler.h>
23#include <linux/debugfs.h>
24#include <linux/errno.h>
25#include <linux/etherdevice.h>
26#include <linux/export.h>
27#include <linux/fcntl.h>
28#include <linux/fs.h>
29#include <linux/if_ether.h>
30#include <linux/kernel.h>
31#include <linux/list.h>
32#include <linux/module.h>
33#include <linux/netdevice.h>
34#include <linux/pkt_sched.h>
35#include <linux/poll.h>
36#include <linux/printk.h>
37#include <linux/sched.h> /* for linux/wait.h */
38#include <linux/skbuff.h>
39#include <linux/slab.h>
40#include <linux/spinlock.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020041#include <linux/stddef.h>
42#include <linux/string.h>
43#include <linux/uaccess.h>
44#include <linux/wait.h>
45
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000046#include "hard-interface.h"
Sven Eckelmannba412082016-05-15 23:48:31 +020047#include "log.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020048#include "originator.h"
49#include "packet.h"
50#include "send.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000051
Sven Eckelmann56303d32012-06-05 22:31:31 +020052static struct batadv_socket_client *batadv_socket_client_hash[256];
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000053
Sven Eckelmann56303d32012-06-05 22:31:31 +020054static void batadv_socket_add_packet(struct batadv_socket_client *socket_client,
Simon Wunderlichda6b8c22013-10-22 22:50:09 +020055 struct batadv_icmp_header *icmph,
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020056 size_t icmp_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000057
Sven Eckelmann9039dc72012-05-12 02:09:33 +020058void batadv_socket_init(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000059{
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020060 memset(batadv_socket_client_hash, 0, sizeof(batadv_socket_client_hash));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000061}
62
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020063static int batadv_socket_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000064{
65 unsigned int i;
Sven Eckelmann56303d32012-06-05 22:31:31 +020066 struct batadv_socket_client *socket_client;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000067
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +020068 if (!try_module_get(THIS_MODULE))
69 return -EBUSY;
70
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000071 nonseekable_open(inode, file);
72
Sven Eckelmann704509b2011-05-14 23:14:54 +020073 socket_client = kmalloc(sizeof(*socket_client), GFP_KERNEL);
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +020074 if (!socket_client) {
75 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000076 return -ENOMEM;
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +020077 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000078
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020079 for (i = 0; i < ARRAY_SIZE(batadv_socket_client_hash); i++) {
80 if (!batadv_socket_client_hash[i]) {
81 batadv_socket_client_hash[i] = socket_client;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000082 break;
83 }
84 }
85
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020086 if (i == ARRAY_SIZE(batadv_socket_client_hash)) {
Sven Eckelmann86ceb362012-03-07 09:07:45 +010087 pr_err("Error - can't add another packet client: maximum number of clients reached\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000088 kfree(socket_client);
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +020089 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000090 return -EXFULL;
91 }
92
93 INIT_LIST_HEAD(&socket_client->queue_list);
94 socket_client->queue_len = 0;
95 socket_client->index = i;
96 socket_client->bat_priv = inode->i_private;
97 spin_lock_init(&socket_client->lock);
98 init_waitqueue_head(&socket_client->queue_wait);
99
100 file->private_data = socket_client;
101
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000102 return 0;
103}
104
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200105static int batadv_socket_release(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000106{
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800107 struct batadv_socket_client *client = file->private_data;
108 struct batadv_socket_packet *packet, *tmp;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000109
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800110 spin_lock_bh(&client->lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000111
112 /* for all packets in the queue ... */
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800113 list_for_each_entry_safe(packet, tmp, &client->queue_list, list) {
114 list_del(&packet->list);
115 kfree(packet);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000116 }
117
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800118 batadv_socket_client_hash[client->index] = NULL;
119 spin_unlock_bh(&client->lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000120
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800121 kfree(client);
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +0200122 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000123
124 return 0;
125}
126
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200127static ssize_t batadv_socket_read(struct file *file, char __user *buf,
128 size_t count, loff_t *ppos)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000129{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200130 struct batadv_socket_client *socket_client = file->private_data;
131 struct batadv_socket_packet *socket_packet;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000132 size_t packet_len;
133 int error;
134
135 if ((file->f_flags & O_NONBLOCK) && (socket_client->queue_len == 0))
136 return -EAGAIN;
137
Sven Eckelmann96412692012-06-05 22:31:30 +0200138 if ((!buf) || (count < sizeof(struct batadv_icmp_packet)))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000139 return -EINVAL;
140
141 if (!access_ok(VERIFY_WRITE, buf, count))
142 return -EFAULT;
143
144 error = wait_event_interruptible(socket_client->queue_wait,
145 socket_client->queue_len);
146
147 if (error)
148 return error;
149
150 spin_lock_bh(&socket_client->lock);
151
152 socket_packet = list_first_entry(&socket_client->queue_list,
Sven Eckelmann56303d32012-06-05 22:31:31 +0200153 struct batadv_socket_packet, list);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000154 list_del(&socket_packet->list);
155 socket_client->queue_len--;
156
157 spin_unlock_bh(&socket_client->lock);
158
Sven Eckelmannb5a1eee2011-12-10 15:28:36 +0100159 packet_len = min(count, socket_packet->icmp_len);
160 error = copy_to_user(buf, &socket_packet->icmp_packet, packet_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000161
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000162 kfree(socket_packet);
163
164 if (error)
165 return -EFAULT;
166
167 return packet_len;
168}
169
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200170static ssize_t batadv_socket_write(struct file *file, const char __user *buff,
171 size_t len, loff_t *off)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000172{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200173 struct batadv_socket_client *socket_client = file->private_data;
174 struct batadv_priv *bat_priv = socket_client->bat_priv;
175 struct batadv_hard_iface *primary_if = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000176 struct sk_buff *skb;
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200177 struct batadv_icmp_packet_rr *icmp_packet_rr;
178 struct batadv_icmp_header *icmp_header;
Sven Eckelmann56303d32012-06-05 22:31:31 +0200179 struct batadv_orig_node *orig_node = NULL;
180 struct batadv_neigh_node *neigh_node = NULL;
Sven Eckelmann96412692012-06-05 22:31:30 +0200181 size_t packet_len = sizeof(struct batadv_icmp_packet);
Sven Eckelmann6b5e9712015-05-26 18:34:26 +0200182 u8 *addr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000183
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200184 if (len < sizeof(struct batadv_icmp_header)) {
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200185 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200186 "Error - can't send packet from char device: invalid packet size\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000187 return -EINVAL;
188 }
189
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200190 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200191
192 if (!primary_if) {
193 len = -EFAULT;
194 goto out;
195 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000196
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200197 if (len >= BATADV_ICMP_MAX_PACKET_SIZE)
198 packet_len = BATADV_ICMP_MAX_PACKET_SIZE;
199 else
200 packet_len = len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000201
Antonio Quartulli41ab6c42013-04-02 22:28:44 +0200202 skb = netdev_alloc_skb_ip_align(NULL, packet_len + ETH_HLEN);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200203 if (!skb) {
204 len = -ENOMEM;
205 goto out;
206 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000207
Simon Wunderlichc54f38c92013-07-29 17:56:44 +0200208 skb->priority = TC_PRIO_CONTROL;
Antonio Quartulli41ab6c42013-04-02 22:28:44 +0200209 skb_reserve(skb, ETH_HLEN);
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200210 icmp_header = (struct batadv_icmp_header *)skb_put(skb, packet_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000211
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200212 if (copy_from_user(icmp_header, buff, packet_len)) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000213 len = -EFAULT;
214 goto free_skb;
215 }
216
Simon Wunderlicha40d9b02013-12-02 20:38:31 +0100217 if (icmp_header->packet_type != BATADV_ICMP) {
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200218 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200219 "Error - can't send packet from char device: got bogus packet type (expected: BAT_ICMP)\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000220 len = -EINVAL;
221 goto free_skb;
222 }
223
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200224 switch (icmp_header->msg_type) {
225 case BATADV_ECHO_REQUEST:
226 if (len < sizeof(struct batadv_icmp_packet)) {
227 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
228 "Error - can't send packet from char device: invalid packet size\n");
229 len = -EINVAL;
230 goto free_skb;
231 }
232
233 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
234 goto dst_unreach;
235
236 orig_node = batadv_orig_hash_find(bat_priv, icmp_header->dst);
237 if (!orig_node)
238 goto dst_unreach;
239
Simon Wunderlich7351a4822013-11-13 19:14:47 +0100240 neigh_node = batadv_orig_router_get(orig_node,
241 BATADV_IF_DEFAULT);
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200242 if (!neigh_node)
243 goto dst_unreach;
244
245 if (!neigh_node->if_incoming)
246 goto dst_unreach;
247
248 if (neigh_node->if_incoming->if_status != BATADV_IF_ACTIVE)
249 goto dst_unreach;
250
251 icmp_packet_rr = (struct batadv_icmp_packet_rr *)icmp_header;
Antonio Quartulli8fdd0152014-01-22 00:42:11 +0100252 if (packet_len == sizeof(*icmp_packet_rr)) {
253 addr = neigh_node->if_incoming->net_dev->dev_addr;
254 ether_addr_copy(icmp_packet_rr->rr[0], addr);
255 }
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200256
257 break;
258 default:
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200259 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200260 "Error - can't send packet from char device: got unknown message type\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000261 len = -EINVAL;
262 goto free_skb;
263 }
264
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200265 icmp_header->uid = socket_client->index;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000266
Simon Wunderlicha40d9b02013-12-02 20:38:31 +0100267 if (icmp_header->version != BATADV_COMPAT_VERSION) {
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200268 icmp_header->msg_type = BATADV_PARAMETER_PROBLEM;
Simon Wunderlicha40d9b02013-12-02 20:38:31 +0100269 icmp_header->version = BATADV_COMPAT_VERSION;
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200270 batadv_socket_add_packet(socket_client, icmp_header,
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200271 packet_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000272 goto free_skb;
273 }
274
Antonio Quartulli8fdd0152014-01-22 00:42:11 +0100275 ether_addr_copy(icmp_header->orig, primary_if->net_dev->dev_addr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000276
Antonio Quartulli95d39272016-01-16 16:40:15 +0800277 batadv_send_unicast_skb(skb, neigh_node);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000278 goto out;
279
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000280dst_unreach:
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200281 icmp_header->msg_type = BATADV_DESTINATION_UNREACHABLE;
282 batadv_socket_add_packet(socket_client, icmp_header, packet_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000283free_skb:
284 kfree_skb(skb);
285out:
Marek Lindner32ae9b22011-04-20 15:40:58 +0200286 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100287 batadv_hardif_put(primary_if);
Marek Lindner44524fc2011-02-10 14:33:53 +0000288 if (neigh_node)
Sven Eckelmann25bb2502016-01-17 11:01:11 +0100289 batadv_neigh_node_put(neigh_node);
Marek Lindner44524fc2011-02-10 14:33:53 +0000290 if (orig_node)
Sven Eckelmann5d967312016-01-17 11:01:09 +0100291 batadv_orig_node_put(orig_node);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000292 return len;
293}
294
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200295static unsigned int batadv_socket_poll(struct file *file, poll_table *wait)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000296{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200297 struct batadv_socket_client *socket_client = file->private_data;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000298
299 poll_wait(file, &socket_client->queue_wait, wait);
300
301 if (socket_client->queue_len > 0)
302 return POLLIN | POLLRDNORM;
303
304 return 0;
305}
306
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200307static const struct file_operations batadv_fops = {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000308 .owner = THIS_MODULE,
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200309 .open = batadv_socket_open,
310 .release = batadv_socket_release,
311 .read = batadv_socket_read,
312 .write = batadv_socket_write,
313 .poll = batadv_socket_poll,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000314 .llseek = no_llseek,
315};
316
Sven Eckelmann56303d32012-06-05 22:31:31 +0200317int batadv_socket_setup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000318{
319 struct dentry *d;
320
321 if (!bat_priv->debug_dir)
322 goto err;
323
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200324 d = debugfs_create_file(BATADV_ICMP_SOCKET, 0600, bat_priv->debug_dir,
325 bat_priv, &batadv_fops);
Sven Eckelmann5346c352012-05-05 13:27:28 +0200326 if (!d)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000327 goto err;
328
329 return 0;
330
331err:
Sven Eckelmann5346c352012-05-05 13:27:28 +0200332 return -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000333}
334
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200335/**
Antonio Quartulli6d030de2016-03-11 16:36:19 +0100336 * batadv_socket_add_packet - schedule an icmp packet to be sent to
Sven Eckelmann34473822015-05-31 10:10:20 +0200337 * userspace on an icmp socket.
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200338 * @socket_client: the socket this packet belongs to
339 * @icmph: pointer to the header of the icmp packet
340 * @icmp_len: total length of the icmp packet
341 */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200342static void batadv_socket_add_packet(struct batadv_socket_client *socket_client,
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200343 struct batadv_icmp_header *icmph,
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200344 size_t icmp_len)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000345{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200346 struct batadv_socket_packet *socket_packet;
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200347 size_t len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000348
Sven Eckelmann704509b2011-05-14 23:14:54 +0200349 socket_packet = kmalloc(sizeof(*socket_packet), GFP_ATOMIC);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000350
351 if (!socket_packet)
352 return;
353
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200354 len = icmp_len;
355 /* check the maximum length before filling the buffer */
356 if (len > sizeof(socket_packet->icmp_packet))
357 len = sizeof(socket_packet->icmp_packet);
358
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000359 INIT_LIST_HEAD(&socket_packet->list);
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200360 memcpy(&socket_packet->icmp_packet, icmph, len);
361 socket_packet->icmp_len = len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000362
363 spin_lock_bh(&socket_client->lock);
364
365 /* while waiting for the lock the socket_client could have been
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200366 * deleted
367 */
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200368 if (!batadv_socket_client_hash[icmph->uid]) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000369 spin_unlock_bh(&socket_client->lock);
370 kfree(socket_packet);
371 return;
372 }
373
374 list_add_tail(&socket_packet->list, &socket_client->queue_list);
375 socket_client->queue_len++;
376
377 if (socket_client->queue_len > 100) {
378 socket_packet = list_first_entry(&socket_client->queue_list,
Sven Eckelmann56303d32012-06-05 22:31:31 +0200379 struct batadv_socket_packet,
380 list);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000381
382 list_del(&socket_packet->list);
383 kfree(socket_packet);
384 socket_client->queue_len--;
385 }
386
387 spin_unlock_bh(&socket_client->lock);
388
389 wake_up(&socket_client->queue_wait);
390}
391
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200392/**
393 * batadv_socket_receive_packet - schedule an icmp packet to be received
394 * locally and sent to userspace.
395 * @icmph: pointer to the header of the icmp packet
396 * @icmp_len: total length of the icmp packet
397 */
398void batadv_socket_receive_packet(struct batadv_icmp_header *icmph,
Sven Eckelmann9039dc72012-05-12 02:09:33 +0200399 size_t icmp_len)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000400{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200401 struct batadv_socket_client *hash;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000402
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200403 hash = batadv_socket_client_hash[icmph->uid];
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000404 if (hash)
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200405 batadv_socket_add_packet(hash, icmph, icmp_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000406}