Skip to content
Permalink
Browse files

net: sockets: tls: Register handler for TLS sockets

Use the automatic registration of TLS socket.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar committed Feb 7, 2019
1 parent 89bf157 commit 61f4597d6453f4f396718b40366e875e1ed3a876
@@ -151,13 +151,6 @@ int z_impl_zsock_socket(int family, int type, int proto)
return sock_family->handler(family, type, proto);
}

#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
if (((proto >= IPPROTO_TLS_1_0) && (proto <= IPPROTO_TLS_1_2)) ||
(proto >= IPPROTO_DTLS_1_0 && proto <= IPPROTO_DTLS_1_2)) {
return ztls_socket(family, type, proto);
}
#endif

#if defined(CONFIG_NET_SOCKETS_PACKET)
if (family == AF_PACKET) {
return zpacket_socket(family, type, proto);
@@ -47,8 +47,6 @@ struct socket_op_vtable {
const void *optval, socklen_t optlen);
};

int ztls_socket(int family, int type, int proto);

int zpacket_socket(int family, int type, int proto);
int zcan_socket(int family, int type, int proto);

@@ -1100,7 +1100,7 @@ static int tls_opt_dtls_role_set(struct net_context *context,
return 0;
}

int ztls_socket(int family, int type, int proto)
static int ztls_socket(int family, int type, int proto)
{
enum net_ip_protocol_secure tls_proto = 0;
int fd = z_reserve_fd();
@@ -2017,3 +2017,16 @@ static const struct socket_op_vtable tls_sock_fd_op_vtable = {
.getsockopt = tls_sock_getsockopt_vmeth,
.setsockopt = tls_sock_setsockopt_vmeth,
};

static bool tls_is_supported(int family, int type, int proto)
{
if ((family == AF_INET || family == AF_INET6) &&
(((proto >= IPPROTO_TLS_1_0) && (proto <= IPPROTO_TLS_1_2)) ||
(proto >= IPPROTO_DTLS_1_0 && proto <= IPPROTO_DTLS_1_2))) {
return true;
}

return false;
}

NET_SOCKET_REGISTER(tls, AF_UNSPEC, tls_is_supported, ztls_socket);

0 comments on commit 61f4597

Please sign in to comment.
You can’t perform that action at this time.