Commit b3cd478a authored by Jukka Rissanen's avatar Jukka Rissanen
Browse files

net: sockets: packet: Register handler for AF_PACKET



Use the automatic registration of AF_PACKET type sockets.

Signed-off-by: default avatarJukka Rissanen <jukka.rissanen@linux.intel.com>
parent 61f4597d
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -151,12 +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_PACKET)
	if (family == AF_PACKET) {
		return zpacket_socket(family, type, proto);
	}
#endif

#if defined(CONFIG_NET_SOCKETS_CAN)
	if (family == AF_CAN) {
		return zcan_socket(family, type, proto);
+0 −1
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ struct socket_op_vtable {
			  const void *optval, socklen_t optlen);
};

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

#endif /* _SOCKETS_INTERNAL_H_ */
+12 −6
Original line number Diff line number Diff line
@@ -36,17 +36,12 @@ static inline int k_fifo_wait_non_empty(struct k_fifo *fifo, int32_t timeout)
	return k_poll(events, ARRAY_SIZE(events), timeout);
}

int zpacket_socket(int family, int type, int proto)
static int zpacket_socket(int family, int type, int proto)
{
	struct net_context *ctx;
	int fd;
	int ret;

	if (type != SOCK_RAW || proto != ETH_P_ALL) {
		errno = -EOPNOTSUPP;
		return -1;
	}

	fd = z_reserve_fd();
	if (fd < 0) {
		return -1;
@@ -341,3 +336,14 @@ static const struct socket_op_vtable packet_sock_fd_op_vtable = {
	.getsockopt = packet_sock_getsockopt_vmeth,
	.setsockopt = packet_sock_setsockopt_vmeth,
};

static bool packet_is_supported(int family, int type, int proto)
{
	if (type != SOCK_RAW || proto != ETH_P_ALL) {
		return false;
	}

	return true;
}

NET_SOCKET_REGISTER(af_packet, AF_PACKET, packet_is_supported, zpacket_socket);