net: hdlc_fr: Improve fr_rx and add support for any Ethertype
Subsystems (3)
v4 cover net: hdlc_fr: Improve fr_rx and add support for any Ethertype
The main purpose of this series is the last patch. The previous 4 patches are just code clean-ups so that the last patch will not make the code too messy. The patches must be applied in sequence.
The receiving code of this driver doesn't support arbitrary Ethertype values. It only recognizes a few known Ethertypes when receiving and drops skbs with other Ethertypes.
However, the standard document RFC 2427 allows Frame Relay to support any Ethertype values. This series adds support for this.
Change from v3:
Split the 4th patch out of the last patch.
Improve the commit message of the 1st patch to explicitly state that the stats.rx_dropped count is also increased after "goto rx_error".
Change from v2:
Small fix to the commit message of the 2nd and 3rd patch
Change from v1:
Small fix to the commit message of the 2nd patch
Xie He (5):
net: hdlc_fr: Simpify fr_rx by using "goto rx_drop" to drop frames
net: hdlc_fr: Change the use of "dev" in fr_rx to make the code
cleaner
net: hdlc_fr: Improve the initial checks when we receive an skb
net: hdlc_fr: Do skb_reset_mac_header for skbs received on normal PVC
devices
net: hdlc_fr: Add support for any Ethertype
drivers/net/wan/hdlc_fr.c | 119 +++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 46 deletions(-)
Signature · 1 line
2.27.0
PATCH v4 1/5 net: hdlc_fr: Simpify fr_rx by using "goto rx_drop" to drop frames
1.
When the fr_rx function drops a received frame (because the protocol type is not supported, or because the PVC virtual device that corresponds to the DLCI number and the protocol type doesn't exist), the function frees the skb and returns.
The code for freeing the skb and returning is repeated several times, this patch uses "goto rx_drop" to replace them so that the code looks cleaner.
2.
Add code to increase the stats.rx_dropped count whenever we drop a frame. Increase the stats.rx_dropped count both after "goto rx_drop" and after "goto rx_error" because I think we should increase this value whenever an skb is dropped.
--- drivers/net/wan/hdlc_fr.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/net/wan/hdlc_fr.c +7 -9
@@ -904,8 +904,7 @@ static int fr_rx(struct sk_buff *skb)netdev_info (frad,"No PVC for received frame's DLCI %d\n" , dlci);#endif -dev_kfree_skb_any (skb); -return NET_RX_DROP ; + goto rx_drop; }if (pvc->state.fecn != fh->fecn) {
@@ -963,14 +962,12 @@ static int fr_rx(struct sk_buff *skb)default :netdev_info (frad,"Unsupported protocol, OUI=%x PID=%x\n" , oui, pid); -dev_kfree_skb_any (skb); -return NET_RX_DROP ; + goto rx_drop; } }else {netdev_info (frad,"Unsupported protocol, NLPID=%x length=%i\n" , data[3 ], skb->len); -dev_kfree_skb_any (skb); -return NET_RX_DROP ; + goto rx_drop; }if (dev) {
@@ -982,12 +979,13 @@ static int fr_rx(struct sk_buff *skb)netif_rx (skb);return NET_RX_SUCCESS ; }else { -dev_kfree_skb_any (skb); -return NET_RX_DROP ; + goto rx_drop; } - rx_error: +rx_error: frad->stats.rx_errors++;/* Mark error */ +rx_drop: + frad->stats.rx_dropped++;dev_kfree_skb_any (skb);return NET_RX_DROP ; }
Signature · 1 line
2.27.0
Re: [PATCH net-next v4 1/5] net: hdlc_fr: Simpify fr_rx by using "goto rx_drop" to drop frames
Quoted 7 lines · Xie He
1.
When thefr_rxfunction drops a received frame (because the protocol type is not supported, or because the PVC virtual device that corresponds to the DLCI number and the protocol type doesn't exist), the function frees the skb and returns.
Quoted 8 lines
The code for freeing the skb and returning is repeated several times, this patch uses "goto
rx_drop" to replace them so that the code looks cleaner.2.
Add code to increase the stats.rx_dropped count whenever we drop a frame. Increase the stats.rx_dropped count both after "gotorx_drop" and after "gotorx_error" because I think we should increase this value whenever an skb is dropped.
In general we try to avoid changing counter behavior like that, as existing users
may depend on current behavior, e.g., in dashboards or automated monitoring.
I don't know how realistic that is in this specific case, no strong objections. Use
good judgment.
Re: [PATCH net-next v4 1/5] net: hdlc_fr: Simpify fr_rx by using "goto rx_drop" to drop frames
Quoted 8 lines · Willem de Bruijn
In general we try to avoid changing counter behavior like that, as existing users
may depend on current behavior, e.g., in dashboards or automated monitoring.I don't know how realistic that is in this specific case, no strong objections. Use
good judgment.
Originally this function only increases stats.rx_dropped only when there's a memory squeeze. I don't know the specification for the meaning of stats.rx_dropped, but as I understand it indicates a frame is dropped. This is why I wanted to increase it whenever we drop a frame.
Originally this function drops a frame silently if the PVC virtual device that corresponds to the DLCI number and the protocol type doesn't exist. I think we may at least need some way to note this. Originally this function drops a frame with a kernel info message printed if the protocol type is not supported. I think this is a bad way because if the other end continuously sends us a lot of frames with unsupported protocol types, our kernel message log will be overwhelmed.
I don't know how important it is to keep backwards compatibility. I usually don't consider this too much. But I can drop this change if we really want to keep the counter behavior unchanged. I think changing it is better if we don't consider backwards compatibility.
Re: [PATCH net-next v4 1/5] net: hdlc_fr: Simpify fr_rx by using "goto rx_drop" to drop frames
Quoted 12 lines · Xie He
Quoted 8 lines · Willem de Bruijn
In general we try to avoid changing counter behavior like that, as existing users
may depend on current behavior, e.g., in dashboards or automated monitoring.I don't know how realistic that is in this specific case, no strong objections. Use
good judgment.
Quoted 5 lines
Originally this function only increases stats.rx_dropped only when there's a memory squeeze. I don't know the specification for the meaning of stats.rx_dropped, but as I understand it indicates a frame is dropped. This is why I wanted to increase it whenever we drop a frame.
Jakub recently made stats behavior less ambiguous, in commit 0db0c34cfbc9 ("net: tighten the definition of interface statistics").
That said, it's not entirely clear whether rx_dropped would be allowed to include rx_errors.
My hunch is that it shouldn't. A quick scan of devices did quickly show at least one example where it does: macvlan. But I expect that to be an outlier.
Quoted 9 lines
Originally this function drops a frame silently if the PVC virtual device that corresponds to the DLCI number and the protocol type doesn't exist. I think we may at least need some way to note this. Originally this function drops a frame with a kernel info message printed if the protocol type is not supported. I think this is a bad way because if the other end continuously sends us a lot of frames with unsupported protocol types, our kernel message log will be overwhelmed.
Quoted 4 lines
I don't know how important it is to keep backwards compatibility. I usually don't consider this too much. But I can drop this change if we really want to keep the counter behavior unchanged. I think changing it is better if we don't consider backwards compatibility.
Please do always consider backward compatibility. In this case, I don't think that the behavioral change is needed for the core of the patch (changing control flow).
Re: [PATCH net-next v4 1/5] net: hdlc_fr: Simpify fr_rx by using "goto rx_drop" to drop frames
Quoted 10 lines · Willem de Bruijn
Jakub recently made stats behavior less ambiguous, in commit
0db0c34cfbc9("net: tighten the definition of interface statistics").That said, it's not entirely clear whether
rx_droppedwould be allowed to includerx_errors.My hunch is that it shouldn't. A quick scan of devices did quickly show at least one example where it does: macvlan. But I expect that to be an outlier.
OK. Thanks for the information.
Quoted 3 lines
Please do always consider backward compatibility. In this case, I don't think that the behavioral change is needed for the core of the patch (changing control flow).
OK. I'll drop the change about stats.rx_dropped. Thanks.
PATCH v4 2/5 net: hdlc_fr: Change the use of "dev" in fr_rx to make the code cleaner
In reply to Xie HeThe eth_type_trans function is called when we receive frames carrying Ethernet frames. This function expects a non-NULL pointer as an argument, and assigns it directly to skb->dev.
However, the code handling other types of frames first assigns the pointer to "dev", and then at the end checks whether the value is NULL, and if it is not NULL, assigns it to skb->dev.
The two flows are different. Mixing them in this function makes the code messy. It's better that we convert the second flow to align with how eth_type_trans does things.
So this patch changes the code to: first make sure the pointer is not NULL, then assign it directly to skb->dev. "dev" is no longer needed until the end where we use it to update stats.
--- drivers/net/wan/hdlc_fr.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-)
drivers/net/wan/hdlc_fr.c +20 -17
@@ -880,7 +880,7 @@ static int fr_rx(struct sk_buff *skb)u8 *data = skb->data;u16 dlci;struct pvc_device *pvc; -struct net_device *dev =NULL ; +struct net_device *dev;if (skb->len <=4 || fh->ea1 || data[2 ] !=FR_UI ) goto rx_error;
@@ -930,13 +930,17 @@ static int fr_rx(struct sk_buff *skb) }if (data[3 ] ==NLPID_IP ) { +if (!pvc->main) + goto rx_drop;skb_pull (skb,4 );/* Remove 4-byte header (hdr, UI, NLPID) */ - dev = pvc->main; + skb->dev = pvc->main; skb->protocol =htons (ETH_P_IP ); }else if (data[3 ] ==NLPID_IPV6 ) { +if (!pvc->main) + goto rx_drop;skb_pull (skb,4 );/* Remove 4-byte header (hdr, UI, NLPID) */ - dev = pvc->main; + skb->dev = pvc->main; skb->protocol =htons (ETH_P_IPV6 ); } else if (skb->len > 10 && data[3] == FR_PAD &&
@@ -950,13 +954,16 @@ static int fr_rx(struct sk_buff *skb)case ETH_P_IPX :case ETH_P_IP :/* a long variant */ case ETH_P_IPV6 : - dev = pvc->main; +if (!pvc->main) + goto rx_drop; + skb->dev = pvc->main; skb->protocol =htons (pid);break ;case 0x80C20007 :/* bridged Ethernet frame */ -if ((dev = pvc->ether) !=NULL ) - skb->protocol =eth_type_trans (skb, dev); +if (!pvc->ether) + goto rx_drop; + skb->protocol =eth_type_trans (skb, pvc->ether);break ;default :
@@ -970,17 +977,13 @@ static int fr_rx(struct sk_buff *skb) goto rx_drop; } -if (dev) { - dev->stats.rx_packets++;/* PVC traffic */ - dev->stats.rx_bytes += skb->len; -if (pvc->state.becn) - dev->stats.rx_compressed++; - skb->dev = dev; -netif_rx (skb); -return NET_RX_SUCCESS ; - }else { - goto rx_drop; - } + dev = skb->dev; + dev->stats.rx_packets++;/* PVC traffic */ + dev->stats.rx_bytes += skb->len; +if (pvc->state.becn) + dev->stats.rx_compressed++; +netif_rx (skb); +return NET_RX_SUCCESS ; rx_error: frad->stats.rx_errors++;/* Mark error */
Signature · 1 line
2.27.0
PATCH v4 3/5 net: hdlc_fr: Improve the initial checks when we receive an skb
In reply to Xie He1.
Change the skb->len check from "<= 4" to "< 4".
At first we only need to ensure a 4-byte header is present. We indeed normally need the 5th byte, too, but it'd be more logical and cleaner to check its existence when we actually need it.
2.
Add an fh->ea2 check to the initial checks in fr_rx. fh->ea2 == 1 means the second address byte is the final address byte. We only support the case where the address length is 2 bytes.
--- drivers/net/wan/hdlc_fr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wan/hdlc_fr.c +1 -1
@@ -882,7 +882,7 @@ static int fr_rx(struct sk_buff *skb)struct pvc_device *pvc;struct net_device *dev; -if (skb->len <=4 || fh->ea1 || data[2 ] !=FR_UI ) +if (skb->len <4 || fh->ea1 || !fh->ea2 || data[2 ] !=FR_UI ) goto rx_error; dlci =q922_to_dlci (skb->data);
Signature · 1 line
2.27.0
Re: [PATCH net-next v4 3/5] net: hdlc_fr: Improve the initial checks when we receive an skb
Quoted 11 lines · Xie He
1.
Change theskb->lencheck from "<= 4" to "< 4".
At first we only need to ensure a 4-byte header is present. We indeed normally need the 5th byte, too, but it'd be more logical and cleaner to check its existence when we actually need it.2.
Add anfh->ea2check to the initial checks infr_rx.fh->ea2== 1 means the second address byte is the final address byte. We only support the case where the address length is 2 bytes.
Can you elaborate a bit for readers not intimately familiar with the codebase?
Is there something in the following code that has this implicit assumption on 2-byte address lengths?
Re: [PATCH net-next v4 3/5] net: hdlc_fr: Improve the initial checks when we receive an skb
Quoted 9 lines · Willem de Bruijn
Quoted 4 lines
Add an
fh->ea2check to the initial checks infr_rx.fh->ea2== 1 means the second address byte is the final address byte. We only support the case where the address length is 2 bytes.Can you elaborate a bit for readers not intimately familiar with the codebase?
Is there something in the following code that has this implicit assumption on 2-byte address lengths?
Yes, the address length must be 2 bytes, otherwise the 3rd and 4th bytes would not be the control and protocol fields as we assumed in the code.
The frame format is specified in RFC 2427
(https://tools.ietf.org/html/rfc2427). We can see the overall frame format on Page 3. If the address length is longer than 2 bytes, all the following fields will be shifted behind.
Re: [PATCH net-next v4 3/5] net: hdlc_fr: Improve the initial checks when we receive an skb
Quoted 13 lines · Xie He
Quoted 9 lines · Willem de Bruijn
Quoted 4 lines
Add an
fh->ea2check to the initial checks infr_rx.fh->ea2== 1 means the second address byte is the final address byte. We only support the case where the address length is 2 bytes.Can you elaborate a bit for readers not intimately familiar with the codebase?
Is there something in the following code that has this implicit assumption on 2-byte address lengths?
Quoted 8 lines
Yes, the address length must be 2 bytes, otherwise the 3rd and 4th bytes would not be the control and protocol fields as we assumed in the code.
The frame format is specified in RFC 2427
(https://tools.ietf.org/html/rfc2427). We can see the overall frame format on Page 3. If the address length is longer than 2 bytes, all the following fields will be shifted behind.
Thanks for that context. If it's not captured in the code, it would be great to include in the commit message.
From a quick scan, RFC 2427 does not appear to actually define the Q.922 address. For that I ended up reading ITU-T doc "Q.922 : ISDN data link layer specification for frame mode bearer services", section 3.2.
Re: [PATCH net-next v4 3/5] net: hdlc_fr: Improve the initial checks when we receive an skb
Quoted 3 lines · Willem de Bruijn
Thanks for that context. If it's not captured in the code, it would be great to include in the commit message.
OK. I'll update the commit message.
Quoted 4 lines
From a quick scan, RFC 2427 does not appear to actually define the Q.922 address. For that I ended up reading ITU-T doc "Q.922 : ISDN data link layer specification for frame mode bearer services", section 3.2.
Yeah. Thanks for posting the name of the document. It's good to see ITU's documents are published in multiple languages because this feels more international :)
PATCH v4 4/5 net: hdlc_fr: Do skb_reset_mac_header for skbs received on normal PVC devices
In reply to Xie HeWhen an skb is received on a normal (non-Ethernet-emulating) PVC device, call skb_reset_mac_header before we pass it to upper layers.
This is because normal PVC devices don't have header_ops, so any header we have would not be visible to upper layer code when sending, so the header shouldn't be visible to upper layer code when receiving, either.
--- drivers/net/wan/hdlc_fr.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/wan/hdlc_fr.c +3 -0
@@ -935,6 +935,7 @@ static int fr_rx(struct sk_buff *skb)skb_pull (skb,4 );/* Remove 4-byte header (hdr, UI, NLPID) */ skb->dev = pvc->main; skb->protocol =htons (ETH_P_IP ); +skb_reset_mac_header (skb); }else if (data[3 ] ==NLPID_IPV6 ) {if (!pvc->main)
@@ -942,6 +943,7 @@ static int fr_rx(struct sk_buff *skb)skb_pull (skb,4 );/* Remove 4-byte header (hdr, UI, NLPID) */ skb->dev = pvc->main; 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 ) {
@@ -958,6 +960,7 @@ static int fr_rx(struct sk_buff *skb) goto rx_drop; skb->dev = pvc->main; skb->protocol =htons (pid); +skb_reset_mac_header (skb);break ;case 0x80C20007 :/* bridged Ethernet frame */
Signature · 1 line
2.27.0
Re: [PATCH net-next v4 4/5] net: hdlc_fr: Do skb_reset_mac_header for skbs received on normal PVC devices
Quoted 11 lines · Xie He
When an skb is received on a normal (non-Ethernet-emulating) PVC device, call
skb_reset_mac_headerbefore we pass it to upper layers.This is because normal PVC devices don't have
header_ops, so any header we have would not be visible to upper layer code when sending, so the header shouldn't be visible to upper layer code when receiving, either.Cc Willem de Bruijn <[email protected]>Cc Krzysztof Halasa <[email protected]>Signed-off-by Xie He <[email protected]>
Should this go to net if a bugfix though?
Re: [PATCH net-next v4 4/5] net: hdlc_fr: Do skb_reset_mac_header for skbs received on normal PVC devices
Quoted 2 lines · Willem de Bruijn
Acked-by Willem de Bruijn <[email protected]>
Thanks for your ack!
Quoted 1 line
Should this go to net if a bugfix though?
Yes, this should theoretically be a bug fix. But I didn't think this was an important fix, because af_packet.c already had workarounds for this issue for all drivers that didn't have header_ops. We can separate this patch to make it go to "net" though, but I'm afraid that this will cause merging conflicts between "net" and "net-next".
Re: [PATCH net-next v4 4/5] net: hdlc_fr: Do skb_reset_mac_header for skbs received on normal PVC devices
Quoted 8 lines · Xie He
Quoted 2 lines · Willem de Bruijn
Acked-by Willem de Bruijn <[email protected]>Thanks for your ack!
Quoted 7 lines
Quoted 1 line
Should this go to net if a bugfix though?
Yes, this should theoretically be a bug fix. But I didn't think this was an important fix, because
af_packet.calready had workarounds for this issue for all drivers that didn't haveheader_ops. We can separate this patch to make it go to "net" though, but I'm afraid that this will cause merging conflicts between "net" and "net-next".
Yes, it might require holding off the other patches until net is merged into net-next.
Packet sockets are likely not the only way these packets are received? It changes mac_len as computed in __netif_receive_skb_core.
If there is no real bug that is fixed, net-next is fine.
Re: [PATCH net-next v4 4/5] net: hdlc_fr: Do skb_reset_mac_header for skbs received on normal PVC devices
Quoted 6 lines · Willem de Bruijn
Yes, it might require holding off the other patches until net is merged into net-next.
Packet sockets are likely not the only way these packets are received? It changes
mac_lenas computed in__netif_receive_skb_core.
I looked at __netif_receive_skb_core. I didn't see it computing mac_len?
I thought only AF_PACKET/RAW sockets would need this information because other upper layers would not care about what happened in L2.
I see mac_len is computed in netif_receive_generic_xdp. I'm not clear about the reason why it calculates it. But it seems that it considers the L2 header as an Ethernet header, which is incorrect for this driver.
Quoted 1 line
If there is no real bug that is fixed, net-next is fine.
Re: [PATCH net-next v4 4/5] net: hdlc_fr: Do skb_reset_mac_header for skbs received on normal PVC devices
Quoted 11 lines · Xie He
Quoted 6 lines · Willem de Bruijn
Yes, it might require holding off the other patches until net is merged into net-next.
Packet sockets are likely not the only way these packets are received? It changes
mac_lenas computed in__netif_receive_skb_core.I looked at
__netif_receive_skb_core. I didn't see it computingmac_len?
It's indirect:
skb_reset_network_header(skb);
if (!skb_transport_header_was_set(skb))
skb_reset_transport_header(skb);
skb_reset_mac_len(skb);Quoted 2 lines
I thought only AF_PACKET/RAW sockets would need this information because other upper layers would not care about what happened in L2.
I think that's a reasonable assumption. I don't have a good counterexample ready. Specific to this case, it seems to have been working with no one complaining so far ;)
Quoted 6 lines
I see
mac_lenis computed innetif_receive_generic_xdp. I'm not clear about the reason why it calculates it. But it seems that it considers the L2 header as an Ethernet header, which is incorrect for this driver.Quoted 1 line
If there is no real bug that is fixed, net-next is fine.
Re: [PATCH net-next v4 4/5] net: hdlc_fr: Do skb_reset_mac_header for skbs received on normal PVC devices
Quoted 7 lines · Willem de Bruijn
It's indirect:
skb_reset_network_header(skb); if (!skb_transport_header_was_set(skb)) skb_reset_transport_header(skb); skb_reset_mac_len(skb);
Oh. I see. skb_reset_mac_len would set skb->mac_len. Not sure where skb->mac_len would be used though.
Quoted 6 lines
Quoted 2 lines
I thought only AF_PACKET/RAW sockets would need this information because other upper layers would not care about what happened in L2.
I think that's a reasonable assumption. I don't have a good counterexample ready. Specific to this case, it seems to have been working with no one complaining so far ;)
Yeah. It seems to me that a lot of drivers (without header_ops) have this problem. The comment in af_packet.c before my commit b79a80bd6dd8 also indicated this problem was widespread. It seemed to not cause any issues.
PATCH v4 5/5 net: hdlc_fr: Add support for any Ethertype
In reply to Xie HeChange 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.
--- drivers/net/wan/hdlc_fr.c | 75 +++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 26 deletions(-)
drivers/net/wan/hdlc_fr.c +49 -26
@@ -871,6 +871,45 @@ static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb)return 0 ; } +static int fr_snap_parse (struct sk_buff *skb,struct pvc_device *pvc) +{ +/* OUI 00-00-00 indicates an Ethertype follows */ +if (skb->data[0 ] ==0x00 && + skb->data[1 ] ==0x00 && + skb->data[2 ] ==0x00 ) { +if (!pvc->main) +return -1 ; + skb->dev = pvc->main; + skb->protocol = *(__be16 *)(skb->data +3 );/* Ethertype */ +skb_pull (skb,5 ); +skb_reset_mac_header (skb); +return 0 ; + +/* OUI 00-80-C2 stands for the 802.1 organization */ + }else if (skb->data[0 ] ==0x00 && + skb->data[1 ] ==0x80 && + skb->data[2 ] ==0xC2 ) { +/* PID 00-07 stands for Ethernet frames without FCS */ +if (skb->data[3 ] ==0x00 && + skb->data[4 ] ==0x07 ) { +if (!pvc->ether) +return -1 ; +skb_pull (skb,5 ); +if (skb->len <ETH_HLEN ) +return -1 ; + skb->protocol =eth_type_trans (skb, pvc->ether); +return 0 ; + +/* PID unsupported */ + }else { +return -1 ; + } + +/* OUI unsupported */ + }else { +return -1 ; + } +}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 */ +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);
Signature · 1 line
2.27.0
Re: [PATCH net-next v4 5/5] net: hdlc_fr: Add support for any Ethertype
Quoted 47 lines · Xie He
Change the
fr_rxfunction 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_rxfunction, 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 makefr_rxsupport any Ethertype. This patch also creates a new functionfr_snap_parseas part of the new code.Cc Willem de Bruijn <[email protected]>Cc Krzysztof Halasa <[email protected]>Signed-off-by Xie He <[email protected]>--- drivers/net/wan/hdlc_fr.c | 75 +++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 26 deletions(-)drivers/net/wan/hdlc_fr.c +0
-14@@ -871,6 +871,45 @@ static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb)return 0 ; }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;
drivers/net/wan/hdlc_fr.c static int fr_rx(struct sk_buff *skb) · line 990
Quoted 10 lines
drivers/net/wan/hdlc_fr.c +4
-6- 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?
Quoted 21 lines
drivers/net/wan/hdlc_fr.c +6
-7+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
Re: [PATCH net-next v4 5/5] net: hdlc_fr: Add support for any Ethertype
Quoted 2 lines · Willem de Bruijn
Should this still check data[5] ==
FR_PAD?
No, the 6th byte (data[5]) is not a padding field. It is the first byte of the SNAP header. The original code is misleading. That is part of the reasons why I want to fix it with this patch.
The frame format is specified in RFC 2427
(https://tools.ietf.org/html/rfc2427). We can see in Section 4.1 and 4.2 that the 6th byte is the first byte of the SNAP header.
Willem de Bruijn
Acked-byRe: [PATCH net-next v4 5/5] net: hdlc_fr: Add support for any Ethertype
Quoted 9 lines · Xie He
Quoted 2 lines · Willem de Bruijn
Should this still check data[5] ==
FR_PAD?No, the 6th byte (data[5]) is not a padding field. It is the first byte of the SNAP header. The original code is misleading. That is part of the reasons why I want to fix it with this patch.
Oh, good point. In that case
Quoted 3 lines
The frame format is specified in RFC 2427
(https://tools.ietf.org/html/rfc2427). We can see in Section 4.1 and 4.2 that the 6th byte is the first byte of the SNAP header.