linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] drivers/net/wan/x25_asy: Fix to make it work
@ 2020-07-16 23:44 Xie He
  2020-07-20 11:23 ` Martin Schiller
  2020-07-22  1:30 ` David Miller
  0 siblings, 2 replies; 5+ messages in thread
From: Xie He @ 2020-07-16 23:44 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, Eric Dumazet, Martin Schiller,
	netdev, linux-kernel, linux-x25
  Cc: Xie He

This driver is not working because of problems of its receiving code.
This patch fixes it to make it work.

When the driver receives an LAPB frame, it should first pass the frame
to the LAPB module to process. After processing, the LAPB module passes
the data (the packet) back to the driver, the driver should then add a
one-byte pseudo header and pass the data to upper layers.

The changes to the "x25_asy_bump" function and the
"x25_asy_data_indication" function are to correctly implement this
procedure.

Also, the "x25_asy_unesc" function ignores any frame that is shorter
than 3 bytes. However the shortest frames are 2-byte long. So we need
to change it to allow 2-byte frames to pass.

Cc: Eric Dumazet <edumazet@google.com>
Cc: Martin Schiller <ms@dev.tdt.de>
Signed-off-by: Xie He <xie.he.0141@gmail.com>
---

Change from v1:
Added skb_cow before skb_push to ensure skb_push will succeed
according the suggestion of Eric Dumazet.

Hi Eric Dumazet and Martin Schiller,
Can you review this patch again and see if it is OK for me to include
your names in a "Signed-off-by", "Reviewed-by" or "Acked-by" tag?
Thank you!

Hi All,
I'm happy to answer any questions you might have and make improvements
according to your suggestions. Thanks!

---
 drivers/net/wan/x25_asy.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c
index 69773d228ec1..84640a0c13f3 100644
--- a/drivers/net/wan/x25_asy.c
+++ b/drivers/net/wan/x25_asy.c
@@ -183,7 +183,7 @@ static inline void x25_asy_unlock(struct x25_asy *sl)
 	netif_wake_queue(sl->dev);
 }
 
-/* Send one completely decapsulated IP datagram to the IP layer. */
+/* Send an LAPB frame to the LAPB module to process. */
 
 static void x25_asy_bump(struct x25_asy *sl)
 {
@@ -195,13 +195,12 @@ static void x25_asy_bump(struct x25_asy *sl)
 	count = sl->rcount;
 	dev->stats.rx_bytes += count;
 
-	skb = dev_alloc_skb(count+1);
+	skb = dev_alloc_skb(count);
 	if (skb == NULL) {
 		netdev_warn(sl->dev, "memory squeeze, dropping packet\n");
 		dev->stats.rx_dropped++;
 		return;
 	}
-	skb_push(skb, 1);	/* LAPB internal control */
 	skb_put_data(skb, sl->rbuff, count);
 	skb->protocol = x25_type_trans(skb, sl->dev);
 	err = lapb_data_received(skb->dev, skb);
@@ -209,7 +208,6 @@ static void x25_asy_bump(struct x25_asy *sl)
 		kfree_skb(skb);
 		printk(KERN_DEBUG "x25_asy: data received err - %d\n", err);
 	} else {
-		netif_rx(skb);
 		dev->stats.rx_packets++;
 	}
 }
@@ -356,12 +354,21 @@ static netdev_tx_t x25_asy_xmit(struct sk_buff *skb,
  */
 
 /*
- *	Called when I frame data arrives. We did the work above - throw it
- *	at the net layer.
+ *	Called when I frame data arrive. We add a pseudo header for upper
+ *	layers and pass it to upper layers.
  */
 
 static int x25_asy_data_indication(struct net_device *dev, struct sk_buff *skb)
 {
+	if (skb_cow(skb, 1)) {
+		kfree_skb(skb);
+		return NET_RX_DROP;
+	}
+	skb_push(skb, 1);
+	skb->data[0] = X25_IFACE_DATA;
+
+	skb->protocol = x25_type_trans(skb, dev);
+
 	return netif_rx(skb);
 }
 
@@ -657,7 +664,7 @@ static void x25_asy_unesc(struct x25_asy *sl, unsigned char s)
 	switch (s) {
 	case X25_END:
 		if (!test_and_clear_bit(SLF_ERROR, &sl->flags) &&
-		    sl->rcount > 2)
+		    sl->rcount >= 2)
 			x25_asy_bump(sl);
 		clear_bit(SLF_ESCAPE, &sl->flags);
 		sl->rcount = 0;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] drivers/net/wan/x25_asy: Fix to make it work
  2020-07-16 23:44 [PATCH v2] drivers/net/wan/x25_asy: Fix to make it work Xie He
@ 2020-07-20 11:23 ` Martin Schiller
  2020-07-20 17:58   ` Xie He
  2020-07-22  1:30 ` David Miller
  1 sibling, 1 reply; 5+ messages in thread
From: Martin Schiller @ 2020-07-20 11:23 UTC (permalink / raw)
  To: Xie He
  Cc: David S. Miller, Jakub Kicinski, Eric Dumazet, netdev,
	linux-kernel, linux-x25

On 2020-07-17 01:44, Xie He wrote:
> This driver is not working because of problems of its receiving code.
> This patch fixes it to make it work.
> 
> When the driver receives an LAPB frame, it should first pass the frame
> to the LAPB module to process. After processing, the LAPB module passes
> the data (the packet) back to the driver, the driver should then add a
> one-byte pseudo header and pass the data to upper layers.
> 
> The changes to the "x25_asy_bump" function and the
> "x25_asy_data_indication" function are to correctly implement this
> procedure.
> 
> Also, the "x25_asy_unesc" function ignores any frame that is shorter
> than 3 bytes. However the shortest frames are 2-byte long. So we need
> to change it to allow 2-byte frames to pass.
> 
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Martin Schiller <ms@dev.tdt.de>
> Signed-off-by: Xie He <xie.he.0141@gmail.com>
> ---
> 
> Change from v1:
> Added skb_cow before skb_push to ensure skb_push will succeed
> according the suggestion of Eric Dumazet.
> 
> Hi Eric Dumazet and Martin Schiller,
> Can you review this patch again and see if it is OK for me to include
> your names in a "Signed-off-by", "Reviewed-by" or "Acked-by" tag?
> Thank you!
> 
> Hi All,
> I'm happy to answer any questions you might have and make improvements
> according to your suggestions. Thanks!
> 
> ---
>  drivers/net/wan/x25_asy.c | 21 ++++++++++++++-------
>  1 file changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c
> index 69773d228ec1..84640a0c13f3 100644
> --- a/drivers/net/wan/x25_asy.c
> +++ b/drivers/net/wan/x25_asy.c
> @@ -183,7 +183,7 @@ static inline void x25_asy_unlock(struct x25_asy 
> *sl)
>  	netif_wake_queue(sl->dev);
>  }
> 
> -/* Send one completely decapsulated IP datagram to the IP layer. */
> +/* Send an LAPB frame to the LAPB module to process. */
> 
>  static void x25_asy_bump(struct x25_asy *sl)
>  {
> @@ -195,13 +195,12 @@ static void x25_asy_bump(struct x25_asy *sl)
>  	count = sl->rcount;
>  	dev->stats.rx_bytes += count;
> 
> -	skb = dev_alloc_skb(count+1);
> +	skb = dev_alloc_skb(count);
>  	if (skb == NULL) {
>  		netdev_warn(sl->dev, "memory squeeze, dropping packet\n");
>  		dev->stats.rx_dropped++;
>  		return;
>  	}
> -	skb_push(skb, 1);	/* LAPB internal control */
>  	skb_put_data(skb, sl->rbuff, count);
>  	skb->protocol = x25_type_trans(skb, sl->dev);
>  	err = lapb_data_received(skb->dev, skb);
> @@ -209,7 +208,6 @@ static void x25_asy_bump(struct x25_asy *sl)
>  		kfree_skb(skb);
>  		printk(KERN_DEBUG "x25_asy: data received err - %d\n", err);
>  	} else {
> -		netif_rx(skb);
>  		dev->stats.rx_packets++;
>  	}
>  }
> @@ -356,12 +354,21 @@ static netdev_tx_t x25_asy_xmit(struct sk_buff 
> *skb,
>   */
> 
>  /*
> - *	Called when I frame data arrives. We did the work above - throw it
> - *	at the net layer.
> + *	Called when I frame data arrive. We add a pseudo header for upper
> + *	layers and pass it to upper layers.
>   */
> 
>  static int x25_asy_data_indication(struct net_device *dev, struct 
> sk_buff *skb)
>  {
> +	if (skb_cow(skb, 1)) {
> +		kfree_skb(skb);
> +		return NET_RX_DROP;
> +	}
> +	skb_push(skb, 1);
> +	skb->data[0] = X25_IFACE_DATA;
> +
> +	skb->protocol = x25_type_trans(skb, dev);
> +
>  	return netif_rx(skb);
>  }
> 
> @@ -657,7 +664,7 @@ static void x25_asy_unesc(struct x25_asy *sl,
> unsigned char s)
>  	switch (s) {
>  	case X25_END:
>  		if (!test_and_clear_bit(SLF_ERROR, &sl->flags) &&
> -		    sl->rcount > 2)
> +		    sl->rcount >= 2)
>  			x25_asy_bump(sl);
>  		clear_bit(SLF_ESCAPE, &sl->flags);
>  		sl->rcount = 0;

LGTM.

I have never used the driver, but the adjustments look conclusive. The
functionality is now comparable to the one in the drivers lapbether or
hdlc_x25.

Reviewed-by: Martin Schiller <ms@dev.tdt.de>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] drivers/net/wan/x25_asy: Fix to make it work
  2020-07-20 11:23 ` Martin Schiller
@ 2020-07-20 17:58   ` Xie He
  0 siblings, 0 replies; 5+ messages in thread
From: Xie He @ 2020-07-20 17:58 UTC (permalink / raw)
  To: Martin Schiller
  Cc: David S. Miller, Jakub Kicinski, Eric Dumazet, netdev,
	linux-kernel, Linux X25

On Mon, Jul 20, 2020 at 4:23 AM -0700
Martin Schiller <ms@dev.tdt.de> wrote:
>
> LGTM.
>
> I have never used the driver, but the adjustments look conclusive. The
> functionality is now comparable to the one in the drivers lapbether or
> hdlc_x25.
>
> Reviewed-by: Martin Schiller <ms@dev.tdt.de>
>
Thank you so much!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] drivers/net/wan/x25_asy: Fix to make it work
  2020-07-16 23:44 [PATCH v2] drivers/net/wan/x25_asy: Fix to make it work Xie He
  2020-07-20 11:23 ` Martin Schiller
@ 2020-07-22  1:30 ` David Miller
  2020-07-22  3:10   ` Xie He
  1 sibling, 1 reply; 5+ messages in thread
From: David Miller @ 2020-07-22  1:30 UTC (permalink / raw)
  To: xie.he.0141; +Cc: kuba, edumazet, ms, netdev, linux-kernel, linux-x25

From: Xie He <xie.he.0141@gmail.com>
Date: Thu, 16 Jul 2020 16:44:33 -0700

> This driver is not working because of problems of its receiving code.
> This patch fixes it to make it work.
> 
> When the driver receives an LAPB frame, it should first pass the frame
> to the LAPB module to process. After processing, the LAPB module passes
> the data (the packet) back to the driver, the driver should then add a
> one-byte pseudo header and pass the data to upper layers.
> 
> The changes to the "x25_asy_bump" function and the
> "x25_asy_data_indication" function are to correctly implement this
> procedure.
> 
> Also, the "x25_asy_unesc" function ignores any frame that is shorter
> than 3 bytes. However the shortest frames are 2-byte long. So we need
> to change it to allow 2-byte frames to pass.
> 
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Martin Schiller <ms@dev.tdt.de>
> Signed-off-by: Xie He <xie.he.0141@gmail.com>

Applied, thank you.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] drivers/net/wan/x25_asy: Fix to make it work
  2020-07-22  1:30 ` David Miller
@ 2020-07-22  3:10   ` Xie He
  0 siblings, 0 replies; 5+ messages in thread
From: Xie He @ 2020-07-22  3:10 UTC (permalink / raw)
  To: David Miller
  Cc: Jakub Kicinski, Eric Dumazet, Martin Schiller, netdev,
	linux-kernel, Linux X25

On Tue, Jul 21, 2020 at 6:30 PM -0700
David Miller <davem@davemloft.net> wrote:
>
> Applied, thank you.

Thank you so much, David!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-22  3:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-16 23:44 [PATCH v2] drivers/net/wan/x25_asy: Fix to make it work Xie He
2020-07-20 11:23 ` Martin Schiller
2020-07-20 17:58   ` Xie He
2020-07-22  1:30 ` David Miller
2020-07-22  3:10   ` Xie He

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).