blob: 378cc1119d6664ff1dcbf5993a8b2871505c6939 [file] [log] [blame]
Sven Eckelmann0046b042016-01-01 00:01:03 +01001/* Copyright (C) 2007-2016 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>
41#include <linux/stat.h>
42#include <linux/stddef.h>
43#include <linux/string.h>
44#include <linux/uaccess.h>
45#include <linux/wait.h>
46
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000047#include "hard-interface.h"
Sven Eckelmannba412082016-05-15 23:48:31 +020048#include "log.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020049#include "originator.h"
50#include "packet.h"
51#include "send.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000052
Sven Eckelmann56303d32012-06-05 22:31:31 +020053static struct batadv_socket_client *batadv_socket_client_hash[256];
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000054
Sven Eckelmann56303d32012-06-05 22:31:31 +020055static void batadv_socket_add_packet(struct batadv_socket_client *socket_client,
Simon Wunderlichda6b8c22013-10-22 22:50:09 +020056 struct batadv_icmp_header *icmph,
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020057 size_t icmp_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000058
Sven Eckelmann9039dc72012-05-12 02:09:33 +020059void batadv_socket_init(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000060{
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020061 memset(batadv_socket_client_hash, 0, sizeof(batadv_socket_client_hash));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000062}
63
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020064static int batadv_socket_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000065{
66 unsigned int i;
Sven Eckelmann56303d32012-06-05 22:31:31 +020067 struct batadv_socket_client *socket_client;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000068
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +020069 if (!try_module_get(THIS_MODULE))
70 return -EBUSY;
71
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000072 nonseekable_open(inode, file);
73
Sven Eckelmann704509b2011-05-14 23:14:54 +020074 socket_client = kmalloc(sizeof(*socket_client), GFP_KERNEL);
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +020075 if (!socket_client) {
76 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000077 return -ENOMEM;
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +020078 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000079
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020080 for (i = 0; i < ARRAY_SIZE(batadv_socket_client_hash); i++) {
81 if (!batadv_socket_client_hash[i]) {
82 batadv_socket_client_hash[i] = socket_client;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000083 break;
84 }
85 }
86
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020087 if (i == ARRAY_SIZE(batadv_socket_client_hash)) {
Sven Eckelmann86ceb362012-03-07 09:07:45 +010088 pr_err("Error - can't add another packet client: maximum number of clients reached\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000089 kfree(socket_client);
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +020090 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000091 return -EXFULL;
92 }
93
94 INIT_LIST_HEAD(&socket_client->queue_list);
95 socket_client->queue_len = 0;
96 socket_client->index = i;
97 socket_client->bat_priv = inode->i_private;
98 spin_lock_init(&socket_client->lock);
99 init_waitqueue_head(&socket_client->queue_wait);
100
101 file->private_data = socket_client;
102
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000103 return 0;
104}
105
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200106static int batadv_socket_release(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000107{
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800108 struct batadv_socket_client *client = file->private_data;
109 struct batadv_socket_packet *packet, *tmp;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000110
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800111 spin_lock_bh(&client->lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000112
113 /* for all packets in the queue ... */
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800114 list_for_each_entry_safe(packet, tmp, &client->queue_list, list) {
115 list_del(&packet->list);
116 kfree(packet);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000117 }
118
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800119 batadv_socket_client_hash[client->index] = NULL;
120 spin_unlock_bh(&client->lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000121
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800122 kfree(client);
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +0200123 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000124
125 return 0;
126}
127
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200128static ssize_t batadv_socket_read(struct file *file, char __user *buf,
129 size_t count, loff_t *ppos)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000130{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200131 struct batadv_socket_client *socket_client = file->private_data;
132 struct batadv_socket_packet *socket_packet;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000133 size_t packet_len;
134 int error;
135
136 if ((file->f_flags & O_NONBLOCK) && (socket_client->queue_len == 0))
137 return -EAGAIN;
138
Sven Eckelmann96412692012-06-05 22:31:30 +0200139 if ((!buf) || (count < sizeof(struct batadv_icmp_packet)))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000140 return -EINVAL;
141
142 if (!access_ok(VERIFY_WRITE, buf, count))
143 return -EFAULT;
144
145 error = wait_event_interruptible(socket_client->queue_wait,
146 socket_client->queue_len);
147
148 if (error)
149 return error;
150
151 spin_lock_bh(&socket_client->lock);
152
153 socket_packet = list_first_entry(&socket_client->queue_list,
Sven Eckelmann56303d32012-06-05 22:31:31 +0200154 struct batadv_socket_packet, list);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000155 list_del(&socket_packet->list);
156 socket_client->queue_len--;
157
158 spin_unlock_bh(&socket_client->lock);
159
Sven Eckelmannb5a1eee2011-12-10 15:28:36 +0100160 packet_len = min(count, socket_packet->icmp_len);
161 error = copy_to_user(buf, &socket_packet->icmp_packet, packet_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000162
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000163 kfree(socket_packet);
164
165 if (error)
166 return -EFAULT;
167
168 return packet_len;
169}
170
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200171static ssize_t batadv_socket_write(struct file *file, const char __user *buff,
172 size_t len, loff_t *off)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000173{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200174 struct batadv_socket_client *socket_client = file->private_data;
175 struct batadv_priv *bat_priv = socket_client->bat_priv;
176 struct batadv_hard_iface *primary_if = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000177 struct sk_buff *skb;
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200178 struct batadv_icmp_packet_rr *icmp_packet_rr;
179 struct batadv_icmp_header *icmp_header;
Sven Eckelmann56303d32012-06-05 22:31:31 +0200180 struct batadv_orig_node *orig_node = NULL;
181 struct batadv_neigh_node *neigh_node = NULL;
Sven Eckelmann96412692012-06-05 22:31:30 +0200182 size_t packet_len = sizeof(struct batadv_icmp_packet);
Sven Eckelmann6b5e9712015-05-26 18:34:26 +0200183 u8 *addr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000184
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200185 if (len < sizeof(struct batadv_icmp_header)) {
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200186 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200187 "Error - can't send packet from char device: invalid packet size\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000188 return -EINVAL;
189 }
190
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200191 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200192
193 if (!primary_if) {
194 len = -EFAULT;
195 goto out;
196 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000197
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200198 if (len >= BATADV_ICMP_MAX_PACKET_SIZE)
199 packet_len = BATADV_ICMP_MAX_PACKET_SIZE;
200 else
201 packet_len = len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000202
Antonio Quartulli41ab6c42013-04-02 22:28:44 +0200203 skb = netdev_alloc_skb_ip_align(NULL, packet_len + ETH_HLEN);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200204 if (!skb) {
205 len = -ENOMEM;
206 goto out;
207 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000208
Simon Wunderlichc54f38c2013-07-29 17:56:44 +0200209 skb->priority = TC_PRIO_CONTROL;
Antonio Quartulli41ab6c42013-04-02 22:28:44 +0200210 skb_reserve(skb, ETH_HLEN);
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200211 icmp_header = (struct batadv_icmp_header *)skb_put(skb, packet_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000212
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200213 if (copy_from_user(icmp_header, buff, packet_len)) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000214 len = -EFAULT;
215 goto free_skb;
216 }
217
Simon Wunderlicha40d9b02013-12-02 20:38:31 +0100218 if (icmp_header->packet_type != BATADV_ICMP) {
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200219 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200220 "Error - can't send packet from char device: got bogus packet type (expected: BAT_ICMP)\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000221 len = -EINVAL;
222 goto free_skb;
223 }
224
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200225 switch (icmp_header->msg_type) {
226 case BATADV_ECHO_REQUEST:
227 if (len < sizeof(struct batadv_icmp_packet)) {
228 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
229 "Error - can't send packet from char device: invalid packet size\n");
230 len = -EINVAL;
231 goto free_skb;
232 }
233
234 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
235 goto dst_unreach;
236
237 orig_node = batadv_orig_hash_find(bat_priv, icmp_header->dst);
238 if (!orig_node)
239 goto dst_unreach;
240
Simon Wunderlich7351a4822013-11-13 19:14:47 +0100241 neigh_node = batadv_orig_router_get(orig_node,
242 BATADV_IF_DEFAULT);
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200243 if (!neigh_node)
244 goto dst_unreach;
245
246 if (!neigh_node->if_incoming)
247 goto dst_unreach;
248
249 if (neigh_node->if_incoming->if_status != BATADV_IF_ACTIVE)
250 goto dst_unreach;
251
252 icmp_packet_rr = (struct batadv_icmp_packet_rr *)icmp_header;
Antonio Quartulli8fdd0152014-01-22 00:42:11 +0100253 if (packet_len == sizeof(*icmp_packet_rr)) {
254 addr = neigh_node->if_incoming->net_dev->dev_addr;
255 ether_addr_copy(icmp_packet_rr->rr[0], addr);
256 }
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200257
258 break;
259 default:
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200260 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200261 "Error - can't send packet from char device: got unknown message type\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000262 len = -EINVAL;
263 goto free_skb;
264 }
265
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200266 icmp_header->uid = socket_client->index;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000267
Simon Wunderlicha40d9b02013-12-02 20:38:31 +0100268 if (icmp_header->version != BATADV_COMPAT_VERSION) {
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200269 icmp_header->msg_type = BATADV_PARAMETER_PROBLEM;
Simon Wunderlicha40d9b02013-12-02 20:38:31 +0100270 icmp_header->version = BATADV_COMPAT_VERSION;
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200271 batadv_socket_add_packet(socket_client, icmp_header,
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200272 packet_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000273 goto free_skb;
274 }
275
Antonio Quartulli8fdd0152014-01-22 00:42:11 +0100276 ether_addr_copy(icmp_header->orig, primary_if->net_dev->dev_addr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000277
Antonio Quartulli95d39272016-01-16 16:40:15 +0800278 batadv_send_unicast_skb(skb, neigh_node);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000279 goto out;
280
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000281dst_unreach:
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200282 icmp_header->msg_type = BATADV_DESTINATION_UNREACHABLE;
283 batadv_socket_add_packet(socket_client, icmp_header, packet_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000284free_skb:
285 kfree_skb(skb);
286out:
Marek Lindner32ae9b22011-04-20 15:40:58 +0200287 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100288 batadv_hardif_put(primary_if);
Marek Lindner44524fc2011-02-10 14:33:53 +0000289 if (neigh_node)
Sven Eckelmann25bb2502016-01-17 11:01:11 +0100290 batadv_neigh_node_put(neigh_node);
Marek Lindner44524fc2011-02-10 14:33:53 +0000291 if (orig_node)
Sven Eckelmann5d967312016-01-17 11:01:09 +0100292 batadv_orig_node_put(orig_node);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000293 return len;
294}
295
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200296static unsigned int batadv_socket_poll(struct file *file, poll_table *wait)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000297{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200298 struct batadv_socket_client *socket_client = file->private_data;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000299
300 poll_wait(file, &socket_client->queue_wait, wait);
301
302 if (socket_client->queue_len > 0)
303 return POLLIN | POLLRDNORM;
304
305 return 0;
306}
307
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200308static const struct file_operations batadv_fops = {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000309 .owner = THIS_MODULE,
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200310 .open = batadv_socket_open,
311 .release = batadv_socket_release,
312 .read = batadv_socket_read,
313 .write = batadv_socket_write,
314 .poll = batadv_socket_poll,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000315 .llseek = no_llseek,
316};
317
Sven Eckelmann56303d32012-06-05 22:31:31 +0200318int batadv_socket_setup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000319{
320 struct dentry *d;
321
322 if (!bat_priv->debug_dir)
323 goto err;
324
Sven Eckelmann64346642012-06-03 22:19:12 +0200325 d = debugfs_create_file(BATADV_ICMP_SOCKET, S_IFREG | S_IWUSR | S_IRUSR,
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200326 bat_priv->debug_dir, bat_priv, &batadv_fops);
Sven Eckelmann5346c352012-05-05 13:27:28 +0200327 if (!d)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000328 goto err;
329
330 return 0;
331
332err:
Sven Eckelmann5346c352012-05-05 13:27:28 +0200333 return -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000334}
335
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200336/**
Antonio Quartulli6d030de2016-03-11 16:36:19 +0100337 * batadv_socket_add_packet - schedule an icmp packet to be sent to
Sven Eckelmann34473822015-05-31 10:10:20 +0200338 * userspace on an icmp socket.
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200339 * @socket_client: the socket this packet belongs to
340 * @icmph: pointer to the header of the icmp packet
341 * @icmp_len: total length of the icmp packet
342 */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200343static void batadv_socket_add_packet(struct batadv_socket_client *socket_client,
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200344 struct batadv_icmp_header *icmph,
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200345 size_t icmp_len)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000346{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200347 struct batadv_socket_packet *socket_packet;
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200348 size_t len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000349
Sven Eckelmann704509b2011-05-14 23:14:54 +0200350 socket_packet = kmalloc(sizeof(*socket_packet), GFP_ATOMIC);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000351
352 if (!socket_packet)
353 return;
354
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200355 len = icmp_len;
356 /* check the maximum length before filling the buffer */
357 if (len > sizeof(socket_packet->icmp_packet))
358 len = sizeof(socket_packet->icmp_packet);
359
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000360 INIT_LIST_HEAD(&socket_packet->list);
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200361 memcpy(&socket_packet->icmp_packet, icmph, len);
362 socket_packet->icmp_len = len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000363
364 spin_lock_bh(&socket_client->lock);
365
366 /* while waiting for the lock the socket_client could have been
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200367 * deleted
368 */
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200369 if (!batadv_socket_client_hash[icmph->uid]) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000370 spin_unlock_bh(&socket_client->lock);
371 kfree(socket_packet);
372 return;
373 }
374
375 list_add_tail(&socket_packet->list, &socket_client->queue_list);
376 socket_client->queue_len++;
377
378 if (socket_client->queue_len > 100) {
379 socket_packet = list_first_entry(&socket_client->queue_list,
Sven Eckelmann56303d32012-06-05 22:31:31 +0200380 struct batadv_socket_packet,
381 list);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000382
383 list_del(&socket_packet->list);
384 kfree(socket_packet);
385 socket_client->queue_len--;
386 }
387
388 spin_unlock_bh(&socket_client->lock);
389
390 wake_up(&socket_client->queue_wait);
391}
392
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200393/**
394 * batadv_socket_receive_packet - schedule an icmp packet to be received
395 * locally and sent to userspace.
396 * @icmph: pointer to the header of the icmp packet
397 * @icmp_len: total length of the icmp packet
398 */
399void batadv_socket_receive_packet(struct batadv_icmp_header *icmph,
Sven Eckelmann9039dc72012-05-12 02:09:33 +0200400 size_t icmp_len)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000401{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200402 struct batadv_socket_client *hash;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000403
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200404 hash = batadv_socket_client_hash[icmph->uid];
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000405 if (hash)
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200406 batadv_socket_add_packet(hash, icmph, icmp_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000407}