Skip to content

Commit e59fb26

Browse files
shrek-wangkartben
authored andcommitted
net: tcp: Remove the 'goto next_state' in tcp_in()
Each incoming TCP packet has been completely handled in current state. No need to do further process by 'goto next_state'. Signed-off-by: Shrek Wang <inet_eman@outlook.com>
1 parent c1a173a commit e59fb26

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

subsys/net/ip/tcp.c

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,6 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt)
29212921
}
29222922
}
29232923

2924-
next_state:
29252924
len = pkt ? tcp_data_len(pkt) : 0;
29262925

29272926
switch (conn->state) {
@@ -3091,8 +3090,6 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt)
30913090
case TCP_ESTABLISHED:
30923091
/* full-close */
30933092
if (th && FL(&fl, &, FIN, th_seq(th) == conn->ack)) {
3094-
bool acked = false;
3095-
30963093
if (len) {
30973094
verdict = tcp_data_get(conn, pkt, &len);
30983095
if (verdict == NET_OK) {
@@ -3106,25 +3103,16 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt)
31063103
conn_ack(conn, + len + 1);
31073104
keep_alive_timer_stop(conn);
31083105

3109-
if (FL(&fl, &, ACK)) {
3110-
acked = true;
3111-
3112-
if (net_tcp_seq_cmp(th_ack(th), conn->seq) > 0) {
3113-
uint32_t len_acked = th_ack(th) - conn->seq;
3106+
if (FL(&fl, &, ACK) && (net_tcp_seq_cmp(th_ack(th), conn->seq) > 0)) {
3107+
uint32_t len_acked = th_ack(th) - conn->seq;
31143108

3115-
conn_seq(conn, + len_acked);
3116-
}
3109+
conn_seq(conn, len_acked);
31173110
}
31183111

3119-
if (acked) {
3120-
tcp_out(conn, FIN | ACK);
3121-
conn_seq(conn, + 1);
3122-
tcp_setup_last_ack_timer(conn);
3123-
next = TCP_LAST_ACK;
3124-
} else {
3125-
tcp_out(conn, ACK);
3126-
next = TCP_CLOSE_WAIT;
3127-
}
3112+
tcp_out(conn, FIN | ACK);
3113+
conn_seq(conn, 1);
3114+
tcp_setup_last_ack_timer(conn);
3115+
next = TCP_LAST_ACK;
31283116

31293117
break;
31303118
}
@@ -3316,10 +3304,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt)
33163304

33173305
break;
33183306
case TCP_CLOSE_WAIT:
3319-
tcp_out(conn, FIN | ACK);
3320-
conn_seq(conn, + 1);
3321-
next = TCP_LAST_ACK;
3322-
tcp_setup_last_ack_timer(conn);
3307+
/* Half-close is not supported, so do nothing here */
33233308
break;
33243309
case TCP_LAST_ACK:
33253310
if (th && FL(&fl, ==, ACK, th_ack(th) == conn->seq)) {
@@ -3586,8 +3571,6 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt)
35863571

35873572
k_sem_give(&conn->connect_sem);
35883573
}
3589-
3590-
goto next_state;
35913574
}
35923575

35933576
if (conn->context) {

0 commit comments

Comments
 (0)