Commit 12cc7bbd authored by Chris Friedt's avatar Chris Friedt Committed by Anas Nashif
Browse files

net: sockets: use z_finalize_typed_fd() to identify as sockets

Fill-in the mode field of the fd_entry so that the
implementation can be made aware that the specific file
descriptors created are sockets.

Signed-off-by: default avatarChris Friedt <cfriedt@tenstorrent.com>
parent e1b95eb6
Loading
Loading
Loading
Loading
+7 −6
Changes for doc/connectivity/networking/api/sockets.rst: 7 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -186,12 +186,13 @@ APIs, specified in :c:struct:`socket_op_vtable` struct.

The function registered for socket creation should allocate a new file
descriptor using :c:func:`z_reserve_fd` function. Any additional actions,
specific to the creation of a particular offloaded socket implementation should
take place after the file descriptor is allocated. As a final step, if the
offloaded socket was created successfully, the file descriptor should be
finalized with :c:func:`z_finalize_fd` function. The finalize function allows
to register a :c:struct:`socket_op_vtable` structure implementing socket APIs
for an offloaded socket along with an optional socket context data pointer.
specific to the creation of a particular offloaded socket implementation,
should take place after the file descriptor is allocated. As a final step,
if the offloaded socket was created successfully, the file descriptor should
be finalized with :c:func:`z_finalize_typed_fd`, or :c:func:`z_finalize_fd`
functions. The finalize function allows to register a
:c:struct:`socket_op_vtable` structure implementing socket APIs for an
offloaded socket along with an optional socket context data pointer.

Finally, when an offloaded network interface is initialized, it should indicate
that the interface is offloaded with :c:func:`net_if_socket_offload_set`
+2 −2
Changes for drivers/modem/modem_socket.c: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -175,8 +175,8 @@ int modem_socket_get(struct modem_socket_config *cfg, int family, int type, int
	cfg->sockets[i].ip_proto = proto;
	cfg->sockets[i].id = (cfg->assign_id) ? (i + cfg->base_socket_id) :
		(cfg->base_socket_id + cfg->sockets_len);
	z_finalize_fd(cfg->sockets[i].sock_fd, &cfg->sockets[i],
		      (const struct fd_op_vtable *)cfg->vtable);
	z_finalize_typed_fd(cfg->sockets[i].sock_fd, &cfg->sockets[i],
			    (const struct fd_op_vtable *)cfg->vtable, ZVFS_MODE_IFSOCK);

	k_sem_give(&cfg->sem_lock);
	return cfg->sockets[i].sock_fd;
+3 −2
Changes for drivers/net/nsos_sockets.c: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -202,7 +202,7 @@ static int nsos_socket_create(int family, int type, int proto)
		goto free_sock;
	}

	z_finalize_fd(fd, sock, &nsos_socket_fd_op_vtable.fd_vtable);
	z_finalize_typed_fd(fd, sock, &nsos_socket_fd_op_vtable.fd_vtable, ZVFS_MODE_IFSOCK);

	return fd;

@@ -718,7 +718,8 @@ static int nsos_accept(void *obj, struct sockaddr *addr, socklen_t *addrlen)
	conn_sock->fd = zephyr_fd;
	conn_sock->poll.mid.fd = adapt_fd;

	z_finalize_fd(zephyr_fd, conn_sock, &nsos_socket_fd_op_vtable.fd_vtable);
	z_finalize_typed_fd(zephyr_fd, conn_sock, &nsos_socket_fd_op_vtable.fd_vtable,
			    ZVFS_MODE_IFSOCK);

	return zephyr_fd;

+6 −6
Changes for drivers/wifi/eswifi/eswifi_socket_offload.c: 6 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -158,9 +158,9 @@ static int eswifi_socket_accept(void *obj, struct sockaddr *addr,
		return -1;
	}

	z_finalize_fd(fd, SD_TO_OBJ(sock),
		      (const struct fd_op_vtable *)
					&eswifi_socket_fd_op_vtable);
	z_finalize_typed_fd(fd, SD_TO_OBJ(sock),
			    (const struct fd_op_vtable *)&eswifi_socket_fd_op_vtable,
			    ZVFS_MODE_IFSOCK);

	return fd;
}
@@ -594,9 +594,9 @@ int eswifi_socket_create(int family, int type, int proto)
		return -1;
	}

	z_finalize_fd(fd, SD_TO_OBJ(sock),
		      (const struct fd_op_vtable *)
					&eswifi_socket_fd_op_vtable);
	z_finalize_typed_fd(fd, SD_TO_OBJ(sock),
			    (const struct fd_op_vtable *)&eswifi_socket_fd_op_vtable,
			    ZVFS_MODE_IFSOCK);

	return fd;
}
+6 −6
Changes for drivers/wifi/simplelink/simplelink_sockets.c: 6 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -1273,9 +1273,9 @@ int simplelink_socket_create(int family, int type, int proto)
		return -1;
	}

	z_finalize_fd(fd, SD_TO_OBJ(sock),
		      (const struct fd_op_vtable *)
					&simplelink_socket_fd_op_vtable);
	z_finalize_typed_fd(fd, SD_TO_OBJ(sock),
			    (const struct fd_op_vtable *)&simplelink_socket_fd_op_vtable,
			    ZVFS_MODE_IFSOCK);

	return fd;
}
@@ -1296,9 +1296,9 @@ static int simplelink_socket_accept(void *obj, struct sockaddr *addr,
		return -1;
	}

	z_finalize_fd(fd, SD_TO_OBJ(sock),
		      (const struct fd_op_vtable *)
					&simplelink_socket_fd_op_vtable);
	z_finalize_typed_fd(fd, SD_TO_OBJ(sock),
			    (const struct fd_op_vtable *)&simplelink_socket_fd_op_vtable,
			    ZVFS_MODE_IFSOCK);

	return fd;
}
Loading