Skip to contentSkip to conversation

X.25: Adds call forwarding to X.25

PATCH Applied ahendry 3 participants 4 messages Jan 4, 2007 – Feb 8, 2007

Subsystems (3)
lore
Share & tools
lore

ahendry

author
#0 lore raw

PATCH 1/2 X.25: Adds call forwarding to X.25

Adds call forwarding to X.25, allowing it to operate like an X.25 router. Useful if one needs to manipulate X.25 traffic with tools like tc.
This is an update/cleanup based off a patch submitted by Daniel Ferenci a few years ago.

Worked ok with Cisco XoT, linux X.25 back to back, and some old NTUs/PADs.

include/net/x25.h +16 -0
diff -uprN -X linux-2.6.19/Documentation/dontdiff linux-2.6.19-vanilla/include/net/x25.h linux-2.6.19/include/net/x25.h
@@ -161,6 +161,14 @@ struct x25_sock {
 	unsigned long 		vc_facil_mask;	/* inc_call facilities mask */
 };
 
+struct x25_forward {
+	struct list_head	node;
+	unsigned int		lci;
+	struct net_device	*dev1;
+	struct net_device	*dev2;
+	atomic_t		refcnt;
+};
+
 static inline struct x25_sock *x25_sk(const struct sock *sk)
 {
 	return (struct x25_sock *)sk;
@@ -198,6 +206,12 @@ extern int x25_negotiate_facilities(stru
 				struct x25_dte_facilities *);
 extern void x25_limit_facilities(struct x25_facilities *, struct x25_neigh *);
 
+/* x25_forward.c */
+extern void x25_clear_forwards(struct net_device *);
+extern struct x25_neigh *x25_find_forward(int, struct x25_neigh *);
+extern int x25_forward_call(struct x25_address *, struct x25_neigh *,
+				struct sk_buff *, int);
+
 /* x25_in.c */
 extern int  x25_process_rx_frame(struct sock *, struct sk_buff *);
 extern int  x25_backlog_rcv(struct sock *, struct sk_buff *);
@@ -281,6 +295,8 @@ extern struct hlist_head x25_list;
 extern rwlock_t x25_list_lock;
 extern struct list_head x25_route_list;
 extern rwlock_t x25_route_list_lock;
+extern struct list_head x25_forward_list;
+extern rwlock_t x25_forward_list_lock;
 
 extern int x25_proc_init(void);
 extern void x25_proc_exit(void);
net/x25/af_x25.c +21 -3
diff -uprN -X linux-2.6.19/Documentation/dontdiff linux-2.6.19-vanilla/net/x25/af_x25.c linux-2.6.19/net/x25/af_x25.c
@@ -850,6 +850,9 @@ int x25_rx_call_request(struct sk_buff *
 	struct x25_dte_facilities dte_facilities;
 	int len, rc;
 
+	struct sk_buff *skbn;
+	skbn = skb_clone(skb, GFP_ATOMIC);
+
 	/*
 	 *	Remove the LCI and frame type.
 	 */
@@ -875,11 +878,23 @@ int x25_rx_call_request(struct sk_buff *
 	sk = x25_find_listener(&source_addr,skb);
 	skb_push(skb,len);
 
+	if (sk != NULL && sk_acceptq_is_full(sk)) {
+		goto out_sock_put;
+	}
+
 	/*
-	 *	We can't accept the Call Request.
+	 *	We dont have any listeners for this incoming call.
+	 *	Try forwarding it.
 	 */
-	if (sk == NULL || sk_acceptq_is_full(sk))
-		goto out_clear_request;
+	if (sk == NULL) {
+		if (x25_forward_call(&dest_addr, nb, skbn, lci) == 0) {
+			/* Call was fowarded, dont process it any more */
+			return 0;
+		} else {
+			/* No listeners, can't forward, clear the call */
+			goto out_clear_request;
+		}
+	}
 
 	/*
 	 *	Try to reach a compromise on the requested facilities.
@@ -1600,6 +1615,9 @@ void x25_kill_by_neigh(struct x25_neigh 
 			x25_disconnect(s, ENETUNREACH, 0, 0);
 
 	write_unlock_bh(&x25_list_lock);
+
+	/* Remove any related forwards */
+	x25_clear_forwards(nb->dev);
 }
 
 static int __init x25_init(void)
net/x25/Makefile +1 -1
diff -uprN -X linux-2.6.19/Documentation/dontdiff linux-2.6.19-vanilla/net/x25/Makefile linux-2.6.19/net/x25/Makefile
@@ -6,5 +6,5 @@ obj-$(CONFIG_X25) += x25.o
 
 x25-y			:= af_x25.o x25_dev.o x25_facilities.o x25_in.o \
 			   x25_link.o x25_out.o x25_route.o x25_subr.o \
-			   x25_timer.o x25_proc.o
+			   x25_timer.o x25_proc.o x25_forward.o
 x25-$(CONFIG_SYSCTL)	+= sysctl_net_x25.o
net/x25/x25_dev.c +13 -2
diff -uprN -X linux-2.6.19/Documentation/dontdiff linux-2.6.19-vanilla/net/x25/x25_dev.c linux-2.6.19/net/x25/x25_dev.c
@@ -29,6 +29,7 @@ static int x25_receive_data(struct sk_bu
 	struct sock *sk;
 	unsigned short frametype;
 	unsigned int lci;
+	struct x25_neigh *to_neigh;
 
 	frametype = skb->data[2];
         lci = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF);
@@ -66,9 +67,19 @@ static int x25_receive_data(struct sk_bu
 		return x25_rx_call_request(skb, nb, lci);
 
 	/*
-	 *	Its not a Call Request, nor is it a control frame.
-	 *      Let caller throw it away.
+	 * 	Its not a Call Request, nor is it a control frame.
+	 *	Can we forward it?
 	 */
+
+	if (( to_neigh = x25_find_forward(lci, nb)) != NULL) {
+		struct sk_buff *skbn = pskb_copy (skb, GFP_ATOMIC);
+		x25_transmit_link(skbn, to_neigh);
+		if (frametype == X25_CLEAR_CONFIRMATION) {
+			x25_clear_forwards(nb->dev);
+		}
+		return 1;
+	}
+
 /*
 	x25_transmit_clear_request(nb, lci, 0x0D);
 */
net/x25/x25_forward.c +115 -0

115 lines not on this page · raw message

net/x25/x25_route.c +3 -0
diff -uprN -X linux-2.6.19/Documentation/dontdiff linux-2.6.19-vanilla/net/x25/x25_route.c linux-2.6.19/net/x25/x25_route.c
@@ -119,6 +119,9 @@ void x25_route_device_down(struct net_de
 			__x25_remove_route(rt);
 	}
 	write_unlock_bh(&x25_route_list_lock);
+
+	/* Remove any related forwarding */
+	x25_clear_forwards(dev);
 }
 
 /*
#1 lore raw

net/x25/af_x25.c int x25_rx_call_request(struct sk_buff * · line 855

Quoted 3 lines
net/x25/af_x25.c +3 -0
+	struct sk_buff *skbn;
+	skbn = skb_clone(skb, GFP_ATOMIC);
+

If this fails then you starting passing NULL around. I'm also a bit confused as to where you free the copy in all the error cases ?

Is there any reason for creating skbn here rather than in skb_forward_call ?

author
#2 lore raw

PATCH RESEND 1/3 X.25: Add call forwarding

Adds call forwarding to X.25, allowing it to operate like an X.25 router. Useful if one needs to manipulate X.25 traffic with tools like tc.
This is an update/cleanup based off a patch submitted by Daniel Ferenci a few years ago.

Thanks Alan for the feedback.
Added the null check to the clones.
Moved the skb_clone's into the forwarding functions.

Worked ok with Cisco XoT, linux X.25 back to back, and some old NTUs/PADs.

include/net/x25.h +17 -0
diff -uprN -X linux-2.6.20/Documentation/dontdiff linux-2.6.20-vanilla.clean/include/net/x25.h linux-2.6.20/include/net/x25.h
@@ -161,6 +161,14 @@ struct x25_sock {
 	unsigned long 		vc_facil_mask;	/* inc_call facilities mask */
 };
 
+struct x25_forward {
+	struct list_head	node;
+	unsigned int		lci;
+	struct net_device	*dev1;
+	struct net_device	*dev2;
+	atomic_t		refcnt;
+};
+
 static inline struct x25_sock *x25_sk(const struct sock *sk)
 {
 	return (struct x25_sock *)sk;
@@ -198,6 +206,13 @@ extern int x25_negotiate_facilities(stru
 				struct x25_dte_facilities *);
 extern void x25_limit_facilities(struct x25_facilities *, struct x25_neigh *);
 
+/* x25_forward.c */
+extern void x25_clear_forward_by_lci(unsigned int lci);
+extern void x25_clear_forward_by_dev(struct net_device *);
+extern int x25_forward_data(int, struct x25_neigh *, struct sk_buff *);
+extern int x25_forward_call(struct x25_address *, struct x25_neigh *,
+				struct sk_buff *, int);
+
 /* x25_in.c */
 extern int  x25_process_rx_frame(struct sock *, struct sk_buff *);
 extern int  x25_backlog_rcv(struct sock *, struct sk_buff *);
@@ -282,6 +297,8 @@ extern struct hlist_head x25_list;
 extern rwlock_t x25_list_lock;
 extern struct list_head x25_route_list;
 extern rwlock_t x25_route_list_lock;
+extern struct list_head x25_forward_list;
+extern rwlock_t x25_forward_list_lock;
 
 extern int x25_proc_init(void);
 extern void x25_proc_exit(void);
net/x25/af_x25.c +25 -5
diff -uprN -X linux-2.6.20/Documentation/dontdiff linux-2.6.20-vanilla.clean/net/x25/af_x25.c linux-2.6.20/net/x25/af_x25.c
@@ -846,7 +846,7 @@ int x25_rx_call_request(struct sk_buff *
 	struct x25_address source_addr, dest_addr;
 	struct x25_facilities facilities;
 	struct x25_dte_facilities dte_facilities;
-	int len, rc;
+	int len, addr_len, rc;
 
 	/*
 	 *	Remove the LCI and frame type.
@@ -857,7 +857,8 @@ int x25_rx_call_request(struct sk_buff *
 	 *	Extract the X.25 addresses and convert them to ASCII strings,
 	 *	and remove them.
 	 */
-	skb_pull(skb, x25_addr_ntoa(skb->data, &source_addr, &dest_addr));
+	addr_len = x25_addr_ntoa(skb->data, &source_addr, &dest_addr);
+	skb_pull(skb, addr_len);
 
 	/*
 	 *	Get the length of the facilities, skip past them for the moment
@@ -873,11 +874,27 @@ int x25_rx_call_request(struct sk_buff *
 	sk = x25_find_listener(&source_addr,skb);
 	skb_push(skb,len);
 
+	if (sk != NULL && sk_acceptq_is_full(sk)) {
+		goto out_sock_put;
+	}
+
 	/*
-	 *	We can't accept the Call Request.
+	 *	We dont have any listeners for this incoming call.
+	 *	Try forwarding it.
 	 */
-	if (sk == NULL || sk_acceptq_is_full(sk))
-		goto out_clear_request;
+	if (sk == NULL) {
+		skb_push(skb, addr_len + X25_STD_MIN_LEN);
+		if (x25_forward_call(&dest_addr, nb, skb, lci) > 0)
+		{
+			/* Call was forwarded, dont process it any more */
+			kfree_skb(skb);
+			rc = 1;
+			goto out;
+		} else {
+			/* No listeners, can't forward, clear the call */
+			goto out_clear_request;
+		}
+	}
 
 	/*
 	 *	Try to reach a compromise on the requested facilities.
@@ -1598,6 +1615,9 @@ void x25_kill_by_neigh(struct x25_neigh 
 			x25_disconnect(s, ENETUNREACH, 0, 0);
 
 	write_unlock_bh(&x25_list_lock);
+
+	/* Remove any related forwards */
+	x25_clear_forward_by_dev(nb->dev);
 }
 
 static int __init x25_init(void)
net/x25/Makefile +1 -1
diff -uprN -X linux-2.6.20/Documentation/dontdiff linux-2.6.20-vanilla.clean/net/x25/Makefile linux-2.6.20/net/x25/Makefile
@@ -6,5 +6,5 @@ obj-$(CONFIG_X25) += x25.o
 
 x25-y			:= af_x25.o x25_dev.o x25_facilities.o x25_in.o \
 			   x25_link.o x25_out.o x25_route.o x25_subr.o \
-			   x25_timer.o x25_proc.o
+			   x25_timer.o x25_proc.o x25_forward.o
 x25-$(CONFIG_SYSCTL)	+= sysctl_net_x25.o
net/x25/x25_dev.c +11 -2
diff -uprN -X linux-2.6.20/Documentation/dontdiff linux-2.6.20-vanilla.clean/net/x25/x25_dev.c linux-2.6.20/net/x25/x25_dev.c
@@ -67,9 +67,18 @@ static int x25_receive_data(struct sk_bu
 		return x25_rx_call_request(skb, nb, lci);
 
 	/*
-	 *	Its not a Call Request, nor is it a control frame.
-	 *      Let caller throw it away.
+	 * 	Its not a Call Request, nor is it a control frame.
+	 *	Can we forward it?
 	 */
+
+	if (x25_forward_data(lci, nb, skb)) {
+		if (frametype == X25_CLEAR_CONFIRMATION) {
+			x25_clear_forward_by_lci(lci);
+		}
+		kfree_skb(skb);
+		return 1;
+	}
+
 /*
 	x25_transmit_clear_request(nb, lci, 0x0D);
 */
net/x25/x25_forward.c +163 -0

163 lines not on this page · raw message

net/x25/x25_route.c +3 -0
diff -uprN -X linux-2.6.20/Documentation/dontdiff linux-2.6.20-vanilla.clean/net/x25/x25_route.c linux-2.6.20/net/x25/x25_route.c
@@ -119,6 +119,9 @@ void x25_route_device_down(struct net_de
 			__x25_remove_route(rt);
 	}
 	write_unlock_bh(&x25_route_list_lock);
+
+	/* Remove any related forwarding */
+	x25_clear_forward_by_dev(dev);
 }
 
 /*
maintainer Applied
#3 lore raw

Re: [PATCH 1/3] [RESEND] X.25: Add call forwarding

From: ahendry <[email protected]>
Date: Thu, 08 Feb 2007 10:14:25 +1100

Quoted 11 lines

Adds call forwarding to X.25, allowing it to operate like an X.25 router. Useful if one needs to manipulate X.25 traffic with tools like tc.
This is an update/cleanup based off a patch submitted by Daniel Ferenci a few years ago.

Thanks Alan for the feedback.
Added the null check to the clones.
Moved the skb_clone's into the forwarding functions.

Worked ok with Cisco XoT, linux X.25 back to back, and some old NTUs/PADs.

Applied, thanks.