wengzhe commented on code in PR #7750:
URL: https://github.com/apache/nuttx/pull/7750#discussion_r1037757065


##########
net/ipforward/ipv4_forward.c:
##########
@@ -505,6 +502,37 @@ int ipv4_forward(FAR struct net_driver_s *dev, FAR struct 
ipv4_hdr_s *ipv4)
 
 drop:
   ipv4_dropstats(ipv4);
+
+#ifdef CONFIG_NET_ICMP
+#ifdef CONFIG_NET_NAT
+  /* Before we reply ICMP, call NAT outbound to try to translate destination
+   * address & port back to original status.
+   */
+
+  if (ret == -ENETUNREACH || ret == -EFBIG || ret == -EMULTIHOP)
+    {
+      ipv4_nat_outbound(dev, ipv4, NAT_MANIP_DST);
+    }
+#endif /* CONFIG_NET_NAT */
+
+  /* Reply ICMP to the sender for particular errors. */
+
+  switch (ret)
+    {
+      case -ENETUNREACH:
+        icmp_reply(dev, ICMP_DEST_UNREACHABLE, ICMP_NET_UNREACH);
+        return OK;
+
+      case -EFBIG:
+        icmp_reply(dev, ICMP_DEST_UNREACHABLE, ICMP_FRAG_NEEDED);
+        return OK;
+
+      case -EMULTIHOP:
+        icmp_reply(dev, ICMP_TIME_EXCEEDED, 0);
+        return OK;
+    }

Review Comment:
   Yeah it's better on case matching (without another `if` with probability of 
mismatch), but the params of `icmp_reply` is really too long (much more 
difficult if we want to add more cases), I'm still considering how to improve 
this.



-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to