Commit 8e6521a1 authored by Cla Mattia Galliard's avatar Cla Mattia Galliard Committed by Benjamin Cabé
Browse files

net: socket: Specify the packet socket-type, when inputting



Specify the socket type, when inputting a packet into a packet-socket.

Signed-off-by: default avatarCla Mattia Galliard <clamattia@gmail.com>
parent b9968e9d
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -637,7 +637,7 @@ out:
#endif /* defined(CONFIG_NET_SOCKETS_PACKET) || defined(CONFIG_NET_SOCKETS_INET_RAW) */

#if defined(CONFIG_NET_SOCKETS_PACKET)
enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto)
enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto, enum net_sock_type type)
{
	bool raw_sock_found = false;
	bool raw_pkt_continue = false;
@@ -670,7 +670,7 @@ enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto)
			continue; /* wrong family */
		}

		if (conn->type == SOCK_DGRAM && !net_pkt_is_l2_processed(pkt)) {
		if (conn->type == SOCK_DGRAM && type == SOCK_RAW) {
			/* If DGRAM packet sockets are present, we shall continue
			 * with this packet regardless the result.
			 */
@@ -678,7 +678,7 @@ enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto)
			continue; /* L2 not processed yet */
		}

		if (conn->type == SOCK_RAW && net_pkt_is_l2_processed(pkt)) {
		if (conn->type == SOCK_RAW && type != SOCK_RAW) {
			continue; /* L2 already processed */
		}

@@ -727,10 +727,11 @@ enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto)
	return NET_CONTINUE;
}
#else
enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto)
enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto, enum net_sock_type type)
{
	ARG_UNUSED(pkt);
	ARG_UNUSED(proto);
	ARG_UNUSED(type);

	return NET_CONTINUE;
}
+4 −1
Original line number Diff line number Diff line
@@ -189,11 +189,14 @@ int net_conn_update(struct net_conn_handle *handle,
 *
 * @param pkt Network packet holding received data
 * @param proto LL protocol for the connection
 * @param type socket type
 *
 * @return NET_OK if the packet was consumed, NET_CONTINUE if the packet should
 * be processed further in the stack.
 */
enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto);
enum net_verdict net_conn_packet_input(struct net_pkt *pkt,
				       uint16_t proto,
				       enum net_sock_type type);

/**
 * @brief Called by net_core.c when an IP packet is received
+5 −7
Original line number Diff line number Diff line
@@ -68,8 +68,7 @@ static inline enum net_verdict process_data(struct net_pkt *pkt)
{
	int ret;

	/* Initial call will forward packets to SOCK_RAW packet sockets. */
	ret = net_packet_socket_input(pkt, ETH_P_ALL);
	ret = net_packet_socket_input(pkt, ETH_P_ALL, SOCK_RAW);
	if (ret != NET_CONTINUE) {
		return ret;
	}
@@ -82,7 +81,7 @@ static inline enum net_verdict process_data(struct net_pkt *pkt)
		return NET_DROP;
	}

	if (!net_pkt_is_loopback(pkt) && !net_pkt_is_l2_processed(pkt)) {
	if (!net_pkt_is_l2_processed(pkt)) {
		ret = net_if_recv_data(net_pkt_iface(pkt), pkt);
		net_pkt_set_l2_processed(pkt, true);
		if (ret != NET_CONTINUE) {
@@ -102,10 +101,7 @@ static inline enum net_verdict process_data(struct net_pkt *pkt)
	net_pkt_cursor_init(pkt);

	if (IS_ENABLED(CONFIG_NET_SOCKETS_PACKET_DGRAM)) {
		/* Consecutive call will forward packets to SOCK_DGRAM packet sockets
		 * (after L2 removed header).
		 */
		ret = net_packet_socket_input(pkt, net_pkt_ll_proto_type(pkt));
		ret = net_packet_socket_input(pkt, net_pkt_ll_proto_type(pkt), SOCK_DGRAM);
		if (ret != NET_CONTINUE) {
			return ret;
		}
@@ -410,6 +406,7 @@ int net_try_send_data(struct net_pkt *pkt, k_timeout_t timeout)
		 */
		NET_DBG("Loopback pkt %p back to us", pkt);
		net_pkt_set_loopback(pkt, true);
		net_pkt_set_l2_processed(pkt, true);
		processing_data(pkt);
		ret = 0;
		goto err;
@@ -482,6 +479,7 @@ static void net_rx(struct net_if *iface, struct net_pkt *pkt)
#ifdef CONFIG_NET_L2_DUMMY
		if (net_if_l2(iface) == &NET_L2_GET_NAME(DUMMY)) {
			net_pkt_set_loopback(pkt, true);
			net_pkt_set_l2_processed(pkt, true);
		}
#endif
	}
+4 −2
Original line number Diff line number Diff line
@@ -22,7 +22,9 @@ LOG_MODULE_REGISTER(net_sockets_raw, CONFIG_NET_SOCKETS_LOG_LEVEL);
#include "connection.h"
#include "packet_socket.h"

enum net_verdict net_packet_socket_input(struct net_pkt *pkt, uint16_t proto)
enum net_verdict net_packet_socket_input(struct net_pkt *pkt,
					 uint16_t proto,
					 enum net_sock_type type)
{
	sa_family_t orig_family;
	enum net_verdict net_verdict;
@@ -41,7 +43,7 @@ enum net_verdict net_packet_socket_input(struct net_pkt *pkt, uint16_t proto)

	net_pkt_set_family(pkt, AF_PACKET);

	net_verdict = net_conn_packet_input(pkt, proto);
	net_verdict = net_conn_packet_input(pkt, proto, type);

	net_pkt_set_family(pkt, orig_family);

+5 −2
Original line number Diff line number Diff line
@@ -26,10 +26,13 @@
 * disabled, the function will always return NET_DROP.
 */
#if defined(CONFIG_NET_SOCKETS_PACKET)
enum net_verdict net_packet_socket_input(struct net_pkt *pkt, uint16_t proto);
enum net_verdict net_packet_socket_input(struct net_pkt *pkt,
					 uint16_t proto,
					 enum net_sock_type type);
#else
static inline enum net_verdict net_packet_socket_input(struct net_pkt *pkt,
						       uint16_t proto)
						       uint16_t proto,
						       enum net_sock_type type)
{
	return NET_CONTINUE;
}