tcp: Generalise probing for tcpi_snd_wnd field
In order to use the tcpi_snd_wnd field from the TCP_INFO getsockopt() we need the field to be supported in the runtime kernel (snd_wnd_cap). In fact we should check that for for every tcp_info field we want to use, beyond the very old ones shared with BSD. Prepare to do that, by generalising the probing from setting a single bool to instead record the size of the returned TCP_INFO structure. We can then use that recorded value to check for the presence of any field we need. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
13f0291ede
commit
81143813a6
1 changed files with 19 additions and 15 deletions
34
tcp.c
34
tcp.c
|
@ -361,10 +361,15 @@ char tcp_buf_discard [MAX_WINDOW];
|
||||||
/* Does the kernel support TCP_PEEK_OFF? */
|
/* Does the kernel support TCP_PEEK_OFF? */
|
||||||
bool peek_offset_cap;
|
bool peek_offset_cap;
|
||||||
|
|
||||||
/* Does the kernel report sending window in TCP_INFO (kernel commit
|
/* Size of data returned by TCP_INFO getsockopt() */
|
||||||
* 8f7baad7f035)
|
socklen_t tcp_info_size;
|
||||||
*/
|
|
||||||
bool snd_wnd_cap;
|
#define tcp_info_cap(f_) \
|
||||||
|
((offsetof(struct tcp_info_linux, tcpi_##f_) + \
|
||||||
|
sizeof(((struct tcp_info_linux *)NULL)->tcpi_##f_)) <= tcp_info_size)
|
||||||
|
|
||||||
|
/* Kernel reports sending window in TCP_INFO (kernel commit 8f7baad7f035) */
|
||||||
|
#define snd_wnd_cap tcp_info_cap(snd_wnd)
|
||||||
|
|
||||||
/* sendmsg() to socket */
|
/* sendmsg() to socket */
|
||||||
static struct iovec tcp_iov [UIO_MAXIOV];
|
static struct iovec tcp_iov [UIO_MAXIOV];
|
||||||
|
@ -2571,11 +2576,11 @@ static bool tcp_probe_peek_offset_cap(sa_family_t af)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tcp_probe_snd_wnd_cap() - Check if TCP_INFO reports tcpi_snd_wnd
|
* tcp_probe_tcp_info() - Check what data TCP_INFO reports
|
||||||
*
|
*
|
||||||
* Return: true if supported, false otherwise
|
* Return: Number of bytes returned by TCP_INFO getsockopt()
|
||||||
*/
|
*/
|
||||||
static bool tcp_probe_snd_wnd_cap(void)
|
static socklen_t tcp_probe_tcp_info(void)
|
||||||
{
|
{
|
||||||
struct tcp_info_linux tinfo;
|
struct tcp_info_linux tinfo;
|
||||||
socklen_t sl = sizeof(tinfo);
|
socklen_t sl = sizeof(tinfo);
|
||||||
|
@ -2595,11 +2600,7 @@ static bool tcp_probe_snd_wnd_cap(void)
|
||||||
|
|
||||||
close(s);
|
close(s);
|
||||||
|
|
||||||
if (sl < (offsetof(struct tcp_info_linux, tcpi_snd_wnd) +
|
return sl;
|
||||||
sizeof(tinfo.tcpi_snd_wnd)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2635,9 +2636,12 @@ int tcp_init(struct ctx *c)
|
||||||
(!c->ifi6 || tcp_probe_peek_offset_cap(AF_INET6));
|
(!c->ifi6 || tcp_probe_peek_offset_cap(AF_INET6));
|
||||||
debug("SO_PEEK_OFF%ssupported", peek_offset_cap ? " " : " not ");
|
debug("SO_PEEK_OFF%ssupported", peek_offset_cap ? " " : " not ");
|
||||||
|
|
||||||
snd_wnd_cap = tcp_probe_snd_wnd_cap();
|
tcp_info_size = tcp_probe_tcp_info();
|
||||||
debug("TCP_INFO tcpi_snd_wnd field%ssupported",
|
|
||||||
snd_wnd_cap ? " " : " not ");
|
#define dbg_tcpi(f_) debug("TCP_INFO tcpi_%s field%s supported", \
|
||||||
|
STRINGIFY(f_), tcp_info_cap(f_) ? " " : " not ")
|
||||||
|
dbg_tcpi(snd_wnd);
|
||||||
|
#undef dbg_tcpi
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue