Thread (23 messages) 23 messages, 2 authors, 2020-10-30

Re: [PATCH net-next v4 5/5] net: hdlc_fr: Add support for any Ethertype

From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date: 2020-10-30 16:33:28
Also in: lkml

On Thu, Oct 29, 2020 at 10:32 PM Xie He [off-list ref] wrote:
quoted hunk ↗ jump to hunk
Change the fr_rx function to make this driver support any Ethertype
when receiving skbs on normal (non-Ethernet-emulating) PVC devices.
(This driver is already able to handle any Ethertype when sending.)

Originally in the fr_rx function, the code that parses the long (10-byte)
header only recognizes a few Ethertype values and drops frames with other
Ethertype values. This patch replaces this code to make fr_rx support
any Ethertype. This patch also creates a new function fr_snap_parse as
part of the new code.

Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: Krzysztof Halasa <khc@pm.waw.pl>
Signed-off-by: Xie He <redacted>
---
 drivers/net/wan/hdlc_fr.c | 75 +++++++++++++++++++++++++--------------
 1 file changed, 49 insertions(+), 26 deletions(-)
diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c
index 9a37575686b9..e95efc14bc97 100644
--- a/drivers/net/wan/hdlc_fr.c
+++ b/drivers/net/wan/hdlc_fr.c
@@ -871,6 +871,45 @@ static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb)
        return 0;
 }
quoted hunk ↗ jump to hunk
 static int fr_rx(struct sk_buff *skb)
 {
@@ -945,35 +984,19 @@ static int fr_rx(struct sk_buff *skb)
                skb->protocol = htons(ETH_P_IPV6);
                skb_reset_mac_header(skb);

-       } else if (skb->len > 10 && data[3] == FR_PAD &&
-                  data[4] == NLPID_SNAP && data[5] == FR_PAD) {
-               u16 oui = ntohs(*(__be16*)(data + 6));
-               u16 pid = ntohs(*(__be16*)(data + 8));
-               skb_pull(skb, 10);
-
-               switch ((((u32)oui) << 16) | pid) {
-               case ETH_P_ARP: /* routed frame with SNAP */
-               case ETH_P_IPX:
-               case ETH_P_IP:  /* a long variant */
-               case ETH_P_IPV6:
-                       if (!pvc->main)
-                               goto rx_drop;
-                       skb->dev = pvc->main;
-                       skb->protocol = htons(pid);
-                       skb_reset_mac_header(skb);
-                       break;
-
-               case 0x80C20007: /* bridged Ethernet frame */
-                       if (!pvc->ether)
+       } else if (data[3] == FR_PAD) {
+               if (skb->len < 5)
+                       goto rx_error;
+               if (data[4] == NLPID_SNAP) { /* A SNAP header follows */
Should this still check data[5] == FR_PAD?

+                       skb_pull(skb, 5);
+                       if (skb->len < 5) /* Incomplete SNAP header */
+                               goto rx_error;
+                       if (fr_snap_parse(skb, pvc))
                                goto rx_drop;
-                       skb->protocol = eth_type_trans(skb, pvc->ether);
-                       break;
-
-               default:
-                       netdev_info(frad, "Unsupported protocol, OUI=%x PID=%x\n",
-                                   oui, pid);
+               } else {
                        goto rx_drop;
                }
+
        } else {
                netdev_info(frad, "Unsupported protocol, NLPID=%x length=%i\n",
                            data[3], skb->len);
--
2.27.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help