Skip to content

Commit 332843b

Browse files
rluboskartben
authored andcommitted
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 <[email protected]>
1 parent 6869668 commit 332843b

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

subsys/net/ip/connection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ enum net_verdict net_conn_input(struct net_pkt *pkt,
793793
* case.
794794
*/
795795
if (IS_ENABLED(CONFIG_NET_SOCKETS_PACKET) && pkt_family == AF_PACKET) {
796-
if (proto != ETH_P_ALL) {
796+
if (conn->proto == 0 || proto != ETH_P_ALL) {
797797
continue; /* wrong protocol */
798798
}
799799
} else if (IS_ENABLED(CONFIG_NET_SOCKETS_INET_RAW) && raw_ip_pkt) {

subsys/net/lib/sockets/sockets_packet.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ static bool packet_is_supported(int family, int type, int proto)
486486
switch (type) {
487487
case SOCK_RAW:
488488
proto = ntohs(proto);
489-
return proto == ETH_P_ALL
489+
return proto == 0
490+
|| proto == ETH_P_ALL
490491
|| proto == ETH_P_ECAT
491492
|| proto == ETH_P_IEEE802154;
492493

0 commit comments

Comments
 (0)