Add link-local addressing support
Subsystems (4)
PATCH v3 8/10 net: cosmetic: sntp.* checkpatch compliance
In reply to Joe Hershberger---
Changes for v2:
- Split into smaller patches
Changes for v3:
- Changed literal to sizeof() for Simon Glass
net/sntp.c | 31 +++++++++++++++++-------------- net/sntp.h | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-)
net/sntp.c +17 -14
@@ -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 ,sizeof (NetServerEther)); -SntpSend (); +SntpSend (); }
net/sntp.h +1 -1
@@ -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__ */
Signature · 1 line
1.6.0.2
PATCH v3 9/10 net: cosmetic: tftp.* checkpatch compliance
In reply to Joe Hershberger---
Changes for v2:
- Split into smaller patches
Changes for v3:
include/net.h | 4 ++++ net/tftp.c | 30 ++++++++++++++---------------- net/tftp.h | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-)
include/net.h +4 -0
@@ -396,6 +396,10 @@ extern IPaddr_t NetNtpServerIP; /* the ip address to NTP */extern int NetTimeOffset;/* offset time from UTC */ #endif +#if defined(CONFIG_MCAST_TFTP ) +extern IPaddr_t Mcast_addr; +#endif +/* Initialize the network adapter */ extern int NetLoop (enum proto_t );
net/tftp.c +14 -16
@@ -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)) - &ð_get_dev ()->mcast) { -free (Bitmap); - Bitmap =NULL ; - pkt +=sprintf ((char *)pkt,"multicast%c%c" ,0 ,0 ); +if (!ProhibitMcast) { + Bitmap =malloc (Mapsize); +if (Bitmap &ð_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
@@ -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
PATCH v3 10/10 net: cosmetic: netconsole.c checkpatch compliance
In reply to Joe HershbergerRequires:
--ignore CONSIDER_KSTRTO
---
Changes for v2:
- Split into smaller patches
Changes for v3:
drivers/net/netconsole.c | 122 +++++++++++++++++++++++---------------------- 1 files changed, 62 insertions(+), 60 deletions(-)
drivers/net/netconsole.c +62 -60
@@ -29,81 +29,82 @@DECLARE_GLOBAL_DATA_PTR ;static char input_buffer[512 ]; -static int input_size =0 ;/* char count in input buffer */ -static int input_offset =0 ;/* offset to valid chars in input buffer */ -static int input_recursion =0 ; -static int output_recursion =0 ; +static int input_size;/* char count in input buffer */ +static int input_offset;/* offset to valid chars in input buffer */ +static int input_recursion; +static int output_recursion;static int net_timeout; -static uchar nc_ether[6 ];/* server enet address */ -static IPaddr_t nc_ip;/* server ip */ -static short nc_port;/* source/target port */ -static const char *output_packet;/* used by first send udp */ -static int output_packet_len =0 ; +static uchar nc_ether[6 ];/* server enet address */ +static IPaddr_t nc_ip;/* server ip */ +static short nc_port;/* source/target port */ +static const char *output_packet;/* used by first send udp */ +static int output_packet_len;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 */ + NetState =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 */ + NetState =NETLOOP_SUCCESS ;/* got input - quit net loop */ } -static void nc_timeout (void ) +static void nc_timeout (void ) { NetState =NETLOOP_SUCCESS ; } -void NcStart (void ) +void NcStart (void ) { -if (!output_packet_len ||memcmp (nc_ether, NetEtherNullAddr,6 )) { +if (!output_packet_len ||memcmp (nc_ether, NetEtherNullAddr,6 )) {/* going to check for input packet */ -NetSetHandler (nc_handler); -NetSetTimeout (net_timeout, nc_timeout); +NetSetHandler (nc_handler); +NetSetTimeout (net_timeout, nc_timeout); }else {/* send arp request */ uchar *pkt; -NetSetHandler (nc_wait_arp_handler); - pkt = (uchar *) NetTxPacket +NetEthHdrSize () +IP_HDR_SIZE ; -memcpy (pkt, output_packet, output_packet_len); -NetSendUDPPacket (nc_ether, nc_ip, nc_port, nc_port, output_packet_len); +NetSetHandler (nc_wait_arp_handler); + pkt = (uchar *)NetTxPacket +NetEthHdrSize () +IP_HDR_SIZE ; +memcpy (pkt, output_packet, output_packet_len); +NetSendUDPPacket (nc_ether, nc_ip, nc_port, nc_port, + output_packet_len); } } -int nc_input_packet (uchar * pkt,unsigned dest,unsigned src,unsigned len) +int nc_input_packet (uchar *pkt,unsigned dest,unsigned src,unsigned len) {int end, chunk;if (dest != nc_port || !len) -return 0 ;/* not for us */ +return 0 ;/* not for us */ -if (input_size ==sizeof input_buffer) -return 1 ;/* no space */ -if (len >sizeof input_buffer - input_size) - len =sizeof input_buffer - input_size; +if (input_size ==sizeof (input_buffer)) +return 1 ;/* no space */ +if (len >sizeof (input_buffer) - input_size) + len =sizeof (input_buffer) - input_size; end = input_offset + input_size; -if (end >sizeof input_buffer) - end -=sizeof input_buffer; +if (end >sizeof (input_buffer)) + end -=sizeof (input_buffer); chunk = len; -if (end + len >sizeof input_buffer) { - chunk =sizeof input_buffer - end; +if (end + len >sizeof (input_buffer)) { + chunk =sizeof (input_buffer) - end;memcpy (input_buffer, pkt + chunk, len - chunk); } -memcpy (input_buffer + end, pkt, chunk); +memcpy (input_buffer + end, pkt, chunk); input_size += len;return 1 ; } -static void nc_send_packet (const char *buf,int len) +static void nc_send_packet (const char *buf,int len) {struct eth_device *eth;int inited =0 ;
@@ -111,33 +112,33 @@ static void nc_send_packet (const char *buf, int len)uchar *ether;IPaddr_t ip; -if ((eth =eth_get_dev ()) ==NULL ) { + eth =eth_get_dev (); +if (eth ==NULL )return ; - } -if (!memcmp (nc_ether, NetEtherNullAddr,6 )) { +if (!memcmp (nc_ether, NetEtherNullAddr,6 )) {if (eth->state ==ETH_STATE_ACTIVE )return ;/* inside net loop */ output_packet = buf; output_packet_len = len; -NetLoop (NETCONS );/* wait for arp reply and send packet */ +NetLoop (NETCONS );/* wait for arp reply and send packet */ output_packet_len =0 ;return ; }if (eth->state !=ETH_STATE_ACTIVE ) { -if (eth_init (gd->bd) <0 ) +if (eth_init (gd->bd) <0 )return ; inited =1 ; } - pkt = (uchar *) NetTxPacket +NetEthHdrSize () +IP_HDR_SIZE ; -memcpy (pkt, buf, len); + pkt = (uchar *)NetTxPacket +NetEthHdrSize () +IP_HDR_SIZE ; +memcpy (pkt, buf, len); ether = nc_ether; ip = nc_ip; -NetSendUDPPacket (ether, ip, nc_port, nc_port, len); +NetSendUDPPacket (ether, ip, nc_port, nc_port, len);if (inited) -eth_halt (); +eth_halt (); }static int nc_start (void )
@@ -146,26 +147,27 @@ static int nc_start(void) nc_port =6666 ;/* default port */ -if (getenv ("ncip" )) { +if (getenv ("ncip" )) {char *p; - nc_ip =getenv_IPaddr ("ncip" ); + nc_ip =getenv_IPaddr ("ncip" );if (!nc_ip)return -1 ;/* ncip is 0.0.0.0 */ -if ((p =strchr (getenv ("ncip" ),':' )) !=NULL ) - nc_port =simple_strtoul (p +1 ,NULL ,10 ); + p =strchr (getenv ("ncip" ),':' ); +if (p !=NULL ) + nc_port =simple_strtoul (p +1 ,NULL ,10 ); }else nc_ip = ~0 ;/* ncip is not set */ - our_ip =getenv_IPaddr ("ipaddr" ); - netmask =getenv_IPaddr ("netmask" ); + our_ip =getenv_IPaddr ("ipaddr" ); + netmask =getenv_IPaddr ("netmask" );if (nc_ip == ~0 ||/* 255.255.255.255 */ ((netmask & our_ip) == (netmask & nc_ip) &&/* on the same net */ - (netmask | nc_ip) == ~0 ))/* broadcast to our net */ -memset (nc_ether,0xff ,sizeof nc_ether); + (netmask | nc_ip) == ~0 ))/* broadcast to our net */ +memset (nc_ether,0xff ,sizeof (nc_ether));else -memset (nc_ether,0 ,sizeof nc_ether);/* force arp request */ +memset (nc_ether,0 ,sizeof (nc_ether));/* force arp request */ return 0 ; }
@@ -176,7 +178,7 @@ static void nc_putc(char c)return ; output_recursion =1 ; -nc_send_packet (&c,1 ); +nc_send_packet (&c,1 ); output_recursion =0 ; }
@@ -208,14 +210,14 @@ static int nc_getc(void) net_timeout =0 ;/* no timeout */ while (!input_size) -NetLoop (NETCONS ); +NetLoop (NETCONS ); input_recursion =0 ; c = input_buffer[input_offset++]; -if (input_offset >=sizeof input_buffer) - input_offset -=sizeof input_buffer; +if (input_offset >=sizeof (input_buffer)) + input_offset -=sizeof (input_buffer); input_size--;return c;
@@ -231,28 +233,28 @@ static int nc_tstc(void)if (input_size)return 1 ; - eth =eth_get_dev (); + eth =eth_get_dev ();if (eth && eth->state ==ETH_STATE_ACTIVE )return 0 ;/* inside net loop */ input_recursion =1 ; net_timeout =1 ; -NetLoop (NETCONS );/* kind of poll */ +NetLoop (NETCONS );/* kind of poll */ input_recursion =0 ;return input_size !=0 ; } -int drv_nc_init (void ) +int drv_nc_init (void ) {struct stdio_dev dev;int rc; -memset (&dev,0 ,sizeof (dev)); +memset (&dev,0 ,sizeof (dev)); -strcpy (dev.name,"nc" ); +strcpy (dev.name,"nc" ); dev.flags =DEV_FLAGS_OUTPUT |DEV_FLAGS_INPUT |DEV_FLAGS_SYSTEM ; dev.start = nc_start; dev.putc = nc_putc;
@@ -260,7 +262,7 @@ int drv_nc_init (void) dev.getc = nc_getc; dev.tstc = nc_tstc; - rc =stdio_register (&dev); + rc =stdio_register (&dev);return (rc ==0 ) ?1 : rc; }
Signature · 1 line
1.6.0.2
PATCH v2 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)
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
@@ -80,7 +80,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
@@ -119,10 +119,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 */
@@ -341,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 */
@@ -407,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 */
@@ -422,13 +423,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
@@ -444,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));
@@ -466,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
@@ -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
@@ -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;
@@ -408,7 +406,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 ;
@@ -425,9 +423,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)
@@ -443,9 +441,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
@@ -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
@@ -71,7 +71,7 @@ voidRarpRequest (void) {int i; -volatile uchar *pkt; +uchar *pkt;ARP_t * rarp;printf ("RARP broadcast %d\n" , ++RarpTry);
net/tftp.c +3 -3
@@ -310,9 +310,9 @@ static voidTftpSend (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
PATCH v2 1/10 net: Remove volatile from net API
Hi Joe,
Quoted 4 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
I have a suggestion below that you might want to take up, but otherwise:
Quoted 22 lines
---
Changes for v2:
? - Remove volatile from eth driver API
? - Not using global NetRxPacket (since not casting away volatile)?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 +0
-0@@ -407,10 +408,10 @@ extern void ? ? ? NetStartAgain(void); ?extern int ? ? NetEthHdrSize(void);?/* Set ethernet header; returns the size of the header */
include/net.h
Quoted 2 lines
include/net.h +1
-1-extern int ? ? NetSetEther(volatile uchar *, uchar *, uint); +extern int NetSetEther (uchar *,uchar *,uint );
I wonder if you can add parameters names into this one and others below as well while you are here. It at least gives some clue as to the parameters even if we don't document them yet.
You may intend to do this in later patches, since this is only for checkpatch.
Regards,
Simon
PATCH v2 2/10 net: cosmetic: net.h checkpatch compliance
In reply to Joe Hershberger---
Changes for v2:
- Split into smaller patches
include/net.h | 114 +++++++++++++++++++++++++++++---------------------------- 1 files changed, 58 insertions(+), 56 deletions(-)
include/net.h +58 -56
@@ -79,14 +79,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;
@@ -100,7 +100,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);
@@ -142,8 +142,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
@@ -218,8 +218,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))/*
@@ -326,46 +326,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 ,
@@ -373,7 +373,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 */
@@ -381,7 +381,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 )
@@ -391,8 +391,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 */
@@ -414,19 +414,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 );
@@ -448,7 +449,7 @@ 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; }
@@ -456,26 +457,26 @@ 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)); }/**
@@ -498,7 +499,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 ]; }/*
@@ -509,7 +510,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 ; }/*
@@ -529,13 +531,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);
@@ -544,7 +546,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
PATCH v2 2/10 net: cosmetic: net.h checkpatch compliance
Hi Joe,
Quoted 7 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>---
Changes for v2:
? - Split into smaller patches
Same suggestion about naming parameters...
Quoted 189 lines
?include/net.h | ?114 +++++++++++++++++++++++++++++---------------------------- ?1 files changed, 58 insertions(+), 56 deletions(-)
include/net.h +4
-4@@ -79,14 +79,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) (structeth_device*, u32 ip, u8 set); ?#endif
- ? ? ? int ?(*write_hwaddr) (struct eth_device*);
+ ? ? ? int ?(*write_hwaddr) (structeth_device*); ? ? ? ?structeth_device*next;
? ? ? ?int index;
? ? ? ?void *priv;include/net.h +0
-0@@ -100,7 +100,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 structeth_device*eth_get_dev_by_name(const char *devname); ?extern structeth_device*eth_get_dev_by_index(int index); /* get dev @ index */include/net.h +1
-1-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 inteth_getenv_enetaddr(char *name, uchar *enetaddr); ?extern inteth_setenv_enetaddr(char *name, const uchar *enetaddr);include/net.h +0
-0@@ -142,8 +142,8 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name, ? ? ? ? ? ? ? ? ? ? int eth_number);?#ifdef
CONFIG_MCAST_TFTPinclude/net.h +2
-2-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
include/net.h +0
-0@@ -218,8 +218,8 @@ typedef struct {?#define
IP_FLAGS_DFRAG0x4000/* don't fragments */ ?#defineIP_FLAGS_MFRAG0x2000/* more fragments */include/net.h +2
-2-#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))?/*
include/net.h +0
-0@@ -326,46 +326,46 @@ typedef struct icmphdr {?/*
net.c*/
?/** BOOTP EXTENTIONS **/include/net.h +3
-3-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)include/net.h +1
-1-extern IPaddr_t ? ? ? ? ? ? ? ?NetOurDNS2IP; ? ?/* Our 2nd Domain Name Server (0 = unknown)*/ +extern IPaddr_t NetOurDNS2IP; ?/* Our 2nd Domain Name Server (0 = unknown) */?#endif
include/net.h +4
-4-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 **/
include/net.h +5
-5-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 */
include/net.h +1
-1-extern uchar ? ? ? ? ? *NetRxPackets[PKTBUFSRX];/* Receive packets */ +extern uchar ? ? ? ? ? *NetRxPackets[PKTBUFSRX]; /* Receive packets */?extern uchar ? ? ? ? ? *NetRxPacket; ? ? ? ? ? /* Current receive packet */
include/net.h +3
-3-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];
include/net.h +8
-8-#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
?#defineNETLOOP_RESTART? ? ? ? ? ? ? ?2
?#defineNETLOOP_SUCCESS? ? ? ? ? ? ? ?3
?#defineNETLOOP_FAIL? ? ? ? ? 4include/net.h +1
-1-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,include/net.h +0
-0@@ -373,7 +373,7 @@ enum proto_t { ?};?/* from
net/net.c*/include/net.h +1
-1-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 ?*/include/net.h +0
-0@@ -381,7 +381,7 @@ extern char *NetDNSenvvar; ? ? ? ? ?/* the env var to put the ip into */?#endif
?#if
defined(CONFIG_CMD_PING)include/net.h +1
-1-extern IPaddr_t ? ? ? ?NetPingIP; ? ? ? ? ? ? ? ? ? ? ?/* the ip address to ping ? ? ? ? ? ? ? */ +extern IPaddr_t ? ? ? ?NetPingIP; ? ? ? ? ? ? ? ? ? ? ?/* the ip address to ping */?#endif
?#if
defined(CONFIG_CMD_CDP)include/net.h +0
-0@@ -391,8 +391,8 @@ extern ushort CDPApplianceVLAN;?#endif
?#if
defined(CONFIG_CMD_SNTP)include/net.h +2
-2-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 */
include/net.h +0
-0@@ -414,19 +414,20 @@ extern int NetSetEther(uchar *, uchar *, uint); ?extern void NetSetIP(uchar *, IPaddr_t, int, int, int);?/* Checksum */
include/net.h +2
-2-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 */
include/net.h +1
-1-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 */include/net.h +1
-1-extern void ? ?NetSetTimeout(ulong, thand_f *);/* Set timeout handler ? ? ? ? ?*/ +extern void ? ?NetSetTimeout(ulong, thand_f *);/* Set timeout handler */?/* Transmit "NetTxPacket" */
?extern voidNetSendPacket(uchar *, int);?/* Transmit UDP packet, performing ARP request if needed */
include/net.h +2
-1-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 voidNetReceive(uchar *, int);
include/net.h void net_auto_load(void); · line 451
Quoted 3 lines
include/net.h +0
-0@@ -448,7 +449,7 @@ void net_auto_load(void); ?static inline IPaddr_t NetReadIP(void *from) ?{ ? ? ? ?IPaddr_t ip;
blank line here?
include/net.h static inline IPaddr_t NetReadIP(void *from) · line 459
Quoted 9 lines
include/net.h +1
-1- ? ? ? memcpy((void*)&ip, (void*)from, sizeof(ip)); + ? ? ? memcpy((void *)&ip, (void *)from, sizeof(ip)); ? ? ? ?return ip; ?}@@ -456,26 +457,26 @@ static inline IPaddr_t NetReadIP(void *from) ?static inline ulong NetReadLong(ulong *from) ?{ ? ? ? ?ulong l;
blank line here?
Quoted 69 lines
include/net.h +1
-1- ? ? ? 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 voidNetCopyIP(void *to, void *from)?{
- ? ? ?memcpy((void*)to, from, sizeof(IPaddr_t));
+ ? ? ?memcpy((void *)to, from, sizeof(IPaddr_t)); ?}?/* copy ulong */
?static inline voidNetCopyLong(ulong *to, ulong *from)?{
- ? ? ?memcpy((void*)to, (void*)from, sizeof(ulong));
+ ? ? ?memcpy((void *)to, (void *)from, sizeof(ulong)); ?}?/**
include/net.h +0
-0@@ -498,7 +499,7 @@ static inline int is_zero_ether_addr(const u8 *addr)?*/
?static inline intis_multicast_ether_addr(const u8 *addr)?{
- ? ? ? return (0x01& addr[0]);
+ ? ? ? return0x01& addr[0];
?}?/*
include/net.h +0
-0@@ -509,7 +510,8 @@ static inline int is_multicast_ether_addr(const u8 *addr)?*/
?static inline intis_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;
?}?/*
include/net.h +0
-0@@ -529,13 +531,13 @@ static inline int is_valid_ether_addr(const u8 *addr) ?}?/* Convert an IP address to a string */
include/net.h +1
-1-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 */
?externIPaddr_tstring_to_ip(const char *s);?/* Convert a VLAN id to a string */
include/net.h +1
-1-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 ushortstring_to_VLAN(const char *s);include/net.h +0
-0@@ -544,7 +546,7 @@ extern ushort string_to_VLAN(const char *s); ?extern ushort getenv_VLAN(char *);?/* copy a filename (allow for "..." notation, limit length) */
include/net.h +1
-1-extern void ? ?copy_filename (char *dst, const char *src, int size); +extern void copy_filename (char *dst,const char *src,int size);
Quoted 5 lines
?/* get a random source port */
?extern unsigned intrandom_port(void);
--
1.6.0.2
Regards,
Simon
PATCH v2 3/10 net: cosmetic: net.c checkpatch compliance
In reply to Joe Hershberger---
Changes for v2:
- Split into smaller patches
net/bootp.c | 340 ++++++++++++++++++++++++++++++----------------------------- net/bootp.h | 56 +++++----- 2 files changed, 203 insertions(+), 193 deletions(-)
net/bootp.c +173 -167
@@ -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 voidBootpTimeout (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
PATCH v2 3/10 net: cosmetic: net.c checkpatch compliance
Hi Joe,
Quoted 29 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>---
Changes for v2:
? - Split into smaller patches?net/bootp.c | ?340 ++++++++++++++++++++++++++++++----------------------------- ?net/bootp.h | ? 56 +++++-----
?2 files changed, 203 insertions(+), 193 deletions(-)net/bootp.c +0
-0@@ -64,37 +64,29 @@ static char *dhcpmsg2str(int type) ? ? ? ?} ?}?#endif
net/bootp.c +0
-6- -#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
Quoted 4 lines
?static int
BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)?{
- ? ? ?Bootp_t*bp = (Bootp_t*) pkt;
+ ? ? ? structBootp_t*bp = (structBootp_t*) pkt;
I'm not sure of the ordering of the serieses, but if this one comes first, then struct Bootp_t doesn't exist yet - it is only a typedef.
Regards,
Simon
PATCH v2 4/10 net: cosmetic: eth.c checkpatch compliance
In reply to Joe Hershberger---
Changes for v2:
- Split into smaller patches
net/eth.c | 67 +++++++++++++++++++++++++++++------------------------------- 1 files changed, 32 insertions(+), 35 deletions(-)
net/eth.c +32 -35
@@ -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; }
@@ -175,7 +174,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",
@@ -188,10 +187,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; }
@@ -199,7 +197,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));
@@ -207,7 +205,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; }
@@ -277,36 +275,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;
@@ -317,9 +316,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 ;
@@ -336,7 +335,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;
@@ -363,7 +362,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 ; }
@@ -383,7 +382,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;
@@ -471,38 +470,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 */
@@ -525,7 +522,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
PATCH v2 5/10 net: cosmetic: net.c checkpatch compliance
In reply to Joe Hershberger---
Changes for v2:
- Split into smaller patches
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
@@ -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
@@ -801,6 +801,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
@@ -432,6 +432,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
@@ -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
PATCH v2 6/10 net: cosmetic: nfs.* checkpatch compliance
In reply to Joe Hershberger---
Changes for v2:
- Split into smaller patches
net/nfs.c | 300 ++++++++++++++++++++++++++++++------------------------------- net/nfs.h | 2 +- 2 files changed, 150 insertions(+), 152 deletions(-)
net/nfs.c +149 -151
@@ -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
@@ -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
PATCH v2 6/10 net: cosmetic: nfs.* checkpatch compliance
Hi Joe,
Quoted 4 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
Looks good.
PATCH v2 7/10 net: cosmetic: rarp.* checkpatch compliance
In reply to Joe Hershberger---
Changes for v2:
- Split into smaller patches
net/rarp.c | 28 ++++++++++++++-------------- net/rarp.h | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-)
net/rarp.c +14 -14
@@ -58,21 +58,21 @@ static voidRarpTimeout (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
@@ -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
PATCH v2 7/10 net: cosmetic: rarp.* checkpatch compliance
Quoted 4 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
Quoted 86 lines
---
Changes for v2:
? - Split into smaller patches?net/rarp.c | ? 28 ++++++++++++++-------------- ?net/rarp.h | ? ?4 ++--
?2 files changed, 16 insertions(+), 16 deletions(-)net/rarp.c +4
-4@@ -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
net/rarp.c +1
-1-RarpRequest (void) +RarpRequest (void)?{
? ? ? ?int i;
? ? ? ?uchar *pkt;
- ? ? ?ARP_t* rarp;
+ ? ? ?ARP_t*rarp;? ? ? ?printf("RARP broadcast %d\n", ++RarpTry); ? ? ? ?pkt = NetTxPacket;
net/rarp.c +7
-6@@ -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 +0
-0@@ -35,9 +35,9 @@?* ? ? Global functions and variables.
?*/net/rarp.h +2
-2-extern int ? ? RarpTry; +extern int RarpTry; -extern void RarpRequest (void); ? ? ? ?/* Send a RARP request */ +extern void RarpRequest (void );/* Send a RARP request */ ?/**********************************************************************/
--
1.6.0.2
PATCH v2 8/10 net: cosmetic: sntp.* checkpatch compliance
In reply to Joe Hershberger---
Changes for v2:
- Split into smaller patches
net/sntp.c | 31 +++++++++++++++++-------------- net/sntp.h | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-)
net/sntp.c +17 -14
@@ -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
@@ -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__ */
Signature · 1 line
1.6.0.2
PATCH v2 8/10 net: cosmetic: sntp.* checkpatch compliance
Quoted 4 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
but see suggestion below (not checkpatch issue though)
Quoted 22 lines
---
Changes for v2:
? - Split into smaller patches?net/sntp.c | ? 31 +++++++++++++++++-------------- ?net/sntp.h | ? ?2 +-
?2 files changed, 18 insertions(+), 15 deletions(-)net/sntp.c +0
-0@@ -77,13 +80,13 @@ SntpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, ?}?void
net/sntp.c +1
-1-SntpStart (void) +SntpStart (void)?{
? ? ? ?debug("%s\n",__func__);
Quoted 5 lines
- ? ? ? NetSetTimeout (
SNTP_TIMEOUT, SntpTimeout);
+ ? ? ?NetSetTimeout(SNTP_TIMEOUT, SntpTimeout); ? ? ? ?NetSetHandler(SntpHandler);
- ? ? ? memset (NetServerEther, 0, 6);
+ ? ? ?memset(NetServerEther, 0, 6);
sizeof(NetServerEther) might be better.
Quoted 19 lines
- ? ? ? SntpSend ();
+ ? ? ?SntpSend();
?}net/sntp.h +1
-1@@ -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__*/
--
1.6.0.2
PATCH v2 9/10 net: cosmetic: tftp.* checkpatch compliance
In reply to Joe Hershberger---
Changes for v2:
- Split into smaller patches
include/net.h | 4 ++++ net/tftp.c | 30 ++++++++++++++---------------- net/tftp.h | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-)
include/net.h +4 -0
@@ -395,6 +395,10 @@ extern IPaddr_t NetNtpServerIP; /* the ip address to NTP */extern int NetTimeOffset;/* offset time from UTC */ #endif +#if defined(CONFIG_MCAST_TFTP ) +extern IPaddr_t Mcast_addr; +#endif +/* Initialize the network adapter */ extern int NetLoop (enum proto_t );
net/tftp.c +14 -16
@@ -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)) - &ð_get_dev ()->mcast) { -free (Bitmap); - Bitmap =NULL ; - pkt +=sprintf ((char *)pkt,"multicast%c%c" ,0 ,0 ); +if (!ProhibitMcast) { + Bitmap =malloc (Mapsize); +if (Bitmap &ð_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
@@ -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
PATCH v2 9/10 net: cosmetic: tftp.* checkpatch compliance
Hi Joe,
Quoted 4 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
Quoted 15 lines
---
Changes for v2:
? - Split into smaller patches?include/net.h | ? ?4 ++++ ?net/tftp.c ? ?| ? 30 ++++++++++++++---------------- ?net/tftp.h ? ?| ? ?2 +-?3 files changed, 19 insertions(+), 17 deletions(-)
(quoted diff) +0
-0@@ -157,7 +155,7 @@ mcast_cleanup(void)?#endif /*
CONFIG_MCAST_TFTP*/net/tftp.c +1
-1-static __inline__ void +static inline void
Quoted 1 line
?store_block(unsigned block, uchar *src, unsigned len)
Q: Do we really need this inline?
Regards,
Simon
PATCH v2 10/10 net: cosmetic: netconsole.c checkpatch compliance
In reply to Joe HershbergerRequires:
--ignore CONSIDER_KSTRTO
---
Changes for v2:
- Split into smaller patches
drivers/net/netconsole.c | 122 +++++++++++++++++++++++---------------------- 1 files changed, 62 insertions(+), 60 deletions(-)
drivers/net/netconsole.c +62 -60
@@ -29,81 +29,82 @@DECLARE_GLOBAL_DATA_PTR ;static char input_buffer[512 ]; -static int input_size =0 ;/* char count in input buffer */ -static int input_offset =0 ;/* offset to valid chars in input buffer */ -static int input_recursion =0 ; -static int output_recursion =0 ; +static int input_size;/* char count in input buffer */ +static int input_offset;/* offset to valid chars in input buffer */ +static int input_recursion; +static int output_recursion;static int net_timeout; -static uchar nc_ether[6 ];/* server enet address */ -static IPaddr_t nc_ip;/* server ip */ -static short nc_port;/* source/target port */ -static const char *output_packet;/* used by first send udp */ -static int output_packet_len =0 ; +static uchar nc_ether[6 ];/* server enet address */ +static IPaddr_t nc_ip;/* server ip */ +static short nc_port;/* source/target port */ +static const char *output_packet;/* used by first send udp */ +static int output_packet_len;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 */ + NetState =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 */ + NetState =NETLOOP_SUCCESS ;/* got input - quit net loop */ } -static void nc_timeout (void ) +static void nc_timeout (void ) { NetState =NETLOOP_SUCCESS ; } -void NcStart (void ) +void NcStart (void ) { -if (!output_packet_len ||memcmp (nc_ether, NetEtherNullAddr,6 )) { +if (!output_packet_len ||memcmp (nc_ether, NetEtherNullAddr,6 )) {/* going to check for input packet */ -NetSetHandler (nc_handler); -NetSetTimeout (net_timeout, nc_timeout); +NetSetHandler (nc_handler); +NetSetTimeout (net_timeout, nc_timeout); }else {/* send arp request */ uchar *pkt; -NetSetHandler (nc_wait_arp_handler); - pkt = (uchar *) NetTxPacket +NetEthHdrSize () +IP_HDR_SIZE ; -memcpy (pkt, output_packet, output_packet_len); -NetSendUDPPacket (nc_ether, nc_ip, nc_port, nc_port, output_packet_len); +NetSetHandler (nc_wait_arp_handler); + pkt = (uchar *)NetTxPacket +NetEthHdrSize () +IP_HDR_SIZE ; +memcpy (pkt, output_packet, output_packet_len); +NetSendUDPPacket (nc_ether, nc_ip, nc_port, nc_port, + output_packet_len); } } -int nc_input_packet (uchar * pkt,unsigned dest,unsigned src,unsigned len) +int nc_input_packet (uchar *pkt,unsigned dest,unsigned src,unsigned len) {int end, chunk;if (dest != nc_port || !len) -return 0 ;/* not for us */ +return 0 ;/* not for us */ -if (input_size ==sizeof input_buffer) -return 1 ;/* no space */ -if (len >sizeof input_buffer - input_size) - len =sizeof input_buffer - input_size; +if (input_size ==sizeof (input_buffer)) +return 1 ;/* no space */ +if (len >sizeof (input_buffer) - input_size) + len =sizeof (input_buffer) - input_size; end = input_offset + input_size; -if (end >sizeof input_buffer) - end -=sizeof input_buffer; +if (end >sizeof (input_buffer)) + end -=sizeof (input_buffer); chunk = len; -if (end + len >sizeof input_buffer) { - chunk =sizeof input_buffer - end; +if (end + len >sizeof (input_buffer)) { + chunk =sizeof (input_buffer) - end;memcpy (input_buffer, pkt + chunk, len - chunk); } -memcpy (input_buffer + end, pkt, chunk); +memcpy (input_buffer + end, pkt, chunk); input_size += len;return 1 ; } -static void nc_send_packet (const char *buf,int len) +static void nc_send_packet (const char *buf,int len) {struct eth_device *eth;int inited =0 ;
@@ -111,33 +112,33 @@ static void nc_send_packet (const char *buf, int len)uchar *ether;IPaddr_t ip; -if ((eth =eth_get_dev ()) ==NULL ) { + eth =eth_get_dev (); +if (eth ==NULL )return ; - } -if (!memcmp (nc_ether, NetEtherNullAddr,6 )) { +if (!memcmp (nc_ether, NetEtherNullAddr,6 )) {if (eth->state ==ETH_STATE_ACTIVE )return ;/* inside net loop */ output_packet = buf; output_packet_len = len; -NetLoop (NETCONS );/* wait for arp reply and send packet */ +NetLoop (NETCONS );/* wait for arp reply and send packet */ output_packet_len =0 ;return ; }if (eth->state !=ETH_STATE_ACTIVE ) { -if (eth_init (gd->bd) <0 ) +if (eth_init (gd->bd) <0 )return ; inited =1 ; } - pkt = (uchar *) NetTxPacket +NetEthHdrSize () +IP_HDR_SIZE ; -memcpy (pkt, buf, len); + pkt = (uchar *)NetTxPacket +NetEthHdrSize () +IP_HDR_SIZE ; +memcpy (pkt, buf, len); ether = nc_ether; ip = nc_ip; -NetSendUDPPacket (ether, ip, nc_port, nc_port, len); +NetSendUDPPacket (ether, ip, nc_port, nc_port, len);if (inited) -eth_halt (); +eth_halt (); }static int nc_start (void )
@@ -146,26 +147,27 @@ static int nc_start(void) nc_port =6666 ;/* default port */ -if (getenv ("ncip" )) { +if (getenv ("ncip" )) {char *p; - nc_ip =getenv_IPaddr ("ncip" ); + nc_ip =getenv_IPaddr ("ncip" );if (!nc_ip)return -1 ;/* ncip is 0.0.0.0 */ -if ((p =strchr (getenv ("ncip" ),':' )) !=NULL ) - nc_port =simple_strtoul (p +1 ,NULL ,10 ); + p =strchr (getenv ("ncip" ),':' ); +if (p !=NULL ) + nc_port =simple_strtoul (p +1 ,NULL ,10 ); }else nc_ip = ~0 ;/* ncip is not set */ - our_ip =getenv_IPaddr ("ipaddr" ); - netmask =getenv_IPaddr ("netmask" ); + our_ip =getenv_IPaddr ("ipaddr" ); + netmask =getenv_IPaddr ("netmask" );if (nc_ip == ~0 ||/* 255.255.255.255 */ ((netmask & our_ip) == (netmask & nc_ip) &&/* on the same net */ - (netmask | nc_ip) == ~0 ))/* broadcast to our net */ -memset (nc_ether,0xff ,sizeof nc_ether); + (netmask | nc_ip) == ~0 ))/* broadcast to our net */ +memset (nc_ether,0xff ,sizeof (nc_ether));else -memset (nc_ether,0 ,sizeof nc_ether);/* force arp request */ +memset (nc_ether,0 ,sizeof (nc_ether));/* force arp request */ return 0 ; }
@@ -176,7 +178,7 @@ static void nc_putc(char c)return ; output_recursion =1 ; -nc_send_packet (&c,1 ); +nc_send_packet (&c,1 ); output_recursion =0 ; }
@@ -208,14 +210,14 @@ static int nc_getc(void) net_timeout =0 ;/* no timeout */ while (!input_size) -NetLoop (NETCONS ); +NetLoop (NETCONS ); input_recursion =0 ; c = input_buffer[input_offset++]; -if (input_offset >=sizeof input_buffer) - input_offset -=sizeof input_buffer; +if (input_offset >=sizeof (input_buffer)) + input_offset -=sizeof (input_buffer); input_size--;return c;
@@ -231,28 +233,28 @@ static int nc_tstc(void)if (input_size)return 1 ; - eth =eth_get_dev (); + eth =eth_get_dev ();if (eth && eth->state ==ETH_STATE_ACTIVE )return 0 ;/* inside net loop */ input_recursion =1 ; net_timeout =1 ; -NetLoop (NETCONS );/* kind of poll */ +NetLoop (NETCONS );/* kind of poll */ input_recursion =0 ;return input_size !=0 ; } -int drv_nc_init (void ) +int drv_nc_init (void ) {struct stdio_dev dev;int rc; -memset (&dev,0 ,sizeof (dev)); +memset (&dev,0 ,sizeof (dev)); -strcpy (dev.name,"nc" ); +strcpy (dev.name,"nc" ); dev.flags =DEV_FLAGS_OUTPUT |DEV_FLAGS_INPUT |DEV_FLAGS_SYSTEM ; dev.start = nc_start; dev.putc = nc_putc;
@@ -260,7 +262,7 @@ int drv_nc_init (void) dev.getc = nc_getc; dev.tstc = nc_tstc; - rc =stdio_register (&dev); + rc =stdio_register (&dev);return (rc ==0 ) ?1 : rc; }
Signature · 1 line
1.6.0.2
PATCH v2 10/10 net: cosmetic: netconsole.c checkpatch compliance
Quoted 7 lines · Joe Hershberger
Requires:
--ignoreCONSIDER_KSTRTOSigned-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
v2 cover Network stack cosmetic improvements
In reply to Joe HershbergerThis patch-series reorganizes some of the net code to make it easier to navigate and easier to leverage common functionality while encapsulating private implementation details. It also makes simple readability clean-ups.
This is dependant on the "Network stack checkpatch.pl compliance" patch-series.
This is a portion of the changes split from the series:
"Add link-local addressing support"
Joe Hershberger (21):
net: Remove CMD_PING where there's no CMD_NET
net: Remove redefinitions of net.h functions
net: Move MAC-seeded rand out of bootp.c
net: Move CDP out of net.c
net: Encapsulate CDP packet identification
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 IP_t
net: cosmetic: Un-typedef Ethernet_t
net: cosmetic: Un-typedef VLAN_Ethernet_t
net: cosmetic: Un-typedef ARP_t
net: cosmetic: Un-typedef ICMP_t
net: cosmetic: Rename parameter len to payload_len
net: cosmetic: Add a more explicit comment about 802.2
net: cosmetic: Rename "x" to "eth_proto"
net: cosmetic: Rename CDPHandler to CDPReceive
net: cosmetic: Rename OPT_SIZE to OPT_FIELD_SIZE
net: cosmetic: Alphabetize includes in net.c
net: cosmetic: Rename tmp to reply_ip_addr in arp.c
net: cosmetic: Replace magic numbers in arp.c with constants
arch/powerpc/cpu/mpc8260/ether_fcc.c | 17 +- arch/powerpc/cpu/mpc8xx/fec.c | 2 +- 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 - drivers/net/netconsole.c | 4 +- include/configs/am3517_crane.h | 2 +- include/configs/am3517_evm.h | 2 +- include/configs/origen.h | 2 +- include/net.h | 93 +++-- net/Makefile | 4 + net/arp.c | 213 ++++++++ net/arp.h | 30 ++ net/bootp.c | 87 +--- net/bootp.h | 10 +- net/cdp.c | 374 ++++++++++++++ net/cdp.h | 20 + net/dns.c | 2 +- net/net.c | 881 ++++------------------------------ net/net_rand.c | 68 +++ net/net_rand.h | 17 + net/nfs.c | 2 +- net/ping.c | 140 ++++++ net/ping.h | 23 + net/rarp.c | 49 ++- net/rarp.h | 6 +- net/sntp.c | 2 +- net/tftp.c | 2 +- 29 files changed, 1128 insertions(+), 932 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/net_rand.c create mode 100644 net/net_rand.h create mode 100644 net/ping.c create mode 100644 net/ping.h
v3 cover Network stack cosmetic improvements
This patch-series reorganizes some of the net code to make it easier to navigate and easier to leverage common functionality while encapsulating private implementation details. It also makes simple readability clean-ups.
This is dependant on the "Network stack checkpatch.pl compliance" patch-series.
This is a portion of the changes split from the series:
"Add link-local addressing support"
Joe Hershberger (21):
net: Remove CMD_PING where there's no CMD_NET
net: Move MAC-seeded rand out of bootp.c
net: Move CDP out of net.c
net: Encapsulate CDP packet identification
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 IP_t
net: cosmetic: Split struct ip_udp_hdr into ip_hdr
net: cosmetic: Un-typedef Ethernet_t
net: cosmetic: Un-typedef VLAN_Ethernet_t
net: cosmetic: Un-typedef ARP_t
net: cosmetic: Un-typedef ICMP_t
net: cosmetic: Rename parameter len to payload_len
net: cosmetic: Add a more explicit comment about 802.2
net: cosmetic: Rename "x" to "eth_proto"
net: cosmetic: Rename CDPHandler to cdp_receive
net: cosmetic: Rename OPT_SIZE to OPT_FIELD_SIZE
net: cosmetic: Alphabetize includes in net.c
net: cosmetic: Rename tmp to reply_ip_addr in arp.c
net: cosmetic: Replace magic numbers in arp.c with constants
arch/powerpc/cpu/mpc8260/ether_fcc.c | 17 +- arch/powerpc/cpu/mpc8xx/fec.c | 2 +- drivers/net/netconsole.c | 4 +- include/configs/am3517_crane.h | 2 +- include/configs/am3517_evm.h | 2 +- include/configs/origen.h | 2 +- include/net.h | 110 +++-- net/Makefile | 4 + net/arp.c | 213 ++++++++ net/arp.h | 30 ++ net/bootp.c | 83 +--- net/bootp.h | 10 +- net/cdp.c | 374 ++++++++++++++ net/cdp.h | 21 + net/dns.c | 2 +- net/net.c | 884 ++++------------------------------ net/net_rand.c | 68 +++ net/net_rand.h | 26 + net/nfs.c | 2 +- net/ping.c | 140 ++++++ net/ping.h | 34 ++ net/rarp.c | 55 ++- net/rarp.h | 7 +- net/sntp.c | 2 +- net/tftp.c | 2 +- 25 files changed, 1166 insertions(+), 930 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/net_rand.c create mode 100644 net/net_rand.h create mode 100644 net/ping.c create mode 100644 net/ping.h
PATCH v3 1/21 net: Remove CMD_PING where there's no CMD_NET
In reply to Joe HershbergerSome boards claim to need ping, but don't support net. That makes no sense, and causes problems now that ping is in a separate file.
---
Changes for v2:
- Separated from "Move PING out of net.c"
include/configs/am3517_crane.h | 2 +- include/configs/am3517_evm.h | 2 +- include/configs/origen.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
include/configs/am3517_crane.h +1 -1
@@ -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
@@ -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
@@ -83,7 +83,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
Signature · 1 line
1.6.0.2
PATCH v3 2/21 net: Move MAC-seeded rand out of bootp.c
In reply to Joe HershbergerMake the MAC-seeded random number generator available to /net in general. MAC-seeded rand will be needed by link-local as well, so give it an interface.
---
Changes for v3:
- Lowercase hex
- Add blank line
- Always include header, even when it isn't needed
- Add function comments
net/Makefile | 1 + net/bootp.c | 67 ++++++++++--------------------------------------------- net/bootp.h | 3 -- net/net_rand.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net_rand.h | 26 +++++++++++++++++++++ 5 files changed, 107 insertions(+), 58 deletions(-) create mode 100644 net/net_rand.c create mode 100644 net/net_rand.h
net/Makefile +1 -0
@@ -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 +12 -55
93 lines not on this page · raw message
net/bootp.h +0 -3
@@ -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 +26 -0
@@ -0,0 +1,26 @@ +/* +* 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 + +/* +* Seed the random number generator using the eth0 MAC address +*/ +void srand_mac (void ); + +/* +* Get a random number (after seeding with MAC address) +* +* @return random number +*/ +unsigned long rand (void ); + +#endif /* __NET_RAND_H__ */
Signature · 1 line
1.6.0.2
PATCH v3 2/21 net: Move MAC-seeded rand out of bootp.c
Am Mittwoch 23 Mai 2012, 19:57:58 schrieb Joe Hershberger:
Quoted 1 line
t_ran
Signature · 9 lines
Mit freundlichen Gr??en, Michael Walle In den Rohrwiesen 1a 66440 Blieskastel michael at walle.cc --- Don't cry because it is over, smile because it happened.
PATCH v3 2/21 net: Move MAC-seeded rand out of bootp.c
In reply to Joe Hershberger[sorry for my first mail.. wasn't intented to be send]
Sorry for being too late on this.
Am Mittwoch 23 Mai 2012, 19:57:58 schrieb Joe Hershberger:
Quoted 24 lines
Make the MAC-seeded random number generator available to /net in general. MAC-seeded rand will be needed by link-local as well, so give it an interface.
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>---
Changes for v3:
- Lowercase hex
- Add blank line
- Always include header, even when it isn't needed
- Add function commentsnet/Makefile | 1 + net/bootp.c | 67 ++++++++++--------------------------------------------- net/bootp.h | 3 -- net/net_rand.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net_rand.h | 26 +++++++++++++++++++++ 5 files changed, 107 insertions(+), 58 deletions(-) create mode 100644 net/net_rand.c create mode 100644 net/net_rand.h
[..]
Quoted 37 lines
net/bootp.h +0
-3@@ -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 +17
-0@@ -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 )
net/net_rand.c line 27
Quoted 10 lines
net/net_rand.c new file +10
-0+{ +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: " );
mh? this shouldn't be here anymore should it?
Quoted 31 lines
net/net_rand.c new file +31
-0+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;
net/net_rand.c line 68
Quoted 10 lines
net/net_rand.c new file +10
-0+ +/* Random Number Generator */ + sum = seed1 + seed2; +if (sum < seed1 || sum < seed2) + sum++; + seed2 = seed1; + seed1 = sum; + +return sum; +}
is this really random? this conflicts with my patch (lib/rand.c) i'm trying to put into upstream.
Quoted 22 lines
net/net_rand.h new file +16
-0@@ -0,0 +1,26 @@ +/* +* 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 + +/* +* Seed the random number generator using the eth0 MAC address +*/
net/net_rand.h line 26
Quoted 10 lines
net/net_rand.h new file +10
-0+void srand_mac (void ); + +/* +* Get a random number (after seeding with MAC address) +* +* @return random number +*/ +unsigned long rand (void ); + +#endif /* __NET_RAND_H__ */
if this is unconditionally included, my patch fails because there are multiple declarations of rand().
Can we unify this with my patch, which is based on a paper about PRNGs? Eg. use the rand()/srand() from my patch and create an srand_mac() inline function which uses srand() from lib/rand.c ?
Joe, if that is ok, i'll put that into the next version of my "lsxl: add support for lschlv2 and lsxhl" patch series.
Signature · 1 line
Michael
PATCH v3 2/21 net: Move MAC-seeded rand out of bootp.c
Hi Michael,
Quoted 58 lines · Michael Walle
[sorry for my first mail.. wasn't intented to be send]
Sorry for being too late on this.
Am Mittwoch 23 Mai 2012, 19:57:58 schrieb Joe Hershberger:
Quoted 24 lines
Make the MAC-seeded random number generator available to /net in general. ?MAC-seeded rand will be needed by link-local as well, so give it an interface.
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>---
Changes for v3:
? - Lowercase hex
? - Add blank line
? - Always include header, even when it isn't needed ? - Add function comments?net/Makefile ? | ? ?1 +
?net/bootp.c ? ?| ? 67 ++++++++++---------------------------------------------net/bootp.h? ?| ?3 --
?net/net_rand.c | ? 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++net/net_rand.h| ?26 +++++++++++++++++++++
?5 files changed, 107 insertions(+), 58 deletions(-)
?create mode 100644net/net_rand.c
?create mode 100644net/net_rand.h[..]
Quoted 26 lines
net/net_rand.c new file +20
-0@@ -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;
Quoted 8 lines
net/net_rand.c line 27
Quoted 7 lines
net/net_rand.c new file +7
-0+ ? ? int reg; + ? ? unsigned char bi_enetaddr[6]; + + ? ? /* get our mac */ + ? ? eth_getenv_enetaddr("ethaddr", bi_enetaddr); + + ? ? debug("BootpRequest => Our Mac: ");mh? this shouldn't be here anymore should it?
Yes... It's not very appropriate any longer.
Quoted 35 lines
Quoted 35 lines
net/net_rand.c new file +35
-0+ ? ? 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)
Quoted 8 lines
net/net_rand.c line 68
Quoted 6 lines
net/net_rand.c new file +6
-0+ ? ? ? ? ? ? sum++; + ? ? seed2 = seed1; + ? ? seed1 = sum; + + ? ? return sum; +}is this really random?
It was the implementation used for bootp delays. It is some form of PRNG... just not the same as what you've implemented.
Quoted 2 lines
this conflicts with my patch (
lib/rand.c) i'm trying to put into upstream.
True.
Quoted 36 lines
Quoted 22 lines
net/net_rand.h new file +16
-0@@ -0,0 +1,26 @@ +/* +* ? 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 + +/* +* Seed the random number generator using the eth0 MAC address +*/ net/net_rand.h line 26
Quoted 10 lines
net/net_rand.h new file +10
-0+void srand_mac (void ); + +/* +* Get a random number (after seeding with MAC address) +* +* @return random number +*/ +unsigned long rand (void ); + +#endif /* __NET_RAND_H__ */ if this is unconditionally included, my patch fails because there are multiple declarations of
rand().
Quoted 3 lines
Can we unify this with my patch, which is based on a paper about PRNGs? Eg. use the rand()/srand() from my patch and create an
srand_mac()inline function which usessrand()fromlib/rand.c?
If you can verify that the functionality of the CONFIG_BOOTP_RANDOM_DELAY and CONFIG_CMD_LINK_LOCAL are uneffected, then I'm OK with it.
One thing to note is that the link-local implementation needs to use a MAC seeded random number. That means we can't have other things coming in and seeding it with a time. It is nice that it is separate for that reason. Can you solve that and integrate it with your PRNG?
Quoted 2 lines
Joe, if that is ok, i'll put that into the next version of my "lsxl: add support for lschlv2 and lsxhl" patch series.
I'm certainly willing to look at what you come up with.
Thanks,
-Joe
PATCH v3 2/21 net: Move MAC-seeded rand out of bootp.c
Hi Joe,
Am Dienstag 29 Mai 2012, 20:08:26 schrieb Joe Hershberger:
Quoted 165 lines
Hi Michael,
Quoted 59 lines · Michael Walle
[sorry for my first mail.. wasn't intented to be send]
Sorry for being too late on this.
Am Mittwoch 23 Mai 2012, 19:57:58 schrieb Joe Hershberger:
Quoted 23 lines
Make the MAC-seeded random number generator available to /net in general. MAC-seeded rand will be needed by link-local as well, so give it an interface.
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>---
Changes for v3:
- Lowercase hex
- Add blank line
- Always include header, even when it isn't needed
- Add function commentsnet/Makefile | 1 + net/bootp.c | 67 ++++++++++--------------------------------------------- net/bootp.h | 3 -- net/net_rand.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net_rand.h | 26 +++++++++++++++++++++ 5 files changed, 107 insertions(+), 58 deletions(-) create mode 100644 net/net_rand.c create mode 100644 net/net_rand.h[..]
Quoted 27 lines
net/net_rand.c new file +21
-0@@ -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;Quoted 8 lines
net/net_rand.c line 27
Quoted 6 lines
net/net_rand.c new file +6
-0+unsigned char bi_enetaddr[6 ]; + +/* get our mac */ +eth_getenv_enetaddr ("ethaddr" , bi_enetaddr); + +debug ("BootpRequest => Our Mac: " );mh? this shouldn't be here anymore should it?
Yes... It's not very appropriate any longer.
Quoted 35 lines
Quoted 35 lines
net/net_rand.c new file +35
-0+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)Quoted 8 lines
net/net_rand.c line 68
Quoted 6 lines
net/net_rand.c new file +6
-0+ sum++; + seed2 = seed1; + seed1 = sum; + +return sum; +}is this really random?
It was the implementation used for bootp delays. It is some form of PRNG... just not the same as what you've implemented.
Quoted 2 lines
this conflicts with my patch (
lib/rand.c) i'm trying to put into upstream.True.
Quoted 36 lines
Quoted 22 lines
net/net_rand.h new file +16
-0@@ -0,0 +1,26 @@ +/* +* 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 + +/* +* Seed the random number generator using the eth0 MAC address +*/ net/net_rand.h line 26
Quoted 10 lines
net/net_rand.h new file +10
-0+void srand_mac (void ); + +/* +* Get a random number (after seeding with MAC address) +* +* @return random number +*/ +unsigned long rand (void ); + +#endif /* __NET_RAND_H__ */ if this is unconditionally included, my patch fails because there are multiple declarations of
rand().Quoted 3 lines
Can we unify this with my patch, which is based on a paper about PRNGs? Eg. use the rand()/srand() from my patch and create an
srand_mac()inline function which usessrand()fromlib/rand.c?
Quoted 8 lines
If you can verify that the functionality of the
CONFIG_BOOTP_RANDOM_DELAYandCONFIG_CMD_LINK_LOCALare uneffected, then I'm OK with it.One thing to note is that the link-local implementation needs to use a MAC seeded random number. That means we can't have other things coming in and seeding it with a time. It is nice that it is separate for that reason. Can you solve that and integrate it with your PRNG?
I'm in a hurry, short answer for now:
I thought of sth like this:
static inline void srand_mac(void)
{
unsigned char enetaddr[6];
unsigned int seed;
/* get our mac */
eth_getenv_enetaddr("ethaddr", enetaddr);
seed = enetaddr[5];
seed |= enetaddr[4] << 8;
seed |= enetaddr[3] << 16;
seed |= enetaddr[2] << 24;
srand(seed);
}Signature · 1 line
Michael
PATCH v3 2/21 net: Move MAC-seeded rand out of bootp.c
Hi Michael,
Quoted 23 lines · Michael Walle
Hi Joe,
Am Dienstag 29 Mai 2012, 20:08:26 schrieb Joe Hershberger:
Quoted 8 lines
If you can verify that the functionality of the
CONFIG_BOOTP_RANDOM_DELAYandCONFIG_CMD_LINK_LOCALare uneffected, then I'm OK with it.One thing to note is that the link-local implementation needs to use a MAC seeded random number. ?That means we can't have other things coming in and seeding it with a time. ?It is nice that it is separate for that reason. ?Can you solve that and integrate it with your PRNG?
I'm in a hurry, short answer for now:
I thought of sth like this:static inline void
srand_mac(void)
{
? ? ? ?unsigned char enetaddr[6];
? ? ? ?unsigned int seed;? ? ? ?/* get our mac */
? ? ? ?eth_getenv_enetaddr("ethaddr", enetaddr);
Quoted 7 lines
? ? ? ?seed = enetaddr[5];
? ? ? ?seed |= enetaddr[4] << 8; ? ? ? ?seed |= enetaddr[3] << 16; ? ? ? ?seed |= enetaddr[2] << 24;? ? ? ?srand(seed);
}
I'm not sure why you are only seeding with the last 4 bytes of the MAC. The original algorithm used all 6 (in its way). You also haven't addressed the issue of isolating the link-local algorithm from other non-MAC-seeded random numbers. The most naive way around it would be to rename the rand() in net to rand_mac() or something like that and not attempt to combine them.
-Joe
PATCH v3 2/21 net: Move MAC-seeded rand out of bootp.c
Hi Joe,
Am Dienstag 29 Mai 2012, 23:08:23 schrieb Joe Hershberger:
Quoted 31 lines
Hi Michael,
Quoted 28 lines · Michael Walle
Hi Joe,
Am Dienstag 29 Mai 2012, 20:08:26 schrieb Joe Hershberger:
Quoted 8 lines
If you can verify that the functionality of the
CONFIG_BOOTP_RANDOM_DELAYandCONFIG_CMD_LINK_LOCALare uneffected, then I'm OK with it.One thing to note is that the link-local implementation needs to use a MAC seeded random number. That means we can't have other things coming in and seeding it with a time. It is nice that it is separate for that reason. Can you solve that and integrate it with your PRNG?
I'm in a hurry, short answer for now:
I thought of sth like this:static inline void
srand_mac(void){ unsigned char enetaddr[6]; unsigned int seed; /* get our mac */ eth_getenv_enetaddr("ethaddr", enetaddr); seed = enetaddr[5]; seed |= enetaddr[4] << 8; seed |= enetaddr[3] << 16; seed |= enetaddr[2] << 24;
Quoted 5 lines
Quoted 2 lines
srand(seed); }I'm not sure why you are only seeding with the last 4 bytes of the MAC. The original algorithm used all 6 (in its way).
yeah i'll fix that.
Quoted 2 lines
You also haven't addressed the issue of isolating the link-local algorithm from other non-MAC-seeded random numbers.
Ah now i get it. But which other code may run and seed the NG with the timer only, while we are in the link local netloop? Shouldn't it be safe to first call srand(mac+timer) and then rand() multiple times? No other code can be run unless NetLoop(LINKLOCAL) returns, right?
Quoted 3 lines
The most naive way around it
would be to rename therand()in net torand_mac()or something like that and not attempt to combine them.
i think we should focus on combining not reinventing the wheel multiple times.
Signature · 1 line
Michael
PATCH v3 2/21 net: Move MAC-seeded rand out of bootp.c
Hi Michael,
Quoted 43 lines · Michael Walle
Hi Joe,
Am Dienstag 29 Mai 2012, 23:08:23 schrieb Joe Hershberger:
Quoted 31 lines
Hi Michael,
Quoted 28 lines · Michael Walle
Hi Joe,
Am Dienstag 29 Mai 2012, 20:08:26 schrieb Joe Hershberger:
Quoted 8 lines
If you can verify that the functionality of the
CONFIG_BOOTP_RANDOM_DELAYandCONFIG_CMD_LINK_LOCALare uneffected, then I'm OK with it.One thing to note is that the link-local implementation needs to use a MAC seeded random number. ?That means we can't have other things coming in and seeding it with a time. ?It is nice that it is separate for that reason. ?Can you solve that and integrate it with your PRNG?
I'm in a hurry, short answer for now:
I thought of sth like this:static inline void
srand_mac(void)
{
? ? ? ?unsigned char enetaddr[6];
? ? ? ?unsigned int seed;? ? ? ?/* get our mac */
? ? ? ?eth_getenv_enetaddr("ethaddr", enetaddr);? ? ? ?seed = enetaddr[5];
? ? ? ?seed |= enetaddr[4] << 8; ? ? ? ?seed |= enetaddr[3] << 16; ? ? ? ?seed |= enetaddr[2] << 24;Quoted 5 lines
Quoted 2 lines
? ? ? ?srand(seed);
}I'm not sure why you are only seeding with the last 4 bytes of the MAC. ?The original algorithm used all 6 (in its way).
yeah i'll fix that.
Quoted 6 lines
Quoted 2 lines
You also haven't addressed the issue of isolating the link-local algorithm from other non-MAC-seeded random numbers.
Ah now i get it. But which other code may run and seed the NG with the timer only, while we are in the link local netloop? Shouldn't it be safe to first call srand(mac+timer) and then
rand()multiple times? No other code can be run unless NetLoop(LINKLOCAL) returns, right?
It needs to run multiple times, yes. But it will also process any packets that are received when executing any other net command later. The state machine will keep running. There can obviously be other commands that run in between.
Perhaps we can separate the state for the PRNG between the 2 cases but share the code.
Quoted 4 lines
Quoted 3 lines
The most naive way around it
would be to rename therand()in net torand_mac()or something like that and not attempt to combine them.i think we should focus on combining not reinventing the wheel multiple times.
Agreed, but we have to solve the problem above.
Thanks,
-Joe
PATCH v3 2/21 net: Move MAC-seeded rand out of bootp.c
Hi Joe,
Am Mittwoch 30 Mai 2012, 00:40:18 schrieb Joe Hershberger:
Quoted 9 lines
Quoted 4 lines
Ah now i get it. But which other code may run and seed the NG with the timer only, while we are in the link local netloop? Shouldn't it be safe to first call srand(mac+timer) and then
rand()multiple times? No other code can be run unless NetLoop(LINKLOCAL) returns, right?It needs to run multiple times, yes. But it will also process any packets that are received when executing any other net command later. The state machine will keep running. There can obviously be other commands that run in between.
i guess i have to study the netloop a bit more ;)
Quoted 3 lines
Perhaps we can separate the state for the PRNG between the 2 cases but share the code.
yeah i was thinking of rand_r().
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
The most naive way around it
would be to rename therand()in net torand_mac()or something like that and not attempt to combine them.i think we should focus on combining not reinventing the wheel multiple times.
Agreed, but we have to solve the problem above.
fully argreeing ;)
Signature · 1 line
michael
PATCH v3 3/21 net: Move CDP out of net.c
In reply to Joe HershbergerSeparate this functionality out of the net.c behemoth
---
Changes for v2:
- Moved is_cdp_packet to a separate patch
- Fixed blank newline at the end of cdp.h
- Pushed #ifdef CONFIG_CMD_CDP into header
Changes for v3:
- Fix comment style
- Clean up format of array initializer
- Added a short commit message
include/net.h | 8 +- net/Makefile | 1 + net/cdp.c | 375 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/cdp.h | 20 +++ net/net.c | 366 +------------------------------------------------------- 5 files changed, 400 insertions(+), 370 deletions(-) create mode 100644 net/cdp.c create mode 100644 net/cdp.h
include/net.h +3 -5
@@ -356,9 +356,7 @@ 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 const uchar NetCDPAddr[6 ];/* Ethernet CDP address */ extern int NetState;/* Network loop state */ #define NETLOOP_CONTINUE 1
@@ -387,8 +385,8 @@ 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 */ #endif #if defined(CONFIG_CMD_SNTP )
net/Makefile +1 -0
@@ -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 +375 -0
375 lines not on this page · raw message
net/cdp.h new file +20 -0
@@ -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, [email protected] +*/ + +#if defined(CONFIG_CMD_CDP ) + +#ifndef __CDP_H__ +#define __CDP_H__ + +void CDPStart (void ); +void CDPHandler (const uchar *pkt,unsigned len); + +#endif /* __CDP_H__ */ +#endif
net/net.c +1 -365
390 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH v3 4/21 net: Encapsulate CDP packet identification
In reply to Joe HershbergerChecking for CDP packets should be encapsulated, not copied code.
---
Changes for v2:
- Split from patch "Move CDP out of net.c"
- Changed to static inline
Changes for v3:
- Added a function comment
- Added a blank line
arch/powerpc/cpu/mpc8xx/fec.c | 2 +- include/net.h | 12 ++++++++++-- net/net.c | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-)
arch/powerpc/cpu/mpc8xx/fec.c +1 -1
@@ -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 +10 -2
@@ -356,8 +356,6 @@ extern uchar NetEtherNullAddr[6];extern ushort NetOurVLAN;/* Our VLAN */ extern ushort NetOurNativeVLAN;/* Our Native VLAN */ -extern const uchar NetCDPAddr[6 ];/* Ethernet CDP address */ -extern int NetState;/* Network loop state */ #define NETLOOP_CONTINUE 1#define NETLOOP_RESTART 2
@@ -387,6 +385,16 @@ extern IPaddr_t NetPingIP; /* the ip address to ping *//* when CDP completes these hold the return values */ extern ushort CDPNativeVLAN;/* CDP returned native VLAN */ extern ushort CDPApplianceVLAN;/* CDP returned appliance VLAN */ + +/* +* Check for a CDP packet by examining the received MAC address field +*/ +static inline int is_cdp_packet (const uchar *et_addr) +{ +extern const uchar NetCDPAddr[6 ]; + +return memcmp (et_addr, NetCDPAddr,6 ) ==0 ; +}#endif #if defined(CONFIG_CMD_SNTP )
net/net.c +1 -1
@@ -1099,7 +1099,7 @@ NetReceive(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);
Signature · 1 line
1.6.0.2
PATCH v3 5/21 net: Move ARP out of net.c
In reply to Joe HershbergerSeparate this functionality out of the net.c behemoth
---
Changes for v2:
Changes for v3:
- Added a short commit message
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
@@ -428,7 +428,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
@@ -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
@@ -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 <common.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
PATCH v3 6/21 net: Move PING out of net.c
In reply to Joe HershbergerSeparate this functionality out of the net.c behemoth
---
Changes for v2:
- Moved config fixes to a separate patch
- Pushed #ifdef CONFIG_CMD_PING into header
- Eliminated CamelCase
Changes for v3:
- Added function comments
- Added a short commit message
net/Makefile | 1 + net/net.c | 133 ++----------------------------------------------------- net/ping.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/ping.h | 34 ++++++++++++++ 4 files changed, 179 insertions(+), 129 deletions(-) create mode 100644 net/ping.c create mode 100644 net/ping.h
net/Makefile +1 -0
@@ -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 +4 -129
165 lines not on this page · raw message
net/ping.c new file +140 -0
140 lines not on this page · raw message
net/ping.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* 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 +*/ + +#if defined(CONFIG_CMD_PING ) + +#ifndef __PING_H__ +#define __PING_H__ + +#include <common.h> +#include <net.h> + +/* +* Initialize ping (beginning of netloop) +*/ +void ping_start (void ); + +/* +* Deal with the receipt of a ping packet +* +* @param et Ethernet header in packet +* @param ip IP header in the same packet +* @param len Packet length +*/ +void ping_receive (Ethernet_t *et,IP_t *ip,int len); + +#endif /* __PING_H__ */ +#endif
Signature · 1 line
1.6.0.2
PATCH v3 7/21 net: Move RARP receive logic out of net.c
In reply to Joe HershbergerSeparate this functionality out of the net.c behemoth
---
Changes for v2:
- Moved void to the same line as function
- Eliminate CamelCase in new function name
Changes for v3:
- Removed extra spaces
- Added a function comment
- Added a short commit message
net/net.c | 27 +-------------------------- net/rarp.c | 51 ++++++++++++++++++++++++++++++++------------------- net/rarp.h | 7 ++++--- 3 files changed, 37 insertions(+), 48 deletions(-)
net/net.c +1 -26
@@ -82,9 +82,7 @@#include "arp.h" #include "bootp.h" #include "tftp.h" -#ifdef CONFIG_CMD_RARP #include "rarp.h" -#endif #include "nfs.h" #ifdef CONFIG_STATUS_LED #include <status_led.h>
@@ -853,9 +851,6 @@ NetReceive(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;
@@ -960,27 +955,7 @@ NetReceive(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 ); - } +rarp_receive (ip, len);break ;#endif case PROT_IP :
net/rarp.c +32 -19
87 lines not on this page · raw message
net/rarp.h +4 -3
@@ -21,14 +21,12 @@* MA 02111-1307 USA */ +#if defined(CONFIG_CMD_RARP )#ifndef __RARP_H__#define __RARP_H__ -#ifndef __NET_H__#include <net.h> -#endif /* __NET_H__ */ -/**********************************************************************/ /*
@@ -37,8 +35,11 @@extern int RarpTry; +/* Process the receipt of a RARP packet */ +extern void rarp_receive (IP_t *ip,unsigned len);extern void RarpRequest (void );/* Send a RARP request */ /**********************************************************************/ #endif /* __RARP_H__ */ +#endif
Signature · 1 line
1.6.0.2
PATCH v3 8/21 net: cosmetic: Un-typedef IP_t
In reply to Joe HershbergerRename IP header related things to IP_UDP. The existing definition of IP_t includes UDP header, so name it to accurately describe the structure.
---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Created a new IP_UDP_hdr struct and removed UDP members from IP_hdr
- Renamed structs from *_t to *_hdr since they are nolonger types
Changes for v3:
- Change IP_UDP_hdr to ip_udp_hdr
- Split out the new ip_hdr to the next patch
drivers/net/netconsole.c | 4 +- include/net.h | 11 ++++--- net/arp.c | 2 +- net/arp.h | 2 +- net/bootp.c | 4 +- net/bootp.h | 2 +- net/dns.c | 2 +- net/net.c | 62 +++++++++++++++++++++++---------------------- net/nfs.c | 2 +- net/ping.c | 6 ++-- net/ping.h | 2 +- net/rarp.c | 2 +- net/rarp.h | 2 +- net/sntp.c | 2 +- net/tftp.c | 2 +- 15 files changed, 55 insertions(+), 52 deletions(-)
drivers/net/netconsole.c +2 -2
@@ -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 +6 -5
@@ -194,9 +194,9 @@ typedef struct {#define IPPROTO_UDP 17/* User Datagram Protocol */ /* -* Internet Protocol (IP) header. +* Internet Protocol (IP) + UDP header. */ -typedef struct { +struct ip_udp_hdr {uchar ip_hl_v;/* header length and version */ uchar ip_tos;/* type of service */ ushort ip_len;/* total length */
@@ -211,7 +211,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 */
@@ -219,9 +219,10 @@ 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(struct ip_udp_hdr) - 8) +#define IP_UDP_HDR_SIZE (sizeof(struct ip_udp_hdr)) +#define UDP_HDR_SIZE (IP_UDP_HDR_SIZE - IP_HDR_SIZE_NO_UDP)/* * Address Resolution Protocol (ARP) header.
net/arp.c +1 -1
@@ -113,7 +113,7 @@ void ArpTimeoutCheck(void) } } -void ArpReceive (Ethernet_t *et,IP_t *ip,int len) +void ArpReceive (Ethernet_t *et,struct ip_udp_hdr *ip,int len) {ARP_t *arp;IPaddr_t tmp;
net/arp.h +1 -1
@@ -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 (Ethernet_t *et,struct ip_udp_hdr *ip,int len);#endif /* __ARP_H__ */
net/bootp.c +2 -2
@@ -622,7 +622,7 @@ 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 ; + 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
@@ -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/dns.c +1 -1
@@ -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 +32 -30
167 lines not on this page · raw message
net/nfs.c +1 -1
@@ -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 +3 -3
@@ -19,7 +19,7 @@ IPaddr_t NetPingIP;static int ping_send (void ) {static uchar mac[6 ]; -IP_t *ip; +struct ip_udp_hdr *ip;ushort *s;uchar *pkt;
@@ -35,7 +35,7 @@ static int ping_send(void) pkt = NetArpWaitTxPacket; pkt +=NetSetEther (pkt, mac,PROT_IP ); - ip = (IP_t *)pkt; + ip = (struct ip_udp_hdr *)pkt;/* * Construct an IP and ICMP header.
@@ -98,7 +98,7 @@ void ping_start(void)ping_send (); } -void ping_receive (Ethernet_t *et,IP_t *ip,int len) +void ping_receive (Ethernet_t *et,struct ip_udp_hdr *ip,int len) {ICMP_t *icmph = (ICMP_t *)&(ip->udp_src);IPaddr_t src_ip;
net/ping.h +1 -1
@@ -28,7 +28,7 @@ void ping_start(void);* @param ip IP header in the same packet * @param len Packet length */ -void ping_receive (Ethernet_t *et,IP_t *ip,int len); +void ping_receive (Ethernet_t *et,struct ip_udp_hdr *ip,int len);#endif /* __PING_H__ */ #endif
net/rarp.c +1 -1
@@ -41,7 +41,7 @@ int RarpTry;/* * Handle a RARP received packet. */ -void rarp_receive (IP_t *ip,unsigned len) +void rarp_receive (struct ip_upd_hdr *ip,unsigned len) {ARP_t *arp;
net/rarp.h +1 -1
@@ -36,7 +36,7 @@extern int RarpTry;/* Process the receipt of a RARP packet */ -extern void rarp_receive (IP_t *ip,unsigned len); +extern void rarp_receive (struct ip_upd_hdr *ip,unsigned len);extern void RarpRequest (void );/* Send a RARP request */ /**********************************************************************/
net/sntp.c +1 -1
@@ -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
@@ -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
PATCH v3 8/21 net: cosmetic: Un-typedef IP_t
Hi Joe,
On Wed, 23 May 2012 12:58:04 -0500
Joe Hershberger <[email protected]> wrote:
...
net/rarp.c int RarpTry; · line 44
Quoted 8 lines
net/rarp.c +1
-1@@ -41,7 +41,7 @@ int RarpTry;/* * Handle a RARP received packet. */ -void rarp_receive (IP_t *ip,unsigned len) +void rarp_receive (struct ip_upd_hdr *ip,unsigned len)
Typo, s/ip_upd_hdr/ip_udp_hdr/
...
net/rarp.h line 39
Quoted 8 lines
net/rarp.h +1
-1@@ -36,7 +36,7 @@extern int RarpTry;/* Process the receipt of a RARP packet */ -extern void rarp_receive (IP_t *ip,unsigned len); +extern void rarp_receive (struct ip_upd_hdr *ip,unsigned len);
Typo, s/ip_upd_hdr/ip_udp_hdr/
It breaks compiling with CONFIG_CMD_RARP defined.
Thanks,
Anatolij
PATCH v3 8/21 net: cosmetic: Un-typedef IP_t
Hi Anatolij,
Quoted 22 lines · Anatolij Gustschin
Hi Joe,
On Wed, 23 May 2012 12:58:04 -0500
Joe Hershberger <[email protected]> wrote:
...net/rarp.c int RarpTry; · line 44
Quoted 8 lines
net/rarp.c +0
-0@@ -41,7 +41,7 @@ int RarpTry;?/*
? * ? Handle a RARP received packet.
? */net/rarp.c +1
-1-void rarp_receive (IP_t *ip,unsigned len) +void rarp_receive (struct ip_upd_hdr *ip,unsigned len)Typo, s/ip_upd_hdr/ip_udp_hdr/
...
Quoted 5 lines
net/rarp.h +0
-0@@ -36,7 +36,7 @@ ?extern int RarpTry;
Quoted 7 lines
net/rarp.h line 39
Quoted 3 lines
?/* Process the receipt of a RARP packet */
net/rarp.h +1
-1-extern void rarp_receive (IP_t *ip,unsigned len); +extern void rarp_receive (struct ip_upd_hdr *ip,unsigned len);Typo, s/ip_upd_hdr/ip_udp_hdr/
It breaks compiling with
CONFIG_CMD_RARPdefined.
Apparently I didn't build test the ethernut5 target since that last round of changes.
I think I'll just fix it inline instead of spamming the mailing list with the whole series again.
Thanks,
-Joe
PATCH v3 9/21 net: cosmetic: Split struct ip_udp_hdr into ip_hdr
In reply to Joe HershbergerAdd a structure that only contains IP header fields to be used by functions that don't need UDP
Rename IP_HDR_SIZE_NO_UDP to IP_HDR_SIZE
---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Created a new IP_UDP_hdr struct and removed UDP members from IP_hdr
- Renamed structs from *_t to *_hdr since they are nolonger types
Changes for v3:
- Change IP_hdr to ip_hdr
- Split this out from the previous patch
include/net.h | 32 ++++++++++++++++++++++++-------- net/net.c | 16 ++++++++-------- net/ping.c | 10 +++++----- 3 files changed, 37 insertions(+), 21 deletions(-)
include/net.h +24 -8
@@ -194,9 +194,9 @@ typedef struct {#define IPPROTO_UDP 17/* User Datagram Protocol */ /* -* Internet Protocol (IP) + UDP header. +* Internet Protocol (IP) header. */ -struct ip_udp_hdr { +struct ip_hdr {uchar ip_hl_v;/* header length and version */ uchar ip_tos;/* type of service */ ushort ip_len;/* total length */
@@ -207,10 +207,6 @@ struct ip_udp_hdr {ushort ip_sum;/* checksum */ IPaddr_t ip_src;/* Source IP address */ IPaddr_t ip_dst;/* Destination IP address */ -ushort udp_src;/* UDP source port */ -ushort udp_dst;/* UDP destination port */ -ushort udp_len;/* Length of UDP packet */ -ushort udp_xsum;/* Checksum */ };#define IP_OFFS 0x1fff/* ip offset *= 8 */
@@ -219,10 +215,30 @@ struct ip_udp_hdr {#define IP_FLAGS_DFRAG 0x4000/* don't fragments */ #define IP_FLAGS_MFRAG 0x2000/* more fragments */ -#define IP_HDR_SIZE_NO_UDP (sizeof(struct ip_udp_hdr) - 8) +#define IP_HDR_SIZE (sizeof(struct ip_hdr)) + +/* +* Internet Protocol (IP) + UDP header. +*/ +struct ip_udp_hdr { +uchar ip_hl_v;/* header length and version */ +uchar ip_tos;/* type of service */ +ushort ip_len;/* total length */ +ushort ip_id;/* identification */ +ushort ip_off;/* fragment offset field */ +uchar ip_ttl;/* time to live */ +uchar ip_p;/* protocol */ +ushort ip_sum;/* checksum */ +IPaddr_t ip_src;/* Source IP address */ +IPaddr_t ip_dst;/* Destination IP address */ +ushort udp_src;/* UDP source port */ +ushort udp_dst;/* UDP destination port */ +ushort udp_len;/* Length of UDP packet */ +ushort udp_xsum;/* Checksum */ +};#define IP_UDP_HDR_SIZE (sizeof(struct ip_udp_hdr)) -#define UDP_HDR_SIZE (IP_UDP_HDR_SIZE - IP_HDR_SIZE_NO_UDP) +#define UDP_HDR_SIZE (IP_UDP_HDR_SIZE - IP_HDR_SIZE)/* * Address Resolution Protocol (ARP) header.
net/net.c +8 -8
@@ -663,7 +663,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)static struct rpc_t rpc_specimen;#define IP_PKTSIZE (CONFIG_NET_MAXDEFRAG + sizeof(rpc_specimen.u.reply)) -#define IP_MAXUDP (IP_PKTSIZE - IP_HDR_SIZE_NO_UDP) +#define IP_MAXUDP (IP_PKTSIZE - IP_HDR_SIZE)/* * this is the packet being assembled, either data or frag control.
@@ -688,11 +688,11 @@ static struct ip_udp_hdr *__NetDefragment(struct ip_udp_hdr *ip, int *lenp)u16 ip_off =ntohs (ip->ip_off);/* payload starts after IP header, this fragment is in there */ - payload = (struct hole *)(pkt_buff +IP_HDR_SIZE_NO_UDP ); + payload = (struct hole *)(pkt_buff +IP_HDR_SIZE ); offset8 = (ip_off &IP_OFFS ); thisfrag = payload + offset8; start = offset8 *8 ; - len =ntohs (ip->ip_len) -IP_HDR_SIZE_NO_UDP ; + len =ntohs (ip->ip_len) -IP_HDR_SIZE ;if (start + len >IP_MAXUDP )/* fragment extends too far */ return NULL ;
@@ -705,7 +705,7 @@ static struct ip_udp_hdr *__NetDefragment(struct ip_udp_hdr *ip, int *lenp) payload[0 ].prev_hole =0 ; first_hole =0 ;/* any IP header will work, copy the first we received */ -memcpy (localip, ip,IP_HDR_SIZE_NO_UDP ); +memcpy (localip, ip,IP_HDR_SIZE ); }/*
@@ -788,12 +788,12 @@ static struct ip_udp_hdr *__NetDefragment(struct ip_udp_hdr *ip, int *lenp) }/* finally copy this fragment and possibly return whole packet */ -memcpy ((uchar *)thisfrag, indata +IP_HDR_SIZE_NO_UDP , len); +memcpy ((uchar *)thisfrag, indata +IP_HDR_SIZE , len);if (!done)return NULL ; localip->ip_len =htons (total_len); - *lenp = total_len +IP_HDR_SIZE_NO_UDP ; + *lenp = total_len +IP_HDR_SIZE ;return localip; }
@@ -983,7 +983,7 @@ NetReceive(uchar *inpkt, int len)if ((ip->ip_hl_v &0x0f ) >0x05 )return ;/* Check the Checksum of the header */ -if (!NetCksumOk ((uchar *)ip,IP_HDR_SIZE_NO_UDP /2 )) { +if (!NetCksumOk ((uchar *)ip,IP_HDR_SIZE /2 )) {puts ("checksum bad\n" );return ; }
@@ -1273,7 +1273,7 @@ void NetSetIP(uchar *xip, IPaddr_t dest, int dport, int sport, int len) 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_NO_UDP /2 ); + ip->ip_sum = ~NetCksum ((uchar *)ip,IP_HDR_SIZE /2 ); }void copy_filename (char *dst,const char *src,int size)
net/ping.c +5 -5
@@ -44,7 +44,7 @@ static int ping_send(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 ping_send(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 ping_send(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 ;
@@ -125,12 +125,12 @@ void ping_receive(Ethernet_t *et, struct ip_udp_hdr *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 ;
Signature · 1 line
1.6.0.2
PATCH v3 10/21 net: cosmetic: Un-typedef Ethernet_t
In reply to Joe HershbergerSeparate the Ethernet header from the 802 header.
Base the size constants on the structs.
---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Created a new E802_hdr struct and removed 802 members from Ethernet_hdr
- Renamed structs from *_t to *_hdr since they are nolonger types
- Replaced offsetof(Ethernet_t, et_dsap) with ETHER_HDR_SIZE in arch/powerpc/cpu/mpc8260/ether_fcc.c
Changes for v3:
- Renamed Ethernet_hdr to ethernet_hdr
- Renamed E802_hdr to e802_hdr
arch/powerpc/cpu/mpc8260/ether_fcc.c | 17 ++++++++--------- include/net.h | 18 ++++++++++++++---- net/arp.c | 4 ++-- net/arp.h | 2 +- net/bootp.c | 2 +- net/cdp.c | 4 ++-- net/net.c | 11 ++++++----- net/ping.c | 2 +- net/ping.h | 2 +- 9 files changed, 36 insertions(+), 26 deletions(-)
arch/powerpc/cpu/mpc8260/ether_fcc.c +8 -9
@@ -1049,11 +1049,11 @@ eth_loopback_test (void) }else {ushort datlen = bdp->cbd_datlen; -Ethernet_t *ehp; +struct ethernet_hdr *ehp;ushort prot;int ours, tb, n, nbytes; - ehp = (Ethernet_t *) \ + ehp = (struct ethernet_hdr *) \ &ecp->rxbufs[i][0 ]; ours = memcmp (ehp->et_src, \
@@ -1063,9 +1063,8 @@ eth_loopback_test (void) tb = prot &0x8000 ; n = prot &0x7fff ; - nbytes =ELBT_BUFSZ - \ - offsetof (Ethernet_t , \ - et_dsap) - \ + nbytes =ELBT_BUFSZ - +ETHER_HDR_SIZE -ELBT_CRCSZ ;/* check the frame is correct */
@@ -1080,10 +1079,10 @@ eth_loopback_test (void) patwords[n];uint nbb; - nbb =badbits ( \ - &ehp->et_dsap, \ - nbytes, \ - patword); + nbb =badbits ( + ((uchar *)&ehp) + +ETHER_HDR_SIZE , + nbytes, patword); ecp->rxeacc.badbit += \ nbb;
include/net.h +14 -4
@@ -156,7 +156,17 @@ u32 ether_crc(size_t len, unsigned char const *p);/* * Ethernet header */ -typedef struct { + +struct ethernet_hdr { +uchar et_dest[6 ];/* Destination node */ +uchar et_src[6 ];/* Source node */ +ushort et_protlen;/* Protocol or length */ +}; + +/* Ethernet header size */ +#define ETHER_HDR_SIZE (sizeof(struct ethernet_hdr)) + +struct e802_hdr {uchar et_dest[6 ];/* Destination node */ uchar et_src[6 ];/* Source node */ ushort et_protlen;/* Protocol or length */
@@ -167,10 +177,10 @@ 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 */ +/* 802 ethernet header size */ +#define E802_HDR_SIZE (sizeof(struct e802_hdr))/* * Ethernet header
net/arp.c +2 -2
@@ -113,7 +113,7 @@ void ArpTimeoutCheck(void) } } -void ArpReceive (Ethernet_t *et,struct ip_udp_hdr *ip,int len) +void ArpReceive (struct ethernet_hdr *et,struct ip_udp_hdr *ip,int len) {ARP_t *arp;IPaddr_t tmp;
@@ -193,7 +193,7 @@ void ArpReceive(Ethernet_t *et, struct ip_udp_hdr *ip, int len)NetGetHandler ()(0 ,0 ,0 ,0 ,0 );#endif /* modify header, and transmit it */ -memcpy (((Ethernet_t *)NetArpWaitTxPacket)-> +memcpy (((struct ethernet_hdr *)NetArpWaitTxPacket)-> et_dest, NetArpWaitPacketMAC,6 ); (void )eth_send (NetArpWaitTxPacket, NetArpWaitTxPacketSize);
net/arp.h +1 -1
@@ -25,6 +25,6 @@ extern int NetArpWaitTry;void ArpInit (void );void ArpRequest (void );void ArpTimeoutCheck (void ); -void ArpReceive (Ethernet_t *et,struct ip_udp_hdr *ip,int len); +void ArpReceive (struct ethernet_hdr *et,struct ip_udp_hdr *ip,int len);#endif /* __ARP_H__ */
net/bootp.c +1 -1
@@ -103,7 +103,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_hdr *)NetRxPacket)->et_src,6 );#endif if (strlen (bp->bp_file) >0 )copy_filename (BootFile, bp->bp_file,sizeof (BootFile));
net/cdp.c +2 -2
@@ -109,7 +109,7 @@ CDPSendTrigger(void)uchar *pkt;ushort *s;ushort *cp; -Ethernet_t *et; +struct ethernet_hdr *et;int len;ushort chksum; #if defined(CONFIG_CDP_DEVICE_ID) || defined(CONFIG_CDP_PORT_ID) || \
@@ -118,7 +118,7 @@ CDPSendTrigger(void)#endif pkt = NetTxPacket; - et = (Ethernet_t *)pkt; + et = (struct ethernet_hdr *)pkt;/* NOTE: trigger sent not on any VLAN */
net/net.c +6 -5
@@ -823,7 +823,7 @@ static inline struct ip_udp_hdr *NetDefragment(struct ip_udp_hdr *ip, int *lenp)* @parma ip IP packet containing the ICMP */ static void receive_icmp (struct ip_udp_hdr *ip,int len, -IPaddr_t src_ip,Ethernet_t *et) +IPaddr_t src_ip,struct ethernet_hdr *et) {ICMP_t *icmph = (ICMP_t *)&ip->udp_src;
@@ -851,7 +851,7 @@ static void receive_icmp(struct ip_udp_hdr *ip, int len,void NetReceive (uchar *inpkt,int len) { -Ethernet_t *et; +struct ethernet_hdr *et;struct ip_udp_hdr *ip;IPaddr_t tmp;IPaddr_t src_ip;
@@ -865,7 +865,7 @@ NetReceive(uchar *inpkt, int len) NetRxPacket = inpkt; NetRxPacketLen = len; - et = (Ethernet_t *)inpkt; + et = (struct ethernet_hdr *)inpkt;/* too small packet? */ if (len <ETHER_HDR_SIZE )
@@ -895,10 +895,11 @@ NetReceive(uchar *inpkt, int len)debug ("packet received\n" );if (x <1514 ) { +struct e802_hdr *et802 = (struct e802_hdr *)et;/* * Got a 802 packet. Check the other protocol field. */ - x =ntohs (et->et_prot); + x =ntohs (et802->et_prot); ip = (struct ip_udp_hdr *)(inpkt +E802_HDR_SIZE ); len -=E802_HDR_SIZE ;
@@ -1218,7 +1219,7 @@ NetEthHdrSize(void)int NetSetEther (uchar *xet,uchar * addr,uint prot) { -Ethernet_t *et = (Ethernet_t *)xet; +struct ethernet_hdr *et = (struct ethernet_hdr *)xet;ushort myvlanid; myvlanid =ntohs (NetOurVLAN);
net/ping.c +1 -1
@@ -98,7 +98,7 @@ void ping_start(void)ping_send (); } -void ping_receive (Ethernet_t *et,struct ip_udp_hdr *ip,int len) +void ping_receive (struct ethernet_hdr *et,struct ip_udp_hdr *ip,int len) {ICMP_t *icmph = (ICMP_t *)&(ip->udp_src);IPaddr_t src_ip;
net/ping.h +1 -1
@@ -28,7 +28,7 @@ void ping_start(void);* @param ip IP header in the same packet * @param len Packet length */ -void ping_receive (Ethernet_t *et,struct ip_udp_hdr *ip,int len); +void ping_receive (struct ethernet_hdr *et,struct ip_udp_hdr *ip,int len);#endif /* __PING_H__ */ #endif
Signature · 1 line
1.6.0.2
PATCH v3 11/21 net: cosmetic: Un-typedef VLAN_Ethernet_t
In reply to Joe HershbergerEliminate the typedef and remove capital letters
---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Renamed structs from *_t to *_hdr since they are nolonger types
Changes for v3:
- Renamed VLAN_Ethernet_hdr to vlan_ethernet_hdr
include/net.h | 7 ++++--- net/net.c | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-)
include/net.h +4 -3
@@ -185,15 +185,16 @@ struct e802_hdr {/* * Ethernet header */ -typedef struct { +struct vlan_ethernet_hdr {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 */ +/* VLAN Ethernet header size */ +#define VLAN_ETHER_HDR_SIZE (sizeof(struct vlan_ethernet_hdr))#define PROT_IP 0x0800/* IP protocol */ #define PROT_ARP 0x0806/* IP ARP protocol */
net/net.c +4 -2
@@ -909,7 +909,8 @@ NetReceive(uchar *inpkt, int len) len -=ETHER_HDR_SIZE ; }else {/* VLAN packet */ -VLAN_Ethernet_t *vet = (VLAN_Ethernet_t *)et; +struct vlan_ethernet_hdr *vet = + (struct vlan_ethernet_hdr *)et;debug ("VLAN packet received\n" );
@@ -1232,7 +1233,8 @@ NetSetEther(uchar *xet, uchar * addr, uint prot) et->et_protlen =htons (prot);return ETHER_HDR_SIZE ; }else { -VLAN_Ethernet_t *vet = (VLAN_Ethernet_t *)xet; +struct vlan_ethernet_hdr *vet = + (struct vlan_ethernet_hdr *)xet; vet->vet_vlan_type =htons (PROT_VLAN ); vet->vet_tag =htons ((0 <<5 ) | (myvlanid &VLAN_IDMASK ));
Signature · 1 line
1.6.0.2
PATCH v3 12/21 net: cosmetic: Un-typedef ARP_t
In reply to Joe HershbergerRemove typedef and lower-case letters
---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Renamed structs from *_t to *_hdr since they are nolonger types
Changes for v3:
- Renamed ARP_hdr to arp_hdr
include/net.h | 5 ++--- net/arp.c | 8 ++++---- net/rarp.c | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-)
include/net.h +2 -3
@@ -254,8 +254,7 @@ struct ip_udp_hdr {/* * Address Resolution Protocol (ARP) header. */ -typedef struct -{ +struct arp_hdr {ushort ar_hrd;/* Format of hardware address */ # define ARP_ETHER 1/* Ethernet hardware address */ ushort ar_pro;/* Format of protocol address */
@@ -280,7 +279,7 @@ typedef structuchar ar_tha[];/* Target hardware address */ uchar ar_tpa[];/* Target protocol address */ #endif /* 0 */ -} ARP_t; +};#define ARP_HDR_SIZE (8+20)/* Size assuming ethernet */
net/arp.c +4 -4
@@ -51,7 +51,7 @@ void ArpInit(void)void ArpRequest (void ) {uchar *pkt; -ARP_t *arp; +struct arp_hdr *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_hdr *) pkt; arp->ar_hrd =htons (ARP_ETHER ); arp->ar_pro =htons (PROT_IP );
@@ -115,7 +115,7 @@ void ArpTimeoutCheck(void)void ArpReceive (struct ethernet_hdr *et,struct ip_udp_hdr *ip,int len) { -ARP_t *arp; +struct arp_hdr *arp;IPaddr_t tmp;uchar *pkt;
@@ -130,7 +130,7 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)*/ debug ("Got ARP\n" ); - arp = (ARP_t *)ip; + arp = (struct arp_hdr *)ip;if (len <ARP_HDR_SIZE ) {printf ("bad length %d < %d\n" , len,ARP_HDR_SIZE );return ;
net/rarp.c +4 -4
@@ -43,10 +43,10 @@ int RarpTry;*/ void rarp_receive (struct ip_upd_hdr *ip,unsigned len) { -ARP_t *arp; +struct arp_hdr *arp;debug ("Got RARP\n" ); - arp = (ARP_t *)ip; + arp = (struct arp_hdr *)ip;if (len <ARP_HDR_SIZE ) {printf ("bad length %d < %d\n" , len,ARP_HDR_SIZE );return ;
@@ -87,14 +87,14 @@ static void RarpTimeout(void)void RarpRequest (void ) {uchar *pkt; -ARP_t *rarp; +struct arp_hdr *rarp;printf ("RARP broadcast %d\n" , ++RarpTry); pkt = NetTxPacket; pkt +=NetSetEther (pkt, NetBcastAddr,PROT_RARP ); - rarp = (ARP_t *)pkt; + rarp = (struct arp_hdr *)pkt; rarp->ar_hrd =htons (ARP_ETHER ); rarp->ar_pro =htons (PROT_IP );
Signature · 1 line
1.6.0.2
PATCH v3 13/21 net: cosmetic: Un-typedef ICMP_t
In reply to Joe HershbergerRemove typedef and lower-case name
---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Renamed structs from *_t to *_hdr since they are nolonger types
Changes for v3:
- Renamed ICMP_hdr to icmp_hdr
- Removed extra brackets
include/net.h | 6 ++++-- net/net.c | 2 +- net/ping.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-)
include/net.h +4 -2
@@ -298,7 +298,7 @@ struct arp_hdr {/* Codes for NOT_REACH */ #define ICMP_NOT_REACH_PORT 3/* Port unreachable */ -typedef struct icmphdr { +struct icmp_hdr {uchar type;uchar code;ushort checksum;
@@ -314,8 +314,10 @@ typedef struct icmphdr { } frag;uchar data[0 ]; } un; -} ICMP_t; +}; +#define ICMP_HDR_SIZE (sizeof(struct icmp_hdr)) +#define IP_ICMP_HDR_SIZE (IP_HDR_SIZE + ICMP_HDR_SIZE)/* * Maximum packet size; used to allocate packet storage.
net/net.c +1 -1
@@ -825,7 +825,7 @@ static inline struct ip_udp_hdr *NetDefragment(struct ip_udp_hdr *ip, int *lenp)static void receive_icmp (struct ip_udp_hdr *ip,int len,IPaddr_t src_ip,struct ethernet_hdr *et) { -ICMP_t *icmph = (ICMP_t *)&ip->udp_src; +struct icmp_hdr *icmph = (struct icmp_hdr *)&ip->udp_src;switch (icmph->type) {case ICMP_REDIRECT :
net/ping.c +1 -1
@@ -100,7 +100,7 @@ void ping_start(void)void ping_receive (struct ethernet_hdr *et,struct ip_udp_hdr *ip,int len) { -ICMP_t *icmph = (ICMP_t *)&(ip->udp_src); +struct icmp_hdr *icmph = (struct icmp_hdr *)&ip->udp_src;IPaddr_t src_ip;switch (icmph->type) {
Signature · 1 line
1.6.0.2
PATCH v3 14/21 net: cosmetic: Rename parameter len to payload_len
In reply to Joe HershbergerThis name more explicitly claims that it does not include the header size
---
Changes for v2:
- Split from "Improve variable names and code readability"
Changes for v3:
- Documented arguments to NetSendUDPPacket()
include/net.h | 12 ++++++++++-- net/net.c | 15 ++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-)
include/net.h +10 -2
@@ -466,9 +466,17 @@ extern void NetSetTimeout(ulong, thand_f *);/* Set timeout handler *//* Transmit "NetTxPacket" */ extern void NetSendPacket (uchar *,int ); -/* Transmit UDP packet, performing ARP request if needed */ +/* +* Transmit UDP packet, performing ARP request if needed +* +* @param ether Raw packet buffer +* @param dest IP address to send the datagram to +* @param dport Destination UDP port +* @param sport Source UDP port +* @param payload_len Length of data after the UDP header +*/ 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 (uchar *,int );
net/net.c +8 -7
@@ -591,8 +591,8 @@ NetSendPacket(uchar *pkt, int len) (void )eth_send (pkt, len); } -int -NetSendUDPPacket (uchar *ether,IPaddr_t dest,int dport,int sport,int len) +int NetSendUDPPacket (uchar *ether,IPaddr_t dest,int dport,int sport, +int payload_len) {uchar *pkt;
@@ -618,14 +618,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 ;
@@ -638,8 +638,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 */ }
Signature · 1 line
1.6.0.2
PATCH v3 15/21 net: cosmetic: Add a more explicit comment about 802.2
In reply to Joe HershbergerMake the comment more accurate about the header including SNAP
---
Changes for v2:
- Split from "Improve variable names and code readability"
- Fixed comment indention
Changes for v3:
- Added a short commit message
include/net.h | 4 ++-- net/net.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)
include/net.h +2 -2
@@ -179,11 +179,11 @@ struct e802_hdr {ushort et_prot;/* 802 protocol */ }; -/* 802 ethernet header size */ +/* 802 + SNAP + ethernet header size */ #define E802_HDR_SIZE (sizeof(struct e802_hdr))/* -* Ethernet header +* Virtual LAN Ethernet header */ struct vlan_ethernet_hdr {uchar vet_dest[6 ];/* Destination node */
net/net.c +2 -1
@@ -898,7 +898,8 @@ NetReceive(uchar *inpkt, int len)if (x <1514 ) {struct e802_hdr *et802 = (struct e802_hdr *)et;/* -* 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 (et802->et_prot);
Signature · 1 line
1.6.0.2
PATCH v3 16/21 net: cosmetic: Rename "x" to "eth_proto"
In reply to Joe Hershbergerx is a poor variable name
---
Changes for v2:
- Split from "Improve variable names and code readability"
Changes for v3:
net/net.c | 24 ++++++++++++------------ 1 files changed, 12 insertions(+), 12 deletions(-)
net/net.c +12 -12
@@ -854,9 +854,9 @@ NetReceive(uchar *inpkt, int len) {struct ethernet_hdr *et;struct ip_udp_hdr *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
@@ -891,22 +891,22 @@ NetReceive(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 ) {struct e802_hdr *et802 = (struct e802_hdr *)et;/* * Got a 802.2 packet. Check the other protocol field. * XXX VLAN over 802.2+SNAP not implemented! */ - x =ntohs (et802->et_prot); + eth_proto =ntohs (et802->et_prot); ip = (struct ip_udp_hdr *)(inpkt +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_hdr *)(inpkt +ETHER_HDR_SIZE ); len -=ETHER_HDR_SIZE ;
@@ -930,13 +930,13 @@ NetReceive(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_hdr *)(inpkt +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) {
@@ -953,7 +953,7 @@ NetReceive(uchar *inpkt, int len)return ; } -switch (x) { +switch (eth_proto) {case PROT_ARP :ArpReceive (et, ip, len);
@@ -992,10 +992,10 @@ NetReceive(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 ; }
Signature · 1 line
1.6.0.2
PATCH v3 17/21 net: cosmetic: Rename CDPHandler to cdp_receive
In reply to Joe HershbergerThis is not called as a handler, so don't name it that way
---
Changes for v2:
- Split from "Improve variable names and code readability"
Changes for v3:
- Added a function comment
- Renamed CDPReceive to cdp_receive
net/cdp.c | 3 +-- net/cdp.h | 3 ++- net/net.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
net/cdp.c +1 -2
@@ -245,8 +245,7 @@ CDPDummyHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,/* nothing */ } -void -CDPHandler (const uchar *pkt,unsigned len) +void cdp_receive (const uchar *pkt,unsigned len) {const uchar *t;const ushort *ss;
net/cdp.h +2 -1
@@ -14,7 +14,8 @@#define __CDP_H__void CDPStart (void ); -void CDPHandler (const uchar *pkt,unsigned len); +/* Process a received CDP packet */ +void cdp_receive (const uchar *pkt,unsigned len);#endif /* __CDP_H__ */ #endif
net/net.c +1 -1
@@ -940,7 +940,7 @@ NetReceive(uchar *inpkt, int len)#if defined(CONFIG_CMD_CDP )if (iscdp) { -CDPHandler ((uchar *)ip, len); +cdp_receive ((uchar *)ip, len);return ; }#endif
Signature · 1 line
1.6.0.2
PATCH v3 18/21 net: cosmetic: Rename OPT_SIZE to OPT_FIELD_SIZE
In reply to Joe HershbergerClearer constant name.
Also remove related BOOTP_SIZE which was unused and doesn't take into account VLAN packets.
---
Changes for v2:
- Split from "Improve variable names and code readability"
Changes for v3:
net/bootp.c | 10 +++++----- net/bootp.h | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-)
net/bootp.c +5 -5
@@ -71,7 +71,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 &&
@@ -368,8 +368,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);
@@ -519,8 +519,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
@@ -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)/**********************************************************************/ /*
Signature · 1 line
1.6.0.2
PATCH v3 19/21 net: cosmetic: Alphabetize includes in net.c
In reply to Joe HershbergerEasier to find when alphabetized
---
Changes for v2:
- Split from "Improve variable names and code readability"
Changes for v3:
- Slight adjustment to order as recommended by Simon
net/net.c | 24 ++++++++++++------------ 1 files changed, 12 insertions(+), 12 deletions(-)
net/net.c +12 -12
@@ -75,27 +75,27 @@#include <common.h> -#include <watchdog.h> #include <command.h> -#include <linux/compiler.h> #include <net.h> -#include "arp.h" -#include "bootp.h" -#include "tftp.h" -#include "rarp.h" -#include "nfs.h" -#ifdef CONFIG_STATUS_LED -#include <status_led.h> +#if defined(CONFIG_STATUS_LED )#include <miiphy.h> +#include <status_led.h> #endif -#if defined(CONFIG_CMD_SNTP ) -#include "sntp.h" -#endif +#include <watchdog.h> +#include <linux/compiler.h> +#include "arp.h" +#include "bootp.h" #include "cdp.h" #if defined(CONFIG_CMD_DNS )#include "dns.h" #endif +#include "nfs.h" #include "ping.h" +#include "rarp.h" +#if defined(CONFIG_CMD_SNTP ) +#include "sntp.h" +#endif +#include "tftp.h" DECLARE_GLOBAL_DATA_PTR ;
Signature · 1 line
1.6.0.2
PATCH v3 20/21 net: cosmetic: Rename tmp to reply_ip_addr in arp.c
In reply to Joe HershbergerRenamed for clarity
---
Changes for v2:
- Split from "Improve variable names and code readability"
Changes for v3:
net/arp.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
net/arp.c +3 -3
@@ -116,7 +116,7 @@ void ArpTimeoutCheck(void)void ArpReceive (struct ethernet_hdr *et,struct ip_udp_hdr *ip,int len) {struct arp_hdr *arp; -IPaddr_t tmp; +IPaddr_t reply_ip_addr;uchar *pkt;/*
@@ -178,10 +178,10 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len) }#endif - tmp =NetReadIP (&arp->ar_data[6 ]); + reply_ip_addr =NetReadIP (&arp->ar_data[6 ]);/* 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);
Signature · 1 line
1.6.0.2
PATCH v3 21/21 net: cosmetic: Replace magic numbers in arp.c with constants
In reply to Joe HershbergerUse field names and sizes when accessing ARP packets
---
Changes for v2:
- Split from "Improve variable names and code readability"
Changes for v3:
include/net.h | 6 ++++++ net/arp.c | 34 +++++++++++++++++----------------- 2 files changed, 23 insertions(+), 17 deletions(-)
include/net.h +6 -0
@@ -259,7 +259,9 @@ struct arp_hdr {# define ARP_ETHER 1/* Ethernet hardware address */ ushort ar_pro;/* Format of protocol address */ uchar ar_hln;/* Length of hardware address */ +# define ARP_HLEN 6uchar ar_pln;/* Length of protocol address */ +# define ARP_PLEN 4ushort ar_op;/* Operation */ # define ARPOP_REQUEST 1/* Request to resolve address */ # define ARPOP_REPLY 2/* Response to previous request */
@@ -273,6 +275,10 @@ struct arp_hdr {* 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 */
net/arp.c +17 -17
@@ -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 ); }
@@ -139,15 +139,15 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *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_hdr *et, struct ip_udp_hdr *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,12 +173,12 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *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 - reply_ip_addr =NetReadIP (&arp->ar_data[6 ]); + reply_ip_addr =NetReadIP (&arp->ar_spa);/* matched waiting packet's address */ if (reply_ip_addr == NetArpWaitReplyIP) {
@@ -187,14 +187,14 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)/* 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_hdr *)NetArpWaitTxPacket)-> - et_dest, NetArpWaitPacketMAC,6 ); + et_dest, NetArpWaitPacketMAC,ARP_HLEN ); (void )eth_send (NetArpWaitTxPacket, NetArpWaitTxPacketSize);
Signature · 1 line
1.6.0.2
PATCH v2 1/21 net: Remove CMD_PING where there's no CMD_NET
In reply to Joe HershbergerSome boards claim to need ping, but don't support net. That makes no sense, and causes problems now that ping is in a separate file.
---
Changes for v2:
- Separated from "Move PING out of net.c"
include/configs/am3517_crane.h | 2 +- include/configs/am3517_evm.h | 2 +- include/configs/origen.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
include/configs/am3517_crane.h +1 -1
@@ -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
@@ -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
@@ -82,7 +82,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
Signature · 1 line
1.6.0.2
PATCH v2 1/21 net: Remove CMD_PING where there's no CMD_NET
Hi Joe,
Quoted 8 lines · Joe Hershberger
Some boards claim to need ping, but don't support net. That makes no sense, and causes problems now that ping is in a separate file.
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
See question below too.
Quoted 14 lines
---
Changes for v2:
? - Separated from "Move PING out ofnet.c"?include/configs/am3517_crane.h | ? ?2 +- ?include/configs/am3517_evm.h ? | ? ?2 +- ?include/configs/origen.h ? ? ? | ? ?2 +-?3 files changed, 3 insertions(+), 3 deletions(-)
include/configs/am3517_crane.h +0
-0@@ -146,7 +146,7 @@
Quoted 3 lines
?#define
CONFIG_CMD_MMC? ? ? ? /* MMC support ? ? ? ? ? ? ? ? ?*/ ?#defineCONFIG_CMD_NAND? ? ? ? ? ? ? ?/* NAND support ? ? ? ? ? ? ? ? */ ?#defineCONFIG_CMD_DHCP
Should you remove the DHCP also?
Quoted 28 lines
include/configs/am3517_crane.h +1
-1-#define CONFIG_CMD_PING +#undef CONFIG_CMD_PING?#undef
CONFIG_CMD_FLASH? ? ? ? ? ? ? ?/* flinfo, erase, protect ? ? ? */ ?#undefCONFIG_CMD_FPGA? ? ? ? /* FPGA configuration Support ? */include/configs/am3517_evm.h +0
-0@@ -145,7 +145,7 @@?#define
CONFIG_CMD_MMC? ? ? ? /* MMC support ? ? ? ? ? ? ? ? ?*/ ?#defineCONFIG_CMD_NAND? ? ? ? ? ? ? ?/* NAND support ? ? ? ? ? ? ? ? */ ?#defineCONFIG_CMD_DHCPinclude/configs/am3517_evm.h +1
-1-#define CONFIG_CMD_PING +#undef CONFIG_CMD_PING?#undef
CONFIG_CMD_FLASH? ? ? ? ? ? ? ?/* flinfo, erase, protect ? ? ? */ ?#undefCONFIG_CMD_FPGA? ? ? ? /* FPGA configuration Support ? */include/configs/origen.h +0
-0@@ -82,7 +82,7 @@?/* Command definition*/
?#include <config_cmd_default.h>include/configs/origen.h +1
-1-#define CONFIG_CMD_PING +#undef CONFIG_CMD_PING
Quoted 6 lines
?#define
CONFIG_CMD_ELF
?#defineCONFIG_CMD_DHCP
?#defineCONFIG_CMD_MMC
--
1.6.0.2
Regards,
Simon
PATCH v2 1/21 net: Remove CMD_PING where there's no CMD_NET
Hi Simon,
Quoted 13 lines · Simon Glass
Hi Joe,
Quoted 8 lines · Joe Hershberger
include/configs/am3517_crane.h +0
-0@@ -146,7 +146,7 @@?#define
CONFIG_CMD_MMC? ? ? ? /* MMC support ? ? ? ? ? ? ? ? ?*/ ?#defineCONFIG_CMD_NAND? ? ? ? ? ? ? ?/* NAND support ? ? ? ? ? ? ? ? */ ?#defineCONFIG_CMD_DHCPShould you remove the DHCP also?
I was interested in changing only what actually caused a build failure in a board I have no way to test, though it would be safe to change as well.
-Joe
PATCH v2 2/21 net: Remove redefinitions of net.h functions
In reply to Joe HershbergerSome copy/pasted drivers redefine functions defined in include/net.h. Remove these so that the definitions can be changed without error.
---
Changes for v2:
- Split from "Remove volatile from all of net except the eth driver interface"
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 -- 4 files changed, 0 insertions(+), 8 deletions(-)
board/Marvell/db64360/mv_eth.c +0 -2
@@ -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
@@ -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
@@ -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
@@ -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 ;
Signature · 1 line
1.6.0.2
PATCH v2 2/21 net: Remove redefinitions of net.h functions
Quoted 8 lines · Joe Hershberger
Some copy/pasted drivers redefine functions defined in
include/net.h. ?Remove these so that the definitions can be changed without error.Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
(I assume MAKEALL throws no errors due to these)
Quoted 65 lines
---
Changes for v2:
? - Split from "Remove volatile from all of net except the eth driver interface"?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 --?4 files changed, 0 insertions(+), 8 deletions(-)
board/Marvell/db64360/mv_eth.c +0
-0@@ -95,8 +95,6 @@ int mv64360_eth_xmit (struct eth_device *, volatile void *packet, int length);?#ifndef ?UPDATE_STATS_BY_SOFTWARE
?static voidmv64360_eth_print_stat(structeth_device*dev); ?#endifboard/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@@ -95,8 +95,6 @@ int mv64460_eth_xmit (struct eth_device *, volatile void *packet, int length);?#ifndef ?UPDATE_STATS_BY_SOFTWARE
?static voidmv64460_eth_print_stat(structeth_device*dev); ?#endifboard/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@@ -95,8 +95,6 @@ int mv64360_eth_xmit (struct eth_device *, volatile void *packet, int length);?#ifndef ?UPDATE_STATS_BY_SOFTWARE
?static voidmv64360_eth_print_stat(structeth_device*dev); ?#endifboard/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@@ -109,8 +109,6 @@ int phy_setup_aneg (char *devname, unsigned char addr);?#ifndef ? ? ? ?
UPDATE_STATS_BY_SOFTWARE
?static voidmv64460_eth_print_stat(structeth_device*dev); ?#endifboard/prodrive/p3mx/mv_eth.c +0
-2-/* Processes a received packet */ -extern void NetReceive (volatile uchar *,int );?extern unsigned int
INTERNAL_REG_BASE_ADDR;--
1.6.0.2
PATCH v2 3/21 net: Move MAC-seeded rand out of bootp.c
In reply to Joe HershbergerMake the MAC-seeded random number generator available to /net in general. MAC-seeded rand will be needed by link-local as well, so give it an interface.
--- net/Makefile | 1 + net/bootp.c | 69 +++++++++++-------------------------------------------- net/bootp.h | 3 -- net/net_rand.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net_rand.h | 17 +++++++++++++ 5 files changed, 100 insertions(+), 58 deletions(-) create mode 100644 net/net_rand.c create mode 100644 net/net_rand.h
net/Makefile +1 -0
@@ -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
@@ -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 +17 -0
@@ -0,0 +1,17 @@ +/* +* 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
PATCH v2 3/21 net: Move MAC-seeded rand out of bootp.c
Hi Joe,
Quoted 38 lines · Joe Hershberger
Make the MAC-seeded random number generator available to /net in general. ?MAC-seeded rand will be needed by link-local as well, so give it an interface.
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>---
?net/Makefile ? | ? ?1 + ?net/bootp.c ? ?| ? 69 +++++++++++-------------------------------------------- ?net/bootp.h ? ?| ? ?3 -- ?net/net_rand.c | ? 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ ?net/net_rand.h | ? 17 +++++++++++++?5 files changed, 100 insertions(+), 58 deletions(-) ?create mode 100644
net/net_rand.c
?create mode 100644net/net_rand.hnet/Makefile +0
-0@@ -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.onet/bootp.c +0
-0@@ -12,6 +12,9 @@?#include <
command.h>
?#include <net.h>
?#include "bootp.h"
net/bootp.c line 17
Quoted 3 lines
net/bootp.c +3
-0+#ifdef CONFIG_BOOTP_RANDOM_DELAY +#include "net_rand.h" +#endif
How about just always including it?
Quoted 72 lines
?#include "
tftp.h"
?#include "nfs.h"
?#ifdefCONFIG_STATUS_LEDnet/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;@@ -584,6 +584,9 @@ BootpRequest(void) ? ? ? ?uchar *pkt, *iphdr; ? ? ? ?struct Bootp_t *bp; ? ? ? ?int ext_len, pktlen, iplen; +#ifdef CONFIG_BOOTP_RANDOM_DELAY + ? ? ? ulong i, rand_ms; +#endif ? ? ? ?bootstage_mark_name(BOOTSTAGE_ID_BOOTP_START, "bootp_start"); ?#if defined(CONFIG_CMD_DHCP)@@ -591,60 +594,16 @@ BootpRequest(void)?#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 +2
-39- - ? ? ? 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;
net/bootp.c
Quoted 10 lines
net/bootp.c +2
-8- ? ? ? ? ? ? ? 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);
Spaces around operators
Quoted 37 lines
+ ? ? ? 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@@ -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 +7
-0@@ -0,0 +1,68 @@ +/* +* ? ? Based on LiMon - BOOTP. +* +* ? ? Copyright 1994, 1995, 2000 Neil Russell. +* ? ? (See License) +* ? ? Copyright 2000 Roland Borde +* ? ? Copyright 2000 Paolo Scaffardi
net/net_rand.c line 17
Quoted 10 lines
net/net_rand.c new file +10
-0+* ? ? 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 )
Perhaps pass in the place to put the random mac, rather than using a global?
Quoted 59 lines
net/net_rand.c new file +51
-0+{ + ? ? ? 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 +2
-0@@ -0,0 +1,17 @@ +/* +* ? ? Copied from LiMon - BOOTP.
net/net_rand.h line 12
Quoted 10 lines
net/net_rand.h new file +10
-0+* +* ? ? Copyright 1994, 1995, 2000 Neil Russell. +* ? ? (See License) +* ? ? Copyright 2000 Paolo Scaffardi +*/ + +#ifndef __NET_RAND_H__ +#define __NET_RAND_H__ + +#define RAND_MAX 0xFFFFFFFF
Do we want lower case hex? Not sure.
net/net_rand.h line 15
Quoted 3 lines
net/net_rand.h new file +3
-0+ +void srand_mac (void ); +unsigned long rand (void );
Function comments are nice :-)
Quoted 5 lines
net/net_rand.h new file +2
-1+ +#endif /* __NET_RAND_H__ */ --1.6.0.2
Regards,
Simon
PATCH v2 3/21 net: Move MAC-seeded rand out of bootp.c
Hi Simon,
Quoted 16 lines · Simon Glass
Hi Joe,
net/bootp.c line 17
Quoted 11 lines · Joe Hershberger
net/bootp.c +0
-0@@ -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 How about just always including it?
OK.
Quoted 20 lines
Quoted 20 lines
?#include "
tftp.h"
?#include "nfs.h"
?#ifdefCONFIG_STATUS_LEDnet/net_rand.c new file +11
-0@@ -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>
Quoted 8 lines
net/net_rand.c line 17
Quoted 6 lines
net/net_rand.c new file +6
-0+#include <net.h> +#include "net_rand.h" + +static ulong seed1, seed2; + +void srand_mac (void )Perhaps pass in the place to put the random mac, rather than using a global?
In this case it is using the env to read the mac. It is not creating a random mac. The point is to create a random number based on the MAC so that the numbers vary from device to device in the absence of other entropy. In the link-local case it also should lead to the same device choosing the same address each time by default and most likely different than other devices.
In the future I could make it take an index for which MAC address to seed with, but for now, using the first is best suited to its application.
Quoted 20 lines
Quoted 20 lines
net/net_rand.c new file +8
-0+{ + ? ? ? 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);net/net_rand.h new file +6
-0@@ -0,0 +1,17 @@ +/* +* ? ? Copied from LiMon - BOOTP. +* +* ? ? Copyright 1994, 1995, 2000 Neil Russell. +* ? ? (See License) +* ? ? Copyright 2000 Paolo Scaffardi
Quoted 8 lines
net/net_rand.h line 12
Quoted 6 lines
net/net_rand.h new file +6
-0+*/ + +#ifndef __NET_RAND_H__ +#define __NET_RAND_H__ + +#define RAND_MAX 0xFFFFFFFFDo we want lower case hex? Not sure.
OK
Quoted 5 lines
net/net_rand.h line 15
Quoted 3 lines
net/net_rand.h new file +3
-0+ +void srand_mac (void ); +unsigned long rand (void );Function comments are nice :-)
OK
Quoted 3 lines
net/net_rand.h
Quoted 3 lines
net/net_rand.h new file +2
-1+ +#endif /* __NET_RAND_H__ */ --
Thanks,
-Joe
PATCH v2 4/21 net: Move CDP out of net.c
In reply to Joe Hershberger---
Changes for v2:
- Moved is_cdp_packet to a separate patch
- Fixed blank newline at the end of cdp.h
- Pushed #ifdef CONFIG_CMD_CDP into header
include/net.h | 8 +- net/Makefile | 1 + net/cdp.c | 374 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/cdp.h | 20 +++ net/net.c | 366 +------------------------------------------------------- 5 files changed, 399 insertions(+), 370 deletions(-) create mode 100644 net/cdp.c create mode 100644 net/cdp.h
include/net.h +3 -5
@@ -355,9 +355,7 @@ 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 const uchar NetCDPAddr[6 ];/* Ethernet CDP address */ extern int NetState;/* Network loop state */ #define NETLOOP_CONTINUE 1
@@ -386,8 +384,8 @@ 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 */ #endif #if defined(CONFIG_CMD_SNTP )
net/Makefile +1 -0
@@ -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 +374 -0
374 lines not on this page · raw message
net/cdp.h new file +20 -0
@@ -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, [email protected] +*/ + +#if defined(CONFIG_CMD_CDP ) + +#ifndef __CDP_H__ +#define __CDP_H__ + +void CDPStart (void ); +void CDPHandler (const uchar *pkt,unsigned len); + +#endif /* __CDP_H__ */ +#endif
net/net.c +1 -365
390 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH v2 4/21 net: Move CDP out of net.c
Hi Joe,
On Tue, Mar 27, 2012 at 4:42 PM, Joe Hershberger <[email protected]> wrote:
This needs a commit message.
Quoted 98 lines
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>---
Changes for v2:
? - Movedis_cdp_packetto a separate patch
? - Fixed blank newline at the end ofcdp.h
? - Pushed #ifdefCONFIG_CMD_CDPinto header?include/net.h | ? ?8 +- ?net/Makefile ?| ? ?1 + ?net/cdp.c ? ? | ?374 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ?net/cdp.h ? ? | ? 20 +++ ?net/net.c ? ? | ?366 +-------------------------------------------------------?5 files changed, 399 insertions(+), 370 deletions(-) ?create mode 100644
net/cdp.c
?create mode 100644net/cdp.hinclude/net.h +0
-0@@ -355,9 +355,7 @@ extern uchar ? ? ? ? ? ? ? ?NetEtherNullAddr[6];?extern ushort ? ? ? ? ?NetOurVLAN; ? ? ? ? ? ? /* Our VLAN */ ?extern ushort ? ? ? ? ?NetOurNativeVLAN; ? ? ? /* Our Native VLAN */
include/net.h +1
-3-extern uchar ? NetCDPAddr[6]; ? ? ? ? ?/* Ethernet CDP address */ -extern ushort ?CDPNativeVLAN; ? ? ? ? ?/* CDP returned native VLAN */ -extern ushort ?CDPApplianceVLAN; ? ? ? /* CDP returned appliance VLAN */ +extern const uchar ? ? NetCDPAddr[6]; ? ? ? ? ?/* Ethernet CDP address */?extern int ? ? ? ? ? ? NetState; ? ? ? ? ? ? ? /* Network loop state */ ?#define
NETLOOP_CONTINUE? ? ? 1include/net.h +0
-0@@ -386,8 +384,8 @@ 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 +2
-2-extern ushort CDPNativeVLAN; -extern ushort CDPApplianceVLAN; +extern ushort CDPNativeVLAN; ? ? ? ? ? /* CDP returned native VLAN */ +extern ushort CDPApplianceVLAN; ? ? ? ? ? ? ? ?/* CDP returned appliance VLAN */?#endif
?#if
defined(CONFIG_CMD_SNTP)net/Makefile +0
-0@@ -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.onet/cdp.c new file +35
-0@@ -0,0 +1,374 @@ +/* +* ? ? 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 */ +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 +
net/cdp.c line 45
Quoted 10 lines
net/cdp.c new file +10
-0+#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 };
Can we put the values on the next line?
net/cdp.c line 48
Quoted 3 lines
net/cdp.c new file +3
-0+ +static ushort +CDP_compute_csum (const uchar *buff,ushort len)
Would be nice to add a function comment if you know what it does, and returns
Quoted 15 lines
net/cdp.c new file +15
-0+{ + ? ? ? 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) {
net/cdp.c line 73
Quoted 10 lines
net/cdp.c new file +10
-0+ ? ? ? ? ? ? ? ? ? ? ? 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):
Comment style. But it is existing code, so perhaps you can leave it along? Poor Cisco.
Quoted 4 lines
net/cdp.c new file +4
-0+? ? ? ? ? ? ? ? ? ? ? ?* CDP uses the IP checksum algorithm with a twist; +? ? ? ? ? ? ? ? ? ? ? ?* for the last byte it *sign* extends and sums. +? ? ? ? ? ? ? ? ? ? ? ?*/ + ? ? ? ? ? ? ? ? ? ? ? result = (result & 0xffff0000) |
net/cdp.c line 87
Quoted 10 lines
net/cdp.c new file +10
-0+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?((result + leftover) & 0x0000ffff); + ? ? ? ? ? ? ? } + ? ? ? ? ? ? ? while (result >> 16) + ? ? ? ? ? ? ? ? ? ? ? result = (result & 0xFFFF) + (result >> 16); + + ? ? ? ? ? ? ? if (odd) + ? ? ? ? ? ? ? ? ? ? ? result = ((result >> 8) & 0xff) | + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?((result & 0xff) << 8); + ? ? ? } +
Regards,
Simon
PATCH v2 5/21 net: Encapsulate CDP packet identification
In reply to Joe HershbergerChecking for CDP packets should be encapsulated, not copied code.
---
Changes for v2:
- Split from patch "Move CDP out of net.c"
- Changed to static inline
arch/powerpc/cpu/mpc8xx/fec.c | 2 +- include/net.h | 7 +++++-- net/net.c | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-)
arch/powerpc/cpu/mpc8xx/fec.c +1 -1
@@ -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 +5 -2
@@ -355,8 +355,6 @@ extern uchar NetEtherNullAddr[6];extern ushort NetOurVLAN;/* Our VLAN */ extern ushort NetOurNativeVLAN;/* Our Native VLAN */ -extern const uchar NetCDPAddr[6 ];/* Ethernet CDP address */ -extern int NetState;/* Network loop state */ #define NETLOOP_CONTINUE 1#define NETLOOP_RESTART 2
@@ -386,6 +384,11 @@ extern IPaddr_t NetPingIP; /* the ip address to ping *//* when CDP completes these hold the return values */ extern ushort CDPNativeVLAN;/* CDP returned native VLAN */ extern ushort CDPApplianceVLAN;/* CDP returned appliance VLAN */ +static inline int is_cdp_packet (const uchar *et_addr) +{ +extern const uchar NetCDPAddr[6 ]; +return memcmp (et_addr, NetCDPAddr,6 ) ==0 ; +}#endif #if defined(CONFIG_CMD_SNTP )
net/net.c +1 -1
@@ -1101,7 +1101,7 @@ NetReceive(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);
Signature · 1 line
1.6.0.2
PATCH v2 5/21 net: Encapsulate CDP packet identification
Hi Joe,
Quoted 43 lines · Joe Hershberger
Checking for CDP packets should be encapsulated, not copied code.
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>---
Changes for v2:
? - Split from patch "Move CDP out ofnet.c"
? - Changed to static inline?arch/powerpc/cpu/mpc8xx/fec.c | ? ?2 +- ?include/net.h ? ? ? ? ? ? ? ? | ? ?7 +++++-- ?net/net.c ? ? ? ? ? ? ? ? ? ? | ? ?2 +-?3 files changed, 7 insertions(+), 4 deletions(-)
arch/powerpc/cpu/mpc8xx/fec.c +0
-0@@ -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 +0
-0@@ -355,8 +355,6 @@ extern uchar ? ? ? ? ? ? ? ?NetEtherNullAddr[6];?extern ushort ? ? ? ? ?NetOurVLAN; ? ? ? ? ? ? /* Our VLAN */ ?extern ushort ? ? ? ? ?NetOurNativeVLAN; ? ? ? /* Our Native VLAN */
include/net.h +0
-2-extern const uchar ? ? NetCDPAddr[6]; ? ? ? ? ?/* Ethernet CDP address */ -?extern int ? ? ? ? ? ? NetState; ? ? ? ? ? ? ? /* Network loop state */ ?#define
NETLOOP_CONTINUE? ? ? 1
?#defineNETLOOP_RESTART? ? ? ? ? ? ? ?2include/net.h +0
-0@@ -386,6 +384,11 @@ extern IPaddr_t ? ?NetPingIP; ? ? ? ? ? ? ? ? ? ? ?/* the ip address to ping */
Quoted 3 lines
?/* when CDP completes these hold the return values */
?extern ushort CDPNativeVLAN; ? ? ? ? ? /* CDP returned native VLAN */ ?extern ushort CDPApplianceVLAN; ? ? ? ? ? ? ? ?/* CDP returned appliance VLAN */
blank line, function comment
include/net.h extern IPaddr_t NetPingIP; /* the ip address to ping */
Quoted 3 lines
include/net.h +3
-0+static inline int is_cdp_packet (const uchar *et_addr) +{ + ? ? ? extern const uchar NetCDPAddr[6];
blank line?
Quoted 17 lines
+ ? ? ? return
memcmp(et_addr, NetCDPAddr, 6)== 0; +}
?#endif?#if
defined(CONFIG_CMD_SNTP)net/net.c +0
-0@@ -1101,7 +1101,7 @@ NetReceive(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
Quoted 4 lines
? ? ? ?myvlanid = ntohs(NetOurVLAN);
--
1.6.0.2
Regards,
Simon
PATCH v2 6/21 net: Move ARP out of net.c
In reply to Joe Hershberger--- 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
@@ -422,7 +422,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
@@ -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
@@ -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 <common.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
PATCH v2 6/21 net: Move ARP out of net.c
Hi Joe,
Quoted 4 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
No changes?
Quoted 74 lines
---
?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 100644net/arp.hinclude/net.h +0
-0@@ -422,7 +422,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@@ -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.onet/arp.c new file +32
-0@@ -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;
net/arp.c line 42
Quoted 10 lines
net/arp.c new file +10
-0+/* THE transmit packet */ +uchar ? ? ? ? *NetArpWaitTxPacket; +int ? ? ? ? ? ?NetArpWaitTxPacketSize; +uchar ? ? ? ? ?NetArpWaitPacketBuf[PKTSIZE_ALIGN + PKTALIGN]; +ulong ? ? ? ? ?NetArpWaitTimerStart; +int ? ? ? ? ? ?NetArpWaitTry; + +void ArpInit(void) +{ + ? ? ? /* XXX problem with bss workaround */
I wonder what this is?
Quoted 482 lines
net/arp.c new file +171
-0+ ? ? ? 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@@ -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 <common.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@@ -79,6 +79,7 @@?#include <
command.h>
?#include <linux/compiler.h>
?#include <net.h>
+#include "arp.h"
?#include "bootp.h"
?#include "tftp.h"
?#ifdefCONFIG_CMD_RARPnet/net.c +0
-14@@ -99,20 +100,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@@ -219,82 +206,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@@ -362,15 +273,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@@ -382,12 +289,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; - ? ? ? } - ? ? ? ?bootstage_mark_name(BOOTSTAGE_ID_ETH_START, "eth_start"); ? ? ? ?eth_halt(); ? ? ? ?eth_set_current();@@ -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(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(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;
Quoted 4 lines
?#ifdef
CONFIG_CMD_RARP
--
1.6.0.2
Regards,
Simon
PATCH v2 7/21 net: Move PING out of net.c
In reply to Joe Hershberger---
Changes for v2:
- Moved config fixes to a separate patch
- Pushed #ifdef CONFIG_CMD_PING into header
- Eliminated CamelCase
net/Makefile | 1 + net/net.c | 133 ++----------------------------------------------------- net/ping.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/ping.h | 23 ++++++++++ 4 files changed, 168 insertions(+), 129 deletions(-) create mode 100644 net/ping.c create mode 100644 net/ping.h
net/Makefile +1 -0
@@ -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 +4 -129
165 lines not on this page · raw message
net/ping.c new file +140 -0
140 lines not on this page · raw message
net/ping.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* 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 +*/ + +#if defined(CONFIG_CMD_PING ) + +#ifndef __PING_H__ +#define __PING_H__ + +#include <common.h> +#include <net.h> + +void ping_start (void ); +void ping_receive (Ethernet_t *et,IP_t *ip,int len); + +#endif /* __PING_H__ */ +#endif
Signature · 1 line
1.6.0.2
PATCH v2 7/21 net: Move PING out of net.c
Hi Joe,
Quoted 4 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
Quoted 362 lines
---
Changes for v2:
? - Moved config fixes to a separate patch
? - Pushed #ifdefCONFIG_CMD_PINGinto header
? - Eliminated CamelCase?net/Makefile | ? ?1 + ?net/net.c ? ?| ?133 ++----------------------------------------------------- ?net/ping.c ? | ?140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ?net/ping.h ? | ? 23 ++++++++++?4 files changed, 168 insertions(+), 129 deletions(-) ?create mode 100644
net/ping.c
?create mode 100644net/ping.hnet/Makefile +0
-0@@ -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.onet/net.c +0
-0@@ -97,6 +97,7 @@ ?#if defined(CONFIG_CMD_DNS)?#include "
dns.h"
?#endif
+#include "ping.h"?DECLARE_GLOBAL_DATA_PTR;
net/net.c +0
-0@@ -167,13 +168,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@@ -358,7 +352,7 @@ restart:?#endif
?#ifdefined(CONFIG_CMD_PING)
? ? ? ? ? ? ? ?case PING:
- ? ? ? ? ? ? ? ? ? ? ?PingStart();
+ ? ? ? ? ? ? ? ? ? ? ?ping_start();
? ? ? ? ? ? ? ? ? ? ? ?break;
?#endif
?#ifdefined(CONFIG_CMD_NFS)net/net.c +0
-0@@ -653,94 +647,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, accordingnet/net.c +2
-32@@ -930,41 +836,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; + ? ? ? ? ? ? ? ping_receive(et, ip, len);?#endif
- ? ? ? default:
?#ifdefCONFIG_CMD_TFTPPUT
? ? ? ? ? ? ? ?if (packet_icmp_handler)
? ? ? ? ? ? ? ? ? ? ? ?packet_icmp_handler(icmph->type,icmph->code,net/ping.c new file +140
-0@@ -0,0 +1,140 @@ +/* + * ? ? 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 ping_send(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 ping_timeout(void) +{ + ? ? ? eth_halt(); + ? ? ? NetState = NETLOOP_FAIL; ? ? ? ?/* we did not get the reply */ +} + +static void ping_handler(uchar *pkt, unsigned dest, IPaddr_t sip, + ? ? ? ? ? unsigned src, unsigned len) +{ + ? ? ? if (sip != NetPingIP) + ? ? ? ? ? ? ? return; + + ? ? ? NetState = NETLOOP_SUCCESS; +} + +void ping_start(void) +{ + ? ? ? printf("Using %s device\n", eth_get_name()); + ? ? ? NetSetTimeout(10000UL, ping_timeout); + ? ? ? NetSetHandler(ping_handler); + + ? ? ? ping_send(); +} + +void ping_receive(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 +10
-0@@ -0,0 +1,23 @@ +/* +* ? ? 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/ping.h line 20
Quoted 10 lines
net/ping.h new file +10
-0+#if defined(CONFIG_CMD_PING ) + +#ifndef __PING_H__ +#define __PING_H__ + +#include <common.h> +#include <net.h> + +void ping_start (void ); +void ping_receive (Ethernet_t *et,IP_t *ip,int len);
Function comments would be nice
Quoted 6 lines
net/ping.h new file +3
-1+ +#endif /* __PING_H__ */ +#endif --1.6.0.2
Regards,
Simon
PATCH v2 8/21 net: Move RARP receive logic out of net.c
In reply to Joe Hershberger---
Changes for v2:
- Moved void to the same line as function
- Eliminate CamelCase in new function name
net/net.c | 27 +-------------------------- net/rarp.c | 45 +++++++++++++++++++++++++++++---------------- net/rarp.h | 6 +++--- 3 files changed, 33 insertions(+), 45 deletions(-)
net/net.c +1 -26
@@ -82,9 +82,7 @@#include "arp.h" #include "bootp.h" #include "tftp.h" -#ifdef CONFIG_CMD_RARP #include "rarp.h" -#endif #include "nfs.h" #ifdef CONFIG_STATUS_LED #include <status_led.h>
@@ -855,9 +853,6 @@ NetReceive(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;
@@ -962,27 +957,7 @@ NetReceive(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 ); - } +rarp_receive (ip, len);break ;#endif case PROT_IP :
net/rarp.c +29 -16
77 lines not on this page · raw message
net/rarp.h +3 -3
@@ -21,14 +21,12 @@* MA 02111-1307 USA */ +#if defined(CONFIG_CMD_RARP )#ifndef __RARP_H__#define __RARP_H__ -#ifndef __NET_H__#include <net.h> -#endif /* __NET_H__ */ -/**********************************************************************/ /*
@@ -37,8 +35,10 @@extern int RarpTry; +extern void rarp_receive (IP_t *ip,unsigned len);extern void RarpRequest (void );/* Send a RARP request */ /**********************************************************************/ #endif /* __RARP_H__ */ +#endif
Signature · 1 line
1.6.0.2
PATCH v2 8/21 net: Move RARP receive logic out of net.c
Hi Joe,
Quoted 5 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
Just a few nits, but otherwise:
Quoted 133 lines
---
Changes for v2:
- Moved void to the same line as function
- Eliminate CamelCase in new function namenet/net.c | 27 +-------------------------- net/rarp.c | 45 +++++++++++++++++++++++++++++---------------- net/rarp.h | 6 +++--- 3 files changed, 33 insertions(+), 45 deletions(-)net/net.c +1
-26@@ -82,9 +82,7 @@#include "arp.h" #include "bootp.h" #include "tftp.h" -#ifdef CONFIG_CMD_RARP #include "rarp.h" -#endif #include "nfs.h" #ifdef CONFIG_STATUS_LED #include <status_led.h> @@ -855,9 +853,6 @@ NetReceive(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;@@ -962,27 +957,7 @@ NetReceive(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 ); - } +rarp_receive (ip, len);break ;#endif case PROT_IP :net/rarp.c +27
-12@@ -36,26 +36,43 @@# define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)#endif - -int RarpTry; +int RarpTry;/* * Handle a RARP received packet. */ -static void -RarpHandler (uchar *dummi0,unsigned dummi1,IPaddr_t sip,unsigned dummi2, -unsigned dummi3) +void rarp_receive (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 (); + } }/* * Timeout on BOOTP request. */ -static void -RarpTimeout (void ) +static void RarpTimeout (void ) {if (RarpTry >=TIMEOUT_COUNT ) {puts ("\nRetry count exceeded; starting again\n" );@@ -67,10 +84,8 @@ RarpTimeout(void) } -void -RarpRequest (void ) +void RarpRequest (void ) { -int i;uchar *pkt;ARP_t *rarp;
net/rarp.c RarpRequest(void) · line 111
Quoted 10 lines
net/rarp.c +2
-3@@ -90,12 +105,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 );
Remove extra spaces perhaps
Quoted 27 lines
net/rarp.c +0
-1NetSendPacket (NetTxPacket, (pkt - NetTxPacket) +ARP_HDR_SIZE );NetSetTimeout (TIMEOUT , RarpTimeout); -NetSetHandler (RarpHandler);}
net/rarp.h +1
-3@@ -21,14 +21,12 @@* MA 02111-1307 USA */ +#if defined(CONFIG_CMD_RARP )#ifndef __RARP_H__#define __RARP_H__ -#ifndef __NET_H__#include <net.h> -#endif /* __NET_H__ */ -/**********************************************************************/ /*
net/rarp.h line 39
Quoted 5 lines
net/rarp.h +1
-0@@ -37,8 +35,10 @@extern int RarpTry; +extern void rarp_receive (IP_t *ip,unsigned len);
How about a comment on this?
Quoted 10 lines
net/rarp.h +1
-1extern void RarpRequest (void );/* Send a RARP request */ /**********************************************************************/ #endif /* __RARP_H__ */ +#endif --1.6.0.2
PATCH v2 9/21 net: cosmetic: Un-typedef IP_t
In reply to Joe HershbergerRename IP header related things to IP_UDP. The existing definition of IP_t includes UDP header, so name it to accurately describe the structure. Also add a structure that only contains IP header fields to be used by functions that don't need UDP.
---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Created a new IP_UDP_hdr struct and removed UDP members from IP_hdr
- Renamed structs from *_t to *_hdr since they are nolonger types
drivers/net/netconsole.c | 4 +- include/net.h | 33 +++++++++++++++----- net/arp.c | 2 +- net/arp.h | 2 +- net/bootp.c | 6 ++-- net/bootp.h | 2 +- net/dns.c | 2 +- net/net.c | 78 +++++++++++++++++++++++---------------------- net/nfs.c | 2 +- net/ping.c | 16 +++++----- net/ping.h | 2 +- net/rarp.c | 2 +- net/rarp.h | 2 +- net/sntp.c | 2 +- net/tftp.c | 2 +- 15 files changed, 88 insertions(+), 69 deletions(-)
drivers/net/netconsole.c +2 -2
@@ -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 +25 -8
@@ -195,7 +195,7 @@ typedef struct {/* * Internet Protocol (IP) header. */ -typedef struct { +struct IP_hdr {uchar ip_hl_v;/* header length and version */ uchar ip_tos;/* type of service */ ushort ip_len;/* total length */
@@ -206,11 +206,7 @@ typedef struct {ushort ip_sum;/* checksum */ IPaddr_t ip_src;/* Source IP address */ IPaddr_t ip_dst;/* Destination IP address */ -ushort udp_src;/* UDP source port */ -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,9 +214,30 @@ 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 (sizeof(struct IP_hdr)) + +/* +* Internet Protocol (IP) + UDP header. +*/ +struct IP_UDP_hdr { +uchar ip_hl_v;/* header length and version */ +uchar ip_tos;/* type of service */ +ushort ip_len;/* total length */ +ushort ip_id;/* identification */ +ushort ip_off;/* fragment offset field */ +uchar ip_ttl;/* time to live */ +uchar ip_p;/* protocol */ +ushort ip_sum;/* checksum */ +IPaddr_t ip_src;/* Source IP address */ +IPaddr_t ip_dst;/* Destination IP address */ +ushort udp_src;/* UDP source port */ +ushort udp_dst;/* UDP destination port */ +ushort udp_len;/* Length of UDP packet */ +ushort udp_xsum;/* Checksum */ +}; +#define IP_UDP_HDR_SIZE (sizeof(struct IP_UDP_hdr)) +#define UDP_HDR_SIZE (IP_UDP_HDR_SIZE - IP_HDR_SIZE)/* * Address Resolution Protocol (ARP) header.
net/arp.c +1 -1
@@ -113,7 +113,7 @@ void ArpTimeoutCheck(void) } } -void ArpReceive (Ethernet_t *et,IP_t *ip,int len) +void ArpReceive (Ethernet_t *et,struct IP_UDP_hdr *ip,int len) {ARP_t *arp;IPaddr_t tmp;
net/arp.h +1 -1
@@ -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 (Ethernet_t *et,struct IP_UDP_hdr *ip,int len);#endif /* __ARP_H__ */
net/bootp.c +3 -3
@@ -623,8 +623,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 ;
@@ -809,7 +809,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
@@ -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/dns.c +1 -1
@@ -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 +40 -38
217 lines not on this page · raw message
net/nfs.c +1 -1
@@ -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 +8 -8
@@ -19,7 +19,7 @@ IPaddr_t NetPingIP;static int ping_send (void ) {static uchar mac[6 ]; -IP_t *ip; +struct IP_UDP_hdr *ip;ushort *s;uchar *pkt;
@@ -35,7 +35,7 @@ static int ping_send(void) pkt = NetArpWaitTxPacket; pkt +=NetSetEther (pkt, mac,PROT_IP ); - ip = (IP_t *)pkt; + ip = (struct IP_UDP_hdr *)pkt;/* * Construct an IP and ICMP header.
@@ -44,7 +44,7 @@ static int ping_send(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 ping_send(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 ping_send(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 ;
@@ -98,7 +98,7 @@ void ping_start(void)ping_send (); } -void ping_receive (Ethernet_t *et,IP_t *ip,int len) +void ping_receive (Ethernet_t *et,struct IP_UDP_hdr *ip,int len) {ICMP_t *icmph = (ICMP_t *)&(ip->udp_src);IPaddr_t src_ip;
@@ -125,12 +125,12 @@ void ping_receive(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
@@ -17,7 +17,7 @@#include <net.h> void ping_start (void ); -void ping_receive (Ethernet_t *et,IP_t *ip,int len); +void ping_receive (Ethernet_t *et,struct IP_UDP_hdr *ip,int len);#endif /* __PING_H__ */ #endif
net/rarp.c +1 -1
@@ -41,7 +41,7 @@ int RarpTry;/* * Handle a RARP received packet. */ -void rarp_receive (IP_t *ip,unsigned len) +void rarp_receive (struct IP_UDP_hdr *ip,unsigned len) {ARP_t *arp;
net/rarp.h +1 -1
@@ -35,7 +35,7 @@extern int RarpTry; -extern void rarp_receive (IP_t *ip,unsigned len); +extern void rarp_receive (struct IP_UDP_hdr *ip,unsigned len);extern void RarpRequest (void );/* Send a RARP request */ /**********************************************************************/
net/sntp.c +1 -1
@@ -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
@@ -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
PATCH v2 9/21 net: cosmetic: Un-typedef IP_t
Hi Joe,
Quoted 11 lines · Joe Hershberger
Rename IP header related things to
IP_UDP. The existing definition ofIP_tincludes UDP header, so name it to accurately describe the structure. Also add a structure that only contains IP header fields to be used by functions that don't need UDP.Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
I feel that these two changes should be separated.
Also, shouldn't we get rid of the capital letters in the structure names at this point? Or are you planning on doing that later?
Regards,
Simon
PATCH v2 10/21 net: cosmetic: Un-typedef Ethernet_t
In reply to Joe HershbergerSeparate the Ethernet header from the 802 header. Base the size constants on the structs.
---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Created a new E802_hdr struct and removed 802 members from Ethernet_hdr
- Renamed structs from *_t to *_hdr since they are nolonger types
- Replaced offsetof(Ethernet_t, et_dsap) with ETHER_HDR_SIZE in arch/powerpc/cpu/mpc8260/ether_fcc.c
arch/powerpc/cpu/mpc8260/ether_fcc.c | 17 ++++++++--------- include/net.h | 18 ++++++++++++++---- net/arp.c | 4 ++-- net/arp.h | 2 +- net/bootp.c | 2 +- net/cdp.c | 4 ++-- net/net.c | 11 ++++++----- net/ping.c | 2 +- net/ping.h | 2 +- 9 files changed, 36 insertions(+), 26 deletions(-)
arch/powerpc/cpu/mpc8260/ether_fcc.c +8 -9
@@ -1049,11 +1049,11 @@ eth_loopback_test (void) }else {ushort datlen = bdp->cbd_datlen; -Ethernet_t *ehp; +struct Ethernet_hdr *ehp;ushort prot;int ours, tb, n, nbytes; - ehp = (Ethernet_t *) \ + ehp = (struct Ethernet_hdr *) \ &ecp->rxbufs[i][0 ]; ours = memcmp (ehp->et_src, \
@@ -1063,9 +1063,8 @@ eth_loopback_test (void) tb = prot &0x8000 ; n = prot &0x7fff ; - nbytes =ELBT_BUFSZ - \ - offsetof (Ethernet_t , \ - et_dsap) - \ + nbytes =ELBT_BUFSZ - +ETHER_HDR_SIZE -ELBT_CRCSZ ;/* check the frame is correct */
@@ -1080,10 +1079,10 @@ eth_loopback_test (void) patwords[n];uint nbb; - nbb =badbits ( \ - &ehp->et_dsap, \ - nbytes, \ - patword); + nbb =badbits ( + ((uchar *)&ehp) + +ETHER_HDR_SIZE , + nbytes, patword); ecp->rxeacc.badbit += \ nbb;
include/net.h +14 -4
@@ -155,7 +155,17 @@ u32 ether_crc(size_t len, unsigned char const *p);/* * Ethernet header */ -typedef struct { + +struct Ethernet_hdr { +uchar et_dest[6 ];/* Destination node */ +uchar et_src[6 ];/* Source node */ +ushort et_protlen;/* Protocol or length */ +}; + +/* Ethernet header size */ +#define ETHER_HDR_SIZE (sizeof(struct Ethernet_hdr)) + +struct E802_hdr {uchar et_dest[6 ];/* Destination node */ uchar et_src[6 ];/* Source node */ ushort et_protlen;/* Protocol or length */
@@ -166,10 +176,10 @@ 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 */ +/* 802 ethernet header size */ +#define E802_HDR_SIZE (sizeof(struct E802_hdr))/* * Ethernet header
net/arp.c +2 -2
@@ -113,7 +113,7 @@ void ArpTimeoutCheck(void) } } -void ArpReceive (Ethernet_t *et,struct IP_UDP_hdr *ip,int len) +void ArpReceive (struct Ethernet_hdr *et,struct IP_UDP_hdr *ip,int len) {ARP_t *arp;IPaddr_t tmp;
@@ -193,7 +193,7 @@ void ArpReceive(Ethernet_t *et, struct IP_UDP_hdr *ip, int len)NetGetHandler ()(0 ,0 ,0 ,0 ,0 );#endif /* modify header, and transmit it */ -memcpy (((Ethernet_t *)NetArpWaitTxPacket)-> +memcpy (((struct Ethernet_hdr *)NetArpWaitTxPacket)-> et_dest, NetArpWaitPacketMAC,6 ); (void )eth_send (NetArpWaitTxPacket, NetArpWaitTxPacketSize);
net/arp.h +1 -1
@@ -25,6 +25,6 @@ extern int NetArpWaitTry;void ArpInit (void );void ArpRequest (void );void ArpTimeoutCheck (void ); -void ArpReceive (Ethernet_t *et,struct IP_UDP_hdr *ip,int len); +void ArpReceive (struct Ethernet_hdr *et,struct IP_UDP_hdr *ip,int len);#endif /* __ARP_H__ */
net/bootp.c +1 -1
@@ -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_hdr *)NetRxPacket)->et_src,6 );#endif if (strlen (bp->bp_file) >0 )copy_filename (BootFile, bp->bp_file,sizeof (BootFile));
net/cdp.c +2 -2
@@ -108,7 +108,7 @@ CDPSendTrigger(void)uchar *pkt;ushort *s;ushort *cp; -Ethernet_t *et; +struct Ethernet_hdr *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_hdr *)pkt;/* NOTE: trigger sent not on any VLAN */
net/net.c +6 -5
@@ -825,7 +825,7 @@ static inline struct IP_UDP_hdr *NetDefragment(struct IP_UDP_hdr *ip, int *lenp)* @parma ip IP packet containing the ICMP */ static void receive_icmp (struct IP_UDP_hdr *ip,int len, -IPaddr_t src_ip,Ethernet_t *et) +IPaddr_t src_ip,struct Ethernet_hdr *et) {ICMP_t *icmph = (ICMP_t *)&ip->udp_src;
@@ -853,7 +853,7 @@ static void receive_icmp(struct IP_UDP_hdr *ip, int len,void NetReceive (uchar *inpkt,int len) { -Ethernet_t *et; +struct Ethernet_hdr *et;struct IP_UDP_hdr *ip;IPaddr_t tmp;IPaddr_t src_ip;
@@ -867,7 +867,7 @@ NetReceive(uchar *inpkt, int len) NetRxPacket = inpkt; NetRxPacketLen = len; - et = (Ethernet_t *)inpkt; + et = (struct Ethernet_hdr *)inpkt;/* too small packet? */ if (len <ETHER_HDR_SIZE )
@@ -897,10 +897,11 @@ NetReceive(uchar *inpkt, int len)debug ("packet received\n" );if (x <1514 ) { +struct E802_hdr *et802 = (struct E802_hdr *)et;/* * Got a 802 packet. Check the other protocol field. */ - x =ntohs (et->et_prot); + x =ntohs (et802->et_prot); ip = (struct IP_UDP_hdr *)(inpkt +E802_HDR_SIZE ); len -=E802_HDR_SIZE ;
@@ -1220,7 +1221,7 @@ NetEthHdrSize(void)int NetSetEther (uchar *xet,uchar * addr,uint prot) { -Ethernet_t *et = (Ethernet_t *)xet; +struct Ethernet_hdr *et = (struct Ethernet_hdr *)xet;ushort myvlanid; myvlanid =ntohs (NetOurVLAN);
net/ping.c +1 -1
@@ -98,7 +98,7 @@ void ping_start(void)ping_send (); } -void ping_receive (Ethernet_t *et,struct IP_UDP_hdr *ip,int len) +void ping_receive (struct Ethernet_hdr *et,struct IP_UDP_hdr *ip,int len) {ICMP_t *icmph = (ICMP_t *)&(ip->udp_src);IPaddr_t src_ip;
net/ping.h +1 -1
@@ -17,7 +17,7 @@#include <net.h> void ping_start (void ); -void ping_receive (Ethernet_t *et,struct IP_UDP_hdr *ip,int len); +void ping_receive (struct Ethernet_hdr *et,struct IP_UDP_hdr *ip,int len);#endif /* __PING_H__ */ #endif
Signature · 1 line
1.6.0.2
PATCH v2 10/21 net: cosmetic: Un-typedef Ethernet_t
Hi Joe,
Quoted 8 lines · Joe Hershberger
Separate the Ethernet header from the 802 header. Base the size constants on the structs.
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
How about struct ethernet_hdr? Otherwise it looks good.
Just an aside - I assume that the sizeof() does not word align the result on any architectures? In other words, does sizeof(struct Ethernet_hdr) definitely give you 14 instead of 16 in all cases? I am sure this might be right, or it would have broken things horribly.
Regards,
Simon
Quoted 8 lines
---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Created a newE802_hdrstruct and removed 802 members fromEthernet_hdr
- Renamed structs from *_t to*_hdrsince they are nolonger types
- Replacedoffsetof(Ethernet_t, et_dsap)withETHER_HDR_SIZEinarch/powerpc/cpu/mpc8260/ether_fcc.c
PATCH v2 11/21 net: cosmetic: Un-typedef VLAN_Ethernet_t
In reply to Joe Hershberger---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Renamed structs from *_t to *_hdr since they are nolonger types
include/net.h | 7 ++++--- net/net.c | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-)
include/net.h +4 -3
@@ -184,15 +184,16 @@ struct E802_hdr {/* * Ethernet header */ -typedef struct { +struct VLAN_Ethernet_hdr {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 */ +/* VLAN Ethernet header size */ +#define VLAN_ETHER_HDR_SIZE (sizeof(struct VLAN_Ethernet_hdr))#define PROT_IP 0x0800/* IP protocol */ #define PROT_ARP 0x0806/* IP ARP protocol */
net/net.c +4 -2
@@ -911,7 +911,8 @@ NetReceive(uchar *inpkt, int len) len -=ETHER_HDR_SIZE ; }else {/* VLAN packet */ -VLAN_Ethernet_t *vet = (VLAN_Ethernet_t *)et; +struct VLAN_Ethernet_hdr *vet = + (struct VLAN_Ethernet_hdr *)et;debug ("VLAN packet received\n" );
@@ -1234,7 +1235,8 @@ NetSetEther(uchar *xet, uchar * addr, uint prot) et->et_protlen =htons (prot);return ETHER_HDR_SIZE ; }else { -VLAN_Ethernet_t *vet = (VLAN_Ethernet_t *)xet; +struct VLAN_Ethernet_hdr *vet = + (struct VLAN_Ethernet_hdr *)xet; vet->vet_vlan_type =htons (PROT_VLAN ); vet->vet_tag =htons ((0 <<5 ) | (myvlanid &VLAN_IDMASK ));
Signature · 1 line
1.6.0.2
PATCH v2 11/21 net: cosmetic: Un-typedef VLAN_Ethernet_t
Hi Joe,
Quoted 9 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Renamed structs from *_t to*_hdrsince they are nolonger types
Same comment about lower case in structure name. What is the plan here?
Regards,
Simon
Quoted 58 lines
include/net.h | 7 ++++--- net/net.c | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-)include/net.h +4
-3@@ -184,15 +184,16 @@ struct E802_hdr {/* * Ethernet header */ -typedef struct { +struct VLAN_Ethernet_hdr {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 */ +/* VLAN Ethernet header size */ +#define VLAN_ETHER_HDR_SIZE (sizeof(struct VLAN_Ethernet_hdr))#define PROT_IP 0x0800/* IP protocol */ #define
PROT_ARP0x0806/* IP ARP protocol */net/net.c +4
-3@@ -911,7 +911,8 @@ NetReceive(uchar *inpkt, int len) len -=ETHER_HDR_SIZE ; }else {/* VLAN packet */ -VLAN_Ethernet_t *vet = (VLAN_Ethernet_t *)et; +struct VLAN_Ethernet_hdr *vet = + (struct VLAN_Ethernet_hdr *)et;debug ("VLAN packet received\n" );@@ -1234,7 +1235,8 @@ NetSetEther(uchar *xet, uchar * addr, uint prot) et->et_protlen =htons (prot);return ETHER_HDR_SIZE ; }else { -VLAN_Ethernet_t *vet = (VLAN_Ethernet_t *)xet; +struct VLAN_Ethernet_hdr *vet = + (struct VLAN_Ethernet_hdr *)xet; vet->vet_vlan_type =htons (PROT_VLAN ); vet->vet_tag =htons ((0 <<5 ) | (myvlanid &VLAN_IDMASK )); --1.6.0.2
PATCH v2 12/21 net: cosmetic: Un-typedef ARP_t
In reply to Joe Hershberger---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Renamed structs from *_t to *_hdr since they are nolonger types
include/net.h | 5 ++--- net/arp.c | 8 ++++---- net/rarp.c | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-)
include/net.h +2 -3
@@ -253,8 +253,7 @@ struct IP_UDP_hdr {/* * Address Resolution Protocol (ARP) header. */ -typedef struct -{ +struct ARP_hdr {ushort ar_hrd;/* Format of hardware address */ # define ARP_ETHER 1/* Ethernet hardware address */ ushort ar_pro;/* Format of protocol address */
@@ -279,7 +278,7 @@ typedef structuchar ar_tha[];/* Target hardware address */ uchar ar_tpa[];/* Target protocol address */ #endif /* 0 */ -} ARP_t; +};#define ARP_HDR_SIZE (8+20)/* Size assuming ethernet */
net/arp.c +4 -4
@@ -51,7 +51,7 @@ void ArpInit(void)void ArpRequest (void ) {uchar *pkt; -ARP_t *arp; +struct ARP_hdr *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_hdr *) pkt; arp->ar_hrd =htons (ARP_ETHER ); arp->ar_pro =htons (PROT_IP );
@@ -115,7 +115,7 @@ void ArpTimeoutCheck(void)void ArpReceive (struct Ethernet_hdr *et,struct IP_UDP_hdr *ip,int len) { -ARP_t *arp; +struct ARP_hdr *arp;IPaddr_t tmp;uchar *pkt;
@@ -130,7 +130,7 @@ void ArpReceive(struct Ethernet_hdr *et, struct IP_UDP_hdr *ip, int len)*/ debug ("Got ARP\n" ); - arp = (ARP_t *)ip; + arp = (struct ARP_hdr *)ip;if (len <ARP_HDR_SIZE ) {printf ("bad length %d < %d\n" , len,ARP_HDR_SIZE );return ;
net/rarp.c +4 -4
@@ -43,10 +43,10 @@ int RarpTry;*/ void rarp_receive (struct IP_UDP_hdr *ip,unsigned len) { -ARP_t *arp; +struct ARP_hdr *arp;debug ("Got RARP\n" ); - arp = (ARP_t *)ip; + arp = (struct ARP_hdr *)ip;if (len <ARP_HDR_SIZE ) {printf ("bad length %d < %d\n" , len,ARP_HDR_SIZE );return ;
@@ -87,14 +87,14 @@ static void RarpTimeout(void)void RarpRequest (void ) {uchar *pkt; -ARP_t *rarp; +struct ARP_hdr *rarp;printf ("RARP broadcast %d\n" , ++RarpTry); pkt = NetTxPacket; pkt +=NetSetEther (pkt, NetBcastAddr,PROT_RARP ); - rarp = (ARP_t *)pkt; + rarp = (struct ARP_hdr *)pkt; rarp->ar_hrd =htons (ARP_ETHER ); rarp->ar_pro =htons (PROT_IP );
Signature · 1 line
1.6.0.2
PATCH v2 12/21 net: cosmetic: Un-typedef ARP_t
Hi Joe,
Quoted 9 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Renamed structs from *_t to*_hdrsince they are nolonger types
struct arp_hdr?
Regards,
Simon
Quoted 108 lines
include/net.h | 5 ++--- net/arp.c | 8 ++++---- net/rarp.c | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-)include/net.h +2
-3@@ -253,8 +253,7 @@ struct IP_UDP_hdr {/* * Address Resolution Protocol (ARP) header. */ -typedef struct -{ +struct ARP_hdr {ushort ar_hrd;/* Format of hardware address */ # define ARP_ETHER 1/* Ethernet hardware address */ ushort ar_pro;/* Format of protocol address */ @@ -279,7 +278,7 @@ typedef structuchar ar_tha[];/* Target hardware address */ uchar ar_tpa[];/* Target protocol address */ #endif /* 0 */ -} ARP_t; +};#define ARP_HDR_SIZE (8+20)/* Size assuming ethernet */ net/arp.c +4
-4@@ -51,7 +51,7 @@ void ArpInit(void)void ArpRequest (void ) {uchar *pkt; -ARP_t *arp; +struct ARP_hdr *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_hdr *) pkt; arp->ar_hrd =htons (ARP_ETHER ); arp->ar_pro =htons (PROT_IP );@@ -115,7 +115,7 @@ void ArpTimeoutCheck(void)void ArpReceive (struct Ethernet_hdr *et,struct IP_UDP_hdr *ip,int len) { -ARP_t *arp; +struct ARP_hdr *arp;IPaddr_t tmp;uchar *pkt;@@ -130,7 +130,7 @@ void ArpReceive(struct Ethernet_hdr *et, structIP_UDP_hdr *ip, int len) */ debug ("Got ARP\n" ); - arp = (ARP_t *)ip; + arp = (struct ARP_hdr *)ip;if (len <ARP_HDR_SIZE ) {printf ("bad length %d < %d\n" , len,ARP_HDR_SIZE );return;net/rarp.c +4
-5@@ -43,10 +43,10 @@ int RarpTry;*/ void rarp_receive (struct IP_UDP_hdr *ip,unsigned len) { -ARP_t *arp; +struct ARP_hdr *arp;debug ("Got RARP\n" ); - arp = (ARP_t *)ip; + arp = (struct ARP_hdr *)ip;if (len <ARP_HDR_SIZE ) {printf ("bad length %d < %d\n" , len,ARP_HDR_SIZE );return ;@@ -87,14 +87,14 @@ static void RarpTimeout(void)void RarpRequest (void ) {uchar *pkt; -ARP_t *rarp; +struct ARP_hdr *rarp;printf ("RARP broadcast %d\n" , ++RarpTry); pkt = NetTxPacket; pkt +=NetSetEther (pkt, NetBcastAddr,PROT_RARP ); - rarp = (ARP_t *)pkt; + rarp = (struct ARP_hdr *)pkt; rarp->ar_hrd =htons (ARP_ETHER ); rarp->ar_pro =htons (PROT_IP ); --1.6.0.2
PATCH v2 13/21 net: cosmetic: Un-typedef ICMP_t
In reply to Joe Hershberger---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Renamed structs from *_t to *_hdr since they are nolonger types
include/net.h | 6 ++++-- net/net.c | 2 +- net/ping.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-)
include/net.h +4 -2
@@ -297,7 +297,7 @@ struct ARP_hdr {/* Codes for NOT_REACH */ #define ICMP_NOT_REACH_PORT 3/* Port unreachable */ -typedef struct icmphdr { +struct ICMP_hdr {uchar type;uchar code;ushort checksum;
@@ -313,8 +313,10 @@ typedef struct icmphdr { } frag;uchar data[0 ]; } un; -} ICMP_t; +}; +#define ICMP_HDR_SIZE (sizeof(struct ICMP_hdr)) +#define IP_ICMP_HDR_SIZE (IP_HDR_SIZE + ICMP_HDR_SIZE)/* * Maximum packet size; used to allocate packet storage.
net/net.c +1 -1
@@ -827,7 +827,7 @@ static inline struct IP_UDP_hdr *NetDefragment(struct IP_UDP_hdr *ip, int *lenp)static void receive_icmp (struct IP_UDP_hdr *ip,int len,IPaddr_t src_ip,struct Ethernet_hdr *et) { -ICMP_t *icmph = (ICMP_t *)&ip->udp_src; +struct ICMP_hdr *icmph = (struct ICMP_hdr *)&(ip->udp_src);switch (icmph->type) {case ICMP_REDIRECT :
net/ping.c +1 -1
@@ -100,7 +100,7 @@ void ping_start(void)void ping_receive (struct Ethernet_hdr *et,struct IP_UDP_hdr *ip,int len) { -ICMP_t *icmph = (ICMP_t *)&(ip->udp_src); +struct ICMP_hdr *icmph = (struct ICMP_hdr *)&(ip->udp_src);IPaddr_t src_ip;switch (icmph->type) {
Signature · 1 line
1.6.0.2
PATCH v2 13/21 net: cosmetic: Un-typedef ICMP_t
Hi Joe,
Quoted 19 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>---
Changes for v2:
- Split apart from "Un-typedef variables in net"
- Renamed structs from *_t to*_hdrsince they are nolonger typesinclude/net.h | 6 ++++-- net/net.c | 2 +- net/ping.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-)include/net.h +0
-0
include/net.h struct ARP_hdr { · line 301
Quoted 6 lines
include/net.h +1
-1@@ -297,7 +297,7 @@ struct ARP_hdr {/* Codes for NOT_REACH */ #define ICMP_NOT_REACH_PORT 3/* Port unreachable */ -typedef struct icmphdr { +struct ICMP_hdr {
struct icmp_hdr might be better?
uchar type;
Quoted 19 lines
include/net.h +3
-1uchar code;ushort checksum;@@ -313,8 +313,10 @@ typedef struct icmphdr { } frag;uchar data[0 ]; } un; -} ICMP_t; +}; +#define ICMP_HDR_SIZE (sizeof(struct ICMP_hdr)) +#define IP_ICMP_HDR_SIZE (IP_HDR_SIZE + ICMP_HDR_SIZE)/* * Maximum packet size; used to allocate packet storage. net/net.c +0
-0
net/net.c static inline struct IP_UDP_hdr *NetDefragment(struct · line 832
Quoted 7 lines
net/net.c +1
-1@@ -827,7 +827,7 @@ static inline struct IP_UDP_hdr *NetDefragment(struct IP_UDP_hdr *ip, int *lenp)static void receive_icmp (struct IP_UDP_hdr *ip,int len,IPaddr_t src_ip,struct Ethernet_hdr *et) { -ICMP_t *icmph = (ICMP_t *)&ip->udp_src; +struct ICMP_hdr *icmph = (struct ICMP_hdr *)&(ip->udp_src);
I don't think you need to add the second lot of brackets.
Quoted 8 lines
net/net.c +0
-0switch (icmph->type) {case
ICMP_REDIRECT:net/ping.c +0
-0
net/ping.c void ping_start(void) · line 104
Quoted 6 lines
net/ping.c +1
-1@@ -100,7 +100,7 @@ void ping_start(void)void ping_receive (struct Ethernet_hdr *et,struct IP_UDP_hdr *ip,int len) { -ICMP_t *icmph = (ICMP_t *)&(ip->udp_src); +struct ICMP_hdr *icmph = (struct ICMP_hdr *)&(ip->udp_src);
Same here.
Quoted 7 lines
net/ping.c +0
-0IPaddr_t src_ip;switch (icmph->type) {--
1.6.0.2
Regards,
Simon
PATCH v2 14/21 net: cosmetic: Rename parameter len to payload_len
In reply to Joe HershbergerThis name more explicitly claims that it does not include the header size
---
Changes for v2:
- Split from "Improve variable names and code readability"
include/net.h | 2 +- net/net.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-)
include/net.h +1 -1
@@ -462,7 +462,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 (uchar *,int );
net/net.c +8 -6
@@ -594,7 +594,8 @@ NetSendPacket(uchar *pkt, int len) }int -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;
@@ -620,14 +621,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 ;
@@ -640,8 +641,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 */ }
Signature · 1 line
1.6.0.2
PATCH v2 14/21 net: cosmetic: Rename parameter len to payload_len
Hi Joe,
Quoted 8 lines · Joe Hershberger
This name more explicitly claims that it does not include the header size
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
Quoted 13 lines
---
Changes for v2:
- Split from "Improve variable names and code readability"include/net.h | 2 +- net/net.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-)include/net.h +0
-0
include/net.h extern void NetSendPacket(uchar *, int); · line 466
Quoted 6 lines
include/net.h +1
-1@@ -462,7 +462,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);
Would be nice to document the arguments here
Quoted 53 lines
include/net.h +0
-0/* Processes a received packet */ extern void NetReceive (uchar *,int );net/net.c +5
-4@@ -594,7 +594,8 @@ NetSendPacket(uchar *pkt, int len) }int -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;@@ -620,14 +621,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@@ -640,8 +641,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 */ }
--
1.6.0.2
Quoted 1 line
Regards,
Simon
PATCH v2 15/21 net: cosmetic: Add a more explicit comment about 802.2
In reply to Joe Hershberger---
Changes for v2:
- Split from "Improve variable names and code readability"
- Fixed comment indention
include/net.h | 2 +- net/net.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
include/net.h +1 -1
@@ -178,7 +178,7 @@ struct E802_hdr {ushort et_prot;/* 802 protocol */ }; -/* 802 ethernet header size */ +/* 802 + SNAP + ethernet header size */ #define E802_HDR_SIZE (sizeof(struct E802_hdr))/*
net/net.c +2 -1
@@ -901,7 +901,8 @@ NetReceive(uchar *inpkt, int len)if (x <1514 ) {struct E802_hdr *et802 = (struct E802_hdr *)et;/* -* 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 (et802->et_prot);
Signature · 1 line
1.6.0.2
PATCH v2 15/21 net: cosmetic: Add a more explicit comment about 802.2
Hi Joe,
Quoted 5 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
A general comment - it would be good to have a short commit message on all patches.
Regards,
Simon
Quoted 41 lines
---
Changes for v2:
- Split from "Improve variable names and code readability"
- Fixed comment indentioninclude/net.h | 2 +- net/net.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)include/net.h +1
-1@@ -178,7 +178,7 @@ struct E802_hdr {ushort et_prot;/* 802 protocol */ }; -/* 802 ethernet header size */ +/* 802 + SNAP + ethernet header size */ #define E802_HDR_SIZE (sizeof(struct E802_hdr))/* net/net.c +1
-1@@ -901,7 +901,8 @@ NetReceive(uchar *inpkt, int len)if (x <1514 ) {struct E802_hdr *et802 = (struct E802_hdr *)et;/* -* 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(et802->et_prot);--
1.6.0.2
PATCH v2 16/21 net: cosmetic: Rename "x" to "eth_proto"
In reply to Joe Hershbergerx is a poor variable name
---
Changes for v2:
- Split from "Improve variable names and code readability"
net/net.c | 24 ++++++++++++------------ 1 files changed, 12 insertions(+), 12 deletions(-)
net/net.c +12 -12
@@ -857,9 +857,9 @@ NetReceive(uchar *inpkt, int len) {struct Ethernet_hdr *et;struct IP_UDP_hdr *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
@@ -894,22 +894,22 @@ NetReceive(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 ) {struct E802_hdr *et802 = (struct E802_hdr *)et;/* * Got a 802.2 packet. Check the other protocol field. * XXX VLAN over 802.2+SNAP not implemented! */ - x =ntohs (et802->et_prot); + eth_proto =ntohs (et802->et_prot); ip = (struct IP_UDP_hdr *)(inpkt +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_hdr *)(inpkt +ETHER_HDR_SIZE ); len -=ETHER_HDR_SIZE ;
@@ -933,13 +933,13 @@ NetReceive(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_hdr *)(inpkt +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) {
@@ -956,7 +956,7 @@ NetReceive(uchar *inpkt, int len)return ; } -switch (x) { +switch (eth_proto) {case PROT_ARP :ArpReceive (et, ip, len);
@@ -995,10 +995,10 @@ NetReceive(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 ; }
Signature · 1 line
1.6.0.2
PATCH v2 16/21 net: cosmetic: Rename "x" to "eth_proto"
Quoted 7 lines · Joe Hershberger
x is a poor variable name
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>
Quoted 94 lines
---
Changes for v2:
- Split from "Improve variable names and code readability"net/net.c | 24 ++++++++++++------------ 1 files changed, 12 insertions(+), 12 deletions(-)net/net.c +12
-12@@ -857,9 +857,9 @@ NetReceive(uchar *inpkt, int len) {struct Ethernet_hdr *et;struct IP_UDP_hdr *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 @@ -894,22 +894,22 @@ NetReceive(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 ) {struct E802_hdr *et802 = (struct E802_hdr *)et;/* * Got a 802.2 packet. Check the other protocol field. * XXX VLAN over 802.2+SNAP not implemented! */ - x =ntohs (et802->et_prot); + eth_proto =ntohs (et802->et_prot); ip = (struct IP_UDP_hdr *)(inpkt +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_hdr *)(inpkt +ETHER_HDR_SIZE ); len -=ETHER_HDR_SIZE ;@@ -933,13 +933,13 @@ NetReceive(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_hdr *)(inpkt +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) {@@ -956,7 +956,7 @@ NetReceive(uchar *inpkt, int len)return ; } -switch (x) { +switch (eth_proto) {case PROT_ARP :ArpReceive (et, ip, len);@@ -995,10 +995,10 @@ NetReceive(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
PATCH v2 17/21 net: cosmetic: Rename CDPHandler to CDPReceive
In reply to Joe HershbergerThis is not called as a handler, so don't name it that way
---
Changes for v2:
- Split from "Improve variable names and code readability"
net/cdp.c | 2 +- net/cdp.h | 2 +- net/net.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
net/cdp.c +1 -1
@@ -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
@@ -14,7 +14,7 @@#define __CDP_H__void CDPStart (void ); -void CDPHandler (const uchar *pkt,unsigned len); +void CDPReceive (const uchar *pkt,unsigned len);#endif /* __CDP_H__ */ #endif
net/net.c +1 -1
@@ -943,7 +943,7 @@ NetReceive(uchar *inpkt, int len)#if defined(CONFIG_CMD_CDP )if (iscdp) { -CDPHandler ((uchar *)ip, len); +CDPReceive ((uchar *)ip, len);return ; }#endif
Signature · 1 line
1.6.0.2
PATCH v2 17/21 net: cosmetic: Rename CDPHandler to CDPReceive
Hi Joe,
Quoted 20 lines · Joe Hershberger
This is not called as a handler, so don't name it that way
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>---
Changes for v2:
- Split from "Improve variable names and code readability"net/cdp.c | 2 +- net/cdp.h | 2 +- net/net.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)net/cdp.c +0
-0
net/cdp.c CDPDummyHandler(uchar *pkt, unsigned dest, IPaddr_t · line 250
Quoted 7 lines
net/cdp.c +1
-1@@ -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)
cdp_receive?
Quoted 8 lines
net/cdp.c +0
-0{const uchar *t; const ushort *ss;net/cdp.h +0
-0
net/cdp.h line 18
Quoted 6 lines
net/cdp.h +1
-1@@ -14,7 +14,7 @@#define __CDP_H__void CDPStart (void ); -void CDPHandler (const uchar *pkt,unsigned len); +void CDPReceive (const uchar *pkt,unsigned len);
How about a comment on the function?
Quoted 19 lines
net/cdp.h +0
-0#endif /* __CDP_H__ */ #endif net/net.c +1
-2@@ -943,7 +943,7 @@ NetReceive(uchar *inpkt, int len)#if defined(CONFIG_CMD_CDP )if (iscdp) { -CDPHandler ((uchar *)ip, len); +CDPReceive ((uchar *)ip, len);return ; }#endif --1.6.0.2
Quoted 1 line
Regards,
Simon
PATCH v2 18/21 net: cosmetic: Rename OPT_SIZE to OPT_FIELD_SIZE
In reply to Joe HershbergerClearer constant name.
Also remove related BOOTP_SIZE which was unused and doesn't take into account VLAN packets.
---
Changes for v2:
- Split from "Improve variable names and code readability"
net/bootp.c | 10 +++++----- net/bootp.h | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-)
net/bootp.c +5 -5
@@ -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 &&
@@ -370,8 +370,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);
@@ -521,8 +521,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
@@ -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)/**********************************************************************/ /*
Signature · 1 line
1.6.0.2
PATCH v2 18/21 net: cosmetic: Rename OPT_SIZE to OPT_FIELD_SIZE
Hi Joe,
Quoted 31 lines · Joe Hershberger
Clearer constant name.
Also remove relatedBOOTP_SIZEwhich was unused and doesn't take into account VLAN packets.Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>---
Changes for v2:
- Split from "Improve variable names and code readability"net/bootp.c | 10 +++++----- net/bootp.h | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-)net/bootp.c +1
-1@@ -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 static int DhcpExtended(u8 *e, int message_type, · line 376
Quoted 9 lines
net/bootp.c +2
-2@@ -370,8 +370,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 ;
Better to use a temporary variable here, and below?
Quoted 50 lines
net/bootp.c +0
-0if (ServerID) {int tmp = ntohl(ServerID);net/bootp.c +2
-2@@ -521,8 +521,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
-5@@ -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)/**********************************************************************/ /* -- 1.6.0.2
Quoted 1 line
Regards,
Simon
PATCH v2 19/21 net: cosmetic: Alphabetize includes in net.c
In reply to Joe Hershberger---
Changes for v2:
- Split from "Improve variable names and code readability"
net/net.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
net/net.c +10 -10
@@ -75,27 +75,27 @@#include <common.h> -#include <watchdog.h> #include <command.h> #include <linux/compiler.h> #include <net.h> -#include "arp.h" -#include "bootp.h" -#include "tftp.h" -#include "rarp.h" -#include "nfs.h" -#ifdef CONFIG_STATUS_LED +#if defined(CONFIG_STATUS_LED )#include <status_led.h> #include <miiphy.h> #endif -#if defined(CONFIG_CMD_SNTP ) -#include "sntp.h" -#endif +#include <watchdog.h> +#include "arp.h" +#include "bootp.h" #include "cdp.h" #if defined(CONFIG_CMD_DNS )#include "dns.h" #endif +#include "nfs.h" #include "ping.h" +#include "rarp.h" +#if defined(CONFIG_CMD_SNTP ) +#include "sntp.h" +#endif +#include "tftp.h" DECLARE_GLOBAL_DATA_PTR ;
Signature · 1 line
1.6.0.2
PATCH v2 19/21 net: cosmetic: Alphabetize includes in net.c
Hi Joe,
Quoted 16 lines · Joe Hershberger
Signed-off-by Joe Hershberger <[email protected]>Cc Joe Hershberger <[email protected]>Cc Simon Glass <[email protected]>Cc Mike Frysinger <[email protected]>---
Changes for v2:
- Split from "Improve variable names and code readability"net/net.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)net/net.c +0
-0
net/net.c line 80
Quoted 7 lines
net/net.c +0
-1@@ -75,27 +75,27 @@#include <common.h> -#include <watchdog.h> #include <command.h> #include <linux/compiler.h>
put this just above "arp.h" I think
net/net.c line 99
Quoted 11 lines
net/net.c +1
-6#include <net.h> -#include "arp.h" -#include "bootp.h" -#include "tftp.h" -#include "rarp.h" -#include "nfs.h" -#ifdef CONFIG_STATUS_LED +#if defined(CONFIG_STATUS_LED )#include <status_led.h> #include <miiphy.h>
Swap those?
Quoted 21 lines
net/net.c +9
-3#endif -#if defined(CONFIG_CMD_SNTP ) -#include "sntp.h" -#endif +#include <watchdog.h> +#include "arp.h" +#include "bootp.h" #include "cdp.h" #if defined(CONFIG_CMD_DNS )#include "dns.h" #endif +#include "nfs.h" #include "ping.h" +#include "rarp.h" +#if defined(CONFIG_CMD_SNTP ) +#include "sntp.h" +#endif +#include "tftp.h"
DECLARE_GLOBAL_DATA_PTR;
Quoted 4 lines
--
1.6.0.2
Regards,
Simon
v2 cover Network stack refactoring
In reply to Joe HershbergerThis patch-series fixes a number of bugs in the network stack as well as improve the readability and maintainability of the network stack by eliminating duplicated code. These are more substantial changes than those in the "Network stack cosmetic improvements" series.
This is dependant on the "Network stack cosmetic improvements" patch-series.
This is a portion of the changes split from the series:
"Add link-local addressing support"
Joe Hershberger (18):
net: Refactor IP, UPD, and ICMP header writing functions
net: Refactor NetSendUDPPacket to share more code
net: Refactor packet length computations
net: Refactor bootp packet length computations
net: Move debug trace to point of action
net: Refactor ping receive handler
net: Refactor to use NetSendPacket instead of eth_send directly
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 and Ping replies
net: Don't write the "serverip" env var if configured not to
net: Fix unused variable compile warning
net: Add option CONFIG_BOOTP_MAY_FAIL
net: Remove static allocation for MAC address in PingSend()
net: Remove unused parameter from NetInitLoop()
net: Fix net buffer initialization
net: Make sure NetLoop is initialized when using NetConsole
net: Don't copy every packet that waits for an ARP
README | 7 ++ common/cmd_net.c | 6 +- drivers/net/netconsole.c | 14 ++- include/net.h | 38 +++++-- net/arp.c | 48 +++++---- net/arp.h | 2 - net/bootp.c | 50 +++++---- net/cdp.c | 12 +-- net/dns.c | 10 +- net/net.c | 263 +++++++++++++++++++++++++++++----------------- net/nfs.c | 10 +- net/ping.c | 95 ++++++----------- net/rarp.c | 6 +- net/sntp.c | 6 +- net/tftp.c | 12 +- 15 files changed, 325 insertions(+), 254 deletions(-)
v3 cover Network stack refactoring
This patch-series fixes a number of bugs in the network stack as well as improve the readability and maintainability of the network stack by eliminating duplicated code. These are more substantial changes than those in the "Network stack cosmetic improvements" series.
This is dependant on the "Network stack cosmetic improvements" patch-series.
This is a portion of the changes split from the series:
"Add link-local addressing support"
Joe Hershberger (18):
net: Refactor IP, UPD, and ICMP header writing functions
net: Refactor NetSendUDPPacket to share more code
net: Refactor packet length computations
net: Refactor bootp packet length computations
net: Move debug trace to point of action
net: Refactor ping receive handler
net: Refactor to use NetSendPacket instead of eth_send directly
net: Refactor to protect access to the NetState variable
net: Refactor to separate the UDP handler from the ARP handler
net: Add net_update_ether() to handle ARP and Ping replies
net: Don't write the "serverip" env var if configured not to
net: Fix unused variable compile warning
net: Add option CONFIG_BOOTP_MAY_FAIL
net: Remove static allocation for MAC address in PingSend()
net: Remove unused parameter from NetInitLoop()
net: Fix net buffer initialization
net: Make sure NetLoop is initialized when using NetConsole
net: Don't copy every packet that waits for an ARP
README | 7 ++ common/cmd_net.c | 8 +- drivers/net/netconsole.c | 16 ++- include/net.h | 44 ++++++--- net/arp.c | 48 +++++---- net/arp.h | 2 - net/bootp.c | 50 +++++---- net/cdp.c | 12 +-- net/dns.c | 10 +- net/net.c | 264 +++++++++++++++++++++++++++++----------------- net/nfs.c | 14 ++-- net/ping.c | 95 ++++++----------- net/rarp.c | 6 +- net/sntp.c | 6 +- net/tftp.c | 12 +- 15 files changed, 337 insertions(+), 257 deletions(-)
PATCH v3 1/18 net: Refactor IP, UPD, and ICMP header writing functions
In reply to Joe HershbergerICMP (ping) was reimplementing IP header code... it now shares code.
---
Changes for v2:
- Eliminate CamelCase in new functions
Changes for v3:
- Rebased onto other changed patches
include/net.h | 4 +++- net/bootp.c | 8 ++++---- net/net.c | 47 ++++++++++++++++++++++++++++------------------- net/ping.c | 52 +++++++++++++++++++++++----------------------------- 4 files changed, 58 insertions(+), 53 deletions(-)
include/net.h +3 -1
@@ -457,7 +457,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 net_set_ip_header (uchar *pkt,IPaddr_t dest,IPaddr_t source); +extern void net_set_udp_header (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 +4 -4
@@ -619,9 +619,9 @@ BootpRequest(void)* determined. * C. Hallinan, DS4.COM, Inc. */ -/* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, +/* net_set_udp_header(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, sizeof (struct Bootp_t)); */ - iphdr = pkt;/* We need this later for NetSetIP() */ + iphdr = pkt;/* We need this later for net_set_udp_header() */ pkt +=IP_UDP_HDR_SIZE ; bp = (struct Bootp_t *)pkt;
@@ -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); +net_set_udp_header (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); +net_set_udp_header (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
PATCH v3 2/18 net: Refactor NetSendUDPPacket to share more code
In reply to Joe HershbergerShare more of the code that is common between ARP vs not.
---
Changes for v2:
Changes for v3:
- Rebased onto other changed patches
net/net.c | 44 +++++++++++++++++++++++++------------------- 1 files changed, 25 insertions(+), 19 deletions(-)
net/net.c +25 -19
@@ -595,6 +595,9 @@ int 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;/* convert to new style broadcast */ if (dest ==0 )
@@ -609,40 +612,43 @@ int 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; +net_set_udp_header (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 ); - -net_set_udp_header (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); +eth_send (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 ); -net_set_udp_header (pkt, dest, dport, sport, payload_len); -eth_send (NetTxPacket, (pkt - NetTxPacket) +IP_UDP_HDR_SIZE + - payload_len); - -return 0 ;/* transmitted */ }#ifdef CONFIG_IP_DEFRAG
Signature · 1 line
1.6.0.2
PATCH v3 3/18 net: Refactor packet length computations
In reply to Joe HershbergerSave the length when it is computed instead of forgetting it and subtracting pointers to figure it out again.
---
Changes for v2:
Changes for v3:
- Rebased onto other changed patches
net/arp.c | 13 ++++++++----- net/ping.c | 7 ++++--- net/rarp.c | 6 ++++-- 3 files changed, 16 insertions(+), 10 deletions(-)
net/arp.c +8 -5
@@ -52,12 +52,14 @@ void ArpRequest(void) {uchar *pkt;struct arp_hdr *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_hdr *) 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_hdr *et, struct ip_udp_hdr *ip, int len)struct arp_hdr *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_hdr *et, struct ip_udp_hdr *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
@@ -42,6 +42,7 @@ static int ping_send(void) {static uchar mac[6 ];uchar *pkt; +int eth_hdr_size;/* XXX always send arp request */
@@ -53,13 +54,13 @@ static int ping_send(void) NetArpWaitPacketMAC = mac; pkt = NetArpWaitTxPacket; - pkt +=NetSetEther (pkt, mac,PROT_IP ); + eth_hdr_size =NetSetEther (pkt, mac,PROT_IP ); + pkt += eth_hdr_size;set_icmp_header (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
@@ -88,11 +88,13 @@ void RarpRequest(void) {uchar *pkt;struct arp_hdr *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_hdr *)pkt;
@@ -108,7 +110,7 @@ void 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
PATCH v3 4/18 net: Refactor bootp packet length computations
In reply to Joe HershbergerEliminate pointer subtraction that recovers values computed earlier
---
Changes for v2:
- Split debug message move to a separate commit
Changes for v3:
- Rebased onto other changed patches
net/bootp.c | 24 +++++++++++++----------- 1 files changed, 13 insertions(+), 11 deletions(-)
net/bootp.c +13 -11
@@ -581,7 +581,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;net_set_udp_header (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,9 +844,8 @@ 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;net_set_udp_header (iphdr,0xFFFFFFFFL ,PORT_BOOTPS ,PORT_BOOTPC , iplen);debug ("Transmitting DHCPREQUEST packet: len = %d\n" , pktlen);
Signature · 1 line
1.6.0.2
PATCH v3 5/18 net: Move debug trace to point of action
In reply to Joe Hershberger---
Changes for v2:
- Split from "Refactor bootp packet length computations"
Changes for v3:
- Rebased onto other changed patches
net/bootp.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/bootp.c +1 -1
@@ -848,10 +848,10 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer) pktlen = eth_hdr_size +IP_UDP_HDR_SIZE + iplen;net_set_udp_header (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
PATCH v3 6/18 net: Refactor ping receive handler
In reply to Joe HershbergerThere is no need to call through the handler... inline it
---
Changes for v2:
Changes for v3:
- Rebased onto other changed patches
net/ping.c | 18 ++---------------- 1 files changed, 2 insertions(+), 16 deletions(-)
net/ping.c +2 -16
@@ -75,20 +75,10 @@ static void ping_timeout(void) NetState =NETLOOP_FAIL ;/* we did not get the reply */ } -static void ping_handler (uchar *pkt,unsigned dest,IPaddr_t sip, -unsigned src,unsigned len) -{ -if (sip != NetPingIP) -return ; - - NetState =NETLOOP_SUCCESS ; -} -void ping_start (void ) {printf ("Using %s device\n" ,eth_get_name ());NetSetTimeout (10000UL , ping_timeout); -NetSetHandler (ping_handler);ping_send (); }
@@ -100,13 +90,9 @@ void ping_receive(struct ethernet_hdr *et, struct ip_udp_hdr *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
PATCH v3 7/18 net: Refactor to use NetSendPacket instead of eth_send directly
In reply to Joe HershbergerUse this entry-point consistently across the net/ code Use a static inline function to preserve code size
---
Changes for v2:
- Change NetSendPacket into a static inline
Changes for v3:
- Rebased onto other changed patches
include/net.h | 5 ++++- net/arp.c | 6 +++--- net/cdp.c | 2 +- net/net.c | 9 +-------- net/ping.c | 3 +-- 5 files changed, 10 insertions(+), 15 deletions(-)
include/net.h +4 -1
@@ -472,7 +472,10 @@ 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 (uchar *,int ); +static inline void NetSendPacket (uchar *pkt,int len) +{ + (void )eth_send (pkt, len); +}/* * Transmit UDP packet, performing ARP request if needed
net/arp.c +3 -3
@@ -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_hdr *et, struct ip_udp_hdr *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_hdr *et, struct ip_udp_hdr *ip, int len)/* modify header, and transmit it */ memcpy (((struct ethernet_hdr *)NetArpWaitTxPacket)-> et_dest, NetArpWaitPacketMAC,ARP_HLEN ); - (void )eth_send (NetArpWaitTxPacket, +NetSendPacket (NetArpWaitTxPacket, NetArpWaitTxPacketSize);/* no arp request pending now */
net/cdp.c +1 -1
@@ -216,7 +216,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 -8
@@ -584,13 +584,6 @@ NetSetTimeout(ulong iv, thand_f *f) } } - -void -NetSendPacket (uchar *pkt,int len) -{ - (void )eth_send (pkt, len); -} -int NetSendUDPPacket (uchar *ether,IPaddr_t dest,int dport,int sport,int payload_len) {
@@ -646,7 +639,7 @@ int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,return 1 ;/* waiting */ }else {debug ("sending UDP to %pI4/%pM\n" , &dest, ether); -eth_send (NetTxPacket, pkt_hdr_size + payload_len); +NetSendPacket (NetTxPacket, pkt_hdr_size + payload_len);return 0 ;/* transmitted */ } }
net/ping.c +1 -2
@@ -112,8 +112,7 @@ void ping_receive(struct ethernet_hdr *et, struct ip_udp_hdr *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