blob: 8af5d30e59b1c69ef4e205262c6c90da1f9d2ce3 [file] [log] [blame]
Sven Eckelmann7db7d9f2017-11-19 15:05:11 +01001// SPDX-License-Identifier: GPL-2.0
Sven Eckelmannac79cbb2017-01-01 00:00:00 +01002/* Copyright (C) 2007-2017 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
4 * Marek Lindner
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
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000019#include "icmp_socket.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020020#include "main.h"
21
22#include <linux/atomic.h>
23#include <linux/compiler.h>
24#include <linux/debugfs.h>
25#include <linux/errno.h>
26#include <linux/etherdevice.h>
27#include <linux/export.h>
28#include <linux/fcntl.h>
29#include <linux/fs.h>
Sven Eckelmannb92b94a2017-11-19 17:12:02 +010030#include <linux/gfp.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020031#include <linux/if_ether.h>
32#include <linux/kernel.h>
33#include <linux/list.h>
34#include <linux/module.h>
35#include <linux/netdevice.h>
36#include <linux/pkt_sched.h>
37#include <linux/poll.h>
38#include <linux/printk.h>
39#include <linux/sched.h> /* for linux/wait.h */
40#include <linux/skbuff.h>
41#include <linux/slab.h>
42#include <linux/spinlock.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020043#include <linux/stddef.h>
44#include <linux/string.h>
45#include <linux/uaccess.h>
46#include <linux/wait.h>
47
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000048#include "hard-interface.h"
Sven Eckelmannba412082016-05-15 23:48:31 +020049#include "log.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020050#include "originator.h"
51#include "packet.h"
52#include "send.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000053
Sven Eckelmann56303d32012-06-05 22:31:31 +020054static struct batadv_socket_client *batadv_socket_client_hash[256];
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000055
Sven Eckelmann56303d32012-06-05 22:31:31 +020056static void batadv_socket_add_packet(struct batadv_socket_client *socket_client,
Simon Wunderlichda6b8c22013-10-22 22:50:09 +020057 struct batadv_icmp_header *icmph,
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020058 size_t icmp_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000059
Sven Eckelmann9039dc72012-05-12 02:09:33 +020060void batadv_socket_init(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000061{
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020062 memset(batadv_socket_client_hash, 0, sizeof(batadv_socket_client_hash));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000063}
64
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020065static int batadv_socket_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000066{
67 unsigned int i;
Sven Eckelmann56303d32012-06-05 22:31:31 +020068 struct batadv_socket_client *socket_client;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000069
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +020070 if (!try_module_get(THIS_MODULE))
71 return -EBUSY;
72
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000073 nonseekable_open(inode, file);
74
Sven Eckelmann704509b2011-05-14 23:14:54 +020075 socket_client = kmalloc(sizeof(*socket_client), GFP_KERNEL);
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +020076 if (!socket_client) {
77 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000078 return -ENOMEM;
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +020079 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000080
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020081 for (i = 0; i < ARRAY_SIZE(batadv_socket_client_hash); i++) {
82 if (!batadv_socket_client_hash[i]) {
83 batadv_socket_client_hash[i] = socket_client;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000084 break;
85 }
86 }
87
Sven Eckelmannaf4447f2012-05-12 18:33:59 +020088 if (i == ARRAY_SIZE(batadv_socket_client_hash)) {
Sven Eckelmann86ceb362012-03-07 09:07:45 +010089 pr_err("Error - can't add another packet client: maximum number of clients reached\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000090 kfree(socket_client);
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +020091 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000092 return -EXFULL;
93 }
94
95 INIT_LIST_HEAD(&socket_client->queue_list);
96 socket_client->queue_len = 0;
97 socket_client->index = i;
98 socket_client->bat_priv = inode->i_private;
99 spin_lock_init(&socket_client->lock);
100 init_waitqueue_head(&socket_client->queue_wait);
101
102 file->private_data = socket_client;
103
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000104 return 0;
105}
106
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200107static int batadv_socket_release(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000108{
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800109 struct batadv_socket_client *client = file->private_data;
110 struct batadv_socket_packet *packet, *tmp;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000111
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800112 spin_lock_bh(&client->lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000113
114 /* for all packets in the queue ... */
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800115 list_for_each_entry_safe(packet, tmp, &client->queue_list, list) {
116 list_del(&packet->list);
117 kfree(packet);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000118 }
119
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800120 batadv_socket_client_hash[client->index] = NULL;
121 spin_unlock_bh(&client->lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000122
Geliang Tangfb1f23e2015-12-18 23:33:31 +0800123 kfree(client);
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +0200124 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000125
126 return 0;
127}
128
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200129static ssize_t batadv_socket_read(struct file *file, char __user *buf,
130 size_t count, loff_t *ppos)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000131{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200132 struct batadv_socket_client *socket_client = file->private_data;
133 struct batadv_socket_packet *socket_packet;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000134 size_t packet_len;
135 int error;
136
Sven Eckelmann825ffe12017-08-23 21:52:13 +0200137 if ((file->f_flags & O_NONBLOCK) && socket_client->queue_len == 0)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000138 return -EAGAIN;
139
Sven Eckelmann825ffe12017-08-23 21:52:13 +0200140 if (!buf || count < sizeof(struct batadv_icmp_packet))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000141 return -EINVAL;
142
143 if (!access_ok(VERIFY_WRITE, buf, count))
144 return -EFAULT;
145
146 error = wait_event_interruptible(socket_client->queue_wait,
147 socket_client->queue_len);
148
149 if (error)
150 return error;
151
152 spin_lock_bh(&socket_client->lock);
153
154 socket_packet = list_first_entry(&socket_client->queue_list,
Sven Eckelmann56303d32012-06-05 22:31:31 +0200155 struct batadv_socket_packet, list);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000156 list_del(&socket_packet->list);
157 socket_client->queue_len--;
158
159 spin_unlock_bh(&socket_client->lock);
160
Sven Eckelmannb5a1eee2011-12-10 15:28:36 +0100161 packet_len = min(count, socket_packet->icmp_len);
162 error = copy_to_user(buf, &socket_packet->icmp_packet, packet_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000163
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000164 kfree(socket_packet);
165
166 if (error)
167 return -EFAULT;
168
169 return packet_len;
170}
171
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200172static ssize_t batadv_socket_write(struct file *file, const char __user *buff,
173 size_t len, loff_t *off)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000174{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200175 struct batadv_socket_client *socket_client = file->private_data;
176 struct batadv_priv *bat_priv = socket_client->bat_priv;
177 struct batadv_hard_iface *primary_if = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000178 struct sk_buff *skb;
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200179 struct batadv_icmp_packet_rr *icmp_packet_rr;
180 struct batadv_icmp_header *icmp_header;
Sven Eckelmann56303d32012-06-05 22:31:31 +0200181 struct batadv_orig_node *orig_node = NULL;
182 struct batadv_neigh_node *neigh_node = NULL;
Sven Eckelmann96412692012-06-05 22:31:30 +0200183 size_t packet_len = sizeof(struct batadv_icmp_packet);
Sven Eckelmann6b5e9712015-05-26 18:34:26 +0200184 u8 *addr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000185
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200186 if (len < sizeof(struct batadv_icmp_header)) {
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200187 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200188 "Error - can't send packet from char device: invalid packet size\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000189 return -EINVAL;
190 }
191
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200192 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200193
194 if (!primary_if) {
195 len = -EFAULT;
196 goto out;
197 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000198
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200199 if (len >= BATADV_ICMP_MAX_PACKET_SIZE)
200 packet_len = BATADV_ICMP_MAX_PACKET_SIZE;
201 else
202 packet_len = len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000203
Antonio Quartulli41ab6c42013-04-02 22:28:44 +0200204 skb = netdev_alloc_skb_ip_align(NULL, packet_len + ETH_HLEN);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200205 if (!skb) {
206 len = -ENOMEM;
207 goto out;
208 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000209
Simon Wunderlichc54f38c2013-07-29 17:56:44 +0200210 skb->priority = TC_PRIO_CONTROL;
Antonio Quartulli41ab6c42013-04-02 22:28:44 +0200211 skb_reserve(skb, ETH_HLEN);
Johannes Berg4df864c2017-06-16 14:29:21 +0200212 icmp_header = skb_put(skb, packet_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000213
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200214 if (copy_from_user(icmp_header, buff, packet_len)) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000215 len = -EFAULT;
216 goto free_skb;
217 }
218
Simon Wunderlicha40d9b02013-12-02 20:38:31 +0100219 if (icmp_header->packet_type != BATADV_ICMP) {
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200220 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200221 "Error - can't send packet from char device: got bogus packet type (expected: BAT_ICMP)\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000222 len = -EINVAL;
223 goto free_skb;
224 }
225
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200226 switch (icmp_header->msg_type) {
227 case BATADV_ECHO_REQUEST:
228 if (len < sizeof(struct batadv_icmp_packet)) {
229 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
230 "Error - can't send packet from char device: invalid packet size\n");
231 len = -EINVAL;
232 goto free_skb;
233 }
234
235 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
236 goto dst_unreach;
237
238 orig_node = batadv_orig_hash_find(bat_priv, icmp_header->dst);
239 if (!orig_node)
240 goto dst_unreach;
241
Simon Wunderlich7351a4822013-11-13 19:14:47 +0100242 neigh_node = batadv_orig_router_get(orig_node,
243 BATADV_IF_DEFAULT);
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200244 if (!neigh_node)
245 goto dst_unreach;
246
247 if (!neigh_node->if_incoming)
248 goto dst_unreach;
249
250 if (neigh_node->if_incoming->if_status != BATADV_IF_ACTIVE)
251 goto dst_unreach;
252
253 icmp_packet_rr = (struct batadv_icmp_packet_rr *)icmp_header;
Antonio Quartulli8fdd0152014-01-22 00:42:11 +0100254 if (packet_len == sizeof(*icmp_packet_rr)) {
255 addr = neigh_node->if_incoming->net_dev->dev_addr;
256 ether_addr_copy(icmp_packet_rr->rr[0], addr);
257 }
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200258
259 break;
260 default:
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200261 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200262 "Error - can't send packet from char device: got unknown message type\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000263 len = -EINVAL;
264 goto free_skb;
265 }
266
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200267 icmp_header->uid = socket_client->index;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000268
Simon Wunderlicha40d9b02013-12-02 20:38:31 +0100269 if (icmp_header->version != BATADV_COMPAT_VERSION) {
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200270 icmp_header->msg_type = BATADV_PARAMETER_PROBLEM;
Simon Wunderlicha40d9b02013-12-02 20:38:31 +0100271 icmp_header->version = BATADV_COMPAT_VERSION;
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200272 batadv_socket_add_packet(socket_client, icmp_header,
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200273 packet_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000274 goto free_skb;
275 }
276
Antonio Quartulli8fdd0152014-01-22 00:42:11 +0100277 ether_addr_copy(icmp_header->orig, primary_if->net_dev->dev_addr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000278
Antonio Quartulli95d39272016-01-16 16:40:15 +0800279 batadv_send_unicast_skb(skb, neigh_node);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000280 goto out;
281
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000282dst_unreach:
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200283 icmp_header->msg_type = BATADV_DESTINATION_UNREACHABLE;
284 batadv_socket_add_packet(socket_client, icmp_header, packet_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000285free_skb:
286 kfree_skb(skb);
287out:
Marek Lindner32ae9b22011-04-20 15:40:58 +0200288 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100289 batadv_hardif_put(primary_if);
Marek Lindner44524fc2011-02-10 14:33:53 +0000290 if (neigh_node)
Sven Eckelmann25bb2502016-01-17 11:01:11 +0100291 batadv_neigh_node_put(neigh_node);
Marek Lindner44524fc2011-02-10 14:33:53 +0000292 if (orig_node)
Sven Eckelmann5d967312016-01-17 11:01:09 +0100293 batadv_orig_node_put(orig_node);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000294 return len;
295}
296
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200297static unsigned int batadv_socket_poll(struct file *file, poll_table *wait)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000298{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200299 struct batadv_socket_client *socket_client = file->private_data;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000300
301 poll_wait(file, &socket_client->queue_wait, wait);
302
303 if (socket_client->queue_len > 0)
304 return POLLIN | POLLRDNORM;
305
306 return 0;
307}
308
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200309static const struct file_operations batadv_fops = {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000310 .owner = THIS_MODULE,
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200311 .open = batadv_socket_open,
312 .release = batadv_socket_release,
313 .read = batadv_socket_read,
314 .write = batadv_socket_write,
315 .poll = batadv_socket_poll,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000316 .llseek = no_llseek,
317};
318
Sven Eckelmann56303d32012-06-05 22:31:31 +0200319int batadv_socket_setup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000320{
321 struct dentry *d;
322
323 if (!bat_priv->debug_dir)
324 goto err;
325
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200326 d = debugfs_create_file(BATADV_ICMP_SOCKET, 0600, bat_priv->debug_dir,
327 bat_priv, &batadv_fops);
Sven Eckelmann5346c352012-05-05 13:27:28 +0200328 if (!d)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000329 goto err;
330
331 return 0;
332
333err:
Sven Eckelmann5346c352012-05-05 13:27:28 +0200334 return -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000335}
336
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200337/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100338 * batadv_socket_add_packet() - schedule an icmp packet to be sent to
Sven Eckelmann34473822015-05-31 10:10:20 +0200339 * userspace on an icmp socket.
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200340 * @socket_client: the socket this packet belongs to
341 * @icmph: pointer to the header of the icmp packet
342 * @icmp_len: total length of the icmp packet
343 */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200344static void batadv_socket_add_packet(struct batadv_socket_client *socket_client,
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200345 struct batadv_icmp_header *icmph,
Sven Eckelmannaf4447f2012-05-12 18:33:59 +0200346 size_t icmp_len)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000347{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200348 struct batadv_socket_packet *socket_packet;
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200349 size_t len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000350
Sven Eckelmann704509b2011-05-14 23:14:54 +0200351 socket_packet = kmalloc(sizeof(*socket_packet), GFP_ATOMIC);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000352
353 if (!socket_packet)
354 return;
355
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200356 len = icmp_len;
357 /* check the maximum length before filling the buffer */
358 if (len > sizeof(socket_packet->icmp_packet))
359 len = sizeof(socket_packet->icmp_packet);
360
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000361 INIT_LIST_HEAD(&socket_packet->list);
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200362 memcpy(&socket_packet->icmp_packet, icmph, len);
363 socket_packet->icmp_len = len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000364
365 spin_lock_bh(&socket_client->lock);
366
367 /* while waiting for the lock the socket_client could have been
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200368 * deleted
369 */
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200370 if (!batadv_socket_client_hash[icmph->uid]) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000371 spin_unlock_bh(&socket_client->lock);
372 kfree(socket_packet);
373 return;
374 }
375
376 list_add_tail(&socket_packet->list, &socket_client->queue_list);
377 socket_client->queue_len++;
378
379 if (socket_client->queue_len > 100) {
380 socket_packet = list_first_entry(&socket_client->queue_list,
Sven Eckelmann56303d32012-06-05 22:31:31 +0200381 struct batadv_socket_packet,
382 list);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000383
384 list_del(&socket_packet->list);
385 kfree(socket_packet);
386 socket_client->queue_len--;
387 }
388
389 spin_unlock_bh(&socket_client->lock);
390
391 wake_up(&socket_client->queue_wait);
392}
393
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200394/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100395 * batadv_socket_receive_packet() - schedule an icmp packet to be received
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200396 * locally and sent to userspace.
397 * @icmph: pointer to the header of the icmp packet
398 * @icmp_len: total length of the icmp packet
399 */
400void batadv_socket_receive_packet(struct batadv_icmp_header *icmph,
Sven Eckelmann9039dc72012-05-12 02:09:33 +0200401 size_t icmp_len)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000402{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200403 struct batadv_socket_client *hash;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000404
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200405 hash = batadv_socket_client_hash[icmph->uid];
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000406 if (hash)
Simon Wunderlichda6b8c22013-10-22 22:50:09 +0200407 batadv_socket_add_packet(hash, icmph, icmp_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000408}