All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 net-next] l2tp: Refactor the codes with existing macros instead of literal number
@ 2016-08-22 10:59 fgao
  2016-08-22 14:43 ` Guillaume Nault
  0 siblings, 1 reply; 3+ messages in thread
From: fgao @ 2016-08-22 10:59 UTC (permalink / raw)
  To: jchapman, g.nault, philipp, davem, netdev; +Cc: gfree.wind, Gao Feng

From: Gao Feng <fgao@ikuai8.com>

Use PPP_ALLSTATIONS, PPP_UI, and SEND_SHUTDOWN instead of 0xff,
0x03, and 2 separately.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
 v4: Remove two static ppph variables;
 v3: Modify the subject;
 v2: Only replace the literal number with macros according to Guillaume's advice
 v1: Inital patch

 net/l2tp/l2tp_ppp.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
index d9560aa..0c071c4 100644
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -177,7 +177,7 @@ static int pppol2tp_recv_payload_hook(struct sk_buff *skb)
 	if (!pskb_may_pull(skb, 2))
 		return 1;
 
-	if ((skb->data[0] == 0xff) && (skb->data[1] == 0x03))
+	if ((skb->data[0] == PPP_ALLSTATIONS) && (skb->data[1] == PPP_UI))
 		skb_pull(skb, 2);
 
 	return 0;
@@ -282,7 +282,6 @@ static void pppol2tp_session_sock_put(struct l2tp_session *session)
 static int pppol2tp_sendmsg(struct socket *sock, struct msghdr *m,
 			    size_t total_len)
 {
-	static const unsigned char ppph[2] = { 0xff, 0x03 };
 	struct sock *sk = sock->sk;
 	struct sk_buff *skb;
 	int error;
@@ -312,7 +311,7 @@ static int pppol2tp_sendmsg(struct socket *sock, struct msghdr *m,
 	error = -ENOMEM;
 	skb = sock_wmalloc(sk, NET_SKB_PAD + sizeof(struct iphdr) +
 			   uhlen + session->hdr_len +
-			   sizeof(ppph) + total_len,
+			   2 + total_len, /* 2 bytes for PPP_ALLSTATIONS & PPP_UI */
 			   0, GFP_KERNEL);
 	if (!skb)
 		goto error_put_sess_tun;
@@ -325,8 +324,8 @@ static int pppol2tp_sendmsg(struct socket *sock, struct msghdr *m,
 	skb_reserve(skb, uhlen);
 
 	/* Add PPP header */
-	skb->data[0] = ppph[0];
-	skb->data[1] = ppph[1];
+	skb->data[0] = PPP_ALLSTATIONS; 
+	skb->data[1] = PPP_UI;
 	skb_put(skb, 2);
 
 	/* Copy user data into skb */
@@ -369,7 +368,6 @@ error:
  */
 static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
 {
-	static const u8 ppph[2] = { 0xff, 0x03 };
 	struct sock *sk = (struct sock *) chan->private;
 	struct sock *sk_tun;
 	struct l2tp_session *session;
@@ -398,14 +396,14 @@ static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
 		   sizeof(struct iphdr) + /* IP header */
 		   uhlen +		/* UDP header (if L2TP_ENCAPTYPE_UDP) */
 		   session->hdr_len +	/* L2TP header */
-		   sizeof(ppph);	/* PPP header */
+		   2;			/* 2 bytes for PPP_ALLSTATIONS & PPP_UI */
 	if (skb_cow_head(skb, headroom))
 		goto abort_put_sess_tun;
 
 	/* Setup PPP header */
-	__skb_push(skb, sizeof(ppph));
-	skb->data[0] = ppph[0];
-	skb->data[1] = ppph[1];
+	__skb_push(skb, 2); 
+	skb->data[0] = PPP_ALLSTATIONS;
+	skb->data[1] = PPP_UI;
 
 	local_bh_disable();
 	l2tp_xmit_skb(session, skb, session->hdr_len);
@@ -440,7 +438,7 @@ static void pppol2tp_session_close(struct l2tp_session *session)
 	BUG_ON(session->magic != L2TP_SESSION_MAGIC);
 
 	if (sock) {
-		inet_shutdown(sock, 2);
+		inet_shutdown(sock, SEND_SHUTDOWN);
 		/* Don't let the session go away before our socket does */
 		l2tp_session_inc_refcount(session);
 	}
-- 
1.9.1

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

* Re: [PATCH v4 net-next] l2tp: Refactor the codes with existing macros instead of literal number
  2016-08-22 10:59 [PATCH v4 net-next] l2tp: Refactor the codes with existing macros instead of literal number fgao
@ 2016-08-22 14:43 ` Guillaume Nault
  2016-08-22 14:51   ` Feng Gao
  0 siblings, 1 reply; 3+ messages in thread
From: Guillaume Nault @ 2016-08-22 14:43 UTC (permalink / raw)
  To: fgao; +Cc: jchapman, philipp, davem, netdev, gfree.wind

On Mon, Aug 22, 2016 at 06:59:51PM +0800, fgao@ikuai8.com wrote:
> From: Gao Feng <fgao@ikuai8.com>
> 
> Use PPP_ALLSTATIONS, PPP_UI, and SEND_SHUTDOWN instead of 0xff,
> 0x03, and 2 separately.
> 
Apart from the checkpatch errors,

Acked-by: Guillaume Nault <g.nault@alphalink.fr>

> @@ -325,8 +324,8 @@ static int pppol2tp_sendmsg(struct socket *sock, struct msghdr *m,
>  	skb_reserve(skb, uhlen);
>  
>  	/* Add PPP header */
> -	skb->data[0] = ppph[0];
> -	skb->data[1] = ppph[1];
> +	skb->data[0] = PPP_ALLSTATIONS; 
> 
Trailing whitespace.

> @@ -398,14 +396,14 @@ static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
>  		   sizeof(struct iphdr) + /* IP header */
>  		   uhlen +		/* UDP header (if L2TP_ENCAPTYPE_UDP) */
>  		   session->hdr_len +	/* L2TP header */
> -		   sizeof(ppph);	/* PPP header */
> +		   2;			/* 2 bytes for PPP_ALLSTATIONS & PPP_UI */
>  	if (skb_cow_head(skb, headroom))
>  		goto abort_put_sess_tun;
>  
>  	/* Setup PPP header */
> -	__skb_push(skb, sizeof(ppph));
> -	skb->data[0] = ppph[0];
> -	skb->data[1] = ppph[1];
> +	__skb_push(skb, 2); 
> 
Here too.

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

* Re: [PATCH v4 net-next] l2tp: Refactor the codes with existing macros instead of literal number
  2016-08-22 14:43 ` Guillaume Nault
@ 2016-08-22 14:51   ` Feng Gao
  0 siblings, 0 replies; 3+ messages in thread
From: Feng Gao @ 2016-08-22 14:51 UTC (permalink / raw)
  To: Guillaume Nault
  Cc: Gao Feng, jchapman, Philp Prindeville, David S. Miller,
	Linux Kernel Network Developers

Sorry, I forget to run the check_patch.pl script this time.
Now I send the v5 update.

Regards
Feng

On Mon, Aug 22, 2016 at 10:43 PM, Guillaume Nault <g.nault@alphalink.fr> wrote:
> On Mon, Aug 22, 2016 at 06:59:51PM +0800, fgao@ikuai8.com wrote:
>> From: Gao Feng <fgao@ikuai8.com>
>>
>> Use PPP_ALLSTATIONS, PPP_UI, and SEND_SHUTDOWN instead of 0xff,
>> 0x03, and 2 separately.
>>
> Apart from the checkpatch errors,
>
> Acked-by: Guillaume Nault <g.nault@alphalink.fr>
>
>> @@ -325,8 +324,8 @@ static int pppol2tp_sendmsg(struct socket *sock, struct msghdr *m,
>>       skb_reserve(skb, uhlen);
>>
>>       /* Add PPP header */
>> -     skb->data[0] = ppph[0];
>> -     skb->data[1] = ppph[1];
>> +     skb->data[0] = PPP_ALLSTATIONS;
>>
> Trailing whitespace.
>
>> @@ -398,14 +396,14 @@ static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
>>                  sizeof(struct iphdr) + /* IP header */
>>                  uhlen +              /* UDP header (if L2TP_ENCAPTYPE_UDP) */
>>                  session->hdr_len +   /* L2TP header */
>> -                sizeof(ppph);        /* PPP header */
>> +                2;                   /* 2 bytes for PPP_ALLSTATIONS & PPP_UI */
>>       if (skb_cow_head(skb, headroom))
>>               goto abort_put_sess_tun;
>>
>>       /* Setup PPP header */
>> -     __skb_push(skb, sizeof(ppph));
>> -     skb->data[0] = ppph[0];
>> -     skb->data[1] = ppph[1];
>> +     __skb_push(skb, 2);
>>
> Here too.

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

end of thread, other threads:[~2016-08-22 14:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-22 10:59 [PATCH v4 net-next] l2tp: Refactor the codes with existing macros instead of literal number fgao
2016-08-22 14:43 ` Guillaume Nault
2016-08-22 14:51   ` Feng Gao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.