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

📄 bgp_vty.c

📁 大名鼎鼎的路由器源码。程序分ZEBRA、OSPFRIP等3个包。程序框架采用一个路由协议一个进程的方式
💻 C
📖 第 1 页 / 共 5 页
字号:
/* BGP VTY interface.   Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro   This file is part of GNU Zebra.   GNU Zebra is free software; you can redistribute it and/or modify it   under the terms of the GNU General Public License as published by the   Free Software Foundation; either version 2, or (at your option) any   later version.   GNU Zebra is distributed in the hope that it will be useful, but   WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   General Public License for more details.   You should have received a copy of the GNU General Public License   along with GNU Zebra; see the file COPYING.  If not, write to the Free   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA   02111-1307, USA.  */#include <zebra.h>#include "command.h"#include "prefix.h"#include "plist.h"#include "buffer.h"#include "linklist.h"#include "stream.h"#include "thread.h"#include "log.h"#include "bgpd/bgpd.h"#include "bgpd/bgp_attr.h"#include "bgpd/bgp_aspath.h"#include "bgpd/bgp_community.h"#include "bgpd/bgp_debug.h"#include "bgpd/bgp_fsm.h"#include "bgpd/bgp_mplsvpn.h"#include "bgpd/bgp_open.h"#include "bgpd/bgp_route.h"#include "bgpd/bgp_zebra.h"/* Utility function to get address family from current node.  */afi_tbgp_node_afi (struct vty *vty){  if (vty->node == BGP_IPV6_NODE)    return AFI_IP6;  return AFI_IP;}/* Utility function to get subsequent address family from current   node.  */safi_tbgp_node_safi (struct vty *vty){  if (vty->node == BGP_VPNV4_NODE)    return SAFI_MPLS_VPN;  if (vty->node == BGP_IPV4M_NODE)    return SAFI_MULTICAST;  return SAFI_UNICAST;}intpeer_address_self_check (union sockunion *su){  struct interface *ifp = NULL;  if (su->sa.sa_family == AF_INET)    ifp = if_lookup_by_ipv4_exact (&su->sin.sin_addr);#ifdef HAVE_IPV6  else if (su->sa.sa_family == AF_INET6)    ifp = if_lookup_by_ipv6_exact (&su->sin6.sin6_addr);#endif /* HAVE IPV6 */  if (ifp)    return 1;  return 0;}/* Utility function for looking up peer from VTY.  */struct peer *peer_lookup_vty (struct vty *vty, char *ip_str){  int ret;  struct bgp *bgp;  union sockunion su;  struct peer *peer;  bgp = vty->index;  ret = str2sockunion (ip_str, &su);  if (ret < 0)    {      vty_out (vty, "%% Malformed address: %s%s", ip_str, VTY_NEWLINE);      return NULL;    }  peer = peer_lookup (bgp, &su);  if (! peer)    {      vty_out (vty, "%% Specify remote-as or peer-group commands first%s", VTY_NEWLINE);      return NULL;    }  return peer;}/* Utility function for looking up peer or peer group.  */struct peer *peer_and_group_lookup_vty (struct vty *vty, char *peer_str){  int ret;  struct bgp *bgp;  union sockunion su;  struct peer *peer;  struct peer_group *group;  bgp = vty->index;  ret = str2sockunion (peer_str, &su);  if (ret == 0)    {      peer = peer_lookup (bgp, &su);      if (peer)	return peer;    }  else    {      group = peer_group_lookup (bgp, peer_str);      if (group)	return group->conf;    }  vty_out (vty, "%% Specify remote-as or peer-group commands first%s",	   VTY_NEWLINE);  return NULL;}intbgp_vty_return (struct vty *vty, int ret){  char *str = NULL;  switch (ret)    {    case BGP_ERR_INVALID_VALUE:      str = "Invalid value";      break;    case BGP_ERR_INVALID_FLAG:      str = "Invalid flag";      break;    case BGP_ERR_PEER_INACTIVE:      str = "Activate the neighbor for the address family first";      break;    case BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER:      str = "Invalid command for a peer-group member";      break;    case BGP_ERR_PEER_GROUP_SHUTDOWN:      str = "Peer-group has been shutdown. Activate the peer-group first";      break;    case BGP_ERR_PEER_GROUP_HAS_THE_FLAG:      str = "This peer is a peer-group member.  Please change peer-group configuration";      break;    case BGP_ERR_PEER_FLAG_CONFLICT:      str = "Can't set override-capability and strict-capability-match at the same time";      break;    case BGP_ERR_PEER_GROUP_MEMBER_EXISTS:      str = "No activate for peergroup can be given only if peer-group has no members";      break;    case BGP_ERR_PEER_BELONGS_TO_GROUP:      str = "No activate for an individual peer-group member is invalid";      break;    case BGP_ERR_PEER_GROUP_AF_UNCONFIGURED:      str = "Activate the peer-group for the address family first";      break;    case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:      str = "Specify remote-as or peer-group remote AS first";      break;    case BGP_ERR_PEER_GROUP_CANT_CHANGE:      str = "Cannot change the peer-group. Deconfigure first";      break;    case BGP_ERR_PEER_GROUP_MISMATCH:      str = "Cannot have different peer-group for the neighbor";      break;    case BGP_ERR_PEER_FILTER_CONFLICT:      str = "Prefix/distribute list can not co-exist";      break;    case BGP_ERR_NOT_INTERNAL_PEER:      str = "Invalid command. Not an internal neighbor";      break;    case BGP_ERR_REMOVE_PRIVATE_AS:      str = "Private AS cannot be removed for IBGP peers";      break;    case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:      str = "Local-AS allowed only for EBGP peers";      break;    case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:      str = "Cannot have local-as same as BGP AS number";      break;    }  if (str)    {      vty_out (vty, "%% %s%s", str, VTY_NEWLINE);      return CMD_WARNING;    }  return CMD_SUCCESS;}/* BGP global configuration.  */DEFUN (bgp_multiple_instance_func,       bgp_multiple_instance_cmd,       "bgp multiple-instance",       BGP_STR       "Enable bgp multiple instance\n"){  bgp_option_set (BGP_OPT_MULTIPLE_INSTANCE);  return CMD_SUCCESS;}DEFUN (no_bgp_multiple_instance,       no_bgp_multiple_instance_cmd,       "no bgp multiple-instance",       NO_STR       BGP_STR       "BGP multiple instance\n"){  int ret;  ret = bgp_option_unset (BGP_OPT_MULTIPLE_INSTANCE);  if (ret < 0)    {      vty_out (vty, "%% There are more than two BGP instances%s", VTY_NEWLINE);      return CMD_WARNING;    }  return CMD_SUCCESS;}DEFUN (bgp_config_type,       bgp_config_type_cmd,       "bgp config-type (cisco|zebra)",       BGP_STR       "Configuration type\n"       "cisco\n"       "zebra\n"){  if (strncmp (argv[0], "c", 1) == 0)    bgp_option_set (BGP_OPT_CONFIG_CISCO);  else    bgp_option_unset (BGP_OPT_CONFIG_CISCO);  return CMD_SUCCESS;}DEFUN (no_bgp_config_type,       no_bgp_config_type_cmd,       "no bgp config-type",       NO_STR       BGP_STR       "Display configuration type\n"){  bgp_option_unset (BGP_OPT_CONFIG_CISCO);  return CMD_SUCCESS;}DEFUN (no_synchronization,       no_synchronization_cmd,       "no synchronization",       NO_STR       "Perform IGP synchronization\n"){  return CMD_SUCCESS;}DEFUN (no_auto_summary,       no_auto_summary_cmd,       "no auto-summary",       NO_STR       "Enable automatic network number summarization\n"){  return CMD_SUCCESS;}/* "router bgp" commands. */DEFUN (router_bgp,        router_bgp_cmd,        "router bgp <1-65535>",       ROUTER_STR       BGP_STR       AS_STR){  int ret;  as_t as;  struct bgp *bgp;  char *name = NULL;  VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, 65535);  if (argc == 2)    name = argv[1];  ret = bgp_get (&bgp, &as, name);  switch (ret)    {    case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:      vty_out (vty, "Please specify 'bgp multiple-instance' first%s", 	       VTY_NEWLINE);      return CMD_WARNING;      break;    case BGP_ERR_AS_MISMATCH:      vty_out (vty, "BGP is already running; AS is %d%s", as, VTY_NEWLINE);      return CMD_WARNING;      break;    case BGP_ERR_INSTANCE_MISMATCH:      vty_out (vty, "BGP view name and AS number mismatch%s", VTY_NEWLINE);      vty_out (vty, "BGP instance is already running; AS is %d%s",	       as, VTY_NEWLINE);      return CMD_WARNING;      break;    }  vty->node = BGP_NODE;  vty->index = bgp;  return CMD_SUCCESS;}ALIAS (router_bgp,       router_bgp_view_cmd,       "router bgp <1-65535> view WORD",       ROUTER_STR       BGP_STR       AS_STR       "BGP view\n"       "view name\n");/* "no router bgp" commands. */DEFUN (no_router_bgp,       no_router_bgp_cmd,       "no router bgp <1-65535>",       NO_STR       ROUTER_STR       BGP_STR       AS_STR){  as_t as;  struct bgp *bgp;  char *name = NULL;  VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, 65535);  if (argc == 2)    name = argv[1];  /* Lookup bgp structure. */  bgp = bgp_lookup (as, name);  if (! bgp)    {      vty_out (vty, "%% Can't find BGP instance%s", VTY_NEWLINE);      return CMD_WARNING;    }  bgp_delete (bgp);  return CMD_SUCCESS;}ALIAS (no_router_bgp,       no_router_bgp_view_cmd,       "no router bgp <1-65535> view WORD",       NO_STR       ROUTER_STR       BGP_STR       AS_STR       "BGP view\n"       "view name\n");/* BGP router-id.  */DEFUN (bgp_router_id,       bgp_router_id_cmd,       "bgp router-id A.B.C.D",       BGP_STR       "Override configured router identifier\n"       "Manually configured router identifier\n"){  int ret;  struct in_addr id;  struct bgp *bgp;  bgp = vty->index;  ret = inet_aton (argv[0], &id);  if (! ret)    {      vty_out (vty, "%% Malformed bgp router identifier%s", VTY_NEWLINE);      return CMD_WARNING;    }  bgp_router_id_set (bgp, &id);  return CMD_SUCCESS;}DEFUN (no_bgp_router_id,       no_bgp_router_id_cmd,       "no bgp router-id",       NO_STR       BGP_STR       "Override configured router identifier\n"){  int ret;  struct in_addr id;  struct bgp *bgp;  bgp = vty->index;  if (argc == 1)    {      ret = inet_aton (argv[0], &id);      if (! ret)	{	  vty_out (vty, "%% Malformed BGP router identifier%s", VTY_NEWLINE);	  return CMD_WARNING;	}      if (! IPV4_ADDR_SAME (&bgp->router_id, &id))	{	  vty_out (vty, "%% BGP router-id doesn't match%s", VTY_NEWLINE);	  return CMD_WARNING;	}    }  bgp_router_id_unset (bgp);  return CMD_SUCCESS;}ALIAS (no_bgp_router_id,       no_bgp_router_id_val_cmd,       "no bgp router-id A.B.C.D",       NO_STR       BGP_STR       "Override configured router identifier\n"       "Manually configured router identifier\n");/* BGP Cluster ID.  */DEFUN (bgp_cluster_id,       bgp_cluster_id_cmd,       "bgp cluster-id A.B.C.D",       BGP_STR       "Configure Route-Reflector Cluster-id\n"       "Route-Reflector Cluster-id in IP address format\n"){  int ret;  struct bgp *bgp;  struct in_addr cluster;  bgp = vty->index;  ret = inet_aton (argv[0], &cluster);  if (! ret)    {      vty_out (vty, "%% Malformed bgp cluster identifier%s", VTY_NEWLINE);      return CMD_WARNING;    }  bgp_cluster_id_set (bgp, &cluster);  return CMD_SUCCESS;}ALIAS (bgp_cluster_id,       bgp_cluster_id32_cmd,       "bgp cluster-id <1-4294967295>",       BGP_STR       "Configure Route-Reflector Cluster-id\n"       "Route-Reflector Cluster-id as 32 bit quantity\n");DEFUN (no_bgp_cluster_id,       no_bgp_cluster_id_cmd,       "no bgp cluster-id",       NO_STR       BGP_STR       "Configure Route-Reflector Cluster-id\n"){  int ret;  struct bgp *bgp;  struct in_addr cluster;  bgp = vty->index;  if (argc == 1)    {      ret = inet_aton (argv[0], &cluster);      if (! ret)	{	  vty_out (vty, "%% Malformed bgp cluster identifier%s", VTY_NEWLINE);	  return CMD_WARNING;	}

⌨️ 快捷键说明

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