Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

bgp.h

Go to the documentation of this file.
00001 /****************************************************************************/
00002 /*  File:            bgp.h                                                  */
00003 /*  Author:          Sunitha Beeram                                         */
00004 /*  Email:           sunithab@ece.gatech.edu                                */
00005 /*  Documentation:   TBD                                                    */
00006 /*                                                                          */
00007 /*  Version:         1.0beta                                                */
00008 /*                                                                          */
00009 /*  Copyright (c) 2005 Georgia Institute of Technology                      */
00010 /*  This program is free software; you can redistribute it and/or           */
00011 /*  modify it under the terms of the GNU General Public License             */
00012 /*  as published by the Free Software Foundation; either version 2          */
00013 /*  of the License, or (at your option) any later version.                  */
00014 /*                                                                          */
00015 /*  This program is distributed in the hope that it will be useful,         */
00016 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of          */
00017 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           */
00018 /*  GNU General Public License for more details.                            */
00019 /*                                                                          */
00020 /****************************************************************************/
00021 
00022 #ifndef BGP_H
00023 #define BGP_H
00024 
00025 #include "../SRC/ipaddr.h"
00026 #include "../SRC/application.h"
00027 #include "../SRC/tcp.h"
00028 #include "routemsg.h"
00029 #include "../SRC/event.h"
00030 
00031 #include <vector>
00032 #include <list>
00033 #include <regex.h>
00034 #include <netdb.h>
00035 #include <unistd.h>
00036 #include <sys/param.h>
00037 #include <sys/socket.h>
00038 #include <sys/uio.h>
00039 #include <errno.h>
00040 #include <syslog.h>
00041 #include <string.h>
00042 #include <netinet/in.h>
00043 #include <arpa/inet.h>
00044 #include <sys/time.h>
00045 #include <assert.h>
00046 
00047 using namespace std;
00048 
00049 class BGPPeer;
00050 class BGPEvent;
00051 class BGPTimer;
00052 class BGP;
00053 
00054 //BGP Peer Connection
00055 
00056 typedef list<RouteMsg>  RMsgList_t;   // Queue of pending messages
00057 
00058 class BGPPeer {
00059  public:
00060   BGPPeer();
00061 
00062  public:
00063   TCP*   tcp; // TCP endpoint for peer
00064   //evaluate if this field is necessary
00065   bool   connected; // True if connected, false if pending
00066   int       m_rxbytes; // Pending received bytes from this peer
00067   RMsgList_t m_msgs;    // Queue of pending msgs from this peer
00068 };
00069 
00070 typedef vector<BGPPeer> PeerVec_t;
00071   
00072 //define BGPEvent class with BGPEvent_t and appropriate constructs for *master*,thread_to_be_fetched and other variables used in BGP::Timeout of bgp++
00073 
00074 class BGPEvent : public Event {
00075  public:
00076 typedef enum { MAIN,FETCH1,FETCH2,EXECUTE,COMMAND} BGPEvent_t; //mapped from bgp++ bgpresched events
00077   BGPEvent(){};
00078   BGPEvent(Event_t ev):Event(ev),argv(NULL),thread_to_be_fetched(NULL){};
00079 
00080   public:
00081         char *argv;
00082         struct thread* thread_to_be_fetched;
00083 
00084 };
00085 
00086 class BGPTimer : public Handler {
00087  public:
00088   BGPTimer(BGP* a) : Handler(){ agent = a;};
00089   void Schedule(double delay, Event* e);
00090   void expire(Event* e);
00091   void Cancel(Event* e);
00092   void Handle(Event* e, Time_t t);
00093   double expire_;
00094  protected:
00095   BGP* agent;
00096 
00097 };
00098 
00099 
00100 /* definitions found in zebra .c and .h files*/
00101 
00102 /****** sockunion.h*********/
00103 
00104 union sockunion
00105 {
00106   struct sockaddr sa;
00107   struct sockaddr_in sin;
00108 };
00109 
00110 enum connect_result
00111   {
00112     connect_error,
00113     connect_success,
00114     connect_in_progress
00115   };
00116 
00117 /* Sockunion address string length.  Same as INET6_ADDRSTRLEN. */
00118 #define SU_ADDRSTRLEN 46
00119 #define sockunion_family(X)  (X)->sa.sa_family
00120 
00121 #define TIME_BUF 27
00122 
00123 /*****zebra.h******/
00124 
00125 /* Zebra message types. */
00126 #define ZEBRA_INTERFACE_ADD                1
00127 #define ZEBRA_INTERFACE_DELETE             2
00128 #define ZEBRA_INTERFACE_ADDRESS_ADD        3
00129 #define ZEBRA_INTERFACE_ADDRESS_DELETE     4
00130 #define ZEBRA_INTERFACE_UP                 5
00131 #define ZEBRA_INTERFACE_DOWN               6
00132 #define ZEBRA_IPV4_ROUTE_ADD               7
00133 #define ZEBRA_IPV4_ROUTE_DELETE            8
00134 #define ZEBRA_IPV6_ROUTE_ADD               9
00135 #define ZEBRA_IPV6_ROUTE_DELETE           10
00136 #define ZEBRA_REDISTRIBUTE_ADD            11
00137 #define ZEBRA_REDISTRIBUTE_DELETE         12
00138 #define ZEBRA_REDISTRIBUTE_DEFAULT_ADD    13
00139 #define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
00140 #define ZEBRA_IPV4_NEXTHOP_LOOKUP         15
00141 #define ZEBRA_IPV6_NEXTHOP_LOOKUP         16
00142 #define ZEBRA_IPV4_IMPORT_LOOKUP          17
00143 #define ZEBRA_IPV6_IMPORT_LOOKUP          18
00144 #define ZEBRA_MESSAGE_MAX                 19
00145 
00146 /* Zebra route's types. */
00147 #define ZEBRA_ROUTE_SYSTEM               0
00148 #define ZEBRA_ROUTE_KERNEL               1
00149 #define ZEBRA_ROUTE_CONNECT              2
00150 #define ZEBRA_ROUTE_STATIC               3
00151 #define ZEBRA_ROUTE_RIP                  4
00152 #define ZEBRA_ROUTE_RIPNG                5
00153 #define ZEBRA_ROUTE_OSPF                 6
00154 #define ZEBRA_ROUTE_OSPF6                7
00155 #define ZEBRA_ROUTE_BGP                  8
00156 #define ZEBRA_ROUTE_MAX                  9
00157 
00158 /* Zebra's family types. */
00159 #define ZEBRA_FAMILY_IPV4                1
00160 #define ZEBRA_FAMILY_IPV6                2
00161 #define ZEBRA_FAMILY_MAX                 3
00162 
00163 /* Error codes of zebra. */
00164 #define ZEBRA_ERR_RTEXIST               -1
00165 #define ZEBRA_ERR_RTUNREACH             -2
00166 #define ZEBRA_ERR_EPERM                 -3
00167 #define ZEBRA_ERR_RTNOEXIST             -4
00168 
00169 /* Zebra message flags */
00170 #define ZEBRA_FLAG_INTERNAL           0x01
00171 #define ZEBRA_FLAG_SELFROUTE          0x02
00172 #define ZEBRA_FLAG_BLACKHOLE          0x04
00173 #define ZEBRA_FLAG_IBGP               0x08
00174 #define ZEBRA_FLAG_SELECTED           0x10
00175 #define ZEBRA_FLAG_CHANGED            0x20
00176 #define ZEBRA_FLAG_STATIC             0x40
00177 
00178 /* Zebra nexthop flags. */
00179 #define ZEBRA_NEXTHOP_IFINDEX            1
00180 #define ZEBRA_NEXTHOP_IFNAME             2
00181 #define ZEBRA_NEXTHOP_IPV4               3
00182 #define ZEBRA_NEXTHOP_IPV4_IFINDEX       4
00183 #define ZEBRA_NEXTHOP_IPV4_IFNAME        5
00184 #define ZEBRA_NEXTHOP_IPV6               6
00185 #define ZEBRA_NEXTHOP_IPV6_IFINDEX       7
00186 #define ZEBRA_NEXTHOP_IPV6_IFNAME        8
00187 #define ZEBRA_NEXTHOP_BLACKHOLE          9 
00188 
00189 #ifndef INADDR_LOOPBACK
00190 #define INADDR_LOOPBACK 0x7f000001      /* Internet address 127.0.0.1.  */
00191 #endif
00192 
00193 /* Address family numbers from RFC1700. */
00194 #define AFI_IP                    1
00195 #define AFI_IP6                   2
00196 #define AFI_MAX                   3
00197 
00198 /* Subsequent Address Family Identifier. */
00199 #define SAFI_UNICAST              1
00200 #define SAFI_MULTICAST            2
00201 #define SAFI_UNICAST_MULTICAST    3
00202 #define SAFI_MPLS_VPN             4
00203 #define SAFI_MAX                  5
00204 
00205 /* Filter direction.  */
00206 #define FILTER_IN                 0
00207 #define FILTER_OUT                1
00208 #define FILTER_MAX                2
00209 
00210 /* Default Administrative Distance of each protocol. */
00211 #define ZEBRA_KERNEL_DISTANCE_DEFAULT      0
00212 #define ZEBRA_CONNECT_DISTANCE_DEFAULT     0
00213 #define ZEBRA_STATIC_DISTANCE_DEFAULT      1
00214 #define ZEBRA_RIP_DISTANCE_DEFAULT       120
00215 #define ZEBRA_RIPNG_DISTANCE_DEFAULT     120
00216 #define ZEBRA_OSPF_DISTANCE_DEFAULT      110
00217 #define ZEBRA_OSPF6_DISTANCE_DEFAULT     110
00218 #define ZEBRA_IBGP_DISTANCE_DEFAULT      200
00219 #define ZEBRA_EBGP_DISTANCE_DEFAULT       20
00220 
00221 /* Flag manipulation macros. */
00222 #define CHECK_FLAG(V,F)      ((V) & (F))
00223 #define SET_FLAG(V,F)        (V) = (V) | (F)
00224 #define UNSET_FLAG(V,F)      (V) = (V) & ~(F)
00225 
00226 /* AFI and SAFI type. */
00227 typedef u_int16_t afi_t;
00228 typedef u_char safi_t;
00229 
00230 /* Zebra types. */
00231 typedef u_int16_t zebra_size_t;
00232 typedef u_int8_t zebra_command_t;
00233 
00234 /* FIFO -- first in first out structure and macros.  */
00235 struct fifo
00236 {
00237   struct fifo *next;
00238   struct fifo *prev;
00239 };
00240 
00241 #define FIFO_INIT(F)                                  \
00242   do {                                                \
00243     struct fifo *Xfifo = (struct fifo *)(F);          \
00244     Xfifo->next = Xfifo->prev = Xfifo;                \
00245   } while (0)
00246 
00247 #define FIFO_ADD(F,N)                                 \
00248   do {                                                \
00249     struct fifo *Xfifo = (struct fifo *)(F);          \
00250     struct fifo *Xnode = (struct fifo *)(N);          \
00251     Xnode->next = Xfifo;                              \
00252     Xnode->prev = Xfifo->prev;                        \
00253     Xfifo->prev = Xfifo->prev->next = Xnode;          \
00254   } while (0)
00255 
00256 #define FIFO_DEL(N)                                   \
00257   do {                                                \
00258     struct fifo *Xnode = (struct fifo *)(N);          \
00259     Xnode->prev->next = Xnode->next;                  \
00260     Xnode->next->prev = Xnode->prev;                  \
00261   } while (0)
00262 
00263 #define FIFO_HEAD(F)                                  \
00264   ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
00265   ? NULL : (F)->next)
00266 
00267 #define FIFO_EMPTY(F)                                 \
00268   (((struct fifo *)(F))->next == (struct fifo *)(F))
00269 
00270 #define FIFO_TOP(F)                                   \
00271   (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
00272 
00273 /*bgp_advertise.h*/
00274 
00275 /* BGP advertise FIFO.  */
00276 struct bgp_advertise_fifo
00277 {
00278   struct bgp_advertise *next;
00279   struct bgp_advertise *prev;
00280 };
00281 
00282 /* BGP advertise attribute.  */
00283 struct bgp_advertise_attr
00284 {
00285   /* Head of advertisement pointer. */
00286   struct bgp_advertise *adv;
00287 
00288   /* Reference counter.  */
00289   unsigned long refcnt;
00290 
00291   /* Attribute pointer to be announced.  */
00292   struct attr *attr;
00293 };
00294 
00295 /* BGP adjacency out.  */
00296 struct bgp_adj_out
00297 {
00298   /* Lined list pointer.  */
00299   struct bgp_adj_out *next;
00300   struct bgp_adj_out *prev;
00301 
00302   /* Advertised peer.  */
00303   struct peer *peer;
00304 
00305   /* Advertised attribute.  */
00306   struct attr *attr;
00307 
00308   /* Advertisement information.  */
00309   struct bgp_advertise *adv;
00310 };
00311 
00312 /* BGP adjacency in. */
00313 struct bgp_adj_in
00314 {
00315   /* Linked list pointer.  */
00316   struct bgp_adj_in *next;
00317   struct bgp_adj_in *prev;
00318 
00319   /* Received peer.  */
00320   struct peer *peer;
00321 
00322   /* Received attribute.  */
00323   struct attr *attr;
00324 };
00325 
00326 /* BGP advertisement list.  */
00327 struct bgp_synchronize
00328 {
00329   struct bgp_advertise_fifo update;
00330   struct bgp_advertise_fifo withdraw;
00331   struct bgp_advertise_fifo withdraw_low;
00332 };
00333 
00334 /* BGP adjacency linked list.  */
00335 #define BGP_INFO_ADD(N,A,TYPE)                        \
00336   do {                                                \
00337     (A)->prev = NULL;                                 \
00338     (A)->next = (N)->TYPE;                            \
00339     if ((N)->TYPE)                                    \
00340       (N)->TYPE->prev = (A);                          \
00341     (N)->TYPE = (A);                                  \
00342   } while (0)
00343 
00344 #define BGP_INFO_DEL(N,A,TYPE)                        \
00345   do {                                                \
00346     if ((A)->next)                                    \
00347       (A)->next->prev = (A)->prev;                    \
00348     if ((A)->prev)                                    \
00349       (A)->prev->next = (A)->next;                    \
00350     else                                              \
00351       (N)->TYPE = (A)->next;                          \
00352   } while (0)
00353 
00354 #define BGP_ADJ_IN_ADD(N,A)    BGP_INFO_ADD(N,A,adj_in)
00355 #define BGP_ADJ_IN_DEL(N,A)    BGP_INFO_DEL(N,A,adj_in)
00356 #define BGP_ADJ_OUT_ADD(N,A)   BGP_INFO_ADD(N,A,adj_out)
00357 #define BGP_ADJ_OUT_DEL(N,A)   BGP_INFO_DEL(N,A,adj_out)
00358 
00359 /*bgp_aspath.h*/
00360 
00361 /* AS path segment type.  */
00362 #define AS_SET                       1
00363 #define AS_SEQUENCE                  2
00364 #define AS_CONFED_SEQUENCE           3
00365 #define AS_CONFED_SET                4
00366 
00367 /* Private AS range defined in RFC2270.  */
00368 #define BGP_PRIVATE_AS_MIN       64512
00369 #define BGP_PRIVATE_AS_MAX       65535
00370 
00371 /* AS path may be include some AsSegments.  */
00372 struct aspath 
00373 {
00374   /* Reference count to this aspath.  */
00375   unsigned long refcnt;
00376 
00377   /* Rawdata length.  */
00378   int length;
00379 
00380   /* AS count.  */
00381   int count;
00382 
00383   /* Rawdata.  */
00384   caddr_t data;
00385 
00386   /* String expression of AS path.  This string is used by vty output
00387      and AS path regular expression match.  */
00388   char *str;
00389 };
00390 
00391 #define ASPATH_STR_DEFAULT_LEN 32
00392 
00393 /******* zebra_zclient.h********/
00394 
00395 /* For input/output buffer to zebra. */
00396 #define ZEBRA_MAX_PACKET_SIZ          4096
00397 
00398 /* Zebra header size. */
00399 #define ZEBRA_HEADER_SIZE                3
00400 
00401 /* Zebra API message flag. */
00402 #define ZAPI_MESSAGE_NEXTHOP  0x01
00403 #define ZAPI_MESSAGE_IFINDEX  0x02
00404 #define ZAPI_MESSAGE_DISTANCE 0x04
00405 #define ZAPI_MESSAGE_METRIC   0x08
00406 
00407 /***** if.h *********/
00408 
00409 #define INTERFACE_NAMSIZ      20
00410 #define INTERFACE_HWADDR_MAX  20
00411 
00412 /* Internal If indexes start at 0xFFFFFFFF and go down to 1 greater
00413    than this */
00414 #define IFINDEX_INTERNBASE 0x80000000
00415 
00416 #ifdef HAVE_PROC_NET_DEV
00417 struct if_stats
00418 {
00419   unsigned long rx_packets;   /* total packets received       */
00420   unsigned long tx_packets;   /* total packets transmitted    */
00421   unsigned long rx_bytes;     /* total bytes received         */
00422   unsigned long tx_bytes;     /* total bytes transmitted      */
00423   unsigned long rx_errors;    /* bad packets received         */
00424   unsigned long tx_errors;    /* packet transmit problems     */
00425   unsigned long rx_dropped;   /* no space in linux buffers    */
00426   unsigned long tx_dropped;   /* no space available in linux  */
00427   unsigned long rx_multicast; /* multicast packets received   */
00428   unsigned long rx_compressed;
00429   unsigned long tx_compressed;
00430   unsigned long collisions;
00431 
00432   /* detailed rx_errors: */
00433   unsigned long rx_length_errors;
00434   unsigned long rx_over_errors;       /* receiver ring buff overflow  */
00435   unsigned long rx_crc_errors;        /* recved pkt with crc error    */
00436   unsigned long rx_frame_errors;      /* recv'd frame alignment error */
00437   unsigned long rx_fifo_errors;       /* recv'r fifo overrun          */
00438   unsigned long rx_missed_errors;     /* receiver missed packet     */
00439   /* detailed tx_errors */
00440   unsigned long tx_aborted_errors;
00441   unsigned long tx_carrier_errors;
00442   unsigned long tx_fifo_errors;
00443   unsigned long tx_heartbeat_errors;
00444   unsigned long tx_window_errors;
00445 };
00446 #endif /* HAVE_PROC_NET_DEV */
00447 
00448 /* Interface structure */
00449 struct interface 
00450 {
00451   /* Interface name. */
00452   char name[INTERFACE_NAMSIZ + 1];
00453 
00454   /* Interface index. */
00455   unsigned int ifindex;
00456 
00457   /* Zebra internal interface status */
00458   u_char status;
00459 #define ZEBRA_INTERFACE_ACTIVE     (1 << 0)
00460 #define ZEBRA_INTERFACE_SUB        (1 << 1)
00461   
00462   /* Interface flags. */
00463   unsigned long flags;
00464 
00465   /* Interface metric */
00466   int metric;
00467 
00468   /* Interface MTU. */
00469   int mtu;
00470 
00471   /* Hardware address. */
00472 #ifdef HAVE_SOCKADDR_DL
00473   struct sockaddr_dl sdl;
00474 #else
00475   unsigned short hw_type;
00476   u_char hw_addr[INTERFACE_HWADDR_MAX];
00477   int hw_addr_len;
00478 #endif /* HAVE_SOCKADDR_DL */
00479 
00480   /* interface bandwidth, kbits */
00481   unsigned int bandwidth;
00482   
00483   /* description of the interface. */
00484   char *desc;                   
00485 
00486   /* Distribute list. */
00487   void *distribute_in;
00488   void *distribute_out;
00489 
00490   /* Connected address list. */
00491   struct llist* connected;
00492 
00493   /* Daemon specific interface data pointer. */
00494   void *info;
00495 
00496   /* Statistics fileds. */
00497 #ifdef HAVE_PROC_NET_DEV
00498   struct if_stats stats;
00499 #endif /* HAVE_PROC_NET_DEV */  
00500 #ifdef HAVE_NET_RT_IFLIST
00501   struct if_data stats;
00502 #endif /* HAVE_NET_RT_IFLIST */
00503 };
00504 
00505 /* Connected address structure. */
00506 struct connected
00507 {
00508   /* Attached interface. */
00509   struct interface *ifp;
00510 
00511   /* Flags for configuration. */
00512   u_char conf;
00513 #define ZEBRA_IFC_REAL         (1 << 0)
00514 #define ZEBRA_IFC_CONFIGURED   (1 << 1)
00515 
00516   /* Flags for connected address. */
00517   u_char flags;
00518 #define ZEBRA_IFA_SECONDARY   (1 << 0)
00519 
00520   /* Address of connected network. */
00521   struct prefix *address;
00522   struct prefix *destination;
00523 
00524   /* Label for Linux 2.2.X and upper. */
00525   char *label;
00526 };
00527 
00528 /* Interface hook sort. */
00529 #define IF_NEW_HOOK   0
00530 #define IF_DELETE_HOOK 1
00531 
00532 /* There are some interface flags which are only supported by some
00533    operating system. */
00534 
00535 #ifndef IFF_NOTRAILERS
00536 #define IFF_NOTRAILERS 0x0
00537 #endif /* IFF_NOTRAILERS */
00538 #ifndef IFF_OACTIVE
00539 #define IFF_OACTIVE 0x0
00540 #endif /* IFF_OACTIVE */
00541 #ifndef IFF_SIMPLEX
00542 #define IFF_SIMPLEX 0x0
00543 #endif /* IFF_SIMPLEX */
00544 #ifndef IFF_LINK0
00545 #define IFF_LINK0 0x0
00546 #endif /* IFF_LINK0 */
00547 #ifndef IFF_LINK1
00548 #define IFF_LINK1 0x0
00549 #endif /* IFF_LINK1 */
00550 #ifndef IFF_LINK2
00551 #define IFF_LINK2 0x0
00552 #endif /* IFF_LINK2 */
00553 
00554 
00555 /****** bgp_nexthop.h******/
00556 
00557 
00558 #define BGP_SCAN_INTERVAL_DEFAULT   60
00559 #define BGP_IMPORT_INTERVAL_DEFAULT 15
00560 
00561 /* BGP nexthop cache value structure. */
00562 struct bgp_nexthop_cache
00563 {
00564   /* This nexthop exists in IGP. */
00565   u_char valid;
00566 
00567   /* Nexthop is changed. */
00568   u_char changed;
00569 
00570   /* Nexthop is changed. */
00571   u_char metricchanged;
00572 
00573   /* IGP route's metric. */
00574   u_int32_t metric;
00575 
00576   /* Nexthop number and nexthop linked list.*/
00577   u_char nexthop_num;
00578   struct nexthop *nexthop;
00579 };
00580 
00581 
00582 
00583 
00584 /*****from bgpd.h******/
00585 
00586 /* Typedef BGP specific types.  */
00587 typedef u_int16_t as_t;
00588 typedef u_long bgp_size_t;
00589 
00590 /* BGP master for system wide configurations and variables.  */
00591 struct bgp_master
00592 {
00593   /* BGP instance list.  */
00594   struct llist *bgp;
00595 
00596   /* BGP thread master.  */
00597   struct thread_master *master;
00598 
00599   /* BGP start time.  */
00600   time_t start_time;
00601 
00602   /* Various BGP global configuration.  */
00603   u_char options;
00604 #define BGP_OPT_NO_FIB                   (1 << 0)
00605 #define BGP_OPT_MULTIPLE_INSTANCE        (1 << 1)
00606 #define BGP_OPT_CONFIG_CISCO             (1 << 2)
00607 };
00608 
00609 /* BGP instance structure.  */
00610 struct bgp 
00611 {
00612   /* AS number of this BGP instance.  */
00613   as_t as;
00614 
00615   /* Name of this BGP instance.  */
00616   char *name;
00617   /* Self peer.  */
00618   struct peer *peer_self;
00619 
00620   /* BGP peer. */
00621   struct llist *peer;
00622 
00623   /* BGP peer group.  */
00624   struct llist *group;
00625 
00626   /* BGP peer-conf */
00627         struct llist *peer_conf;
00628 
00629   /* BGP configuration.  */
00630   u_int16_t config;
00631 #define BGP_CONFIG_ROUTER_ID              (1 << 0)
00632 #define BGP_CONFIG_CLUSTER_ID             (1 << 1)
00633 #define BGP_CONFIG_CONFEDERATION          (1 << 2)
00634 #define BGP_CONFIG_DEFAULT_LOCAL_PREF     (1 << 3)
00635 
00636   /*BGP identifier */
00637   struct in_addr id;
00638   
00639   /*Local sockunion*/
00640   union sockunion su;
00641 
00642   /* BGP router identifier.  */
00643   struct in_addr router_id;
00644 
00645   /* BGP route reflector cluster ID.  */
00646   struct in_addr cluster_id;
00647 
00648   /* BGP confederation information.  */
00649   as_t confed_id;
00650   as_t *confed_peers;
00651   int confed_peers_cnt;
00652 
00653   /* BGP flags. */
00654   u_int16_t flags;
00655 #define BGP_FLAG_ALWAYS_COMPARE_MED       (1 << 0)
00656 #define BGP_FLAG_DETERMINISTIC_MED        (1 << 1)
00657 #define BGP_FLAG_MED_MISSING_AS_WORST     (1 << 2)
00658 #define BGP_FLAG_MED_CONFED               (1 << 3)
00659 #define BGP_FLAG_NO_DEFAULT_IPV4          (1 << 4)
00660 #define BGP_FLAG_NO_CLIENT_TO_CLIENT      (1 << 5)
00661 #define BGP_FLAG_ENFORCE_FIRST_AS         (1 << 6)
00662 #define BGP_FLAG_COMPARE_ROUTER_ID        (1 << 7)
00663 #define BGP_FLAG_ASPATH_IGNORE            (1 << 8)
00664 #define BGP_FLAG_IMPORT_CHECK             (1 << 9)
00665 #define BGP_FLAG_NO_FAST_EXT_FAILOVER     (1 << 10)
00666 #define BGP_FLAG_LOG_NEIGHBOR_CHANGES     (1 << 11)
00667 
00668   /* BGP Per AF flags */
00669   u_int16_t af_flags[AFI_MAX][SAFI_MAX];
00670 #define BGP_CONFIG_DAMPENING              (1 << 0)
00671 
00672   /* Static route configuration.  */
00673   struct bgp_table *route[AFI_MAX][SAFI_MAX];
00674 
00675   /* Aggregate address configuration.  */
00676   struct bgp_table *aggregate[AFI_MAX][SAFI_MAX];
00677 
00678   /* BGP routing information base.  */
00679   struct bgp_table *rib[AFI_MAX][SAFI_MAX];
00680 
00681   /* BGP redistribute configuration. */
00682   u_char redist[AFI_MAX][ZEBRA_ROUTE_MAX];
00683 
00684   /* BGP redistribute metric configuration. */
00685   u_char redist_metric_flag[AFI_MAX][ZEBRA_ROUTE_MAX];
00686   u_int32_t redist_metric[AFI_MAX][ZEBRA_ROUTE_MAX];
00687 
00688   /* BGP redistribute route-map.  */
00689   struct
00690   {
00691     char *name;
00692     struct route_map *map;
00693   } rmap[AFI_MAX][ZEBRA_ROUTE_MAX];
00694 
00695   /* BGP distance configuration.  */
00696   u_char distance_ebgp;
00697   u_char distance_ibgp;
00698   u_char distance_local;
00699   
00700   /* BGP default local-preference.  */
00701   u_int32_t default_local_pref;
00702 
00703   /* BGP default timer.  */
00704   u_int32_t default_holdtime;
00705   u_int32_t default_keepalive;
00706 };
00707 
00708 /* BGP peer-group support. */
00709 struct peer_group
00710 {
00711   /* Name of the peer-group. */
00712   char *name;
00713 
00714   /* Pointer to BGP.  */
00715   struct bgp *bgp;
00716   
00717   /* Peer-group client list. */
00718   struct llist *peer;
00719 
00720   /* Peer-group config */
00721   struct peer *conf;
00722 };
00723 
00724 /* BGP Notify message format. */
00725 struct bgp_notify 
00726 {
00727   u_char code;
00728   u_char subcode;
00729   char *data;
00730   bgp_size_t length;
00731 };
00732 
00733 /* Next hop self address. */
00734 struct bgp_nexthop
00735 {
00736   struct interface *ifp;
00737   struct in_addr v4;
00738 #ifdef HAVE_IPV6
00739   struct in6_addr v6_global;
00740   struct in6_addr v6_local;
00741 #endif /* HAVE_IPV6 */  
00742 };
00743 
00744 /* BGP router distinguisher value.  */
00745 #define BGP_RD_SIZE                8
00746 
00747 struct bgp_rd
00748 {
00749   u_char val[BGP_RD_SIZE];
00750 };
00751 
00752 /* BGP filter structure. */
00753 struct bgp_filter
00754 {
00755   /* Distribute-list.  */
00756   struct 
00757   {
00758     char *name;
00759     struct access_list *alist;
00760   } dlist[FILTER_MAX];
00761 
00762   /* Prefix-list.  */
00763   struct
00764   {
00765     char *name;
00766     struct prefix_list *plist;
00767   } plist[FILTER_MAX];
00768 
00769   /* Filter-list.  */
00770   struct
00771   {
00772     char *name;
00773     struct as_list *aslist;
00774   } aslist[FILTER_MAX];
00775 
00776   /* Route-map.  */
00777   struct
00778   {
00779     char *name;
00780     struct route_map *map;
00781   } map[FILTER_MAX];
00782 
00783   /* Unsuppress-map.  */
00784   struct
00785   {
00786     char *name;
00787     struct route_map *map;
00788   } usmap;
00789 };
00790 
00791 /* BGP peer configuration. */
00792 struct peer_conf
00793 {
00794   /* Pointer to BGP structure. */
00795   struct bgp *bgp;
00796 
00797   /* Pointer to peer. */
00798   struct peer *peer;
00799 
00800   /* Address Family Configuration. */
00801   u_char afc[AFI_MAX][SAFI_MAX];
00802 
00803   /* Prefix count. */
00804   unsigned long pcount[AFI_MAX][SAFI_MAX];
00805 
00806   /* Max prefix count. */
00807   unsigned long pmax[AFI_MAX][SAFI_MAX];
00808   u_char pmax_warning[AFI_MAX][SAFI_MAX];
00809 
00810   /* Filter structure. */
00811   struct bgp_filter filter[AFI_MAX][SAFI_MAX];
00812 };
00813 
00814 #ifdef BGP_MRAI
00815 struct bgp_routeadv_list {
00816   struct bgp_routeadv_list *next;
00817   struct bgp_routeadv_list *prev;
00818   struct thread *t;
00819 };
00820 #endif
00821 
00822 
00823 typedef list<pair<struct prefix,double> >    Prefix2Timestamp_t;
00824 
00825 /* default-originate route-map.  */
00826 struct default_rmap
00827 {
00828    char *name;
00829    struct route_map *map;
00830 } ;
00831 
00832 
00833 /* BGP neighbor structure. */
00834 struct peer
00835 {
00836     
00837     /*pointer to BGP instance*/
00838     
00839     BGP* Bgp;
00840 
00841     /* BGP structure.  */
00842     struct bgp *bgp;
00843     
00844     /* BGP peer group.  */
00845     struct peer_group *group;
00846     u_char af_group[AFI_MAX][SAFI_MAX];
00847     
00848     /* Peer's remote AS number. */
00849     as_t as;                    
00850     
00851     /* Peer's local AS number. */
00852     as_t local_as;
00853     
00854     /* Peer's Change local AS number. */
00855     as_t change_local_as;
00856     
00857     /* Remote router ID. */
00858     struct in_addr remote_id;
00859     
00860     /* Local router ID. */
00861     struct in_addr local_id;
00862     
00863     /* Packet receive and send buffer. */
00864     struct stream *ibuf;
00865     struct stream_fifo *obuf;
00866     struct stream *work;
00867     
00868     /* Status of the peer. */
00869     int status;
00870     int ostatus;
00871     
00872     /* Peer information */
00873     TCP* listenAgent;                   /* File descriptor */
00874     int ttl;                    /* TTL of TCP connection to the peer. */
00875     char *desc;                 /* Description of the peer. */
00876     unsigned short port;          /* Destination port for peer */
00877     char *host;                 /* Printable address of the peer. */
00878     union sockunion su;         /* Sockunion address of the peer. */
00879     time_t uptime;              /* Last Up/Down time */
00880     time_t readtime;            /* Last read time */
00881     time_t resettime;           /* Last reset time */
00882     
00883     unsigned int ifindex;               /* ifindex of the BGP connection. */
00884     char *ifname;                       /* bind interface name. */
00885     char *update_if;
00886     union sockunion *update_source;
00887     struct zlog *log;
00888     u_char version;             /* Peer BGP version. */
00889     
00890     union sockunion *su_local;  /* Sockunion of local address.  */
00891     union sockunion *su_remote; /* Sockunion of remote address.  */
00892     int shared_network;         /* Is this peer shared same network. */
00893     struct bgp_nexthop nexthop; /* Nexthop */
00894     
00895     /* Peer address family configuration. */
00896     u_char afc[AFI_MAX][SAFI_MAX];
00897     u_char afc_nego[AFI_MAX][SAFI_MAX];
00898     u_char afc_adv[AFI_MAX][SAFI_MAX];
00899     u_char afc_recv[AFI_MAX][SAFI_MAX];
00900     
00901     /* Capability Flags.*/
00902     u_char cap;
00903 #define PEER_CAP_REFRESH_ADV                (1 << 0) /* refresh advertised */
00904 #define PEER_CAP_REFRESH_OLD_RCV            (1 << 1) /* refresh old received */
00905 #define PEER_CAP_REFRESH_NEW_RCV            (1 << 2) /* refresh rfc received */
00906 #define PEER_CAP_DYNAMIC_ADV                (1 << 3) /* dynamic advertised */
00907 #define PEER_CAP_DYNAMIC_RCV                (1 << 4) /* dynamic received */
00908 
00909     /* Capability Flags.*/
00910     u_int16_t af_cap[AFI_MAX][SAFI_MAX];
00911 #define PEER_CAP_ORF_PREFIX_SM_ADV          (1 << 0) /* send-mode advertised */
00912 #define PEER_CAP_ORF_PREFIX_RM_ADV          (1 << 1) /* receive-mode advertised */
00913 #define PEER_CAP_ORF_PREFIX_SM_RCV          (1 << 2) /* send-mode received */
00914 #define PEER_CAP_ORF_PREFIX_RM_RCV          (1 << 3) /* receive-mode received */
00915 #define PEER_CAP_ORF_PREFIX_SM_OLD_RCV      (1 << 4) /* send-mode received */
00916 #define PEER_CAP_ORF_PREFIX_RM_OLD_RCV      (1 << 5) /* receive-mode received */
00917 
00918     /* Global configuration flags. */
00919     u_int32_t flags;
00920 #define PEER_FLAG_PASSIVE                   (1 << 0) /* passive mode */
00921 #define PEER_FLAG_SHUTDOWN                  (1 << 1) /* shutdown */
00922 #define PEER_FLAG_DONT_CAPABILITY           (1 << 2) /* dont-capability */
00923 #define PEER_FLAG_OVERRIDE_CAPABILITY       (1 << 3) /* override-capability */
00924 #define PEER_FLAG_STRICT_CAP_MATCH          (1 << 4) /* strict-match */
00925 #define PEER_FLAG_NO_ROUTE_REFRESH_CAP      (1 << 5) /* route-refresh */
00926 #define PEER_FLAG_DYNAMIC_CAPABILITY        (1 << 6) /* dynamic capability */
00927 #define PEER_FLAG_ENFORCE_MULTIHOP          (1 << 7) /* enforce-multihop */
00928 #define PEER_FLAG_LOCAL_AS_NO_PREPEND       (1 << 8) /* local-as no-prepend */
00929 
00930     /* Per AF configuration flags. */
00931     u_int32_t af_flags[AFI_MAX][SAFI_MAX];
00932 #define PEER_FLAG_SEND_COMMUNITY            (1 << 0) /* send-community */
00933 #define PEER_FLAG_SEND_EXT_COMMUNITY        (1 << 1) /* send-community ext. */
00934 #define PEER_FLAG_NEXTHOP_SELF              (1 << 2) /* next-hop-self */
00935 #define PEER_FLAG_REFLECTOR_CLIENT          (1 << 3) /* reflector-client */
00936 #define PEER_FLAG_RSERVER_CLIENT            (1 << 4) /* route-server-client */
00937 #define PEER_FLAG_SOFT_RECONFIG             (1 << 5) /* soft-reconfiguration */
00938 #define PEER_FLAG_AS_PATH_UNCHANGED         (1 << 6) /* transparent-as */
00939 #define PEER_FLAG_NEXTHOP_UNCHANGED         (1 << 7) /* transparent-next-hop */
00940 #define PEER_FLAG_MED_UNCHANGED             (1 << 8) /* transparent-next-hop */
00941 #define PEER_FLAG_DEFAULT_ORIGINATE         (1 << 9) /* default-originate */
00942 #define PEER_FLAG_REMOVE_PRIVATE_AS         (1 << 10) /* remove-private-as */
00943 #define PEER_FLAG_ALLOWAS_IN                (1 << 11) /* set allowas-in */
00944 #define PEER_FLAG_ORF_PREFIX_SM             (1 << 12) /* orf capability send-mode */
00945 #define PEER_FLAG_ORF_PREFIX_RM             (1 << 13) /* orf capability receive-mode */
00946 #define PEER_FLAG_MAX_PREFIX                (1 << 14) /* maximum prefix */
00947 #define PEER_FLAG_MAX_PREFIX_WARNING        (1 << 15) /* maximum prefix warning-only */
00948 
00949     /* default-originate route-map.  */
00950         struct default_rmap default_rmap[AFI_MAX][SAFI_MAX];
00951     
00952     /* Peer status flags. */
00953     u_int16_t sflags;
00954 #define PEER_STATUS_ACCEPT_PEER       (1 << 0) /* accept peer */
00955 #define PEER_STATUS_PREFIX_OVERFLOW   (1 << 1) /* prefix-overflow */
00956 #define PEER_STATUS_CAPABILITY_OPEN   (1 << 2) /* capability open send */
00957 #define PEER_STATUS_HAVE_ACCEPT       (1 << 3) /* accept peer's parent */
00958 #define PEER_STATUS_GROUP             (1 << 4) /* peer-group conf */
00959 
00960     /* Peer status af flags. */
00961     u_int16_t af_sflags[AFI_MAX][SAFI_MAX];
00962 #define PEER_STATUS_ORF_PREFIX_SEND   (1 << 0) /* prefix-list send peer */
00963 #define PEER_STATUS_ORF_WAIT_REFRESH  (1 << 1) /* wait refresh received peer */
00964 #define PEER_STATUS_DEFAULT_ORIGINATE (1 << 2) /* default-originate peer */
00965 #define PEER_STATUS_PREFIX_THRESHOLD  (1 << 3) /* exceed prefix-threshold */
00966 #define PEER_STATUS_PREFIX_LIMIT      (1 << 4) /* exceed prefix-limit */
00967 
00968     /* Default attribute value for the peer. */
00969     u_int32_t config;
00970 #define PEER_CONFIG_WEIGHT            (1 << 0) /* Default weight. */
00971 #define PEER_CONFIG_TIMER             (1 << 1) /* keepalive & holdtime */
00972 #define PEER_CONFIG_CONNECT           (1 << 2) /* connect */
00973 #define PEER_CONFIG_ROUTEADV          (1 << 3) /* route advertise */
00974     u_int32_t weight;
00975     u_int32_t holdtime;
00976     u_int32_t keepalive;
00977     u_int32_t Connect;
00978     u_int32_t routeadv;
00979     
00980     /* Timer values. */
00981     u_int32_t v_start;
00982     u_int32_t v_connect;
00983     u_int32_t v_holdtime;
00984     u_int32_t v_keepalive;
00985     u_int32_t v_asorig;
00986     u_int32_t v_routeadv;
00987     
00988     /* Threads. */
00989     struct thread *t_read;
00990     struct thread *t_write;
00991     struct thread *t_start;
00992     struct thread *t_connect;
00993     struct thread *t_holdtime;
00994     struct thread *t_keepalive;
00995     struct thread *t_asorig;
00996 
00997         //pending timer pointer
00998         //used for per peer MRAI
00999     struct thread *t_routeadv;
01000     
01001     /* MRAI implementation*/
01002     
01003     // List of pending MRAI timers, for per prefix MRAI
01004     // there are more than one pending MRAI timers
01005     struct bgp_routeadv_list *t_routeadv_list;
01006     
01007     //per prefix list of last update timestamps
01008     Prefix2Timestamp_t  update_stamps;
01009     
01010     //List of supressed advertisements
01011     struct bgp_advertise *top_adv;
01012     
01013     /* Statistics field */
01014     u_int32_t open_in;          /* Open message input count */
01015     u_int32_t open_out;         /* Open message output count */
01016     u_int32_t update_in;                /* Update message input count */
01017     u_int32_t update_out;               /* Update message ouput count */
01018     Time_t update_time;         /* Update message received time. */
01019     u_int32_t keepalive_in;     /* Keepalive input count */
01020     u_int32_t keepalive_out;    /* Keepalive output count */
01021     u_int32_t notify_in;                /* Notify input count */
01022     u_int32_t notify_out;               /* Notify output count */
01023     u_int32_t refresh_in;               /* Route Refresh input count */
01024     u_int32_t refresh_out;      /* Route Refresh output count */
01025     u_int32_t dynamic_cap_in;   /* Dynamic Capability input count.  */
01026     u_int32_t dynamic_cap_out;  /* Dynamic Capability output count.  */
01027     
01028     /* BGP state count */
01029     u_int32_t established;      /* Established */
01030     u_int32_t dropped;          /* Dropped */
01031 
01032         /* Adj-RIBs-In.  */
01033         struct bgp_table *adj_in[AFI_MAX][SAFI_MAX];
01034         struct bgp_table *adj_out[AFI_MAX][SAFI_MAX];
01035 
01036     
01037     /* Syncronization list and time.  */
01038     struct bgp_synchronize *sync[AFI_MAX][SAFI_MAX];
01039     Time_t synctime;
01040 
01041     /* Send prefix count. */
01042     unsigned long scount[AFI_MAX][SAFI_MAX];
01043     
01044     /* Announcement attribute hash.  */
01045     struct hash *hash[AFI_MAX][SAFI_MAX];
01046 
01047         /* Linked peer configuration. */
01048         struct llist *conf;
01049     
01050     /* Notify data. */
01051     struct bgp_notify notify;
01052     
01053     /* Whole packet size to be read. */
01054     unsigned long packet_size;
01055     
01056     /* Filter structure. */
01057     struct bgp_filter filter[AFI_MAX][SAFI_MAX];
01058     
01059     /* ORF Prefix-list */
01060     struct prefix_list *orf_plist[AFI_MAX][SAFI_MAX];
01061     
01062     /* Prefix count. */
01063     unsigned long pcount[AFI_MAX][SAFI_MAX];
01064     
01065   /* Max prefix count. */
01066     unsigned long pmax[AFI_MAX][SAFI_MAX];
01067     u_char pmax_threshold[AFI_MAX][SAFI_MAX];
01068 #define MAXIMUM_PREFIX_THRESHOLD_DEFAULT 75
01069     
01070     /* allowas-in. */
01071     char allowas_in[AFI_MAX][SAFI_MAX];
01072     
01073     /* peer reset cause */
01074     char last_reset;
01075 #define PEER_DOWN_RID_CHANGE             1 /* bgp router-id command */
01076 #define PEER_DOWN_REMOTE_AS_CHANGE       2 /* neighbor remote-as command */
01077 #define PEER_DOWN_LOCAL_AS_CHANGE        3 /* neighbor local-as command */
01078 #define PEER_DOWN_CLID_CHANGE            4 /* bgp cluster-id command */
01079 #define PEER_DOWN_CONFED_ID_CHANGE       5 /* bgp confederation identifier command */
01080 #define PEER_DOWN_CONFED_PEER_CHANGE     6 /* bgp confederation peer command */
01081 #define PEER_DOWN_RR_CLIENT_CHANGE       7 /* neighbor route-reflector-client command */
01082 #define PEER_DOWN_RS_CLIENT_CHANGE       8 /* neighbor route-server-client command */
01083 #define PEER_DOWN_UPDATE_SOURCE_CHANGE   9 /* neighbor update-source command */
01084 #define PEER_DOWN_AF_ACTIVATE           10 /* neighbor activate command */
01085 #define PEER_DOWN_USER_SHUTDOWN         11 /* neighbor shutdown command */
01086 #define PEER_DOWN_USER_RESET            12 /* clear ip bgp command */
01087 #define PEER_DOWN_NOTIFY_RECEIVED       13 /* notification received */
01088 #define PEER_DOWN_NOTIFY_SEND           14 /* notification send */
01089 #define PEER_DOWN_CLOSE_SESSION         15 /* tcp session close */
01090 #define PEER_DOWN_NEIGHBOR_DELETE       16 /* neghbor delete */
01091 #define PEER_DOWN_RMAP_BIND             17 /* neghbor peer-group command */
01092 #define PEER_DOWN_RMAP_UNBIND           18 /* no neighbor peer-group command */
01093 #define PEER_DOWN_CAPABILITY_CHANGE     19 /* neighbor capability command */
01094 #define PEER_DOWN_PASSIVE_CHANGE        20 /* neighbor passive command */
01095 #define PEER_DOWN_MULTIHOP_CHANGE       21 /* neighbor multihop command */
01096 
01097   /* The kind of route-map Flags.*/
01098   u_char rmap_type;
01099 #define PEER_RMAP_TYPE_IN             (1 << 0) /* neighbor route-map in */
01100 #define PEER_RMAP_TYPE_OUT            (1 << 1) /* neighbor route-map out */
01101 #define PEER_RMAP_TYPE_NETWORK        (1 << 2) /* network route-map */
01102 #define PEER_RMAP_TYPE_REDISTRIBUTE   (1 << 3) /* redistribute route-map */
01103 #define PEER_RMAP_TYPE_DEFAULT        (1 << 4) /* default-originate route-map */
01104 #define PEER_RMAP_TYPE_NOSET          (1 << 5) /* not allow to set commands */
01105 };
01106 
01107 /* This structure's member directly points incoming packet data
01108    stream. */
01109 struct bgp_nlri
01110 {
01111   /* AFI.  */
01112   afi_t afi;
01113 
01114   /* SAFI.  */
01115   safi_t safi;
01116 
01117   /* Pointer to NLRI byte stream.  */
01118   u_char *nlri;
01119 
01120   /* Length of whole NLRI.  */
01121   bgp_size_t length;
01122 };
01123 
01124 /* BGP versions.  */
01125 #define BGP_VERSION_4                            4
01126 #define BGP_VERSION_MP_4_DRAFT_00               40
01127 
01128 /* Default BGP port number.  */
01129 #define BGP_PORT_DEFAULT                       179
01130 
01131 /* BGP message header and packet size.  */
01132 #define BGP_MARKER_SIZE                         16
01133 #define BGP_HEADER_SIZE                         19
01134 #define BGP_MAX_PACKET_SIZE                   4096
01135 
01136 /* BGP minimum message size.  */
01137 #define BGP_MSG_OPEN_MIN_SIZE                   (BGP_HEADER_SIZE + 10)
01138 #define BGP_MSG_UPDATE_MIN_SIZE                 (BGP_HEADER_SIZE + 4)
01139 #define BGP_MSG_NOTIFY_MIN_SIZE                 (BGP_HEADER_SIZE + 2)
01140 #define BGP_MSG_KEEPALIVE_MIN_SIZE              (BGP_HEADER_SIZE + 0)
01141 #define BGP_MSG_ROUTE_REFRESH_MIN_SIZE          (BGP_HEADER_SIZE + 4)
01142 #define BGP_MSG_CAPABILITY_MIN_SIZE             (BGP_HEADER_SIZE + 3)
01143 
01144 /* BGP message types.  */
01145 #define BGP_MSG_OPEN                             1
01146 #define BGP_MSG_UPDATE                           2
01147 #define BGP_MSG_NOTIFY                           3
01148 #define BGP_MSG_KEEPALIVE                        4
01149 #define BGP_MSG_ROUTE_REFRESH_NEW                5
01150 #define BGP_MSG_CAPABILITY                       6
01151 #define BGP_MSG_ROUTE_REFRESH_OLD              128
01152 
01153 /* BGP open optional parameter.  */
01154 #define BGP_OPEN_OPT_AUTH                        1
01155 #define BGP_OPEN_OPT_CAP                         2
01156 
01157 /* BGP4 attribute type codes.  */
01158 #define BGP_ATTR_ORIGIN                          1
01159 #define BGP_ATTR_AS_PATH                         2
01160 #define BGP_ATTR_NEXT_HOP                        3
01161 #define BGP_ATTR_MULTI_EXIT_DISC                 4
01162 #define BGP_ATTR_LOCAL_PREF                      5
01163 #define BGP_ATTR_ATOMIC_AGGREGATE                6
01164 #define BGP_ATTR_AGGREGATOR                      7
01165 #define BGP_ATTR_COMMUNITIES                     8
01166 #define BGP_ATTR_ORIGINATOR_ID                   9
01167 #define BGP_ATTR_CLUSTER_LIST                   10
01168 #define BGP_ATTR_DPA                            11
01169 #define BGP_ATTR_ADVERTISER                     12
01170 #define BGP_ATTR_RCID_PATH                      13
01171 #define BGP_ATTR_MP_REACH_NLRI                  14
01172 #define BGP_ATTR_MP_UNREACH_NLRI                15
01173 #define BGP_ATTR_EXT_COMMUNITIES                16
01174 
01175 /* BGP update origin.  */
01176 #define BGP_ORIGIN_IGP                           0
01177 #define BGP_ORIGIN_EGP                           1
01178 #define BGP_ORIGIN_INCOMPLETE                    2
01179 
01180 /* BGP notify message codes.  */
01181 #define BGP_NOTIFY_HEADER_ERR                    1
01182 #define BGP_NOTIFY_OPEN_ERR                      2
01183 #define BGP_NOTIFY_UPDATE_ERR                    3
01184 #define BGP_NOTIFY_HOLD_ERR                      4
01185 #define BGP_NOTIFY_FSM_ERR                       5
01186 #define BGP_NOTIFY_CEASE                         6
01187 #define BGP_NOTIFY_CAPABILITY_ERR                7
01188 #define BGP_NOTIFY_MAX                           8
01189 
01190 /* BGP_NOTIFY_HEADER_ERR sub codes.  */
01191 #define BGP_NOTIFY_HEADER_NOT_SYNC               1
01192 #define BGP_NOTIFY_HEADER_BAD_MESLEN             2
01193 #define BGP_NOTIFY_HEADER_BAD_MESTYPE            3
01194 #define BGP_NOTIFY_HEADER_MAX                    4
01195 
01196 /* BGP_NOTIFY_OPEN_ERR sub codes.  */
01197 #define BGP_NOTIFY_OPEN_UNSUP_VERSION            1
01198 #define BGP_NOTIFY_OPEN_BAD_PEER_AS              2
01199 #define BGP_NOTIFY_OPEN_BAD_BGP_IDENT            3
01200 #define BGP_NOTIFY_OPEN_UNSUP_PARAM              4
01201 #define BGP_NOTIFY_OPEN_AUTH_FAILURE             5
01202 #define BGP_NOTIFY_OPEN_UNACEP_HOLDTIME          6
01203 #define BGP_NOTIFY_OPEN_UNSUP_CAPBL              7
01204 #define BGP_NOTIFY_OPEN_MAX                      8
01205 
01206 /* BGP_NOTIFY_UPDATE_ERR sub codes.  */
01207 #define BGP_NOTIFY_UPDATE_MAL_ATTR               1
01208 #define BGP_NOTIFY_UPDATE_UNREC_ATTR             2
01209 #define BGP_NOTIFY_UPDATE_MISS_ATTR              3
01210 #define BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR          4
01211 #define BGP_NOTIFY_UPDATE_ATTR_LENG_ERR          5
01212 #define BGP_NOTIFY_UPDATE_INVAL_ORIGIN           6
01213 #define BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP          7
01214 #define BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP         8
01215 #define BGP_NOTIFY_UPDATE_OPT_ATTR_ERR           9
01216 #define BGP_NOTIFY_UPDATE_INVAL_NETWORK         10
01217 #define BGP_NOTIFY_UPDATE_MAL_AS_PATH           11
01218 #define BGP_NOTIFY_UPDATE_MAX                   12
01219 
01220 /* BGP_NOTIFY_CEASE sub codes (draft-ietf-idr-cease-subcode-03).  */
01221 #define BGP_NOTIFY_CEASE_MAX_PREFIX              1
01222 #define BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN          2
01223 #define BGP_NOTIFY_CEASE_PEER_UNCONFIG           3
01224 #define BGP_NOTIFY_CEASE_ADMIN_RESET             4
01225 #define BGP_NOTIFY_CEASE_CONNECT_REJECT          5
01226 #define BGP_NOTIFY_CEASE_CONFIG_CHANGE           6
01227 #define BGP_NOTIFY_CEASE_CONNECT_COLLISION       7
01228 #define BGP_NOTIFY_CEASE_MAX                     8
01229 
01230 /* BGP_NOTIFY_CAPABILITY_ERR sub codes (draft-ietf-idr-dynamic-cap-02). */
01231 #define BGP_NOTIFY_CAPABILITY_INVALID_ACTION     1
01232 #define BGP_NOTIFY_CAPABILITY_INVALID_LENGTH     2
01233 #define BGP_NOTIFY_CAPABILITY_MALFORMED_CODE     3
01234 #define BGP_NOTIFY_CAPABILITY_MAX                4
01235 
01236 /* BGP finite state machine status.  */
01237 #define Idle                                     1
01238 #define connect                                  2 /*Originally Connect, made connect to avoid name collision with TCP::Connect*/
01239 #define Active                                   3
01240 #define OpenSent                                 4
01241 #define OpenConfirm                              5
01242 #define Established                              6
01243 #define BGP_STATUS_MAX                           7
01244 
01245 /* BGP finite state machine events.  */
01246 #define BGP_Start                                1
01247 #define BGP_Stop                                 2
01248 #define TCP_connection_open                      3
01249 #define TCP_connection_closed                    4
01250 #define TCP_connection_open_failed               5
01251 #define TCP_fatal_error                          6
01252 #define ConnectRetry_timer_expired               7
01253 #define Hold_Timer_expired                       8
01254 #define KeepAlive_timer_expired                  9
01255 #define Receive_OPEN_message                    10
01256 #define Receive_KEEPALIVE_message               11
01257 #define Receive_UPDATE_message                  12
01258 #define Receive_NOTIFICATION_message            13
01259 #define BGP_EVENTS_MAX                          14
01260 
01261 /* BGP timers default value.  */
01262 #define BGP_INIT_START_TIMER                     5
01263 #define BGP_ERROR_START_TIMER                   30
01264 #define BGP_DEFAULT_HOLDTIME                   180
01265 #define BGP_DEFAULT_KEEPALIVE                   60 
01266 #define BGP_DEFAULT_ASORIGINATE                 15
01267 #define BGP_DEFAULT_EBGP_ROUTEADV               30
01268 #define BGP_DEFAULT_IBGP_ROUTEADV                5
01269 #define BGP_CLEAR_CONNECT_RETRY                 20
01270 #define BGP_DEFAULT_CONNECT_RETRY              120
01271 
01272 /* BGP default local preference.  */
01273 #define BGP_DEFAULT_LOCAL_PREF                 100
01274 
01275 /* SAFI which used in open capability negotiation.  */
01276 #define BGP_SAFI_VPNV4                         128
01277 #define BGP_SAFI_VPNV6                         129
01278 
01279 /* Max TTL value.  */
01280 #define TTL_MAX                                255
01281 
01282 /* BGP uptime string length.  */
01283 #define BGP_UPTIME_LEN 25
01284 
01285 /* Default configuration settings for bgpd.  */
01286 #define BGP_VTY_PORT                          2605
01287 #define BGP_VTYSH_PATH                "/tmp/.bgpd"
01288 #define BGP_DEFAULT_CONFIG             "bgpd.conf"
01289 
01290 /* Check AS path loop when we send NLRI.  */
01291 /* #define BGP_SEND_ASPATH_CHECK */
01292 
01293 /* IBGP/EBGP identifier.  We also have a CONFED peer, which is to say,
01294    a peer who's AS is part of our Confederation.  */
01295 enum
01296 {
01297   BGP_PEER_IBGP,
01298   BGP_PEER_EBGP,
01299   BGP_PEER_INTERNAL,
01300   BGP_PEER_CONFED
01301 };
01302 
01303 /* Flag for peer_clear_soft().  */
01304 enum bgp_clear_type
01305 {
01306   BGP_CLEAR_SOFT_NONE,
01307   BGP_CLEAR_SOFT_OUT,
01308   BGP_CLEAR_SOFT_IN,
01309   BGP_CLEAR_SOFT_BOTH,
01310   BGP_CLEAR_SOFT_IN_ORF_PREFIX
01311 };
01312 
01313 /* Macros. */
01314 #define BGP_INPUT(P)         ((P)->ibuf)
01315 #define BGP_INPUT_PNT(P)     (STREAM_PNT(BGP_INPUT(P)))
01316 
01317 /* Macro to check BGP information is alive or not.  */
01318 #define BGP_INFO_HOLDDOWN(BI)                         \
01319   (! CHECK_FLAG ((BI)->flags, BGP_INFO_VALID)         \
01320    || CHECK_FLAG ((BI)->flags, BGP_INFO_HISTORY)      \
01321    || CHECK_FLAG ((BI)->flags, BGP_INFO_DAMPED))
01322 
01323 /* Count prefix size from mask length */
01324 #define PSIZE(a) (((a) + 7) / (8))
01325 
01326 /* BGP error codes.  */
01327 #define BGP_SUCCESS                               0
01328 #define BGP_ERR_INVALID_VALUE                    -1
01329 #define BGP_ERR_INVALID_FLAG                     -2
01330 #define BGP_ERR_INVALID_AS                       -3
01331 #define BGP_ERR_INVALID_BGP                      -4
01332 #define BGP_ERR_PEER_GROUP_MEMBER                -5
01333 #define BGP_ERR_MULTIPLE_INSTANCE_USED           -6
01334 #define BGP_ERR_PEER_GROUP_MEMBER_EXISTS         -7
01335 #define BGP_ERR_PEER_BELONGS_TO_GROUP            -8
01336 #define BGP_ERR_PEER_GROUP_AF_UNCONFIGURED       -9
01337 #define BGP_ERR_PEER_GROUP_NO_REMOTE_AS         -10
01338 #define BGP_ERR_PEER_GROUP_CANT_CHANGE          -11
01339 #define BGP_ERR_PEER_GROUP_MISMATCH             -12
01340 #define BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT  -13
01341 #define BGP_ERR_MULTIPLE_INSTANCE_NOT_SET       -14
01342 #define BGP_ERR_AS_MISMATCH                     -15
01343 #define BGP_ERR_PEER_INACTIVE                   -16
01344 #define BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER   -17
01345 #define BGP_ERR_PEER_GROUP_HAS_THE_FLAG         -18
01346 #define BGP_ERR_PEER_FLAG_CONFLICT              -19
01347 #define BGP_ERR_PEER_GROUP_SHUTDOWN             -20
01348 #define BGP_ERR_PEER_FILTER_CONFLICT            -21
01349 #define BGP_ERR_NOT_INTERNAL_PEER               -22
01350 #define BGP_ERR_REMOVE_PRIVATE_AS               -23
01351 #define BGP_ERR_AF_UNCONFIGURED                 -24
01352 #define BGP_ERR_SOFT_RECONFIG_UNCONFIGURED      -25
01353 #define BGP_ERR_INSTANCE_MISMATCH               -26
01354 #define BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP  -27
01355 #define BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS    -28
01356 #define BGP_ERR_MAX                             -29
01357 
01358 /********bgpd.c*********/
01359 
01360 /* peer_flag_change_type. */
01361 enum peer_change_type
01362 {
01363   peer_change_none,
01364   peer_change_reset,
01365   peer_change_reset_in,
01366   peer_change_reset_out,
01367 };
01368 
01369 struct peer_flag_action
01370 {
01371   /* Peer's flag.  */
01372   u_int32_t flag;
01373 
01374   /* This flag can be set for peer-group member.  */
01375   u_char not_for_member;
01376 
01377   /* Action when the flag is changed.  */
01378   enum peer_change_type type;
01379 
01380   /* Peer down cause */
01381   u_char peer_down;
01382 };
01383 
01384 /**********bgp_aspath.c*************/
01385 
01386 /* Attr. Flags and Attr. Type Code. */
01387 #define AS_HEADER_SIZE        2  
01388 
01389 /* Two octet is used for AS value. */
01390 #define AS_VALUE_SIZE         sizeof (as_t)
01391 
01392 /* AS segment octet length. */
01393 #define ASSEGMENT_LEN(X)  ((X)->length * AS_VALUE_SIZE + AS_HEADER_SIZE)
01394 
01395 /* To fetch and store as segment value. */
01396 struct assegment
01397 {
01398   u_char type;
01399   u_char length;
01400   as_t asval[1];
01401 };
01402 
01403 enum as_token
01404   {
01405     as_token_asval,
01406     as_token_set_start,
01407     as_token_set_end,
01408     as_token_confed_start,
01409     as_token_confed_end,
01410     as_token_unknown
01411   };
01412 
01413 /*bgp_community.h*/
01414 
01415 /* Communities attribute.  */
01416 struct community 
01417 {
01418   /* Reference count of communities value.  */
01419   unsigned long refcnt;
01420 
01421   /* Communities value size.  */
01422   int size;
01423 
01424   /* Communities value.  */
01425   u_int32_t *val;
01426 
01427   /* String of community attribute.  This sring is used by vty output
01428      and expanded community-list for regular expression match.  */
01429   char *str;
01430 };
01431 
01432 /* Well-known communities value.  */
01433 #define COMMUNITY_INTERNET              0x0
01434 #define COMMUNITY_NO_EXPORT             0xFFFFFF01
01435 #define COMMUNITY_NO_ADVERTISE          0xFFFFFF02
01436 #define COMMUNITY_NO_EXPORT_SUBCONFED   0xFFFFFF03
01437 #define COMMUNITY_LOCAL_AS              0xFFFFFF03
01438 
01439 /* Macros of community attribute.  */
01440 #define com_length(X)    ((X)->size * 4)
01441 #define com_lastval(X)   ((X)->val + (X)->size - 1)
01442 #define com_nthval(X,n)  ((X)->val + (n))
01443 
01444 /*bgp_ecommunity.h*/
01445 
01446 /* High-order octet of the Extended Communities type field.  */
01447 #define ECOMMUNITY_ENCODE_AS                0x00
01448 #define ECOMMUNITY_ENCODE_IP                0x01
01449 
01450 /* Low-order octet of the Extended Communityes type field.  */
01451 #define ECOMMUNITY_ROUTE_TARGET             0x02
01452 #define ECOMMUNITY_SITE_ORIGIN              0x03
01453 
01454 /* Extended communities attribute string format.  */
01455 #define ECOMMUNITY_FORMAT_ROUTE_MAP            0
01456 #define ECOMMUNITY_FORMAT_COMMUNITY_LIST       1
01457 #define ECOMMUNITY_FORMAT_DISPLAY              2
01458 
01459 /* Extended Communities value is eight octet long.  */
01460 #define ECOMMUNITY_SIZE                        8
01461 
01462 /* Extended Communities attribute.  */
01463 struct ecommunity
01464 {
01465   /* Reference counter.  */
01466   unsigned long refcnt;
01467 
01468   /* Size of Extended Communities attribute.  */
01469   int size;
01470 
01471   /* Extended Communities value.  */
01472   u_char *val;
01473 
01474   /* Human readable format string.  */
01475   char *str;
01476 };
01477 
01478 /* Extended community value is eight octet.  */
01479 struct ecommunity_val
01480 {
01481   char val[ECOMMUNITY_SIZE];
01482 };
01483 
01484 #define ecom_length(X)    ((X)->size * ECOMMUNITY_SIZE)
01485 
01486 /*bgp_attr.h*/
01487 
01488 /* Simple bit mapping. */
01489 #define BITMAP_NBBY 8
01490 
01491 #define SET_BITMAP(MAP, NUM) \
01492         SET_FLAG (MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
01493 
01494 #define CHECK_BITMAP(MAP, NUM) \
01495         CHECK_FLAG (MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
01496 
01497 /* BGP Attribute type range. */
01498 #define BGP_ATTR_TYPE_RANGE     256
01499 #define BGP_ATTR_BITMAP_SIZE    (BGP_ATTR_TYPE_RANGE / BITMAP_NBBY)
01500 
01501 /* BGP Attribute flags. */
01502 #define BGP_ATTR_FLAG_OPTIONAL  0x80    /* Attribute is optional. */
01503 #define BGP_ATTR_FLAG_TRANS     0x40    /* Attribute is transitive. */
01504 #define BGP_ATTR_FLAG_PARTIAL   0x20    /* Attribute is partial. */
01505 #define BGP_ATTR_FLAG_EXTLEN    0x10    /* Extended length flag. */
01506 
01507 /* BGP attribute header must bigger than 2. */
01508 #define BGP_ATTR_MIN_LEN        2       /* Attribute flag and type. */
01509 
01510 /* BGP attribute structure. */
01511 struct attr
01512 {
01513   /* Reference count of this attribute. */
01514   unsigned long refcnt;
01515 
01516   /* Flag of attribute is set or not. */
01517   u_int32_t flag;
01518 
01519   /* Attributes. */
01520   u_char origin;
01521   struct in_addr nexthop;
01522   u_int32_t med;
01523   u_int32_t local_pref;
01524   as_t aggregator_as;
01525   struct in_addr aggregator_addr;
01526   u_int32_t weight;
01527   struct in_addr originator_id;
01528   struct cluster_list *cluster;
01529 
01530   u_char mp_nexthop_len;
01531 #ifdef HAVE_IPV6
01532   struct in6_addr mp_nexthop_global;
01533   struct in6_addr mp_nexthop_local;
01534 #endif /* HAVE_IPV6 */
01535   struct in_addr mp_nexthop_global_in;
01536   struct in_addr mp_nexthop_local_in;
01537 
01538   /* AS Path structure */
01539   struct aspath *aspath;
01540 
01541   /* Community structure */
01542   struct community *community;  
01543 
01544   /* Extended Communities attribute. */
01545   struct ecommunity *ecommunity;
01546 
01547   /* Unknown transitive attribute. */
01548   struct transit *transit;
01549 };
01550 
01551 #ifdef BGP_MRAI
01552 
01553 struct bgp_advertise {
01554   struct bgp_advertise *next;
01555   struct bgp_advertise *prev;
01556 
01557   struct peer_conf *conf;
01558   struct prefix *p;
01559   struct attr attribute;
01560   afi_t afi;
01561   safi_t safi;
01562   struct peer *from;
01563   struct prefix_rd *prd;
01564   u_char *tag;
01565 
01566   /* FIFO for advertisement.  */
01567   struct bgp_advertise_fifo fifo;
01568   /* Prefix information.  */
01569   struct bgp_node *rn;
01570   /* Reference pointer.  */
01571   struct bgp_adj_out *adj;
01572   /* Advertisement attribute.  */
01573   struct bgp_advertise_attr *baa;
01574   /* BGP info.  */
01575   struct bgp_info *binfo;
01576 
01577 };
01578 
01579 struct bgp_mrai_info {
01580   struct peer *peer;
01581   struct prefix *p;
01582   struct bgp_info *bi;
01583 };
01584 
01585 #else
01586 struct bgp_advertise
01587 {
01588   /* FIFO for advertisement.  */
01589   struct bgp_advertise_fifo fifo;
01590 
01591   /* Link list for same attribute advertise.  */
01592   struct bgp_advertise *next;
01593   struct bgp_advertise *prev;
01594 
01595   /* Prefix information.  */
01596   struct bgp_node *rn;
01597 
01598   /* Reference pointer.  */
01599   struct bgp_adj_out *adj;
01600 
01601   /* Advertisement attribute.  */
01602   struct bgp_advertise_attr *baa;
01603 
01604   /* BGP info.  */
01605   struct bgp_info *binfo;
01606 };
01607 #endif
01608 
01609 
01610 
01611 /* Router Reflector related structure. */
01612 struct cluster_list
01613 {
01614   unsigned long refcnt;
01615   int length;
01616   struct in_addr *list;
01617 };
01618 
01619 /* Unknown transit attribute. */
01620 struct transit
01621 {
01622   unsigned long refcnt;
01623   int length;
01624   u_char *val;
01625 };
01626 
01627 #define ATTR_FLAG_BIT(X)  (1 << ((X) - 1))
01628 
01629 
01630 /*bgp_clist.h*/
01631 
01632 /* Community-list deny and permit.  */
01633 #define COMMUNITY_DENY                 0
01634 #define COMMUNITY_PERMIT               1
01635 
01636 /* Number and string based community-list name.  */
01637 #define COMMUNITY_LIST_STRING          0
01638 #define COMMUNITY_LIST_NUMBER          1
01639 
01640 /* Community-list entry types.  */
01641 #define COMMUNITY_LIST_STANDARD        0 /* Standard community-list.  */
01642 #define COMMUNITY_LIST_EXPANDED        1 /* Expanded community-list.  */
01643 #define COMMUNITY_LIST_AUTO            2 /* Automatically detected.  */
01644 #define EXTCOMMUNITY_LIST_STANDARD     3 /* Standard extcommunity-list.  */
01645 #define EXTCOMMUNITY_LIST_EXPANDED     4 /* Expanded extcommunity-list.  */
01646 #define EXTCOMMUNITY_LIST_AUTO         5 /* Automatically detected.  */
01647 
01648 /* Community-list.  */
01649 struct community_list
01650 {
01651   /* Name of the community-list.  */
01652   char *name;
01653 
01654   /* String or number.  */
01655   int sort;
01656 
01657   /* Link to upper list.  */
01658   struct community_list_list *parent;
01659 
01660   /* Linked list for other community-list.  */
01661   struct community_list *next;
01662   struct community_list *prev;
01663 
01664   /* Community-list entry in this community-list.  */
01665   struct community_entry *head;
01666   struct community_entry *tail;
01667 };
01668 
01669 /* Each entry in community-list.  */
01670 struct community_entry
01671 {
01672   struct community_entry *next;
01673   struct community_entry *prev;
01674 
01675   /* Permit or deny.  */
01676   u_char direct;
01677 
01678   /* Standard or expanded.  */
01679   u_char style;
01680 
01681   /* Any match.  */
01682   u_char any;
01683 
01684   /* Community structure.  */
01685   union
01686   {
01687     struct community *com;
01688     struct ecommunity *ecom;
01689   } u;
01690 
01691   /* Configuration string.  */
01692   char *config;
01693 
01694   /* Expanded community-list regular expression.  */
01695   regex_t *reg;
01696 };
01697 
01698 /* Linked list of community-list.  */
01699 struct community_list_list
01700 {
01701   struct community_list *head;
01702   struct community_list *tail;
01703 };
01704 
01705 /* Master structure of community-list and extcommunity-list.  */
01706 struct community_list_master
01707 {
01708   struct community_list_list num;
01709   struct community_list_list str;
01710 };
01711 
01712 /* Community-list handler.  community_list_init() returns this
01713    structure as handler.  */
01714 struct community_list_handler
01715 {
01716   /* Community-list.  */
01717   struct community_list_master community_list;
01718 
01719   /* Exteded community-list.  */
01720   struct community_list_master extcommunity_list;
01721 };
01722 
01723 /* Error code of community-list.  */
01724 #define COMMUNITY_LIST_ERR_CANT_FIND_LIST        -1
01725 #define COMMUNITY_LIST_ERR_MALFORMED_VAL         -2
01726 #define COMMUNITY_LIST_ERR_STANDARD_CONFLICT     -3
01727 #define COMMUNITY_LIST_ERR_EXPANDED_CONFLICT     -4
01728 
01729 
01730 /*bgp_community.c*/
01731 /* Community token enum. */
01732 enum community_token
01733 {
01734   community_token_val,
01735   community_token_no_export,
01736   community_token_no_advertise,
01737   community_token_local_as,
01738   community_token_unknown
01739 };
01740 
01741 /*bgp_ecommunity.c*/
01742 /* Extended Communities token enum. */
01743 enum ecommunity_token
01744 {
01745   ecommunity_token_rt,
01746   ecommunity_token_soo,
01747   ecommunity_token_val,
01748   ecommunity_token_unknown
01749 };
01750 
01751 /*bgp_filter.h*/
01752 
01753 enum as_filter_type
01754 {
01755   AS_FILTER_DENY,
01756   AS_FILTER_PERMIT
01757 };
01758 
01759 /*bgp_filter.c*/
01760 
01761 enum as_list_type
01762 {
01763   ACCESS_TYPE_STRING,
01764   ACCESS_TYPE_NUMBER
01765 };
01766 
01767 
01768 /* List of AS filter list. */
01769 struct as_list_list
01770 {
01771   struct as_list *head;
01772   struct as_list *tail;
01773 };
01774 
01775 /* AS path filter master. */
01776 struct as_list_master
01777 {
01778   /* List of access_list which name is number. */
01779   struct as_list_list num;
01780 
01781   /* List of access_list which name is string. */
01782   struct as_list_list str;
01783 
01784   /* Hook function which is executed when new access_list is added. */
01785   void (BGP::*add_hook) ();
01786 
01787   /* Hook function which is executed when access_list is deleted. */
01788   void (BGP::*delete_hook) ();
01789 };
01790 
01791 /* Element of AS path filter. */
01792 struct as_filter
01793 {
01794   struct as_filter *next;
01795   struct as_filter *prev;
01796 
01797   enum as_filter_type type;
01798 
01799   regex_t *reg;
01800   char *reg_str;
01801 };
01802 
01803 /* AS path filter list. */
01804 struct as_list
01805 {
01806   char *name;
01807 
01808   enum as_list_type type;
01809 
01810   struct as_list *next;
01811   struct as_list *prev;
01812 
01813   struct as_filter *head;
01814   struct as_filter *tail;
01815 };
01816 /* ip as-path access-list 10 permit AS1. */
01817 
01818 /*bgp_open.h*/
01819 
01820 /* MP Capability information. */
01821 struct capability_mp
01822 {
01823   u_int16_t afi;
01824   u_char reserved;
01825   u_char safi;
01826 };
01827 
01828 /* BGP open message capability. */
01829 struct capability
01830 {
01831   u_char code;
01832   u_char length;
01833   struct capability_mp mpc;
01834 };
01835 
01836 /* Multiprotocol Extensions capabilities. */
01837 #define CAPABILITY_CODE_MP              1
01838 #define CAPABILITY_CODE_MP_LEN          4
01839 
01840 /* Route refresh capabilities. */
01841 #define CAPABILITY_CODE_REFRESH         2
01842 #define CAPABILITY_CODE_REFRESH_OLD   128
01843 #define CAPABILITY_CODE_REFRESH_LEN     0
01844 
01845 /* Cooperative Route Filtering Capability.  */
01846 #define CAPABILITY_CODE_ORF             3 
01847 #define CAPABILITY_CODE_ORF_OLD       130
01848 
01849 /* ORF Type.  */
01850 #define ORF_TYPE_PREFIX                64 
01851 #define ORF_TYPE_PREFIX_OLD           128
01852 
01853 /* ORF Mode.  */
01854 #define ORF_MODE_RECEIVE                1 
01855 #define ORF_MODE_SEND                   2 
01856 #define ORF_MODE_BOTH                   3 
01857 
01858 /* Dynamic capability.  */
01859 #define CAPABILITY_CODE_DYNAMIC        66
01860 #define CAPABILITY_CODE_DYNAMIC_LEN     0
01861 
01862 /* Capability Message Action.  */
01863 #define CAPABILITY_ACTION_SET           0
01864 #define CAPABILITY_ACTION_UNSET         1
01865 
01866 /********prefix.h**********/
01867 
01868 /* IPv4 and IPv6 unified prefix structure. */
01869 struct prefix
01870 {
01871   u_char family;
01872   u_char prefixlen;
01873   union 
01874   {
01875     u_char prefix;
01876     struct in_addr prefix4;
01877 #ifdef HAVE_IPV6
01878     struct in6_addr prefix6;
01879 #endif /* HAVE_IPV6 */
01880     struct 
01881     {
01882       struct in_addr id;
01883       struct in_addr adv_router;
01884     } lp;
01885     u_char val[8];
01886   } u __attribute__ ((aligned (8)));
01887 };
01888 
01889 /* IPv4 prefix structure. */
01890 struct prefix_ipv4
01891 {
01892   u_char family;
01893   u_char prefixlen;
01894   struct in_addr prefix __attribute__ ((aligned (8)));
01895 };
01896 
01897 /* IPv6 prefix structure. */
01898 #ifdef HAVE_IPV6
01899 struct prefix_ipv6
01900 {
01901   u_char family;
01902   u_char prefixlen;
01903   struct in6_addr prefix __attribute__ ((aligned (8)));
01904 };
01905 #endif /* HAVE_IPV6 */
01906 
01907 struct prefix_ls
01908 {
01909   u_char family;
01910   u_char prefixlen;
01911   struct in_addr id __attribute__ ((aligned (8)));
01912   struct in_addr adv_router;
01913 };
01914 
01915 /* Prefix for routing distinguisher. */
01916 struct prefix_rd
01917 {
01918   u_char family;
01919   u_char prefixlen;
01920   u_char val[8] __attribute__ ((aligned (8)));
01921 };
01922 
01923 #ifndef INET_ADDRSTRLEN
01924 #define INET_ADDRSTRLEN 16
01925 #endif /* INET_ADDRSTRLEN */
01926 
01927 #ifndef INET6_ADDRSTRLEN
01928 #define INET6_ADDRSTRLEN 46
01929 #endif /* INET6_ADDRSTRLEN */
01930 
01931 #ifndef INET6_BUFSIZ
01932 #define INET6_BUFSIZ 51
01933 #endif /* INET6_BUFSIZ */
01934 
01935 /* Max bit/byte length of IPv4 address. */
01936 #define IPV4_MAX_BYTELEN    4
01937 #define IPV4_MAX_BITLEN    32
01938 #define IPV4_MAX_PREFIXLEN 32
01939 #define IPV4_ADDR_CMP(D,S)   memcmp ((D), (S), IPV4_MAX_BYTELEN)
01940 #define IPV4_ADDR_SAME(D,S)  (memcmp ((D), (S), IPV4_MAX_BYTELEN) == 0)
01941 #define IPV4_ADDR_COPY(D,S)  memcpy ((D), (S), IPV4_MAX_BYTELEN)
01942 
01943 #define IPV4_NET0(a)    ((((u_int32_t) (a)) & 0xff000000) == 0x00000000)
01944 #define IPV4_NET127(a)  ((((u_int32_t) (a)) & 0xff000000) == 0x7f000000)
01945 
01946 /* Max bit/byte length of IPv6 address. */
01947 #define IPV6_MAX_BYTELEN    16
01948 #define IPV6_MAX_BITLEN    128
01949 #define IPV6_MAX_PREFIXLEN 128
01950 #define IPV6_ADDR_CMP(D,S)   memcmp ((D), (S), IPV6_MAX_BYTELEN)
01951 #define IPV6_ADDR_SAME(D,S)  (memcmp ((D), (S), IPV6_MAX_BYTELEN) == 0)
01952 #define IPV6_ADDR_COPY(D,S)  memcpy ((D), (S), IPV6_MAX_BYTELEN)
01953 
01954 /* Count prefix size from mask length */
01955 #define PSIZE(a) (((a) + 7) / (8))
01956 
01957 /* Prefix's family member. */
01958 #define PREFIX_FAMILY(p)  ((p)->family)
01959 
01960 /**********bgp_table.h***********/
01961 
01962 struct bgp_table
01963 {
01964   struct bgp_node *top;
01965 };
01966 
01967 struct bgp_node
01968 {
01969   struct prefix p;
01970 
01971   struct bgp_table *table;
01972   struct bgp_node *parent;
01973   struct bgp_node *link[2];
01974 #define l_left   link[0]
01975 #define l_right  link[1]
01976 
01977   unsigned int lock;
01978 
01979   void *info;
01980 
01981   struct bgp_adj_out *adj_out;
01982 
01983   struct bgp_adj_in *adj_in;
01984 
01985   void *aggregate;
01986 
01987   struct bgp_node *prn;
01988 };
01989 
01990 /********bgp_vty.c**********/
01991 
01992 /* BGP clear sort. */
01993 enum clear_sort
01994   {
01995     clear_all,
01996     clear_peer,
01997     clear_group,
01998     clear_external,
01999     clear_as
02000   };
02001 
02002 
02003 /* Show BGP peer's information. */
02004 enum show_type
02005   {
02006     show_all,
02007     show_peer
02008   };
02009 
02010 
02011 /**********bgp_damp.h************/
02012 /* Structure maintained on a per-route basis. */
02013 struct bgp_damp_info
02014 {
02015   /* Doubly linked list.  This information must be linked to
02016      reuse_list or no_reuse_list.  */
02017   struct bgp_damp_info *next;
02018   struct bgp_damp_info *prev;
02019 
02020   /* Figure-of-merit.  */
02021   unsigned int penalty;
02022 
02023   /* Number of flapping.  */
02024   int flap;
02025         
02026   /* First flap time  */
02027   time_t start_time;
02028  
02029   /* Last time penalty was updated.  */
02030   Time_t t_updated;
02031 
02032   /* Time of route start to be suppressed.  */
02033   Time_t suppress_time;
02034 
02035   /* Back reference to bgp_info. */
02036   struct bgp_info *binfo;
02037 
02038   /* Back reference to bgp_node. */
02039   struct bgp_node *rn;
02040 
02041   /* Current index in the reuse_list. */
02042   int index;
02043 
02044   /* Last time message type. */
02045   u_char lastrecord;
02046 
02047 #define BGP_RECORD_UPDATE       1
02048 #define BGP_RECORD_WITHDRAW     2
02049 
02050   afi_t afi;
02051   safi_t safi;
02052 };
02053 
02054 /* Specified parameter set configuration. */
02055 struct bgp_damp_config
02056 {
02057   /* Value over which routes suppressed.  */
02058   unsigned int suppress_value;
02059 
02060   /* Value below which suppressed routes reused.  */
02061   unsigned int reuse_limit;    
02062 
02063   /* Max time a route can be suppressed.  */
02064   unsigned int max_suppress_time;      
02065 
02066   /* Time during which accumulated penalty reduces by half.  */
02067   unsigned int half_life; 
02068 
02069   /* Non-configurable parameters but fixed at implementation time.
02070    * To change this values, init_bgp_damp() should be modified.
02071    */
02072   int tmax;               /* Max time previous instability retained */
02073   int reuse_list_size;          /* Number of reuse lists */
02074   int reuse_index_size;         /* Size of reuse index array */
02075 
02076   /* Non-configurable parameters.  Most of these are calculated from
02077    * the configurable parameters above.
02078    */
02079   unsigned int ceiling;         /* Max value a penalty can attain */
02080   int decay_rate_per_tick;      /* Calculated from half-life */
02081   int decay_array_size;         /* Calculated using config parameters */
02082   double scale_factor;
02083   int reuse_scale_factor; 
02084          
02085   /* Decay array per-set based. */ 
02086   double *decay_array;  
02087 
02088   /* Reuse index array per-set based. */ 
02089   int *reuse_index;
02090 
02091   /* Reuse list array per-set based. */  
02092   struct bgp_damp_info **reuse_list;
02093   int reuse_offset;
02094         
02095   /* All dampening information which is not on reuse list.  */
02096   struct bgp_damp_info *no_reuse_list;
02097 
02098   /* Reuse timer thread per-set base. */
02099   struct thread* t_reuse;
02100 };
02101 
02102 #define BGP_DAMP_NONE           0
02103 #define BGP_DAMP_USED           1
02104 #define BGP_DAMP_SUPPRESSED     2
02105 
02106 /* Time granularity for reuse lists */
02107 #define DELTA_REUSE               10
02108 
02109 /* Time granularity for decay arrays */
02110 #define DELTA_T                    5
02111 
02112 #define DEFAULT_PENALTY         1000
02113 
02114 #define DEFAULT_HALF_LIFE         15
02115 #define DEFAULT_REUSE            750
02116 #define DEFAULT_SUPPRESS        2000
02117 
02118 #define REUSE_LIST_SIZE          256
02119 #define REUSE_ARRAY_SIZE        1024
02120 
02121 
02122 /* Utility macro to add and delete BGP dampening information to no
02123    used list.  */
02124 #define BGP_DAMP_LIST_ADD(N,A)  BGP_INFO_ADD(N,A,no_reuse_list)
02125 #define BGP_DAMP_LIST_DEL(N,A)  BGP_INFO_DEL(N,A,no_reuse_list)
02126 
02127 #define BGP_UPTIME_LEN 25
02128 
02129 
02130 /**********bgp_debug.h***********/
02131 /* sort of packet direction */
02132 #define DUMP_ON        1
02133 #define DUMP_SEND      2
02134 #define DUMP_RECV      4
02135 
02136 /* for dump_update */
02137 #define DUMP_WITHDRAW  8
02138 #define DUMP_NLRI     16
02139 
02140 /* dump detail */
02141 #define DUMP_DETAIL   32
02142 
02143 
02144 #define NLRI     1
02145 #define WITHDRAW 2
02146 #define NO_OPT   3
02147 #define SEND     4
02148 #define RECV     5
02149 #define DETAIL   6
02150 
02151 #define BGP_DEBUG_FSM                 0x01
02152 #define BGP_DEBUG_EVENTS              0x01
02153 #define BGP_DEBUG_PACKET              0x01
02154 #define BGP_DEBUG_FILTER              0x01
02155 #define BGP_DEBUG_KEEPALIVE           0x01
02156 #define BGP_DEBUG_UPDATE_IN           0x01
02157 #define BGP_DEBUG_UPDATE_OUT          0x02
02158 #define BGP_DEBUG_NORMAL              0x01
02159 
02160 #define BGP_DEBUG_PACKET_SEND         0x01
02161 #define BGP_DEBUG_PACKET_SEND_DETAIL  0x02
02162 
02163 #define BGP_DEBUG_PACKET_RECV         0x01
02164 #define BGP_DEBUG_PACKET_RECV_DETAIL  0x02
02165 
02166 #define CONF_DEBUG_ON(a, b) (conf_bgp_debug_ ## a |= (BGP_DEBUG_ ## b))
02167 #define CONF_DEBUG_OFF(a, b)    (conf_bgp_debug_ ## a &= ~(BGP_DEBUG_ ## b))
02168 
02169 #define TERM_DEBUG_ON(a, b) (term_bgp_debug_ ## a |= (BGP_DEBUG_ ## b))
02170 #define TERM_DEBUG_OFF(a, b)    (term_bgp_debug_ ## a &= ~(BGP_DEBUG_ ## b))
02171 
02172 #define DEBUG_ON(a, b) \
02173     do { \
02174     CONF_DEBUG_ON(a, b); \
02175     TERM_DEBUG_ON(a, b); \
02176     } while (0)
02177 #define DEBUG_OFF(a, b) \
02178     do { \
02179     CONF_DEBUG_OFF(a, b); \
02180     TERM_DEBUG_OFF(a, b); \
02181     } while (0)
02182 
02183 #define BGP_DEBUG(a, b)     (term_bgp_debug_ ## a & BGP_DEBUG_ ## b)
02184 #define CONF_BGP_DEBUG(a, b)    (conf_bgp_debug_ ## a & BGP_DEBUG_ ## b)
02185 
02186 
02187 /*****bgp_dump.h******/
02188 
02189 #define MSG_PROTOCOL_BGP4MP  16
02190 /* subtype value */
02191 #define BGP4MP_STATE_CHANGE   0
02192 #define BGP4MP_MESSAGE        1
02193 #define BGP4MP_ENTRY          2
02194 #define BGP4MP_SNAPSHOT       3
02195 
02196 #define BGP_DUMP_HEADER_SIZE 12
02197 
02198 
02199 /*****bgp_dump.c*******/
02200 
02201 enum bgp_dump_type
02202 {
02203   BGP_DUMP_ALL,
02204   BGP_DUMP_UPDATES,
02205   BGP_DUMP_ROUTES
02206 };
02207 
02208 enum MRT_MSG_TYPES {
02209    MSG_NULL,
02210    MSG_START,                   /* sender is starting up */
02211    MSG_DIE,                     /* receiver should shut down */
02212    MSG_I_AM_DEAD,               /* sender is shutting down */
02213    MSG_PEER_DOWN,               /* sender's peer is down */
02214    MSG_PROTOCOL_BGP,            /* msg is a BGP packet */
02215    MSG_PROTOCOL_RIP,            /* msg is a RIP packet */
02216    MSG_PROTOCOL_IDRP,           /* msg is an IDRP packet */
02217    MSG_PROTOCOL_RIPNG,          /* msg is a RIPNG packet */
02218    MSG_PROTOCOL_BGP4PLUS,       /* msg is a BGP4+ packet */
02219    MSG_PROTOCOL_BGP4PLUS_01,    /* msg is a BGP4+ (draft 01) packet */
02220    MSG_PROTOCOL_OSPF,           /* msg is an OSPF packet */
02221    MSG_TABLE_DUMP               /* routing table dump */
02222 };
02223 
02224 struct bgp_dump
02225 {
02226   enum bgp_dump_type type;
02227 
02228   char *filename;
02229 
02230   FILE *fp;
02231 
02232   unsigned int interval;
02233 
02234   char *interval_str;
02235 
02236   struct thread *t_interval;
02237 };
02238 
02239 
02240 /******bgp_route.c******/
02241 #define BGP_SHOW_HEADER "   Network          Next Hop            Metric LocPrf Weight Path%s"
02242 #define BGP_SHOW_DAMP_HEADER "   Network          From             Reuse    Path%s"
02243 #define BGP_SHOW_FLAP_HEADER "   Network          From            Flaps Duration Reuse    Path%s"
02244 
02245 enum bgp_show_type
02246 {
02247   bgp_show_type_normal,
02248   bgp_show_type_regexp,
02249   bgp_show_type_prefix_list,
02250   bgp_show_type_filter_list,
02251   bgp_show_type_route_map,
02252   bgp_show_type_neighbor,
02253   bgp_show_type_cidr_only,
02254   bgp_show_type_prefix_longer,
02255   bgp_show_type_community_all,
02256   bgp_show_type_community,
02257   bgp_show_type_community_exact,
02258   bgp_show_type_community_list,
02259   bgp_show_type_community_list_exact,
02260   bgp_show_type_flap_statistics,
02261   bgp_show_type_flap_address,
02262   bgp_show_type_flap_prefix,
02263   bgp_show_type_flap_cidr_only,
02264   bgp_show_type_flap_regexp,
02265   bgp_show_type_flap_filter_list,
02266   bgp_show_type_flap_prefix_list,
02267   bgp_show_type_flap_prefix_longer,
02268   bgp_show_type_flap_route_map,
02269   bgp_show_type_flap_neighbor,
02270   bgp_show_type_dampend_paths,
02271   bgp_show_type_damp_neighbor
02272 };
02273 
02274 /*****bgp_route.h*****/
02275 
02276 struct bgp_info
02277 {
02278   /* For linked list. */
02279   struct bgp_info *next;
02280   struct bgp_info *prev;
02281 
02282   /* BGP route type.  This can be static, RIP, OSPF, BGP etc.  */
02283   u_char type;
02284 
02285   /* When above type is BGP.  This sub type specify BGP sub type
02286      information.  */
02287   u_char sub_type;
02288 #define BGP_ROUTE_NORMAL       0
02289 #define BGP_ROUTE_STATIC       1
02290 #define BGP_ROUTE_AGGREGATE    2
02291 #define BGP_ROUTE_REDISTRIBUTE 3 
02292 
02293   /* BGP information status.  */
02294   u_char flags;
02295 #define BGP_INFO_IGP_CHANGED    (1 << 0)
02296 #define BGP_INFO_DAMPED         (1 << 1)
02297 #define BGP_INFO_HISTORY        (1 << 2)
02298 #define BGP_INFO_SELECTED       (1 << 3)
02299 #define BGP_INFO_VALID          (1 << 4)
02300 #define BGP_INFO_ATTR_CHANGED   (1 << 5)
02301 #define BGP_INFO_DMED_CHECK     (1 << 6)
02302 #define BGP_INFO_DMED_SELECTED  (1 << 7)
02303 
02304   /* Peer structure.  */
02305   struct peer *peer;
02306 
02307   /* Attribute structure.  */
02308   struct attr *attr;
02309 
02310   /* This route is suppressed with aggregation.  */
02311   int suppress;
02312   
02313   /* Nexthop reachability check.  */
02314   u_int32_t igpmetric;
02315 
02316   /* Uptime.  */
02317   time_t uptime;
02318 
02319   /* Pointer to dampening structure.  */
02320   struct bgp_damp_info *damp_info;
02321 
02322   /* MPLS label.  */
02323   u_char tag[3];
02324 };
02325 
02326 /* BGP static route configuration. */
02327 struct bgp_static
02328 {
02329   /* Backdoor configuration.  */
02330   int backdoor;
02331 
02332   /* Import check status.  */
02333   u_char valid;
02334 
02335   /* IGP metric. */
02336   u_int32_t igpmetric;
02337 
02338   /* IGP nexthop. */
02339   struct in_addr igpnexthop;
02340 
02341   /* BGP redistribute route-map.  */
02342   struct
02343   {
02344     char *name;
02345     struct route_map *map;
02346   } rmap;
02347 
02348   /* MPLS label.  */
02349   u_char tag[3];
02350 };
02351 
02352 #define DISTRIBUTE_IN_NAME(F)   ((F)->dlist[FILTER_IN].name)
02353 #define DISTRIBUTE_IN(F)        ((F)->dlist[FILTER_IN].alist)
02354 #define DISTRIBUTE_OUT_NAME(F)  ((F)->dlist[FILTER_OUT].name)
02355 #define DISTRIBUTE_OUT(F)       ((F)->dlist[FILTER_OUT].alist)
02356 
02357 #define PREFIX_LIST_IN_NAME(F)  ((F)->plist[FILTER_IN].name)
02358 #define PREFIX_LIST_IN(F)       ((F)->plist[FILTER_IN].plist)
02359 #define PREFIX_LIST_OUT_NAME(F) ((F)->plist[FILTER_OUT].name)
02360 #define PREFIX_LIST_OUT(F)      ((F)->plist[FILTER_OUT].plist)
02361 
02362 #define FILTER_LIST_IN_NAME(F)  ((F)->aslist[FILTER_IN].name)
02363 #define FILTER_LIST_IN(F)       ((F)->aslist[FILTER_IN].aslist)
02364 #define FILTER_LIST_OUT_NAME(F) ((F)->aslist[FILTER_OUT].name)
02365 #define FILTER_LIST_OUT(F)      ((F)->aslist[FILTER_OUT].aslist)
02366 
02367 #define ROUTE_MAP_IN_NAME(F)    ((F)->map[FILTER_IN].name)
02368 #define ROUTE_MAP_IN(F)         ((F)->map[FILTER_IN].map)
02369 #define ROUTE_MAP_OUT_NAME(F)   ((F)->map[FILTER_OUT].name)
02370 #define ROUTE_MAP_OUT(F)        ((F)->map[FILTER_OUT].map)
02371 
02372 #define UNSUPPRESS_MAP_NAME(F)  ((F)->usmap.name)
02373 #define UNSUPPRESS_MAP(F)       ((F)->usmap.map)
02374 
02375 /*bgp_fsm.h*/
02376 
02377 /* Macro for BGP read, write and timer thread.  */
02378 #define BGP_READ_ON(T,F,V)   THREAD_READ_ON(master,T,F,peer,V)
02379 #define BGP_READ_OFF(X)      THREAD_READ_OFF(X)
02380 
02381 /* Macro for BGP write add */
02382 #define BGP_WRITE_ON(T,F) \
02383 do { \
02384   if (!(T)) \
02385     (T) = thread_add_ready (master, (F), peer); \
02386 } while (0)
02387 
02388 
02389 #define BGP_WRITE_OFF(X)     THREAD_WRITE_OFF(X)
02390 
02391 #define BGP_TIMER_ON(T,F,V)  THREAD_TIMER_ON(master,T,F,peer,V)
02392 #define BGP_TIMER_OFF(X)     THREAD_TIMER_OFF(X)
02393 
02394 #define BGP_EVENT_ADD(P,E) \
02395     thread_add_event (master, &BGP::bgp_event, (P), (E))
02396 
02397 #define BGP_EVENT_DELETE(P) \
02398     thread_cancel_event (master, (P))
02399 
02400 struct fsm_struct {
02401   int (BGP::*func) (struct peer*);
02402   int next_state;
02403 };
02404 
02405 
02406 /******bgp_packet.h******/
02407 #define BGP_NLRI_LENGTH       1
02408 #define BGP_TOTAL_ATTR_LEN    2
02409 #define BGP_UNFEASIBLE_LEN    2
02410 #define BGP_WRITE_PACKET_MAX 10
02411 
02412 /* When to refresh */
02413 #define REFRESH_IMMEDIATE 1
02414 #define REFRESH_DEFER     2 
02415 
02416 /* ORF Common part flag */
02417 #define ORF_COMMON_PART_ADD        0x00 
02418 #define ORF_COMMON_PART_REMOVE     0x80 
02419 #define ORF_COMMON_PART_REMOVE_ALL 0xC0 
02420 #define ORF_COMMON_PART_PERMIT     0x00 
02421 #define ORF_COMMON_PART_DENY       0x20 
02422 
02423 
02424 /******Zebra/lib**********/
02425 
02426 /*****buffer.h******/
02427 /* Buffer master. */
02428 struct buffer
02429 {
02430   /* Data list. */
02431   struct buffer_data *head;
02432   struct buffer_data *tail;
02433 
02434   /* Current allocated data. */
02435   unsigned long alloc;
02436 
02437   /* Total length of buffer. */
02438   unsigned long size;
02439 
02440   /* For allocation. */
02441   struct buffer_data *unused_head;
02442   struct buffer_data *unused_tail;
02443 
02444   /* Current total length of this buffer. */
02445   unsigned long length;
02446 };
02447 
02448 /* Data container. */
02449 struct buffer_data
02450 {
02451   struct buffer *parent;
02452   struct buffer_data *next;
02453   struct buffer_data *prev;
02454 
02455   /* Acctual data stream. */
02456   unsigned char *data;
02457 
02458   /* Current pointer. */
02459   unsigned long cp;
02460 
02461   /* Start pointer. */
02462   unsigned long sp;
02463 };
02464 
02465 /*command.c*/
02466 
02467 enum match_type 
02468 {
02469   no_match,
02470   extend_match,
02471   ipv4_prefix_match,
02472   ipv4_match,
02473   ipv6_prefix_match,
02474   ipv6_match,
02475   range_match,
02476   vararg_match,
02477   partly_match,
02478   exact_match 
02479 };
02480 
02481 /***** vty.h ********/
02482 
02483 #define VTY_BUFSIZ 512
02484 #define VTY_MAXHIST 20
02485 
02486 enum Type
02487 {
02488   VTY_TERM,
02489   VTY_FILE,
02490   VTY_SHELL,
02491   VTY_SHELL_SERV
02492 };
02493 
02494 enum Status
02495 { 
02496   VTY_NORMAL,
02497   VTY_CLOSE,
02498   VTY_MORE,
02499   VTY_MORELINE,
02500   VTY_START,
02501   VTY_CONTINUE
02502 };
02503 
02504 /* VTY struct. */
02505 struct vty 
02506 {
02507   /* File descripter of this vty. */
02508   int fd;
02509 
02510   /* Is this vty connect to file or not */
02511   Type type;
02512 
02513   /* Node status of this vty */
02514   int node;
02515 
02516   /* What address is this vty comming from. */
02517   char *address;
02518 
02519   /* Privilege level of this vty. */
02520   int privilege;
02521 
02522   /* Failure count */
02523   int fail;
02524 
02525   /* Output buffer. */
02526   struct buffer *obuf;
02527 
02528   /* Command input buffer */
02529   char *buf;
02530 
02531   /* Command cursor point */
02532   int cp;
02533 
02534   /* Command length */
02535   int length;
02536 
02537   /* Command max length. */
02538   int max;
02539 
02540   /* Histry of command */
02541   char *hist[VTY_MAXHIST];
02542 
02543   /* History lookup current point */
02544   int hp;
02545 
02546   /* History insert end point */
02547   int hindex;
02548 
02549   /* For current referencing point of interface, route-map,
02550      access-list etc... */
02551   void *index;
02552 
02553   /* For multiple level index treatment such as key chain and key. */
02554   void *index_sub;
02555 
02556   /* For escape character. */
02557   unsigned char escape;
02558 
02559   /* Current vty status. */
02560   Status status;
02561 
02562   /* IAC handling */
02563   unsigned char iac;
02564 
02565   /* IAC SB handling */
02566   unsigned char iac_sb_in_progress;
02567   struct buffer *sb_buffer;
02568 
02569   /* Window width/height. */
02570   int width;
02571   int height;
02572 
02573   int scroll_one;
02574 
02575   /* Configure lines. */
02576   int lines;
02577 
02578   /* Current executing function pointer. */
02579   int (BGP::*func) (struct vty *, void *arg);
02580 
02581   /* Terminal monitor. */
02582   int monitor;
02583 
02584   /* In configure mode. */
02585   int config;
02586 
02587   /* Read and write thread. */
02588   struct thread *t_read;
02589   struct thread *t_write;
02590 
02591   /* Timeout seconds and thread. */
02592   unsigned long v_timeout;
02593   struct thread *t_timeout;
02594 
02595   /* Thread output function. */
02596   struct thread *t_output;
02597 
02598   /* Output data pointer. */
02599   int (BGP::*output_func) (struct vty *, int);
02600   void (BGP::*output_clean) (struct vty *);
02601   void *output_rn;
02602   unsigned long output_count;
02603   int output_type;
02604   void *output_arg;
02605 };
02606 
02607 /* Integrated configuration file. */
02608 #define INTEGRATE_DEFAULT_CONFIG "Zebra.conf"
02609 
02610 /* Small macro to determine newline is newline only or linefeed needed. */
02611 #define VTY_NEWLINE  ("\n")
02612 
02613 /* Default time out value */
02614 #define VTY_TIMEOUT_DEFAULT 600
02615 
02616 /* Vty read buffer size. */
02617 #define VTY_READ_BUFSIZ 512
02618 
02619 /* Directory separator. */
02620 #ifndef DIRECTORY_SEP
02621 #define DIRECTORY_SEP '/'
02622 #endif /* DIRECTORY_SEP */
02623 
02624 #ifndef IS_DIRECTORY_SEP
02625 #define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP)
02626 #endif
02627 
02628 /* GCC have printf type attribute check.  */
02629 #ifdef __GNUC__
02630 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
02631 #else
02632 #define PRINTF_ATTRIBUTE(a,b)
02633 #endif /* __GNUC__ */
02634 
02635 /* Utility macro to convert VTY argument to unsigned integer.  */
02636 #define VTY_GET_INTEGER(NAME,V,STR)                              \
02637 {                                                                \
02638   char *endptr = NULL;                                           \
02639   (V) = strtoul ((STR), &endptr, 10);                            \
02640   if (*endptr != '\0')                                           \
02641     {                                                            \
02642       vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
02643       return CMD_WARNING;                                        \
02644     }                                                            \
02645 }
02646 
02647 #define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX)                \
02648 {                                                                \
02649   char *endptr = NULL;                                           \
02650   (V) = strtoul ((STR), &endptr, 10);                            \
02651   if (*endptr != '\0'                                            \
02652       || (V) < (MIN) || (V) > (MAX))                             \
02653     {                                                            \
02654       vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
02655       return CMD_WARNING;                                        \
02656     }                                                            \
02657 }
02658 
02659 
02660 /*command.h*/
02661 
02662 /* Host configuration variable */
02663 struct host
02664 {
02665   /* Host name of this router. */
02666   char *name;
02667 
02668   /* Password for vty interface. */
02669   char *password;
02670   char *password_encrypt;
02671 
02672   /* Enable password */
02673   char *enable;
02674   char *enable_encrypt;
02675 
02676   /* System wide terminal lines. */
02677   int lines;
02678 
02679   /* Log filename. */
02680   char *logfile;
02681 
02682   /* Log stdout. */
02683   u_char log_stdout;
02684 
02685   /* Log syslog. */
02686   u_char log_syslog;
02687   
02688   /* config file name of this host */
02689   char *config;
02690 
02691   /* Flags for services */
02692   int advanced;
02693   int encrypt;
02694 
02695   /* Banner configuration. */
02696   char *motd;
02697 };
02698 
02699 /* There are some command levels which called from command node. */
02700 enum node_type 
02701 {
02702   AUTH_NODE,                    /* Authentication mode of vty interface. */
02703   VIEW_NODE,                    /* View node. Default mode of vty interface. */
02704   AUTH_ENABLE_NODE,             /* Authentication mode for change enable. */
02705   ENABLE_NODE,                  /* Enable node. */
02706   CONFIG_NODE,                  /* Config node. Default mode of config file. */
02707   DEBUG_NODE,                   /* Debug node. */
02708   AAA_NODE,                     /* AAA node. */
02709   KEYCHAIN_NODE,                /* Key-chain node. */
02710   KEYCHAIN_KEY_NODE,            /* Key-chain key node. */
02711   INTERFACE_NODE,               /* Interface mode node. */
02712   ZEBRA_NODE,                   /* zebra connection node. */
02713   TABLE_NODE,                   /* rtm_table selection node. */
02714   RIP_NODE,                     /* RIP protocol mode node. */ 
02715   RIPNG_NODE,                   /* RIPng protocol mode node. */
02716   BGP_NODE,                     /* BGP protocol mode which includes BGP4+ */
02717   BGP_VPNV4_NODE,               /* BGP MPLS-VPN PE exchange. */
02718   BGP_IPV4_NODE,                /* BGP IPv4 unicast address family.  */
02719   BGP_IPV4M_NODE,               /* BGP IPv4 multicast address family.  */
02720   BGP_IPV6_NODE,                /* BGP IPv6 address family */
02721   OSPF_NODE,                    /* OSPF protocol mode */
02722   OSPF6_NODE,                   /* OSPF protocol for IPv6 mode */
02723   MASC_NODE,                    /* MASC for multicast.  */
02724   IRDP_NODE,                    /* ICMP Router Discovery Protocol mode. */ 
02725   IP_NODE,                      /* Static ip route node. */
02726   ACCESS_NODE,                  /* Access list node. */
02727   PREFIX_NODE,                  /* Prefix list node. */
02728   ACCESS_IPV6_NODE,             /* Access list node. */
02729   PREFIX_IPV6_NODE,             /* Prefix list node. */
02730   AS_LIST_NODE,                 /* AS list node. */
02731   COMMUNITY_LIST_NODE,          /* Community list node. */
02732   RMAP_NODE,                    /* Route map node. */
02733   SMUX_NODE,                    /* SNMP configuration node. */
02734   DUMP_NODE,                    /* Packet dump node. */
02735   FORWARDING_NODE,              /* IP forwarding node. */
02736   VTY_NODE                      /* Vty node. */
02737 };
02738 
02739 /* Node which has some commands and prompt string and configuration
02740    function pointer . */
02741 struct cmd_node 
02742 {
02743   /* Node index. */
02744   enum node_type node;          
02745 
02746   /* Prompt character at vty interface. */
02747   char *prompt;                 
02748 
02749   /* Is this node's configuration goes to vtysh ? */
02750   int vtysh;
02751   
02752   /* Node's configuration write function */
02753   int (BGP::*func) (struct vty *);
02754 
02755   /* Vector of this node's command list. */
02756   struct _vector* cmd_vector;   
02757 };
02758 
02759 /* Structure of command element. */
02760 struct cmd_element 
02761 {
02762   char *string;                 /* Command specification by string. */
02763   int (BGP::*func) (struct cmd_element *, struct vty *, int, char **);
02764   char *doc;                    /* Documentation of this command. */
02765   int daemon;                   /* Daemon to which this command belong. */
02766   struct _vector* strvec;               /* Pointing out each description vector. */
02767   unsigned int cmdsize;                 /* Command index count. */
02768   char *config;                 /* Configuration string */
02769   struct _vector* subconfig;            /* Sub configuration string */
02770 };
02771 
02772 /* Command description structure. */
02773 struct desc
02774 {
02775   char *cmd;                    /* Command string. */
02776   char *str;                    /* Command's description. */
02777 };
02778 
02779 /* Return value of the commands. */
02780 #define CMD_SUCCESS              0
02781 #define CMD_WARNING              1
02782 #define CMD_ERR_NO_MATCH         2
02783 #define CMD_ERR_AMBIGUOUS        3
02784 #define CMD_ERR_INCOMPLETE       4
02785 #define CMD_ERR_EXEED_ARGC_MAX   5
02786 #define CMD_ERR_NOTHING_TODO     6
02787 #define CMD_COMPLETE_FULL_MATCH  7
02788 #define CMD_COMPLETE_MATCH       8
02789 #define CMD_COMPLETE_LIST_MATCH  9
02790 #define CMD_SUCCESS_DAEMON      10
02791 
02792 /* Argc max counts. */
02793 #define CMD_ARGC_MAX   25
02794 
02795 /* Turn off these macros when uisng cpp with extract.pl */
02796 #ifndef VTYSH_EXTRACT_PL  
02797 
02798 /* DEFUN for vty command interafce. Little bit hacky ;-). */
02799 #define DEFUN(funcname, cmdname, cmdstr, helpstr) \
02800   int BGP::funcname \
02801         (struct cmd_element * self, struct vty *vty, int argc, char **argv)
02802 
02803 
02804 #define DEFUNST(funcname, cmdname, cmdstr, helpstr) \
02805   struct cmd_element BGP::cmdname = \
02806   { \
02807     cmdstr, \
02808     &BGP::funcname, \
02809     helpstr \
02810   };
02811 
02812 
02813 /* DEFUN_NOSH for commands that vtysh should ignore */
02814 #define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \
02815   DEFUN(funcname, cmdname, cmdstr, helpstr)\
02816   struct cmd_element BGP::cmdname = \
02817   { \
02818     cmdstr, \
02819     &BGP::funcname, \
02820     helpstr \
02821   }; \
02822   int funcname \
02823   (struct cmd_element *self, struct vty *vty, int argc, char **argv)
02824 
02825 /* DEFSH for vtysh. */
02826 #define DEFSH(daemon, cmdname, cmdstr, helpstr) \
02827   struct cmd_element cmdname = \
02828   { \
02829     cmdstr, \
02830     NULL, \
02831     helpstr, \
02832     daemon \
02833   }; \
02834 
02835 /* DEFUN + DEFSH */
02836 #define DEFUNSH(daemon, funcname, cmdname, cmdstr, helpstr) \
02837   int funcname (struct cmd_element *, struct vty *, int, char **); \
02838   struct cmd_element cmdname = \
02839   { \
02840     cmdstr, \
02841     funcname, \
02842     helpstr, \
02843     daemon \
02844   }; \
02845   int funcname \
02846   (struct cmd_element *self, struct vty *vty, int argc, char **argv)
02847 
02848 /* ALIAS macro which define existing command's alias. */
02849 #define ALIAS(funcname, cmdname, cmdstr, helpstr) \
02850   struct cmd_element BGP::cmdname = \
02851   { \
02852     cmdstr, \
02853     &BGP::funcname, \
02854     helpstr \
02855   };
02856 
02857 #endif /* VTYSH_EXTRACT_PL */
02858 
02859 /* Some macroes */
02860 #define CMD_OPTION(S)   ((S[0]) == '[')
02861 #define CMD_VARIABLE(S) (((S[0]) >= 'A' && (S[0]) <= 'Z') || ((S[0]) == '<'))
02862 #define CMD_VARARG(S)   ((S[0]) == '.')
02863 #define CMD_RANGE(S)    ((S[0] == '<'))
02864 
02865 #define CMD_IPV4(S)        ((strcmp ((S), "A.B.C.D") == 0))
02866 #define CMD_IPV4_PREFIX(S) ((strcmp ((S), "A.B.C.D/M") == 0))
02867 #define CMD_IPV6(S)        ((strcmp ((S), "X:X::X:X") == 0))
02868 #define CMD_IPV6_PREFIX(S) ((strcmp ((S), "X:X::X:X/M") == 0))
02869 
02870 /* Common descriptions. */
02871 #define SHOW_STR "Show running system information\n"
02872 #define IP_STR "IP information\n"
02873 #define IPV6_STR "IPv6 information\n"
02874 #define NO_STR "Negate a command or set its defaults\n"
02875 #define CLEAR_STR "Reset functions\n"
02876 #define RIP_STR "RIP information\n"
02877 #define BGP_STR "BGP information\n"
02878 #define OSPF_STR "OSPF information\n"
02879 #define NEIGHBOR_STR "Specify neighbor router\n"
02880 #define DEBUG_STR "Debugging functions (see also 'undebug')\n"
02881 #define UNDEBUG_STR "Disable debugging functions (see also 'debug')\n"
02882 #define ROUTER_STR "Enable a routing process\n"
02883 #define AS_STR "AS number\n"
02884 #define MBGP_STR "MBGP information\n"
02885 #define MATCH_STR "Match values from routing table\n"
02886 #define SET_STR "Set values in destination routing protocol\n"
02887 #define OUT_STR "Filter outgoing routing updates\n"
02888 #define IN_STR  "Filter incoming routing updates\n"
02889 #define V4NOTATION_STR "specify by IPv4 address notation(e.g. 0.0.0.0)\n"
02890 #define OSPF6_NUMBER_STR "Specify by number\n"
02891 #define INTERFACE_STR "Interface infomation\n"
02892 #define IFNAME_STR "Interface name(e.g. ep0)\n"
02893 #define IP6_STR "IPv6 Information\n"
02894 #define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n"
02895 #define OSPF6_ROUTER_STR "Enable a routing process\n"
02896 #define OSPF6_INSTANCE_STR "<1-65535> Instance ID\n"
02897 #define SECONDS_STR "<1-65535> Seconds\n"
02898 #define ROUTE_STR "Routing Table\n"
02899 #define PREFIX_LIST_STR "Build a prefix list\n"
02900 #define OSPF6_DUMP_TYPE_LIST \
02901 "(neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr)"
02902 
02903 #define CONF_BACKUP_EXT ".sav"
02904 
02905 /* IPv4 only machine should not accept IPv6 address for peer's IP
02906    address.  So we replace VTY command string like below. */
02907 #ifdef HAVE_IPV6
02908 #define NEIGHBOR_CMD       "neighbor (A.B.C.D|X:X::X:X) "
02909 #define NO_NEIGHBOR_CMD    "no neighbor (A.B.C.D|X:X::X:X) "
02910 #define NEIGHBOR_ADDR_STR  "Neighbor address\nIPv6 address\n"
02911 #define NEIGHBOR_CMD2      "neighbor (A.B.C.D|X:X::X:X|WORD) "
02912 #define NO_NEIGHBOR_CMD2   "no neighbor (A.B.C.D|X:X::X:X|WORD) "
02913 #define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor IPv6 address\nNeighbor tag\n"
02914 #else
02915 #define NEIGHBOR_CMD       "neighbor A.B.C.D "
02916 #define NO_NEIGHBOR_CMD    "no neighbor A.B.C.D "
02917 #define NEIGHBOR_ADDR_STR  "Neighbor address\n"
02918 #define NEIGHBOR_CMD2      "neighbor (A.B.C.D|WORD) "
02919 #define NO_NEIGHBOR_CMD2   "no neighbor (A.B.C.D|WORD) "
02920 #define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor tag\n"
02921 #endif /* HAVE_IPV6 */
02922 
02923 /*distribute.h*/
02924 /* Disctirubte list types. */
02925 enum distribute_type
02926 {
02927   DISTRIBUTE_IN,
02928   DISTRIBUTE_OUT,
02929   DISTRIBUTE_MAX
02930 };
02931 
02932 struct distribute
02933 {
02934   /* Name of the interface. */
02935   char *ifname;
02936 
02937   /* Filter name of `in' and `out' */
02938   char *list[DISTRIBUTE_MAX];
02939 
02940   /* prefix-list name of `in' and `out' */
02941   char *prefix[DISTRIBUTE_MAX];
02942 };
02943 
02944 
02945 /*filter.h*/
02946 
02947 enum filter_type 
02948 {
02949   FILTER_DENY,
02950   FILTER_PERMIT,
02951   FILTER_DYNAMIC
02952 };
02953 
02954 /*filter.c*/
02955 /* List of access_list. */
02956 struct access_list_list
02957 {
02958   struct access_list *head;
02959   struct access_list *tail;
02960 };
02961 
02962 /* Master structure of access_list. */
02963 struct access_master
02964 {
02965   /* List of access_list which name is number. */
02966   struct access_list_list num;
02967 
02968   /* List of access_list which name is string. */
02969   struct access_list_list str;
02970 
02971   /* Hook function which is executed when new access_list is added. */
02972   void (BGP::*add_hook) (struct access_list*);
02973 
02974   /* Hook function which is executed when access_list is deleted. */
02975   void (BGP::*delete_hook) (struct access_list*);
02976 };
02977 
02978 
02979 /*enum access_type
02980 {
02981   ACCESS_TYPE_STRING,
02982   ACCESS_TYPE_NUMBER
02983 };*/ 
02984 
02985 
02986 /* Access list */
02987 
02988 struct access_list
02989 {
02990   char *name;
02991   char *remark;
02992 
02993   struct access_master *master;
02994 
02995   as_list_type type;
02996 
02997   struct access_list *next;
02998   struct access_list *prev;
02999 
03000   struct filter *head;
03001   struct filter *tail;
03002 };
03003 
03004 /*hash.h*/
03005 
03006 
03007 /* Default hash table size.  */ 
03008 #define HASHTABSIZE     1024
03009 
03010 struct hash_backet
03011 {
03012   /* Linked list.  */
03013   struct hash_backet *next;
03014 
03015   /* Hash key. */
03016   unsigned int key;
03017 
03018   /* Data.  */
03019   void *data;
03020 };
03021 
03022 struct hash
03023 {
03024   /* Hash backet. */
03025   struct hash_backet **index;
03026 
03027   /* Hash table size. */
03028   unsigned int size;
03029 
03030   /* Key make function. */
03031   unsigned int (BGP::*hash_key) (void*);
03032 
03033   /* Data compare function. */
03034   int (BGP::*hash_cmp) (void*,void*);
03035 
03036   /* Backet alloc. */
03037   unsigned long count;
03038 };
03039 
03040 
03041 /*linklist.h*/
03042 
03043 #define nextnode(X) ((X) = (X)->next)
03044 #define listhead(X) ((X)->head)
03045 #define listcount(X) ((X)->count)
03046 #define list_isempty(X) ((X)->head == NULL && (X)->tail == NULL)
03047 #define getdata(X) ((X)->data)
03048 
03049 struct listnode 
03050 {
03051   struct listnode *next;
03052   struct listnode *prev;
03053   void *data;
03054 };
03055 
03056 struct llist 
03057 {
03058   struct listnode *head;
03059   struct listnode *tail;
03060   unsigned int count;
03061   int (BGP::*cmp) (void *val1, void *val2);
03062   void (BGP::*del) (void *val);
03063 };
03064 
03065 /* List iteration macro. */
03066 #define LIST_LOOP(L,V,N) \
03067   for ((N) = (L)->head; (N); (N) = (N)->next) \
03068     if (((V) = ((N)->data) != NULL)
03069 
03070 /* List node add macro.  */
03071 #define LISTNODE_ADD(L,N) \
03072   do { \
03073     (N)->prev = (L)->tail; \
03074     if ((L)->head == NULL) \
03075       (L)->head = (N); \
03076     else \
03077       (L)->tail->next = (N); \
03078     (L)->tail = (N); \
03079   } while (0)
03080 
03081 /* List node delete macro.  */
03082 #define LISTNODE_DELETE(L,N) \
03083   do { \
03084     if ((N)->prev) \
03085       (N)->prev->next = (N)->next; \
03086     else \
03087       (L)->head = (N)->next; \
03088     if ((N)->next) \
03089       (N)->next->prev = (N)->prev; \
03090     else \
03091       (L)->tail = (N)->prev; \
03092   } while (0)
03093 
03094 
03095 
03096 /*log.h*/
03097 
03098 #define ZLOG_NOLOG              0x00
03099 #define ZLOG_FILE               0x01
03100 #define ZLOG_SYSLOG             0x02
03101 #define ZLOG_STDOUT             0x04
03102 #define ZLOG_STDERR             0x08
03103 
03104 #define ZLOG_NOLOG_INDEX        0
03105 #define ZLOG_FILE_INDEX         1
03106 #define ZLOG_SYSLOG_INDEX       2
03107 #define ZLOG_STDOUT_INDEX       3
03108 #define ZLOG_STDERR_INDEX       4
03109 #define ZLOG_MAX_INDEX          5
03110 
03111 typedef enum 
03112 {
03113   ZLOG_NONE,
03114   ZLOG_DEFAULT,
03115   ZLOG_ZEBRA,
03116   ZLOG_RIP,
03117   ZLOG_BGP,
03118   ZLOG_OSPF,
03119   ZLOG_RIPNG,  
03120   ZLOG_OSPF6,
03121   ZLOG_MASC
03122 } zlog_proto_t;
03123 
03124 struct zlog 
03125 {
03126   const char *ident;
03127   zlog_proto_t protocol;
03128   int flags;
03129   FILE *fp;
03130   char *filename;
03131   int syslog;
03132   int stat;
03133   int connected;
03134   int maskpri;          /* as per syslog setlogmask */
03135   int priority;         /* as per syslog priority */
03136   int facility;         /* as per syslog facility */
03137   int record_priority;
03138 };
03139 
03140 /* Message structure. */
03141 struct message
03142 {
03143   int key;
03144   char *str;
03145 };
03146 
03147 /* For hackey massage lookup and check */
03148 #define LOOKUP(x, y) mes_lookup(x, x ## _max, y)
03149 
03150 
03152 /* #define MEMORY_LOG */
03153 
03154 /* For tagging memory, below is the type of the memory. */
03155 enum
03156 {
03157   MTYPE_TMP = 1,
03158   MTYPE_STRVEC,
03159   MTYPE_VECTOR,
03160   MTYPE_VECTOR_INDEX,
03161   MTYPE_LINK_LIST,
03162   MTYPE_LINK_NODE,
03163   MTYPE_THREAD,
03164   MTYPE_THREAD_MASTER,
03165   MTYPE_VTY,
03166   MTYPE_VTY_HIST,
03167   MTYPE_VTY_OUT_BUF,
03168   MTYPE_IF,
03169   MTYPE_CONNECTED,
03170   MTYPE_AS_SEG,
03171   MTYPE_AS_STR,
03172   MTYPE_AS_PATH,
03173   MTYPE_CLUSTER,
03174   MTYPE_CLUSTER_VAL,
03175   MTYPE_ATTR,
03176   MTYPE_TRANSIT,
03177   MTYPE_TRANSIT_VAL,
03178   MTYPE_BUFFER,
03179   MTYPE_BUFFER_DATA,
03180   MTYPE_STREAM,
03181   MTYPE_STREAM_DATA,
03182   MTYPE_STREAM_FIFO,
03183   MTYPE_PREFIX,
03184   MTYPE_PREFIX_IPV4,
03185   MTYPE_PREFIX_IPV6,
03186   MTYPE_HASH,
03187   MTYPE_HASH_INDEX,
03188   MTYPE_HASH_BACKET,
03189   MTYPE_RIPNG_ROUTE,
03190   MTYPE_RIPNG_AGGREGATE,
03191   MTYPE_ROUTE_TABLE,
03192   MTYPE_ROUTE_NODE,
03193   MTYPE_ACCESS_LIST,
03194   MTYPE_ACCESS_LIST_STR,
03195   MTYPE_ACCESS_FILTER,
03196   MTYPE_PREFIX_LIST,
03197   MTYPE_PREFIX_LIST_STR,
03198   MTYPE_PREFIX_LIST_ENTRY,
03199   MTYPE_ROUTE_MAP,
03200   MTYPE_ROUTE_MAP_NAME,
03201   MTYPE_ROUTE_MAP_INDEX,
03202   MTYPE_ROUTE_MAP_RULE,
03203   MTYPE_ROUTE_MAP_RULE_STR,
03204   MTYPE_ROUTE_MAP_COMPILED,
03205 
03206   MTYPE_RIB,
03207   MTYPE_DISTRIBUTE,
03208   MTYPE_ZLOG,
03209   MTYPE_ZCLIENT,
03210   MTYPE_NEXTHOP,
03211   MTYPE_RTADV_PREFIX,
03212   MTYPE_IF_RMAP,
03213   MTYPE_SOCKUNION,
03214   MTYPE_STATIC_IPV4,
03215   MTYPE_STATIC_IPV6,
03216 
03217   MTYPE_DESC,
03218   MTYPE_OSPF_TOP,
03219   MTYPE_OSPF_AREA,
03220   MTYPE_OSPF_AREA_RANGE,
03221   MTYPE_OSPF_NETWORK,
03222   MTYPE_OSPF_NEIGHBOR_STATIC,
03223   MTYPE_OSPF_IF,
03224   MTYPE_OSPF_NEIGHBOR,
03225   MTYPE_OSPF_ROUTE,
03226   MTYPE_OSPF_TMP,
03227   MTYPE_OSPF_LSA,
03228   MTYPE_OSPF_LSA_DATA,
03229   MTYPE_OSPF_LSDB,
03230   MTYPE_OSPF_PACKET,
03231   MTYPE_OSPF_FIFO,
03232   MTYPE_OSPF_VERTEX,
03233   MTYPE_OSPF_NEXTHOP,
03234   MTYPE_OSPF_PATH,
03235   MTYPE_OSPF_VL_DATA,
03236   MTYPE_OSPF_CRYPT_KEY,
03237   MTYPE_OSPF_EXTERNAL_INFO,
03238   MTYPE_OSPF_MESSAGE,
03239   MTYPE_OSPF_DISTANCE,
03240   MTYPE_OSPF_IF_INFO,
03241   MTYPE_OSPF_IF_PARAMS,
03242 
03243   MTYPE_OSPF6_TOP,
03244   MTYPE_OSPF6_AREA,
03245   MTYPE_OSPF6_IF,
03246   MTYPE_OSPF6_NEIGHBOR,
03247   MTYPE_OSPF6_ROUTE,
03248   MTYPE_OSPF6_PREFIX,
03249   MTYPE_OSPF6_MESSAGE,
03250   MTYPE_OSPF6_LSA,
03251   MTYPE_OSPF6_LSA_SUMMARY,
03252   MTYPE_OSPF6_LSDB,
03253   MTYPE_OSPF6_VERTEX,
03254   MTYPE_OSPF6_SPFTREE,
03255   MTYPE_OSPF6_NEXTHOP,
03256   MTYPE_OSPF6_EXTERNAL_INFO,
03257   MTYPE_OSPF6_OTHER,
03258 
03259   MTYPE_BGP,
03260   MTYPE_PEER_CONF,
03261   MTYPE_BGP_PEER,
03262   MTYPE_PEER_GROUP,
03263   MTYPE_PEER_DESC,
03264   MTYPE_PEER_UPDATE_SOURCE,
03265   MTYPE_BGP_STATIC,
03266   MTYPE_BGP_AGGREGATE,
03267   MTYPE_BGP_CONFED_LIST,
03268   MTYPE_BGP_NEXTHOP_CACHE,
03269   MTYPE_BGP_DAMP_INFO,
03270   MTYPE_BGP_DAMP_ARRAY,
03271   MTYPE_BGP_ANNOUNCE,
03272   MTYPE_BGP_ATTR_QUEUE,
03273   MTYPE_BGP_ROUTE_QUEUE,
03274   MTYPE_BGP_DISTANCE,
03275   MTYPE_BGP_ROUTE,
03276   MTYPE_BGP_TABLE,
03277   MTYPE_BGP_NODE,
03278   MTYPE_BGP_MRAI_INFO,
03279   MTYPE_BGP_ROUTEADV_LIST,
03280   MTYPE_BGP_ADVERTISE_ATTR,
03281   MTYPE_BGP_ADVERTISE,
03282   MTYPE_BGP_ADJ_IN,
03283   MTYPE_BGP_ADJ_OUT,
03284   MTYPE_BGP_REGEXP,
03285   MTYPE_AS_FILTER,
03286   MTYPE_AS_FILTER_STR,
03287   MTYPE_AS_LIST,
03288 
03289   MTYPE_COMMUNITY,
03290   MTYPE_COMMUNITY_VAL,
03291   MTYPE_COMMUNITY_STR,
03292 
03293   MTYPE_ECOMMUNITY,
03294   MTYPE_ECOMMUNITY_VAL,
03295   MTYPE_ECOMMUNITY_STR,
03296 
03297   /* community-list and extcommunity-list.  */
03298   MTYPE_COMMUNITY_LIST_HANDLER,
03299   MTYPE_COMMUNITY_LIST,
03300   MTYPE_COMMUNITY_LIST_NAME,
03301   MTYPE_COMMUNITY_LIST_ENTRY,
03302   MTYPE_COMMUNITY_LIST_CONFIG,
03303 
03304   MTYPE_RIP,
03305   MTYPE_RIP_INTERFACE,
03306   MTYPE_RIP_DISTANCE,
03307   MTYPE_RIP_OFFSET_LIST,
03308   MTYPE_RIP_INFO,
03309   MTYPE_RIP_PEER,
03310   MTYPE_KEYCHAIN,
03311   MTYPE_KEY,
03312 
03313   MTYPE_VTYSH_CONFIG,
03314   MTYPE_VTYSH_CONFIG_LINE,
03315 
03316   MTYPE_VRF,
03317   MTYPE_VRF_NAME,
03318 
03319   MTYPE_MAX
03320 };
03321 
03322 #ifdef MEMORY_LOG
03323 #define XMALLOC(mtype, size) \
03324   mtype_zmalloc (__FILE__, __LINE__, (mtype), (size))
03325 #define XCALLOC(mtype, size) \
03326   mtype_zcalloc (__FILE__, __LINE__, (mtype), (size))
03327 #define XREALLOC(mtype, ptr, size)  \
03328   mtype_zrealloc (__FILE__, __LINE__, (mtype), (ptr), (size))
03329 #define XFREE(mtype, ptr) \
03330   mtype_zfree (__FILE__, __LINE__, (mtype), (ptr))
03331 #define XSTRDUP(mtype, str) \
03332   mtype_zstrdup (__FILE__, __LINE__, (mtype), (str))
03333 #else
03334 #define XMALLOC(mtype, size)       zmalloc ((mtype), (size))
03335 #define XCALLOC(mtype, size)       zcalloc ((mtype), (size))
03336 #define XREALLOC(mtype, ptr, size) zrealloc ((mtype), (ptr), (size))
03337 #define XFREE(mtype, ptr)          zfree ((mtype), (ptr))
03338 #define XSTRDUP(mtype, str)        zstrdup ((mtype), (str))
03339 #endif /* MEMORY_LOG */
03340 
03343 /* For pretty printng of memory allocate information. */
03344 struct memory_list
03345 {
03346   int index;
03347   char *format;
03348 };
03349 
03350 /*plist.c*/
03351 
03352 /* List of struct prefix_list. */
03353 struct prefix_list_list
03354 {
03355   struct prefix_list *head;
03356   struct prefix_list *tail;
03357 };
03358 
03359 
03360 /* Master structure of prefix_list. */
03361 struct prefix_master
03362 {
03363   /* List of prefix_list which name is number. */
03364   struct prefix_list_list num;
03365 
03366   /* List of prefix_list which name is string. */
03367   struct prefix_list_list str;
03368 
03369   /* Whether sequential number is used. */
03370   int seqnum;
03371 
03372   /* The latest update. */
03373   struct prefix_list *recent;
03374 
03375   /* Hook function which is executed when new prefix_list is added. */
03376   void (BGP::*add_hook) ();
03377 
03378   /* Hook function which is executed when prefix_list is deleted. */
03379   void (BGP::*delete_hook) ();
03380 };
03381 
03382 
03383 enum display_type
03384 {
03385   normal_display,
03386   summary_display,
03387   detail_display,
03388   sequential_display,
03389   longer_display,
03390   first_match_display
03391 };
03392 
03393 /*plist.h*/
03394 
03395 #define AFI_ORF_PREFIX 65535
03396 
03397 enum prefix_list_type 
03398 {
03399   PREFIX_DENY,
03400   PREFIX_PERMIT,
03401 };
03402 
03403 enum prefix_name_type
03404 {
03405   PREFIX_TYPE_STRING,
03406   PREFIX_TYPE_NUMBER
03407 };
03408 
03409 struct prefix_list
03410 {
03411   char *name;
03412   char *desc;
03413 
03414   struct prefix_master *master;
03415 
03416   enum prefix_name_type type;
03417 
03418   int count;
03419   int rangecount;
03420 
03421   struct prefix_list_entry *head;
03422   struct prefix_list_entry *tail;
03423 
03424   struct prefix_list *next;
03425   struct prefix_list *prev;
03426 };
03427 
03428 struct orf_prefix
03429 {
03430   u_int32_t seq;
03431   u_char ge;
03432   u_char le;
03433   struct prefix p;
03434 };
03435 
03436 
03437 /*routemap.h*/
03438 
03439 /* Route map's type. */
03440 enum route_map_type
03441 {
03442   RMAP_PERMIT,
03443   RMAP_DENY,
03444   RMAP_ANY
03445 };
03446 
03447 typedef enum 
03448 {
03449   RMAP_MATCH,
03450   RMAP_DENYMATCH,
03451   RMAP_NOMATCH,
03452   RMAP_ERROR,
03453   RMAP_OKAY
03454 } route_map_result_t;
03455 
03456 typedef enum
03457 {
03458   RMAP_RIP,
03459   RMAP_RIPNG,
03460   RMAP_OSPF,
03461   RMAP_OSPF6,
03462   RMAP_BGP
03463 } route_map_object_t;
03464 
03465 typedef enum
03466 {
03467   RMAP_EXIT,
03468   RMAP_GOTO,
03469   RMAP_NEXT
03470 } route_map_end_t;
03471 
03472 typedef enum
03473 {
03474   RMAP_EVENT_SET_ADDED,
03475   RMAP_EVENT_SET_DELETED,
03476   RMAP_EVENT_SET_REPLACED,
03477   RMAP_EVENT_MATCH_ADDED,
03478   RMAP_EVENT_MATCH_DELETED,
03479   RMAP_EVENT_MATCH_REPLACED,
03480   RMAP_EVENT_INDEX_ADDED,
03481   RMAP_EVENT_INDEX_DELETED
03482 } route_map_event_t;
03483 
03484 
03485 /* Route map rule. This rule has both `match' rule and `set' rule. */
03486 struct route_map_rule
03487 {
03488   /* Rule type. */
03489   struct route_map_rule_cmd *cmd;
03490 
03491   /* For pretty printing. */
03492   char *rule_str;
03493 
03494   /* Pre-compiled match rule. */
03495   void *value;
03496 
03497   /* Linked list. */
03498   struct route_map_rule *next;
03499   struct route_map_rule *prev;
03500 };
03501 
03502 /* Making route map list. */
03503 struct route_map_list
03504 {
03505   struct route_map *head;
03506   struct route_map *tail;
03507 
03508   void (BGP::*add_hook) (char *);
03509   void (BGP::*delete_hook) (char *);
03510   void (BGP::*event_hook) (route_map_event_t, char *); 
03511 };
03512 /* Route map rule structure for matching and setting. */
03513 struct route_map_rule_cmd
03514 {
03515   /* Route map rule name (e.g. as-path, metric) */
03516   char *str;
03517 
03518   /* Function for value set or match. */
03519   route_map_result_t (BGP::*func_apply)(void *, struct prefix *, 
03520                                    route_map_object_t, void *);
03521 
03522   /* Compile argument and return result as void *. */
03523   void *(BGP::*func_compile)(char *);
03524 
03525   /* Free allocated value by func_compile (). */
03526   void (BGP::*func_free)(void *);
03527 };
03528 
03529 /* Route map apply error. */
03530 enum
03531 {
03532   /* Route map rule is missing. */
03533   RMAP_RULE_MISSING = 1,
03534 
03535   /* Route map rule can't compile */
03536   RMAP_COMPILE_ERROR
03537 };
03538 
03539 /* Route map rule list. */
03540 struct route_map_rule_list
03541 {
03542   struct route_map_rule *head;
03543   struct route_map_rule *tail;
03544 };
03545 
03546 /* Route map index structure. */
03547 struct route_map_index
03548 {
03549   struct route_map *mmap;
03550 
03551   /* Preference of this route map rule. */
03552   int pref;
03553 
03554   /* Route map type permit or deny. */
03555   enum route_map_type type;                     
03556 
03557   /* Do we follow old rules, or hop forward? */
03558   route_map_end_t exitpolicy;
03559 
03560   /* If we're using "GOTO", to where do we go? */
03561   int nextpref;
03562 
03563   /* Matching rule list. */
03564   struct route_map_rule_list match_list;
03565   struct route_map_rule_list set_list;
03566 
03567   /* Make linked list. */
03568   struct route_map_index *next;
03569   struct route_map_index *prev;
03570 };
03571 
03572 /* Route map list structure. */
03573 struct route_map
03574 {
03575   /* Name of route map. */
03576   char *name;
03577 
03578   /* Route map's rule. */
03579   struct route_map_index *head;
03580   struct route_map_index *tail;
03581 
03582   /* Make linked list. */
03583   struct route_map *next;
03584   struct route_map *prev;
03585 };
03586 
03587 /*stream.h*/
03588 
03589 /* Stream buffer. */
03590 struct stream
03591 {
03592   struct stream *next;
03593 
03594   unsigned char *data;
03595   
03596   /* Put pointer. */
03597   unsigned long putp;
03598 
03599   /* Get pointer. */
03600   unsigned long getp;
03601 
03602   /* End of pointer. */
03603   unsigned long endp;
03604 
03605   /* Data size. */
03606   unsigned long size;
03607 };
03608 
03609 /* First in first out queue structure. */
03610 struct stream_fifo
03611 {
03612   unsigned long count;
03613 
03614   struct stream *head;
03615   struct stream *tail;
03616 };
03617 
03618 /* Utility macros. */
03619 #define STREAM_PNT(S)   ((S)->data + (S)->getp)
03620 #define STREAM_SIZE(S)  ((S)->size)
03621 #define STREAM_REMAIN(S) ((S)->size - (S)->putp)
03622 #define STREAM_DATA(S)  ((S)->data)
03623 
03624 
03625 /***table.c****/
03626 
03627 /* Routing table top structure. */
03628 struct route_table
03629 {
03630   struct route_node *top;
03631 };
03632 
03633 /* Each routing entry. */
03634 struct route_node
03635 {
03636   /* Actual prefix of this radix. */
03637   struct prefix p;
03638 
03639   /* Tree link. */
03640   struct route_table *table;
03641   struct route_node *parent;
03642   struct route_node *link[2];
03643 #define l_left   link[0]
03644 #define l_right  link[1]
03645 
03646   /* Lock of this radix */
03647   unsigned int lock;
03648 
03649   /* Each node of route. */
03650   void *info;
03651 
03652   /* Aggregation. */
03653   void *aggregate;
03654 };
03655 
03656 
03657 /*****thread.c*****/
03658 
03659 #ifdef HAVE_RUSAGE
03660 #define RUSAGE_T        struct rusage
03661 #define GETRUSAGE(X)    getrusage (RUSAGE_SELF, X);
03662 #else
03663 #define RUSAGE_T        struct timeval
03664 #define GETRUSAGE(X)    gettimeofday (X, NULL);
03665 #endif /* HAVE_RUSAGE */
03666 
03667 /* Linked list of thread. */
03668 struct thread_list
03669 {
03670   struct thread *head;
03671   struct thread *tail;
03672   int count;
03673 };
03674 
03675 /* Master of the theads. */
03676 struct thread_master
03677 {
03678   struct thread_list read;
03679   struct thread_list write;
03680   struct thread_list timer;
03681   struct thread_list event;
03682   struct thread_list ready;
03683   struct thread_list unuse;
03684   fd_set readfd;
03685   fd_set writefd;
03686   fd_set exceptfd;
03687   unsigned long alloc;
03688 };
03689 
03690 /* Thread itself. */
03691 struct thread
03692 {
03693   unsigned char type;           /* thread type */
03694   struct thread *next;          /* next pointer of the thread */
03695   struct thread *prev;          /* previous pointer of the thread */
03696   struct thread_master *master; /* pointer to the struct thread_master. */
03697   int (BGP::*func) (struct thread *); /* event function */
03698   void *arg;                    /* event argument */
03699   union {
03700     int val;                    /* second argument of the event. */
03701     TCP *listenAgent;                   /* file descriptor in case of read/write. */
03702     time_t time;        /* rest of time sands value. */
03703   } u;
03704   RUSAGE_T ru;                  /* Indepth usage info.  */
03705 };
03706 
03707 /* Thread types. */
03708 #define THREAD_READ           0
03709 #define THREAD_WRITE          1
03710 #define THREAD_TIMER          2
03711 #define THREAD_EVENT          3
03712 #define THREAD_READY          4
03713 #define THREAD_UNUSED         5
03714 
03715 /* Thread yield time.  */
03716 #define THREAD_YIELD_TIME_SLOT     100 * 1000L /* 100ms */
03717 
03718 /* Macros. */
03719 #define THREAD_ARG(X) ((X)->arg)
03720 #define THREAD_FD(X)  ((X)->u.fd)
03721 #define THREAD_VAL(X) ((X)->u.val)
03722 
03723 #define THREAD_READ_ON(master,thread,func,arg,sock) \
03724   do { \
03725     if (! thread) \
03726       thread = thread_add_read (master, func, arg, sock); \
03727   } while (0)
03728 
03729 #define THREAD_WRITE_ON(master,thread,func,arg,sock) \
03730   do { \
03731     if (! thread) \
03732       thread = thread_add_write (master,func, arg, sock); \
03733   } while (0)
03734 
03735 #define THREAD_TIMER_ON(master,thread,func,arg,time) \
03736   do { \
03737     if (! thread) \
03738       thread = thread_add_timer (master,func, arg, time); \
03739   } while (0)
03740 
03741 #define THREAD_OFF(thread) \
03742   do { \
03743     if (thread) \
03744       { \
03745         thread_cancel (thread); \
03746         thread = NULL; \
03747       } \
03748   } while (0)
03749 
03750 #define THREAD_READ_OFF(thread)  THREAD_OFF(thread)
03751 #define THREAD_WRITE_OFF(thread)  THREAD_OFF(thread)
03752 #define THREAD_TIMER_OFF(thread)  THREAD_OFF(thread)
03753 
03754 
03755 /*****vector.h*******/
03756 /* struct for vector */
03757 struct _vector 
03758 {
03759   unsigned int max;             /* max number of used slot */
03760   unsigned int alloced;         /* number of allocated slot */
03761   void **index;                 /* index to data */
03762 };
03763 
03764 #define VECTOR_MIN_SIZE 1
03765 
03766 /* (Sometimes) usefull macros.  This macro convert index expression to
03767  array expression. */
03768 #define vector_slot(V,I)  ((V)->index[(I)])
03769 #define vector_max(V) ((V)->max)
03770 
03771 /*****vty.c*******/
03772 
03773 /* Vty events */
03774 enum event 
03775   {
03776     VTY_SERV,
03777     VTY_READ,
03778     VTY_WRITE,
03779     VTY_TIMEOUT_RESET,
03780 #ifdef VTYSH
03781     VTYSH_SERV,
03782     VTYSH_READ
03783 #endif /* VTYSH */
03784   };
03785 
03786 
03787 /* Timeout types */
03788 #define TYPE_MAIN    0
03789 #define TYPE_FETCH1  1
03790 #define TYPE_FETCH2  2
03791 #define TYPE_EXECUTE 3
03792 
03793 #define SET_TIMEOUT_TYPE_MAIN     type=TYPE_MAIN
03794 #define SET_TIMEOUT_TYPE_FETCH1   type=TYPE_FETCH1
03795 #define SET_TIMEOUT_TYPE_FETCH2   type=TYPE_FETCH2
03796 #define SET_TIMEOUT_TYPE_EXECUTE  type=TYPE_EXECUTE
03797 
03798 
03799 /*duplet that identifies an agent */
03800 struct agent_index {
03801   u_int32_t addr;
03802   u_int32_t port;
03803 };
03804 
03805 
03806 typedef vector<pair<IPAddr_t,BGP*> > IpBgp_t;
03807 typedef vector<pair<agent_index,pair<int,RMsgList_t> > >        Agent2MsgListMap_t ;
03808 typedef vector<pair<agent_index,union sockunion > >             Agent2Su_t ;
03809 typedef vector< pair < union sockunion ,BGP* > >                Su2BgpMap_t ;
03810 typedef pair<string,string>                                     IpAddrMaskPair_t;
03811 typedef list<IpAddrMaskPair_t>                                  InterfaceList_t; 
03812 typedef list<pair<string,InterfaceList_t > >                    String2List_t ;
03813 struct InterruptInfo
03814 {
03815   TCP *IntAgent;
03816   Data *intmsg;
03817 };
03818 
03819 #define BGP_VERSION 1.0
03820 
03821 /*extern "C"  void Qsort(void *base, size_t nmemb, size_t size,
03822                   int(*compar)(const void *, const void *))
03823         {
03824                 qsort(base,nmemb,size,compar);
03825         }
03826 */
03827 extern "C"
03828 {
03829   int community_compare(const void*,const void *);
03830   int cmp_node(const void*,const void*);
03831   int cmp_desc(const void*,const void*);
03832 }
03833 
03834 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
03835 #define EXTCOMMUNITY_VAL_STR  "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
03836 #define COMMUNITY_LIST_STR "Add a community list entry\n"
03837 #define COMMUNITY_VAL_STR  "Community number in aa:nn format or internet|local-AS|no-advertise|no-export\n"
03838 
03839 class MessageBuffer
03840 {
03841  public:
03842     MessageBuffer():ReceivedMsg(0),partialRead(false),dataAvailable(false)
03843         {}
03844     MessageBuffer(Data* data,bool partial, bool avl):ReceivedMsg(data),partialRead(partial),dataAvailable(avl)
03845     {}
03846     Data* ReceivedMsg;
03847     bool partialRead; // indicates if receivedmsg has partial data => need to append data
03848     bool dataAvailable; //indicates if data is available to read
03849 };
03850 
03851 typedef std::pair<TCP*,MessageBuffer*> TCPMsgBuf_pair;
03852 typedef std::map<TCP*,MessageBuffer*> TCPMsgBuf;
03853 
03854 class BGP : public Application {
03855 
03856   /*******************************************************************************
03857                             member functions added for BGP class
03858   ********************************************************************************/
03859  public:
03860   BGP(double);
03861   virtual Application* Copy() const;
03862   void bgp_main();      
03863   void timeout(Event *e);
03864   void AttachNode(Node*);
03865   void SetTrace(Trace::TraceStatus);
03866   void StartAt(double);
03867   void StopAt(double);
03868   void ConnectionComplete(L4Protocol *);
03869   void ServConnectionComplete(L4Protocol *);
03870   bool ConnectionFromPeer(L4Protocol*, IPAddr_t,PortId_t);
03871   void Receive(Packet *p,L4Protocol*,Seq_t);
03872   void Closed(L4Protocol*);
03873   void config_file(char*);
03874   int sendMessage(Data,struct peer*);
03875   virtual int command(int argc,const char** argv);
03876   void recv(int nbytes,TCP* from);
03877   void bgp_interrupt(BGP*,TCP*,Data*);
03878   BGP* findBgp(IPAddr_t);
03879   int bgp_accept(struct thread*);
03880  // bool bgp_accept(IPAddr_t *,TCP*);
03881   void dump_peer_list();
03882   // void bgp_randomize();
03883   void bgp_serv_sock_family();
03884   ~BGP(){
03885 
03886         //delete all the data alloced in the ctr?
03887     closezlog(zlog_default);
03888   };
03889 
03890   /**********************************************************************************
03891                                member variables for the class
03892   **********************************************************************************/
03893 
03894   Node* myNode;
03895   static bool enter_bgp_construct;         /*Flag turn on when first BGP instance enters constructor */
03896   static bool enter_bgp_main;              /*Flag turn on when first BGP instance enters main bgp_func */
03897   static int instance_cnt;                 /*# of BGP instances */
03898 
03899   static bool dont_reuse;                   /*Used to check the memory savings of the mem reusing scheme */
03900   static double last_update_time_;
03901   static FILE*  use_log_fp_;
03902   static char*  use_log_file_;
03903   char new_line[INET_ADDRSTRLEN + 3];   /* Hack, to append BGP identifier (ip addr string)
03904                        when one global file for logging is used*/
03905 
03906 
03907   
03908 #define NO_WORKLOAD_MODEL         0
03909 #define UNIFORM_WORKLOAD_MODEL     1
03910 #define TIME_SAMPLE_WORKLOAD_MODEL  2 
03911 
03912 #ifdef HAVE_PERFCTR
03913   double workload(struct perfctr_sum_ctrs *);
03914   static int perfcnt_init;
03915   static struct perfctr_info info;
03916 #else 
03917   double workload();
03918 #endif /* HAVE_PERFCTR */
03919 
03920   int workload_model;                  /* type of workload model */
03921   static double uniform_max;
03922   static double uniform_min;
03923   static bool default_randomize; 
03924   static Uniform*  rng;  /* uniform random number generator 
03925                                           used by uniform workload model*/
03926   static int rnd;                      /* rng initialization flag */
03927 
03928   static IpBgp_t IpBgp;
03929 
03930   BGPTimer* timer;                     /* timer used for BGP++ task scheduling */
03931   static time_t start_time ;           /* Global Start Time of Simulation  */
03932   int type ;                           /* type of timeout */
03933   bool debug_on;                        /* print debug information */           
03934   bool enable_routeadv;                /* enable per peer route adv rate limiting */  
03935   bool enable_routeadv_prefix;          /* enable per prefix route adv rate limiting */ 
03936 #define MRAI_DISABLE     0
03937 #define MRAI_PER_PEER    1 
03938 #define MRAI_PER_PREFIX  2
03939   int mrai_type;                       /* MRAI type    */  
03940   bool ssld;                           /* sender side loop detection on */
03941   double finish_time;                  /* finish time of simulation */
03942   struct thread *thread_to_be_fetched; /* holds the thread that is fetched 
03943                                           after the virtual select unblocks */
03944 #define MAX_CONFIG_LENGTH  512
03945 
03946   char bgp_config_file[MAX_CONFIG_LENGTH]; /* bgpd configuration file */
03947   TCP* ServAgent;                          /* Local listening tcp agent  */ 
03948   TCP* InterruptAgent ;                    /* Agent, analogous to file pointer, that cause  
03949                                               the most recently virtual select unblocking */
03950 
03951   TCPMsgBuf MsgBuffer; /* Each TCP Agent supported by BGP needs its own message buffer*/
03952   list<struct InterruptInfo> InterruptQueue ;  /* Queue were interrupts, i.e. msg arrivals,
03953                                               are temporary stored if the bgp daemon is busy when the 
03954                                               interrupt occurs; as soon as the bgpd finishes with 
03955                                               the work in progress, it checks the Interrupt queue, before 
03956                                               entering the virtual select()                                         
03957                                            */
03958   struct llist* dummy_peer_list;
03959 
03960 
03961 
03962   /************************************************************************************
03963                               static data members from zebra
03964   *************************************************************************************/
03965 
03966   /*aspath.c*/
03967  
03968   static struct as_list_master as_list_master;
03969 
03970 
03971   /*bgp_vty.c*/
03972 
03973   static struct cmd_node bgp_node;
03974   static struct cmd_node bgp_ipv4_unicast_node;
03975   static struct cmd_node bgp_ipv4_multicast_node;
03976   static struct cmd_node bgp_ipv6_unicast_node;
03977   static struct cmd_node bgp_vpnv4_node;
03978   static struct cmd_node community_list_node;
03979   /* These are found as DEFUNs in a lot of zebra .c files. Co-locating them here*/
03980   
03981   static struct cmd_element ip_community_list_cmd;
03982   static struct cmd_element no_ip_community_list_cmd;
03983   static struct cmd_element no_ip_community_list_all_cmd;
03984   static struct cmd_element no_ip_community_list_name_all_cmd;
03985   static struct cmd_element debug_bgp_fsm_cmd;
03986   static struct cmd_element no_debug_bgp_fsm_cmd;
03987   static struct cmd_element undebug_bgp_fsm_cmd;
03988   static struct cmd_element debug_bgp_events_cmd;
03989   static struct cmd_element no_debug_bgp_events_cmd;
03990   static struct cmd_element undebug_bgp_events_cmd;
03991   static struct cmd_element debug_bgp_filter_cmd;
03992   static struct cmd_element no_debug_bgp_filter_cmd;
03993   static struct cmd_element undebug_bgp_filter_cmd;
03994   static struct cmd_element debug_bgp_keepalive_cmd;
03995   static struct cmd_element no_debug_bgp_keepalive_cmd;
03996   static struct cmd_element undebug_bgp_keepalive_cmd;
03997   static struct cmd_element debug_bgp_update_cmd;
03998   static struct cmd_element debug_bgp_update_direct_cmd;
03999   static struct cmd_element no_debug_bgp_update_cmd;
04000   static struct cmd_element undebug_bgp_update_cmd;
04001   static struct cmd_element debug_bgp_normal_cmd;
04002   static struct cmd_element no_debug_bgp_normal_cmd;
04003   static struct cmd_element undebug_bgp_normal_cmd;
04004   static struct cmd_element no_debug_bgp_all_cmd;
04005   static struct cmd_element undebug_bgp_all_cmd;
04006   static struct cmd_element show_debugging_bgp_cmd;
04007   static struct cmd_element dump_bgp_all_cmd;
04008   static struct cmd_element dump_bgp_all_interval_cmd;
04009   static struct cmd_element no_dump_bgp_all_cmd;
04010   static struct cmd_element dump_bgp_updates_cmd;
04011   static struct cmd_element dump_bgp_updates_interval_cmd;
04012   static struct cmd_element no_dump_bgp_updates_cmd;
04013   static struct cmd_element dump_bgp_routes_interval_cmd;
04014   static struct cmd_element no_dump_bgp_routes_cmd;
04015   static struct cmd_element ip_as_path_cmd;
04016   static struct cmd_element no_ip_as_path_cmd;
04017   static struct cmd_element no_ip_as_path_all_cmd;
04018   static struct cmd_element bgp_network_cmd;
04019   static struct cmd_element bgp_network_mask_cmd;
04020   static struct cmd_element bgp_network_mask_natural_cmd;
04021   static struct cmd_element no_bgp_network_cmd;
04022   static struct cmd_element no_bgp_network_mask_cmd;
04023   static struct cmd_element no_bgp_network_mask_natural_cmd;
04024   static struct cmd_element aggregate_address_cmd;
04025   static struct cmd_element aggregate_address_mask_cmd;
04026   static struct cmd_element aggregate_address_summary_only_cmd;
04027   static struct cmd_element aggregate_address_mask_summary_only_cmd;
04028   static struct cmd_element aggregate_address_as_set_cmd;
04029   static struct cmd_element aggregate_address_mask_as_set_cmd;
04030   static struct cmd_element aggregate_address_as_set_summary_cmd;
04031   static struct cmd_element aggregate_address_summary_as_set_cmd;
04032   static struct cmd_element aggregate_address_mask_as_set_summary_cmd;
04033   static struct cmd_element aggregate_address_mask_summary_as_set_cmd;
04034   static struct cmd_element no_aggregate_address_cmd;
04035   static struct cmd_element no_aggregate_address_summary_only_cmd;
04036   static struct cmd_element no_aggregate_address_as_set_cmd;
04037   static struct cmd_element no_aggregate_address_as_set_summary_cmd;
04038   static struct cmd_element no_aggregate_address_summary_as_set_cmd;
04039   static struct cmd_element no_aggregate_address_mask_cmd;
04040   static struct cmd_element no_aggregate_address_mask_summary_only_cmd;
04041   static struct cmd_element no_aggregate_address_mask_as_set_cmd;
04042   static struct cmd_element no_aggregate_address_mask_as_set_summary_cmd;
04043   static struct cmd_element no_aggregate_address_mask_summary_as_set_cmd;
04044   static struct cmd_element show_ip_bgp_cmd;
04045   static struct cmd_element show_ip_bgp_route_cmd;
04046   static struct cmd_element show_ip_bgp_prefix_cmd;
04047   static struct cmd_element show_ip_bgp_regexp_cmd;
04048   static struct cmd_element show_ip_bgp_prefix_list_cmd;
04049   static struct cmd_element show_ip_bgp_filter_list_cmd;
04050   static struct cmd_element show_ip_bgp_cidr_only_cmd;
04051   static struct cmd_element show_ip_bgp_community_all_cmd;
04052   static struct cmd_element show_ip_bgp_community_cmd;
04053   static struct cmd_element show_ip_bgp_community2_cmd;
04054   static struct cmd_element show_ip_bgp_community3_cmd;
04055   static struct cmd_element show_ip_bgp_community4_cmd;
04056   static struct cmd_element show_ip_bgp_community_exact_cmd;
04057   static struct cmd_element show_ip_bgp_community2_exact_cmd;
04058   static struct cmd_element show_ip_bgp_community3_exact_cmd;
04059   static struct cmd_element show_ip_bgp_community4_exact_cmd;
04060   static struct cmd_element show_ip_bgp_community_list_cmd;
04061   static struct cmd_element show_ip_bgp_community_list_exact_cmd;
04062   static struct cmd_element show_ip_bgp_prefix_longer_cmd;
04063   static struct cmd_element show_ip_bgp_neighbor_advertised_route_cmd;
04064   static struct cmd_element show_ip_bgp_neighbor_received_routes_cmd;
04065   static struct cmd_element show_ip_bgp_neighbor_routes_cmd;
04066   static struct cmd_element bgp_distance_cmd;
04067   static struct cmd_element no_bgp_distance_cmd;
04068   static struct cmd_element no_bgp_distance2_cmd;
04069   static struct cmd_element bgp_distance_source_cmd;
04070   static struct cmd_element no_bgp_distance_source_cmd;
04071   static struct cmd_element bgp_distance_source_access_list_cmd;
04072   static struct cmd_element no_bgp_distance_source_access_list_cmd;
04073   static struct cmd_element bgp_damp_set_cmd;
04074   static struct cmd_element bgp_damp_set2_cmd;
04075   static struct cmd_element bgp_damp_set3_cmd;
04076   static struct cmd_element bgp_damp_unset_cmd;
04077   static struct cmd_element bgp_damp_unset2_cmd;
04078   static struct cmd_element match_ip_address_cmd;
04079   static struct cmd_element no_match_ip_address_cmd;
04080   static struct cmd_element no_match_ip_address_val_cmd;
04081   static struct cmd_element match_ip_next_hop_cmd;
04082   static struct cmd_element no_match_ip_next_hop_cmd;
04083   static struct cmd_element no_match_ip_next_hop_val_cmd;
04084   static struct cmd_element match_ip_address_prefix_list_cmd;
04085   static struct cmd_element no_match_ip_address_prefix_list_cmd;
04086   static struct cmd_element no_match_ip_address_prefix_list_val_cmd;
04087   static struct cmd_element match_ip_next_hop_prefix_list_cmd;
04088   static struct cmd_element no_match_ip_next_hop_prefix_list_cmd;
04089   static struct cmd_element no_match_ip_next_hop_prefix_list_val_cmd;
04090   static struct cmd_element match_metric_cmd;
04091   static struct cmd_element no_match_metric_cmd;
04092   static struct cmd_element no_match_metric_val_cmd;
04093   static struct cmd_element match_community_cmd;
04094   static struct cmd_element no_match_community_cmd;
04095   static struct cmd_element no_match_community_val_cmd;
04096   static struct cmd_element match_aspath_cmd;
04097   static struct cmd_element no_match_aspath_cmd;
04098   static struct cmd_element no_match_aspath_val_cmd;
04099   static struct cmd_element set_ip_nexthop_cmd;
04100   static struct cmd_element no_set_ip_nexthop_cmd;
04101   static struct cmd_element no_set_ip_nexthop_val_cmd;
04102   static struct cmd_element set_metric_cmd;
04103   static struct cmd_element no_set_metric_cmd;
04104   static struct cmd_element no_set_metric_val_cmd;
04105   static struct cmd_element set_local_pref_cmd;
04106   static struct cmd_element no_set_local_pref_cmd;
04107   static struct cmd_element no_set_local_pref_val_cmd;
04108   static struct cmd_element set_weight_cmd;
04109   static struct cmd_element no_set_weight_cmd;
04110   static struct cmd_element no_set_weight_val_cmd;
04111   static struct cmd_element set_aspath_prepend_cmd;
04112   static struct cmd_element no_set_aspath_prepend_cmd;
04113   static struct cmd_element no_set_aspath_prepend_val_cmd;
04114   static struct cmd_element set_community_cmd;
04115   static struct cmd_element set_community_none_cmd;
04116   static struct cmd_element no_set_community_cmd;
04117   static struct cmd_element no_set_community_val_cmd;
04118   static struct cmd_element no_set_community_none_cmd;
04119   static struct cmd_element set_community_additive_cmd;
04120   static struct cmd_element no_set_community_additive_cmd;
04121   static struct cmd_element no_set_community_additive_val_cmd;
04122   static struct cmd_element set_community_delete_cmd;
04123   static struct cmd_element no_set_community_delete_cmd;
04124   static struct cmd_element no_set_community_delete_val_cmd;
04125   static struct cmd_element set_ecommunity_rt_cmd;
04126   static struct cmd_element no_set_ecommunity_rt_cmd;
04127   static struct cmd_element no_set_ecommunity_rt_val_cmd;
04128   static struct cmd_element set_ecommunity_soo_cmd;
04129   static struct cmd_element no_set_ecommunity_soo_cmd;
04130   static struct cmd_element no_set_ecommunity_soo_val_cmd;
04131   static struct cmd_element set_origin_cmd;
04132   static struct cmd_element no_set_origin_cmd;
04133   static struct cmd_element no_set_origin_val_cmd;
04134   static struct cmd_element set_atomic_aggregate_cmd;
04135   static struct cmd_element no_set_atomic_aggregate_cmd;
04136   static struct cmd_element set_aggregator_as_cmd;
04137   static struct cmd_element no_set_aggregator_as_cmd;
04138   static struct cmd_element no_set_aggregator_as_val_cmd;
04139   static struct cmd_element set_originator_id_cmd;
04140   static struct cmd_element no_set_originator_id_cmd;
04141   static struct cmd_element no_set_originator_id_val_cmd;
04142   static struct cmd_element bgp_cluster_id_cmd;
04143   static struct cmd_element neighbor_transparent_nexthop_cmd;
04144   static struct cmd_element show_startup_config_cmd;
04145   static struct cmd_element config_log_file_cmd;
04146   static struct cmd_element no_config_log_file_cmd;
04147   static struct cmd_element access_list_cmd;
04148   static struct cmd_element access_list_exact_cmd;
04149   static struct cmd_element no_access_list_cmd;
04150   static struct cmd_element no_access_list_exact_cmd;
04151   static struct cmd_element no_access_list_all_cmd;
04152   static struct cmd_element access_list_remark_cmd;
04153   static struct cmd_element no_access_list_remark_cmd;
04154   static struct cmd_element no_access_list_remark_arg_cmd;
04155   static struct cmd_element show_memory_all_cmd;
04156   static struct cmd_element show_memory_cmd;
04157   static struct cmd_element show_memory_lib_cmd;
04158   static struct cmd_element show_memory_bgp_cmd;
04159   static struct cmd_element ip_prefix_list_cmd;
04160   static struct cmd_element ip_prefix_list_ge_cmd;
04161   static struct cmd_element ip_prefix_list_ge_le_cmd;
04162   static struct cmd_element ip_prefix_list_le_cmd;
04163   static struct cmd_element ip_prefix_list_le_ge_cmd;
04164   static struct cmd_element ip_prefix_list_seq_cmd;
04165   static struct cmd_element ip_prefix_list_seq_ge_cmd;
04166   static struct cmd_element ip_prefix_list_seq_ge_le_cmd;
04167   static struct cmd_element ip_prefix_list_seq_le_cmd;
04168   static struct cmd_element ip_prefix_list_seq_le_ge_cmd;
04169   static struct cmd_element no_ip_prefix_list_cmd;
04170   static struct cmd_element no_ip_prefix_list_prefix_cmd;
04171   static struct cmd_element no_ip_prefix_list_ge_cmd;
04172   static struct cmd_element no_ip_prefix_list_ge_le_cmd;
04173   static struct cmd_element no_ip_prefix_list_le_cmd;
04174   static struct cmd_element no_ip_prefix_list_le_ge_cmd;
04175   static struct cmd_element no_ip_prefix_list_seq_cmd;
04176   static struct cmd_element no_ip_prefix_list_seq_ge_cmd;
04177   static struct cmd_element no_ip_prefix_list_seq_ge_le_cmd;
04178   static struct cmd_element no_ip_prefix_list_seq_le_cmd;
04179   static struct cmd_element no_ip_prefix_list_seq_le_ge_cmd;
04180   static struct cmd_element ip_prefix_list_sequence_number_cmd;
04181   static struct cmd_element no_ip_prefix_list_sequence_number_cmd;
04182   static struct cmd_element ip_prefix_list_description_cmd;
04183   static struct cmd_element no_ip_prefix_list_description_cmd;
04184   static struct cmd_element no_ip_prefix_list_description_arg_cmd;
04185   static struct cmd_element show_ip_prefix_list_cmd;
04186   static struct cmd_element show_ip_prefix_list_name_cmd;
04187   static struct cmd_element show_ip_prefix_list_name_seq_cmd;
04188   static struct cmd_element show_ip_prefix_list_prefix_cmd;
04189   static struct cmd_element show_ip_prefix_list_prefix_longer_cmd;
04190   static struct cmd_element show_ip_prefix_list_prefix_first_match_cmd;
04191   static struct cmd_element show_ip_prefix_list_summary_cmd;
04192   static struct cmd_element show_ip_prefix_list_summary_name_cmd;
04193   static struct cmd_element show_ip_prefix_list_detail_cmd;
04194   static struct cmd_element show_ip_prefix_list_detail_name_cmd;
04195   static struct cmd_element clear_ip_prefix_list_cmd;
04196   static struct cmd_element clear_ip_prefix_list_name_cmd;
04197   static struct cmd_element clear_ip_prefix_list_name_prefix_cmd;
04198   static struct cmd_element route_map_cmd;
04199   static struct cmd_element no_route_map_all_cmd;
04200   static struct cmd_element no_route_map_cmd;
04201   static struct cmd_element rmap_onmatch_next_cmd;
04202   static struct cmd_element no_rmap_onmatch_next_cmd;
04203   static struct cmd_element rmap_onmatch_goto_cmd;
04204   static struct cmd_element no_rmap_onmatch_goto_cmd;
04205   static struct cmd_element bgp_network_route_map_cmd;
04206   static struct cmd_element bgp_network_mask_route_map_cmd;
04207   static struct cmd_element bgp_network_mask_natural_route_map_cmd;
04208   static struct cmd_element bgp_network_backdoor_cmd;
04209   static struct cmd_element bgp_network_mask_backdoor_cmd;
04210   static struct cmd_element bgp_network_mask_natural_backdoor_cmd;
04211   static struct cmd_element show_ip_bgp_ipv4_cmd;
04212   static struct cmd_element show_ip_bgp_ipv4_route_cmd;
04213   static struct cmd_element show_ip_bgp_vpnv4_all_route_cmd;
04214   //static struct cmd_element show_ip_bgp_vpnv4_rd_route_cmd;
04215   static struct cmd_element show_ip_bgp_ipv4_prefix_cmd;
04216   static struct cmd_element show_ip_bgp_vpnv4_all_prefix_cmd;
04217   //static struct cmd_element show_ip_bgp_vpnv4_rd_prefix_cmd;
04218   static struct cmd_element show_ip_bgp_view_cmd;
04219   static struct cmd_element show_ip_bgp_view_route_cmd;
04220   static struct cmd_element show_ip_bgp_view_prefix_cmd;
04221   static struct cmd_element show_ip_bgp_ipv4_regexp_cmd;
04222   static struct cmd_element show_ip_bgp_ipv4_prefix_list_cmd;
04223   static struct cmd_element show_ip_bgp_ipv4_filter_list_cmd;
04224   static struct cmd_element show_ip_bgp_route_map_cmd;
04225   static struct cmd_element show_ip_bgp_ipv4_route_map_cmd;
04226   static struct cmd_element show_ip_bgp_ipv4_cidr_only_cmd;
04227   static struct cmd_element show_ip_bgp_ipv4_community_all_cmd;
04228   static struct cmd_element show_ip_bgp_ipv4_community_cmd;
04229   static struct cmd_element show_ip_bgp_ipv4_community_exact_cmd;
04230   static struct cmd_element show_ip_bgp_ipv4_community_list_cmd;
04231   static struct cmd_element show_ip_bgp_ipv4_community_list_exact_cmd;
04232   static struct cmd_element show_ip_bgp_ipv4_prefix_longer_cmd;
04233   static struct cmd_element show_ip_bgp_ipv4_neighbor_advertised_route_cmd;
04234   static struct cmd_element show_ip_bgp_ipv4_neighbor_received_routes_cmd;
04235   static struct cmd_element show_ip_bgp_ipv4_neighbor_routes_cmd;
04236   static struct cmd_element show_ip_bgp_neighbor_received_prefix_filter_cmd;
04237   static struct cmd_element show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd;
04238   static struct cmd_element show_ip_bgp_dampened_paths_cmd;
04239   static struct cmd_element show_ip_bgp_flap_statistics_cmd;
04240   static struct cmd_element show_ip_bgp_flap_address_cmd;
04241   static struct cmd_element show_ip_bgp_flap_prefix_cmd;
04242   static struct cmd_element show_ip_bgp_flap_cidr_only_cmd;
04243   static struct cmd_element show_ip_bgp_flap_regexp_cmd;
04244   static struct cmd_element show_ip_bgp_flap_filter_list_cmd;
04245   static struct cmd_element show_ip_bgp_flap_prefix_list_cmd;
04246   static struct cmd_element show_ip_bgp_flap_prefix_longer_cmd;
04247   static struct cmd_element show_ip_bgp_flap_route_map_cmd;
04248   static struct cmd_element show_ip_bgp_neighbor_flap_cmd;
04249   static struct cmd_element show_ip_bgp_neighbor_damp_cmd;
04250   static struct cmd_element clear_ip_bgp_dampening_cmd;
04251   static struct cmd_element clear_ip_bgp_dampening_prefix_cmd;
04252   static struct cmd_element clear_ip_bgp_dampening_address_cmd;
04253   static struct cmd_element clear_ip_bgp_dampening_address_mask_cmd;
04254   static struct cmd_element match_community_exact_cmd;  
04255   static struct cmd_element match_ecommunity_cmd;  
04256   static struct cmd_element no_match_ecommunity_cmd;  
04257   static struct cmd_element match_origin_cmd;  
04258   static struct cmd_element no_match_origin_cmd;  
04259   static struct cmd_element set_vpnv4_nexthop_cmd;  
04260   static struct cmd_element no_set_vpnv4_nexthop_cmd;  
04261   static struct cmd_element show_ip_as_path_access_list_cmd;  
04262   static struct cmd_element show_ip_as_path_access_list_all_cmd;  
04263   static struct cmd_element dump_bgp_routes_cmd;
04264   static struct cmd_element show_ip_bgp_scan_cmd;
04265   static struct cmd_element bgp_scan_time_cmd;
04266   static struct cmd_element no_bgp_scan_time_cmd;
04267   static struct cmd_element no_bgp_scan_time_val_cmd;
04268 
04269   static struct cmd_element no_bgp_network_route_map_cmd;
04270   static struct cmd_element show_ip_bgp_ipv4_community2_cmd;
04271   static struct cmd_element show_ip_bgp_ipv4_community3_cmd;
04272   static struct cmd_element show_ip_bgp_ipv4_community4_cmd;
04273   static struct cmd_element show_ip_bgp_ipv4_community2_exact_cmd;
04274   static struct cmd_element show_ip_bgp_ipv4_community3_exact_cmd;
04275   static struct cmd_element show_ip_bgp_ipv4_community4_exact_cmd;
04276 
04277   static struct cmd_element no_bgp_network_mask_route_map_cmd;
04278   static struct cmd_element no_bgp_network_mask_natural_route_map_cmd;
04279   static struct cmd_element no_bgp_network_backdoor_cmd;
04280   static struct cmd_element no_bgp_network_mask_backdoor_cmd;
04281   static struct cmd_element no_bgp_network_mask_natural_backdoor_cmd;
04282   static struct cmd_element show_bgp_ipv6_route_map_cmd;
04283 
04284   static struct cmd_element no_match_community_exact_cmd;
04285   static struct cmd_element no_match_ecommunity_val_cmd;
04286   static struct cmd_element no_match_origin_val_cmd;
04287   static struct cmd_element set_metric_addsub_cmd;
04288   static struct cmd_element config_quit_cmd;
04289   static struct cmd_element config_write_cmd;
04290   static struct cmd_element config_write_memory_cmd;
04291   static struct cmd_element copy_runningconfig_startupconfig_cmd;
04292   static struct cmd_element show_running_config_cmd;
04293   static struct cmd_element password_text_cmd;
04294   static struct cmd_element enable_password_text_cmd;
04295   static struct cmd_element no_config_log_syslog_facility_cmd;
04296   static struct cmd_element bgp_multiple_instance_cmd;
04297   static struct cmd_element no_bgp_multiple_instance_cmd;
04298   static struct cmd_element bgp_config_type_cmd;
04299   static struct cmd_element no_bgp_config_type_cmd;
04300   static struct cmd_element no_synchronization_cmd;
04301   static struct cmd_element no_auto_summary_cmd;
04302   static struct cmd_element router_bgp_cmd;
04303   static struct cmd_element router_bgp_view_cmd;
04304   static struct cmd_element no_router_bgp_cmd;
04305   static struct cmd_element no_router_bgp_view_cmd;
04306   static struct cmd_element bgp_router_id_cmd;
04307   static struct cmd_element no_bgp_router_id_cmd;
04308   static struct cmd_element no_bgp_router_id_val_cmd;
04309   static struct cmd_element bgp_cluster_id32_cmd;
04310   static struct cmd_element no_bgp_cluster_id_cmd;
04311   static struct cmd_element no_bgp_cluster_id_arg_cmd;
04312   static struct cmd_element bgp_confederation_identifier_cmd;
04313   static struct cmd_element no_bgp_confederation_identifier_cmd;
04314   static struct cmd_element no_bgp_confederation_identifier_arg_cmd;
04315   static struct cmd_element bgp_confederation_peers_cmd;
04316   static struct cmd_element no_bgp_confederation_peers_cmd;
04317   static struct cmd_element bgp_timers_cmd;
04318   static struct cmd_element no_bgp_timers_cmd;
04319   static struct cmd_element no_bgp_timers_arg_cmd;
04320   static struct cmd_element bgp_client_to_client_reflection_cmd;
04321   static struct cmd_element no_bgp_client_to_client_reflection_cmd;
04322   static struct cmd_element bgp_always_compare_med_cmd;
04323   static struct cmd_element no_bgp_always_compare_med_cmd;
04324   static struct cmd_element bgp_deterministic_med_cmd;
04325   static struct cmd_element no_bgp_deterministic_med_cmd;
04326   static struct cmd_element bgp_fast_external_failover_cmd;
04327   static struct cmd_element no_bgp_fast_external_failover_cmd;
04328   static struct cmd_element bgp_enforce_first_as_cmd;
04329   static struct cmd_element no_bgp_enforce_first_as_cmd;
04330   static struct cmd_element bgp_bestpath_compare_router_id_cmd;
04331   static struct cmd_element no_bgp_bestpath_compare_router_id_cmd;
04332   static struct cmd_element bgp_bestpath_aspath_ignore_cmd;
04333   static struct cmd_element no_bgp_bestpath_aspath_ignore_cmd;
04334   static struct cmd_element bgp_log_neighbor_changes_cmd;
04335   static struct cmd_element no_bgp_log_neighbor_changes_cmd;
04336   static struct cmd_element bgp_bestpath_med_cmd;
04337   static struct cmd_element bgp_bestpath_med2_cmd;
04338   static struct cmd_element bgp_bestpath_med3_cmd;
04339   static struct cmd_element no_bgp_bestpath_med_cmd;
04340   static struct cmd_element no_bgp_bestpath_med2_cmd;
04341   static struct cmd_element no_bgp_bestpath_med3_cmd;
04342   static struct cmd_element no_bgp_default_ipv4_unicast_cmd;
04343   static struct cmd_element bgp_default_ipv4_unicast_cmd;
04344   static struct cmd_element bgp_network_import_check_cmd;
04345   static struct cmd_element no_bgp_network_import_check_cmd;
04346   static struct cmd_element bgp_default_local_preference_cmd;
04347   static struct cmd_element no_bgp_default_local_preference_cmd;
04348   static struct cmd_element no_bgp_default_local_preference_val_cmd;
04349   static struct cmd_element neighbor_remote_as_cmd;
04350   static struct cmd_element neighbor_peer_group_cmd;
04351   static struct cmd_element no_neighbor_cmd;
04352   static struct cmd_element no_neighbor_remote_as_cmd;
04353   static struct cmd_element no_neighbor_peer_group_cmd;
04354   static struct cmd_element no_neighbor_peer_group_remote_as_cmd;
04355   static struct cmd_element neighbor_local_as_cmd;
04356   static struct cmd_element neighbor_local_as_no_prepend_cmd;
04357   static struct cmd_element no_neighbor_local_as_cmd;
04358   static struct cmd_element no_neighbor_local_as_val_cmd;
04359   static struct cmd_element no_neighbor_local_as_val2_cmd;
04360   static struct cmd_element neighbor_activate_cmd;
04361   static struct cmd_element no_neighbor_activate_cmd;
04362   static struct cmd_element neighbor_set_peer_group_cmd;
04363   static struct cmd_element no_neighbor_set_peer_group_cmd;
04364   static struct cmd_element neighbor_passive_cmd;
04365   static struct cmd_element no_neighbor_passive_cmd;
04366   static struct cmd_element neighbor_shutdown_cmd;
04367   static struct cmd_element no_neighbor_shutdown_cmd;
04368   static struct cmd_element neighbor_capability_route_refresh_cmd;
04369   static struct cmd_element no_neighbor_capability_route_refresh_cmd;
04370   static struct cmd_element neighbor_capability_dynamic_cmd;
04371   static struct cmd_element no_neighbor_capability_dynamic_cmd;
04372   static struct cmd_element neighbor_dont_capability_negotiate_cmd;
04373   static struct cmd_element no_neighbor_dont_capability_negotiate_cmd;
04374   static struct cmd_element neighbor_capability_orf_prefix_cmd;
04375   static struct cmd_element no_neighbor_capability_orf_prefix_cmd;
04376   static struct cmd_element neighbor_nexthop_self_cmd;
04377   static struct cmd_element no_neighbor_nexthop_self_cmd;
04378   static struct cmd_element neighbor_remove_private_as_cmd;
04379   static struct cmd_element no_neighbor_remove_private_as_cmd;
04380   static struct cmd_element neighbor_send_community_cmd;
04381   static struct cmd_element no_neighbor_send_community_cmd;
04382   static struct cmd_element neighbor_send_community_type_cmd;
04383   static struct cmd_element no_neighbor_send_community_type_cmd;
04384   static struct cmd_element neighbor_soft_reconfiguration_cmd;
04385   static struct cmd_element no_neighbor_soft_reconfiguration_cmd;
04386   static struct cmd_element neighbor_route_reflector_client_cmd;
04387   static struct cmd_element no_neighbor_route_reflector_client_cmd;
04388   static struct cmd_element neighbor_route_server_client_cmd;
04389   static struct cmd_element no_neighbor_route_server_client_cmd;
04390   static struct cmd_element neighbor_attr_unchanged_cmd;
04391   static struct cmd_element neighbor_attr_unchanged1_cmd;
04392   static struct cmd_element neighbor_attr_unchanged2_cmd;
04393   static struct cmd_element neighbor_attr_unchanged3_cmd;
04394   static struct cmd_element neighbor_attr_unchanged4_cmd;
04395   static struct cmd_element neighbor_attr_unchanged5_cmd;
04396   static struct cmd_element neighbor_attr_unchanged6_cmd;
04397   static struct cmd_element neighbor_attr_unchanged7_cmd;
04398   static struct cmd_element neighbor_attr_unchanged8_cmd;
04399   static struct cmd_element neighbor_attr_unchanged9_cmd;
04400   static struct cmd_element neighbor_attr_unchanged10_cmd;
04401   static struct cmd_element no_neighbor_attr_unchanged_cmd;
04402   static struct cmd_element no_neighbor_attr_unchanged1_cmd;
04403   static struct cmd_element no_neighbor_attr_unchanged2_cmd;
04404   static struct cmd_element no_neighbor_attr_unchanged3_cmd;
04405   static struct cmd_element no_neighbor_attr_unchanged4_cmd;
04406   static struct cmd_element no_neighbor_attr_unchanged5_cmd;
04407   static struct cmd_element no_neighbor_attr_unchanged6_cmd;
04408   static struct cmd_element no_neighbor_attr_unchanged7_cmd;
04409   static struct cmd_element no_neighbor_attr_unchanged8_cmd;
04410   static struct cmd_element no_neighbor_attr_unchanged9_cmd;
04411   static struct cmd_element no_neighbor_attr_unchanged10_cmd;
04412   static struct cmd_element neighbor_transparent_as_cmd;
04413   static struct cmd_element neighbor_ebgp_multihop_cmd;
04414   static struct cmd_element neighbor_ebgp_multihop_ttl_cmd;
04415   static struct cmd_element no_neighbor_ebgp_multihop_cmd;
04416   static struct cmd_element no_neighbor_ebgp_multihop_ttl_cmd;
04417   static struct cmd_element neighbor_enforce_multihop_cmd;
04418   static struct cmd_element no_neighbor_enforce_multihop_cmd;
04419   static struct cmd_element neighbor_description_cmd;
04420   static struct cmd_element no_neighbor_description_cmd;
04421   static struct cmd_element no_neighbor_description_val_cmd;
04422   static struct cmd_element neighbor_update_source_cmd;
04423   static struct cmd_element no_neighbor_update_source_cmd;
04424   static struct cmd_element neighbor_default_originate_cmd;
04425   static struct cmd_element neighbor_default_originate_rmap_cmd;
04426   static struct cmd_element no_neighbor_default_originate_cmd;
04427   static struct cmd_element no_neighbor_default_originate_rmap_cmd;
04428   static struct cmd_element neighbor_port_cmd;
04429   static struct cmd_element no_neighbor_port_cmd;
04430   static struct cmd_element no_neighbor_port_val_cmd;
04431   static struct cmd_element neighbor_weight_cmd;
04432   static struct cmd_element no_neighbor_weight_cmd;
04433   static struct cmd_element no_neighbor_weight_val_cmd;
04434   static struct cmd_element neighbor_override_capability_cmd;
04435   static struct cmd_element no_neighbor_override_capability_cmd;
04436   static struct cmd_element neighbor_strict_capability_cmd;
04437   static struct cmd_element no_neighbor_strict_capability_cmd;
04438   static struct cmd_element neighbor_timers_cmd;
04439   static struct cmd_element no_neighbor_timers_cmd;
04440   static struct cmd_element neighbor_timers_connect_cmd;
04441   static struct cmd_element no_neighbor_timers_connect_cmd;
04442   static struct cmd_element no_neighbor_timers_connect_val_cmd;
04443   static struct cmd_element neighbor_advertise_interval_cmd;
04444   static struct cmd_element no_neighbor_advertise_interval_cmd;
04445   static struct cmd_element no_neighbor_advertise_interval_val_cmd;
04446   static struct cmd_element neighbor_version_cmd;
04447   static struct cmd_element no_neighbor_version_cmd;
04448   static struct cmd_element neighbor_interface_cmd;
04449   static struct cmd_element no_neighbor_interface_cmd;
04450   static struct cmd_element neighbor_distribute_list_cmd;
04451   static struct cmd_element no_neighbor_distribute_list_cmd;
04452   static struct cmd_element neighbor_prefix_list_cmd;
04453   static struct cmd_element no_neighbor_prefix_list_cmd;
04454   static struct cmd_element neighbor_filter_list_cmd;
04455   static struct cmd_element no_neighbor_filter_list_cmd;
04456   static struct cmd_element neighbor_route_map_cmd;
04457   static struct cmd_element no_neighbor_route_map_cmd;
04458   static struct cmd_element neighbor_unsuppress_map_cmd;
04459   static struct cmd_element no_neighbor_unsuppress_map_cmd;
04460   static struct cmd_element neighbor_maximum_prefix_cmd;
04461   static struct cmd_element neighbor_maximum_prefix_threshold_cmd;
04462   static struct cmd_element neighbor_maximum_prefix_warning_cmd;
04463   static struct cmd_element neighbor_maximum_prefix_threshold_warning_cmd;
04464   static struct cmd_element no_neighbor_maximum_prefix_cmd;
04465   static struct cmd_element no_neighbor_maximum_prefix_val_cmd;
04466   static struct cmd_element no_neighbor_maximum_prefix_val2_cmd;
04467   static struct cmd_element no_neighbor_maximum_prefix_val3_cmd;
04468   static struct cmd_element neighbor_allowas_in_cmd;
04469   static struct cmd_element neighbor_allowas_in_arg_cmd;
04470   static struct cmd_element no_neighbor_allowas_in_cmd;
04471   static struct cmd_element address_family_ipv4_cmd;
04472   static struct cmd_element address_family_ipv4_safi_cmd;
04473   static struct cmd_element address_family_ipv6_unicast_cmd;
04474   static struct cmd_element address_family_ipv6_cmd;
04475   static struct cmd_element address_family_vpnv4_cmd;
04476   static struct cmd_element address_family_vpnv4_unicast_cmd;
04477   static struct cmd_element exit_address_family_cmd;
04478   static struct cmd_element clear_ip_bgp_all_cmd;
04479   static struct cmd_element clear_bgp_all_cmd;
04480   static struct cmd_element clear_bgp_ipv6_all_cmd;
04481   static struct cmd_element clear_ip_bgp_instance_all_cmd;
04482   static struct cmd_element clear_bgp_instance_all_cmd;
04483   static struct cmd_element clear_ip_bgp_peer_cmd;
04484   static struct cmd_element clear_bgp_peer_cmd;
04485   static struct cmd_element clear_bgp_ipv6_peer_cmd;
04486   static struct cmd_element clear_ip_bgp_peer_group_cmd;
04487   static struct cmd_element clear_bgp_peer_group_cmd;
04488   static struct cmd_element clear_bgp_ipv6_peer_group_cmd;
04489   static struct cmd_element clear_ip_bgp_external_cmd;
04490   static struct cmd_element clear_bgp_external_cmd;
04491   static struct cmd_element clear_bgp_ipv6_external_cmd;
04492   static struct cmd_element clear_ip_bgp_as_cmd;
04493   static struct cmd_element clear_bgp_as_cmd;
04494   static struct cmd_element clear_bgp_ipv6_as_cmd;
04495   static struct cmd_element clear_ip_bgp_all_soft_out_cmd;
04496   static struct cmd_element clear_ip_bgp_all_out_cmd;
04497   static struct cmd_element clear_ip_bgp_instance_all_soft_out_cmd;
04498   static struct cmd_element clear_ip_bgp_all_ipv4_soft_out_cmd;
04499   static struct cmd_element clear_ip_bgp_all_ipv4_out_cmd;
04500   static struct cmd_element clear_ip_bgp_instance_all_ipv4_soft_out_cmd;
04501   static struct cmd_element clear_ip_bgp_all_vpnv4_soft_out_cmd;
04502   static struct cmd_element clear_ip_bgp_all_vpnv4_out_cmd;
04503   static struct cmd_element clear_bgp_all_soft_out_cmd;
04504   static struct cmd_element clear_bgp_instance_all_soft_out_cmd;
04505   static struct cmd_element clear_bgp_all_out_cmd;
04506   static struct cmd_element clear_bgp_ipv6_all_soft_out_cmd;
04507   static struct cmd_element clear_bgp_ipv6_all_out_cmd;
04508   static struct cmd_element clear_ip_bgp_peer_soft_out_cmd;
04509   static struct cmd_element clear_ip_bgp_peer_out_cmd;
04510   static struct cmd_element clear_ip_bgp_peer_ipv4_soft_out_cmd;
04511   static struct cmd_element clear_ip_bgp_peer_ipv4_out_cmd;
04512   static struct cmd_element clear_ip_bgp_peer_vpnv4_soft_out_cmd;
04513   static struct cmd_element clear_ip_bgp_peer_vpnv4_out_cmd;
04514   static struct cmd_element clear_bgp_peer_soft_out_cmd;
04515   static struct cmd_element clear_bgp_ipv6_peer_soft_out_cmd;
04516   static struct cmd_element clear_bgp_peer_out_cmd;
04517   static struct cmd_element clear_bgp_ipv6_peer_out_cmd;
04518   static struct cmd_element clear_ip_bgp_peer_group_soft_out_cmd;
04519   static struct cmd_element clear_ip_bgp_peer_group_out_cmd;
04520   static struct cmd_element clear_ip_bgp_peer_group_ipv4_soft_out_cmd;
04521   static struct cmd_element clear_ip_bgp_peer_group_ipv4_out_cmd;
04522   static struct cmd_element clear_bgp_peer_group_soft_out_cmd;
04523   static struct cmd_element clear_bgp_ipv6_peer_group_soft_out_cmd;
04524   static struct cmd_element clear_bgp_peer_group_out_cmd;
04525   static struct cmd_element clear_bgp_ipv6_peer_group_out_cmd;
04526   static struct cmd_element clear_ip_bgp_external_soft_out_cmd;
04527   static struct cmd_element clear_ip_bgp_external_out_cmd;
04528   static struct cmd_element clear_ip_bgp_external_ipv4_soft_out_cmd;
04529   static struct cmd_element clear_ip_bgp_external_ipv4_out_cmd;
04530   static struct cmd_element clear_bgp_external_soft_out_cmd;
04531   static struct cmd_element clear_bgp_ipv6_external_soft_out_cmd;
04532   static struct cmd_element clear_bgp_external_out_cmd;
04533   static struct cmd_element clear_bgp_ipv6_external_out_cmd;
04534   static struct cmd_element clear_ip_bgp_as_soft_out_cmd;
04535   static struct cmd_element clear_ip_bgp_as_out_cmd;
04536   static struct cmd_element clear_ip_bgp_as_ipv4_soft_out_cmd;
04537   static struct cmd_element clear_ip_bgp_as_ipv4_out_cmd;
04538   static struct cmd_element clear_ip_bgp_as_vpnv4_soft_out_cmd;
04539   static struct cmd_element clear_ip_bgp_as_vpnv4_out_cmd;
04540   static struct cmd_element clear_bgp_as_soft_out_cmd;
04541   static struct cmd_element clear_bgp_ipv6_as_soft_out_cmd;
04542   static struct cmd_element clear_bgp_as_out_cmd;
04543   static struct cmd_element clear_bgp_ipv6_as_out_cmd;
04544   static struct cmd_element clear_ip_bgp_all_soft_in_cmd;
04545   static struct cmd_element clear_ip_bgp_instance_all_soft_in_cmd;
04546   static struct cmd_element clear_ip_bgp_all_in_cmd;
04547   static struct cmd_element clear_ip_bgp_all_in_prefix_filter_cmd;
04548   static struct cmd_element clear_ip_bgp_instance_all_in_prefix_filter_cmd;
04549   static struct cmd_element clear_ip_bgp_all_ipv4_soft_in_cmd;
04550   static struct cmd_element clear_ip_bgp_all_ipv4_in_cmd;
04551   static struct cmd_element clear_ip_bgp_instance_all_ipv4_soft_in_cmd;
04552   static struct cmd_element clear_ip_bgp_all_ipv4_in_prefix_filter_cmd;
04553   static struct cmd_element clear_ip_bgp_instance_all_ipv4_in_prefix_filter_cmd;
04554   static struct cmd_element clear_ip_bgp_all_vpnv4_soft_in_cmd;
04555   static struct cmd_element clear_ip_bgp_all_vpnv4_in_cmd;
04556   static struct cmd_element clear_bgp_all_soft_in_cmd;
04557   static struct cmd_element clear_bgp_instance_all_soft_in_cmd;
04558   static struct cmd_element clear_bgp_ipv6_all_soft_in_cmd;
04559   static struct cmd_element clear_bgp_all_in_cmd;
04560   static struct cmd_element clear_bgp_ipv6_all_in_cmd;
04561   static struct cmd_element clear_bgp_all_in_prefix_filter_cmd;
04562   static struct cmd_element clear_bgp_ipv6_all_in_prefix_filter_cmd;
04563   static struct cmd_element clear_ip_bgp_peer_soft_in_cmd;
04564   static struct cmd_element clear_ip_bgp_peer_in_cmd;
04565   static struct cmd_element clear_ip_bgp_peer_in_prefix_filter_cmd;
04566   static struct cmd_element clear_ip_bgp_peer_ipv4_soft_in_cmd;
04567   static struct cmd_element clear_ip_bgp_peer_ipv4_in_cmd;
04568   static struct cmd_element clear_ip_bgp_peer_ipv4_in_prefix_filter_cmd;
04569   static struct cmd_element clear_ip_bgp_peer_vpnv4_soft_in_cmd;
04570   static struct cmd_element clear_ip_bgp_peer_vpnv4_in_cmd;
04571   static struct cmd_element clear_bgp_peer_soft_in_cmd;
04572   static struct cmd_element clear_bgp_ipv6_peer_soft_in_cmd;
04573   static struct cmd_element clear_bgp_peer_in_cmd;
04574   static struct cmd_element clear_bgp_ipv6_peer_in_cmd;
04575   static struct cmd_element clear_bgp_peer_in_prefix_filter_cmd;
04576   static struct cmd_element clear_bgp_ipv6_peer_in_prefix_filter_cmd;
04577   static struct cmd_element clear_ip_bgp_peer_group_soft_in_cmd;
04578   static struct cmd_element clear_ip_bgp_peer_group_in_cmd;
04579   static struct cmd_element clear_ip_bgp_peer_group_in_prefix_filter_cmd;
04580   static struct cmd_element clear_ip_bgp_peer_group_ipv4_soft_in_cmd;
04581   static struct cmd_element clear_ip_bgp_peer_group_ipv4_in_cmd;
04582   static struct cmd_element clear_ip_bgp_peer_group_ipv4_in_prefix_filter_cmd;
04583   static struct cmd_element clear_bgp_peer_group_soft_in_cmd;
04584   static struct cmd_element clear_bgp_ipv6_peer_group_soft_in_cmd;
04585   static struct cmd_element clear_bgp_peer_group_in_cmd;
04586   static struct cmd_element clear_bgp_ipv6_peer_group_in_cmd;
04587   static struct cmd_element clear_bgp_peer_group_in_prefix_filter_cmd;
04588   static struct cmd_element clear_bgp_ipv6_peer_group_in_prefix_filter_cmd;
04589   static struct cmd_element clear_ip_bgp_external_soft_in_cmd;
04590   static struct cmd_element clear_ip_bgp_external_in_cmd;
04591   static struct cmd_element clear_ip_bgp_external_in_prefix_filter_cmd;
04592   static struct cmd_element clear_ip_bgp_external_ipv4_soft_in_cmd;
04593   static struct cmd_element clear_ip_bgp_external_ipv4_in_cmd;
04594   static struct cmd_element clear_ip_bgp_external_ipv4_in_prefix_filter_cmd;
04595   static struct cmd_element clear_bgp_external_soft_in_cmd;
04596   static struct cmd_element clear_bgp_ipv6_external_soft_in_cmd;
04597   static struct cmd_element clear_bgp_external_in_cmd;
04598   static struct cmd_element clear_bgp_ipv6_external_in_cmd;
04599   static struct cmd_element clear_bgp_external_in_prefix_filter_cmd;
04600   static struct cmd_element clear_bgp_ipv6_external_in_prefix_filter_cmd;
04601   static struct cmd_element clear_ip_bgp_as_soft_in_cmd;
04602   static struct cmd_element clear_ip_bgp_as_in_cmd;
04603   static struct cmd_element clear_ip_bgp_as_in_prefix_filter_cmd;
04604   static struct cmd_element clear_ip_bgp_as_ipv4_soft_in_cmd;
04605   static struct cmd_element clear_ip_bgp_as_ipv4_in_cmd;
04606   static struct cmd_element clear_ip_bgp_as_ipv4_in_prefix_filter_cmd;
04607   static struct cmd_element clear_ip_bgp_as_vpnv4_soft_in_cmd;
04608   static struct cmd_element clear_ip_bgp_as_vpnv4_in_cmd;
04609   static struct cmd_element clear_bgp_as_soft_in_cmd;
04610   static struct cmd_element clear_bgp_ipv6_as_soft_in_cmd;
04611   static struct cmd_element clear_bgp_as_in_cmd;
04612   static struct cmd_element clear_bgp_ipv6_as_in_cmd;
04613   static struct cmd_element clear_bgp_as_in_prefix_filter_cmd;
04614   static struct cmd_element clear_bgp_ipv6_as_in_prefix_filter_cmd;
04615   static struct cmd_element clear_ip_bgp_all_soft_cmd;
04616   static struct cmd_element clear_ip_bgp_instance_all_soft_cmd;
04617   static struct cmd_element clear_ip_bgp_all_ipv4_soft_cmd;
04618   static struct cmd_element clear_ip_bgp_instance_all_ipv4_soft_cmd;
04619   static struct cmd_element clear_ip_bgp_all_vpnv4_soft_cmd;
04620   static struct cmd_element clear_bgp_all_soft_cmd;
04621   static struct cmd_element clear_bgp_instance_all_soft_cmd;
04622   static struct cmd_element clear_bgp_ipv6_all_soft_cmd;
04623   static struct cmd_element clear_ip_bgp_peer_soft_cmd;
04624   static struct cmd_element clear_ip_bgp_peer_ipv4_soft_cmd;
04625   static struct cmd_element clear_ip_bgp_peer_vpnv4_soft_cmd;
04626   static struct cmd_element clear_bgp_peer_soft_cmd;
04627   static struct cmd_element clear_bgp_ipv6_peer_soft_cmd;
04628   static struct cmd_element clear_ip_bgp_peer_group_soft_cmd;
04629   static struct cmd_element clear_ip_bgp_peer_group_ipv4_soft_cmd;
04630   static struct cmd_element clear_bgp_peer_group_soft_cmd;
04631   static struct cmd_element clear_bgp_ipv6_peer_group_soft_cmd;
04632   static struct cmd_element clear_ip_bgp_external_soft_cmd;
04633   static struct cmd_element clear_ip_bgp_external_ipv4_soft_cmd;
04634   static struct cmd_element clear_bgp_external_soft_cmd;
04635   static struct cmd_element clear_bgp_ipv6_external_soft_cmd;
04636   static struct cmd_element clear_ip_bgp_as_soft_cmd;
04637   static struct cmd_element clear_ip_bgp_as_ipv4_soft_cmd;
04638   static struct cmd_element clear_ip_bgp_as_vpnv4_soft_cmd;
04639   static struct cmd_element clear_bgp_as_soft_cmd;
04640   static struct cmd_element clear_bgp_ipv6_as_soft_cmd;
04641   static struct cmd_element show_ip_bgp_summary_cmd;
04642   static struct cmd_element show_ip_bgp_instance_summary_cmd;
04643   static struct cmd_element show_ip_bgp_ipv4_summary_cmd;
04644   static struct cmd_element show_ip_bgp_instance_ipv4_summary_cmd;
04645   static struct cmd_element show_ip_bgp_vpnv4_all_summary_cmd;
04646   static struct cmd_element show_bgp_summary_cmd;
04647   static struct cmd_element show_bgp_instance_summary_cmd;
04648   static struct cmd_element show_bgp_ipv6_summary_cmd;
04649   static struct cmd_element show_bgp_instance_ipv6_summary_cmd;
04650   static struct cmd_element show_ipv6_bgp_summary_cmd;
04651   static struct cmd_element show_ipv6_mbgp_summary_cmd;
04652   static struct cmd_element show_ip_bgp_neighbors_cmd;
04653   static struct cmd_element show_ip_bgp_ipv4_neighbors_cmd;
04654   static struct cmd_element show_ip_bgp_vpnv4_all_neighbors_cmd;
04655   static struct cmd_element show_ip_bgp_vpnv4_rd_neighbors_cmd;
04656   static struct cmd_element show_bgp_neighbors_cmd;
04657   static struct cmd_element show_bgp_ipv6_neighbors_cmd;
04658   static struct cmd_element show_ip_bgp_neighbors_peer_cmd;
04659   static struct cmd_element show_ip_bgp_ipv4_neighbors_peer_cmd;
04660   static struct cmd_element show_ip_bgp_vpnv4_all_neighbors_peer_cmd;
04661   static struct cmd_element show_ip_bgp_vpnv4_rd_neighbors_peer_cmd;
04662   static struct cmd_element show_bgp_neighbors_peer_cmd;
04663   static struct cmd_element show_bgp_ipv6_neighbors_peer_cmd;
04664   static struct cmd_element show_ip_bgp_instance_neighbors_cmd;
04665   static struct cmd_element show_ip_bgp_instance_neighbors_peer_cmd;
04666   static struct cmd_element show_ip_bgp_paths_cmd;
04667   static struct cmd_element show_ip_bgp_ipv4_paths_cmd;
04668   static struct cmd_element show_ip_bgp_community_info_cmd;
04669   static struct cmd_element show_ip_bgp_attr_info_cmd;
04670   static struct cmd_element bgp_redistribute_ipv4_cmd;
04671   static struct cmd_element bgp_redistribute_ipv4_rmap_cmd;
04672   static struct cmd_element bgp_redistribute_ipv4_metric_cmd;
04673   static struct cmd_element bgp_redistribute_ipv4_rmap_metric_cmd;
04674   static struct cmd_element bgp_redistribute_ipv4_metric_rmap_cmd;
04675   static struct cmd_element no_bgp_redistribute_ipv4_cmd;
04676   static struct cmd_element no_bgp_redistribute_ipv4_rmap_cmd;
04677   static struct cmd_element no_bgp_redistribute_ipv4_metric_cmd;
04678   static struct cmd_element no_bgp_redistribute_ipv4_rmap_metric_cmd;
04679   static struct cmd_element no_bgp_redistribute_ipv4_metric_rmap_cmd;
04680   static struct cmd_element bgp_redistribute_ipv6_cmd;
04681   static struct cmd_element bgp_redistribute_ipv6_rmap_cmd;
04682   static struct cmd_element bgp_redistribute_ipv6_metric_cmd;
04683   static struct cmd_element bgp_redistribute_ipv6_rmap_metric_cmd;
04684   static struct cmd_element bgp_redistribute_ipv6_metric_rmap_cmd;
04685   static struct cmd_element no_bgp_redistribute_ipv6_cmd;
04686   static struct cmd_element no_bgp_redistribute_ipv6_rmap_cmd;
04687   static struct cmd_element no_bgp_redistribute_ipv6_metric_cmd;
04688   static struct cmd_element no_bgp_redistribute_ipv6_rmap_metric_cmd;
04689   static struct cmd_element no_bgp_redistribute_ipv6_metric_rmap_cmd;
04690   static struct cmd_element ip_community_list_standard_cmd;
04691   static struct cmd_element ip_community_list_standard2_cmd;
04692   static struct cmd_element ip_community_list_expanded_cmd;
04693   static struct cmd_element ip_community_list_name_standard_cmd;
04694   static struct cmd_element ip_community_list_name_standard2_cmd;
04695   static struct cmd_element ip_community_list_name_expanded_cmd;
04696   static struct cmd_element no_ip_community_list_standard_cmd;
04697   static struct cmd_element no_ip_community_list_expanded_cmd;
04698   static struct cmd_element no_ip_community_list_name_standard_cmd;
04699   static struct cmd_element no_ip_community_list_name_expanded_cmd;
04700   static struct cmd_element show_ip_community_list_cmd;
04701   static struct cmd_element show_ip_community_list_arg_cmd;
04702   static struct cmd_element ip_extcommunity_list_standard_cmd;
04703   static struct cmd_element ip_extcommunity_list_standard2_cmd;
04704   static struct cmd_element ip_extcommunity_list_expanded_cmd;
04705   static struct cmd_element ip_extcommunity_list_name_standard_cmd;
04706   static struct cmd_element ip_extcommunity_list_name_standard2_cmd;
04707   static struct cmd_element ip_extcommunity_list_name_expanded_cmd;
04708   static struct cmd_element no_ip_extcommunity_list_all_cmd;
04709   static struct cmd_element no_ip_extcommunity_list_name_all_cmd;
04710   static struct cmd_element no_ip_extcommunity_list_standard_cmd;
04711   static struct cmd_element no_ip_extcommunity_list_expanded_cmd;
04712   static struct cmd_element no_ip_extcommunity_list_name_standard_cmd;
04713   static struct cmd_element no_ip_extcommunity_list_name_expanded_cmd;
04714   static struct cmd_element show_ip_extcommunity_list_cmd;
04715   static struct cmd_element show_ip_extcommunity_list_arg_cmd;
04716 
04717   static struct cmd_element show_ip_access_list_cmd;
04718   static struct cmd_element show_ip_access_list_name_cmd;
04719   static struct cmd_element access_list_any_cmd;
04720   static struct cmd_element no_access_list_any_cmd;
04721   static struct cmd_element access_list_standard_cmd;
04722   static struct cmd_element access_list_standard_nomask_cmd;
04723   static struct cmd_element access_list_standard_host_cmd;
04724   static struct cmd_element access_list_standard_any_cmd;
04725   static struct cmd_element no_access_list_standard_cmd;
04726   static struct cmd_element no_access_list_standard_nomask_cmd;
04727   static struct cmd_element no_access_list_standard_host_cmd;
04728   static struct cmd_element no_access_list_standard_any_cmd;
04729   static struct cmd_element access_list_extended_cmd;
04730   static struct cmd_element access_list_extended_any_mask_cmd;
04731   static struct cmd_element access_list_extended_mask_any_cmd;
04732   static struct cmd_element access_list_extended_any_any_cmd;
04733   static struct cmd_element access_list_extended_host_mask_cmd;
04734   static struct cmd_element access_list_extended_mask_host_cmd;
04735   static struct cmd_element access_list_extended_host_host_cmd;
04736   static struct cmd_element access_list_extended_any_host_cmd;
04737   static struct cmd_element access_list_extended_host_any_cmd;
04738   static struct cmd_element no_access_list_extended_cmd;
04739   static struct cmd_element no_access_list_extended_any_mask_cmd;
04740   static struct cmd_element no_access_list_extended_mask_any_cmd;
04741   static struct cmd_element no_access_list_extended_any_any_cmd;
04742   static struct cmd_element no_access_list_extended_host_mask_cmd;
04743   static struct cmd_element no_access_list_extended_mask_host_cmd;
04744   static struct cmd_element no_access_list_extended_host_host_cmd;
04745   static struct cmd_element no_access_list_extended_any_host_cmd;
04746   static struct cmd_element no_access_list_extended_host_any_cmd;
04747 
04748   //static struct cmd_element ;
04749   
04750   
04751   static struct route_map_rule_cmd route_match_ip_address_cmd ; 
04752   static struct route_map_rule_cmd route_match_ip_next_hop_cmd ;    
04753   static struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd ;
04754   static struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd ;
04755   static struct route_map_rule_cmd route_match_metric_cmd ; 
04756   static struct route_map_rule_cmd route_match_aspath_cmd ; 
04757   static struct route_map_rule_cmd route_match_community_cmd ;
04758   static struct route_map_rule_cmd route_set_aggregator_as_cmd ; 
04759   static struct route_map_rule_cmd route_set_aspath_prepend_cmd ; 
04760   static struct route_map_rule_cmd route_set_atomic_aggregate_cmd ; 
04761   static struct route_map_rule_cmd route_set_community_additive_cmd ; 
04762   static struct route_map_rule_cmd route_set_community_cmd ; 
04763   static struct route_map_rule_cmd route_set_community_delete_cmd ; 
04764   static struct route_map_rule_cmd route_set_ecommunity_rt_cmd; 
04765   static struct route_map_rule_cmd route_set_ecommunity_soo_cmd ;  
04766   static struct route_map_rule_cmd route_set_ip_nexthop_cmd ; 
04767   static struct route_map_rule_cmd route_set_local_pref_cmd ; 
04768   static struct route_map_rule_cmd route_set_metric_cmd ; 
04769   static struct route_map_rule_cmd route_set_origin_cmd ; 
04770   static struct route_map_rule_cmd route_set_originator_id_cmd; 
04771   static struct route_map_rule_cmd route_set_weight_cmd;
04772   static struct route_map_rule_cmd route_match_ecommunity_cmd;
04773   static struct route_map_rule_cmd route_match_origin_cmd;
04774   static struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd;
04775 
04776   static char* progname;
04777   static struct message attr_str[16]; /*bgp_attr.c*/
04778 
04779 
04780   //bgpd.c
04781 
04782   static struct peer_flag_action peer_flag_action_list[] ;
04783 
04784 
04785   //vty.c
04786 
04787   static struct _vector* vtyvec;
04788  
04789   //following are from bgp_debug.c
04790 
04791   /* messages for BGP-4 status */
04792   static struct message bgp_status_msg[7] ;
04793   static int bgp_status_msg_max  ;
04794 
04795   /* BGP message type string. */
04796   static char *bgp_type_str[7] ;
04797 
04798   /* message for BGP-4 Notify */
04799   static struct message bgp_notify_msg[8] ;
04800   static int bgp_notify_msg_max  ;
04801 
04802   static struct message bgp_notify_head_msg[4] ;
04803   static int bgp_notify_head_msg_max ;
04804 
04805   static struct message bgp_notify_open_msg[8] ;
04806   static int bgp_notify_open_msg_max  ;
04807 
04808   static struct message bgp_notify_update_msg[12]; 
04809   static int bgp_notify_update_msg_max  ;
04810 
04811   /* Origin strings. */
04812   static char *bgp_origin_str[3] ;
04813   static char *bgp_origin_long_str[3] ;
04814 
04815   /* Finite State Machine structures from bgp_fsm.c */
04816   static struct fsm_struct FSM [BGP_STATUS_MAX - 1][BGP_EVENTS_MAX - 1] ;
04817   static char *bgp_event_str[14] ;
04818   static char *peer_down_str[];
04819   /* bgpd.c*/
04820   
04821   /* BGP process wide configuration.  */
04822   static struct bgp_master bgp_master;
04823   
04824   /* BGP process wide configuration pointer to export.  */
04825   static struct bgp_master *bm;
04826   
04827   /* BGP community-list.  */
04828   static struct community_list_handler *bgp_clist;
04829   
04830   /*from command.c*/
04831   
04832   /* Command vector which includes some level of command lists. Normally
04833      each daemon maintains each own cmdvec. */
04834   static struct _vector* cmdvec;
04835   static int cmdvec_init;
04836 
04837   static struct cmd_node config_node ;
04838 
04839   /*from log.c*/
04840 
04841   static char *zlog_proto_names[10];
04842   static char *zlog_priority[9];
04843 
04844   /*memory.c*/
04845   static struct message mstr[6] ; 
04846 #ifdef MEMORY_LOG
04847   struct
04848   {
04849     char *name;
04850     unsigned long alloc;
04851     unsigned long t_malloc;
04852     unsigned long c_malloc;
04853     unsigned long t_calloc;
04854     unsigned long c_calloc;
04855     unsigned long t_realloc;
04856     unsigned long t_free;
04857     unsigned long c_strdup;
04858   } mstat [MTYPE_MAX];
04859 #else
04860   struct
04861   {
04862     char *name;
04863     unsigned long alloc;
04864   } mstat [MTYPE_MAX];
04865 #endif /* MTPYE_LOG */
04866 
04867   static struct memory_list memory_list_lib[28];
04868   static struct memory_list memory_list_bgp[43] ;
04869   static struct memory_list memory_list_separator[2];
04870 
04871   /*prefix.c*/
04872   
04873   static u_char maskbit[9] ;
04874   /*routemap.c*/
04875 
04876   /* Vector for route match rules. */
04877   static struct cmd_node rmap_node;
04878   static struct _vector* route_match_vec;
04879   /* Master list of route map. */
04880   struct route_map_list route_map_master ;
04881   /* Vector for route set rules. */
04882   static struct _vector* route_set_vec;
04883 
04884   /* BGP node structure. */
04885   static struct cmd_node bgp_dump_node ;
04886 
04887   /*vty.c*/
04888 
04889   static char* vty_cwd;
04890   static unsigned long vty_timeout_val;
04891   /* Configure lock. */
04892   static int vty_config;
04893 
04894   /*************************************************************************
04895                      per-instance variables from zebra
04896   *************************************************************************/
04897   
04898   /*filter.c*/
04899   struct access_master access_master_ipv4;
04900 
04901   /*prefix.c*/
04902   struct prefix_master prefix_master_ipv4;
04903 
04904 
04905   struct thread_master* master;
04906 
04907   //top level structure of aspath
04908   struct hash *aspath; /* defined in bgp_aspath.c*/
04909   
04910   struct hash *cluster_hash; /*bgp_attr.c*/
04911   
04912   //unknown transit attribute
04913   struct hash *transit_hash; /*bgp_attr.c*/
04914 
04915   //attribute hash routines
04916   struct hash *attrhash; /*bgp_attr.c*/
04917 
04918   struct community_list_master community_list_master; /*bgp_clist.c*/
04919 
04920   //Hash of community attribute
04921   struct hash *comhash; /*bgp_community.c*/
04922 
04923   //from bgp_damp.c
04924 
04925   /* Global variable to access damping configuration */
04926   struct bgp_damp_config bgp_damp_cfg;
04927   int reuse_array_offset ;
04928   struct thread *bgp_reuse_thread ;
04929   struct bgp_damp_config *prev_bgp_damp_cfg ;
04930 
04931   //from bgp_debug.c
04932 
04933   unsigned long conf_bgp_debug_fsm;
04934   unsigned long conf_bgp_debug_events;
04935   unsigned long conf_bgp_debug_packet;
04936   unsigned long conf_bgp_debug_filter;
04937   unsigned long conf_bgp_debug_keepalive;
04938   unsigned long conf_bgp_debug_update;
04939   unsigned long conf_bgp_debug_normal;
04940 
04941   unsigned long term_bgp_debug_fsm;
04942   unsigned long term_bgp_debug_events;
04943   unsigned long term_bgp_debug_packet;
04944   unsigned long term_bgp_debug_filter;
04945   unsigned long term_bgp_debug_keepalive;
04946   unsigned long term_bgp_debug_update;
04947   unsigned long term_bgp_debug_normal;
04948 
04949   //from bgp_route.c
04950   /*Static announcement peer*/
04951   struct peer *peer_self;
04952   struct bgp_table *bgp_distance_table; /*Not used in the simulation*/
04953   
04954 
04955   //from bgp_dump.c
04956 
04957 
04958     /* BGP packet dump output buffer. */
04959   struct stream *bgp_dump_obuf;
04960 
04961   /* BGP dump strucuture for 'dump bgp all' */
04962   struct bgp_dump bgp_dump_all;
04963 
04964   /* BGP dump structure for 'dump bgp updates' */
04965   struct bgp_dump bgp_dump_updates;
04966 
04967   /* BGP dump structure for 'dump bgp routes' */
04968   struct bgp_dump bgp_dump_routes;
04969 
04970   /* Dump whole BGP table is very heavy process.  */
04971   struct thread *t_bgp_dump_routes;
04972 
04973   //from bgp_ecommunity
04974 
04975   /* Hash of community attribute. */
04976   struct hash *ecomhash;
04977 
04978   /* ip as-path access-list 10 permit AS1. */
04979   //struct as_list_master as_list_master  ; //bgp_filter.c
04980   
04981   /*from bgpd.c*/
04982   struct llist* bgp_list;
04983   struct llist* peer_list;
04984 
04985   /*command.c*/
04986   struct host host;
04987 
04988   /*from log.c*/
04989   struct zlog *zlog_default ;
04990   
04991   /*distribute.c*/
04992   /* Hash of distribute list. */
04993   struct hash *disthash;
04994   struct llist *iflist;
04995 
04996   /***********************************************************************
04997                          member functions from zebra
04998   ***********************************************************************/
04999 
05000   /*bgp_aspath.c*/
05001   struct aspath * aspath_new ();
05002   void aspath_free (struct aspath *aspath);
05003   void aspath_unintern (struct aspath *aspath);
05004   char aspath_delimiter_char (u_char type, u_char which);
05005   char * aspath_make_str_count (struct aspath *as);
05006   struct aspath * aspath_intern (struct aspath *aspath);
05007   struct aspath * aspath_dup (struct aspath *aspath);
05008   void * aspath_hash_alloc (void *arg);
05009   struct aspath * aspath_parse (caddr_t pnt, int length);
05010   struct aspath * aspath_aggregate_segment_copy (struct aspath *aspath, struct assegment *seg,int i);
05011   struct assegment * aspath_aggregate_as_set_add (struct aspath *aspath, struct assegment *asset,as_t as);
05012   struct aspath *  aspath_aggregate (struct aspath *as1, struct aspath *as2);
05013   int aspath_firstas_check (struct aspath *aspath, as_t asno);
05014   int aspath_loop_check (struct aspath *aspath, as_t asno);
05015   int aspath_private_as_check (struct aspath *aspath);
05016   struct aspath * aspath_merge (struct aspath *as1, struct aspath *as2);
05017   struct aspath *aspath_prepend (struct aspath *as1, struct aspath *as2);
05018   struct aspath * aspath_add_one_as (struct aspath *aspath, as_t asno, u_char type);
05019   struct aspath * aspath_add_seq (struct aspath *aspath, as_t asno);
05020   int aspath_cmp_left (struct aspath *aspath1, struct aspath *aspath2);
05021   int aspath_cmp_left_confed (struct aspath *aspath1, struct aspath *aspath2);
05022   struct aspath * aspath_delete_confed_seq (struct aspath *aspath);
05023   struct aspath * aspath_add_confed_seq (struct aspath *aspath, as_t asno);
05024   void aspath_as_add (struct aspath *as, as_t asno);
05025   void aspath_segment_add (struct aspath *as, int type);
05026   struct aspath * aspath_empty();
05027   struct aspath * aspath_empty_get();
05028   unsigned long aspath_count();
05029   char * aspath_gettoken (char *buf, enum as_token *token, u_short *asno);
05030   struct aspath * aspath_str2aspath (char *str);
05031   unsigned int  aspath_key_make (void *aspath);
05032   int aspath_cmp (void *as1, void *as2);
05033   void aspath_init();
05034   const char * aspath_print (struct aspath *as);
05035   void aspath_print_vty (struct vty *vty, struct aspath *as);
05036   void aspath_show_all_iterator (struct hash_backet *backet, void *vty);
05037   void aspath_print_all_vty (struct vty *vty);
05038 
05039   /*bgp_attr.c*/
05040   
05041   void * cluster_hash_alloc (void *val);
05042   struct cluster_list * cluster_parse (caddr_t pnt, int length);
05043   int cluster_loop_check (struct cluster_list *cluster, struct in_addr originator);
05044   unsigned int cluster_hash_key_make (void *cluster);
05045   int cluster_hash_cmp (void *cluster1, void *cluster2);
05046   void cluster_free (struct cluster_list *cluster);
05047   struct cluster_list * cluster_dup (struct cluster_list *cluster);
05048   struct cluster_list * cluster_intern (struct cluster_list *cluster);
05049   void cluster_unintern (struct cluster_list *cluster);
05050   void cluster_init ();
05051   void transit_free (struct transit *transit);
05052   void * transit_hash_alloc (void *transit);
05053   struct transit * transit_intern (struct transit *transit);
05054   void transit_unintern (struct transit *transit);
05055   unsigned int transit_hash_key_make (void *transit);
05056   int transit_hash_cmp (void *transit1, void *transit2);
05057   void transit_init();
05058   unsigned int attrhash_key_make (void *attr);
05059   int attrhash_cmp (void *attr1, void *attr2);
05060   void attrhash_init();
05061   void attr_show_all_iterator (struct hash_backet *backet, void *vty);
05062   void attr_show_all (struct vty *vty);
05063   void * bgp_attr_hash_alloc (void *val);
05064   struct attr * bgp_attr_intern (struct attr *attr);
05065   struct attr * bgp_attr_default_set (struct attr *attr, u_char origin);
05066   struct attr * bgp_attr_default_intern (u_char origin);
05067   struct attr * bgp_attr_aggregate_intern (struct bgp *bgp, u_char origin,struct aspath *aspath,struct community *community, int as_set);
05068   void bgp_attr_unintern (struct attr *attr);
05069   void bgp_attr_flush (struct attr *attr);
05070   int bgp_attr_origin (struct peer *peer, bgp_size_t length,struct attr *attr, u_char flag, u_char *startp);
05071   int bgp_attr_aspath (struct peer *peer, bgp_size_t length,struct attr *attr, u_char flag, u_char *startp);
05072   int bgp_attr_nexthop (struct peer *peer, bgp_size_t length,struct attr *attr, u_char flag, u_char *startp);
05073   int bgp_attr_med (struct peer *peer, bgp_size_t length,struct attr *attr, u_char flag, u_char *startp);
05074   int bgp_attr_local_pref (struct peer *peer, bgp_size_t length,struct attr *attr, u_char flag);
05075   int bgp_attr_atomic (struct peer *peer, bgp_size_t length,struct attr *attr, u_char flag);
05076   int bgp_attr_aggregator (struct peer *peer, bgp_size_t length,struct attr *attr, u_char flag);
05077   int bgp_attr_community (struct peer *peer, bgp_size_t length,struct attr *attr, u_char flag);
05078   int bgp_attr_originator_id (struct peer *peer, bgp_size_t length,struct attr *attr, u_char flag);
05079   int bgp_attr_cluster_list (struct peer *peer, bgp_size_t length,struct attr *attr, u_char flag);
05080   int bgp_mp_reach_parse (struct peer *peer, bgp_size_t length, struct attr *attr,struct bgp_nlri *mp_update);
05081   int bgp_mp_unreach_parse (struct peer *peer, int length,struct bgp_nlri *mp_withdraw);
05082   int bgp_attr_ext_communities (struct peer *peer, bgp_size_t length,struct attr *attr, u_char flag);
05083   int bgp_attr_unknown (struct peer *peer, struct attr *attr, u_char flag,u_char type, bgp_size_t length, u_char *startp);
05084   int bgp_attr_parse (struct peer *peer, struct attr *attr, bgp_size_t size,struct bgp_nlri *mp_update, struct bgp_nlri *mp_withdraw);
05085   int bgp_attr_check (struct peer *peer, struct attr *attr);
05086   bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *peer,struct stream *s, struct attr *attr, struct prefix *p,afi_t afi, safi_t safi, struct peer *from,struct prefix_rd *prd, u_char *tag);
05087   bgp_size_t bgp_packet_withdraw (struct peer *peer, struct stream *s, struct prefix *p,afi_t afi, safi_t safi, struct prefix_rd *prd,u_char *tag);
05088   void bgp_attr_init();
05089   void bgp_dump_routes_attr (struct stream *s, struct attr *attr);
05090 
05091   /*bgp_advertise.c*/
05092 
05093 
05094   struct bgp_advertise * bgp_advertise_new();
05095   struct bgp_advertise_attr * baa_new ();
05096   void baa_free (struct bgp_advertise_attr *baa);
05097   void * baa_hash_alloc (void *ref);
05098   unsigned int baa_hash_key (void *baa);
05099   int baa_hash_cmp(void *baa1,void* baa2);
05100   void bgp_advertise_free (struct bgp_advertise *adv);
05101   void bgp_advertise_add (struct bgp_advertise_attr *baa,struct bgp_advertise *adv);
05102   void bgp_advertise_delete (struct bgp_advertise_attr *baa,struct bgp_advertise *adv);
05103   struct bgp_advertise_attr * bgp_advertise_intern (struct hash *hash, struct attr *attr);
05104   void bgp_advertise_unintern (struct hash *hash, struct bgp_advertise_attr *baa);
05105   void bgp_adj_out_free (struct bgp_adj_out *adj);
05106   
05107   int bgp_adj_out_lookup (struct peer *peer, struct prefix *p,afi_t afi, safi_t safi, struct bgp_node *rn);
05108   void bgp_adj_in_set (struct bgp_node *rn, struct peer *peer, struct attr *attr);
05109   struct bgp_advertise * bgp_advertise_clean (struct peer *peer, struct bgp_adj_out *adj,afi_t afi, safi_t safi);
05110   void bgp_adj_out_set (struct bgp_node *rn, struct peer *peer, struct prefix *p,struct attr *attr, afi_t afi, safi_t safi,struct bgp_info *binfo);
05111   void bgp_adj_out_unset (struct bgp_node *rn, struct peer *peer, struct prefix *p,afi_t afi, safi_t safi);
05112   void bgp_adj_out_remove (struct bgp_node *rn, struct bgp_adj_out *adj,struct peer *peer, afi_t afi, safi_t safi);
05113   void bgp_adj_in_remove (struct bgp_node *rn, struct bgp_adj_in *bai);
05114   void bgp_adj_in_unset (struct bgp_node *rn, struct peer *peer);
05115   void bgp_sync_init (struct peer *peer);
05116   void bgp_sync_delete (struct peer *peer);
05117 
05118   /*bgp_clist.c*/
05119   struct community_list_master * community_list_master_lookup (struct community_list_handler *ch, int style);
05120   struct community_entry * community_entry_new ();
05121   void community_entry_free (struct community_entry *entry);
05122   struct community_list * community_list_new ();
05123   void community_list_free (struct community_list *list);
05124   struct community_list * community_list_insert (struct community_list_handler *ch,char *name, int style);
05125   struct community_list * community_list_lookup (struct community_list_handler *ch,char *name, int style);
05126   struct community_list * community_list_get (struct community_list_handler *ch, char *name, int style);
05127   void community_list_delete (struct community_list *list);
05128   int community_list_empty_p (struct community_list *list);
05129   void community_list_entry_add (struct community_list *list,struct community_entry *entry);
05130   void community_list_entry_delete (struct community_list *list,struct community_entry *entry, int style);
05131   struct community_entry * community_list_entry_lookup (struct community_list *list, void *arg,int direct);
05132   int community_regexp_match (struct community *com, regex_t *reg);
05133   int ecommunity_regexp_match (struct ecommunity *ecom, regex_t *reg);
05134   int community_list_match (struct community *com, struct community_list *list);
05135   int ecommunity_list_match (struct ecommunity *ecom, struct community_list *list);
05136   int community_list_exact_match (struct community *com, struct community_list *list);
05137   int comval_regexp_match (u_int32_t comval, regex_t *reg);
05138   struct community * community_list_match_delete (struct community *com,struct community_list *clist);
05139   int community_list_dup_check (struct community_list *list,struct community_entry *New);
05140   int community_list_set (struct community_list_handler *ch,char *name, char *str, int direct, int style);
05141   int community_list_unset (struct community_list_handler *ch,char *name, char *str, int direct, int style);
05142   int extcommunity_list_set (struct community_list_handler *ch,char *name, char *str, int direct, int style);
05143   int extcommunity_list_unset (struct community_list_handler *ch,char *name, char *str, int direct, int style);
05144   struct community_list_handler * community_list_init ();
05145   void community_list_terminate (struct community_list_handler *ch);
05146 
05147   /*bgp_community.c*/
05148   
05149   struct community * community_new ();
05150   void community_free (struct community *com);
05151   void community_add_val (struct community *com, u_int32_t val);
05152   void community_del_val (struct community *com, u_int32_t *val);
05153   struct community * community_delete (struct community *com1, struct community *com2);
05154  // int community_compare (const void *a1, const void *a2);
05155   int community_include (struct community *com, u_int32_t val);
05156   u_int32_t community_val_get (struct community *com, int i);
05157   struct community * community_uniq_sort (struct community *com);
05158   char * community_com2str  (struct community *com);
05159   struct community * community_intern (struct community *com);
05160   void community_unintern (struct community *com);
05161   struct community * community_parse (char *pnt, u_short length);
05162   struct community * community_dup (struct community *com);
05163   char * community_str (struct community *com);
05164   unsigned int community_hash_make (void *com);
05165   int community_match (struct community *com1, struct community *com2);
05166   int community_cmp (void *c1, void *com2);
05167   struct community * community_merge (struct community *com1, struct community *com2);
05168   char * community_gettoken (char *buf, enum community_token *token, u_int32_t *val);
05169   struct community * community_str2com (char *str);
05170   unsigned long community_count ();
05171   struct hash * community_hash ();
05172   void community_init ();
05173 
05174 
05175   /*bgp_ecommunity.c*/
05176   struct ecommunity * ecommunity_new ();
05177   void ecommunity_free (struct ecommunity *ecom);
05178   int ecommunity_add_val (struct ecommunity *ecom, struct ecommunity_val *eval);
05179   struct ecommunity * ecommunity_uniq_sort (struct ecommunity *ecom);
05180   struct ecommunity * ecommunity_parse (char *pnt, u_short length);
05181   struct ecommunity * ecommunity_dup (struct ecommunity *ecom);
05182   char * ecommunity_str (struct ecommunity *ecom);
05183   struct ecommunity * ecommunity_merge (struct ecommunity *ecom1, struct ecommunity *ecom2);
05184   struct ecommunity * ecommunity_intern (struct ecommunity *ecom);
05185   void ecommunity_unintern (struct ecommunity *ecom);
05186   unsigned int ecommunity_hash_make (void *ecom);
05187   int ecommunity_cmp (void *ecom1, void *ecom2);
05188   void ecommunity_init ();
05189   char * ecommunity_gettoken (char *str, struct ecommunity_val *eval,enum ecommunity_token *token);
05190   struct ecommunity * ecommunity_str2com (char *str, int type, int keyword_included);
05191   char * ecommunity_ecom2str (struct ecommunity *ecom, int format);
05192   int ecommunity_match (struct ecommunity *ecom1, struct ecommunity *ecom2);
05193   
05194   /*bgp_filter.c*/
05195   struct as_filter * as_filter_new ();
05196   void as_filter_free (struct as_filter *asfilter);
05197   struct as_filter *  as_filter_make (regex_t *reg, char *reg_str, enum as_filter_type type);
05198   struct as_filter * as_filter_lookup (struct as_list *aslist, char *reg_str,enum as_filter_type type);
05199   void as_list_filter_add (struct as_list *aslist, struct as_filter *asfilter);
05200   struct as_list * as_list_lookup (char *name);
05201   struct as_list * as_list_new ();
05202   void as_list_free (struct as_list *aslist);
05203   struct as_list * as_list_insert (char *name);
05204   struct as_list * as_list_get (char *name);
05205   char * filter_type_str (enum as_filter_type type);
05206   void  as_list_delete (struct as_list *aslist);
05207   int as_list_empty (struct as_list *aslist);
05208   void as_list_filter_delete (struct as_list *aslist, struct as_filter *asfilter);
05209   int as_filter_match (struct as_filter *asfilter, struct aspath *aspath);
05210   enum as_filter_type as_list_apply (struct as_list *aslist, void *object);
05211   void as_list_add_hook (void (BGP::*) ());
05212   void as_list_delete_hook (void (BGP::*) ());
05213   int as_list_dup_check (struct as_list *aslist, struct as_filter *New);
05214   void as_list_show (struct vty *vty, struct as_list *aslist);
05215   void as_list_show_all (struct vty *vty);
05216   int config_write_as_list (struct vty *vty);
05217   void bgp_filter_init ();
05218 
05219   
05220   int ip_as_path(struct cmd_element *,struct vty *,int,char **); 
05221   int no_ip_as_path(struct cmd_element *,struct vty *,int,char **);
05222   int no_ip_as_path_all(struct cmd_element *,struct vty *,int,char **);
05223   int show_ip_as_path_access_list(struct cmd_element *,struct vty *,int,char **);
05224   int show_ip_as_path_access_list_all(struct cmd_element *,struct vty *,int,char **);
05225   
05226   /*bgp_network.c*/
05227   int bgp_connect (struct peer *peer);
05228   void bgp_getsockname (struct peer *peer);
05229 
05230   /*bgp_open.c*/
05231   void bgp_capability_vty_out (struct vty *vty, struct peer *peer);
05232   int bgp_capability_mp (struct peer *peer, struct capability *cap);
05233   void bgp_capability_orf_not_support (struct peer *peer, afi_t afi, safi_t safi,u_char type, u_char mode);
05234   int bgp_capability_orf (struct peer *peer, struct capability *cap,u_char *pnt);
05235   int bgp_capability_parse (struct peer *peer, u_char *pnt, u_char length,u_char **error);
05236   int bgp_auth_parse (struct peer *peer, u_char *pnt, size_t length);
05237   int strict_capability_same (struct peer *peer);
05238   int bgp_open_option_parse (struct peer *peer, u_char length, int *capability);
05239   void bgp_open_capability_orf (struct stream *s, struct peer *peer,afi_t afi, safi_t safi, u_char code);
05240   void bgp_open_capability (struct stream *s, struct peer *peer);
05241   
05242   /*bgp_regex.c*/
05243 
05244   regex_t *  bgp_regcomp (char *regstr);
05245   int bgp_regexec (regex_t *regex, struct aspath *aspath);
05246   void bgp_regex_free (regex_t *regex);
05247 
05248   /*bgp_routemap.c*/
05249 
05250   route_map_result_t route_match_ip_address (void *, struct prefix *,route_map_object_t , void *);
05251   void *route_match_ip_address_compile (char *);
05252   void route_match_ip_address_free (void *);
05253   route_map_result_t route_match_ip_next_hop (void *rule, struct prefix *,route_map_object_t , void *);
05254   void * route_match_ip_next_hop_compile (char *);
05255   void route_match_ip_next_hop_free (void *);
05256   route_map_result_t route_match_ip_address_prefix_list (void *, struct prefix *,route_map_object_t , void *);
05257   void * route_match_ip_address_prefix_list_compile (char *);
05258   void route_match_ip_address_prefix_list_free (void *);
05259   route_map_result_t route_match_ip_next_hop_prefix_list (void *, struct prefix *,route_map_object_t , void *);
05260   void * route_match_ip_next_hop_prefix_list_compile (char *);
05261   void route_match_ip_next_hop_prefix_list_free (void *);
05262   route_map_result_t route_match_metric (void *, struct prefix *,route_map_object_t , void *);
05263   void * route_match_metric_compile (char *);
05264   void route_match_metric_free (void *);
05265   route_map_result_t route_match_aspath (void *, struct prefix *,route_map_object_t , void *);
05266   void * route_match_aspath_compile (char *);
05267   int route_match_aspath (void *, struct prefix *, void *);
05268   void route_match_aspath_free (void *);
05269   route_map_result_t route_match_community (void *, struct prefix *, route_map_object_t , void *);
05270   void * route_match_community_compile (char *);
05271   void route_match_community_free (void *);
05272   route_map_result_t route_match_ecommunity (void *, struct prefix *,route_map_object_t , void *);
05273   void * route_match_ecommunity_compile (char *);
05274   void route_match_ecommunity_free (void *);
05275   route_map_result_t route_match_origin (void *, struct prefix *,route_map_object_t, void *);
05276   void * route_match_origin_compile (char *);
05277   void route_match_origin_free (void *);
05278   route_map_result_t route_set_ip_nexthop (void *, struct prefix *,route_map_object_t , void *);
05279   void * route_set_ip_nexthop_compile (char *);
05280   void route_set_ip_nexthop_free (void *);
05281   route_map_result_t route_set_local_pref (void *, struct prefix *,route_map_object_t , void *);
05282   void * route_set_local_pref_compile (char *);
05283   void route_set_local_pref_free (void *);
05284   route_map_result_t route_set_weight (void *, struct prefix *, route_map_object_t ,void *);
05285   void * route_set_weight_compile (char *);
05286   void route_set_weight_free (void *);
05287   route_map_result_t route_set_metric (void *, struct prefix *,route_map_object_t , void *);
05288   void * route_set_metric_compile (char *);
05289   void route_set_metric_free (void *);
05290   route_map_result_t route_set_aspath_prepend (void *, struct prefix *, route_map_object_t , void *);
05291   void * route_set_aspath_prepend_compile (char *);
05292   void route_set_aspath_prepend_free (void *);
05293   route_map_result_t route_set_community (void *, struct prefix *,route_map_object_t , void *);
05294   void * route_set_community_compile (char *);
05295   void route_set_community_free (void *);
05296   route_map_result_t route_set_community_additive(void *,struct prefix *,route_map_object_t,void *);
05297   void *route_set_community_additive_compile(char *);
05298   void route_set_community_additive_free(void *);
05299   route_map_result_t route_set_community_delete (void *, struct prefix *,route_map_object_t, void *);
05300   void * route_set_community_delete_compile (char *);
05301   void route_set_community_delete_free (void *);
05302   route_map_result_t route_set_ecommunity_rt (void *, struct prefix *,route_map_object_t , void *);
05303   void * route_set_ecommunity_rt_compile (char *);
05304   void route_set_ecommunity_rt_free (void *);
05305   route_map_result_t route_set_ecommunity_soo (void *, struct prefix *,route_map_object_t , void *);
05306   void * route_set_ecommunity_soo_compile (char *);
05307   void route_set_ecommunity_soo_free (void *);
05308   route_map_result_t route_set_origin (void *, struct prefix *, route_map_object_t , void *);
05309   void * route_set_origin_compile (char *);
05310   void route_set_origin_free (void *);
05311   route_map_result_t route_set_atomic_aggregate (void *, struct prefix *,route_map_object_t , void *);
05312   void * route_set_atomic_aggregate_compile (char *);
05313   void route_set_atomic_aggregate_free (void *);
05314   route_map_result_t route_set_aggregator_as (void *, struct prefix *,route_map_object_t , void *);
05315   void * route_set_aggregator_as_compile (char *);
05316   void route_set_aggregator_as_free (void *);
05317   route_map_result_t route_match_ipv6_address (void *, struct prefix *,route_map_object_t , void *);
05318   void * route_match_ipv6_address_compile (char *);
05319   void route_match_ipv6_address_free (void *);
05320   route_map_result_t route_match_ipv6_next_hop (void *, struct prefix *, route_map_object_t , void *);
05321   void * route_match_ipv6_next_hop_compile (char *);
05322   void route_match_ipv6_next_hop_free (void *);
05323   route_map_result_t route_match_ipv6_address_prefix_list (void *, struct prefix *,route_map_object_t , void *);
05324   void * route_match_ipv6_address_prefix_list_compile (char *);
05325   void route_match_ipv6_address_prefix_list_free (void *);
05326   route_map_result_t route_set_ipv6_nexthop_global (void *, struct prefix *,route_map_object_t , void *);
05327   void * route_set_ipv6_nexthop_global_compile (char *);
05328   void route_set_ipv6_nexthop_global_free (void *);
05329   route_map_result_t route_set_ipv6_nexthop_local (void *, struct prefix *, route_map_object_t , void *);
05330   void * route_set_ipv6_nexthop_local_compile (char *);
05331   void route_set_ipv6_nexthop_local_free (void *);
05332   route_map_result_t route_set_vpnv4_nexthop (void *, struct prefix *,route_map_object_t , void *);
05333   void * route_set_vpnv4_nexthop_compile (char *);
05334   void route_set_vpnv4_nexthop_free (void *);
05335   route_map_result_t  route_set_originator_id (void *, struct prefix *, route_map_object_t , void *);
05336   void * route_set_originator_id_compile (char *);
05337   void route_set_originator_id_free (void *);
05338   int bgp_route_match_add (struct vty *, struct route_map_index *, char *, char *);
05339   int bgp_route_match_delete (struct vty *, struct route_map_index *,char *, char *);
05340   int bgp_route_set_add (struct vty *, struct route_map_index *, char *, char *);
05341   int bgp_route_set_delete (struct vty *, struct route_map_index *, char *, char *);
05342   void bgp_route_map_update (char *);
05343   void bgp_route_map_init ();
05344 
05345   
05346   int match_ip_address(struct cmd_element *,struct vty *,int,char **); 
05347   int no_match_ip_address(struct cmd_element *,struct vty *,int,char **); 
05348   int match_ip_next_hop(struct cmd_element *,struct vty *,int,char **); 
05349   int no_match_ip_next_hop(struct cmd_element *,struct vty *,int,char **);
05350   int match_ip_address_prefix_list(struct cmd_element *,struct vty *,int,char **); 
05351   int no_match_ip_address_prefix_list(struct cmd_element *,struct vty *,int,char **);
05352   int match_ip_next_hop_prefix_list(struct cmd_element *,struct vty *,int,char **); 
05353   int no_match_ip_next_hop_prefix_list(struct cmd_element *,struct vty *,int,char **);
05354   int match_metric(struct cmd_element *,struct vty *,int,char **); 
05355   int no_match_metric(struct cmd_element *,struct vty *,int,char **);
05356   int match_community(struct cmd_element *,struct vty *,int,char **); 
05357   int match_community_exact(struct cmd_element *,struct vty *,int,char **); 
05358   int no_match_community(struct cmd_element *,struct vty *,int,char **);
05359   int match_ecommunity(struct cmd_element *,struct vty *,int,char **); 
05360   int no_match_ecommunity(struct cmd_element *,struct vty *,int,char **);
05361   int match_aspath(struct cmd_element *,struct vty *,int,char **);
05362   int no_match_aspath(struct cmd_element *,struct vty *,int,char **);
05363   int match_origin(struct cmd_element *,struct vty *,int,char **);
05364   int no_match_origin(struct cmd_element *,struct vty *,int,char **);
05365   int set_ip_nexthop(struct cmd_element *,struct vty *,int,char **);
05366   int no_set_ip_nexthop(struct cmd_element *,struct vty *,int,char **);
05367   int set_metric(struct cmd_element *,struct vty *,int,char **);
05368   int no_set_metric(struct cmd_element *,struct vty *,int,char **);
05369   int set_local_pref(struct cmd_element *,struct vty *,int,char **);
05370   int no_set_local_pref(struct cmd_element *,struct vty *,int,char **);
05371   int set_weight(struct cmd_element *,struct vty *,int,char **);
05372   int no_set_weight(struct cmd_element *,struct vty *,int,char **);
05373   int set_aspath_prepend(struct cmd_element *,struct vty *,int,char **);
05374   int no_set_aspath_prepend(struct cmd_element *,struct vty *,int,char **);
05375   int set_community(struct cmd_element *,struct vty *,int,char **);
05376   int set_community_none(struct cmd_element *,struct vty *,int,char **);
05377   int no_set_community(struct cmd_element *,struct vty *,int,char **);
05378   int set_community_delete(struct cmd_element *,struct vty *,int,char **);
05379   int no_set_community_delete(struct cmd_element *,struct vty *,int,char **);
05380   int set_community_additive(struct cmd_element *,struct vty *,int,char **);
05381   int no_set_community_additive(struct cmd_element *,struct vty *,int,char **);
05382   int set_ecommunity_rt(struct cmd_element *,struct vty *,int,char **);
05383   int no_set_ecommunity_rt(struct cmd_element *,struct vty *,int,char **);
05384   int set_ecommunity_soo(struct cmd_element *,struct vty *,int,char **);
05385   int no_set_ecommunity_soo(struct cmd_element *,struct vty *,int,char **);
05386   int set_origin(struct cmd_element *,struct vty *,int,char **);
05387   int no_set_origin(struct cmd_element *,struct vty *,int,char **);
05388   int set_atomic_aggregate(struct cmd_element *,struct vty *,int,char **);
05389   int no_set_atomic_aggregate(struct cmd_element *,struct vty *,int,char **);
05390   int set_aggregator_as(struct cmd_element *,struct vty *,int,char **);
05391   int no_set_aggregator_as(struct cmd_element *,struct vty *,int,char **);
05392   int match_ipv6_address(struct cmd_element *,struct vty *,int,char **); 
05393   int no_match_ipv6_address(struct cmd_element *,struct vty *,int,char **); 
05394   int match_ipv6_next_hop(struct cmd_element *,struct vty *,int,char **); 
05395   int no_match_ipv6_next_hop(struct cmd_element *,struct vty *,int,char **);
05396   int match_ipv6_address_prefix_list(struct cmd_element *,struct vty *,int,char **); 
05397   int no_match_ipv6_address_prefix_list(struct cmd_element *,struct vty *,int,char **);
05398   int set_ipv6_nexthop_global(struct cmd_element *,struct vty *,int,char **);
05399   int no_set_ipv6_nexthop_global(struct cmd_element *,struct vty *,int,char **);
05400   int set_ipv6_nexthop_local(struct cmd_element *,struct vty *,int,char **);
05401   int no_set_ipv6_nexthop_local(struct cmd_element *,struct vty *,int,char **);
05402   int set_vpnv4_nexthop(struct cmd_element *,struct vty *,int,char **);
05403   int no_set_vpnv4_nexthop(struct cmd_element *,struct vty *,int,char **);
05404   int set_originator_id(struct cmd_element *,struct vty *,int,char **);
05405   int no_set_originator_id(struct cmd_element *,struct vty *,int,char **);
05406   
05407   /*bgpd.h*/
05408   
05409   int bgp_option_set (int flag);
05410   int bgp_option_unset (int flag);
05411   int bgp_option_check (int flag);
05412   int bgp_flag_set (struct bgp *bgp, int flag);
05413   int bgp_flag_unset (struct bgp *bgp, int flag);
05414   int bgp_flag_check (struct bgp *bgp, int flag);
05415   void bgp_config_set (struct bgp *bgp, int config);
05416   void bgp_config_unset (struct bgp *bgp, int config);
05417   int bgp_config_check (struct bgp *bgp, int config);
05418   int bgp_router_id_set (struct bgp *bgp, struct in_addr *id);
05419   int bgp_router_id_unset (struct bgp *bgp);
05420   int bgp_cluster_id_set (struct bgp *bgp, struct in_addr *cluster_id);
05421   int bgp_cluster_id_unset (struct bgp *bgp);
05422   int bgp_timers_set (struct bgp *bgp, u_int32_t keepalive, u_int32_t holdtime);
05423   int bgp_timers_unset (struct bgp *bgp);
05424   int bgp_confederation_id_set (struct bgp *bgp, as_t as);
05425   int bgp_confederation_id_unset (struct bgp *bgp);
05426   int bgp_confederation_peers_check (struct bgp *bgp, as_t as);
05427   int bgp_confederation_peers_add (struct bgp *bgp, as_t as);
05428   int bgp_confederation_peers_remove (struct bgp *bgp, as_t as);
05429   int bgp_default_local_preference_set (struct bgp *bgp, u_int32_t local_pref);
05430   int bgp_default_local_preference_unset (struct bgp *bgp);
05431   int peer_cmp (void *p1,void *p2);
05432   int peer_af_flag_check (struct peer *peer, afi_t afi, safi_t safi, u_int32_t flag);
05433   void peer_af_flag_reset (struct peer *peer, afi_t afi, safi_t safi);
05434   void peer_global_config_reset (struct peer *peer);
05435   int peer_list_cmp(struct peer*,struct peer*);
05436   int peer_conf_cmp(void*,void*);
05437   struct peer_conf* peer_conf_new();
05438   void peer_conf_free(struct peer_conf*);
05439   void peer_conf_delete(struct peer_conf*);
05440   int peer_sort (struct peer *peer);
05441   struct peer * peer_new ();
05442   struct peer * peer_create (union sockunion *su, struct bgp *bgp, as_t local_as, as_t remote_as, afi_t afi, safi_t safi);
05443   struct peer * peer_create_accept (struct bgp *bgp);
05444   void peer_as_change (struct peer *peer, as_t as);
05445   int peer_remote_as (struct bgp *bgp, union sockunion *su, as_t *as,afi_t afi, safi_t safi);
05446   int peer_activate (struct peer *peer, afi_t afi, safi_t safi);
05447   int peer_deactivate (struct peer *peer, afi_t afi, safi_t safi);
05448   int peer_delete (struct peer *peer);
05449   int peer_group_cmp (void *g1, void *g2);
05450   int peer_group_active (struct peer *peer);
05451   struct peer_group * peer_group_new ();
05452   void peer_group_free (struct peer_group *group);
05453   struct peer_group * peer_group_lookup (struct bgp *bgp, char *name);
05454   struct peer_group * peer_group_get (struct bgp *bgp, char *name);
05455   void peer_group2peer_config_copy (struct peer_group *group, struct peer *peer,afi_t afi, safi_t safi);
05456   int peer_group_remote_as (struct bgp *bgp, char *group_name, as_t *as);
05457   int peer_group_delete (struct peer_group *group);
05458   int peer_group_remote_as_delete (struct peer_group *group);
05459   int peer_group_bind (struct bgp *bgp, union sockunion *su, struct peer_group *group, afi_t afi, safi_t safi, as_t *as);
05460   int peer_group_unbind (struct bgp *bgp, struct peer *peer,struct peer_group *group, afi_t afi, safi_t safi);
05461   struct bgp * bgp_create (as_t *as, char *name);
05462   struct bgp_master * bgp_get_master ();
05463   struct bgp * bgp_get_default ();
05464   struct bgp * bgp_lookup (as_t as, char *name);
05465   struct bgp * bgp_lookup_by_name (char *name);
05466   int bgp_get (struct bgp **bgp_val, as_t *as, char *name);
05467   int bgp_delete (struct bgp *bgp);
05468   struct peer * peer_lookup (struct bgp *bgp, union sockunion *su);
05469   struct peer * peer_lookup_by_su(union sockunion *su);
05470   struct peer * peer_lookup_with_open (union sockunion *su, as_t remote_as,struct in_addr *remote_id, int *as);
05471   int peer_active (struct peer *peer);
05472   int peer_active_nego (struct peer *peer);
05473   void peer_change_action (struct peer *peer, afi_t afi, safi_t safi,enum peer_change_type type);
05474   int peer_flag_action_set (struct peer_flag_action *action_list, int size,struct peer_flag_action *action, u_int32_t flag);
05475   void peer_flag_modify_action (struct peer *peer, u_int32_t flag);
05476   int peer_flag_modify (struct peer *peer, u_int32_t flag, int set);
05477   int peer_flag_set (struct peer *peer, u_int32_t flag);
05478   int peer_flag_unset (struct peer *peer, u_int32_t flag);
05479   int peer_is_group_member (struct peer *peer, afi_t afi, safi_t safi);
05480   int peer_af_flag_modify (struct peer *peer, afi_t afi, safi_t safi, u_int32_t flag,int set);
05481   int peer_af_flag_set (struct peer *peer, afi_t afi, safi_t safi, u_int32_t flag);
05482   int peer_af_flag_unset (struct peer *peer, afi_t afi, safi_t safi, u_int32_t flag);
05483   int peer_ebgp_multihop_set (struct peer *peer, int ttl);
05484   int peer_ebgp_multihop_unset (struct peer *peer);
05485   int peer_description_set (struct peer *peer, char *desc);
05486   int peer_description_unset (struct peer *peer);
05487   int  peer_update_source_if_set (struct peer *peer, char *ifname);
05488   int peer_update_source_addr_set (struct peer *peer, union sockunion *su);
05489   int peer_update_source_unset (struct peer *peer);
05490   int peer_default_originate_set (struct peer *peer, afi_t afi, safi_t safi,char *rmap);
05491   int peer_default_originate_unset (struct peer *peer, afi_t afi, safi_t safi);
05492   int peer_port_set (struct peer *peer, u_int16_t port);
05493   int peer_port_unset (struct peer *peer);
05494   int peer_weight_set (struct peer *peer, u_int16_t weight);
05495   int peer_weight_unset (struct peer *peer);
05496   int peer_timers_set (struct peer *peer, u_int32_t keepalive, u_int32_t holdtime);
05497   int peer_timers_unset (struct peer *peer);
05498   int peer_timers_connect_set (struct peer *peer, u_int32_t );
05499   int peer_timers_connect_unset (struct peer *peer);
05500   int peer_advertise_interval_set (struct peer *peer, u_int32_t routeadv);
05501   int peer_advertise_interval_unset (struct peer *peer);
05502   int peer_version_set (struct peer *peer, int version);
05503   int peer_version_unset (struct peer *peer);
05504   int peer_interface_set (struct peer *peer, char *str);
05505   int peer_interface_unset (struct peer *peer);
05506   int peer_allowas_in_set (struct peer *peer, afi_t afi, safi_t safi, int allow_num);
05507   int peer_allowas_in_unset (struct peer *peer, afi_t afi, safi_t safi);
05508   int peer_local_as_set (struct peer *peer, as_t as, int no_prepend);
05509   int peer_local_as_unset (struct peer *peer);
05510   int peer_distribute_set (struct peer *peer, afi_t afi, safi_t safi, int direct,char *name);
05511   int peer_distribute_unset (struct peer *peer, afi_t afi, safi_t safi, int direct);
05512   void peer_distribute_update (struct access_list *access);
05513   int peer_prefix_list_set (struct peer *peer, afi_t afi, safi_t safi, int direct,char *name);
05514   int peer_prefix_list_unset (struct peer *peer, afi_t afi, safi_t safi, int direct);
05515   void peer_prefix_list_update ();
05516   int peer_aslist_set (struct peer *peer, afi_t afi, safi_t safi, int direct,char *name);
05517   int peer_aslist_unset (struct peer *peer,afi_t afi, safi_t safi, int direct);
05518   void peer_aslist_update ();
05519   int peer_route_map_set (struct peer *peer, afi_t afi, safi_t safi, int direct,char *name);
05520   int peer_route_map_unset (struct peer *peer, afi_t afi, safi_t safi, int direct);
05521   int peer_unsuppress_map_set (struct peer *peer, afi_t afi, safi_t safi, char *name);
05522   int peer_unsuppress_map_unset (struct peer *peer, afi_t afi, safi_t safi);
05523   int peer_maximum_prefix_set (struct peer *peer, afi_t afi, safi_t safi,u_int32_t max, u_char threshold, int warning);
05524   int peer_maximum_prefix_unset (struct peer *peer, afi_t afi, safi_t safi);
05525   int peer_clear (struct peer *peer);
05526   int peer_clear_soft (struct peer *peer, afi_t afi, safi_t safi,enum bgp_clear_type stype);
05527   char * peer_uptime (time_t uptime2, char *buf, size_t len);
05528   struct peer_conf *peer_conf_lookup (struct bgp *bgp, union sockunion *su, int afi);
05529   struct peer_conf *peer_conf_lookup_vty (struct vty *vty,char *ip_str,int afi);
05530   struct peer_conf *peer_conf_lookup_existing (struct bgp *bgp, union sockunion *su);
05531   void bgp_config_write_filter (struct vty *vty, struct peer *peer,afi_t afi, safi_t safi);
05532   void bgp_config_write_peer (struct vty *vty, struct bgp *bgp,struct peer *peer, afi_t afi, safi_t safi);
05533   void bgp_config_write_family_header (struct vty *vty, afi_t afi, safi_t safi,int *write);
05534   int bgp_config_write_family (struct vty *vty, struct bgp *bgp, afi_t afi,safi_t safi);
05535   int bgp_config_write (struct vty *vty);
05536   void bgp_master_init ();
05537   void bgp_init ();
05538   
05539 
05540   /*bgp_damp.h*/
05541 
05542   int bgp_reuse_index (int penalty);
05543   void bgp_reuse_list_add (struct bgp_damp_info *bdi);
05544   void bgp_reuse_list_delete (struct bgp_damp_info *bdi);
05545   int bgp_damp_decay (Time_t tdiff, int penalty);
05546   int bgp_reuse_timer (struct thread *t);
05547   int bgp_damp_withdraw (struct bgp_info *binfo, struct bgp_node *rn,afi_t afi, safi_t safi, int attr_change);
05548   int bgp_damp_update (struct bgp_info *binfo, struct bgp_node *rn,afi_t afi, safi_t safi);
05549   int bgp_damp_scan (struct bgp_info *binfo, afi_t afi, safi_t safi);
05550   void bgp_damp_info_free (struct bgp_damp_info *bdi, int withdraw);
05551   void bgp_damp_parameter_set (int hlife, int reuse, int sup, int maxsup);
05552   int bgp_damp_enable (struct bgp *bgp, afi_t afi, safi_t safi, int half,unsigned int reuse, unsigned int suppress,unsigned int max);
05553   void bgp_damp_config_clean (struct bgp_damp_config *damp);
05554   void bgp_damp_info_clean ();
05555   int bgp_damp_disable (struct bgp *bgp, afi_t afi, safi_t safi);
05556   int bgp_config_write_damp (struct vty *vty);
05557   char * bgp_get_reuse_time (unsigned int penalty, char *buf, size_t len);
05558   void bgp_damp_info_vty (struct vty *vty, struct bgp_info *binfo) ;
05559   char * bgp_damp_reuse_time_vty (struct vty *vty, struct bgp_info *binfo);
05560   
05561 
05562   /*bgp_debug.c*/
05563 
05564   void bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size);
05565   void bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify, char *direct);
05566   int debug (unsigned int option);
05567   int bgp_config_write_debug (struct vty *vty);
05568   void bgp_debug_init ();
05569   int debug_bgp_fsm(struct cmd_element *,struct vty *,int,char **); 
05570   int no_debug_bgp_fsm(struct cmd_element *,struct vty *,int,char **); 
05571   int debug_bgp_events(struct cmd_element *,struct vty *,int,char **); 
05572   int no_debug_bgp_events(struct cmd_element *,struct vty *,int,char **); 
05573   int debug_bgp_filter(struct cmd_element *,struct vty *,int,char **); 
05574   int no_debug_bgp_filter(struct cmd_element *,struct vty *,int,char **); 
05575   int no_debug_bgp_keepalive(struct cmd_element *,struct vty *,int,char **); 
05576   int debug_bgp_keepalive(struct cmd_element *,struct vty *,int,char **); 
05577   int debug_bgp_update(struct cmd_element *,struct vty *,int,char **); 
05578   int debug_bgp_update_direct(struct cmd_element *,struct vty *,int,char **); 
05579   int no_debug_bgp_update(struct cmd_element *,struct vty *,int,char **); 
05580   int debug_bgp_normal(struct cmd_element *,struct vty *,int,char **); 
05581   int no_debug_bgp_normal(struct cmd_element *,struct vty *,int,char **); 
05582   int no_debug_bgp_all(struct cmd_element *,struct vty *,int,char **); 
05583   int show_debugging_bgp(struct cmd_element *,struct vty *,int,char **); 
05584 
05585   /*bgp_dump.c*/
05586 
05587   FILE * bgp_dump_open_file (struct bgp_dump *bgp_dump);
05588   int bgp_dump_interval_add (struct bgp_dump *bgp_dump, int interval);
05589   void bgp_dump_header (struct stream *obuf, int type, int subtype);
05590   void bgp_dump_set_size (struct stream *s, int type);
05591   void bgp_dump_routes_entry (struct prefix *p, struct bgp_info *info, int afi,int type, unsigned int seq);
05592   void bgp_dump_routes_func (int afi);
05593   int bgp_dump_interval_func (struct thread *t);
05594   void bgp_dump_common (struct stream *obuf, struct peer *peer);
05595   void bgp_dump_state (struct peer *peer, int status_old, int status_new);
05596   void bgp_dump_packet_func (struct bgp_dump *bgp_dump, struct peer *peer,struct stream *packet);
05597   void bgp_dump_packet (struct peer *peer, int type, struct stream *packet);
05598   unsigned int bgp_dump_parse_time (char *str);
05599   int bgp_dump_set (struct vty *vty, struct bgp_dump *bgp_dump, int type,char *path, char *interval_str);
05600   int bgp_dump_unset (struct vty *vty, struct bgp_dump *bgp_dump);
05601   int config_write_bgp_dump (struct vty *vty);
05602   void bgp_dump_init ();
05603 
05604 
05605   int dump_bgp_all(struct cmd_element *,struct vty *,int,char **);
05606   int dump_bgp_all_interval(struct cmd_element *,struct vty *,int,char **);
05607   int no_dump_bgp_all(struct cmd_element *,struct vty *,int,char **);
05608   int dump_bgp_updates(struct cmd_element *,struct vty *,int,char **);
05609   int dump_bgp_updates_interval(struct cmd_element *,struct vty *,int,char **);
05610   int no_dump_bgp_updates(struct cmd_element *,struct vty *,int,char **);
05611   int dump_bgp_routes(struct cmd_element *,struct vty *,int,char **);
05612   int dump_bgp_routes_interval(struct cmd_element *,struct vty *,int,char **);
05613   int no_dump_bgp_routes(struct cmd_element *,struct vty *,int,char **);
05614   
05615   
05616   /*bgp_route.c*/
05617 
05618 
05619   struct bgp_node * bgp_afi_node_get (struct bgp *bgp, afi_t afi, safi_t safi, struct prefix *p,struct prefix_rd *prd);
05620   struct bgp_info * bgp_info_new ();
05621   void bgp_info_free (struct bgp_info *binfo);
05622   void bgp_info_add (struct bgp_node *rn, struct bgp_info *ri);
05623   void bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri);
05624   u_int32_t bgp_med_value (struct attr *attr, struct bgp *bgp);
05625   int bgp_info_cmp (struct bgp *bgp, struct bgp_info *New, struct bgp_info *exist);
05626   enum filter_type bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,afi_t afi, safi_t safi);
05627   enum filter_type bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,afi_t afi, safi_t safi);
05628   int bgp_community_filter (struct peer *peer, struct attr *attr);
05629   int bgp_cluster_filter (struct peer *peer, struct attr *attr);
05630   int bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,afi_t afi, safi_t safi);
05631   int bgp_adj_set(struct bgp_table *table, struct prefix *p, struct attr *attr,
05632                   struct prefix_rd *prd, safi_t safi);
05633   int bgp_adj_unset (struct bgp_table *table, struct prefix *p,
05634                     struct prefix_rd *prd, safi_t safi);
05635   int bgp_adj_lookup (struct bgp_table *table, struct prefix *p,
05636                      struct prefix_rd *prd, safi_t safi);
05637   void bgp_adj_clear (struct bgp_table *table, safi_t safi);
05638   int bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,struct attr *attr, afi_t afi, safi_t safi);
05639 #ifdef BGP_MRAI
05640   void bgp_refresh_rib (struct peer_conf *conf, afi_t afi, safi_t safi);
05641   void bgp_announce_table (struct peer *peer);
05642   void bgp_announce_rib (struct peer_conf *conf, afi_t afi, safi_t safi);
05643   void bgp_refresh_table (struct peer *peer, afi_t afi, safi_t safi);
05644   int bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi,
05645                   struct bgp_info *del, struct prefix_rd *prd, u_char *tag);
05646 #endif
05647 
05648 #ifndef BGP_MRAI
05649   int bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi);
05650 #endif
05651   int bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi, safi_t safi, int always);
05652   void bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,afi_t afi, safi_t safi);
05653   void bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,afi_t afi, safi_t safi, int force);
05654   /* from bgp_nexthop.c*/
05655 int bgp_nexthop_self (afi_t afi, struct attr *attr);
05656 
05657   int bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,afi_t afi, safi_t safi, int type, int sub_type,struct prefix_rd *prd, u_char *tag, int soft_reconfig);
05658   int bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,int afi, int safi, int type, int sub_type, struct prefix_rd *prd,u_char *tag);
05659   void bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw);
05660   void bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,struct bgp_table *table);
05661   void bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi);
05662   void bgp_announce_route_all (struct peer *peer);
05663   void bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,struct bgp_table *table);
05664   void bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi);
05665   void bgp_route_clear_with_afi (struct peer *peer, struct bgp *bgp, afi_t afi,
05666                                safi_t safi);
05667   void bgp_route_clear (struct peer *peer);
05668   void bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,struct bgp_table *table);
05669   void bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi);
05670   void bgp_clear_route_all (struct peer *peer);
05671   void bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi);
05672   void bgp_terminate ();
05673   void bgp_reset ();
05674   int bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet);
05675   int bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,bgp_size_t length);
05676   struct bgp_static * bgp_static_new ();
05677   void bgp_static_free (struct bgp_static *bgp_static);
05678   void bgp_static_update (struct bgp *bgp, struct prefix *p,struct bgp_static *bgp_static, afi_t afi, safi_t safi);
05679   void bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,u_char safi, struct prefix_rd *prd, u_char *tag);
05680   void bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,safi_t safi);
05681   void bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,u_char safi, struct prefix_rd *prd, u_char *tag);
05682   int bgp_static_set (struct vty *vty, struct bgp *bgp, char *ip_str, u_int16_t afi,u_char safi, char *rmap, int backdoor);
05683   int bgp_static_unset (struct vty *vty, struct bgp *bgp, char *ip_str,u_int16_t afi, u_char safi);
05684   void bgp_static_delete (struct bgp *bgp);
05685   int bgp_static_set_vpnv4 (struct vty *vty, char *ip_str, char *rd_str,char *tag_str);
05686   int bgp_static_unset_vpnv4 (struct vty *vty, char *ip_str, char *rd_str,char *tag_str);
05687   struct bgp_aggregate * bgp_aggregate_new ();
05688   void bgp_aggregate_free (struct bgp_aggregate *aggregate);
05689   void bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,afi_t afi, safi_t safi, struct bgp_info *del,struct bgp_aggregate *aggregate);
05690   void bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,struct bgp_info *ri, afi_t afi, safi_t safi);
05691   void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,struct bgp_aggregate *);
05692   void bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,struct bgp_info *del, afi_t afi, safi_t safi);
05693   void bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,struct bgp_aggregate *aggregate);
05694   int bgp_aggregate_set (struct vty *vty, char *prefix_str, afi_t afi, safi_t safi,u_char summary_only, u_char as_set);
05695   int bgp_aggregate_unset (struct vty *vty, char *prefix_str, afi_t afi, safi_t safi);
05696   void bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,u_int32_t metric, u_char type);
05697   void bgp_redistribute_delete (struct prefix *p, u_char type);
05698   void bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type);
05699   void route_vty_out_route (struct prefix *p, struct vty *vty);
05700   int vty_calc_line (struct vty *vty, unsigned long length);
05701   int route_vty_out (struct vty *vty, struct prefix *p,struct bgp_info *binfo, int display, safi_t safi);
05702   void route_vty_out_tmp (struct vty *vty, struct prefix *p,struct attr *attr, safi_t safi);
05703   int damp_route_vty_out (struct vty *vty, struct prefix *p,struct bgp_info *binfo, int display, safi_t safi);
05704   int flap_route_vty_out (struct vty *vty, struct prefix *p,struct bgp_info *binfo, int display, safi_t safi);
05705   void route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,struct bgp_info *binfo, afi_t afi, safi_t safi);
05706   int bgp_show_callback (struct vty *vty, int unlock);
05707   int bgp_show (struct vty *vty, char *view_name, afi_t afi, safi_t safi,enum bgp_show_type type);
05708   int bgp_show_route (struct vty *vty, char *view_name, char *ip_str,afi_t afi, safi_t safi, struct prefix_rd *prd,int prefix_check);
05709   void bgp_show_regexp_clean (struct vty *vty);
05710   int bgp_show_regexp (struct vty *vty, int argc, char **argv, afi_t afi,safi_t safi, enum bgp_show_type type);
05711   int bgp_show_prefix_list (struct vty *vty, char *prefix_list_str, afi_t afi,safi_t safi, enum bgp_show_type type);
05712   int bgp_show_filter_list (struct vty *vty, char *filter, afi_t afi,safi_t safi, enum bgp_show_type type);
05713   int bgp_show_route_map (struct vty *vty, char *rmap_str, afi_t afi,safi_t safi, enum bgp_show_type type);
05714   int bgp_show_community (struct vty *vty, int argc, char **argv, int exact,u_int16_t afi, u_char safi);
05715   int bgp_show_community_list (struct vty *vty, char *com, int exact,u_int16_t afi, u_char safi);
05716   void bgp_show_prefix_longer_clean (struct vty *vty);
05717   int bgp_show_prefix_longer (struct vty *vty, char *prefix, afi_t afi,safi_t safi, enum bgp_show_type type);
05718   void show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,int in);
05719   int peer_adj_routes (struct vty *vty, char *ip_str, afi_t afi, safi_t safi, int in);
05720   void bgp_show_neighbor_route_clean (struct vty *vty);
05721   int bgp_show_neighbor_route (struct vty *vty, char *ip_str, afi_t afi,safi_t safi, enum bgp_show_type type);
05722   struct bgp_distance * bgp_distance_new ();
05723   void bgp_distance_free (struct bgp_distance *bdistance);
05724   int bgp_distance_set (struct vty *vty, char *distance_str, char *ip_str,char *access_list_str);
05725   int bgp_distance_unset (struct vty *vty, char *distance_str, char *ip_str,char *access_list_str);
05726   void bgp_distance_reset ();
05727   u_char bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp);
05728   int bgp_clear_damp_route (struct vty *vty, char *view_name, char *ip_str,afi_t afi, safi_t safi, struct prefix_rd *prd,int prefix_check);
05729   int bgp_config_write_network (struct vty *vty, struct bgp *bgp,afi_t afi, safi_t safi, int *write);
05730   int bgp_config_write_distance (struct vty *vty, struct bgp *bgp);
05731   void bgp_route_init ();
05732  
05733   int bgp_network(struct cmd_element *,struct vty *,int,char **); 
05734   int bgp_network_route_map(struct cmd_element *,struct vty *,int,char **); 
05735   int bgp_network_backdoor(struct cmd_element *,struct vty *,int,char **); 
05736   int bgp_network_mask(struct cmd_element *,struct vty *,int,char **); 
05737   int bgp_network_mask_route_map(struct cmd_element *,struct vty *,int,char **); 
05738   int bgp_network_mask_backdoor(struct cmd_element *,struct vty *,int,char **); 
05739   int bgp_network_mask_natural(struct cmd_element *,struct vty *,int,char **); 
05740   int bgp_network_mask_natural_route_map(struct cmd_element *,struct vty *,int,char **); 
05741   int bgp_network_mask_natural_backdoor(struct cmd_element *,struct vty *,int,char **); 
05742   int no_bgp_network(struct cmd_element *,struct vty *,int,char **); 
05743   int no_bgp_network_mask(struct cmd_element *,struct vty *,int,char **); 
05744   int no_bgp_network_mask_natural(struct cmd_element *,struct vty *,int,char **); 
05745   int ipv6_bgp_netowrk(struct cmd_element *,struct vty *,int,char **); 
05746   int ipv6_bgp_network_route_map(struct cmd_element *,struct vty *,int,char **); 
05747   int no_ipv6_bgp_network(struct cmd_element *,struct vty *,int,char **); 
05748   int aggregate_address(struct cmd_element *,struct vty *,int,char **); 
05749   int aggregate_address_mask(struct cmd_element *,struct vty *,int,char **); 
05750   int aggregate_address_summary_only(struct cmd_element *,struct vty *,int,char **); 
05751   int aggregate_address_mask_summary_only(struct cmd_element *,struct vty *,int,char **); 
05752   int aggregate_address_as_set(struct cmd_element *,struct vty *,int,char **); 
05753 
05754   int aggregate_address_mask_as_set(struct cmd_element *,struct vty *,int,char **);
05755   int aggregate_address_as_set_summary(struct cmd_element *,struct vty *,int,char **);
05756   int aggregate_address_mask_as_set_summary(struct cmd_element *,struct vty *,int,char **);
05757   int no_aggregate_address(struct cmd_element *,struct vty *,int,char **);
05758   int no_aggregate_address_mask(struct cmd_element *,struct vty *,int,char **);
05759   int ipv6_aggregate_address(struct cmd_element *,struct vty *,int,char **);
05760   int ipv6_aggregate_address_summary_only(struct cmd_element *,struct vty *,int,char **);
05761   int no_ipv6_aggregate_address(struct cmd_element *,struct vty *,int,char **);
05762   int no_ipv6_aggregate_address_summary_only(struct cmd_element *,struct vty *,int,char **);
05763   int show_ip_bgp(struct cmd_element *,struct vty *,int,char **);
05764   int show_ip_bgp_ipv4(struct cmd_element *,struct vty *,int,char **);
05765   int show_ip_bgp_route(struct cmd_element *,struct vty *,int,char **);
05766   int show_ip_bgp_ipv4_route(struct cmd_element *,struct vty *,int,char **);
05767   int show_ip_bgp_vpnv4_all_route(struct cmd_element *,struct vty *,int,char **);
05768   int show_ip_bgp_vpnv4_rd_route(struct cmd_element *,struct vty *,int,char **);
05769   int show_ip_bgp_prefix(struct cmd_element *,struct vty *,int,char **);
05770   int show_ip_bgp_ipv4_prefix(struct cmd_element *,struct vty *,int,char **);
05771   int show_ip_bgp_vpnv4_all_prefix(struct cmd_element *,struct vty *,int,char **);
05772   int show_ip_bgp_vpnv4_rd_prefix(struct cmd_element *,struct vty *,int,char **);
05773   int show_ip_bgp_view(struct cmd_element *,struct vty *,int,char **);
05774   int show_ip_bgp_view_route(struct cmd_element *,struct vty *,int,char **);
05775   int show_ip_bgp_view_prefix(struct cmd_element *,struct vty *,int,char **);
05776   int show_bgp(struct cmd_element *,struct vty *,int,char **);
05777   int show_ipv6_bgp(struct cmd_element *,struct vty *,int,char **);
05778   int show_ipv6_bgp_route(struct cmd_element *,struct vty *,int,char **);
05779   int show_bgp_prefix(struct cmd_element *,struct vty *,int,char **);
05780   int show_ipv6_bgp_prefix(struct cmd_element *,struct vty *,int,char **);
05781   int show_ipv6_mbgp(struct cmd_element *,struct vty *,int,char **);
05782   int show_ipv6_mbgp_route(struct cmd_element *,struct vty *,int,char **);
05783   int show_ipv6_mbgp_prefix(struct cmd_element *,struct vty *,int,char **);
05784   int show_ip_bgp_regexp(struct cmd_element *,struct vty *,int,char **); 
05785   int show_ip_bgp_flap_regexp(struct cmd_element *,struct vty *,int,char **); 
05786   int show_ip_bgp_ipv4_regexp(struct cmd_element *,struct vty *,int,char **); 
05787   int show_bgp_regexp(struct cmd_element *,struct vty *,int,char **); 
05788   int show_ipv6_bgp_regexp(struct cmd_element *,struct vty *,int,char **); 
05789   int show_ipv6_mbgp_regexp(struct cmd_element *,struct vty *,int,char **); 
05790   int show_ip_bgp_prefix_list(struct cmd_element *,struct vty *,int,char **); 
05791   int show_ip_bgp_flap_prefix_list(struct cmd_element *,struct vty *,int,char **); 
05792   int show_ip_bgp_ipv4_prefix_list(struct cmd_element *,struct vty *,int,char **); 
05793   int show_bgp_prefix_list(struct cmd_element *,struct vty *,int,char **); 
05794   int show_ipv6_bgp_prefix_list(struct cmd_element *,struct vty *,int,char **); 
05795   int show_ipv6_mbgp_prefix_list(struct cmd_element *,struct vty *,int,char **); 
05796   int show_ip_bgp_filter_list(struct cmd_element *,struct vty *,int,char **); 
05797   int show_ip_bgp_flap_filter_list(struct cmd_element *,struct vty *,int,char **); 
05798   int show_ip_bgp_ipv4_filter_list(struct cmd_element *,struct vty *,int,char **); 
05799   int show_bgp_filter_list(struct cmd_element *,struct vty *,int,char **); 
05800   int show_ipv6_bgp_filter_list(struct cmd_element *,struct vty *,int,char **); 
05801   int show_ipv6_mbgp_filter_list(struct cmd_element *,struct vty *,int,char **); 
05802   int show_ip_bgp_route_map(struct cmd_element *,struct vty *,int,char **); 
05803   int show_ip_bgp_flap_route_map(struct cmd_element *,struct vty *,int,char **); 
05804   int show_ip_bgp_ipv4_route_map(struct cmd_element *,struct vty *,int,char **); 
05805   int show_bgp_route_map(struct cmd_element *,struct vty *,int,char **); 
05806   int show_ip_bgp_cidr_only(struct cmd_element *,struct vty *,int,char **);
05807   int show_ip_bgp_flap_cidr_only(struct cmd_element *,struct vty *,int,char **);
05808   int show_ip_bgp_ipv4_cidr_only(struct cmd_element *,struct vty *,int,char **);
05809   int show_ip_bgp_community_all(struct cmd_element *,struct vty *,int,char **);
05810   int show_ip_bgp_ipv4_community_all(struct cmd_element *,struct vty *,int,char **);
05811   int show_bgp_community_all(struct cmd_element *,struct vty *,int,char **);
05812   int show_ipv6_bgp_community_all(struct cmd_element *,struct vty *,int,char **);
05813   int show_ipv6_mbgp_community_all(struct cmd_element *,struct vty *,int,char **);
05814   int show_ip_bgp_community(struct cmd_element *,struct vty *,int,char **);
05815   int show_ip_bgp_ipv4_community(struct cmd_element *,struct vty *,int,char **);
05816   int show_ip_bgp_community_exact(struct cmd_element *,struct vty *,int,char **);
05817   int show_ip_bgp_ipv4_community_exact(struct cmd_element *,struct vty *,int,char **);
05818   int show_bgp_community(struct cmd_element *,struct vty *,int,char **);
05819   int show_ipv6_bgp_community(struct cmd_element *,struct vty *,int,char **);
05820   int show_bgp_community_exact(struct cmd_element *,struct vty *,int,char **);
05821   int show_ipv6_bgp_community_exact(struct cmd_element *,struct vty *,int,char **);
05822   int show_ipv6_mbgp_community(struct cmd_element *,struct vty *,int,char **);
05823   int show_ipv6_mbgp_community_exact(struct cmd_element *,struct vty *,int,char **);
05824   int show_ip_bgp_community_list(struct cmd_element *,struct vty *,int,char **);
05825   int show_ip_bgp_ipv4_community_list(struct cmd_element *,struct vty *,int,char **);
05826   int show_ip_bgp_community_list_exact(struct cmd_element *,struct vty *,int,char **);
05827   int show_ip_bgp_ipv4_community_list_exact(struct cmd_element *,struct vty *,int,char **);
05828   int show_bgp_community_list(struct cmd_element *,struct vty *,int,char **);
05829   int show_ipv6_bgp_community_list(struct cmd_element *,struct vty *,int,char **);
05830   int show_ipv6_mbgp_community_list(struct cmd_element *,struct vty *,int,char **);
05831   int show_bgp_community_list_exact(struct cmd_element *,struct vty *,int,char **);
05832   int show_ipv6_bgp_community_list_exact(struct cmd_element *,struct vty *,int,char **);
05833   int show_ipv6_mbgp_community_list_exact(struct cmd_element *,struct vty *,int,char **);
05834   int show_ip_bgp_prefix_longer(struct cmd_element *,struct vty *,int,char **);
05835   int show_ip_bgp_flap_prefix_longer(struct cmd_element *,struct vty *,int,char **);
05836   int show_ip_bgp_ipv4_prefix_longer(struct cmd_element *,struct vty *,int,char **);
05837   int show_ip_bgp_flap_address(struct cmd_element *,struct vty *,int,char **);
05838   int show_ip_bgp_flap_prefix(struct cmd_element *,struct vty *,int,char **);
05839   int show_bgp_prefix_longer(struct cmd_element *,struct vty *,int,char **);
05840   int show_ipv6_bgp_prefix_longer(struct cmd_element *,struct vty *,int,char **);
05841   int show_ipv6_mbgp_prefix_longer(struct cmd_element *,struct vty *,int,char **);
05842   int show_ip_bgp_neighbor_advertised_route(struct cmd_element *,struct vty *,int,char **);
05843   int show_ip_bgp_ipv4_neighbor_advertised_route(struct cmd_element *,struct vty *,int,char **);
05844   int show_bgp_neighbor_advertised_route(struct cmd_element *,struct vty *,int,char **);
05845   int ipv6_bgp_neighbor_advertised_route(struct cmd_element *,struct vty *,int,char **);
05846   int ipv6_mbgp_neighbor_advertised_route(struct cmd_element *,struct vty *,int,char **);
05847   int show_ip_bgp_neighbor_received_routes(struct cmd_element *,struct vty *,int,char **);
05848   int show_ip_bgp_ipv4_neighbor_received_routes(struct cmd_element *,struct vty *,int,char **);
05849   int show_ip_bgp_neighbor_received_prefix_filter(struct cmd_element *,struct vty *,int,char **);
05850   int show_ip_bgp_ipv4_neighbor_received_prefix_filter(struct cmd_element *,struct vty *,int,char **);
05851   int show_bgp_neighbor_received_routes(struct cmd_element *,struct vty *,int,char **);
05852   int show_bgp_neighbor_received_prefix_filter(struct cmd_element *,struct vty *,int,char **);
05853   int ipv6_bgp_neighbor_received_routes(struct cmd_element *,struct vty *,int,char **);
05854   int ipv6_mbgp_neighbor_received_routes(struct cmd_element *,struct vty *,int,char **);
05855   int show_ip_bgp_neighbor_routes(struct cmd_element *,struct vty *,int,char **);
05856   int show_ip_bgp_neighbor_flap(struct cmd_element *,struct vty *,int,char **);
05857   int show_ip_bgp_neighbor_damp(struct cmd_element *,struct vty *,int,char **);
05858   int show_ip_bgp_ipv4_neighbor_routes(struct cmd_element *,struct vty *,int,char **);
05859   int show_bgp_neighbor_routes(struct cmd_element *,struct vty *,int,char **);
05860   int ipv6_bgp_neighbor_routes(struct cmd_element *,struct vty *,int,char **);
05861   int ipv6_mbgp_neighbor_routes(struct cmd_element *,struct vty *,int,char **);
05862   int bgp_distance(struct cmd_element *,struct vty *,int,char **);
05863   int no_bgp_distance(struct cmd_element *,struct vty *,int,char **);
05864   int bgp_distance_source(struct cmd_element *,struct vty *,int,char **);
05865   int no_bgp_distance_source(struct cmd_element *,struct vty *,int,char **);
05866   int bgp_distance_source_access_list(struct cmd_element *,struct vty *,int,char **);
05867   int no_bgp_distance_source_access_list(struct cmd_element *,struct vty *,int,char **);
05868   int bgp_damp_set(struct cmd_element *,struct vty *,int,char **);
05869   int bgp_damp_unset(struct cmd_element *,struct vty *,int,char **);
05870   int show_ip_bgp_dampened_paths(struct cmd_element *,struct vty *,int,char **);
05871   int show_ip_bgp_flap_statistics(struct cmd_element *,struct vty *,int,char **);
05872   int clear_ip_bgp_dampening(struct cmd_element *,struct vty *,int,char **);
05873   int clear_ip_bgp_dampening_prefix(struct cmd_element *,struct vty *,int,char **);
05874   int clear_ip_bgp_dampening_address(struct cmd_element *,struct vty *,int,char **);
05875   int clear_ip_bgp_dampening_address_mask(struct cmd_element *,struct vty *,int,char **);
05876   
05877   /*bgp_fsm.c*/
05878   
05879   int bgp_start_jitter (int time);
05880   void bgp_timer_set (struct peer *peer);
05881   int bgp_start_timer (struct thread *thread);
05882   int bgp_connect_timer (struct thread *thread);
05883   int bgp_holdtime_timer (struct thread *thread);
05884   int bgp_keepalive_timer (struct thread *thread);
05885   int bgp_routeadv_timer (struct thread *thread);
05886   void bgp_uptime_reset (struct peer *peer);
05887   int bgp_stop (struct peer *peer);
05888   int bgp_stop_with_error (struct peer *peer);
05889   int bgp_connect_success (struct peer *peer);
05890   int bgp_connect_fail (struct peer *peer);
05891   int bgp_start (struct peer *peer);
05892   int bgp_reconnect (struct peer *peer);
05893   int bgp_fsm_open (struct peer *peer);
05894   void bgp_fsm_change_status (struct peer *peer, int status);
05895   int bgp_fsm_keepalive_expire (struct peer *peer);
05896   int bgp_fsm_holdtime_expire (struct peer *peer);
05897   int bgp_establish (struct peer *peer);
05898   int bgp_fsm_keepalive (struct peer *peer);
05899   int bgp_fsm_update (struct peer *peer);
05900   int bgp_ignore (struct peer *peer);
05901   int bgp_event (struct thread *thread);
05902 
05903 
05904   /*bgp_packet.c*/
05905 
05906   int peer_writen(struct peer* peer,char *ptr,int nbytes);
05907   int bgp_packet_set_marker (struct stream *s, u_char type);
05908   int bgp_packet_set_size (struct stream *s);
05909   void bgp_packet_add (struct peer *peer, struct stream *s);
05910   void bgp_packet_delete (struct peer *peer);
05911   struct stream * bgp_packet_dup (struct stream *s);
05912   void bgp_connect_check (struct peer *peer);
05913   struct stream * bgp_update_packet (struct peer *peer, afi_t afi, safi_t safi);
05914   struct stream * bgp_withdraw_packet (struct peer *peer, afi_t afi, safi_t safi);
05915   void bgp_update_send (struct peer *peer, struct prefix*,struct attr *attr,afi_t afi, safi_t safi, struct peer *from);
05916   void bgp_withdraw_send (struct peer *peer,struct prefix*, afi_t afi, safi_t safi);
05917   struct stream * bgp_write_packet (struct peer *peer);
05918   int bgp_write_proceed (struct peer *peer);
05919   int bgp_write (struct thread *thread);
05920   int bgp_write_notify (struct peer *peer);
05921   void bgp_keepalive_send (struct peer *peer);
05922   void bgp_open_send (struct peer *peer);
05923   void bgp_notify_send_with_data (struct peer *peer, u_char code, u_char sub_code,u_char *data, size_t datalen);
05924   void bgp_notify_send (struct peer *peer, u_char code, u_char sub_code);
05925   void bgp_route_refresh_send (struct peer *peer, afi_t afi, safi_t safi,u_char orf_type, u_char when_to_refresh, int remove);
05926   void bgp_capability_send (struct peer *peer, afi_t afi, safi_t safi,int capability_code, int action);
05927   int bgp_collision_detect (struct peer *New, struct in_addr remote_id);
05928   int bgp_open_receive (struct peer *peer, bgp_size_t size);
05929   int bgp_update_receive (struct peer *peer, bgp_size_t size);
05930   void bgp_notify_receive (struct peer *peer, bgp_size_t size);
05931   void bgp_keepalive_receive (struct peer *peer, bgp_size_t size);
05932   void bgp_route_refresh_receive (struct peer *peer, bgp_size_t size);
05933   int bgp_capability_msg_parse (struct peer *peer, u_char *pnt, bgp_size_t length);
05934   void bgp_capability_receive (struct peer *peer, bgp_size_t size);
05935   int bgp_read_packet (struct peer *peer,Data*);
05936   int bgp_marker_all_one (struct stream *s, int length);
05937   int bgp_read (struct thread *thread);
05938   char *afi2str (afi_t afi);
05939   char *safi2str (safi_t safi);
05940   
05941 /*****bgp_table.c******/
05942 
05943   struct bgp_table * bgp_table_init (void);
05944   void bgp_table_finish (struct bgp_table *rt);
05945   void bgp_node_free (struct bgp_node *node);
05946   void bgp_table_free(struct bgp_table*);
05947   void route_common (struct prefix *n, struct prefix *p, struct prefix *New);
05948   int check_bit (u_char *prefix, u_char prefixlen);
05949   void set_link (struct bgp_node *node, struct bgp_node *New);
05950   struct bgp_node *bgp_lock_node (struct bgp_node *node);
05951   void bgp_unlock_node (struct bgp_node *node);
05952   struct bgp_node *bgp_node_match (struct bgp_table *table, struct prefix *p);
05953   struct bgp_node *bgp_node_match_ipv4 (struct bgp_table *table, struct in_addr *addr);
05954   struct bgp_node *bgp_node_lookup (struct bgp_table *table, struct prefix *p);
05955   struct bgp_node *bgp_node_get (struct bgp_table *table, struct prefix *p);
05956   void bgp_node_delete (struct bgp_node *node);
05957   struct bgp_node * bgp_table_top (struct bgp_table *table);
05958   struct bgp_node *bgp_route_next (struct bgp_node *node);
05959   struct bgp_node *bgp_route_next_until (struct bgp_node *node, struct bgp_node *limit);
05960   struct bgp_node *bgp_node_create ();
05961   struct bgp_node *bgp_node_set (struct bgp_table *table, struct prefix *prefix);
05962   
05963   
05964 
05965   /**** Zebra library functions ****/
05966   
05967   /*routemap.c*/
05968   void route_map_index_delete (struct route_map_index *, int);
05969   struct route_map * route_map_new (char *name);
05970   struct route_map * route_map_add (char *name);
05971   void route_map_delete (struct route_map *mmap);
05972   struct route_map * route_map_lookup_by_name (char *name);
05973   struct route_map * route_map_get (char *name);
05974   char * route_map_type_str (enum route_map_type type);
05975   int route_map_empty (struct route_map *mmap);
05976   void route_map_print ();
05977   struct route_map_index * route_map_index_new ();
05978   struct route_map_index * route_map_index_lookup (struct route_map *map, enum route_map_type type,int pref);
05979   struct route_map_index * route_map_index_add (struct route_map *mmap, enum route_map_type type,int pref);
05980   struct route_map_index * route_map_index_get (struct route_map *map, enum route_map_type type,int pref);
05981   struct route_map_rule * route_map_rule_new ();
05982   void route_map_install_match (struct route_map_rule_cmd *cmd);
05983   void route_map_install_set (struct route_map_rule_cmd *cmd);
05984   struct route_map_rule_cmd * route_map_lookup_match (char *name);
05985   struct route_map_rule_cmd * route_map_lookup_set (char *name);
05986   void route_map_rule_add (struct route_map_rule_list *list,struct route_map_rule *rule);
05987   void route_map_rule_delete (struct route_map_rule_list *list,struct route_map_rule *rule);
05988   int rulecmp (char *dst, char *src);
05989   int route_map_add_match (struct route_map_index *index, char *match_name,char *match_arg);
05990   int route_map_delete_match (struct route_map_index *index, char *match_name,char *match_arg);
05991   int route_map_add_set (struct route_map_index *index, char *set_name,char *set_arg);
05992   int route_map_delete_set (struct route_map_index *index, char *set_name,char *set_arg);
05993   route_map_result_t route_map_apply_index (struct route_map_index *index, struct prefix *prefix,route_map_object_t type, void *object);
05994   route_map_result_t route_map_apply (struct route_map *map, struct prefix *prefix,route_map_object_t type, void *object);
05995   void route_map_add_hook (void (BGP::*func) (char *));
05996   void route_map_delete_hook (void (BGP::*func) (char *));
05997   void route_map_event_hook (void (BGP::*func) (route_map_event_t, char *));
05998   void route_map_init ();
05999   int route_map_config_write (struct vty *vty);
06000   void route_map_init_vty ();
06001   
06002   
06003   int route_map(struct cmd_element *,struct vty *,int,char **);
06004   int no_route_map_all(struct cmd_element *,struct vty *,int,char **);
06005   int no_route_map(struct cmd_element *,struct vty *,int,char **);
06006   int rmap_onmatch_next(struct cmd_element *,struct vty *,int,char **);
06007   int no_rmap_onmatch_next(struct cmd_element *,struct vty *,int,char **);
06008   int rmap_onmatch_goto(struct cmd_element *,struct vty *,int,char **);
06009   int no_rmap_onmatch_goto(struct cmd_element *,struct vty *,int,char **);
06010   
06011  
06012   /*buffer.c*/
06013   
06014   struct buffer_data * buffer_data_new (size_t size);
06015   void buffer_data_free (struct buffer_data *d);
06016   struct buffer * buffer_new (size_t size);
06017   void buffer_free (struct buffer *b);
06018   char * buffer_getstr (struct buffer *b);
06019   int buffer_empty (struct buffer *b);
06020   void buffer_reset (struct buffer *b);
06021   void buffer_add (struct buffer *b);
06022   int buffer_write (struct buffer *b, u_char *ptr, size_t size);
06023   int buffer_putc (struct buffer *b, u_char c);
06024   int buffer_putw (struct buffer *b, u_short c);
06025   int buffer_putstr (struct buffer *b, u_char *c);
06026   void buffer_flush (struct buffer *b, int fd, size_t size);
06027   int buffer_flush_all (struct buffer *b, int fd);
06028   int buffer_flush_vty_all (struct buffer *b, int fd, int erase_flag,int no_more_flag);
06029   int buffer_flush_vty (struct buffer *b, int fd, unsigned int size,int erase_flag, int no_more_flag);
06030   int buffer_flush_window (struct buffer *b, int fd, int width, int height,int erase, int no_more);
06031   
06032 
06033   /*command.c*/
06034 
06035   char * argv_concat (char **argv, int argc, int shift);
06036   void install_node (struct cmd_node *node,int (BGP::*func) (struct vty *));
06037 //  int cmp_node (const void *p, const void *q);
06038 //  int cmp_desc (const void *p, const void *q);
06039   void sort_node ();
06040   struct _vector* cmd_make_strvec (char *string);
06041   void cmd_free_strvec (struct _vector* v);
06042   char * cmd_desc_str (char **string);
06043   struct _vector* cmd_make_descvec (char *string, char *descstr);
06044   int cmd_cmdsize (struct _vector *strvec);
06045   char * cmd_prompt (enum node_type node);
06046   void install_element (enum node_type ntype, struct cmd_element *cmd);
06047   void to64(char *s, long v, int n);
06048 //  char *zencrypt (char *passwd);
06049   char *syslog_facility_print (int facility);
06050   int config_write_host (struct vty *vty);
06051   struct _vector* cmd_node_vector (struct _vector* v, enum node_type ntype);
06052   int cmd_filter_by_symbol (char *command, char *symbol);
06053   enum match_type cmd_ipv4_match (char *str);
06054   enum match_type cmd_ipv4_prefix_match (char *str);
06055   enum match_type cmd_ipv6_match (char *str);
06056   enum match_type cmd_ipv6_prefix_match (char *str);
06057   int cmd_range_match (char *range, char *str);
06058   enum match_type cmd_filter_by_completion (char *command,struct _vector* v, unsigned int index);
06059   enum match_type cmd_filter_by_string (char *command, struct _vector* v,unsigned int index);
06060   int is_cmd_ambiguous (char *command, struct _vector* v, int index, enum match_type type);
06061   char * cmd_entry_function (char *src, char *dst);
06062   char * cmd_entry_function_desc (char *src, char *dst);
06063   int cmd_unique_string (struct _vector* v, char *str);
06064   int desc_unique_string (struct _vector* v, char *str);
06065   struct _vector* cmd_describe_command (struct _vector* vline, struct vty *vty, int *status);
06066   int cmd_lcd (char **matched);
06067   char ** cmd_complete_command (struct _vector* vline, struct vty *vty, int *status);
06068   int cmd_execute_command (struct _vector* vline, struct vty *vty, struct cmd_element **cmd);
06069   int cmd_execute_command_strict (struct _vector* vline, struct vty *vty,struct cmd_element **cmd);
06070   int config_from_file (struct vty *vty, FILE *fp);
06071   void host_config_set (char *filename);
06072   void install_default (enum node_type node);
06073   void cmd_init(int );
06074 
06075 
06076   int config_terminal(struct cmd_element *,struct vty *,int,char **);
06077   int enable(struct cmd_element *,struct vty *,int,char **); 
06078   int disable(struct cmd_element *,struct vty *,int,char **); 
06079   int config_exit(struct cmd_element *,struct vty *,int,char **);
06080   int config_end(struct cmd_element *,struct vty *,int,char **);
06081   int show_version(struct cmd_element *,struct vty *,int,char **);
06082   int config_help(struct cmd_element *,struct vty *,int,char **);
06083   int config_list(struct cmd_element *,struct vty *,int,char **);
06084   int config_write_file(struct cmd_element *,struct vty *,int,char **); 
06085   int config_write_terminal(struct cmd_element *,struct vty *,int,char **);
06086   int show_startup_config(struct cmd_element *,struct vty *,int,char **);
06087   int config_hostname(struct cmd_element *,struct vty *,int,char **); 
06088   int config_no_hostname(struct cmd_element *,struct vty *,int,char **); 
06089   //int config_password(struct cmd_element *,struct vty *,int,char **); 
06090   int config_enable_password(struct cmd_element *,struct vty *,int,char**);
06091   int no_config_enable_password(struct cmd_element *,struct vty *,int,char **); 
06092   int service_password_encrypt(struct cmd_element *,struct vty *,int,char **);
06093   int no_service_password_encrypt(struct cmd_element *,struct vty *,int,char **);
06094   int config_terminal_length(struct cmd_element *,struct vty *,int,char **); 
06095   int config_terminal_no_length(struct cmd_element *,struct vty *,int,char **);
06096   int service_terminal_length(struct cmd_element *,struct vty *,int,char **);
06097   int no_service_terminal_length(struct cmd_element *,struct vty *,int,char **);
06098   int config_log_stdout(struct cmd_element *,struct vty *,int,char **);
06099   int no_config_log_stdout(struct cmd_element *,struct vty *,int,char **);
06100   int config_log_file(struct cmd_element *,struct vty *,int,char **);
06101   int no_config_log_file(struct cmd_element *,struct vty *,int,char **);
06102   int config_log_syslog(struct cmd_element *,struct vty *,int,char **);
06103   int config_log_syslog_facility(struct cmd_element *,struct vty *,int,char **);
06104   int no_config_log_syslog(struct cmd_element *,struct vty *,int,char **);
06105   int config_log_trap(struct cmd_element *,struct vty *,int,char **);
06106   int no_config_log_trap(struct cmd_element *,struct vty *,int,char **);
06107   int config_log_record_priority(struct cmd_element *,struct vty *,int,char **);
06108   int no_config_log_record_priority(struct cmd_element *,struct vty *,int,char **);
06109   int banner_motd_default(struct cmd_element *,struct vty *,int,char **);
06110   int no_banner_motd(struct cmd_element *,struct vty *,int,char **);
06111   
06112   /*Distribute.c*/
06113   
06114   struct distribute * distribute_new ();
06115   void distribute_free (void *dist);
06116   struct distribute * distribute_lookup (char *ifname);
06117   void distribute_list_add_hook (void (BGP::*func) (struct distribute *));
06118   void distribute_list_delete_hook (void (BGP::*func) (struct distribute *));
06119   void * distribute_hash_alloc (void *arg);
06120   struct distribute * distribute_get (char *ifname);
06121   unsigned int distribute_hash_make (void *dist);
06122   int distribute_cmp (void *dist1, void *dist2);
06123   struct distribute * distribute_list_set (char *ifname, enum distribute_type type, char *alist_name);
06124   int distribute_list_unset (char *ifname, enum distribute_type type,char *alist_name);
06125   struct distribute * distribute_list_prefix_set (char *ifname, enum distribute_type type,char *plist_name);
06126   int distribute_list_prefix_unset (char *ifname, enum distribute_type type,char *plist_name);
06127   int config_show_distribute (struct vty *vty);
06128   int config_write_distribute (struct vty *vty);
06129   void distribute_list_reset ();
06130   void distribute_list_init (int node);
06131 
06132   /*filter.c*/
06133 
06134   struct access_master * access_master_get (afi_t afi);
06135   struct filter * filter_new ();
06136   void filter_free (struct filter *filter);
06137   char * filter_type_str (struct filter *filter);
06138   int filter_match_cisco (struct filter *mfilter, struct prefix *p);
06139   int filter_match_zebra (struct filter *mfilter, struct prefix *p);
06140   struct access_list * access_list_new ();
06141   void access_list_free (struct access_list *access);
06142   void access_list_delete (struct access_list *access);
06143   struct access_list * access_list_insert (afi_t afi, char *name);
06144   struct access_list * access_list_lookup (afi_t afi, char *name);
06145   struct access_list * access_list_get (afi_t afi, char *name);
06146   enum filter_type access_list_apply (struct access_list *access, void *object);
06147   void access_list_add_hook (void (BGP::*func) (struct access_list *access));
06148   void access_list_delete_hook (void (BGP::*func) (struct access_list *access));
06149   void access_list_filter_add (struct access_list *access, struct filter *filter);
06150   int access_list_empty (struct access_list *access);
06151   void access_list_filter_delete (struct access_list *access, struct filter *filter);
06152   struct filter * filter_lookup_cisco (struct access_list *access, struct filter *mnew);
06153   struct filter * filter_lookup_zebra (struct access_list *access, struct filter *mnew);
06154   int vty_access_list_remark_unset (struct vty *vty, afi_t afi, char *name);
06155   int filter_set_cisco (struct vty *vty, char *name_str, char *type_str,char *addr_str, char *addr_mask_str,char *mask_str, char *mask_mask_str,int extended, int set);
06156   int filter_set_zebra (struct vty *vty, char *name_str, char *type_str,afi_t afi, char *prefix_str, int exact, int set);
06157   int filter_show (struct vty *vty, char *name, afi_t afi);
06158   void config_write_access_cisco (struct vty *vty, struct filter *mfilter);
06159   void config_write_access_zebra (struct vty *vty, struct filter *mfilter);
06160   int config_write_access (struct vty *vty, afi_t afi);
06161   int config_write_access_ipv4 (struct vty *vty);
06162   void access_list_reset_ipv4 ();
06163   void access_list_init_ipv4 ();
06164   int config_write_access_ipv6 (struct vty *vty);
06165   void access_list_reset_ipv6 ();
06166   void access_list_init_ipv6 ();
06167   void access_list_reset ();
06168   void access_list_init ();
06169 
06170 
06171   int access_list_standard(struct cmd_element *,struct vty *,int,char **);
06172   int access_list_standard_nomask(struct cmd_element *,struct vty *,int,char **);
06173   int access_list_standard_host(struct cmd_element *,struct vty *,int,char **);
06174   int access_list_standard_any(struct cmd_element *,struct vty *,int,char **);
06175   int no_access_list_standard(struct cmd_element *,struct vty *,int,char **);
06176   int no_access_list_standard_nomask(struct cmd_element *,struct vty *,int,char **);
06177   int no_access_list_standard_host(struct cmd_element *,struct vty *,int,char **);
06178   int no_access_list_standard_any(struct cmd_element *,struct vty *,int,char **);
06179   int access_list_extended(struct cmd_element *,struct vty *,int,char **);
06180   int access_list_extended_mask_any(struct cmd_element *,struct vty *,int,char **);
06181   int access_list_extended_any_mask(struct cmd_element *,struct vty *,int,char **);
06182   int access_list_extended_any_any(struct cmd_element *,struct vty *,int,char **);
06183   int access_list_extended_mask_host(struct cmd_element *,struct vty *,int,char **);
06184   int access_list_extended_host_mask(struct cmd_element *,struct vty *,int,char **);
06185   int access_list_extended_host_host(struct cmd_element *,struct vty *,int,char **);
06186   int access_list_extended_any_host(struct cmd_element *,struct vty *,int,char **);
06187   int access_list_extended_host_any(struct cmd_element *,struct vty *,int,char **);
06188   int no_access_list_extended(struct cmd_element *,struct vty *,int,char **);
06189   int no_access_list_extended_mask_any(struct cmd_element *,struct vty *,int,char **);
06190   int no_access_list_extended_any_mask(struct cmd_element *,struct vty *,int,char **);
06191   int no_access_list_extended_any_any(struct cmd_element *,struct vty *,int,char **);
06192   int no_access_list_extended_mask_host(struct cmd_element *,struct vty *,int,char **);
06193   int no_access_list_extended_host_mask(struct cmd_element *,struct vty *,int,char **);
06194   int no_access_list_extended_host_host(struct cmd_element *,struct vty *,int,char **);
06195   int no_access_list_extended_any_host(struct cmd_element *,struct vty *,int,char **);
06196   int no_access_list_extended_host_any(struct cmd_element *,struct vty *,int,char **);
06197   int access_list(struct cmd_element *,struct vty *,int,char **);
06198   int access_list_exact(struct cmd_element *,struct vty *,int,char **);
06199   int access_list_any(struct cmd_element *,struct vty *,int,char **);
06200   int no_access_list(struct cmd_element *,struct vty *,int,char **);
06201   int no_access_list_exact(struct cmd_element *,struct vty *,int,char **);
06202   int no_access_list_any(struct cmd_element *,struct vty *,int,char **);
06203   int no_access_list_all(struct cmd_element *,struct vty *,int,char **);
06204   int access_list_remark(struct cmd_element *,struct vty *,int,char **);
06205   int no_access_list_remark(struct cmd_element *,struct vty *,int,char **);
06206   int ipv6_access_list(struct cmd_element *,struct vty *,int,char **);
06207   int ipv6_access_list_exact(struct cmd_element *,struct vty *,int,char **);
06208   int ipv6_access_list_any(struct cmd_element *,struct vty *,int,char **);
06209   int no_ipv6_access_list(struct cmd_element *,struct vty *,int,char **);
06210   int no_ipv6_access_list_exact(struct cmd_element *,struct vty *,int,char **);
06211   int no_ipv6_access_list_any(struct cmd_element *,struct vty *,int,char **);
06212   int no_ipv6_access_list_all(struct cmd_element *,struct vty *,int,char **);
06213   int ipv6_access_list_remark(struct cmd_element *,struct vty *,int,char **);
06214   int no_ipv6_access_list_remark(struct cmd_element *,struct vty *,int,char **);
06215   int show_ip_access_list(struct cmd_element *,struct vty *,int,char **);
06216   int show_ip_access_list_name(struct cmd_element *,struct vty *,int,char **);
06217   int show_ipv6_access_list(struct cmd_element *,struct vty *,int,char **);
06218   int show_ipv6_access_list_name(struct cmd_element *,struct vty *,int,char **);
06219   
06220   /*memory.c*/
06221   
06222   void zerror (const char *fname, int type, size_t size);
06223   void * zmalloc (int type, size_t size);
06224   void * zcalloc (int type, size_t size);
06225   void * zrealloc (int type, void *ptr, size_t size);
06226   void zfree (int type, void *ptr);
06227   char * zstrdup (int type, char *str);
06228   void mtype_log (char *func, void *memory, const char *file, int line, int type);
06229   void * mtype_zmalloc (const char *file, int line, int type, size_t size);
06230   void * mtype_zcalloc (const char *file, int line, int type, size_t size);
06231   void * mtype_zrealloc (const char *file, int line, int type, void *ptr, size_t size);
06232   void  mtype_zfree (const char *file, int line, int type, void *ptr);
06233   char * mtype_zstrdup (const char *file, int line, int type, char *str);
06234   void alloc_inc (int type);
06235   void alloc_dec (int type);
06236   void show_memory_vty(struct vty *vty, struct memory_list *llist);
06237   void memory_init ();
06238   int show_memory_all(struct cmd_element*,struct vty*,int, char **);
06239   int show_memory_lib(struct cmd_element *,struct vty *,int,char **);
06240   int show_memory_bgp(struct cmd_element *,struct vty *,int,char **);
06241  
06242   /*hash.c*/
06243 
06244   struct hash * hash_create (unsigned int (BGP::*hash_key) (void*), int (BGP::*hash_cmp) (void *,void*));
06245   void * hash_alloc_intern (void *arg);
06246   void * hash_get (struct hash *hash, void *data, void * (BGP::*alloc_func) (void*));
06247   void * hash_lookup (struct hash *hash, void *data);
06248   void * hash_release (struct hash *hash, void *data);
06249   void hash_iterate (struct hash *hash,void (BGP::*func) (struct hash_backet *, void *), void *arg);
06250   void hash_clean (struct hash *hash, void (BGP::*free_func) (void *));
06251   void hash_free (struct hash *hash);
06252 
06253   /*linklist.c*/
06254 
06255   struct llist * list_new ();
06256   void list_free (struct llist *l);
06257   struct listnode * listnode_new ();
06258   void listnode_free (struct listnode *node);
06259   void listnode_add (struct llist *, void *val);
06260   void listnode_add_sort (struct llist *, void *val);
06261   void listnode_add_after (struct llist *, struct listnode *pp, void *val);
06262   void listnode_delete (struct llist *, void *val);
06263   void * listnode_head (struct llist *);
06264   void list_delete_all_node (struct llist *);
06265   void list_delete (struct llist *);
06266   struct listnode * listnode_lookup (struct llist *, void *data);
06267   void list_delete_node (struct llist*,struct listnode* node);
06268   void list_add_node_prev (struct llist *, struct listnode *current, void *val);
06269   void list_add_node_next (struct llist* , struct listnode *current, void *val);
06270   void list_add_list (struct llist *l, struct llist *m);
06271 
06272   /*log.c*/
06273 
06274   void time_print (FILE *fp);
06275   void vzlog (struct zlog *zl, int priority, const char *format, va_list *args);
06276   void zlog (struct zlog *zl, int priority, const char *format, ...);
06277   void zlog_err (const char *format, ...);
06278   void zlog_warn (const char *format, ...);
06279   void zlog_info (const char *format, ...);
06280   void zlog_notice (const char *format, ...);
06281   void zlog_debug (const char *format, ...);
06282   void plog_err (struct zlog *zl, const char *format, ...);
06283   void plog_warn (struct zlog *zl, const char *format, ...);
06284   void plog_info (struct zlog *zl, const char *format, ...);
06285   void plog_notice (struct zlog *zl, const char *format, ...);
06286   void plog_debug (struct zlog *zl, const char *format, ...);
06287   struct zlog * openzlog (const char *progname, int flags, zlog_proto_t protocol,int syslog_flags, int syslog_facility);
06288   void closezlog (struct zlog *zl);
06289   void zlog_set_flag (struct zlog *zl, int flags);
06290   void zlog_reset_flag (struct zlog *zl, int flags);
06291   int zlog_set_file (struct zlog *zl, int flags, char *filename);
06292   int zlog_reset_file (struct zlog *zl);
06293   int zlog_rotate (struct zlog *zl);
06294   void zlog_save_cwd ();
06295   char * zlog_get_cwd ();
06296   void zlog_free_cwd ();
06297   char * lookup (struct message *mes, int key);
06298   char * mes_lookup (struct message *meslist, int max, int index);
06299 
06300 
06301 
06302   /*network.c*/
06303   
06304   int readn (int fd, char *ptr, int nbytes);
06305   int writen(int fd, char *ptr, int nbytes);
06306   
06307   
06308   /*plist.c*/
06309 
06310   struct prefix_master * prefix_master_get (afi_t afi);
06311   struct prefix_list * prefix_list_lookup (afi_t afi, char *name);
06312   struct prefix_list * prefix_list_new ();
06313   void prefix_list_free (struct prefix_list *plist);
06314   struct prefix_list_entry * prefix_list_entry_new ();
06315   void prefix_list_entry_free (struct prefix_list_entry *pentry);
06316   struct prefix_list * prefix_list_insert (afi_t afi, char *name);
06317   struct prefix_list * prefix_list_get (afi_t afi, char *name);
06318   void prefix_list_delete (struct prefix_list *plist);
06319   struct prefix_list_entry * prefix_list_entry_make (struct prefix *prefix, enum prefix_list_type type,int seq, int le, int ge, int any);
06320   void prefix_list_add_hook (void (BGP::*func) ());
06321   void prefix_list_delete_hook (void (BGP::*func) ());
06322   int prefix_new_seq_get (struct prefix_list *plist);
06323   struct prefix_list_entry * prefix_seq_check (struct prefix_list *plist, int seq);
06324   struct prefix_list_entry * prefix_list_entry_lookup (struct prefix_list *plist, struct prefix *prefix,enum prefix_list_type type, int seq, int le, int ge);
06325   void prefix_list_entry_delete (struct prefix_list *plist,struct prefix_list_entry *pentry ,int update_list);
06326   void prefix_list_entry_add (struct prefix_list *plist,struct prefix_list_entry *pentry);
06327   char * prefix_list_type_str (struct prefix_list_entry *pentry);
06328   int prefix_list_entry_match (struct prefix_list_entry *pentry, struct prefix *p);
06329   enum prefix_list_type prefix_list_apply (struct prefix_list *plist, void *object);
06330   void prefix_list_print (struct prefix_list *plist);
06331   struct prefix_list_entry * prefix_entry_dup_check (struct prefix_list *plist,struct prefix_list_entry *New);
06332   int vty_invalid_prefix_range (struct vty *vty, char *prefix);
06333   int vty_prefix_list_install (struct vty *vty, afi_t afi,char *name, char *seq, char *typestr,char *prefix, char *ge, char *le);
06334   int vty_prefix_list_uninstall (struct vty *vty, afi_t afi,char *name, char *seq, char *typestr,char *prefix, char *ge, char *le);
06335   int vty_prefix_list_desc_unset (struct vty *vty, afi_t afi, char *name);
06336   void vty_show_prefix_entry (struct vty *vty, afi_t afi, struct prefix_list *plist,struct prefix_master *master, enum display_type dtype,int seqnum);
06337   int vty_show_prefix_list (struct vty *vty, afi_t afi, char *name,char *seq, enum display_type dtype);
06338   int vty_show_prefix_list_prefix (struct vty *vty, afi_t afi, char *name,char *prefix, enum display_type type);
06339   int vty_clear_prefix_list (struct vty *vty, afi_t afi, char *name, char *prefix);
06340   int config_write_prefix_afi (afi_t afi, struct vty *vty);
06341   struct stream * prefix_bgp_orf_entry (struct stream *s, struct prefix_list *plist,u_char init_flag, u_char permit_flag, u_char deny_flag);
06342   int prefix_bgp_orf_set (char *name, afi_t afi, struct orf_prefix *orfp,int permit, int set);
06343   void prefix_bgp_orf_remove_all (char *name);
06344   int prefix_bgp_show_prefix_list (struct vty *vty, afi_t afi, char *name);
06345   void prefix_list_reset_orf ();
06346   int config_write_prefix_ipv4 (struct vty *vty);
06347   void prefix_list_reset_ipv4 ();
06348   void prefix_list_init_ipv4 ();
06349   int config_write_prefix_ipv6 (struct vty *vty);
06350   void prefix_list_reset_ipv6 ();
06351   void prefix_list_init_ipv6 ();
06352   void prefix_list_init ();
06353   void prefix_list_reset ();
06354 
06355 
06356   int ip_prefix_list(struct cmd_element *,struct vty *,int,char **);
06357   int ip_prefix_list_ge(struct cmd_element *,struct vty *,int,char **);
06358   int ip_prefix_list_ge_le(struct cmd_element *,struct vty *,int,char **);
06359   int ip_prefix_list_le(struct cmd_element *,struct vty *,int,char **);
06360   int ip_prefix_list_le_ge(struct cmd_element *,struct vty *,int,char **);
06361   int ip_prefix_list_seq(struct cmd_element *,struct vty *,int,char **);
06362   int ip_prefix_list_seq_ge(struct cmd_element *,struct vty *,int,char **);
06363   int ip_prefix_list_seq_ge_le(struct cmd_element *,struct vty *,int,char **);
06364   int ip_prefix_list_seq_le(struct cmd_element *,struct vty *,int,char **);
06365   int ip_prefix_list_seq_le_ge(struct cmd_element *,struct vty *,int,char **);
06366   int no_ip_prefix_list(struct cmd_element *,struct vty *,int,char **);
06367   int no_ip_prefix_list_prefix(struct cmd_element *,struct vty *,int,char **);
06368   int no_ip_prefix_list_ge(struct cmd_element *,struct vty *,int,char **);
06369   int no_ip_prefix_list_ge_le(struct cmd_element *,struct vty *,int,char **);
06370   int no_ip_prefix_list_le(struct cmd_element *,struct vty *,int,char **);
06371   int no_ip_prefix_list_le_ge(struct cmd_element *,struct vty *,int,char **);
06372   int no_ip_prefix_list_seq(struct cmd_element *,struct vty *,int,char **);
06373   int no_ip_prefix_list_seq_ge(struct cmd_element *,struct vty *,int,char **);
06374   int no_ip_prefix_list_seq_ge_le(struct cmd_element *,struct vty *,int,char **);
06375   int no_ip_prefix_list_seq_le(struct cmd_element *,struct vty *,int,char **);
06376   int no_ip_prefix_list_seq_le_ge(struct cmd_element *,struct vty *,int,char **);
06377   int ip_prefix_list_sequence_number(struct cmd_element *,struct vty *,int,char **);
06378   int no_ip_prefix_list_sequence_number(struct cmd_element *,struct vty *,int,char **);
06379   int ip_prefix_list_description(struct cmd_element *,struct vty *,int,char **);
06380   int no_ip_prefix_list_description(struct cmd_element *,struct vty *,int,char **);
06381   int show_ip_prefix_list(struct cmd_element *,struct vty *,int,char **);
06382   int show_ip_prefix_list_name(struct cmd_element *,struct vty *,int,char **);
06383   int show_ip_prefix_list_name_seq(struct cmd_element *,struct vty *,int,char **);
06384   int show_ip_prefix_list_prefix(struct cmd_element *,struct vty *,int,char **);
06385   int show_ip_prefix_list_prefix_longer(struct cmd_element *,struct vty *,int,char **);
06386   int show_ip_prefix_list_prefix_first_match(struct cmd_element *,struct vty *,int,char **);
06387   int show_ip_prefix_list_summary(struct cmd_element *,struct vty *,int,char **);
06388   int show_ip_prefix_list_summary_name(struct cmd_element *,struct vty *,int,char **);
06389   int show_ip_prefix_list_detail(struct cmd_element *,struct vty *,int,char **);
06390   int show_ip_prefix_list_detail_name(struct cmd_element *,struct vty *,int,char **);
06391   int clear_ip_prefix_list(struct cmd_element *,struct vty *,int,char **);
06392   int clear_ip_prefix_list_name(struct cmd_element *,struct vty *,int,char **);
06393   int clear_ip_prefix_list_name_prefix(struct cmd_element *,struct vty *,int,char **);
06394   int ipv6_prefix_list(struct cmd_element *,struct vty *,int,char **);
06395   int ipv6_prefix_list_ge(struct cmd_element *,struct vty *,int,char **);
06396   int ipv6_prefix_list_ge_le(struct cmd_element *,struct vty *,int,char **);
06397   int ipv6_prefix_list_le(struct cmd_element *,struct vty *,int,char **);
06398   int ipv6_prefix_list_le_ge(struct cmd_element *,struct vty *,int,char **);
06399   int ipv6_prefix_list_seq(struct cmd_element *,struct vty *,int,char **);
06400   int ipv6_prefix_list_seq_ge(struct cmd_element *,struct vty *,int,char **);
06401   int ipv6_prefix_list_seq_ge_le(struct cmd_element *,struct vty *,int,char **);
06402   int ipv6_prefix_list_seq_le(struct cmd_element *,struct vty *,int,char **);
06403   int ipv6_prefix_list_seq_le_ge(struct cmd_element *,struct vty *,int,char **);
06404   int no_ipv6_prefix_list(struct cmd_element *,struct vty *,int,char **);
06405   int no_ipv6_prefix_list_prefix(struct cmd_element *,struct vty *,int,char **);
06406   int no_ipv6_prefix_list_ge(struct cmd_element *,struct vty *,int,char **);
06407   int no_ipv6_prefix_list_ge_le(struct cmd_element *,struct vty *,int,char **);
06408   int no_ipv6_prefix_list_le(struct cmd_element *,struct vty *,int,char **);
06409   int no_ipv6_prefix_list_le_ge(struct cmd_element *,struct vty *,int,char **);
06410   int no_ipv6_prefix_list_seq(struct cmd_element *,struct vty *,int,char **);
06411   int no_ipv6_prefix_list_seq_ge(struct cmd_element *,struct vty *,int,char **);
06412   int no_ipv6_prefix_list_seq_ge_le(struct cmd_element *,struct vty *,int,char **);
06413   int no_ipv6_prefix_list_seq_le(struct cmd_element *,struct vty *,int,char **);
06414   int no_ipv6_prefix_list_seq_le_ge(struct cmd_element *,struct vty *,int,char **);
06415   int ipv6_prefix_list_sequence_number(struct cmd_element *,struct vty *,int,char **);
06416   int no_ipv6_prefix_list_sequence_number(struct cmd_element *,struct vty *,int,char **);
06417   int ipv6_prefix_list_description(struct cmd_element *,struct vty *,int,char **);
06418   int no_ipv6_prefix_list_description(struct cmd_element *,struct vty *,int,char **);
06419   int show_ipv6_prefix_list(struct cmd_element *,struct vty *,int,char **);
06420   int show_ipv6_prefix_list_name(struct cmd_element *,struct vty *,int,char **);
06421   int show_ipv6_prefix_list_name_seq(struct cmd_element *,struct vty *,int,char **);
06422   int show_ipv6_prefix_list_prefix(struct cmd_element *,struct vty *,int,char **);
06423   int show_ipv6_prefix_list_prefix_longer(struct cmd_element *,struct vty *,int,char **);
06424   int show_ipv6_prefix_list_prefix_first_match(struct cmd_element *,struct vty *,int,char **);
06425   int show_ipv6_prefix_list_summary(struct cmd_element *,struct vty *,int,char **);
06426   int show_ipv6_prefix_list_summary_name(struct cmd_element *,struct vty *,int,char **);
06427   int show_ipv6_prefix_list_detail(struct cmd_element *,struct vty *,int,char **);
06428   int show_ipv6_prefix_list_detail_name(struct cmd_element *,struct vty *,int,char **);
06429   int clear_ipv6_prefix_list(struct cmd_element *,struct vty *,int,char **);
06430   int clear_ipv6_prefix_list_name(struct cmd_element *,struct vty *,int,char **);
06431   int clear_ipv6_prefix_list_name_prefix(struct cmd_element *,struct vty *,int,char **);
06432   
06433   
06434 
06435   /*prefix.c*/
06436 
06437   int afi2family (int afi);
06438   int family2afi (int family);
06439   int prefix_match (struct prefix *n, struct prefix *p);
06440   void prefix_copy (struct prefix *dest, struct prefix *src);
06441   int prefix_same (struct prefix *p1, struct prefix *p2);
06442   int prefix_cmp (struct prefix *p1, struct prefix *p2);
06443   char * prefix_family_str (struct prefix *p);
06444   struct prefix_ipv4 * prefix_ipv4_new ();
06445   void prefix_ipv4_free (struct prefix_ipv4 *p);
06446   int str2prefix_ipv4 (char *str, struct prefix_ipv4 *p);
06447   void masklen2ip (int masklen, struct in_addr *netmask);
06448   u_char ip_masklen (struct in_addr netmask);
06449   void apply_mask_ipv4 (struct prefix_ipv4 *p);
06450   int prefix_ipv4_any (struct prefix_ipv4 *p);
06451   struct prefix_ipv6 * prefix_ipv6_new ();
06452   void prefix_ipv6_free (struct prefix_ipv6 *p);
06453   int str2prefix_ipv6 (char *str, struct prefix_ipv6 *p);
06454   int ip6_masklen (struct in6_addr netmask);
06455   void  masklen2ip6 (int masklen, struct in6_addr *netmask);
06456   void apply_mask_ipv6 (struct prefix_ipv6 *p);
06457   void str2in6_addr (char *str, struct in6_addr *addr);
06458   void apply_mask (struct prefix *p);
06459   struct prefix * sockunion2prefix (union sockunion *dest,union sockunion *mask);
06460   struct prefix * sockunion2hostprefix (union sockunion *su);
06461   int prefix_blen (struct prefix *p);
06462   int str2prefix (char *str, struct prefix *p);
06463   int prefix2str (struct prefix *p, char *str, int size);
06464   struct prefix * prefix_new ();
06465   void prefix_free (struct prefix *p);
06466   int all_digit (char *str);
06467   void apply_classful_mask_ipv4 (struct prefix_ipv4 *p);
06468   int netmask_str2prefix_str (char *net_str, char *mask_str, char *prefix_str);
06469   
06470 
06471   /*sockunion.c*/
06472 
06473   int inet_aton (const char *cp, struct in_addr *inaddr);
06474   int inet_pton (int family, const char *strptr, void *addrptr);
06475   const char * inet_ntop (int family, const void *addrptr, char *strptr, size_t len);
06476   const char * inet_sutop (union sockunion *su, char *str);
06477   int str2sockunion (char *str, union sockunion *su);
06478   const char * sockunion2str (union sockunion *su, char *buf, size_t len);
06479   union sockunion * sockunion_str2su (char *str);
06480   char * sockunion_su2str (union sockunion *su);
06481   int sockunion_sizeof (union sockunion *su);
06482   int sockunion_same (union sockunion *su1, union sockunion *su2);
06483   int in6addr_cmp (struct in6_addr *addr1, struct in6_addr *addr2);
06484   int sockunion_cmp (union sockunion *su1, union sockunion *su2);
06485   union sockunion * sockunion_dup (union sockunion *su);
06486   void sockunion_free (union sockunion *su);
06487 
06488 
06489   /*stream*/
06490 
06491   struct stream * stream_new (size_t size);
06492   void stream_free (struct stream *s);
06493   unsigned long stream_get_getp (struct stream *s);
06494   unsigned long stream_get_putp (struct stream *s);
06495   unsigned long stream_get_endp (struct stream *s);
06496   unsigned long stream_get_size (struct stream *s);
06497   void stream_set_getp (struct stream *s, unsigned long pos);
06498   void stream_set_putp (struct stream *s, unsigned long pos);
06499   void stream_forward (struct stream *s, int size);
06500   void stream_get (void *dst, struct stream *s, size_t size);
06501   u_char stream_getc (struct stream *s);
06502   u_char stream_getc_from (struct stream *s, unsigned long from);
06503   u_int16_t stream_getw (struct stream *s);
06504   u_int16_t stream_getw_from (struct stream *s, unsigned long from);
06505   u_int32_t stream_getl (struct stream *s);
06506   u_int32_t stream_get_ipv4 (struct stream *s);
06507   void stream_put (struct stream *s, void *src, size_t size);
06508   int stream_putc (struct stream *s, u_char c);
06509   int stream_putw (struct stream *s, u_int16_t w);
06510   int stream_putl (struct stream *s, u_int32_t l);
06511   int stream_putc_at (struct stream *s, unsigned long putp, u_char c);
06512   int stream_putw_at (struct stream *s, unsigned long putp, u_int16_t w);
06513   int stream_putl_at (struct stream *s, unsigned long putp, u_int32_t l);
06514   int stream_put_ipv4 (struct stream *s, u_int32_t l);
06515   int stream_put_in_addr (struct stream *s, struct in_addr *addr);
06516   int stream_put_prefix (struct stream *s, struct prefix *p);
06517   int stream_read (struct stream *s, int fd, size_t size);
06518   int stream_read_unblock (struct stream *s, size_t size,Data*);
06519   int stream_write (struct stream *s, u_char *ptr, size_t size);
06520   u_char * stream_pnt (struct stream *s);
06521   int stream_empty (struct stream *s);
06522   void stream_reset (struct stream *s);
06523   int stream_flush (struct stream *s, int fd);
06524   struct stream_fifo * stream_fifo_new ();
06525   void stream_fifo_push (struct stream_fifo *fifo, struct stream *s);
06526   struct stream * stream_fifo_pop (struct stream_fifo *fifo);
06527   struct stream * stream_fifo_head (struct stream_fifo *fifo);
06528   void stream_fifo_clean (struct stream_fifo *fifo);
06529   void stream_fifo_free (struct stream_fifo *fifo);
06530 
06531   
06532   /****table.c****/
06533 
06534   struct bgp_table * route_table_init (void);
06535   void route_table_finish (struct bgp_table *rt);
06536   struct bgp_node * route_node_new ();
06537   struct bgp_node * route_node_set (struct bgp_table *table, struct prefix *prefix);
06538   void route_node_free (struct bgp_node *node);
06539   void route_table_free (struct bgp_table *rt);
06540   void set_link (struct route_node *node, struct route_node *New);
06541   struct bgp_node * route_lock_node (struct bgp_node *node);
06542   void route_unlock_node (struct bgp_node *node);
06543   void route_dump_node (struct bgp_table *t);
06544   struct bgp_node * route_node_match (struct bgp_table *table, struct prefix *p);
06545   struct bgp_node * route_node_match_ipv4 (struct bgp_table *table, struct in_addr *addr);
06546   struct bgp_node * route_node_match_ipv6 (struct bgp_table *table, struct in6_addr *addr);
06547   struct bgp_node * route_node_lookup (struct bgp_table *table, struct prefix *p);
06548   struct bgp_node * route_node_get (struct bgp_table *table, struct prefix *p);
06549   void route_node_delete (struct bgp_node *node);
06550   struct bgp_node * route_top (struct bgp_table *table);
06551   struct bgp_node * route_next (struct bgp_node *node);
06552   struct bgp_node * route_next_until (struct bgp_node *node, struct bgp_node *limit);
06553   
06554   /******thread.c******/
06555 
06556   Time_t thread_timer_sub (Time_t a, Time_t b);
06557   unsigned long thread_timer_remain_second(struct thread*);
06558   int thread_timer_cmp (Time_t a, Time_t b);
06559   void thread_list_debug (struct thread_list *list);
06560   void thread_master_debug (struct thread_master *m);
06561   struct thread_master * thread_master_create ();
06562   void thread_list_add (struct thread_list *list, struct thread *thread);
06563   void thread_list_add_before (struct thread_list *list,struct thread *point,struct thread *thread);
06564   struct thread * thread_list_delete (struct thread_list *list, struct thread *thread);
06565   void thread_add_unuse (struct thread_master *m, struct thread *thread);
06566   void thread_list_free (struct thread_master *m, struct thread_list *list);
06567   void thread_master_free (struct thread_master *m);
06568   struct thread * thread_trim_head (struct thread_list *list);
06569   int thread_empty (struct thread_list *list);
06570   struct thread * thread_new(struct thread_master *m);
06571   struct thread * thread_get (struct thread_master *m, u_char type,int (BGP::*func) (struct thread *), void *arg);
06572   struct thread * thread_add_read (struct thread_master *m,int (BGP::*func) (struct thread *), void *arg, TCP* );
06573   struct thread * thread_add_ready (struct thread_master *m,int (BGP::*func) (struct thread *), void *arg);
06574   struct thread * thread_add_timer (struct thread_master *m,int (BGP::*func) (struct thread *), void *arg, long timer);
06575   struct thread * thread_add_event (struct thread_master *m,int (BGP::*func) (struct thread *), void *arg, int val);
06576   void thread_cancel (struct thread *thread);
06577   void thread_cancel_event (struct thread_master *m, void *arg);
06578   struct thread * thread_run (struct thread_master *m, struct thread *thread,struct thread *fetch);
06579   void thread_call (struct thread *thread);
06580   struct thread * thread_execute (struct thread_master *m,int (BGP::*func)(struct thread *),void *arg,int val);
06581   void thread_fetch_part1(struct thread_master *);
06582   void thread_fetch_part2(struct thread_master *,TCP*); 
06583   struct thread_master * thread_make_master();
06584 
06585   /*****vector.c*****/
06586   struct _vector* vector_init (unsigned int size);
06587   void vector_only_wrapper_free (struct _vector* v);
06588   void vector_only_index_free (void *index);
06589   void vector_free (struct _vector* v);
06590   struct _vector* vector_copy (struct _vector* v);
06591   void vector_ensure (struct _vector* v, unsigned int num);
06592   int vector_empty_slot (struct _vector* v);
06593   int vector_set (struct _vector* v, void *val);
06594   int vector_set_index (struct _vector* v, unsigned int i, void *val);
06595   void * vector_lookup (struct _vector* v, unsigned int i);
06596   void * vector_lookup_ensure (struct _vector* v, unsigned int i);
06597   void vector_unset (struct _vector* v, unsigned int i);
06598   unsigned int vector_count (struct _vector* v);
06599 
06600   /***vty.c****/
06601   int vty_out (struct vty *vty, const char *format, ...);
06602   void vty_log (const char *proto_str, const char *format, va_list va);
06603   int vty_shell (struct vty *vty);
06604   int vty_shell_serv (struct vty *vty);
06605   int vty_log_out (struct vty *vty, const char *proto_str, const char *format,va_list va);
06606   int time_str (char *buf);
06607   struct vty* vty_new();
06608   void vty_close(struct vty*);
06609   void vty_read_config();
06610   void vty_read_file(FILE *confp);
06611 
06612 #ifdef BGP_MRAI
06613   int bgp_advertise_insert(struct peer *peer,struct bgp_advertise *adv);
06614   void bgp_advertise_remove( struct peer *peer,struct bgp_advertise *rmv);
06615   void bgp_advertise_remove_by_prefix (struct peer *peer,struct prefix *p);
06616   void routeadv_list_add(struct peer *peer, struct thread *t);
06617   void routeadv_list_remove(struct peer *peer, struct thread *t);
06618   bool routeadv_list_search(struct peer *peer, struct prefix *p) ;
06619   int bgp_update_send_check (struct bgp_info *ri, struct peer_conf *conf, struct peer *peer,
06620                 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi,
06621                 struct peer *from, struct prefix_rd *prd, u_char *tag); 
06622   int bgp_withdraw_send_check(struct peer* peer,struct prefix *p);
06623 #endif  
06624 
06625   /*****bgp_vty.c*****/
06626 
06627   afi_t bgp_node_afi(struct vty *vty);
06628   safi_t bgp_node_safi(struct vty *vty);
06629   //int  peer_address_self_check (union sockunion *su);
06630   struct peer * peer_lookup_vty (struct vty *vty, char *ip_str);
06631   struct peer * peer_and_group_lookup_vty (struct vty *vty, char *peer_str);
06632   int bgp_vty_return (struct vty *vty, int ret);
06633   struct peer_conf* peer_conf_create(int,int,struct peer*);
06634   void peer_conf_active(int,int,struct peer_conf*);
06635   void peer_conf_deactive(int,int,struct peer_conf*);
06636   int peer_remote_as_vty (struct vty *vty, char *peer_str, char *as_str, afi_t afi,safi_t safi);
06637   int peer_flag_modify_vty (struct vty *vty, char *ip_str, u_int16_t flag, int set);
06638   int peer_flag_set_vty (struct vty *vty, char *ip_str, u_int16_t flag);
06639   int peer_af_flag_modify_vty (struct vty *vty, char *peer_str, afi_t afi,safi_t safi, u_int16_t flag, int set);
06640   int peer_af_flag_set_vty (struct vty *vty, char *peer_str, afi_t afi,safi_t safi, u_int16_t flag);
06641   int peer_af_flag_unset_vty (struct vty *vty, char *peer_str, afi_t afi,safi_t safi, u_int16_t flag);
06642   int peer_ebgp_multihop_set_vty (struct vty *vty, char *ip_str, char *ttl_str); 
06643   int peer_ebgp_multihop_unset_vty (struct vty *vty, char *ip_str) ;
06644   int peer_update_source_vty (struct vty *vty, char *peer_str, char *source_str); 
06645   int peer_default_originate_set_vty (struct vty *vty, char *peer_str, afi_t afi,safi_t safi, char *rmap, int set);
06646   int peer_port_vty (struct vty *vty, char *ip_str, int afi, char *port_str);
06647   int peer_advertise_interval_vty (struct vty *vty, char *ip_str, char *time_str,int set) ; 
06648 #ifdef BGP_MRAI
06649   void bgp_update_add_timestamp( struct peer* peer, struct prefix *p);
06650   void bgp_mrai_timers_off(struct peer *peer);
06651   void bgp_cancel_supressed_update_by_prefix(struct peer *peer,struct prefix* p);
06652   void bgp_cancel_timer_by_prefix(struct peer *peer,struct prefix* p);
06653   void aspath_delete(struct aspath *aspath);
06654 #endif
06655   int peer_version_vty (struct vty *vty, char *ip_str, char *str);
06656   int peer_interface_vty (struct vty *vty, char *ip_str, char *str);
06657   int peer_distribute_set_vty (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,char *name_str, char *direct_str); 
06658   int peer_distribute_unset_vty (struct vty *vty, char *ip_str, afi_t afi,safi_t safi, char *direct_str);
06659   int peer_prefix_list_set_vty (struct vty *vty, char *ip_str, afi_t afi,safi_t safi, char *name_str, char *direct_str);
06660   int peer_prefix_list_unset_vty (struct vty *vty, char *ip_str, afi_t afi,safi_t safi, char *direct_str);
06661   int peer_aslist_set_vty (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,char *name_str, char *direct_str);
06662   int peer_aslist_unset_vty (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,char *direct_str);
06663   int peer_route_map_set_vty (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,char *name_str, char *direct_str);
06664   int peer_route_map_unset_vty (struct vty *vty, char *ip_str, afi_t afi,safi_t safi, char *direct_str); 
06665   void community_list_show (struct vty *vty, struct community_list *llist);
06666   int peer_weight_set_vty (struct vty *vty, char *ip_str, char *weight_str);
06667   int peer_weight_unset_vty (struct vty *vty, char *ip_str);
06668   int peer_timers_set_vty (struct vty *vty, char *ip_str, char *keep_str,char *hold_str);
06669   int peer_timers_unset_vty (struct vty *vty, char *ip_str);
06670   int peer_timers_connect_set_vty (struct vty *vty, char *ip_str, char *time_str);
06671   int peer_timers_connect_unset_vty (struct vty *vty, char *ip_str);
06672   int extcommunity_list_set_vty (struct vty *vty, int argc, char **argv, int style, int reject_all_digit_name);
06673   int extcommunity_list_unset_all_vty (struct vty *vty, char *name);
06674   
06675   int bgp_multiple_instance_func(struct cmd_element *,struct vty *,int,char **);
06676   int no_bgp_multiple_instance(struct cmd_element *,struct vty *,int,char **);
06677   int bgp_config_type(struct cmd_element *,struct vty *,int,char **);
06678   int no_bgp_config_type(struct cmd_element *,struct vty *,int,char **);
06679   int no_synchronization(struct cmd_element *,struct vty *,int,char **);
06680   int no_auto_summary(struct cmd_element *,struct vty *,int,char **);
06681   int router_bgp(struct cmd_element *,struct vty *,int,char **); 
06682   int no_router_bgp(struct cmd_element *,struct vty *,int,char **);
06683   int bgp_router_id(struct cmd_element *,struct vty *,int,char **);
06684   int no_bgp_router_id(struct cmd_element *,struct vty *,int,char **);
06685   int bgp_cluster_id(struct cmd_element *,struct vty *,int,char **);
06686   int no_bgp_cluster_id(struct cmd_element *,struct vty *,int,char **);
06687   int bgp_confederation_identifier(struct cmd_element *,struct vty *,int,char **);
06688   int no_bgp_confederation_identifier(struct cmd_element *,struct vty *,int,char **);
06689   int bgp_confederation_peers(struct cmd_element *,struct vty *,int,char **);
06690   int no_bgp_confederation_peers(struct cmd_element *,struct vty *,int,char **);
06691   int bgp_timers(struct cmd_element *,struct vty *,int,char **);
06692   int no_bgp_timers(struct cmd_element *,struct vty *,int,char **);
06693   int bgp_client_to_client_reflection(struct cmd_element *,struct vty *,int,char **);
06694   int no_bgp_client_to_client_reflection(struct cmd_element *,struct vty *,int,char **);
06695   int bgp_always_compare_med(struct cmd_element *,struct vty *,int,char **);
06696   int no_bgp_always_compare_med(struct cmd_element *,struct vty *,int,char **);
06697   int bgp_deterministic_med(struct cmd_element *,struct vty *,int,char **);
06698   int no_bgp_deterministic_med(struct cmd_element *,struct vty *,int,char **);
06699   int bgp_fast_external_failover(struct cmd_element *,struct vty *,int,char **);
06700   int no_bgp_fast_external_failover(struct cmd_element *,struct