TCP-IP Setup Using SYSCTL
From RTEMSWiki
TCP-IP Setup
The FreeBSD provides a number of parmeters that allow the stack to be tuned in specific ways. On a FreeBSD the parameters are usually tuned for a server or workstation, how-ever RTEMS being an embedded operating system sometimes requires different tuning of these parameters.
To change the keepalive state, the keepalive interval and the keepidle the function tcpip_setup is provided below.
The keepalive value can be 0 to disable keep alive requests or 1 to enable them. The keepidle period is the number of seconds between keep alive requests. The keepidle period is the period of time in seconds before keep alive requests are made.
RTEMS is currently missing the sysctlbyname call required to access OID_AUTO sysctl variables. You need to include this in your application until such time as the file is added to RTEMS. You can find the source code here -
http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/gen/sysctlbyname.c
void tcpip_setup (int keepalive, int keepintvl, int keepidle);
/* Needs to match the setting used to compile the stack. */
#define BYTE_PACK
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <netinet/tcp.h>
#include <netinet/tcp_timer.h>
#include <netinet/tcp_var.h>
void
tcpip_setup (int keepalive, int keepintvl, int keepidle)
{
int mib[4], value;
size_t len;
unsigned32 result;
mib[0] = CTL_NET;
mib[1] = PF_INET;
mib[2] = IPPROTO_TCP;
// set tcp_keepintvl to 20 (10 seconds between keepalive probes)
value = keepalive;
len = sizeof (value);
result = sysctlbyname ("always_keepalive", NULL, 0, &value, len);
if (result < 0)
printf ("tcpip-setup: always_keepalive: %s\n", strerror (errno));
// set tcp_keepintvl to 20 (10 seconds between keepalive probes)
mib[3] = TCPCTL_KEEPINTVL;
value = keepintvl;
len = sizeof (value);
result = sysctl (mib, 4, NULL, 0, &value, len);
if (result < 0)
printf ("tcpip-setup: keepintvl: %s\n", strerror (errno));
// set tcp_keepidle to 60 (30 seconds idle before first probe)
mib[3] = TCPCTL_KEEPIDLE;
value = keepidle;
len = sizeof (value);
result = sysctl (mib, 4, NULL, 0, &value, len);
if (result < 0)
printf ("tcpip-setup: keepidle: %s\n", strerror (errno));
}
