@@ -312,6 +312,11 @@ ip_input(struct pbuf *p, struct netif *inp)
312312 int check_ip_src = 1 ;
313313#endif /* IP_ACCEPT_LINK_LAYER_ADDRESSING */
314314
315+ #if IP_NAT
316+ extern u8_t ip_nat_input (struct pbuf * p );
317+ extern u8_t ip_nat_out (struct pbuf * p );
318+ #endif
319+
315320 IP_STATS_INC (ip .recv );
316321 snmp_inc_ipinreceives ();
317322
@@ -487,15 +492,30 @@ ip_input(struct pbuf *p, struct netif *inp)
487492
488493 /* packet not for us? */
489494 if (netif == NULL ) {
495+ #if IP_FORWARD || IP_NAT
496+ u8_t taken = 0 ;
497+ #endif /* IP_FORWARD || IP_NAT */
490498 /* packet not for us, route or discard */
491499 LWIP_DEBUGF (IP_DEBUG | LWIP_DBG_TRACE , ("ip_input: packet not for us.\n" ));
492- #if IP_FORWARD
500+ #if IP_FORWARD || IP_NAT
493501 /* non-broadcast packet? */
494- if (!ip_addr_isbroadcast (& current_iphdr_dest , inp )) {
495- /* try to forward IP packet on (other) interfaces */
496- ip_forward (p , iphdr , inp );
497- } else
502+ if (!ip_addr_isbroadcast (& (iphdr -> dest ), inp )) {
503+ #if IP_NAT
504+ /* check if we want to perform NAT with this packet. */
505+ taken = ip_nat_out (p );
506+ if (!taken )
507+ #endif /* IP_NAT */
508+ {
509+ #if IP_FORWARD
510+ /* try to forward IP packet on (other) interfaces */
511+ if (ip_forward (p , iphdr , inp ) != NULL ) {
512+ taken = 1 ;
513+ }
498514#endif /* IP_FORWARD */
515+ }
516+ }
517+ if (!taken )
518+ #endif /* IP_FORWARD || IP_NAT */
499519 {
500520 snmp_inc_ipinaddrerrors ();
501521 snmp_inc_ipindiscards ();
@@ -553,6 +573,13 @@ ip_input(struct pbuf *p, struct netif *inp)
553573 current_netif = inp ;
554574 current_header = iphdr ;
555575
576+ #if IP_NAT
577+ if (!ip_addr_isbroadcast (& (iphdr -> dest ), inp ) &&
578+ (ip_nat_input (p ) != 0 )) {
579+ LWIP_DEBUGF (IP_DEBUG , ("ip_input: packet consumed by nat layer\n" ));
580+ } else
581+ #endif /* IP_NAT */
582+
556583#if LWIP_RAW
557584 /* raw input did not eat the packet? */
558585 if (raw_input (p , inp ) == 0 )
0 commit comments