casaroli commented on code in PR #21517:
URL: https://github.com/apache/nuttx/pull/21517#discussion_r4547221225


##########
net/pkt/pkt_recvmsg.c:
##########
@@ -154,9 +157,35 @@ static void pkt_recvfrom_newdata(FAR struct net_driver_s 
*dev,
  *
  ****************************************************************************/
 
-static inline void pkt_recvfrom_sender(FAR struct net_driver_s *dev,
+static inline void pkt_recvfrom_sender(int ifindex, FAR void *llhdr,
+                                       unsigned int llhdrlen,
                                        FAR struct pkt_recvfrom_s *pstate)
 {
+  struct sockaddr_ll from;
+  socklen_t copylen;
+
+  if (pstate->pr_msg->msg_name != NULL)
+    {
+      memset(&from, 0, sizeof(from));
+      from.sll_family   = AF_PACKET;
+      from.sll_ifindex  = ifindex;
+      from.sll_protocol = pstate->pr_type;

Review Comment:
   `pr_type` is the socket type (`pkt_recvfrom_initialize()` sets it from 
`psock->s_type`), so `sll_protocol` is 3 for every frame of a `SOCK_RAW` 
socket: frames of type 0x88b5, 0x0806 and 0x0800 all gave 3 on qemu-armv8a. 
`sll_protocol` is the protocol of the frame.
   Fix: set `sll_protocol` to the type of the frame (`ethhdr->type`, already in 
network byte order) in the Ethernet branch.



##########
net/pkt/pkt_recvmsg.c:
##########
@@ -154,9 +157,35 @@ static void pkt_recvfrom_newdata(FAR struct net_driver_s 
*dev,
  *
  ****************************************************************************/
 
-static inline void pkt_recvfrom_sender(FAR struct net_driver_s *dev,
+static inline void pkt_recvfrom_sender(int ifindex, FAR void *llhdr,
+                                       unsigned int llhdrlen,
                                        FAR struct pkt_recvfrom_s *pstate)
 {
+  struct sockaddr_ll from;
+  socklen_t copylen;
+
+  if (pstate->pr_msg->msg_name != NULL)
+    {
+      memset(&from, 0, sizeof(from));
+      from.sll_family   = AF_PACKET;
+      from.sll_ifindex  = ifindex;
+      from.sll_protocol = pstate->pr_type;
+      from.sll_halen    = ETH_ALEN;
+
+      if (llhdr != NULL && llhdrlen >= sizeof(struct eth_hdr_s))

Review Comment:
   This takes the source address from an Ethernet header for every device. On a 
device without one (TUN, which the last commit enables), `sll_addr` gets bytes 
6 to 11 of the IP header and `sll_halen` is 6.
   Fix: fill `sll_addr` and `sll_halen` only when `dev->d_lltype` is 
`NET_LL_ETHERNET` (pass the device or the link type to 
`pkt_recvfrom_sender()`), and leave them 0 otherwise.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to