diff mbox

[U-Boot,v2,2/6] NET: pass source IP address to packet handlers

Message ID 1303143594-5345-3-git-send-email-luca.ceresoli@comelit.it
State Accepted
Commit 03eb129f8a37f7d7d222e02330cd806d3a0aef1d
Headers show

Commit Message

Luca Ceresoli April 18, 2011, 4:19 p.m. UTC
This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
---
Changes in v2:
 - fixed checkpatch issues.

 drivers/net/netconsole.c |    5 +++--
 include/net.h            |   15 ++++++++++-----
 net/bootp.c              |    9 ++++++---
 net/dns.c                |    2 +-
 net/net.c                |   30 +++++++++++++++++-------------
 net/nfs.c                |    2 +-
 net/rarp.c               |    3 ++-
 net/sntp.c               |    3 ++-
 net/tftp.c               |    3 ++-
 9 files changed, 44 insertions(+), 28 deletions(-)

Comments

Detlev Zundel April 19, 2011, 2:15 p.m. UTC | #1
Hi Luca,

> This is needed for the upcoming TFTP server implementation.
>
> This also simplifies PingHandler() and fixes rxhand_f documentation.
>
> Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
> Cc: Wolfgang Denk <wd@denx.de>
> ---
> Changes in v2:
>  - fixed checkpatch issues.
>
>  drivers/net/netconsole.c |    5 +++--
>  include/net.h            |   15 ++++++++++-----
>  net/bootp.c              |    9 ++++++---
>  net/dns.c                |    2 +-
>  net/net.c                |   30 +++++++++++++++++-------------
>  net/nfs.c                |    2 +-
>  net/rarp.c               |    3 ++-
>  net/sntp.c               |    3 ++-
>  net/tftp.c               |    3 ++-
>  9 files changed, 44 insertions(+), 28 deletions(-)
>

[...]

> diff --git a/net/net.c b/net/net.c
> index a609632..132f99b 100644
> --- a/net/net.c
> +++ b/net/net.c

[...]

> @@ -1596,11 +1598,12 @@ NetReceive(volatile uchar * inpkt, int len)
>  				 *	IP header OK.  Pass the packet to the current handler.
>  				 */
>  				/* XXX point to ip packet */
> -				(*packetHandler)((uchar *)ip, 0, 0, 0);
> +				(*packetHandler)((uchar *)ip, 0, src_ip, 0, 0);
>  				return;
>  			case ICMP_ECHO_REQUEST:
> -				debug("Got ICMP ECHO REQUEST, return %d bytes \n",
> -					ETHER_HDR_SIZE + len);
> +				debug("Got ICMP ECHO REQUEST, "
> +				      "return %d bytes\n",
> +				      ETHER_HDR_SIZE + len);
>  
>  				memcpy (&et->et_dest[0], &et->et_src[0], 6);
>  				memcpy (&et->et_src[ 0], NetOurEther, 6);

This second hunk is not related to the patch at hand, so strictly
speaking it should not be in here.  It's not enough to NAK the patch
however, just something to look out for in the future.

Apart from that the changes look good, so

Acked-by: Detlev Zundel <dzu@denx.de>
Luca Ceresoli April 19, 2011, 3:26 p.m. UTC | #2
Il 19/04/2011 16:15, Detlev Zundel ha scritto:
> Hi Luca,
>
>> This is needed for the upcoming TFTP server implementation.
>>
>> This also simplifies PingHandler() and fixes rxhand_f documentation.
>>
>> Signed-off-by: Luca Ceresoli<luca.ceresoli@comelit.it>
>> Cc: Wolfgang Denk<wd@denx.de>
>> ---
>> Changes in v2:
>>   - fixed checkpatch issues.
>>
>>   drivers/net/netconsole.c |    5 +++--
>>   include/net.h            |   15 ++++++++++-----
>>   net/bootp.c              |    9 ++++++---
>>   net/dns.c                |    2 +-
>>   net/net.c                |   30 +++++++++++++++++-------------
>>   net/nfs.c                |    2 +-
>>   net/rarp.c               |    3 ++-
>>   net/sntp.c               |    3 ++-
>>   net/tftp.c               |    3 ++-
>>   9 files changed, 44 insertions(+), 28 deletions(-)
>>
> [...]
>
>> diff --git a/net/net.c b/net/net.c
>> index a609632..132f99b 100644
>> --- a/net/net.c
>> +++ b/net/net.c
> [...]
>
>> @@ -1596,11 +1598,12 @@ NetReceive(volatile uchar * inpkt, int len)
>>   				 *	IP header OK.  Pass the packet to the current handler.
>>   				 */
>>   				/* XXX point to ip packet */
>> -				(*packetHandler)((uchar *)ip, 0, 0, 0);
>> +				(*packetHandler)((uchar *)ip, 0, src_ip, 0, 0);
>>   				return;
>>   			case ICMP_ECHO_REQUEST:
>> -				debug("Got ICMP ECHO REQUEST, return %d bytes \n",
>> -					ETHER_HDR_SIZE + len);
>> +				debug("Got ICMP ECHO REQUEST, "
>> +				      "return %d bytes\n",
>> +				      ETHER_HDR_SIZE + len);
>>
>>   				memcpy (&et->et_dest[0],&et->et_src[0], 6);
>>   				memcpy (&et->et_src[ 0], NetOurEther, 6);
> This second hunk is not related to the patch at hand, so strictly
> speaking it should not be in here.  It's not enough to NAK the patch
> however, just something to look out for in the future.

Yep, but it's needed for checkpatch compliance.

Luca
Wolfgang Denk May 12, 2011, 5:38 p.m. UTC | #3
Dear Luca Ceresoli,

In message <1303143594-5345-3-git-send-email-luca.ceresoli@comelit.it> you wrote:
> This is needed for the upcoming TFTP server implementation.
> 
> This also simplifies PingHandler() and fixes rxhand_f documentation.
> 
> Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
> Cc: Wolfgang Denk <wd@denx.de>
> ---
> Changes in v2:
>  - fixed checkpatch issues.
> 
>  drivers/net/netconsole.c |    5 +++--
>  include/net.h            |   15 ++++++++++-----
>  net/bootp.c              |    9 ++++++---
>  net/dns.c                |    2 +-
>  net/net.c                |   30 +++++++++++++++++-------------
>  net/nfs.c                |    2 +-
>  net/rarp.c               |    3 ++-
>  net/sntp.c               |    3 ++-
>  net/tftp.c               |    3 ++-
>  9 files changed, 44 insertions(+), 28 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk
diff mbox

Patch

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index e27bb3e..e40efb8 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -40,13 +40,14 @@  static short nc_port;			/* source/target port */
 static const char *output_packet;	/* used by first send udp */
 static int output_packet_len = 0;
 
-static void nc_wait_arp_handler (uchar * pkt, unsigned dest, unsigned src,
+static void nc_wait_arp_handler(uchar *pkt, unsigned dest,
+				 IPaddr_t sip, unsigned src,
 				 unsigned len)
 {
 	NetState = NETLOOP_SUCCESS;	/* got arp reply - quit net loop */
 }
 
-static void nc_handler (uchar * pkt, unsigned dest, unsigned src,
+static void nc_handler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 			unsigned len)
 {
 	if (input_size)
diff --git a/include/net.h b/include/net.h
index 95ef8ab..01f7159 100644
--- a/include/net.h
+++ b/include/net.h
@@ -72,12 +72,17 @@ 
 typedef ulong		IPaddr_t;
 
 
-/*
- * The current receive packet handler.  Called with a pointer to the
- * application packet, and a protocol type (PORT_BOOTPC or PORT_TFTP).
- * All other packets are dealt with without calling the handler.
+/**
+ * An incoming packet handler.
+ * @param pkt    pointer to the application packet
+ * @param dport  destination UDP port
+ * @param sip    source IP address
+ * @param sport  source UDP port
+ * @param len    packet length
  */
-typedef void	rxhand_f(uchar *, unsigned, unsigned, unsigned);
+typedef void rxhand_f(uchar *pkt, unsigned dport,
+		      IPaddr_t sip, unsigned sport,
+		      unsigned len);
 
 /*
  *	A timeout handler.  Called after time interval has expired.
diff --git a/net/bootp.c b/net/bootp.c
index 87b027e..4db63cb 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -44,7 +44,8 @@  ulong		seed1, seed2;
 dhcp_state_t dhcp_state = INIT;
 unsigned long dhcp_leasetime = 0;
 IPaddr_t NetDHCPServerIP = 0;
-static void DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len);
+static void DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+			unsigned len);
 
 /* For Debug */
 #if 0
@@ -282,7 +283,8 @@  static void BootpVendorProcess (u8 * ext, int size)
  *	Handle a BOOTP received packet.
  */
 static void
-BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
+BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+	     unsigned len)
 {
 	Bootp_t *bp;
 	char	*s;
@@ -858,7 +860,8 @@  static void DhcpSendRequestPkt(Bootp_t *bp_offer)
  *	Handle DHCP received packets.
  */
 static void
-DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
+DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+	    unsigned len)
 {
 	Bootp_t *bp = (Bootp_t *)pkt;
 
diff --git a/net/dns.c b/net/dns.c
index bb3e3f5..b51d1bd 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -101,7 +101,7 @@  DnsTimeout(void)
 }
 
 static void
-DnsHandler(uchar *pkt, unsigned dest, unsigned src, unsigned len)
+DnsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
 {
 	struct header *header;
 	const unsigned char *p, *e, *s;
diff --git a/net/net.c b/net/net.c
index a609632..132f99b 100644
--- a/net/net.c
+++ b/net/net.c
@@ -555,7 +555,8 @@  startAgainTimeout(void)
 }
 
 static void
-startAgainHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
+startAgainHandler(uchar *pkt, unsigned dest, IPaddr_t sip,
+		  unsigned src, unsigned len)
 {
 	/* Totally ignore the packet */
 }
@@ -752,13 +753,10 @@  PingTimeout (void)
 }
 
 static void
-PingHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
+PingHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+	    unsigned len)
 {
-	IPaddr_t tmp;
-	volatile IP_t *ip = (volatile IP_t *)pkt;
-
-	tmp = NetReadIP((void *)&ip->ip_src);
-	if (tmp != NetPingIP)
+	if (sip != NetPingIP)
 		return;
 
 	NetState = NETLOOP_SUCCESS;
@@ -990,7 +988,8 @@  CDPTimeout (void)
 }
 
 static void
-CDPDummyHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
+CDPDummyHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+		unsigned len)
 {
 	/* nothing */
 }
@@ -1304,6 +1303,7 @@  NetReceive(volatile uchar * inpkt, int len)
 	IP_t	*ip;
 	ARP_t	*arp;
 	IPaddr_t tmp;
+	IPaddr_t src_ip;
 	int	x;
 	uchar *pkt;
 #if defined(CONFIG_CMD_CDP)
@@ -1477,7 +1477,7 @@  NetReceive(volatile uchar * inpkt, int len)
 				memcpy(NetArpWaitPacketMAC, &arp->ar_data[0], 6);
 
 #ifdef CONFIG_NETCONSOLE
-				(*packetHandler)(0,0,0,0);
+				(*packetHandler)(0, 0, 0, 0, 0);
 #endif
 				/* modify header, and transmit it */
 				memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, NetArpWaitPacketMAC, 6);
@@ -1517,7 +1517,7 @@  NetReceive(volatile uchar * inpkt, int len)
 				NetCopyIP(&NetServerIP, &arp->ar_data[ 6]);
 			memcpy (NetServerEther, &arp->ar_data[ 0], 6);
 
-			(*packetHandler)(0,0,0,0);
+			(*packetHandler)(0, 0, 0, 0, 0);
 		}
 		break;
 #endif
@@ -1557,6 +1557,8 @@  NetReceive(volatile uchar * inpkt, int len)
 #endif
 			return;
 		}
+		/* Read source IP address for later use */
+		src_ip = NetReadIP(&ip->ip_src);
 		/*
 		 * The function returns the unchanged packet if it's not
 		 * a fragment, and either the complete packet or NULL if
@@ -1596,11 +1598,12 @@  NetReceive(volatile uchar * inpkt, int len)
 				 *	IP header OK.  Pass the packet to the current handler.
 				 */
 				/* XXX point to ip packet */
-				(*packetHandler)((uchar *)ip, 0, 0, 0);
+				(*packetHandler)((uchar *)ip, 0, src_ip, 0, 0);
 				return;
 			case ICMP_ECHO_REQUEST:
-				debug("Got ICMP ECHO REQUEST, return %d bytes \n",
-					ETHER_HDR_SIZE + len);
+				debug("Got ICMP ECHO REQUEST, "
+				      "return %d bytes\n",
+				      ETHER_HDR_SIZE + len);
 
 				memcpy (&et->et_dest[0], &et->et_src[0], 6);
 				memcpy (&et->et_src[ 0], NetOurEther, 6);
@@ -1678,6 +1681,7 @@  NetReceive(volatile uchar * inpkt, int len)
 		 */
 		(*packetHandler)((uchar *)ip +IP_HDR_SIZE,
 						ntohs(ip->udp_dst),
+						src_ip,
 						ntohs(ip->udp_src),
 						ntohs(ip->udp_len) - 8);
 		break;
diff --git a/net/nfs.c b/net/nfs.c
index d11bb4c..f76f60d 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -580,7 +580,7 @@  NfsTimeout (void)
 }
 
 static void
-NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
+NfsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
 {
 	int rlen;
 
diff --git a/net/rarp.c b/net/rarp.c
index 9444c03..94c86d3 100644
--- a/net/rarp.c
+++ b/net/rarp.c
@@ -43,7 +43,8 @@  int		RarpTry;
  *	Handle a RARP received packet.
  */
 static void
-RarpHandler(uchar * dummi0, unsigned dummi1, unsigned dummi2, unsigned dummi3)
+RarpHandler(uchar *dummi0, unsigned dummi1, IPaddr_t sip, unsigned dummi2,
+	    unsigned dummi3)
 {
 	char *s;
 	debug("Got good RARP\n");
diff --git a/net/sntp.c b/net/sntp.c
index 76c10ec..82f2fe6 100644
--- a/net/sntp.c
+++ b/net/sntp.c
@@ -48,7 +48,8 @@  SntpTimeout (void)
 }
 
 static void
-SntpHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
+SntpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+	    unsigned len)
 {
 	struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt;
 	struct rtc_time tm;
diff --git a/net/tftp.c b/net/tftp.c
index ed559b7..00abec3 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -278,7 +278,8 @@  TftpSend (void)
 
 
 static void
-TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
+TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+	    unsigned len)
 {
 	ushort proto;
 	ushort *s;