Skip to content

Commit fd65f8b

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. Signed-off-by: Cla Mattia Galliard <clamattia@gmail.com>
1 parent 74aa269 commit fd65f8b

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
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: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,13 @@ LOG_MODULE_REGISTER(net_core, CONFIG_NET_CORE_LOG_LEVEL);
6767
static inline enum net_verdict process_data(struct net_pkt *pkt)
6868
{
6969
int ret;
70-
bool locally_routed = false;
71-
72-
net_pkt_set_l2_processed(pkt, false);
7370

7471
/* Initial call will forward packets to SOCK_RAW packet sockets. */
7572
ret = net_packet_socket_input(pkt, ETH_P_ALL);
7673
if (ret != NET_CONTINUE) {
7774
return ret;
7875
}
7976

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

95-
if (!net_pkt_is_loopback(pkt) && !locally_routed) {
85+
if (!net_pkt_is_loopback() && !net_pkt_is_l2_processed(pkt)) {
9686
ret = net_if_recv_data(net_pkt_iface(pkt), pkt);
87+
net_pkt_set_l2_processed(pkt, true);
9788
if (ret != NET_CONTINUE) {
9889
if (ret == NET_DROP) {
9990
NET_DBG("Packet %p discarded by L2", pkt);
@@ -105,8 +96,6 @@ static inline enum net_verdict process_data(struct net_pkt *pkt)
10596
}
10697
}
10798

108-
net_pkt_set_l2_processed(pkt, true);
109-
11099
/* L2 has modified the buffer starting point, it is easier
111100
* to re-initialize the cursor rather than updating it.
112101
*/
@@ -421,6 +410,7 @@ int net_try_send_data(struct net_pkt *pkt, k_timeout_t timeout)
421410
*/
422411
NET_DBG("Loopback pkt %p back to us", pkt);
423412
net_pkt_set_loopback(pkt, true);
413+
net_pkt_set_l2_processed(pkt, true);
424414
processing_data(pkt);
425415
ret = 0;
426416
goto err;

0 commit comments

Comments
 (0)