Skip to content

Commit 1584a16

Browse files
committed
lib: add setsockopt IP_TRANSPARENT
Add sockopt_ip_transparent(), a thin wrapper around setsockopt(sock, SOL_IP, IP_TRANSPARENT) guarded by #ifdef IP_TRANSPARENT. This lets daemons such as bgpd create transparent sockets when running on kernels that support the option, while keeping the build portable on systems that do not provide it. Signed-off-by: Vincent Jardin <[email protected]>
1 parent 4998363 commit 1584a16

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/sockopt.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,3 +739,21 @@ int setsockopt_tcp_keepalive(int sock, uint16_t keepalive_idle,
739739
return 0;
740740
#endif
741741
}
742+
743+
/* set IP_TRANSPARENT to socket */
744+
void sockopt_ip_transparent(int sock)
745+
{
746+
int err = -1;
747+
748+
#if defined(IP_TRANSPARENT)
749+
const char flag_on = 1;
750+
751+
err = setsockopt(sock, SOL_IP, IP_TRANSPARENT, &flag_on, sizeof(flag_on));
752+
#else
753+
err = ENOPROTOOPT;
754+
#endif
755+
if (err < 0) {
756+
flog_err_sys(EC_LIB_SYSTEM_CALL, "%s failed: setsockopt(%d, IP_TRANSPARENT): %s",
757+
__func__, sock, safe_strerror(errno));
758+
}
759+
}

lib/sockopt.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ extern int setsockopt_tcp_keepalive(int sock, uint16_t keepalive_idle,
170170
uint16_t keepalive_intvl,
171171
uint16_t keepalive_probes);
172172

173+
/*
174+
* Set IP_TRANSPARENT option to socket
175+
*
176+
* sock
177+
* Socket to enable option on.
178+
*/
179+
extern void sockopt_ip_transparent(int sock);
180+
173181
#ifdef __cplusplus
174182
}
175183
#endif

0 commit comments

Comments
 (0)