2004-09-13 Jose Luis Rubio <jrubio@dit.upm.es>
           (at Technical University of Madrid as part of Euro6ix Project)

        Enhanced Route Server functionality and Route-Maps:

        * bgpd/bgpd.h: Modified 'struct peer' and 'struct bgp_filter' to
        support rs-clients. A 'struct bgp_table *rib' has been added to the
        first (to mantain a separated RIB for each rs-client) and two new
        route-maps have been added to the last (for import/export policies).
        Added the following #defines: RMAP_{IN|OUT|IMPORT|EXPORT|MAX},
        PEER_RMAP_TYPE_{IMPORT|EXPORT} and BGP_CLEAR_SOFT_RSCLIENT.

        * bgpd/bgpd.c: Modified the functions that create/delete/etc peers in
        order to consider the new fields included in 'struct peer' for
        supporting rs-clients, i.e. the import/export route-maps and the
        'struct bgp_table'.

        * bgpd/bgp_route.{ch}: Modified several functions related with
        receiving/sending announces in order to support the new Route Server
        capabilities.
        Function 'bgp_process' has been reorganized, creating an auxiliar
        function for best path selection ('bgp_best_selection').
        Modified 'bgp_show' and 'bgp_show_route' for displaying information
        about any RIB (and not only the main bgp RIB).
        Added commands for displaying information about RS-clients RIBs:
        'show bgp rsclient (A.B.C.D|X:X::X:X)', 'show bgp rsclient
        (A.B.C.D|X:X::X:X) X:X::X:X/M', etc

        * bgpd/bgp_table.{ch}: The structure 'struct bgp_table' now has two
        new fields: type (which can take the values BGP_TABLE_{MAIN|RSCLIENT})
        and 'void *owner' which points to 'struct bgp' or 'struct peer' which
        owns the table.
        When creating a new bgp_table by default 'type=BGP_TABLE_MAIN' is set.

        * bgpd/bgp_vty.c: The commands 'neighbor ... route-server-client' and
        'no neighbor ... route-server-client' now not only set/unset the flag
        PEER_FLAG_RSERVER_CLIENT, but they create/destroy the 'struct
        bgp_table' of the peer. Special actions are taken for peer_groups.
        Command 'neighbor ... route-map WORD (in|out)' now also supports two
        new kinds of route-map: 'import' and 'export'.
        Added commands 'clear bgp * rsclient', etc. These commands allow a new
        kind of soft_reconfig which affects only the RIB of the specified
        RS-client.
        Added commands 'show bgp rsclient summary', etc which display a
        summary of the rs-clients configured for the corresponding address
        family.

        * bgpd/bgp_routemap.c: A new match statement is available,
        'match peer (A.B.C.D|X:X::X:X)'. This statement can only be used in
        import/export route-maps, and it matches when the peer who announces
        (when used in an import route-map) or is going to receive (when used
        in an export route-map) the route is the same than the one specified
        in the statement.
        For peer-groups the statement matches if the specified peer is member
        of the peer-group.
        A special version of the command, 'match peer local', matches with
        routes originated by the Route Server (defined with 'network ...',
        redistributed routes and default-originate).

        * lib/routemap.{ch}: Added a new clause 'call NAME' for use in
        route-maps. It jumps into the specified route-map and when it returns
        the first route-map ends if the called RM returns DENY_MATCH, or
        continues in other case.
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 818f7dc..61472d8 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -65,6 +65,9 @@
   /* BGP peer group.  */
   struct list *group;
 
+  /* BGP route-server-clients. */
+  struct list *rsclient;
+
   /* BGP configuration.  */
   u_int16_t config;
 #define BGP_CONFIG_ROUTER_ID              (1 << 0)
@@ -186,6 +189,12 @@
   u_char val[BGP_RD_SIZE];
 };
 
+#define RMAP_IN           0
+#define RMAP_OUT        1
+#define RMAP_IMPORT   2
+#define RMAP_EXPORT   3
+#define RMAP_MAX        4
+
 /* BGP filter structure. */
 struct bgp_filter
 {
@@ -215,7 +224,7 @@
   {
     char *name;
     struct route_map *map;
-  } map[FILTER_MAX];
+  } map[RMAP_MAX];
 
   /* Unsuppress-map.  */
   struct
@@ -250,6 +259,9 @@
   /* Local router ID. */
   struct in_addr local_id;
 
+  /* Peer specific RIB when configured as route-server-client. */
+  struct bgp_table *rib[AFI_MAX][SAFI_MAX];
+
   /* Packet receive and send buffer. */
   struct stream *ibuf;
   struct stream_fifo *obuf;
@@ -341,6 +353,7 @@
 #define PEER_FLAG_ORF_PREFIX_RM             (1 << 13) /* orf capability receive-mode */
 #define PEER_FLAG_MAX_PREFIX                (1 << 14) /* maximum prefix */
 #define PEER_FLAG_MAX_PREFIX_WARNING        (1 << 15) /* maximum prefix warning-only */
+#define PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED   (1 << 16) /* leave link-local nexthop unchanged */ 
 
   /* default-originate route-map.  */
   struct
@@ -480,6 +493,8 @@
 #define PEER_RMAP_TYPE_REDISTRIBUTE   (1 << 3) /* redistribute route-map */
 #define PEER_RMAP_TYPE_DEFAULT        (1 << 4) /* default-originate route-map */
 #define PEER_RMAP_TYPE_NOSET          (1 << 5) /* not allow to set commands */
+#define PEER_RMAP_TYPE_IMPORT         (1 << 6) /* neighbor route-map import */
+#define PEER_RMAP_TYPE_EXPORT         (1 << 7) /* neighbor route-map export */
 };
 
 /* This structure's member directly points incoming packet data
@@ -689,7 +704,8 @@
   BGP_CLEAR_SOFT_OUT,
   BGP_CLEAR_SOFT_IN,
   BGP_CLEAR_SOFT_BOTH,
-  BGP_CLEAR_SOFT_IN_ORF_PREFIX
+  BGP_CLEAR_SOFT_IN_ORF_PREFIX,
+  BGP_CLEAR_SOFT_RSCLIENT
 };
 
 /* Macros. */
@@ -797,6 +813,8 @@
 int bgp_default_local_preference_set (struct bgp *, u_int32_t);
 int bgp_default_local_preference_unset (struct bgp *);
 
+int peer_rsclient_active (struct peer *);
+
 int peer_remote_as (struct bgp *, union sockunion *, as_t *, afi_t, safi_t);
 int peer_group_remote_as (struct bgp *, char *, as_t *);
 int peer_delete (struct peer *peer);