net: sockets: packet: Allow proto 0 for RAW sockets

According to AF_PACKET man pages protocol number 0 is allowed, however
in such case the socket is only capable of transmitting packets then:

  "If protocol is set to zero, no packets are received."

Therefore, allow to create sockets with such protocol, and at the
connection.c level filter out such sockets from data reception.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2025-04-10 15:20:48 +02:00 committed by Benjamin Cabé
commit 332843be33
2 changed files with 3 additions and 2 deletions

View file

@ -793,7 +793,7 @@ enum net_verdict net_conn_input(struct net_pkt *pkt,
* case. * case.
*/ */
if (IS_ENABLED(CONFIG_NET_SOCKETS_PACKET) && pkt_family == AF_PACKET) { if (IS_ENABLED(CONFIG_NET_SOCKETS_PACKET) && pkt_family == AF_PACKET) {
if (proto != ETH_P_ALL) { if (conn->proto == 0 || proto != ETH_P_ALL) {
continue; /* wrong protocol */ continue; /* wrong protocol */
} }
} else if (IS_ENABLED(CONFIG_NET_SOCKETS_INET_RAW) && raw_ip_pkt) { } else if (IS_ENABLED(CONFIG_NET_SOCKETS_INET_RAW) && raw_ip_pkt) {

View file

@ -486,7 +486,8 @@ static bool packet_is_supported(int family, int type, int proto)
switch (type) { switch (type) {
case SOCK_RAW: case SOCK_RAW:
proto = ntohs(proto); proto = ntohs(proto);
return proto == ETH_P_ALL return proto == 0
|| proto == ETH_P_ALL
|| proto == ETH_P_ECAT || proto == ETH_P_ECAT
|| proto == ETH_P_IEEE802154; || proto == ETH_P_IEEE802154;