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

📄 interface.c

📁 zebra测试源代码用于 SOCKET 通信
💻 C
📖 第 1 页 / 共 3 页
字号:
  struct sockaddr_dl *sdl;#endif /* HAVE_SOCKADDR_DL */  struct connected *connected;  listnode node;  vty_out (vty, "Interface %s%s", ifp->name,	   VTY_NEWLINE);  if (ifp->desc)    vty_out (vty, "  Description: %s%s", ifp->desc,	     VTY_NEWLINE);  if (ifp->ifindex <= 0)    {      vty_out(vty, "  index %d pseudo interface%s", ifp->ifindex, VTY_NEWLINE);      return;    }  else if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))    {      vty_out(vty, "  index %d inactive interface%s", 	      ifp->ifindex, 	      VTY_NEWLINE);      return;    }  vty_out (vty, "  index %d metric %d mtu %d ",	   ifp->ifindex, ifp->metric, ifp->mtu);  if_flag_dump_vty (vty, ifp->flags);  vty_out (vty, "%s", VTY_NEWLINE);  /* Hardware address. */#ifdef HAVE_SOCKADDR_DL  sdl = &ifp->sdl;  if (sdl != NULL && sdl->sdl_alen != 0)    {      int i;      u_char *ptr;      vty_out (vty, "  HWaddr: ");      for (i = 0, ptr = LLADDR (sdl); i < sdl->sdl_alen; i++, ptr++)	vty_out (vty, "%s%02x", i == 0 ? "" : ":", *ptr);      vty_out (vty, "%s", VTY_NEWLINE);    }#else  if (ifp->hw_addr_len != 0)    {      int i;      vty_out (vty, "  HWaddr: ");      for (i = 0; i < ifp->hw_addr_len; i++)	vty_out (vty, "%s%02x", i == 0 ? "" : ":", ifp->hw_addr[i]);      vty_out (vty, "%s", VTY_NEWLINE);    }#endif /* HAVE_SOCKADDR_DL */    /* Bandwidth in kbps */  if (ifp->bandwidth != 0)    {      vty_out(vty, "  bandwidth %u kbps", ifp->bandwidth);      vty_out(vty, "%s", VTY_NEWLINE);    }  for (node = listhead (ifp->connected); node; nextnode (node))    {      connected = getdata (node);      if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL))	connected_dump_vty (vty, connected);    }#ifdef RTADV  nd_dump_vty (vty, ifp);#endif /* RTADV */#ifdef HAVE_PROC_NET_DEV  /* Statistics print out using proc file system. */  vty_out (vty, "    input packets %lu, bytes %lu, dropped %lu,"	   " multicast packets %lu%s",	   ifp->stats.rx_packets, ifp->stats.rx_bytes, 	   ifp->stats.rx_dropped, ifp->stats.rx_multicast, VTY_NEWLINE);  vty_out (vty, "    input errors %lu, length %lu, overrun %lu,"	   " CRC %lu, frame %lu, fifo %lu, missed %lu%s",	   ifp->stats.rx_errors, ifp->stats.rx_length_errors,	   ifp->stats.rx_over_errors, ifp->stats.rx_crc_errors,	   ifp->stats.rx_frame_errors, ifp->stats.rx_fifo_errors,	   ifp->stats.rx_missed_errors, VTY_NEWLINE);  vty_out (vty, "    output packets %lu, bytes %lu, dropped %lu%s",	   ifp->stats.tx_packets, ifp->stats.tx_bytes,	   ifp->stats.tx_dropped, VTY_NEWLINE);  vty_out (vty, "    output errors %lu, aborted %lu, carrier %lu,"	   " fifo %lu, heartbeat %lu, window %lu%s",	   ifp->stats.tx_errors, ifp->stats.tx_aborted_errors,	   ifp->stats.tx_carrier_errors, ifp->stats.tx_fifo_errors,	   ifp->stats.tx_heartbeat_errors, ifp->stats.tx_window_errors,	   VTY_NEWLINE);  vty_out (vty, "    collisions %lu%s", ifp->stats.collisions, VTY_NEWLINE);#endif /* HAVE_PROC_NET_DEV */#ifdef HAVE_NET_RT_IFLIST#if defined (__bsdi__) || defined (__NetBSD__)  /* Statistics print out using sysctl (). */  vty_out (vty, "    input packets %qu, bytes %qu, dropped %qu,"	   " multicast packets %qu%s",	   ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes,	   ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts,	   VTY_NEWLINE);  vty_out (vty, "    input errors %qu%s",	   ifp->stats.ifi_ierrors, VTY_NEWLINE);  vty_out (vty, "    output packets %qu, bytes %qu, multicast packets %qu%s",	   ifp->stats.ifi_opackets, ifp->stats.ifi_obytes,	   ifp->stats.ifi_omcasts, VTY_NEWLINE);  vty_out (vty, "    output errors %qu%s",	   ifp->stats.ifi_oerrors, VTY_NEWLINE);  vty_out (vty, "    collisions %qu%s",	   ifp->stats.ifi_collisions, VTY_NEWLINE);#else  /* Statistics print out using sysctl (). */  vty_out (vty, "    input packets %lu, bytes %lu, dropped %lu,"	   " multicast packets %lu%s",	   ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes,	   ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts,	   VTY_NEWLINE);  vty_out (vty, "    input errors %lu%s",	   ifp->stats.ifi_ierrors, VTY_NEWLINE);  vty_out (vty, "    output packets %lu, bytes %lu, multicast packets %lu%s",	   ifp->stats.ifi_opackets, ifp->stats.ifi_obytes,	   ifp->stats.ifi_omcasts, VTY_NEWLINE);  vty_out (vty, "    output errors %lu%s",	   ifp->stats.ifi_oerrors, VTY_NEWLINE);  vty_out (vty, "    collisions %lu%s",	   ifp->stats.ifi_collisions, VTY_NEWLINE);#endif /* __bsdi__ || __NetBSD__ */#endif /* HAVE_NET_RT_IFLIST */}/* Check supported address family. */intif_supported_family (int family){  if (family == AF_INET)    return 1;#ifdef HAVE_IPV6  if (family == AF_INET6)    return 1;#endif /* HAVE_IPV6 */  return 0;}/* Wrapper hook point for zebra daemon so that ifindex can be set  * DEFUN macro not used as extract.pl HAS to ignore this * See also interface_cmd in lib/if.c */ DEFUN_NOSH (zebra_interface,	    zebra_interface_cmd,	    "interface IFNAME",	    "Select an interface to configure\n"	    "Interface's name\n"){  int ret;  struct interface * ifp; vty_out (vty, "sunl 2%s", VTY_NEWLINE);   /* Call lib interface() */  ret = interface_cmd.func (self, vty, argc, argv);  ifp = vty->index;    /* Set ifindex      this only happens if interface is NOT in kernel */  if (ifp->ifindex == 0)    {      ifp->ifindex = if_new_intern_ifindex ();      UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);    }  return ret;}DEFUN (no_zebra_interface,       no_zebra_interface_cmd,       "no interface IFNAME",       "Delete a pseudo interface's configuration\n"       "Interface's name\n"){  struct interface *ifp;    ifp = if_lookup_by_name(argv[0]);    if (ifp == NULL)     {      vty_out (vty, "Inteface %s does not exist%s",               argv[0],              VTY_NEWLINE);      return CMD_WARNING;    }  if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))    {      vty_out(vty, "Only inactive interfaces can be deleted%s", VTY_NEWLINE);      return CMD_WARNING;    }  /* Delete interface */  if_delete(ifp);  return CMD_SUCCESS;} struct cmd_node interface_node ={  INTERFACE_NODE,  "%s(config-if)# ",  1};/* Show all or specified interface to vty. */DEFUN (show_interface, show_interface_cmd,       "show interface [IFNAME]",         SHOW_STR       "Interface status and configuration\n"       "Inteface name\n"){  listnode node;  struct interface *ifp;  #ifdef HAVE_PROC_NET_DEV  /* If system has interface statistics via proc file system, update     statistics. */  ifstat_update_proc ();#endif /* HAVE_PROC_NET_DEV */#ifdef HAVE_NET_RT_IFLIST  ifstat_update_sysctl ();#endif /* HAVE_NET_RT_IFLIST */  /* Specified interface print. */  if (argc != 0)    {      ifp = if_lookup_by_name (argv[0]);      if (ifp == NULL) 	{	  vty_out (vty, "%% Can't find interface %s%s", argv[0],		   VTY_NEWLINE);	  return CMD_WARNING;	}      if_dump_vty (vty, ifp);      return CMD_SUCCESS;    }  /* All interface print. */  for (node = listhead (iflist); node; nextnode (node))    if_dump_vty (vty, getdata (node));  return CMD_SUCCESS;}DEFUN (multicast,       multicast_cmd,       "multicast",       "Set multicast flag to interface\n"){  int ret;  struct interface *ifp;  struct zebra_if *if_data;  ifp = (struct interface *) vty->index;  ret = if_set_flags (ifp, IFF_MULTICAST);  if (ret < 0)    {      vty_out (vty, "Can't set multicast flag%s", VTY_NEWLINE);      return CMD_WARNING;    }  if_refresh (ifp);  if_data = ifp->info;  if_data->multicast = IF_ZEBRA_MULTICAST_ON;    return CMD_SUCCESS;}DEFUN (no_multicast,       no_multicast_cmd,       "no multicast",       NO_STR       "Unset multicast flag to interface\n"){  int ret;  struct interface *ifp;  struct zebra_if *if_data;  ifp = (struct interface *) vty->index;  ret = if_unset_flags (ifp, IFF_MULTICAST);  if (ret < 0)    {      vty_out (vty, "Can't unset multicast flag%s", VTY_NEWLINE);      return CMD_WARNING;    }  if_refresh (ifp);  if_data = ifp->info;  if_data->multicast = IF_ZEBRA_MULTICAST_OFF;  return CMD_SUCCESS;}DEFUN (shutdown_if,       shutdown_if_cmd,       "shutdown",       "Shutdown the selected interface\n"){  int ret;  struct interface *ifp;  struct zebra_if *if_data;  ifp = (struct interface *) vty->index;  ret = if_unset_flags (ifp, IFF_UP);  if (ret < 0)    {      vty_out (vty, "Can't shutdown interface%s", VTY_NEWLINE);      return CMD_WARNING;    }  if_refresh (ifp);  if_data = ifp->info;  if_data->shutdown = IF_ZEBRA_SHUTDOWN_ON;  return CMD_SUCCESS;}DEFUN (no_shutdown_if,       no_shutdown_if_cmd,       "no shutdown",       NO_STR       "Shutdown the selected interface\n"){  int ret;  struct interface *ifp;  struct zebra_if *if_data;  ifp = (struct interface *) vty->index;  ret = if_set_flags (ifp, IFF_UP | IFF_RUNNING);  if (ret < 0)    {      vty_out (vty, "Can't up interface%s", VTY_NEWLINE);      return CMD_WARNING;    }  if_refresh (ifp);  if_data = ifp->info;  if_data->shutdown = IF_ZEBRA_SHUTDOWN_OFF;  return CMD_SUCCESS;}DEFUN (bandwidth_if,       bandwidth_if_cmd,       "bandwidth <1-10000000>",       "Set bandwidth informational parameter\n"       "Bandwidth in kilobits\n"){  struct interface *ifp;     unsigned int bandwidth;    ifp = (struct interface *) vty->index;  bandwidth = strtol(argv[0], NULL, 10);  /* bandwidth range is <1-10000000> */  if (bandwidth < 1 || bandwidth > 10000000)    {      vty_out (vty, "Bandwidth is invalid%s", VTY_NEWLINE);      return CMD_WARNING;    }    ifp->bandwidth = bandwidth;  /* force protocols to recalculate routes due to cost change */  if (if_is_up (ifp))    zebra_interface_up_update (ifp);    return CMD_SUCCESS;}DEFUN (no_bandwidth_if,       no_bandwidth_if_cmd,       "no bandwidth",       NO_STR       "Set bandwidth informational parameter\n"){  struct interface *ifp;       ifp = (struct interface *) vty->index;  ifp->bandwidth = 0;    /* force protocols to recalculate routes due to cost change */  if (if_is_up (ifp))    zebra_interface_up_update (ifp);  return CMD_SUCCESS;}ALIAS (no_bandwidth_if,       no_bandwidth_if_val_cmd,       "no bandwidth <1-10000000>",       NO_STR       "Set bandwidth informational parameter\n"       "Bandwidth in kilobits\n");intip_address_install (struct vty *vty, struct interface *ifp, char *addr_str,		    char *peer_str, char *label, int secondary){  struct prefix_ipv4 cp;  struct connected *ifc;  struct prefix_ipv4 *p;  struct in_addr mask;  int ret;vty_out (vty, "sunlei is here %s", VTY_NEWLINE);  ret = str2prefix_ipv4 (addr_str, &cp);  if (ret <= 0)    {      vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);      return CMD_WARNING;    }  ifc = connected_check_ipv4 (ifp, (struct prefix *) &cp);  if (! ifc)    {      ifc = connected_new ();      ifc->ifp = ifp;      /* Address. */      p = prefix_ipv4_new ();      *p = cp;      ifc->address = (struct prefix *) p;      /* Broadcast. */      if (p->prefixlen <= 30)	{	  p = prefix_ipv4_new ();	  *p = cp;	  masklen2ip (p->prefixlen, &mask);	  p->prefix.s_addr |= ~mask.s_addr;	  ifc->destination = (struct prefix *) p;	}      /* Secondary. */      if (secondary)	SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);      /* Label. */      if (label)	ifc->label = strdup (label);      /* Add to linked list. */      listnode_add (ifp->connected, ifc);    }  /* This address is configured from zebra. */  if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))    SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);  /* In case of this route need to install kernel. */  if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)      && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))

⌨️ 快捷键说明

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