Skip to content

Commit 6d03a91

Browse files
add tcp_info logging to track link quality
1 parent 0b37771 commit 6d03a91

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

include/pepsal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ enum proxy_status {
3535
struct pep_proxy;
3636

3737
struct pep_endpoint{
38-
int addr;
39-
unsigned short port;
38+
int addr;
39+
unsigned short port;
4040
int fd;
4141
struct pep_buffer buf;
4242
struct pep_proxy *owner;

src/pep.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include <getopt.h>
3838
#include <linux/netfilter.h>
3939
#include <netinet/ip.h>
40-
#include <netinet/tcp.h>
40+
#include <linux/tcp.h>
4141
#include <arpa/inet.h>
4242
#include <net/if.h>
4343

@@ -246,14 +246,15 @@ static void logger_fn(void)
246246
struct pep_proxy *proxy;
247247
time_t tm;
248248
char ip_src[17], ip_dst[17];
249-
int len, i = 0;
249+
int len, i = 0, tcp_info_length;
250+
struct tcp_info tcp_info;
250251

251252
PEP_DEBUG("Logger invoked!");
252253
SYNTAB_LOCK_READ();
253254
tm = time(NULL);
254255
fprintf(logger.file, "{\"time\":%.f,\"proxies\":[",difftime(tm, (time_t) 0));
255256
syntab_foreach_connection(proxy) {
256-
if (i > 0)
257+
if (i++ > 0)
257258
fprintf(logger.file, ",");
258259

259260
toip(ip_src, proxy->src.addr);
@@ -266,11 +267,23 @@ static void logger_fn(void)
266267
fprintf(logger.file, "\"sync_recv\":%.f", difftime(proxy->syn_time, (time_t) 0));
267268

268269
if (proxy->last_rxtx != 0) {
269-
fprintf(logger.file, ",\"last_act\":\"%s\"", difftime(proxy->last_rxtx, (time_t) 0));
270+
fprintf(logger.file, ",\"last_rxtx\":\"%.f\"", difftime(proxy->last_rxtx, (time_t) 0));
270271
}
271272

273+
tcp_info_length = sizeof(tcp_info);
274+
if ( getsockopt(proxy->dst.fd, IPPROTO_TCP, TCP_INFO, (void *)&tcp_info,
275+
(socklen_t *)&tcp_info_length ) == 0 ) {
276+
fprintf(logger.file,"\",rto\":%u,", tcp_info.tcpi_rto);
277+
fprintf(logger.file,"\"retrans\":%u,", tcp_info.tcpi_total_retrans);
278+
fprintf(logger.file,"\"rtt\":%u,", tcp_info.tcpi_rtt);
279+
fprintf(logger.file,"\"rtt_var\":%u,", tcp_info.tcpi_rttvar);
280+
fprintf(logger.file,"\"btyes_recv\":%u,", tcp_info.tcpi_bytes_received);
281+
fprintf(logger.file,"\"segs_in\":%u,", tcp_info.tcpi_segs_in);
282+
fprintf(logger.file,"\"segs_out\":%u,", tcp_info.tcpi_segs_out);
283+
fprintf(logger.file,"\"tcp_delivery_rate_byps\":%lu", tcp_info.tcpi_delivery_rate);
284+
}
285+
272286
fprintf(logger.file, "}");
273-
i++;
274287
}
275288
fprintf(logger.file, "]}\n");
276289

@@ -639,7 +652,7 @@ void *listener_loop(void UNUSED(*unused))
639652
/* Set TCP_FASTOPEN socket option */
640653
if (fastopen) {
641654
optval = 5;
642-
ret = setsockopt(listenfd, SOL_TCP, TCP_FASTOPEN,
655+
ret = setsockopt(listenfd, IPPROTO_TCP, TCP_FASTOPEN,
643656
&optval, sizeof(optval));
644657
if (ret < 0) {
645658
pep_error("Failed to set TCP_FASTOPEN option! [RET = %d]", ret);

0 commit comments

Comments
 (0)