From ce79811bce54fea22848c2a3769b32d4852d20dc Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 24 Jan 2018 14:35:17 +0100 Subject: [PATCH] sockets: add hooks to implement additional socket options LWIP_HOOK_SOCKETS_SETSOCKOPT() and LWIP_HOOK_SOCKETS_GETSOCKOPT() are introduced to implement additional socket options. The hooks are always called first and report back if they handled the option or not. Signed-off-by: goldsimon --- src/api/sockets.c | 16 +++++++++++++++ src/include/lwip/opt.h | 44 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/api/sockets.c b/src/api/sockets.c index da0d6c23..fcc4b970 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -64,6 +64,10 @@ #include +#ifdef LWIP_HOOK_FILENAME +#include LWIP_HOOK_FILENAME +#endif + /* If the netconn API is not required publicly, then we include the necessary files here to get the implementation */ #if !LWIP_NETCONN @@ -2835,6 +2839,12 @@ lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *opt return EBADF; } +#ifdef LWIP_HOOK_SOCKETS_GETSOCKOPT + if (LWIP_HOOK_SOCKETS_GETSOCKOPT(s, sock, level, optname, optval, optlen, &err)) { + return err; + } +#endif + switch (level) { /* Level: SOL_SOCKET */ @@ -3250,6 +3260,12 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_ return EBADF; } +#ifdef LWIP_HOOK_SOCKETS_SETSOCKOPT + if (LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, &err)) { + return err; + } +#endif + switch (level) { /* Level: SOL_SOCKET */ diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 930253c1..15127c61 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2935,6 +2935,50 @@ #define LWIP_HOOK_DHCP_PARSE_OPTION(netif, dhcp, state, msg, msg_type, option, len, pbuf, offset) #endif +/** + * LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, err) + * Called from socket API to implement setsockopt() for options not provided by lwIP. + * Core lock is held when this hook is called. + * Signature: + * int my_hook(int s, struct lwip_sock *sock, int level, int optname, const void *optval, socklen_t optlen, int *err) + * Arguments: + * - s: socket file descriptor + * - sock: internal socket descriptor (see lwip/priv/sockets_priv.h) + * - level: protocol level at which the option resides + * - optname: option to set + * - optval: value to set + * - optlen: size of optval + * - err: output error + * Return values: + * - 0: Hook has not consumed the option, code continues as normal (to internal options) + * - != 0: Hook has consumed the option, 'err' is returned + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, err) +#endif + +/** + * LWIP_HOOK_SOCKETS_GETSOCKOPT(s, sock, level, optname, optval, optlen, err) + * Called from socket API to implement getsockopt() for options not provided by lwIP. + * Core lock is held when this hook is called. + * Signature: + * int my_hook(int s, struct lwip_sock *sock, int level, int optname, void *optval, socklen_t *optlen, int *err) + * Arguments: + * - s: socket file descriptor + * - sock: internal socket descriptor (see lwip/priv/sockets_priv.h) + * - level: protocol level at which the option resides + * - optname: option to get + * - optval: value to get + * - optlen: size of optval + * - err: output error + * Return values: + * - 0: Hook has not consumed the option, code continues as normal (to internal options) + * - != 0: Hook has consumed the option, 'err' is returned + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_SOCKETS_GETSOCKOPT(s, sock, level, optname, optval, optlen, err) +#endif + /** * LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE(name, addr, addrtype, err) * Called from netconn APIs (not usable with callback apps) allowing an