Skip to contentSkip to conversation

tcp: unify tcp flag macros

PATCH Superseded Changli Gao 3 participants 5 messages Jun 12, 2010

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: unify tcp flag macros

unify tcp flag macros

unify tcp flag macros: TH_FIN, TH_SYN, TH_RST, TH_PUSH, TH_ACK, TH_URG, TH_ECE and TH_CWR. TCBCB_FLAG_* are replaced with the corresponding TH_*.

----

 include/net/tcp.h                      |   24 +++++-------
 net/ipv4/tcp.c                         |    8 ++--
 net/ipv4/tcp_input.c                   |    2 -
 net/ipv4/tcp_output.c                  |   62 +++++++++++++++------------------
 net/netfilter/nf_conntrack_proto_tcp.c |   11 -----
 net/netfilter/xt_TCPMSS.c              |    2 -
 6 files changed, 46 insertions(+), 63 deletions(-)
include/net/tcp.h +11 -13
index 5731664..238b636 100644
@@ -602,6 +602,17 @@ extern u32	__tcp_select_window(struct sock *sk);
  */
 #define tcp_time_stamp		((__u32)(jiffies))
 
+#define tcp_flag_byte(th) (((u_int8_t *)th)[13])
+
+#define	TH_FIN	0x01
+#define	TH_SYN	0x02
+#define	TH_RST	0x04
+#define	TH_PUSH	0x08
+#define	TH_ACK	0x10
+#define	TH_URG	0x20
+#define	TH_ECE	0x40
+#define	TH_CWR	0x80
+
 /* This is what the send packet queuing engine uses to pass
  * TCP per-packet control information to the transmission
  * code.  We also store the host-order sequence numbers in
@@ -620,19 +631,6 @@ struct tcp_skb_cb {
 	__u32		end_seq;	/* SEQ + FIN + SYN + datalen	*/
 	__u32		when;		/* used to compute rtt's	*/
 	__u8		flags;		/* TCP header flags.		*/
-
-	/* NOTE: These must match up to the flags byte in a
-	 *       real TCP header.
-	 */
-#define TCPCB_FLAG_FIN		0x01
-#define TCPCB_FLAG_SYN		0x02
-#define TCPCB_FLAG_RST		0x04
-#define TCPCB_FLAG_PSH		0x08
-#define TCPCB_FLAG_ACK		0x10
-#define TCPCB_FLAG_URG		0x20
-#define TCPCB_FLAG_ECE		0x40
-#define TCPCB_FLAG_CWR		0x80
-
 	__u8		sacked;		/* State flags for SACK/FACK.	*/
 #define TCPCB_SACKED_ACKED	0x01	/* SKB ACK'd by a SACK block	*/
 #define TCPCB_SACKED_RETRANS	0x02	/* SKB retransmitted		*/
net/ipv4/tcp.c +4 -4
index 49d0d2b..ada200d 100644
@@ -511,7 +511,7 @@ int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg)
 
 static inline void tcp_mark_push(struct tcp_sock *tp, struct sk_buff *skb)
 {
-	TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_PSH;
+	TCP_SKB_CB(skb)->flags |= TH_PUSH;
 	tp->pushed_seq = tp->write_seq;
 }
 
@@ -527,7 +527,7 @@ static inline void skb_entail(struct sock *sk, struct sk_buff *skb)
 
 	skb->csum    = 0;
 	tcb->seq     = tcb->end_seq = tp->write_seq;
-	tcb->flags   = TCPCB_FLAG_ACK;
+	tcb->flags   = TH_ACK;
 	tcb->sacked  = 0;
 	skb_header_release(skb);
 	tcp_add_write_queue_tail(sk, skb);
@@ -815,7 +815,7 @@ new_segment:
 		skb_shinfo(skb)->gso_segs = 0;
 
 		if (!copied)
-			TCP_SKB_CB(skb)->flags &= ~TCPCB_FLAG_PSH;
+			TCP_SKB_CB(skb)->flags &= ~TH_PUSH;
 
 		copied += copy;
 		poffset += copy;
@@ -1061,7 +1061,7 @@ new_segment:
 			}
 
 			if (!copied)
-				TCP_SKB_CB(skb)->flags &= ~TCPCB_FLAG_PSH;
+				TCP_SKB_CB(skb)->flags &= ~TH_PUSH;
 
 			tp->write_seq += copy;
 			TCP_SKB_CB(skb)->end_seq += copy;
net/ipv4/tcp_input.c +1 -1
index 548d575..fbadd66 100644
@@ -3286,7 +3286,7 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets,
 		 * connection startup slow start one packet too
 		 * quickly.  This is severely frowned upon behavior.
 		 */
-		if (!(scb->flags & TCPCB_FLAG_SYN)) {
+		if (!(scb->flags & TH_SYN)) {
 			flag |= FLAG_DATA_ACKED;
 		} else {
 			flag |= FLAG_SYN_ACKED;
net/ipv4/tcp_output.c +29 -33

227 lines not on this page · raw message

net/netfilter/nf_conntrack_proto_tcp.c +1 -10
index 9dd8cd4..8c65d62 100644
@@ -736,15 +736,6 @@ static bool tcp_in_window(const struct nf_conn *ct,
 	return res;
 }
 
-#define	TH_FIN	0x01
-#define	TH_SYN	0x02
-#define	TH_RST	0x04
-#define	TH_PUSH	0x08
-#define	TH_ACK	0x10
-#define	TH_URG	0x20
-#define	TH_ECE	0x40
-#define	TH_CWR	0x80
-
 /* table of valid flag combinations - PUSH, ECE and CWR are always valid */
 static const u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG) + 1] =
 {
@@ -803,7 +794,7 @@ static int tcp_error(struct net *net, struct nf_conn *tmpl,
 	}
 
 	/* Check TCP flags. */
-	tcpflags = (((u_int8_t *)th)[13] & ~(TH_ECE|TH_CWR|TH_PUSH));
+	tcpflags = (tcp_flag_byte(th) & ~(TH_ECE|TH_CWR|TH_PUSH));
 	if (!tcp_valid_flags[tcpflags]) {
 		if (LOG_INVALID(net, IPPROTO_TCP))
 			nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
net/netfilter/xt_TCPMSS.c +0 -2
index 1841388..5bd203b 100644
@@ -220,8 +220,6 @@ tcpmss_tg6(struct sk_buff *skb, const struct xt_action_param *par)
 }
 #endif
 
-#define TH_SYN 0x02
-
 /* Must specify -p tcp --syn */
 static inline bool find_syn_match(const struct xt_entry_match *m)
 {
#1 lore raw
Quoted 6 lines · Changli Gao
include/net/tcp.h +0 -0
@@ -602,6 +602,17 @@ extern u32	__tcp_select_window(struct sock *sk);
 */
 #define tcp_time_stamp		((__u32)(jiffies))
 

include/net/tcp.h extern u32 __tcp_select_window(struct sock *sk); · line 614

Quoted 10 lines
include/net/tcp.h +10 -0
+#define tcp_flag_byte(th) (((u_int8_t *)th)[13])
+
+#define	TH_FIN	0x01
+#define	TH_SYN	0x02
+#define	TH_RST	0x04
+#define	TH_PUSH	0x08
+#define	TH_ACK	0x10
+#define	TH_URG	0x20
+#define	TH_ECE	0x40
+#define	TH_CWR	0x80

I'd prefer something less generic, like TCPHDR_{FIN,SYN,etc}.

#2 lore raw
Quoted 8 lines · Jan Engelhardt
Quoted 6 lines · Changli Gao
include/net/tcp.h +0 -0
@@ -602,6 +602,17 @@ extern u32        __tcp_select_window(struct sock *sk);
  */
 #define tcp_time_stamp                ((__u32)(jiffies))
 
Quoted 14 lines

include/net/tcp.h extern u32 __tcp_select_window(struct sock *sk); · line 614

Quoted 10 lines
include/net/tcp.h +10 -0
+#define tcp_flag_byte(th) (((u_int8_t *)th)[13])
+
+#define       TH_FIN  0x01
+#define       TH_SYN  0x02
+#define       TH_RST  0x04
+#define       TH_PUSH 0x08
+#define       TH_ACK  0x10
+#define       TH_URG  0x20
+#define       TH_ECE  0x40
+#define       TH_CWR  0x80

I'd prefer something less generic, like TCPHDR_{FIN,SYN,etc}.

The same macros are definied by BSDs too. So I think it is better to keep them the same.

Signature · 2 lines
Regards,
Changli Gao([email protected])
maintainer
#3 lore raw

From: Changli Gao <[email protected]>
Date: Sat, 12 Jun 2010 17:21:09 +0800

Quoted 2 lines

The same macros are definied by BSDs too. So I think it is better to keep them the same.

That is an absolutely meaningless argument.

This is a "net/*.h" header, not something in "linux/*.h" that application in userspace might want access to.

It's entirely private to the kernel, therefore we do what makes the most sense (from a cleanliness and namespace perspective) rather than "what other people do."

#4 lore raw
Quoted 4 lines · David Miller
Quoted 3 lines

The same macros are definied by BSDs too. So I think it is better to keep them the same.

Quoted 8 lines

That is an absolutely meaningless argument.

This is a "net/*.h" header, not something in "linux/*.h" that application in userspace might want access to.

It's entirely private to the kernel, therefore we do what makes the most sense (from a cleanliness and namespace perspective) rather than "what other people do."

And we'd also need to fight netinet/in.h in userspace programs, because they do already define TH_*.