22 #include <linux/slab.h>
37 memset(batadv_socket_client_hash, 0,
sizeof(batadv_socket_client_hash));
52 for (i = 0; i <
ARRAY_SIZE(batadv_socket_client_hash); i++) {
53 if (!batadv_socket_client_hash[i]) {
54 batadv_socket_client_hash[
i] = socket_client;
59 if (i ==
ARRAY_SIZE(batadv_socket_client_hash)) {
60 pr_err(
"Error - can't add another packet client: maximum number of clients reached\n");
78 static int batadv_socket_release(
struct inode *inode,
struct file *file)
82 struct list_head *list_pos, *list_pos_tmp;
84 spin_lock_bh(&socket_client->
lock);
95 batadv_socket_client_hash[socket_client->
index] =
NULL;
96 spin_unlock_bh(&socket_client->
lock);
104 static ssize_t batadv_socket_read(
struct file *file,
char __user *
buf,
105 size_t count, loff_t *ppos)
127 spin_lock_bh(&socket_client->
lock);
134 spin_unlock_bh(&socket_client->
lock);
139 kfree(socket_packet);
147 static ssize_t batadv_socket_write(
struct file *file,
const char __user *buff,
148 size_t len, loff_t *off)
162 "Error - can't send packet from char device: invalid packet size\n");
166 primary_if = batadv_primary_if_get_selected(bat_priv);
176 skb = dev_alloc_skb(packet_len +
ETH_HLEN);
192 "Error - can't send packet from char device: got bogus packet type (expected: BAT_ICMP)\n");
199 "Error - can't send packet from char device: got bogus message type (expected: ECHO_REQUEST)\n");
204 icmp_packet->
uid = socket_client->
index;
209 batadv_socket_add_packet(socket_client, icmp_packet,
217 orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->
dst);
243 batadv_socket_add_packet(socket_client, icmp_packet, packet_len);
248 batadv_hardif_free_ref(primary_if);
256 static unsigned int batadv_socket_poll(
struct file *file,
poll_table *
wait)
260 poll_wait(file, &socket_client->
queue_wait, wait);
270 .open = batadv_socket_open,
271 .release = batadv_socket_release,
272 .read = batadv_socket_read,
273 .write = batadv_socket_write,
274 .poll = batadv_socket_poll,
286 bat_priv->
debug_dir, bat_priv, &batadv_fops);
307 INIT_LIST_HEAD(&socket_packet->
list);
311 spin_lock_bh(&socket_client->
lock);
316 if (!batadv_socket_client_hash[icmp_packet->
uid]) {
317 spin_unlock_bh(&socket_client->
lock);
318 kfree(socket_packet);
331 kfree(socket_packet);
335 spin_unlock_bh(&socket_client->
lock);
345 hash = batadv_socket_client_hash[icmp_packet->
uid];
347 batadv_socket_add_packet(hash, icmp_packet, icmp_len);