All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] l2tp: Use existing macros instead of literal number
@ 2016-08-19  9:55 fgao
  2016-08-19 18:28 ` Guillaume Nault
  0 siblings, 1 reply; 7+ messages in thread
From: fgao @ 2016-08-19  9:55 UTC (permalink / raw)
  To: jchapman, davem, g.nault, philipp, netdev; +Cc: gfree.wind, Gao Feng

From: Gao Feng <fgao@ikuai8.com>

1. Use PPP_ALLSTATIONS/PPP_UI instead of literal 0xff/0x03;
2. Use one static const global fixed_ppphdr instead of two same
static variable ppph in two different functions;
3. Use SEND_SHUTDOWN instead of literal 2;

Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
 v1: Initial patch

 net/l2tp/l2tp_ppp.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
index d9560aa..0e69eb4 100644
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -138,6 +138,8 @@ static const struct ppp_channel_ops pppol2tp_chan_ops = {
 
 static const struct proto_ops pppol2tp_ops;
 
+static const unsigned char fixed_ppphdr[2] = {PPP_ALLSTATIONS, PPP_UI};
+
 /* Helpers to obtain tunnel/session contexts from sockets.
  */
 static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)
@@ -174,11 +176,11 @@ static int pppol2tp_recv_payload_hook(struct sk_buff *skb)
 	 * Note that skb->data[] isn't dereferenced from a u16 ptr here since
 	 * the field may be unaligned.
 	 */
-	if (!pskb_may_pull(skb, 2))
+	if (!pskb_may_pull(skb, sizeof(fixed_ppphdr)))
 		return 1;
 
-	if ((skb->data[0] == 0xff) && (skb->data[1] == 0x03))
-		skb_pull(skb, 2);
+	if ((PPP_ADDRESS(skb->data) == PPP_ALLSTATIONS) && (PPP_CONTROL(skb->data) == PPP_UI))
+		skb_pull(skb, sizeof(fixed_ppphdr));
 
 	return 0;
 }
@@ -282,7 +284,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 +313,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,
+			   sizeof(fixed_ppphdr) + total_len,
 			   0, GFP_KERNEL);
 	if (!skb)
 		goto error_put_sess_tun;
@@ -325,9 +326,9 @@ 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_put(skb, 2);
+	PPP_ADDRESS(skb->data) = fixed_ppphdr[0];
+	PPP_CONTROL(skb->data) = fixed_ppphdr[1];
+	skb_put(skb, sizeof(fixed_ppphdr));
 
 	/* Copy user data into skb */
 	error = memcpy_from_msg(skb_put(skb, total_len), m, total_len);
@@ -369,7 +370,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 +398,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 */
+		   sizeof(fixed_ppphdr); /* PPP header */
 	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, sizeof(fixed_ppphdr));
+	skb->data[0] = fixed_ppphdr[0];
+	skb->data[1] = fixed_ppphdr[1];
 
 	local_bh_disable();
 	l2tp_xmit_skb(session, skb, session->hdr_len);
@@ -440,7 +440,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] 7+ messages in thread

* Re: [PATCH v1 1/1] l2tp: Use existing macros instead of literal number
  2016-08-19  9:55 [PATCH v1 1/1] l2tp: Use existing macros instead of literal number fgao
@ 2016-08-19 18:28 ` Guillaume Nault
  2016-08-20  6:24   ` Feng Gao
  0 siblings, 1 reply; 7+ messages in thread
From: Guillaume Nault @ 2016-08-19 18:28 UTC (permalink / raw)
  To: fgao; +Cc: jchapman, davem, philipp, netdev, gfree.wind

On Fri, Aug 19, 2016 at 05:55:26PM +0800, fgao@ikuai8.com wrote:
> From: Gao Feng <fgao@ikuai8.com>
> 
> 1. Use PPP_ALLSTATIONS/PPP_UI instead of literal 0xff/0x03;
> 2. Use one static const global fixed_ppphdr instead of two same
> static variable ppph in two different functions;
> 3. Use SEND_SHUTDOWN instead of literal 2;
> 
> Signed-off-by: Gao Feng <fgao@ikuai8.com>
> ---
>  v1: Initial patch
> 
v1 again?

BTW, no need to number your patch for a single patch series.
But you have to tell which tree is the series for.

So instead of [PATCH v1 1/1], you should send [PATCH v2 net-next].

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

* Re: [PATCH v1 1/1] l2tp: Use existing macros instead of literal number
  2016-08-19 18:28 ` Guillaume Nault
@ 2016-08-20  6:24   ` Feng Gao
  0 siblings, 0 replies; 7+ messages in thread
From: Feng Gao @ 2016-08-20  6:24 UTC (permalink / raw)
  To: Guillaume Nault
  Cc: Gao Feng, jchapman, David S. Miller, Philp Prindeville,
	Linux Kernel Network Developers

Sorry, I forget to modify the title.
I will sent another update.

On Sat, Aug 20, 2016 at 2:28 AM, Guillaume Nault <g.nault@alphalink.fr> wrote:
> On Fri, Aug 19, 2016 at 05:55:26PM +0800, fgao@ikuai8.com wrote:
>> From: Gao Feng <fgao@ikuai8.com>
>>
>> 1. Use PPP_ALLSTATIONS/PPP_UI instead of literal 0xff/0x03;
>> 2. Use one static const global fixed_ppphdr instead of two same
>> static variable ppph in two different functions;
>> 3. Use SEND_SHUTDOWN instead of literal 2;
>>
>> Signed-off-by: Gao Feng <fgao@ikuai8.com>
>> ---
>>  v1: Initial patch
>>
> v1 again?
>
> BTW, no need to number your patch for a single patch series.
> But you have to tell which tree is the series for.
>
> So instead of [PATCH v1 1/1], you should send [PATCH v2 net-next].

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

* Re: [PATCH v1 1/1] l2tp: Use existing macros instead of literal number
  2016-08-18  7:05 fgao
  2016-08-18 18:41 ` Guillaume Nault
@ 2016-08-19 21:32 ` David Miller
  1 sibling, 0 replies; 7+ messages in thread
From: David Miller @ 2016-08-19 21:32 UTC (permalink / raw)
  To: fgao; +Cc: jchapman, netdev, gfree.wind

From: fgao@ikuai8.com
Date: Thu, 18 Aug 2016 15:05:19 +0800

> @@ -138,6 +138,8 @@ static const struct ppp_channel_ops pppol2tp_chan_ops = {
>  
>  static const struct proto_ops pppol2tp_ops;
>  
> +static const unsigned char fixed_ppphdr[2] = {PPP_ALLSTATIONS, PPP_UI};
> +
>  /* Helpers to obtain tunnel/session contexts from sockets.
>   */
>  static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)

Same problem as the pptp patch, I'm not applying this.

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

* Re: [PATCH v1 1/1] l2tp: Use existing macros instead of literal number
  2016-08-18 18:41 ` Guillaume Nault
@ 2016-08-18 23:02   ` Feng Gao
  0 siblings, 0 replies; 7+ messages in thread
From: Feng Gao @ 2016-08-18 23:02 UTC (permalink / raw)
  To: Guillaume Nault
  Cc: Gao Feng, jchapman, David S. Miller, Linux Kernel Network Developers

On Fri, Aug 19, 2016 at 2:41 AM, Guillaume Nault <g.nault@alphalink.fr> wrote:
> On Thu, Aug 18, 2016 at 03:05:19PM +0800, fgao@ikuai8.com wrote:
>> From: Gao Feng <fgao@ikuai8.com>
>>
>> 1. Use PPP_ALLSTATIONS/PPP_UI instead of literal 0xff/0x03;
>> 2. Use one static const global fixed_ppphdr instead of two same
>> static variable ppph in two different functions;
>> 3. Use SEND_SHUTDOWN instead of literal 2;
>>
>> Signed-off-by: Gao Feng <fgao@ikuai8.com>
>> ---
>>  v1: Initial patch
> No need to send 'v1' for the initial series.

OK, I get it.

>
>> --- a/net/l2tp/l2tp_ppp.c
>> +++ b/net/l2tp/l2tp_ppp.c
>> @@ -138,6 +138,8 @@ static const struct ppp_channel_ops pppol2tp_chan_ops = {
>>
>>  static const struct proto_ops pppol2tp_ops;
>>
>> +static const unsigned char fixed_ppphdr[2] = {PPP_ALLSTATIONS, PPP_UI};
>> +
>>  /* Helpers to obtain tunnel/session contexts from sockets.
>>   */
>>  static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)
>> @@ -174,11 +176,11 @@ static int pppol2tp_recv_payload_hook(struct sk_buff *skb)
>>        * Note that skb->data[] isn't dereferenced from a u16 ptr here since
>>        * the field may be unaligned.
>>        */
>> -     if (!pskb_may_pull(skb, 2))
>> +     if (!pskb_may_pull(skb, sizeof(fixed_ppphdr)))
>>               return 1;
>>
>> -     if ((skb->data[0] == 0xff) && (skb->data[1] == 0x03))
>> -             skb_pull(skb, 2);
>> +     if ((PPP_ADDRESS(skb->data) == PPP_ALLSTATIONS) && (PPP_CONTROL(skb->data) == PPP_UI))
>> +             skb_pull(skb, sizeof(fixed_ppphdr));
>>
> Sorry, but I find the original code clearer. It's important to be
> explicit about what's done with the sk_buff. Hiding skb->data[x] behind
> macros certainly doesn't help.
>
> Same thing for the use of sizeof(fixed_ppphdr) in pskb_may_pull(). The
> size of fixed_ppphdr isn't used aftewards, so it's unclear why its size
> was pulled. 2 was not a magic number here, it was directly related with
> the operations done on the skb (i.e. accessing skb->data[0] and
> skb->data[1]). So pskb_may_pull(skb, 2) makes perfect sense.

Agree now because of detail explanation.
Thanks.

>
> OTOH, replacing 0xff and 0x03 with PPP_ALLSTATIONS and PPP_UI is fine.

OK. get it.

>
>> @@ -312,7 +313,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,
>> +                        sizeof(fixed_ppphdr) + total_len,
>>                          0, GFP_KERNEL);
>>       if (!skb)
>>               goto error_put_sess_tun;
>> @@ -325,9 +326,9 @@ 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_put(skb, 2);
>> +     PPP_ADDRESS(skb->data) = fixed_ppphdr[0];
>> +     PPP_CONTROL(skb->data) = fixed_ppphdr[1];
>> +     skb_put(skb, sizeof(fixed_ppphdr));
>>
> Same here. What about
> + skb->data[0] = PPP_ALLSTATIONS;
> + skb->data[1] = PPP_UI;
> + skb_put(skb, 2);
> and removing ppph entirely?

Agree with you.

>
>>       /* Copy user data into skb */
>>       error = memcpy_from_msg(skb_put(skb, total_len), m, total_len);
>> @@ -369,7 +370,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 +398,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 */
>> +                sizeof(fixed_ppphdr); /* PPP header */
>>       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, sizeof(fixed_ppphdr));
>> +     skb->data[0] = fixed_ppphdr[0];
>> +     skb->data[1] = fixed_ppphdr[1];
>>
> Same as for pppol2tp_sendmsg().
>
>> @@ -440,7 +440,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);
>>
> Ok.

Regards
Feng

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

* Re: [PATCH v1 1/1] l2tp: Use existing macros instead of literal number
  2016-08-18  7:05 fgao
@ 2016-08-18 18:41 ` Guillaume Nault
  2016-08-18 23:02   ` Feng Gao
  2016-08-19 21:32 ` David Miller
  1 sibling, 1 reply; 7+ messages in thread
From: Guillaume Nault @ 2016-08-18 18:41 UTC (permalink / raw)
  To: fgao; +Cc: jchapman, davem, netdev, gfree.wind

On Thu, Aug 18, 2016 at 03:05:19PM +0800, fgao@ikuai8.com wrote:
> From: Gao Feng <fgao@ikuai8.com>
> 
> 1. Use PPP_ALLSTATIONS/PPP_UI instead of literal 0xff/0x03;
> 2. Use one static const global fixed_ppphdr instead of two same
> static variable ppph in two different functions;
> 3. Use SEND_SHUTDOWN instead of literal 2;
> 
> Signed-off-by: Gao Feng <fgao@ikuai8.com>
> ---
>  v1: Initial patch
No need to send 'v1' for the initial series.

> --- a/net/l2tp/l2tp_ppp.c
> +++ b/net/l2tp/l2tp_ppp.c
> @@ -138,6 +138,8 @@ static const struct ppp_channel_ops pppol2tp_chan_ops = {
>  
>  static const struct proto_ops pppol2tp_ops;
>  
> +static const unsigned char fixed_ppphdr[2] = {PPP_ALLSTATIONS, PPP_UI};
> +
>  /* Helpers to obtain tunnel/session contexts from sockets.
>   */
>  static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)
> @@ -174,11 +176,11 @@ static int pppol2tp_recv_payload_hook(struct sk_buff *skb)
>  	 * Note that skb->data[] isn't dereferenced from a u16 ptr here since
>  	 * the field may be unaligned.
>  	 */
> -	if (!pskb_may_pull(skb, 2))
> +	if (!pskb_may_pull(skb, sizeof(fixed_ppphdr)))
>  		return 1;
>  
> -	if ((skb->data[0] == 0xff) && (skb->data[1] == 0x03))
> -		skb_pull(skb, 2);
> +	if ((PPP_ADDRESS(skb->data) == PPP_ALLSTATIONS) && (PPP_CONTROL(skb->data) == PPP_UI))
> +		skb_pull(skb, sizeof(fixed_ppphdr));
>
Sorry, but I find the original code clearer. It's important to be
explicit about what's done with the sk_buff. Hiding skb->data[x] behind
macros certainly doesn't help.

Same thing for the use of sizeof(fixed_ppphdr) in pskb_may_pull(). The
size of fixed_ppphdr isn't used aftewards, so it's unclear why its size
was pulled. 2 was not a magic number here, it was directly related with
the operations done on the skb (i.e. accessing skb->data[0] and
skb->data[1]). So pskb_may_pull(skb, 2) makes perfect sense.

OTOH, replacing 0xff and 0x03 with PPP_ALLSTATIONS and PPP_UI is fine.

> @@ -312,7 +313,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,
> +			   sizeof(fixed_ppphdr) + total_len,
>  			   0, GFP_KERNEL);
>  	if (!skb)
>  		goto error_put_sess_tun;
> @@ -325,9 +326,9 @@ 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_put(skb, 2);
> +	PPP_ADDRESS(skb->data) = fixed_ppphdr[0];
> +	PPP_CONTROL(skb->data) = fixed_ppphdr[1];
> +	skb_put(skb, sizeof(fixed_ppphdr));
>
Same here. What about
+ skb->data[0] = PPP_ALLSTATIONS;
+ skb->data[1] = PPP_UI;
+ skb_put(skb, 2);
and removing ppph entirely?

>  	/* Copy user data into skb */
>  	error = memcpy_from_msg(skb_put(skb, total_len), m, total_len);
> @@ -369,7 +370,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 +398,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 */
> +		   sizeof(fixed_ppphdr); /* PPP header */
>  	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, sizeof(fixed_ppphdr));
> +	skb->data[0] = fixed_ppphdr[0];
> +	skb->data[1] = fixed_ppphdr[1];
> 
Same as for pppol2tp_sendmsg().

> @@ -440,7 +440,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);
> 
Ok.

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

* [PATCH v1 1/1] l2tp: Use existing macros instead of literal number
@ 2016-08-18  7:05 fgao
  2016-08-18 18:41 ` Guillaume Nault
  2016-08-19 21:32 ` David Miller
  0 siblings, 2 replies; 7+ messages in thread
From: fgao @ 2016-08-18  7:05 UTC (permalink / raw)
  To: jchapman, davem, netdev; +Cc: gfree.wind, Gao Feng

From: Gao Feng <fgao@ikuai8.com>

1. Use PPP_ALLSTATIONS/PPP_UI instead of literal 0xff/0x03;
2. Use one static const global fixed_ppphdr instead of two same
static variable ppph in two different functions;
3. Use SEND_SHUTDOWN instead of literal 2;

Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
 v1: Initial patch

 net/l2tp/l2tp_ppp.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
index d9560aa..0e69eb4 100644
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -138,6 +138,8 @@ static const struct ppp_channel_ops pppol2tp_chan_ops = {
 
 static const struct proto_ops pppol2tp_ops;
 
+static const unsigned char fixed_ppphdr[2] = {PPP_ALLSTATIONS, PPP_UI};
+
 /* Helpers to obtain tunnel/session contexts from sockets.
  */
 static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)
@@ -174,11 +176,11 @@ static int pppol2tp_recv_payload_hook(struct sk_buff *skb)
 	 * Note that skb->data[] isn't dereferenced from a u16 ptr here since
 	 * the field may be unaligned.
 	 */
-	if (!pskb_may_pull(skb, 2))
+	if (!pskb_may_pull(skb, sizeof(fixed_ppphdr)))
 		return 1;
 
-	if ((skb->data[0] == 0xff) && (skb->data[1] == 0x03))
-		skb_pull(skb, 2);
+	if ((PPP_ADDRESS(skb->data) == PPP_ALLSTATIONS) && (PPP_CONTROL(skb->data) == PPP_UI))
+		skb_pull(skb, sizeof(fixed_ppphdr));
 
 	return 0;
 }
@@ -282,7 +284,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 +313,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,
+			   sizeof(fixed_ppphdr) + total_len,
 			   0, GFP_KERNEL);
 	if (!skb)
 		goto error_put_sess_tun;
@@ -325,9 +326,9 @@ 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_put(skb, 2);
+	PPP_ADDRESS(skb->data) = fixed_ppphdr[0];
+	PPP_CONTROL(skb->data) = fixed_ppphdr[1];
+	skb_put(skb, sizeof(fixed_ppphdr));
 
 	/* Copy user data into skb */
 	error = memcpy_from_msg(skb_put(skb, total_len), m, total_len);
@@ -369,7 +370,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 +398,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 */
+		   sizeof(fixed_ppphdr); /* PPP header */
 	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, sizeof(fixed_ppphdr));
+	skb->data[0] = fixed_ppphdr[0];
+	skb->data[1] = fixed_ppphdr[1];
 
 	local_bh_disable();
 	l2tp_xmit_skb(session, skb, session->hdr_len);
@@ -440,7 +440,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] 7+ messages in thread

end of thread, other threads:[~2016-08-20  6:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-19  9:55 [PATCH v1 1/1] l2tp: Use existing macros instead of literal number fgao
2016-08-19 18:28 ` Guillaume Nault
2016-08-20  6:24   ` Feng Gao
  -- strict thread matches above, loose matches on Subject: below --
2016-08-18  7:05 fgao
2016-08-18 18:41 ` Guillaume Nault
2016-08-18 23:02   ` Feng Gao
2016-08-19 21:32 ` David Miller

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.