Skip to contentSkip to conversation

Add link-local addressing support

PATCH Superseded Joe Hershberger 11 participants 281 messages Jan 20, 2012 – May 29, 2012 Page 1 of 3

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Add link-local addressing support

Link-local support allows the bootloader to get a usable network address regardless of network environment. Given that bootloaders may not always have access to a DHCP server, this functionality makes accessing it in those environments easier. It is also referred to as zero-configuration IP.

The following script allows the network to be configured for DHCP, link-local, and static IP addresses configurably by the environment using "dhcpenabled" and "linklocalenabled".

#define CONFIG_EXTRA_ENV_SETTINGS \
	"ipconfigcmd=if test \\\"$dhcpenabled\\\" -ne 0;"		\
		"then "							\
			"dhcpfail=0;dhcp || dhcpfail=1;"		\
		"else "							\
			"dhcpfail=-1;"					\
		"fi;"							\
		"if test \\\"$linklocalenabled\\\" -ne 0 -a "		\
			"\\\"$dhcpfail\\\" -ne 0;"			\
		"then "							\
			"linklocal;"					\
			"llfail=0;"					\
		"else "							\
			"llfail=-1;"					\
		"fi;"							\
		"if test \\\"$llfail\\\" -ne 0 -a "			\
			"\\\"$dhcpfail\\\" -ne 0; "			\
		"then "							\
			"setenv ipaddr $sipaddr; "			\
			"setenv netmask $snetmask; "			\
			"setenv gatewayip $sgatewayip; "		\
		"fi;\0"							\

Some refactoring of net/ was done to make adding link-local support cleaner as well as generally improving the readability and organization of the code.

Tested on da850_am18xxevm
Tested on MPC8313ERDB_33

check-patch
No warnings or errors (depends on ignoring CONSIDER_KSTRTO)

MAKEALL -a powerpc
No additional warnings or errors beyond master

MAKEALL -a arm
No additional warnings or errors beyond master

git-test-sequence
Cleanly bisectable
Code-size affects on MPC8313ERDB_33 shown below

Quoted 1 line

cat sizeofMCP8313

make BUILD_DIR=/tmp/u-boot-build/ ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu- USE_PRIVATE_LIBGG=yes distclean > /dev/null && \
make BUILD_DIR=/tmp/u-boot-build/ ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu- MPC8313ERDB_33_config > /dev/null && \
make BUILD_DIR=/tmp/u-boot-build/ ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu- USE_PRIVATE_LIBGG=yes > /dev/null && \
powerpc-linux-gnu-size /tmp/u-boot-build/u-boot

Quoted 1 line

git-test-sequence origin/master.. './sizeofMCP8313'

Testing ./sizeofMCP8313
HEAD is now at 4dbe8d8 net: Remove volatile from all of net except the eth driver interface
text data bss dec hex filename
264917 24880 42104 331901 5107d /tmp/u-boot-build/ppc/u-boot
Passed: 90ea672853753b5a4244db60d095e5f99cdcfe7d.
Testing ./sizeofMCP8313
HEAD is now at 92893c4 net: cosmetic: checkpatch compliance
text data bss dec hex filename
264917 24880 42104 331901 5107d /tmp/u-boot-build/ppc/u-boot
Passed: 12b0b6e953406a1ed98d1c4dd9701078d1dfe00d.
Testing ./sizeofMCP8313
HEAD is now at d6c19a3 net: Move mv64x6x_eth_initialize() to board_eth_init()
text data bss dec hex filename
264917 24880 42104 331901 5107d /tmp/u-boot-build/ppc/u-boot
Passed: cf9f493ab5d08a282ec9905797fa58d82b15714d.
Testing ./sizeofMCP8313
HEAD is now at 52403e8 net: Make the MAC-seeded random number generator available to /net
text data bss dec hex filename
264917 24880 42104 331901 5107d /tmp/u-boot-build/ppc/u-boot
Passed: a92c9c9e8f68337a78ee2d7c6775299d7c057b52.
Testing ./sizeofMCP8313
HEAD is now at ff86c81 net: Move CDP out of net.c
text data bss dec hex filename
264917 24880 42104 331901 5107d /tmp/u-boot-build/ppc/u-boot
Passed: 9bf01065cb04c34e43cc5d56162aa2dac9d61f3e.
Testing ./sizeofMCP8313
HEAD is now at da1998d net: Move ARP out of net.c
text data bss dec hex filename
265045 24928 42104 332077 5112d /tmp/u-boot-build/ppc/u-boot
Passed: 621d67b8c6126ef6510d0a2b2c06ce410cd60327.
Testing ./sizeofMCP8313
HEAD is now at 408b8ab net: Move PING out of net.c
text data bss dec hex filename
265237 24976 42096 332309 51215 /tmp/u-boot-build/ppc/u-boot
Passed: e8aaa7382de39137c91809ba2e121f87338627d5.
Testing ./sizeofMCP8313
HEAD is now at 1b3ed14 net: Move RARP receive logic out of net.c
text data bss dec hex filename
265237 24976 42096 332309 51215 /tmp/u-boot-build/ppc/u-boot
Passed: 7a8216874def295337178da67078758cbf909681.
Testing ./sizeofMCP8313
HEAD is now at 50eb857 net: cosmetic: Un-typedef variables in net
text data bss dec hex filename
265237 24976 42096 332309 51215 /tmp/u-boot-build/ppc/u-boot
Passed: b679739af8ffc6f9a31264c175077f4ac96c236d.
Testing ./sizeofMCP8313
HEAD is now at 22259f9 net: cosmetic: Improve variable names and code readability
text data bss dec hex filename
265237 24976 42096 332309 51215 /tmp/u-boot-build/ppc/u-boot
Passed: 834a569897337636fe861797625fbdbbe1373f75.
Testing ./sizeofMCP8313
HEAD is now at 5340a18 net: Refactor IP, UPD, and ICMP header writing functions
text data bss dec hex filename
265237 24972 42096 332305 51211 /tmp/u-boot-build/ppc/u-boot
Passed: 20b84dcfa7d355010cacc3493e1e86521b00879f.
Testing ./sizeofMCP8313
HEAD is now at 275e230 net: Refactor packet length computations
text data bss dec hex filename
265221 24972 42096 332289 51201 /tmp/u-boot-build/ppc/u-boot
Passed: d078d84d959dbb40a67baa16e8b0d210e6472c79.
Testing ./sizeofMCP8313
HEAD is now at c1214f2 net: Refactor bootp packet length computations
text data bss dec hex filename
265221 24972 42096 332289 51201 /tmp/u-boot-build/ppc/u-boot
Passed: 3ff5dfd46c8f70ec2304a150a606871b7504cf42.
Testing ./sizeofMCP8313
HEAD is now at 9cff376 net: Refactor ping recieve handler
text data bss dec hex filename
265093 24968 42096 332157 5117d /tmp/u-boot-build/ppc/u-boot
Passed: e531ec8d3986f45d30862eacce73b0db55e2fb13.
Testing ./sizeofMCP8313
HEAD is now at e47e5ac net: Refactor to call NetSendPacket() instead of calling eth_send()
text data bss dec hex filename
265093 24968 42096 332157 5117d /tmp/u-boot-build/ppc/u-boot
Passed: 4a78d3ab2514c8d00bc18978f7a489a800a3a77b.
Testing ./sizeofMCP8313
HEAD is now at 9bcb672 net: Refactor to protect access to the NetState variable
text data bss dec hex filename
265109 24956 42096 332161 51181 /tmp/u-boot-build/ppc/u-boot
Passed: 8ecfa86d86fe2624cb509c41fbaec8dcf13a9945.
Testing ./sizeofMCP8313
HEAD is now at a2c79e3 net: Refactor to separate the UDP handler from the ARP handler
text data bss dec hex filename
265317 24956 42112 332385 51261 /tmp/u-boot-build/ppc/u-boot
Passed: f66f88edda9ec16b3de20a10faa1c6bb35f316c2.
Testing ./sizeofMCP8313
HEAD is now at 502deaa net: Add NetUpdateEther() to handle ARP or Ping replies (VLAN or SNAP)
text data bss dec hex filename
265429 24952 42112 332493 512cd /tmp/u-boot-build/ppc/u-boot
Passed: 3daff36dc0b5b65b8df7a3a7011f1e5f89eb5a9d.
Testing ./sizeofMCP8313
HEAD is now at 315bd4d net: Don't write the "serverip" env var if told not to in the config
text data bss dec hex filename
265429 24952 42112 332493 512cd /tmp/u-boot-build/ppc/u-boot
Passed: b0e7a73485c771eed710d6b9afd1e80e0ccc2cfa.
Testing ./sizeofMCP8313
HEAD is now at 82b1968 net: Fix compile warning if CONFIG_BOOTP_SERVERIP is not defined
text data bss dec hex filename
265429 24952 42112 332493 512cd /tmp/u-boot-build/ppc/u-boot
Passed: 121eb763232d5cf6a4e66f6c100713537f6036cf.
Testing ./sizeofMCP8313
HEAD is now at cebdefe net: Remove unneeded static allocation for MAC address in PingSend()
text data bss dec hex filename
265397 24944 42104 332445 5129d /tmp/u-boot-build/ppc/u-boot
Passed: 1366a9b1529e9752dd4a47d7c82545b13e11b461.
Testing ./sizeofMCP8313
HEAD is now at 8f856ad net: Fix net buffer initialization
text data bss dec hex filename
265605 24956 42104 332665 51379 /tmp/u-boot-build/ppc/u-boot
Passed: 16cbef4189d5be4837c3de9dc2ac0bcf8d89fa75.
Testing ./sizeofMCP8313
HEAD is now at 002991b net: Refactor NetSendUDPPacket to share more code
text data bss dec hex filename
265557 24956 42104 332617 51349 /tmp/u-boot-build/ppc/u-boot
Passed: 7f001d4025dc564fe2a96a1e32214e194b891bd1.
Testing ./sizeofMCP8313
HEAD is now at 314902e net: Don't copy every packet that waits for an ARP
text data bss dec hex filename
265573 24956 42104 332633 51359 /tmp/u-boot-build/ppc/u-boot
Passed: 3be3cdd2224c88c88442e48c0f4f836d7be1d8ae.
Testing ./sizeofMCP8313
HEAD is now at 2a43805 net: Add option CONFIG_BOOTP_CAN_FAIL
text data bss dec hex filename
265573 24956 42104 332633 51359 /tmp/u-boot-build/ppc/u-boot
Passed: 4d578ba84228e51a56249035207085f0845d3be8.
Testing ./sizeofMCP8313
HEAD is now at defb33c net: Add link-local addressing support
text data bss dec hex filename
265577 24956 42104 332637 5135d /tmp/u-boot-build/ppc/u-boot
Passed: cb6b29e82f292b5b27aec6f51f2f9d50e1f8b0f8.
Testing ./sizeofMCP8313
HEAD is now at 615c707 net: Work-around for brain-damaged Cisco routers with arp-proxy
text data bss dec hex filename
265657 24956 42104 332717 513ad /tmp/u-boot-build/ppc/u-boot
Passed: 63a3ddaf7e029bb7ec71b1edb42473ae6a208dec.
Testing ./sizeofMCP8313
HEAD is now at 7d5229d net: Allow filtering on debug traces in the net subsystem
text data bss dec hex filename
265594 24948 42104 332646 51366 /tmp/u-boot-build/ppc/u-boot
Passed: 1cf14c686c5b60bfa48d8bfd6eb40e20ac0c378b.
All's well.

Joe Hershberger (28):
net: Remove volatile from all of net except the eth driver interface
net: cosmetic: checkpatch compliance
net: Move mv64x6x_eth_initialize() to board_eth_init()
net: Make the MAC-seeded random number generator available to /net
net: Move CDP out of net.c
net: Move ARP out of net.c
net: Move PING out of net.c
net: Move RARP receive logic out of net.c
net: cosmetic: Un-typedef variables in net
net: cosmetic: Improve variable names and code readability
net: Refactor IP, UPD, and ICMP header writing functions
net: Refactor packet length computations
net: Refactor bootp packet length computations
net: Refactor ping recieve handler
net: Refactor to call NetSendPacket() instead of calling eth_send()
net: Refactor to protect access to the NetState variable
net: Refactor to separate the UDP handler from the ARP handler
net: Add NetUpdateEther() to handle ARP or Ping replies (VLAN or
SNAP)
net: Don't write the "serverip" env var if told not to in the config
net: Fix compile warning if CONFIG_BOOTP_SERVERIP is not defined
net: Remove unneeded static allocation for MAC address in PingSend()
net: Fix net buffer initialization
net: Refactor NetSendUDPPacket to share more code
net: Don't copy every packet that waits for an ARP
net: Add option CONFIG_BOOTP_CAN_FAIL
net: Add link-local addressing support
net: Work-around for brain-damaged Cisco routers with arp-proxy
net: Allow filtering on debug traces in the net subsystem

 README                               |   22 +-
 arch/powerpc/cpu/mpc8260/ether_fcc.c |   10 +-
 arch/powerpc/cpu/mpc8xx/fec.c        |    2 +-
 board/Marvell/db64360/db64360.c      |   12 +-
 board/Marvell/db64360/mv_eth.c       |   78 ++-
 board/Marvell/db64360/mv_eth.h       |   63 +--
 board/Marvell/db64460/db64460.c      |   12 +-
 board/Marvell/db64460/mv_eth.c       |   78 ++-
 board/Marvell/db64460/mv_eth.h       |   63 +--
 board/esd/cpci750/cpci750.c          |    6 +
 board/esd/cpci750/mv_eth.c           |   78 ++-
 board/esd/cpci750/mv_eth.h           |   63 +--
 board/prodrive/p3mx/mv_eth.c         |   78 ++-
 board/prodrive/p3mx/mv_eth.h         |   63 +--
 board/prodrive/p3mx/p3mx.c           |    6 +
 common/cmd_net.c                     |   34 +-
 common/main.c                        |    1 -
 drivers/net/netconsole.c             |  130 ++--
 include/common.h                     |    4 +
 include/configs/am3517_crane.h       |    2 +-
 include/configs/am3517_evm.h         |    2 +-
 include/configs/origen.h             |    2 +-
 include/net.h                        |  206 ++++---
 net/Makefile                         |    8 +-
 net/arp.c                            |  242 +++++++
 net/arp.h                            |   30 +
 net/bootp.c                          |  435 ++++++-------
 net/bootp.h                          |   60 +-
 net/cdp.c                            |  372 +++++++++++
 net/cdp.h                            |   18 +
 net/dns.c                            |   12 +-
 net/eth.c                            |   75 +--
 net/link_local.c                     |  340 ++++++++++
 net/link_local.h                     |   21 +
 net/net.c                            | 1152 +++++++++-------------------------
 net/net_rand.c                       |   68 ++
 net/net_rand.h                       |   18 +
 net/nfs.c                            |  306 +++++-----
 net/nfs.h                            |    2 +-
 net/ping.c                           |  119 ++++
 net/ping.h                           |   20 +
 net/rarp.c                           |   77 ++-
 net/rarp.h                           |    5 +-
 net/sntp.c                           |   37 +-
 net/sntp.h                           |    2 +-
 net/tftp.c                           |   50 +-
 net/tftp.h                           |    2 +-
 47 files changed, 2625 insertions(+), 1861 deletions(-)
 create mode 100644 net/arp.c
 create mode 100644 net/arp.h
 create mode 100644 net/cdp.c
 create mode 100644 net/cdp.h
 create mode 100644 net/link_local.c
 create mode 100644 net/link_local.h
 create mode 100644 net/net_rand.c
 create mode 100644 net/net_rand.h
 create mode 100644 net/ping.c
 create mode 100644 net/ping.h
#1 lore raw

PATCH 1/28 net: Remove volatile from all of net except the eth driver interface

The mv_eth driver should not redefine the net function definition

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 board/Marvell/db64360/mv_eth.c |    2 --
 board/Marvell/db64460/mv_eth.c |    2 --
 board/esd/cpci750/mv_eth.c     |    2 --
 board/prodrive/p3mx/mv_eth.c   |    2 --
 include/net.h                  |   16 ++++++++--------
 net/bootp.c                    |    4 ++--
 net/net.c                      |   40 ++++++++++++++++++++--------------------
 net/rarp.c                     |    2 +-
 net/tftp.c                     |    6 +++---
 9 files changed, 34 insertions(+), 42 deletions(-)
board/Marvell/db64360/mv_eth.c +0 -2
index 6340585..550610e 100644
@@ -95,8 +95,6 @@ int mv64360_eth_xmit (struct eth_device *, volatile void *packet, int length);
 #ifndef  UPDATE_STATS_BY_SOFTWARE
 static void mv64360_eth_print_stat (struct eth_device *dev);
 #endif
-/* Processes a received packet */
-extern void NetReceive (volatile uchar *, int);
 
 extern unsigned int INTERNAL_REG_BASE_ADDR;
 
board/Marvell/db64460/mv_eth.c +0 -2
index 4aefbaf..c447229 100644
@@ -95,8 +95,6 @@ int mv64460_eth_xmit (struct eth_device *, volatile void *packet, int length);
 #ifndef  UPDATE_STATS_BY_SOFTWARE
 static void mv64460_eth_print_stat (struct eth_device *dev);
 #endif
-/* Processes a received packet */
-extern void NetReceive (volatile uchar *, int);
 
 extern unsigned int INTERNAL_REG_BASE_ADDR;
 
board/esd/cpci750/mv_eth.c +0 -2
index 001c1ad..db2324b 100644
@@ -95,8 +95,6 @@ int mv64360_eth_xmit (struct eth_device *, volatile void *packet, int length);
 #ifndef  UPDATE_STATS_BY_SOFTWARE
 static void mv64360_eth_print_stat (struct eth_device *dev);
 #endif
-/* Processes a received packet */
-extern void NetReceive (volatile uchar *, int);
 
 extern unsigned int INTERNAL_REG_BASE_ADDR;
 
board/prodrive/p3mx/mv_eth.c +0 -2
index 15b3bfc..f26ded8 100644
@@ -109,8 +109,6 @@ int phy_setup_aneg (char *devname, unsigned char addr);
 #ifndef	 UPDATE_STATS_BY_SOFTWARE
 static void mv64460_eth_print_stat (struct eth_device *dev);
 #endif
-/* Processes a received packet */
-extern void NetReceive (volatile uchar *, int);
 
 extern unsigned int INTERNAL_REG_BASE_ADDR;
 
include/net.h +8 -8
index e4d42c2..ccdb01d 100644
@@ -342,9 +342,9 @@ extern uchar		NetOurEther[6];		/* Our ethernet address		*/
 extern uchar		NetServerEther[6];	/* Boot server enet address	*/
 extern IPaddr_t		NetOurIP;		/* Our    IP addr (0 = unknown)	*/
 extern IPaddr_t		NetServerIP;		/* Server IP addr (0 = unknown)	*/
-extern volatile uchar * NetTxPacket;		/* THE transmit packet		*/
-extern volatile uchar * NetRxPackets[PKTBUFSRX];/* Receive packets		*/
-extern volatile uchar * NetRxPacket;		/* Current receive packet	*/
+extern uchar		*NetTxPacket;		/* THE transmit packet */
+extern uchar		*NetRxPackets[PKTBUFSRX];/* Receive packets */
+extern uchar		*NetRxPacket;		/* Current receive packet */
 extern int		NetRxPacketLen;		/* Current rx packet length	*/
 extern unsigned		NetIPID;		/* IP ID (counting)		*/
 extern uchar		NetBcastAddr[6];	/* Ethernet boardcast address	*/
@@ -408,10 +408,10 @@ extern void	NetStartAgain(void);
 extern int	NetEthHdrSize(void);
 
 /* Set ethernet header; returns the size of the header */
-extern int	NetSetEther(volatile uchar *, uchar *, uint);
+extern int NetSetEther(uchar *, uchar *, uint);
 
 /* Set IP header */
-extern void	NetSetIP(volatile uchar *, IPaddr_t, int, int, int);
+extern void NetSetIP(uchar *, IPaddr_t, int, int, int);
 
 /* Checksum */
 extern int	NetCksumOk(uchar *, int);	/* Return true if cksum OK	*/
@@ -423,7 +423,7 @@ extern void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */
 extern void	NetSetTimeout(ulong, thand_f *);/* Set timeout handler		*/
 
 /* Transmit "NetTxPacket" */
-extern void	NetSendPacket(volatile uchar *, int);
+extern void NetSendPacket(uchar *, int);
 
 /* Transmit UDP packet, performing ARP request if needed */
 extern int	NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len);
@@ -445,7 +445,7 @@ void net_auto_load(void);
  * footprint in our tests.
  */
 /* return IP *in network byteorder* */
-static inline IPaddr_t NetReadIP(volatile void *from)
+static inline IPaddr_t NetReadIP(void *from)
 {
 	IPaddr_t ip;
 	memcpy((void*)&ip, (void*)from, sizeof(ip));
@@ -467,7 +467,7 @@ static inline void NetWriteIP(void *to, IPaddr_t ip)
 }
 
 /* copy IP */
-static inline void NetCopyIP(volatile void *to, void *from)
+static inline void NetCopyIP(void *to, void *from)
 {
 	memcpy((void*)to, from, sizeof(IPaddr_t));
 }
net/bootp.c +2 -2
index 34124b8..6d40608 100644
@@ -585,7 +585,7 @@ static int BootpExtended (u8 * e)
 void
 BootpRequest (void)
 {
-	volatile uchar *pkt, *iphdr;
+	uchar *pkt, *iphdr;
 	Bootp_t *bp;
 	int ext_len, pktlen, iplen;
 
@@ -837,7 +837,7 @@ static int DhcpMessageType(unsigned char *popt)
 
 static void DhcpSendRequestPkt(Bootp_t *bp_offer)
 {
-	volatile uchar *pkt, *iphdr;
+	uchar *pkt, *iphdr;
 	Bootp_t *bp;
 	int pktlen, iplen, extlen;
 	IPaddr_t OfferedIP;
net/net.c +20 -20
index 045405b..29e018c 100644
@@ -152,7 +152,7 @@ IPaddr_t	NetOurIP;
 /* Server IP addr (0 = unknown) */
 IPaddr_t	NetServerIP;
 /* Current receive packet */
-volatile uchar *NetRxPacket;
+uchar *NetRxPacket;
 /* Current rx packet length */
 int		NetRxPacketLen;
 /* IP packet ID */
@@ -208,10 +208,10 @@ void NcStart(void);
 int nc_input_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len);
 #endif
 
-volatile uchar	PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
+uchar PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
 
 /* Receive packet */
-volatile uchar *NetRxPackets[PKTBUFSRX];
+uchar *NetRxPackets[PKTBUFSRX];
 
 /* Current RX packet handler */
 static rxhand_f *packetHandler;
@@ -225,7 +225,7 @@ static ulong	timeStart;
 /* Current timeout value */
 static ulong	timeDelta;
 /* THE transmit packet */
-volatile uchar *NetTxPacket;
+uchar *NetTxPacket;
 
 static int net_check_prereq(enum proto_t protocol);
 
@@ -246,7 +246,7 @@ int		NetArpWaitTry;
 
 void ArpRequest(void)
 {
-	volatile uchar *pkt;
+	uchar *pkt;
 	ARP_t *arp;
 
 	debug("ARP broadcast %d\n", NetArpWaitTry);
@@ -704,7 +704,7 @@ NetSetTimeout(ulong iv, thand_f *f)
 
 
 void
-NetSendPacket(volatile uchar *pkt, int len)
+NetSendPacket(uchar *pkt, int len)
 {
 	(void) eth_send(pkt, len);
 }
@@ -767,8 +767,8 @@ static ushort PingSeqNo;
 int PingSend(void)
 {
 	static uchar mac[6];
-	volatile IP_t *ip;
-	volatile ushort *s;
+	IP_t *ip;
+	ushort *s;
 	uchar *pkt;
 
 	/* XXX always send arp request */
@@ -783,7 +783,7 @@ int PingSend(void)
 	pkt = NetArpWaitTxPacket;
 	pkt += NetSetEther(pkt, mac, PROT_IP);
 
-	ip = (volatile IP_t *)pkt;
+	ip = (IP_t *)pkt;
 
 	/*
 	 * Construct an IP and ICMP header.
@@ -935,9 +935,9 @@ static ushort CDP_compute_csum(const uchar *buff, ushort len)
 
 int CDPSendTrigger(void)
 {
-	volatile uchar *pkt;
-	volatile ushort *s;
-	volatile ushort *cp;
+	uchar *pkt;
+	ushort *s;
+	ushort *cp;
 	Ethernet_t *et;
 	int len;
 	ushort chksum;
@@ -964,7 +964,7 @@ int CDPSendTrigger(void)
 	/* CDP header */
 	*pkt++ = 0x02;				/* CDP version 2 */
 	*pkt++ = 180;				/* TTL */
-	s = (volatile ushort *)pkt;
+	s = (ushort *)pkt;
 	cp = s;
 	/* checksum (0 for later calculation) */
 	*s++ = htons(0);
@@ -1454,9 +1454,9 @@ NetReceive(volatile uchar *inpkt, int len)
 
 	debug("packet received\n");
 
-	NetRxPacket = inpkt;
+	NetRxPacket = (uchar *)inpkt;
 	NetRxPacketLen = len;
-	et = (Ethernet_t *)inpkt;
+	et = (Ethernet_t *)NetRxPacket;
 
 	/* too small packet? */
 	if (len < ETHER_HDR_SIZE)
@@ -1491,11 +1491,11 @@ NetReceive(volatile uchar *inpkt, int len)
 		 */
 		x = ntohs(et->et_prot);
 
-		ip = (IP_t *)(inpkt + E802_HDR_SIZE);
+		ip = (IP_t *)(NetRxPacket + E802_HDR_SIZE);
 		len -= E802_HDR_SIZE;
 
 	} else if (x != PROT_VLAN) {	/* normal packet */
-		ip = (IP_t *)(inpkt + ETHER_HDR_SIZE);
+		ip = (IP_t *)(NetRxPacket + ETHER_HDR_SIZE);
 		len -= ETHER_HDR_SIZE;
 
 	} else {			/* VLAN packet */
@@ -1519,7 +1519,7 @@ NetReceive(volatile uchar *inpkt, int len)
 		vlanid = cti & VLAN_IDMASK;
 		x = ntohs(vet->vet_type);
 
-		ip = (IP_t *)(inpkt + VLAN_ETHER_HDR_SIZE);
+		ip = (IP_t *)(NetRxPacket + VLAN_ETHER_HDR_SIZE);
 		len -= VLAN_ETHER_HDR_SIZE;
 	}
 
@@ -1917,7 +1917,7 @@ NetEthHdrSize(void)
 }
 
 int
-NetSetEther(volatile uchar *xet, uchar * addr, uint prot)
+NetSetEther(uchar *xet, uchar * addr, uint prot)
 {
 	Ethernet_t *et = (Ethernet_t *)xet;
 	ushort myvlanid;
@@ -1942,7 +1942,7 @@ NetSetEther(volatile uchar *xet, uchar * addr, uint prot)
 }
 
 void
-NetSetIP(volatile uchar *xip, IPaddr_t dest, int dport, int sport, int len)
+NetSetIP(uchar *xip, IPaddr_t dest, int dport, int sport, int len)
 {
 	IP_t *ip = (IP_t *)xip;
 
net/rarp.c +1 -1
index 097f970..77d63e8 100644
@@ -71,7 +71,7 @@ void
 RarpRequest (void)
 {
 	int i;
-	volatile uchar *pkt;
+	uchar *pkt;
 	ARP_t *	rarp;
 
 	printf("RARP broadcast %d\n", ++RarpTry);
net/tftp.c +3 -3
index 7aa3e23..e62f229 100644
@@ -310,9 +310,9 @@ static void
 TftpSend(void)
 {
 	uchar *pkt;
-	volatile uchar *xp;
-	int		len = 0;
-	volatile ushort *s;
+	uchar *xp;
+	int len = 0;
+	ushort *s;
 
 #ifdef CONFIG_MCAST_TFTP
 	/* Multicast TFTP.. non-MasterClients do not ACK data. */
Signature · 1 line
1.6.0.2
#2 lore raw

PATCH 1/28 net: Remove volatile from all of net except the eth driver interface

Hi Joe,

Quoted 244 lines · Joe Hershberger

The mv_eth driver should not redefine the net function definition

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

?board/Marvell/db64360/mv_eth.c | ? ?2 --
?board/Marvell/db64460/mv_eth.c | ? ?2 --
?board/esd/cpci750/mv_eth.c ? ? | ? ?2 --
?board/prodrive/p3mx/mv_eth.c ? | ? ?2 --
?include/net.h ? ? ? ? ? ? ? ? ?| ? 16 ++++++++--------
?net/bootp.c ? ? ? ? ? ? ? ? ? ?| ? ?4 ++--
?net/net.c ? ? ? ? ? ? ? ? ? ? ?| ? 40 ++++++++++++++++++++--------------------
?net/rarp.c ? ? ? ? ? ? ? ? ? ? | ? ?2 +-
?net/tftp.c ? ? ? ? ? ? ? ? ? ? | ? ?6 +++---

?9 files changed, 34 insertions(+), 42 deletions(-)

board/Marvell/db64360/mv_eth.c +0 -0
index 6340585..550610e 100644
@@ -95,8 +95,6 @@ int mv64360_eth_xmit (struct eth_device *, volatile void *packet, int length);

?#ifndef ?UPDATE_STATS_BY_SOFTWARE
?static void mv64360_eth_print_stat (struct eth_device *dev); ?#endif

board/Marvell/db64360/mv_eth.c +0 -2
-/* Processes a received packet */
-extern void NetReceive (volatile uchar *, int);

?extern unsigned int INTERNAL_REG_BASE_ADDR;

board/Marvell/db64460/mv_eth.c +0 -0
index 4aefbaf..c447229 100644
@@ -95,8 +95,6 @@ int mv64460_eth_xmit (struct eth_device *, volatile void *packet, int length);

?#ifndef ?UPDATE_STATS_BY_SOFTWARE
?static void mv64460_eth_print_stat (struct eth_device *dev); ?#endif

board/Marvell/db64460/mv_eth.c +0 -2
-/* Processes a received packet */
-extern void NetReceive (volatile uchar *, int);

?extern unsigned int INTERNAL_REG_BASE_ADDR;

board/esd/cpci750/mv_eth.c +0 -0
index 001c1ad..db2324b 100644
@@ -95,8 +95,6 @@ int mv64360_eth_xmit (struct eth_device *, volatile void *packet, int length);

?#ifndef ?UPDATE_STATS_BY_SOFTWARE
?static void mv64360_eth_print_stat (struct eth_device *dev); ?#endif

board/esd/cpci750/mv_eth.c +0 -2
-/* Processes a received packet */
-extern void NetReceive (volatile uchar *, int);

?extern unsigned int INTERNAL_REG_BASE_ADDR;

board/prodrive/p3mx/mv_eth.c +0 -0
index 15b3bfc..f26ded8 100644
@@ -109,8 +109,6 @@ int phy_setup_aneg (char *devname, unsigned char addr);

?#ifndef ? ? ? ? UPDATE_STATS_BY_SOFTWARE
?static void mv64460_eth_print_stat (struct eth_device *dev); ?#endif

board/prodrive/p3mx/mv_eth.c +0 -2
-/* Processes a received packet */
-extern void NetReceive (volatile uchar *, int);

?extern unsigned int INTERNAL_REG_BASE_ADDR;

include/net.h +0 -0
index e4d42c2..ccdb01d 100644
@@ -342,9 +342,9 @@ extern uchar ? ? ? ? ? ? ? ?NetOurEther[6]; ? ? ? ? /* Our ethernet address ? ? ? ? */

?extern uchar ? ? ? ? ? NetServerEther[6]; ? ? ?/* Boot server enet address ? ? */ ?extern IPaddr_t ? ? ? ? ? ? ? ?NetOurIP; ? ? ? ? ? ? ? /* Our ? ?IP addr (0 = unknown) */ ?extern IPaddr_t ? ? ? ? ? ? ? ?NetServerIP; ? ? ? ? ? ?/* Server IP addr (0 = unknown) */

include/net.h +3 -3
-extern volatile uchar * NetTxPacket; ? ? ? ? ? /* THE transmit packet ? ? ? ? ?*/
-extern volatile uchar * NetRxPackets[PKTBUFSRX];/* Receive packets ? ? ? ? ? ? */
-extern volatile uchar * NetRxPacket; ? ? ? ? ? /* Current receive packet ? ? ? */
+extern uchar ? ? ? ? ? *NetTxPacket; ? ? ? ? ? /* THE transmit packet */
+extern uchar ? ? ? ? ? *NetRxPackets[PKTBUFSRX];/* Receive packets */
+extern uchar ? ? ? ? ? *NetRxPacket; ? ? ? ? ? /* Current receive packet */

?extern int ? ? ? ? ? ? NetRxPacketLen; ? ? ? ? /* Current rx packet length ? ? */ ?extern unsigned ? ? ? ? ? ? ? ?NetIPID; ? ? ? ? ? ? ? ?/* IP ID (counting) ? ? ? ? ? ? */ ?extern uchar ? ? ? ? ? NetBcastAddr[6]; ? ? ? ?/* Ethernet boardcast address ? */

include/net.h +0 -0
@@ -408,10 +408,10 @@ extern void ? ? ? NetStartAgain(void);
 ?extern int ? ? NetEthHdrSize(void);
 

?/* Set ethernet header; returns the size of the header */

include/net.h +1 -1
-extern int ? ? NetSetEther(volatile uchar *, uchar *, uint);
+extern int NetSetEther(uchar *, uchar *, uint);

?/* Set IP header */

include/net.h +1 -1
-extern void ? ?NetSetIP(volatile uchar *, IPaddr_t, int, int, int);
+extern void NetSetIP(uchar *, IPaddr_t, int, int, int);

?/* Checksum */
?extern int ? ? NetCksumOk(uchar *, int); ? ? ? /* Return true if cksum OK ? ? ?*/

include/net.h +0 -0
@@ -423,7 +423,7 @@ extern void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */

?extern void ? ?NetSetTimeout(ulong, thand_f *);/* Set timeout handler ? ? ? ? ?*/

?/* Transmit "NetTxPacket" */

include/net.h +1 -1
-extern void ? ?NetSendPacket(volatile uchar *, int);
+extern void NetSendPacket(uchar *, int);

?/* Transmit UDP packet, performing ARP request if needed */
?extern int ? ? NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len);

include/net.h +0 -0
@@ -445,7 +445,7 @@ void net_auto_load(void);

?* footprint in our tests.
?*/
?/* return IP *in network byteorder* */

include/net.h +1 -1
-static inline IPaddr_t NetReadIP(volatile void *from)
+static inline IPaddr_t NetReadIP(void *from)

?{
? ? ? ?IPaddr_t ip;
? ? ? ?memcpy((void*)&ip, (void*)from, sizeof(ip));

include/net.h +0 -0
@@ -467,7 +467,7 @@ static inline void NetWriteIP(void *to, IPaddr_t ip)
 ?}
 

?/* copy IP */

include/net.h +1 -1
-static inline void NetCopyIP(volatile void *to, void *from)
+static inline void NetCopyIP(void *to, void *from)

?{
? ? ? ?memcpy((void*)to, from, sizeof(IPaddr_t));
?}

net/bootp.c +0 -0
index 34124b8..6d40608 100644
@@ -585,7 +585,7 @@ static int BootpExtended (u8 * e)

?void
?BootpRequest (void)
?{
- ? ? ? volatile uchar *pkt, *iphdr;
+ ? ? ? uchar *pkt, *iphdr;
? ? ? ?Bootp_t *bp;
? ? ? ?int ext_len, pktlen, iplen;

net/bootp.c +1 -1
@@ -837,7 +837,7 @@ static int DhcpMessageType(unsigned char *popt)
 
 ?static void DhcpSendRequestPkt(Bootp_t *bp_offer)
 ?{
- ? ? ? volatile uchar *pkt, *iphdr;
+ ? ? ? uchar *pkt, *iphdr;
 ? ? ? ?Bootp_t *bp;
 ? ? ? ?int pktlen, iplen, extlen;
 ? ? ? ?IPaddr_t OfferedIP;
net/net.c +0 -0
index 045405b..29e018c 100644
@@ -152,7 +152,7 @@ IPaddr_t ? ?NetOurIP;

?/* Server IP addr (0 = unknown) */
?IPaddr_t ? ? ? NetServerIP;
?/* Current receive packet */

net/net.c +1 -1
-volatile uchar *NetRxPacket;
+uchar *NetRxPacket;

?/* Current rx packet length */
?int ? ? ? ? ? ?NetRxPacketLen;
?/* IP packet ID */

net/net.c +0 -0
@@ -208,10 +208,10 @@ void NcStart(void);
 ?int nc_input_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len);

?#endif

net/net.c +1 -1
-volatile uchar PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
+uchar PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];

?/* Receive packet */

net/net.c +1 -1
-volatile uchar *NetRxPackets[PKTBUFSRX];
+uchar *NetRxPackets[PKTBUFSRX];

?/* Current RX packet handler */
?static rxhand_f *packetHandler;

net/net.c +0 -0
@@ -225,7 +225,7 @@ static ulong ? ? ? ?timeStart;

?/* Current timeout value */
?static ulong ? timeDelta;
?/* THE transmit packet */

net/net.c +1 -1
-volatile uchar *NetTxPacket;
+uchar *NetTxPacket;

?static int net_check_prereq(enum proto_t protocol);

net/net.c +1 -1
@@ -246,7 +246,7 @@ int ? ? ? ? NetArpWaitTry;
 
 ?void ArpRequest(void)
 ?{
- ? ? ? volatile uchar *pkt;
+ ? ? ? uchar *pkt;
 ? ? ? ?ARP_t *arp;
 
 ? ? ? ?debug("ARP broadcast %d\n", NetArpWaitTry);
@@ -704,7 +704,7 @@ NetSetTimeout(ulong iv, thand_f *f)
 
 

?void

net/net.c +1 -1
-NetSendPacket(volatile uchar *pkt, int len)
+NetSendPacket(uchar *pkt, int len)

?{
? ? ? ?(void) eth_send(pkt, len);
?}

net/net.c +2 -2
@@ -767,8 +767,8 @@ static ushort PingSeqNo;
 ?int PingSend(void)
 ?{
 ? ? ? ?static uchar mac[6];
- ? ? ? volatile IP_t *ip;
- ? ? ? volatile ushort *s;
+ ? ? ? IP_t *ip;
+ ? ? ? ushort *s;
 ? ? ? ?uchar *pkt;
 

? ? ? ?/* XXX always send arp request */

net/net.c +1 -1
@@ -783,7 +783,7 @@ int PingSend(void)
 ? ? ? ?pkt = NetArpWaitTxPacket;
 ? ? ? ?pkt += NetSetEther(pkt, mac, PROT_IP);
 
- ? ? ? ip = (volatile IP_t *)pkt;
+ ? ? ? ip = (IP_t *)pkt;
 

? ? ? ?/*
? ? ? ? * Construct an IP and ICMP header.

net/net.c +3 -3
@@ -935,9 +935,9 @@ static ushort CDP_compute_csum(const uchar *buff, ushort len)
 
 ?int CDPSendTrigger(void)
 ?{
- ? ? ? volatile uchar *pkt;
- ? ? ? volatile ushort *s;
- ? ? ? volatile ushort *cp;
+ ? ? ? uchar *pkt;
+ ? ? ? ushort *s;
+ ? ? ? ushort *cp;
 ? ? ? ?Ethernet_t *et;
 ? ? ? ?int len;
 ? ? ? ?ushort chksum;
@@ -964,7 +964,7 @@ int CDPSendTrigger(void)

? ? ? ?/* CDP header */
? ? ? ?*pkt++ = 0x02; ? ? ? ? ? ? ? ? ? ? ? ? ?/* CDP version 2 */ ? ? ? ?*pkt++ = 180; ? ? ? ? ? ? ? ? ? ? ? ? ? /* TTL */
- ? ? ? s = (volatile ushort *)pkt;
+ ? ? ? s = (ushort *)pkt;
? ? ? ?cp = s;
? ? ? ?/* checksum (0 for later calculation) */
? ? ? ?*s++ = htons(0);

net/net.c NetReceive(volatile uchar *inpkt, int len) · line 1459

Quoted 8 lines
net/net.c +2 -2
@@ -1454,9 +1454,9 @@ NetReceive(volatile uchar *inpkt, int len)
 
 ? ? ? ?debug("packet received\n");
 
- ? ? ? NetRxPacket = inpkt;
+ ? ? ? NetRxPacket = (uchar *)inpkt;
 ? ? ? ?NetRxPacketLen = len;
- ? ? ? et = (Ethernet_t *)inpkt;
+ ? ? ? et = (Ethernet_t *)NetRxPacket;

Why change this?

Quoted 9 lines

? ? ? ?/* too small packet? */
? ? ? ?if (len < ETHER_HDR_SIZE)

net/net.c +0 -0
@@ -1491,11 +1491,11 @@ NetReceive(volatile uchar *inpkt, int len)

? ? ? ? ? ? ? ? */
? ? ? ? ? ? ? ?x = ntohs(et->et_prot);

- ? ? ? ? ? ? ? ip = (IP_t *)(inpkt + E802_HDR_SIZE);
+ ? ? ? ? ? ? ? ip = (IP_t *)(NetRxPacket + E802_HDR_SIZE);

and these? You are using a global instead of the passed-in local.

Quoted 72 lines

? ? ? ? ? ? ? ?len -= E802_HDR_SIZE;

? ? ? ?} else if (x != PROT_VLAN) { ? ?/* normal packet */
- ? ? ? ? ? ? ? ip = (IP_t *)(inpkt + ETHER_HDR_SIZE);
+ ? ? ? ? ? ? ? ip = (IP_t *)(NetRxPacket + ETHER_HDR_SIZE);

? ? ? ? ? ? ? ?len -= ETHER_HDR_SIZE;

? ? ? ?} else { ? ? ? ? ? ? ? ? ? ? ? ?/* VLAN packet */

net/net.c +1 -1
@@ -1519,7 +1519,7 @@ NetReceive(volatile uchar *inpkt, int len)
 ? ? ? ? ? ? ? ?vlanid = cti & VLAN_IDMASK;
 ? ? ? ? ? ? ? ?x = ntohs(vet->vet_type);
 
- ? ? ? ? ? ? ? ip = (IP_t *)(inpkt + VLAN_ETHER_HDR_SIZE);
+ ? ? ? ? ? ? ? ip = (IP_t *)(NetRxPacket + VLAN_ETHER_HDR_SIZE);
 
 
 ? ? ? ? ? ? ? ?len -= VLAN_ETHER_HDR_SIZE;

? ? ? ?}

net/net.c +0 -0
@@ -1917,7 +1917,7 @@ NetEthHdrSize(void)
 ?}
 

?int

net/net.c +1 -1
-NetSetEther(volatile uchar *xet, uchar * addr, uint prot)
+NetSetEther(uchar *xet, uchar * addr, uint prot)

?{
? ? ? ?Ethernet_t *et = (Ethernet_t *)xet;
? ? ? ?ushort myvlanid;

net/net.c +0 -0
@@ -1942,7 +1942,7 @@ NetSetEther(volatile uchar *xet, uchar * addr, uint prot)
 ?}
 

?void

net/net.c +1 -1
-NetSetIP(volatile uchar *xip, IPaddr_t dest, int dport, int sport, int len)
+NetSetIP(uchar *xip, IPaddr_t dest, int dport, int sport, int len)

?{
? ? ? ?IP_t *ip = (IP_t *)xip;

net/rarp.c +1 -1
index 097f970..77d63e8 100644
@@ -71,7 +71,7 @@ void
 ?RarpRequest (void)
 ?{
 ? ? ? ?int i;
- ? ? ? volatile uchar *pkt;
+ ? ? ? uchar *pkt;
 ? ? ? ?ARP_t * rarp;
 
 ? ? ? ?printf("RARP broadcast %d\n", ++RarpTry);
net/tftp.c +3 -3
index 7aa3e23..e62f229 100644
@@ -310,9 +310,9 @@ static void
 ?TftpSend(void)
 ?{
 ? ? ? ?uchar *pkt;
- ? ? ? volatile uchar *xp;
- ? ? ? int ? ? ? ? ? ? len = 0;
- ? ? ? volatile ushort *s;
+ ? ? ? uchar *xp;
+ ? ? ? int len = 0;
+ ? ? ? ushort *s;
 

?#ifdef CONFIG_MCAST_TFTP
? ? ? ?/* Multicast TFTP.. non-MasterClients do not ACK data. */ --
1.6.0.2

Quoted 4 lines

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Regards,
Simon

#3 lore raw

PATCH 1/28 net: Remove volatile from all of net except the eth driver interface

Hi Simon,

Quoted 29 lines · Simon Glass

Hi Joe,

Quoted 8 lines · Joe Hershberger

The mv_eth driver should not redefine the net function definition

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---
?<snip>

Review NetReceive(volatile uchar *inpkt, int len) · line 1459

Quoted 8 lines
(quoted diff) +2 -2
@@ -1454,9 +1454,9 @@ NetReceive(volatile uchar *inpkt, int len)
 
 ? ? ? ?debug("packet received\n");
 
- ? ? ? NetRxPacket = inpkt;
+ ? ? ? NetRxPacket = (uchar *)inpkt;
 ? ? ? ?NetRxPacketLen = len;
- ? ? ? et = (Ethernet_t *)inpkt;
+ ? ? ? et = (Ethernet_t *)NetRxPacket;

Why change this?

Quoted 7 lines

? ? ? ?/* too small packet? */
? ? ? ?if (len < ETHER_HDR_SIZE)

(quoted diff) +0 -0
@@ -1491,11 +1491,11 @@ NetReceive(volatile uchar *inpkt, int len)

? ? ? ? ? ? ? ? */
? ? ? ? ? ? ? ?x = ntohs(et->et_prot);

Quoted 26 lines
Quoted 2 lines

- ? ? ? ? ? ? ? ip = (IP_t *)(inpkt + E802_HDR_SIZE);
+ ? ? ? ? ? ? ? ip = (IP_t *)(NetRxPacket + E802_HDR_SIZE);

and these? You are using a global instead of the passed-in local.

Quoted 21 lines

? ? ? ? ? ? ? ?len -= E802_HDR_SIZE;

? ? ? ?} else if (x != PROT_VLAN) { ? ?/* normal packet */
- ? ? ? ? ? ? ? ip = (IP_t *)(inpkt + ETHER_HDR_SIZE);
+ ? ? ? ? ? ? ? ip = (IP_t *)(NetRxPacket + ETHER_HDR_SIZE);

? ? ? ? ? ? ? ?len -= ETHER_HDR_SIZE;

? ? ? ?} else { ? ? ? ? ? ? ? ? ? ? ? ?/* VLAN packet */

(quoted diff) +1 -1
@@ -1519,7 +1519,7 @@ NetReceive(volatile uchar *inpkt, int len)
 ? ? ? ? ? ? ? ?vlanid = cti & VLAN_IDMASK;
 ? ? ? ? ? ? ? ?x = ntohs(vet->vet_type);
 
- ? ? ? ? ? ? ? ip = (IP_t *)(inpkt + VLAN_ETHER_HDR_SIZE);
+ ? ? ? ? ? ? ? ip = (IP_t *)(NetRxPacket + VLAN_ETHER_HDR_SIZE);
 
 
 ? ? ? ? ? ? ? ?len -= VLAN_ETHER_HDR_SIZE;

? ? ? ?}

This patch removes volatile from the NetRxPacket and all but 1 of the other places that inpkt was assigned. You will notice that the first assignment of inpkt to NetRxPacket casts away the volatile:

Quoted 4 lines

net/net.c NetReceive(volatile uchar *inpkt, int len) · line 1457

Quoted 4 lines
net/net.c +1 -1
@@ -1454,9 +1454,9 @@ NetReceive(volatile uchar *inpkt, int len)
<snip>
-       NetRxPacket = inpkt;
+       NetRxPacket = (uchar *)inpkt;

All the assignments that need a non-volatile pointer now use NetRxPacket instead of inpkt, since it is already assigned and and the same type minus volatile.

Best regards,
-Joe

#4 lore raw

PATCH 1/28 net: Remove volatile from all of net except the eth driver interface

Hi Joe,

Quoted 55 lines · Joe Hershberger

Hi Simon,

Quoted 52 lines · Simon Glass

Hi Joe,

Quoted 8 lines · Joe Hershberger

The mv_eth driver should not redefine the net function definition

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---
?<snip>

Review NetReceive(volatile uchar *inpkt, int len) · line 1459

Quoted 8 lines
(quoted diff) +2 -2
@@ -1454,9 +1454,9 @@ NetReceive(volatile uchar *inpkt, int len)
 
 ? ? ? ?debug("packet received\n");
 
- ? ? ? NetRxPacket = inpkt;
+ ? ? ? NetRxPacket = (uchar *)inpkt;
 ? ? ? ?NetRxPacketLen = len;
- ? ? ? et = (Ethernet_t *)inpkt;
+ ? ? ? et = (Ethernet_t *)NetRxPacket;

Why change this?

Quoted 9 lines

? ? ? ?/* too small packet? */
? ? ? ?if (len < ETHER_HDR_SIZE)

(quoted diff) +0 -0
@@ -1491,11 +1491,11 @@ NetReceive(volatile uchar *inpkt, int len)

? ? ? ? ? ? ? ? */
? ? ? ? ? ? ? ?x = ntohs(et->et_prot);

- ? ? ? ? ? ? ? ip = (IP_t *)(inpkt + E802_HDR_SIZE);
+ ? ? ? ? ? ? ? ip = (IP_t *)(NetRxPacket + E802_HDR_SIZE);

and these? You are using a global instead of the passed-in local.

Quoted 16 lines

? ? ? ? ? ? ? ?len -= E802_HDR_SIZE;

? ? ? ?} else if (x != PROT_VLAN) { ? ?/* normal packet */
- ? ? ? ? ? ? ? ip = (IP_t *)(inpkt + ETHER_HDR_SIZE);
+ ? ? ? ? ? ? ? ip = (IP_t *)(NetRxPacket + ETHER_HDR_SIZE);

? ? ? ? ? ? ? ?len -= ETHER_HDR_SIZE;

? ? ? ?} else { ? ? ? ? ? ? ? ? ? ? ? ?/* VLAN packet */

(quoted diff) +1 -1
@@ -1519,7 +1519,7 @@ NetReceive(volatile uchar *inpkt, int len)
 ? ? ? ? ? ? ? ?vlanid = cti & VLAN_IDMASK;
 ? ? ? ? ? ? ? ?x = ntohs(vet->vet_type);
 
- ? ? ? ? ? ? ? ip = (IP_t *)(inpkt + VLAN_ETHER_HDR_SIZE);
+ ? ? ? ? ? ? ? ip = (IP_t *)(NetRxPacket + VLAN_ETHER_HDR_SIZE);
Quoted 7 lines
Quoted 3 lines

Review NetReceive(volatile uchar *inpkt, int len) · line 1525

Quoted 3 lines
(quoted diff) +0 -0
 ? ? ? ? ? ? ? ?len -= VLAN_ETHER_HDR_SIZE;
 ? ? ? ?}
 

This patch removes volatile from the NetRxPacket and all but 1 of the other places that inpkt was assigned. ?You will notice that the first assignment of inpkt to NetRxPacket casts away the volatile:

Yes - I wonder why NetReceive needs to remain volatile?

Quoted 9 lines
Quoted 5 lines

Review NetReceive(volatile uchar *inpkt, int len)

Quoted 5 lines
(quoted diff) +1 -1
@@ -1454,9 +1454,9 @@ NetReceive(volatile uchar *inpkt, int len)
<snip>
- ? ? ? NetRxPacket = inpkt;
+ ? ? ? NetRxPacket = (uchar *)inpkt;

All the assignments that need a non-volatile pointer now use NetRxPacket instead of inpkt, since it is already assigned and and the same type minus volatile.

Yes, I am only sensitive to this because it is a global and there is enough use of globals in the net code already.

Quoted 3 lines

Best regards,
-Joe

Regards,
Simon

#5 lore raw

PATCH 1/28 net: Remove volatile from all of net except the eth driver interface

Hi Simon,

Quoted 63 lines · Simon Glass

Hi Joe,

Quoted 59 lines · Joe Hershberger

Hi Simon,

Quoted 55 lines · Simon Glass

Hi Joe,

Quoted 8 lines · Joe Hershberger

The mv_eth driver should not redefine the net function definition

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---
?<snip>

Review NetReceive(volatile uchar *inpkt, int len) · line 1459

Quoted 8 lines
(quoted diff) +2 -2
@@ -1454,9 +1454,9 @@ NetReceive(volatile uchar *inpkt, int len)
 
 ? ? ? ?debug("packet received\n");
 
- ? ? ? NetRxPacket = inpkt;
+ ? ? ? NetRxPacket = (uchar *)inpkt;
 ? ? ? ?NetRxPacketLen = len;
- ? ? ? et = (Ethernet_t *)inpkt;
+ ? ? ? et = (Ethernet_t *)NetRxPacket;

Why change this?

Quoted 9 lines

? ? ? ?/* too small packet? */
? ? ? ?if (len < ETHER_HDR_SIZE)

(quoted diff) +0 -0
@@ -1491,11 +1491,11 @@ NetReceive(volatile uchar *inpkt, int len)

? ? ? ? ? ? ? ? */
? ? ? ? ? ? ? ?x = ntohs(et->et_prot);

- ? ? ? ? ? ? ? ip = (IP_t *)(inpkt + E802_HDR_SIZE);
+ ? ? ? ? ? ? ? ip = (IP_t *)(NetRxPacket + E802_HDR_SIZE);

and these? You are using a global instead of the passed-in local.

Quoted 21 lines

? ? ? ? ? ? ? ?len -= E802_HDR_SIZE;

? ? ? ?} else if (x != PROT_VLAN) { ? ?/* normal packet */
- ? ? ? ? ? ? ? ip = (IP_t *)(inpkt + ETHER_HDR_SIZE);
+ ? ? ? ? ? ? ? ip = (IP_t *)(NetRxPacket + ETHER_HDR_SIZE);

? ? ? ? ? ? ? ?len -= ETHER_HDR_SIZE;

? ? ? ?} else { ? ? ? ? ? ? ? ? ? ? ? ?/* VLAN packet */

(quoted diff) +1 -1
@@ -1519,7 +1519,7 @@ NetReceive(volatile uchar *inpkt, int len)
 ? ? ? ? ? ? ? ?vlanid = cti & VLAN_IDMASK;
 ? ? ? ? ? ? ? ?x = ntohs(vet->vet_type);
 
- ? ? ? ? ? ? ? ip = (IP_t *)(inpkt + VLAN_ETHER_HDR_SIZE);
+ ? ? ? ? ? ? ? ip = (IP_t *)(NetRxPacket + VLAN_ETHER_HDR_SIZE);
 
 
 ? ? ? ? ? ? ? ?len -= VLAN_ETHER_HDR_SIZE;

? ? ? ?}

Quoted 5 lines
Quoted 3 lines

This patch removes volatile from the NetRxPacket and all but 1 of the other places that inpkt was assigned. ?You will notice that the first assignment of inpkt to NetRxPacket casts away the volatile:

Yes - I wonder why NetReceive needs to remain volatile?

It is called by all the Ethernet drivers with volatile buffer pointers. At this point, I decided to limit the changes to not include every Ethernet driver (have to split it somewhere).

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

Review NetReceive(volatile uchar *inpkt, int len)

Quoted 4 lines
(quoted diff) +1 -1
@@ -1454,9 +1454,9 @@ NetReceive(volatile uchar *inpkt, int len)
<snip>
- ? ? ? NetRxPacket = inpkt;
+ ? ? ? NetRxPacket = (uchar *)inpkt;

All the assignments that need a non-volatile pointer now use NetRxPacket instead of inpkt, since it is already assigned and and the same type minus volatile.

Yes, I am only sensitive to this because it is a global and there is enough use of globals in the net code already.

I chose to not add a local variable to hold the non-volatile pointer since there was already a global. Since u-boot is single threaded, this should not be a problem and could be easily changed later when the Ethernet driver interface is cleaned up.

Best regards,
-Joe

#6 lore raw

PATCH 1/28 net: Remove volatile from all of net except the eth driver interface

Quoted 13 lines · On Tuesday 24 January 2012 01:27:53 Joe Hershberger wrote:
Quoted 12 lines · Simon Glass
Quoted 10 lines · Joe Hershberger
Quoted 5 lines · Simon Glass

net/net.c NetReceive(volatile uchar *inpkt, int len) · line 1457

Quoted 4 lines · Joe Hershberger
net/net.c +1 -1
@@ -1454,9 +1454,9 @@ NetReceive(volatile uchar *inpkt, int len)
<snip>
-       NetRxPacket = inpkt;
+       NetRxPacket = (uchar *)inpkt;

All the assignments that need a non-volatile pointer now use NetRxPacket instead of inpkt, since it is already assigned and and the same type minus volatile.

Quoted 7 lines
Quoted 2 lines

Yes, I am only sensitive to this because it is a global and there is enough use of globals in the net code already.

I chose to not add a local variable to hold the non-volatile pointer since there was already a global. Since u-boot is single threaded, this should not be a problem and could be easily changed later when the Ethernet driver interface is cleaned up.

funcs given a ptr should operate on that ptr. relying on global variables is a step backwards imo.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/7f365f18/attachment.pgp>

#7 lore raw

PATCH 1/28 net: Remove volatile from all of net except the eth driver interface

In reply to Joe Hershberger

in general, i like this. my only concern would be the drivers that might break due to incorrect cache management (which the volatile markers happen to work around for them).

having the API accept a volatile but then casting it away puts us in a worse place i think. on one hand, our API is saying "we treat it as volatile" when we really don't, so any drivers that call it with a volatile don't get build warnings. i'd just drop it from all of the net API so that the drivers which do call with a volatile pointer get a build warning -- now the driver maintainer knows they have to at least look at something.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/5cf09c98/attachment.pgp>

#8 lore raw

PATCH 1/28 net: Remove volatile from all of net except the eth driver interface

Hi Mike,

Quoted 11 lines · Mike Frysinger

in general, i like this. ?my only concern would be the drivers that might break due to incorrect cache management (which the volatile markers happen to work around for them).

having the API accept a volatile but then casting it away puts us in a worse place i think. ?on one hand, our API is saying "we treat it as volatile" when we really don't, so any drivers that call it with a volatile don't get build warnings. ?i'd just drop it from all of the net API so that the drivers which do call with a volatile pointer get a build warning -- now the driver maintainer knows they have to at least look at something.
-mike

I'm fine with that... it was my first approach, in fact. However, I was concerned that if I submitted a patch that added warnings to every Ethernet-enabled board, that would be frowned upon. I think it is the correct thing to do, but don't have a good feeling for how open people are to changing an interface like that. I also did not want to attempt to revise every net driver in this series.

Wolfgang,

Would you approve of changing the net driver API to not use volatile buffer pointers and have the driver file warn until the driver maintainer addresses the warnings?

Thanks,
-Joe

#9 lore raw

PATCH 2/28 net: cosmetic: checkpatch compliance

In reply to Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 common/main.c            |    1 -
 drivers/net/netconsole.c |  122 +++++++++--------
 include/common.h         |    4 +
 include/net.h            |  123 +++++++++--------
 net/bootp.c              |  338 +++++++++++++++++++++++-----------------------
 net/bootp.h              |   56 ++++----
 net/eth.c                |   66 +++++-----
 net/net.c                |   19 +--
 net/nfs.c                |  300 ++++++++++++++++++++---------------------
 net/nfs.h                |    2 +-
 net/rarp.c               |   28 ++--
 net/rarp.h               |    4 +-
 net/sntp.c               |   31 +++--
 net/sntp.h               |    2 +-
 net/tftp.c               |   30 ++---
 net/tftp.h               |    2 +-
 16 files changed, 572 insertions(+), 556 deletions(-)
common/main.c +0 -1
index e96c95a..c514345 100644
@@ -979,7 +979,6 @@ int readline_into_buffer (const char *const prompt, char * buffer)
 
 #ifdef CONFIG_SHOW_ACTIVITY
 		while (!tstc()) {
-			extern void show_activity(int arg);
 			show_activity(0);
 			WATCHDOG_RESET();
 		}
drivers/net/netconsole.c +62 -60

258 lines not on this page · raw message

include/common.h +4 -0
index 3df1def..bd557bd 100644
@@ -804,6 +804,10 @@ int	pcmcia_init (void);
  */
 void show_boot_progress(int val);
 
+#ifdef CONFIG_SHOW_ACTIVITY
+void show_activity(int arg);
+#endif
+
 /* Multicore arch functions */
 #ifdef CONFIG_MP
 int cpu_status(int nr);
include/net.h +67 -56

268 lines not on this page · raw message

net/bootp.c +172 -166

758 lines not on this page · raw message

net/bootp.h +30 -26

88 lines not on this page · raw message

net/eth.c +32 -34

188 lines not on this page · raw message

net/net.c +6 -13
index 29e018c..1d6252f 100644
@@ -203,11 +203,6 @@ IPaddr_t	NetNtpServerIP;
 int		NetTimeOffset;
 #endif
 
-#ifdef CONFIG_NETCONSOLE
-void NcStart(void);
-int nc_input_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len);
-#endif
-
 uchar PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
 
 /* Receive packet */
@@ -526,10 +521,7 @@ restart:
 	for (;;) {
 		WATCHDOG_RESET();
 #ifdef CONFIG_SHOW_ACTIVITY
-		{
-			extern void show_activity(int arg);
-			show_activity(1);
-		}
+		show_activity(1);
 #endif
 		/*
 		 *	Check the ethernet for a new packet.  The ethernet
@@ -1102,8 +1094,8 @@ CDPHandler(const uchar *pkt, unsigned len)
 	 * output a warning
 	 */
 	if (pkt[0] != 0x02)
-		printf("** WARNING: CDP packet received with a protocol version %d > 2\n",
-				pkt[0] & 0xff);
+		printf("**WARNING: CDP packet received with a protocol version "
+				"%d > 2\n", pkt[0] & 0xff);
 
 	if (CDP_compute_csum(pkt, len) != 0)
 		return;
@@ -1610,6 +1602,7 @@ NetReceive(volatile uchar *inpkt, int len)
 			/* matched waiting packet's address */
 			if (tmp == NetArpWaitReplyIP) {
 				debug("Got it\n");
+
 				/* save address for later use */
 				memcpy(NetArpWaitPacketMAC,
 				       &arp->ar_data[0], 6);
@@ -1618,7 +1611,8 @@ NetReceive(volatile uchar *inpkt, int len)
 				(*packetHandler)(0, 0, 0, 0, 0);
 #endif
 				/* modify header, and transmit it */
-				memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, NetArpWaitPacketMAC, 6);
+				memcpy(((Ethernet_t *)NetArpWaitTxPacket)->
+					et_dest, NetArpWaitPacketMAC, 6);
 				(void) eth_send(NetArpWaitTxPacket,
 						NetArpWaitTxPacketSize);
 
@@ -1855,7 +1849,6 @@ common:
 	case CDP:
 	case DHCP:
 		if (memcmp(NetOurEther, "\0\0\0\0\0\0", 6) == 0) {
-			extern int eth_get_dev_index(void);
 			int num = eth_get_dev_index();
 
 			switch (num) {
net/nfs.c +149 -151

752 lines not on this page · raw message

net/nfs.h +1 -1
index de8a0c6..a5a1b43 100644
@@ -72,7 +72,7 @@ struct rpc_t {
 		} reply;
 	} u;
 };
-extern void	NfsStart (void);	/* Begin NFS */
+extern void NfsStart(void);	/* Begin NFS */
 
 
 /**********************************************************************/
net/rarp.c +14 -14
index 77d63e8..5a813a2 100644
@@ -58,21 +58,21 @@ static void
 RarpTimeout(void)
 {
 	if (RarpTry >= TIMEOUT_COUNT) {
-		puts ("\nRetry count exceeded; starting again\n");
-		NetStartAgain ();
+		puts("\nRetry count exceeded; starting again\n");
+		NetStartAgain();
 	} else {
-		NetSetTimeout (TIMEOUT, RarpTimeout);
-		RarpRequest ();
+		NetSetTimeout(TIMEOUT, RarpTimeout);
+		RarpRequest();
 	}
 }
 
 
 void
-RarpRequest (void)
+RarpRequest(void)
 {
 	int i;
 	uchar *pkt;
-	ARP_t *	rarp;
+	ARP_t *rarp;
 
 	printf("RARP broadcast %d\n", ++RarpTry);
 	pkt = NetTxPacket;
@@ -81,18 +81,18 @@ RarpRequest (void)
 
 	rarp = (ARP_t *)pkt;
 
-	rarp->ar_hrd = htons (ARP_ETHER);
-	rarp->ar_pro = htons (PROT_IP);
+	rarp->ar_hrd = htons(ARP_ETHER);
+	rarp->ar_pro = htons(PROT_IP);
 	rarp->ar_hln = 6;
 	rarp->ar_pln = 4;
-	rarp->ar_op  = htons (RARPOP_REQUEST);
-	memcpy (&rarp->ar_data[0],  NetOurEther, 6);	/* source ET addr */
-	memcpy (&rarp->ar_data[6],  &NetOurIP,   4);	/* source IP addr */
-	memcpy (&rarp->ar_data[10], NetOurEther, 6);	/* dest ET addr = source ET addr ??*/
+	rarp->ar_op  = htons(RARPOP_REQUEST);
+	memcpy(&rarp->ar_data[0],  NetOurEther, 6);	/* source ET addr */
+	memcpy(&rarp->ar_data[6],  &NetOurIP,   4);	/* source IP addr */
+	/* dest ET addr = source ET addr ??*/
+	memcpy(&rarp->ar_data[10], NetOurEther, 6);
 	/* dest. IP addr set to broadcast */
-	for (i = 0; i <= 3; i++) {
+	for (i = 0; i <= 3; i++)
 		rarp->ar_data[16 + i] = 0xff;
-	}
 
 	NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
 
net/rarp.h +2 -2
index 0c16d46..4e92d80 100644
@@ -35,9 +35,9 @@
  *	Global functions and variables.
  */
 
-extern int	RarpTry;
+extern int RarpTry;
 
-extern void RarpRequest (void);	/* Send a RARP request */
+extern void RarpRequest(void);	/* Send a RARP request */
 
 /**********************************************************************/
 
net/sntp.c +17 -14
index 82f2fe6..6dd0dbd 100644
@@ -17,7 +17,7 @@
 static int SntpOurPort;
 
 static void
-SntpSend (void)
+SntpSend(void)
 {
 	struct sntp_pkt_t pkt;
 	int pktlen = SNTP_PACKET_LEN;
@@ -25,24 +25,26 @@ SntpSend (void)
 
 	debug("%s\n", __func__);
 
-	memset (&pkt, 0, sizeof(pkt));
+	memset(&pkt, 0, sizeof(pkt));
 
 	pkt.li = NTP_LI_NOLEAP;
 	pkt.vn = NTP_VERSION;
 	pkt.mode = NTP_MODE_CLIENT;
 
-	memcpy ((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE, (char *)&pkt, pktlen);
+	memcpy((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE,
+		(char *)&pkt, pktlen);
 
 	SntpOurPort = 10000 + (get_timer(0) % 4096);
 	sport = NTP_SERVICE_PORT;
 
-	NetSendUDPPacket (NetServerEther, NetNtpServerIP, sport, SntpOurPort, pktlen);
+	NetSendUDPPacket(NetServerEther, NetNtpServerIP, sport, SntpOurPort,
+		pktlen);
 }
 
 static void
-SntpTimeout (void)
+SntpTimeout(void)
 {
-	puts ("Timeout\n");
+	puts("Timeout\n");
 	NetState = NETLOOP_FAIL;
 	return;
 }
@@ -57,19 +59,20 @@ SntpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 
 	debug("%s\n", __func__);
 
-	if (dest != SntpOurPort) return;
+	if (dest != SntpOurPort)
+		return;
 
 	/*
 	 * As the RTC's used in U-Boot sepport second resolution only
 	 * we simply ignore the sub-second field.
 	 */
-	memcpy (&seconds, &rpktp->transmit_timestamp, sizeof(ulong));
+	memcpy(&seconds, &rpktp->transmit_timestamp, sizeof(ulong));
 
 	to_tm(ntohl(seconds) - 2208988800UL + NetTimeOffset, &tm);
 #if defined(CONFIG_CMD_DATE)
-	rtc_set (&tm);
+	rtc_set(&tm);
 #endif
-	printf ("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n",
+	printf("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n",
 		tm.tm_year, tm.tm_mon, tm.tm_mday,
 		tm.tm_hour, tm.tm_min, tm.tm_sec);
 
@@ -77,13 +80,13 @@ SntpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 }
 
 void
-SntpStart (void)
+SntpStart(void)
 {
 	debug("%s\n", __func__);
 
-	NetSetTimeout (SNTP_TIMEOUT, SntpTimeout);
+	NetSetTimeout(SNTP_TIMEOUT, SntpTimeout);
 	NetSetHandler(SntpHandler);
-	memset (NetServerEther, 0, 6);
+	memset(NetServerEther, 0, 6);
 
-	SntpSend ();
+	SntpSend();
 }
net/sntp.h +1 -1
index 8a097bf..1d0046e 100644
@@ -56,6 +56,6 @@ struct sntp_pkt_t {
 	unsigned long long transmit_timestamp;
 };
 
-extern void	SntpStart (void);	/* Begin SNTP */
+extern void SntpStart(void);	/* Begin SNTP */
 
 #endif /* __SNTP_H__ */
net/tftp.c +14 -16
index e62f229..bc7fe05 100644
@@ -11,6 +11,9 @@
 #include <net.h>
 #include "tftp.h"
 #include "bootp.h"
+#ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
+#include <flash.h>
+#endif
 
 /* Well known TFTP port # */
 #define WELL_KNOWN_PORT	69
@@ -112,10 +115,6 @@ static char default_filename[DEFAULT_NAME_LEN];
 
 static char tftp_filename[MAX_LEN];
 
-#ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
-extern flash_info_t flash_info[];
-#endif
-
 /* 512 is poor choice for ethernet, MTU is typically 1500.
  * Minus eth.hdrs thats 1468.  Can get 2x better throughput with
  * almost-MTU block sizes.  At least try... fall back to 512 if need be.
@@ -137,7 +136,6 @@ static unsigned *Bitmap;
 static int PrevBitmapHole, Mapsize = MTFTP_BITMAPSIZE;
 static uchar ProhibitMcast, MasterClient;
 static uchar Multicast;
-extern IPaddr_t Mcast_addr;
 static int Mcast_port;
 static ulong TftpEndingBlock; /* can get 'last' block before done..*/
 
@@ -157,7 +155,7 @@ mcast_cleanup(void)
 
 #endif	/* CONFIG_MCAST_TFTP */
 
-static __inline__ void
+static inline void
 store_block(unsigned block, uchar *src, unsigned len)
 {
 	ulong offset = block * TftpBlkSize + TftpBlockWrapOffset;
@@ -182,8 +180,7 @@ store_block(unsigned block, uchar *src, unsigned len)
 			NetState = NETLOOP_FAIL;
 			return;
 		}
-	}
-	else
+	} else
 #endif /* CONFIG_SYS_DIRECT_FLASH_TFTP */
 	{
 		(void)memcpy((void *)(load_addr + offset), src, len);
@@ -357,12 +354,14 @@ TftpSend(void)
 				0, TftpBlkSizeOption, 0);
 #ifdef CONFIG_MCAST_TFTP
 		/* Check all preconditions before even trying the option */
-		if (!ProhibitMcast
-		 && (Bitmap = malloc(Mapsize))
-		 && eth_get_dev()->mcast) {
-			free(Bitmap);
-			Bitmap = NULL;
-			pkt += sprintf((char *)pkt, "multicast%c%c", 0, 0);
+		if (!ProhibitMcast) {
+			Bitmap = malloc(Mapsize);
+			if (Bitmap && eth_get_dev()->mcast) {
+				free(Bitmap);
+				Bitmap = NULL;
+				pkt += sprintf((char *)pkt, "multicast%c%c",
+					0, 0);
+			}
 		}
 #endif /* CONFIG_MCAST_TFTP */
 		len = pkt - xp;
@@ -630,8 +629,7 @@ TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 				mcast_cleanup();
 				NetState = NETLOOP_SUCCESS;
 			}
-		}
-		else
+		} else
 #endif
 		if (len < TftpBlkSize)
 			tftp_complete();
net/tftp.h +1 -1
index c51aa25..18e4c9c 100644
@@ -19,7 +19,7 @@
 void TftpStart(enum proto_t protocol);	/* Begin TFTP get/put */
 
 #ifdef CONFIG_CMD_TFTPSRV
-extern void	TftpStartServer(void);	/* Wait for incoming TFTP put */
+extern void TftpStartServer(void);	/* Wait for incoming TFTP put */
 #endif
 
 /**********************************************************************/
Signature · 1 line
1.6.0.2
#10 lore raw

PATCH 2/28 net: cosmetic: checkpatch compliance

Hi Joe,

Quoted 20 lines · Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

?common/main.c ? ? ? ? ? ?| ? ?1 -
?drivers/net/netconsole.c | ?122 +++++++++--------
?include/common.h ? ? ? ? | ? ?4 +
?include/net.h ? ? ? ? ? ?| ?123 +++++++++--------
?net/bootp.c ? ? ? ? ? ? ?| ?338 +++++++++++++++++++++++-----------------------
?net/bootp.h ? ? ? ? ? ? ?| ? 56 ++++----
?net/eth.c ? ? ? ? ? ? ? ?| ? 66 +++++-----
?net/net.c ? ? ? ? ? ? ? ?| ? 19 +--
?net/nfs.c ? ? ? ? ? ? ? ?| ?300 ++++++++++++++++++++---------------------
?net/nfs.h ? ? ? ? ? ? ? ?| ? ?2 +-
?net/rarp.c ? ? ? ? ? ? ? | ? 28 ++--
?net/rarp.h ? ? ? ? ? ? ? | ? ?4 +-
?net/sntp.c ? ? ? ? ? ? ? | ? 31 +++--
?net/sntp.h ? ? ? ? ? ? ? | ? ?2 +-
?net/tftp.c ? ? ? ? ? ? ? | ? 30 ++---
?net/tftp.h ? ? ? ? ? ? ? | ? ?2 +-
Quoted 2 lines

?16 files changed, 572 insertions(+), 556 deletions(-)

Others may fine with it, but it might be worth splitting this very long patch, perhaps split out some of the larger files or the show_activity() change.

Regards,
Simon

#11 lore raw

PATCH 2/28 net: cosmetic: checkpatch compliance

Hi Simon,

Quoted 26 lines · Simon Glass

Hi Joe,

Quoted 20 lines · Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

?common/main.c ? ? ? ? ? ?| ? ?1 -
?drivers/net/netconsole.c | ?122 +++++++++--------
?include/common.h ? ? ? ? | ? ?4 +
?include/net.h ? ? ? ? ? ?| ?123 +++++++++--------
?net/bootp.c ? ? ? ? ? ? ?| ?338 +++++++++++++++++++++++-----------------------
?net/bootp.h ? ? ? ? ? ? ?| ? 56 ++++----
?net/eth.c ? ? ? ? ? ? ? ?| ? 66 +++++-----
?net/net.c ? ? ? ? ? ? ? ?| ? 19 +--
?net/nfs.c ? ? ? ? ? ? ? ?| ?300 ++++++++++++++++++++---------------------
?net/nfs.h ? ? ? ? ? ? ? ?| ? ?2 +-
?net/rarp.c ? ? ? ? ? ? ? | ? 28 ++--
?net/rarp.h ? ? ? ? ? ? ? | ? ?4 +-
?net/sntp.c ? ? ? ? ? ? ? | ? 31 +++--
?net/sntp.h ? ? ? ? ? ? ? | ? ?2 +-
?net/tftp.c ? ? ? ? ? ? ? | ? 30 ++---
?net/tftp.h ? ? ? ? ? ? ? | ? ?2 +-
Quoted 2 lines

?16 files changed, 572 insertions(+), 556 deletions(-)

Quoted 3 lines

Others may fine with it, but it might be worth splitting this very long patch, perhaps split out some of the larger files or the show_activity() change.

I had this separated by file, but figured since the series was pretty long, it is all cosmetic (making separate patches not especially helpful), and it was under the 100kB mail limit that it would be better as a single patch. If it will be a barrier to review, I can split it up again.

Best regards,
-Joe

#12 lore raw

PATCH 2/28 net: cosmetic: checkpatch compliance

Hi Joe,

Quoted 33 lines · Joe Hershberger

Hi Simon,

Quoted 26 lines · Simon Glass

Hi Joe,

Quoted 20 lines · Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

?common/main.c ? ? ? ? ? ?| ? ?1 -
?drivers/net/netconsole.c | ?122 +++++++++--------
?include/common.h ? ? ? ? | ? ?4 +
?include/net.h ? ? ? ? ? ?| ?123 +++++++++--------
?net/bootp.c ? ? ? ? ? ? ?| ?338 +++++++++++++++++++++++-----------------------
?net/bootp.h ? ? ? ? ? ? ?| ? 56 ++++----
?net/eth.c ? ? ? ? ? ? ? ?| ? 66 +++++-----
?net/net.c ? ? ? ? ? ? ? ?| ? 19 +--
?net/nfs.c ? ? ? ? ? ? ? ?| ?300 ++++++++++++++++++++---------------------
?net/nfs.h ? ? ? ? ? ? ? ?| ? ?2 +-
?net/rarp.c ? ? ? ? ? ? ? | ? 28 ++--
?net/rarp.h ? ? ? ? ? ? ? | ? ?4 +-
?net/sntp.c ? ? ? ? ? ? ? | ? 31 +++--
?net/sntp.h ? ? ? ? ? ? ? | ? ?2 +-
?net/tftp.c ? ? ? ? ? ? ? | ? 30 ++---
?net/tftp.h ? ? ? ? ? ? ? | ? ?2 +-
Quoted 2 lines

?16 files changed, 572 insertions(+), 556 deletions(-)

Quoted 3 lines

Others may fine with it, but it might be worth splitting this very long patch, perhaps split out some of the larger files or the show_activity() change.

Quoted 5 lines

I had this separated by file, but figured since the series was pretty long, it is all cosmetic (making separate patches not especially helpful), and it was under the 100kB mail limit that it would be better as a single patch. ?If it will be a barrier to review, I can split it up again.

I'm not sure if it is a barrier to review or not, but I did nod off about 15% through :-)

Regards,
Simon

Quoted 3 lines

Best regards,
-Joe

#13 lore raw

PATCH 2/28 net: cosmetic: checkpatch compliance

In reply to Joe Hershberger
Quoted 4 lines · Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

Hi Joe,

as far as I understand this patch has nothing to do with the main feature (link-local addressing). Maybe is it worth to remove it from this patchset and send it in a separate patch ?

I see the patch address only code styling, but it is quite long for a review. IMHO it is better to have a separate patchset for this.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#14 lore raw

PATCH 2/28 net: cosmetic: checkpatch compliance

In reply to Joe Hershberger

i hope you ran a script on this and didn't do it by hand :). can you post the commands that you ran ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/8fd183a5/attachment.pgp>

#15 lore raw

PATCH 3/28 net: Move mv64x6x_eth_initialize() to board_eth_init()

In reply to Joe Hershberger

Clears up checkpatch.pl complaint about extern in c file Completes the effort started by Ben Warren in 2008 to generalize eth init

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 board/Marvell/db64360/db64360.c |   12 ++++++-
 board/Marvell/db64360/mv_eth.c  |   76 +++++++++++++++++++++++++++++++++++----
 board/Marvell/db64360/mv_eth.h  |   63 +-------------------------------
 board/Marvell/db64460/db64460.c |   12 ++++++-
 board/Marvell/db64460/mv_eth.c  |   76 +++++++++++++++++++++++++++++++++++----
 board/Marvell/db64460/mv_eth.h  |   63 +-------------------------------
 board/esd/cpci750/cpci750.c     |    6 +++
 board/esd/cpci750/mv_eth.c      |   76 +++++++++++++++++++++++++++++++++++----
 board/esd/cpci750/mv_eth.h      |   63 +-------------------------------
 board/prodrive/p3mx/mv_eth.c    |   76 +++++++++++++++++++++++++++++++++++----
 board/prodrive/p3mx/mv_eth.h    |   63 +-------------------------------
 board/prodrive/p3mx/p3mx.c      |    6 +++
 net/eth.c                       |    9 -----
 13 files changed, 314 insertions(+), 287 deletions(-)
board/Marvell/db64360/db64360.c +11 -1
index 5183466..c66dc14 100644
@@ -40,6 +40,7 @@
 #include "mpsc.h"
 #include "i2c.h"
 #include "64360.h"
+#include "mv_eth.h"
 #include "mv_regs.h"
 
 #undef	DEBUG
@@ -934,5 +935,14 @@ void board_prebootm_init ()
 
 int board_eth_init(bd_t *bis)
 {
-	return pci_eth_init(bis);
+	int pci_retval;
+	int mv_retval;
+
+	pci_retval = pci_eth_init(bis);
+	mv_retval = mv6436x_eth_initialize(bis);
+
+	if (pci_retval < 0 && mv_retval < 0)
+		return -1;
+	else
+		return 0;
 }
board/Marvell/db64360/mv_eth.c +69 -7

130 lines not on this page · raw message

board/Marvell/db64360/mv_eth.h +1 -62

73 lines not on this page · raw message

board/Marvell/db64460/db64460.c +11 -1
index a7836ed..de201b5 100644
@@ -40,6 +40,7 @@
 #include "mpsc.h"
 #include "i2c.h"
 #include "64460.h"
+#include "mv_eth.h"
 #include "mv_regs.h"
 
 #undef	DEBUG
@@ -934,5 +935,14 @@ void board_prebootm_init ()
 
 int board_eth_init(bd_t *bis)
 {
-	return pci_eth_init(bis);
+	int pci_retval;
+	int mv_retval;
+
+	pci_retval = pci_eth_init(bis);
+	mv_retval = mv6446x_eth_initialize(bis);
+
+	if (pci_retval < 0 && mv_retval < 0)
+		return -1;
+	else
+		return 0;
 }
board/Marvell/db64460/mv_eth.c +69 -7

130 lines not on this page · raw message

board/Marvell/db64460/mv_eth.h +1 -62

73 lines not on this page · raw message

board/esd/cpci750/cpci750.c +6 -0
index 08311c9..904eff7 100644
@@ -40,6 +40,7 @@
 #include "mpsc.h"
 #include "i2c.h"
 #include "64360.h"
+#include "mv_eth.h"
 #include "mv_regs.h"
 
 #undef	DEBUG
@@ -148,6 +149,11 @@ int board_video_skip(void)
 	return CPCI750_SLAVE_TEST;
 }
 
+int board_eth_init(bd_t *bis)
+{
+	return mv6436x_eth_initialize(bis);
+}
+
 /* ------------------------------------------------------------------------- */
 
 /*
board/esd/cpci750/mv_eth.c +69 -7

130 lines not on this page · raw message

board/esd/cpci750/mv_eth.h +1 -62

73 lines not on this page · raw message

board/prodrive/p3mx/mv_eth.c +69 -7

130 lines not on this page · raw message

board/prodrive/p3mx/mv_eth.h +1 -62

73 lines not on this page · raw message

board/prodrive/p3mx/p3mx.c +6 -0
index 09e4f82..31c7869 100644
@@ -44,6 +44,7 @@
 #include "eth.h"
 #include "mpsc.h"
 #include "64460.h"
+#include "mv_eth.h"
 #include "mv_regs.h"
 #include "p3mx.h"
 
@@ -82,6 +83,11 @@ void set_led(int);
 
 /* ------------------------------------------------------------------------- */
 
+int board_eth_init(bd_t *bis)
+{
+	return mv6446x_eth_initialize(bis);
+}
+
 /*
  * This is a version of the GT register space remapping function that
  * doesn't touch globals (meaning, it's ok to run from flash.)
net/eth.c +0 -9
index 02ccc75..fdc9e22 100644
@@ -81,9 +81,6 @@ static int __def_eth_init(bd_t *bis)
 int cpu_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
 int board_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
 
-extern int mv6436x_eth_initialize(bd_t *);
-extern int mv6446x_eth_initialize(bd_t *);
-
 #ifdef CONFIG_API
 extern void (*push_packet)(volatile void *, int);
 
@@ -251,12 +248,6 @@ int eth_initialize(bd_t *bis)
 	} else
 		printf("Net Initialization Skipped\n");
 
-#if defined(CONFIG_DB64360) || defined(CONFIG_CPCI750)
-	mv6436x_eth_initialize(bis);
-#endif
-#if defined(CONFIG_DB64460) || defined(CONFIG_P3Mx)
-	mv6446x_eth_initialize(bis);
-#endif
 	if (!eth_devices) {
 		puts("No ethernet found.\n");
 		show_boot_progress(-64);
Signature · 1 line
1.6.0.2
#16 lore raw

PATCH 3/28 net: Move mv64x6x_eth_initialize() to board_eth_init()

Quoted 3 lines · On Thursday 19 January 2012 19:53:06 Joe Hershberger wrote:

Clears up checkpatch.pl complaint about extern in c file Completes the effort started by Ben Warren in 2008 to generalize eth init

awesome. these boards have been around "forever", so if Stefan doesn't have any feedback, i'm good to merge it.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/7f22ff8e/attachment.pgp>

#17 lore raw

PATCH 3/28 net: Move mv64x6x_eth_initialize() to board_eth_init()

Quoted 7 lines · On Friday 03 February 2012 12:49:12 Mike Frysinger wrote:
Quoted 3 lines · On Thursday 19 January 2012 19:53:06 Joe Hershberger wrote:

Clears up checkpatch.pl complaint about extern in c file Completes the effort started by Ben Warren in 2008 to generalize eth init

awesome. these boards have been around "forever", so if Stefan doesn't have any feedback, i'm good to merge it.

I have no objections. I didn't even remember being maintainer of these PowerPC 750/7448 based boards. It might be possible to drop support for those completely.

But never the less:

Thanks,
Stefan

#18 lore raw

PATCH 4/28 net: Make the MAC-seeded random number generator available to /net

In reply to Joe Hershberger

MAC-seeded rand() will be needed by link-local as well, so give it an interface

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 net/Makefile   |    1 +
 net/bootp.c    |   69 +++++++++++--------------------------------------------
 net/bootp.h    |    3 --
 net/net_rand.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/net_rand.h |   18 ++++++++++++++
 5 files changed, 101 insertions(+), 58 deletions(-)
 create mode 100644 net/net_rand.c
 create mode 100644 net/net_rand.h
net/Makefile +1 -0
index 0544f6b..5901046 100644
@@ -31,6 +31,7 @@ COBJS-$(CONFIG_CMD_NET)  += bootp.o
 COBJS-$(CONFIG_CMD_DNS)  += dns.o
 COBJS-$(CONFIG_CMD_NET)  += eth.o
 COBJS-$(CONFIG_CMD_NET)  += net.o
+COBJS-$(CONFIG_BOOTP_RANDOM_DELAY) += net_rand.o
 COBJS-$(CONFIG_CMD_NFS)  += nfs.o
 COBJS-$(CONFIG_CMD_RARP) += rarp.o
 COBJS-$(CONFIG_CMD_SNTP) += sntp.o
net/bootp.c +14 -55

95 lines not on this page · raw message

net/bootp.h +0 -3
index ce73734..bf4e875 100644
@@ -63,9 +63,6 @@ struct Bootp_t {
 extern ulong	BootpID;		/* ID of cur BOOTP request	*/
 extern char	BootFile[128];		/* Boot file name		*/
 extern int	BootpTry;
-#ifdef CONFIG_BOOTP_RANDOM_DELAY
-extern ulong	seed1, seed2;		/* seed for random BOOTP delay	*/
-#endif
 
 
 /* Send a BOOTP request */
net/net_rand.c new file +68 -0

68 lines not on this page · raw message

net/net_rand.h new file +18 -0
new file mode 100644
index 0000000..2c6a6ac
@@ -0,0 +1,18 @@
+/*
+ *	Copied from LiMon - BOOTP.
+ *
+ *	Copyright 1994, 1995, 2000 Neil Russell.
+ *	(See License)
+ *	Copyright 2000 Paolo Scaffardi
+ */
+
+#ifndef __NET_RAND_H__
+#define __NET_RAND_H__
+
+#define RAND_MAX 0xFFFFFFFF
+
+void srand_mac(void);
+unsigned long rand(void);
+
+#endif /* __NET_RAND_H__ */
+
Signature · 1 line
1.6.0.2
#19 lore raw

PATCH 4/28 net: Make the MAC-seeded random number generator available to /net

Hi Joe,

Quoted 4 lines · Joe Hershberger

MAC-seeded rand() will be needed by link-local as well, so give it an interface

Quoted 245 lines
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

?net/Makefile ? | ? ?1 +
?net/bootp.c ? ?| ? 69 +++++++++++--------------------------------------------
?net/bootp.h ? ?| ? ?3 --
?net/net_rand.c | ? 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
?net/net_rand.h | ? 18 ++++++++++++++

?5 files changed, 101 insertions(+), 58 deletions(-) ?create mode 100644 net/net_rand.c
?create mode 100644 net/net_rand.h

net/Makefile +0 -0
index 0544f6b..5901046 100644
@@ -31,6 +31,7 @@ COBJS-$(CONFIG_CMD_NET) ?+= bootp.o

?COBJS-$(CONFIG_CMD_DNS) ?+= dns.o ?COBJS-$(CONFIG_CMD_NET) ?+= eth.o ?COBJS-$(CONFIG_CMD_NET) ?+= net.o +COBJS-$(CONFIG_BOOTP_RANDOM_DELAY) += net_rand.o ?COBJS-$(CONFIG_CMD_NFS) ?+= nfs.o ?COBJS-$(CONFIG_CMD_RARP) += rarp.o ?COBJS-$(CONFIG_CMD_SNTP) += sntp.o

net/bootp.c +0 -0
index 07870d0..9824cd1 100644
@@ -12,6 +12,9 @@

?#include <command.h>
?#include <net.h>
?#include "bootp.h"

net/bootp.c +3 -0
+#ifdef CONFIG_BOOTP_RANDOM_DELAY
+#include "net_rand.h"
+#endif

?#include "tftp.h"
?#include "nfs.h"
?#ifdef CONFIG_STATUS_LED

net/bootp.c +3 -3
@@ -37,9 +40,6 @@
 
 ?ulong ? ? ? ? ?BootpID;
 ?int ? ? ? ? ? ?BootpTry;
-#ifdef CONFIG_BOOTP_RANDOM_DELAY
-ulong ? ? ? ? ?seed1, seed2;
-#endif
 
 ?#if defined(CONFIG_CMD_DHCP)
 ?dhcp_state_t dhcp_state = INIT;
@@ -583,66 +583,25 @@ BootpRequest(void)
 ? ? ? ?uchar *pkt, *iphdr;
 ? ? ? ?struct Bootp_t *bp;
 ? ? ? ?int ext_len, pktlen, iplen;
+#ifdef CONFIG_BOOTP_RANDOM_DELAY
+ ? ? ? ulong i, rand_ms;
+#endif
 
 ?#if defined(CONFIG_CMD_DHCP)
 ? ? ? ?dhcp_state = INIT;

?#endif

?#ifdef CONFIG_BOOTP_RANDOM_DELAY ? ? ? ? ? ? ? /* Random BOOTP delay */
- ? ? ? unsigned char bi_enetaddr[6];
- ? ? ? int ? reg;
- ? ? ? ulong tst1, tst2, sum, m_mask, m_value = 0;

net/bootp.c +8 -49
-
- ? ? ? if (BootpTry == 0) {
- ? ? ? ? ? ? ? /* get our mac */
- ? ? ? ? ? ? ? eth_getenv_enetaddr("ethaddr", bi_enetaddr);
-
- ? ? ? ? ? ? ? debug("BootpRequest => Our Mac: ");
- ? ? ? ? ? ? ? for (reg = 0; reg < 6; reg++)
- ? ? ? ? ? ? ? ? ? ? ? debug("%x%c", bi_enetaddr[reg], reg == 5 ? '\n' : ':');
-
- ? ? ? ? ? ? ? /* Mac-Manipulation 2 get seed1 */
- ? ? ? ? ? ? ? tst1 = 0;
- ? ? ? ? ? ? ? tst2 = 0;
- ? ? ? ? ? ? ? for (reg = 2; reg < 6; reg++) {
- ? ? ? ? ? ? ? ? ? ? ? tst1 = tst1 << 8;
- ? ? ? ? ? ? ? ? ? ? ? tst1 = tst1 | bi_enetaddr[reg];
- ? ? ? ? ? ? ? }
- ? ? ? ? ? ? ? for (reg = 0; reg < 2; reg++) {
- ? ? ? ? ? ? ? ? ? ? ? tst2 = tst2 | bi_enetaddr[reg];
- ? ? ? ? ? ? ? ? ? ? ? tst2 = tst2 << 8;
- ? ? ? ? ? ? ? }
-
- ? ? ? ? ? ? ? seed1 = tst1^tst2;
+ ? ? ? if (BootpTry == 0)
+ ? ? ? ? ? ? ? srand_mac();
 
- ? ? ? ? ? ? ? /* Mirror seed1*/
- ? ? ? ? ? ? ? m_mask = 0x1;
- ? ? ? ? ? ? ? for (reg = 1; reg <= 32; reg++) {
- ? ? ? ? ? ? ? ? ? ? ? m_value |= (m_mask & seed1);
- ? ? ? ? ? ? ? ? ? ? ? seed1 = seed1 >> 1;
- ? ? ? ? ? ? ? ? ? ? ? m_value = m_value << 1;
- ? ? ? ? ? ? ? }
- ? ? ? ? ? ? ? seed1 = m_value;
- ? ? ? ? ? ? ? seed2 = 0xB78D0945;
- ? ? ? }
-
- ? ? ? /* Random Number Generator */
- ? ? ? for (reg = 0; reg <= 0; reg++) {
- ? ? ? ? ? ? ? sum = seed1 + seed2;
- ? ? ? ? ? ? ? if (sum < seed1 || sum < seed2)
- ? ? ? ? ? ? ? ? ? ? ? sum++;
- ? ? ? ? ? ? ? seed2 = seed1;
- ? ? ? ? ? ? ? seed1 = sum;
-
- ? ? ? ? ? ? ? if (BootpTry <= 2) { ? ?/* Start with max 1024 * 1ms */
- ? ? ? ? ? ? ? ? ? ? ? sum = sum >> (22-BootpTry);
- ? ? ? ? ? ? ? } else { ? ? ? ?/*After 3rd BOOTP request max 8192 * 1ms */
- ? ? ? ? ? ? ? ? ? ? ? sum = sum >> 19;
- ? ? ? ? ? ? ? }
- ? ? ? }
+ ? ? ? if (BootpTry <= 2) ? ? ?/* Start with max 1024 * 1ms */
+ ? ? ? ? ? ? ? rand_ms = rand() >> (22-BootpTry);
+ ? ? ? else ? ? ? ? ? ?/* After 3rd BOOTP request max 8192 * 1ms */
+ ? ? ? ? ? ? ? rand_ms = rand() >> 19;
 
- ? ? ? printf("Random delay: %ld ms...\n", sum);
- ? ? ? for (reg = 0; reg < sum; reg++)
+ ? ? ? printf("Random delay: %ld ms...\n", rand_ms);
+ ? ? ? for (i = 0; i < rand_ms; i++)

? ? ? ? ? ? ? ?udelay(1000); /*Wait 1ms*/

?#endif /* CONFIG_BOOTP_RANDOM_DELAY */

net/bootp.h +0 -0
index ce73734..bf4e875 100644
@@ -63,9 +63,6 @@ struct Bootp_t {

?extern ulong ? BootpID; ? ? ? ? ? ? ? ?/* ID of cur BOOTP request ? ? ?*/ ?extern char ? ?BootFile[128]; ? ? ? ? ?/* Boot file name ? ? ? ? ? ? ? */ ?extern int ? ? BootpTry;

net/bootp.h +0 -3
-#ifdef CONFIG_BOOTP_RANDOM_DELAY
-extern ulong ? seed1, seed2; ? ? ? ? ? /* seed for random BOOTP delay ?*/
-#endif

?/* Send a BOOTP request */

net/net_rand.c new file +68 -0
new file mode 100644
index 0000000..744e2f9
@@ -0,0 +1,68 @@
+/*
+ * ? ? Based on LiMon - BOOTP.
+ *
+ * ? ? Copyright 1994, 1995, 2000 Neil Russell.
+ * ? ? (See License)
+ * ? ? Copyright 2000 Roland Borde
+ * ? ? Copyright 2000 Paolo Scaffardi
+ * ? ? Copyright 2000-2004 Wolfgang Denk, wd at denx.de
+ */
+
+#include <common.h>
+#include <net.h>
+#include "net_rand.h"
+
+static ulong seed1, seed2;
+
+void srand_mac(void)
+{
+ ? ? ? ulong tst1, tst2, m_mask;
+ ? ? ? ulong m_value = 0;
+ ? ? ? int reg;
+ ? ? ? unsigned char bi_enetaddr[6];
+
+ ? ? ? /* get our mac */
+ ? ? ? eth_getenv_enetaddr("ethaddr", bi_enetaddr);
+
+ ? ? ? debug("BootpRequest => Our Mac: ");
+ ? ? ? for (reg = 0; reg < 6; reg++)
+ ? ? ? ? ? ? ? debug("%x%c", bi_enetaddr[reg], reg == 5 ? '\n' : ':');
+
+ ? ? ? /* Mac-Manipulation 2 get seed1 */
+ ? ? ? tst1 = 0;
+ ? ? ? tst2 = 0;
+ ? ? ? for (reg = 2; reg < 6; reg++) {
+ ? ? ? ? ? ? ? tst1 = tst1 << 8;
+ ? ? ? ? ? ? ? tst1 = tst1 | bi_enetaddr[reg];
+ ? ? ? }
+ ? ? ? for (reg = 0; reg < 2; reg++) {
+ ? ? ? ? ? ? ? tst2 = tst2 | bi_enetaddr[reg];
+ ? ? ? ? ? ? ? tst2 = tst2 << 8;
+ ? ? ? }
+
+ ? ? ? seed1 = tst1^tst2;
+
+ ? ? ? /* Mirror seed1*/
+ ? ? ? m_mask = 0x1;
+ ? ? ? for (reg = 1; reg <= 32; reg++) {
+ ? ? ? ? ? ? ? m_value |= (m_mask & seed1);
+ ? ? ? ? ? ? ? seed1 = seed1 >> 1;
+ ? ? ? ? ? ? ? m_value = m_value << 1;
+ ? ? ? }
+ ? ? ? seed1 = m_value;
+ ? ? ? seed2 = 0xB78D0945;
+}
+
+unsigned long rand(void)
+{
+ ? ? ? ulong sum;
+
+ ? ? ? /* Random Number Generator */
+ ? ? ? sum = seed1 + seed2;
+ ? ? ? if (sum < seed1 || sum < seed2)
+ ? ? ? ? ? ? ? sum++;
+ ? ? ? seed2 = seed1;
+ ? ? ? seed1 = sum;
+
+ ? ? ? return sum;
+}
net/net_rand.h new file +18 -1
new file mode 100644
index 0000000..2c6a6ac
@@ -0,0 +1,18 @@
+/*
+ * ? ? Copied from LiMon - BOOTP.
+ *
+ * ? ? Copyright 1994, 1995, 2000 Neil Russell.
+ * ? ? (See License)
+ * ? ? Copyright 2000 Paolo Scaffardi
+ */
+
+#ifndef __NET_RAND_H__
+#define __NET_RAND_H__
+
+#define RAND_MAX 0xFFFFFFFF
+
+void srand_mac(void);
+unsigned long rand(void);
+
+#endif /* __NET_RAND_H__ */
+
--

1.6.0.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#20 lore raw

PATCH 4/28 net: Make the MAC-seeded random number generator available to /net

In reply to Joe Hershberger

net/bootp.c line 17

Quoted 6 lines · On Thursday 19 January 2012 19:53:07 Joe Hershberger wrote:
net/bootp.c +3 -0
 
+#ifdef CONFIG_BOOTP_RANDOM_DELAY
+#include "net_rand.h"
+#endif

let's push this CONFIG_xxx check into net_rand.h so we don't have to check it every time we include the file
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/2db1c6c6/attachment.pgp>

#21 lore raw

PATCH 4/28 net: Make the MAC-seeded random number generator available to /net

Hi Mike,

Quoted 10 lines · Mike Frysinger

net/bootp.c line 17

Quoted 6 lines · On Thursday 19 January 2012 19:53:07 Joe Hershberger wrote:
net/bootp.c +3 -0
 
+#ifdef CONFIG_BOOTP_RANDOM_DELAY
+#include "net_rand.h"
+#endif

let's push this CONFIG_xxx check into net_rand.h so we don't have to check it every time we include the file

In this case, it doesn't make sense. The rand is enabled based on other features that need it... it does not have a config of its own. As a result, putting this in the header would make it worse. This guard is still needed in bootp.c, since rand is only needed when that subfeature is enabled. For link-local, it will always be included.

-Joe

#22 lore raw

PATCH 4/28 net: Make the MAC-seeded random number generator available to /net

Quoted 12 lines · On Friday 10 February 2012 16:51:00 Joe Hershberger wrote:
Quoted 10 lines · Mike Frysinger

net/bootp.c line 17

Quoted 6 lines · On Thursday 19 January 2012 19:53:07 Joe Hershberger wrote:
net/bootp.c +3 -0
 
+#ifdef CONFIG_BOOTP_RANDOM_DELAY
+#include "net_rand.h"
+#endif

let's push this CONFIG_xxx check into net_rand.h so we don't have to check it every time we include the file

Quoted 5 lines

In this case, it doesn't make sense. The rand is enabled based on other features that need it... it does not have a config of its own. As a result, putting this in the header would make it worse. This guard is still needed in bootp.c, since rand is only needed when that subfeature is enabled. For link-local, it will always be included.

i'm not sure guarding the include really gains us anything. i'm inclined to just always include it and be done.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120214/e9f5a107/attachment.pgp>

#23 lore raw

PATCH 5/28 net: Move CDP out of net.c

In reply to Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 arch/powerpc/cpu/mpc8xx/fec.c |    2 +-
 include/net.h                 |    9 +-
 net/Makefile                  |    1 +
 net/cdp.c                     |  380 +++++++++++++++++++++++++++++++++++++++++
 net/cdp.h                     |   18 ++
 net/net.c                     |  368 +---------------------------------------
 6 files changed, 406 insertions(+), 372 deletions(-)
 create mode 100644 net/cdp.c
 create mode 100644 net/cdp.h
arch/powerpc/cpu/mpc8xx/fec.c +1 -1
index f2a2c3a..0bc1e5d 100644
@@ -274,7 +274,7 @@ static int fec_recv (struct eth_device *dev)
 #if defined(CONFIG_CMD_CDP)
 			if ((rx[0] & 1) != 0
 			    && memcmp ((uchar *) rx, NetBcastAddr, 6) != 0
-			    && memcmp ((uchar *) rx, NetCDPAddr, 6) != 0)
+			    && !is_cdp_packet((uchar *)rx))
 				rx = NULL;
 #endif
 			/*
include/net.h +3 -6
index 09d1b51..0396b69 100644
@@ -355,10 +355,6 @@ extern uchar		NetEtherNullAddr[6];
 extern ushort		NetOurVLAN;		/* Our VLAN */
 extern ushort		NetOurNativeVLAN;	/* Our Native VLAN */
 
-extern uchar	NetCDPAddr[6];		/* Ethernet CDP address */
-extern ushort	CDPNativeVLAN;		/* CDP returned native VLAN */
-extern ushort	CDPApplianceVLAN;	/* CDP returned appliance VLAN */
-
 extern int		NetState;		/* Network loop state */
 #define NETLOOP_CONTINUE	1
 #define NETLOOP_RESTART		2
@@ -386,8 +382,9 @@ extern IPaddr_t	NetPingIP;			/* the ip address to ping */
 
 #if defined(CONFIG_CMD_CDP)
 /* when CDP completes these hold the return values */
-extern ushort CDPNativeVLAN;
-extern ushort CDPApplianceVLAN;
+extern ushort CDPNativeVLAN;		/* CDP returned native VLAN */
+extern ushort CDPApplianceVLAN;		/* CDP returned appliance VLAN */
+int is_cdp_packet(const uchar *et_addr);
 #endif
 
 #if defined(CONFIG_CMD_SNTP)
net/Makefile +1 -0
index 5901046..b350bfc 100644
@@ -28,6 +28,7 @@ include $(TOPDIR)/config.mk
 LIB	= $(obj)libnet.o
 
 COBJS-$(CONFIG_CMD_NET)  += bootp.o
+COBJS-$(CONFIG_CMD_CDP)  += cdp.o
 COBJS-$(CONFIG_CMD_DNS)  += dns.o
 COBJS-$(CONFIG_CMD_NET)  += eth.o
 COBJS-$(CONFIG_CMD_NET)  += net.o
net/cdp.c new file +380 -0

380 lines not on this page · raw message

net/cdp.h new file +18 -0
new file mode 100644
index 0000000..fef744e
@@ -0,0 +1,18 @@
+/*
+ *	Copied from Linux Monitor (LiMon) - Networking.
+ *
+ *	Copyright 1994 - 2000 Neil Russell.
+ *	(See License)
+ *	Copyright 2000 Roland Borde
+ *	Copyright 2000 Paolo Scaffardi
+ *	Copyright 2000-2002 Wolfgang Denk, [email protected]
+ */
+
+#ifndef __CDP_H__
+#define __CDP_H__
+
+void CDPStart(void);
+void CDPHandler(const uchar *pkt, unsigned len);
+
+#endif /* __CDP_H__ */
+
net/net.c +3 -365

398 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#24 lore raw

PATCH 5/28 net: Move CDP out of net.c

Hi Joe,

Quoted 20 lines · Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

?arch/powerpc/cpu/mpc8xx/fec.c | ? ?2 +-
?include/net.h ? ? ? ? ? ? ? ? | ? ?9 +-
?net/Makefile ? ? ? ? ? ? ? ? ?| ? ?1 +
?net/cdp.c ? ? ? ? ? ? ? ? ? ? | ?380 +++++++++++++++++++++++++++++++++++++++++
?net/cdp.h ? ? ? ? ? ? ? ? ? ? | ? 18 ++
?net/net.c ? ? ? ? ? ? ? ? ? ? | ?368 +---------------------------------------

?6 files changed, 406 insertions(+), 372 deletions(-) ?create mode 100644 net/cdp.c
?create mode 100644 net/cdp.h

arch/powerpc/cpu/mpc8xx/fec.c +0 -0
index f2a2c3a..0bc1e5d 100644
@@ -274,7 +274,7 @@ static int fec_recv (struct eth_device *dev)
 ?#if defined(CONFIG_CMD_CDP)
Quoted 4 lines

? ? ? ? ? ? ? ? ? ? ? ?if ((rx[0] & 1) != 0
? ? ? ? ? ? ? ? ? ? ? ? ? ?&& memcmp ((uchar *) rx, NetBcastAddr, 6) != 0
- ? ? ? ? ? ? ? ? ? ? ? ? ? && memcmp ((uchar *) rx, NetCDPAddr, 6) != 0)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? && !is_cdp_packet((uchar *)rx))

Do you think the is_cdp_packet() change should be in a separate commit?

Regards,
Simon

Quoted 866 lines

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?rx = NULL;
?#endif
? ? ? ? ? ? ? ? ? ? ? ?/*

include/net.h +0 -0
index 09d1b51..0396b69 100644
@@ -355,10 +355,6 @@ extern uchar ? ? ? ? ? ? ? NetEtherNullAddr[6];

?extern ushort ? ? ? ? ?NetOurVLAN; ? ? ? ? ? ? /* Our VLAN */ ?extern ushort ? ? ? ? ?NetOurNativeVLAN; ? ? ? /* Our Native VLAN */

include/net.h +0 -4
-extern uchar ? NetCDPAddr[6]; ? ? ? ? ?/* Ethernet CDP address */
-extern ushort ?CDPNativeVLAN; ? ? ? ? ?/* CDP returned native VLAN */
-extern ushort ?CDPApplianceVLAN; ? ? ? /* CDP returned appliance VLAN */
-

?extern int ? ? ? ? ? ? NetState; ? ? ? ? ? ? ? /* Network loop state */ ?#define NETLOOP_CONTINUE ? ? ? 1
?#define NETLOOP_RESTART ? ? ? ? ? ? ? ?2

include/net.h +0 -0
@@ -386,8 +382,9 @@ extern IPaddr_t ? ? NetPingIP; ? ? ? ? ? ? ? ? ? ? ?/* the ip address to ping */
 
 ?#if defined(CONFIG_CMD_CDP)

?/* when CDP completes these hold the return values */

include/net.h +3 -2
-extern ushort CDPNativeVLAN;
-extern ushort CDPApplianceVLAN;
+extern ushort CDPNativeVLAN; ? ? ? ? ? /* CDP returned native VLAN */
+extern ushort CDPApplianceVLAN; ? ? ? ? ? ? ? ?/* CDP returned appliance VLAN */
+int is_cdp_packet(const uchar *et_addr);

?#endif

?#if defined(CONFIG_CMD_SNTP)

net/Makefile +0 -0
index 5901046..b350bfc 100644
@@ -28,6 +28,7 @@ include $(TOPDIR)/config.mk

?LIB ? ?= $(obj)libnet.o

?COBJS-$(CONFIG_CMD_NET) ?+= bootp.o
+COBJS-$(CONFIG_CMD_CDP) ?+= cdp.o
?COBJS-$(CONFIG_CMD_DNS) ?+= dns.o
?COBJS-$(CONFIG_CMD_NET) ?+= eth.o
?COBJS-$(CONFIG_CMD_NET) ?+= net.o

net/cdp.c new file +380 -0
new file mode 100644
index 0000000..c5e54b2
@@ -0,0 +1,380 @@
+/*
+ * ? ? Copied from Linux Monitor (LiMon) - Networking.
+ *
+ * ? ? Copyright 1994 - 2000 Neil Russell.
+ * ? ? (See License)
+ * ? ? Copyright 2000 Roland Borde
+ * ? ? Copyright 2000 Paolo Scaffardi
+ * ? ? Copyright 2000-2002 Wolfgang Denk, wd at denx.de
+ */
+
+#include <common.h>
+#include <net.h>
+#if defined(CONFIG_CDP_VERSION)
+#include <timestamp.h>
+#endif
+
+#include "cdp.h"
+
+/* Ethernet bcast address */
+static const uchar NetCDPAddr[6] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc };
+
+#define CDP_DEVICE_ID_TLV ? ? ? ? ? ? ?0x0001
+#define CDP_ADDRESS_TLV ? ? ? ? ? ? ? ? ? ? ? ?0x0002
+#define CDP_PORT_ID_TLV ? ? ? ? ? ? ? ? ? ? ? ?0x0003
+#define CDP_CAPABILITIES_TLV ? ? ? ? ? 0x0004
+#define CDP_VERSION_TLV ? ? ? ? ? ? ? ? ? ? ? ?0x0005
+#define CDP_PLATFORM_TLV ? ? ? ? ? ? ? 0x0006
+#define CDP_NATIVE_VLAN_TLV ? ? ? ? ? ?0x000a
+#define CDP_APPLIANCE_VLAN_TLV ? ? ? ? 0x000e
+#define CDP_TRIGGER_TLV ? ? ? ? ? ? ? ? ? ? ? ?0x000f
+#define CDP_POWER_CONSUMPTION_TLV ? ? ?0x0010
+#define CDP_SYSNAME_TLV ? ? ? ? ? ? ? ? ? ? ? ?0x0014
+#define CDP_SYSOBJECT_TLV ? ? ? ? ? ? ?0x0015
+#define CDP_MANAGEMENT_ADDRESS_TLV ? ? 0x0016
+
+#define CDP_TIMEOUT ? ? ? ? ? ? ? ? ? ?250UL ? /* one packet every 250ms */
+
+static int CDPSeq;
+static int CDPOK;
+
+ushort CDPNativeVLAN;
+ushort CDPApplianceVLAN;
+
+static const uchar CDP_SNAP_hdr[8] = { 0xAA, 0xAA, 0x03, 0x00, 0x00, 0x0C, 0x20,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0x00 };
+
+static ushort
+CDP_compute_csum(const uchar *buff, ushort len)
+{
+ ? ? ? ushort csum;
+ ? ? ? int ? ? odd;
+ ? ? ? ulong ? result = 0;
+ ? ? ? ushort ?leftover;
+ ? ? ? ushort *p;
+
+ ? ? ? if (len > 0) {
+ ? ? ? ? ? ? ? odd = 1 & (ulong)buff;
+ ? ? ? ? ? ? ? if (odd) {
+ ? ? ? ? ? ? ? ? ? ? ? result = *buff << 8;
+ ? ? ? ? ? ? ? ? ? ? ? len--;
+ ? ? ? ? ? ? ? ? ? ? ? buff++;
+ ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? while (len > 1) {
+ ? ? ? ? ? ? ? ? ? ? ? p = (ushort *)buff;
+ ? ? ? ? ? ? ? ? ? ? ? result += *p++;
+ ? ? ? ? ? ? ? ? ? ? ? buff = (uchar *)p;
+ ? ? ? ? ? ? ? ? ? ? ? if (result & 0x80000000)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? result = (result & 0xFFFF) + (result >> 16);
+ ? ? ? ? ? ? ? ? ? ? ? len -= 2;
+ ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? if (len) {
+ ? ? ? ? ? ? ? ? ? ? ? leftover = (signed short)(*(const signed char *)buff);
+ ? ? ? ? ? ? ? ? ? ? ? /* CISCO SUCKS big time! (and blows too):
+ ? ? ? ? ? ? ? ? ? ? ? ?* CDP uses the IP checksum algorithm with a twist;
+ ? ? ? ? ? ? ? ? ? ? ? ?* for the last byte it *sign* extends and sums.
+ ? ? ? ? ? ? ? ? ? ? ? ?*/
+ ? ? ? ? ? ? ? ? ? ? ? result = (result & 0xffff0000) |
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?((result + leftover) & 0x0000ffff);
+ ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? while (result >> 16)
+ ? ? ? ? ? ? ? ? ? ? ? result = (result & 0xFFFF) + (result >> 16);
+
+ ? ? ? ? ? ? ? if (odd)
+ ? ? ? ? ? ? ? ? ? ? ? result = ((result >> 8) & 0xff) |
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?((result & 0xff) << 8);
+ ? ? ? }
+
+ ? ? ? /* add up 16-bit and 17-bit words for 17+c bits */
+ ? ? ? result = (result & 0xffff) + (result >> 16);
+ ? ? ? /* add up 16-bit and 2-bit for 16+c bit */
+ ? ? ? result = (result & 0xffff) + (result >> 16);
+ ? ? ? /* add up carry.. */
+ ? ? ? result = (result & 0xffff) + (result >> 16);
+
+ ? ? ? /* negate */
+ ? ? ? csum = ~(ushort)result;
+
+ ? ? ? /* run time endian detection */
+ ? ? ? if (csum != htons(csum)) ? ? ? ?/* little endian */
+ ? ? ? ? ? ? ? csum = htons(csum);
+
+ ? ? ? return csum;
+}
+
+static int
+CDPSendTrigger(void)
+{
+ ? ? ? uchar *pkt;
+ ? ? ? ushort *s;
+ ? ? ? ushort *cp;
+ ? ? ? Ethernet_t *et;
+ ? ? ? int len;
+ ? ? ? ushort chksum;
+#if ? ?defined(CONFIG_CDP_DEVICE_ID) || defined(CONFIG_CDP_PORT_ID) ? || \
+ ? ? ? defined(CONFIG_CDP_VERSION) ? || defined(CONFIG_CDP_PLATFORM)
+ ? ? ? char buf[32];
+#endif
+
+ ? ? ? pkt = NetTxPacket;
+ ? ? ? et = (Ethernet_t *)pkt;
+
+ ? ? ? /* NOTE: trigger sent not on any VLAN */
+
+ ? ? ? /* form ethernet header */
+ ? ? ? memcpy(et->et_dest, NetCDPAddr, 6);
+ ? ? ? memcpy(et->et_src, NetOurEther, 6);
+
+ ? ? ? pkt += ETHER_HDR_SIZE;
+
+ ? ? ? /* SNAP header */
+ ? ? ? memcpy((uchar *)pkt, CDP_SNAP_hdr, sizeof(CDP_SNAP_hdr));
+ ? ? ? pkt += sizeof(CDP_SNAP_hdr);
+
+ ? ? ? /* CDP header */
+ ? ? ? *pkt++ = 0x02; ? ? ? ? ? ? ? ? ? ? ? ? ?/* CDP version 2 */
+ ? ? ? *pkt++ = 180; ? ? ? ? ? ? ? ? ? ? ? ? ? /* TTL */
+ ? ? ? s = (ushort *)pkt;
+ ? ? ? cp = s;
+ ? ? ? /* checksum (0 for later calculation) */
+ ? ? ? *s++ = htons(0);
+
+ ? ? ? /* CDP fields */
+#ifdef CONFIG_CDP_DEVICE_ID
+ ? ? ? *s++ = htons(CDP_DEVICE_ID_TLV);
+ ? ? ? *s++ = htons(CONFIG_CDP_DEVICE_ID);
+ ? ? ? sprintf(buf, CONFIG_CDP_DEVICE_ID_PREFIX "%pm", NetOurEther);
+ ? ? ? memcpy((uchar *)s, buf, 16);
+ ? ? ? s += 16 / 2;
+#endif
+
+#ifdef CONFIG_CDP_PORT_ID
+ ? ? ? *s++ = htons(CDP_PORT_ID_TLV);
+ ? ? ? memset(buf, 0, sizeof(buf));
+ ? ? ? sprintf(buf, CONFIG_CDP_PORT_ID, eth_get_dev_index());
+ ? ? ? len = strlen(buf);
+ ? ? ? if (len & 1) ? ?/* make it even */
+ ? ? ? ? ? ? ? len++;
+ ? ? ? *s++ = htons(len + 4);
+ ? ? ? memcpy((uchar *)s, buf, len);
+ ? ? ? s += len / 2;
+#endif
+
+#ifdef CONFIG_CDP_CAPABILITIES
+ ? ? ? *s++ = htons(CDP_CAPABILITIES_TLV);
+ ? ? ? *s++ = htons(8);
+ ? ? ? *(ulong *)s = htonl(CONFIG_CDP_CAPABILITIES);
+ ? ? ? s += 2;
+#endif
+
+#ifdef CONFIG_CDP_VERSION
+ ? ? ? *s++ = htons(CDP_VERSION_TLV);
+ ? ? ? memset(buf, 0, sizeof(buf));
+ ? ? ? strcpy(buf, CONFIG_CDP_VERSION);
+ ? ? ? len = strlen(buf);
+ ? ? ? if (len & 1) ? ?/* make it even */
+ ? ? ? ? ? ? ? len++;
+ ? ? ? *s++ = htons(len + 4);
+ ? ? ? memcpy((uchar *)s, buf, len);
+ ? ? ? s += len / 2;
+#endif
+
+#ifdef CONFIG_CDP_PLATFORM
+ ? ? ? *s++ = htons(CDP_PLATFORM_TLV);
+ ? ? ? memset(buf, 0, sizeof(buf));
+ ? ? ? strcpy(buf, CONFIG_CDP_PLATFORM);
+ ? ? ? len = strlen(buf);
+ ? ? ? if (len & 1) ? ?/* make it even */
+ ? ? ? ? ? ? ? len++;
+ ? ? ? *s++ = htons(len + 4);
+ ? ? ? memcpy((uchar *)s, buf, len);
+ ? ? ? s += len / 2;
+#endif
+
+#ifdef CONFIG_CDP_TRIGGER
+ ? ? ? *s++ = htons(CDP_TRIGGER_TLV);
+ ? ? ? *s++ = htons(8);
+ ? ? ? *(ulong *)s = htonl(CONFIG_CDP_TRIGGER);
+ ? ? ? s += 2;
+#endif
+
+#ifdef CONFIG_CDP_POWER_CONSUMPTION
+ ? ? ? *s++ = htons(CDP_POWER_CONSUMPTION_TLV);
+ ? ? ? *s++ = htons(6);
+ ? ? ? *s++ = htons(CONFIG_CDP_POWER_CONSUMPTION);
+#endif
+
+ ? ? ? /* length of ethernet packet */
+ ? ? ? len = (uchar *)s - ((uchar *)NetTxPacket + ETHER_HDR_SIZE);
+ ? ? ? et->et_protlen = htons(len);
+
+ ? ? ? len = ETHER_HDR_SIZE + sizeof(CDP_SNAP_hdr);
+ ? ? ? chksum = CDP_compute_csum((uchar *)NetTxPacket + len,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (uchar *)s - (NetTxPacket + len));
+ ? ? ? if (chksum == 0)
+ ? ? ? ? ? ? ? chksum = 0xFFFF;
+ ? ? ? *cp = htons(chksum);
+
+ ? ? ? (void) eth_send(NetTxPacket, (uchar *)s - NetTxPacket);
+ ? ? ? return 0;
+}
+
+static void
+CDPTimeout(void)
+{
+ ? ? ? CDPSeq++;
+
+ ? ? ? if (CDPSeq < 3) {
+ ? ? ? ? ? ? ? NetSetTimeout(CDP_TIMEOUT, CDPTimeout);
+ ? ? ? ? ? ? ? CDPSendTrigger();
+ ? ? ? ? ? ? ? return;
+ ? ? ? }
+
+ ? ? ? /* if not OK try again */
+ ? ? ? if (!CDPOK)
+ ? ? ? ? ? ? ? NetStartAgain();
+ ? ? ? else
+ ? ? ? ? ? ? ? NetState = NETLOOP_SUCCESS;
+}
+
+static void
+CDPDummyHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+ ? ? ? ? ? ? ? unsigned len)
+{
+ ? ? ? /* nothing */
+}
+
+void
+CDPHandler(const uchar *pkt, unsigned len)
+{
+ ? ? ? const uchar *t;
+ ? ? ? const ushort *ss;
+ ? ? ? ushort type, tlen;
+ ? ? ? ushort vlan, nvlan;
+
+ ? ? ? /* minimum size? */
+ ? ? ? if (len < sizeof(CDP_SNAP_hdr) + 4)
+ ? ? ? ? ? ? ? goto pkt_short;
+
+ ? ? ? /* check for valid CDP SNAP header */
+ ? ? ? if (memcmp(pkt, CDP_SNAP_hdr, sizeof(CDP_SNAP_hdr)) != 0)
+ ? ? ? ? ? ? ? return;
+
+ ? ? ? pkt += sizeof(CDP_SNAP_hdr);
+ ? ? ? len -= sizeof(CDP_SNAP_hdr);
+
+ ? ? ? /* Version of CDP protocol must be >= 2 and TTL != 0 */
+ ? ? ? if (pkt[0] < 0x02 || pkt[1] == 0)
+ ? ? ? ? ? ? ? return;
+
+ ? ? ? /*
+ ? ? ? ?* if version is greater than 0x02 maybe we'll have a problem;
+ ? ? ? ?* output a warning
+ ? ? ? ?*/
+ ? ? ? if (pkt[0] != 0x02)
+ ? ? ? ? ? ? ? printf("**WARNING: CDP packet received with a protocol version "
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "%d > 2\n", pkt[0] & 0xff);
+
+ ? ? ? if (CDP_compute_csum(pkt, len) != 0)
+ ? ? ? ? ? ? ? return;
+
+ ? ? ? pkt += 4;
+ ? ? ? len -= 4;
+
+ ? ? ? vlan = htons(-1);
+ ? ? ? nvlan = htons(-1);
+ ? ? ? while (len > 0) {
+ ? ? ? ? ? ? ? if (len < 4)
+ ? ? ? ? ? ? ? ? ? ? ? goto pkt_short;
+
+ ? ? ? ? ? ? ? ss = (const ushort *)pkt;
+ ? ? ? ? ? ? ? type = ntohs(ss[0]);
+ ? ? ? ? ? ? ? tlen = ntohs(ss[1]);
+ ? ? ? ? ? ? ? if (tlen > len)
+ ? ? ? ? ? ? ? ? ? ? ? goto pkt_short;
+
+ ? ? ? ? ? ? ? pkt += tlen;
+ ? ? ? ? ? ? ? len -= tlen;
+
+ ? ? ? ? ? ? ? ss += 2; ? ? ? ?/* point ss to the data of the TLV */
+ ? ? ? ? ? ? ? tlen -= 4;
+
+ ? ? ? ? ? ? ? switch (type) {
+ ? ? ? ? ? ? ? case CDP_DEVICE_ID_TLV:
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? case CDP_ADDRESS_TLV:
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? case CDP_PORT_ID_TLV:
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? case CDP_CAPABILITIES_TLV:
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? case CDP_VERSION_TLV:
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? case CDP_PLATFORM_TLV:
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? case CDP_NATIVE_VLAN_TLV:
+ ? ? ? ? ? ? ? ? ? ? ? nvlan = *ss;
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? case CDP_APPLIANCE_VLAN_TLV:
+ ? ? ? ? ? ? ? ? ? ? ? t = (const uchar *)ss;
+ ? ? ? ? ? ? ? ? ? ? ? while (tlen > 0) {
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (tlen < 3)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto pkt_short;
+
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ss = (const ushort *)(t + 1);
+
+#ifdef CONFIG_CDP_APPLIANCE_VLAN_TYPE
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (t[0] == CONFIG_CDP_APPLIANCE_VLAN_TYPE)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? vlan = *ss;
+#else
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* XXX will this work; dunno */
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? vlan = ntohs(*ss);
+#endif
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? t += 3; tlen -= 3;
+ ? ? ? ? ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? case CDP_TRIGGER_TLV:
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? case CDP_POWER_CONSUMPTION_TLV:
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? case CDP_SYSNAME_TLV:
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? case CDP_SYSOBJECT_TLV:
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? case CDP_MANAGEMENT_ADDRESS_TLV:
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? }
+ ? ? ? }
+
+ ? ? ? CDPApplianceVLAN = vlan;
+ ? ? ? CDPNativeVLAN = nvlan;
+
+ ? ? ? CDPOK = 1;
+ ? ? ? return;
+
+ pkt_short:
+ ? ? ? printf("** CDP packet is too short\n");
+ ? ? ? return;
+}
+
+void
+CDPStart(void)
+{
+ ? ? ? printf("Using %s device\n", eth_get_name());
+ ? ? ? CDPSeq = 0;
+ ? ? ? CDPOK = 0;
+
+ ? ? ? CDPNativeVLAN = htons(-1);
+ ? ? ? CDPApplianceVLAN = htons(-1);
+
+ ? ? ? NetSetTimeout(CDP_TIMEOUT, CDPTimeout);
+ ? ? ? NetSetHandler(CDPDummyHandler);
+
+ ? ? ? CDPSendTrigger();
+}
+
+int
+is_cdp_packet(const uchar *et_addr)
+{
+ ? ? ? return memcmp(et_addr, NetCDPAddr, 6) == 0;
+}
net/cdp.h new file +18 -0
new file mode 100644
index 0000000..fef744e
@@ -0,0 +1,18 @@
+/*
+ * ? ? Copied from Linux Monitor (LiMon) - Networking.
+ *
+ * ? ? Copyright 1994 - 2000 Neil Russell.
+ * ? ? (See License)
+ * ? ? Copyright 2000 Roland Borde
+ * ? ? Copyright 2000 Paolo Scaffardi
+ * ? ? Copyright 2000-2002 Wolfgang Denk, wd at denx.de
+ */
+
+#ifndef __CDP_H__
+#define __CDP_H__
+
+void CDPStart(void);
+void CDPHandler(const uchar *pkt, unsigned len);
+
+#endif /* __CDP_H__ */
+
net/net.c +0 -0
index 1d6252f..48d3ca8 100644
@@ -91,8 +91,8 @@
 ?#if defined(CONFIG_CMD_SNTP)

?#include "sntp.h"
?#endif

net/net.c +2 -2
-#if defined(CONFIG_CDP_VERSION)
-#include <timestamp.h>
+#if defined(CONFIG_CMD_CDP)
+#include "cdp.h"

?#endif
?#if defined(CONFIG_CMD_DNS)
?#include "dns.h"

net/net.c +0 -0
@@ -163,10 +163,6 @@ uchar ? ? ? ? ? ? ?NetEtherNullAddr[6];

?#ifdef CONFIG_API
?void ? ? ? ? ? (*push_packet)(volatile void *, int len) = 0; ?#endif

net/net.c +0 -4
-#if defined(CONFIG_CMD_CDP)
-/* Ethernet bcast address */
-uchar ? ? ? ? ?NetCDPAddr[6] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc };
-#endif

?/* Network loop state */
?int ? ? ? ? ? ?NetState;
?/* Tried all network devices */

net/net.c +0 -0
@@ -192,10 +188,6 @@ IPaddr_t ? NetPingIP;
 ?static void PingStart(void);

?#endif

net/net.c +0 -4
-#if defined(CONFIG_CMD_CDP)
-static void CDPStart(void);
-#endif
-

?#if defined(CONFIG_CMD_SNTP)
?/* NTP server IP address */
?IPaddr_t ? ? ? NetNtpServerIP;

net/net.c +0 -0
@@ -841,360 +833,6 @@ static void PingStart(void)
 ?}

?#endif

net/net.c +0 -354
-#if defined(CONFIG_CMD_CDP)
-
-#define CDP_DEVICE_ID_TLV ? ? ? ? ? ? ?0x0001
-#define CDP_ADDRESS_TLV ? ? ? ? ? ? ? ? ? ? ? ?0x0002
-#define CDP_PORT_ID_TLV ? ? ? ? ? ? ? ? ? ? ? ?0x0003
-#define CDP_CAPABILITIES_TLV ? ? ? ? ? 0x0004
-#define CDP_VERSION_TLV ? ? ? ? ? ? ? ? ? ? ? ?0x0005
-#define CDP_PLATFORM_TLV ? ? ? ? ? ? ? 0x0006
-#define CDP_NATIVE_VLAN_TLV ? ? ? ? ? ?0x000a
-#define CDP_APPLIANCE_VLAN_TLV ? ? ? ? 0x000e
-#define CDP_TRIGGER_TLV ? ? ? ? ? ? ? ? ? ? ? ?0x000f
-#define CDP_POWER_CONSUMPTION_TLV ? ? ?0x0010
-#define CDP_SYSNAME_TLV ? ? ? ? ? ? ? ? ? ? ? ?0x0014
-#define CDP_SYSOBJECT_TLV ? ? ? ? ? ? ?0x0015
-#define CDP_MANAGEMENT_ADDRESS_TLV ? ? 0x0016
-
-#define CDP_TIMEOUT ? ? ? ? ? ? ? ? ? ?250UL ? /* one packet every 250ms */
-
-static int CDPSeq;
-static int CDPOK;
-
-ushort CDPNativeVLAN;
-ushort CDPApplianceVLAN;
-
-static const uchar CDP_SNAP_hdr[8] = { 0xAA, 0xAA, 0x03, 0x00, 0x00, 0x0C, 0x20,
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0x00 };
-
-static ushort CDP_compute_csum(const uchar *buff, ushort len)
-{
- ? ? ? ushort csum;
- ? ? ? int ? ? odd;
- ? ? ? ulong ? result = 0;
- ? ? ? ushort ?leftover;
- ? ? ? ushort *p;
-
- ? ? ? if (len > 0) {
- ? ? ? ? ? ? ? odd = 1 & (ulong)buff;
- ? ? ? ? ? ? ? if (odd) {
- ? ? ? ? ? ? ? ? ? ? ? result = *buff << 8;
- ? ? ? ? ? ? ? ? ? ? ? len--;
- ? ? ? ? ? ? ? ? ? ? ? buff++;
- ? ? ? ? ? ? ? }
- ? ? ? ? ? ? ? while (len > 1) {
- ? ? ? ? ? ? ? ? ? ? ? p = (ushort *)buff;
- ? ? ? ? ? ? ? ? ? ? ? result += *p++;
- ? ? ? ? ? ? ? ? ? ? ? buff = (uchar *)p;
- ? ? ? ? ? ? ? ? ? ? ? if (result & 0x80000000)
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? result = (result & 0xFFFF) + (result >> 16);
- ? ? ? ? ? ? ? ? ? ? ? len -= 2;
- ? ? ? ? ? ? ? }
- ? ? ? ? ? ? ? if (len) {
- ? ? ? ? ? ? ? ? ? ? ? leftover = (signed short)(*(const signed char *)buff);
- ? ? ? ? ? ? ? ? ? ? ? /* CISCO SUCKS big time! (and blows too):
- ? ? ? ? ? ? ? ? ? ? ? ?* CDP uses the IP checksum algorithm with a twist;
- ? ? ? ? ? ? ? ? ? ? ? ?* for the last byte it *sign* extends and sums.
- ? ? ? ? ? ? ? ? ? ? ? ?*/
- ? ? ? ? ? ? ? ? ? ? ? result = (result & 0xffff0000) |
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?((result + leftover) & 0x0000ffff);
- ? ? ? ? ? ? ? }
- ? ? ? ? ? ? ? while (result >> 16)
- ? ? ? ? ? ? ? ? ? ? ? result = (result & 0xFFFF) + (result >> 16);
-
- ? ? ? ? ? ? ? if (odd)
- ? ? ? ? ? ? ? ? ? ? ? result = ((result >> 8) & 0xff) |
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?((result & 0xff) << 8);
- ? ? ? }
-
- ? ? ? /* add up 16-bit and 17-bit words for 17+c bits */
- ? ? ? result = (result & 0xffff) + (result >> 16);
- ? ? ? /* add up 16-bit and 2-bit for 16+c bit */
- ? ? ? result = (result & 0xffff) + (result >> 16);
- ? ? ? /* add up carry.. */
- ? ? ? result = (result & 0xffff) + (result >> 16);
-
- ? ? ? /* negate */
- ? ? ? csum = ~(ushort)result;
-
- ? ? ? /* run time endian detection */
- ? ? ? if (csum != htons(csum)) ? ? ? ?/* little endian */
- ? ? ? ? ? ? ? csum = htons(csum);
-
- ? ? ? return csum;
-}
-
-int CDPSendTrigger(void)
-{
- ? ? ? uchar *pkt;
- ? ? ? ushort *s;
- ? ? ? ushort *cp;
- ? ? ? Ethernet_t *et;
- ? ? ? int len;
- ? ? ? ushort chksum;
-#if ? ?defined(CONFIG_CDP_DEVICE_ID) || defined(CONFIG_CDP_PORT_ID) ? || \
- ? ? ? defined(CONFIG_CDP_VERSION) ? || defined(CONFIG_CDP_PLATFORM)
- ? ? ? char buf[32];
-#endif
-
- ? ? ? pkt = NetTxPacket;
- ? ? ? et = (Ethernet_t *)pkt;
-
- ? ? ? /* NOTE: trigger sent not on any VLAN */
-
- ? ? ? /* form ethernet header */
- ? ? ? memcpy(et->et_dest, NetCDPAddr, 6);
- ? ? ? memcpy(et->et_src, NetOurEther, 6);
-
- ? ? ? pkt += ETHER_HDR_SIZE;
-
- ? ? ? /* SNAP header */
- ? ? ? memcpy((uchar *)pkt, CDP_SNAP_hdr, sizeof(CDP_SNAP_hdr));
- ? ? ? pkt += sizeof(CDP_SNAP_hdr);
-
- ? ? ? /* CDP header */
- ? ? ? *pkt++ = 0x02; ? ? ? ? ? ? ? ? ? ? ? ? ?/* CDP version 2 */
- ? ? ? *pkt++ = 180; ? ? ? ? ? ? ? ? ? ? ? ? ? /* TTL */
- ? ? ? s = (ushort *)pkt;
- ? ? ? cp = s;
- ? ? ? /* checksum (0 for later calculation) */
- ? ? ? *s++ = htons(0);
-
- ? ? ? /* CDP fields */
-#ifdef CONFIG_CDP_DEVICE_ID
- ? ? ? *s++ = htons(CDP_DEVICE_ID_TLV);
- ? ? ? *s++ = htons(CONFIG_CDP_DEVICE_ID);
- ? ? ? sprintf(buf, CONFIG_CDP_DEVICE_ID_PREFIX "%pm", NetOurEther);
- ? ? ? memcpy((uchar *)s, buf, 16);
- ? ? ? s += 16 / 2;
-#endif
-
-#ifdef CONFIG_CDP_PORT_ID
- ? ? ? *s++ = htons(CDP_PORT_ID_TLV);
- ? ? ? memset(buf, 0, sizeof(buf));
- ? ? ? sprintf(buf, CONFIG_CDP_PORT_ID, eth_get_dev_index());
- ? ? ? len = strlen(buf);
- ? ? ? if (len & 1) ? ?/* make it even */
- ? ? ? ? ? ? ? len++;
- ? ? ? *s++ = htons(len + 4);
- ? ? ? memcpy((uchar *)s, buf, len);
- ? ? ? s += len / 2;
-#endif
-
-#ifdef CONFIG_CDP_CAPABILITIES
- ? ? ? *s++ = htons(CDP_CAPABILITIES_TLV);
- ? ? ? *s++ = htons(8);
- ? ? ? *(ulong *)s = htonl(CONFIG_CDP_CAPABILITIES);
- ? ? ? s += 2;
-#endif
-
-#ifdef CONFIG_CDP_VERSION
- ? ? ? *s++ = htons(CDP_VERSION_TLV);
- ? ? ? memset(buf, 0, sizeof(buf));
- ? ? ? strcpy(buf, CONFIG_CDP_VERSION);
- ? ? ? len = strlen(buf);
- ? ? ? if (len & 1) ? ?/* make it even */
- ? ? ? ? ? ? ? len++;
- ? ? ? *s++ = htons(len + 4);
- ? ? ? memcpy((uchar *)s, buf, len);
- ? ? ? s += len / 2;
-#endif
-
-#ifdef CONFIG_CDP_PLATFORM
- ? ? ? *s++ = htons(CDP_PLATFORM_TLV);
- ? ? ? memset(buf, 0, sizeof(buf));
- ? ? ? strcpy(buf, CONFIG_CDP_PLATFORM);
- ? ? ? len = strlen(buf);
- ? ? ? if (len & 1) ? ?/* make it even */
- ? ? ? ? ? ? ? len++;
- ? ? ? *s++ = htons(len + 4);
- ? ? ? memcpy((uchar *)s, buf, len);
- ? ? ? s += len / 2;
-#endif
-
-#ifdef CONFIG_CDP_TRIGGER
- ? ? ? *s++ = htons(CDP_TRIGGER_TLV);
- ? ? ? *s++ = htons(8);
- ? ? ? *(ulong *)s = htonl(CONFIG_CDP_TRIGGER);
- ? ? ? s += 2;
-#endif
-
-#ifdef CONFIG_CDP_POWER_CONSUMPTION
- ? ? ? *s++ = htons(CDP_POWER_CONSUMPTION_TLV);
- ? ? ? *s++ = htons(6);
- ? ? ? *s++ = htons(CONFIG_CDP_POWER_CONSUMPTION);
-#endif
-
- ? ? ? /* length of ethernet packet */
- ? ? ? len = (uchar *)s - ((uchar *)NetTxPacket + ETHER_HDR_SIZE);
- ? ? ? et->et_protlen = htons(len);
-
- ? ? ? len = ETHER_HDR_SIZE + sizeof(CDP_SNAP_hdr);
- ? ? ? chksum = CDP_compute_csum((uchar *)NetTxPacket + len,
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (uchar *)s - (NetTxPacket + len));
- ? ? ? if (chksum == 0)
- ? ? ? ? ? ? ? chksum = 0xFFFF;
- ? ? ? *cp = htons(chksum);
-
- ? ? ? (void) eth_send(NetTxPacket, (uchar *)s - NetTxPacket);
- ? ? ? return 0;
-}
-
-static void
-CDPTimeout(void)
-{
- ? ? ? CDPSeq++;
-
- ? ? ? if (CDPSeq < 3) {
- ? ? ? ? ? ? ? NetSetTimeout(CDP_TIMEOUT, CDPTimeout);
- ? ? ? ? ? ? ? CDPSendTrigger();
- ? ? ? ? ? ? ? return;
- ? ? ? }
-
- ? ? ? /* if not OK try again */
- ? ? ? if (!CDPOK)
- ? ? ? ? ? ? ? NetStartAgain();
- ? ? ? else
- ? ? ? ? ? ? ? NetState = NETLOOP_SUCCESS;
-}
-
-static void
-CDPDummyHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
- ? ? ? ? ? ? ? unsigned len)
-{
- ? ? ? /* nothing */
-}
-
-static void
-CDPHandler(const uchar *pkt, unsigned len)
-{
- ? ? ? const uchar *t;
- ? ? ? const ushort *ss;
- ? ? ? ushort type, tlen;
- ? ? ? ushort vlan, nvlan;
-
- ? ? ? /* minimum size? */
- ? ? ? if (len < sizeof(CDP_SNAP_hdr) + 4)
- ? ? ? ? ? ? ? goto pkt_short;
-
- ? ? ? /* check for valid CDP SNAP header */
- ? ? ? if (memcmp(pkt, CDP_SNAP_hdr, sizeof(CDP_SNAP_hdr)) != 0)
- ? ? ? ? ? ? ? return;
-
- ? ? ? pkt += sizeof(CDP_SNAP_hdr);
- ? ? ? len -= sizeof(CDP_SNAP_hdr);
-
- ? ? ? /* Version of CDP protocol must be >= 2 and TTL != 0 */
- ? ? ? if (pkt[0] < 0x02 || pkt[1] == 0)
- ? ? ? ? ? ? ? return;
-
- ? ? ? /*
- ? ? ? ?* if version is greater than 0x02 maybe we'll have a problem;
- ? ? ? ?* output a warning
- ? ? ? ?*/
- ? ? ? if (pkt[0] != 0x02)
- ? ? ? ? ? ? ? printf("**WARNING: CDP packet received with a protocol version "
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "%d > 2\n", pkt[0] & 0xff);
-
- ? ? ? if (CDP_compute_csum(pkt, len) != 0)
- ? ? ? ? ? ? ? return;
-
- ? ? ? pkt += 4;
- ? ? ? len -= 4;
-
- ? ? ? vlan = htons(-1);
- ? ? ? nvlan = htons(-1);
- ? ? ? while (len > 0) {
- ? ? ? ? ? ? ? if (len < 4)
- ? ? ? ? ? ? ? ? ? ? ? goto pkt_short;
-
- ? ? ? ? ? ? ? ss = (const ushort *)pkt;
- ? ? ? ? ? ? ? type = ntohs(ss[0]);
- ? ? ? ? ? ? ? tlen = ntohs(ss[1]);
- ? ? ? ? ? ? ? if (tlen > len)
- ? ? ? ? ? ? ? ? ? ? ? goto pkt_short;
-
- ? ? ? ? ? ? ? pkt += tlen;
- ? ? ? ? ? ? ? len -= tlen;
-
- ? ? ? ? ? ? ? ss += 2; ? ? ? ?/* point ss to the data of the TLV */
- ? ? ? ? ? ? ? tlen -= 4;
-
- ? ? ? ? ? ? ? switch (type) {
- ? ? ? ? ? ? ? case CDP_DEVICE_ID_TLV:
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? case CDP_ADDRESS_TLV:
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? case CDP_PORT_ID_TLV:
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? case CDP_CAPABILITIES_TLV:
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? case CDP_VERSION_TLV:
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? case CDP_PLATFORM_TLV:
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? case CDP_NATIVE_VLAN_TLV:
- ? ? ? ? ? ? ? ? ? ? ? nvlan = *ss;
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? case CDP_APPLIANCE_VLAN_TLV:
- ? ? ? ? ? ? ? ? ? ? ? t = (const uchar *)ss;
- ? ? ? ? ? ? ? ? ? ? ? while (tlen > 0) {
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (tlen < 3)
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto pkt_short;
-
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ss = (const ushort *)(t + 1);
-
-#ifdef CONFIG_CDP_APPLIANCE_VLAN_TYPE
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (t[0] == CONFIG_CDP_APPLIANCE_VLAN_TYPE)
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? vlan = *ss;
-#else
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* XXX will this work; dunno */
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? vlan = ntohs(*ss);
-#endif
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? t += 3; tlen -= 3;
- ? ? ? ? ? ? ? ? ? ? ? }
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? case CDP_TRIGGER_TLV:
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? case CDP_POWER_CONSUMPTION_TLV:
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? case CDP_SYSNAME_TLV:
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? case CDP_SYSOBJECT_TLV:
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? case CDP_MANAGEMENT_ADDRESS_TLV:
- ? ? ? ? ? ? ? ? ? ? ? break;
- ? ? ? ? ? ? ? }
- ? ? ? }
-
- ? ? ? CDPApplianceVLAN = vlan;
- ? ? ? CDPNativeVLAN = nvlan;
-
- ? ? ? CDPOK = 1;
- ? ? ? return;
-
- pkt_short:
- ? ? ? printf("** CDP packet is too short\n");
- ? ? ? return;
-}
-
-static void CDPStart(void)
-{
- ? ? ? printf("Using %s device\n", eth_get_name());
- ? ? ? CDPSeq = 0;
- ? ? ? CDPOK = 0;
-
- ? ? ? CDPNativeVLAN = htons(-1);
- ? ? ? CDPApplianceVLAN = htons(-1);
-
- ? ? ? NetSetTimeout(CDP_TIMEOUT, CDPTimeout);
- ? ? ? NetSetHandler(CDPDummyHandler);
-
- ? ? ? CDPSendTrigger();
-}
-#endif
-

?#ifdef CONFIG_IP_DEFRAG
?/*
?* This function collects fragments in a single packet, according

net/net.c +0 -0
@@ -1463,7 +1101,7 @@ NetReceive(volatile uchar *inpkt, int len)
 
 ?#if defined(CONFIG_CMD_CDP)

? ? ? ?/* keep track if packet is CDP */
- ? ? ? iscdp = memcmp(et->et_dest, NetCDPAddr, 6) == 0;
+ ? ? ? iscdp = is_cdp_packet(et->et_dest); ?#endif

? ? ? ?myvlanid = ntohs(NetOurVLAN);
--
1.6.0.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#25 lore raw

PATCH 5/28 net: Move CDP out of net.c

In reply to Joe Hershberger

include/net.h extern IPaddr_t NetPingIP; /* the ip address to ping */ · line 387

Quoted 4 lines · On Thursday 19 January 2012 19:53:08 Joe Hershberger wrote:
include/net.h +1 -0
 
+int is_cdp_packet(const uchar *et_addr);

seems like this would be better as a static inline since it's just a memcmp

Quoted 11 lines
net/cdp.h new file +8 -0
@@ -0,0 +1,18 @@
+/*
+ *	Copied from Linux Monitor (LiMon) - Networking.
+ *
+ *	Copyright 1994 - 2000 Neil Russell.
+ *	(See License)
+ *	Copyright 2000 Roland Borde
+ *	Copyright 2000 Paolo Scaffardi
+ *	Copyright 2000-2002 Wolfgang Denk, wd at denx.de

net/cdp.h line 18

Quoted 10 lines
net/cdp.h new file +10 -0
+ */
+
+#ifndef __CDP_H__
+#define __CDP_H__
+
+void CDPStart(void);
+void CDPHandler(const uchar *pkt, unsigned len);
+
+#endif /* __CDP_H__ */
+

no blank newlines at end of files

net/net.c line 96

Quoted 6 lines
net/net.c +2 -0
 
+#if defined(CONFIG_CMD_CDP)
+#include "cdp.h"
 #endif

let's push this ifdef down into cdp.h
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/668f55cb/attachment.pgp>

#26 lore raw

PATCH 6/28 net: Move ARP out of net.c

In reply to Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 include/net.h |    3 +-
 net/Makefile  |    1 +
 net/arp.c     |  213 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/arp.h     |   30 ++++++++
 net/net.c     |  209 ++++----------------------------------------------------
 5 files changed, 259 insertions(+), 197 deletions(-)
 create mode 100644 net/arp.c
 create mode 100644 net/arp.h
include/net.h +2 -1
index 0396b69..2d00233 100644
@@ -418,7 +418,8 @@ extern void NetSetIP(uchar *, IPaddr_t, int, int, int);
 extern int	NetCksumOk(uchar *, int);	/* Return true if cksum OK */
 extern uint	NetCksum(uchar *, int);		/* Calculate the checksum */
 
-/* Set callbacks */
+/* Callbacks */
+extern rxhand_f *NetGetHandler(void);		/* Get RX packet handler */
 extern void	NetSetHandler(rxhand_f *);	/* Set RX packet handler */
 extern void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */
 extern void	NetSetTimeout(ulong, thand_f *);/* Set timeout handler */
net/Makefile +1 -0
index b350bfc..0916a56 100644
@@ -27,6 +27,7 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)libnet.o
 
+COBJS-$(CONFIG_CMD_NET)  += arp.o
 COBJS-$(CONFIG_CMD_NET)  += bootp.o
 COBJS-$(CONFIG_CMD_CDP)  += cdp.o
 COBJS-$(CONFIG_CMD_DNS)  += dns.o
net/arp.c new file +213 -0

213 lines not on this page · raw message

net/arp.h new file +30 -0
new file mode 100644
index 0000000..09c763d
@@ -0,0 +1,30 @@
+/*
+ *	Copied from Linux Monitor (LiMon) - Networking.
+ *
+ *	Copyright 1994 - 2000 Neil Russell.
+ *	(See License)
+ *	Copyright 2000 Roland Borde
+ *	Copyright 2000 Paolo Scaffardi
+ *	Copyright 2000-2002 Wolfgang Denk, wd at denx.de
+ */
+
+#ifndef __ARP_H__
+#define __ARP_H__
+
+#include <net.h>
+
+extern IPaddr_t	NetArpWaitPacketIP;
+/* MAC address of waiting packet's destination */
+extern uchar *NetArpWaitPacketMAC;
+/* THE transmit packet */
+extern uchar *NetArpWaitTxPacket;
+extern int NetArpWaitTxPacketSize;
+extern ulong NetArpWaitTimerStart;
+extern int NetArpWaitTry;
+
+void ArpInit(void);
+void ArpRequest(void);
+void ArpTimeoutCheck(void);
+void ArpReceive(Ethernet_t *et, IP_t *ip, int len);
+
+#endif /* __ARP_H__ */
net/net.c +13 -196

264 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#27 lore raw

PATCH 6/28 net: Move ARP out of net.c

Quoted 1 line · Joe Hershberger
Quoted 576 lines
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

?include/net.h | ? ?3 +-
?net/Makefile ?| ? ?1 +
?net/arp.c ? ? | ?213 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
?net/arp.h ? ? | ? 30 ++++++++
?net/net.c ? ? | ?209 ++++----------------------------------------------------

?5 files changed, 259 insertions(+), 197 deletions(-) ?create mode 100644 net/arp.c
?create mode 100644 net/arp.h

include/net.h +0 -0
index 0396b69..2d00233 100644
@@ -418,7 +418,8 @@ extern void NetSetIP(uchar *, IPaddr_t, int, int, int);

?extern int ? ? NetCksumOk(uchar *, int); ? ? ? /* Return true if cksum OK */ ?extern uint ? ?NetCksum(uchar *, int); ? ? ? ? /* Calculate the checksum */

include/net.h +2 -1
-/* Set callbacks */
+/* Callbacks */
+extern rxhand_f *NetGetHandler(void); ? ? ? ? ?/* Get RX packet handler */

?extern void ? ?NetSetHandler(rxhand_f *); ? ? ?/* Set RX packet handler */ ?extern void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */ ?extern void ? ?NetSetTimeout(ulong, thand_f *);/* Set timeout handler */

net/Makefile +0 -0
index b350bfc..0916a56 100644
@@ -27,6 +27,7 @@ include $(TOPDIR)/config.mk
 

?LIB ? ?= $(obj)libnet.o

+COBJS-$(CONFIG_CMD_NET) ?+= arp.o
?COBJS-$(CONFIG_CMD_NET) ?+= bootp.o
?COBJS-$(CONFIG_CMD_CDP) ?+= cdp.o
?COBJS-$(CONFIG_CMD_DNS) ?+= dns.o

net/arp.c new file +213 -0
new file mode 100644
index 0000000..f75217c
@@ -0,0 +1,213 @@
+/*
+ * ? ? Copied from Linux Monitor (LiMon) - Networking.
+ *
+ * ? ? Copyright 1994 - 2000 Neil Russell.
+ * ? ? (See License)
+ * ? ? Copyright 2000 Roland Borde
+ * ? ? Copyright 2000 Paolo Scaffardi
+ * ? ? Copyright 2000-2002 Wolfgang Denk, wd at denx.de
+ */
+
+#include <common.h>
+
+#include "arp.h"
+
+#ifndef ? ? ? ?CONFIG_ARP_TIMEOUT
+/* Milliseconds before trying ARP again */
+# define ARP_TIMEOUT ? ? ? ? ? 5000UL
+#else
+# define ARP_TIMEOUT ? ? ? ? ? CONFIG_ARP_TIMEOUT
+#endif
+
+
+#ifndef ? ? ? ?CONFIG_NET_RETRY_COUNT
+# define ARP_TIMEOUT_COUNT ? ? 5 ? ? ? /* # of timeouts before giving up ?*/
+#else
+# define ARP_TIMEOUT_COUNT ? ? CONFIG_NET_RETRY_COUNT
+#endif
+
+IPaddr_t ? ? ? NetArpWaitPacketIP;
+IPaddr_t ? ? ? NetArpWaitReplyIP;
+/* MAC address of waiting packet's destination */
+uchar ? ? ? ? *NetArpWaitPacketMAC;
+/* THE transmit packet */
+uchar ? ? ? ? *NetArpWaitTxPacket;
+int ? ? ? ? ? ?NetArpWaitTxPacketSize;
+uchar ? ? ? ? ?NetArpWaitPacketBuf[PKTSIZE_ALIGN + PKTALIGN];
+ulong ? ? ? ? ?NetArpWaitTimerStart;
+int ? ? ? ? ? ?NetArpWaitTry;
+
+void ArpInit(void)
+{
+ ? ? ? /* XXX problem with bss workaround */
+ ? ? ? NetArpWaitPacketMAC = NULL;
+ ? ? ? NetArpWaitPacketIP = 0;
+ ? ? ? NetArpWaitReplyIP = 0;
+ ? ? ? NetArpWaitTxPacket = &NetArpWaitPacketBuf[0] + (PKTALIGN - 1);
+ ? ? ? NetArpWaitTxPacket -= (ulong)NetArpWaitTxPacket % PKTALIGN;
+ ? ? ? NetArpWaitTxPacketSize = 0;
+}
+
+void ArpRequest(void)
+{
+ ? ? ? uchar *pkt;
+ ? ? ? ARP_t *arp;
+
+ ? ? ? debug("ARP broadcast %d\n", NetArpWaitTry);
+
+ ? ? ? pkt = NetTxPacket;
+
+ ? ? ? pkt += NetSetEther(pkt, NetBcastAddr, PROT_ARP);
+
+ ? ? ? arp = (ARP_t *) pkt;
+
+ ? ? ? arp->ar_hrd = htons(ARP_ETHER);
+ ? ? ? arp->ar_pro = htons(PROT_IP);
+ ? ? ? arp->ar_hln = 6;
+ ? ? ? arp->ar_pln = 4;
+ ? ? ? arp->ar_op = htons(ARPOP_REQUEST);
+
+ ? ? ? /* source ET addr */
+ ? ? ? memcpy(&arp->ar_data[0], NetOurEther, 6);
+ ? ? ? /* source IP addr */
+ ? ? ? NetWriteIP((uchar *) &arp->ar_data[6], NetOurIP);
+ ? ? ? /* dest ET addr = 0 */
+ ? ? ? memset(&arp->ar_data[10], '\0', 6);
+ ? ? ? if ((NetArpWaitPacketIP & NetOurSubnetMask) !=
+ ? ? ? ? ? (NetOurIP & NetOurSubnetMask)) {
+ ? ? ? ? ? ? ? if (NetOurGatewayIP == 0) {
+ ? ? ? ? ? ? ? ? ? ? ? puts("## Warning: gatewayip needed but not set\n");
+ ? ? ? ? ? ? ? ? ? ? ? NetArpWaitReplyIP = NetArpWaitPacketIP;
+ ? ? ? ? ? ? ? } else {
+ ? ? ? ? ? ? ? ? ? ? ? NetArpWaitReplyIP = NetOurGatewayIP;
+ ? ? ? ? ? ? ? }
+ ? ? ? } else {
+ ? ? ? ? ? ? ? NetArpWaitReplyIP = NetArpWaitPacketIP;
+ ? ? ? }
+
+ ? ? ? NetWriteIP((uchar *) &arp->ar_data[16], NetArpWaitReplyIP);
+ ? ? ? (void) eth_send(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
+}
+
+void ArpTimeoutCheck(void)
+{
+ ? ? ? ulong t;
+
+ ? ? ? if (!NetArpWaitPacketIP)
+ ? ? ? ? ? ? ? return;
+
+ ? ? ? t = get_timer(0);
+
+ ? ? ? /* check for arp timeout */
+ ? ? ? if ((t - NetArpWaitTimerStart) > ARP_TIMEOUT) {
+ ? ? ? ? ? ? ? NetArpWaitTry++;
+
+ ? ? ? ? ? ? ? if (NetArpWaitTry >= ARP_TIMEOUT_COUNT) {
+ ? ? ? ? ? ? ? ? ? ? ? puts("\nARP Retry count exceeded; starting again\n");
+ ? ? ? ? ? ? ? ? ? ? ? NetArpWaitTry = 0;
+ ? ? ? ? ? ? ? ? ? ? ? NetStartAgain();
+ ? ? ? ? ? ? ? } else {
+ ? ? ? ? ? ? ? ? ? ? ? NetArpWaitTimerStart = t;
+ ? ? ? ? ? ? ? ? ? ? ? ArpRequest();
+ ? ? ? ? ? ? ? }
+ ? ? ? }
+}
+
+void ArpReceive(Ethernet_t *et, IP_t *ip, int len)
+{
+ ? ? ? ARP_t *arp;
+ ? ? ? IPaddr_t tmp;
+ ? ? ? uchar *pkt;
+
+ ? ? ? /*
+ ? ? ? ?* We have to deal with two types of ARP packets:
+ ? ? ? ?* - REQUEST packets will be answered by sending ?our
+ ? ? ? ?* ? IP address - if we know it.
+ ? ? ? ?* - REPLY packates are expected only after we asked
+ ? ? ? ?* ? for the TFTP server's or the gateway's ethernet
+ ? ? ? ?* ? address; so if we receive such a packet, we set
+ ? ? ? ?* ? the server ethernet address
+ ? ? ? ?*/
+ ? ? ? debug("Got ARP\n");
+
+ ? ? ? arp = (ARP_t *)ip;
+ ? ? ? if (len < ARP_HDR_SIZE) {
+ ? ? ? ? ? ? ? printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
+ ? ? ? ? ? ? ? return;
+ ? ? ? }
+ ? ? ? if (ntohs(arp->ar_hrd) != ARP_ETHER)
+ ? ? ? ? ? ? ? return;
+ ? ? ? if (ntohs(arp->ar_pro) != PROT_IP)
+ ? ? ? ? ? ? ? return;
+ ? ? ? if (arp->ar_hln != 6)
+ ? ? ? ? ? ? ? return;
+ ? ? ? if (arp->ar_pln != 4)
+ ? ? ? ? ? ? ? return;
+
+ ? ? ? if (NetOurIP == 0)
+ ? ? ? ? ? ? ? return;
+
+ ? ? ? if (NetReadIP(&arp->ar_data[16]) != NetOurIP)
+ ? ? ? ? ? ? ? return;
+
+ ? ? ? switch (ntohs(arp->ar_op)) {
+ ? ? ? case ARPOP_REQUEST:
+ ? ? ? ? ? ? ? /* reply with our IP address */
+ ? ? ? ? ? ? ? debug("Got ARP REQUEST, return our IP\n");
+ ? ? ? ? ? ? ? pkt = (uchar *)et;
+ ? ? ? ? ? ? ? pkt += NetSetEther(pkt, et->et_src, PROT_ARP);
+ ? ? ? ? ? ? ? arp->ar_op = htons(ARPOP_REPLY);
+ ? ? ? ? ? ? ? memcpy(&arp->ar_data[10], &arp->ar_data[0], 6);
+ ? ? ? ? ? ? ? NetCopyIP(&arp->ar_data[16], &arp->ar_data[6]);
+ ? ? ? ? ? ? ? memcpy(&arp->ar_data[0], NetOurEther, 6);
+ ? ? ? ? ? ? ? NetCopyIP(&arp->ar_data[6], &NetOurIP);
+ ? ? ? ? ? ? ? (void) eth_send((uchar *)et,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (pkt - (uchar *)et) + ARP_HDR_SIZE);
+ ? ? ? ? ? ? ? return;
+
+ ? ? ? case ARPOP_REPLY: ? ? ? ? ? ? ? /* arp reply */
+ ? ? ? ? ? ? ? /* are we waiting for a reply */
+ ? ? ? ? ? ? ? if (!NetArpWaitPacketIP || !NetArpWaitPacketMAC)
+ ? ? ? ? ? ? ? ? ? ? ? break;
+
+#ifdef CONFIG_KEEP_SERVERADDR
+ ? ? ? ? ? ? ? if (NetServerIP == NetArpWaitPacketIP) {
+ ? ? ? ? ? ? ? ? ? ? ? char buf[20];
+ ? ? ? ? ? ? ? ? ? ? ? sprintf(buf, "%pM", arp->ar_data);
+ ? ? ? ? ? ? ? ? ? ? ? setenv("serveraddr", buf);
+ ? ? ? ? ? ? ? }
+#endif
+
+ ? ? ? ? ? ? ? tmp = NetReadIP(&arp->ar_data[6]);
+
+ ? ? ? ? ? ? ? /* matched waiting packet's address */
+ ? ? ? ? ? ? ? if (tmp == NetArpWaitReplyIP) {
+ ? ? ? ? ? ? ? ? ? ? ? debug("Got ARP REPLY, set eth addr (%pM)\n",
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? arp->ar_data);
+
+ ? ? ? ? ? ? ? ? ? ? ? /* save address for later use */
+ ? ? ? ? ? ? ? ? ? ? ? memcpy(NetArpWaitPacketMAC,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?&arp->ar_data[0], 6);
+
+#ifdef CONFIG_NETCONSOLE
+ ? ? ? ? ? ? ? ? ? ? ? NetGetHandler()(0, 0, 0, 0, 0);
+#endif
+ ? ? ? ? ? ? ? ? ? ? ? /* modify header, and transmit it */
+ ? ? ? ? ? ? ? ? ? ? ? memcpy(((Ethernet_t *)NetArpWaitTxPacket)->
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_dest, NetArpWaitPacketMAC, 6);
+ ? ? ? ? ? ? ? ? ? ? ? (void) eth_send(NetArpWaitTxPacket,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NetArpWaitTxPacketSize);
+
+ ? ? ? ? ? ? ? ? ? ? ? /* no arp request pending now */
+ ? ? ? ? ? ? ? ? ? ? ? NetArpWaitPacketIP = 0;
+ ? ? ? ? ? ? ? ? ? ? ? NetArpWaitTxPacketSize = 0;
+ ? ? ? ? ? ? ? ? ? ? ? NetArpWaitPacketMAC = NULL;
+
+ ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? return;
+ ? ? ? default:
+ ? ? ? ? ? ? ? debug("Unexpected ARP opcode 0x%x\n",
+ ? ? ? ? ? ? ? ? ? ? ntohs(arp->ar_op));
+ ? ? ? ? ? ? ? return;
+ ? ? ? }
+}
net/arp.h new file +30 -0
new file mode 100644
index 0000000..09c763d
@@ -0,0 +1,30 @@
+/*
+ * ? ? Copied from Linux Monitor (LiMon) - Networking.
+ *
+ * ? ? Copyright 1994 - 2000 Neil Russell.
+ * ? ? (See License)
+ * ? ? Copyright 2000 Roland Borde
+ * ? ? Copyright 2000 Paolo Scaffardi
+ * ? ? Copyright 2000-2002 Wolfgang Denk, wd at denx.de
+ */
+
+#ifndef __ARP_H__
+#define __ARP_H__
+
+#include <net.h>
+
+extern IPaddr_t ? ? ? ?NetArpWaitPacketIP;
+/* MAC address of waiting packet's destination */
+extern uchar *NetArpWaitPacketMAC;
+/* THE transmit packet */
+extern uchar *NetArpWaitTxPacket;
+extern int NetArpWaitTxPacketSize;
+extern ulong NetArpWaitTimerStart;
+extern int NetArpWaitTry;
+
+void ArpInit(void);
+void ArpRequest(void);
+void ArpTimeoutCheck(void);
+void ArpReceive(Ethernet_t *et, IP_t *ip, int len);
+
+#endif /* __ARP_H__ */
net/net.c +0 -0
index 48d3ca8..2dae5a0 100644
@@ -78,6 +78,7 @@

?#include <watchdog.h>
?#include <command.h>
?#include <net.h>
+#include "arp.h"
?#include "bootp.h"
?#include "tftp.h"
?#ifdef CONFIG_CMD_RARP

net/net.c +0 -14
@@ -100,20 +101,6 @@
 
 ?DECLARE_GLOBAL_DATA_PTR;
 
-#ifndef ? ? ? ?CONFIG_ARP_TIMEOUT
-/* Milliseconds before trying ARP again */
-# define ARP_TIMEOUT ? ? ? ? ? 5000UL
-#else
-# define ARP_TIMEOUT ? ? ? ? ? CONFIG_ARP_TIMEOUT
-#endif
-
-
-#ifndef ? ? ? ?CONFIG_NET_RETRY_COUNT
-# define ARP_TIMEOUT_COUNT ? ? 5 ? ? ? /* # of timeouts before giving up ?*/
-#else
-# define ARP_TIMEOUT_COUNT ? ? CONFIG_NET_RETRY_COUNT
-#endif
-

?/** BOOTP EXTENTIONS **/

?/* Our subnet mask (0=unknown) */

net/net.c +0 -0
@@ -220,82 +207,6 @@ static int NetTryCount;
 

?/**********************************************************************/

net/net.c +0 -76
-IPaddr_t ? ? ? NetArpWaitPacketIP;
-IPaddr_t ? ? ? NetArpWaitReplyIP;
-/* MAC address of waiting packet's destination */
-uchar ? ? ? ? *NetArpWaitPacketMAC;
-/* THE transmit packet */
-uchar ? ? ? ? *NetArpWaitTxPacket;
-int ? ? ? ? ? ?NetArpWaitTxPacketSize;
-uchar ? ? ? ? ?NetArpWaitPacketBuf[PKTSIZE_ALIGN + PKTALIGN];
-ulong ? ? ? ? ?NetArpWaitTimerStart;
-int ? ? ? ? ? ?NetArpWaitTry;
-
-void ArpRequest(void)
-{
- ? ? ? uchar *pkt;
- ? ? ? ARP_t *arp;
-
- ? ? ? debug("ARP broadcast %d\n", NetArpWaitTry);
-
- ? ? ? pkt = NetTxPacket;
-
- ? ? ? pkt += NetSetEther(pkt, NetBcastAddr, PROT_ARP);
-
- ? ? ? arp = (ARP_t *) pkt;
-
- ? ? ? arp->ar_hrd = htons(ARP_ETHER);
- ? ? ? arp->ar_pro = htons(PROT_IP);
- ? ? ? arp->ar_hln = 6;
- ? ? ? arp->ar_pln = 4;
- ? ? ? arp->ar_op = htons(ARPOP_REQUEST);
-
- ? ? ? /* source ET addr */
- ? ? ? memcpy(&arp->ar_data[0], NetOurEther, 6);
- ? ? ? /* source IP addr */
- ? ? ? NetWriteIP((uchar *) &arp->ar_data[6], NetOurIP);
- ? ? ? /* dest ET addr = 0 */
- ? ? ? memset(&arp->ar_data[10], '\0', 6);
- ? ? ? if ((NetArpWaitPacketIP & NetOurSubnetMask) !=
- ? ? ? ? ? (NetOurIP & NetOurSubnetMask)) {
- ? ? ? ? ? ? ? if (NetOurGatewayIP == 0) {
- ? ? ? ? ? ? ? ? ? ? ? puts("## Warning: gatewayip needed but not set\n");
- ? ? ? ? ? ? ? ? ? ? ? NetArpWaitReplyIP = NetArpWaitPacketIP;
- ? ? ? ? ? ? ? } else {
- ? ? ? ? ? ? ? ? ? ? ? NetArpWaitReplyIP = NetOurGatewayIP;
- ? ? ? ? ? ? ? }
- ? ? ? } else {
- ? ? ? ? ? ? ? NetArpWaitReplyIP = NetArpWaitPacketIP;
- ? ? ? }
-
- ? ? ? NetWriteIP((uchar *) &arp->ar_data[16], NetArpWaitReplyIP);
- ? ? ? (void) eth_send(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
-}
-
-void ArpTimeoutCheck(void)
-{
- ? ? ? ulong t;
-
- ? ? ? if (!NetArpWaitPacketIP)
- ? ? ? ? ? ? ? return;
-
- ? ? ? t = get_timer(0);
-
- ? ? ? /* check for arp timeout */
- ? ? ? if ((t - NetArpWaitTimerStart) > ARP_TIMEOUT) {
- ? ? ? ? ? ? ? NetArpWaitTry++;
-
- ? ? ? ? ? ? ? if (NetArpWaitTry >= ARP_TIMEOUT_COUNT) {
- ? ? ? ? ? ? ? ? ? ? ? puts("\nARP Retry count exceeded; starting again\n");
- ? ? ? ? ? ? ? ? ? ? ? NetArpWaitTry = 0;
- ? ? ? ? ? ? ? ? ? ? ? NetStartAgain();
- ? ? ? ? ? ? ? } else {
- ? ? ? ? ? ? ? ? ? ? ? NetArpWaitTimerStart = t;
- ? ? ? ? ? ? ? ? ? ? ? ArpRequest();
- ? ? ? ? ? ? ? }
- ? ? ? }
-}
-

?/*
?* Check if autoload is enabled. If so, use either NFS or TFTP to download ?* the boot file.

net/net.c +2 -6
@@ -363,15 +274,11 @@ int NetLoop(enum proto_t protocol)
 ? ? ? ?NetRestarted = 0;
 ? ? ? ?NetDevExists = 0;
 
- ? ? ? /* XXX problem with bss workaround */
- ? ? ? NetArpWaitPacketMAC = NULL;
- ? ? ? NetArpWaitTxPacket = NULL;
- ? ? ? NetArpWaitPacketIP = 0;
- ? ? ? NetArpWaitReplyIP = 0;
- ? ? ? NetArpWaitTxPacket = NULL;
 ? ? ? ?NetTxPacket = NULL;
 ? ? ? ?NetTryCount = 1;
 
+ ? ? ? ArpInit();
+
 ? ? ? ?if (!NetTxPacket) {
 ? ? ? ? ? ? ? ?int ? ? i;

? ? ? ? ? ? ? ?/*

net/net.c +0 -6
@@ -383,12 +290,6 @@ int NetLoop(enum proto_t protocol)
 ? ? ? ? ? ? ? ? ? ? ? ?NetRxPackets[i] = NetTxPacket + (i+1)*PKTSIZE_ALIGN;
 ? ? ? ?}
 
- ? ? ? if (!NetArpWaitTxPacket) {
- ? ? ? ? ? ? ? NetArpWaitTxPacket = &NetArpWaitPacketBuf[0] + (PKTALIGN - 1);
- ? ? ? ? ? ? ? NetArpWaitTxPacket -= (ulong)NetArpWaitTxPacket % PKTALIGN;
- ? ? ? ? ? ? ? NetArpWaitTxPacketSize = 0;
- ? ? ? }
-
 ? ? ? ?eth_halt();
 ? ? ? ?eth_set_current();
 ? ? ? ?if (eth_init(bd) < 0) {
@@ -661,6 +562,13 @@ void NetStartAgain(void)

?* ? ? Miscelaneous bits.
?*/

net/net.c +7 -0
+rxhand_f *
+NetGetHandler(void)
+{
+ ? ? ? return packetHandler;
+}
+
+

?void
?NetSetHandler(rxhand_f *f)
?{

net/net.c +2 -1
@@ -1072,11 +980,12 @@ NetReceive(volatile uchar *inpkt, int len)
 ?{
 ? ? ? ?Ethernet_t *et;
 ? ? ? ?IP_t ? ?*ip;
+#ifdef CONFIG_CMD_RARP
 ? ? ? ?ARP_t ? *arp;
+#endif
 ? ? ? ?IPaddr_t tmp;
 ? ? ? ?IPaddr_t src_ip;
 ? ? ? ?int ? ? x;
- ? ? ? uchar *pkt;
 ?#if defined(CONFIG_CMD_CDP)
 ? ? ? ?int iscdp;

?#endif

net/net.c +0 -0
@@ -1173,99 +1082,7 @@ NetReceive(volatile uchar *inpkt, int len)
 ? ? ? ?switch (x) {
 

? ? ? ?case PROT_ARP:
- ? ? ? ? ? ? ? /*
- ? ? ? ? ? ? ? ?* We have to deal with two types of ARP packets:
- ? ? ? ? ? ? ? ?* - REQUEST packets will be answered by sending ?our
- ? ? ? ? ? ? ? ?* ? IP address - if we know it.
- ? ? ? ? ? ? ? ?* - REPLY packates are expected only after we asked
- ? ? ? ? ? ? ? ?* ? for the TFTP server's or the gateway's ethernet
- ? ? ? ? ? ? ? ?* ? address; so if we receive such a packet, we set
- ? ? ? ? ? ? ? ?* ? the server ethernet address
- ? ? ? ? ? ? ? ?*/
- ? ? ? ? ? ? ? debug("Got ARP\n");

net/net.c +1 -83
-
- ? ? ? ? ? ? ? arp = (ARP_t *)ip;
- ? ? ? ? ? ? ? if (len < ARP_HDR_SIZE) {
- ? ? ? ? ? ? ? ? ? ? ? printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
- ? ? ? ? ? ? ? ? ? ? ? return;
- ? ? ? ? ? ? ? }
- ? ? ? ? ? ? ? if (ntohs(arp->ar_hrd) != ARP_ETHER)
- ? ? ? ? ? ? ? ? ? ? ? return;
- ? ? ? ? ? ? ? if (ntohs(arp->ar_pro) != PROT_IP)
- ? ? ? ? ? ? ? ? ? ? ? return;
- ? ? ? ? ? ? ? if (arp->ar_hln != 6)
- ? ? ? ? ? ? ? ? ? ? ? return;
- ? ? ? ? ? ? ? if (arp->ar_pln != 4)
- ? ? ? ? ? ? ? ? ? ? ? return;
-
- ? ? ? ? ? ? ? if (NetOurIP == 0)
- ? ? ? ? ? ? ? ? ? ? ? return;
-
- ? ? ? ? ? ? ? if (NetReadIP(&arp->ar_data[16]) != NetOurIP)
- ? ? ? ? ? ? ? ? ? ? ? return;
-
- ? ? ? ? ? ? ? switch (ntohs(arp->ar_op)) {
- ? ? ? ? ? ? ? case ARPOP_REQUEST:
- ? ? ? ? ? ? ? ? ? ? ? /* reply with our IP address */
- ? ? ? ? ? ? ? ? ? ? ? debug("Got ARP REQUEST, return our IP\n");
- ? ? ? ? ? ? ? ? ? ? ? pkt = (uchar *)et;
- ? ? ? ? ? ? ? ? ? ? ? pkt += NetSetEther(pkt, et->et_src, PROT_ARP);
- ? ? ? ? ? ? ? ? ? ? ? arp->ar_op = htons(ARPOP_REPLY);
- ? ? ? ? ? ? ? ? ? ? ? memcpy(&arp->ar_data[10], &arp->ar_data[0], 6);
- ? ? ? ? ? ? ? ? ? ? ? NetCopyIP(&arp->ar_data[16], &arp->ar_data[6]);
- ? ? ? ? ? ? ? ? ? ? ? memcpy(&arp->ar_data[0], NetOurEther, 6);
- ? ? ? ? ? ? ? ? ? ? ? NetCopyIP(&arp->ar_data[6], &NetOurIP);
- ? ? ? ? ? ? ? ? ? ? ? (void) eth_send((uchar *)et,
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (pkt - (uchar *)et) + ARP_HDR_SIZE);
- ? ? ? ? ? ? ? ? ? ? ? return;
-
- ? ? ? ? ? ? ? case ARPOP_REPLY: ? ? ? ? ? ? ? /* arp reply */
- ? ? ? ? ? ? ? ? ? ? ? /* are we waiting for a reply */
- ? ? ? ? ? ? ? ? ? ? ? if (!NetArpWaitPacketIP || !NetArpWaitPacketMAC)
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
-
-#ifdef CONFIG_KEEP_SERVERADDR
- ? ? ? ? ? ? ? ? ? ? ? if (NetServerIP == NetArpWaitPacketIP) {
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? char buf[20];
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sprintf(buf, "%pM", arp->ar_data);
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? setenv("serveraddr", buf);
- ? ? ? ? ? ? ? ? ? ? ? }
-#endif
-
- ? ? ? ? ? ? ? ? ? ? ? debug("Got ARP REPLY, set server/gtwy eth addr (%pM)\n",
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? arp->ar_data);
-
- ? ? ? ? ? ? ? ? ? ? ? tmp = NetReadIP(&arp->ar_data[6]);
-
- ? ? ? ? ? ? ? ? ? ? ? /* matched waiting packet's address */
- ? ? ? ? ? ? ? ? ? ? ? if (tmp == NetArpWaitReplyIP) {
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? debug("Got it\n");
-
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* save address for later use */
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? memcpy(NetArpWaitPacketMAC,
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?&arp->ar_data[0], 6);
-
-#ifdef CONFIG_NETCONSOLE
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (*packetHandler)(0, 0, 0, 0, 0);
-#endif
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* modify header, and transmit it */
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? memcpy(((Ethernet_t *)NetArpWaitTxPacket)->
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_dest, NetArpWaitPacketMAC, 6);
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (void) eth_send(NetArpWaitTxPacket,
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NetArpWaitTxPacketSize);
-
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* no arp request pending now */
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NetArpWaitPacketIP = 0;
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NetArpWaitTxPacketSize = 0;
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NetArpWaitPacketMAC = NULL;
-
- ? ? ? ? ? ? ? ? ? ? ? }
- ? ? ? ? ? ? ? ? ? ? ? return;
- ? ? ? ? ? ? ? default:
- ? ? ? ? ? ? ? ? ? ? ? debug("Unexpected ARP opcode 0x%x\n",
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ntohs(arp->ar_op));
- ? ? ? ? ? ? ? ? ? ? ? return;
- ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? ArpReceive(et, ip, len);

? ? ? ? ? ? ? ?break;

?#ifdef CONFIG_CMD_RARP
--
1.6.0.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#29 lore raw

PATCH 7/28 net: Move PING out of net.c

In reply to Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 include/configs/am3517_crane.h |    2 +-
 include/configs/am3517_evm.h   |    2 +-
 include/configs/origen.h       |    2 +-
 net/Makefile                   |    1 +
 net/net.c                      |  133 ++-----------------------------------
 net/ping.c                     |  143 ++++++++++++++++++++++++++++++++++++++++
 net/ping.h                     |   20 ++++++
 7 files changed, 172 insertions(+), 131 deletions(-)
 create mode 100644 net/ping.c
 create mode 100644 net/ping.h
include/configs/am3517_crane.h +1 -1
index 0a0c261..acd4e3f 100644
@@ -146,7 +146,7 @@
 #define CONFIG_CMD_MMC		/* MMC support			*/
 #define CONFIG_CMD_NAND		/* NAND support			*/
 #define CONFIG_CMD_DHCP
-#define CONFIG_CMD_PING
+#undef CONFIG_CMD_PING
 
 #undef CONFIG_CMD_FLASH		/* flinfo, erase, protect	*/
 #undef CONFIG_CMD_FPGA		/* FPGA configuration Support	*/
include/configs/am3517_evm.h +1 -1
index d44eeec..9775107 100644
@@ -145,7 +145,7 @@
 #define CONFIG_CMD_MMC		/* MMC support			*/
 #define CONFIG_CMD_NAND		/* NAND support			*/
 #define CONFIG_CMD_DHCP
-#define CONFIG_CMD_PING
+#undef CONFIG_CMD_PING
 
 #undef CONFIG_CMD_FLASH		/* flinfo, erase, protect	*/
 #undef CONFIG_CMD_FPGA		/* FPGA configuration Support	*/
include/configs/origen.h +1 -1
index cd502d1..c9bac30 100644
@@ -84,7 +84,7 @@
 /* Command definition*/
 #include <config_cmd_default.h>
 
-#define CONFIG_CMD_PING
+#undef CONFIG_CMD_PING
 #define CONFIG_CMD_ELF
 #define CONFIG_CMD_DHCP
 #define CONFIG_CMD_MMC
net/Makefile +1 -0
index 0916a56..f1c4859 100644
@@ -35,6 +35,7 @@ COBJS-$(CONFIG_CMD_NET)  += eth.o
 COBJS-$(CONFIG_CMD_NET)  += net.o
 COBJS-$(CONFIG_BOOTP_RANDOM_DELAY) += net_rand.o
 COBJS-$(CONFIG_CMD_NFS)  += nfs.o
+COBJS-$(CONFIG_CMD_PING) += ping.o
 COBJS-$(CONFIG_CMD_RARP) += rarp.o
 COBJS-$(CONFIG_CMD_SNTP) += sntp.o
 COBJS-$(CONFIG_CMD_NET)  += tftp.o
net/net.c +5 -128

159 lines not on this page · raw message

net/ping.c new file +143 -0

143 lines not on this page · raw message

net/ping.h new file +20 -0
new file mode 100644
index 0000000..56aad43
@@ -0,0 +1,20 @@
+/*
+ *	Copied from Linux Monitor (LiMon) - Networking.
+ *
+ *	Copyright 1994 - 2000 Neil Russell.
+ *	(See License)
+ *	Copyright 2000 Roland Borde
+ *	Copyright 2000 Paolo Scaffardi
+ *	Copyright 2000-2002 Wolfgang Denk, wd at denx.de
+ */
+
+#ifndef __PING_H__
+#define __PING_H__
+
+#include <common.h>
+#include <net.h>
+
+void PingStart(void);
+void PingReceive(Ethernet_t *et, IP_t *ip, int len);
+
+#endif /* __PING_H__ */
Signature · 1 line
1.6.0.2
#30 lore raw

PATCH 7/28 net: Move PING out of net.c

Hi Joe,

Quoted 7 lines · Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

?include/configs/am3517_crane.h | ? ?2 +-
?include/configs/am3517_evm.h ? | ? ?2 +-
?include/configs/origen.h ? ? ? | ? ?2 +-

Perhaps move these config changes to another commit?

It would be nice (perhaps later) to remove the camel case.

Regards,
Simon

Quoted 408 lines
?net/Makefile ? ? ? ? ? ? ? ? ? | ? ?1 +
?net/net.c ? ? ? ? ? ? ? ? ? ? ?| ?133 ++-----------------------------------
?net/ping.c ? ? ? ? ? ? ? ? ? ? | ?143 ++++++++++++++++++++++++++++++++++++++++
?net/ping.h ? ? ? ? ? ? ? ? ? ? | ? 20 ++++++

?7 files changed, 172 insertions(+), 131 deletions(-) ?create mode 100644 net/ping.c
?create mode 100644 net/ping.h

include/configs/am3517_crane.h +0 -0
index 0a0c261..acd4e3f 100644
@@ -146,7 +146,7 @@

?#define CONFIG_CMD_MMC ? ? ? ? /* MMC support ? ? ? ? ? ? ? ? ?*/ ?#define CONFIG_CMD_NAND ? ? ? ? ? ? ? ?/* NAND support ? ? ? ? ? ? ? ? */ ?#define CONFIG_CMD_DHCP

include/configs/am3517_crane.h +1 -1
-#define CONFIG_CMD_PING
+#undef CONFIG_CMD_PING

?#undef CONFIG_CMD_FLASH ? ? ? ? ? ? ? ?/* flinfo, erase, protect ? ? ? */ ?#undef CONFIG_CMD_FPGA ? ? ? ? /* FPGA configuration Support ? */

include/configs/am3517_evm.h +0 -0
index d44eeec..9775107 100644
@@ -145,7 +145,7 @@

?#define CONFIG_CMD_MMC ? ? ? ? /* MMC support ? ? ? ? ? ? ? ? ?*/ ?#define CONFIG_CMD_NAND ? ? ? ? ? ? ? ?/* NAND support ? ? ? ? ? ? ? ? */ ?#define CONFIG_CMD_DHCP

include/configs/am3517_evm.h +1 -1
-#define CONFIG_CMD_PING
+#undef CONFIG_CMD_PING

?#undef CONFIG_CMD_FLASH ? ? ? ? ? ? ? ?/* flinfo, erase, protect ? ? ? */ ?#undef CONFIG_CMD_FPGA ? ? ? ? /* FPGA configuration Support ? */

include/configs/origen.h +0 -0
index cd502d1..c9bac30 100644
@@ -84,7 +84,7 @@

?/* Command definition*/
?#include <config_cmd_default.h>

include/configs/origen.h +1 -1
-#define CONFIG_CMD_PING
+#undef CONFIG_CMD_PING

?#define CONFIG_CMD_ELF
?#define CONFIG_CMD_DHCP
?#define CONFIG_CMD_MMC

net/Makefile +0 -0
index 0916a56..f1c4859 100644
@@ -35,6 +35,7 @@ COBJS-$(CONFIG_CMD_NET) ?+= eth.o

?COBJS-$(CONFIG_CMD_NET) ?+= net.o
?COBJS-$(CONFIG_BOOTP_RANDOM_DELAY) += net_rand.o
?COBJS-$(CONFIG_CMD_NFS) ?+= nfs.o
+COBJS-$(CONFIG_CMD_PING) += ping.o
?COBJS-$(CONFIG_CMD_RARP) += rarp.o
?COBJS-$(CONFIG_CMD_SNTP) += sntp.o
?COBJS-$(CONFIG_CMD_NET) ?+= tftp.o

net/net.c +0 -0
index 2dae5a0..c2fbcb5 100644
@@ -98,6 +98,9 @@
 ?#if defined(CONFIG_CMD_DNS)

?#include "dns.h"
?#endif

net/net.c +3 -0
+#if defined(CONFIG_CMD_PING)
+#include "ping.h"
+#endif

?DECLARE_GLOBAL_DATA_PTR;

net/net.c +0 -0
@@ -168,13 +171,6 @@ ushort ? ? ? ? ? ? NetOurNativeVLAN = 0xFFFF;

?/* Boot File name */
?char ? ? ? ? ? BootFile[128];

net/net.c +0 -7
-#if defined(CONFIG_CMD_PING)
-/* the ip address to ping */
-IPaddr_t ? ? ? NetPingIP;
-
-static void PingStart(void);
-#endif
-

?#if defined(CONFIG_CMD_SNTP)
?/* NTP server IP address */
?IPaddr_t ? ? ? NetNtpServerIP;

net/net.c +0 -0
@@ -653,94 +649,6 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)

? ? ? ?return 0; ? ? ? /* transmitted */
?}

net/net.c +0 -88
-#if defined(CONFIG_CMD_PING)
-static ushort PingSeqNo;
-
-int PingSend(void)
-{
- ? ? ? static uchar mac[6];
- ? ? ? IP_t *ip;
- ? ? ? ushort *s;
- ? ? ? uchar *pkt;
-
- ? ? ? /* XXX always send arp request */
-
- ? ? ? memcpy(mac, NetEtherNullAddr, 6);
-
- ? ? ? debug("sending ARP for %08x\n", NetPingIP);
-
- ? ? ? NetArpWaitPacketIP = NetPingIP;
- ? ? ? NetArpWaitPacketMAC = mac;
-
- ? ? ? pkt = NetArpWaitTxPacket;
- ? ? ? pkt += NetSetEther(pkt, mac, PROT_IP);
-
- ? ? ? ip = (IP_t *)pkt;
-
- ? ? ? /*
- ? ? ? ?* Construct an IP and ICMP header.
- ? ? ? ?* (need to set no fragment bit - XXX)
- ? ? ? ?*/
- ? ? ? /* IP_HDR_SIZE / 4 (not including UDP) */
- ? ? ? ip->ip_hl_v ?= 0x45;
- ? ? ? ip->ip_tos ? = 0;
- ? ? ? ip->ip_len ? = htons(IP_HDR_SIZE_NO_UDP + 8);
- ? ? ? ip->ip_id ? ?= htons(NetIPID++);
- ? ? ? ip->ip_off ? = htons(IP_FLAGS_DFRAG); ? /* Don't fragment */
- ? ? ? ip->ip_ttl ? = 255;
- ? ? ? ip->ip_p ? ? = 0x01; ? ? ? ? ? ?/* ICMP */
- ? ? ? ip->ip_sum ? = 0;
- ? ? ? /* already in network byte order */
- ? ? ? NetCopyIP((void *)&ip->ip_src, &NetOurIP);
- ? ? ? /* - "" - */
- ? ? ? NetCopyIP((void *)&ip->ip_dst, &NetPingIP);
- ? ? ? ip->ip_sum ? = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
-
- ? ? ? s = &ip->udp_src; ? ? ? ? ? ? ? /* XXX ICMP starts here */
- ? ? ? s[0] = htons(0x0800); ? ? ? ? ? /* echo-request, code */
- ? ? ? s[1] = 0; ? ? ? ? ? ? ? ? ? ? ? /* checksum */
- ? ? ? s[2] = 0; ? ? ? ? ? ? ? ? ? ? ? /* identifier */
- ? ? ? s[3] = htons(PingSeqNo++); ? ? ?/* sequence number */
- ? ? ? s[1] = ~NetCksum((uchar *)s, 8/2);
-
- ? ? ? /* size of the waiting packet */
- ? ? ? NetArpWaitTxPacketSize =
- ? ? ? ? ? ? ? (pkt - NetArpWaitTxPacket) + IP_HDR_SIZE_NO_UDP + 8;
-
- ? ? ? /* and do the ARP request */
- ? ? ? NetArpWaitTry = 1;
- ? ? ? NetArpWaitTimerStart = get_timer(0);
- ? ? ? ArpRequest();
- ? ? ? return 1; ? ? ? /* waiting */
-}
-
-static void
-PingTimeout(void)
-{
- ? ? ? eth_halt();
- ? ? ? NetState = NETLOOP_FAIL; ? ? ? ?/* we did not get the reply */
-}
-
-static void
-PingHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
- ? ? ? ? ? unsigned len)
-{
- ? ? ? if (sip != NetPingIP)
- ? ? ? ? ? ? ? return;
-
- ? ? ? NetState = NETLOOP_SUCCESS;
-}
-
-static void PingStart(void)
-{
- ? ? ? printf("Using %s device\n", eth_get_name());
- ? ? ? NetSetTimeout(10000UL, PingTimeout);
- ? ? ? NetSetHandler(PingHandler);
-
- ? ? ? PingSend();
-}
-#endif
-

?#ifdef CONFIG_IP_DEFRAG
?/*
?* This function collects fragments in a single packet, according

net/net.c +2 -32
@@ -930,41 +838,10 @@ static void receive_icmp(IP_t *ip, int len, IPaddr_t src_ip, Ethernet_t *et)
 ? ? ? ? ? ? ? ?printf(" ICMP Host Redirect to %pI4 ",
 ? ? ? ? ? ? ? ? ? ? ? ?&icmph->un.gateway);
 ? ? ? ? ? ? ? ?break;
+ ? ? ? default:
 ?#if defined(CONFIG_CMD_PING)
- ? ? ? case ICMP_ECHO_REPLY:
- ? ? ? ? ? ? ? /*
- ? ? ? ? ? ? ? ? ? ? ? * IP header OK. ?Pass the packet to the
- ? ? ? ? ? ? ? ? ? ? ? * current handler.
- ? ? ? ? ? ? ? ? ? ? ? */
- ? ? ? ? ? ? ? /*
- ? ? ? ? ? ? ? ?* XXX point to ip packet - should this use
- ? ? ? ? ? ? ? ?* packet_icmp_handler?
- ? ? ? ? ? ? ? ?*/
- ? ? ? ? ? ? ? (*packetHandler)((uchar *)ip, 0, src_ip, 0, 0);
- ? ? ? ? ? ? ? break;
- ? ? ? case ICMP_ECHO_REQUEST:
- ? ? ? ? ? ? ? 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);
-
- ? ? ? ? ? ? ? ip->ip_sum = 0;
- ? ? ? ? ? ? ? ip->ip_off = 0;
- ? ? ? ? ? ? ? NetCopyIP((void *)&ip->ip_dst, &ip->ip_src);
- ? ? ? ? ? ? ? NetCopyIP((void *)&ip->ip_src, &NetOurIP);
- ? ? ? ? ? ? ? ip->ip_sum = ~NetCksum((uchar *)ip,
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? IP_HDR_SIZE_NO_UDP >> 1);
-
- ? ? ? ? ? ? ? icmph->type = ICMP_ECHO_REPLY;
- ? ? ? ? ? ? ? icmph->checksum = 0;
- ? ? ? ? ? ? ? icmph->checksum = ~NetCksum((uchar *)icmph,
- ? ? ? ? ? ? ? ? ? ? ? (len - IP_HDR_SIZE_NO_UDP) >> 1);
- ? ? ? ? ? ? ? (void) eth_send((uchar *)et,
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ETHER_HDR_SIZE + len);
- ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? PingReceive(et, ip, len);

?#endif
- ? ? ? default:
?#ifdef CONFIG_CMD_TFTPPUT
? ? ? ? ? ? ? ?if (packet_icmp_handler)
? ? ? ? ? ? ? ? ? ? ? ?packet_icmp_handler(icmph->type, icmph->code,

net/ping.c new file +143 -0
new file mode 100644
index 0000000..4a66b8d
@@ -0,0 +1,143 @@
+/*
+ * ? ? Copied from Linux Monitor (LiMon) - Networking.
+ *
+ * ? ? Copyright 1994 - 2000 Neil Russell.
+ * ? ? (See License)
+ * ? ? Copyright 2000 Roland Borde
+ * ? ? Copyright 2000 Paolo Scaffardi
+ * ? ? Copyright 2000-2002 Wolfgang Denk, wd at denx.de
+ */
+
+#include "ping.h"
+#include "arp.h"
+
+static ushort PingSeqNo;
+
+/* The ip address to ping */
+IPaddr_t NetPingIP;
+
+static int PingSend(void)
+{
+ ? ? ? static uchar mac[6];
+ ? ? ? IP_t *ip;
+ ? ? ? ushort *s;
+ ? ? ? uchar *pkt;
+
+ ? ? ? /* XXX always send arp request */
+
+ ? ? ? memcpy(mac, NetEtherNullAddr, 6);
+
+ ? ? ? debug("sending ARP for %pI4\n", &NetPingIP);
+
+ ? ? ? NetArpWaitPacketIP = NetPingIP;
+ ? ? ? NetArpWaitPacketMAC = mac;
+
+ ? ? ? pkt = NetArpWaitTxPacket;
+ ? ? ? pkt += NetSetEther(pkt, mac, PROT_IP);
+
+ ? ? ? ip = (IP_t *)pkt;
+
+ ? ? ? /*
+ ? ? ? ?* Construct an IP and ICMP header.
+ ? ? ? ?* (need to set no fragment bit - XXX)
+ ? ? ? ?*/
+ ? ? ? /* IP_HDR_SIZE / 4 (not including UDP) */
+ ? ? ? ip->ip_hl_v ?= 0x45;
+ ? ? ? ip->ip_tos ? = 0;
+ ? ? ? ip->ip_len ? = htons(IP_HDR_SIZE_NO_UDP + 8);
+ ? ? ? ip->ip_id ? ?= htons(NetIPID++);
+ ? ? ? ip->ip_off ? = htons(IP_FLAGS_DFRAG); ? /* Don't fragment */
+ ? ? ? ip->ip_ttl ? = 255;
+ ? ? ? ip->ip_p ? ? = 0x01; ? ? ? ? ? ?/* ICMP */
+ ? ? ? ip->ip_sum ? = 0;
+ ? ? ? /* already in network byte order */
+ ? ? ? NetCopyIP((void *)&ip->ip_src, &NetOurIP);
+ ? ? ? /* - "" - */
+ ? ? ? NetCopyIP((void *)&ip->ip_dst, &NetPingIP);
+ ? ? ? ip->ip_sum ? = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
+
+ ? ? ? s = &ip->udp_src; ? ? ? ? ? ? ? /* XXX ICMP starts here */
+ ? ? ? s[0] = htons(0x0800); ? ? ? ? ? /* echo-request, code */
+ ? ? ? s[1] = 0; ? ? ? ? ? ? ? ? ? ? ? /* checksum */
+ ? ? ? s[2] = 0; ? ? ? ? ? ? ? ? ? ? ? /* identifier */
+ ? ? ? s[3] = htons(PingSeqNo++); ? ? ?/* sequence number */
+ ? ? ? s[1] = ~NetCksum((uchar *)s, 8/2);
+
+ ? ? ? /* size of the waiting packet */
+ ? ? ? NetArpWaitTxPacketSize =
+ ? ? ? ? ? ? ? (pkt - NetArpWaitTxPacket) + IP_HDR_SIZE_NO_UDP + 8;
+
+ ? ? ? /* and do the ARP request */
+ ? ? ? NetArpWaitTry = 1;
+ ? ? ? NetArpWaitTimerStart = get_timer(0);
+ ? ? ? ArpRequest();
+ ? ? ? return 1; ? ? ? /* waiting */
+}
+
+static void
+PingTimeout(void)
+{
+ ? ? ? eth_halt();
+ ? ? ? NetState = NETLOOP_FAIL; ? ? ? ?/* we did not get the reply */
+}
+
+static void
+PingHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+ ? ? ? ? ? unsigned len)
+{
+ ? ? ? if (sip != NetPingIP)
+ ? ? ? ? ? ? ? return;
+
+ ? ? ? NetState = NETLOOP_SUCCESS;
+}
+
+void
+PingStart(void)
+{
+ ? ? ? printf("Using %s device\n", eth_get_name());
+ ? ? ? NetSetTimeout(10000UL, PingTimeout);
+ ? ? ? NetSetHandler(PingHandler);
+
+ ? ? ? PingSend();
+}
+
+void PingReceive(Ethernet_t *et, IP_t *ip, int len)
+{
+ ? ? ? ICMP_t *icmph = (ICMP_t *)&(ip->udp_src);
+ ? ? ? IPaddr_t src_ip;
+
+ ? ? ? switch (icmph->type) {
+ ? ? ? case ICMP_ECHO_REPLY:
+ ? ? ? ? ? ? ? /*
+ ? ? ? ? ? ? ? ?* IP header OK. ?Pass the packet to the
+ ? ? ? ? ? ? ? ?* current handler.
+ ? ? ? ? ? ? ? ?*/
+ ? ? ? ? ? ? ? /* XXX point to ip packet */
+ ? ? ? ? ? ? ? src_ip = NetReadIP((void *)&ip->ip_src);
+ ? ? ? ? ? ? ? NetGetHandler()((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);
+
+ ? ? ? ? ? ? ? memcpy(&et->et_dest[0], &et->et_src[0], 6);
+ ? ? ? ? ? ? ? memcpy(&et->et_src[0], NetOurEther, 6);
+
+ ? ? ? ? ? ? ? ip->ip_sum = 0;
+ ? ? ? ? ? ? ? ip->ip_off = 0;
+ ? ? ? ? ? ? ? NetCopyIP((void *)&ip->ip_dst, &ip->ip_src);
+ ? ? ? ? ? ? ? NetCopyIP((void *)&ip->ip_src, &NetOurIP);
+ ? ? ? ? ? ? ? ip->ip_sum = ~NetCksum((uchar *)ip,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?IP_HDR_SIZE_NO_UDP >> 1);
+
+ ? ? ? ? ? ? ? icmph->type = ICMP_ECHO_REPLY;
+ ? ? ? ? ? ? ? icmph->checksum = 0;
+ ? ? ? ? ? ? ? icmph->checksum = ~NetCksum((uchar *)icmph,
+ ? ? ? ? ? ? ? ? ? ? ? (len - IP_HDR_SIZE_NO_UDP) >> 1);
+ ? ? ? ? ? ? ? (void) eth_send((uchar *)et,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ETHER_HDR_SIZE + len);
+ ? ? ? ? ? ? ? return;
+/* ? ? default:
+ ? ? ? ? ? ? ? return;*/
+ ? ? ? }
+}
net/ping.h new file +20 -1
new file mode 100644
index 0000000..56aad43
@@ -0,0 +1,20 @@
+/*
+ * ? ? Copied from Linux Monitor (LiMon) - Networking.
+ *
+ * ? ? Copyright 1994 - 2000 Neil Russell.
+ * ? ? (See License)
+ * ? ? Copyright 2000 Roland Borde
+ * ? ? Copyright 2000 Paolo Scaffardi
+ * ? ? Copyright 2000-2002 Wolfgang Denk, wd at denx.de
+ */
+
+#ifndef __PING_H__
+#define __PING_H__
+
+#include <common.h>
+#include <net.h>
+
+void PingStart(void);
+void PingReceive(Ethernet_t *et, IP_t *ip, int len);
+
+#endif /* __PING_H__ */
--

1.6.0.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#31 lore raw

PATCH 7/28 net: Move PING out of net.c

Quoted 6 lines · On Tuesday 24 January 2012 00:37:51 Simon Glass wrote:
Quoted 3 lines · Joe Hershberger
 include/configs/am3517_crane.h |    2 +-
 include/configs/am3517_evm.h   |    2 +-
 include/configs/origen.h       |    2 +-

Perhaps move these config changes to another commit?

+1
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/a8124e85/attachment.pgp>

#32 lore raw

PATCH 7/28 net: Move PING out of net.c

In reply to Joe Hershberger

net/net.c line 103

Quoted 6 lines · On Thursday 19 January 2012 19:53:10 Joe Hershberger wrote:
net/net.c +3 -0
 
+#if defined(CONFIG_CMD_PING)
+#include "ping.h"
+#endif

please push ifdef down into ping.h header
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/7f9bbef3/attachment.pgp>

#34 lore raw

PATCH 7/28 net: Move PING out of net.c

Hi Mike,

Quoted 2 lines · Mike Frysinger

hmm, thinking a bit more, i wonder if it makes more sense to split all of icmp out of net.c

This would also be fine. Are you thinking that icmp would include all of icmp or would we still have ping separate? Does this need to be done now? It would be quite a bit of churn to move ping changes to a different file first since the changes after the move would have to be manually recreated.

Thanks,
-Joe

#35 lore raw

PATCH 7/28 net: Move PING out of net.c

Quoted 9 lines · On Monday 13 February 2012 18:54:46 Joe Hershberger wrote:
Quoted 2 lines · Mike Frysinger

hmm, thinking a bit more, i wonder if it makes more sense to split all of icmp out of net.c

This would also be fine. Are you thinking that icmp would include all of icmp or would we still have ping separate? Does this need to be done now? It would be quite a bit of churn to move ping changes to a different file first since the changes after the move would have to be manually recreated.

keeping ping.c is fine, but i think we should also have icmp.c broken out of net.c. since we're keeping ping.c, no need to rebase onto a new patch. icmp.c can come after these.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120214/5d7d90d0/attachment.pgp>

#36 lore raw

PATCH 8/28 net: Move RARP receive logic out of net.c

In reply to Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 net/net.c  |   25 +------------------------
 net/rarp.c |   38 +++++++++++++++++++++++++++-----------
 net/rarp.h |    1 +
 3 files changed, 29 insertions(+), 35 deletions(-)
net/net.c +1 -24
index c2fbcb5..fdc1ebe 100644
@@ -857,9 +857,6 @@ NetReceive(volatile uchar *inpkt, int len)
 {
 	Ethernet_t *et;
 	IP_t	*ip;
-#ifdef CONFIG_CMD_RARP
-	ARP_t	*arp;
-#endif
 	IPaddr_t tmp;
 	IPaddr_t src_ip;
 	int	x;
@@ -964,27 +961,7 @@ NetReceive(volatile uchar *inpkt, int len)
 
 #ifdef CONFIG_CMD_RARP
 	case PROT_RARP:
-		debug("Got RARP\n");
-		arp = (ARP_t *)ip;
-		if (len < ARP_HDR_SIZE) {
-			printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
-			return;
-		}
-
-		if ((ntohs(arp->ar_op) != RARPOP_REPLY) ||
-			(ntohs(arp->ar_hrd) != ARP_ETHER)   ||
-			(ntohs(arp->ar_pro) != PROT_IP)     ||
-			(arp->ar_hln != 6) || (arp->ar_pln != 4)) {
-
-			puts("invalid RARP header\n");
-		} else {
-			NetCopyIP(&NetOurIP, &arp->ar_data[16]);
-			if (NetServerIP == 0)
-				NetCopyIP(&NetServerIP, &arp->ar_data[6]);
-			memcpy(NetServerEther, &arp->ar_data[0], 6);
-
-			(*packetHandler)(0, 0, 0, 0, 0);
-		}
+		RarpReceive(ip, len);
 		break;
 #endif
 	case PROT_IP:
net/rarp.c +27 -11
index 5a813a2..761560c 100644
@@ -36,18 +36,37 @@
 # define TIMEOUT_COUNT  (CONFIG_NET_RETRY_COUNT)
 #endif
 
-
 int		RarpTry;
 
 /*
  *	Handle a RARP received packet.
  */
-static void
-RarpHandler(uchar *dummi0, unsigned dummi1, IPaddr_t sip, unsigned dummi2,
-	    unsigned dummi3)
+void
+RarpReceive(IP_t *ip, unsigned len)
 {
-	debug("Got good RARP\n");
-	net_auto_load();
+	ARP_t *arp;
+
+	debug("Got RARP\n");
+	arp = (ARP_t *)ip;
+	if (len < ARP_HDR_SIZE) {
+		printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
+		return;
+	}
+
+	if ((ntohs(arp->ar_op) != RARPOP_REPLY) ||
+		(ntohs(arp->ar_hrd) != ARP_ETHER)   ||
+		(ntohs(arp->ar_pro) != PROT_IP)     ||
+		(arp->ar_hln != 6) || (arp->ar_pln != 4)) {
+
+		puts("invalid RARP header\n");
+	} else {
+		NetCopyIP(&NetOurIP, &arp->ar_data[16]);
+		if (NetServerIP == 0)
+			NetCopyIP(&NetServerIP, &arp->ar_data[6]);
+		memcpy(NetServerEther, &arp->ar_data[0], 6);
+		debug("Got good RARP\n");
+		net_auto_load();
+	}
 }
 
 
@@ -70,7 +89,6 @@ RarpTimeout(void)
 void
 RarpRequest(void)
 {
-	int i;
 	uchar *pkt;
 	ARP_t *rarp;
 
@@ -90,12 +108,10 @@ RarpRequest(void)
 	memcpy(&rarp->ar_data[6],  &NetOurIP,   4);	/* source IP addr */
 	/* dest ET addr = source ET addr ??*/
 	memcpy(&rarp->ar_data[10], NetOurEther, 6);
-	/* dest. IP addr set to broadcast */
-	for (i = 0; i <= 3; i++)
-		rarp->ar_data[16 + i] = 0xff;
+	/* dest IP addr set to broadcast */
+	memset(&rarp->ar_data[16], 0xff,        4);
 
 	NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
 
 	NetSetTimeout(TIMEOUT, RarpTimeout);
-	NetSetHandler(RarpHandler);
 }
net/rarp.h +1 -0
index 4e92d80..0d728dc 100644
@@ -37,6 +37,7 @@
 
 extern int RarpTry;
 
+extern void RarpReceive(IP_t *ip, unsigned len);
 extern void RarpRequest(void);	/* Send a RARP request */
 
 /**********************************************************************/
Signature · 1 line
1.6.0.2
#37 lore raw

PATCH 8/28 net: Move RARP receive logic out of net.c

Quoted 3 lines · Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
Quoted 63 lines

---

?net/net.c ?| ? 25 +------------------------
?net/rarp.c | ? 38 +++++++++++++++++++++++++++-----------
?net/rarp.h | ? ?1 +

?3 files changed, 29 insertions(+), 35 deletions(-)

net/net.c +0 -3
index c2fbcb5..fdc1ebe 100644
@@ -857,9 +857,6 @@ NetReceive(volatile uchar *inpkt, int len)
 ?{
 ? ? ? ?Ethernet_t *et;
 ? ? ? ?IP_t ? ?*ip;
-#ifdef CONFIG_CMD_RARP
- ? ? ? ARP_t ? *arp;
-#endif
 ? ? ? ?IPaddr_t tmp;
 ? ? ? ?IPaddr_t src_ip;
 ? ? ? ?int ? ? x;
@@ -964,27 +961,7 @@ NetReceive(volatile uchar *inpkt, int len)
 

?#ifdef CONFIG_CMD_RARP
? ? ? ?case PROT_RARP:
- ? ? ? ? ? ? ? debug("Got RARP\n");
- ? ? ? ? ? ? ? arp = (ARP_t *)ip;
- ? ? ? ? ? ? ? if (len < ARP_HDR_SIZE) {
- ? ? ? ? ? ? ? ? ? ? ? printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
- ? ? ? ? ? ? ? ? ? ? ? return;
- ? ? ? ? ? ? ? }

net/net.c +1 -15
-
- ? ? ? ? ? ? ? if ((ntohs(arp->ar_op) != RARPOP_REPLY) ||
- ? ? ? ? ? ? ? ? ? ? ? (ntohs(arp->ar_hrd) != ARP_ETHER) ? ||
- ? ? ? ? ? ? ? ? ? ? ? (ntohs(arp->ar_pro) != PROT_IP) ? ? ||
- ? ? ? ? ? ? ? ? ? ? ? (arp->ar_hln != 6) || (arp->ar_pln != 4)) {
-
- ? ? ? ? ? ? ? ? ? ? ? puts("invalid RARP header\n");
- ? ? ? ? ? ? ? } else {
- ? ? ? ? ? ? ? ? ? ? ? NetCopyIP(&NetOurIP, &arp->ar_data[16]);
- ? ? ? ? ? ? ? ? ? ? ? if (NetServerIP == 0)
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NetCopyIP(&NetServerIP, &arp->ar_data[6]);
- ? ? ? ? ? ? ? ? ? ? ? memcpy(NetServerEther, &arp->ar_data[0], 6);
-
- ? ? ? ? ? ? ? ? ? ? ? (*packetHandler)(0, 0, 0, 0, 0);
- ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? RarpReceive(ip, len);

? ? ? ? ? ? ? ?break;
?#endif
? ? ? ?case PROT_IP:

net/rarp.c +0 -0
index 5a813a2..761560c 100644
@@ -36,18 +36,37 @@
 ?# define TIMEOUT_COUNT ?(CONFIG_NET_RETRY_COUNT)

?#endif

-
?int ? ? ? ? ? ?RarpTry;

?/*
?* ? ? Handle a RARP received packet.
?*/

net/rarp.c line 44

Quoted 4 lines
net/rarp.c +1 -3
-static void
-RarpHandler(uchar *dummi0, unsigned dummi1, IPaddr_t sip, unsigned dummi2,
- ? ? ? ? ? unsigned dummi3)
+void

void on same line as function?

Quoted 72 lines

+RarpReceive(IP_t *ip, unsigned len)
?{
- ? ? ? debug("Got good RARP\n");
- ? ? ? net_auto_load();
+ ? ? ? ARP_t *arp;

net/rarp.c +22 -0
+
+ ? ? ? debug("Got RARP\n");
+ ? ? ? arp = (ARP_t *)ip;
+ ? ? ? if (len < ARP_HDR_SIZE) {
+ ? ? ? ? ? ? ? printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
+ ? ? ? ? ? ? ? return;
+ ? ? ? }
+
+ ? ? ? if ((ntohs(arp->ar_op) != RARPOP_REPLY) ||
+ ? ? ? ? ? ? ? (ntohs(arp->ar_hrd) != ARP_ETHER) ? ||
+ ? ? ? ? ? ? ? (ntohs(arp->ar_pro) != PROT_IP) ? ? ||
+ ? ? ? ? ? ? ? (arp->ar_hln != 6) || (arp->ar_pln != 4)) {
+
+ ? ? ? ? ? ? ? puts("invalid RARP header\n");
+ ? ? ? } else {
+ ? ? ? ? ? ? ? NetCopyIP(&NetOurIP, &arp->ar_data[16]);
+ ? ? ? ? ? ? ? if (NetServerIP == 0)
+ ? ? ? ? ? ? ? ? ? ? ? NetCopyIP(&NetServerIP, &arp->ar_data[6]);
+ ? ? ? ? ? ? ? memcpy(NetServerEther, &arp->ar_data[0], 6);
+ ? ? ? ? ? ? ? debug("Got good RARP\n");
+ ? ? ? ? ? ? ? net_auto_load();
+ ? ? ? }

?}

net/rarp.c +0 -0
@@ -70,7 +89,6 @@ RarpTimeout(void)

?void
?RarpRequest(void)
?{
- ? ? ? int i;
? ? ? ?uchar *pkt;
? ? ? ?ARP_t *rarp;

net/rarp.c +0 -0
@@ -90,12 +108,10 @@ RarpRequest(void)

? ? ? ?memcpy(&rarp->ar_data[6], ?&NetOurIP, ? 4); ? ? /* source IP addr */ ? ? ? ?/* dest ET addr = source ET addr ??*/
? ? ? ?memcpy(&rarp->ar_data[10], NetOurEther, 6);
- ? ? ? /* dest. IP addr set to broadcast */
- ? ? ? for (i = 0; i <= 3; i++)
- ? ? ? ? ? ? ? rarp->ar_data[16 + i] = 0xff;
+ ? ? ? /* dest IP addr set to broadcast */
+ ? ? ? memset(&rarp->ar_data[16], 0xff, ? ? ? ?4);

? ? ? ?NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);

? ? ? ?NetSetTimeout(TIMEOUT, RarpTimeout);
- ? ? ? NetSetHandler(RarpHandler);
?}

net/rarp.h +1 -0
index 4e92d80..0d728dc 100644
@@ -37,6 +37,7 @@
 
 ?extern int RarpTry;
 
+extern void RarpReceive(IP_t *ip, unsigned len);

?extern void RarpRequest(void); /* Send a RARP request */

?/**********************************************************************/ --
1.6.0.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#39 lore raw

PATCH 9/28 net: cosmetic: Un-typedef variables in net

In reply to Joe Hershberger

Un-typedef IP_t, Ethernet_t, VLAN_Ethernet_t, ARP_t, ICMP_t Rename IP header related things to IP_UDP
The existing definition of IP_t includes UDP header, so name it to accurately describe the structure

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 arch/powerpc/cpu/mpc8260/ether_fcc.c |   10 ++--
 drivers/net/netconsole.c             |    4 +-
 include/net.h                        |   30 ++++++-----
 net/arp.c                            |   12 ++--
 net/arp.h                            |    2 +-
 net/bootp.c                          |    8 ++--
 net/bootp.h                          |    2 +-
 net/cdp.c                            |    4 +-
 net/dns.c                            |    2 +-
 net/net.c                            |   87 +++++++++++++++++----------------
 net/nfs.c                            |    2 +-
 net/ping.c                           |   18 ++++----
 net/ping.h                           |    2 +-
 net/rarp.c                           |   10 ++--
 net/rarp.h                           |    2 +-
 net/sntp.c                           |    2 +-
 net/tftp.c                           |    2 +-
 17 files changed, 102 insertions(+), 97 deletions(-)
arch/powerpc/cpu/mpc8260/ether_fcc.c +5 -5
index 879ec0e..f59d9e1 100644
@@ -1049,11 +1049,11 @@ eth_loopback_test (void)
 					}
 					else {
 						ushort datlen = bdp->cbd_datlen;
-						Ethernet_t *ehp;
+						struct Ethernet_t *ehp;
 						ushort prot;
 						int ours, tb, n, nbytes;
 
-						ehp = (Ethernet_t *) \
+						ehp = (struct Ethernet_t *) \
 							&ecp->rxbufs[i][0];
 
 						ours = memcmp (ehp->et_src, \
@@ -1064,9 +1064,9 @@ eth_loopback_test (void)
 						n = prot & 0x7fff;
 
 						nbytes = ELBT_BUFSZ - \
-							offsetof (Ethernet_t, \
-								et_dsap) - \
-							ELBT_CRCSZ;
+							offsetof(
+							struct Ethernet_t, \
+							et_dsap) - ELBT_CRCSZ;
 
 						/* check the frame is correct */
 						if (datlen != ELBT_BUFSZ)
drivers/net/netconsole.c +2 -2
index 7acd5b0..ba02fd7 100644
@@ -69,7 +69,7 @@ void NcStart(void)
 		/* send arp request */
 		uchar *pkt;
 		NetSetHandler(nc_wait_arp_handler);
-		pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE;
+		pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE;
 		memcpy(pkt, output_packet, output_packet_len);
 		NetSendUDPPacket(nc_ether, nc_ip, nc_port, nc_port,
 			output_packet_len);
@@ -131,7 +131,7 @@ static void nc_send_packet(const char *buf, int len)
 			return;
 		inited = 1;
 	}
-	pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE;
+	pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE;
 	memcpy(pkt, buf, len);
 	ether = nc_ether;
 	ip = nc_ip;
include/net.h +16 -14
index 2d00233..9de1181 100644
@@ -155,7 +155,7 @@ u32 ether_crc(size_t len, unsigned char const *p);
 /*
  *	Ethernet header
  */
-typedef struct {
+struct Ethernet_t {
 	uchar		et_dest[6];	/* Destination node		*/
 	uchar		et_src[6];	/* Source node			*/
 	ushort		et_protlen;	/* Protocol or length		*/
@@ -166,7 +166,7 @@ typedef struct {
 	uchar		et_snap2;
 	uchar		et_snap3;
 	ushort		et_prot;	/* 802 protocol			*/
-} Ethernet_t;
+};
 
 #define ETHER_HDR_SIZE	14		/* Ethernet header size		*/
 #define E802_HDR_SIZE	22		/* 802 ethernet header size	*/
@@ -174,13 +174,13 @@ typedef struct {
 /*
  *	Ethernet header
  */
-typedef struct {
+struct VLAN_Ethernet_t {
 	uchar		vet_dest[6];	/* Destination node		*/
 	uchar		vet_src[6];	/* Source node			*/
 	ushort		vet_vlan_type;	/* PROT_VLAN			*/
 	ushort		vet_tag;	/* TAG of VLAN			*/
 	ushort		vet_type;	/* protocol type		*/
-} VLAN_Ethernet_t;
+};
 
 #define VLAN_ETHER_HDR_SIZE	18	/* VLAN Ethernet header size	*/
 
@@ -193,9 +193,9 @@ typedef struct {
 #define IPPROTO_UDP	17	/* User Datagram Protocol		*/
 
 /*
- *	Internet Protocol (IP) header.
+ *	Internet Protocol (IP) + UDP header.
  */
-typedef struct {
+struct IP_UDP_t {
 	uchar		ip_hl_v;	/* header length and version	*/
 	uchar		ip_tos;		/* type of service		*/
 	ushort		ip_len;		/* total length			*/
@@ -210,7 +210,7 @@ typedef struct {
 	ushort		udp_dst;	/* UDP destination port		*/
 	ushort		udp_len;	/* Length of UDP packet		*/
 	ushort		udp_xsum;	/* Checksum			*/
-} IP_t;
+};
 
 #define IP_OFFS		0x1fff /* ip offset *= 8 */
 #define IP_FLAGS	0xe000 /* first 3 bits */
@@ -218,15 +218,15 @@ typedef struct {
 #define IP_FLAGS_DFRAG	0x4000 /* don't fragments */
 #define IP_FLAGS_MFRAG	0x2000 /* more fragments */
 
-#define IP_HDR_SIZE_NO_UDP	(sizeof(IP_t) - 8)
-#define IP_HDR_SIZE		(sizeof(IP_t))
+#define UDP_HDR_SIZE		(sizeof(ushort) * 4)
+#define IP_HDR_SIZE		(sizeof(struct IP_UDP_t) - UDP_HDR_SIZE)
+#define IP_UDP_HDR_SIZE		(sizeof(struct IP_UDP_t))
 
 
 /*
  *	Address Resolution Protocol (ARP) header.
  */
-typedef struct
-{
+struct ARP_t {
 	ushort		ar_hrd;		/* Format of hardware address	*/
 #   define ARP_ETHER	    1		/* Ethernet  hardware address	*/
 	ushort		ar_pro;		/* Format of protocol address	*/
@@ -251,7 +251,7 @@ typedef struct
 	uchar		ar_tha[];	/* Target hardware address	*/
 	uchar		ar_tpa[];	/* Target protocol address	*/
 #endif /* 0 */
-} ARP_t;
+};
 
 #define ARP_HDR_SIZE	(8+20)		/* Size assuming ethernet	*/
 
@@ -270,7 +270,7 @@ typedef struct
 /* Codes for NOT_REACH */
 #define ICMP_NOT_REACH_PORT	3	/* Port unreachable		*/
 
-typedef struct icmphdr {
+struct ICMP_t {
 	uchar		type;
 	uchar		code;
 	ushort		checksum;
@@ -286,8 +286,10 @@ typedef struct icmphdr {
 		} frag;
 		uchar data[0];
 	} un;
-} ICMP_t;
+};
 
+#define ICMP_HDR_SIZE		(sizeof(struct ICMP_t))
+#define IP_ICMP_HDR_SIZE	(IP_HDR_SIZE + ICMP_HDR_SIZE)
 
 /*
  * Maximum packet size; used to allocate packet storage.
net/arp.c +6 -6
index f75217c..96ffb85 100644
@@ -51,7 +51,7 @@ void ArpInit(void)
 void ArpRequest(void)
 {
 	uchar *pkt;
-	ARP_t *arp;
+	struct ARP_t *arp;
 
 	debug("ARP broadcast %d\n", NetArpWaitTry);
 
@@ -59,7 +59,7 @@ void ArpRequest(void)
 
 	pkt += NetSetEther(pkt, NetBcastAddr, PROT_ARP);
 
-	arp = (ARP_t *) pkt;
+	arp = (struct ARP_t *) pkt;
 
 	arp->ar_hrd = htons(ARP_ETHER);
 	arp->ar_pro = htons(PROT_IP);
@@ -113,9 +113,9 @@ void ArpTimeoutCheck(void)
 	}
 }
 
-void ArpReceive(Ethernet_t *et, IP_t *ip, int len)
+void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 {
-	ARP_t *arp;
+	struct ARP_t *arp;
 	IPaddr_t tmp;
 	uchar *pkt;
 
@@ -130,7 +130,7 @@ void ArpReceive(Ethernet_t *et, IP_t *ip, int len)
 	 */
 	debug("Got ARP\n");
 
-	arp = (ARP_t *)ip;
+	arp = (struct ARP_t *)ip;
 	if (len < ARP_HDR_SIZE) {
 		printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
 		return;
@@ -193,7 +193,7 @@ void ArpReceive(Ethernet_t *et, IP_t *ip, int len)
 			NetGetHandler()(0, 0, 0, 0, 0);
 #endif
 			/* modify header, and transmit it */
-			memcpy(((Ethernet_t *)NetArpWaitTxPacket)->
+			memcpy(((struct Ethernet_t *)NetArpWaitTxPacket)->
 				et_dest, NetArpWaitPacketMAC, 6);
 			(void) eth_send(NetArpWaitTxPacket,
 					NetArpWaitTxPacketSize);
net/arp.h +1 -1
index 09c763d..d9ce03d 100644
@@ -25,6 +25,6 @@ extern int NetArpWaitTry;
 void ArpInit(void);
 void ArpRequest(void);
 void ArpTimeoutCheck(void);
-void ArpReceive(Ethernet_t *et, IP_t *ip, int len);
+void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len);
 
 #endif /* __ARP_H__ */
net/bootp.c +4 -4
index 9824cd1..e95419f 100644
@@ -105,7 +105,7 @@ static void BootpCopyNetParams(struct Bootp_t *bp)
 	NetCopyIP(&tmp_ip, &bp->bp_siaddr);
 	if (tmp_ip != 0)
 		NetCopyIP(&NetServerIP, &bp->bp_siaddr);
-	memcpy(NetServerEther, ((Ethernet_t *)NetRxPacket)->et_src, 6);
+	memcpy(NetServerEther, ((struct Ethernet_t *)NetRxPacket)->et_src, 6);
 #endif
 	if (strlen(bp->bp_file) > 0)
 		copy_filename(BootFile, bp->bp_file, sizeof(BootFile));
@@ -621,8 +621,8 @@ BootpRequest(void)
 	 */
 	/* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC,
 		sizeof (struct Bootp_t)); */
-	iphdr = pkt;	/* We need this later for NetSetIP() */
-	pkt += IP_HDR_SIZE;
+	iphdr = pkt;	/* We need this later for NetSetUDPHeader() */
+	pkt += IP_UDP_HDR_SIZE;
 
 	bp = (struct Bootp_t *)pkt;
 	bp->bp_op = OP_BOOTREQUEST;
@@ -807,7 +807,7 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
 	pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
 
 	iphdr = pkt;	/* We'll need this later to set proper pkt size */
-	pkt += IP_HDR_SIZE;
+	pkt += IP_UDP_HDR_SIZE;
 
 	bp = (struct Bootp_t *)pkt;
 	bp->bp_op = OP_BOOTREQUEST;
net/bootp.h +1 -1
index bf4e875..1cf9a02 100644
@@ -52,7 +52,7 @@ struct Bootp_t {
 };
 
 #define BOOTP_HDR_SIZE	sizeof(struct Bootp_t)
-#define BOOTP_SIZE	(ETHER_HDR_SIZE + IP_HDR_SIZE + BOOTP_HDR_SIZE)
+#define BOOTP_SIZE	(ETHER_HDR_SIZE + IP_UDP_HDR_SIZE + BOOTP_HDR_SIZE)
 
 /**********************************************************************/
 /*
net/cdp.c +2 -2
index c5e54b2..d617f18 100644
@@ -108,7 +108,7 @@ CDPSendTrigger(void)
 	uchar *pkt;
 	ushort *s;
 	ushort *cp;
-	Ethernet_t *et;
+	struct Ethernet_t *et;
 	int len;
 	ushort chksum;
 #if	defined(CONFIG_CDP_DEVICE_ID) || defined(CONFIG_CDP_PORT_ID)   || \
@@ -117,7 +117,7 @@ CDPSendTrigger(void)
 #endif
 
 	pkt = NetTxPacket;
-	et = (Ethernet_t *)pkt;
+	et = (struct Ethernet_t *)pkt;
 
 	/* NOTE: trigger sent not on any VLAN */
 
net/dns.c +1 -1
index 7a3f1f9..cc7ed51 100644
@@ -45,7 +45,7 @@ DnsSend(void)
 	enum dns_query_type qtype = DNS_A_RECORD;
 
 	name = NetDNSResolve;
-	pkt = p = (uchar *)(NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE);
+	pkt = p = (uchar *)(NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE);
 
 	/* Prepare DNS packet header */
 	header           = (struct header *) pkt;
net/net.c +45 -42

247 lines not on this page · raw message

net/nfs.c +1 -1
index 54f56c4..b6188fe 100644
@@ -189,7 +189,7 @@ rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
 
 	pktlen = (char *)p + datalen*sizeof(uint32_t) - (char *)&pkt;
 
-	memcpy((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE,
+	memcpy((char *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE,
 		(char *)&pkt, pktlen);
 
 	if (rpc_prog == PROG_PORTMAP)
net/ping.c +9 -9
index 4a66b8d..34e287c 100644
@@ -19,7 +19,7 @@ IPaddr_t NetPingIP;
 static int PingSend(void)
 {
 	static uchar mac[6];
-	IP_t *ip;
+	struct IP_UDP_t *ip;
 	ushort *s;
 	uchar *pkt;
 
@@ -35,7 +35,7 @@ static int PingSend(void)
 	pkt = NetArpWaitTxPacket;
 	pkt += NetSetEther(pkt, mac, PROT_IP);
 
-	ip = (IP_t *)pkt;
+	ip = (struct IP_UDP_t *)pkt;
 
 	/*
 	 * Construct an IP and ICMP header.
@@ -44,7 +44,7 @@ static int PingSend(void)
 	/* IP_HDR_SIZE / 4 (not including UDP) */
 	ip->ip_hl_v  = 0x45;
 	ip->ip_tos   = 0;
-	ip->ip_len   = htons(IP_HDR_SIZE_NO_UDP + 8);
+	ip->ip_len   = htons(IP_HDR_SIZE + 8);
 	ip->ip_id    = htons(NetIPID++);
 	ip->ip_off   = htons(IP_FLAGS_DFRAG);	/* Don't fragment */
 	ip->ip_ttl   = 255;
@@ -54,7 +54,7 @@ static int PingSend(void)
 	NetCopyIP((void *)&ip->ip_src, &NetOurIP);
 	/* - "" - */
 	NetCopyIP((void *)&ip->ip_dst, &NetPingIP);
-	ip->ip_sum   = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
+	ip->ip_sum   = ~NetCksum((uchar *)ip, IP_HDR_SIZE / 2);
 
 	s = &ip->udp_src;		/* XXX ICMP starts here */
 	s[0] = htons(0x0800);		/* echo-request, code */
@@ -65,7 +65,7 @@ static int PingSend(void)
 
 	/* size of the waiting packet */
 	NetArpWaitTxPacketSize =
-		(pkt - NetArpWaitTxPacket) + IP_HDR_SIZE_NO_UDP + 8;
+		(pkt - NetArpWaitTxPacket) + IP_HDR_SIZE + 8;
 
 	/* and do the ARP request */
 	NetArpWaitTry = 1;
@@ -101,9 +101,9 @@ PingStart(void)
 	PingSend();
 }
 
-void PingReceive(Ethernet_t *et, IP_t *ip, int len)
+void PingReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 {
-	ICMP_t *icmph = (ICMP_t *)&(ip->udp_src);
+	struct ICMP_t *icmph = (struct ICMP_t *)&(ip->udp_src);
 	IPaddr_t src_ip;
 
 	switch (icmph->type) {
@@ -128,12 +128,12 @@ void PingReceive(Ethernet_t *et, IP_t *ip, int len)
 		NetCopyIP((void *)&ip->ip_dst, &ip->ip_src);
 		NetCopyIP((void *)&ip->ip_src, &NetOurIP);
 		ip->ip_sum = ~NetCksum((uchar *)ip,
-				       IP_HDR_SIZE_NO_UDP >> 1);
+				       IP_HDR_SIZE >> 1);
 
 		icmph->type = ICMP_ECHO_REPLY;
 		icmph->checksum = 0;
 		icmph->checksum = ~NetCksum((uchar *)icmph,
-			(len - IP_HDR_SIZE_NO_UDP) >> 1);
+			(len - IP_HDR_SIZE) >> 1);
 		(void) eth_send((uchar *)et,
 				ETHER_HDR_SIZE + len);
 		return;
net/ping.h +1 -1
index 56aad43..4671909 100644
@@ -15,6 +15,6 @@
 #include <net.h>
 
 void PingStart(void);
-void PingReceive(Ethernet_t *et, IP_t *ip, int len);
+void PingReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len);
 
 #endif /* __PING_H__ */
net/rarp.c +5 -5
index 761560c..305b0a4 100644
@@ -42,12 +42,12 @@ int		RarpTry;
  *	Handle a RARP received packet.
  */
 void
-RarpReceive(IP_t *ip, unsigned len)
+RarpReceive(struct IP_UDP_t *ip, unsigned len)
 {
-	ARP_t *arp;
+	struct ARP_t *arp;
 
 	debug("Got RARP\n");
-	arp = (ARP_t *)ip;
+	arp = (struct ARP_t *)ip;
 	if (len < ARP_HDR_SIZE) {
 		printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
 		return;
@@ -90,14 +90,14 @@ void
 RarpRequest(void)
 {
 	uchar *pkt;
-	ARP_t *rarp;
+	struct ARP_t *rarp;
 
 	printf("RARP broadcast %d\n", ++RarpTry);
 	pkt = NetTxPacket;
 
 	pkt += NetSetEther(pkt, NetBcastAddr, PROT_RARP);
 
-	rarp = (ARP_t *)pkt;
+	rarp = (struct ARP_t *)pkt;
 
 	rarp->ar_hrd = htons(ARP_ETHER);
 	rarp->ar_pro = htons(PROT_IP);
net/rarp.h +1 -1
index 0d728dc..8723dd3 100644
@@ -37,7 +37,7 @@
 
 extern int RarpTry;
 
-extern void RarpReceive(IP_t *ip, unsigned len);
+extern void RarpReceive(struct IP_UDP_t *ip, unsigned len);
 extern void RarpRequest(void);	/* Send a RARP request */
 
 /**********************************************************************/
net/sntp.c +1 -1
index 6dd0dbd..7997f98 100644
@@ -31,7 +31,7 @@ SntpSend(void)
 	pkt.vn = NTP_VERSION;
 	pkt.mode = NTP_MODE_CLIENT;
 
-	memcpy((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE,
+	memcpy((char *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE,
 		(char *)&pkt, pktlen);
 
 	SntpOurPort = 10000 + (get_timer(0) % 4096);
net/tftp.c +1 -1
index bc7fe05..a04a832 100644
@@ -322,7 +322,7 @@ TftpSend(void)
 	 *	We will always be sending some sort of packet, so
 	 *	cobble together the packet headers now.
 	 */
-	pkt = (uchar *)(NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE);
+	pkt = NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE;
 
 	switch (TftpState) {
 	case STATE_SEND_RRQ:
Signature · 1 line
1.6.0.2
#40 lore raw

PATCH 9/28 net: cosmetic: Un-typedef variables in net

Quoted 1 line · On Thursday 19 January 2012 19:53:12 Joe Hershberger wrote:

Un-typedef IP_t, Ethernet_t, VLAN_Ethernet_t, ARP_t, ICMP_t

i'm not sure about this. i don't mind the typedefs myself and they have the advantage of already being done ... let's see what Wolfgang prefers.

Quoted 2 lines

The existing definition of IP_t includes UDP header, so name it to accurately describe the structure

i feel like we should split it out. drop the UDP parts from IP_t and add a new IP_UDP_t. much of the code operates on UDP packages, but not all (such as the main NetReceive func).
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/6d9ba5da/attachment.pgp>

#41 lore raw

PATCH 9/28 net: cosmetic: Un-typedef variables in net

Hi Mike,

Quoted 5 lines · Mike Frysinger
Quoted 1 line · On Thursday 19 January 2012 19:53:12 Joe Hershberger wrote:

Un-typedef IP_t, Ethernet_t, VLAN_Ethernet_t, ARP_t, ICMP_t

i'm not sure about this. ?i don't mind the typedefs myself and they have the advantage of already being done ... let's see what Wolfgang prefers.

Wolfgang was clearly against typedef'ed structs when I asked him in October of last year.

Quoted 9 lines · Wolfgang Denk
Quoted 5 lines · In message <CANr=Z=bmm64Qxv+Zpc=GShY7c2KapAgh9xm-cq79TM1oQ76V5A@mail.gmail.com>…

WARNING:NEW_TYPEDEFS: do not add new typedefs
This seems rather limiting... I'm not sure why even Linux would want this, at least when it applies to typedefs of structs. It makes sense if it's a new typedef for int or something.

See the CodingStyle, start reading at "It's a _mistake_ to use typedef for structures and pointers."

That's why I didn't leave them to be complained about by checkpatch.

-Joe

#42 lore raw

PATCH 10/28 net: cosmetic: Improve variable names and code readability

In reply to Joe Hershberger

Rename parameter len to payload_len in NetSendUDPPacket: this name
more explicitly claims that it does not include the header size
Rename CDPHandler to CDPReceive: this is not called as a handler,
so don't name it that way
Rename OPT_SIZE to OPT_FIELD_SIZE: clearer constant name and also
remove related BOOTP_SIZE which was unused and doesn't take into account VLAN packets
Rename tmp to reply_ip_addr in arp.c
Alphabetize includes in net.c
Replace magic numbers in arp.c with constants
Add a more explicit comment about 802.2

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 include/net.h |   11 +++++++-
 net/arp.c     |   38 ++++++++++++++++----------------
 net/bootp.c   |   10 ++++----
 net/bootp.h   |    7 ++---
 net/cdp.c     |    2 +-
 net/cdp.h     |    2 +-
 net/net.c     |   67 +++++++++++++++++++++++++++++---------------------------
 7 files changed, 73 insertions(+), 64 deletions(-)
include/net.h +9 -2
index 9de1181..add2080 100644
@@ -169,7 +169,8 @@ struct Ethernet_t {
 };
 
 #define ETHER_HDR_SIZE	14		/* Ethernet header size		*/
-#define E802_HDR_SIZE	22		/* 802 ethernet header size	*/
+				/* 802.2 + SNAP + ethernet header size	*/
+#define E802_HDR_SIZE	(ETHER_HDR_SIZE + 8)
 
 /*
  *	Ethernet header
@@ -231,7 +232,9 @@ struct ARP_t {
 #   define ARP_ETHER	    1		/* Ethernet  hardware address	*/
 	ushort		ar_pro;		/* Format of protocol address	*/
 	uchar		ar_hln;		/* Length of hardware address	*/
+#   define ARP_HLEN	6
 	uchar		ar_pln;		/* Length of protocol address	*/
+#   define ARP_PLEN	4
 	ushort		ar_op;		/* Operation			*/
 #   define ARPOP_REQUEST    1		/* Request  to resolve  address	*/
 #   define ARPOP_REPLY	    2		/* Response to previous request	*/
@@ -245,6 +248,10 @@ struct ARP_t {
 	 * specific hardware/protocol combinations.
 	 */
 	uchar		ar_data[0];
+#define ar_sha		ar_data[0]
+#define ar_spa		ar_data[ARP_HLEN]
+#define ar_tha		ar_data[ARP_HLEN + ARP_PLEN]
+#define ar_tpa		ar_data[ARP_HLEN + ARP_PLEN + ARP_HLEN]
 #if 0
 	uchar		ar_sha[];	/* Sender hardware address	*/
 	uchar		ar_spa[];	/* Sender protocol address	*/
@@ -431,7 +438,7 @@ extern void NetSendPacket(uchar *, int);
 
 /* Transmit UDP packet, performing ARP request if needed */
 extern int	NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport,
-			int sport, int len);
+			int sport, int payload_len);
 
 /* Processes a received packet */
 extern void	NetReceive(volatile uchar *, int);
net/arp.c +19 -19
index 96ffb85..456decd 100644
@@ -63,16 +63,16 @@ void ArpRequest(void)
 
 	arp->ar_hrd = htons(ARP_ETHER);
 	arp->ar_pro = htons(PROT_IP);
-	arp->ar_hln = 6;
-	arp->ar_pln = 4;
+	arp->ar_hln = ARP_HLEN;
+	arp->ar_pln = ARP_PLEN;
 	arp->ar_op = htons(ARPOP_REQUEST);
 
 	/* source ET addr */
-	memcpy(&arp->ar_data[0], NetOurEther, 6);
+	memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);
 	/* source IP addr */
-	NetWriteIP((uchar *) &arp->ar_data[6], NetOurIP);
+	NetWriteIP(&arp->ar_spa, NetOurIP);
 	/* dest ET addr = 0 */
-	memset(&arp->ar_data[10], '\0', 6);
+	memset(&arp->ar_tha, 0, ARP_HLEN);
 	if ((NetArpWaitPacketIP & NetOurSubnetMask) !=
 	    (NetOurIP & NetOurSubnetMask)) {
 		if (NetOurGatewayIP == 0) {
@@ -85,7 +85,7 @@ void ArpRequest(void)
 		NetArpWaitReplyIP = NetArpWaitPacketIP;
 	}
 
-	NetWriteIP((uchar *) &arp->ar_data[16], NetArpWaitReplyIP);
+	NetWriteIP(&arp->ar_tpa, NetArpWaitReplyIP);
 	(void) eth_send(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
 }
 
@@ -116,7 +116,7 @@ void ArpTimeoutCheck(void)
 void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 {
 	struct ARP_t *arp;
-	IPaddr_t tmp;
+	IPaddr_t reply_ip_addr;
 	uchar *pkt;
 
 	/*
@@ -139,15 +139,15 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 		return;
 	if (ntohs(arp->ar_pro) != PROT_IP)
 		return;
-	if (arp->ar_hln != 6)
+	if (arp->ar_hln != ARP_HLEN)
 		return;
-	if (arp->ar_pln != 4)
+	if (arp->ar_pln != ARP_PLEN)
 		return;
 
 	if (NetOurIP == 0)
 		return;
 
-	if (NetReadIP(&arp->ar_data[16]) != NetOurIP)
+	if (NetReadIP(&arp->ar_tpa) != NetOurIP)
 		return;
 
 	switch (ntohs(arp->ar_op)) {
@@ -157,10 +157,10 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 		pkt = (uchar *)et;
 		pkt += NetSetEther(pkt, et->et_src, PROT_ARP);
 		arp->ar_op = htons(ARPOP_REPLY);
-		memcpy(&arp->ar_data[10], &arp->ar_data[0], 6);
-		NetCopyIP(&arp->ar_data[16], &arp->ar_data[6]);
-		memcpy(&arp->ar_data[0], NetOurEther, 6);
-		NetCopyIP(&arp->ar_data[6], &NetOurIP);
+		memcpy(&arp->ar_tha, &arp->ar_sha, ARP_HLEN);
+		NetCopyIP(&arp->ar_tpa, &arp->ar_spa);
+		memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);
+		NetCopyIP(&arp->ar_spa, &NetOurIP);
 		(void) eth_send((uchar *)et,
 				(pkt - (uchar *)et) + ARP_HDR_SIZE);
 		return;
@@ -173,28 +173,28 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 #ifdef CONFIG_KEEP_SERVERADDR
 		if (NetServerIP == NetArpWaitPacketIP) {
 			char buf[20];
-			sprintf(buf, "%pM", arp->ar_data);
+			sprintf(buf, "%pM", arp->ar_sha);
 			setenv("serveraddr", buf);
 		}
 #endif
 
-		tmp = NetReadIP(&arp->ar_data[6]);
+		reply_ip_addr = NetReadIP(&arp->ar_spa);
 
 		/* matched waiting packet's address */
-		if (tmp == NetArpWaitReplyIP) {
+		if (reply_ip_addr == NetArpWaitReplyIP) {
 			debug("Got ARP REPLY, set eth addr (%pM)\n",
 				arp->ar_data);
 
 			/* save address for later use */
 			memcpy(NetArpWaitPacketMAC,
-			       &arp->ar_data[0], 6);
+				&arp->ar_sha, ARP_HLEN);
 
 #ifdef CONFIG_NETCONSOLE
 			NetGetHandler()(0, 0, 0, 0, 0);
 #endif
 			/* modify header, and transmit it */
 			memcpy(((struct Ethernet_t *)NetArpWaitTxPacket)->
-				et_dest, NetArpWaitPacketMAC, 6);
+				et_dest, NetArpWaitPacketMAC, ARP_HLEN);
 			(void) eth_send(NetArpWaitTxPacket,
 					NetArpWaitTxPacketSize);
 
net/bootp.c +5 -5
index e95419f..2be8083 100644
@@ -73,7 +73,7 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
 
 	if (dest != PORT_BOOTPC || src != PORT_BOOTPS)
 		retval = -1;
-	else if (len < sizeof(struct Bootp_t) - OPT_SIZE)
+	else if (len < sizeof(struct Bootp_t) - OPT_FIELD_SIZE)
 		retval = -2;
 	else if (bp->bp_op != OP_BOOTREQUEST &&
 			bp->bp_op != OP_BOOTREPLY &&
@@ -369,8 +369,8 @@ static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
 
 	*e++ = 57;		/* Maximum DHCP Message Size */
 	*e++ = 2;
-	*e++ = (576 - 312 + OPT_SIZE) >> 8;
-	*e++ = (576 - 312 + OPT_SIZE) & 0xff;
+	*e++ = (576 - 312 + OPT_FIELD_SIZE) >> 8;
+	*e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;
 
 	if (ServerID) {
 		int tmp = ntohl(ServerID);
@@ -520,8 +520,8 @@ static int BootpExtended(u8 *e)
 
 	*e++ = 57;		/* Maximum DHCP Message Size */
 	*e++ = 2;
-	*e++ = (576 - 312 + OPT_SIZE) >> 16;
-	*e++ = (576 - 312 + OPT_SIZE) & 0xff;
+	*e++ = (576 - 312 + OPT_FIELD_SIZE) >> 16;
+	*e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;
 #endif
 
 #if defined(CONFIG_BOOTP_SUBNETMASK)
net/bootp.h +3 -4
index 1cf9a02..ecbcc4d 100644
@@ -20,13 +20,13 @@
  */
 #if defined(CONFIG_CMD_DHCP)
 /* Minimum DHCP Options size per RFC2131 - results in 576 byte pkt */
-#define OPT_SIZE 312
+#define OPT_FIELD_SIZE 312
 #if defined(CONFIG_BOOTP_VENDOREX)
 extern u8 *dhcp_vendorex_prep(u8 *e); /*rtn new e after add own opts. */
 extern u8 *dhcp_vendorex_proc(u8 *e); /*rtn next e if mine,else NULL  */
 #endif
 #else
-#define OPT_SIZE 64
+#define OPT_FIELD_SIZE 64
 #endif
 
 struct Bootp_t {
@@ -48,11 +48,10 @@ struct Bootp_t {
 	uchar		bp_chaddr[16];	/* Client hardware address	*/
 	char		bp_sname[64];	/* Server host name		*/
 	char		bp_file[128];	/* Boot file name		*/
-	char		bp_vend[OPT_SIZE];	/* Vendor information	*/
+	char		bp_vend[OPT_FIELD_SIZE]; /* Vendor information	*/
 };
 
 #define BOOTP_HDR_SIZE	sizeof(struct Bootp_t)
-#define BOOTP_SIZE	(ETHER_HDR_SIZE + IP_UDP_HDR_SIZE + BOOTP_HDR_SIZE)
 
 /**********************************************************************/
 /*
net/cdp.c +1 -1
index d617f18..38b79bd 100644
@@ -245,7 +245,7 @@ CDPDummyHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 }
 
 void
-CDPHandler(const uchar *pkt, unsigned len)
+CDPReceive(const uchar *pkt, unsigned len)
 {
 	const uchar *t;
 	const ushort *ss;
net/cdp.h +1 -1
index fef744e..88191c4 100644
@@ -12,7 +12,7 @@
 #define __CDP_H__
 
 void CDPStart(void);
-void CDPHandler(const uchar *pkt, unsigned len);
+void CDPReceive(const uchar *pkt, unsigned len);
 
 #endif /* __CDP_H__ */
 
net/net.c +35 -32

159 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#43 lore raw

PATCH 10/28 net: cosmetic: Improve variable names and code readability

Hi Joe,

Quoted 11 lines · Joe Hershberger

Rename parameter len to payload_len in NetSendUDPPacket: this name ? more explicitly claims that it does not include the header size Rename CDPHandler to CDPReceive: this is not called as a handler, ? so don't name it that way
Rename OPT_SIZE to OPT_FIELD_SIZE: clearer constant name and also ? remove related BOOTP_SIZE which was unused and doesn't take into ? account VLAN packets
Rename tmp to reply_ip_addr in arp.c
Alphabetize includes in net.c
Replace magic numbers in arp.c with constants
Add a more explicit comment about 802.2

Yes but why lump all of these together? It would benefit from 3-4 separate commits IMO.

Regards,
Simon

Quoted 443 lines
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

?include/net.h | ? 11 +++++++-
?net/arp.c ? ? | ? 38 ++++++++++++++++----------------
?net/bootp.c ? | ? 10 ++++----
?net/bootp.h ? | ? ?7 ++---
?net/cdp.c ? ? | ? ?2 +-
?net/cdp.h ? ? | ? ?2 +-
?net/net.c ? ? | ? 67 +++++++++++++++++++++++++++++---------------------------

?7 files changed, 73 insertions(+), 64 deletions(-)

include/net.h +0 -0
index 9de1181..add2080 100644
@@ -169,7 +169,8 @@ struct Ethernet_t {
 ?};
 

?#define ETHER_HDR_SIZE 14 ? ? ? ? ? ? ?/* Ethernet header size ? ? ? ? */

include/net.h +2 -1
-#define E802_HDR_SIZE ?22 ? ? ? ? ? ? ?/* 802 ethernet header size ? ? */
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* 802.2 + SNAP + ethernet header size ?*/
+#define E802_HDR_SIZE ?(ETHER_HDR_SIZE + 8)

?/*
?* ? ? Ethernet header

include/net.h +0 -0
@@ -231,7 +232,9 @@ struct ARP_t {

?# ? define ARP_ETHER ? ? ? 1 ? ? ? ? ? /* Ethernet ?hardware address ? */ ? ? ? ?ushort ? ? ? ? ?ar_pro; ? ? ? ? /* Format of protocol address ? */ ? ? ? ?uchar ? ? ? ? ? ar_hln; ? ? ? ? /* Length of hardware address ? */ +# ? define ARP_HLEN ? ?6
? ? ? ?uchar ? ? ? ? ? ar_pln; ? ? ? ? /* Length of protocol address ? */ +# ? define ARP_PLEN ? ?4
? ? ? ?ushort ? ? ? ? ?ar_op; ? ? ? ? ?/* Operation ? ? ? ? ? ? ? ? ? ?*/ ?# ? define ARPOP_REQUEST ? ?1 ? ? ? ? ?/* Request ?to resolve ?address */ ?# ? define ARPOP_REPLY ? ? 2 ? ? ? ? ? /* Response to previous request */

include/net.h +0 -0
@@ -245,6 +248,10 @@ struct ARP_t {

? ? ? ? * specific hardware/protocol combinations. ? ? ? ? */
? ? ? ?uchar ? ? ? ? ? ar_data[0];

include/net.h +4 -0
+#define ar_sha ? ? ? ? ar_data[0]
+#define ar_spa ? ? ? ? ar_data[ARP_HLEN]
+#define ar_tha ? ? ? ? ar_data[ARP_HLEN + ARP_PLEN]
+#define ar_tpa ? ? ? ? ar_data[ARP_HLEN + ARP_PLEN + ARP_HLEN]

?#if 0
? ? ? ?uchar ? ? ? ? ? ar_sha[]; ? ? ? /* Sender hardware address ? ? ?*/ ? ? ? ?uchar ? ? ? ? ? ar_spa[]; ? ? ? /* Sender protocol address ? ? ?*/

include/net.h +0 -0
@@ -431,7 +438,7 @@ extern void NetSendPacket(uchar *, int);
 

?/* Transmit UDP packet, performing ARP request if needed */ ?extern int ? ? NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport,
- ? ? ? ? ? ? ? ? ? ? ? int sport, int len);
+ ? ? ? ? ? ? ? ? ? ? ? int sport, int payload_len);

?/* Processes a received packet */
?extern void ? ?NetReceive(volatile uchar *, int);

net/arp.c +2 -2
index 96ffb85..456decd 100644
@@ -63,16 +63,16 @@ void ArpRequest(void)
 
 ? ? ? ?arp->ar_hrd = htons(ARP_ETHER);
 ? ? ? ?arp->ar_pro = htons(PROT_IP);
- ? ? ? arp->ar_hln = 6;
- ? ? ? arp->ar_pln = 4;
+ ? ? ? arp->ar_hln = ARP_HLEN;
+ ? ? ? arp->ar_pln = ARP_PLEN;
 ? ? ? ?arp->ar_op = htons(ARPOP_REQUEST);
 

? ? ? ?/* source ET addr */
- ? ? ? memcpy(&arp->ar_data[0], NetOurEther, 6);
+ ? ? ? memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN); ? ? ? ?/* source IP addr */
- ? ? ? NetWriteIP((uchar *) &arp->ar_data[6], NetOurIP);
+ ? ? ? NetWriteIP(&arp->ar_spa, NetOurIP);
? ? ? ?/* dest ET addr = 0 */
- ? ? ? memset(&arp->ar_data[10], '\0', 6);
+ ? ? ? memset(&arp->ar_tha, 0, ARP_HLEN);
? ? ? ?if ((NetArpWaitPacketIP & NetOurSubnetMask) != ? ? ? ? ? ?(NetOurIP & NetOurSubnetMask)) {
? ? ? ? ? ? ? ?if (NetOurGatewayIP == 0) {

net/arp.c +2 -2
@@ -85,7 +85,7 @@ void ArpRequest(void)
 ? ? ? ? ? ? ? ?NetArpWaitReplyIP = NetArpWaitPacketIP;
 ? ? ? ?}
 
- ? ? ? NetWriteIP((uchar *) &arp->ar_data[16], NetArpWaitReplyIP);
+ ? ? ? NetWriteIP(&arp->ar_tpa, NetArpWaitReplyIP);
 ? ? ? ?(void) eth_send(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
 ?}
 
@@ -116,7 +116,7 @@ void ArpTimeoutCheck(void)
 ?void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 ?{
 ? ? ? ?struct ARP_t *arp;
- ? ? ? IPaddr_t tmp;
+ ? ? ? IPaddr_t reply_ip_addr;
 ? ? ? ?uchar *pkt;
 

? ? ? ?/*

net/arp.c +7 -7
@@ -139,15 +139,15 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 ? ? ? ? ? ? ? ?return;
 ? ? ? ?if (ntohs(arp->ar_pro) != PROT_IP)
 ? ? ? ? ? ? ? ?return;
- ? ? ? if (arp->ar_hln != 6)
+ ? ? ? if (arp->ar_hln != ARP_HLEN)
 ? ? ? ? ? ? ? ?return;
- ? ? ? if (arp->ar_pln != 4)
+ ? ? ? if (arp->ar_pln != ARP_PLEN)
 ? ? ? ? ? ? ? ?return;
 
 ? ? ? ?if (NetOurIP == 0)
 ? ? ? ? ? ? ? ?return;
 
- ? ? ? if (NetReadIP(&arp->ar_data[16]) != NetOurIP)
+ ? ? ? if (NetReadIP(&arp->ar_tpa) != NetOurIP)
 ? ? ? ? ? ? ? ?return;
 
 ? ? ? ?switch (ntohs(arp->ar_op)) {
@@ -157,10 +157,10 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 ? ? ? ? ? ? ? ?pkt = (uchar *)et;
 ? ? ? ? ? ? ? ?pkt += NetSetEther(pkt, et->et_src, PROT_ARP);
 ? ? ? ? ? ? ? ?arp->ar_op = htons(ARPOP_REPLY);
- ? ? ? ? ? ? ? memcpy(&arp->ar_data[10], &arp->ar_data[0], 6);
- ? ? ? ? ? ? ? NetCopyIP(&arp->ar_data[16], &arp->ar_data[6]);
- ? ? ? ? ? ? ? memcpy(&arp->ar_data[0], NetOurEther, 6);
- ? ? ? ? ? ? ? NetCopyIP(&arp->ar_data[6], &NetOurIP);
+ ? ? ? ? ? ? ? memcpy(&arp->ar_tha, &arp->ar_sha, ARP_HLEN);
+ ? ? ? ? ? ? ? NetCopyIP(&arp->ar_tpa, &arp->ar_spa);
+ ? ? ? ? ? ? ? memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);
+ ? ? ? ? ? ? ? NetCopyIP(&arp->ar_spa, &NetOurIP);
 ? ? ? ? ? ? ? ?(void) eth_send((uchar *)et,
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?(pkt - (uchar *)et) + ARP_HDR_SIZE);
 ? ? ? ? ? ? ? ?return;
@@ -173,28 +173,28 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)

?#ifdef CONFIG_KEEP_SERVERADDR
? ? ? ? ? ? ? ?if (NetServerIP == NetArpWaitPacketIP) { ? ? ? ? ? ? ? ? ? ? ? ?char buf[20];
- ? ? ? ? ? ? ? ? ? ? ? sprintf(buf, "%pM", arp->ar_data);
+ ? ? ? ? ? ? ? ? ? ? ? sprintf(buf, "%pM", arp->ar_sha); ? ? ? ? ? ? ? ? ? ? ? ?setenv("serveraddr", buf); ? ? ? ? ? ? ? ?}
?#endif

- ? ? ? ? ? ? ? tmp = NetReadIP(&arp->ar_data[6]);
+ ? ? ? ? ? ? ? reply_ip_addr = NetReadIP(&arp->ar_spa);

? ? ? ? ? ? ? ?/* matched waiting packet's address */
- ? ? ? ? ? ? ? if (tmp == NetArpWaitReplyIP) {
+ ? ? ? ? ? ? ? if (reply_ip_addr == NetArpWaitReplyIP) { ? ? ? ? ? ? ? ? ? ? ? ?debug("Got ARP REPLY, set eth addr (%pM)\n", ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?arp->ar_data);

? ? ? ? ? ? ? ? ? ? ? ?/* save address for later use */ ? ? ? ? ? ? ? ? ? ? ? ?memcpy(NetArpWaitPacketMAC,
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?&arp->ar_data[0], 6);
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &arp->ar_sha, ARP_HLEN);

?#ifdef CONFIG_NETCONSOLE
? ? ? ? ? ? ? ? ? ? ? ?NetGetHandler()(0, 0, 0, 0, 0); ?#endif
? ? ? ? ? ? ? ? ? ? ? ?/* modify header, and transmit it */
? ? ? ? ? ? ? ? ? ? ? ?memcpy(((struct Ethernet_t *)NetArpWaitTxPacket)->
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_dest, NetArpWaitPacketMAC, 6);
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? et_dest, NetArpWaitPacketMAC, ARP_HLEN); ? ? ? ? ? ? ? ? ? ? ? ?(void) eth_send(NetArpWaitTxPacket,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?NetArpWaitTxPacketSize);

net/bootp.c +1 -1
index e95419f..2be8083 100644
@@ -73,7 +73,7 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
 
 ? ? ? ?if (dest != PORT_BOOTPC || src != PORT_BOOTPS)
 ? ? ? ? ? ? ? ?retval = -1;
- ? ? ? else if (len < sizeof(struct Bootp_t) - OPT_SIZE)
+ ? ? ? else if (len < sizeof(struct Bootp_t) - OPT_FIELD_SIZE)
 ? ? ? ? ? ? ? ?retval = -2;

? ? ? ?else if (bp->bp_op != OP_BOOTREQUEST && ? ? ? ? ? ? ? ? ? ? ? ?bp->bp_op != OP_BOOTREPLY &&

net/bootp.c +0 -0
@@ -369,8 +369,8 @@ static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
 

? ? ? ?*e++ = 57; ? ? ? ? ? ? ?/* Maximum DHCP Message Size */ ? ? ? ?*e++ = 2;
- ? ? ? *e++ = (576 - 312 + OPT_SIZE) >> 8;
- ? ? ? *e++ = (576 - 312 + OPT_SIZE) & 0xff;
+ ? ? ? *e++ = (576 - 312 + OPT_FIELD_SIZE) >> 8;
+ ? ? ? *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;

? ? ? ?if (ServerID) {
? ? ? ? ? ? ? ?int tmp = ntohl(ServerID);

net/bootp.c +0 -0
@@ -520,8 +520,8 @@ static int BootpExtended(u8 *e)
 

? ? ? ?*e++ = 57; ? ? ? ? ? ? ?/* Maximum DHCP Message Size */ ? ? ? ?*e++ = 2;
- ? ? ? *e++ = (576 - 312 + OPT_SIZE) >> 16;
- ? ? ? *e++ = (576 - 312 + OPT_SIZE) & 0xff;
+ ? ? ? *e++ = (576 - 312 + OPT_FIELD_SIZE) >> 16;
+ ? ? ? *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff; ?#endif

?#if defined(CONFIG_BOOTP_SUBNETMASK)

net/bootp.h +0 -0
index 1cf9a02..ecbcc4d 100644
@@ -20,13 +20,13 @@

?*/
?#if defined(CONFIG_CMD_DHCP)
?/* Minimum DHCP Options size per RFC2131 - results in 576 byte pkt */

net/bootp.h +1 -1
-#define OPT_SIZE 312
+#define OPT_FIELD_SIZE 312

?#if defined(CONFIG_BOOTP_VENDOREX)
?extern u8 *dhcp_vendorex_prep(u8 *e); /*rtn new e after add own opts. */ ?extern u8 *dhcp_vendorex_proc(u8 *e); /*rtn next e if mine,else NULL ?*/ ?#endif
?#else

net/bootp.h +1 -1
-#define OPT_SIZE 64
+#define OPT_FIELD_SIZE 64

?#endif

?struct Bootp_t {

net/bootp.h +0 -0
@@ -48,11 +48,10 @@ struct Bootp_t {

? ? ? ?uchar ? ? ? ? ? bp_chaddr[16]; ?/* Client hardware address ? ? ?*/ ? ? ? ?char ? ? ? ? ? ?bp_sname[64]; ? /* Server host name ? ? ? ? ? ? */ ? ? ? ?char ? ? ? ? ? ?bp_file[128]; ? /* Boot file name ? ? ? ? ? ? ? */
- ? ? ? char ? ? ? ? ? ?bp_vend[OPT_SIZE]; ? ? ?/* Vendor information ? */
+ ? ? ? char ? ? ? ? ? ?bp_vend[OPT_FIELD_SIZE]; /* Vendor information ?*/ ?};

?#define BOOTP_HDR_SIZE sizeof(struct Bootp_t)
-#define BOOTP_SIZE ? ? (ETHER_HDR_SIZE + IP_UDP_HDR_SIZE + BOOTP_HDR_SIZE)

?/**********************************************************************/ ?/*

net/cdp.c +0 -0
index d617f18..38b79bd 100644
@@ -245,7 +245,7 @@ CDPDummyHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 ?}
 

?void

net/cdp.c +1 -1
-CDPHandler(const uchar *pkt, unsigned len)
+CDPReceive(const uchar *pkt, unsigned len)

?{
? ? ? ?const uchar *t;
? ? ? ?const ushort *ss;

net/cdp.h +0 -0
index fef744e..88191c4 100644
@@ -12,7 +12,7 @@

?#define __CDP_H__

?void CDPStart(void);

net/cdp.h +1 -1
-void CDPHandler(const uchar *pkt, unsigned len);
+void CDPReceive(const uchar *pkt, unsigned len);

?#endif /* __CDP_H__ */

net/net.c +0 -0
index 023802d..9bf74d5 100644
@@ -75,32 +75,32 @@
 
 

?#include <common.h>
-#include <watchdog.h>
?#include <command.h>
?#include <net.h>

net/net.c +1 -8
-#include "arp.h"
-#include "bootp.h"
-#include "tftp.h"
-#ifdef CONFIG_CMD_RARP
-#include "rarp.h"
-#endif
-#include "nfs.h"
-#ifdef CONFIG_STATUS_LED
+#if defined(CONFIG_STATUS_LED)

?#include <status_led.h>
?#include <miiphy.h>
?#endif

net/net.c +3 -3
-#if defined(CONFIG_CMD_SNTP)
-#include "sntp.h"
-#endif
+#include <watchdog.h>
+#include "arp.h"
+#include "bootp.h"

?#if defined(CONFIG_CMD_CDP)
?#include "cdp.h"
?#endif
?#if defined(CONFIG_CMD_DNS)
?#include "dns.h"
?#endif
+#include "nfs.h"
?#if defined(CONFIG_CMD_PING)
?#include "ping.h"
?#endif

net/net.c +7 -0
+#if defined(CONFIG_CMD_RARP)
+#include "rarp.h"
+#endif
+#if defined(CONFIG_CMD_SNTP)
+#include "sntp.h"
+#endif
+#include "tftp.h"

?DECLARE_GLOBAL_DATA_PTR;

net/net.c +0 -0
@@ -598,7 +598,8 @@ NetSendPacket(uchar *pkt, int len)
 ?}
 

?int

net/net.c +2 -1
-NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
+NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
+ ? ? ? ? ? ? ? int payload_len)

?{
? ? ? ?uchar *pkt;

net/net.c +1 -1
@@ -624,14 +625,14 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
 ? ? ? ? ? ? ? ?pkt = NetArpWaitTxPacket;
 ? ? ? ? ? ? ? ?pkt += NetSetEther(pkt, NetArpWaitPacketMAC, PROT_IP);
 
- ? ? ? ? ? ? ? NetSetIP(pkt, dest, dport, sport, len);
+ ? ? ? ? ? ? ? NetSetIP(pkt, dest, dport, sport, payload_len);

? ? ? ? ? ? ? ?memcpy(pkt + IP_UDP_HDR_SIZE, (uchar *)NetTxPacket + ? ? ? ? ? ? ? ? ? ? ? (pkt - (uchar *)NetArpWaitTxPacket) +
- ? ? ? ? ? ? ? ? ? ? ?IP_UDP_HDR_SIZE, len);
+ ? ? ? ? ? ? ? ? ? ? ?IP_UDP_HDR_SIZE, payload_len);

? ? ? ? ? ? ? ?/* size of the waiting packet */
? ? ? ? ? ? ? ?NetArpWaitTxPacketSize = (pkt - NetArpWaitTxPacket) +
- ? ? ? ? ? ? ? ? ? ? ? IP_UDP_HDR_SIZE + len;
+ ? ? ? ? ? ? ? ? ? ? ? IP_UDP_HDR_SIZE + payload_len;

? ? ? ? ? ? ? ?/* and do the ARP request */
? ? ? ? ? ? ? ?NetArpWaitTry = 1;

net/net.c +3 -2
@@ -644,8 +645,9 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
 
 ? ? ? ?pkt = (uchar *)NetTxPacket;
 ? ? ? ?pkt += NetSetEther(pkt, ether, PROT_IP);
- ? ? ? NetSetIP(pkt, dest, dport, sport, len);
- ? ? ? eth_send(NetTxPacket, (pkt - NetTxPacket) + IP_UDP_HDR_SIZE + len);
+ ? ? ? NetSetIP(pkt, dest, dport, sport, payload_len);
+ ? ? ? eth_send(NetTxPacket, (pkt - NetTxPacket) + IP_UDP_HDR_SIZE +
+ ? ? ? ? ? ? ? payload_len);
 

? ? ? ?return 0; ? ? ? /* transmitted */
?}

net/net.c +2 -2
@@ -859,9 +861,9 @@ NetReceive(volatile uchar *inpkt, int len)
 ?{
 ? ? ? ?struct Ethernet_t *et;
 ? ? ? ?struct IP_UDP_t *ip;
- ? ? ? IPaddr_t tmp;
+ ? ? ? IPaddr_t dst_ip;
 ? ? ? ?IPaddr_t src_ip;
- ? ? ? int ? ? x;
+ ? ? ? int eth_proto;
 ?#if defined(CONFIG_CMD_CDP)
 ? ? ? ?int iscdp;

?#endif

net/net.c +2 -2
@@ -896,20 +898,21 @@ NetReceive(volatile uchar *inpkt, int len)
 ? ? ? ?if (mynvlanid == (ushort)-1)
 ? ? ? ? ? ? ? ?mynvlanid = VLAN_NONE;
 
- ? ? ? x = ntohs(et->et_protlen);
+ ? ? ? eth_proto = ntohs(et->et_protlen);
 
 ? ? ? ?debug("packet received\n");
 
- ? ? ? if (x < 1514) {
+ ? ? ? if (eth_proto < 1514) {

? ? ? ? ? ? ? ?/*
- ? ? ? ? ? ? ? ?* ? ? ?Got a 802 packet. ?Check the other protocol field.
+ ? ? ? ? ? ? ? ?* ? ? ?Got a 802.2 packet. ?Check the other protocol field.
+ ? ? ? ? ? ? ? ?* ? ? ?XXX VLAN over 802.2+SNAP not implemented! ? ? ? ? ? ? ? ? */
- ? ? ? ? ? ? ? x = ntohs(et->et_prot);
+ ? ? ? ? ? ? ? eth_proto = ntohs(et->et_prot);

? ? ? ? ? ? ? ?ip = (struct IP_UDP_t *)(NetRxPacket + E802_HDR_SIZE); ? ? ? ? ? ? ? ?len -= E802_HDR_SIZE;

- ? ? ? } else if (x != PROT_VLAN) { ? ?/* normal packet */
+ ? ? ? } else if (eth_proto != PROT_VLAN) { ? ?/* normal packet */ ? ? ? ? ? ? ? ?ip = (struct IP_UDP_t *)(NetRxPacket + ETHER_HDR_SIZE); ? ? ? ? ? ? ? ?len -= ETHER_HDR_SIZE;

net/net.c +3 -3
@@ -932,17 +935,17 @@ NetReceive(volatile uchar *inpkt, int len)
 
 ? ? ? ? ? ? ? ?cti = ntohs(vet->vet_tag);
 ? ? ? ? ? ? ? ?vlanid = cti & VLAN_IDMASK;
- ? ? ? ? ? ? ? x = ntohs(vet->vet_type);
+ ? ? ? ? ? ? ? eth_proto = ntohs(vet->vet_type);
 
 ? ? ? ? ? ? ? ?ip = (struct IP_UDP_t *)(NetRxPacket + VLAN_ETHER_HDR_SIZE);
 ? ? ? ? ? ? ? ?len -= VLAN_ETHER_HDR_SIZE;
 ? ? ? ?}
 
- ? ? ? debug("Receive from protocol 0x%x\n", x);
+ ? ? ? debug("Receive from protocol 0x%x\n", eth_proto);
 
 ?#if defined(CONFIG_CMD_CDP)
 ? ? ? ?if (iscdp) {
- ? ? ? ? ? ? ? CDPHandler((uchar *)ip, len);
+ ? ? ? ? ? ? ? CDPReceive((uchar *)ip, len);
 ? ? ? ? ? ? ? ?return;
 ? ? ? ?}

?#endif

net/net.c +1 -1
@@ -955,7 +958,7 @@ NetReceive(volatile uchar *inpkt, int len)
 ? ? ? ? ? ? ? ? ? ? ? ?return;
 ? ? ? ?}
 
- ? ? ? switch (x) {
+ ? ? ? switch (eth_proto) {
 

? ? ? ?case PROT_ARP:
? ? ? ? ? ? ? ?ArpReceive(et, ip, len);

net/net.c +0 -0
@@ -994,10 +997,10 @@ NetReceive(volatile uchar *inpkt, int len)
 ? ? ? ? ? ? ? ? ? ? ? ?return;
 ? ? ? ? ? ? ? ?}

? ? ? ? ? ? ? ?/* If it is not for us, ignore it */
- ? ? ? ? ? ? ? tmp = NetReadIP(&ip->ip_dst);
- ? ? ? ? ? ? ? if (NetOurIP && tmp != NetOurIP && tmp != 0xFFFFFFFF) {
+ ? ? ? ? ? ? ? dst_ip = NetReadIP(&ip->ip_dst);
+ ? ? ? ? ? ? ? if (NetOurIP && dst_ip != NetOurIP && dst_ip != 0xFFFFFFFF) { ?#ifdef CONFIG_MCAST_TFTP
- ? ? ? ? ? ? ? ? ? ? ? if (Mcast_addr != tmp)
+ ? ? ? ? ? ? ? ? ? ? ? if (Mcast_addr != dst_ip)
?#endif
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?return;
? ? ? ? ? ? ? ?}
--
1.6.0.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#44 lore raw

PATCH 10/28 net: cosmetic: Improve variable names and code readability

Quoted 13 lines · On Tuesday 24 January 2012 01:19:14 Simon Glass wrote:
Quoted 11 lines · Joe Hershberger

Rename parameter len to payload_len in NetSendUDPPacket: this name
more explicitly claims that it does not include the header size
Rename CDPHandler to CDPReceive: this is not called as a handler,
so don't name it that way
Rename OPT_SIZE to OPT_FIELD_SIZE: clearer constant name and also
remove related BOOTP_SIZE which was unused and doesn't take into account VLAN packets
Rename tmp to reply_ip_addr in arp.c
Alphabetize includes in net.c
Replace magic numbers in arp.c with constants
Add a more explicit comment about 802.2

Quoted 2 lines

Yes but why lump all of these together? It would benefit from 3-4 separate commits IMO.

+1
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/4e4d7049/attachment.pgp>

#45 lore raw

PATCH 10/28 net: cosmetic: Improve variable names and code readability

In reply to Joe Hershberger

include/net.h struct Ethernet_t { · line 173

Quoted 6 lines · On Thursday 19 January 2012 19:53:13 Joe Hershberger wrote:
include/net.h +2 -1
 
-#define E802_HDR_SIZE	22		/* 802 ethernet header size	*/
+				/* 802.2 + SNAP + ethernet header size	*/
+#define E802_HDR_SIZE	(ETHER_HDR_SIZE + 8)

comment should be moved all the way to the left (i.e. no whitespace before it) -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/21eb7ad6/attachment.pgp>

#46 lore raw

PATCH 11/28 net: Refactor IP, UPD, and ICMP header writing functions

In reply to Joe Hershberger

ICMP (ping) was reimplementing IP header code... it now shares code.

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 include/net.h |    4 +++-
 net/bootp.c   |    6 +++---
 net/net.c     |   47 ++++++++++++++++++++++++++++-------------------
 net/ping.c    |   52 +++++++++++++++++++++++-----------------------------
 4 files changed, 57 insertions(+), 52 deletions(-)
include/net.h +3 -1
index add2080..19e9463 100644
@@ -421,7 +421,9 @@ extern int	NetEthHdrSize(void);
 extern int NetSetEther(uchar *, uchar *, uint);
 
 /* Set IP header */
-extern void NetSetIP(uchar *, IPaddr_t, int, int, int);
+extern void NetSetIPHeader(uchar *pkt, IPaddr_t dest, IPaddr_t source);
+extern void NetSetUDPHeader(uchar *pkt, IPaddr_t dest, int dport,
+				int sport, int len);
 
 /* Checksum */
 extern int	NetCksumOk(uchar *, int);	/* Return true if cksum OK */
net/bootp.c +3 -3
index 2be8083..0c2af48 100644
@@ -619,7 +619,7 @@ BootpRequest(void)
 	 * determined.
 	 * C. Hallinan, DS4.COM, Inc.
 	 */
-	/* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC,
+	/* NetSetUDPHeader(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC,
 		sizeof (struct Bootp_t)); */
 	iphdr = pkt;	/* We need this later for NetSetUDPHeader() */
 	pkt += IP_UDP_HDR_SIZE;
@@ -663,7 +663,7 @@ BootpRequest(void)
 	pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
 		sizeof(bp->bp_vend) + ext_len;
 	iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
-	NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
+	NetSetUDPHeader(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
 	NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);
 
 #if defined(CONFIG_CMD_DHCP)
@@ -844,7 +844,7 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
 	pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
 		sizeof(bp->bp_vend) + extlen;
 	iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
-	NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
+	NetSetUDPHeader(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
 
 	debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
 #ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
net/net.c +28 -19

82 lines not on this page · raw message

net/ping.c +23 -29

67 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#47 lore raw

PATCH 11/28 net: Refactor IP, UPD, and ICMP header writing functions

Hi Joe,

Quoted 11 lines · Joe Hershberger

ICMP (ping) was reimplementing IP header code... it now shares code.

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

?include/net.h | ? ?4 +++-
?net/bootp.c ? | ? ?6 +++---
?net/net.c ? ? | ? 47 ++++++++++++++++++++++++++++-------------------
?net/ping.c ? ?| ? 52 +++++++++++++++++++++++-----------------------------

?4 files changed, 57 insertions(+), 52 deletions(-)

To be honest these sorts of cleanup are great, but they are very hard to review unless you know the code well. In particular your commit message makes me imagine that you are cutting out duplicate code, but it is changing a bit also.

Quoted 147 lines
include/net.h +0 -0
index add2080..19e9463 100644
@@ -421,7 +421,9 @@ extern int ?NetEthHdrSize(void);
 ?extern int NetSetEther(uchar *, uchar *, uint);
 

?/* Set IP header */

include/net.h +3 -1
-extern void NetSetIP(uchar *, IPaddr_t, int, int, int);
+extern void NetSetIPHeader(uchar *pkt, IPaddr_t dest, IPaddr_t source);
+extern void NetSetUDPHeader(uchar *pkt, IPaddr_t dest, int dport,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int sport, int len);

?/* Checksum */
?extern int ? ? NetCksumOk(uchar *, int); ? ? ? /* Return true if cksum OK */

net/bootp.c +0 -0
index 2be8083..0c2af48 100644
@@ -619,7 +619,7 @@ BootpRequest(void)

? ? ? ? * determined.
? ? ? ? * C. Hallinan, DS4.COM, Inc.
? ? ? ? */
- ? ? ? /* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC,
+ ? ? ? /* NetSetUDPHeader(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, ? ? ? ? ? ? ? ?sizeof (struct Bootp_t)); */
? ? ? ?iphdr = pkt; ? ?/* We need this later for NetSetUDPHeader() */ ? ? ? ?pkt += IP_UDP_HDR_SIZE;

net/bootp.c +0 -0
@@ -663,7 +663,7 @@ BootpRequest(void)

? ? ? ?pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
? ? ? ? ? ? ? ?sizeof(bp->bp_vend) + ext_len;
? ? ? ?iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
- ? ? ? NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
+ ? ? ? NetSetUDPHeader(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen); ? ? ? ?NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);

?#if defined(CONFIG_CMD_DHCP)

net/bootp.c +0 -0
@@ -844,7 +844,7 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)

? ? ? ?pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
? ? ? ? ? ? ? ?sizeof(bp->bp_vend) + extlen;
? ? ? ?iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
- ? ? ? NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
+ ? ? ? NetSetUDPHeader(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);

? ? ? ?debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen); ?#ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY

net/net.c +1 -1
index 9bf74d5..a47b215 100644
@@ -625,7 +625,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
 ? ? ? ? ? ? ? ?pkt = NetArpWaitTxPacket;
 ? ? ? ? ? ? ? ?pkt += NetSetEther(pkt, NetArpWaitPacketMAC, PROT_IP);
 
- ? ? ? ? ? ? ? NetSetIP(pkt, dest, dport, sport, payload_len);
+ ? ? ? ? ? ? ? NetSetUDPHeader(pkt, dest, dport, sport, payload_len);

? ? ? ? ? ? ? ?memcpy(pkt + IP_UDP_HDR_SIZE, (uchar *)NetTxPacket + ? ? ? ? ? ? ? ? ? ? ? (pkt - (uchar *)NetArpWaitTxPacket) + ? ? ? ? ? ? ? ? ? ? ? IP_UDP_HDR_SIZE, payload_len);

net/net.c +1 -1
@@ -645,7 +645,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
 
 ? ? ? ?pkt = (uchar *)NetTxPacket;
 ? ? ? ?pkt += NetSetEther(pkt, ether, PROT_IP);
- ? ? ? NetSetIP(pkt, dest, dport, sport, payload_len);
+ ? ? ? NetSetUDPHeader(pkt, dest, dport, sport, payload_len);

? ? ? ?eth_send(NetTxPacket, (pkt - NetTxPacket) + IP_UDP_HDR_SIZE + ? ? ? ? ? ? ? ?payload_len);

net/net.c +0 -0
@@ -1250,40 +1250,49 @@ NetSetEther(uchar *xet, uchar * addr, uint prot)
 ?}
 

?void

net/net.c +1 -1
-NetSetIP(uchar *xip, IPaddr_t dest, int dport, int sport, int len)
+NetSetIPHeader(uchar *pkt, IPaddr_t dest, IPaddr_t source)

?{
- ? ? ? struct IP_UDP_t *ip = (struct IP_UDP_t *)xip;
+ ? ? ? struct IP_UDP_t *ip = (struct IP_UDP_t *)pkt;

? ? ? ?/*
- ? ? ? ?* ? ? ?If the data is an odd number of bytes, zero the
- ? ? ? ?* ? ? ?byte after the last byte so that the checksum
- ? ? ? ?* ? ? ?will work.
- ? ? ? ?*/
- ? ? ? if (len & 1)
- ? ? ? ? ? ? ? xip[IP_UDP_HDR_SIZE + len] = 0;
-
- ? ? ? /*
- ? ? ? ?* ? ? ?Construct an IP and UDP header.
- ? ? ? ?* ? ? ?(need to set no fragment bit - XXX)
+ ? ? ? ?* ? ? ?Construct an IP header.
? ? ? ? */
? ? ? ?/* IP_HDR_SIZE / 4 (not including UDP) */
? ? ? ?ip->ip_hl_v ?= 0x45;
? ? ? ?ip->ip_tos ? = 0;
- ? ? ? ip->ip_len ? = htons(IP_UDP_HDR_SIZE + len);
+ ? ? ? ip->ip_len ? = htons(IP_HDR_SIZE);
? ? ? ?ip->ip_id ? ?= htons(NetIPID++);
? ? ? ?ip->ip_off ? = htons(IP_FLAGS_DFRAG); ? /* Don't fragment */ ? ? ? ?ip->ip_ttl ? = 255;
- ? ? ? ip->ip_p ? ? = 17; ? ? ? ? ? ? ?/* UDP */
? ? ? ?ip->ip_sum ? = 0;
? ? ? ?/* already in network byte order */
- ? ? ? NetCopyIP((void *)&ip->ip_src, &NetOurIP);
- ? ? ? /* - "" - */
+ ? ? ? NetCopyIP((void *)&ip->ip_src, &source);
+ ? ? ? /* already in network byte order */
? ? ? ?NetCopyIP((void *)&ip->ip_dst, &dest);

net/net.c +20 -0
+}
+
+void
+NetSetUDPHeader(uchar *pkt, IPaddr_t dest, int dport, int sport, int len)
+{
+ ? ? ? struct IP_UDP_t *ip = (struct IP_UDP_t *)pkt;
+
+ ? ? ? /*
+ ? ? ? ?* ? ? ?If the data is an odd number of bytes, zero the
+ ? ? ? ?* ? ? ?byte after the last byte so that the checksum
+ ? ? ? ?* ? ? ?will work.
+ ? ? ? ?*/
+ ? ? ? if (len & 1)
+ ? ? ? ? ? ? ? pkt[IP_UDP_HDR_SIZE + len] = 0;
+
+ ? ? ? NetSetIPHeader(pkt, dest, NetOurIP);
+ ? ? ? ip->ip_len ? = htons(IP_UDP_HDR_SIZE + len);
+ ? ? ? ip->ip_p ? ? = IPPROTO_UDP;
+ ? ? ? ip->ip_sum ? = ~NetCksum((uchar *)ip, IP_HDR_SIZE >> 1);
+

? ? ? ?ip->udp_src ?= htons(sport);
? ? ? ?ip->udp_dst ?= htons(dport);
? ? ? ?ip->udp_len ?= htons(UDP_HDR_SIZE + len);
? ? ? ?ip->udp_xsum = 0;
- ? ? ? ip->ip_sum ? = ~NetCksum((uchar *)ip, IP_HDR_SIZE / 2); ?}

?void copy_filename(char *dst, const char *src, int size)

net/ping.c +0 -0
index 34e287c..356f107 100644
@@ -16,11 +16,31 @@ static ushort PingSeqNo;

?/* The ip address to ping */
?IPaddr_t NetPingIP;

net/ping.c +3 -0
+static void SetICMPHeader(uchar *pkt, IPaddr_t dest)
+{
+ ? ? ? /*

net/ping.c

Quoted 10 lines
net/ping.c +10 -0
+ ? ? ? ?* ? ? ?Construct an IP and ICMP header.
+ ? ? ? ?*/
+ ? ? ? struct IP_UDP_t *ip = (struct IP_UDP_t *)pkt;
+ ? ? ? struct ICMP_t *icmp = (struct ICMP_t *)&ip->udp_src;
+
+ ? ? ? NetSetIPHeader(pkt, dest, NetOurIP);
+
+ ? ? ? ip->ip_len ? = htons(IP_ICMP_HDR_SIZE);
+ ? ? ? ip->ip_p ? ? = IPPROTO_ICMP;
+ ? ? ? ip->ip_sum ? = ~NetCksum((uchar *)ip, IP_HDR_SIZE >> 1);

Is >> 1 better than / 2 ?

Quoted 55 lines
net/ping.c +9 -0
+
+ ? ? ? icmp->type = ICMP_ECHO_REQUEST;
+ ? ? ? icmp->code = 0;
+ ? ? ? icmp->checksum = 0;
+ ? ? ? icmp->un.echo.id = 0;
+ ? ? ? icmp->un.echo.sequence = htons(PingSeqNo++);
+ ? ? ? icmp->checksum = ~NetCksum((uchar *)icmp, ICMP_HDR_SIZE >> 1);
+}
+

?static int PingSend(void)
?{
? ? ? ?static uchar mac[6];
- ? ? ? struct IP_UDP_t *ip;
- ? ? ? ushort *s;
? ? ? ?uchar *pkt;

? ? ? ?/* XXX always send arp request */

net/ping.c +1 -27
@@ -35,33 +55,7 @@ static int PingSend(void)
 ? ? ? ?pkt = NetArpWaitTxPacket;
 ? ? ? ?pkt += NetSetEther(pkt, mac, PROT_IP);
 
- ? ? ? ip = (struct IP_UDP_t *)pkt;
-
- ? ? ? /*
- ? ? ? ?* Construct an IP and ICMP header.
- ? ? ? ?* (need to set no fragment bit - XXX)
- ? ? ? ?*/
- ? ? ? /* IP_HDR_SIZE / 4 (not including UDP) */
- ? ? ? ip->ip_hl_v ?= 0x45;
- ? ? ? ip->ip_tos ? = 0;
- ? ? ? ip->ip_len ? = htons(IP_HDR_SIZE + 8);
- ? ? ? ip->ip_id ? ?= htons(NetIPID++);
- ? ? ? ip->ip_off ? = htons(IP_FLAGS_DFRAG); ? /* Don't fragment */
- ? ? ? ip->ip_ttl ? = 255;
- ? ? ? ip->ip_p ? ? = 0x01; ? ? ? ? ? ?/* ICMP */
- ? ? ? ip->ip_sum ? = 0;
- ? ? ? /* already in network byte order */
- ? ? ? NetCopyIP((void *)&ip->ip_src, &NetOurIP);
- ? ? ? /* - "" - */
- ? ? ? NetCopyIP((void *)&ip->ip_dst, &NetPingIP);
- ? ? ? ip->ip_sum ? = ~NetCksum((uchar *)ip, IP_HDR_SIZE / 2);
-
- ? ? ? s = &ip->udp_src; ? ? ? ? ? ? ? /* XXX ICMP starts here */
- ? ? ? s[0] = htons(0x0800); ? ? ? ? ? /* echo-request, code */
- ? ? ? s[1] = 0; ? ? ? ? ? ? ? ? ? ? ? /* checksum */
- ? ? ? s[2] = 0; ? ? ? ? ? ? ? ? ? ? ? /* identifier */
- ? ? ? s[3] = htons(PingSeqNo++); ? ? ?/* sequence number */
- ? ? ? s[1] = ~NetCksum((uchar *)s, 8/2);
+ ? ? ? SetICMPHeader(pkt, NetPingIP);
 

? ? ? ?/* size of the waiting packet */
? ? ? ?NetArpWaitTxPacketSize =
--
1.6.0.2

Quoted 4 lines

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Regards,
Simon

#49 lore raw

PATCH 12/28 net: Refactor packet length computations

In reply to Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 net/arp.c  |   13 ++++++++-----
 net/ping.c |    7 ++++---
 net/rarp.c |    6 ++++--
 3 files changed, 16 insertions(+), 10 deletions(-)
net/arp.c +8 -5
index 456decd..60a1ded 100644
@@ -52,12 +52,14 @@ void ArpRequest(void)
 {
 	uchar *pkt;
 	struct ARP_t *arp;
+	int eth_hdr_size;
 
 	debug("ARP broadcast %d\n", NetArpWaitTry);
 
 	pkt = NetTxPacket;
 
-	pkt += NetSetEther(pkt, NetBcastAddr, PROT_ARP);
+	eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_ARP);
+	pkt += eth_hdr_size;
 
 	arp = (struct ARP_t *) pkt;
 
@@ -86,7 +88,7 @@ void ArpRequest(void)
 	}
 
 	NetWriteIP(&arp->ar_tpa, NetArpWaitReplyIP);
-	(void) eth_send(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
+	(void) eth_send(NetTxPacket, eth_hdr_size + ARP_HDR_SIZE);
 }
 
 void ArpTimeoutCheck(void)
@@ -118,6 +120,7 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 	struct ARP_t *arp;
 	IPaddr_t reply_ip_addr;
 	uchar *pkt;
+	int eth_hdr_size;
 
 	/*
 	 * We have to deal with two types of ARP packets:
@@ -155,14 +158,14 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 		/* reply with our IP address */
 		debug("Got ARP REQUEST, return our IP\n");
 		pkt = (uchar *)et;
-		pkt += NetSetEther(pkt, et->et_src, PROT_ARP);
+		eth_hdr_size = NetSetEther(pkt, et->et_src, PROT_ARP);
+		pkt += eth_hdr_size;
 		arp->ar_op = htons(ARPOP_REPLY);
 		memcpy(&arp->ar_tha, &arp->ar_sha, ARP_HLEN);
 		NetCopyIP(&arp->ar_tpa, &arp->ar_spa);
 		memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);
 		NetCopyIP(&arp->ar_spa, &NetOurIP);
-		(void) eth_send((uchar *)et,
-				(pkt - (uchar *)et) + ARP_HDR_SIZE);
+		(void) eth_send((uchar *)et, eth_hdr_size + ARP_HDR_SIZE);
 		return;
 
 	case ARPOP_REPLY:		/* arp reply */
net/ping.c +4 -3
index 356f107..12f9185 100644
@@ -42,6 +42,7 @@ static int PingSend(void)
 {
 	static uchar mac[6];
 	uchar *pkt;
+	int eth_hdr_size;
 
 	/* XXX always send arp request */
 
@@ -53,13 +54,13 @@ static int PingSend(void)
 	NetArpWaitPacketMAC = mac;
 
 	pkt = NetArpWaitTxPacket;
-	pkt += NetSetEther(pkt, mac, PROT_IP);
+	eth_hdr_size = NetSetEther(pkt, mac, PROT_IP);
+	pkt += eth_hdr_size;
 
 	SetICMPHeader(pkt, NetPingIP);
 
 	/* size of the waiting packet */
-	NetArpWaitTxPacketSize =
-		(pkt - NetArpWaitTxPacket) + IP_HDR_SIZE + 8;
+	NetArpWaitTxPacketSize = eth_hdr_size + IP_ICMP_HDR_SIZE;
 
 	/* and do the ARP request */
 	NetArpWaitTry = 1;
net/rarp.c +4 -2
index 305b0a4..3097341 100644
@@ -91,11 +91,13 @@ RarpRequest(void)
 {
 	uchar *pkt;
 	struct ARP_t *rarp;
+	int eth_hdr_size;
 
 	printf("RARP broadcast %d\n", ++RarpTry);
 	pkt = NetTxPacket;
 
-	pkt += NetSetEther(pkt, NetBcastAddr, PROT_RARP);
+	eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_RARP);
+	pkt += eth_hdr_size;
 
 	rarp = (struct ARP_t *)pkt;
 
@@ -111,7 +113,7 @@ RarpRequest(void)
 	/* dest IP addr set to broadcast */
 	memset(&rarp->ar_data[16], 0xff,        4);
 
-	NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
+	NetSendPacket(NetTxPacket, eth_hdr_size + ARP_HDR_SIZE);
 
 	NetSetTimeout(TIMEOUT, RarpTimeout);
 }
Signature · 1 line
1.6.0.2
#50 lore raw

PATCH 12/28 net: Refactor packet length computations

Quoted 3 lines · Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
Quoted 125 lines

---

?net/arp.c ?| ? 13 ++++++++-----
?net/ping.c | ? ?7 ++++---
?net/rarp.c | ? ?6 ++++--

?3 files changed, 16 insertions(+), 10 deletions(-)

net/arp.c +5 -2
index 456decd..60a1ded 100644
@@ -52,12 +52,14 @@ void ArpRequest(void)
 ?{
 ? ? ? ?uchar *pkt;
 ? ? ? ?struct ARP_t *arp;
+ ? ? ? int eth_hdr_size;
 
 ? ? ? ?debug("ARP broadcast %d\n", NetArpWaitTry);
 
 ? ? ? ?pkt = NetTxPacket;
 
- ? ? ? pkt += NetSetEther(pkt, NetBcastAddr, PROT_ARP);
+ ? ? ? eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_ARP);
+ ? ? ? pkt += eth_hdr_size;
 
 ? ? ? ?arp = (struct ARP_t *) pkt;
 
@@ -86,7 +88,7 @@ void ArpRequest(void)
 ? ? ? ?}
 
 ? ? ? ?NetWriteIP(&arp->ar_tpa, NetArpWaitReplyIP);
- ? ? ? (void) eth_send(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
+ ? ? ? (void) eth_send(NetTxPacket, eth_hdr_size + ARP_HDR_SIZE);
 ?}
 
 ?void ArpTimeoutCheck(void)
@@ -118,6 +120,7 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 ? ? ? ?struct ARP_t *arp;
 ? ? ? ?IPaddr_t reply_ip_addr;
 ? ? ? ?uchar *pkt;
+ ? ? ? int eth_hdr_size;
 

? ? ? ?/*
? ? ? ? * We have to deal with two types of ARP packets:

net/arp.c +0 -0
@@ -155,14 +158,14 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)

? ? ? ? ? ? ? ?/* reply with our IP address */
? ? ? ? ? ? ? ?debug("Got ARP REQUEST, return our IP\n");
? ? ? ? ? ? ? ?pkt = (uchar *)et;
- ? ? ? ? ? ? ? pkt += NetSetEther(pkt, et->et_src, PROT_ARP);
+ ? ? ? ? ? ? ? eth_hdr_size = NetSetEther(pkt, et->et_src, PROT_ARP);
+ ? ? ? ? ? ? ? pkt += eth_hdr_size;
? ? ? ? ? ? ? ?arp->ar_op = htons(ARPOP_REPLY);
? ? ? ? ? ? ? ?memcpy(&arp->ar_tha, &arp->ar_sha, ARP_HLEN);
? ? ? ? ? ? ? ?NetCopyIP(&arp->ar_tpa, &arp->ar_spa);
? ? ? ? ? ? ? ?memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);
? ? ? ? ? ? ? ?NetCopyIP(&arp->ar_spa, &NetOurIP);
- ? ? ? ? ? ? ? (void) eth_send((uchar *)et,
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (pkt - (uchar *)et) + ARP_HDR_SIZE);
+ ? ? ? ? ? ? ? (void) eth_send((uchar *)et, eth_hdr_size + ARP_HDR_SIZE); ? ? ? ? ? ? ? ?return;

? ? ? ?case ARPOP_REPLY: ? ? ? ? ? ? ? /* arp reply */

net/ping.c +1 -0
index 356f107..12f9185 100644
@@ -42,6 +42,7 @@ static int PingSend(void)
 ?{
 ? ? ? ?static uchar mac[6];
 ? ? ? ?uchar *pkt;
+ ? ? ? int eth_hdr_size;
 

? ? ? ?/* XXX always send arp request */

net/ping.c +2 -1
@@ -53,13 +54,13 @@ static int PingSend(void)
 ? ? ? ?NetArpWaitPacketMAC = mac;
 
 ? ? ? ?pkt = NetArpWaitTxPacket;
- ? ? ? pkt += NetSetEther(pkt, mac, PROT_IP);
+ ? ? ? eth_hdr_size = NetSetEther(pkt, mac, PROT_IP);
+ ? ? ? pkt += eth_hdr_size;
 
 ? ? ? ?SetICMPHeader(pkt, NetPingIP);
 

? ? ? ?/* size of the waiting packet */
- ? ? ? NetArpWaitTxPacketSize =
- ? ? ? ? ? ? ? (pkt - NetArpWaitTxPacket) + IP_HDR_SIZE + 8;
+ ? ? ? NetArpWaitTxPacketSize = eth_hdr_size + IP_ICMP_HDR_SIZE;

? ? ? ?/* and do the ARP request */
? ? ? ?NetArpWaitTry = 1;

net/rarp.c +3 -1
index 305b0a4..3097341 100644
@@ -91,11 +91,13 @@ RarpRequest(void)
 ?{
 ? ? ? ?uchar *pkt;
 ? ? ? ?struct ARP_t *rarp;
+ ? ? ? int eth_hdr_size;
 
 ? ? ? ?printf("RARP broadcast %d\n", ++RarpTry);
 ? ? ? ?pkt = NetTxPacket;
 
- ? ? ? pkt += NetSetEther(pkt, NetBcastAddr, PROT_RARP);
+ ? ? ? eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_RARP);
+ ? ? ? pkt += eth_hdr_size;
 
 ? ? ? ?rarp = (struct ARP_t *)pkt;
 
@@ -111,7 +113,7 @@ RarpRequest(void)

? ? ? ?/* dest IP addr set to broadcast */ ? ? ? ?memset(&rarp->ar_data[16], 0xff, ? ? ? ?4);

- ? ? ? NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
+ ? ? ? NetSendPacket(NetTxPacket, eth_hdr_size + ARP_HDR_SIZE);

? ? ? ?NetSetTimeout(TIMEOUT, RarpTimeout);
?}
--
1.6.0.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#52 lore raw

PATCH 13/28 net: Refactor bootp packet length computations

In reply to Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 net/bootp.c |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)
net/bootp.c +14 -12
index 0c2af48..0d5f4cf 100644
@@ -582,7 +582,8 @@ BootpRequest(void)
 {
 	uchar *pkt, *iphdr;
 	struct Bootp_t *bp;
-	int ext_len, pktlen, iplen;
+	int extlen, pktlen, iplen;
+	int eth_hdr_size;
 #ifdef CONFIG_BOOTP_RANDOM_DELAY
 	ulong i, rand_ms;
 #endif
@@ -610,7 +611,8 @@ BootpRequest(void)
 	pkt = NetTxPacket;
 	memset((void *)pkt, 0, PKTSIZE);
 
-	pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
+	eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP);
+	pkt += eth_hdr_size;
 
 	/*
 	 * Next line results in incorrect packet size being transmitted,
@@ -639,9 +641,9 @@ BootpRequest(void)
 
 	/* Request additional information from the BOOTP/DHCP server */
 #if defined(CONFIG_CMD_DHCP)
-	ext_len = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
+	extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
 #else
-	ext_len = BootpExtended((u8 *)bp->bp_vend);
+	extlen = BootpExtended((u8 *)bp->bp_vend);
 #endif
 
 	/*
@@ -660,9 +662,8 @@ BootpRequest(void)
 	 * Calculate proper packet lengths taking into account the
 	 * variable size of the options field
 	 */
-	pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
-		sizeof(bp->bp_vend) + ext_len;
-	iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
+	iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
+	pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
 	NetSetUDPHeader(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
 	NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);
 
@@ -798,13 +799,15 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
 	uchar *pkt, *iphdr;
 	struct Bootp_t *bp;
 	int pktlen, iplen, extlen;
+	int eth_hdr_size;
 	IPaddr_t OfferedIP;
 
 	debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
 	pkt = NetTxPacket;
 	memset((void *)pkt, 0, PKTSIZE);
 
-	pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
+	eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP);
+	pkt += eth_hdr_size;
 
 	iphdr = pkt;	/* We'll need this later to set proper pkt size */
 	pkt += IP_UDP_HDR_SIZE;
@@ -841,15 +844,14 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
 	extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST,
 		NetDHCPServerIP, OfferedIP);
 
-	pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
-		sizeof(bp->bp_vend) + extlen;
-	iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
+	iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
+	pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
 	NetSetUDPHeader(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
 
-	debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
 #ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
 	udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
 #endif	/* CONFIG_BOOTP_DHCP_REQUEST_DELAY */
+	debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
 	NetSendPacket(NetTxPacket, pktlen);
 }
 
Signature · 1 line
1.6.0.2
#53 lore raw

PATCH 13/28 net: Refactor bootp packet length computations

Hi Joe,

Quoted 7 lines · Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---
?net/bootp.c | ? 26 ++++++++++++++------------ ?1 files changed, 14 insertions(+), 12 deletions(-)

Refactor why or to what purpose? Perhaps a bit more detail in the commit message?

net/bootp.c BootpRequest(void) · line 585

Quoted 10 lines
net/bootp.c +1 -1
index 0c2af48..0d5f4cf 100644
@@ -582,7 +582,8 @@ BootpRequest(void)
 ?{
 ? ? ? ?uchar *pkt, *iphdr;
 ? ? ? ?struct Bootp_t *bp;
- ? ? ? int ext_len, pktlen, iplen;
+ ? ? ? int extlen, pktlen, iplen;

Is extlen better than ext_len?

Quoted 67 lines
net/bootp.c +1 -0
+ ? ? ? int eth_hdr_size;

?#ifdef CONFIG_BOOTP_RANDOM_DELAY
? ? ? ?ulong i, rand_ms;
?#endif

net/bootp.c +2 -1
@@ -610,7 +611,8 @@ BootpRequest(void)
 ? ? ? ?pkt = NetTxPacket;
 ? ? ? ?memset((void *)pkt, 0, PKTSIZE);
 
- ? ? ? pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
+ ? ? ? eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP);
+ ? ? ? pkt += eth_hdr_size;
 

? ? ? ?/*
? ? ? ? * Next line results in incorrect packet size being transmitted,

net/bootp.c +0 -0
@@ -639,9 +641,9 @@ BootpRequest(void)
 

? ? ? ?/* Request additional information from the BOOTP/DHCP server */ ?#if defined(CONFIG_CMD_DHCP)
- ? ? ? ext_len = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
+ ? ? ? extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0); ?#else
- ? ? ? ext_len = BootpExtended((u8 *)bp->bp_vend);
+ ? ? ? extlen = BootpExtended((u8 *)bp->bp_vend);
?#endif

? ? ? ?/*

net/bootp.c +0 -0
@@ -660,9 +662,8 @@ BootpRequest(void)

? ? ? ? * Calculate proper packet lengths taking into account the ? ? ? ? * variable size of the options field
? ? ? ? */
- ? ? ? pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
- ? ? ? ? ? ? ? sizeof(bp->bp_vend) + ext_len;
- ? ? ? iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
+ ? ? ? iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
+ ? ? ? pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
? ? ? ?NetSetUDPHeader(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen); ? ? ? ?NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);

net/bootp.c +3 -1
@@ -798,13 +799,15 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
 ? ? ? ?uchar *pkt, *iphdr;
 ? ? ? ?struct Bootp_t *bp;
 ? ? ? ?int pktlen, iplen, extlen;
+ ? ? ? int eth_hdr_size;
 ? ? ? ?IPaddr_t OfferedIP;
 
 ? ? ? ?debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
 ? ? ? ?pkt = NetTxPacket;
 ? ? ? ?memset((void *)pkt, 0, PKTSIZE);
 
- ? ? ? pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
+ ? ? ? eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP);
+ ? ? ? pkt += eth_hdr_size;
 

? ? ? ?iphdr = pkt; ? ?/* We'll need this later to set proper pkt size */ ? ? ? ?pkt += IP_UDP_HDR_SIZE;

net/bootp.c +2 -4
@@ -841,15 +844,14 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
 ? ? ? ?extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST,
 ? ? ? ? ? ? ? ?NetDHCPServerIP, OfferedIP);
 
- ? ? ? pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
- ? ? ? ? ? ? ? sizeof(bp->bp_vend) + extlen;
- ? ? ? iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
+ ? ? ? iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
+ ? ? ? pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
 ? ? ? ?NetSetUDPHeader(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
 
- ? ? ? debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
Quoted 4 lines

?#ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
? ? ? ?udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
?#endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */
+ ? ? ? debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);

Did you move this on purpose?

Quoted 10 lines

? ? ? ?NetSendPacket(NetTxPacket, pktlen);
?}

--
1.6.0.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Regards,
Simon

#54 lore raw

PATCH 13/28 net: Refactor bootp packet length computations

Hi Simon,

Quoted 11 lines · Simon Glass

Hi Joe,

Quoted 7 lines · Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

---
?net/bootp.c | ? 26 ++++++++++++++------------ ?1 files changed, 14 insertions(+), 12 deletions(-)

Quoted 2 lines

Refactor why or to what purpose? Perhaps a bit more detail in the commit message?

Just removing the pointer subtraction similar to patch 12.

Quoted 4 lines
Quoted 4 lines
net/bootp.c +0 -0
index 0c2af48..0d5f4cf 100644
Quoted 8 lines

net/bootp.c BootpRequest(void) · line 585

Quoted 6 lines
net/bootp.c +1 -1
@@ -582,7 +582,8 @@ BootpRequest(void)
 ?{
 ? ? ? ?uchar *pkt, *iphdr;
 ? ? ? ?struct Bootp_t *bp;
- ? ? ? int ext_len, pktlen, iplen;
+ ? ? ? int extlen, pktlen, iplen;

Is extlen better than ext_len?

Just more consistent with other variables in the same calculations. Not especially important, I guess.

Quoted 66 lines
Quoted 66 lines
net/bootp.c +1 -0
+ ? ? ? int eth_hdr_size;

?#ifdef CONFIG_BOOTP_RANDOM_DELAY
? ? ? ?ulong i, rand_ms;
?#endif

net/bootp.c +2 -1
@@ -610,7 +611,8 @@ BootpRequest(void)
 ? ? ? ?pkt = NetTxPacket;
 ? ? ? ?memset((void *)pkt, 0, PKTSIZE);
 
- ? ? ? pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
+ ? ? ? eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP);
+ ? ? ? pkt += eth_hdr_size;
 

? ? ? ?/*
? ? ? ? * Next line results in incorrect packet size being transmitted,

net/bootp.c +0 -0
@@ -639,9 +641,9 @@ BootpRequest(void)
 

? ? ? ?/* Request additional information from the BOOTP/DHCP server */ ?#if defined(CONFIG_CMD_DHCP)
- ? ? ? ext_len = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
+ ? ? ? extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0); ?#else
- ? ? ? ext_len = BootpExtended((u8 *)bp->bp_vend);
+ ? ? ? extlen = BootpExtended((u8 *)bp->bp_vend);
?#endif

? ? ? ?/*

net/bootp.c +0 -0
@@ -660,9 +662,8 @@ BootpRequest(void)

? ? ? ? * Calculate proper packet lengths taking into account the ? ? ? ? * variable size of the options field
? ? ? ? */
- ? ? ? pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
- ? ? ? ? ? ? ? sizeof(bp->bp_vend) + ext_len;
- ? ? ? iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
+ ? ? ? iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
+ ? ? ? pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
? ? ? ?NetSetUDPHeader(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen); ? ? ? ?NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);

net/bootp.c +3 -1
@@ -798,13 +799,15 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
 ? ? ? ?uchar *pkt, *iphdr;
 ? ? ? ?struct Bootp_t *bp;
 ? ? ? ?int pktlen, iplen, extlen;
+ ? ? ? int eth_hdr_size;
 ? ? ? ?IPaddr_t OfferedIP;
 
 ? ? ? ?debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
 ? ? ? ?pkt = NetTxPacket;
 ? ? ? ?memset((void *)pkt, 0, PKTSIZE);
 
- ? ? ? pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
+ ? ? ? eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP);
+ ? ? ? pkt += eth_hdr_size;
 

? ? ? ?iphdr = pkt; ? ?/* We'll need this later to set proper pkt size */ ? ? ? ?pkt += IP_UDP_HDR_SIZE;

net/bootp.c +2 -3
@@ -841,15 +844,14 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
 ? ? ? ?extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST,
 ? ? ? ? ? ? ? ?NetDHCPServerIP, OfferedIP);
 
- ? ? ? pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
- ? ? ? ? ? ? ? sizeof(bp->bp_vend) + extlen;
- ? ? ? iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
+ ? ? ? iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
+ ? ? ? pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
 ? ? ? ?NetSetUDPHeader(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
 
Quoted 7 lines
Quoted 5 lines
net/bootp.c +0 -1
- ? ? ? debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);

?#ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
? ? ? ?udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
?#endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */
+ ? ? ? debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);

Did you move this on purpose?

Yes... I figured a transmit debug message should be close to the transmit... not before a delay.

Quoted 2 lines
Quoted 2 lines

? ? ? ?NetSendPacket(NetTxPacket, pktlen);
?}

Best regards,
-Joe

#55 lore raw

PATCH 13/28 net: Refactor bootp packet length computations

Quoted 8 lines · On Tuesday 24 January 2012 02:15:41 Joe Hershberger wrote:
Quoted 7 lines · Simon Glass
Quoted 5 lines · Joe Hershberger
net/bootp.c +1 -1
-       debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
 #ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
       udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
 #endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */
+       debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
Quoted 4 lines
Quoted 1 line

Did you move this on purpose?

Yes... I figured a transmit debug message should be close to the transmit... not before a delay.

generally we frown on these sort of side-commits ...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/f4015037/attachment.pgp>

#56 lore raw

PATCH 14/28 net: Refactor ping recieve handler

In reply to Joe Hershberger

There is no need to call through the handler when we can handle it inline

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 net/ping.c |   19 ++-----------------
 1 files changed, 2 insertions(+), 17 deletions(-)
net/ping.c +2 -17
index 12f9185..e4a7a21 100644
@@ -76,22 +76,11 @@ PingTimeout(void)
 	NetState = NETLOOP_FAIL;	/* we did not get the reply */
 }
 
-static void
-PingHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
-	    unsigned len)
-{
-	if (sip != NetPingIP)
-		return;
-
-	NetState = NETLOOP_SUCCESS;
-}
-
 void
 PingStart(void)
 {
 	printf("Using %s device\n", eth_get_name());
 	NetSetTimeout(10000UL, PingTimeout);
-	NetSetHandler(PingHandler);
 
 	PingSend();
 }
@@ -103,13 +92,9 @@ void PingReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 
 	switch (icmph->type) {
 	case ICMP_ECHO_REPLY:
-		/*
-		 * IP header OK.  Pass the packet to the
-		 * current handler.
-		 */
-		/* XXX point to ip packet */
 		src_ip = NetReadIP((void *)&ip->ip_src);
-		NetGetHandler()((uchar *)ip, 0, src_ip, 0, 0);
+		if (src_ip == NetPingIP)
+			NetState = NETLOOP_SUCCESS;
 		return;
 	case ICMP_ECHO_REQUEST:
 		debug("Got ICMP ECHO REQUEST, return "
Signature · 1 line
1.6.0.2
#58 lore raw

PATCH 15/28 net: Refactor to call NetSendPacket() instead of calling eth_send()

In reply to Joe Hershberger

Use this entry-point consistently across the net/ code

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 net/arp.c  |    6 +++---
 net/cdp.c  |    2 +-
 net/net.c  |    2 +-
 net/ping.c |    3 +--
 4 files changed, 6 insertions(+), 7 deletions(-)
net/arp.c +3 -3
index 60a1ded..d9113dc 100644
@@ -88,7 +88,7 @@ void ArpRequest(void)
 	}
 
 	NetWriteIP(&arp->ar_tpa, NetArpWaitReplyIP);
-	(void) eth_send(NetTxPacket, eth_hdr_size + ARP_HDR_SIZE);
+	NetSendPacket(NetTxPacket, eth_hdr_size + ARP_HDR_SIZE);
 }
 
 void ArpTimeoutCheck(void)
@@ -165,7 +165,7 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 		NetCopyIP(&arp->ar_tpa, &arp->ar_spa);
 		memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);
 		NetCopyIP(&arp->ar_spa, &NetOurIP);
-		(void) eth_send((uchar *)et, eth_hdr_size + ARP_HDR_SIZE);
+		NetSendPacket((uchar *)et, eth_hdr_size + ARP_HDR_SIZE);
 		return;
 
 	case ARPOP_REPLY:		/* arp reply */
@@ -198,7 +198,7 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 			/* modify header, and transmit it */
 			memcpy(((struct Ethernet_t *)NetArpWaitTxPacket)->
 				et_dest, NetArpWaitPacketMAC, ARP_HLEN);
-			(void) eth_send(NetArpWaitTxPacket,
+			NetSendPacket(NetArpWaitTxPacket,
 					NetArpWaitTxPacketSize);
 
 			/* no arp request pending now */
net/cdp.c +1 -1
index 38b79bd..305ecad 100644
@@ -215,7 +215,7 @@ CDPSendTrigger(void)
 		chksum = 0xFFFF;
 	*cp = htons(chksum);
 
-	(void) eth_send(NetTxPacket, (uchar *)s - NetTxPacket);
+	NetSendPacket(NetTxPacket, (uchar *)s - NetTxPacket);
 	return 0;
 }
 
net/net.c +1 -1
index a47b215..16cbadc 100644
@@ -646,7 +646,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
 	pkt = (uchar *)NetTxPacket;
 	pkt += NetSetEther(pkt, ether, PROT_IP);
 	NetSetUDPHeader(pkt, dest, dport, sport, payload_len);
-	eth_send(NetTxPacket, (pkt - NetTxPacket) + IP_UDP_HDR_SIZE +
+	NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + IP_UDP_HDR_SIZE +
 		payload_len);
 
 	return 0;	/* transmitted */
net/ping.c +1 -2
index e4a7a21..7d03072 100644
@@ -114,8 +114,7 @@ void PingReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 		icmph->checksum = 0;
 		icmph->checksum = ~NetCksum((uchar *)icmph,
 			(len - IP_HDR_SIZE) >> 1);
-		(void) eth_send((uchar *)et,
-				ETHER_HDR_SIZE + len);
+		NetSendPacket((uchar *)et, ETHER_HDR_SIZE + len);
 		return;
 /*	default:
 		return;*/
Signature · 1 line
1.6.0.2
#59 lore raw

PATCH 15/28 net: Refactor to call NetSendPacket() instead of calling eth_send()

Quoted 1 line · On Thursday 19 January 2012 19:53:18 Joe Hershberger wrote:

Use this entry-point consistently across the net/ code

i like this, but i'd like it even more if NetSendPacket() was a static inline in the header. all this func does is jump straight to eth_send():

01fa2054 <_NetSendPacket>:
1fa2054: ff e2 f6 fd JUMP.L 0x1fa1c40 <_eth_send>;
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/28dcc98d/attachment.pgp>

#60 lore raw

PATCH 16/28 net: Refactor to protect access to the NetState variable

In reply to Joe Hershberger

Changes to NetState now go through an accessor function called NetSetState()

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 drivers/net/netconsole.c |    6 +++---
 include/net.h            |   13 +++++++------
 net/cdp.c                |    2 +-
 net/dns.c                |    8 ++++----
 net/net.c                |   21 ++++++++++++++-------
 net/nfs.c                |    6 +++---
 net/ping.c               |    4 ++--
 net/sntp.c               |    4 ++--
 net/tftp.c               |    8 ++++----
 9 files changed, 40 insertions(+), 32 deletions(-)
drivers/net/netconsole.c +3 -3
index ba02fd7..89b5956 100644
@@ -44,19 +44,19 @@ 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 */
+	NetSetState(NETLOOP_SUCCESS); /* got arp reply - quit net loop */
 }
 
 static void nc_handler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 			unsigned len)
 {
 	if (input_size)
-		NetState = NETLOOP_SUCCESS; /* got input - quit net loop */
+		NetSetState(NETLOOP_SUCCESS); /* got input - quit net loop */
 }
 
 static void nc_timeout(void)
 {
-	NetState = NETLOOP_SUCCESS;
+	NetSetState(NETLOOP_SUCCESS);
 }
 
 void NcStart(void)
include/net.h +7 -6
index 19e9463..fe49ff7 100644
@@ -364,12 +364,6 @@ extern uchar		NetEtherNullAddr[6];
 extern ushort		NetOurVLAN;		/* Our VLAN */
 extern ushort		NetOurNativeVLAN;	/* Our Native VLAN */
 
-extern int		NetState;		/* Network loop state */
-#define NETLOOP_CONTINUE	1
-#define NETLOOP_RESTART		2
-#define NETLOOP_SUCCESS		3
-#define NETLOOP_FAIL		4
-
 extern int		NetRestartWrap;		/* Tried all network devices */
 
 enum proto_t {
@@ -435,6 +429,13 @@ extern void	NetSetHandler(rxhand_f *);	/* Set RX packet handler */
 extern void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */
 extern void	NetSetTimeout(ulong, thand_f *);/* Set timeout handler */
 
+/* Network loop state */
+extern void	NetSetState(int state);
+#define NETLOOP_CONTINUE	1
+#define NETLOOP_RESTART		2
+#define NETLOOP_SUCCESS		3
+#define NETLOOP_FAIL		4
+
 /* Transmit "NetTxPacket" */
 extern void NetSendPacket(uchar *, int);
 
net/cdp.c +1 -1
index 305ecad..31f9ce7 100644
@@ -234,7 +234,7 @@ CDPTimeout(void)
 	if (!CDPOK)
 		NetStartAgain();
 	else
-		NetState = NETLOOP_SUCCESS;
+		NetSetState(NETLOOP_SUCCESS);
 }
 
 static void
net/dns.c +4 -4
index cc7ed51..0b655cc 100644
@@ -98,7 +98,7 @@ static void
 DnsTimeout(void)
 {
 	puts("Timeout\n");
-	NetState = NETLOOP_FAIL;
+	NetSetState(NETLOOP_FAIL);
 }
 
 static void
@@ -128,7 +128,7 @@ DnsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
 	/* Received 0 answers */
 	if (header->nanswers == 0) {
 		puts("DNS: host not found\n");
-		NetState = NETLOOP_SUCCESS;
+		NetSetState(NETLOOP_SUCCESS);
 		return;
 	}
 
@@ -141,7 +141,7 @@ DnsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
 	/* We sent query class 1, query type 1 */
 	if (&p[5] > e || get_unaligned_be16(p+1) != DNS_A_RECORD) {
 		puts("DNS: response was not an A record\n");
-		NetState = NETLOOP_SUCCESS;
+		NetSetState(NETLOOP_SUCCESS);
 		return;
 	}
 
@@ -191,7 +191,7 @@ DnsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
 			puts("server responded with invalid IP number\n");
 	}
 
-	NetState = NETLOOP_SUCCESS;
+	NetSetState(NETLOOP_SUCCESS);
 }
 
 void
net/net.c +14 -7
index 16cbadc..a92df90 100644
@@ -154,7 +154,7 @@ uchar		NetEtherNullAddr[6];
 void		(*push_packet)(volatile void *, int len) = 0;
 #endif
 /* Network loop state */
-int		NetState;
+static int	NetState;
 /* Tried all network devices */
 int		NetRestartWrap;
 /* Network loop restarted */
@@ -217,7 +217,7 @@ void net_auto_load(void)
 			 * Just use BOOTP/RARP to configure system;
 			 * Do not use TFTP to load the bootfile.
 			 */
-			NetState = NETLOOP_SUCCESS;
+			NetSetState(NETLOOP_SUCCESS);
 			return;
 		}
 #if defined(CONFIG_CMD_NFS)
@@ -296,7 +296,7 @@ int NetLoop(enum proto_t protocol)
 restart:
 	memcpy(NetOurEther, eth_get_dev()->enetaddr, 6);
 
-	NetState = NETLOOP_CONTINUE;
+	NetSetState(NETLOOP_CONTINUE);
 
 	/*
 	 *	Start the ball rolling with the given start function.  From
@@ -498,7 +498,7 @@ done:
 static void
 startAgainTimeout(void)
 {
-	NetState = NETLOOP_RESTART;
+	NetSetState(NETLOOP_RESTART);
 }
 
 static void
@@ -529,7 +529,7 @@ void NetStartAgain(void)
 
 	if ((!retry_forever) && (NetTryCount >= retrycnt)) {
 		eth_halt();
-		NetState = NETLOOP_FAIL;
+		NetSetState(NETLOOP_FAIL);
 		return;
 	}
 
@@ -546,10 +546,10 @@ void NetStartAgain(void)
 			NetSetTimeout(10000UL, startAgainTimeout);
 			NetSetHandler(startAgainHandler);
 		} else {
-			NetState = NETLOOP_FAIL;
+			NetSetState(NETLOOP_FAIL);
 		}
 	} else {
-		NetState = NETLOOP_RESTART;
+		NetSetState(NETLOOP_RESTART);
 	}
 }
 
@@ -592,6 +592,13 @@ NetSetTimeout(ulong iv, thand_f *f)
 
 
 void
+NetSetState(int state)
+{
+	NetState = state;
+}
+
+
+void
 NetSendPacket(uchar *pkt, int len)
 {
 	(void) eth_send(pkt, len);
net/nfs.c +3 -3
index b6188fe..e366505 100644
@@ -613,10 +613,10 @@ NfsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
 	case STATE_UMOUNT_REQ:
 		if (nfs_umountall_reply(pkt, len)) {
 			puts("*** ERROR: Cannot umount\n");
-			NetState = NETLOOP_FAIL;
+			NetSetState(NETLOOP_FAIL);
 		} else {
 			puts("\ndone\n");
-			NetState = NfsDownloadState;
+			NetSetState(NfsDownloadState);
 		}
 		break;
 
@@ -679,7 +679,7 @@ NfsStart(void)
 	nfs_path = (char *)nfs_path_buff;
 
 	if (nfs_path == NULL) {
-		NetState = NETLOOP_FAIL;
+		NetSetState(NETLOOP_FAIL);
 		puts("*** ERROR: Fail allocate memory\n");
 		return;
 	}
net/ping.c +2 -2
index 7d03072..795d5c9 100644
@@ -73,7 +73,7 @@ static void
 PingTimeout(void)
 {
 	eth_halt();
-	NetState = NETLOOP_FAIL;	/* we did not get the reply */
+	NetSetState(NETLOOP_FAIL);	/* we did not get the reply */
 }
 
 void
@@ -94,7 +94,7 @@ void PingReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 	case ICMP_ECHO_REPLY:
 		src_ip = NetReadIP((void *)&ip->ip_src);
 		if (src_ip == NetPingIP)
-			NetState = NETLOOP_SUCCESS;
+			NetSetState(NETLOOP_SUCCESS);
 		return;
 	case ICMP_ECHO_REQUEST:
 		debug("Got ICMP ECHO REQUEST, return "
net/sntp.c +2 -2
index 7997f98..f5fa6f7 100644
@@ -45,7 +45,7 @@ static void
 SntpTimeout(void)
 {
 	puts("Timeout\n");
-	NetState = NETLOOP_FAIL;
+	NetSetState(NETLOOP_FAIL);
 	return;
 }
 
@@ -76,7 +76,7 @@ SntpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 		tm.tm_year, tm.tm_mon, tm.tm_mday,
 		tm.tm_hour, tm.tm_min, tm.tm_sec);
 
-	NetState = NETLOOP_SUCCESS;
+	NetSetState(NETLOOP_SUCCESS);
 }
 
 void
net/tftp.c +4 -4
index a04a832..49ddbd7 100644
@@ -177,7 +177,7 @@ store_block(unsigned block, uchar *src, unsigned len)
 		rc = flash_write((char *)src, (ulong)(load_addr+offset), len);
 		if (rc) {
 			flash_perror(rc);
-			NetState = NETLOOP_FAIL;
+			NetSetState(NETLOOP_FAIL);
 			return;
 		}
 	} else
@@ -300,7 +300,7 @@ static void tftp_complete(void)
 	}
 #endif
 	puts("\ndone\n");
-	NetState = NETLOOP_SUCCESS;
+	NetSetState(NETLOOP_SUCCESS);
 }
 
 static void
@@ -627,7 +627,7 @@ TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 			if (MasterClient && (TftpBlock >= TftpEndingBlock)) {
 				puts("\nMulticast tftp done\n");
 				mcast_cleanup();
-				NetState = NETLOOP_SUCCESS;
+				NetSetState(NETLOOP_SUCCESS);
 			}
 		} else
 #endif
@@ -644,7 +644,7 @@ TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 		case TFTP_ERR_ACCESS_DENIED:
 			puts("Not retrying...\n");
 			eth_halt();
-			NetState = NETLOOP_FAIL;
+			NetSetState(NETLOOP_FAIL);
 			break;
 		case TFTP_ERR_UNDEFINED:
 		case TFTP_ERR_DISK_FULL:
Signature · 1 line
1.6.0.2
#61 lore raw

PATCH 16/28 net: Refactor to protect access to the NetState variable

Quoted 2 lines · On Thursday 19 January 2012 19:53:19 Joe Hershberger wrote:

Changes to NetState now go through an accessor function called NetSetState()

i'm not sure i see the value here. all i see is overhead being added. if you really want this to be an improvement, there's two minor tweaks to make.

include/net.h extern void NetSetHandler(rxhand_f *); /* Set RX packet handler */ · line 433

Quoted 5 lines
include/net.h +2 -0
 
+/* Network loop state */
+extern void	NetSetState(int state);

make this into a static inline

include/net.h extern void NetSetHandler(rxhand_f *); /* Set RX packet handler */ · line 437

Quoted 4 lines
include/net.h +4 -0
+#define NETLOOP_CONTINUE	1
+#define NETLOOP_RESTART		2
+#define NETLOOP_SUCCESS		3
+#define NETLOOP_FAIL		4

turn these into an enum
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/f017eb94/attachment.pgp>

#62 lore raw

PATCH 17/28 net: Refactor to separate the UDP handler from the ARP handler

In reply to Joe Hershberger

Only call the handlers if one was registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp (instead of
needing a #define hack in arp.c)
Clear handlers at the end of net loop

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 drivers/net/netconsole.c |    4 +-
 include/net.h            |    9 ++++--
 net/arp.c                |    7 ++--
 net/bootp.c              |    4 +-
 net/cdp.c                |    8 -----
 net/dns.c                |    2 +-
 net/net.c                |   70 +++++++++++++++++++++++++++++-----------------
 net/nfs.c                |    2 +-
 net/sntp.c               |    2 +-
 net/tftp.c               |    4 +-
 10 files changed, 63 insertions(+), 49 deletions(-)
drivers/net/netconsole.c +2 -2
index 89b5956..1e31159 100644
@@ -63,12 +63,12 @@ void NcStart(void)
 {
 	if (!output_packet_len || memcmp(nc_ether, NetEtherNullAddr, 6)) {
 		/* going to check for input packet */
-		NetSetHandler(nc_handler);
+		NetSetUDPHandler(nc_handler);
 		NetSetTimeout(net_timeout, nc_timeout);
 	} else {
 		/* send arp request */
 		uchar *pkt;
-		NetSetHandler(nc_wait_arp_handler);
+		NetSetARPHandler(nc_wait_arp_handler);
 		pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE;
 		memcpy(pkt, output_packet, output_packet_len);
 		NetSendUDPPacket(nc_ether, nc_ip, nc_port, nc_port,
include/net.h +6 -3
index fe49ff7..dca8e1c 100644
@@ -424,8 +424,10 @@ extern int	NetCksumOk(uchar *, int);	/* Return true if cksum OK */
 extern uint	NetCksum(uchar *, int);		/* Calculate the checksum */
 
 /* Callbacks */
-extern rxhand_f *NetGetHandler(void);		/* Get RX packet handler */
-extern void	NetSetHandler(rxhand_f *);	/* Set RX packet handler */
+extern rxhand_f *NetGetUDPHandler(void);	/* Get UDP RX packet handler */
+extern void	NetSetUDPHandler(rxhand_f *);	/* Set UDP RX packet handler */
+extern rxhand_f *NetGetARPHandler(void);	/* Get ARP RX packet handler */
+extern void	NetSetARPHandler(rxhand_f *);	/* Set ARP RX packet handler */
 extern void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */
 extern void	NetSetTimeout(ulong, thand_f *);/* Set timeout handler */
 
@@ -439,7 +441,8 @@ extern void	NetSetState(int state);
 /* Transmit "NetTxPacket" */
 extern void NetSendPacket(uchar *, int);
 
-/* Transmit UDP packet, performing ARP request if needed */
+/* Transmit UDP packet, performing ARP request if needed
+   (ether will be populated) */
 extern int	NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport,
 			int sport, int payload_len);
 
net/arp.c +4 -3
index d9113dc..5b6c787 100644
@@ -192,9 +192,10 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 			memcpy(NetArpWaitPacketMAC,
 				&arp->ar_sha, ARP_HLEN);
 
-#ifdef CONFIG_NETCONSOLE
-			NetGetHandler()(0, 0, 0, 0, 0);
-#endif
+			if (NetGetARPHandler() != NULL)
+				NetGetARPHandler()((uchar *)arp, 0,
+					reply_ip_addr, 0, len);
+
 			/* modify header, and transmit it */
 			memcpy(((struct Ethernet_t *)NetArpWaitTxPacket)->
 				et_dest, NetArpWaitPacketMAC, ARP_HLEN);
net/bootp.c +2 -2
index 0d5f4cf..9d709f1 100644
@@ -669,9 +669,9 @@ BootpRequest(void)
 
 #if defined(CONFIG_CMD_DHCP)
 	dhcp_state = SELECTING;
-	NetSetHandler(DhcpHandler);
+	NetSetUDPHandler(DhcpHandler);
 #else
-	NetSetHandler(BootpHandler);
+	NetSetUDPHandler(BootpHandler);
 #endif
 	NetSendPacket(NetTxPacket, pktlen);
 }
net/cdp.c +0 -8
index 31f9ce7..120d410 100644
@@ -237,13 +237,6 @@ CDPTimeout(void)
 		NetSetState(NETLOOP_SUCCESS);
 }
 
-static void
-CDPDummyHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
-		unsigned len)
-{
-	/* nothing */
-}
-
 void
 CDPReceive(const uchar *pkt, unsigned len)
 {
@@ -368,7 +361,6 @@ CDPStart(void)
 	CDPApplianceVLAN = htons(-1);
 
 	NetSetTimeout(CDP_TIMEOUT, CDPTimeout);
-	NetSetHandler(CDPDummyHandler);
 
 	CDPSendTrigger();
 }
net/dns.c +1 -1
index 0b655cc..9da3cac 100644
@@ -200,7 +200,7 @@ DnsStart(void)
 	debug("%s\n", __func__);
 
 	NetSetTimeout(DNS_TIMEOUT, DnsTimeout);
-	NetSetHandler(DnsHandler);
+	NetSetUDPHandler(DnsHandler);
 
 	DnsSend();
 }
net/net.c +44 -26

143 lines not on this page · raw message

net/nfs.c +1 -1
index e366505..752ab33 100644
@@ -735,7 +735,7 @@ NfsStart(void)
 		"Loading: *\b", load_addr);
 
 	NetSetTimeout(NFS_TIMEOUT, NfsTimeout);
-	NetSetHandler(NfsHandler);
+	NetSetUDPHandler(NfsHandler);
 
 	NfsTimeoutCount = 0;
 	NfsState = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
net/sntp.c +1 -1
index f5fa6f7..4d902cb 100644
@@ -85,7 +85,7 @@ SntpStart(void)
 	debug("%s\n", __func__);
 
 	NetSetTimeout(SNTP_TIMEOUT, SntpTimeout);
-	NetSetHandler(SntpHandler);
+	NetSetUDPHandler(SntpHandler);
 	memset(NetServerEther, 0, 6);
 
 	SntpSend();
net/tftp.c +2 -2
index 49ddbd7..ae8abc7 100644
@@ -778,7 +778,7 @@ void TftpStart(enum proto_t protocol)
 	TftpTimeoutCountMax = TftpRRQTimeoutCountMax;
 
 	NetSetTimeout(TftpTimeoutMSecs, TftpTimeout);
-	NetSetHandler(TftpHandler);
+	NetSetUDPHandler(TftpHandler);
 #ifdef CONFIG_CMD_TFTPPUT
 	net_set_icmp_handler(icmp_handler);
 #endif
@@ -840,7 +840,7 @@ TftpStartServer(void)
 #endif
 
 	TftpState = STATE_RECV_WRQ;
-	NetSetHandler(TftpHandler);
+	NetSetUDPHandler(TftpHandler);
 }
 #endif /* CONFIG_CMD_TFTPSRV */
 
Signature · 1 line
1.6.0.2
#63 lore raw

PATCH 17/28 net: Refactor to separate the UDP handler from the ARP handler

Quoted 5 lines · On Thursday 19 January 2012 19:53:20 Joe Hershberger wrote:

Only call the handlers if one was registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp (instead of
needing a #define hack in arp.c)
Clear handlers at the end of net loop

what if the SetHandler funcs took care of setting to a dummy func when it was given NULL ? then calling code need not worry about creating their own dummies, and you don't have to add NULL pointer checking.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/03b93355/attachment.pgp>

#64 lore raw

PATCH 17/28 net: Refactor to separate the UDP handler from the ARP handler

Hi Mike,

Quoted 10 lines · Mike Frysinger
Quoted 5 lines · On Thursday 19 January 2012 19:53:20 Joe Hershberger wrote:

Only call the handlers if one was registered... don't require ? ?protocols to register a handler (eliminating dummies) NetConsole now uses the ARP handler when waiting on arp (instead of ? ?needing a #define hack in arp.c)
Clear handlers at the end of net loop

what if the SetHandler funcs took care of setting to a dummy func when it was given NULL ? ?then calling code need not worry about creating their own dummies, and you don't have to add NULL pointer checking.

The calling code doesn't create dummies any longer. That is the point of the NULL checking. Do you prefer the set method register a dummy instead of a NULL check?

-Joe

#65 lore raw

PATCH 17/28 net: Refactor to separate the UDP handler from the ARP handler

Quoted 8 lines · On Wednesday 08 February 2012 17:52:54 Joe Hershberger wrote:
Quoted 7 lines · Mike Frysinger
Quoted 5 lines · On Thursday 19 January 2012 19:53:20 Joe Hershberger wrote:

Only call the handlers if one was registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp (instead of
needing a #define hack in arp.c)
Clear handlers at the end of net loop

Quoted 7 lines
Quoted 3 lines

what if the SetHandler funcs took care of setting to a dummy func when it was given NULL ? then calling code need not worry about creating their own dummies, and you don't have to add NULL pointer checking.

The calling code doesn't create dummies any longer. That is the point of the NULL checking. Do you prefer the set method register a dummy instead of a NULL check?

yes, i like that fringe code need not setup dummies anymore themselves. however, i think the core code should take take on setting up dummies so that the rest of the code need not have to do NULL checking everywhere.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120208/74d0d379/attachment.pgp>

#66 lore raw

PATCH 18/28 net: Add NetUpdateEther() to handle ARP or Ping replies (VLAN or SNAP)

In reply to Joe Hershberger

NetUpdateEther() will preserve the original Ethernet packet header
and simply replace the src and dest MACs and the protocol

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 include/net.h |    1 +
 net/arp.c     |    2 +-
 net/net.c     |   22 ++++++++++++++++++++++
 net/ping.c    |   10 +++++-----
 4 files changed, 29 insertions(+), 6 deletions(-)
include/net.h +1 -0
index dca8e1c..af6a803 100644
@@ -413,6 +413,7 @@ extern int	NetEthHdrSize(void);
 
 /* Set ethernet header; returns the size of the header */
 extern int NetSetEther(uchar *, uchar *, uint);
+extern int NetUpdateEther(struct Ethernet_t *et, uchar *addr, uint prot);
 
 /* Set IP header */
 extern void NetSetIPHeader(uchar *pkt, IPaddr_t dest, IPaddr_t source);
net/arp.c +1 -1
index 5b6c787..8c3557b 100644
@@ -158,7 +158,7 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 		/* reply with our IP address */
 		debug("Got ARP REQUEST, return our IP\n");
 		pkt = (uchar *)et;
-		eth_hdr_size = NetSetEther(pkt, et->et_src, PROT_ARP);
+		eth_hdr_size = NetUpdateEther(et, et->et_src, PROT_ARP);
 		pkt += eth_hdr_size;
 		arp->ar_op = htons(ARPOP_REPLY);
 		memcpy(&arp->ar_tha, &arp->ar_sha, ARP_HLEN);
net/net.c +22 -0
index 2dc49f5..1c0c822 100644
@@ -1274,6 +1274,28 @@ NetSetEther(uchar *xet, uchar * addr, uint prot)
 	}
 }
 
+int
+NetUpdateEther(struct Ethernet_t *et, uchar *addr, uint prot)
+{
+	ushort protlen;
+
+	memcpy(et->et_dest, addr, 6);
+	memcpy(et->et_src, NetOurEther, 6);
+	protlen = ntohs(et->et_protlen);
+	if (protlen == PROT_VLAN) {
+		struct VLAN_Ethernet_t *vet = (struct VLAN_Ethernet_t *)et;
+		vet->vet_type = htons(prot);
+		return VLAN_ETHER_HDR_SIZE;
+	} else if (protlen > 1514) {
+		et->et_protlen = htons(prot);
+		return ETHER_HDR_SIZE;
+	} else {
+		/* 802.2 + SNAP */
+		et->et_prot = htons(prot);
+		return E802_HDR_SIZE;
+	}
+}
+
 void
 NetSetIPHeader(uchar *pkt, IPaddr_t dest, IPaddr_t source)
 {
net/ping.c +5 -5
index 795d5c9..913506b 100644
@@ -89,6 +89,7 @@ void PingReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 {
 	struct ICMP_t *icmph = (struct ICMP_t *)&(ip->udp_src);
 	IPaddr_t src_ip;
+	int eth_hdr_size;
 
 	switch (icmph->type) {
 	case ICMP_ECHO_REPLY:
@@ -97,11 +98,10 @@ void PingReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 			NetSetState(NETLOOP_SUCCESS);
 		return;
 	case ICMP_ECHO_REQUEST:
-		debug("Got ICMP ECHO REQUEST, return "
-			"%d bytes\n", ETHER_HDR_SIZE + len);
+		eth_hdr_size = NetUpdateEther(et, et->et_src, PROT_IP);
 
-		memcpy(&et->et_dest[0], &et->et_src[0], 6);
-		memcpy(&et->et_src[0], NetOurEther, 6);
+		debug("Got ICMP ECHO REQUEST, return "
+			"%d bytes\n", eth_hdr_size + len);
 
 		ip->ip_sum = 0;
 		ip->ip_off = 0;
@@ -114,7 +114,7 @@ void PingReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 		icmph->checksum = 0;
 		icmph->checksum = ~NetCksum((uchar *)icmph,
 			(len - IP_HDR_SIZE) >> 1);
-		NetSendPacket((uchar *)et, ETHER_HDR_SIZE + len);
+		NetSendPacket((uchar *)et, eth_hdr_size + len);
 		return;
 /*	default:
 		return;*/
Signature · 1 line
1.6.0.2
#67 lore raw

PATCH 18/28 net: Add NetUpdateEther() to handle ARP or Ping replies (VLAN or SNAP)

Quoted 14 lines · On Thursday 19 January 2012 19:53:21 Joe Hershberger wrote:
net/net.c +11 -0
 
+int
+NetUpdateEther(struct Ethernet_t *et, uchar *addr, uint prot)
+{
+	ushort protlen;
+
+	memcpy(et->et_dest, addr, 6);
+	memcpy(et->et_src, NetOurEther, 6);
+	protlen = ntohs(et->et_protlen);
+	if (protlen == PROT_VLAN) {
+		struct VLAN_Ethernet_t *vet = (struct VLAN_Ethernet_t *)et;
+		vet->vet_type = htons(prot);

net/net.c NetSetEther(uchar *xet, uchar * addr, uint prot) · line 1297

Quoted 10 lines
net/net.c +10 -0
+		return VLAN_ETHER_HDR_SIZE;
+	} else if (protlen > 1514) {
+		et->et_protlen = htons(prot);
+		return ETHER_HDR_SIZE;
+	} else {
+		/* 802.2 + SNAP */
+		et->et_prot = htons(prot);
+		return E802_HDR_SIZE;
+	}
+}

seems to overlap a bit with NetSetEther. can't you have one use the other ? -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/0b6a03f9/attachment.pgp>

#68 lore raw

PATCH 18/28 net: Add NetUpdateEther() to handle ARP or Ping replies (VLAN or SNAP)

Hi Mike,

Quoted 19 lines · Mike Frysinger
Quoted 18 lines · On Thursday 19 January 2012 19:53:21 Joe Hershberger wrote:
net/net.c +15 -0
 
+int
+NetUpdateEther(struct Ethernet_t *et, uchar *addr, uint prot)
+{
+ ? ? ushort protlen;
+
+ ? ? memcpy(et->et_dest, addr, 6);
+ ? ? memcpy(et->et_src, NetOurEther, 6);
+ ? ? protlen = ntohs(et->et_protlen);
+ ? ? if (protlen == PROT_VLAN) {
+ ? ? ? ? ? ? struct VLAN_Ethernet_t *vet = (struct VLAN_Ethernet_t *)et;
+ ? ? ? ? ? ? vet->vet_type = htons(prot);
+ ? ? ? ? ? ? return VLAN_ETHER_HDR_SIZE;
+ ? ? } else if (protlen > 1514) {
+ ? ? ? ? ? ? et->et_protlen = htons(prot);
+ ? ? ? ? ? ? return ETHER_HDR_SIZE;
Quoted 8 lines
Quoted 6 lines

+ ? ? } else {
+ ? ? ? ? ? ? /* 802.2 + SNAP */
+ ? ? ? ? ? ? et->et_prot = htons(prot);
+ ? ? ? ? ? ? return E802_HDR_SIZE;
+ ? ? }
+}

seems to overlap a bit with NetSetEther. ?can't you have one use the other ?

I don't see a very clean way ATM. Maybe some future refactoring will make that more obvious.

-Joe

#69 lore raw

PATCH 19/28 net: Don't write the "serverip" env var if told not to in the config

In reply to Joe Hershberger

Before this patch, bootp would not overwrite the value, but the
value was still clobbered in the env

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 common/cmd_net.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
common/cmd_net.c +2 -2
index 89519fa..49ef680 100644
@@ -148,12 +148,12 @@ static void netboot_update_env (void)
 		ip_to_string (NetOurIP, tmp);
 		setenv ("ipaddr", tmp);
 	}
-
+#if !defined(CONFIG_BOOTP_SERVERIP)
 	if (NetServerIP) {
 		ip_to_string (NetServerIP, tmp);
 		setenv ("serverip", tmp);
 	}
-
+#endif
 	if (NetOurDNSIP) {
 		ip_to_string (NetOurDNSIP, tmp);
 		setenv ("dnsip", tmp);
Signature · 1 line
1.6.0.2
#70 lore raw

PATCH 19/28 net: Don't write the "serverip" env var if told not to in the config

common/cmd_net.c static void netboot_update_env (void) · line 156

Quoted 9 lines · On Thursday 19 January 2012 19:53:22 Joe Hershberger wrote:
common/cmd_net.c +2 -0
 
+#if !defined(CONFIG_BOOTP_SERVERIP)
 	if (NetServerIP) {
 		ip_to_string (NetServerIP, tmp);
 		setenv ("serverip", tmp);
 	}
+#endif

please add a comment referring people to net/bootp.c:BootpCopyNetParams() -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/f713d39e/attachment.pgp>

#71 lore raw

PATCH 20/28 net: Fix compile warning if CONFIG_BOOTP_SERVERIP is not defined

In reply to Joe Hershberger

There is no reason to use compiler magic to fix this Actually move the definition inside the #ifdef

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 net/bootp.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
net/bootp.c +3 -4
index 9d709f1..187b3a8 100644
@@ -20,7 +20,6 @@
 #ifdef CONFIG_STATUS_LED
 #include <status_led.h>
 #endif
-#include <linux/compiler.h>
 
 #define BOOTP_VENDOR_MAGIC	0x63825363	/* RFC1048 Magic Cookie */
 
@@ -98,15 +97,15 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
  */
 static void BootpCopyNetParams(struct Bootp_t *bp)
 {
-	__maybe_unused IPaddr_t tmp_ip;
-
-	NetCopyIP(&NetOurIP, &bp->bp_yiaddr);
 #if !defined(CONFIG_BOOTP_SERVERIP)
+	IPaddr_t tmp_ip;
+
 	NetCopyIP(&tmp_ip, &bp->bp_siaddr);
 	if (tmp_ip != 0)
 		NetCopyIP(&NetServerIP, &bp->bp_siaddr);
 	memcpy(NetServerEther, ((struct Ethernet_t *)NetRxPacket)->et_src, 6);
 #endif
+	NetCopyIP(&NetOurIP, &bp->bp_yiaddr);
 	if (strlen(bp->bp_file) > 0)
 		copy_filename(BootFile, bp->bp_file, sizeof(BootFile));
 
Signature · 1 line
1.6.0.2
#73 lore raw

PATCH 21/28 net: Remove unneeded static allocation for MAC address in PingSend()

In reply to Joe Hershberger

Don't force ARP clients to return the MAC address if they don't
care about it (such as ping)

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 net/arp.c  |    9 +++++----
 net/ping.c |   10 +++-------
 2 files changed, 8 insertions(+), 11 deletions(-)
net/arp.c +5 -4
index 8c3557b..b3be0a6 100644
@@ -170,7 +170,7 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 
 	case ARPOP_REPLY:		/* arp reply */
 		/* are we waiting for a reply */
-		if (!NetArpWaitPacketIP || !NetArpWaitPacketMAC)
+		if (!NetArpWaitPacketIP)
 			break;
 
 #ifdef CONFIG_KEEP_SERVERADDR
@@ -189,8 +189,9 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 				arp->ar_data);
 
 			/* save address for later use */
-			memcpy(NetArpWaitPacketMAC,
-				&arp->ar_sha, ARP_HLEN);
+			if (NetArpWaitPacketMAC != NULL)
+				memcpy(NetArpWaitPacketMAC,
+				       &arp->ar_sha, ARP_HLEN);
 
 			if (NetGetARPHandler() != NULL)
 				NetGetARPHandler()((uchar *)arp, 0,
@@ -198,7 +199,7 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 
 			/* modify header, and transmit it */
 			memcpy(((struct Ethernet_t *)NetArpWaitTxPacket)->
-				et_dest, NetArpWaitPacketMAC, ARP_HLEN);
+				et_dest, &arp->ar_sha, ARP_HLEN);
 			NetSendPacket(NetArpWaitTxPacket,
 					NetArpWaitTxPacketSize);
 
net/ping.c +3 -7
index 913506b..687c5aa 100644
@@ -40,22 +40,18 @@ static void SetICMPHeader(uchar *pkt, IPaddr_t dest)
 
 static int PingSend(void)
 {
-	static uchar mac[6];
 	uchar *pkt;
 	int eth_hdr_size;
 
 	/* XXX always send arp request */
 
-	memcpy(mac, NetEtherNullAddr, 6);
-
 	debug("sending ARP for %pI4\n", &NetPingIP);
 
 	NetArpWaitPacketIP = NetPingIP;
-	NetArpWaitPacketMAC = mac;
 
-	pkt = NetArpWaitTxPacket;
-	eth_hdr_size = NetSetEther(pkt, mac, PROT_IP);
-	pkt += eth_hdr_size;
+	eth_hdr_size = NetSetEther(NetArpWaitTxPacket, NetEtherNullAddr,
+		PROT_IP);
+	pkt = NetArpWaitTxPacket + eth_hdr_size;
 
 	SetICMPHeader(pkt, NetPingIP);
 
Signature · 1 line
1.6.0.2
#75 lore raw

PATCH 22/28 net: Fix net buffer initialization

In reply to Joe Hershberger

A new non-static function NetInit() will initialize buffers and read
from the env
Only update from the env on each entry to NetLoop()
Check when attempting to send a packet that the buffers were initialized

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 include/net.h |    7 ++++---
 net/net.c     |   48 +++++++++++++++++++++++++++++++++---------------
 2 files changed, 37 insertions(+), 18 deletions(-)
include/net.h +4 -3
index af6a803..1861406 100644
@@ -400,7 +400,8 @@ extern IPaddr_t Mcast_addr;
 #endif
 
 /* Initialize the network adapter */
-extern int NetLoop(enum proto_t);
+extern void	NetInit(void);
+extern int	NetLoop(enum proto_t protocol);
 
 /* Shutdown adapters and cleanup */
 extern void	NetStop(void);
@@ -439,10 +440,10 @@ extern void	NetSetState(int state);
 #define NETLOOP_SUCCESS		3
 #define NETLOOP_FAIL		4
 
-/* Transmit "NetTxPacket" */
+/* Transmit a packet */
 extern void NetSendPacket(uchar *, int);
 
-/* Transmit UDP packet, performing ARP request if needed
+/* Transmit "NetTxPacket" as UDP packet, performing ARP request if needed
    (ether will be populated) */
 extern int	NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport,
 			int sport, int payload_len);
net/net.c +33 -15

85 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#76 lore raw

PATCH 22/28 net: Fix net buffer initialization

include/net.h extern IPaddr_t Mcast_addr; · line 404

Quoted 5 lines · On Thursday 19 January 2012 19:53:25 Joe Hershberger wrote:
include/net.h +1 -1
 
-extern int NetLoop(enum proto_t);
+extern int	NetLoop(enum proto_t protocol);

explicit variable names are unnecessary when the type is self explanatory

net/net.c void net_auto_load(void) · line 239

Quoted 5 lines
net/net.c +1 -1
 
-static void NetInitLoop(enum proto_t protocol)
+static void NetInitLoop(void)

this could prob do with a sep patch ...

Quoted 10 lines
net/net.c +10 -0
+void
+NetInit(void)
+{
+	static int first_call = 1;
+
+	if (first_call) {
+		/*
+		 *	Setup packet buffers, aligned correctly.
+		 */
+		int i;

net/net.c NetCleanupLoop(void) · line 291

Quoted 10 lines
net/net.c +10 -0
+		NetTxPacket = &PktBuf[0] + (PKTALIGN - 1);
+		NetTxPacket -= (ulong)NetTxPacket % PKTALIGN;
+		for (i = 0; i < PKTBUFSRX; i++)
+			NetRxPackets[i] = NetTxPacket + (i+1)*PKTSIZE_ALIGN;
+
+		ArpInit();
+
+		/* Only need to setup buffer pointers once. */
+		first_call = 0;
+	}

it *seems* like it should be fine, but i worry what might be lurking. guess we'll find out :P.

net/net.c NetSendUDPPacket · line 644

Quoted 7 lines
net/net.c +5 -0
@@ -627,6 +639,12 @@ NetSendUDPPacket
 
+	/* make sure the NetTxPacket is initialized (NetInit() was called) */
+	if (NetTxPacket == NULL) {
+		puts("*** ERROR: NetTxPacket buffer pointer is NULL!\n");
+		return -1;
+	}

why check here only (udp) ? and why check at all ? this should be an assert() in the comment netsendpacket entry point ...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/f4e0a2a4/attachment.pgp>

#77 lore raw

PATCH 22/28 net: Fix net buffer initialization

Hi Mike,

Quoted 11 lines · Mike Frysinger

Review NetSendUDPPacket · line 644

Quoted 7 lines · On Thursday 19 January 2012 19:53:25 Joe Hershberger wrote:
(quoted diff) +5 -0
@@ -627,6 +639,12 @@ NetSendUDPPacket
 
+ ? ? /* make sure the NetTxPacket is initialized (NetInit() was called) */
+ ? ? if (NetTxPacket == NULL) {
+ ? ? ? ? ? ? puts("*** ERROR: NetTxPacket buffer pointer is NULL!\n");
+ ? ? ? ? ? ? return -1;
+ ? ? }

why check here only (udp) ? ?and why check at all ? ?this should be an assert() in the comment netsendpacket entry point ...

This is specifically needed here because the NetSendUDPPacket() function expects to use the NetTxPacket as a buffer and will write header information into it. The NetSendPacket() function takes the packet buffer itself as a parameter, so it isn't expecting anything as a side-band precondition to avoid crashing. I specifically added the check because the failure to initialize NetTxPacket in all code paths caused problems. It is easy to run into this if someone were to add a new thing that can send a packet. I will change it to an assert.

-Joe

#78 lore raw

PATCH 23/28 net: Refactor NetSendUDPPacket to share more code

In reply to Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 net/net.c |   44 +++++++++++++++++++++++++-------------------
 1 files changed, 25 insertions(+), 19 deletions(-)
net/net.c +25 -19
index 51d899b..59ac167 100644
@@ -638,6 +638,9 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
 		int payload_len)
 {
 	uchar *pkt;
+	int need_arp = 0;
+	int eth_hdr_size;
+	int pkt_hdr_size;
 
 	/* make sure the NetTxPacket is initialized (NetInit() was called) */
 	if (NetTxPacket == NULL) {
@@ -658,40 +661,43 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
 	 * an ARP request
 	 */
 	if (memcmp(ether, NetEtherNullAddr, 6) == 0) {
+		need_arp = 1;
+		pkt = NetArpWaitTxPacket;
+	} else
+		pkt = (uchar *)NetTxPacket;
+
+	eth_hdr_size = NetSetEther(pkt, ether, PROT_IP);
+	pkt += eth_hdr_size;
+	NetSetUDPHeader(pkt, dest, dport, sport, payload_len);
+	pkt_hdr_size = eth_hdr_size + IP_UDP_HDR_SIZE;
 
-		debug("sending ARP for %08x\n", dest);
+	if (need_arp) {
+		debug("sending ARP for %pI4\n", &dest);
 
+		/* save the ip and eth addr for the packet to send after arp */
 		NetArpWaitPacketIP = dest;
 		NetArpWaitPacketMAC = ether;
 
-		pkt = NetArpWaitTxPacket;
-		pkt += NetSetEther(pkt, NetArpWaitPacketMAC, PROT_IP);
-
-		NetSetUDPHeader(pkt, dest, dport, sport, payload_len);
+		/*
+		 * Copy the packet data from the NetTxPacket into the
+		 *   NetArpWaitTxPacket to send after arp
+		 */
 		memcpy(pkt + IP_UDP_HDR_SIZE, (uchar *)NetTxPacket +
-		       (pkt - (uchar *)NetArpWaitTxPacket) +
-		       IP_UDP_HDR_SIZE, payload_len);
+			pkt_hdr_size, payload_len);
 
 		/* size of the waiting packet */
-		NetArpWaitTxPacketSize = (pkt - NetArpWaitTxPacket) +
-			IP_UDP_HDR_SIZE + payload_len;
+		NetArpWaitTxPacketSize = pkt_hdr_size + payload_len;
 
 		/* and do the ARP request */
 		NetArpWaitTry = 1;
 		NetArpWaitTimerStart = get_timer(0);
 		ArpRequest();
 		return 1;	/* waiting */
+	} else {
+		debug("sending UDP to %pI4/%pM\n", &dest, ether);
+		NetSendPacket(NetTxPacket, pkt_hdr_size + payload_len);
+		return 0;	/* transmitted */
 	}
-
-	debug("sending UDP to %08x/%pM\n", dest, ether);
-
-	pkt = (uchar *)NetTxPacket;
-	pkt += NetSetEther(pkt, ether, PROT_IP);
-	NetSetUDPHeader(pkt, dest, dport, sport, payload_len);
-	NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + IP_UDP_HDR_SIZE +
-		payload_len);
-
-	return 0;	/* transmitted */
 }
 
 #ifdef CONFIG_IP_DEFRAG
Signature · 1 line
1.6.0.2
#79 lore raw

PATCH 24/28 net: Don't copy every packet that waits for an ARP

In reply to Joe Hershberger

Use the NetArpTxPacket for the ARP packet, not to hold what used to be
in NetTxPacket
This saves a copy and makes the code easier to understand Generalize the formation of the ARP packet

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 net/arp.c  |   44 ++++++++++++++++++++++++--------------------
 net/arp.h  |    4 ++--
 net/net.c  |   24 ++++++------------------
 net/ping.c |    5 ++---
 4 files changed, 34 insertions(+), 43 deletions(-)
net/arp.c +24 -20
index b3be0a6..938db59 100644
@@ -30,25 +30,26 @@ IPaddr_t	NetArpWaitPacketIP;
 IPaddr_t	NetArpWaitReplyIP;
 /* MAC address of waiting packet's destination */
 uchar	       *NetArpWaitPacketMAC;
-/* THE transmit packet */
-uchar	       *NetArpWaitTxPacket;
 int		NetArpWaitTxPacketSize;
-uchar		NetArpWaitPacketBuf[PKTSIZE_ALIGN + PKTALIGN];
 ulong		NetArpWaitTimerStart;
 int		NetArpWaitTry;
 
+uchar	       *NetArpTxPacket;	/* THE ARP transmit packet */
+uchar		NetArpPacketBuf[PKTSIZE_ALIGN + PKTALIGN];
+
 void ArpInit(void)
 {
 	/* XXX problem with bss workaround */
 	NetArpWaitPacketMAC = NULL;
 	NetArpWaitPacketIP = 0;
 	NetArpWaitReplyIP = 0;
-	NetArpWaitTxPacket = &NetArpWaitPacketBuf[0] + (PKTALIGN - 1);
-	NetArpWaitTxPacket -= (ulong)NetArpWaitTxPacket % PKTALIGN;
 	NetArpWaitTxPacketSize = 0;
+	NetArpTxPacket = &NetArpPacketBuf[0] + (PKTALIGN - 1);
+	NetArpTxPacket -= (ulong)NetArpTxPacket % PKTALIGN;
 }
 
-void ArpRequest(void)
+void ArpRawRequest(IPaddr_t sourceIP, const uchar *targetEther,
+	IPaddr_t targetIP)
 {
 	uchar *pkt;
 	struct ARP_t *arp;
@@ -56,7 +57,7 @@ void ArpRequest(void)
 
 	debug("ARP broadcast %d\n", NetArpWaitTry);
 
-	pkt = NetTxPacket;
+	pkt = NetArpTxPacket;
 
 	eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_ARP);
 	pkt += eth_hdr_size;
@@ -69,12 +70,16 @@ void ArpRequest(void)
 	arp->ar_pln = ARP_PLEN;
 	arp->ar_op = htons(ARPOP_REQUEST);
 
-	/* source ET addr */
-	memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);
-	/* source IP addr */
-	NetWriteIP(&arp->ar_spa, NetOurIP);
-	/* dest ET addr = 0 */
-	memset(&arp->ar_tha, 0, ARP_HLEN);
+	memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);	/* source ET addr */
+	NetWriteIP(&arp->ar_spa, sourceIP);		/* source IP addr */
+	memcpy(&arp->ar_tha, targetEther, ARP_HLEN);	/* target ET addr */
+	NetWriteIP(&arp->ar_tpa, targetIP);		/* target IP addr */
+
+	NetSendPacket(NetArpTxPacket, eth_hdr_size + ARP_HDR_SIZE);
+}
+
+void ArpRequest(void)
+{
 	if ((NetArpWaitPacketIP & NetOurSubnetMask) !=
 	    (NetOurIP & NetOurSubnetMask)) {
 		if (NetOurGatewayIP == 0) {
@@ -87,8 +92,7 @@ void ArpRequest(void)
 		NetArpWaitReplyIP = NetArpWaitPacketIP;
 	}
 
-	NetWriteIP(&arp->ar_tpa, NetArpWaitReplyIP);
-	NetSendPacket(NetTxPacket, eth_hdr_size + ARP_HDR_SIZE);
+	ArpRawRequest(NetOurIP, NetEtherNullAddr, NetArpWaitReplyIP);
 }
 
 void ArpTimeoutCheck(void)
@@ -197,11 +201,11 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 				NetGetARPHandler()((uchar *)arp, 0,
 					reply_ip_addr, 0, len);
 
-			/* modify header, and transmit it */
-			memcpy(((struct Ethernet_t *)NetArpWaitTxPacket)->
-				et_dest, &arp->ar_sha, ARP_HLEN);
-			NetSendPacket(NetArpWaitTxPacket,
-					NetArpWaitTxPacketSize);
+			/* set the mac address in the waiting packet's header
+			   and transmit it */
+			memcpy(((struct Ethernet_t *)NetTxPacket)->et_dest,
+				&arp->ar_sha, ARP_HLEN);
+			NetSendPacket(NetTxPacket, NetArpWaitTxPacketSize);
 
 			/* no arp request pending now */
 			NetArpWaitPacketIP = 0;
net/arp.h +2 -2
index d9ce03d..9657e67 100644
@@ -16,14 +16,14 @@
 extern IPaddr_t	NetArpWaitPacketIP;
 /* MAC address of waiting packet's destination */
 extern uchar *NetArpWaitPacketMAC;
-/* THE transmit packet */
-extern uchar *NetArpWaitTxPacket;
 extern int NetArpWaitTxPacketSize;
 extern ulong NetArpWaitTimerStart;
 extern int NetArpWaitTry;
 
 void ArpInit(void);
 void ArpRequest(void);
+void ArpRawRequest(IPaddr_t sourceIP, const uchar *targetEther,
+	IPaddr_t targetIP);
 void ArpTimeoutCheck(void);
 void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len);
 
net/net.c +6 -18
index 59ac167..fe4e528 100644
@@ -444,6 +444,9 @@ restart:
 		 *	Abort if ctrl-c was pressed.
 		 */
 		if (ctrlc()) {
+			/* cancel any ARP that may not have completed */
+			NetArpWaitPacketIP = 0;
+
 			NetCleanupLoop();
 			eth_halt();
 			puts("\nAbort\n");
@@ -638,7 +641,6 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
 		int payload_len)
 {
 	uchar *pkt;
-	int need_arp = 0;
 	int eth_hdr_size;
 	int pkt_hdr_size;
 
@@ -656,35 +658,21 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
 	if (dest == 0xFFFFFFFF)
 		ether = NetBcastAddr;
 
-	/*
-	 * if MAC address was not discovered yet, save the packet and do
-	 * an ARP request
-	 */
-	if (memcmp(ether, NetEtherNullAddr, 6) == 0) {
-		need_arp = 1;
-		pkt = NetArpWaitTxPacket;
-	} else
-		pkt = (uchar *)NetTxPacket;
+	pkt = (uchar *)NetTxPacket;
 
 	eth_hdr_size = NetSetEther(pkt, ether, PROT_IP);
 	pkt += eth_hdr_size;
 	NetSetUDPHeader(pkt, dest, dport, sport, payload_len);
 	pkt_hdr_size = eth_hdr_size + IP_UDP_HDR_SIZE;
 
-	if (need_arp) {
+	/* if MAC address was not discovered yet, do an ARP request */
+	if (memcmp(ether, NetEtherNullAddr, 6) == 0) {
 		debug("sending ARP for %pI4\n", &dest);
 
 		/* save the ip and eth addr for the packet to send after arp */
 		NetArpWaitPacketIP = dest;
 		NetArpWaitPacketMAC = ether;
 
-		/*
-		 * Copy the packet data from the NetTxPacket into the
-		 *   NetArpWaitTxPacket to send after arp
-		 */
-		memcpy(pkt + IP_UDP_HDR_SIZE, (uchar *)NetTxPacket +
-			pkt_hdr_size, payload_len);
-
 		/* size of the waiting packet */
 		NetArpWaitTxPacketSize = pkt_hdr_size + payload_len;
 
net/ping.c +2 -3
index 687c5aa..8332c88 100644
@@ -49,9 +49,8 @@ static int PingSend(void)
 
 	NetArpWaitPacketIP = NetPingIP;
 
-	eth_hdr_size = NetSetEther(NetArpWaitTxPacket, NetEtherNullAddr,
-		PROT_IP);
-	pkt = NetArpWaitTxPacket + eth_hdr_size;
+	eth_hdr_size = NetSetEther(NetTxPacket, NetEtherNullAddr, PROT_IP);
+	pkt = (uchar *)NetTxPacket + eth_hdr_size;
 
 	SetICMPHeader(pkt, NetPingIP);
 
Signature · 1 line
1.6.0.2
#80 lore raw

PATCH 25/28 net: Add option CONFIG_BOOTP_CAN_FAIL

In reply to Joe Hershberger

This is useful if you want to look for a DHCP server, but try some
other settings if not available

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 README      |    7 +++++++
 net/bootp.c |    5 +++++
 2 files changed, 12 insertions(+), 0 deletions(-)
README +7 -0
index 9d713e8..352db7d 100644
@@ -1573,10 +1573,17 @@ The following options need to be configured:
 		CONFIG_BOOTP_NTPSERVER
 		CONFIG_BOOTP_TIMEOFFSET
 		CONFIG_BOOTP_VENDOREX
+		CONFIG_BOOTP_CAN_FAIL
 
 		CONFIG_BOOTP_SERVERIP - TFTP server will be the serverip
 		environment variable, not the BOOTP server.
 
+		CONFIG_BOOTP_CAN_FAIL - If the DHCP server is not found
+		after the configured retry count, the call will fail
+		instead of starting over.  This can be used to fail over
+		to Link-local IP address configuration if the DHCP server
+		is not available.
+
 		CONFIG_BOOTP_DNS2 - If a DHCP client requests the DNS
 		serverip from a DHCP server, it is possible that more
 		than one DNS serverip is offered to the client.
net/bootp.c +5 -0
index 187b3a8..07f9d0e 100644
@@ -327,8 +327,13 @@ static void
 BootpTimeout(void)
 {
 	if (BootpTry >= TIMEOUT_COUNT) {
+#ifdef CONFIG_BOOTP_CAN_FAIL
+		puts("\nRetry count exceeded\n");
+		NetSetState(NETLOOP_FAIL);
+#else
 		puts("\nRetry count exceeded; starting again\n");
 		NetStartAgain();
+#endif
 	} else {
 		NetSetTimeout(TIMEOUT, BootpTimeout);
 		BootpRequest();
Signature · 1 line
1.6.0.2
#81 lore raw

PATCH 25/28 net: Add option CONFIG_BOOTP_CAN_FAIL

README The following options need to be configured: · line 1585

Quoted 8 lines · On Thursday 19 January 2012 19:53:28 Joe Hershberger wrote:
README +5 -0
 
+		CONFIG_BOOTP_CAN_FAIL - If the DHCP server is not found
+		after the configured retry count, the call will fail
+		instead of starting over.  This can be used to fail over
+		to Link-local IP address configuration if the DHCP server
+		is not available.

the pedant in me says this should be CONFIG_BOOTP_MAY_FAIL
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/c41cbfee/attachment.pgp>

#82 lore raw

PATCH 26/28 net: Add link-local addressing support

In reply to Joe Hershberger

Code based on networking/zcip.c in busybox
- commit 8531d76a15890c2c535908ce888b2e2aed35b172

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 README           |   15 +++-
 common/cmd_net.c |   30 +++++
 include/net.h    |    2 +-
 net/Makefile     |    4 +-
 net/arp.c        |    3 +
 net/link_local.c |  333 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/link_local.h |   21 ++++
 net/net.c        |   15 +++
 8 files changed, 420 insertions(+), 3 deletions(-)
 create mode 100644 net/link_local.c
 create mode 100644 net/link_local.h
README +14 -1
index 352db7d..776614e 100644
@@ -782,6 +782,7 @@ The following options need to be configured:
 		CONFIG_CMD_JFFS2	* JFFS2 Support
 		CONFIG_CMD_KGDB		* kgdb
 		CONFIG_CMD_LDRINFO	  ldrinfo (display Blackfin loader)
+		CONFIG_CMD_LINK_LOCAL	* link-local IP address auto-configuration (169.254.*.*)
 		CONFIG_CMD_LOADB	  loadb
 		CONFIG_CMD_LOADS	  loads
 		CONFIG_CMD_MD5SUM	  print md5 message digest
@@ -797,7 +798,7 @@ The following options need to be configured:
 		CONFIG_CMD_PCA953X	* PCA953x I2C gpio commands
 		CONFIG_CMD_PCA953X_INFO * PCA953x I2C gpio info command
 		CONFIG_CMD_PCI		* pciinfo
-		CONFIG_CMD_PCMCIA		* PCMCIA support
+		CONFIG_CMD_PCMCIA	* PCMCIA support
 		CONFIG_CMD_PING		* send ICMP ECHO_REQUEST to network
 					  host
 		CONFIG_CMD_PORTIO	* Port I/O
@@ -1614,6 +1615,18 @@ The following options need to be configured:
 		the DHCP timeout and retry process takes a longer than
 		this delay.
 
+ - Link-local IP address negotiation:
+		Negotiate with other link-local clients on the local network
+		for an address that doesn't require explicit configuration.
+		This is especially useful if a DHCP server cannot be guaranteed
+		to exist in all environments that the device must operate.
+
+		The "llipaddr" variable is set with the most recently
+		negotiated address and is preferred in future negotiations.
+
+		The "ipaddr", "netmask", and "gatewayip" variables are set
+		after successful negotiation to enable network access.
+
  - CDP Options:
 		CONFIG_CDP_DEVICE_ID
 
common/cmd_net.c +30 -0
index 49ef680..ffca8c9 100644
@@ -418,3 +418,33 @@ U_BOOT_CMD(
 );
 
 #endif	/* CONFIG_CMD_DNS */
+
+#if defined(CONFIG_CMD_LINK_LOCAL)
+int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	char tmp[22];
+
+	if (NetLoop(LINKLOCAL) < 0)
+		return 1;
+
+	NetOurGatewayIP = 0;
+	ip_to_string(NetOurGatewayIP, tmp);
+	setenv("gatewayip", tmp);
+
+	ip_to_string(NetOurSubnetMask, tmp);
+	setenv("netmask", tmp);
+
+	ip_to_string(NetOurIP, tmp);
+	setenv("ipaddr", tmp);
+	setenv("llipaddr", tmp); /* store this for next time */
+
+	return 0;
+}
+
+U_BOOT_CMD(
+	linklocal,	1,	1,	do_link_local,
+	"acquire a network IP address using the link-local protocol",
+	""
+);
+
+#endif  /* CONFIG_CMD_LINK_LOCAL */
include/net.h +1 -1
index 1861406..fbb1412 100644
@@ -368,7 +368,7 @@ extern int		NetRestartWrap;		/* Tried all network devices */
 
 enum proto_t {
 	BOOTP, RARP, ARP, TFTPGET, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP,
-	TFTPSRV, TFTPPUT
+	TFTPSRV, TFTPPUT, LINKLOCAL
 };
 
 /* from net/net.c */
net/Makefile +3 -1
index f1c4859..5264687 100644
@@ -32,15 +32,17 @@ COBJS-$(CONFIG_CMD_NET)  += bootp.o
 COBJS-$(CONFIG_CMD_CDP)  += cdp.o
 COBJS-$(CONFIG_CMD_DNS)  += dns.o
 COBJS-$(CONFIG_CMD_NET)  += eth.o
+COBJS-$(CONFIG_CMD_LINK_LOCAL) += link_local.o
 COBJS-$(CONFIG_CMD_NET)  += net.o
 COBJS-$(CONFIG_BOOTP_RANDOM_DELAY) += net_rand.o
+COBJS-$(CONFIG_CMD_LINK_LOCAL) += net_rand.o
 COBJS-$(CONFIG_CMD_NFS)  += nfs.o
 COBJS-$(CONFIG_CMD_PING) += ping.o
 COBJS-$(CONFIG_CMD_RARP) += rarp.o
 COBJS-$(CONFIG_CMD_SNTP) += sntp.o
 COBJS-$(CONFIG_CMD_NET)  += tftp.o
 
-COBJS	:= $(COBJS-y)
+COBJS	:= $(sort $(COBJS-y))
 SRCS	:= $(COBJS:.o=.c)
 OBJS	:= $(addprefix $(obj),$(COBJS))
 
net/arp.c +3 -0
index 938db59..9eb4ab0 100644
@@ -11,6 +11,9 @@
 #include <common.h>
 
 #include "arp.h"
+#if defined(CONFIG_CMD_LINK_LOCAL)
+#include "link_local.h"
+#endif
 
 #ifndef	CONFIG_ARP_TIMEOUT
 /* Milliseconds before trying ARP again */
net/link_local.c new file +333 -0

333 lines not on this page · raw message

net/link_local.h new file +21 -0
new file mode 100644
index 0000000..0316321
@@ -0,0 +1,21 @@
+/*
+ * RFC3927 ZeroConf IPv4 Link-Local addressing
+ * (see <http://www.zeroconf.org/>)
+ *
+ * Copied from BusyBox - networking/zcip.c
+ *
+ * Copyright (C) 2003 by Arthur van Hoff (avh at strangeberry.com)
+ * Copyright (C) 2004 by David Brownell
+ *
+ * Licensed under the GPL v2 or later
+ */
+
+#ifndef __LINK_LOCAL_H__
+#define __LINK_LOCAL_H__
+
+#include <common.h>
+
+void LinkLocalReceiveArp(struct ARP_t *arp, int len);
+void LinkLocalStart(void);
+
+#endif /* __LINK_LOCAL_H__ */
net/net.c +15 -0
index fe4e528..d541234 100644
@@ -23,6 +23,12 @@
  *			- name of bootfile
  *	Next step:	ARP
  *
+ * LINK_LOCAL:
+ *
+ *	Prerequisites:	- own ethernet address
+ *	We want:	- own IP address
+ *	Next step:	ARP
+ *
  * RARP:
  *
  *	Prerequisites:	- own ethernet address
@@ -90,6 +96,9 @@
 #if defined(CONFIG_CMD_DNS)
 #include "dns.h"
 #endif
+#if defined(CONFIG_CMD_LINK_LOCAL)
+#include "link_local.h"
+#endif
 #include "nfs.h"
 #if defined(CONFIG_CMD_PING)
 #include "ping.h"
@@ -404,6 +413,11 @@ restart:
 			DnsStart();
 			break;
 #endif
+#if defined(CONFIG_CMD_LINK_LOCAL)
+		case LINKLOCAL:
+			LinkLocalStart();
+			break;
+#endif
 		default:
 			break;
 		}
@@ -1200,6 +1214,7 @@ common:
 	case BOOTP:
 	case CDP:
 	case DHCP:
+	case LINKLOCAL:
 		if (memcmp(NetOurEther, "\0\0\0\0\0\0", 6) == 0) {
 			int num = eth_get_dev_index();
 
Signature · 1 line
1.6.0.2
#83 lore raw

PATCH 26/28 net: Add link-local addressing support

README The following options need to be configured: · line 801

Quoted 5 lines · On Thursday 19 January 2012 19:53:29 Joe Hershberger wrote:
README +1 -1
 
-		CONFIG_CMD_PCMCIA		* PCMCIA support
+		CONFIG_CMD_PCMCIA	* PCMCIA support

please omit unrelated whitespace changes

common/cmd_net.c

Quoted 4 lines
common/cmd_net.c +1 -0
 
+int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc, char * const

static

common/cmd_net.c U_BOOT_CMD( · line 438

Quoted 9 lines
common/cmd_net.c +9 -0
+	NetOurGatewayIP = 0;
+	ip_to_string(NetOurGatewayIP, tmp);
+	setenv("gatewayip", tmp);
+
+	ip_to_string(NetOurSubnetMask, tmp);
+	setenv("netmask", tmp);
+
+	ip_to_string(NetOurIP, tmp);
+	setenv("ipaddr", tmp);

i feel like we should add a helper to do this

	setenv_ip("ipaddr", NetOurIP);

net/Makefile COBJS-$(CONFIG_CMD_NET) += bootp.o · line 45

Quoted 5 lines
net/Makefile +1 -1
 
-COBJS	:= $(COBJS-y)
+COBJS	:= $(sort $(COBJS-y))

why ?

net/arp.c line 16

Quoted 6 lines
net/arp.c +3 -0
 
+#if defined(CONFIG_CMD_LINK_LOCAL)
+#include "link_local.h"
+#endif

please push the ifdef down into the header
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/cb860423/attachment.pgp>

#84 lore raw

PATCH 26/28 net: Add link-local addressing support

Hi Mike,

Quoted 13 lines · Mike Frysinger

Review

Quoted 9 lines · On Thursday 19 January 2012 19:53:29 Joe Hershberger wrote:

+ ? ? NetOurGatewayIP = 0;
+ ? ? ip_to_string(NetOurGatewayIP, tmp);
+ ? ? setenv("gatewayip", tmp);

(quoted diff) +6 -0
+
+ ? ? ip_to_string(NetOurSubnetMask, tmp);
+ ? ? setenv("netmask", tmp);
+
+ ? ? ip_to_string(NetOurIP, tmp);
+ ? ? setenv("ipaddr", tmp);

i feel like we should add a helper to do this
? ? ? ?setenv_ip("ipaddr", NetOurIP);

I think that's a good idea, but I don't think it should be part of this patch series. It would probably be clearer to do that independently later.

Quoted 7 lines

net/Makefile

Quoted 5 lines
net/Makefile +1 -1
 
-COBJS ? ? ? ?:= $(COBJS-y)
+COBJS ? ? ? ?:= $(sort $(COBJS-y))

why ?

Sort is needed because there are 2 different config options that could add the net_rand source file and sort will eliminate duplicates.

-Joe

#85 lore raw

PATCH 26/28 net: Add link-local addressing support

Quoted 15 lines · On Monday 13 February 2012 15:21:12 Joe Hershberger wrote:
Quoted 12 lines · Mike Frysinger

common/cmd_net.c U_BOOT_CMD( · line 438

Quoted 9 lines · On Thursday 19 January 2012 19:53:29 Joe Hershberger wrote:
common/cmd_net.c +9 -0
+     NetOurGatewayIP = 0;
+     ip_to_string(NetOurGatewayIP, tmp);
+     setenv("gatewayip", tmp);
+
+     ip_to_string(NetOurSubnetMask, tmp);
+     setenv("netmask", tmp);
+
+     ip_to_string(NetOurIP, tmp);
+     setenv("ipaddr", tmp);

i feel like we should add a helper to do this

Quoted 1 line
       setenv_ip("ipaddr", NetOurIP);
Quoted 3 lines

I think that's a good idea, but I don't think it should be part of this patch series. It would probably be clearer to do that independently later.

that's fine

Quoted 10 lines
Quoted 7 lines

net/Makefile COBJS-$(CONFIG_CMD_NET) += bootp.o · line 45

Quoted 5 lines
net/Makefile +1 -1
 
-COBJS        := $(COBJS-y)
+COBJS        := $(sort $(COBJS-y))

why ?

Sort is needed because there are 2 different config options that could add the net_rand source file and sort will eliminate duplicates.

i'd say "needs a comment", but it seems we already crossed that threshold in other Makefiles. should probably make this the standard moving forward so people can copy & paste & not ask again.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120214/8b453073/attachment.pgp>

#86 lore raw

PATCH 27/28 net: Work-around for brain-damaged Cisco routers with arp-proxy

In reply to Joe Hershberger

Cisco's arp-proxy feature fails to ignore the link-local address range This means that a link-local device on a network with this Cisco
equipment will reply to ARP requests for our device (in addition to our reply)
If we happen to reply first, the requester's ARP table will be
populated with our MAC address, and one packet will be sent to us... shortly following this, the requester will get an ARP reply from the Cisco equipment telling the requester to send packets their way instead of to our device from now on
This work-around detects this link-local condition and will delay
replying to the ARP request for 5ms so that the first packet is sent to the Cisco equipment and all following packets are sent to our device

Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 net/arp.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
net/arp.c +13 -0
index 9eb4ab0..8a7b4a2 100644
@@ -172,6 +172,19 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 		NetCopyIP(&arp->ar_tpa, &arp->ar_spa);
 		memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);
 		NetCopyIP(&arp->ar_spa, &NetOurIP);
+
+		/*
+		 * Work-around for brain-damaged Cisco equipment with
+		 *   arp-proxy enabled.
+		 *
+		 *   If the requesting IP is not on our subnet, wait 5ms to
+		 *   reply to ARP request so that our reply will overwrite
+		 *   the arp-proxy's instead of the other way around.
+		 */
+		if ((NetReadIP(&arp->ar_tpa) & NetOurSubnetMask) !=
+		    (NetReadIP(&arp->ar_spa) & NetOurSubnetMask))
+			udelay(5000);
+
 		NetSendPacket((uchar *)et, eth_hdr_size + ARP_HDR_SIZE);
 		return;
 
Signature · 1 line
1.6.0.2
#87 lore raw

PATCH 27/28 net: Work-around for brain-damaged Cisco routers with arp-proxy

Quoted 9 lines · On Thursday 19 January 2012 19:53:30 Joe Hershberger wrote:

Cisco's arp-proxy feature fails to ignore the link-local address range This means that a link-local device on a network with this Cisco
equipment will reply to ARP requests for our device (in addition to our reply)
...

net/arp.c +1 -0
 
+		/*

net/arp.c void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len) · line 186

Quoted 10 lines
net/arp.c +10 -0
+		 * Work-around for brain-damaged Cisco equipment with
+		 *   arp-proxy enabled.
+		 *
+		 *   If the requesting IP is not on our subnet, wait 5ms to
+		 *   reply to ARP request so that our reply will overwrite
+		 *   the arp-proxy's instead of the other way around.
+		 */
+		if ((NetReadIP(&arp->ar_tpa) & NetOurSubnetMask) !=
+		    (NetReadIP(&arp->ar_spa) & NetOurSubnetMask))
+			udelay(5000);

shouldn't this sit behind a link local ifdef then ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/b1ff938d/attachment.pgp>

#88 lore raw

PATCH 28/28 net: Allow filtering on debug traces in the net subsystem

In reply to Joe Hershberger
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 drivers/net/netconsole.c |    6 ++++++
 net/arp.c                |   12 ++++++++----
 net/link_local.c         |   31 +++++++++++++++++++------------
 net/net.c                |   45 ++++++++++++++++++++++++++++++++++-----------
 net/ping.c               |    6 ++++--
 net/rarp.c               |    7 +++++--
 6 files changed, 76 insertions(+), 31 deletions(-)
drivers/net/netconsole.c +6 -0
index 1e31159..aee671e 100644
@@ -26,6 +26,8 @@
 #include <stdio_dev.h>
 #include <net.h>
 
+#define DEBUG_DEV_PKT 0
+
 DECLARE_GLOBAL_DATA_PTR;
 
 static char input_buffer[512];
@@ -83,6 +85,8 @@ int nc_input_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len)
 	if (dest != nc_port || !len)
 		return 0; /* not for us */
 
+	debug_cond(DEBUG_DEV_PKT, "input: \"%*.*s\"\n", len, len, pkt);
+
 	if (input_size == sizeof(input_buffer))
 		return 1; /* no space */
 	if (len > sizeof(input_buffer) - input_size)
@@ -112,6 +116,8 @@ static void nc_send_packet(const char *buf, int len)
 	uchar *ether;
 	IPaddr_t ip;
 
+	debug_cond(DEBUG_DEV_PKT, "output: \"%*.*s\"\n", len, len, buf);
+
 	eth = eth_get_dev();
 	if (eth == NULL)
 		return;
net/arp.c +8 -4
index 8a7b4a2..b8fb21f 100644
@@ -15,6 +15,9 @@
 #include "link_local.h"
 #endif
 
+#define DEBUG_DEV_PKT 0
+#define DEBUG_NET_PKT 0
+
 #ifndef	CONFIG_ARP_TIMEOUT
 /* Milliseconds before trying ARP again */
 # define ARP_TIMEOUT		5000UL
@@ -58,7 +61,7 @@ void ArpRawRequest(IPaddr_t sourceIP, const uchar *targetEther,
 	struct ARP_t *arp;
 	int eth_hdr_size;
 
-	debug("ARP broadcast %d\n", NetArpWaitTry);
+	debug_cond(DEBUG_DEV_PKT, "ARP broadcast %d\n", NetArpWaitTry);
 
 	pkt = NetArpTxPacket;
 
@@ -138,7 +141,7 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 	 *   address; so if we receive such a packet, we set
 	 *   the server ethernet address
 	 */
-	debug("Got ARP\n");
+	debug_cond(DEBUG_NET_PKT, "Got ARP\n");
 
 	arp = (struct ARP_t *)ip;
 	if (len < ARP_HDR_SIZE) {
@@ -163,7 +166,7 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 	switch (ntohs(arp->ar_op)) {
 	case ARPOP_REQUEST:
 		/* reply with our IP address */
-		debug("Got ARP REQUEST, return our IP\n");
+		debug_cond(DEBUG_DEV_PKT, "Got ARP REQUEST, return our IP\n");
 		pkt = (uchar *)et;
 		eth_hdr_size = NetUpdateEther(et, et->et_src, PROT_ARP);
 		pkt += eth_hdr_size;
@@ -205,7 +208,8 @@ void ArpReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 
 		/* matched waiting packet's address */
 		if (reply_ip_addr == NetArpWaitReplyIP) {
-			debug("Got ARP REPLY, set eth addr (%pM)\n",
+			debug_cond(DEBUG_DEV_PKT,
+				"Got ARP REPLY, set eth addr (%pM)\n",
 				arp->ar_data);
 
 			/* save address for later use */
net/link_local.c +19 -12
index 16ec9a7..5395bf6 100644
@@ -16,6 +16,11 @@
 #include "arp.h"
 #include "net_rand.h"
 
+#define DEBUG_LL_STATE 0
+#define DEBUG_DEV_PKT 0
+#define DEBUG_NET_PKT 0
+#define DEBUG_INT_STATE 0
+
 /* We don't need more than 32 bits of the counter */
 #define MONOTONIC_MS() ((unsigned)get_timer(0) * (1000 / CONFIG_SYS_HZ))
 
@@ -93,7 +98,7 @@ static void configure_wait(void)
 	/* set deadline_ms to the point in time when we timeout */
 	deadline_ms = MONOTONIC_MS() + timeout_ms;
 
-	debug("...wait %d %s nprobes=%u, nclaims=%u\n",
+	debug_cond(DEBUG_DEV_PKT, "...wait %d %s nprobes=%u, nclaims=%u\n",
 			timeout_ms, eth_get_name(), nprobes, nclaims);
 
 	NetSetTimeout(timeout_ms, LinkLocalTimeout);
@@ -132,7 +137,7 @@ LinkLocalTimeout(void)
 		   have been received, so we can progress through the states */
 		if (nprobes < PROBE_NUM) {
 			nprobes++;
-			debug("probe/%u %s@%pI4\n",
+			debug_cond(DEBUG_LL_STATE, "probe/%u %s@%pI4\n",
 					nprobes, eth_get_name(), &ip);
 			ArpRawRequest(0, NetEtherNullAddr, ip);
 			timeout_ms = PROBE_MIN * 1000;
@@ -141,7 +146,7 @@ LinkLocalTimeout(void)
 			/* Switch to announce state */
 			state = ANNOUNCE;
 			nclaims = 0;
-			debug("announce/%u %s@%pI4\n",
+			debug_cond(DEBUG_LL_STATE, "announce/%u %s@%pI4\n",
 					nclaims, eth_get_name(), &ip);
 			ArpRawRequest(ip, NetOurEther, ip);
 			timeout_ms = ANNOUNCE_INTERVAL * 1000;
@@ -153,7 +158,7 @@ LinkLocalTimeout(void)
 		   to the announce state */
 		state = ANNOUNCE;
 		nclaims = 0;
-		debug("announce/%u %s@%pI4\n",
+		debug_cond(DEBUG_LL_STATE, "announce/%u %s@%pI4\n",
 				nclaims, eth_get_name(), &ip);
 		ArpRawRequest(ip, NetOurEther, ip);
 		timeout_ms = ANNOUNCE_INTERVAL * 1000;
@@ -164,7 +169,7 @@ LinkLocalTimeout(void)
 		   the states */
 		if (nclaims < ANNOUNCE_NUM) {
 			nclaims++;
-			debug("announce/%u %s@%pI4\n",
+			debug_cond(DEBUG_LL_STATE, "announce/%u %s@%pI4\n",
 					nclaims, eth_get_name(), &ip);
 			ArpRawRequest(ip, NetOurEther, ip);
 			timeout_ms = ANNOUNCE_INTERVAL * 1000;
@@ -217,10 +222,11 @@ void LinkLocalReceiveArp(struct ARP_t *arp, int len)
 		if ((int)(diff) < 0) {
 			/* Current time is greater than the expected timeout
 			   time. This should never happen */
-			debug("missed an expected timeout\n");
+			debug_cond(DEBUG_LL_STATE,
+				"missed an expected timeout\n");
 			timeout_ms = 0;
 		} else {
-			debug("adjusting timeout\n");
+			debug_cond(DEBUG_INT_STATE, "adjusting timeout\n");
 			timeout_ms = diff | 1; /* never 0 */
 		}
 	}
@@ -240,13 +246,13 @@ void LinkLocalReceiveArp(struct ARP_t *arp, int len)
 	}
 */
 
-	debug("%s recv arp type=%d, op=%d,\n",
+	debug_cond(DEBUG_INT_STATE, "%s recv arp type=%d, op=%d,\n",
 		eth_get_name(), ntohs(arp->ar_pro),
 		ntohs(arp->ar_op));
-	debug("\tsource=%pM %pI4\n",
+	debug_cond(DEBUG_INT_STATE, "\tsource=%pM %pI4\n",
 		&arp->ar_sha,
 		&arp->ar_spa);
-	debug("\ttarget=%pM %pI4\n",
+	debug_cond(DEBUG_INT_STATE, "\ttarget=%pM %pI4\n",
 		&arp->ar_tha,
 		&arp->ar_tpa);
 
@@ -272,8 +278,9 @@ void LinkLocalReceiveArp(struct ARP_t *arp, int len)
 		target_ip_conflict = 1;
 	}
 
-	debug("state = %d, source ip conflict = %d, target ip conflict = %d\n",
-		state, source_ip_conflict, target_ip_conflict);
+	debug_cond(DEBUG_NET_PKT,
+		"state = %d, source ip conflict = %d, target ip conflict = "
+		"%d\n", state, source_ip_conflict, target_ip_conflict);
 	switch (state) {
 	case PROBE:
 	case ANNOUNCE:
net/net.c +34 -11

174 lines not on this page · raw message

net/ping.c +4 -2
index 8332c88..a4fb7b7 100644
@@ -11,6 +11,8 @@
 #include "ping.h"
 #include "arp.h"
 
+#define DEBUG_DEV_PKT 0
+
 static ushort PingSeqNo;
 
 /* The ip address to ping */
@@ -45,7 +47,7 @@ static int PingSend(void)
 
 	/* XXX always send arp request */
 
-	debug("sending ARP for %pI4\n", &NetPingIP);
+	debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &NetPingIP);
 
 	NetArpWaitPacketIP = NetPingIP;
 
@@ -95,7 +97,7 @@ void PingReceive(struct Ethernet_t *et, struct IP_UDP_t *ip, int len)
 	case ICMP_ECHO_REQUEST:
 		eth_hdr_size = NetUpdateEther(et, et->et_src, PROT_IP);
 
-		debug("Got ICMP ECHO REQUEST, return "
+		debug_cond(DEBUG_DEV_PKT, "Got ICMP ECHO REQUEST, return "
 			"%d bytes\n", eth_hdr_size + len);
 
 		ip->ip_sum = 0;
net/rarp.c +5 -2
index 3097341..edc33ca 100644
@@ -29,6 +29,9 @@
 #include "rarp.h"
 #include "tftp.h"
 
+#define DEBUG_DEV_PKT 0
+#define DEBUG_NET_PKT 0
+
 #define TIMEOUT		5000UL	/* Milliseconds before trying BOOTP again */
 #ifndef	CONFIG_NET_RETRY_COUNT
 # define TIMEOUT_COUNT	5		/* # of timeouts before giving up  */
@@ -46,7 +49,7 @@ RarpReceive(struct IP_UDP_t *ip, unsigned len)
 {
 	struct ARP_t *arp;
 
-	debug("Got RARP\n");
+	debug_cond(DEBUG_NET_PKT, "Got RARP\n");
 	arp = (struct ARP_t *)ip;
 	if (len < ARP_HDR_SIZE) {
 		printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
@@ -64,7 +67,7 @@ RarpReceive(struct IP_UDP_t *ip, unsigned len)
 		if (NetServerIP == 0)
 			NetCopyIP(&NetServerIP, &arp->ar_data[6]);
 		memcpy(NetServerEther, &arp->ar_data[0], 6);
-		debug("Got good RARP\n");
+		debug_cond(DEBUG_DEV_PKT, "Got good RARP\n");
 		net_auto_load();
 	}
 }
Signature · 1 line
1.6.0.2
#89 lore raw

PATCH 28/28 net: Allow filtering on debug traces in the net subsystem

drivers/net/netconsole.c

Quoted 4 lines · On Thursday 19 January 2012 19:53:31 Joe Hershberger wrote:
drivers/net/netconsole.c +1 -0
 
+#define DEBUG_DEV_PKT 0

wouldn't be better to move these to net.h by default rather than copying & pasting to all the source files ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/debe8fe1/attachment.pgp>

#90 lore raw

cover Add link-local addressing support

In reply to Joe Hershberger
Quoted 5 lines · Joe Hershberger

Link-local support allows the bootloader to get a usable network address regardless of network environment. Given that bootloaders may not always have access to a DHCP server, this functionality makes accessing it in those environments easier. It is also referred to as zero-configuration IP.

Hi Joe,

I have a basic question about your patchset. RFC3927 requires that addresses are continuosly checked to avoid conflicts - this is a strict requirement.

However, it is clear we cannot comply with this requirement. The protocol runs once and there is not a background process to check for conflicts.

I can imagine we can get conflicts, when several targets are running at the same time in u_boot and they are attached to a network where local-link addressing is active. Then we can have two or more system using the same ip address, making the network unreliable.

Which are the limitations of this implementation ? They should also described in your patchset, maybe with a README file. Is is thought to connect the target directly to a PC ?

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#91 lore raw

cover Add link-local addressing support

Hi Stefano,

Quoted 7 lines · Stefano Babic
Quoted 5 lines · Joe Hershberger

Link-local support allows the bootloader to get a usable network address regardless of network environment. ?Given that bootloaders may not always have access to a DHCP server, this functionality makes accessing it in those environments easier. ?It is also referred to as zero-configuration IP.

Quoted 5 lines

Hi Joe,

I have a basic question about your patchset. RFC3927 requires that addresses are continuosly checked to avoid conflicts - this is a strict requirement.

True. It cannot be 100% compliant in every use-case.

Quoted 3 lines

However, it is clear we cannot comply with this requirement. The protocol runs once and there is not a background process to check for conflicts.

Any time we are processing NetLoop, we will handle conflict correctly.
In the case of actually doing something on the network, (generally
happens at least some of the time the device is on the network) conflicts are monitored for. In the use case for the devices I use this on, I also run NetConsole, which means the NetLoop is always being run. In that case, it is compliant with the RFC.

Quoted 4 lines

I can imagine we can get conflicts, when several targets are running at the same time in u_boot and they are attached to a network where local-link addressing is active. Then we can have two or more system using the same ip address, making the network unreliable.

That is true. I believe there are some cases you could contrive that could allow a device to pick the same address as another device, but it is quite unlikely. Initial address selections are based on MAC-seeded random number, making it hard to get a conflicting address in general. It would have to be a pretty congested 169.254.0.0 network. In addition, any time both devices run NetLoop at the same time as each other, the conflict will be detected and handled.

Quoted 3 lines

Which are the limitations of this implementation ? They should also described in your patchset, maybe with a README file. Is is thought to connect the target directly to a PC ?

The most likely use-case is connecting directly to a PC, but it also works on any generic network. I added documentation to the README. I can add a note about the potential for non-compliance if NetLoop is not run.

Best regards,
-Joe

#92 lore raw

cover Add link-local addressing support

Quoted 5 lines · Joe Hershberger
Quoted 3 lines

I have a basic question about your patchset. RFC3927 requires that addresses are continuosly checked to avoid conflicts - this is a strict requirement.

True. It cannot be 100% compliant in every use-case.

It is important that these limitations are well documented

Quoted 1 line

Any time we are processing NetLoop, we will handle conflict correctly.

Yes, but NetLoop is running only when there some activity on the network.

Quoted 5 lines

In the case of actually doing something on the network, (generally
happens at least some of the time the device is on the network) conflicts are monitored for. In the use case for the devices I use this on, I also run NetConsole, which means the NetLoop is always being run. In that case, it is compliant with the RFC.

Right - I think this is the best case.

Quoted 11 lines
Quoted 5 lines

I can imagine we can get conflicts, when several targets are running at the same time in u_boot and they are attached to a network where local-link addressing is active. Then we can have two or more system using the same ip address, making the network unreliable.

That is true. I believe there are some cases you could contrive that could allow a device to pick the same address as another device, but it is quite unlikely. Initial address selections are based on MAC-seeded random number, making it hard to get a conflicting address in general.

It depends on the number of devices attached to the network - in a small environment, it is not probable. Anyway, if we document well how this feature should be used and which are the limitations, anybody is warned about its usage and about the best conditions to run the feature.

Quoted 6 lines
Quoted 4 lines

Which are the limitations of this implementation ? They should also described in your patchset, maybe with a README file. Is is thought to connect the target directly to a PC ?

The most likely use-case is connecting directly to a PC,

I have supposed also this is the best use-case.

Quoted 2 lines

but it also
works on any generic network. I added documentation to the README.

Ok - please add a separate file doc/README.link-local (or whatever filename you want)

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#93 lore raw

cover Add link-local addressing support

Quoted 5 lines · On Thursday 26 January 2012 04:21:21 Stefano Babic wrote:
Quoted 4 lines · Joe Hershberger
Quoted 3 lines

I have a basic question about your patchset. RFC3927 requires that addresses are continuosly checked to avoid conflicts - this is a strict requirement.

Quoted 7 lines
Quoted 1 line

True. It cannot be 100% compliant in every use-case.

It is important that these limitations are well documented

Quoted 1 line

Any time we are processing NetLoop, we will handle conflict correctly.

Yes, but NetLoop is running only when there some activity on the network.

isn't that the only time that matters ? if we're sitting at the command prompt, then u-boot has the network pretty much shut off (doesn't respond to ARP let alone anything higher). as soon as we try to do network communication, we are compliant again.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/f4dd560d/attachment.pgp>

#94 lore raw

cover Add link-local addressing support

Quoted 13 lines · Mike Frysinger
Quoted 12 lines · On Thursday 26 January 2012 04:21:21 Stefano Babic wrote:
Quoted 5 lines · Joe Hershberger
Quoted 3 lines

I have a basic question about your patchset. RFC3927 requires that addresses are continuosly checked to avoid conflicts - this is a strict requirement.

True. It cannot be 100% compliant in every use-case.

It is important that these limitations are well documented

Quoted 2 lines

Any time we are processing NetLoop, we will handle conflict correctly.

Quoted 6 lines
Quoted 2 lines

Yes, but NetLoop is running only when there some activity on the network.

isn't that the only time that matters ? if we're sitting at the command prompt, then u-boot has the network pretty much shut off (doesn't respond to ARP let alone anything higher).

This is true, but what does happen with a second / multiple boards on the network ? Some of them can steal the same ip address because our board does not answer and conflicts are not solved. At least, I am expecting that some ip address suddenly changes and that can be some inconsistencies in ARP tables.

Stefano

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#95 lore raw

cover Add link-local addressing support

Quoted 21 lines · On Friday 03 February 2012 11:19:22 Stefano Babic wrote:
Quoted 13 lines · Mike Frysinger
Quoted 12 lines · On Thursday 26 January 2012 04:21:21 Stefano Babic wrote:
Quoted 5 lines · Joe Hershberger
Quoted 3 lines

I have a basic question about your patchset. RFC3927 requires that addresses are continuosly checked to avoid conflicts - this is a strict requirement.

True. It cannot be 100% compliant in every use-case.

It is important that these limitations are well documented

Quoted 2 lines

Any time we are processing NetLoop, we will handle conflict correctly.

Quoted 6 lines
Quoted 2 lines

Yes, but NetLoop is running only when there some activity on the network.

isn't that the only time that matters ? if we're sitting at the command prompt, then u-boot has the network pretty much shut off (doesn't respond to ARP let alone anything higher).

Quoted 5 lines

This is true, but what does happen with a second / multiple boards on the network ? Some of them can steal the same ip address because our board does not answer and conflicts are not solved. At least, I am expecting that some ip address suddenly changes and that can be some inconsistencies in ARP tables.

as soon as the conflict occurs, wouldn't that get detected then ? u-boot not actively responding to a few requests isn't really all that different from the packets getting dropped by say a busy hub.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/961a2972/attachment.pgp>

#96 lore raw

v2 cover Network stack checkpatch.pl compliance

In reply to Joe Hershberger

This patch-series addresses checkpatch compliance issues throughout the networking stack.

One particularly intrusive change is the removal of "volatile" from the Ethernet driver API. All network drivers need to be updated to not use volatile pointers when calling into the network stack.

This is a portion of the changes split from the series:
"Add link-local addressing support"

Joe Hershberger (10):
net: Remove volatile from net API
net: cosmetic: net.h checkpatch compliance
net: cosmetic: net.c checkpatch compliance
net: cosmetic: eth.c checkpatch compliance
net: cosmetic: net.c checkpatch compliance
net: cosmetic: nfs.* checkpatch compliance
net: cosmetic: rarp.* checkpatch compliance
net: cosmetic: sntp.* checkpatch compliance
net: cosmetic: tftp.* checkpatch compliance
net: cosmetic: netconsole.c checkpatch compliance

 common/main.c            |    1 -
 drivers/net/netconsole.c |  122 +++++++++--------
 include/common.h         |    4 +
 include/net.h            |  144 +++++++++++---------
 net/bootp.c              |  344 +++++++++++++++++++++++-----------------------
 net/bootp.h              |   56 ++++----
 net/eth.c                |   79 +++++------
 net/net.c                |   56 ++++----
 net/nfs.c                |  300 ++++++++++++++++++++--------------------
 net/nfs.h                |    2 +-
 net/rarp.c               |   30 ++--
 net/rarp.h               |    4 +-
 net/sntp.c               |   31 +++--
 net/sntp.h               |    2 +-
 net/tftp.c               |   36 +++---
 net/tftp.h               |    2 +-
 16 files changed, 614 insertions(+), 599 deletions(-)
#97 lore raw

v3 cover Network stack checkpatch.pl compliance

This patch-series addresses checkpatch compliance issues throughout the networking stack.

One particularly intrusive change is the removal of "volatile" from the Ethernet driver API. All network drivers need to be updated to not use volatile pointers when calling into the network stack.

This is a portion of the changes split from the series:
"Add link-local addressing support"

Joe Hershberger (10):
net: Remove volatile from net API
net: cosmetic: net.h checkpatch compliance
net: cosmetic: bootp.* checkpatch compliance
net: cosmetic: eth.c checkpatch compliance
net: cosmetic: net.c checkpatch compliance
net: cosmetic: nfs.* checkpatch compliance
net: cosmetic: rarp.* checkpatch compliance
net: cosmetic: sntp.* checkpatch compliance
net: cosmetic: tftp.* checkpatch compliance
net: cosmetic: netconsole.c checkpatch compliance

 common/main.c            |    1 -
 drivers/net/netconsole.c |  122 +++++++++--------
 include/common.h         |    4 +
 include/net.h            |  146 +++++++++++---------
 net/bootp.c              |  344 +++++++++++++++++++++++-----------------------
 net/bootp.h              |   56 ++++----
 net/eth.c                |   79 +++++------
 net/net.c                |   56 ++++----
 net/nfs.c                |  300 ++++++++++++++++++++--------------------
 net/nfs.h                |    2 +-
 net/rarp.c               |   30 ++--
 net/rarp.h               |    4 +-
 net/sntp.c               |   31 +++--
 net/sntp.h               |    2 +-
 net/tftp.c               |   36 +++---
 net/tftp.h               |    2 +-
 16 files changed, 616 insertions(+), 599 deletions(-)
#98 lore raw

PATCH v3 1/10 net: Remove volatile from net API

In reply to Joe Hershberger

---
Changes for v2:
- Remove volatile from eth driver API
- Not using global NetRxPacket (since not casting away volatile)
Changes for v3:

 include/net.h |   25 +++++++++++++------------
 net/bootp.c   |    4 ++--
 net/eth.c     |   12 +++++-------
 net/net.c     |   34 +++++++++++++++++-----------------
 net/rarp.c    |    2 +-
 net/tftp.c    |    6 +++---
 6 files changed, 41 insertions(+), 42 deletions(-)
include/net.h +13 -12
index ee11f82..7440182 100644
@@ -81,7 +81,7 @@ struct eth_device {
 	int state;
 
 	int  (*init) (struct eth_device*, bd_t*);
-	int  (*send) (struct eth_device*, volatile void* packet, int length);
+	int  (*send) (struct eth_device*, void *packet, int length);
 	int  (*recv) (struct eth_device*);
 	void (*halt) (struct eth_device*);
 #ifdef CONFIG_MCAST_TFTP
@@ -120,10 +120,11 @@ extern int eth_getenv_enetaddr_by_index(const char *base_name, int index,
 
 extern int usb_eth_initialize(bd_t *bi);
 extern int eth_init(bd_t *bis);			/* Initialize the device */
-extern int eth_send(volatile void *packet, int length);	   /* Send a packet */
+extern int eth_send(void *packet, int length);	   /* Send a packet */
 
 #ifdef CONFIG_API
-extern int eth_receive(volatile void *packet, int length); /* Receive a packet*/
+extern int eth_receive(void *packet, int length); /* Receive a packet*/
+extern void (*push_packet)(void *packet, int length);
 #endif
 extern int eth_rx(void);			/* Check for received packets */
 extern void eth_halt(void);			/* stop SCC */
@@ -342,9 +343,9 @@ extern uchar		NetOurEther[6];		/* Our ethernet address		*/
 extern uchar		NetServerEther[6];	/* Boot server enet address	*/
 extern IPaddr_t		NetOurIP;		/* Our    IP addr (0 = unknown)	*/
 extern IPaddr_t		NetServerIP;		/* Server IP addr (0 = unknown)	*/
-extern volatile uchar * NetTxPacket;		/* THE transmit packet		*/
-extern volatile uchar * NetRxPackets[PKTBUFSRX];/* Receive packets		*/
-extern volatile uchar * NetRxPacket;		/* Current receive packet	*/
+extern uchar		*NetTxPacket;		/* THE transmit packet */
+extern uchar		*NetRxPackets[PKTBUFSRX];/* Receive packets */
+extern uchar		*NetRxPacket;		/* Current receive packet */
 extern int		NetRxPacketLen;		/* Current rx packet length	*/
 extern unsigned		NetIPID;		/* IP ID (counting)		*/
 extern uchar		NetBcastAddr[6];	/* Ethernet boardcast address	*/
@@ -408,10 +409,10 @@ extern void	NetStartAgain(void);
 extern int	NetEthHdrSize(void);
 
 /* Set ethernet header; returns the size of the header */
-extern int	NetSetEther(volatile uchar *, uchar *, uint);
+extern int NetSetEther(uchar *, uchar *, uint);
 
 /* Set IP header */
-extern void	NetSetIP(volatile uchar *, IPaddr_t, int, int, int);
+extern void NetSetIP(uchar *, IPaddr_t, int, int, int);
 
 /* Checksum */
 extern int	NetCksumOk(uchar *, int);	/* Return true if cksum OK	*/
@@ -423,13 +424,13 @@ extern void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */
 extern void	NetSetTimeout(ulong, thand_f *);/* Set timeout handler		*/
 
 /* Transmit "NetTxPacket" */
-extern void	NetSendPacket(volatile uchar *, int);
+extern void NetSendPacket(uchar *, int);
 
 /* Transmit UDP packet, performing ARP request if needed */
 extern int	NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len);
 
 /* Processes a received packet */
-extern void	NetReceive(volatile uchar *, int);
+extern void NetReceive(uchar *, int);
 
 /*
  * Check if autoload is enabled. If so, use either NFS or TFTP to download
@@ -445,7 +446,7 @@ void net_auto_load(void);
  * footprint in our tests.
  */
 /* return IP *in network byteorder* */
-static inline IPaddr_t NetReadIP(volatile void *from)
+static inline IPaddr_t NetReadIP(void *from)
 {
 	IPaddr_t ip;
 	memcpy((void*)&ip, (void*)from, sizeof(ip));
@@ -467,7 +468,7 @@ static inline void NetWriteIP(void *to, IPaddr_t ip)
 }
 
 /* copy IP */
-static inline void NetCopyIP(volatile void *to, void *from)
+static inline void NetCopyIP(void *to, void *from)
 {
 	memcpy((void*)to, from, sizeof(IPaddr_t));
 }
net/bootp.c +2 -2
index 9e32476..35654b4 100644
@@ -586,7 +586,7 @@ static int BootpExtended (u8 * e)
 void
 BootpRequest (void)
 {
-	volatile uchar *pkt, *iphdr;
+	uchar *pkt, *iphdr;
 	Bootp_t *bp;
 	int ext_len, pktlen, iplen;
 
@@ -839,7 +839,7 @@ static int DhcpMessageType(unsigned char *popt)
 
 static void DhcpSendRequestPkt(Bootp_t *bp_offer)
 {
-	volatile uchar *pkt, *iphdr;
+	uchar *pkt, *iphdr;
 	Bootp_t *bp;
 	int pktlen, iplen, extlen;
 	IPaddr_t OfferedIP;
net/eth.c +5 -7
index 3eeb908..66a84d4 100644
@@ -82,8 +82,6 @@ int cpu_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
 int board_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
 
 #ifdef CONFIG_API
-extern void (*push_packet)(volatile void *, int);
-
 static struct {
 	uchar data[PKTSIZE];
 	int length;
@@ -407,7 +405,7 @@ void eth_halt(void)
 	eth_current->state = ETH_STATE_PASSIVE;
 }
 
-int eth_send(volatile void *packet, int length)
+int eth_send(void *packet, int length)
 {
 	if (!eth_current)
 		return -1;
@@ -424,9 +422,9 @@ int eth_rx(void)
 }
 
 #ifdef CONFIG_API
-static void eth_save_packet(volatile void *packet, int length)
+static void eth_save_packet(void *packet, int length)
 {
-	volatile char *p = packet;
+	char *p = packet;
 	int i;
 
 	if ((eth_rcv_last+1) % PKTBUFSRX == eth_rcv_current)
@@ -442,9 +440,9 @@ static void eth_save_packet(volatile void *packet, int length)
 	eth_rcv_last = (eth_rcv_last + 1) % PKTBUFSRX;
 }
 
-int eth_receive(volatile void *packet, int length)
+int eth_receive(void *packet, int length)
 {
-	volatile char *p = packet;
+	char *p = packet;
 	void *pp = push_packet;
 	int i;
 
net/net.c +17 -17
index c5acf8f..9a0417d 100644
@@ -152,7 +152,7 @@ IPaddr_t	NetOurIP;
 /* Server IP addr (0 = unknown) */
 IPaddr_t	NetServerIP;
 /* Current receive packet */
-volatile uchar *NetRxPacket;
+uchar *NetRxPacket;
 /* Current rx packet length */
 int		NetRxPacketLen;
 /* IP packet ID */
@@ -161,7 +161,7 @@ unsigned	NetIPID;
 uchar		NetBcastAddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 uchar		NetEtherNullAddr[6];
 #ifdef CONFIG_API
-void		(*push_packet)(volatile void *, int len) = 0;
+void		(*push_packet)(void *, int len) = 0;
 #endif
 #if defined(CONFIG_CMD_CDP)
 /* Ethernet bcast address */
@@ -208,10 +208,10 @@ void NcStart(void);
 int nc_input_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len);
 #endif
 
-volatile uchar	PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
+uchar PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
 
 /* Receive packet */
-volatile uchar *NetRxPackets[PKTBUFSRX];
+uchar *NetRxPackets[PKTBUFSRX];
 
 /* Current RX packet handler */
 static rxhand_f *packetHandler;
@@ -225,7 +225,7 @@ static ulong	timeStart;
 /* Current timeout value */
 static ulong	timeDelta;
 /* THE transmit packet */
-volatile uchar *NetTxPacket;
+uchar *NetTxPacket;
 
 static int net_check_prereq(enum proto_t protocol);
 
@@ -246,7 +246,7 @@ int		NetArpWaitTry;
 
 void ArpRequest(void)
 {
-	volatile uchar *pkt;
+	uchar *pkt;
 	ARP_t *arp;
 
 	debug("ARP broadcast %d\n", NetArpWaitTry);
@@ -705,7 +705,7 @@ NetSetTimeout(ulong iv, thand_f *f)
 
 
 void
-NetSendPacket(volatile uchar *pkt, int len)
+NetSendPacket(uchar *pkt, int len)
 {
 	(void) eth_send(pkt, len);
 }
@@ -768,8 +768,8 @@ static ushort PingSeqNo;
 int PingSend(void)
 {
 	static uchar mac[6];
-	volatile IP_t *ip;
-	volatile ushort *s;
+	IP_t *ip;
+	ushort *s;
 	uchar *pkt;
 
 	/* XXX always send arp request */
@@ -784,7 +784,7 @@ int PingSend(void)
 	pkt = NetArpWaitTxPacket;
 	pkt += NetSetEther(pkt, mac, PROT_IP);
 
-	ip = (volatile IP_t *)pkt;
+	ip = (IP_t *)pkt;
 
 	/*
 	 * Construct an IP and ICMP header.
@@ -936,9 +936,9 @@ static ushort CDP_compute_csum(const uchar *buff, ushort len)
 
 int CDPSendTrigger(void)
 {
-	volatile uchar *pkt;
-	volatile ushort *s;
-	volatile ushort *cp;
+	uchar *pkt;
+	ushort *s;
+	ushort *cp;
 	Ethernet_t *et;
 	int len;
 	ushort chksum;
@@ -965,7 +965,7 @@ int CDPSendTrigger(void)
 	/* CDP header */
 	*pkt++ = 0x02;				/* CDP version 2 */
 	*pkt++ = 180;				/* TTL */
-	s = (volatile ushort *)pkt;
+	s = (ushort *)pkt;
 	cp = s;
 	/* checksum (0 for later calculation) */
 	*s++ = htons(0);
@@ -1439,7 +1439,7 @@ static void receive_icmp(IP_t *ip, int len, IPaddr_t src_ip, Ethernet_t *et)
 }
 
 void
-NetReceive(volatile uchar *inpkt, int len)
+NetReceive(uchar *inpkt, int len)
 {
 	Ethernet_t *et;
 	IP_t	*ip;
@@ -1918,7 +1918,7 @@ NetEthHdrSize(void)
 }
 
 int
-NetSetEther(volatile uchar *xet, uchar * addr, uint prot)
+NetSetEther(uchar *xet, uchar * addr, uint prot)
 {
 	Ethernet_t *et = (Ethernet_t *)xet;
 	ushort myvlanid;
@@ -1943,7 +1943,7 @@ NetSetEther(volatile uchar *xet, uchar * addr, uint prot)
 }
 
 void
-NetSetIP(volatile uchar *xip, IPaddr_t dest, int dport, int sport, int len)
+NetSetIP(uchar *xip, IPaddr_t dest, int dport, int sport, int len)
 {
 	IP_t *ip = (IP_t *)xip;
 
net/rarp.c +1 -1
index 097f970..77d63e8 100644
@@ -71,7 +71,7 @@ void
 RarpRequest (void)
 {
 	int i;
-	volatile uchar *pkt;
+	uchar *pkt;
 	ARP_t *	rarp;
 
 	printf("RARP broadcast %d\n", ++RarpTry);
net/tftp.c +3 -3
index 7aa3e23..e62f229 100644
@@ -310,9 +310,9 @@ static void
 TftpSend(void)
 {
 	uchar *pkt;
-	volatile uchar *xp;
-	int		len = 0;
-	volatile ushort *s;
+	uchar *xp;
+	int len = 0;
+	ushort *s;
 
 #ifdef CONFIG_MCAST_TFTP
 	/* Multicast TFTP.. non-MasterClients do not ACK data. */
Signature · 1 line
1.6.0.2
#99 lore raw

PATCH v3 1/10 net: Remove volatile from net API

Dear Joe Hershberger,

Quoted 8 lines · In message <[email protected]> you wrote:

---
Changes for v2:
- Remove volatile from eth driver API
- Not using global NetRxPacket (since not casting away volatile)
Changes for v3:

Quoted 7 lines
 include/net.h |   25 +++++++++++++------------
 net/bootp.c   |    4 ++--
 net/eth.c     |   12 +++++-------
 net/net.c     |   34 +++++++++++++++++-----------------
 net/rarp.c    |    2 +-
 net/tftp.c    |    6 +++---
 6 files changed, 41 insertions(+), 42 deletions(-)

While getting rid of volatile is a good thing in general, I am worried about the test scope of this patch.

This commit is causing tons of compiler warnings because the respective changes have only be done in the header file and the net/ code, but they are missing in _all_ network drivers. I wonder which compile and run time testing has been done with this? I mean, you decided to pull this into mainline - has it been tested at all ?!?

When are you planning to provide fixes for all these warnings? As is, the whole build is spoiled. Or should we revert these patches?

Best regards,

Wolfgang Denk

Signature · 8 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The alternative to genuflecting before the  god  of  code-bumming  is
finding  a  better  algorithm.  It should be clear that none such was
available. If your code is too slow, you must make it faster.  If  no
better algorithm is available, you must trim cycles.
                                 - td at alice.UUCP (Tom Duff) 29 Aug 88
#100 lore raw

PATCH v3 1/10 net: Remove volatile from net API

Hi Wolfgang,

Quoted 19 lines · Wolfgang Denk

Dear Joe Hershberger,

Quoted 8 lines · In message <[email protected]> you wrote:

---
Changes for v2:
? - Remove volatile from eth driver API
? - Not using global NetRxPacket (since not casting away volatile) Changes for v3:

Quoted 7 lines
?include/net.h | ? 25 +++++++++++++------------
?net/bootp.c ? | ? ?4 ++--
?net/eth.c ? ? | ? 12 +++++-------
?net/net.c ? ? | ? 34 +++++++++++++++++-----------------
?net/rarp.c ? ?| ? ?2 +-
?net/tftp.c ? ?| ? ?6 +++---

?6 files changed, 41 insertions(+), 42 deletions(-)

Quoted 2 lines

While getting rid of volatile is a good thing in general, I am worried about the test scope of this patch.

I was too. That's why I asked for guidance:

Quoted 33 lines · Wolfgang Denk

Dear Joe,

Quoted 20 lines · In message <CANr=Z=bA9gPv=OALJ2OR_drNM7-KuZn9H4EL7nEsdSMtMyn1Kw@mail.gmail.com>…
Quoted 20 lines · Mike Frysinger
Quoted 10 lines

in general, i like this. my only concern would be the drivers that might break due to incorrect cache management (which the volatile markers happen to work around for them).

having the API accept a volatile but then casting it away puts us in a worse place i think. on one hand, our API is saying "we treat it as volatile" when we really don't, so any drivers that call it with a volatile don't get build warnings. i'd just drop it from all of the net API so that the drivers which do call with a volatile pointer get a build warning -- now the driver maintainer knows they have to at least look at something.

I'm fine with that... it was my first approach, in fact. However, I was concerned that if I submitted a patch that added warnings to every Ethernet-enabled board, that would be frowned upon. I think it is the correct thing to do, but don't have a good feeling for how open people are to changing an interface like that. I also did not want to attempt to revise every net driver in this series.

Quoted 5 lines
Quoted 5 lines

Wolfgang,

Would you approve of changing the net driver API to not use volatile buffer pointers and have the driver file warn until the driver maintainer addresses the warnings?

I also think this is the right thing to do, and such cleanups sometimes have to spitout warnings for the not-yet-fixed boards. That's unavoidable. Go for it...

Quoted 5 lines
Quoted 3 lines

Can I get guidance on this from you? I'm about done preparing the changes to the link-local patch-set and would like to know how you prefer that I proceed.

ACK for above.

This is why I went forward with warnings in the mainline for this interface change.

Quoted 5 lines

This commit is causing tons of compiler warnings because the respective changes have only be done in the header file and the net/ code, but they are missing in _all_ network drivers. ?I wonder which compile and run time testing has been done with this? ?I mean, you decided to pull this into mainline - has it been tested at all ?!?

Yes... I tested this on MPC8313 (powerpc) and AM1808 (arm).

Quoted 2 lines

When are you planning to provide fixes for all these warnings? ?As is, the whole build is spoiled. ?Or should we revert these patches?

I plan to submit patches for the boards I am able to test, but for reason that Mike suggested, I'm not sure it is wise to fix the warning unless it can be tested on hardware.

Apologies for not making this clear,
-Joe

#101 lore raw

PATCH v3 1/10 net: Remove volatile from net API

Dear Joe Hershberger,

Quoted 5 lines · In message <CANr=Z=ZiMqvn2vxp0_kMA76O091TJFu4ck6wVf7re3hEFMOk2g@mail.gmail.com>…
Quoted 3 lines

While getting rid of volatile is a good thing in general, I am worried about the test scope of this patch.

I was too. That's why I asked for guidance:

Sorry, this was a misunderstanding then.

My expectation was that you wuld continue this patch series and clean up the drivers, even though you cannot actually test these.

Quoted 6 lines
Quoted 2 lines

When are you planning to provide fixes for all these warnings? As is, the whole build is spoiled. Or should we revert these patches?

I plan to submit patches for the boards I am able to test, but for reason that Mike suggested, I'm not sure it is wise to fix the warning unless it can be tested on hardware.

The rule is that he who breaks the code is also responsible to fix it. Please make the code at least compile-clean again. Board maintainers will have to help with actual testing.

Thanks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Program maintenance is an entropy-increasing process,  and  even  its
most skilfull execution only delays the subsidence of the system into
unfixable obsolescence.       - Fred Brooks, "The Mythical Man Month"
#102 lore raw

PATCH v3 1/10 net: Remove volatile from net API

Hi Wolfgang,

Quoted 17 lines · Wolfgang Denk

Dear Joe Hershberger,

Quoted 5 lines · In message <CANr=Z=ZiMqvn2vxp0_kMA76O091TJFu4ck6wVf7re3hEFMOk2g@mail.gmail.com>…
Quoted 3 lines

While getting rid of volatile is a good thing in general, I am worried about the test scope of this patch.

I was too. ?That's why I asked for guidance:

Sorry, this was a misunderstanding then.

My expectation was that you wuld continue this patch series and clean up the drivers, even though you cannot actually test these.

Quoted 3 lines
Quoted 2 lines

When are you planning to provide fixes for all these warnings? ?As is, the whole build is spoiled. ?Or should we revert these patches?

Quoted 7 lines
Quoted 3 lines

I plan to submit patches for the boards I am able to test, but for reason that Mike suggested, I'm not sure it is wise to fix the warning unless it can be tested on hardware.

The rule is that he who breaks the code is also responsible to fix it. ?Please make the code at least compile-clean again. ?Board maintainers will have to help with actual testing.

Will do.

-Joe

#103 lore raw

PATCH v3 1/10 net: Remove volatile from net API

Dear Joe Hershberger,

Quoted 6 lines · In message <CANr=Z=bmuwyjiDmXj1qjJ5hsKCfm15gbK2GbZNp8X2E=1KMp6A@mail.gmail.com>…
Quoted 4 lines

The rule is that he who breaks the code is also responsible to fix it. Please make the code at least compile-clean again. Board maintainers will have to help with actual testing.

Will do.

Thanks a lot. Sorry for the miscommunication.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Earth -- mother of the most beautiful women in the universe.
	-- Apollo, "Who Mourns for Adonais?" stardate 3468.1
#104 lore raw

PATCH 1/1 MPC8xx: fix "Remove volatile from net API" aftermath

In reply to Joe Hershberger

Commit db288a9 "net: Remove volatile from net API" caused a number of
build warnings:
fec.c: In function 'fec_initialize':
fec.c:183:13: warning: assignment from incompatible pointer type [enabled by default]
fec.c: In function 'fec_recv':
fec.c:284:5: warning: passing argument 1 of 'NetReceive' discards 'volatile' qualifier from pointer target type [enabled by default] /home/wd/git/u-boot/work/include/net.h:433:13: note: expected 'uchar *' but argument is of type 'volatile uchar *' scc.c: In function 'scc_initialize':
scc.c:85:14: warning: assignment from incompatible pointer type [enabled by default]

Fix these.

Cc Joe Hershberger <[email protected]>

---

Joe, I started fixing these issues when I realized that this is not just a few files, but actually _ALL_ network drivers that you forgot to adapt. I wonder how much testing was done before you decided to pull this into mainline? It appears not much compile testing... what about run-time testing?

Sorry, but I don't have time to clean up all of this. Are you going to do that?

-wd

 arch/powerpc/cpu/mpc8xx/fec.c |    6 +++---
 arch/powerpc/cpu/mpc8xx/scc.c |    4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/cpu/mpc8xx/fec.c +3 -3
index f2a2c3a..64e2ef7 100644
@@ -139,7 +139,7 @@ typedef volatile struct CommonBufferDescriptor {
 
 static RTXBD *rtx = NULL;
 
-static int fec_send(struct eth_device* dev, volatile void *packet, int length);
+static int fec_send(struct eth_device* dev, void *packet, int length);
 static int fec_recv(struct eth_device* dev);
 static int fec_init(struct eth_device* dev, bd_t * bd);
 static void fec_halt(struct eth_device* dev);
@@ -193,7 +193,7 @@ int fec_initialize(bd_t *bis)
 	return 1;
 }
 
-static int fec_send(struct eth_device* dev, volatile void *packet, int length)
+static int fec_send(struct eth_device* dev, void *packet, int length)
 {
 	int j, rc;
 	struct ether_fcc_info_s *efis = dev->priv;
@@ -267,7 +267,7 @@ static int fec_recv (struct eth_device *dev)
 				rtx->rxbd[rxIdx].cbd_sc);
 #endif
 		} else {
-			volatile uchar *rx = NetRxPackets[rxIdx];
+			uchar *rx = NetRxPackets[rxIdx];
 
 			length -= 4;
 
arch/powerpc/cpu/mpc8xx/scc.c +2 -2
index e376c64..b172121 100644
@@ -65,7 +65,7 @@ typedef volatile struct CommonBufferDescriptor {
 
 static RTXBD *rtx;
 
-static int scc_send(struct eth_device* dev, volatile void *packet, int length);
+static int scc_send(struct eth_device* dev, void *packet, int length);
 static int scc_recv(struct eth_device* dev);
 static int scc_init (struct eth_device* dev, bd_t * bd);
 static void scc_halt(struct eth_device* dev);
@@ -90,7 +90,7 @@ int scc_initialize(bd_t *bis)
 	return 1;
 }
 
-static int scc_send(struct eth_device* dev, volatile void *packet, int length)
+static int scc_send(struct eth_device* dev, void *packet, int length)
 {
 	int i, j=0;
 #if 0
Signature · 1 line
1.7.7.6
#105 lore raw

PATCH 1/1 MPC8xx: fix "Remove volatile from net API" aftermath

Hi Wolfgang,

Quoted 16 lines · Wolfgang Denk

Commit db288a9 "net: Remove volatile from net API" caused a number of
build warnings:
fec.c: In function 'fec_initialize':
fec.c:183:13: warning: assignment from incompatible pointer type [enabled by default]
fec.c: In function 'fec_recv':
fec.c:284:5: warning: passing argument 1 of 'NetReceive' discards 'volatile' qualifier from pointer target type [enabled by default] /home/wd/git/u-boot/work/include/net.h:433:13: note: expected 'uchar *' but argument is of type 'volatile uchar *' scc.c: In function 'scc_initialize':
scc.c:85:14: warning: assignment from incompatible pointer type [enabled by default]

Fix these.

Cc Joe Hershberger <[email protected]>

---

Quoted 8 lines

Joe, ?I started fixing these issues when I realized that this is not just a few files, but actually _ALL_ network drivers that you forgot to adapt. ?I wonder how much testing was done before you decided to pull this into mainline? ?It appears not much compile testing... what about run-time testing?

Sorry, but I don't have time to clean up all of this. ?Are you going to do that?

Applied this for a start.

Thanks,
-Joe

#106 lore raw

PATCH v3 2/10 net: cosmetic: net.h checkpatch compliance

In reply to Joe Hershberger

---
Changes for v2:
- Split into smaller patches
Changes for v3:
- Added blank lines for Simon Glass

 include/net.h |  116 +++++++++++++++++++++++++++++---------------------------
 1 files changed, 60 insertions(+), 56 deletions(-)
include/net.h +60 -56
index 7440182..2b6e59a 100644
@@ -80,14 +80,14 @@ struct eth_device {
 	int iobase;
 	int state;
 
-	int  (*init) (struct eth_device*, bd_t*);
-	int  (*send) (struct eth_device*, void *packet, int length);
-	int  (*recv) (struct eth_device*);
-	void (*halt) (struct eth_device*);
+	int  (*init) (struct eth_device *, bd_t *);
+	int  (*send) (struct eth_device *, void *packet, int length);
+	int  (*recv) (struct eth_device *);
+	void (*halt) (struct eth_device *);
 #ifdef CONFIG_MCAST_TFTP
-	int (*mcast) (struct eth_device*, u32 ip, u8 set);
+	int (*mcast) (struct eth_device *, u32 ip, u8 set);
 #endif
-	int  (*write_hwaddr) (struct eth_device*);
+	int  (*write_hwaddr) (struct eth_device *);
 	struct eth_device *next;
 	int index;
 	void *priv;
@@ -101,7 +101,7 @@ extern void eth_set_current(void);		/* set nterface to ethcur var */
 extern struct eth_device *eth_get_dev(void);	/* get the current device MAC */
 extern struct eth_device *eth_get_dev_by_name(const char *devname);
 extern struct eth_device *eth_get_dev_by_index(int index); /* get dev @ index */
-extern int eth_get_dev_index (void);		/* get the device index */
+extern int eth_get_dev_index(void);		/* get the device index */
 extern void eth_parse_enetaddr(const char *addr, uchar *enetaddr);
 extern int eth_getenv_enetaddr(char *name, uchar *enetaddr);
 extern int eth_setenv_enetaddr(char *name, const uchar *enetaddr);
@@ -143,8 +143,8 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
 		     int eth_number);
 
 #ifdef CONFIG_MCAST_TFTP
-int eth_mcast_join( IPaddr_t mcast_addr, u8 join);
-u32 ether_crc (size_t len, unsigned char const *p);
+int eth_mcast_join(IPaddr_t mcast_addr, u8 join);
+u32 ether_crc(size_t len, unsigned char const *p);
 #endif
 
 
@@ -219,8 +219,8 @@ typedef struct {
 #define IP_FLAGS_DFRAG	0x4000 /* don't fragments */
 #define IP_FLAGS_MFRAG	0x2000 /* more fragments */
 
-#define IP_HDR_SIZE_NO_UDP	(sizeof (IP_t) - 8)
-#define IP_HDR_SIZE		(sizeof (IP_t))
+#define IP_HDR_SIZE_NO_UDP	(sizeof(IP_t) - 8)
+#define IP_HDR_SIZE		(sizeof(IP_t))
 
 
 /*
@@ -327,46 +327,46 @@ typedef struct icmphdr {
 
 /* net.c */
 /** BOOTP EXTENTIONS **/
-extern IPaddr_t		NetOurGatewayIP;	/* Our gateway IP addresse	*/
-extern IPaddr_t		NetOurSubnetMask;	/* Our subnet mask (0 = unknown)*/
-extern IPaddr_t		NetOurDNSIP;	 /* Our Domain Name Server (0 = unknown)*/
+extern IPaddr_t NetOurGatewayIP;	/* Our gateway IP address */
+extern IPaddr_t NetOurSubnetMask;	/* Our subnet mask (0 = unknown) */
+extern IPaddr_t NetOurDNSIP;	/* Our Domain Name Server (0 = unknown) */
 #if defined(CONFIG_BOOTP_DNS2)
-extern IPaddr_t		NetOurDNS2IP;	 /* Our 2nd Domain Name Server (0 = unknown)*/
+extern IPaddr_t NetOurDNS2IP;	/* Our 2nd Domain Name Server (0 = unknown) */
 #endif
-extern char		NetOurNISDomain[32];	/* Our NIS domain		*/
-extern char		NetOurHostName[32];	/* Our hostname			*/
-extern char		NetOurRootPath[64];	/* Our root path		*/
-extern ushort		NetBootFileSize;	/* Our boot file size in blocks	*/
+extern char	NetOurNISDomain[32];	/* Our NIS domain */
+extern char	NetOurHostName[32];	/* Our hostname */
+extern char	NetOurRootPath[64];	/* Our root path */
+extern ushort	NetBootFileSize;	/* Our boot file size in blocks */
 /** END OF BOOTP EXTENTIONS **/
-extern ulong		NetBootFileXferSize;	/* size of bootfile in bytes	*/
-extern uchar		NetOurEther[6];		/* Our ethernet address		*/
-extern uchar		NetServerEther[6];	/* Boot server enet address	*/
-extern IPaddr_t		NetOurIP;		/* Our    IP addr (0 = unknown)	*/
-extern IPaddr_t		NetServerIP;		/* Server IP addr (0 = unknown)	*/
+extern ulong		NetBootFileXferSize;	/* size of bootfile in bytes */
+extern uchar		NetOurEther[6];		/* Our ethernet address */
+extern uchar		NetServerEther[6];	/* Boot server enet address */
+extern IPaddr_t		NetOurIP;	/* Our    IP addr (0 = unknown) */
+extern IPaddr_t		NetServerIP;	/* Server IP addr (0 = unknown) */
 extern uchar		*NetTxPacket;		/* THE transmit packet */
-extern uchar		*NetRxPackets[PKTBUFSRX];/* Receive packets */
+extern uchar		*NetRxPackets[PKTBUFSRX]; /* Receive packets */
 extern uchar		*NetRxPacket;		/* Current receive packet */
-extern int		NetRxPacketLen;		/* Current rx packet length	*/
-extern unsigned		NetIPID;		/* IP ID (counting)		*/
-extern uchar		NetBcastAddr[6];	/* Ethernet boardcast address	*/
+extern int		NetRxPacketLen;		/* Current rx packet length */
+extern unsigned		NetIPID;		/* IP ID (counting) */
+extern uchar		NetBcastAddr[6];	/* Ethernet boardcast address */
 extern uchar		NetEtherNullAddr[6];
 
-#define VLAN_NONE	4095			/* untagged			*/
-#define VLAN_IDMASK	0x0fff			/* mask of valid vlan id	*/
-extern ushort		NetOurVLAN;		/* Our VLAN			*/
-extern ushort		NetOurNativeVLAN;	/* Our Native VLAN		*/
+#define VLAN_NONE	4095			/* untagged */
+#define VLAN_IDMASK	0x0fff			/* mask of valid vlan id */
+extern ushort		NetOurVLAN;		/* Our VLAN */
+extern ushort		NetOurNativeVLAN;	/* Our Native VLAN */
 
-extern uchar		NetCDPAddr[6];		/* Ethernet CDP address		*/
-extern ushort		CDPNativeVLAN;		/* CDP returned native VLAN	*/
-extern ushort		CDPApplianceVLAN;	/* CDP returned appliance VLAN	*/
+extern uchar	NetCDPAddr[6];		/* Ethernet CDP address */
+extern ushort	CDPNativeVLAN;		/* CDP returned native VLAN */
+extern ushort	CDPApplianceVLAN;	/* CDP returned appliance VLAN */
 
-extern int		NetState;		/* Network loop state		*/
+extern int		NetState;		/* Network loop state */
 #define NETLOOP_CONTINUE	1
 #define NETLOOP_RESTART		2
 #define NETLOOP_SUCCESS		3
 #define NETLOOP_FAIL		4
 
-extern int		NetRestartWrap;		/* Tried all network devices	*/
+extern int		NetRestartWrap;		/* Tried all network devices */
 
 enum proto_t {
 	BOOTP, RARP, ARP, TFTPGET, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP,
@@ -374,7 +374,7 @@ enum proto_t {
 };
 
 /* from net/net.c */
-extern char	BootFile[128];			/* Boot File name		*/
+extern char	BootFile[128];			/* Boot File name */
 
 #if defined(CONFIG_CMD_DNS)
 extern char *NetDNSResolve;		/* The host to resolve  */
@@ -382,7 +382,7 @@ extern char *NetDNSenvvar;		/* the env var to put the ip into */
 #endif
 
 #if defined(CONFIG_CMD_PING)
-extern IPaddr_t	NetPingIP;			/* the ip address to ping		*/
+extern IPaddr_t	NetPingIP;			/* the ip address to ping */
 #endif
 
 #if defined(CONFIG_CMD_CDP)
@@ -392,8 +392,8 @@ extern ushort CDPApplianceVLAN;
 #endif
 
 #if defined(CONFIG_CMD_SNTP)
-extern IPaddr_t	NetNtpServerIP;			/* the ip address to NTP	*/
-extern int NetTimeOffset;			/* offset time from UTC		*/
+extern IPaddr_t	NetNtpServerIP;			/* the ip address to NTP */
+extern int NetTimeOffset;			/* offset time from UTC */
 #endif
 
 /* Initialize the network adapter */
@@ -415,19 +415,20 @@ extern int NetSetEther(uchar *, uchar *, uint);
 extern void NetSetIP(uchar *, IPaddr_t, int, int, int);
 
 /* Checksum */
-extern int	NetCksumOk(uchar *, int);	/* Return true if cksum OK	*/
-extern uint	NetCksum(uchar *, int);		/* Calculate the checksum	*/
+extern int	NetCksumOk(uchar *, int);	/* Return true if cksum OK */
+extern uint	NetCksum(uchar *, int);		/* Calculate the checksum */
 
 /* Set callbacks */
-extern void	NetSetHandler(rxhand_f *);	/* Set RX packet handler	*/
+extern void	NetSetHandler(rxhand_f *);	/* Set RX packet handler */
 extern void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */
-extern void	NetSetTimeout(ulong, thand_f *);/* Set timeout handler		*/
+extern void	NetSetTimeout(ulong, thand_f *);/* Set timeout handler */
 
 /* Transmit "NetTxPacket" */
 extern void NetSendPacket(uchar *, int);
 
 /* Transmit UDP packet, performing ARP request if needed */
-extern int	NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len);
+extern int	NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport,
+			int sport, int len);
 
 /* Processes a received packet */
 extern void NetReceive(uchar *, int);
@@ -449,7 +450,8 @@ void net_auto_load(void);
 static inline IPaddr_t NetReadIP(void *from)
 {
 	IPaddr_t ip;
-	memcpy((void*)&ip, (void*)from, sizeof(ip));
+
+	memcpy((void *)&ip, (void *)from, sizeof(ip));
 	return ip;
 }
 
@@ -457,26 +459,27 @@ static inline IPaddr_t NetReadIP(void *from)
 static inline ulong NetReadLong(ulong *from)
 {
 	ulong l;
-	memcpy((void*)&l, (void*)from, sizeof(l));
+
+	memcpy((void *)&l, (void *)from, sizeof(l));
 	return l;
 }
 
 /* write IP *in network byteorder* */
 static inline void NetWriteIP(void *to, IPaddr_t ip)
 {
-	memcpy(to, (void*)&ip, sizeof(ip));
+	memcpy(to, (void *)&ip, sizeof(ip));
 }
 
 /* copy IP */
 static inline void NetCopyIP(void *to, void *from)
 {
-	memcpy((void*)to, from, sizeof(IPaddr_t));
+	memcpy((void *)to, from, sizeof(IPaddr_t));
 }
 
 /* copy ulong */
 static inline void NetCopyLong(ulong *to, ulong *from)
 {
-	memcpy((void*)to, (void*)from, sizeof(ulong));
+	memcpy((void *)to, (void *)from, sizeof(ulong));
 }
 
 /**
@@ -499,7 +502,7 @@ static inline int is_zero_ether_addr(const u8 *addr)
  */
 static inline int is_multicast_ether_addr(const u8 *addr)
 {
-	return (0x01 & addr[0]);
+	return 0x01 & addr[0];
 }
 
 /*
@@ -510,7 +513,8 @@ static inline int is_multicast_ether_addr(const u8 *addr)
  */
 static inline int is_broadcast_ether_addr(const u8 *addr)
 {
-	return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff;
+	return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) ==
+		0xff;
 }
 
 /*
@@ -530,13 +534,13 @@ static inline int is_valid_ether_addr(const u8 *addr)
 }
 
 /* Convert an IP address to a string */
-extern void	ip_to_string (IPaddr_t x, char *s);
+extern void ip_to_string(IPaddr_t x, char *s);
 
 /* Convert a string to ip address */
 extern IPaddr_t string_to_ip(const char *s);
 
 /* Convert a VLAN id to a string */
-extern void	VLAN_to_string (ushort x, char *s);
+extern void VLAN_to_string(ushort x, char *s);
 
 /* Convert a string to a vlan id */
 extern ushort string_to_VLAN(const char *s);
@@ -545,7 +549,7 @@ extern ushort string_to_VLAN(const char *s);
 extern ushort getenv_VLAN(char *);
 
 /* copy a filename (allow for "..." notation, limit length) */
-extern void	copy_filename (char *dst, const char *src, int size);
+extern void copy_filename(char *dst, const char *src, int size);
 
 /* get a random source port */
 extern unsigned int random_port(void);
Signature · 1 line
1.6.0.2
#107 lore raw

PATCH v3 3/10 net: cosmetic: bootp.* checkpatch compliance

In reply to Joe Hershberger

---
Changes for v2:
- Split into smaller patches
Changes for v3:
- Fixed commit summary net.c -> bootp.*

 net/bootp.c |  340 ++++++++++++++++++++++++++++++-----------------------------
 net/bootp.h |   56 +++++-----
 2 files changed, 203 insertions(+), 193 deletions(-)
net/bootp.c +173 -167
index 35654b4..d0a7da2 100644
@@ -19,19 +19,19 @@
 #endif
 #include <linux/compiler.h>
 
-#define BOOTP_VENDOR_MAGIC	0x63825363	/* RFC1048 Magic Cookie		*/
+#define BOOTP_VENDOR_MAGIC	0x63825363	/* RFC1048 Magic Cookie */
 
 #define TIMEOUT		5000UL	/* Milliseconds before trying BOOTP again */
 #ifndef CONFIG_NET_RETRY_COUNT
-# define TIMEOUT_COUNT	5		/* # of timeouts before giving up  */
+# define TIMEOUT_COUNT	5		/* # of timeouts before giving up */
 #else
 # define TIMEOUT_COUNT	(CONFIG_NET_RETRY_COUNT)
 #endif
 
-#define PORT_BOOTPS	67		/* BOOTP server UDP port		*/
-#define PORT_BOOTPC	68		/* BOOTP client UDP port		*/
+#define PORT_BOOTPS	67		/* BOOTP server UDP port */
+#define PORT_BOOTPC	68		/* BOOTP client UDP port */
 
-#ifndef CONFIG_DHCP_MIN_EXT_LEN		/* minimal length of extension list	*/
+#ifndef CONFIG_DHCP_MIN_EXT_LEN		/* minimal length of extension list */
 #define CONFIG_DHCP_MIN_EXT_LEN 64
 #endif
 
@@ -43,8 +43,8 @@ ulong		seed1, seed2;
 
 #if defined(CONFIG_CMD_DHCP)
 dhcp_state_t dhcp_state = INIT;
-unsigned long dhcp_leasetime = 0;
-IPaddr_t NetDHCPServerIP = 0;
+unsigned long dhcp_leasetime;
+IPaddr_t NetDHCPServerIP;
 static void DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 			unsigned len);
 
@@ -64,37 +64,29 @@ static char *dhcpmsg2str(int type)
 	}
 }
 #endif
-
-#if defined(CONFIG_BOOTP_VENDOREX)
-extern u8 *dhcp_vendorex_prep (u8 *e); /*rtn new e after add own opts. */
-extern u8 *dhcp_vendorex_proc (u8 *e); /*rtn next e if mine,else NULL  */
-#endif
-
 #endif
 
 static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
 {
-	Bootp_t *bp = (Bootp_t *) pkt;
+	struct Bootp_t *bp = (struct Bootp_t *) pkt;
 	int retval = 0;
 
 	if (dest != PORT_BOOTPC || src != PORT_BOOTPS)
 		retval = -1;
-	else if (len < sizeof (Bootp_t) - OPT_SIZE)
+	else if (len < sizeof(struct Bootp_t) - OPT_SIZE)
 		retval = -2;
 	else if (bp->bp_op != OP_BOOTREQUEST &&
-	    bp->bp_op != OP_BOOTREPLY &&
-	    bp->bp_op != DHCP_OFFER &&
-	    bp->bp_op != DHCP_ACK &&
-	    bp->bp_op != DHCP_NAK ) {
+			bp->bp_op != OP_BOOTREPLY &&
+			bp->bp_op != DHCP_OFFER &&
+			bp->bp_op != DHCP_ACK &&
+			bp->bp_op != DHCP_NAK)
 		retval = -3;
-	}
 	else if (bp->bp_htype != HWT_ETHER)
 		retval = -4;
 	else if (bp->bp_hlen != HWL_ETHER)
 		retval = -5;
-	else if (NetReadLong((ulong*)&bp->bp_id) != BootpID) {
+	else if (NetReadLong((ulong *)&bp->bp_id) != BootpID)
 		retval = -6;
-	}
 
 	debug("Filtering pkt = %d\n", retval);
 
@@ -104,7 +96,7 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
 /*
  * Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet
  */
-static void BootpCopyNetParams(Bootp_t *bp)
+static void BootpCopyNetParams(struct Bootp_t *bp)
 {
 	__maybe_unused IPaddr_t tmp_ip;
 
@@ -113,10 +105,10 @@ static void BootpCopyNetParams(Bootp_t *bp)
 	NetCopyIP(&tmp_ip, &bp->bp_siaddr);
 	if (tmp_ip != 0)
 		NetCopyIP(&NetServerIP, &bp->bp_siaddr);
-	memcpy (NetServerEther, ((Ethernet_t *)NetRxPacket)->et_src, 6);
+	memcpy(NetServerEther, ((Ethernet_t *)NetRxPacket)->et_src, 6);
 #endif
 	if (strlen(bp->bp_file) > 0)
-		copy_filename (BootFile, bp->bp_file, sizeof(BootFile));
+		copy_filename(BootFile, bp->bp_file, sizeof(BootFile));
 
 	debug("Bootfile: %s\n", BootFile);
 
@@ -124,97 +116,95 @@ static void BootpCopyNetParams(Bootp_t *bp)
 	 * don't delete exising entry when BOOTP / DHCP reply does
 	 * not contain a new value
 	 */
-	if (*BootFile) {
-		setenv ("bootfile", BootFile);
-	}
+	if (*BootFile)
+		setenv("bootfile", BootFile);
 }
 
-static int truncate_sz (const char *name, int maxlen, int curlen)
+static int truncate_sz(const char *name, int maxlen, int curlen)
 {
 	if (curlen >= maxlen) {
-		printf("*** WARNING: %s is too long (%d - max: %d) - truncated\n",
-			name, curlen, maxlen);
+		printf("*** WARNING: %s is too long (%d - max: %d)"
+			" - truncated\n", name, curlen, maxlen);
 		curlen = maxlen - 1;
 	}
-	return (curlen);
+	return curlen;
 }
 
 #if !defined(CONFIG_CMD_DHCP)
 
-static void BootpVendorFieldProcess (u8 * ext)
+static void BootpVendorFieldProcess(u8 *ext)
 {
 	int size = *(ext + 1);
 
 	debug("[BOOTP] Processing extension %d... (%d bytes)\n", *ext,
-		   *(ext + 1));
+		*(ext + 1));
 
 	NetBootFileSize = 0;
 
 	switch (*ext) {
 		/* Fixed length fields */
-	case 1:			/* Subnet mask					*/
+	case 1:			/* Subnet mask */
 		if (NetOurSubnetMask == 0)
-			NetCopyIP (&NetOurSubnetMask, (IPaddr_t *) (ext + 2));
+			NetCopyIP(&NetOurSubnetMask, (IPaddr_t *) (ext + 2));
 		break;
-	case 2:			/* Time offset - Not yet supported		*/
+	case 2:			/* Time offset - Not yet supported */
 		break;
 		/* Variable length fields */
-	case 3:			/* Gateways list				*/
-		if (NetOurGatewayIP == 0) {
-			NetCopyIP (&NetOurGatewayIP, (IPaddr_t *) (ext + 2));
-		}
+	case 3:			/* Gateways list */
+		if (NetOurGatewayIP == 0)
+			NetCopyIP(&NetOurGatewayIP, (IPaddr_t *) (ext + 2));
 		break;
-	case 4:			/* Time server - Not yet supported		*/
+	case 4:			/* Time server - Not yet supported */
 		break;
-	case 5:			/* IEN-116 name server - Not yet supported	*/
+	case 5:			/* IEN-116 name server - Not yet supported */
 		break;
 	case 6:
-		if (NetOurDNSIP == 0) {
-			NetCopyIP (&NetOurDNSIP, (IPaddr_t *) (ext + 2));
-		}
+		if (NetOurDNSIP == 0)
+			NetCopyIP(&NetOurDNSIP, (IPaddr_t *) (ext + 2));
 #if defined(CONFIG_BOOTP_DNS2)
-		if ((NetOurDNS2IP == 0) && (size > 4)) {
-			NetCopyIP (&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4));
-		}
+		if ((NetOurDNS2IP == 0) && (size > 4))
+			NetCopyIP(&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4));
 #endif
 		break;
-	case 7:			/* Log server - Not yet supported		*/
+	case 7:			/* Log server - Not yet supported */
 		break;
-	case 8:			/* Cookie/Quote server - Not yet supported	*/
+	case 8:			/* Cookie/Quote server - Not yet supported */
 		break;
-	case 9:			/* LPR server - Not yet supported		*/
+	case 9:			/* LPR server - Not yet supported */
 		break;
-	case 10:		/* Impress server - Not yet supported		*/
+	case 10:		/* Impress server - Not yet supported */
 		break;
-	case 11:		/* RPL server - Not yet supported		*/
+	case 11:		/* RPL server - Not yet supported */
 		break;
-	case 12:		/* Host name					*/
+	case 12:		/* Host name */
 		if (NetOurHostName[0] == 0) {
-			size = truncate_sz ("Host Name", sizeof (NetOurHostName), size);
-			memcpy (&NetOurHostName, ext + 2, size);
+			size = truncate_sz("Host Name",
+				sizeof(NetOurHostName), size);
+			memcpy(&NetOurHostName, ext + 2, size);
 			NetOurHostName[size] = 0;
 		}
 		break;
-	case 13:		/* Boot file size				*/
+	case 13:		/* Boot file size */
 		if (size == 2)
-			NetBootFileSize = ntohs (*(ushort *) (ext + 2));
+			NetBootFileSize = ntohs(*(ushort *) (ext + 2));
 		else if (size == 4)
-			NetBootFileSize = ntohl (*(ulong *) (ext + 2));
+			NetBootFileSize = ntohl(*(ulong *) (ext + 2));
 		break;
-	case 14:		/* Merit dump file - Not yet supported		*/
+	case 14:		/* Merit dump file - Not yet supported */
 		break;
-	case 15:		/* Domain name - Not yet supported		*/
+	case 15:		/* Domain name - Not yet supported */
 		break;
-	case 16:		/* Swap server - Not yet supported		*/
+	case 16:		/* Swap server - Not yet supported */
 		break;
-	case 17:		/* Root path					*/
+	case 17:		/* Root path */
 		if (NetOurRootPath[0] == 0) {
-			size = truncate_sz ("Root Path", sizeof (NetOurRootPath), size);
-			memcpy (&NetOurRootPath, ext + 2, size);
+			size = truncate_sz("Root Path",
+				sizeof(NetOurRootPath), size);
+			memcpy(&NetOurRootPath, ext + 2, size);
 			NetOurRootPath[size] = 0;
 		}
 		break;
-	case 18:		/* Extension path - Not yet supported		*/
+	case 18:		/* Extension path - Not yet supported */
 		/*
 		 * This can be used to send the information of the
 		 * vendor area in another file that the client can
@@ -222,10 +212,11 @@ static void BootpVendorFieldProcess (u8 * ext)
 		 */
 		break;
 		/* IP host layer fields */
-	case 40:		/* NIS Domain name				*/
+	case 40:		/* NIS Domain name */
 		if (NetOurNISDomain[0] == 0) {
-			size = truncate_sz ("NIS Domain Name", sizeof (NetOurNISDomain), size);
-			memcpy (&NetOurNISDomain, ext + 2, size);
+			size = truncate_sz("NIS Domain Name",
+				sizeof(NetOurNISDomain), size);
+			memcpy(&NetOurNISDomain, ext + 2, size);
 			NetOurNISDomain[size] = 0;
 		}
 		break;
@@ -235,7 +226,7 @@ static void BootpVendorFieldProcess (u8 * ext)
 		break;
 #endif
 		/* Application layer fields */
-	case 43:		/* Vendor specific info - Not yet supported	*/
+	case 43:		/* Vendor specific info - Not yet supported */
 		/*
 		 * Binary information to exchange specific
 		 * product information.
@@ -245,7 +236,7 @@ static void BootpVendorFieldProcess (u8 * ext)
 	}
 }
 
-static void BootpVendorProcess (u8 * ext, int size)
+static void BootpVendorProcess(u8 *ext, int size)
 {
 	u8 *end = ext + size;
 
@@ -259,11 +250,11 @@ static void BootpVendorProcess (u8 * ext, int size)
 
 			ext += ext[1] + 2;
 			if (ext <= end)
-				BootpVendorFieldProcess (opt);
+				BootpVendorFieldProcess(opt);
 		}
 	}
 
-	debug("[BOOTP] Received fields: \n");
+	debug("[BOOTP] Received fields:\n");
 	if (NetOurSubnetMask)
 		debug("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask);
 
@@ -298,27 +289,28 @@ static void
 BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 	     unsigned len)
 {
-	Bootp_t *bp;
+	struct Bootp_t *bp;
 
 	debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n",
-		src, dest, len, sizeof (Bootp_t));
+		src, dest, len, sizeof(struct Bootp_t));
 
-	bp = (Bootp_t *)pkt;
+	bp = (struct Bootp_t *)pkt;
 
-	if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
+	/* Filter out pkts we don't want */
+	if (BootpCheckPkt(pkt, dest, src, len))
 		return;
 
 	/*
 	 *	Got a good BOOTP reply.	 Copy the data into our variables.
 	 */
 #ifdef CONFIG_STATUS_LED
-	status_led_set (STATUS_LED_BOOT, STATUS_LED_OFF);
+	status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
 #endif
 
 	BootpCopyNetParams(bp);		/* Store net parameters from reply */
 
 	/* Retrieve extended information (we must parse the vendor area) */
-	if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
+	if (NetReadLong((ulong *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
 		BootpVendorProcess((uchar *)&bp->bp_vend[4], len);
 
 	NetSetTimeout(0, (thand_f *)0);
@@ -337,11 +329,11 @@ static void
 BootpTimeout(void)
 {
 	if (BootpTry >= TIMEOUT_COUNT) {
-		puts ("\nRetry count exceeded; starting again\n");
-		NetStartAgain ();
+		puts("\nRetry count exceeded; starting again\n");
+		NetStartAgain();
 	} else {
-		NetSetTimeout (TIMEOUT, BootpTimeout);
-		BootpRequest ();
+		NetSetTimeout(TIMEOUT, BootpTimeout);
+		BootpRequest();
 	}
 }
 
@@ -349,7 +341,8 @@ BootpTimeout(void)
  *	Initialize BOOTP extension fields in the request.
  */
 #if defined(CONFIG_CMD_DHCP)
-static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t RequestedIP)
+static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
+			IPaddr_t RequestedIP)
 {
 	u8 *start = e;
 	u8 *cnt;
@@ -381,7 +374,7 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
 	*e++ = (576 - 312 + OPT_SIZE) & 0xff;
 
 	if (ServerID) {
-		int tmp = ntohl (ServerID);
+		int tmp = ntohl(ServerID);
 
 		*e++ = 54;	/* ServerID */
 		*e++ = 4;
@@ -392,7 +385,7 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
 	}
 
 	if (RequestedIP) {
-		int tmp = ntohl (RequestedIP);
+		int tmp = ntohl(RequestedIP);
 
 		*e++ = 50;	/* Requested IP */
 		*e++ = 4;
@@ -402,12 +395,13 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
 		*e++ = tmp & 0xff;
 	}
 #if defined(CONFIG_BOOTP_SEND_HOSTNAME)
-	if ((hostname = getenv ("hostname"))) {
-		int hostnamelen = strlen (hostname);
+	hostname = getenv("hostname");
+	if (hostname) {
+		int hostnamelen = strlen(hostname);
 
 		*e++ = 12;	/* Hostname */
 		*e++ = hostnamelen;
-		memcpy (e, hostname, hostnamelen);
+		memcpy(e, hostname, hostnamelen);
 		e += hostnamelen;
 	}
 #endif
@@ -448,7 +442,8 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
 #endif
 
 #if defined(CONFIG_BOOTP_VENDOREX)
-	if ((x = dhcp_vendorex_prep (e)))
+	x = dhcp_vendorex_prep(e);
+	if (x)
 		return x - start;
 #endif
 
@@ -508,9 +503,9 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
 
 #else
 /*
- *	Warning: no field size check - change CONFIG_BOOTP_* at your own risk!
+ * Warning: no field size check - change CONFIG_BOOTP_* at your own risk!
  */
-static int BootpExtended (u8 * e)
+static int BootpExtended(u8 *e)
 {
 	u8 *start = e;
 
@@ -584,10 +579,10 @@ static int BootpExtended (u8 * e)
 #endif
 
 void
-BootpRequest (void)
+BootpRequest(void)
 {
 	uchar *pkt, *iphdr;
-	Bootp_t *bp;
+	struct Bootp_t *bp;
 	int ext_len, pktlen, iplen;
 
 	bootstage_mark_name(BOOTSTAGE_ID_BOOTP_START, "bootp_start");
@@ -600,22 +595,22 @@ BootpRequest (void)
 	int   reg;
 	ulong tst1, tst2, sum, m_mask, m_value = 0;
 
-	if (BootpTry ==0) {
+	if (BootpTry == 0) {
 		/* get our mac */
 		eth_getenv_enetaddr("ethaddr", bi_enetaddr);
 
 		debug("BootpRequest => Our Mac: ");
-		for (reg=0; reg<6; reg++)
-			debug("%x%c", bi_enetaddr[reg], reg==5 ? '\n' : ':');
+		for (reg = 0; reg < 6; reg++)
+			debug("%x%c", bi_enetaddr[reg], reg == 5 ? '\n' : ':');
 
 		/* Mac-Manipulation 2 get seed1 */
-		tst1=0;
-		tst2=0;
-		for (reg=2; reg<6; reg++) {
+		tst1 = 0;
+		tst2 = 0;
+		for (reg = 2; reg < 6; reg++) {
 			tst1 = tst1 << 8;
 			tst1 = tst1 | bi_enetaddr[reg];
 		}
-		for (reg=0; reg<2; reg++) {
+		for (reg = 0; reg < 2; reg++) {
 			tst2 = tst2 | bi_enetaddr[reg];
 			tst2 = tst2 << 8;
 		}
@@ -623,8 +618,8 @@ BootpRequest (void)
 		seed1 = tst1^tst2;
 
 		/* Mirror seed1*/
-		m_mask=0x1;
-		for (reg=1;reg<=32;reg++) {
+		m_mask = 0x1;
+		for (reg = 1; reg <= 32; reg++) {
 			m_value |= (m_mask & seed1);
 			seed1 = seed1 >> 1;
 			m_value = m_value << 1;
@@ -634,44 +629,45 @@ BootpRequest (void)
 	}
 
 	/* Random Number Generator */
-
-	for (reg=0;reg<=0;reg++) {
+	for (reg = 0; reg <= 0; reg++) {
 		sum = seed1 + seed2;
 		if (sum < seed1 || sum < seed2)
 			sum++;
 		seed2 = seed1;
 		seed1 = sum;
 
-		if (BootpTry<=2) {	/* Start with max 1024 * 1ms */
+		if (BootpTry <= 2) {	/* Start with max 1024 * 1ms */
 			sum = sum >> (22-BootpTry);
-		} else {		/*After 3rd BOOTP request max 8192 * 1ms */
+		} else {	/*After 3rd BOOTP request max 8192 * 1ms */
 			sum = sum >> 19;
 		}
 	}
 
-	printf ("Random delay: %ld ms...\n", sum);
-	for (reg=0; reg <sum; reg++) {
+	printf("Random delay: %ld ms...\n", sum);
+	for (reg = 0; reg < sum; reg++)
 		udelay(1000); /*Wait 1ms*/
-	}
+
 #endif	/* CONFIG_BOOTP_RANDOM_DELAY */
 
 	printf("BOOTP broadcast %d\n", ++BootpTry);
 	pkt = NetTxPacket;
-	memset ((void*)pkt, 0, PKTSIZE);
+	memset((void *)pkt, 0, PKTSIZE);
 
 	pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
 
 	/*
-	 * Next line results in incorrect packet size being transmitted, resulting
-	 * in errors in some DHCP servers, reporting missing bytes.  Size must be
-	 * set in packet header after extension length has been determined.
+	 * Next line results in incorrect packet size being transmitted,
+	 * resulting in errors in some DHCP servers, reporting missing bytes.
+	 * Size must be set in packet header after extension length has been
+	 * determined.
 	 * C. Hallinan, DS4.COM, Inc.
 	 */
-	/* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, sizeof (Bootp_t)); */
+	/* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC,
+		sizeof (struct Bootp_t)); */
 	iphdr = pkt;	/* We need this later for NetSetIP() */
 	pkt += IP_HDR_SIZE;
 
-	bp = (Bootp_t *)pkt;
+	bp = (struct Bootp_t *)pkt;
 	bp->bp_op = OP_BOOTREQUEST;
 	bp->bp_htype = HWT_ETHER;
 	bp->bp_hlen = HWL_ETHER;
@@ -681,8 +677,8 @@ BootpRequest (void)
 	NetWriteIP(&bp->bp_yiaddr, 0);
 	NetWriteIP(&bp->bp_siaddr, 0);
 	NetWriteIP(&bp->bp_giaddr, 0);
-	memcpy (bp->bp_chaddr, NetOurEther, 6);
-	copy_filename (bp->bp_file, BootFile, sizeof(bp->bp_file));
+	memcpy(bp->bp_chaddr, NetOurEther, 6);
+	copy_filename(bp->bp_file, BootFile, sizeof(bp->bp_file));
 
 	/* Request additional information from the BOOTP/DHCP server */
 #if defined(CONFIG_CMD_DHCP)
@@ -707,7 +703,8 @@ BootpRequest (void)
 	 * Calculate proper packet lengths taking into account the
 	 * variable size of the options field
 	 */
-	pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
+	pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
+		sizeof(bp->bp_vend) + ext_len;
 	iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
 	NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
 	NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);
@@ -722,7 +719,7 @@ BootpRequest (void)
 }
 
 #if defined(CONFIG_CMD_DHCP)
-static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
+static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
 {
 	uchar *end = popt + BOOTP_HDR_SIZE;
 	int oplen, size;
@@ -734,50 +731,51 @@ static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
 		oplen = *(popt + 1);
 		switch (*popt) {
 		case 1:
-			NetCopyIP (&NetOurSubnetMask, (popt + 2));
+			NetCopyIP(&NetOurSubnetMask, (popt + 2));
 			break;
 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
 		case 2:		/* Time offset	*/
 			to_ptr = &NetTimeOffset;
-			NetCopyLong ((ulong *)to_ptr, (ulong *)(popt + 2));
-			NetTimeOffset = ntohl (NetTimeOffset);
+			NetCopyLong((ulong *)to_ptr, (ulong *)(popt + 2));
+			NetTimeOffset = ntohl(NetTimeOffset);
 			break;
 #endif
 		case 3:
-			NetCopyIP (&NetOurGatewayIP, (popt + 2));
+			NetCopyIP(&NetOurGatewayIP, (popt + 2));
 			break;
 		case 6:
-			NetCopyIP (&NetOurDNSIP, (popt + 2));
+			NetCopyIP(&NetOurDNSIP, (popt + 2));
 #if defined(CONFIG_BOOTP_DNS2)
-			if (*(popt + 1) > 4) {
-				NetCopyIP (&NetOurDNS2IP, (popt + 2 + 4));
-			}
+			if (*(popt + 1) > 4)
+				NetCopyIP(&NetOurDNS2IP, (popt + 2 + 4));
 #endif
 			break;
 		case 12:
-			size = truncate_sz ("Host Name", sizeof (NetOurHostName), oplen);
-			memcpy (&NetOurHostName, popt + 2, size);
+			size = truncate_sz("Host Name",
+				sizeof(NetOurHostName), oplen);
+			memcpy(&NetOurHostName, popt + 2, size);
 			NetOurHostName[size] = 0;
 			break;
 		case 15:	/* Ignore Domain Name Option */
 			break;
 		case 17:
-			size = truncate_sz ("Root Path", sizeof (NetOurRootPath), oplen);
-			memcpy (&NetOurRootPath, popt + 2, size);
+			size = truncate_sz("Root Path",
+				sizeof(NetOurRootPath), oplen);
+			memcpy(&NetOurRootPath, popt + 2, size);
 			NetOurRootPath[size] = 0;
 			break;
 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
 		case 42:	/* NTP server IP */
-			NetCopyIP (&NetNtpServerIP, (popt + 2));
+			NetCopyIP(&NetNtpServerIP, (popt + 2));
 			break;
 #endif
 		case 51:
-			NetCopyLong (&dhcp_leasetime, (ulong *) (popt + 2));
+			NetCopyLong(&dhcp_leasetime, (ulong *) (popt + 2));
 			break;
 		case 53:	/* Ignore Message Type Option */
 			break;
 		case 54:
-			NetCopyIP (&NetDHCPServerIP, (popt + 2));
+			NetCopyIP(&NetDHCPServerIP, (popt + 2));
 			break;
 		case 58:	/* Ignore Renewal Time Option */
 			break;
@@ -792,7 +790,7 @@ static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
 			 * pass the bootp packet pointer into here as the
 			 * second arg
 			 */
-			size = truncate_sz ("Opt Boot File",
+			size = truncate_sz("Opt Boot File",
 					    sizeof(bp->bp_file),
 					    oplen);
 			if (bp->bp_file[0] == '\0' && size > 0) {
@@ -813,10 +811,11 @@ static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
 			break;
 		default:
 #if defined(CONFIG_BOOTP_VENDOREX)
-			if (dhcp_vendorex_proc (popt))
+			if (dhcp_vendorex_proc(popt))
 				break;
 #endif
-			printf ("*** Unhandled DHCP Option in OFFER/ACK: %d\n", *popt);
+			printf("*** Unhandled DHCP Option in OFFER/ACK:"
+				" %d\n", *popt);
 			break;
 		}
 		popt += oplen + 2;	/* Process next option */
@@ -825,42 +824,42 @@ static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
 
 static int DhcpMessageType(unsigned char *popt)
 {
-	if (NetReadLong((ulong*)popt) != htonl(BOOTP_VENDOR_MAGIC))
+	if (NetReadLong((ulong *)popt) != htonl(BOOTP_VENDOR_MAGIC))
 		return -1;
 
 	popt += 4;
-	while ( *popt != 0xff ) {
-		if ( *popt == 53 )	/* DHCP Message Type */
+	while (*popt != 0xff) {
+		if (*popt == 53)	/* DHCP Message Type */
 			return *(popt + 2);
 		popt += *(popt + 1) + 2;	/* Scan through all options */
 	}
 	return -1;
 }
 
-static void DhcpSendRequestPkt(Bootp_t *bp_offer)
+static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
 {
 	uchar *pkt, *iphdr;
-	Bootp_t *bp;
+	struct Bootp_t *bp;
 	int pktlen, iplen, extlen;
 	IPaddr_t OfferedIP;
 
 	debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
 	pkt = NetTxPacket;
-	memset ((void*)pkt, 0, PKTSIZE);
+	memset((void *)pkt, 0, PKTSIZE);
 
 	pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
 
-	iphdr = pkt;		/* We'll need this later to set proper pkt size */
+	iphdr = pkt;	/* We'll need this later to set proper pkt size */
 	pkt += IP_HDR_SIZE;
 
-	bp = (Bootp_t *)pkt;
+	bp = (struct Bootp_t *)pkt;
 	bp->bp_op = OP_BOOTREQUEST;
 	bp->bp_htype = HWT_ETHER;
 	bp->bp_hlen = HWL_ETHER;
 	bp->bp_hops = 0;
 	bp->bp_secs = htons(get_timer(0) / 1000);
-	/* Do not set the client IP, your IP, or server IP yet, since it hasn't been ACK'ed by
-	 * the server yet */
+	/* Do not set the client IP, your IP, or server IP yet, since it
+	 * hasn't been ACK'ed by the server yet */
 
 	/*
 	 * RFC3046 requires Relay Agents to discard packets with
@@ -868,7 +867,7 @@ static void DhcpSendRequestPkt(Bootp_t *bp_offer)
 	 */
 	NetWriteIP(&bp->bp_giaddr, 0);
 
-	memcpy (bp->bp_chaddr, NetOurEther, 6);
+	memcpy(bp->bp_chaddr, NetOurEther, 6);
 
 	/*
 	 * ID is the id of the OFFER packet
@@ -882,9 +881,11 @@ static void DhcpSendRequestPkt(Bootp_t *bp_offer)
 
 	/* Copy offered IP into the parameters request list */
 	NetCopyIP(&OfferedIP, &bp_offer->bp_yiaddr);
-	extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST, NetDHCPServerIP, OfferedIP);
+	extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST,
+		NetDHCPServerIP, OfferedIP);
 
-	pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
+	pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
+		sizeof(bp->bp_vend) + extlen;
 	iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
 	NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
 
@@ -902,36 +903,38 @@ static void
 DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 	    unsigned len)
 {
-	Bootp_t *bp = (Bootp_t *)pkt;
+	struct Bootp_t *bp = (struct Bootp_t *)pkt;
 
 	debug("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n",
 		src, dest, len, dhcp_state);
 
-	if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
+	/* Filter out pkts we don't want */
+	if (BootpCheckPkt(pkt, dest, src, len))
 		return;
 
-	debug("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n",
-		src, dest, len, dhcp_state);
+	debug("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state:"
+		" %d\n", src, dest, len, dhcp_state);
 
 	switch (dhcp_state) {
 	case SELECTING:
 		/*
 		 * Wait an appropriate time for any potential DHCPOFFER packets
-		 * to arrive.  Then select one, and generate DHCPREQUEST response.
-		 * If filename is in format we recognize, assume it is a valid
-		 * OFFER from a server we want.
+		 * to arrive.  Then select one, and generate DHCPREQUEST
+		 * response.  If filename is in format we recognize, assume it
+		 * is a valid OFFER from a server we want.
 		 */
 		debug("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file);
 #ifdef CONFIG_SYS_BOOTFILE_PREFIX
 		if (strncmp(bp->bp_file,
 			    CONFIG_SYS_BOOTFILE_PREFIX,
-			    strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0 ) {
+			    strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0) {
 #endif	/* CONFIG_SYS_BOOTFILE_PREFIX */
 
 			debug("TRANSITIONING TO REQUESTING STATE\n");
 			dhcp_state = REQUESTING;
 
-			if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
+			if (NetReadLong((ulong *)&bp->bp_vend[0]) ==
+						htonl(BOOTP_VENDOR_MAGIC))
 				DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
 
 			NetSetTimeout(TIMEOUT, BootpTimeout);
@@ -945,14 +948,17 @@ DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 	case REQUESTING:
 		debug("DHCP State: REQUESTING\n");
 
-		if ( DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK ) {
-			if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
+		if (DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK) {
+			if (NetReadLong((ulong *)&bp->bp_vend[0]) ==
+						htonl(BOOTP_VENDOR_MAGIC))
 				DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
-			BootpCopyNetParams(bp); /* Store net params from reply */
+			/* Store net params from reply */
+			BootpCopyNetParams(bp);
 			dhcp_state = BOUND;
-			printf ("DHCP client bound to address %pI4\n", &NetOurIP);
+			printf("DHCP client bound to address %pI4\n",
+				&NetOurIP);
 			bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP,
-					    "bootp_stop");
+				"bootp_stop");
 
 			net_auto_load();
 			return;
@@ -962,7 +968,7 @@ DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 		/* DHCP client bound to address */
 		break;
 	default:
-		puts ("DHCP: INVALID STATE\n");
+		puts("DHCP: INVALID STATE\n");
 		break;
 	}
 
net/bootp.h +30 -26

88 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#108 lore raw

PATCH v3 4/10 net: cosmetic: eth.c checkpatch compliance

In reply to Joe Hershberger

---
Changes for v2:
- Split into smaller patches
Changes for v3:

 net/eth.c |   67 +++++++++++++++++++++++++++++-------------------------------
 1 files changed, 32 insertions(+), 35 deletions(-)
net/eth.c +32 -35
index 66a84d4..35e0de6 100644
@@ -87,7 +87,7 @@ static struct {
 	int length;
 } eth_rcv_bufs[PKTBUFSRX];
 
-static unsigned int eth_rcv_current = 0, eth_rcv_last = 0;
+static unsigned int eth_rcv_current, eth_rcv_last;
 #endif
 
 static struct eth_device *eth_devices, *eth_current;
@@ -139,11 +139,10 @@ struct eth_device *eth_get_dev_by_index(int index)
 	return target_dev;
 }
 
-int eth_get_dev_index (void)
+int eth_get_dev_index(void)
 {
-	if (!eth_current) {
+	if (!eth_current)
 		return -1;
-	}
 
 	return eth_current->index;
 }
@@ -174,7 +173,7 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
 
 	if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) {
 		if (memcmp(dev->enetaddr, "\0\0\0\0\0\0", 6) &&
-			memcmp(dev->enetaddr, env_enetaddr, 6)) {
+				memcmp(dev->enetaddr, env_enetaddr, 6)) {
 			printf("\nWarning: %s MAC addresses don't match:\n",
 				dev->name);
 			printf("Address in SROM is         %pM\n",
@@ -187,10 +186,9 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
 	}
 
 	if (dev->write_hwaddr &&
-		!eth_mac_skip(eth_number) &&
-		is_valid_ether_addr(dev->enetaddr)) {
+			!eth_mac_skip(eth_number) &&
+			is_valid_ether_addr(dev->enetaddr))
 		ret = dev->write_hwaddr(dev);
-	}
 
 	return ret;
 }
@@ -198,7 +196,7 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
 int eth_register(struct eth_device *dev)
 {
 	struct eth_device *d;
-	static int index = 0;
+	static int index;
 
 	assert(strlen(dev->name) < sizeof(dev->name));
 
@@ -206,7 +204,7 @@ int eth_register(struct eth_device *dev)
 		eth_current = eth_devices = dev;
 		eth_current_changed();
 	} else {
-		for (d=eth_devices; d->next!=eth_devices; d=d->next)
+		for (d = eth_devices; d->next != eth_devices; d = d->next)
 			;
 		d->next = dev;
 	}
@@ -276,36 +274,37 @@ int eth_initialize(bd_t *bis)
 		printf("Net Initialization Skipped\n");
 
 	if (!eth_devices) {
-		puts ("No ethernet found.\n");
+		puts("No ethernet found.\n");
 		bootstage_error(BOOTSTAGE_ID_NET_ETH_START);
 	} else {
 		struct eth_device *dev = eth_devices;
-		char *ethprime = getenv ("ethprime");
+		char *ethprime = getenv("ethprime");
 
 		bootstage_mark(BOOTSTAGE_ID_NET_ETH_INIT);
 		do {
 			if (dev->index)
-				puts (", ");
+				puts(", ");
 
 			printf("%s", dev->name);
 
-			if (ethprime && strcmp (dev->name, ethprime) == 0) {
+			if (ethprime && strcmp(dev->name, ethprime) == 0) {
 				eth_current = dev;
-				puts (" [PRIME]");
+				puts(" [PRIME]");
 			}
 
 			if (strchr(dev->name, ' '))
-				puts("\nWarning: eth device name has a space!\n");
+				puts("\nWarning: eth device name has a space!"
+					"\n");
 
 			if (eth_write_hwaddr(dev, "eth", dev->index))
 				puts("\nWarning: failed to set MAC address\n");
 
 			dev = dev->next;
 			num_devices++;
-		} while(dev != eth_devices);
+		} while (dev != eth_devices);
 
 		eth_current_changed();
-		putc ('\n');
+		putc('\n');
 	}
 
 	return num_devices;
@@ -316,9 +315,9 @@ int eth_initialize(bd_t *bis)
  * mcast_addr: multicast ipaddr from which multicast Mac is made
  * join: 1=join, 0=leave.
  */
-int eth_mcast_join( IPaddr_t mcast_ip, u8 join)
+int eth_mcast_join(IPaddr_t mcast_ip, u8 join)
 {
- u8 mcast_mac[6];
+	u8 mcast_mac[6];
 	if (!eth_current || !eth_current->mcast)
 		return -1;
 	mcast_mac[5] = htonl(mcast_ip) & 0xff;
@@ -335,7 +334,7 @@ int eth_mcast_join( IPaddr_t mcast_ip, u8 join)
  * some other adapter -- hash tables
  */
 #define CRCPOLY_LE 0xedb88320
-u32 ether_crc (size_t len, unsigned char const *p)
+u32 ether_crc(size_t len, unsigned char const *p)
 {
 	int i;
 	u32 crc;
@@ -362,7 +361,7 @@ int eth_init(bd_t *bis)
 	struct eth_device *old_current, *dev;
 
 	if (!eth_current) {
-		puts ("No ethernet found.\n");
+		puts("No ethernet found.\n");
 		return -1;
 	}
 
@@ -382,7 +381,7 @@ int eth_init(bd_t *bis)
 	do {
 		debug("Trying %s\n", eth_current->name);
 
-		if (eth_current->init(eth_current,bis) >= 0) {
+		if (eth_current->init(eth_current, bis) >= 0) {
 			eth_current->state = ETH_STATE_ACTIVE;
 
 			return 0;
@@ -470,38 +469,36 @@ int eth_receive(void *packet, int length)
 
 void eth_try_another(int first_restart)
 {
-	static struct eth_device *first_failed = NULL;
+	static struct eth_device *first_failed;
 	char *ethrotate;
 
 	/*
 	 * Do not rotate between network interfaces when
 	 * 'ethrotate' variable is set to 'no'.
 	 */
-	if (((ethrotate = getenv ("ethrotate")) != NULL) &&
-	    (strcmp(ethrotate, "no") == 0))
+	ethrotate = getenv("ethrotate");
+	if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
 		return;
 
 	if (!eth_current)
 		return;
 
-	if (first_restart) {
+	if (first_restart)
 		first_failed = eth_current;
-	}
 
 	eth_current = eth_current->next;
 
 	eth_current_changed();
 
-	if (first_failed == eth_current) {
+	if (first_failed == eth_current)
 		NetRestartWrap = 1;
-	}
 }
 
 void eth_set_current(void)
 {
-	static char *act = NULL;
-	static int  env_changed_id = 0;
-	struct eth_device* old_current;
+	static char *act;
+	static int  env_changed_id;
+	struct eth_device *old_current;
 	int	env_id;
 
 	if (!eth_current)	/* XXX no current */
@@ -524,7 +521,7 @@ void eth_set_current(void)
 	eth_current_changed();
 }
 
-char *eth_get_name (void)
+char *eth_get_name(void)
 {
-	return (eth_current ? eth_current->name : "unknown");
+	return eth_current ? eth_current->name : "unknown";
 }
Signature · 1 line
1.6.0.2
#109 lore raw

PATCH v3 5/10 net: cosmetic: net.c checkpatch compliance

In reply to Joe Hershberger

---
Changes for v2:
- Split into smaller patches
Changes for v3:

 common/main.c    |    1 -
 include/common.h |    4 ++++
 include/net.h    |    5 +++++
 net/net.c        |   22 ++++++++--------------
 4 files changed, 17 insertions(+), 15 deletions(-)
common/main.c +0 -1
index 3b9e39a..a933357 100644
@@ -973,7 +973,6 @@ int readline_into_buffer(const char *const prompt, char *buffer, int timeout)
 
 #ifdef CONFIG_SHOW_ACTIVITY
 		while (!tstc()) {
-			extern void show_activity(int arg);
 			show_activity(0);
 			WATCHDOG_RESET();
 		}
include/common.h +4 -0
index 4b5841e..7338e39 100644
@@ -794,6 +794,10 @@ int	pcmcia_init (void);
 
 #include <bootstage.h>
 
+#ifdef CONFIG_SHOW_ACTIVITY
+void show_activity(int arg);
+#endif
+
 /* Multicore arch functions */
 #ifdef CONFIG_MP
 int cpu_status(int nr);
include/net.h +5 -0
index 2b6e59a..3dbe154 100644
@@ -433,6 +433,11 @@ extern int	NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport,
 /* Processes a received packet */
 extern void NetReceive(uchar *, int);
 
+#ifdef CONFIG_NETCONSOLE
+void NcStart(void);
+int nc_input_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len);
+#endif
+
 /*
  * Check if autoload is enabled. If so, use either NFS or TFTP to download
  * the boot file.
net/net.c +8 -14
index 9a0417d..1435245 100644
@@ -77,6 +77,7 @@
 #include <common.h>
 #include <watchdog.h>
 #include <command.h>
+#include <linux/compiler.h>
 #include <net.h>
 #include "bootp.h"
 #include "tftp.h"
@@ -203,11 +204,6 @@ IPaddr_t	NetNtpServerIP;
 int		NetTimeOffset;
 #endif
 
-#ifdef CONFIG_NETCONSOLE
-void NcStart(void);
-int nc_input_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len);
-#endif
-
 uchar PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
 
 /* Receive packet */
@@ -527,10 +523,7 @@ restart:
 	for (;;) {
 		WATCHDOG_RESET();
 #ifdef CONFIG_SHOW_ACTIVITY
-		{
-			extern void show_activity(int arg);
-			show_activity(1);
-		}
+		show_activity(1);
 #endif
 		/*
 		 *	Check the ethernet for a new packet.  The ethernet
@@ -1103,8 +1096,8 @@ CDPHandler(const uchar *pkt, unsigned len)
 	 * output a warning
 	 */
 	if (pkt[0] != 0x02)
-		printf("** WARNING: CDP packet received with a protocol version %d > 2\n",
-				pkt[0] & 0xff);
+		printf("**WARNING: CDP packet received with a protocol version "
+				"%d > 2\n", pkt[0] & 0xff);
 
 	if (CDP_compute_csum(pkt, len) != 0)
 		return;
@@ -1239,7 +1232,7 @@ struct hole {
 
 static IP_t *__NetDefragment(IP_t *ip, int *lenp)
 {
-	static uchar pkt_buff[IP_PKTSIZE] __attribute__((aligned(PKTALIGN)));
+	static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
 	static u16 first_hole, total_len;
 	struct hole *payload, *thisfrag, *h, *newh;
 	IP_t *localip = (IP_t *)pkt_buff;
@@ -1611,6 +1604,7 @@ NetReceive(uchar *inpkt, int len)
 			/* matched waiting packet's address */
 			if (tmp == NetArpWaitReplyIP) {
 				debug("Got it\n");
+
 				/* save address for later use */
 				memcpy(NetArpWaitPacketMAC,
 				       &arp->ar_data[0], 6);
@@ -1619,7 +1613,8 @@ NetReceive(uchar *inpkt, int len)
 				(*packetHandler)(0, 0, 0, 0, 0);
 #endif
 				/* modify header, and transmit it */
-				memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, NetArpWaitPacketMAC, 6);
+				memcpy(((Ethernet_t *)NetArpWaitTxPacket)->
+					et_dest, NetArpWaitPacketMAC, 6);
 				(void) eth_send(NetArpWaitTxPacket,
 						NetArpWaitTxPacketSize);
 
@@ -1856,7 +1851,6 @@ common:
 	case CDP:
 	case DHCP:
 		if (memcmp(NetOurEther, "\0\0\0\0\0\0", 6) == 0) {
-			extern int eth_get_dev_index(void);
 			int num = eth_get_dev_index();
 
 			switch (num) {
Signature · 1 line
1.6.0.2
#110 lore raw

PATCH v3 6/10 net: cosmetic: nfs.* checkpatch compliance

In reply to Joe Hershberger

---
Changes for v2:
- Split into smaller patches
Changes for v3:

 net/nfs.c |  300 ++++++++++++++++++++++++++++++-------------------------------
 net/nfs.h |    2 +-
 2 files changed, 150 insertions(+), 152 deletions(-)
net/nfs.c +149 -151
index b5b482c..54f56c4 100644
@@ -33,8 +33,8 @@
 #define NFS_RETRY_COUNT 30
 #define NFS_TIMEOUT 2000UL
 
-static int fs_mounted = 0;
-static unsigned long rpc_id = 0;
+static int fs_mounted;
+static unsigned long rpc_id;
 static int nfs_offset = -1;
 static int nfs_len;
 
@@ -61,14 +61,14 @@ static char *nfs_filename;
 static char *nfs_path;
 static char nfs_path_buff[2048];
 
-static __inline__ int
-store_block (uchar * src, unsigned offset, unsigned len)
+static inline int
+store_block(uchar *src, unsigned offset, unsigned len)
 {
 	ulong newsize = offset + len;
 #ifdef CONFIG_SYS_DIRECT_FLASH_NFS
 	int i, rc = 0;
 
-	for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; i++) {
+	for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) {
 		/* start address in flash? */
 		if (load_addr + offset >= flash_info[i].start[0]) {
 			rc = 1;
@@ -77,15 +77,15 @@ store_block (uchar * src, unsigned offset, unsigned len)
 	}
 
 	if (rc) { /* Flash is destination for this packet */
-		rc = flash_write ((uchar *)src, (ulong)(load_addr+offset), len);
+		rc = flash_write((uchar *)src, (ulong)(load_addr+offset), len);
 		if (rc) {
-			flash_perror (rc);
+			flash_perror(rc);
 			return -1;
 		}
 	} else
 #endif /* CONFIG_SYS_DIRECT_FLASH_NFS */
 	{
-		(void)memcpy ((void *)(load_addr + offset), src, len);
+		(void)memcpy((void *)(load_addr + offset), src, len);
 	}
 
 	if (NetBootFileXferSize < (offset+len))
@@ -94,7 +94,7 @@ store_block (uchar * src, unsigned offset, unsigned len)
 }
 
 static char*
-basename (char *path)
+basename(char *path)
 {
 	char *fname;
 
@@ -110,11 +110,11 @@ basename (char *path)
 }
 
 static char*
-dirname (char *path)
+dirname(char *path)
 {
 	char *fname;
 
-	fname = basename (path);
+	fname = basename(path);
 	--fname;
 	*fname = '\0';
 	return path;
@@ -123,14 +123,14 @@ dirname (char *path)
 /**************************************************************************
 RPC_ADD_CREDENTIALS - Add RPC authentication/verifier entries
 **************************************************************************/
-static long *rpc_add_credentials (long *p)
+static long *rpc_add_credentials(long *p)
 {
 	int hl;
 	int hostnamelen;
 	char hostname[256];
 
-	strcpy (hostname, "");
-	hostnamelen=strlen (hostname);
+	strcpy(hostname, "");
+	hostnamelen = strlen(hostname);
 
 	/* Here's the executive summary on authentication requirements of the
 	 * various NFS server implementations:	Linux accepts both AUTH_NONE
@@ -148,10 +148,9 @@ static long *rpc_add_credentials (long *p)
 	*p++ = htonl(hl+20);		/* auth length */
 	*p++ = htonl(0);		/* stamp */
 	*p++ = htonl(hostnamelen);	/* hostname string */
-	if (hostnamelen & 3) {
+	if (hostnamelen & 3)
 		*(p + hostnamelen / 4) = 0; /* add zero padding */
-	}
-	memcpy (p, hostname, hostnamelen);
+	memcpy(p, hostname, hostnamelen);
 	p += hl / 4;
 	*p++ = 0;			/* uid */
 	*p++ = 0;			/* gid */
@@ -168,7 +167,7 @@ static long *rpc_add_credentials (long *p)
 RPC_LOOKUP - Lookup RPC Port numbers
 **************************************************************************/
 static void
-rpc_req (int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
+rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
 {
 	struct rpc_t pkt;
 	unsigned long id;
@@ -186,11 +185,12 @@ rpc_req (int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
 	p = (uint32_t *)&(pkt.u.call.data);
 
 	if (datalen)
-		memcpy ((char *)p, (char *)data, datalen*sizeof(uint32_t));
+		memcpy((char *)p, (char *)data, datalen*sizeof(uint32_t));
 
 	pktlen = (char *)p + datalen*sizeof(uint32_t) - (char *)&pkt;
 
-	memcpy ((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE, (char *)&pkt, pktlen);
+	memcpy((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE,
+		(char *)&pkt, pktlen);
 
 	if (rpc_prog == PROG_PORTMAP)
 		sport = SUNRPC_PORT;
@@ -199,14 +199,15 @@ rpc_req (int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
 	else
 		sport = NfsSrvNfsPort;
 
-	NetSendUDPPacket (NetServerEther, NfsServerIP, sport, NfsOurPort, pktlen);
+	NetSendUDPPacket(NetServerEther, NfsServerIP, sport, NfsOurPort,
+		pktlen);
 }
 
 /**************************************************************************
 RPC_LOOKUP - Lookup RPC Port numbers
 **************************************************************************/
 static void
-rpc_lookup_req (int prog, int ver)
+rpc_lookup_req(int prog, int ver)
 {
 	uint32_t data[16];
 
@@ -217,56 +218,56 @@ rpc_lookup_req (int prog, int ver)
 	data[6] = htonl(17);	/* IP_UDP */
 	data[7] = 0;
 
-	rpc_req (PROG_PORTMAP, PORTMAP_GETPORT, data, 8);
+	rpc_req(PROG_PORTMAP, PORTMAP_GETPORT, data, 8);
 }
 
 /**************************************************************************
 NFS_MOUNT - Mount an NFS Filesystem
 **************************************************************************/
 static void
-nfs_mount_req (char *path)
+nfs_mount_req(char *path)
 {
 	uint32_t data[1024];
 	uint32_t *p;
 	int len;
 	int pathlen;
 
-	pathlen = strlen (path);
+	pathlen = strlen(path);
 
 	p = &(data[0]);
 	p = (uint32_t *)rpc_add_credentials((long *)p);
 
 	*p++ = htonl(pathlen);
-	if (pathlen & 3) *(p + pathlen / 4) = 0;
-	memcpy (p, path, pathlen);
+	if (pathlen & 3)
+		*(p + pathlen / 4) = 0;
+	memcpy(p, path, pathlen);
 	p += (pathlen + 3) / 4;
 
 	len = (uint32_t *)p - (uint32_t *)&(data[0]);
 
-	rpc_req (PROG_MOUNT, MOUNT_ADDENTRY, data, len);
+	rpc_req(PROG_MOUNT, MOUNT_ADDENTRY, data, len);
 }
 
 /**************************************************************************
 NFS_UMOUNTALL - Unmount all our NFS Filesystems on the Server
 **************************************************************************/
 static void
-nfs_umountall_req (void)
+nfs_umountall_req(void)
 {
 	uint32_t data[1024];
 	uint32_t *p;
 	int len;
 
-	if ((NfsSrvMountPort == -1) || (!fs_mounted)) {
+	if ((NfsSrvMountPort == -1) || (!fs_mounted))
 		/* Nothing mounted, nothing to umount */
 		return;
-	}
 
 	p = &(data[0]);
-	p = (uint32_t *)rpc_add_credentials ((long *)p);
+	p = (uint32_t *)rpc_add_credentials((long *)p);
 
 	len = (uint32_t *)p - (uint32_t *)&(data[0]);
 
-	rpc_req (PROG_MOUNT, MOUNT_UMOUNTALL, data, len);
+	rpc_req(PROG_MOUNT, MOUNT_UMOUNTALL, data, len);
 }
 
 /***************************************************************************
@@ -277,65 +278,66 @@ nfs_umountall_req (void)
  * so that inside the nfs() function a recursion can be done.
  **************************************************************************/
 static void
-nfs_readlink_req (void)
+nfs_readlink_req(void)
 {
 	uint32_t data[1024];
 	uint32_t *p;
 	int len;
 
 	p = &(data[0]);
-	p = (uint32_t *)rpc_add_credentials ((long *)p);
+	p = (uint32_t *)rpc_add_credentials((long *)p);
 
-	memcpy (p, filefh, NFS_FHSIZE);
+	memcpy(p, filefh, NFS_FHSIZE);
 	p += (NFS_FHSIZE / 4);
 
 	len = (uint32_t *)p - (uint32_t *)&(data[0]);
 
-	rpc_req (PROG_NFS, NFS_READLINK, data, len);
+	rpc_req(PROG_NFS, NFS_READLINK, data, len);
 }
 
 /**************************************************************************
 NFS_LOOKUP - Lookup Pathname
 **************************************************************************/
 static void
-nfs_lookup_req (char *fname)
+nfs_lookup_req(char *fname)
 {
 	uint32_t data[1024];
 	uint32_t *p;
 	int len;
 	int fnamelen;
 
-	fnamelen = strlen (fname);
+	fnamelen = strlen(fname);
 
 	p = &(data[0]);
-	p = (uint32_t *)rpc_add_credentials ((long *)p);
+	p = (uint32_t *)rpc_add_credentials((long *)p);
 
-	memcpy (p, dirfh, NFS_FHSIZE);
+	memcpy(p, dirfh, NFS_FHSIZE);
 	p += (NFS_FHSIZE / 4);
 	*p++ = htonl(fnamelen);
-	if (fnamelen & 3) *(p + fnamelen / 4) = 0;
-	memcpy (p, fname, fnamelen);
+	if (fnamelen & 3)
+		*(p + fnamelen / 4) = 0;
+	memcpy(p, fname, fnamelen);
 	p += (fnamelen + 3) / 4;
 
 	len = (uint32_t *)p - (uint32_t *)&(data[0]);
 
-	rpc_req (PROG_NFS, NFS_LOOKUP, data, len);
+	rpc_req(PROG_NFS, NFS_LOOKUP, data, len);
 }
 
 /**************************************************************************
 NFS_READ - Read File on NFS Server
 **************************************************************************/
 static void
-nfs_read_req (int offset, int readlen)
+nfs_read_req(int offset, int readlen)
 {
 	uint32_t data[1024];
 	uint32_t *p;
 	int len;
 
 	p = &(data[0]);
-	p = (uint32_t *)rpc_add_credentials ((long *)p);
+	p = (uint32_t *)rpc_add_credentials((long *)p);
 
-	memcpy (p, filefh, NFS_FHSIZE);
+	memcpy(p, filefh, NFS_FHSIZE);
 	p += (NFS_FHSIZE / 4);
 	*p++ = htonl(offset);
 	*p++ = htonl(readlen);
@@ -343,7 +345,7 @@ nfs_read_req (int offset, int readlen)
 
 	len = (uint32_t *)p - (uint32_t *)&(data[0]);
 
-	rpc_req (PROG_NFS, NFS_READ, data, len);
+	rpc_req(PROG_NFS, NFS_READ, data, len);
 }
 
 /**************************************************************************
@@ -351,31 +353,31 @@ RPC request dispatcher
 **************************************************************************/
 
 static void
-NfsSend (void)
+NfsSend(void)
 {
 	debug("%s\n", __func__);
 
 	switch (NfsState) {
 	case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
-		rpc_lookup_req (PROG_MOUNT, 1);
+		rpc_lookup_req(PROG_MOUNT, 1);
 		break;
 	case STATE_PRCLOOKUP_PROG_NFS_REQ:
-		rpc_lookup_req (PROG_NFS, 2);
+		rpc_lookup_req(PROG_NFS, 2);
 		break;
 	case STATE_MOUNT_REQ:
-		nfs_mount_req (nfs_path);
+		nfs_mount_req(nfs_path);
 		break;
 	case STATE_UMOUNT_REQ:
-		nfs_umountall_req ();
+		nfs_umountall_req();
 		break;
 	case STATE_LOOKUP_REQ:
-		nfs_lookup_req (nfs_filename);
+		nfs_lookup_req(nfs_filename);
 		break;
 	case STATE_READ_REQ:
-		nfs_read_req (nfs_offset, nfs_len);
+		nfs_read_req(nfs_offset, nfs_len);
 		break;
 	case STATE_READLINK_REQ:
-		nfs_readlink_req ();
+		nfs_readlink_req();
 		break;
 	}
 }
@@ -385,11 +387,11 @@ Handlers for the reply from server
 **************************************************************************/
 
 static int
-rpc_lookup_reply (int prog, uchar *pkt, unsigned len)
+rpc_lookup_reply(int prog, uchar *pkt, unsigned len)
 {
 	struct rpc_t rpc_pkt;
 
-	memcpy ((unsigned char *)&rpc_pkt, pkt, len);
+	memcpy((unsigned char *)&rpc_pkt, pkt, len);
 
 	debug("%s\n", __func__);
 
@@ -398,9 +400,8 @@ rpc_lookup_reply (int prog, uchar *pkt, unsigned len)
 
 	if (rpc_pkt.u.reply.rstatus  ||
 	    rpc_pkt.u.reply.verifier ||
-	    rpc_pkt.u.reply.astatus) {
+	    rpc_pkt.u.reply.astatus)
 		return -1;
-	}
 
 	switch (prog) {
 	case PROG_MOUNT:
@@ -415,13 +416,13 @@ rpc_lookup_reply (int prog, uchar *pkt, unsigned len)
 }
 
 static int
-nfs_mount_reply (uchar *pkt, unsigned len)
+nfs_mount_reply(uchar *pkt, unsigned len)
 {
 	struct rpc_t rpc_pkt;
 
 	debug("%s\n", __func__);
 
-	memcpy ((unsigned char *)&rpc_pkt, pkt, len);
+	memcpy((unsigned char *)&rpc_pkt, pkt, len);
 
 	if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
 		return -1;
@@ -429,48 +430,46 @@ nfs_mount_reply (uchar *pkt, unsigned len)
 	if (rpc_pkt.u.reply.rstatus  ||
 	    rpc_pkt.u.reply.verifier ||
 	    rpc_pkt.u.reply.astatus  ||
-	    rpc_pkt.u.reply.data[0]) {
+	    rpc_pkt.u.reply.data[0])
 		return -1;
-	}
 
 	fs_mounted = 1;
-	memcpy (dirfh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE);
+	memcpy(dirfh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE);
 
 	return 0;
 }
 
 static int
-nfs_umountall_reply (uchar *pkt, unsigned len)
+nfs_umountall_reply(uchar *pkt, unsigned len)
 {
 	struct rpc_t rpc_pkt;
 
 	debug("%s\n", __func__);
 
-	memcpy ((unsigned char *)&rpc_pkt, pkt, len);
+	memcpy((unsigned char *)&rpc_pkt, pkt, len);
 
 	if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
 		return -1;
 
 	if (rpc_pkt.u.reply.rstatus  ||
 	    rpc_pkt.u.reply.verifier ||
-	    rpc_pkt.u.reply.astatus) {
+	    rpc_pkt.u.reply.astatus)
 		return -1;
-	}
 
 	fs_mounted = 0;
-	memset (dirfh, 0, sizeof(dirfh));
+	memset(dirfh, 0, sizeof(dirfh));
 
 	return 0;
 }
 
 static int
-nfs_lookup_reply (uchar *pkt, unsigned len)
+nfs_lookup_reply(uchar *pkt, unsigned len)
 {
 	struct rpc_t rpc_pkt;
 
 	debug("%s\n", __func__);
 
-	memcpy ((unsigned char *)&rpc_pkt, pkt, len);
+	memcpy((unsigned char *)&rpc_pkt, pkt, len);
 
 	if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
 		return -1;
@@ -478,24 +477,23 @@ nfs_lookup_reply (uchar *pkt, unsigned len)
 	if (rpc_pkt.u.reply.rstatus  ||
 	    rpc_pkt.u.reply.verifier ||
 	    rpc_pkt.u.reply.astatus  ||
-	    rpc_pkt.u.reply.data[0]) {
+	    rpc_pkt.u.reply.data[0])
 		return -1;
-	}
 
-	memcpy (filefh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE);
+	memcpy(filefh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE);
 
 	return 0;
 }
 
 static int
-nfs_readlink_reply (uchar *pkt, unsigned len)
+nfs_readlink_reply(uchar *pkt, unsigned len)
 {
 	struct rpc_t rpc_pkt;
 	int rlen;
 
 	debug("%s\n", __func__);
 
-	memcpy ((unsigned char *)&rpc_pkt, pkt, len);
+	memcpy((unsigned char *)&rpc_pkt, pkt, len);
 
 	if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
 		return -1;
@@ -503,34 +501,34 @@ nfs_readlink_reply (uchar *pkt, unsigned len)
 	if (rpc_pkt.u.reply.rstatus  ||
 	    rpc_pkt.u.reply.verifier ||
 	    rpc_pkt.u.reply.astatus  ||
-	    rpc_pkt.u.reply.data[0]) {
+	    rpc_pkt.u.reply.data[0])
 		return -1;
-	}
 
-	rlen = ntohl (rpc_pkt.u.reply.data[1]); /* new path length */
+	rlen = ntohl(rpc_pkt.u.reply.data[1]); /* new path length */
 
 	if (*((char *)&(rpc_pkt.u.reply.data[2])) != '/') {
 		int pathlen;
-		strcat (nfs_path, "/");
+		strcat(nfs_path, "/");
 		pathlen = strlen(nfs_path);
-		memcpy (nfs_path+pathlen, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen);
+		memcpy(nfs_path + pathlen, (uchar *)&(rpc_pkt.u.reply.data[2]),
+			rlen);
 		nfs_path[pathlen + rlen] = 0;
 	} else {
-		memcpy (nfs_path, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen);
+		memcpy(nfs_path, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen);
 		nfs_path[rlen] = 0;
 	}
 	return 0;
 }
 
 static int
-nfs_read_reply (uchar *pkt, unsigned len)
+nfs_read_reply(uchar *pkt, unsigned len)
 {
 	struct rpc_t rpc_pkt;
 	int rlen;
 
 	debug("%s\n", __func__);
 
-	memcpy ((uchar *)&rpc_pkt, pkt, sizeof(rpc_pkt.u.reply));
+	memcpy((uchar *)&rpc_pkt, pkt, sizeof(rpc_pkt.u.reply));
 
 	if (ntohl(rpc_pkt.u.reply.id) != rpc_id)
 		return -1;
@@ -539,24 +537,22 @@ nfs_read_reply (uchar *pkt, unsigned len)
 	    rpc_pkt.u.reply.verifier ||
 	    rpc_pkt.u.reply.astatus  ||
 	    rpc_pkt.u.reply.data[0]) {
-		if (rpc_pkt.u.reply.rstatus) {
+		if (rpc_pkt.u.reply.rstatus)
 			return -9999;
-		}
-		if (rpc_pkt.u.reply.astatus) {
+		if (rpc_pkt.u.reply.astatus)
 			return -9999;
-		}
-		return -ntohl(rpc_pkt.u.reply.data[0]);;
+		return -ntohl(rpc_pkt.u.reply.data[0]);
 	}
 
-	if ((nfs_offset!=0) && !((nfs_offset) % (NFS_READ_SIZE/2*10*HASHES_PER_LINE))) {
-		puts ("\n\t ");
-	}
-	if (!(nfs_offset % ((NFS_READ_SIZE/2)*10))) {
-		putc ('#');
-	}
+	if ((nfs_offset != 0) && !((nfs_offset) %
+			(NFS_READ_SIZE / 2 * 10 * HASHES_PER_LINE)))
+		puts("\n\t ");
+	if (!(nfs_offset % ((NFS_READ_SIZE / 2) * 10)))
+		putc('#');
 
 	rlen = ntohl(rpc_pkt.u.reply.data[18]);
-	if ( store_block ((uchar *)pkt+sizeof(rpc_pkt.u.reply), nfs_offset, rlen) )
+	if (store_block((uchar *)pkt + sizeof(rpc_pkt.u.reply),
+			nfs_offset, rlen))
 		return -9999;
 
 	return rlen;
@@ -567,15 +563,15 @@ Interfaces of U-BOOT
 **************************************************************************/
 
 static void
-NfsTimeout (void)
+NfsTimeout(void)
 {
-	if ( ++NfsTimeoutCount > NFS_RETRY_COUNT ) {
-		puts ("\nRetry count exceeded; starting again\n");
-		NetStartAgain ();
+	if (++NfsTimeoutCount > NFS_RETRY_COUNT) {
+		puts("\nRetry count exceeded; starting again\n");
+		NetStartAgain();
 	} else {
 		puts("T ");
-		NetSetTimeout (NFS_TIMEOUT, NfsTimeout);
-		NfsSend ();
+		NetSetTimeout(NFS_TIMEOUT, NfsTimeout);
+		NfsSend();
 	}
 }
 
@@ -586,86 +582,87 @@ NfsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
 
 	debug("%s\n", __func__);
 
-	if (dest != NfsOurPort) return;
+	if (dest != NfsOurPort)
+		return;
 
 	switch (NfsState) {
 	case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
-		rpc_lookup_reply (PROG_MOUNT, pkt, len);
+		rpc_lookup_reply(PROG_MOUNT, pkt, len);
 		NfsState = STATE_PRCLOOKUP_PROG_NFS_REQ;
-		NfsSend ();
+		NfsSend();
 		break;
 
 	case STATE_PRCLOOKUP_PROG_NFS_REQ:
-		rpc_lookup_reply (PROG_NFS, pkt, len);
+		rpc_lookup_reply(PROG_NFS, pkt, len);
 		NfsState = STATE_MOUNT_REQ;
-		NfsSend ();
+		NfsSend();
 		break;
 
 	case STATE_MOUNT_REQ:
 		if (nfs_mount_reply(pkt, len)) {
-			puts ("*** ERROR: Cannot mount\n");
+			puts("*** ERROR: Cannot mount\n");
 			/* just to be sure... */
 			NfsState = STATE_UMOUNT_REQ;
-			NfsSend ();
+			NfsSend();
 		} else {
 			NfsState = STATE_LOOKUP_REQ;
-			NfsSend ();
+			NfsSend();
 		}
 		break;
 
 	case STATE_UMOUNT_REQ:
 		if (nfs_umountall_reply(pkt, len)) {
-			puts ("*** ERROR: Cannot umount\n");
+			puts("*** ERROR: Cannot umount\n");
 			NetState = NETLOOP_FAIL;
 		} else {
-			puts ("\ndone\n");
+			puts("\ndone\n");
 			NetState = NfsDownloadState;
 		}
 		break;
 
 	case STATE_LOOKUP_REQ:
 		if (nfs_lookup_reply(pkt, len)) {
-			puts ("*** ERROR: File lookup fail\n");
+			puts("*** ERROR: File lookup fail\n");
 			NfsState = STATE_UMOUNT_REQ;
-			NfsSend ();
+			NfsSend();
 		} else {
 			NfsState = STATE_READ_REQ;
 			nfs_offset = 0;
 			nfs_len = NFS_READ_SIZE;
-			NfsSend ();
+			NfsSend();
 		}
 		break;
 
 	case STATE_READLINK_REQ:
 		if (nfs_readlink_reply(pkt, len)) {
-			puts ("*** ERROR: Symlink fail\n");
+			puts("*** ERROR: Symlink fail\n");
 			NfsState = STATE_UMOUNT_REQ;
-			NfsSend ();
+			NfsSend();
 		} else {
 			debug("Symlink --> %s\n", nfs_path);
-			nfs_filename = basename (nfs_path);
-			nfs_path     = dirname (nfs_path);
+			nfs_filename = basename(nfs_path);
+			nfs_path     = dirname(nfs_path);
 
 			NfsState = STATE_MOUNT_REQ;
-			NfsSend ();
+			NfsSend();
 		}
 		break;
 
 	case STATE_READ_REQ:
-		rlen = nfs_read_reply (pkt, len);
-		NetSetTimeout (NFS_TIMEOUT, NfsTimeout);
+		rlen = nfs_read_reply(pkt, len);
+		NetSetTimeout(NFS_TIMEOUT, NfsTimeout);
 		if (rlen > 0) {
 			nfs_offset += rlen;
-			NfsSend ();
-		}
-		else if ((rlen == -NFSERR_ISDIR)||(rlen == -NFSERR_INVAL)) {
+			NfsSend();
+		} else if ((rlen == -NFSERR_ISDIR) || (rlen == -NFSERR_INVAL)) {
 			/* symbolic link */
 			NfsState = STATE_READLINK_REQ;
-			NfsSend ();
+			NfsSend();
 		} else {
-			if ( ! rlen ) NfsDownloadState = NETLOOP_SUCCESS;
+			if (!rlen)
+				NfsDownloadState = NETLOOP_SUCCESS;
 			NfsState = STATE_UMOUNT_REQ;
-			NfsSend ();
+			NfsSend();
 		}
 		break;
 	}
@@ -673,7 +670,7 @@ NfsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
 
 
 void
-NfsStart (void)
+NfsStart(void)
 {
 	debug("%s\n", __func__);
 	NfsDownloadState = NETLOOP_FAIL;
@@ -683,7 +680,7 @@ NfsStart (void)
 
 	if (nfs_path == NULL) {
 		NetState = NETLOOP_FAIL;
-		puts ("*** ERROR: Fail allocate memory\n");
+		puts("*** ERROR: Fail allocate memory\n");
 		return;
 	}
 
@@ -692,29 +689,29 @@ NfsStart (void)
 			NetOurIP & 0xFF,
 			(NetOurIP >>  8) & 0xFF,
 			(NetOurIP >> 16) & 0xFF,
-			(NetOurIP >> 24) & 0xFF	);
-		strcpy (nfs_path, default_filename);
+			(NetOurIP >> 24) & 0xFF);
+		strcpy(nfs_path, default_filename);
 
-		printf ("*** Warning: no boot file name; using '%s'\n",
+		printf("*** Warning: no boot file name; using '%s'\n",
 			nfs_path);
 	} else {
-		char *p=BootFile;
+		char *p = BootFile;
 
-		p = strchr (p, ':');
+		p = strchr(p, ':');
 
 		if (p != NULL) {
-			NfsServerIP = string_to_ip (BootFile);
+			NfsServerIP = string_to_ip(BootFile);
 			++p;
-			strcpy (nfs_path, p);
+			strcpy(nfs_path, p);
 		} else {
-			strcpy (nfs_path, BootFile);
+			strcpy(nfs_path, BootFile);
 		}
 	}
 
-	nfs_filename = basename (nfs_path);
-	nfs_path     = dirname (nfs_path);
+	nfs_filename = basename(nfs_path);
+	nfs_path     = dirname(nfs_path);
 
-	printf ("Using %s device\n", eth_get_name());
+	printf("Using %s device\n", eth_get_name());
 
 	printf("File transfer via NFS from server %pI4"
 		"; our IP address is %pI4", &NfsServerIP, &NetOurIP);
@@ -725,19 +722,20 @@ NfsStart (void)
 		IPaddr_t ServerNet  = NetServerIP & NetOurSubnetMask;
 
 		if (OurNet != ServerNet)
-			printf("; sending through gateway %pI4", &NetOurGatewayIP);
+			printf("; sending through gateway %pI4",
+				&NetOurGatewayIP);
 	}
-	printf ("\nFilename '%s/%s'.", nfs_path, nfs_filename);
+	printf("\nFilename '%s/%s'.", nfs_path, nfs_filename);
 
 	if (NetBootFileSize) {
-		printf (" Size is 0x%x Bytes = ", NetBootFileSize<<9);
-		print_size (NetBootFileSize<<9, "");
+		printf(" Size is 0x%x Bytes = ", NetBootFileSize<<9);
+		print_size(NetBootFileSize<<9, "");
 	}
-	printf ("\nLoad address: 0x%lx\n"
+	printf("\nLoad address: 0x%lx\n"
 		"Loading: *\b", load_addr);
 
-	NetSetTimeout (NFS_TIMEOUT, NfsTimeout);
-	NetSetHandler (NfsHandler);
+	NetSetTimeout(NFS_TIMEOUT, NfsTimeout);
+	NetSetHandler(NfsHandler);
 
 	NfsTimeoutCount = 0;
 	NfsState = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
@@ -747,7 +745,7 @@ NfsStart (void)
 	NfsOurPort = 1000;
 
 	/* zero out server ether in case the server ip has changed */
-	memset (NetServerEther, 0, 6);
+	memset(NetServerEther, 0, 6);
 
-	NfsSend ();
+	NfsSend();
 }
net/nfs.h +1 -1
index de8a0c6..a5a1b43 100644
@@ -72,7 +72,7 @@ struct rpc_t {
 		} reply;
 	} u;
 };
-extern void	NfsStart (void);	/* Begin NFS */
+extern void NfsStart(void);	/* Begin NFS */
 
 
 /**********************************************************************/
Signature · 1 line
1.6.0.2
#111 lore raw

PATCH v3 7/10 net: cosmetic: rarp.* checkpatch compliance

In reply to Joe Hershberger

---
Changes for v2:
- Split into smaller patches
Changes for v3:

 net/rarp.c |   28 ++++++++++++++--------------
 net/rarp.h |    4 ++--
 2 files changed, 16 insertions(+), 16 deletions(-)
net/rarp.c +14 -14
index 77d63e8..5a813a2 100644
@@ -58,21 +58,21 @@ static void
 RarpTimeout(void)
 {
 	if (RarpTry >= TIMEOUT_COUNT) {
-		puts ("\nRetry count exceeded; starting again\n");
-		NetStartAgain ();
+		puts("\nRetry count exceeded; starting again\n");
+		NetStartAgain();
 	} else {
-		NetSetTimeout (TIMEOUT, RarpTimeout);
-		RarpRequest ();
+		NetSetTimeout(TIMEOUT, RarpTimeout);
+		RarpRequest();
 	}
 }
 
 
 void
-RarpRequest (void)
+RarpRequest(void)
 {
 	int i;
 	uchar *pkt;
-	ARP_t *	rarp;
+	ARP_t *rarp;
 
 	printf("RARP broadcast %d\n", ++RarpTry);
 	pkt = NetTxPacket;
@@ -81,18 +81,18 @@ RarpRequest (void)
 
 	rarp = (ARP_t *)pkt;
 
-	rarp->ar_hrd = htons (ARP_ETHER);
-	rarp->ar_pro = htons (PROT_IP);
+	rarp->ar_hrd = htons(ARP_ETHER);
+	rarp->ar_pro = htons(PROT_IP);
 	rarp->ar_hln = 6;
 	rarp->ar_pln = 4;
-	rarp->ar_op  = htons (RARPOP_REQUEST);
-	memcpy (&rarp->ar_data[0],  NetOurEther, 6);	/* source ET addr */
-	memcpy (&rarp->ar_data[6],  &NetOurIP,   4);	/* source IP addr */
-	memcpy (&rarp->ar_data[10], NetOurEther, 6);	/* dest ET addr = source ET addr ??*/
+	rarp->ar_op  = htons(RARPOP_REQUEST);
+	memcpy(&rarp->ar_data[0],  NetOurEther, 6);	/* source ET addr */
+	memcpy(&rarp->ar_data[6],  &NetOurIP,   4);	/* source IP addr */
+	/* dest ET addr = source ET addr ??*/
+	memcpy(&rarp->ar_data[10], NetOurEther, 6);
 	/* dest. IP addr set to broadcast */
-	for (i = 0; i <= 3; i++) {
+	for (i = 0; i <= 3; i++)
 		rarp->ar_data[16 + i] = 0xff;
-	}
 
 	NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
 
net/rarp.h +2 -2
index 0c16d46..4e92d80 100644
@@ -35,9 +35,9 @@
  *	Global functions and variables.
  */
 
-extern int	RarpTry;
+extern int RarpTry;
 
-extern void RarpRequest (void);	/* Send a RARP request */
+extern void RarpRequest(void);	/* Send a RARP request */
 
 /**********************************************************************/
 
Signature · 1 line
1.6.0.2