Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: tcp stack bugs #72

Merged
merged 1 commit into from
Mar 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 33 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ static int config_parse_mss(int argc, char *argv[], void *data)
}

mss = config_parse_number(argv[1], false, false);
if ((mss < 0) || (mss > MSS_MAX)) {
if (mss <= 0) {
return -1;
}

Expand Down Expand Up @@ -1413,6 +1413,36 @@ static int config_check_size(struct config *cfg)
return 0;
}

static int config_check_mss(struct config *cfg)
{
int mss_max = 0;

if (cfg->ipv6) {
if (cfg->jumbo) {
mss_max = MSS_JUMBO_IPV6;
} else {
mss_max = MSS_IPV6;
}
} else {
if (cfg->jumbo) {
mss_max = MSS_JUMBO_IPV4;
} else {
mss_max = MSS_IPV4;
}
}

if (cfg->mss > mss_max) {
printf("Error: bad mss %d\n", cfg->mss);
return -1;
}

if (cfg->mss == 0) {
cfg->mss = mss_max;
}

return 0;
}

int config_parse(int argc, char **argv, struct config *cfg)
{
int conf = 0;
Expand Down Expand Up @@ -1467,8 +1497,8 @@ int config_parse(int argc, char **argv, struct config *cfg)
cfg->duration = DEFAULT_DURATION;
}

if (cfg->mss == 0) {
cfg->mss = MSS_MAX;
if (config_check_mss(cfg) < 0) {
return -1;
}

if ((cfg->listen == 0) || (cfg->listen_num == 0)) {
Expand Down
7 changes: 6 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#define RTE_ARG_LEN 64
#define CACHE_ALIGN_SIZE 64
#define MSS_MAX 1460
#define TCP_WIN (1460 * 10)
#define NETWORK_PORT_NUM 65536

#define PACKET_SIZE_MAX 1514
Expand All @@ -51,6 +51,11 @@
#define JUMBO_MBUF_SIZE (1024 * 11)
#define MBUF_DATA_SIZE (1024 * 10)

#define MSS_IPV4 (PACKET_SIZE_MAX - 14 - 20 - 20)
#define MSS_IPV6 (PACKET_SIZE_MAX - 14 - 40 - 20)
#define MSS_JUMBO_IPV4 (JUMBO_PKT_SIZE_MAX - 14 - 20 - 20)
#define MSS_JUMBO_IPV6 (JUMBO_PKT_SIZE_MAX - 14 - 40 - 20)

#define LOG_DIR "/var/log/dperf"

struct config {
Expand Down
2 changes: 1 addition & 1 deletion src/mbuf_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static int mbuf_data_push_tcp(struct mbuf_data *mdata)
uint16_t len = sizeof(struct tcphdr);

memset(&th, 0, len);
th.th_win = htons(MSS_MAX);
th.th_win = htons(TCP_WIN);
th.th_off = 5;

mdata->l4_len = len;
Expand Down
7 changes: 5 additions & 2 deletions src/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,18 +484,21 @@ static inline uint8_t tcp_process_fin(struct socket *sk, uint8_t rx_flags, uint8
case SK_FIN_WAIT_1:
if (rx_flags & TH_FIN) {
flags = TH_ACK;
/* todo TIME WAIT */
/* enter TIME WAIT */
socket_close(sk);
} else {
/* wait FIN */
sk->state = SK_FIN_WAIT_2;
}
break;
case SK_LAST_ACK:
socket_close(sk);
break;
case SK_FIN_WAIT_2:
/* FIN is here */
if (rx_flags & TH_FIN) {
/* todo TIME WAIT */
flags = TH_ACK;
/* enter TIME WAIT */
socket_close(sk);
}
case SK_TIME_WAIT:
Expand Down