fast-ping: force send RST after ping finish.

This commit is contained in:
Nick Peng
2020-04-19 09:43:47 +08:00
parent 3985ea8269
commit 304e94bc6f
3 changed files with 21 additions and 0 deletions

View File

@@ -573,6 +573,11 @@ static int _fast_ping_sendping_tcp(struct ping_host_struct *ping_host)
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority));
setsockopt(fd, IPPROTO_IP, IP_TOS, &ip_tos, sizeof(ip_tos));
set_sock_keepalive(fd, 0, 0, 0);
/* Set the socket lingering so we will RST connections instead of wasting
* bandwidth with the four-step close
*/
set_sock_lingertime(fd, 0);
ping_host->seq++;
if (connect(fd, (struct sockaddr *)&ping_host->addr, ping_host->addr_len) != 0) {

View File

@@ -969,5 +969,19 @@ int set_sock_keepalive(int fd, int keepidle, int keepinterval, int keepcnt)
setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepinterval, sizeof(keepinterval));
setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepcnt, sizeof(keepcnt));
return 0;
}
int set_sock_lingertime(int fd, int time)
{
struct linger l;
l.l_onoff = 1;
l.l_linger = 0;
if (setsockopt(fd, SOL_SOCKET, SO_LINGER, (const char *)&l, sizeof(l)) != 0) {
return -1;
}
return 0;
}

View File

@@ -102,6 +102,8 @@ int has_network_raw_cap(void);
int set_sock_keepalive(int fd, int keepidle, int keepinterval, int keepcnt);
int set_sock_lingertime(int fd, int time);
#ifdef __cplusplus
}
#endif /*__cplusplus */