Ver código fonte

[tcp] Merge boolean flags into a single "flags" field

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 anos atrás
pai
commit
75505942ac
1 arquivos alterados com 15 adições e 8 exclusões
  1. 15
    8
      src/net/tcp.c

+ 15
- 8
src/net/tcp.c Ver arquivo

@@ -30,10 +30,11 @@ struct tcp_connection {
30 30
 	/** List of TCP connections */
31 31
 	struct list_head list;
32 32
 
33
+	/** Flags */
34
+	unsigned int flags;
35
+
33 36
 	/** Data transfer interface */
34 37
 	struct interface xfer;
35
-	/** Data transfer interface closed flag */
36
-	int xfer_closed;
37 38
 
38 39
 	/** Remote socket address */
39 40
 	struct sockaddr_tcpip peer;
@@ -77,8 +78,6 @@ struct tcp_connection {
77 78
 	 * Equivalent to TS.Recent in RFC 1323 terminology.
78 79
 	 */
79 80
 	uint32_t ts_recent;
80
-	/** Timestamps enabled */
81
-	int timestamps;
82 81
 
83 82
 	/** Transmit queue */
84 83
 	struct list_head queue;
@@ -88,6 +87,14 @@ struct tcp_connection {
88 87
 	struct retry_timer wait;
89 88
 };
90 89
 
90
+/** TCP flags */
91
+enum tcp_flags {
92
+	/** TCP data transfer interface has been closed */
93
+	TCP_XFER_CLOSED = 0x0001,
94
+	/** TCP timestamps are enabled */
95
+	TCP_TS_ENABLED = 0x0002,
96
+};
97
+
91 98
 /**
92 99
  * List of registered TCP connections
93 100
  */
@@ -275,7 +282,7 @@ static void tcp_close ( struct tcp_connection *tcp, int rc ) {
275 282
 
276 283
 	/* Close data transfer interface */
277 284
 	intf_shutdown ( &tcp->xfer, rc );
278
-	tcp->xfer_closed = 1;
285
+	tcp->flags |= TCP_XFER_CLOSED;
279 286
 
280 287
 	/* If we are in CLOSED, or have otherwise not yet received a
281 288
 	 * SYN (i.e. we are in LISTEN or SYN_SENT), just delete the
@@ -474,7 +481,7 @@ static int tcp_xmit ( struct tcp_connection *tcp, int force_send ) {
474 481
 		mssopt->length = sizeof ( *mssopt );
475 482
 		mssopt->mss = htons ( TCP_MSS );
476 483
 	}
477
-	if ( ( flags & TCP_SYN ) || tcp->timestamps ) {
484
+	if ( ( flags & TCP_SYN ) || ( tcp->flags & TCP_TS_ENABLED ) ) {
478 485
 		tsopt = iob_push ( iobuf, sizeof ( *tsopt ) );
479 486
 		memset ( tsopt->nop, TCP_OPTION_NOP, sizeof ( tsopt->nop ) );
480 487
 		tsopt->tsopt.kind = TCP_OPTION_TS;
@@ -719,7 +726,7 @@ static int tcp_rx_syn ( struct tcp_connection *tcp, uint32_t seq,
719 726
 	if ( ! ( tcp->tcp_state & TCP_STATE_RCVD ( TCP_SYN ) ) ) {
720 727
 		tcp->rcv_ack = seq;
721 728
 		if ( options->tsopt )
722
-			tcp->timestamps = 1;
729
+			tcp->flags |= TCP_TS_ENABLED;
723 730
 	}
724 731
 
725 732
 	/* Ignore duplicate SYN */
@@ -801,7 +808,7 @@ static int tcp_rx_ack ( struct tcp_connection *tcp, uint32_t ack,
801 808
 		tcp->tcp_state |= TCP_STATE_ACKED ( acked_flags );
802 809
 
803 810
 	/* Start sending FIN if we've had all possible data ACKed */
804
-	if ( list_empty ( &tcp->queue ) && tcp->xfer_closed )
811
+	if ( list_empty ( &tcp->queue ) && ( tcp->flags & TCP_XFER_CLOSED ) )
805 812
 		tcp->tcp_state |= TCP_STATE_SENT ( TCP_FIN );
806 813
 
807 814
 	return 0;

Carregando…
Cancelar
Salvar