Int netloop (proto_t Protocol)

Source: Internet
Author: User

/*************************************** *******************************/
/*
* Main network processing loop.
*/

Int
Netloop (proto_t Protocol)
{
Bd_t * BD = Gd-> BD;

# Ifdef config_net_multi
Netrestarted = 0;
Netdevexists = 0;
# Endif

/* XXX problem with BSS workaround */
Netarpwaitpacketmac = NULL;
Netarpwaittxpacket = NULL;
Netarpwaitpacketip = 0;
Netarpwaitreplyip = 0;
Netarpwaittxpacket = NULL;
Nettxpacket = NULL;

If (! Nettxpacket ){
Int I;
/*
* Setup packet buffers, aligned correctly.
*/
Nettxpacket = & pktbuf [0] + (pktalign-1 );
Nettxpacket-= (ulong) nettxpacket % pktalign; // assign nettxpacket
For (I = 0; I <pktbufsrx; I ++ ){
Netrxpackets [I] = nettxpacket + (I + 1) * pktsize_align; // assign netrxpackets [4]
}
}

If (! Netarpwaittxpacket ){
Netarpwaittxpacket = & netarpwaitpacketbuf [0] + (pktalign-1 );
Netarpwaittxpacket-= (ulong) netarpwaittxpacket % pktalign; // assign netarpwaittxpacket
Netarpwaittxpacketsize = 0; // netarpwaittxpacketsize = 0
}

Eth_halt (); // stop the NIC
# Ifdef config_net_multi
Eth_set_current ();
# Endif
If (eth_init (BD) <0) {// Nic hardware initialization
Eth_halt ();
Return (-1 );
}

Restart:
# Ifdef config_net_multi
Memcpy (netourether, eth_get_dev ()-> enetaddr, 6); // read the MAC address of the Local Machine
# Else
Memcpy (netourether, BD-> bi_enetaddr, 6 );
# Endif

Netstate = netloop_continue; // sets the network status to OK.

/*
* Start the ball rolling with the given start function. From
* Here on, this code is a state machine driven by driven ed
* Packets and timer events.
*/

Switch (Protocol) {// select the command
# If (config_commands & cmd_cmd_nfs)
Case NFS:
# Endif
# If (config_commands & cmd_cmd_ping) // command defined
Case Ping:
# Endif
# If (config_commands & cmd_cmd_sntp)
Case SNTP:
# Endif
Case netcons:
Case TFTP:
Netcopyip (& netourip, & BD-> bi_ip_addr); // read the local IP Address
Netourgatewayip = getenv_ipaddr ("gatewayip"); // read the local gateway address
Netoursubnetmask = getenv_ipaddr ("netmask"); // read the local mask address.
Netourvlan = getenv_vlan ("VLAN"); // read the virtual network
Netournativevlan = getenv_vlan ("nvlan"); // read the virtual network

Switch (Protocol ){
# If (config_commands & cmd_cmd_nfs)
Case NFS:
# Endif
Case netcons:
Case TFTP:
Netserverip = getenv_ipaddr ("serverip ");
Break;
# If (config_commands & cmd_cmd_ping)
Case Ping:
/* Nothing */
Break;
# Endif
# If (config_commands & cmd_cmd_sntp)
Case SNTP:
/* Nothing */
Break;
# Endif
Default:
Break;
}

Break;
Case BOOTP:
Case RARP:
/*
* Initialize our ip addr to 0 in order to accept any
* Ip addr assigned to us by the Bootp/RARP Server
*/
Netourip = 0;
Netserverip = getenv_ipaddr ("serverip ");
Netourvlan = getenv_vlan ("VLAN");/* VLANs must be read */
Netournativevlan = getenv_vlan ("nvlan ");
Case CDP:
Netourvlan = getenv_vlan ("VLAN");/* VLANs must be read */
Netournativevlan = getenv_vlan ("nvlan ");
Break;
Default:
Break;
}

Switch (net_check_prereq (Protocol) {// check Command Format, correct return 0
Case 1:
/* Network not configured */
Eth_halt ();
Return (-1 );

# Ifdef config_net_multi
Case 2:
/* Network device not configured */
Break;
# Endif/* config_net_multi */

Case 0:
# Ifdef config_net_multi
Netdevexists = 1;
# Endif
Switch (Protocol ){
Case TFTP:
/* Always use ARP to get server ethernet address */
Tftpstart ();
Break;

# If (config_commands & cmd_cmd_dhcp)
Case DHCP:
/* Start with a clean slate ...*/
Bootptry = 0;
Netourip = 0;
Netserverip = getenv_ipaddr ("serverip ");
Dhcprequest ();/* basically same as BOOTP */
Break;
# Endif/* cfg_cmd_dhcp */

Case BOOTP:
Bootptry = 0;
Bootprequest ();
Break;

Case RARP:
Rarptry = 0;
Rarprequest ();
Break;
# If (config_commands & cmd_cmd_ping)
Case Ping:
Pingstart ();
Break;
# Endif
# If (config_commands & cmd_cmd_nfs)
Case NFS:
Nfsstart ();
Break;
# Endif
# If (config_commands & cmd_cmd_cdp)
Case CDP:
Cdpstart ();
Break;
# Endif
# Ifdef config_netconsole
Case netcons:
Ncstart ();
Break;
# Endif
# If (config_commands & cmd_cmd_sntp)
Case SNTP:
Sntpstart ();
Break;
# Endif
Default:
Break;
}

Netbootfilexfersize = 0; // the size of the Startup File actually transmitted (in bytes)
Break;
}

# If defined (config_mii) | (config_commands & cfg_cmd_mii)
# If defined (pai_fault_echo_link_down) & defined (config_status_led) & defined (status_led_red)
/*
* Echo the inverted link state to the fault led.
*/
If (miiphy_link (eth_get_dev ()-> name, pai_fault_mii_addr )){
Status_led_set (status_led_red, status_led_off );
} Else {
Status_led_set (status_led_red, status_led_on );
}
# Endif/* fault_echo_link_down ,...*/
# Endif/* config_mii ,...*/

/*
* Main packet injection tion loop. Loop processing ing packets
* Someone sets 'netstate' to a State that terminates.
*/
For (;;){
Watchdog_reset ();
# Ifdef config_show_activity
{
Extern void show_activity (INT Arg );
Show_activity (1 );
}
# Endif
/*
* Check the Ethernet for a new packet. The Ethernet
* Receive routine will process it.
*/
Eth_rx ();

/*
* Abort if Ctrl-C was pressed.
*/
If (ctrlc ()){
Eth_halt ();
Puts ("\ nabort \ n ");
Return (-1 );
}

Arptimeoutcheck ();

/*
* Check for a timeout, and run the timeout Handler
* If we have one.
*/
If (timehandler & (get_timer (0)-timestart)> timedelta )){
Thand_f * X;

# If defined (config_mii) | (config_commands & cfg_cmd_mii)
# If defined (pai_fault_echo_link_down )&&\
Defined (config_status_led )&&\
Defined (status_led_red)
/*
* Echo the inverted link state to the fault led.
*/
If (miiphy_link (eth_get_dev ()-> name, pai_fault_mii_addr )){
Status_led_set (status_led_red, status_led_off );
} Else {
Status_led_set (status_led_red, status_led_on );
}
# Endif/* fault_echo_link_down ,...*/
# Endif/* config_mii ,...*/
X = timehandler;
Timehandler = (thand_f *) 0;
(* X )();
}

Switch (netstate ){

Case netloop_restart:
# Ifdef config_net_multi
Netrestarted = 1;
# Endif
Goto restart;

Case netloop_success:
If (netbootfilexfersize> 0 ){
Char Buf [10];
Printf ("bytes transferred = % LD (% lx HEX) \ n ",
Netbootfilexfersize,
Netbootfilexfersize );
Sprintf (BUF, "% lx", netbootfilexfersize );
Setenv ("filesize", Buf );

Sprintf (BUF, "% lx", (unsigned long) load_addr );
Setenv ("fileaddr", Buf );
}
Eth_halt ();
Return netbootfilexfersize;

Case netloop_fail:
Return (-1 );
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.