Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License as published by |
| 4 | * the Free Software Foundation; either version 2 of the License, or |
| 5 | * (at your option) any later version. |
| 6 | * |
| 7 | * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk) |
| 8 | * Copyright (C) Terry Dawson VK2KTJ (terry@animats.net) |
| 9 | */ |
| 10 | #include <linux/errno.h> |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/socket.h> |
| 13 | #include <linux/in.h> |
| 14 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/timer.h> |
| 16 | #include <linux/string.h> |
| 17 | #include <linux/sockios.h> |
| 18 | #include <linux/net.h> |
| 19 | #include <net/ax25.h> |
| 20 | #include <linux/inet.h> |
| 21 | #include <linux/netdevice.h> |
| 22 | #include <net/arp.h> |
| 23 | #include <linux/if_arp.h> |
| 24 | #include <linux/skbuff.h> |
| 25 | #include <net/sock.h> |
Arnaldo Carvalho de Melo | c752f07 | 2005-08-09 20:08:28 -0700 | [diff] [blame] | 26 | #include <net/tcp_states.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/system.h> |
| 28 | #include <asm/uaccess.h> |
| 29 | #include <linux/fcntl.h> |
| 30 | #include <linux/termios.h> /* For TIOCINQ/OUTQ */ |
| 31 | #include <linux/mm.h> |
| 32 | #include <linux/interrupt.h> |
| 33 | #include <linux/notifier.h> |
| 34 | #include <linux/netfilter.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <net/rose.h> |
| 37 | #include <linux/seq_file.h> |
| 38 | |
| 39 | static unsigned int rose_neigh_no = 1; |
| 40 | |
| 41 | static struct rose_node *rose_node_list; |
| 42 | static DEFINE_SPINLOCK(rose_node_list_lock); |
| 43 | static struct rose_neigh *rose_neigh_list; |
| 44 | static DEFINE_SPINLOCK(rose_neigh_list_lock); |
| 45 | static struct rose_route *rose_route_list; |
| 46 | static DEFINE_SPINLOCK(rose_route_list_lock); |
| 47 | |
Alexey Dobriyan | 891e6a9 | 2007-10-07 23:44:17 -0700 | [diff] [blame] | 48 | struct rose_neigh *rose_loopback_neigh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | /* |
| 51 | * Add a new route to a node, and in the process add the node and the |
| 52 | * neighbour if it is new. |
| 53 | */ |
Ralf Baechle | c9266b9 | 2006-12-14 15:49:28 -0800 | [diff] [blame] | 54 | static int __must_check rose_add_node(struct rose_route_struct *rose_route, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | struct net_device *dev) |
| 56 | { |
| 57 | struct rose_node *rose_node, *rose_tmpn, *rose_tmpp; |
| 58 | struct rose_neigh *rose_neigh; |
| 59 | int i, res = 0; |
| 60 | |
| 61 | spin_lock_bh(&rose_node_list_lock); |
| 62 | spin_lock_bh(&rose_neigh_list_lock); |
| 63 | |
| 64 | rose_node = rose_node_list; |
| 65 | while (rose_node != NULL) { |
| 66 | if ((rose_node->mask == rose_route->mask) && |
| 67 | (rosecmpm(&rose_route->address, &rose_node->address, |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 68 | rose_route->mask) == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | break; |
| 70 | rose_node = rose_node->next; |
| 71 | } |
| 72 | |
| 73 | if (rose_node != NULL && rose_node->loopback) { |
| 74 | res = -EINVAL; |
| 75 | goto out; |
| 76 | } |
| 77 | |
| 78 | rose_neigh = rose_neigh_list; |
| 79 | while (rose_neigh != NULL) { |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 80 | if (ax25cmp(&rose_route->neighbour, |
| 81 | &rose_neigh->callsign) == 0 && |
| 82 | rose_neigh->dev == dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | break; |
| 84 | rose_neigh = rose_neigh->next; |
| 85 | } |
| 86 | |
| 87 | if (rose_neigh == NULL) { |
| 88 | rose_neigh = kmalloc(sizeof(*rose_neigh), GFP_ATOMIC); |
| 89 | if (rose_neigh == NULL) { |
| 90 | res = -ENOMEM; |
| 91 | goto out; |
| 92 | } |
| 93 | |
| 94 | rose_neigh->callsign = rose_route->neighbour; |
| 95 | rose_neigh->digipeat = NULL; |
| 96 | rose_neigh->ax25 = NULL; |
| 97 | rose_neigh->dev = dev; |
| 98 | rose_neigh->count = 0; |
| 99 | rose_neigh->use = 0; |
| 100 | rose_neigh->dce_mode = 0; |
| 101 | rose_neigh->loopback = 0; |
| 102 | rose_neigh->number = rose_neigh_no++; |
| 103 | rose_neigh->restarted = 0; |
| 104 | |
| 105 | skb_queue_head_init(&rose_neigh->queue); |
| 106 | |
| 107 | init_timer(&rose_neigh->ftimer); |
| 108 | init_timer(&rose_neigh->t0timer); |
| 109 | |
| 110 | if (rose_route->ndigis != 0) { |
| 111 | if ((rose_neigh->digipeat = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) { |
| 112 | kfree(rose_neigh); |
| 113 | res = -ENOMEM; |
| 114 | goto out; |
| 115 | } |
| 116 | |
| 117 | rose_neigh->digipeat->ndigi = rose_route->ndigis; |
| 118 | rose_neigh->digipeat->lastrepeat = -1; |
| 119 | |
| 120 | for (i = 0; i < rose_route->ndigis; i++) { |
| 121 | rose_neigh->digipeat->calls[i] = |
| 122 | rose_route->digipeaters[i]; |
| 123 | rose_neigh->digipeat->repeated[i] = 0; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | rose_neigh->next = rose_neigh_list; |
| 128 | rose_neigh_list = rose_neigh; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * This is a new node to be inserted into the list. Find where it needs |
| 133 | * to be inserted into the list, and insert it. We want to be sure |
| 134 | * to order the list in descending order of mask size to ensure that |
| 135 | * later when we are searching this list the first match will be the |
| 136 | * best match. |
| 137 | */ |
| 138 | if (rose_node == NULL) { |
| 139 | rose_tmpn = rose_node_list; |
| 140 | rose_tmpp = NULL; |
| 141 | |
| 142 | while (rose_tmpn != NULL) { |
| 143 | if (rose_tmpn->mask > rose_route->mask) { |
| 144 | rose_tmpp = rose_tmpn; |
| 145 | rose_tmpn = rose_tmpn->next; |
| 146 | } else { |
| 147 | break; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /* create new node */ |
| 152 | rose_node = kmalloc(sizeof(*rose_node), GFP_ATOMIC); |
| 153 | if (rose_node == NULL) { |
| 154 | res = -ENOMEM; |
| 155 | goto out; |
| 156 | } |
| 157 | |
| 158 | rose_node->address = rose_route->address; |
| 159 | rose_node->mask = rose_route->mask; |
| 160 | rose_node->count = 1; |
| 161 | rose_node->loopback = 0; |
| 162 | rose_node->neighbour[0] = rose_neigh; |
| 163 | |
| 164 | if (rose_tmpn == NULL) { |
| 165 | if (rose_tmpp == NULL) { /* Empty list */ |
| 166 | rose_node_list = rose_node; |
| 167 | rose_node->next = NULL; |
| 168 | } else { |
| 169 | rose_tmpp->next = rose_node; |
| 170 | rose_node->next = NULL; |
| 171 | } |
| 172 | } else { |
| 173 | if (rose_tmpp == NULL) { /* 1st node */ |
| 174 | rose_node->next = rose_node_list; |
| 175 | rose_node_list = rose_node; |
| 176 | } else { |
| 177 | rose_tmpp->next = rose_node; |
| 178 | rose_node->next = rose_tmpn; |
| 179 | } |
| 180 | } |
| 181 | rose_neigh->count++; |
| 182 | |
| 183 | goto out; |
| 184 | } |
| 185 | |
| 186 | /* We have space, slot it in */ |
| 187 | if (rose_node->count < 3) { |
| 188 | rose_node->neighbour[rose_node->count] = rose_neigh; |
| 189 | rose_node->count++; |
| 190 | rose_neigh->count++; |
| 191 | } |
| 192 | |
| 193 | out: |
| 194 | spin_unlock_bh(&rose_neigh_list_lock); |
| 195 | spin_unlock_bh(&rose_node_list_lock); |
| 196 | |
| 197 | return res; |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * Caller is holding rose_node_list_lock. |
| 202 | */ |
| 203 | static void rose_remove_node(struct rose_node *rose_node) |
| 204 | { |
| 205 | struct rose_node *s; |
| 206 | |
| 207 | if ((s = rose_node_list) == rose_node) { |
| 208 | rose_node_list = rose_node->next; |
| 209 | kfree(rose_node); |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | while (s != NULL && s->next != NULL) { |
| 214 | if (s->next == rose_node) { |
| 215 | s->next = rose_node->next; |
| 216 | kfree(rose_node); |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | s = s->next; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | /* |
| 225 | * Caller is holding rose_neigh_list_lock. |
| 226 | */ |
| 227 | static void rose_remove_neigh(struct rose_neigh *rose_neigh) |
| 228 | { |
| 229 | struct rose_neigh *s; |
| 230 | |
| 231 | rose_stop_ftimer(rose_neigh); |
| 232 | rose_stop_t0timer(rose_neigh); |
| 233 | |
| 234 | skb_queue_purge(&rose_neigh->queue); |
| 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | if ((s = rose_neigh_list) == rose_neigh) { |
| 237 | rose_neigh_list = rose_neigh->next; |
Jesper Juhl | a51482b | 2005-11-08 09:41:34 -0800 | [diff] [blame] | 238 | kfree(rose_neigh->digipeat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | kfree(rose_neigh); |
| 240 | return; |
| 241 | } |
| 242 | |
| 243 | while (s != NULL && s->next != NULL) { |
| 244 | if (s->next == rose_neigh) { |
| 245 | s->next = rose_neigh->next; |
Jesper Juhl | a51482b | 2005-11-08 09:41:34 -0800 | [diff] [blame] | 246 | kfree(rose_neigh->digipeat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | kfree(rose_neigh); |
| 248 | return; |
| 249 | } |
| 250 | |
| 251 | s = s->next; |
| 252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /* |
| 256 | * Caller is holding rose_route_list_lock. |
| 257 | */ |
| 258 | static void rose_remove_route(struct rose_route *rose_route) |
| 259 | { |
| 260 | struct rose_route *s; |
| 261 | |
| 262 | if (rose_route->neigh1 != NULL) |
| 263 | rose_route->neigh1->use--; |
| 264 | |
| 265 | if (rose_route->neigh2 != NULL) |
| 266 | rose_route->neigh2->use--; |
| 267 | |
| 268 | if ((s = rose_route_list) == rose_route) { |
| 269 | rose_route_list = rose_route->next; |
| 270 | kfree(rose_route); |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | while (s != NULL && s->next != NULL) { |
| 275 | if (s->next == rose_route) { |
| 276 | s->next = rose_route->next; |
| 277 | kfree(rose_route); |
| 278 | return; |
| 279 | } |
| 280 | |
| 281 | s = s->next; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * "Delete" a node. Strictly speaking remove a route to a node. The node |
| 287 | * is only deleted if no routes are left to it. |
| 288 | */ |
| 289 | static int rose_del_node(struct rose_route_struct *rose_route, |
| 290 | struct net_device *dev) |
| 291 | { |
| 292 | struct rose_node *rose_node; |
| 293 | struct rose_neigh *rose_neigh; |
| 294 | int i, err = 0; |
| 295 | |
| 296 | spin_lock_bh(&rose_node_list_lock); |
| 297 | spin_lock_bh(&rose_neigh_list_lock); |
| 298 | |
| 299 | rose_node = rose_node_list; |
| 300 | while (rose_node != NULL) { |
| 301 | if ((rose_node->mask == rose_route->mask) && |
| 302 | (rosecmpm(&rose_route->address, &rose_node->address, |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 303 | rose_route->mask) == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | break; |
| 305 | rose_node = rose_node->next; |
| 306 | } |
| 307 | |
| 308 | if (rose_node == NULL || rose_node->loopback) { |
| 309 | err = -EINVAL; |
| 310 | goto out; |
| 311 | } |
| 312 | |
| 313 | rose_neigh = rose_neigh_list; |
| 314 | while (rose_neigh != NULL) { |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 315 | if (ax25cmp(&rose_route->neighbour, |
| 316 | &rose_neigh->callsign) == 0 && |
| 317 | rose_neigh->dev == dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | break; |
| 319 | rose_neigh = rose_neigh->next; |
| 320 | } |
| 321 | |
| 322 | if (rose_neigh == NULL) { |
| 323 | err = -EINVAL; |
| 324 | goto out; |
| 325 | } |
| 326 | |
| 327 | for (i = 0; i < rose_node->count; i++) { |
| 328 | if (rose_node->neighbour[i] == rose_neigh) { |
| 329 | rose_neigh->count--; |
| 330 | |
| 331 | if (rose_neigh->count == 0 && rose_neigh->use == 0) |
| 332 | rose_remove_neigh(rose_neigh); |
| 333 | |
| 334 | rose_node->count--; |
| 335 | |
| 336 | if (rose_node->count == 0) { |
| 337 | rose_remove_node(rose_node); |
| 338 | } else { |
| 339 | switch (i) { |
| 340 | case 0: |
| 341 | rose_node->neighbour[0] = |
| 342 | rose_node->neighbour[1]; |
| 343 | case 1: |
| 344 | rose_node->neighbour[1] = |
| 345 | rose_node->neighbour[2]; |
| 346 | case 2: |
| 347 | break; |
| 348 | } |
| 349 | } |
| 350 | goto out; |
| 351 | } |
| 352 | } |
| 353 | err = -EINVAL; |
| 354 | |
| 355 | out: |
| 356 | spin_unlock_bh(&rose_neigh_list_lock); |
| 357 | spin_unlock_bh(&rose_node_list_lock); |
| 358 | |
| 359 | return err; |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * Add the loopback neighbour. |
| 364 | */ |
Ralf Baechle | a3d3840 | 2006-12-14 15:52:13 -0800 | [diff] [blame] | 365 | void rose_add_loopback_neigh(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | { |
Alexey Dobriyan | 891e6a9 | 2007-10-07 23:44:17 -0700 | [diff] [blame] | 367 | struct rose_neigh *sn; |
| 368 | |
| 369 | rose_loopback_neigh = kmalloc(sizeof(struct rose_neigh), GFP_KERNEL); |
| 370 | if (!rose_loopback_neigh) |
| 371 | return; |
| 372 | sn = rose_loopback_neigh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Ralf Baechle | a3d3840 | 2006-12-14 15:52:13 -0800 | [diff] [blame] | 374 | sn->callsign = null_ax25_address; |
| 375 | sn->digipeat = NULL; |
| 376 | sn->ax25 = NULL; |
| 377 | sn->dev = NULL; |
| 378 | sn->count = 0; |
| 379 | sn->use = 0; |
| 380 | sn->dce_mode = 1; |
| 381 | sn->loopback = 1; |
| 382 | sn->number = rose_neigh_no++; |
| 383 | sn->restarted = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Ralf Baechle | a3d3840 | 2006-12-14 15:52:13 -0800 | [diff] [blame] | 385 | skb_queue_head_init(&sn->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
Ralf Baechle | a3d3840 | 2006-12-14 15:52:13 -0800 | [diff] [blame] | 387 | init_timer(&sn->ftimer); |
| 388 | init_timer(&sn->t0timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | spin_lock_bh(&rose_neigh_list_lock); |
Ralf Baechle | a3d3840 | 2006-12-14 15:52:13 -0800 | [diff] [blame] | 391 | sn->next = rose_neigh_list; |
| 392 | rose_neigh_list = sn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | spin_unlock_bh(&rose_neigh_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /* |
| 397 | * Add a loopback node. |
| 398 | */ |
| 399 | int rose_add_loopback_node(rose_address *address) |
| 400 | { |
| 401 | struct rose_node *rose_node; |
Alexey Dobriyan | 0506d40 | 2006-12-02 22:17:48 -0800 | [diff] [blame] | 402 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
| 404 | spin_lock_bh(&rose_node_list_lock); |
| 405 | |
| 406 | rose_node = rose_node_list; |
| 407 | while (rose_node != NULL) { |
| 408 | if ((rose_node->mask == 10) && |
| 409 | (rosecmpm(address, &rose_node->address, 10) == 0) && |
| 410 | rose_node->loopback) |
| 411 | break; |
| 412 | rose_node = rose_node->next; |
| 413 | } |
| 414 | |
| 415 | if (rose_node != NULL) |
| 416 | goto out; |
| 417 | |
| 418 | if ((rose_node = kmalloc(sizeof(*rose_node), GFP_ATOMIC)) == NULL) { |
| 419 | err = -ENOMEM; |
| 420 | goto out; |
| 421 | } |
| 422 | |
| 423 | rose_node->address = *address; |
| 424 | rose_node->mask = 10; |
| 425 | rose_node->count = 1; |
| 426 | rose_node->loopback = 1; |
Alexey Dobriyan | 891e6a9 | 2007-10-07 23:44:17 -0700 | [diff] [blame] | 427 | rose_node->neighbour[0] = rose_loopback_neigh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
| 429 | /* Insert at the head of list. Address is always mask=10 */ |
| 430 | rose_node->next = rose_node_list; |
| 431 | rose_node_list = rose_node; |
| 432 | |
Alexey Dobriyan | 891e6a9 | 2007-10-07 23:44:17 -0700 | [diff] [blame] | 433 | rose_loopback_neigh->count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | out: |
| 436 | spin_unlock_bh(&rose_node_list_lock); |
| 437 | |
Alexey Dobriyan | 0506d40 | 2006-12-02 22:17:48 -0800 | [diff] [blame] | 438 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | /* |
| 442 | * Delete a loopback node. |
| 443 | */ |
| 444 | void rose_del_loopback_node(rose_address *address) |
| 445 | { |
| 446 | struct rose_node *rose_node; |
| 447 | |
| 448 | spin_lock_bh(&rose_node_list_lock); |
| 449 | |
| 450 | rose_node = rose_node_list; |
| 451 | while (rose_node != NULL) { |
| 452 | if ((rose_node->mask == 10) && |
| 453 | (rosecmpm(address, &rose_node->address, 10) == 0) && |
| 454 | rose_node->loopback) |
| 455 | break; |
| 456 | rose_node = rose_node->next; |
| 457 | } |
| 458 | |
| 459 | if (rose_node == NULL) |
| 460 | goto out; |
| 461 | |
| 462 | rose_remove_node(rose_node); |
| 463 | |
Alexey Dobriyan | 891e6a9 | 2007-10-07 23:44:17 -0700 | [diff] [blame] | 464 | rose_loopback_neigh->count--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | out: |
| 467 | spin_unlock_bh(&rose_node_list_lock); |
| 468 | } |
| 469 | |
| 470 | /* |
| 471 | * A device has been removed. Remove its routes and neighbours. |
| 472 | */ |
| 473 | void rose_rt_device_down(struct net_device *dev) |
| 474 | { |
| 475 | struct rose_neigh *s, *rose_neigh; |
| 476 | struct rose_node *t, *rose_node; |
| 477 | int i; |
| 478 | |
| 479 | spin_lock_bh(&rose_node_list_lock); |
| 480 | spin_lock_bh(&rose_neigh_list_lock); |
| 481 | rose_neigh = rose_neigh_list; |
| 482 | while (rose_neigh != NULL) { |
| 483 | s = rose_neigh; |
| 484 | rose_neigh = rose_neigh->next; |
| 485 | |
| 486 | if (s->dev != dev) |
| 487 | continue; |
| 488 | |
| 489 | rose_node = rose_node_list; |
| 490 | |
| 491 | while (rose_node != NULL) { |
| 492 | t = rose_node; |
| 493 | rose_node = rose_node->next; |
| 494 | |
| 495 | for (i = 0; i < t->count; i++) { |
| 496 | if (t->neighbour[i] != s) |
| 497 | continue; |
| 498 | |
| 499 | t->count--; |
| 500 | |
| 501 | switch (i) { |
| 502 | case 0: |
| 503 | t->neighbour[0] = t->neighbour[1]; |
| 504 | case 1: |
| 505 | t->neighbour[1] = t->neighbour[2]; |
| 506 | case 2: |
| 507 | break; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | if (t->count <= 0) |
| 512 | rose_remove_node(t); |
| 513 | } |
| 514 | |
| 515 | rose_remove_neigh(s); |
| 516 | } |
| 517 | spin_unlock_bh(&rose_neigh_list_lock); |
| 518 | spin_unlock_bh(&rose_node_list_lock); |
| 519 | } |
| 520 | |
| 521 | #if 0 /* Currently unused */ |
| 522 | /* |
| 523 | * A device has been removed. Remove its links. |
| 524 | */ |
| 525 | void rose_route_device_down(struct net_device *dev) |
| 526 | { |
| 527 | struct rose_route *s, *rose_route; |
| 528 | |
| 529 | spin_lock_bh(&rose_route_list_lock); |
| 530 | rose_route = rose_route_list; |
| 531 | while (rose_route != NULL) { |
| 532 | s = rose_route; |
| 533 | rose_route = rose_route->next; |
| 534 | |
| 535 | if (s->neigh1->dev == dev || s->neigh2->dev == dev) |
| 536 | rose_remove_route(s); |
| 537 | } |
| 538 | spin_unlock_bh(&rose_route_list_lock); |
| 539 | } |
| 540 | #endif |
| 541 | |
| 542 | /* |
| 543 | * Clear all nodes and neighbours out, except for neighbours with |
| 544 | * active connections going through them. |
| 545 | * Do not clear loopback neighbour and nodes. |
| 546 | */ |
| 547 | static int rose_clear_routes(void) |
| 548 | { |
| 549 | struct rose_neigh *s, *rose_neigh; |
| 550 | struct rose_node *t, *rose_node; |
| 551 | |
| 552 | spin_lock_bh(&rose_node_list_lock); |
| 553 | spin_lock_bh(&rose_neigh_list_lock); |
| 554 | |
| 555 | rose_neigh = rose_neigh_list; |
| 556 | rose_node = rose_node_list; |
| 557 | |
| 558 | while (rose_node != NULL) { |
| 559 | t = rose_node; |
| 560 | rose_node = rose_node->next; |
| 561 | if (!t->loopback) |
| 562 | rose_remove_node(t); |
| 563 | } |
| 564 | |
| 565 | while (rose_neigh != NULL) { |
| 566 | s = rose_neigh; |
| 567 | rose_neigh = rose_neigh->next; |
| 568 | |
| 569 | if (s->use == 0 && !s->loopback) { |
| 570 | s->count = 0; |
| 571 | rose_remove_neigh(s); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | spin_unlock_bh(&rose_neigh_list_lock); |
| 576 | spin_unlock_bh(&rose_node_list_lock); |
| 577 | |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | /* |
| 582 | * Check that the device given is a valid AX.25 interface that is "up". |
Eric Dumazet | b4ec824 | 2009-11-05 20:56:07 -0800 | [diff] [blame] | 583 | * called whith RTNL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | */ |
Eric Dumazet | b4ec824 | 2009-11-05 20:56:07 -0800 | [diff] [blame] | 585 | static struct net_device *rose_ax25_dev_find(char *devname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | { |
| 587 | struct net_device *dev; |
| 588 | |
Eric Dumazet | b4ec824 | 2009-11-05 20:56:07 -0800 | [diff] [blame] | 589 | if ((dev = __dev_get_by_name(&init_net, devname)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | return NULL; |
| 591 | |
| 592 | if ((dev->flags & IFF_UP) && dev->type == ARPHRD_AX25) |
| 593 | return dev; |
| 594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | return NULL; |
| 596 | } |
| 597 | |
| 598 | /* |
| 599 | * Find the first active ROSE device, usually "rose0". |
| 600 | */ |
| 601 | struct net_device *rose_dev_first(void) |
| 602 | { |
| 603 | struct net_device *dev, *first = NULL; |
| 604 | |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 605 | rcu_read_lock(); |
| 606 | for_each_netdev_rcu(&init_net, dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE) |
| 608 | if (first == NULL || strncmp(dev->name, first->name, 3) < 0) |
| 609 | first = dev; |
| 610 | } |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 611 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
| 613 | return first; |
| 614 | } |
| 615 | |
| 616 | /* |
| 617 | * Find the ROSE device for the given address. |
| 618 | */ |
| 619 | struct net_device *rose_dev_get(rose_address *addr) |
| 620 | { |
| 621 | struct net_device *dev; |
| 622 | |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 623 | rcu_read_lock(); |
| 624 | for_each_netdev_rcu(&init_net, dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0) { |
| 626 | dev_hold(dev); |
| 627 | goto out; |
| 628 | } |
| 629 | } |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 630 | dev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | out: |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 632 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | return dev; |
| 634 | } |
| 635 | |
| 636 | static int rose_dev_exists(rose_address *addr) |
| 637 | { |
| 638 | struct net_device *dev; |
| 639 | |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 640 | rcu_read_lock(); |
| 641 | for_each_netdev_rcu(&init_net, dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0) |
| 643 | goto out; |
| 644 | } |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 645 | dev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | out: |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 647 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | return dev != NULL; |
| 649 | } |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | struct rose_route *rose_route_free_lci(unsigned int lci, struct rose_neigh *neigh) |
| 655 | { |
| 656 | struct rose_route *rose_route; |
| 657 | |
| 658 | for (rose_route = rose_route_list; rose_route != NULL; rose_route = rose_route->next) |
| 659 | if ((rose_route->neigh1 == neigh && rose_route->lci1 == lci) || |
| 660 | (rose_route->neigh2 == neigh && rose_route->lci2 == lci)) |
| 661 | return rose_route; |
| 662 | |
| 663 | return NULL; |
| 664 | } |
| 665 | |
| 666 | /* |
Bernard Pidoux | fe2c802 | 2008-06-17 17:08:32 -0700 | [diff] [blame] | 667 | * Find a neighbour or a route given a ROSE address. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | */ |
| 669 | struct rose_neigh *rose_get_neigh(rose_address *addr, unsigned char *cause, |
Bernard Pidoux | fe2c802 | 2008-06-17 17:08:32 -0700 | [diff] [blame] | 670 | unsigned char *diagnostic, int new) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | { |
| 672 | struct rose_neigh *res = NULL; |
| 673 | struct rose_node *node; |
| 674 | int failed = 0; |
| 675 | int i; |
| 676 | |
Bernard Pidoux | fe2c802 | 2008-06-17 17:08:32 -0700 | [diff] [blame] | 677 | if (!new) spin_lock_bh(&rose_node_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | for (node = rose_node_list; node != NULL; node = node->next) { |
| 679 | if (rosecmpm(addr, &node->address, node->mask) == 0) { |
| 680 | for (i = 0; i < node->count; i++) { |
Bernard Pidoux | fe2c802 | 2008-06-17 17:08:32 -0700 | [diff] [blame] | 681 | if (new) { |
| 682 | if (node->neighbour[i]->restarted) { |
| 683 | res = node->neighbour[i]; |
| 684 | goto out; |
| 685 | } |
| 686 | } |
| 687 | else { |
| 688 | if (!rose_ftimer_running(node->neighbour[i])) { |
| 689 | res = node->neighbour[i]; |
| 690 | goto out; |
| 691 | } else |
| 692 | failed = 1; |
| 693 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
| 698 | if (failed) { |
| 699 | *cause = ROSE_OUT_OF_ORDER; |
| 700 | *diagnostic = 0; |
| 701 | } else { |
| 702 | *cause = ROSE_NOT_OBTAINABLE; |
| 703 | *diagnostic = 0; |
| 704 | } |
| 705 | |
| 706 | out: |
Bernard Pidoux | fe2c802 | 2008-06-17 17:08:32 -0700 | [diff] [blame] | 707 | if (!new) spin_unlock_bh(&rose_node_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
| 709 | return res; |
| 710 | } |
| 711 | |
| 712 | /* |
| 713 | * Handle the ioctls that control the routing functions. |
| 714 | */ |
| 715 | int rose_rt_ioctl(unsigned int cmd, void __user *arg) |
| 716 | { |
| 717 | struct rose_route_struct rose_route; |
| 718 | struct net_device *dev; |
| 719 | int err; |
| 720 | |
| 721 | switch (cmd) { |
| 722 | case SIOCADDRT: |
| 723 | if (copy_from_user(&rose_route, arg, sizeof(struct rose_route_struct))) |
| 724 | return -EFAULT; |
Eric Dumazet | b4ec824 | 2009-11-05 20:56:07 -0800 | [diff] [blame] | 725 | if ((dev = rose_ax25_dev_find(rose_route.device)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | return -EINVAL; |
Eric Dumazet | b4ec824 | 2009-11-05 20:56:07 -0800 | [diff] [blame] | 727 | if (rose_dev_exists(&rose_route.address)) /* Can't add routes to ourself */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | if (rose_route.mask > 10) /* Mask can't be more than 10 digits */ |
| 730 | return -EINVAL; |
Ralf Baechle | 95df1c0 | 2005-10-18 21:39:33 +0100 | [diff] [blame] | 731 | if (rose_route.ndigis > AX25_MAX_DIGIS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | return -EINVAL; |
| 733 | err = rose_add_node(&rose_route, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | return err; |
| 735 | |
| 736 | case SIOCDELRT: |
| 737 | if (copy_from_user(&rose_route, arg, sizeof(struct rose_route_struct))) |
| 738 | return -EFAULT; |
Eric Dumazet | b4ec824 | 2009-11-05 20:56:07 -0800 | [diff] [blame] | 739 | if ((dev = rose_ax25_dev_find(rose_route.device)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | return -EINVAL; |
| 741 | err = rose_del_node(&rose_route, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | return err; |
| 743 | |
| 744 | case SIOCRSCLRRT: |
| 745 | return rose_clear_routes(); |
| 746 | |
| 747 | default: |
| 748 | return -EINVAL; |
| 749 | } |
| 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | static void rose_del_route_by_neigh(struct rose_neigh *rose_neigh) |
| 755 | { |
| 756 | struct rose_route *rose_route, *s; |
| 757 | |
| 758 | rose_neigh->restarted = 0; |
| 759 | |
| 760 | rose_stop_t0timer(rose_neigh); |
| 761 | rose_start_ftimer(rose_neigh); |
| 762 | |
| 763 | skb_queue_purge(&rose_neigh->queue); |
| 764 | |
| 765 | spin_lock_bh(&rose_route_list_lock); |
| 766 | |
| 767 | rose_route = rose_route_list; |
| 768 | |
| 769 | while (rose_route != NULL) { |
| 770 | if ((rose_route->neigh1 == rose_neigh && rose_route->neigh2 == rose_neigh) || |
| 771 | (rose_route->neigh1 == rose_neigh && rose_route->neigh2 == NULL) || |
| 772 | (rose_route->neigh2 == rose_neigh && rose_route->neigh1 == NULL)) { |
| 773 | s = rose_route->next; |
| 774 | rose_remove_route(rose_route); |
| 775 | rose_route = s; |
| 776 | continue; |
| 777 | } |
| 778 | |
| 779 | if (rose_route->neigh1 == rose_neigh) { |
| 780 | rose_route->neigh1->use--; |
| 781 | rose_route->neigh1 = NULL; |
| 782 | rose_transmit_clear_request(rose_route->neigh2, rose_route->lci2, ROSE_OUT_OF_ORDER, 0); |
| 783 | } |
| 784 | |
| 785 | if (rose_route->neigh2 == rose_neigh) { |
| 786 | rose_route->neigh2->use--; |
| 787 | rose_route->neigh2 = NULL; |
| 788 | rose_transmit_clear_request(rose_route->neigh1, rose_route->lci1, ROSE_OUT_OF_ORDER, 0); |
| 789 | } |
| 790 | |
| 791 | rose_route = rose_route->next; |
| 792 | } |
| 793 | spin_unlock_bh(&rose_route_list_lock); |
| 794 | } |
| 795 | |
| 796 | /* |
| 797 | * A level 2 link has timed out, therefore it appears to be a poor link, |
| 798 | * then don't use that neighbour until it is reset. Blow away all through |
| 799 | * routes and connections using this route. |
| 800 | */ |
| 801 | void rose_link_failed(ax25_cb *ax25, int reason) |
| 802 | { |
| 803 | struct rose_neigh *rose_neigh; |
| 804 | |
| 805 | spin_lock_bh(&rose_neigh_list_lock); |
| 806 | rose_neigh = rose_neigh_list; |
| 807 | while (rose_neigh != NULL) { |
| 808 | if (rose_neigh->ax25 == ax25) |
| 809 | break; |
| 810 | rose_neigh = rose_neigh->next; |
| 811 | } |
| 812 | |
| 813 | if (rose_neigh != NULL) { |
| 814 | rose_neigh->ax25 = NULL; |
| 815 | |
| 816 | rose_del_route_by_neigh(rose_neigh); |
| 817 | rose_kill_by_neigh(rose_neigh); |
| 818 | } |
| 819 | spin_unlock_bh(&rose_neigh_list_lock); |
| 820 | } |
| 821 | |
| 822 | /* |
| 823 | * A device has been "downed" remove its link status. Blow away all |
| 824 | * through routes and connections that use this device. |
| 825 | */ |
| 826 | void rose_link_device_down(struct net_device *dev) |
| 827 | { |
| 828 | struct rose_neigh *rose_neigh; |
| 829 | |
| 830 | for (rose_neigh = rose_neigh_list; rose_neigh != NULL; rose_neigh = rose_neigh->next) { |
| 831 | if (rose_neigh->dev == dev) { |
| 832 | rose_del_route_by_neigh(rose_neigh); |
| 833 | rose_kill_by_neigh(rose_neigh); |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | /* |
| 839 | * Route a frame to an appropriate AX.25 connection. |
| 840 | */ |
| 841 | int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25) |
| 842 | { |
| 843 | struct rose_neigh *rose_neigh, *new_neigh; |
| 844 | struct rose_route *rose_route; |
| 845 | struct rose_facilities_struct facilities; |
| 846 | rose_address *src_addr, *dest_addr; |
| 847 | struct sock *sk; |
| 848 | unsigned short frametype; |
| 849 | unsigned int lci, new_lci; |
| 850 | unsigned char cause, diagnostic; |
| 851 | struct net_device *dev; |
| 852 | int len, res = 0; |
Ralf Baechle | f75268c | 2005-09-06 15:49:39 -0700 | [diff] [blame] | 853 | char buf[11]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | |
| 855 | #if 0 |
| 856 | if (call_in_firewall(PF_ROSE, skb->dev, skb->data, NULL, &skb) != FW_ACCEPT) |
| 857 | return res; |
| 858 | #endif |
| 859 | |
| 860 | frametype = skb->data[2]; |
| 861 | lci = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF); |
| 862 | src_addr = (rose_address *)(skb->data + 9); |
| 863 | dest_addr = (rose_address *)(skb->data + 4); |
| 864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | spin_lock_bh(&rose_neigh_list_lock); |
| 866 | spin_lock_bh(&rose_route_list_lock); |
| 867 | |
| 868 | rose_neigh = rose_neigh_list; |
| 869 | while (rose_neigh != NULL) { |
| 870 | if (ax25cmp(&ax25->dest_addr, &rose_neigh->callsign) == 0 && |
| 871 | ax25->ax25_dev->dev == rose_neigh->dev) |
| 872 | break; |
| 873 | rose_neigh = rose_neigh->next; |
| 874 | } |
| 875 | |
| 876 | if (rose_neigh == NULL) { |
| 877 | printk("rose_route : unknown neighbour or device %s\n", |
Ralf Baechle | f75268c | 2005-09-06 15:49:39 -0700 | [diff] [blame] | 878 | ax2asc(buf, &ax25->dest_addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | goto out; |
| 880 | } |
| 881 | |
| 882 | /* |
| 883 | * Obviously the link is working, halt the ftimer. |
| 884 | */ |
| 885 | rose_stop_ftimer(rose_neigh); |
| 886 | |
| 887 | /* |
| 888 | * LCI of zero is always for us, and its always a restart |
| 889 | * frame. |
| 890 | */ |
| 891 | if (lci == 0) { |
| 892 | rose_link_rx_restart(skb, rose_neigh, frametype); |
| 893 | goto out; |
| 894 | } |
| 895 | |
| 896 | /* |
| 897 | * Find an existing socket. |
| 898 | */ |
| 899 | if ((sk = rose_find_socket(lci, rose_neigh)) != NULL) { |
| 900 | if (frametype == ROSE_CALL_REQUEST) { |
| 901 | struct rose_sock *rose = rose_sk(sk); |
| 902 | |
| 903 | /* Remove an existing unused socket */ |
| 904 | rose_clear_queues(sk); |
| 905 | rose->cause = ROSE_NETWORK_CONGESTION; |
| 906 | rose->diagnostic = 0; |
| 907 | rose->neighbour->use--; |
| 908 | rose->neighbour = NULL; |
| 909 | rose->lci = 0; |
| 910 | rose->state = ROSE_STATE_0; |
| 911 | sk->sk_state = TCP_CLOSE; |
| 912 | sk->sk_err = 0; |
| 913 | sk->sk_shutdown |= SEND_SHUTDOWN; |
| 914 | if (!sock_flag(sk, SOCK_DEAD)) { |
| 915 | sk->sk_state_change(sk); |
| 916 | sock_set_flag(sk, SOCK_DEAD); |
| 917 | } |
| 918 | } |
| 919 | else { |
Arnaldo Carvalho de Melo | badff6d | 2007-03-13 13:06:52 -0300 | [diff] [blame] | 920 | skb_reset_transport_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | res = rose_process_rx_frame(sk, skb); |
| 922 | goto out; |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | /* |
| 927 | * Is is a Call Request and is it for us ? |
| 928 | */ |
| 929 | if (frametype == ROSE_CALL_REQUEST) |
| 930 | if ((dev = rose_dev_get(dest_addr)) != NULL) { |
| 931 | res = rose_rx_call_request(skb, dev, rose_neigh, lci); |
| 932 | dev_put(dev); |
| 933 | goto out; |
| 934 | } |
| 935 | |
| 936 | if (!sysctl_rose_routing_control) { |
| 937 | rose_transmit_clear_request(rose_neigh, lci, ROSE_NOT_OBTAINABLE, 0); |
| 938 | goto out; |
| 939 | } |
| 940 | |
| 941 | /* |
| 942 | * Route it to the next in line if we have an entry for it. |
| 943 | */ |
| 944 | rose_route = rose_route_list; |
| 945 | while (rose_route != NULL) { |
| 946 | if (rose_route->lci1 == lci && |
| 947 | rose_route->neigh1 == rose_neigh) { |
| 948 | if (frametype == ROSE_CALL_REQUEST) { |
| 949 | /* F6FBB - Remove an existing unused route */ |
| 950 | rose_remove_route(rose_route); |
| 951 | break; |
| 952 | } else if (rose_route->neigh2 != NULL) { |
| 953 | skb->data[0] &= 0xF0; |
| 954 | skb->data[0] |= (rose_route->lci2 >> 8) & 0x0F; |
| 955 | skb->data[1] = (rose_route->lci2 >> 0) & 0xFF; |
| 956 | rose_transmit_link(skb, rose_route->neigh2); |
| 957 | if (frametype == ROSE_CLEAR_CONFIRMATION) |
| 958 | rose_remove_route(rose_route); |
| 959 | res = 1; |
| 960 | goto out; |
| 961 | } else { |
| 962 | if (frametype == ROSE_CLEAR_CONFIRMATION) |
| 963 | rose_remove_route(rose_route); |
| 964 | goto out; |
| 965 | } |
| 966 | } |
| 967 | if (rose_route->lci2 == lci && |
| 968 | rose_route->neigh2 == rose_neigh) { |
| 969 | if (frametype == ROSE_CALL_REQUEST) { |
| 970 | /* F6FBB - Remove an existing unused route */ |
| 971 | rose_remove_route(rose_route); |
| 972 | break; |
| 973 | } else if (rose_route->neigh1 != NULL) { |
| 974 | skb->data[0] &= 0xF0; |
| 975 | skb->data[0] |= (rose_route->lci1 >> 8) & 0x0F; |
| 976 | skb->data[1] = (rose_route->lci1 >> 0) & 0xFF; |
| 977 | rose_transmit_link(skb, rose_route->neigh1); |
| 978 | if (frametype == ROSE_CLEAR_CONFIRMATION) |
| 979 | rose_remove_route(rose_route); |
| 980 | res = 1; |
| 981 | goto out; |
| 982 | } else { |
| 983 | if (frametype == ROSE_CLEAR_CONFIRMATION) |
| 984 | rose_remove_route(rose_route); |
| 985 | goto out; |
| 986 | } |
| 987 | } |
| 988 | rose_route = rose_route->next; |
| 989 | } |
| 990 | |
| 991 | /* |
| 992 | * We know that: |
| 993 | * 1. The frame isn't for us, |
| 994 | * 2. It isn't "owned" by any existing route. |
| 995 | */ |
David S. Miller | dc16aaf | 2005-08-23 10:50:09 -0700 | [diff] [blame] | 996 | if (frametype != ROSE_CALL_REQUEST) { /* XXX */ |
David S. Miller | c1cc168 | 2005-08-23 14:55:32 -0700 | [diff] [blame] | 997 | res = 0; |
David S. Miller | dc16aaf | 2005-08-23 10:50:09 -0700 | [diff] [blame] | 998 | goto out; |
| 999 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
Eric Dumazet | 95b7d92 | 2008-01-15 03:30:35 -0800 | [diff] [blame] | 1001 | len = (((skb->data[3] >> 4) & 0x0F) + 1) >> 1; |
| 1002 | len += (((skb->data[3] >> 0) & 0x0F) + 1) >> 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | |
| 1004 | memset(&facilities, 0x00, sizeof(struct rose_facilities_struct)); |
| 1005 | |
| 1006 | if (!rose_parse_facilities(skb->data + len + 4, &facilities)) { |
| 1007 | rose_transmit_clear_request(rose_neigh, lci, ROSE_INVALID_FACILITY, 76); |
| 1008 | goto out; |
| 1009 | } |
| 1010 | |
| 1011 | /* |
| 1012 | * Check for routing loops. |
| 1013 | */ |
| 1014 | rose_route = rose_route_list; |
| 1015 | while (rose_route != NULL) { |
| 1016 | if (rose_route->rand == facilities.rand && |
| 1017 | rosecmp(src_addr, &rose_route->src_addr) == 0 && |
| 1018 | ax25cmp(&facilities.dest_call, &rose_route->src_call) == 0 && |
| 1019 | ax25cmp(&facilities.source_call, &rose_route->dest_call) == 0) { |
| 1020 | rose_transmit_clear_request(rose_neigh, lci, ROSE_NOT_OBTAINABLE, 120); |
| 1021 | goto out; |
| 1022 | } |
| 1023 | rose_route = rose_route->next; |
| 1024 | } |
| 1025 | |
Bernard Pidoux | fe2c802 | 2008-06-17 17:08:32 -0700 | [diff] [blame] | 1026 | if ((new_neigh = rose_get_neigh(dest_addr, &cause, &diagnostic, 1)) == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | rose_transmit_clear_request(rose_neigh, lci, cause, diagnostic); |
| 1028 | goto out; |
| 1029 | } |
| 1030 | |
| 1031 | if ((new_lci = rose_new_lci(new_neigh)) == 0) { |
| 1032 | rose_transmit_clear_request(rose_neigh, lci, ROSE_NETWORK_CONGESTION, 71); |
| 1033 | goto out; |
| 1034 | } |
| 1035 | |
| 1036 | if ((rose_route = kmalloc(sizeof(*rose_route), GFP_ATOMIC)) == NULL) { |
| 1037 | rose_transmit_clear_request(rose_neigh, lci, ROSE_NETWORK_CONGESTION, 120); |
| 1038 | goto out; |
| 1039 | } |
| 1040 | |
| 1041 | rose_route->lci1 = lci; |
| 1042 | rose_route->src_addr = *src_addr; |
| 1043 | rose_route->dest_addr = *dest_addr; |
| 1044 | rose_route->src_call = facilities.dest_call; |
| 1045 | rose_route->dest_call = facilities.source_call; |
| 1046 | rose_route->rand = facilities.rand; |
| 1047 | rose_route->neigh1 = rose_neigh; |
| 1048 | rose_route->lci2 = new_lci; |
| 1049 | rose_route->neigh2 = new_neigh; |
| 1050 | |
| 1051 | rose_route->neigh1->use++; |
| 1052 | rose_route->neigh2->use++; |
| 1053 | |
| 1054 | rose_route->next = rose_route_list; |
| 1055 | rose_route_list = rose_route; |
| 1056 | |
| 1057 | skb->data[0] &= 0xF0; |
| 1058 | skb->data[0] |= (rose_route->lci2 >> 8) & 0x0F; |
| 1059 | skb->data[1] = (rose_route->lci2 >> 0) & 0xFF; |
| 1060 | |
| 1061 | rose_transmit_link(skb, rose_route->neigh2); |
| 1062 | res = 1; |
| 1063 | |
| 1064 | out: |
| 1065 | spin_unlock_bh(&rose_route_list_lock); |
| 1066 | spin_unlock_bh(&rose_neigh_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | |
| 1068 | return res; |
| 1069 | } |
| 1070 | |
| 1071 | #ifdef CONFIG_PROC_FS |
| 1072 | |
| 1073 | static void *rose_node_start(struct seq_file *seq, loff_t *pos) |
Bernard Pidoux | f37f2c6 | 2008-05-02 17:03:22 -0700 | [diff] [blame] | 1074 | __acquires(rose_node_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | { |
| 1076 | struct rose_node *rose_node; |
| 1077 | int i = 1; |
| 1078 | |
Bernard Pidoux | f37f2c6 | 2008-05-02 17:03:22 -0700 | [diff] [blame] | 1079 | spin_lock_bh(&rose_node_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | if (*pos == 0) |
| 1081 | return SEQ_START_TOKEN; |
| 1082 | |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 1083 | for (rose_node = rose_node_list; rose_node && i < *pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | rose_node = rose_node->next, ++i); |
| 1085 | |
| 1086 | return (i == *pos) ? rose_node : NULL; |
| 1087 | } |
| 1088 | |
| 1089 | static void *rose_node_next(struct seq_file *seq, void *v, loff_t *pos) |
| 1090 | { |
| 1091 | ++*pos; |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 1092 | |
| 1093 | return (v == SEQ_START_TOKEN) ? rose_node_list |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | : ((struct rose_node *)v)->next; |
| 1095 | } |
| 1096 | |
| 1097 | static void rose_node_stop(struct seq_file *seq, void *v) |
Bernard Pidoux | f37f2c6 | 2008-05-02 17:03:22 -0700 | [diff] [blame] | 1098 | __releases(rose_node_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | { |
Bernard Pidoux | f37f2c6 | 2008-05-02 17:03:22 -0700 | [diff] [blame] | 1100 | spin_unlock_bh(&rose_node_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | static int rose_node_show(struct seq_file *seq, void *v) |
| 1104 | { |
Ralf Baechle | dcf777f | 2009-07-26 19:11:14 -0700 | [diff] [blame] | 1105 | char rsbuf[11]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | int i; |
| 1107 | |
| 1108 | if (v == SEQ_START_TOKEN) |
| 1109 | seq_puts(seq, "address mask n neigh neigh neigh\n"); |
| 1110 | else { |
| 1111 | const struct rose_node *rose_node = v; |
| 1112 | /* if (rose_node->loopback) { |
| 1113 | seq_printf(seq, "%-10s %04d 1 loopback\n", |
Ralf Baechle | dcf777f | 2009-07-26 19:11:14 -0700 | [diff] [blame] | 1114 | rose2asc(rsbuf, &rose_node->address), |
| 1115 | rose_node->mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | } else { */ |
| 1117 | seq_printf(seq, "%-10s %04d %d", |
Ralf Baechle | dcf777f | 2009-07-26 19:11:14 -0700 | [diff] [blame] | 1118 | rose2asc(rsbuf, &rose_node->address), |
| 1119 | rose_node->mask, |
| 1120 | rose_node->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | |
| 1122 | for (i = 0; i < rose_node->count; i++) |
| 1123 | seq_printf(seq, " %05d", |
| 1124 | rose_node->neighbour[i]->number); |
| 1125 | |
| 1126 | seq_puts(seq, "\n"); |
| 1127 | /* } */ |
| 1128 | } |
| 1129 | return 0; |
| 1130 | } |
| 1131 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 1132 | static const struct seq_operations rose_node_seqops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | .start = rose_node_start, |
| 1134 | .next = rose_node_next, |
| 1135 | .stop = rose_node_stop, |
| 1136 | .show = rose_node_show, |
| 1137 | }; |
| 1138 | |
| 1139 | static int rose_nodes_open(struct inode *inode, struct file *file) |
| 1140 | { |
| 1141 | return seq_open(file, &rose_node_seqops); |
| 1142 | } |
| 1143 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 1144 | const struct file_operations rose_nodes_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | .owner = THIS_MODULE, |
| 1146 | .open = rose_nodes_open, |
| 1147 | .read = seq_read, |
| 1148 | .llseek = seq_lseek, |
| 1149 | .release = seq_release, |
| 1150 | }; |
| 1151 | |
| 1152 | static void *rose_neigh_start(struct seq_file *seq, loff_t *pos) |
Eric Dumazet | 95b7d92 | 2008-01-15 03:30:35 -0800 | [diff] [blame] | 1153 | __acquires(rose_neigh_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | { |
| 1155 | struct rose_neigh *rose_neigh; |
| 1156 | int i = 1; |
| 1157 | |
| 1158 | spin_lock_bh(&rose_neigh_list_lock); |
| 1159 | if (*pos == 0) |
| 1160 | return SEQ_START_TOKEN; |
| 1161 | |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 1162 | for (rose_neigh = rose_neigh_list; rose_neigh && i < *pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | rose_neigh = rose_neigh->next, ++i); |
| 1164 | |
| 1165 | return (i == *pos) ? rose_neigh : NULL; |
| 1166 | } |
| 1167 | |
| 1168 | static void *rose_neigh_next(struct seq_file *seq, void *v, loff_t *pos) |
| 1169 | { |
| 1170 | ++*pos; |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 1171 | |
| 1172 | return (v == SEQ_START_TOKEN) ? rose_neigh_list |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | : ((struct rose_neigh *)v)->next; |
| 1174 | } |
| 1175 | |
| 1176 | static void rose_neigh_stop(struct seq_file *seq, void *v) |
Eric Dumazet | 95b7d92 | 2008-01-15 03:30:35 -0800 | [diff] [blame] | 1177 | __releases(rose_neigh_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | { |
| 1179 | spin_unlock_bh(&rose_neigh_list_lock); |
| 1180 | } |
| 1181 | |
| 1182 | static int rose_neigh_show(struct seq_file *seq, void *v) |
| 1183 | { |
Ralf Baechle | f75268c | 2005-09-06 15:49:39 -0700 | [diff] [blame] | 1184 | char buf[11]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | int i; |
| 1186 | |
| 1187 | if (v == SEQ_START_TOKEN) |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 1188 | seq_puts(seq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | "addr callsign dev count use mode restart t0 tf digipeaters\n"); |
| 1190 | else { |
| 1191 | struct rose_neigh *rose_neigh = v; |
| 1192 | |
| 1193 | /* if (!rose_neigh->loopback) { */ |
| 1194 | seq_printf(seq, "%05d %-9s %-4s %3d %3d %3s %3s %3lu %3lu", |
| 1195 | rose_neigh->number, |
Ralf Baechle | f75268c | 2005-09-06 15:49:39 -0700 | [diff] [blame] | 1196 | (rose_neigh->loopback) ? "RSLOOP-0" : ax2asc(buf, &rose_neigh->callsign), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | rose_neigh->dev ? rose_neigh->dev->name : "???", |
| 1198 | rose_neigh->count, |
| 1199 | rose_neigh->use, |
| 1200 | (rose_neigh->dce_mode) ? "DCE" : "DTE", |
| 1201 | (rose_neigh->restarted) ? "yes" : "no", |
| 1202 | ax25_display_timer(&rose_neigh->t0timer) / HZ, |
| 1203 | ax25_display_timer(&rose_neigh->ftimer) / HZ); |
| 1204 | |
| 1205 | if (rose_neigh->digipeat != NULL) { |
| 1206 | for (i = 0; i < rose_neigh->digipeat->ndigi; i++) |
Ralf Baechle | f75268c | 2005-09-06 15:49:39 -0700 | [diff] [blame] | 1207 | seq_printf(seq, " %s", ax2asc(buf, &rose_neigh->digipeat->calls[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | seq_puts(seq, "\n"); |
| 1211 | } |
| 1212 | return 0; |
| 1213 | } |
| 1214 | |
| 1215 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 1216 | static const struct seq_operations rose_neigh_seqops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | .start = rose_neigh_start, |
| 1218 | .next = rose_neigh_next, |
| 1219 | .stop = rose_neigh_stop, |
| 1220 | .show = rose_neigh_show, |
| 1221 | }; |
| 1222 | |
| 1223 | static int rose_neigh_open(struct inode *inode, struct file *file) |
| 1224 | { |
| 1225 | return seq_open(file, &rose_neigh_seqops); |
| 1226 | } |
| 1227 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 1228 | const struct file_operations rose_neigh_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | .owner = THIS_MODULE, |
| 1230 | .open = rose_neigh_open, |
| 1231 | .read = seq_read, |
| 1232 | .llseek = seq_lseek, |
| 1233 | .release = seq_release, |
| 1234 | }; |
| 1235 | |
| 1236 | |
| 1237 | static void *rose_route_start(struct seq_file *seq, loff_t *pos) |
Eric Dumazet | 95b7d92 | 2008-01-15 03:30:35 -0800 | [diff] [blame] | 1238 | __acquires(rose_route_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | { |
| 1240 | struct rose_route *rose_route; |
| 1241 | int i = 1; |
| 1242 | |
| 1243 | spin_lock_bh(&rose_route_list_lock); |
| 1244 | if (*pos == 0) |
| 1245 | return SEQ_START_TOKEN; |
| 1246 | |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 1247 | for (rose_route = rose_route_list; rose_route && i < *pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | rose_route = rose_route->next, ++i); |
| 1249 | |
| 1250 | return (i == *pos) ? rose_route : NULL; |
| 1251 | } |
| 1252 | |
| 1253 | static void *rose_route_next(struct seq_file *seq, void *v, loff_t *pos) |
| 1254 | { |
| 1255 | ++*pos; |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 1256 | |
| 1257 | return (v == SEQ_START_TOKEN) ? rose_route_list |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | : ((struct rose_route *)v)->next; |
| 1259 | } |
| 1260 | |
| 1261 | static void rose_route_stop(struct seq_file *seq, void *v) |
Eric Dumazet | 95b7d92 | 2008-01-15 03:30:35 -0800 | [diff] [blame] | 1262 | __releases(rose_route_list_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | { |
| 1264 | spin_unlock_bh(&rose_route_list_lock); |
| 1265 | } |
| 1266 | |
| 1267 | static int rose_route_show(struct seq_file *seq, void *v) |
| 1268 | { |
Ralf Baechle | dcf777f | 2009-07-26 19:11:14 -0700 | [diff] [blame] | 1269 | char buf[11], rsbuf[11]; |
Ralf Baechle | f75268c | 2005-09-06 15:49:39 -0700 | [diff] [blame] | 1270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | if (v == SEQ_START_TOKEN) |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 1272 | seq_puts(seq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | "lci address callsign neigh <-> lci address callsign neigh\n"); |
| 1274 | else { |
| 1275 | struct rose_route *rose_route = v; |
| 1276 | |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 1277 | if (rose_route->neigh1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | seq_printf(seq, |
| 1279 | "%3.3X %-10s %-9s %05d ", |
| 1280 | rose_route->lci1, |
Ralf Baechle | dcf777f | 2009-07-26 19:11:14 -0700 | [diff] [blame] | 1281 | rose2asc(rsbuf, &rose_route->src_addr), |
Ralf Baechle | f75268c | 2005-09-06 15:49:39 -0700 | [diff] [blame] | 1282 | ax2asc(buf, &rose_route->src_call), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | rose_route->neigh1->number); |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 1284 | else |
| 1285 | seq_puts(seq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | "000 * * 00000 "); |
| 1287 | |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 1288 | if (rose_route->neigh2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | seq_printf(seq, |
| 1290 | "%3.3X %-10s %-9s %05d\n", |
Ralf Baechle | dcf777f | 2009-07-26 19:11:14 -0700 | [diff] [blame] | 1291 | rose_route->lci2, |
| 1292 | rose2asc(rsbuf, &rose_route->dest_addr), |
| 1293 | ax2asc(buf, &rose_route->dest_call), |
| 1294 | rose_route->neigh2->number); |
YOSHIFUJI Hideaki | 3dcf7c5 | 2007-02-09 23:25:12 +0900 | [diff] [blame] | 1295 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | seq_puts(seq, |
| 1297 | "000 * * 00000\n"); |
| 1298 | } |
| 1299 | return 0; |
| 1300 | } |
| 1301 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 1302 | static const struct seq_operations rose_route_seqops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | .start = rose_route_start, |
| 1304 | .next = rose_route_next, |
| 1305 | .stop = rose_route_stop, |
| 1306 | .show = rose_route_show, |
| 1307 | }; |
| 1308 | |
| 1309 | static int rose_route_open(struct inode *inode, struct file *file) |
| 1310 | { |
| 1311 | return seq_open(file, &rose_route_seqops); |
| 1312 | } |
| 1313 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 1314 | const struct file_operations rose_routes_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | .owner = THIS_MODULE, |
| 1316 | .open = rose_route_open, |
| 1317 | .read = seq_read, |
| 1318 | .llseek = seq_lseek, |
| 1319 | .release = seq_release, |
| 1320 | }; |
| 1321 | |
| 1322 | #endif /* CONFIG_PROC_FS */ |
| 1323 | |
| 1324 | /* |
| 1325 | * Release all memory associated with ROSE routing structures. |
| 1326 | */ |
| 1327 | void __exit rose_rt_free(void) |
| 1328 | { |
| 1329 | struct rose_neigh *s, *rose_neigh = rose_neigh_list; |
| 1330 | struct rose_node *t, *rose_node = rose_node_list; |
| 1331 | struct rose_route *u, *rose_route = rose_route_list; |
| 1332 | |
| 1333 | while (rose_neigh != NULL) { |
| 1334 | s = rose_neigh; |
| 1335 | rose_neigh = rose_neigh->next; |
| 1336 | |
| 1337 | rose_remove_neigh(s); |
| 1338 | } |
| 1339 | |
| 1340 | while (rose_node != NULL) { |
| 1341 | t = rose_node; |
| 1342 | rose_node = rose_node->next; |
| 1343 | |
| 1344 | rose_remove_node(t); |
| 1345 | } |
| 1346 | |
| 1347 | while (rose_route != NULL) { |
| 1348 | u = rose_route; |
| 1349 | rose_route = rose_route->next; |
| 1350 | |
| 1351 | rose_remove_route(u); |
| 1352 | } |
| 1353 | } |