Skip to content

Commit 46efe3e

Browse files
jukkarnashif
authored andcommitted
net: packet: Do not drop net_pkt immediately
If there are no sockets in the system, then do not drop the packet immediately as there can be other L2 network handlers like gPTP in the system. This will also allow ICMP messages to pass to local handler. Fixes #34865 Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 9b2d8e8 commit 46efe3e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

subsys/net/ip/connection.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,9 @@ enum net_verdict net_conn_input(struct net_pkt *pkt,
634634
* but the listener might have a specific protocol set. This is ok
635635
* and let the packet pass this check in this case.
636636
*/
637-
if (IS_ENABLED(CONFIG_NET_SOCKETS_PACKET_DGRAM) ||
638-
IS_ENABLED(CONFIG_NET_SOCKETS_PACKET)) {
637+
if ((IS_ENABLED(CONFIG_NET_SOCKETS_PACKET_DGRAM) ||
638+
IS_ENABLED(CONFIG_NET_SOCKETS_PACKET)) &&
639+
net_pkt_family(pkt) == AF_PACKET) {
639640
if ((conn->proto != proto) && (proto != ETH_P_ALL) &&
640641
(proto != IPPROTO_RAW)) {
641642
continue;
@@ -775,8 +776,9 @@ enum net_verdict net_conn_input(struct net_pkt *pkt,
775776
}
776777
}
777778

778-
if ((is_mcast_pkt && mcast_pkt_delivered) || raw_pkt_delivered ||
779-
raw_pkt_continue) {
779+
if ((is_mcast_pkt && mcast_pkt_delivered) ||
780+
(net_pkt_family(pkt) == AF_PACKET && (raw_pkt_delivered ||
781+
raw_pkt_continue))) {
780782
if (raw_pkt_continue) {
781783
/* When there is open connection different than
782784
* AF_PACKET this packet shall be also handled in

subsys/net/ip/packet_socket.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ LOG_MODULE_REGISTER(net_sockets_raw, CONFIG_NET_SOCKETS_LOG_LEVEL);
2222

2323
enum net_verdict net_packet_socket_input(struct net_pkt *pkt, uint8_t proto)
2424
{
25+
sa_family_t orig_family;
26+
2527
#if IS_ENABLED(CONFIG_NET_DSA)
2628
/*
2729
* For DSA the master port is not supporting raw packets. Only the
@@ -46,7 +48,13 @@ enum net_verdict net_packet_socket_input(struct net_pkt *pkt, uint8_t proto)
4648
* data part to be feed to non raw socket.
4749
*/
4850

51+
orig_family = net_pkt_family(pkt);
52+
4953
net_pkt_set_family(pkt, AF_PACKET);
5054

51-
return net_conn_input(pkt, NULL, proto, NULL);
55+
(void)net_conn_input(pkt, NULL, proto, NULL);
56+
57+
net_pkt_set_family(pkt, orig_family);
58+
59+
return NET_CONTINUE;
5260
}

0 commit comments

Comments
 (0)