Commit 03459345 authored by Gao Feng's avatar Gao Feng Committed by David S. Miller

pptp: Refactor the struct and macros of PPTP codes

1. Use struct gre_base_hdr directly in pptp_gre_header instead of
duplicated members;
2. Use existing macros like GRE_KEY, GRE_SEQ, and so on instead of
duplicated macros defined by PPTP;
3. Add new macros like GRE_IS_ACK/SEQ and so on instead of
PPTP_GRE_IS_A/S and so on;
Signed-off-by: default avatarGao Feng <fgao@ikuai8.com>
Reviewed-by: default avatarPhilip Prindeville <philipp@redfish-solutions.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cfad65c7
...@@ -206,16 +206,14 @@ static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb) ...@@ -206,16 +206,14 @@ static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
skb_push(skb, header_len); skb_push(skb, header_len);
hdr = (struct pptp_gre_header *)(skb->data); hdr = (struct pptp_gre_header *)(skb->data);
hdr->flags = PPTP_GRE_FLAG_K; hdr->gre_hd.flags = GRE_KEY | GRE_VERSION_1 | GRE_SEQ;
hdr->ver = PPTP_GRE_VER; hdr->gre_hd.protocol = GRE_PROTO_PPP;
hdr->protocol = htons(PPTP_GRE_PROTO); hdr->call_id = htons(opt->dst_addr.call_id);
hdr->call_id = htons(opt->dst_addr.call_id);
hdr->flags |= PPTP_GRE_FLAG_S; hdr->seq = htonl(++opt->seq_sent);
hdr->seq = htonl(++opt->seq_sent);
if (opt->ack_sent != seq_recv) { if (opt->ack_sent != seq_recv) {
/* send ack with this message */ /* send ack with this message */
hdr->ver |= PPTP_GRE_FLAG_A; hdr->gre_hd.flags |= GRE_ACK;
hdr->ack = htonl(seq_recv); hdr->ack = htonl(seq_recv);
opt->ack_sent = seq_recv; opt->ack_sent = seq_recv;
} }
...@@ -278,7 +276,7 @@ static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb) ...@@ -278,7 +276,7 @@ static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb)
headersize = sizeof(*header); headersize = sizeof(*header);
/* test if acknowledgement present */ /* test if acknowledgement present */
if (PPTP_GRE_IS_A(header->ver)) { if (GRE_IS_ACK(header->gre_hd.flags)) {
__u32 ack; __u32 ack;
if (!pskb_may_pull(skb, headersize)) if (!pskb_may_pull(skb, headersize))
...@@ -286,7 +284,7 @@ static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb) ...@@ -286,7 +284,7 @@ static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb)
header = (struct pptp_gre_header *)(skb->data); header = (struct pptp_gre_header *)(skb->data);
/* ack in different place if S = 0 */ /* ack in different place if S = 0 */
ack = PPTP_GRE_IS_S(header->flags) ? header->ack : header->seq; ack = GRE_IS_SEQ(header->gre_hd.flags) ? header->ack : header->seq;
ack = ntohl(ack); ack = ntohl(ack);
...@@ -299,7 +297,7 @@ static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb) ...@@ -299,7 +297,7 @@ static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb)
headersize -= sizeof(header->ack); headersize -= sizeof(header->ack);
} }
/* test if payload present */ /* test if payload present */
if (!PPTP_GRE_IS_S(header->flags)) if (!GRE_IS_SEQ(header->gre_hd.flags))
goto drop; goto drop;
payload_len = ntohs(header->payload_len); payload_len = ntohs(header->payload_len);
...@@ -360,11 +358,11 @@ static int pptp_rcv(struct sk_buff *skb) ...@@ -360,11 +358,11 @@ static int pptp_rcv(struct sk_buff *skb)
header = (struct pptp_gre_header *)skb->data; header = (struct pptp_gre_header *)skb->data;
if (ntohs(header->protocol) != PPTP_GRE_PROTO || /* PPTP-GRE protocol for PPTP */ if (header->gre_hd.protocol != GRE_PROTO_PPP || /* PPTP-GRE protocol for PPTP */
PPTP_GRE_IS_C(header->flags) || /* flag C should be clear */ GRE_IS_CSUM(header->gre_hd.flags) || /* flag CSUM should be clear */
PPTP_GRE_IS_R(header->flags) || /* flag R should be clear */ GRE_IS_ROUTING(header->gre_hd.flags) || /* flag ROUTING should be clear */
!PPTP_GRE_IS_K(header->flags) || /* flag K should be set */ !GRE_IS_KEY(header->gre_hd.flags) || /* flag KEY should be set */
(header->flags&0xF) != 0) /* routing and recursion ctrl = 0 */ (header->gre_hd.flags & GRE_FLAGS)) /* flag Recursion Ctrl should be clear */
/* if invalid, discard this packet */ /* if invalid, discard this packet */
goto drop; goto drop;
......
...@@ -10,26 +10,9 @@ ...@@ -10,26 +10,9 @@
((((curseq) & 0xffffff00) == 0) &&\ ((((curseq) & 0xffffff00) == 0) &&\
(((lastseq) & 0xffffff00) == 0xffffff00)) (((lastseq) & 0xffffff00) == 0xffffff00))
#define PPTP_GRE_PROTO 0x880B
#define PPTP_GRE_VER 0x1
#define PPTP_GRE_FLAG_C 0x80
#define PPTP_GRE_FLAG_R 0x40
#define PPTP_GRE_FLAG_K 0x20
#define PPTP_GRE_FLAG_S 0x10
#define PPTP_GRE_FLAG_A 0x80
#define PPTP_GRE_IS_C(f) ((f)&PPTP_GRE_FLAG_C)
#define PPTP_GRE_IS_R(f) ((f)&PPTP_GRE_FLAG_R)
#define PPTP_GRE_IS_K(f) ((f)&PPTP_GRE_FLAG_K)
#define PPTP_GRE_IS_S(f) ((f)&PPTP_GRE_FLAG_S)
#define PPTP_GRE_IS_A(f) ((f)&PPTP_GRE_FLAG_A)
#define PPTP_HEADER_OVERHEAD (2+sizeof(struct pptp_gre_header)) #define PPTP_HEADER_OVERHEAD (2+sizeof(struct pptp_gre_header))
struct pptp_gre_header { struct pptp_gre_header {
u8 flags; struct gre_base_hdr gre_hd;
u8 ver;
__be16 protocol;
__be16 payload_len; __be16 payload_len;
__be16 call_id; __be16 call_id;
__be32 seq; __be32 seq;
......
...@@ -28,8 +28,16 @@ ...@@ -28,8 +28,16 @@
#define GRE_FLAGS __cpu_to_be16(0x0078) #define GRE_FLAGS __cpu_to_be16(0x0078)
#define GRE_VERSION __cpu_to_be16(0x0007) #define GRE_VERSION __cpu_to_be16(0x0007)
#define GRE_VERSION_1 __cpu_to_be16(0x0001) #define GRE_IS_CSUM(f) ((f) & GRE_CSUM)
#define GRE_PROTO_PPP __cpu_to_be16(0x880b) #define GRE_IS_ROUTING(f) ((f) & GRE_ROUTING)
#define GRE_IS_KEY(f) ((f) & GRE_KEY)
#define GRE_IS_SEQ(f) ((f) & GRE_SEQ)
#define GRE_IS_STRICT(f) ((f) & GRE_STRICT)
#define GRE_IS_REC(f) ((f) & GRE_REC)
#define GRE_IS_ACK(f) ((f) & GRE_ACK)
#define GRE_VERSION_1 __cpu_to_be16(0x0001)
#define GRE_PROTO_PPP __cpu_to_be16(0x880b)
#define GRE_PPTP_KEY_MASK __cpu_to_be32(0xffff) #define GRE_PPTP_KEY_MASK __cpu_to_be32(0xffff)
struct ip_tunnel_parm { struct ip_tunnel_parm {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment