3 * This module is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version
6 * 2 of the License, or (at your option) any later version.
9 * 03-01-2007 Added forwarding for x.25 Andrew Hendry
11 #include <linux/if_arp.h>
12 #include <linux/init.h>
15 struct list_head x25_forward_list
= LIST_HEAD_INIT(x25_forward_list
);
16 DEFINE_RWLOCK(x25_forward_list_lock
);
18 int x25_forward_call(struct x25_address
*dest_addr
, struct x25_neigh
*from
,
19 struct sk_buff
*skb
, int lci
)
22 struct x25_neigh
*neigh_new
= NULL
;
23 struct list_head
*entry
;
24 struct x25_forward
*x25_frwd
, *new_frwd
;
29 if ((rt
= x25_get_route(dest_addr
)) == NULL
)
32 if ((neigh_new
= x25_get_neigh(rt
->dev
)) == NULL
) {
33 /* This shouldnt happen, if it occurs somehow
34 * do something sensible
39 /* Avoid a loop. This is the normal exit path for a
40 * system with only one x.25 iface and default route
42 if (rt
->dev
== from
->dev
) {
46 /* Remote end sending a call request on an already
47 * established LCI? It shouldnt happen, just in case..
49 read_lock_bh(&x25_forward_list_lock
);
50 list_for_each(entry
, &x25_forward_list
) {
51 x25_frwd
= list_entry(entry
, struct x25_forward
, node
);
52 if (x25_frwd
->lci
== lci
) {
53 printk(KERN_WARNING
"X.25: call request for lci which is already registered!, transmitting but not registering new pair\n");
57 read_unlock_bh(&x25_forward_list_lock
);
59 /* Save the forwarding details for future traffic */
61 if ((new_frwd
= kmalloc(sizeof(struct x25_forward
),
62 GFP_ATOMIC
)) == NULL
){
67 new_frwd
->dev1
= rt
->dev
;
68 new_frwd
->dev2
= from
->dev
;
69 write_lock_bh(&x25_forward_list_lock
);
70 list_add(&new_frwd
->node
, &x25_forward_list
);
71 write_unlock_bh(&x25_forward_list_lock
);
74 /* Forward the call request */
75 if ( (skbn
= skb_clone(skb
, GFP_ATOMIC
)) == NULL
){
78 x25_transmit_link(skbn
, neigh_new
);
83 x25_neigh_put(neigh_new
);
93 int x25_forward_data(int lci
, struct x25_neigh
*from
, struct sk_buff
*skb
) {
95 struct x25_forward
*frwd
;
96 struct list_head
*entry
;
97 struct net_device
*peer
= NULL
;
102 read_lock_bh(&x25_forward_list_lock
);
103 list_for_each(entry
, &x25_forward_list
) {
104 frwd
= list_entry(entry
, struct x25_forward
, node
);
105 if (frwd
->lci
== lci
) {
106 /* The call is established, either side can send */
107 if (from
->dev
== frwd
->dev1
) {
115 read_unlock_bh(&x25_forward_list_lock
);
117 if ( (nb
= x25_get_neigh(peer
)) == NULL
)
120 if ( (skbn
= pskb_copy(skb
, GFP_ATOMIC
)) == NULL
){
124 x25_transmit_link(skbn
, nb
);
132 void x25_clear_forward_by_lci(unsigned int lci
)
134 struct x25_forward
*fwd
;
135 struct list_head
*entry
, *tmp
;
137 write_lock_bh(&x25_forward_list_lock
);
139 list_for_each_safe(entry
, tmp
, &x25_forward_list
) {
140 fwd
= list_entry(entry
, struct x25_forward
, node
);
141 if (fwd
->lci
== lci
) {
142 list_del(&fwd
->node
);
146 write_unlock_bh(&x25_forward_list_lock
);
150 void x25_clear_forward_by_dev(struct net_device
*dev
)
152 struct x25_forward
*fwd
;
153 struct list_head
*entry
, *tmp
;
155 write_lock_bh(&x25_forward_list_lock
);
157 list_for_each_safe(entry
, tmp
, &x25_forward_list
) {
158 fwd
= list_entry(entry
, struct x25_forward
, node
);
159 if ((fwd
->dev1
== dev
) || (fwd
->dev2
== dev
)){
160 list_del(&fwd
->node
);
164 write_unlock_bh(&x25_forward_list_lock
);