Skip to content

Commit 87a6df2

Browse files
mniestrojcarlescufi
authored andcommitted
drivers: nsos: support IPV6_V6ONLY getsockopt() and setsockopt()
Handle IPV6_V6ONLY option in getsockopt() and setsockopt() APIs. Signed-off-by: Marcin Niestroj <[email protected]>
1 parent d47ec4f commit 87a6df2

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

drivers/net/nsos_adapt.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,13 @@ int nsos_adapt_getsockopt(int fd, int nsos_mid_level, int nsos_mid_optname,
641641
return nsos_adapt_getsockopt_int(fd, IPPROTO_TCP, TCP_KEEPCNT,
642642
nsos_mid_optval, nsos_mid_optlen);
643643
}
644+
645+
case NSOS_MID_IPPROTO_IPV6:
646+
switch (nsos_mid_optname) {
647+
case NSOS_MID_IPV6_V6ONLY:
648+
return nsos_adapt_getsockopt_int(fd, IPPROTO_IPV6, IPV6_V6ONLY,
649+
nsos_mid_optval, nsos_mid_optlen);
650+
}
644651
}
645652

646653
return -NSOS_MID_EOPNOTSUPP;
@@ -720,6 +727,13 @@ int nsos_adapt_setsockopt(int fd, int nsos_mid_level, int nsos_mid_optname,
720727
return nsos_adapt_setsockopt_int(fd, IPPROTO_TCP, TCP_KEEPCNT,
721728
nsos_mid_optval, nsos_mid_optlen);
722729
}
730+
731+
case NSOS_MID_IPPROTO_IPV6:
732+
switch (nsos_mid_optname) {
733+
case NSOS_MID_IPV6_V6ONLY:
734+
return nsos_adapt_setsockopt_int(fd, IPPROTO_IPV6, IPV6_V6ONLY,
735+
nsos_mid_optval, nsos_mid_optlen);
736+
}
723737
}
724738

725739
return -NSOS_MID_EOPNOTSUPP;

drivers/net/nsos_socket.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,32 @@ struct nsos_mid_timeval {
103103

104104
/** @} */
105105

106+
/**
107+
* @name IPv6 level options (NSOS_MID_IPPROTO_IPV6)
108+
* @{
109+
*/
110+
/* Socket options for NSOS_MID_IPPROTO_IPV6 level */
111+
/** Set the unicast hop limit for the socket. */
112+
#define NSOS_MID_IPV6_UNICAST_HOPS 16
113+
114+
/** Set the multicast hop limit for the socket. */
115+
#define NSOS_MID_IPV6_MULTICAST_HOPS 18
116+
117+
/** Join IPv6 multicast group. */
118+
#define NSOS_MID_IPV6_ADD_MEMBERSHIP 20
119+
120+
/** Leave IPv6 multicast group. */
121+
#define NSOS_MID_IPV6_DROP_MEMBERSHIP 21
122+
123+
/** Don't support IPv4 access */
124+
#define NSOS_MID_IPV6_V6ONLY 26
125+
126+
/** Pass an IPV6_RECVPKTINFO ancillary message that contains a
127+
* in6_pktinfo structure that supplies some information about the
128+
* incoming packet. See RFC 3542.
129+
*/
130+
#define NSOS_MID_IPV6_RECVPKTINFO 49
131+
132+
/** @} */
133+
106134
#endif /* __DRIVERS_NET_NSOS_SOCKET_H__ */

drivers/net/nsos_sockets.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,14 @@ static int nsos_getsockopt(void *obj, int level, int optname,
10441044
NSOS_MID_IPPROTO_TCP, NSOS_MID_TCP_KEEPCNT,
10451045
optval, optlen);
10461046
}
1047+
1048+
case IPPROTO_IPV6:
1049+
switch (optname) {
1050+
case IPV6_V6ONLY:
1051+
return nsos_getsockopt_int(sock,
1052+
NSOS_MID_IPPROTO_IPV6, NSOS_MID_IPV6_V6ONLY,
1053+
optval, optlen);
1054+
}
10471055
}
10481056

10491057
errno = EOPNOTSUPP;
@@ -1173,6 +1181,14 @@ static int nsos_setsockopt(void *obj, int level, int optname,
11731181
NSOS_MID_IPPROTO_TCP, NSOS_MID_TCP_KEEPCNT,
11741182
optval, optlen);
11751183
}
1184+
1185+
case IPPROTO_IPV6:
1186+
switch (optname) {
1187+
case IPV6_V6ONLY:
1188+
return nsos_setsockopt_int(sock,
1189+
NSOS_MID_IPPROTO_IPV6, NSOS_MID_IPV6_V6ONLY,
1190+
optval, optlen);
1191+
}
11761192
}
11771193

11781194
errno = EOPNOTSUPP;

0 commit comments

Comments
 (0)