Esempio n. 1
0
void
lb_ifsetup(NET netp)
{
   IFMIB mib;

   netp->n_ipaddr = htonl(0x7f000001);     /* 127.0.0.1 */
   netp->n_defgw  = htonl(0x00000000);
   netp->snmask   = htonl(0xFF000000);
   netp->n_lnh = ETHHDR_SIZE;   /* space reserved for ethernet header */
#ifdef IEEE_802_3
   netp->n_lnh += sizeof(struct snap_hdr);   /* The bloated version */
#endif
   netp->n_hal = 6;    /* hardware address length */
   netp->n_mib->ifType = LOOPIFTYPE;

   /*
    * Yes! In Interniche Stack Lingo, MTU for Ethernet II and IEEE 802.3 is
    * identical. Since the n_mtu field indicates the total frame size sent on
    * the wire, and not MTU in the usual sense. If things are correctly set up
    * then (n_mtu - n_lnh) should give us the actual MTU (or the MTU in the 
    * usual sense of the term.
    */
#ifdef IEEE_802_3
   netp->n_mtu = 1514; /* max frame size */
#else
   netp->n_mtu = 1514; /* max frame size */
#endif

   if(netp->name[0] == 0)
   {
      netp->name[0] = 'l';
      netp->name[1] = 'o';
      netp->name[2] = (char)('0' + lbnets);
   }
   netp->n_flags |= NF_NBPROT;

#ifdef IP_V6
   {
   int i;
   int keepDup;
   char * cp;

   netp->n_flags |= NF_IPV6;  /* set flag for v6 compatability */

   /* set up the standard v6 loopback addresses */
   for(i = IPA_LINK; i <= IPA_GLOBAL; i++)
   {

	   							      IPV6LOG(("+ lb_ifsetup   ip6_dupchecks = %d, i = %d\n", ip6_dupchecks, i));


      keepDup = ip6_dupchecks;  /* loopback can't affect DAD */
      netp->v6addrs[i] = ip6_mkaddr(netp, i, &ip6loopback);
	  ip6_dupchecks = keepDup;
      netp->v6addrs[i]->prefix = 128;
      netp->v6addrs[i]->flags = IA_PREFERRED;

							      IPV6LOG(("+ lb_ifsetup  2 ip6_dupchecks = %d, i = %d\n", ip6_dupchecks, i));


      cp = (char *)&netp->v6addrs[i]->addr;
      switch(i)
        {
         case IPA_LINK:
            *cp++ = (char)0xFE;     /* paste in the link-local prefix */
            *cp   = (char)0x80;
            break;
         case IPA_SITE:
            *cp++ = (char)0xFE;     /* paste in the site-local prefix */
            *cp   = (char)0xC0;
            break;
         case IPA_GLOBAL:     /* leave it all zeros */
            break;
         default:
            dtrap();
         }
	  				              IPV6DUMP("+ lb_ifsetup addr = \n", (char *)&netp->v6addrs[i]->addr, 16);
							      IPV6LOG(("+ lb_ifsetup   netp->v6addrs[i]->flags = %d\n", netp->v6addrs[i]->flags));
   }
   }
#endif   /* IP_V6 */

   /* search the NV parameters for iface setup for our name. If this
    * fails we just default to what's already in the ifp.
    */
#ifdef INCLUDE_NVPARMS
   if_configbyname(netp);
#endif
#ifdef DYNAMIC_IFACES   /* dynamic extensions */
   netp->n_setstate = lb_setstate;
#endif  /* DYNAMIC_IFACES */

   mib = netp->n_mib;
   mib->ifAdminStatus = 2;  /* status = down */
   mib->ifOperStatus = 2;   /* will be set up in init()  */
   mib->ifLastChange = cticks * (100 / TPS);
   mib->ifPhysAddress = (u_char *)&lpbhaddr[0];
   mib->ifDescr = (u_char *)"loopback (pseudo ethernet)";
   mib->ifIndex = if_netnumber(netp);

#ifdef IP_V6
   /* IPv6 has very specific requirements for loopback behaviour */
   mib->ifType = LOOPIFTYPE;
#else
   /* For IPV4 it's convenient to masquerade as ethernet, so we can
    * test ARP, DHCP, etc., in loopback.
    */
   mib->ifType = ETHERNET;
#endif

   mib->ifSpeed = 10000000;
   mib->ifMtu = 1500;         /* ethernetish default */

   /* install our hardware driver routines */
   netp->n_init = lb_init;
#ifdef LB_RAW_SEND
   netp->raw_send = lb_raw_send;
#else /* use packet send */
   netp->pkt_send = lb_pkt_send;
#endif   /* LB_RAW_SEND */
   netp->n_close = lb_close;
   netp->n_stats = lb_stats;
}
Esempio n. 2
0
void 
netmain_init(void)
{
   int   e;
   int   i;
   char *   msg;
#ifdef IP_V6
   ip6_addr host;
#endif

   printf("\n%s\n", name);
   printf("Copyright 1997-2006 by InterNiche Technologies. All rights reserved. \n");

#ifndef SUPERLOOP
   /* call this to do pre-task setup including intialization of port_prep */
   msg = pre_task_setup();
   if (msg)
      panic(msg);
#endif

#ifdef INCLUDE_NVPARMS     /* system uses InterNiche NV system */
   e = get_nv_params();    /* get flash parameters into data structs */
   if (e)
   {
      printf("fatal error (%d) reading NV parameters.\n", e);
      panic("nv");
   }

   /* set static iface IP info up from stored parameters. These may 
   be overwritten from command line parms or DHCP later. */
   for (i = 0; i < STATIC_NETS; i++)
   {
      netstatic[i].n_ipaddr = inet_nvparms.ifs[i].ipaddr;
      netstatic[i].snmask = inet_nvparms.ifs[i].subnet;
      netstatic[i].n_defgw = inet_nvparms.ifs[i].gateway;
#ifdef IP_MULTICAST
      /* Create a dummy entry for the Ethernet interface mcastlist */
      /* If this entry is set to NULL, multicast is not supported  */
      /* on this interface */
      netstatic[i].n_mcastlist = mcastlist;
#endif   /* IP_MULTICAST */
#ifdef IP_V6
      IP6CPY(&host, &inet_nvparms.ifs[i].ipv6addr);
      if ( (host.addr[0] == 0xFE) && (host.addr[1] == 0xC0))
      {
         netstatic[i].v6addrs[IPA_SITE] = ip6_mkaddr(&netstatic[i], 
            IPA_SITE, &host);
      }
      else if ( (host.addr[0] == 0xFE) && (host.addr[1] == 0x80) )
      {
         printf ("[IPV6 init]error : bad IPV6 address\n");
      }
      else if (host.addr[0] != 0)
      {
         netstatic[i].v6addrs[IPA_GLOBAL] = ip6_mkaddr(&netstatic[i], 
            IPA_GLOBAL, &host );
      }
#endif
   }

#ifdef DNS_CLIENT
   /* set DNS client's server list from nvparms information */
   MEMCPY(dns_servers, inet_nvparms.dns_servers, sizeof(dns_servers));

#ifdef DNS_CLIENT_UPDT
   MEMCPY(soa_mname, inet_nvparms.dns_zone_name, sizeof(soa_mname));
#endif   /* DNS_CLIENT_UPDT */

#endif   /* DNS_CLIENT */

#ifdef USE_COMPORT
   comportcfg.comport = comport_nvparms.comport;
   comportcfg.LineProtocol = comport_nvparms.LineProtocol;
#endif   /* USE_COMPORT */
#endif   /* INCLUDE_NVPARMS */

#ifndef INCLUDE_NVPARMS
#ifdef USE_COMPORT
   comportcfg.comport = 0x01;
   comportcfg.LineProtocol = PPP;   /* Default to PPP */
#endif   /* USE_COMPORT */
#endif   /* INCLUDE_NVPARMS */

   msg = ip_startup();
   if (msg)
   {
      printf("inet startup error: %s\n", msg);
      panic("IP");
   }

#if defined(MEMDEV_SIZE) && defined(VFS_FILES)
   init_memdev(); /* init the mem and null test devices */
#endif

#ifdef IP_MULTICAST
#ifdef INCLUDE_TCP
   /* call the IP multicast test program */
   u_mctest_init();
#endif
#endif  

   /* clear debugging flags. Port can optionally turn them
    * back on in post_task_setup();
    * NDEBUG = UPCTRACE | IPTRACE | TPTRACE ;  
    */
   NDEBUG = 0;    

   /* print IP address of the first interface - for user's benefit */
   printf("IP address of %s : %s\n" , ((NET)(netlist.q_head))->name,
      print_ipad(((NET)(netlist.q_head))->n_ipaddr));
 
#ifndef SUPERLOOP
   /* call this per-target routine after basic tasks & net are up */
   msg = post_task_setup();
   if (msg)
      panic(msg);
#endif

#ifdef PING_APP
   ping_init();
#endif   /* PING_APP */

#ifdef RAWIPTEST
   raw_test_init();
#endif   /* RAWIPTEST */

#if defined(TFTP_CLIENT) || defined(TFTP_SERVER)
   tftp_init();
#endif   /* TFTP */

#ifdef TESTMENU
   install_menu(testmenu);
#endif   /* TESTMENU */

#ifdef USE_AUTOIP
   Upnp_init();      /* start Auto IP before DHCP client */
#endif   /* USE_AUTOIP */

#ifdef DHCP_CLIENT
	if( POWERUP_CONFIG_DHCP_ENABLED )
   		dhc_setup();   /* kick off any DHCP clients */
#endif   /* DHCP_CLIENT */

#ifdef DHCP_SERVER
#ifdef INCLUDE_NVPARMS
   if(dhserve_nvparms.ServeDHCP)
#endif
   {
      e = dhcp_init();
      if(e)
      {
         dprintf("Error %d starting DHCP server.\n",e);
      }
      else
      {
         exit_hook(dhcpsrv_cleanup);
         dprintf("Started DHCP server\n");
      }
   }
#endif /* DHCP_SERVER */

#ifdef IN_MENUS
   printf(prompt);
#endif

#ifdef UDPSTEST
   e=udp_echo_init();
   if ( e == SUCCESS )
   {
      exit_hook(udp_echo_cleanup);
   }
   else
      dprintf("Error %d starting UDP Echo server.\n",e);
#endif

#ifdef RIP_SUPPORT
   e=rip_init();
   if ( e == SUCCESS )
   {
      exit_hook(rip_cleanup);
   }
   else
      dprintf("Error %d starting RIP server.\n",e);
#endif

#ifdef INICHE_SYSLOG
   e =syslog_init();
   if (e == SUCCESS)
      exit_hook(closelog);
   else
      dprintf("Error %d initializing syslog client.\n",e);
#endif

#ifdef FTP_CLIENT
   fc_callback=ftpc_callback;
#endif

/* The following initializations take place when SUPERLOOP is enabled.
 * Otherwise they would be done in the respective task.
 */

#ifdef SUPERLOOP

#ifdef INCLUDE_SNMP
   e = snmp_init();
   if (e == SUCCESS)
      exit_hook(snmp_cleanup);
   else
      dprintf("Error %d initializing SNMP agent.\n",e);
#endif   /* INCLUDE_SNMP */

#ifdef WEBPORT
   e = http_init(); /* start up http server */
   if (e)
      dprintf("Error %d starting HTTP server.\n",e);
#endif   /* WEBPORT */

#ifdef FTP_SERVER
   e = ftps_init();
   if ( e == SUCCESS )
   {
      exit_hook(ftps_cleanup);
   }
   else
      dprintf("Error %d starting FTP server.\n",e);
#endif   /* FTP_SERVER */

#ifdef TELNET_SVR
   e=tel_init();
   if ( e == SUCCESS )
   {
      exit_hook(tel_cleanup);
   }
   else
      dprintf("Error %d starting TELNET server.\n",e);
#endif

#ifdef TCP_ECHOTEST
   e=tcp_echo_init();
   if ( e == SUCCESS )
   {
      exit_hook(tcp_echo_cleanup);
   }
   else
      dprintf("Error %d starting TCP Echo server.\n",e);
#endif
#ifdef TCP_CIPHERTEST
   e=tcp_cipher_init();
   if ( e == SUCCESS )
   {
      exit_hook(tcp_cipher_cleanup);
   }
   else
      dprintf("Error %d starting TCP cipher server.\n",e);
#endif
#ifdef USE_CRYPTOENG
   e = ce_init();
   if(e != 0)
   {
      dprintf("ce_init() failed\n");
      panic("prep_modules");
   }
#endif

#ifdef SMTP_ALERTS
   smtp_init ();
#endif

#endif   /* SUPERLOOP */

   USE_ARG(e);    /* Avoid compiler warnings */
   USE_ARG(i);

} /* end of netmain_init() */