⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netconf.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 5 页
字号:
#include <wrn/wm/attache/dns.h>#include <wrn/wm/attache/loop.h>#include <wrn/wm/attache/ipaddr.h>#include <wrn/wm/attache/ip_rte.h>#if INSTALL_ATTACHE_MULTICAST && INSTALL_ATTACHE_MULTICAST_IGMP#include <wrn/wm/attache/igmp.h>#endif#if INSTALL_ATTACHE_IPV4_ROUTER_DISCOVERY#include <wrn/wm/attache/ip4_rd.h>#include <wrn/wm/attache/rd_cache.h>#endif#if INSTALL_ATTACHE_RIP#include <wrn/wm/attache/rip.h>#endif#if INSTALL_ATTACHE_DHCP#include <wrn/wm/attache/dhcp.h>#endif#if INSTALL_ATTACHE_PPP#include <wrn/wm/attache/ppp.h>#endif#include <wrn/wm/attache/glue.h>#if INSTALL_COURIER#include <courier/common/ut_incl.h>#include <courier/common/port_inc.h>#include <courier/common/avl_incl.h>#include <courier/common/ip_incl.h>#endif#if INSTALL_COURIER_OSPF#include <courier/ospf/ospf_inc.h>#endif#if INSTALL_COURIER_BGP#include <courier/bgp/bgp_inc.h>#endif#if INSTALL_COURIER_RIP#include <courier/rip/rip_inc.h>#endif#if INSTALL_COURIER_BGP_TRAPS#include <courier/common/trap.h>#endif#include <wrn/wm/demo/snarklib.h>#include <wrn/wm/demo/read_ini.h>#include <wrn/wm/demo/parse.h>#include <wrn/wm/demo/netconf.h>#if INSTALL_ATTACHE_SNTP_CLIENT#include <wrn/wm/attache/sntp.h>#endif#include <wrn/wm/demo/snarklib.h>#if INSTALL_LIAISON#include <liaison/hrmon/rmonapi.h>#if INSTALL_SNARK_BSD_BPF#include <wrn/wm/demo/bpf.h>#endif#if INSTALL_SNARK_BSD_NIT#include <wrn/wm/demo/nit.h>#endif#endifstatic char attache_section[] = "etc attache";#if INSTALL_COURIERstatic char courier_section[] = "etc courier";#endif#if INSTALL_LIAISONextern void snark_liaison_collect(int, void *);static char liaison_section[] = "etc liaison";#endifstatic struct ini_handle *ini_handle;#define	INI_LOOKUP(x, y)	ini_lookup(ini_handle, x, y)#define	INI_ITER_START(x, y)	ini_iter_start(ini_handle, x, y)#define	INI_ITER_NEXT()		ini_iter_next(ini_handle)struct dns_config domain_config;#if INSTALL_ATTACHE_PPPstatic ppp_upret_t netconfig_ppp_upcall(ppp_upevt_t, net_if *, void *);#endif/* This is only as a sanity check on reading an *//* address out of the initialization file. */#ifndef MAX_MAC_ADDR_LEN#define MAX_MAC_ADDR_LEN 64#endif/* * Configure one interface.  Called by system dependent code when it's * constructed an interface structure and wants to know whether to attach * it.  We set up the IP address and IP netmask. */boolean_t netconfig_if(struct net *net){  char buf[40], *s;  char *av[20];#if INSTALL_SNARK_BSD_BPF /* SunOS doesn't have strtoul(), sigh */  /*   * get the hardware address out of the initialization file;   * so far only useful for testing BOOTP on BPF...   * The other snark ports assume that ha_len and h_address arrive at   *  the driver init zero'd.   */  sprintf(buf, "%s-haddrlen", net->s_name);  if ((s = INI_LOOKUP(attache_section, buf)) != 0 && (*s != 0))    net->ha_len = STRTOUL(s, 0, 16);  if (net->ha_len > MAX_MAC_ADDR_LEN)    net->ha_len = 0;  /* get ha_len bytes of MAC address */  if (net->ha_len) {    int count = 0;    net->h_address = GLUE_ALLOC(net->ha_len);    sprintf(buf, "%s-haddr", net->s_name);    s = INI_LOOKUP(attache_section, buf);    if (s) {      while (count < net->ha_len) {	net->h_address[count++] = (bits8_t) STRTOUL(s, &s, 16);	if (*s++ != ':')	  break;      }    }    if (count != net->ha_len) {      net->ha_len = 0;      GLUE_FREE(net->h_address);      net->h_address = 0;    }  }#if INSTALL_ATTACHE_IPV6  /* do the same things to initialize the IPv6 token and token   * length, if they were configured */  sprintf(buf, "%s-token_len", net->s_name);  if ((s = INI_LOOKUP(attache_section, buf)) != 0 && (*s != 0))    net->tok_len = STRTOUL(s, 0, 16);  if (net->tok_len > MAX_IPV6_TOKEN_LEN)    net->tok_len = 0;  /* get tok_len bytes of MAC address */  if (net->tok_len) {    int count = 0;    sprintf(buf, "%s-token", net->s_name);    s = INI_LOOKUP(attache_section, buf);    if (s) {      while (count < net->tok_len) {	net->token[count++] = (bits8_t) STRTOUL(s, &s, 16);	if (*s++ != ':')	  break;      }    }    if (count != net->tok_len) {      net->tok_len = 0;    }  }#endif /* INSTALL_ATTACHE_IPV6 */#endif /* INSTALL_SNARK_BSD_BPF */  /*   * Configure the interface speed.   * This is only relevant for things like serial lines.   */  sprintf(buf, "%s-speed", net->s_name);  if ((s = INI_LOOKUP(attache_section, buf)) != 0)    net->speed = atol(s);  #if INSTALL_ATTACHE_DHCP  /*   * Check for DHCP; if we're using it on this interface, we don't   * want to set anything up yet.   */  sprintf(buf, "%s-dhcp", net->s_name);  if ((s = INI_LOOKUP(attache_section, buf)) != 0 && STRCMP(s, "yes") == 0) {    net->ip_mask = 0xFFFFFFFFL;    net->ip_bcast = 0xFFFFFFFFL;    return 1; 	/* Keep it around, even if it's not set up yet. */  }#endif /* INSTALL_ATTACHE_DHCP */#if INSTALL_ATTACHE_MULTICAST && INSTALL_ATTACHE_MULTICAST_IGMP  /* if Attache is configured to support IGMP messages, configure   * the interface to support them, too.  */  net->flags |= NF_IGMP;#endif /* INSTALL_ATTACHE_MULTICAST && INSTALL_ATTACHE_MULTICAST_IGMP */#if INSTALL_ATTACHE_IPV6  /* if the interface supports ipv6, mark it to be autoconfigured.  this   * should probably be changed to a separate configuration setting !!! */  if (net->driver->ipv6_send != 0)    net->flags |= NF_AUTOCONF;  /* If the interface supports ipv6 and rd is turned on mark it for   * router discover */#if INSTALL_ATTACHE_IPV6_RD  if (net->driver->ipv6_send != 0)    net->flags |= NF_V6_DISCOVER;#endif  /* Check to see if the interface will loopback copies of packets that   * are sent to one of its addresses including multicast addresses   */  sprintf(buf, "%s-loops_pkts", net->s_name);  if ((s = INI_LOOKUP(attache_section, buf)) != 0 && STRCMP(s, "yes") == 0) {    net->flags |= NF_LOOPS_PKTS;  }#endif#if INSTALL_ATTACHE_IPV4_ROUTER_DISCOVERY  net->flags |= NF_DISCOVER;#endif  #if INSTALL_ATTACHE_PPP  /*   * Why am I adding more of this garbage when I'm trying to phase out   * this style of interface initialization?  Because this whole routine   * needs rewriting and I don't have time to do that today.  Bletch.   */  if (net->driver->type == IF_PPP) {    struct pppctl *pc = net->media_cookie;    int ac = 0, i = -1;    BUG_ASSERT(pc);    sprintf(buf, "%s-pppctl", net->s_name);    if ((s = INI_LOOKUP(attache_section, buf)) != 0)      ac = parse_line(s, av, sizeof(av)/sizeof(*av));    pc->ctl_flags       = (bits16_t) (ac > ++i ? STRTOUL(av[i], 0, 0) : 0);    pc->max_terminate   = (bits16_t) (ac > ++i ? STRTOUL(av[i], 0, 0) : 5);    pc->max_configure   = (bits16_t) (ac > ++i ? STRTOUL(av[i], 0, 0) : 5);    pc->restart_timeout = (bits32_t) (ac > ++i ? STRTOUL(av[i], 0, 0) : 5000);    pc->ctl_flags |= PPPC_FCS;    pc->upcall = netconfig_ppp_upcall;  }#endif  /*   * Finally, a relatively sane way to initalize interfaces with   * the current API.  It's a little slower but a lot less ridiculous.   */  for (s = INI_ITER_START(attache_section, "interface"); s;       s = INI_ITER_NEXT()) {    if (parse_line(s, av, 2) != 1 || STRCMP(*av, net->s_name) != 0)      continue;    printf("  -- Interface %s (%s) speed %lu --\n",	   net->s_name, net->driver->name, net->speed);    return 1;  }  /*   * The code below here is the old-style (Attache 2.x compatable)   * initialization sequence.  Don't use this in new code.   */  /*   * Look for an IP address.  If there isn't one, this interface isn't   * configured, so don't bring it up.   */  sprintf(buf, "%s-address", net->s_name);  if ((s = INI_LOOKUP(attache_section, buf)) == 0) {    s = INI_LOOKUP(attache_section, "mention-all-ifs");    if (s && STRCMP(s, "yes") == 0)      printf("  -- %s (%s): Not configured --\n",	     net->s_name, net->driver->name);    s = INI_LOOKUP(attache_section, "keep-all-ifs");    if (s && STRCMP(s, "yes") == 0) {      net->ip_mask = 0xFFFFFFFFL;       net->ip_bcast = 0xFFFFFFFFL;      return 1;    }    return 0;  }  /*   * If the interface is configured but the IP address is zero, the interface   * does get brought up, but it's not going to be used for IP routing.   */  if ((net->ip_addr = atoinet(s)) == 0) {    printf("  -- %s (%s): No IP Address --\n",	   net->s_name, net->driver->name);    net->ip_mask = 0;  }  /*   * If there's no netmask, we set the netmask to all ones.  This causes   * all packets sent out this interface to go to the default router.   */  if (net->ip_addr) {    sprintf(buf, "%s-netmask", net->s_name);    if ((s = INI_LOOKUP(attache_section, buf)) == 0)      net->ip_mask = 0xFFFFFFFFL;    else      net->ip_mask = atoinet(s);  }  /*   * Broadcast address.  All-ones is the only sane choice, but some   * nets aren't configured right.   */  sprintf(buf, "%s-broadcast", net->s_name);  if ((s = INI_LOOKUP(attache_section, buf)) == 0)    net->ip_bcast = 0xFFFFFFFFL;  else    net->ip_bcast = atoinet(s);  /*   * Show what we got.   */  printf("  -- %s (%s): %s/", net->s_name, net->driver->name,	 inettoa(net->ip_addr));  if (net->speed)    printf("%s (%lu) --\n", inettoa(net->ip_mask), net->speed);  else    printf("%s --\n", inettoa(net->ip_mask));  return 1;}#if INSTALL_ATTACHE_PPPstatic ppp_upret_tnetconfig_ppp_upcall(ppp_upevt_t event,		     net_if *net,		     void *arg){  int close_ini_when_done = (ini_handle == 0);  ppp_upret_t result = PPP_UPRET_ABORT;#if (INSTALL_ATTACHE_PPP_CHAP || INSTALL_ATTACHE_PPP_PAP)  char *s, *av[3];#endif  if (close_ini_when_done && (ini_handle = ini_open(256)) == 0)    return PPP_UPRET_ABORT;  switch (event) {#if INSTALL_ATTACHE_PPP_CHAP  case PPP_UPEVT_CHAP_SERVER_STARTING:    if ((s = INI_LOOKUP(attache_section, "ppp-chap-reauth-interval")) != 0)      set_ppp_chap_server_rechallenge(net, STRTOUL(s, 0, 0));    /* fall through into common startup code */      case PPP_UPEVT_CHAP_CLIENT_STARTING:    if ((s = INI_LOOKUP(attache_section, "ppp-chap-hostname")) != 0 &&	parse_line(s, av, sizeof(av)/sizeof(*av)) == 1) {      ppp_auth_string_cons((event == PPP_UPEVT_CHAP_CLIENT_STARTING			    ? ptr_ppp_chap_client_hostname(net)			    : ptr_ppp_chap_server_hostname(net)),			   (bits8_t *) av[0], STRLEN(av[0]));      result = PPP_UPRET_CONTINUE;    }    break;  case PPP_UPEVT_CHAP_CLIENT_GET_SECRET:  case PPP_UPEVT_CHAP_SERVER_GET_SECRET:    {      ppp_auth_string_t *client = 0, *server = 0, *secret = 0;      switch (event) {      case PPP_UPEVT_CHAP_CLIENT_GET_SECRET:	client = ptr_ppp_chap_client_hostname(net);	server = ptr_ppp_chap_client_peername(net);	secret = ptr_ppp_chap_client_secret(net);	break;      case PPP_UPEVT_CHAP_SERVER_GET_SECRET:	client = ptr_ppp_chap_server_hostname(net);	server = ptr_ppp_chap_server_peername(net);	secret = ptr_ppp_chap_server_secret(net);	break;      default:	break;      }      BUG_ASSERT(ppp_auth_string_str(client) && ppp_auth_string_str(server));      for (s = INI_ITER_START(attache_section, "ppp-chap-secret"); s;	   s = INI_ITER_NEXT()) {	if (parse_line(s, av, sizeof(av)/sizeof(*av)) != 3 ||	    STRNCMP(av[0], ppp_auth_string_str(client),		    ppp_auth_string_len(client)) ||	    STRNCMP(av[1], ppp_auth_string_str(server),		    ppp_auth_string_len(server)))	  continue;	ppp_auth_string_cons(secret, (bits8_t *) av[2], STRLEN(av[2]));	result = PPP_UPRET_CONTINUE;	break;      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -