Skip to content

Commit 2730c6c

Browse files
committed
packet_socket: Specify the socket-type, when inputing
Specify the socket type, when inputing a packet into a packet-socket. Signed-off-by: Cla Mattia Galliard <clamattia@gmail.com>
1 parent 99ffcc6 commit 2730c6c

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

subsys/net/ip/connection.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ static void conn_raw_socket_deliver(struct net_pkt *pkt, struct net_conn *conn,
637637
#endif /* defined(CONFIG_NET_SOCKETS_PACKET) || defined(CONFIG_NET_SOCKETS_INET_RAW) */
638638

639639
#if defined(CONFIG_NET_SOCKETS_PACKET)
640-
enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto)
640+
enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto, enum net_sock_type type)
641641
{
642642
bool raw_sock_found = false;
643643
bool raw_pkt_continue = false;
@@ -670,15 +670,15 @@ enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto)
670670
continue; /* wrong family */
671671
}
672672

673-
if (conn->type == SOCK_DGRAM && !net_pkt_is_l2_processed(pkt)) {
673+
if (conn->type == SOCK_DGRAM && type == SOCK_RAW) {
674674
/* If DGRAM packet sockets are present, we shall continue
675675
* with this packet regardless the result.
676676
*/
677677
raw_pkt_continue = true;
678678
continue; /* L2 not processed yet */
679679
}
680680

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

@@ -727,10 +727,11 @@ enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto)
727727
return NET_CONTINUE;
728728
}
729729
#else
730-
enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto)
730+
enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto, enum net_sock_type type)
731731
{
732732
ARG_UNUSED(pkt);
733733
ARG_UNUSED(proto);
734+
ARG_UNUSED(type);
734735

735736
return NET_CONTINUE;
736737
}

subsys/net/ip/connection.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,14 @@ int net_conn_update(struct net_conn_handle *handle,
189189
*
190190
* @param pkt Network packet holding received data
191191
* @param proto LL protocol for the connection
192+
* @param type socket type
192193
*
193194
* @return NET_OK if the packet was consumed, NET_CONTINUE if the packet should
194195
* be processed further in the stack.
195196
*/
196-
enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto);
197+
enum net_verdict net_conn_packet_input(struct net_pkt *pkt,
198+
uint16_t proto,
199+
enum net_sock_type type);
197200

198201
/**
199202
* @brief Called by net_core.c when an IP packet is received

subsys/net/ip/net_core.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ static inline enum net_verdict process_data(struct net_pkt *pkt)
6868
{
6969
int ret;
7070

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

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

104103
if (IS_ENABLED(CONFIG_NET_SOCKETS_PACKET_DGRAM)) {
105-
/* Consecutive call will forward packets to SOCK_DGRAM packet sockets
106-
* (after L2 removed header).
107-
*/
108-
ret = net_packet_socket_input(pkt, net_pkt_ll_proto_type(pkt));
104+
ret = net_packet_socket_input(pkt, net_pkt_ll_proto_type(pkt), SOCK_DGRAM);
109105
if (ret != NET_CONTINUE) {
110106
return ret;
111107
}
@@ -410,6 +406,7 @@ int net_try_send_data(struct net_pkt *pkt, k_timeout_t timeout)
410406
*/
411407
NET_DBG("Loopback pkt %p back to us", pkt);
412408
net_pkt_set_loopback(pkt, true);
409+
net_pkt_set_l2_processed(pkt, true);
413410
processing_data(pkt);
414411
ret = 0;
415412
goto err;
@@ -482,6 +479,7 @@ static void net_rx(struct net_if *iface, struct net_pkt *pkt)
482479
#ifdef CONFIG_NET_L2_DUMMY
483480
if (net_if_l2(iface) == &NET_L2_GET_NAME(DUMMY)) {
484481
net_pkt_set_loopback(pkt, true);
482+
net_pkt_set_l2_processed(pkt, true);
485483
}
486484
#endif
487485
}

subsys/net/ip/packet_socket.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ LOG_MODULE_REGISTER(net_sockets_raw, CONFIG_NET_SOCKETS_LOG_LEVEL);
2222
#include "connection.h"
2323
#include "packet_socket.h"
2424

25-
enum net_verdict net_packet_socket_input(struct net_pkt *pkt, uint16_t proto)
25+
enum net_verdict net_packet_socket_input(struct net_pkt *pkt,
26+
uint16_t proto,
27+
enum net_sock_type type)
2628
{
2729
sa_family_t orig_family;
2830
enum net_verdict net_verdict;
@@ -41,7 +43,7 @@ enum net_verdict net_packet_socket_input(struct net_pkt *pkt, uint16_t proto)
4143

4244
net_pkt_set_family(pkt, AF_PACKET);
4345

44-
net_verdict = net_conn_packet_input(pkt, proto);
46+
net_verdict = net_conn_packet_input(pkt, proto, type);
4547

4648
net_pkt_set_family(pkt, orig_family);
4749

0 commit comments

Comments
 (0)