Skip to content

Commit 48aa070

Browse files
committed
net_core: Decide about l2-processing based on l2_processed-flag
Use the l2_processed-flag to decide whether a network packet needs to be processed by an L2-handler. This could be used in the future to requeue packets for later processing by a different traffic class queue. Introduce a loopback-flag to aoivd passing the information around as argument. Signed-off-by: Cla Mattia Galliard <clamattia@gmail.com>
1 parent 322da1d commit 48aa070

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

subsys/net/ip/ipv4_fragment.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ static void reassemble_packet(struct net_ipv4_reassembly *reass)
206206
net_pkt_set_data(pkt, &ipv4_access);
207207
net_pkt_set_ip_reassembled(pkt, true);
208208

209+
/* If the packet is reassembled, then do not pass it to L2 as the
210+
* packet does not have link layer headers in it.
211+
*/
212+
net_pkt_set_l2_processed(pkt, true);
213+
209214
LOG_DBG("New pkt %p IPv4 len is %zd bytes", pkt, net_pkt_get_len(pkt));
210215

211216
/* We need to use the queue when feeding the packet back into the

subsys/net/ip/ipv6_fragment.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ static void reassemble_packet(struct net_ipv6_reassembly *reass)
340340
net_pkt_set_data(pkt, &ipv6_access);
341341
net_pkt_set_ip_reassembled(pkt, true);
342342

343+
/* If the packet is reassembled, then do not pass it to L2 as the
344+
* packet does not have link layer headers in it.
345+
*/
346+
net_pkt_set_l2_processed(pkt, true);
347+
343348
NET_DBG("New pkt %p IPv6 len is %d bytes", pkt,
344349
len + NET_IPV6H_LEN);
345350

subsys/net/ip/net_core.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,16 @@ LOG_MODULE_REGISTER(net_core, CONFIG_NET_CORE_LOG_LEVEL);
6464
#include "net_stats.h"
6565

6666
#if defined(CONFIG_NET_NATIVE)
67-
static inline enum net_verdict process_data(struct net_pkt *pkt,
68-
bool is_loopback)
67+
static inline enum net_verdict process_data(struct net_pkt *pkt)
6968
{
7069
int ret;
71-
bool locally_routed = false;
72-
73-
net_pkt_set_l2_processed(pkt, false);
7470

7571
/* Initial call will forward packets to SOCK_RAW packet sockets. */
7672
ret = net_packet_socket_input(pkt, ETH_P_ALL);
7773
if (ret != NET_CONTINUE) {
7874
return ret;
7975
}
8076

81-
/* If the packet is routed back to us when we have reassembled an IPv4 or IPv6 packet,
82-
* then do not pass it to L2 as the packet does not have link layer headers in it.
83-
*/
84-
if (net_pkt_is_ip_reassembled(pkt)) {
85-
locally_routed = true;
86-
}
87-
8877
/* If there is no data, then drop the packet. */
8978
if (!pkt->frags) {
9079
NET_DBG("Corrupted packet (frags %p)", pkt->frags);
@@ -93,8 +82,9 @@ static inline enum net_verdict process_data(struct net_pkt *pkt,
9382
return NET_DROP;
9483
}
9584

96-
if (!is_loopback && !locally_routed) {
85+
if (!net_pkt_is_l2_processed(pkt)) {
9786
ret = net_if_recv_data(net_pkt_iface(pkt), pkt);
87+
net_pkt_set_l2_processed(pkt, true);
9888
if (ret != NET_CONTINUE) {
9989
if (ret == NET_DROP) {
10090
NET_DBG("Packet %p discarded by L2", pkt);
@@ -106,8 +96,6 @@ static inline enum net_verdict process_data(struct net_pkt *pkt,
10696
}
10797
}
10898

109-
net_pkt_set_l2_processed(pkt, true);
110-
11199
/* L2 has modified the buffer starting point, it is easier
112100
* to re-initialize the cursor rather than updating it.
113101
*/
@@ -148,10 +136,10 @@ static inline enum net_verdict process_data(struct net_pkt *pkt,
148136
return NET_DROP;
149137
}
150138

151-
static void processing_data(struct net_pkt *pkt, bool is_loopback)
139+
static void processing_data(struct net_pkt *pkt)
152140
{
153141
again:
154-
switch (process_data(pkt, is_loopback)) {
142+
switch (process_data(pkt)) {
155143
case NET_CONTINUE:
156144
if (IS_ENABLED(CONFIG_NET_L2_VIRTUAL)) {
157145
/* If we have a tunneling packet, feed it back
@@ -421,7 +409,8 @@ int net_try_send_data(struct net_pkt *pkt, k_timeout_t timeout)
421409
* to RX processing.
422410
*/
423411
NET_DBG("Loopback pkt %p back to us", pkt);
424-
processing_data(pkt, true);
412+
+ net_pkt_set_l2_processed(pkt, true);
413+
processing_data(pkt);
425414
ret = 0;
426415
goto err;
427416
}
@@ -481,7 +470,6 @@ int net_try_send_data(struct net_pkt *pkt, k_timeout_t timeout)
481470

482471
static void net_rx(struct net_if *iface, struct net_pkt *pkt)
483472
{
484-
bool is_loopback = false;
485473
size_t pkt_len;
486474

487475
pkt_len = net_pkt_get_len(pkt);
@@ -493,12 +481,12 @@ static void net_rx(struct net_if *iface, struct net_pkt *pkt)
493481
if (IS_ENABLED(CONFIG_NET_LOOPBACK)) {
494482
#ifdef CONFIG_NET_L2_DUMMY
495483
if (net_if_l2(iface) == &NET_L2_GET_NAME(DUMMY)) {
496-
is_loopback = true;
484+
net_pkt_set_l2_processed(pkt, true);
497485
}
498486
#endif
499487
}
500488

501-
processing_data(pkt, is_loopback);
489+
processing_data(pkt);
502490

503491
net_print_statistics();
504492
net_pkt_print();

0 commit comments

Comments
 (0)