diff options
Diffstat (limited to 'net/batman-adv/icmp_socket.c')
-rw-r--r-- | net/batman-adv/icmp_socket.c | 121 |
1 files changed, 61 insertions, 60 deletions
diff --git a/net/batman-adv/icmp_socket.c b/net/batman-adv/icmp_socket.c index 2e98a57f3407..f2f578b1d9f0 100644 --- a/net/batman-adv/icmp_socket.c +++ b/net/batman-adv/icmp_socket.c | |||
@@ -1,5 +1,4 @@ | |||
1 | /* | 1 | /* Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: |
2 | * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: | ||
3 | * | 2 | * |
4 | * Marek Lindner | 3 | * Marek Lindner |
5 | * | 4 | * |
@@ -16,7 +15,6 @@ | |||
16 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | * 02110-1301, USA | 17 | * 02110-1301, USA |
19 | * | ||
20 | */ | 18 | */ |
21 | 19 | ||
22 | #include "main.h" | 20 | #include "main.h" |
@@ -28,18 +26,18 @@ | |||
28 | #include "originator.h" | 26 | #include "originator.h" |
29 | #include "hard-interface.h" | 27 | #include "hard-interface.h" |
30 | 28 | ||
31 | static struct socket_client *socket_client_hash[256]; | 29 | static struct socket_client *batadv_socket_client_hash[256]; |
32 | 30 | ||
33 | static void bat_socket_add_packet(struct socket_client *socket_client, | 31 | static void batadv_socket_add_packet(struct socket_client *socket_client, |
34 | struct icmp_packet_rr *icmp_packet, | 32 | struct icmp_packet_rr *icmp_packet, |
35 | size_t icmp_len); | 33 | size_t icmp_len); |
36 | 34 | ||
37 | void bat_socket_init(void) | 35 | void batadv_socket_init(void) |
38 | { | 36 | { |
39 | memset(socket_client_hash, 0, sizeof(socket_client_hash)); | 37 | memset(batadv_socket_client_hash, 0, sizeof(batadv_socket_client_hash)); |
40 | } | 38 | } |
41 | 39 | ||
42 | static int bat_socket_open(struct inode *inode, struct file *file) | 40 | static int batadv_socket_open(struct inode *inode, struct file *file) |
43 | { | 41 | { |
44 | unsigned int i; | 42 | unsigned int i; |
45 | struct socket_client *socket_client; | 43 | struct socket_client *socket_client; |
@@ -51,14 +49,14 @@ static int bat_socket_open(struct inode *inode, struct file *file) | |||
51 | if (!socket_client) | 49 | if (!socket_client) |
52 | return -ENOMEM; | 50 | return -ENOMEM; |
53 | 51 | ||
54 | for (i = 0; i < ARRAY_SIZE(socket_client_hash); i++) { | 52 | for (i = 0; i < ARRAY_SIZE(batadv_socket_client_hash); i++) { |
55 | if (!socket_client_hash[i]) { | 53 | if (!batadv_socket_client_hash[i]) { |
56 | socket_client_hash[i] = socket_client; | 54 | batadv_socket_client_hash[i] = socket_client; |
57 | break; | 55 | break; |
58 | } | 56 | } |
59 | } | 57 | } |
60 | 58 | ||
61 | if (i == ARRAY_SIZE(socket_client_hash)) { | 59 | if (i == ARRAY_SIZE(batadv_socket_client_hash)) { |
62 | pr_err("Error - can't add another packet client: maximum number of clients reached\n"); | 60 | pr_err("Error - can't add another packet client: maximum number of clients reached\n"); |
63 | kfree(socket_client); | 61 | kfree(socket_client); |
64 | return -EXFULL; | 62 | return -EXFULL; |
@@ -73,11 +71,11 @@ static int bat_socket_open(struct inode *inode, struct file *file) | |||
73 | 71 | ||
74 | file->private_data = socket_client; | 72 | file->private_data = socket_client; |
75 | 73 | ||
76 | inc_module_count(); | 74 | batadv_inc_module_count(); |
77 | return 0; | 75 | return 0; |
78 | } | 76 | } |
79 | 77 | ||
80 | static int bat_socket_release(struct inode *inode, struct file *file) | 78 | static int batadv_socket_release(struct inode *inode, struct file *file) |
81 | { | 79 | { |
82 | struct socket_client *socket_client = file->private_data; | 80 | struct socket_client *socket_client = file->private_data; |
83 | struct socket_packet *socket_packet; | 81 | struct socket_packet *socket_packet; |
@@ -94,17 +92,17 @@ static int bat_socket_release(struct inode *inode, struct file *file) | |||
94 | kfree(socket_packet); | 92 | kfree(socket_packet); |
95 | } | 93 | } |
96 | 94 | ||
97 | socket_client_hash[socket_client->index] = NULL; | 95 | batadv_socket_client_hash[socket_client->index] = NULL; |
98 | spin_unlock_bh(&socket_client->lock); | 96 | spin_unlock_bh(&socket_client->lock); |
99 | 97 | ||
100 | kfree(socket_client); | 98 | kfree(socket_client); |
101 | dec_module_count(); | 99 | batadv_dec_module_count(); |
102 | 100 | ||
103 | return 0; | 101 | return 0; |
104 | } | 102 | } |
105 | 103 | ||
106 | static ssize_t bat_socket_read(struct file *file, char __user *buf, | 104 | static ssize_t batadv_socket_read(struct file *file, char __user *buf, |
107 | size_t count, loff_t *ppos) | 105 | size_t count, loff_t *ppos) |
108 | { | 106 | { |
109 | struct socket_client *socket_client = file->private_data; | 107 | struct socket_client *socket_client = file->private_data; |
110 | struct socket_packet *socket_packet; | 108 | struct socket_packet *socket_packet; |
@@ -146,8 +144,8 @@ static ssize_t bat_socket_read(struct file *file, char __user *buf, | |||
146 | return packet_len; | 144 | return packet_len; |
147 | } | 145 | } |
148 | 146 | ||
149 | static ssize_t bat_socket_write(struct file *file, const char __user *buff, | 147 | static ssize_t batadv_socket_write(struct file *file, const char __user *buff, |
150 | size_t len, loff_t *off) | 148 | size_t len, loff_t *off) |
151 | { | 149 | { |
152 | struct socket_client *socket_client = file->private_data; | 150 | struct socket_client *socket_client = file->private_data; |
153 | struct bat_priv *bat_priv = socket_client->bat_priv; | 151 | struct bat_priv *bat_priv = socket_client->bat_priv; |
@@ -160,12 +158,12 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff, | |||
160 | size_t packet_len = sizeof(struct icmp_packet); | 158 | size_t packet_len = sizeof(struct icmp_packet); |
161 | 159 | ||
162 | if (len < sizeof(struct icmp_packet)) { | 160 | if (len < sizeof(struct icmp_packet)) { |
163 | bat_dbg(DBG_BATMAN, bat_priv, | 161 | batadv_dbg(DBG_BATMAN, bat_priv, |
164 | "Error - can't send packet from char device: invalid packet size\n"); | 162 | "Error - can't send packet from char device: invalid packet size\n"); |
165 | return -EINVAL; | 163 | return -EINVAL; |
166 | } | 164 | } |
167 | 165 | ||
168 | primary_if = primary_if_get_selected(bat_priv); | 166 | primary_if = batadv_primary_if_get_selected(bat_priv); |
169 | 167 | ||
170 | if (!primary_if) { | 168 | if (!primary_if) { |
171 | len = -EFAULT; | 169 | len = -EFAULT; |
@@ -190,36 +188,37 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff, | |||
190 | } | 188 | } |
191 | 189 | ||
192 | if (icmp_packet->header.packet_type != BAT_ICMP) { | 190 | if (icmp_packet->header.packet_type != BAT_ICMP) { |
193 | bat_dbg(DBG_BATMAN, bat_priv, | 191 | batadv_dbg(DBG_BATMAN, bat_priv, |
194 | "Error - can't send packet from char device: got bogus packet type (expected: BAT_ICMP)\n"); | 192 | "Error - can't send packet from char device: got bogus packet type (expected: BAT_ICMP)\n"); |
195 | len = -EINVAL; | 193 | len = -EINVAL; |
196 | goto free_skb; | 194 | goto free_skb; |
197 | } | 195 | } |
198 | 196 | ||
199 | if (icmp_packet->msg_type != ECHO_REQUEST) { | 197 | if (icmp_packet->msg_type != ECHO_REQUEST) { |
200 | bat_dbg(DBG_BATMAN, bat_priv, | 198 | batadv_dbg(DBG_BATMAN, bat_priv, |
201 | "Error - can't send packet from char device: got bogus message type (expected: ECHO_REQUEST)\n"); | 199 | "Error - can't send packet from char device: got bogus message type (expected: ECHO_REQUEST)\n"); |
202 | len = -EINVAL; | 200 | len = -EINVAL; |
203 | goto free_skb; | 201 | goto free_skb; |
204 | } | 202 | } |
205 | 203 | ||
206 | icmp_packet->uid = socket_client->index; | 204 | icmp_packet->uid = socket_client->index; |
207 | 205 | ||
208 | if (icmp_packet->header.version != COMPAT_VERSION) { | 206 | if (icmp_packet->header.version != BATADV_COMPAT_VERSION) { |
209 | icmp_packet->msg_type = PARAMETER_PROBLEM; | 207 | icmp_packet->msg_type = PARAMETER_PROBLEM; |
210 | icmp_packet->header.version = COMPAT_VERSION; | 208 | icmp_packet->header.version = BATADV_COMPAT_VERSION; |
211 | bat_socket_add_packet(socket_client, icmp_packet, packet_len); | 209 | batadv_socket_add_packet(socket_client, icmp_packet, |
210 | packet_len); | ||
212 | goto free_skb; | 211 | goto free_skb; |
213 | } | 212 | } |
214 | 213 | ||
215 | if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE) | 214 | if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE) |
216 | goto dst_unreach; | 215 | goto dst_unreach; |
217 | 216 | ||
218 | orig_node = orig_hash_find(bat_priv, icmp_packet->dst); | 217 | orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->dst); |
219 | if (!orig_node) | 218 | if (!orig_node) |
220 | goto dst_unreach; | 219 | goto dst_unreach; |
221 | 220 | ||
222 | neigh_node = orig_node_get_router(orig_node); | 221 | neigh_node = batadv_orig_node_get_router(orig_node); |
223 | if (!neigh_node) | 222 | if (!neigh_node) |
224 | goto dst_unreach; | 223 | goto dst_unreach; |
225 | 224 | ||
@@ -236,25 +235,25 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff, | |||
236 | memcpy(icmp_packet->rr, | 235 | memcpy(icmp_packet->rr, |
237 | neigh_node->if_incoming->net_dev->dev_addr, ETH_ALEN); | 236 | neigh_node->if_incoming->net_dev->dev_addr, ETH_ALEN); |
238 | 237 | ||
239 | send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); | 238 | batadv_send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); |
240 | goto out; | 239 | goto out; |
241 | 240 | ||
242 | dst_unreach: | 241 | dst_unreach: |
243 | icmp_packet->msg_type = DESTINATION_UNREACHABLE; | 242 | icmp_packet->msg_type = DESTINATION_UNREACHABLE; |
244 | bat_socket_add_packet(socket_client, icmp_packet, packet_len); | 243 | batadv_socket_add_packet(socket_client, icmp_packet, packet_len); |
245 | free_skb: | 244 | free_skb: |
246 | kfree_skb(skb); | 245 | kfree_skb(skb); |
247 | out: | 246 | out: |
248 | if (primary_if) | 247 | if (primary_if) |
249 | hardif_free_ref(primary_if); | 248 | batadv_hardif_free_ref(primary_if); |
250 | if (neigh_node) | 249 | if (neigh_node) |
251 | neigh_node_free_ref(neigh_node); | 250 | batadv_neigh_node_free_ref(neigh_node); |
252 | if (orig_node) | 251 | if (orig_node) |
253 | orig_node_free_ref(orig_node); | 252 | batadv_orig_node_free_ref(orig_node); |
254 | return len; | 253 | return len; |
255 | } | 254 | } |
256 | 255 | ||
257 | static unsigned int bat_socket_poll(struct file *file, poll_table *wait) | 256 | static unsigned int batadv_socket_poll(struct file *file, poll_table *wait) |
258 | { | 257 | { |
259 | struct socket_client *socket_client = file->private_data; | 258 | struct socket_client *socket_client = file->private_data; |
260 | 259 | ||
@@ -266,37 +265,37 @@ static unsigned int bat_socket_poll(struct file *file, poll_table *wait) | |||
266 | return 0; | 265 | return 0; |
267 | } | 266 | } |
268 | 267 | ||
269 | static const struct file_operations fops = { | 268 | static const struct file_operations batadv_fops = { |
270 | .owner = THIS_MODULE, | 269 | .owner = THIS_MODULE, |
271 | .open = bat_socket_open, | 270 | .open = batadv_socket_open, |
272 | .release = bat_socket_release, | 271 | .release = batadv_socket_release, |
273 | .read = bat_socket_read, | 272 | .read = batadv_socket_read, |
274 | .write = bat_socket_write, | 273 | .write = batadv_socket_write, |
275 | .poll = bat_socket_poll, | 274 | .poll = batadv_socket_poll, |
276 | .llseek = no_llseek, | 275 | .llseek = no_llseek, |
277 | }; | 276 | }; |
278 | 277 | ||
279 | int bat_socket_setup(struct bat_priv *bat_priv) | 278 | int batadv_socket_setup(struct bat_priv *bat_priv) |
280 | { | 279 | { |
281 | struct dentry *d; | 280 | struct dentry *d; |
282 | 281 | ||
283 | if (!bat_priv->debug_dir) | 282 | if (!bat_priv->debug_dir) |
284 | goto err; | 283 | goto err; |
285 | 284 | ||
286 | d = debugfs_create_file(ICMP_SOCKET, S_IFREG | S_IWUSR | S_IRUSR, | 285 | d = debugfs_create_file(BATADV_ICMP_SOCKET, S_IFREG | S_IWUSR | S_IRUSR, |
287 | bat_priv->debug_dir, bat_priv, &fops); | 286 | bat_priv->debug_dir, bat_priv, &batadv_fops); |
288 | if (d) | 287 | if (!d) |
289 | goto err; | 288 | goto err; |
290 | 289 | ||
291 | return 0; | 290 | return 0; |
292 | 291 | ||
293 | err: | 292 | err: |
294 | return 1; | 293 | return -ENOMEM; |
295 | } | 294 | } |
296 | 295 | ||
297 | static void bat_socket_add_packet(struct socket_client *socket_client, | 296 | static void batadv_socket_add_packet(struct socket_client *socket_client, |
298 | struct icmp_packet_rr *icmp_packet, | 297 | struct icmp_packet_rr *icmp_packet, |
299 | size_t icmp_len) | 298 | size_t icmp_len) |
300 | { | 299 | { |
301 | struct socket_packet *socket_packet; | 300 | struct socket_packet *socket_packet; |
302 | 301 | ||
@@ -312,8 +311,9 @@ static void bat_socket_add_packet(struct socket_client *socket_client, | |||
312 | spin_lock_bh(&socket_client->lock); | 311 | spin_lock_bh(&socket_client->lock); |
313 | 312 | ||
314 | /* while waiting for the lock the socket_client could have been | 313 | /* while waiting for the lock the socket_client could have been |
315 | * deleted */ | 314 | * deleted |
316 | if (!socket_client_hash[icmp_packet->uid]) { | 315 | */ |
316 | if (!batadv_socket_client_hash[icmp_packet->uid]) { | ||
317 | spin_unlock_bh(&socket_client->lock); | 317 | spin_unlock_bh(&socket_client->lock); |
318 | kfree(socket_packet); | 318 | kfree(socket_packet); |
319 | return; | 319 | return; |
@@ -336,11 +336,12 @@ static void bat_socket_add_packet(struct socket_client *socket_client, | |||
336 | wake_up(&socket_client->queue_wait); | 336 | wake_up(&socket_client->queue_wait); |
337 | } | 337 | } |
338 | 338 | ||
339 | void bat_socket_receive_packet(struct icmp_packet_rr *icmp_packet, | 339 | void batadv_socket_receive_packet(struct icmp_packet_rr *icmp_packet, |
340 | size_t icmp_len) | 340 | size_t icmp_len) |
341 | { | 341 | { |
342 | struct socket_client *hash = socket_client_hash[icmp_packet->uid]; | 342 | struct socket_client *hash; |
343 | 343 | ||
344 | hash = batadv_socket_client_hash[icmp_packet->uid]; | ||
344 | if (hash) | 345 | if (hash) |
345 | bat_socket_add_packet(hash, icmp_packet, icmp_len); | 346 | batadv_socket_add_packet(hash, icmp_packet, icmp_len); |
346 | } | 347 | } |