diff mbox series

[U-Boot,06/10] net: Add an accessor to know if waiting for ARP

Message ID 20180724214012.22798-7-joe.hershberger@ni.com
State Superseded
Delegated to: Joe Hershberger
Headers show
Series net: Fix packet corruption issue when handling asynch replies | expand

Commit Message

Joe Hershberger July 24, 2018, 9:40 p.m. UTC
This single-sources the state of the ARP.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
---

 include/net.h |  1 +
 net/arp.c     | 11 ++++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

Comments

Simon Glass Aug. 2, 2018, 5:08 p.m. UTC | #1
On 24 July 2018 at 15:40, Joe Hershberger <joe.hershberger@ni.com> wrote:
> This single-sources the state of the ARP.
>
> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
> ---
>
>  include/net.h |  1 +
>  net/arp.c     | 11 ++++++++---
>  2 files changed, 9 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Bin Meng Sept. 25, 2018, 8:22 a.m. UTC | #2
Hi Joe,

On Wed, Jul 25, 2018 at 5:45 AM Joe Hershberger <joe.hershberger@ni.com> wrote:
>
> This single-sources the state of the ARP.
>
> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
> ---
>
>  include/net.h |  1 +
>  net/arp.c     | 11 ++++++++---
>  2 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/include/net.h b/include/net.h
> index f9984ae86c..63718a47f2 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -635,6 +635,7 @@ rxhand_f *net_get_udp_handler(void);        /* Get UDP RX packet handler */
>  void net_set_udp_handler(rxhand_f *);  /* Set UDP RX packet handler */
>  rxhand_f *net_get_arp_handler(void);   /* Get ARP RX packet handler */
>  void net_set_arp_handler(rxhand_f *);  /* Set ARP RX packet handler */
> +int arp_is_waiting(void);              /* Waiting for ARP reply? */

Can we use 'bool' instead of 'int'?

>  void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */
>  void net_set_timeout_handler(ulong, thand_f *);/* Set timeout handler */
>
> diff --git a/net/arp.c b/net/arp.c
> index b8a71684cd..524361cf1b 100644
> --- a/net/arp.c
> +++ b/net/arp.c
> @@ -100,7 +100,7 @@ int arp_timeout_check(void)
>  {
>         ulong t;
>
> -       if (!net_arp_wait_packet_ip.s_addr)
> +       if (!arp_is_waiting())
>                 return 0;
>
>         t = get_timer(0);
> @@ -187,8 +187,8 @@ void arp_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
>                 return;
>
>         case ARPOP_REPLY:               /* arp reply */
> -               /* are we waiting for a reply */
> -               if (!net_arp_wait_packet_ip.s_addr)
> +               /* are we waiting for a reply? */
> +               if (!arp_is_waiting())
>                         break;
>
>  #ifdef CONFIG_KEEP_SERVERADDR
> @@ -233,3 +233,8 @@ void arp_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
>                 return;
>         }
>  }
> +
> +int arp_is_waiting(void)
> +{
> +       return !!net_arp_wait_packet_ip.s_addr;
> +}
> --

Regards,
Bin
diff mbox series

Patch

diff --git a/include/net.h b/include/net.h
index f9984ae86c..63718a47f2 100644
--- a/include/net.h
+++ b/include/net.h
@@ -635,6 +635,7 @@  rxhand_f *net_get_udp_handler(void);	/* Get UDP RX packet handler */
 void net_set_udp_handler(rxhand_f *);	/* Set UDP RX packet handler */
 rxhand_f *net_get_arp_handler(void);	/* Get ARP RX packet handler */
 void net_set_arp_handler(rxhand_f *);	/* Set ARP RX packet handler */
+int arp_is_waiting(void);		/* Waiting for ARP reply? */
 void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */
 void net_set_timeout_handler(ulong, thand_f *);/* Set timeout handler */
 
diff --git a/net/arp.c b/net/arp.c
index b8a71684cd..524361cf1b 100644
--- a/net/arp.c
+++ b/net/arp.c
@@ -100,7 +100,7 @@  int arp_timeout_check(void)
 {
 	ulong t;
 
-	if (!net_arp_wait_packet_ip.s_addr)
+	if (!arp_is_waiting())
 		return 0;
 
 	t = get_timer(0);
@@ -187,8 +187,8 @@  void arp_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
 		return;
 
 	case ARPOP_REPLY:		/* arp reply */
-		/* are we waiting for a reply */
-		if (!net_arp_wait_packet_ip.s_addr)
+		/* are we waiting for a reply? */
+		if (!arp_is_waiting())
 			break;
 
 #ifdef CONFIG_KEEP_SERVERADDR
@@ -233,3 +233,8 @@  void arp_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
 		return;
 	}
 }
+
+int arp_is_waiting(void)
+{
+	return !!net_arp_wait_packet_ip.s_addr;
+}