Skip to content

Commit 0345934

Browse files
gfreewinddavem330
authored andcommitted
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: Gao Feng <fgao@ikuai8.com> Reviewed-by: Philip Prindeville <philipp@redfish-solutions.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cfad65c commit 0345934

3 files changed

Lines changed: 24 additions & 35 deletions

File tree

‎drivers/net/ppp/pptp.c‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,14 @@ static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
206206
skb_push(skb, header_len);
207207
hdr = (struct pptp_gre_header *)(skb->data);
208208

209-
hdr->flags = PPTP_GRE_FLAG_K;
210-
hdr->ver = PPTP_GRE_VER;
211-
hdr->protocol = htons(PPTP_GRE_PROTO);
212-
hdr->call_id = htons(opt->dst_addr.call_id);
209+
hdr->gre_hd.flags = GRE_KEY | GRE_VERSION_1 | GRE_SEQ;
210+
hdr->gre_hd.protocol = GRE_PROTO_PPP;
211+
hdr->call_id = htons(opt->dst_addr.call_id);
213212

214-
hdr->flags |= PPTP_GRE_FLAG_S;
215-
hdr->seq = htonl(++opt->seq_sent);
213+
hdr->seq = htonl(++opt->seq_sent);
216214
if (opt->ack_sent != seq_recv) {
217215
/* send ack with this message */
218-
hdr->ver |= PPTP_GRE_FLAG_A;
216+
hdr->gre_hd.flags |= GRE_ACK;
219217
hdr->ack = htonl(seq_recv);
220218
opt->ack_sent = seq_recv;
221219
}
@@ -278,15 +276,15 @@ static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb)
278276
headersize = sizeof(*header);
279277

280278
/* test if acknowledgement present */
281-
if (PPTP_GRE_IS_A(header->ver)) {
279+
if (GRE_IS_ACK(header->gre_hd.flags)) {
282280
__u32 ack;
283281

284282
if (!pskb_may_pull(skb, headersize))
285283
goto drop;
286284
header = (struct pptp_gre_header *)(skb->data);
287285

288286
/* ack in different place if S = 0 */
289-
ack = PPTP_GRE_IS_S(header->flags) ? header->ack : header->seq;
287+
ack = GRE_IS_SEQ(header->gre_hd.flags) ? header->ack : header->seq;
290288

291289
ack = ntohl(ack);
292290

@@ -299,7 +297,7 @@ static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb)
299297
headersize -= sizeof(header->ack);
300298
}
301299
/* test if payload present */
302-
if (!PPTP_GRE_IS_S(header->flags))
300+
if (!GRE_IS_SEQ(header->gre_hd.flags))
303301
goto drop;
304302

305303
payload_len = ntohs(header->payload_len);
@@ -360,11 +358,11 @@ static int pptp_rcv(struct sk_buff *skb)
360358

361359
header = (struct pptp_gre_header *)skb->data;
362360

363-
if (ntohs(header->protocol) != PPTP_GRE_PROTO || /* PPTP-GRE protocol for PPTP */
364-
PPTP_GRE_IS_C(header->flags) || /* flag C should be clear */
365-
PPTP_GRE_IS_R(header->flags) || /* flag R should be clear */
366-
!PPTP_GRE_IS_K(header->flags) || /* flag K should be set */
367-
(header->flags&0xF) != 0) /* routing and recursion ctrl = 0 */
361+
if (header->gre_hd.protocol != GRE_PROTO_PPP || /* PPTP-GRE protocol for PPTP */
362+
GRE_IS_CSUM(header->gre_hd.flags) || /* flag CSUM should be clear */
363+
GRE_IS_ROUTING(header->gre_hd.flags) || /* flag ROUTING should be clear */
364+
!GRE_IS_KEY(header->gre_hd.flags) || /* flag KEY should be set */
365+
(header->gre_hd.flags & GRE_FLAGS)) /* flag Recursion Ctrl should be clear */
368366
/* if invalid, discard this packet */
369367
goto drop;
370368

‎include/net/pptp.h‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,9 @@
1010
((((curseq) & 0xffffff00) == 0) &&\
1111
(((lastseq) & 0xffffff00) == 0xffffff00))
1212

13-
#define PPTP_GRE_PROTO 0x880B
14-
#define PPTP_GRE_VER 0x1
15-
16-
#define PPTP_GRE_FLAG_C 0x80
17-
#define PPTP_GRE_FLAG_R 0x40
18-
#define PPTP_GRE_FLAG_K 0x20
19-
#define PPTP_GRE_FLAG_S 0x10
20-
#define PPTP_GRE_FLAG_A 0x80
21-
22-
#define PPTP_GRE_IS_C(f) ((f)&PPTP_GRE_FLAG_C)
23-
#define PPTP_GRE_IS_R(f) ((f)&PPTP_GRE_FLAG_R)
24-
#define PPTP_GRE_IS_K(f) ((f)&PPTP_GRE_FLAG_K)
25-
#define PPTP_GRE_IS_S(f) ((f)&PPTP_GRE_FLAG_S)
26-
#define PPTP_GRE_IS_A(f) ((f)&PPTP_GRE_FLAG_A)
27-
2813
#define PPTP_HEADER_OVERHEAD (2+sizeof(struct pptp_gre_header))
2914
struct pptp_gre_header {
30-
u8 flags;
31-
u8 ver;
32-
__be16 protocol;
15+
struct gre_base_hdr gre_hd;
3316
__be16 payload_len;
3417
__be16 call_id;
3518
__be32 seq;

‎include/uapi/linux/if_tunnel.h‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,16 @@
2828
#define GRE_FLAGS __cpu_to_be16(0x0078)
2929
#define GRE_VERSION __cpu_to_be16(0x0007)
3030

31-
#define GRE_VERSION_1 __cpu_to_be16(0x0001)
32-
#define GRE_PROTO_PPP __cpu_to_be16(0x880b)
31+
#define GRE_IS_CSUM(f) ((f) & GRE_CSUM)
32+
#define GRE_IS_ROUTING(f) ((f) & GRE_ROUTING)
33+
#define GRE_IS_KEY(f) ((f) & GRE_KEY)
34+
#define GRE_IS_SEQ(f) ((f) & GRE_SEQ)
35+
#define GRE_IS_STRICT(f) ((f) & GRE_STRICT)
36+
#define GRE_IS_REC(f) ((f) & GRE_REC)
37+
#define GRE_IS_ACK(f) ((f) & GRE_ACK)
38+
39+
#define GRE_VERSION_1 __cpu_to_be16(0x0001)
40+
#define GRE_PROTO_PPP __cpu_to_be16(0x880b)
3341
#define GRE_PPTP_KEY_MASK __cpu_to_be32(0xffff)
3442

3543
struct ip_tunnel_parm {

0 commit comments

Comments
 (0)