Skip to content

Commit f2ef654

Browse files
shrek-wangkartben
authored andcommitted
net: tcp: Replace the FIN only case with FIN+ACK
According to TCP Spec. RFC793, ACK flag should be always set after sequences of both sides are sync-ed except for RST seg- ment. It is not necessary to send FIN only packet in the test case, using FIN | ACK instead. Similarly, change the tcp_out(conn, FIN | ACK) in CLOSE_WAIT. Signed-off-by: Shrek Wang <[email protected]>
1 parent ee45869 commit f2ef654

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

subsys/net/ip/tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3316,7 +3316,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt)
33163316

33173317
break;
33183318
case TCP_CLOSE_WAIT:
3319-
tcp_out(conn, FIN);
3319+
tcp_out(conn, FIN | ACK);
33203320
conn_seq(conn, + 1);
33213321
next = TCP_LAST_ACK;
33223322
tcp_setup_last_ack_timer(conn);

tests/net/tcp/src/main.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,6 @@ static struct net_pkt *prepare_fin_ack_packet(sa_family_t af, uint16_t src_port,
380380
NULL, 0U);
381381
}
382382

383-
static struct net_pkt *prepare_fin_packet(sa_family_t af, uint16_t src_port,
384-
uint16_t dst_port)
385-
{
386-
return tester_prepare_tcp_pkt(af, src_port, dst_port, FIN, NULL, 0U);
387-
}
388-
389383
static struct net_pkt *prepare_rst_packet(sa_family_t af, uint16_t src_port,
390384
uint16_t dst_port)
391385
{
@@ -1166,7 +1160,7 @@ static void handle_client_fin_wait_2_test(sa_family_t af, struct tcphdr *th)
11661160
break;
11671161
case T_FIN_2:
11681162
t_state = T_FIN_ACK;
1169-
reply = prepare_fin_packet(af, htons(MY_PORT), th->th_sport);
1163+
reply = prepare_fin_ack_packet(af, htons(MY_PORT), th->th_sport);
11701164
break;
11711165
case T_FIN_ACK:
11721166
test_verify_flags(th, ACK);
@@ -1459,7 +1453,7 @@ static void handle_data_fin1_test(sa_family_t af, struct tcphdr *th)
14591453
break;
14601454
case T_FIN_2:
14611455
t_state = T_FIN_ACK;
1462-
reply = prepare_fin_packet(af, htons(MY_PORT), th->th_sport);
1456+
reply = prepare_fin_ack_packet(af, htons(MY_PORT), th->th_sport);
14631457
break;
14641458
case T_FIN_ACK:
14651459
test_verify_flags(th, ACK);
@@ -1813,12 +1807,12 @@ static void handle_client_closing_failure_test(sa_family_t af, struct tcphdr *th
18131807
case T_FIN:
18141808
test_verify_flags(th, FIN | ACK);
18151809
t_state = T_FIN_1;
1816-
reply = prepare_fin_packet(af, htons(MY_PORT), th->th_sport);
1810+
reply = prepare_fin_ack_packet(af, htons(MY_PORT), th->th_sport);
18171811
break;
18181812
case T_FIN_1:
18191813
test_verify_flags(th, FIN | ACK);
18201814
t_state = T_CLOSING;
1821-
reply = prepare_fin_packet(af, htons(MY_PORT), th->th_sport);
1815+
reply = prepare_fin_ack_packet(af, htons(MY_PORT), th->th_sport);
18221816
break;
18231817
case T_CLOSING:
18241818
test_verify_flags(th, FIN | ACK);
@@ -2418,7 +2412,6 @@ ZTEST(net_tcp, test_client_rst_on_unexpected_ack_on_syn)
24182412
#define TEST_FIN_DATA "test_data"
24192413

24202414
static enum fin_data_variant {
2421-
FIN_DATA_FIN,
24222415
FIN_DATA_FIN_ACK,
24232416
FIN_DATA_FIN_ACK_PSH,
24242417
} test_fin_data_variant;
@@ -2458,10 +2451,6 @@ static void handle_client_fin_ack_with_data_test(sa_family_t af, struct tcphdr *
24582451
return;
24592452
case T_DATA:
24602453
switch (test_fin_data_variant) {
2461-
case FIN_DATA_FIN:
2462-
flags = FIN;
2463-
t_state = T_FIN;
2464-
break;
24652454
case FIN_DATA_FIN_ACK:
24662455
flags = FIN | ACK;
24672456
t_state = T_FIN_ACK;
@@ -2500,7 +2489,7 @@ static void handle_client_fin_ack_with_data_test(sa_family_t af, struct tcphdr *
25002489
break;
25012490

25022491
case T_CLOSING:
2503-
test_verify_flags(th, FIN);
2492+
test_verify_flags(th, FIN | ACK);
25042493
zassert_equal(get_rel_seq(th), 1, "Unexpected SEQ number in T_CLOSING, got %d",
25052494
get_rel_seq(th));
25062495

@@ -2568,7 +2557,7 @@ ZTEST(net_tcp, test_client_fin_ack_with_data)
25682557

25692558
k_work_init_delayable(&test_fin_data_work, test_fin_data_handler);
25702559

2571-
for (enum fin_data_variant variant = FIN_DATA_FIN;
2560+
for (enum fin_data_variant variant = FIN_DATA_FIN_ACK;
25722561
variant <= FIN_DATA_FIN_ACK_PSH; variant++) {
25732562
test_fin_data_variant = variant;
25742563
t_state = T_SYN;

0 commit comments

Comments
 (0)