Skip to content

Commit d47ec4f

Browse files
mniestrojcarlescufi
authored andcommitted
drivers: nsos: support IPPROTO_TCP getsockopt() and setsockopt()
Handle IPPROTO_TCP specific options in getsockopt() and setsockopt() APIs. Signed-off-by: Marcin Niestroj <[email protected]>
1 parent 736fe29 commit d47ec4f

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

drivers/net/nsos_adapt.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <fcntl.h>
1717
#include <netdb.h>
1818
#include <netinet/in.h>
19+
#include <netinet/tcp.h>
1920
#include <poll.h>
2021
#include <stdlib.h>
2122
#include <string.h>
@@ -624,6 +625,22 @@ int nsos_adapt_getsockopt(int fd, int nsos_mid_level, int nsos_mid_optname,
624625
return nsos_adapt_getsockopt_int(fd, SOL_SOCKET, SO_KEEPALIVE,
625626
nsos_mid_optval, nsos_mid_optlen);
626627
}
628+
629+
case NSOS_MID_IPPROTO_TCP:
630+
switch (nsos_mid_optname) {
631+
case NSOS_MID_TCP_NODELAY:
632+
return nsos_adapt_getsockopt_int(fd, IPPROTO_TCP, TCP_NODELAY,
633+
nsos_mid_optval, nsos_mid_optlen);
634+
case NSOS_MID_TCP_KEEPIDLE:
635+
return nsos_adapt_getsockopt_int(fd, IPPROTO_TCP, TCP_KEEPIDLE,
636+
nsos_mid_optval, nsos_mid_optlen);
637+
case NSOS_MID_TCP_KEEPINTVL:
638+
return nsos_adapt_getsockopt_int(fd, IPPROTO_TCP, TCP_KEEPINTVL,
639+
nsos_mid_optval, nsos_mid_optlen);
640+
case NSOS_MID_TCP_KEEPCNT:
641+
return nsos_adapt_getsockopt_int(fd, IPPROTO_TCP, TCP_KEEPCNT,
642+
nsos_mid_optval, nsos_mid_optlen);
643+
}
627644
}
628645

629646
return -NSOS_MID_EOPNOTSUPP;
@@ -687,6 +704,22 @@ int nsos_adapt_setsockopt(int fd, int nsos_mid_level, int nsos_mid_optname,
687704
return nsos_adapt_setsockopt_int(fd, SOL_SOCKET, SO_KEEPALIVE,
688705
nsos_mid_optval, nsos_mid_optlen);
689706
}
707+
708+
case NSOS_MID_IPPROTO_TCP:
709+
switch (nsos_mid_optname) {
710+
case NSOS_MID_TCP_NODELAY:
711+
return nsos_adapt_setsockopt_int(fd, IPPROTO_TCP, TCP_NODELAY,
712+
nsos_mid_optval, nsos_mid_optlen);
713+
case NSOS_MID_TCP_KEEPIDLE:
714+
return nsos_adapt_setsockopt_int(fd, IPPROTO_TCP, TCP_KEEPIDLE,
715+
nsos_mid_optval, nsos_mid_optlen);
716+
case NSOS_MID_TCP_KEEPINTVL:
717+
return nsos_adapt_setsockopt_int(fd, IPPROTO_TCP, TCP_KEEPINTVL,
718+
nsos_mid_optval, nsos_mid_optlen);
719+
case NSOS_MID_TCP_KEEPCNT:
720+
return nsos_adapt_setsockopt_int(fd, IPPROTO_TCP, TCP_KEEPCNT,
721+
nsos_mid_optval, nsos_mid_optlen);
722+
}
690723
}
691724

692725
return -NSOS_MID_EOPNOTSUPP;

drivers/net/nsos_socket.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,20 @@ struct nsos_mid_timeval {
8787

8888
/** @} */
8989

90+
/**
91+
* @name TCP level options (NSOS_MID_IPPROTO_TCP)
92+
* @{
93+
*/
94+
/* Socket options for NSOS_MID_IPPROTO_TCP level */
95+
/** Disable TCP buffering (ignored, for compatibility) */
96+
#define NSOS_MID_TCP_NODELAY 1
97+
/** Start keepalives after this period (seconds) */
98+
#define NSOS_MID_TCP_KEEPIDLE 2
99+
/** Interval between keepalives (seconds) */
100+
#define NSOS_MID_TCP_KEEPINTVL 3
101+
/** Number of keepalives before dropping connection */
102+
#define NSOS_MID_TCP_KEEPCNT 4
103+
104+
/** @} */
105+
90106
#endif /* __DRIVERS_NET_NSOS_SOCKET_H__ */

drivers/net/nsos_sockets.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,26 @@ static int nsos_getsockopt(void *obj, int level, int optname,
10241024
NSOS_MID_SOL_SOCKET, NSOS_MID_SO_KEEPALIVE,
10251025
optval, optlen);
10261026
}
1027+
1028+
case IPPROTO_TCP:
1029+
switch (optname) {
1030+
case TCP_NODELAY:
1031+
return nsos_getsockopt_int(sock,
1032+
NSOS_MID_IPPROTO_TCP, NSOS_MID_TCP_NODELAY,
1033+
optval, optlen);
1034+
case TCP_KEEPIDLE:
1035+
return nsos_getsockopt_int(sock,
1036+
NSOS_MID_IPPROTO_TCP, NSOS_MID_TCP_KEEPIDLE,
1037+
optval, optlen);
1038+
case TCP_KEEPINTVL:
1039+
return nsos_getsockopt_int(sock,
1040+
NSOS_MID_IPPROTO_TCP, NSOS_MID_TCP_KEEPINTVL,
1041+
optval, optlen);
1042+
case TCP_KEEPCNT:
1043+
return nsos_getsockopt_int(sock,
1044+
NSOS_MID_IPPROTO_TCP, NSOS_MID_TCP_KEEPCNT,
1045+
optval, optlen);
1046+
}
10271047
}
10281048

10291049
errno = EOPNOTSUPP;
@@ -1133,6 +1153,26 @@ static int nsos_setsockopt(void *obj, int level, int optname,
11331153
NSOS_MID_SOL_SOCKET, NSOS_MID_SO_KEEPALIVE,
11341154
optval, optlen);
11351155
}
1156+
1157+
case IPPROTO_TCP:
1158+
switch (optname) {
1159+
case TCP_NODELAY:
1160+
return nsos_setsockopt_int(sock,
1161+
NSOS_MID_IPPROTO_TCP, NSOS_MID_TCP_NODELAY,
1162+
optval, optlen);
1163+
case TCP_KEEPIDLE:
1164+
return nsos_setsockopt_int(sock,
1165+
NSOS_MID_IPPROTO_TCP, NSOS_MID_TCP_KEEPIDLE,
1166+
optval, optlen);
1167+
case TCP_KEEPINTVL:
1168+
return nsos_setsockopt_int(sock,
1169+
NSOS_MID_IPPROTO_TCP, NSOS_MID_TCP_KEEPINTVL,
1170+
optval, optlen);
1171+
case TCP_KEEPCNT:
1172+
return nsos_setsockopt_int(sock,
1173+
NSOS_MID_IPPROTO_TCP, NSOS_MID_TCP_KEEPCNT,
1174+
optval, optlen);
1175+
}
11361176
}
11371177

11381178
errno = EOPNOTSUPP;

0 commit comments

Comments
 (0)