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.
7 * Copyright Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
8 * Copyright Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
9 * Copyright Tomi Manninen OH2BNS (oh2bns@sral.fi)
11 #include <linux/errno.h>
12 #include <linux/types.h>
13 #include <linux/socket.h>
15 #include <linux/kernel.h>
16 #include <linux/timer.h>
17 #include <linux/string.h>
18 #include <linux/sockios.h>
19 #include <linux/net.h>
20 #include <linux/slab.h>
22 #include <linux/inet.h>
23 #include <linux/netdevice.h>
25 #include <linux/if_arp.h>
26 #include <linux/skbuff.h>
28 #include <linux/uaccess.h>
29 #include <linux/fcntl.h>
30 #include <linux/termios.h> /* For TIOCINQ/OUTQ */
32 #include <linux/interrupt.h>
33 #include <linux/notifier.h>
34 #include <linux/init.h>
35 #include <linux/spinlock.h>
36 #include <net/netrom.h>
37 #include <linux/seq_file.h>
38 #include <linux/export.h>
40 static unsigned int nr_neigh_no
= 1;
42 static HLIST_HEAD(nr_node_list
);
43 static DEFINE_SPINLOCK(nr_node_list_lock
);
44 static HLIST_HEAD(nr_neigh_list
);
45 static DEFINE_SPINLOCK(nr_neigh_list_lock
);
47 static struct nr_node
*nr_node_get(ax25_address
*callsign
)
49 struct nr_node
*found
= NULL
;
50 struct nr_node
*nr_node
;
52 spin_lock_bh(&nr_node_list_lock
);
53 nr_node_for_each(nr_node
, &nr_node_list
)
54 if (ax25cmp(callsign
, &nr_node
->callsign
) == 0) {
55 nr_node_hold(nr_node
);
59 spin_unlock_bh(&nr_node_list_lock
);
63 static struct nr_neigh
*nr_neigh_get_dev(ax25_address
*callsign
,
64 struct net_device
*dev
)
66 struct nr_neigh
*found
= NULL
;
67 struct nr_neigh
*nr_neigh
;
69 spin_lock_bh(&nr_neigh_list_lock
);
70 nr_neigh_for_each(nr_neigh
, &nr_neigh_list
)
71 if (ax25cmp(callsign
, &nr_neigh
->callsign
) == 0 &&
72 nr_neigh
->dev
== dev
) {
73 nr_neigh_hold(nr_neigh
);
77 spin_unlock_bh(&nr_neigh_list_lock
);
81 static void nr_remove_neigh(struct nr_neigh
*);
83 /* re-sort the routes in quality order. */
84 static void re_sort_routes(struct nr_node
*nr_node
, int x
, int y
)
86 if (nr_node
->routes
[y
].quality
> nr_node
->routes
[x
].quality
) {
87 if (nr_node
->which
== x
)
89 else if (nr_node
->which
== y
)
92 swap(nr_node
->routes
[x
], nr_node
->routes
[y
]);
97 * Add a new route to a node, and in the process add the node and the
98 * neighbour if it is new.
100 static int __must_check
nr_add_node(ax25_address
*nr
, const char *mnemonic
,
101 ax25_address
*ax25
, ax25_digi
*ax25_digi
, struct net_device
*dev
,
102 int quality
, int obs_count
)
104 struct nr_node
*nr_node
;
105 struct nr_neigh
*nr_neigh
;
107 struct net_device
*odev
;
109 if ((odev
=nr_dev_get(nr
)) != NULL
) { /* Can't add routes to ourself */
114 nr_node
= nr_node_get(nr
);
116 nr_neigh
= nr_neigh_get_dev(ax25
, dev
);
119 * The L2 link to a neighbour has failed in the past
120 * and now a frame comes from this neighbour. We assume
121 * it was a temporary trouble with the link and reset the
122 * routes now (and not wait for a node broadcast).
124 if (nr_neigh
!= NULL
&& nr_neigh
->failed
!= 0 && quality
== 0) {
125 struct nr_node
*nr_nodet
;
127 spin_lock_bh(&nr_node_list_lock
);
128 nr_node_for_each(nr_nodet
, &nr_node_list
) {
129 nr_node_lock(nr_nodet
);
130 for (i
= 0; i
< nr_nodet
->count
; i
++)
131 if (nr_nodet
->routes
[i
].neighbour
== nr_neigh
)
132 if (i
< nr_nodet
->which
)
134 nr_node_unlock(nr_nodet
);
136 spin_unlock_bh(&nr_node_list_lock
);
139 if (nr_neigh
!= NULL
)
140 nr_neigh
->failed
= 0;
142 if (quality
== 0 && nr_neigh
!= NULL
&& nr_node
!= NULL
) {
143 nr_neigh_put(nr_neigh
);
144 nr_node_put(nr_node
);
148 if (nr_neigh
== NULL
) {
149 if ((nr_neigh
= kmalloc(sizeof(*nr_neigh
), GFP_ATOMIC
)) == NULL
) {
151 nr_node_put(nr_node
);
155 nr_neigh
->callsign
= *ax25
;
156 nr_neigh
->digipeat
= NULL
;
157 nr_neigh
->ax25
= NULL
;
159 nr_neigh
->quality
= sysctl_netrom_default_path_quality
;
160 nr_neigh
->locked
= 0;
162 nr_neigh
->number
= nr_neigh_no
++;
163 nr_neigh
->failed
= 0;
164 refcount_set(&nr_neigh
->refcount
, 1);
166 if (ax25_digi
!= NULL
&& ax25_digi
->ndigi
> 0) {
167 nr_neigh
->digipeat
= kmemdup(ax25_digi
,
170 if (nr_neigh
->digipeat
== NULL
) {
173 nr_node_put(nr_node
);
178 spin_lock_bh(&nr_neigh_list_lock
);
179 hlist_add_head(&nr_neigh
->neigh_node
, &nr_neigh_list
);
180 nr_neigh_hold(nr_neigh
);
181 spin_unlock_bh(&nr_neigh_list_lock
);
184 if (quality
!= 0 && ax25cmp(nr
, ax25
) == 0 && !nr_neigh
->locked
)
185 nr_neigh
->quality
= quality
;
187 if (nr_node
== NULL
) {
188 if ((nr_node
= kmalloc(sizeof(*nr_node
), GFP_ATOMIC
)) == NULL
) {
190 nr_neigh_put(nr_neigh
);
194 nr_node
->callsign
= *nr
;
195 strcpy(nr_node
->mnemonic
, mnemonic
);
199 refcount_set(&nr_node
->refcount
, 1);
200 spin_lock_init(&nr_node
->node_lock
);
202 nr_node
->routes
[0].quality
= quality
;
203 nr_node
->routes
[0].obs_count
= obs_count
;
204 nr_node
->routes
[0].neighbour
= nr_neigh
;
206 nr_neigh_hold(nr_neigh
);
209 spin_lock_bh(&nr_node_list_lock
);
210 hlist_add_head(&nr_node
->node_node
, &nr_node_list
);
211 /* refcount initialized at 1 */
212 spin_unlock_bh(&nr_node_list_lock
);
214 nr_neigh_put(nr_neigh
);
217 nr_node_lock(nr_node
);
220 strcpy(nr_node
->mnemonic
, mnemonic
);
222 for (found
= 0, i
= 0; i
< nr_node
->count
; i
++) {
223 if (nr_node
->routes
[i
].neighbour
== nr_neigh
) {
224 nr_node
->routes
[i
].quality
= quality
;
225 nr_node
->routes
[i
].obs_count
= obs_count
;
232 /* We have space at the bottom, slot it in */
233 if (nr_node
->count
< 3) {
234 nr_node
->routes
[2] = nr_node
->routes
[1];
235 nr_node
->routes
[1] = nr_node
->routes
[0];
237 nr_node
->routes
[0].quality
= quality
;
238 nr_node
->routes
[0].obs_count
= obs_count
;
239 nr_node
->routes
[0].neighbour
= nr_neigh
;
243 nr_neigh_hold(nr_neigh
);
246 /* It must be better than the worst */
247 if (quality
> nr_node
->routes
[2].quality
) {
248 nr_node
->routes
[2].neighbour
->count
--;
249 nr_neigh_put(nr_node
->routes
[2].neighbour
);
251 if (nr_node
->routes
[2].neighbour
->count
== 0 && !nr_node
->routes
[2].neighbour
->locked
)
252 nr_remove_neigh(nr_node
->routes
[2].neighbour
);
254 nr_node
->routes
[2].quality
= quality
;
255 nr_node
->routes
[2].obs_count
= obs_count
;
256 nr_node
->routes
[2].neighbour
= nr_neigh
;
258 nr_neigh_hold(nr_neigh
);
264 /* Now re-sort the routes in quality order */
265 switch (nr_node
->count
) {
267 re_sort_routes(nr_node
, 0, 1);
268 re_sort_routes(nr_node
, 1, 2);
271 re_sort_routes(nr_node
, 0, 1);
276 for (i
= 0; i
< nr_node
->count
; i
++) {
277 if (nr_node
->routes
[i
].neighbour
== nr_neigh
) {
278 if (i
< nr_node
->which
)
284 nr_neigh_put(nr_neigh
);
285 nr_node_unlock(nr_node
);
286 nr_node_put(nr_node
);
290 static inline void __nr_remove_node(struct nr_node
*nr_node
)
292 hlist_del_init(&nr_node
->node_node
);
293 nr_node_put(nr_node
);
296 #define nr_remove_node_locked(__node) \
297 __nr_remove_node(__node)
299 static void nr_remove_node(struct nr_node
*nr_node
)
301 spin_lock_bh(&nr_node_list_lock
);
302 __nr_remove_node(nr_node
);
303 spin_unlock_bh(&nr_node_list_lock
);
306 static inline void __nr_remove_neigh(struct nr_neigh
*nr_neigh
)
308 hlist_del_init(&nr_neigh
->neigh_node
);
309 nr_neigh_put(nr_neigh
);
312 #define nr_remove_neigh_locked(__neigh) \
313 __nr_remove_neigh(__neigh)
315 static void nr_remove_neigh(struct nr_neigh
*nr_neigh
)
317 spin_lock_bh(&nr_neigh_list_lock
);
318 __nr_remove_neigh(nr_neigh
);
319 spin_unlock_bh(&nr_neigh_list_lock
);
323 * "Delete" a node. Strictly speaking remove a route to a node. The node
324 * is only deleted if no routes are left to it.
326 static int nr_del_node(ax25_address
*callsign
, ax25_address
*neighbour
, struct net_device
*dev
)
328 struct nr_node
*nr_node
;
329 struct nr_neigh
*nr_neigh
;
332 nr_node
= nr_node_get(callsign
);
337 nr_neigh
= nr_neigh_get_dev(neighbour
, dev
);
339 if (nr_neigh
== NULL
) {
340 nr_node_put(nr_node
);
344 nr_node_lock(nr_node
);
345 for (i
= 0; i
< nr_node
->count
; i
++) {
346 if (nr_node
->routes
[i
].neighbour
== nr_neigh
) {
348 nr_neigh_put(nr_neigh
);
350 if (nr_neigh
->count
== 0 && !nr_neigh
->locked
)
351 nr_remove_neigh(nr_neigh
);
352 nr_neigh_put(nr_neigh
);
356 if (nr_node
->count
== 0) {
357 nr_remove_node(nr_node
);
361 nr_node
->routes
[0] = nr_node
->routes
[1];
364 nr_node
->routes
[1] = nr_node
->routes
[2];
368 nr_node_put(nr_node
);
370 nr_node_unlock(nr_node
);
375 nr_neigh_put(nr_neigh
);
376 nr_node_unlock(nr_node
);
377 nr_node_put(nr_node
);
383 * Lock a neighbour with a quality.
385 static int __must_check
nr_add_neigh(ax25_address
*callsign
,
386 ax25_digi
*ax25_digi
, struct net_device
*dev
, unsigned int quality
)
388 struct nr_neigh
*nr_neigh
;
390 nr_neigh
= nr_neigh_get_dev(callsign
, dev
);
392 nr_neigh
->quality
= quality
;
393 nr_neigh
->locked
= 1;
394 nr_neigh_put(nr_neigh
);
398 if ((nr_neigh
= kmalloc(sizeof(*nr_neigh
), GFP_ATOMIC
)) == NULL
)
401 nr_neigh
->callsign
= *callsign
;
402 nr_neigh
->digipeat
= NULL
;
403 nr_neigh
->ax25
= NULL
;
405 nr_neigh
->quality
= quality
;
406 nr_neigh
->locked
= 1;
408 nr_neigh
->number
= nr_neigh_no
++;
409 nr_neigh
->failed
= 0;
410 refcount_set(&nr_neigh
->refcount
, 1);
412 if (ax25_digi
!= NULL
&& ax25_digi
->ndigi
> 0) {
413 nr_neigh
->digipeat
= kmemdup(ax25_digi
, sizeof(*ax25_digi
),
415 if (nr_neigh
->digipeat
== NULL
) {
421 spin_lock_bh(&nr_neigh_list_lock
);
422 hlist_add_head(&nr_neigh
->neigh_node
, &nr_neigh_list
);
423 /* refcount is initialized at 1 */
424 spin_unlock_bh(&nr_neigh_list_lock
);
430 * "Delete" a neighbour. The neighbour is only removed if the number
431 * of nodes that may use it is zero.
433 static int nr_del_neigh(ax25_address
*callsign
, struct net_device
*dev
, unsigned int quality
)
435 struct nr_neigh
*nr_neigh
;
437 nr_neigh
= nr_neigh_get_dev(callsign
, dev
);
439 if (nr_neigh
== NULL
) return -EINVAL
;
441 nr_neigh
->quality
= quality
;
442 nr_neigh
->locked
= 0;
444 if (nr_neigh
->count
== 0)
445 nr_remove_neigh(nr_neigh
);
446 nr_neigh_put(nr_neigh
);
452 * Decrement the obsolescence count by one. If a route is reduced to a
453 * count of zero, remove it. Also remove any unlocked neighbours with
454 * zero nodes routing via it.
456 static int nr_dec_obs(void)
458 struct nr_neigh
*nr_neigh
;
460 struct hlist_node
*nodet
;
463 spin_lock_bh(&nr_node_list_lock
);
464 nr_node_for_each_safe(s
, nodet
, &nr_node_list
) {
466 for (i
= 0; i
< s
->count
; i
++) {
467 switch (s
->routes
[i
].obs_count
) {
468 case 0: /* A locked entry */
471 case 1: /* From 1 -> 0 */
472 nr_neigh
= s
->routes
[i
].neighbour
;
475 nr_neigh_put(nr_neigh
);
477 if (nr_neigh
->count
== 0 && !nr_neigh
->locked
)
478 nr_remove_neigh(nr_neigh
);
484 s
->routes
[0] = s
->routes
[1];
487 s
->routes
[1] = s
->routes
[2];
494 s
->routes
[i
].obs_count
--;
501 nr_remove_node_locked(s
);
504 spin_unlock_bh(&nr_node_list_lock
);
510 * A device has been removed. Remove its routes and neighbours.
512 void nr_rt_device_down(struct net_device
*dev
)
515 struct hlist_node
*nodet
, *node2t
;
519 spin_lock_bh(&nr_neigh_list_lock
);
520 nr_neigh_for_each_safe(s
, nodet
, &nr_neigh_list
) {
522 spin_lock_bh(&nr_node_list_lock
);
523 nr_node_for_each_safe(t
, node2t
, &nr_node_list
) {
525 for (i
= 0; i
< t
->count
; i
++) {
526 if (t
->routes
[i
].neighbour
== s
) {
531 t
->routes
[0] = t
->routes
[1];
534 t
->routes
[1] = t
->routes
[2];
542 nr_remove_node_locked(t
);
545 spin_unlock_bh(&nr_node_list_lock
);
547 nr_remove_neigh_locked(s
);
550 spin_unlock_bh(&nr_neigh_list_lock
);
554 * Check that the device given is a valid AX.25 interface that is "up".
555 * Or a valid ethernet interface with an AX.25 callsign binding.
557 static struct net_device
*nr_ax25_dev_get(char *devname
)
559 struct net_device
*dev
;
561 if ((dev
= dev_get_by_name(&init_net
, devname
)) == NULL
)
564 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_AX25
)
572 * Find the first active NET/ROM device, usually "nr0".
574 struct net_device
*nr_dev_first(void)
576 struct net_device
*dev
, *first
= NULL
;
579 for_each_netdev_rcu(&init_net
, dev
) {
580 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_NETROM
)
581 if (first
== NULL
|| strncmp(dev
->name
, first
->name
, 3) < 0)
592 * Find the NET/ROM device for the given callsign.
594 struct net_device
*nr_dev_get(ax25_address
*addr
)
596 struct net_device
*dev
;
599 for_each_netdev_rcu(&init_net
, dev
) {
600 if ((dev
->flags
& IFF_UP
) && dev
->type
== ARPHRD_NETROM
&&
601 ax25cmp(addr
, (ax25_address
*)dev
->dev_addr
) == 0) {
612 static ax25_digi
*nr_call_to_digi(ax25_digi
*digi
, int ndigis
,
613 ax25_address
*digipeaters
)
620 for (i
= 0; i
< ndigis
; i
++) {
621 digi
->calls
[i
] = digipeaters
[i
];
622 digi
->repeated
[i
] = 0;
625 digi
->ndigi
= ndigis
;
626 digi
->lastrepeat
= -1;
632 * Handle the ioctls that control the routing functions.
634 int nr_rt_ioctl(unsigned int cmd
, void __user
*arg
)
636 struct nr_route_struct nr_route
;
637 struct net_device
*dev
;
643 if (copy_from_user(&nr_route
, arg
, sizeof(struct nr_route_struct
)))
645 if (nr_route
.ndigis
> AX25_MAX_DIGIS
)
647 if ((dev
= nr_ax25_dev_get(nr_route
.device
)) == NULL
)
649 switch (nr_route
.type
) {
651 if (strnlen(nr_route
.mnemonic
, 7) == 7) {
656 ret
= nr_add_node(&nr_route
.callsign
,
659 nr_call_to_digi(&digi
, nr_route
.ndigis
,
660 nr_route
.digipeaters
),
661 dev
, nr_route
.quality
,
665 ret
= nr_add_neigh(&nr_route
.callsign
,
666 nr_call_to_digi(&digi
, nr_route
.ndigis
,
667 nr_route
.digipeaters
),
668 dev
, nr_route
.quality
);
677 if (copy_from_user(&nr_route
, arg
, sizeof(struct nr_route_struct
)))
679 if ((dev
= nr_ax25_dev_get(nr_route
.device
)) == NULL
)
681 switch (nr_route
.type
) {
683 ret
= nr_del_node(&nr_route
.callsign
,
684 &nr_route
.neighbour
, dev
);
687 ret
= nr_del_neigh(&nr_route
.callsign
,
688 dev
, nr_route
.quality
);
707 * A level 2 link has timed out, therefore it appears to be a poor link,
708 * then don't use that neighbour until it is reset.
710 void nr_link_failed(ax25_cb
*ax25
, int reason
)
712 struct nr_neigh
*s
, *nr_neigh
= NULL
;
713 struct nr_node
*nr_node
= NULL
;
715 spin_lock_bh(&nr_neigh_list_lock
);
716 nr_neigh_for_each(s
, &nr_neigh_list
) {
717 if (s
->ax25
== ax25
) {
723 spin_unlock_bh(&nr_neigh_list_lock
);
725 if (nr_neigh
== NULL
)
728 nr_neigh
->ax25
= NULL
;
731 if (++nr_neigh
->failed
< sysctl_netrom_link_fails_count
) {
732 nr_neigh_put(nr_neigh
);
735 spin_lock_bh(&nr_node_list_lock
);
736 nr_node_for_each(nr_node
, &nr_node_list
) {
737 nr_node_lock(nr_node
);
738 if (nr_node
->which
< nr_node
->count
&&
739 nr_node
->routes
[nr_node
->which
].neighbour
== nr_neigh
)
741 nr_node_unlock(nr_node
);
743 spin_unlock_bh(&nr_node_list_lock
);
744 nr_neigh_put(nr_neigh
);
748 * Route a frame to an appropriate AX.25 connection. A NULL ax25_cb
749 * indicates an internally generated frame.
751 int nr_route_frame(struct sk_buff
*skb
, ax25_cb
*ax25
)
753 ax25_address
*nr_src
, *nr_dest
;
754 struct nr_neigh
*nr_neigh
;
755 struct nr_node
*nr_node
;
756 struct net_device
*dev
;
760 struct sk_buff
*skbn
;
763 nr_src
= (ax25_address
*)(skb
->data
+ 0);
764 nr_dest
= (ax25_address
*)(skb
->data
+ 7);
767 ret
= nr_add_node(nr_src
, "", &ax25
->dest_addr
, ax25
->digipeat
,
768 ax25
->ax25_dev
->dev
, 0,
769 sysctl_netrom_obsolescence_count_initialiser
);
774 if ((dev
= nr_dev_get(nr_dest
)) != NULL
) { /* Its for me */
775 if (ax25
== NULL
) /* Its from me */
776 ret
= nr_loopback_queue(skb
);
778 ret
= nr_rx_frame(skb
, dev
);
783 if (!sysctl_netrom_routing_control
&& ax25
!= NULL
)
786 /* Its Time-To-Live has expired */
787 if (skb
->data
[14] == 1) {
791 nr_node
= nr_node_get(nr_dest
);
794 nr_node_lock(nr_node
);
796 if (nr_node
->which
>= nr_node
->count
) {
797 nr_node_unlock(nr_node
);
798 nr_node_put(nr_node
);
802 nr_neigh
= nr_node
->routes
[nr_node
->which
].neighbour
;
804 if ((dev
= nr_dev_first()) == NULL
) {
805 nr_node_unlock(nr_node
);
806 nr_node_put(nr_node
);
810 /* We are going to change the netrom headers so we should get our
811 own skb, we also did not know until now how much header space
812 we had to reserve... - RXQ */
813 if ((skbn
=skb_copy_expand(skb
, dev
->hard_header_len
, 0, GFP_ATOMIC
)) == NULL
) {
814 nr_node_unlock(nr_node
);
815 nr_node_put(nr_node
);
823 dptr
= skb_push(skb
, 1);
824 *dptr
= AX25_P_NETROM
;
826 ax25s
= nr_neigh
->ax25
;
827 nr_neigh
->ax25
= ax25_send_frame(skb
, 256,
828 (ax25_address
*)dev
->dev_addr
,
830 nr_neigh
->digipeat
, nr_neigh
->dev
);
835 ret
= (nr_neigh
->ax25
!= NULL
);
836 nr_node_unlock(nr_node
);
837 nr_node_put(nr_node
);
842 #ifdef CONFIG_PROC_FS
844 static void *nr_node_start(struct seq_file
*seq
, loff_t
*pos
)
846 spin_lock_bh(&nr_node_list_lock
);
847 return seq_hlist_start_head(&nr_node_list
, *pos
);
850 static void *nr_node_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
852 return seq_hlist_next(v
, &nr_node_list
, pos
);
855 static void nr_node_stop(struct seq_file
*seq
, void *v
)
857 spin_unlock_bh(&nr_node_list_lock
);
860 static int nr_node_show(struct seq_file
*seq
, void *v
)
865 if (v
== SEQ_START_TOKEN
)
867 "callsign mnemonic w n qual obs neigh qual obs neigh qual obs neigh\n");
869 struct nr_node
*nr_node
= hlist_entry(v
, struct nr_node
,
872 nr_node_lock(nr_node
);
873 seq_printf(seq
, "%-9s %-7s %d %d",
874 ax2asc(buf
, &nr_node
->callsign
),
875 (nr_node
->mnemonic
[0] == '\0') ? "*" : nr_node
->mnemonic
,
879 for (i
= 0; i
< nr_node
->count
; i
++) {
880 seq_printf(seq
, " %3d %d %05d",
881 nr_node
->routes
[i
].quality
,
882 nr_node
->routes
[i
].obs_count
,
883 nr_node
->routes
[i
].neighbour
->number
);
885 nr_node_unlock(nr_node
);
892 const struct seq_operations nr_node_seqops
= {
893 .start
= nr_node_start
,
894 .next
= nr_node_next
,
895 .stop
= nr_node_stop
,
896 .show
= nr_node_show
,
899 static void *nr_neigh_start(struct seq_file
*seq
, loff_t
*pos
)
901 spin_lock_bh(&nr_neigh_list_lock
);
902 return seq_hlist_start_head(&nr_neigh_list
, *pos
);
905 static void *nr_neigh_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
907 return seq_hlist_next(v
, &nr_neigh_list
, pos
);
910 static void nr_neigh_stop(struct seq_file
*seq
, void *v
)
912 spin_unlock_bh(&nr_neigh_list_lock
);
915 static int nr_neigh_show(struct seq_file
*seq
, void *v
)
920 if (v
== SEQ_START_TOKEN
)
921 seq_puts(seq
, "addr callsign dev qual lock count failed digipeaters\n");
923 struct nr_neigh
*nr_neigh
;
925 nr_neigh
= hlist_entry(v
, struct nr_neigh
, neigh_node
);
926 seq_printf(seq
, "%05d %-9s %-4s %3d %d %3d %3d",
928 ax2asc(buf
, &nr_neigh
->callsign
),
929 nr_neigh
->dev
? nr_neigh
->dev
->name
: "???",
935 if (nr_neigh
->digipeat
!= NULL
) {
936 for (i
= 0; i
< nr_neigh
->digipeat
->ndigi
; i
++)
937 seq_printf(seq
, " %s",
938 ax2asc(buf
, &nr_neigh
->digipeat
->calls
[i
]));
946 const struct seq_operations nr_neigh_seqops
= {
947 .start
= nr_neigh_start
,
948 .next
= nr_neigh_next
,
949 .stop
= nr_neigh_stop
,
950 .show
= nr_neigh_show
,
955 * Free all memory associated with the nodes and routes lists.
957 void nr_rt_free(void)
959 struct nr_neigh
*s
= NULL
;
960 struct nr_node
*t
= NULL
;
961 struct hlist_node
*nodet
;
963 spin_lock_bh(&nr_neigh_list_lock
);
964 spin_lock_bh(&nr_node_list_lock
);
965 nr_node_for_each_safe(t
, nodet
, &nr_node_list
) {
967 nr_remove_node_locked(t
);
970 nr_neigh_for_each_safe(s
, nodet
, &nr_neigh_list
) {
975 nr_remove_neigh_locked(s
);
977 spin_unlock_bh(&nr_node_list_lock
);
978 spin_unlock_bh(&nr_neigh_list_lock
);