Skip to contentSkip to conversation

hdlc bridge

PATCH Ferenci Daniel 2 participants 2 messages Nov 15, 2004 – Nov 16, 2004

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi Mr. Eis,
Hi linux folks,

excuse the newcommer, this is my first attempt to make a contribution. I tried to keep all advices from the Documentation.

Change log:

HDLC bridge is kind of a stack for hdlc bridging.
It can be usefull for sniffing hdlc traffic (within two hdlc interface).

- why the kernel needed patching

I didn't find such functionality within the kernel tree.

- the overall design approach in the patch

HDLC bridge is one of the network stacs.
Like other x25,lapb stacks also hdlc bridge stack is connected to the HW device via sethdlc command.

sethdlc hdlc0 hdlc-bridge
sethdlc hdlc1 hdlc-bridge

If you have two hdlc cards (like MOXA or TAHOE or any other) you can swith on bridging via updated command sethdlc (new version is placed at htp://www.dafe.net/x25/) like:
and afterwards all traffic incoming to hdlc0 card is sent from hdlc1 card and vice versa. If you have switched #define DEBUG_PKT you can found all passing hdlc traffic in dmesg.

- implementation details

Principles of hdlc bridge stack is are the same like x25 or lapb stack.

- testing results

I tested it several times on several ATM maschines and CISCO devices and it worked without problem.

---

include/net/hdlcbridge.h Sat Nov 13 08:21:12 2004 renamed from include/net/hdlcbridge.h Thu Jan 1 01:00:00 1970 +32 -0
diff --new-file -u --recursive linux-2.4.25/include/net/hdlcbridge.h linux-2.4.25.intel/include/net/hdlcbridge.h
@@ -0,0 +1,33 @@
+#ifndef _HDLCBRIDGE_H
+#define _HDLCBRIDGE_H
+
+/*
+    Definitions for hdlc bridge
+    +    History
+    12.11.2004 Daniel Ferenci creation
+*/
+
+
+typedef enum {
+    PHYS_OK,
+    PHYS_NOK
+} STAT;
+
+typedef struct phys_bridge_register_struct {
+    int  (*tx)(struct sk_buff *skb, struct net_device *dev);
+} PHYS_BRIDGE_REGISTER_STRUCT;
+
+typedef struct bridge_pair
+{
+    hdlc_device *hdlc1;
+    struct phys_bridge_register_struct *cb1;
+    hdlc_device *hdlc2;
+    struct phys_bridge_register_struct *cb2;
+} BRIDGE_PAIR;
+
+int phys_bridge_register(hdlc_device *hdlc, struct phys_bridge_register_struct *callbacks);
+int phys_bridge_unregister(hdlc_device *hdlc);
+int phys_bridge_data_received(hdlc_device *hdlc, struct sk_buff *skb);
+
+#endif /* _HDLCBRIDGE_H */
net/Config.in Sat Nov 13 08:22:39 2004 renamed from net/Config.in Fri Nov 28 19:26:21 2003 +0 -0
@@ -1,6 +1,8 @@

#
# Network configuration
#
+# 12.11.2004 Daniel Ferenci added parts for hdlcbridge +
mainmenu_option next_comment
comment 'Networking options'
tristate 'Packet socket' CONFIG_PACKET
@@ -9,6 +11,9 @@
fi

tristate 'Netlink device emulation' CONFIG_NETLINK_DEV +tristate 'Netlink sockets' CONFIG_NETLINK
+
+tristate 'HDLC Bridging' CONFIG_HDLC_BRIDGE

bool 'Network packet filtering (replaces ipchains)' CONFIG_NETFILTER if [ "$CONFIG_NETFILTER" = "y" ]; then

net/Makefile Sat Nov 13 08:22:14 2004 renamed from net/Makefile Fri Nov 28 19:26:21 2003 +0 -0
@@ -4,6 +4,9 @@

# 2 Sep 2000, Christoph Hellwig <[email protected]> # Rewritten to use lists instead of if-statements. #
+# 12.11.2004 Daniel Ferenci added hdlcbridge files +
+

O_TARGET := network.o

@@ -46,6 +49,7 @@
subdir-$(CONFIG_DECNET) += decnet
subdir-$(CONFIG_ECONET) += econet
subdir-$(CONFIG_VLAN_8021Q) += 8021q
+subdir-$(CONFIG_HDLC_BRIDGE) += hdlcbridge

ifeq ($(CONFIG_NETFILTER),y)
mod-subdirs += ipv4/ipvs

net/hdlcbridge/Makefile Sat Nov 13 08:24:48 2004 renamed from net/hdlcbridge/Makefile Thu Jan 1 01:00:00 1970 +22 -0
diff --new-file -u --recursive linux-2.4.25/net/hdlcbridge/Makefile linux-2.4.25.intel/net/hdlcbridge/Makefile
@@ -0,0 +1,22 @@
+#
+# Makefile for the Linux HDLC Bridge
+#
+# History:
+#     12.11.2004 Daniel Ferenci creation
+#
+# Note! Dependencies are done automagically by 'make dep', which also
+# removes any old dependencies. DON'T put your own dependencies here
+# unless it's something special (ie not a .c file).
+#
+# Note 2! The CFLAGS definition is now in the main makefile...
+
+
+O_TARGET := hdlcbridge.o
+
+export-objs := hdlc_bridge.o
+
+obj-y     := hdlc_bridge.o
+obj-m    := $(O_TARGET)
+
+include $(TOPDIR)/Rules.make
+
net/hdlcbridge/hdlc_bridge.c Sat Nov 13 08:24:12 2004 renamed from net/hdlcbridge/hdlc_bridge.c Thu Jan 1 01:00:00 1970 +116 -0

116 lines not on this page · raw message

drivers/net/wan/hdlc_bridge.c Sat Nov 13 08:26:02 2004 renamed from drivers/net/wan/hdlc_bridge.c Thu Jan 1 01:00:00 1970 +124 -0

124 lines not on this page · raw message

drivers/net/wan/hdlc_generic.c Sat Oct 30 08:50:17 2004 renamed from drivers/net/wan/hdlc_generic.c Wed Feb 18 14:36:31 2004 +3 -0
@@ -107,6 +107,7 @@
    case IF_PROTO_CISCO:
    case IF_PROTO_FR:
    case IF_PROTO_X25:
+    case IF_PROTO_HDLC_BRIDGE:
        proto = ifr->ifr_settings.type;
        break;
 
@@ -121,6 +122,8 @@
    case IF_PROTO_CISCO:    return hdlc_cisco_ioctl(hdlc, ifr);
    case IF_PROTO_FR:    return hdlc_fr_ioctl(hdlc, ifr);
    case IF_PROTO_X25:    return hdlc_x25_ioctl(hdlc, ifr);
+    case IF_PROTO_LAPB:    return hdlc_x25_ioctl(hdlc, ifr);
+    case IF_PROTO_HDLC_BRIDGE: return hdlc_bridge_ioctl(hdlc, ifr);
    default:        return -EINVAL;
    }

}

include/linux/if.h Sat Oct 2 08:09:35 2004 renamed from include/linux/if.h Fri Nov 28 19:26:21 2003 +0 -0
@@ -23,7 +23,9 @@

#include <linux/socket.h> /* for "struct sockaddr" et al */

#define IFNAMSIZ 16
+
#include <linux/hdlc/ioctl.h>
+#include <linux/lapb/ioctl.h>

/* Standard interface flags (netdevice->flags). */
#define IFF_UP 0x1 /* interface is up */
@@ -54,6 +56,7 @@

#define IF_GET_IFACE 0x0001 /* for querying only */
#define IF_GET_PROTO 0x0002
+#define IF_GET_ST3 0x0003

/* For definitions see hdlc.h */
#define IF_IFACE_V35 0x1000 /* V.35 serial interface */
@@ -76,6 +79,9 @@
#define IF_PROTO_FR_DEL_ETH_PVC 0x2009 /* Delete FR Ethernet-bridged PVC */
#define IF_PROTO_FR_PVC 0x200A /* for reading PVC status */
#define IF_PROTO_FR_ETH_PVC 0x200B
+#define IF_PROTO_HDLC_BRIDGE 0x200C /* hdlc bridge stack */
+#define IF_PROTO_HDLC_SEND 0x200D /* hdlc bridge stack */
+#define IF_PROTO_LAPB 0x200E /* lapb stack */

/*
@@ -110,10 +116,13 @@

        fr_proto        *fr;
        fr_proto_pvc        *fr_pvc;
        fr_proto_pvc_info    *fr_pvc_info;
-
+        struct lapb_parms_struct    *lapb_stuff;
        /* interface settings */
        sync_serial_settings    *sync;
        te1_settings        *te1;
+        st3_status        *st3;
+        +        buffer            *data;
    } ifs_ifsu;
};
drivers/net/wan/Makefile Sat Oct 2 08:04:28 2004 renamed from drivers/net/wan/Makefile Sat Nov 13 09:14:24 2004 +0 -0
@@ -82,6 +82,9 @@

obj-$(CONFIG_N2) += n2.o
obj-$(CONFIG_C101) += c101.o
obj-$(CONFIG_PCI200SYN) += pci200syn.o
+obj-$(CONFIG_TAHOE9XX) += tahoe9xx.o
+obj-$(CONFIG_X25TAP) += x25tap.o
+

include $(TOPDIR)/Rules.make

maintainer
#1 lore raw

Hi,

BTW: I would appreciate being Cc:'ied while discussing generic HDLC things, especially the ones which are aimed at the official kernels. Thanks.

Added netdev, too.

Quoted 2 lines · Ferenci Daniel

HDLC bridge is kind of a stack for hdlc bridging.
It can be usefull for sniffing hdlc traffic (within two hdlc interface).

Right.

Of course, given the isolated nature of such bridge, it can be implemented in either kernel-space or user-space.

Quoted 2 lines

sethdlc hdlc0 hdlc-bridge
sethdlc hdlc1 hdlc-bridge

You should be able to use more than one bridge I think - the syntax should allow this.

Something like:
sethdlc hdlc0 hdlc
sethdlc hdlc1 add-to-bridge hdlc0
or
sethdlc create-hdlc-bridge hdlcbr0
sethdlc hdlc0 add-to-bridge hdlcbr0
sethdlc hdlc1 add-to-bridge hdlcbr0

would probably be better.

Quoted 1 line

+++ linux-2.4.25.intel/include/net/hdlcbridge.h Sat Nov 13 08:21:12 2004

First, I would do all works against 2.6 kernel. You may want to check with Marcelo, Jeff and/or David, but I wouldn't expect them to apply such patches to 2.4 when 2.6 doesn't have them.
I wouldn't do that either.

include/net/hdlcbridge.h Sat Nov 13 08:21:12 2004 line 14

Quoted 4 lines
include/net/hdlcbridge.h Sat Nov 13 08:21:12 2004 renamed from include/net/hdlcbridge.h Thu Jan 1 01:00:00 1970 +4 -0
+typedef enum {
+    PHYS_OK,
+    PHYS_NOK
+} STAT;

I don't think such bridge has anything to do with anything "physical". I would rather change "PHYS" into something related to the actual nature of underlying device (which could be virtual, a tunnel, or anything).

Quoted 11 lines

+++ linux-2.4.25.intel/net/Config.in Sat Nov 13 08:22:39 2004

(quoted diff) +2 -0
@@ -1,6 +1,8 @@
 #
 # Network configuration
 #
+# 12.11.2004 Daniel Ferenci added parts for hdlcbridge
+
 mainmenu_option next_comment
 comment 'Networking options'
 tristate 'Packet socket' CONFIG_PACKET

Review line 14

Quoted 4 lines
(quoted diff) +2 -0
@@ -9,6 +11,9 @@
 fi
 tristate 'Netlink device emulation' CONFIG_NETLINK_DEV
+tristate 'Netlink sockets' CONFIG_NETLINK
+

I sense something not related to HDLC bridging here.

Quoted 1 line
(quoted diff) +1 -0
+++ linux-2.4.25.intel/net/hdlcbridge/hdlc_bridge.c    Sat Nov 13

...

Quoted 1 line

+int phys_bridge_data_received(hdlc_device *hdlc, struct sk_buff *skb)

I think it should be run directly in/from hdlc->netif_rx(). Possibly using *_type_trans() etc.
Not sure why it has to be that complicated - one more file in drivers/wan would be enough, wouldn't it?

Quoted 1 line

+++ linux-2.4.25.intel/drivers/net/wan/hdlc_bridge.c Sat Nov 13

Exactly such a file.

drivers/net/wan/hdlc_bridge.c Sat Nov 13 08:26:02 2004 line 76

Quoted 10 lines
drivers/net/wan/hdlc_bridge.c Sat Nov 13 08:26:02 2004 renamed from drivers/net/wan/hdlc_bridge.c Thu Jan 1 01:00:00 1970 +10 -0
+static void bridge_rx(struct sk_buff *skb)
+{
+    hdlc_device *hdlc = dev_to_hdlc(skb->dev);
+    +    printk(KERN_ERR "bridge_rx device: %s", skb->dev->name);
+
+    if (phys_bridge_data_received(hdlc, skb) == PHYS_OK)
+        return;
+    hdlc->stats.rx_errors++;
+    dev_kfree_skb_any(skb);
+}

bridge_rx() should IMHO just send the frame to the other end, if of course possible (device up etc). This module would better know both ends, right?

Quoted 3 lines

+++ linux-2.4.25.intel/drivers/net/wan/hdlc_generic.c Sat Oct 30

+ case IF_PROTO_LAPB: return hdlc_x25_ioctl(hdlc, ifr);

Something extra I'd say.

Quoted 1 line

+#include <linux/lapb/ioctl.h>

Same here.

Quoted 1 line

+#define IF_GET_ST3 0x0003

Hmm... Not sure.

Quoted 1 line

+#define IF_PROTO_HDLC_BRIDGE 0x200C /* hdlc bridge stack */

This one is probably fine, but not sure about the following two:

Review

Quoted 5 lines
(quoted diff) +3 -1
+#define IF_PROTO_HDLC_SEND 0x200D     /* hdlc bridge stack */
+#define IF_PROTO_LAPB 0x200E     /* lapb stack */
 
-
+        struct lapb_parms_struct    *lapb_stuff;

Same here.

Review

Quoted 5 lines
(quoted diff) +5 -0
+        st3_status        *st3;
+        +        buffer            *data;
+obj-$(CONFIG_TAHOE9XX)        += tahoe9xx.o
+obj-$(CONFIG_X25TAP)        += x25tap.o
+

Hmm...

Signature · 1 line
Krzysztof Halasa