@ -30,40 +30,40 @@
struct in_addr net_arp_wait_packet_ip ;
struct in_addr net_arp_wait_packet_ip ;
static struct in_addr net_arp_wait_reply_ip ;
static struct in_addr net_arp_wait_reply_ip ;
/* MAC address of waiting packet's destination */
/* MAC address of waiting packet's destination */
uchar * NetArpWaitPacketMAC ;
uchar * arp_wait_packet_ethaddr ;
int NetArpWaitTxPacketS ize;
int arp_wait_tx_packet_s ize;
ulong NetArpWaitTimerS tart;
ulong arp_wait_timer_s tart;
int NetArpWaitT ry;
int arp_wait_t ry;
static uchar * net_ arp_tx_packet; /* THE ARP transmit packet */
static uchar * arp_tx_packet ; /* THE ARP transmit packet */
static uchar NetArpPacketB uf[ PKTSIZE_ALIGN + PKTALIGN ] ;
static uchar arp_tx_packet_b uf[ PKTSIZE_ALIGN + PKTALIGN ] ;
void ArpI nit( void )
void arp_i nit( void )
{
{
/* XXX problem with bss workaround */
/* XXX problem with bss workaround */
NetArpWaitPacketMAC = NULL ;
arp_wait_packet_ethaddr = NULL ;
net_arp_wait_packet_ip . s_addr = 0 ;
net_arp_wait_packet_ip . s_addr = 0 ;
net_arp_wait_reply_ip . s_addr = 0 ;
net_arp_wait_reply_ip . s_addr = 0 ;
NetArpWaitTxPacketS ize = 0 ;
arp_wait_tx_packet_s ize = 0 ;
net_ arp_tx_packet = & NetArpPacketB uf[ 0 ] + ( PKTALIGN - 1 ) ;
arp_tx_packet = & arp_tx_packet_b uf[ 0 ] + ( PKTALIGN - 1 ) ;
net_ arp_tx_packet - = ( ulong ) net_ arp_tx_packet % PKTALIGN ;
arp_tx_packet - = ( ulong ) arp_tx_packet % PKTALIGN ;
}
}
void arp_raw_request ( struct in_addr source_ip , const uchar * targetEthe r ,
void arp_raw_request ( struct in_addr source_ip , const uchar * target_ethadd r ,
struct in_addr target_ip )
struct in_addr target_ip )
{
{
uchar * pkt ;
uchar * pkt ;
struct arp_hdr * arp ;
struct arp_hdr * arp ;
int eth_hdr_size ;
int eth_hdr_size ;
debug_cond ( DEBUG_DEV_PKT , " ARP broadcast %d \n " , NetArpWaitT ry) ;
debug_cond ( DEBUG_DEV_PKT , " ARP broadcast %d \n " , arp_wait_t ry) ;
pkt = net_ arp_tx_packet;
pkt = arp_tx_packet ;
eth_hdr_size = net_set_ether ( pkt , net_bcast_ethaddr , PROT_ARP ) ;
eth_hdr_size = net_set_ether ( pkt , net_bcast_ethaddr , PROT_ARP ) ;
pkt + = eth_hdr_size ;
pkt + = eth_hdr_size ;
arp = ( struct arp_hdr * ) pkt ;
arp = ( struct arp_hdr * ) pkt ;
arp - > ar_hrd = htons ( ARP_ETHER ) ;
arp - > ar_hrd = htons ( ARP_ETHER ) ;
arp - > ar_pro = htons ( PROT_IP ) ;
arp - > ar_pro = htons ( PROT_IP ) ;
@ -73,13 +73,13 @@ void arp_raw_request(struct in_addr source_ip, const uchar *targetEther,
memcpy ( & arp - > ar_sha , net_ethaddr , ARP_HLEN ) ; /* source ET addr */
memcpy ( & arp - > ar_sha , net_ethaddr , ARP_HLEN ) ; /* source ET addr */
net_write_ip ( & arp - > ar_spa , source_ip ) ; /* source IP addr */
net_write_ip ( & arp - > ar_spa , source_ip ) ; /* source IP addr */
memcpy ( & arp - > ar_tha , targetEthe r , ARP_HLEN ) ; /* target ET addr */
memcpy ( & arp - > ar_tha , target_ethadd r , ARP_HLEN ) ; /* target ET addr */
net_write_ip ( & arp - > ar_tpa , target_ip ) ; /* target IP addr */
net_write_ip ( & arp - > ar_tpa , target_ip ) ; /* target IP addr */
net_send_packet ( net_ arp_tx_packet, eth_hdr_size + ARP_HDR_SIZE ) ;
net_send_packet ( arp_tx_packet , eth_hdr_size + ARP_HDR_SIZE ) ;
}
}
void ArpR equest( void )
void arp_r equest( void )
{
{
if ( ( net_arp_wait_packet_ip . s_addr & net_netmask . s_addr ) ! =
if ( ( net_arp_wait_packet_ip . s_addr & net_netmask . s_addr ) ! =
( net_ip . s_addr & net_netmask . s_addr ) ) {
( net_ip . s_addr & net_netmask . s_addr ) ) {
@ -96,7 +96,7 @@ void ArpRequest(void)
arp_raw_request ( net_ip , net_null_ethaddr , net_arp_wait_reply_ip ) ;
arp_raw_request ( net_ip , net_null_ethaddr , net_arp_wait_reply_ip ) ;
}
}
void ArpTimeoutC heck( void )
void arp_timeout_c heck( void )
{
{
ulong t ;
ulong t ;
@ -106,21 +106,21 @@ void ArpTimeoutCheck(void)
t = get_timer ( 0 ) ;
t = get_timer ( 0 ) ;
/* check for arp timeout */
/* check for arp timeout */
if ( ( t - NetArpWaitTimerS tart) > ARP_TIMEOUT ) {
if ( ( t - arp_wait_timer_s tart) > ARP_TIMEOUT ) {
NetArpWaitT ry+ + ;
arp_wait_t ry+ + ;
if ( NetArpWaitT ry > = ARP_TIMEOUT_COUNT ) {
if ( arp_wait_t ry > = ARP_TIMEOUT_COUNT ) {
puts ( " \n ARP Retry count exceeded; starting again \n " ) ;
puts ( " \n ARP Retry count exceeded; starting again \n " ) ;
NetArpWaitT ry = 0 ;
arp_wait_t ry = 0 ;
NetStartAgain ( ) ;
NetStartAgain ( ) ;
} else {
} else {
NetArpWaitTimerS tart = t ;
arp_wait_timer_s tart = t ;
ArpR equest( ) ;
arp_r equest( ) ;
}
}
}
}
}
}
void ArpR eceive( struct ethernet_hdr * et , struct ip_udp_hdr * ip , int len )
void arp_r eceive( struct ethernet_hdr * et , struct ip_udp_hdr * ip , int len )
{
{
struct arp_hdr * arp ;
struct arp_hdr * arp ;
struct in_addr reply_ip_addr ;
struct in_addr reply_ip_addr ;
@ -205,28 +205,27 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
/* matched waiting packet's address */
/* matched waiting packet's address */
if ( reply_ip_addr . s_addr = = net_arp_wait_reply_ip . s_addr ) {
if ( reply_ip_addr . s_addr = = net_arp_wait_reply_ip . s_addr ) {
debug_cond ( DEBUG_DEV_PKT ,
debug_cond ( DEBUG_DEV_PKT ,
" Got ARP REPLY, set eth addr (%pM) \n " ,
" Got ARP REPLY, set eth addr (%pM) \n " ,
arp - > ar_data ) ;
arp - > ar_data ) ;
/* save address for later use */
/* save address for later use */
if ( NetArpWaitPacketMAC ! = NULL )
if ( arp_wait_packet_ethaddr ! = NULL )
memcpy ( NetArpWaitPacketMAC ,
memcpy ( arp_wait_packet_ethaddr ,
& arp - > ar_sha , ARP_HLEN ) ;
& arp - > ar_sha , ARP_HLEN ) ;
net_get_arp_handler ( ) ( ( uchar * ) arp , 0 , reply_ip_addr ,
net_get_arp_handler ( ) ( ( uchar * ) arp , 0 , reply_ip_addr ,
0 , len ) ;
0 , len ) ;
/* set the mac address in the waiting packet's header
/* set the mac address in the waiting packet's header
and transmit it */
and transmit it */
memcpy ( ( ( struct ethernet_hdr * ) net_tx_packet ) - > et_dest ,
memcpy ( ( ( struct ethernet_hdr * ) net_tx_packet ) - > et_dest ,
& arp - > ar_sha , ARP_HLEN ) ;
& arp - > ar_sha , ARP_HLEN ) ;
net_send_packet ( net_tx_packet , NetArpWaitTxPacketS ize) ;
net_send_packet ( net_tx_packet , arp_wait_tx_packet_s ize) ;
/* no arp request pending now */
/* no arp request pending now */
net_arp_wait_packet_ip . s_addr = 0 ;
net_arp_wait_packet_ip . s_addr = 0 ;
NetArpWaitTxPacketSize = 0 ;
arp_wait_tx_packet_size = 0 ;
NetArpWaitPacketMAC = NULL ;
arp_wait_packet_ethaddr = NULL ;
}
}
return ;
return ;
default :
default :