]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
BGP: Allow exchanging LOCAL_PREF with eBGP peers
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Thu, 23 Feb 2017 15:32:07 +0000 (16:32 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Thu, 23 Feb 2017 15:32:07 +0000 (16:32 +0100)
Adds option 'allow bgp_local_pref' to override the usual restriction of
LOCAL_PREF on eBGP sessions.

Thanks to Lennert Buytenhek for the patch.

doc/bird.sgml
proto/bgp/attrs.c
proto/bgp/bgp.h
proto/bgp/config.Y

index 11fe21900cc67113b6a4a91236759c8bf1c4b32b..dd4472aee04f482718e97130302773ef1a3a2e48 100644 (file)
@@ -2043,6 +2043,14 @@ using the following configuration parameters:
        TX direction. When active, all available routes accepted by the export
        filter are advertised to the neighbor. Default: off.
 
+       <tag><label id="bgp-allow-local-pref">allow bgp_local_pref <m/switch/</tag>
+       A standard BGP implementation do not send the Local Preference attribute
+       to eBGP neighbors and ignore this attribute if received from eBGP
+       neighbors, as per <rfc id="4271">.  When this option is enabled on an
+       eBGP session, this attribute will be sent to and accepted from the peer,
+       which is useful for example if you have a setup like in <rfc id="7938">.
+       The option does not affect iBGP sessions. Default: off.
+
        <tag><label id="bgp-allow-local-as">allow local as [<m/number/]</tag>
        BGP prevents routing loops by rejecting received routes with the local
        AS number in the AS path. This option allows to loose or disable the
index 2b0a92dcad712dbf28544e6777105ee1ce7f4639..b9e2490dc65cfc10b3c82e47bc4ee0682bdafa2a 100644 (file)
@@ -306,7 +306,7 @@ static struct attr_desc bgp_attr_table[] = {
     bgp_check_next_hop, bgp_format_next_hop },
   { "med", 4, BAF_OPTIONAL, EAF_TYPE_INT, 1,                                   /* BA_MULTI_EXIT_DISC */
     NULL, NULL },
-  { "local_pref", 4, BAF_TRANSITIVE, EAF_TYPE_INT, 0,                          /* BA_LOCAL_PREF */
+  { "local_pref", 4, BAF_TRANSITIVE, EAF_TYPE_INT, 1,                          /* BA_LOCAL_PREF */
     NULL, NULL },
   { "atomic_aggr", 0, BAF_TRANSITIVE, EAF_TYPE_OPAQUE, 1,                      /* BA_ATOMIC_AGGR */
     NULL, NULL },
@@ -821,8 +821,13 @@ bgp_get_bucket(struct bgp_proto *p, net *n, ea_list *attrs, int originate)
       code = EA_ID(a->id);
       if (ATTR_KNOWN(code))
        {
-         if (!bgp_attr_table[code].allow_in_ebgp && !p->is_internal)
-           continue;
+         if (!p->is_internal)
+           {
+             if (!bgp_attr_table[code].allow_in_ebgp)
+               continue;
+             if ((code == BA_LOCAL_PREF) && !p->cf->allow_local_pref)
+               continue;
+           }
          /* The flags might have been zero if the attr was added by filters */
          a->flags = (a->flags & BAF_PARTIAL) | bgp_attr_table[code].expected_flags;
          if (code < 32)
@@ -1776,8 +1781,13 @@ bgp_decode_attrs(struct bgp_conn *conn, byte *attr, uint len, struct linpool *po
            { errcode = 5; goto err; }
          if ((desc->expected_flags ^ flags) & (BAF_OPTIONAL | BAF_TRANSITIVE))
            { errcode = 4; goto err; }
-         if (!desc->allow_in_ebgp && !bgp->is_internal)
-           continue;
+         if (!bgp->is_internal)
+           {
+             if (!desc->allow_in_ebgp)
+               continue;
+             if ((code == BA_LOCAL_PREF) && !bgp->cf->allow_local_pref)
+               continue;
+           }
          if (desc->validate)
            {
              errcode = desc->validate(bgp, z, l);
index bf9335543b8c4880e78db5b3d3edc54b023a3586..e47a0eb1d8c894bc35afd878a58c5724aa68877c 100644 (file)
@@ -50,6 +50,7 @@ struct bgp_config {
   int secondary;                       /* Accept also non-best routes (i.e. RA_ACCEPTED) */
   int add_path;                                /* Use ADD-PATH extension [RFC7911] */
   int allow_local_as;                  /* Allow that number of local ASNs in incoming AS_PATHs */
+  int allow_local_pref;                        /* Allow LOCAL_PREF in EBGP sessions */
   int gr_mode;                         /* Graceful restart mode (BGP_GR_*) */
   int setkey;                          /* Set MD5 password to system SA/SP database */
   unsigned gr_time;                    /* Graceful restart timeout */
index 32ae88a3d83623ce1962d0743634fcb727d557f6..55c602f1e80121177de323b8fee27e2f128a75cf 100644 (file)
@@ -126,6 +126,7 @@ bgp_proto:
  | bgp_proto ADD PATHS RX ';' { BGP_CFG->add_path = ADD_PATH_RX; }
  | bgp_proto ADD PATHS TX ';' { BGP_CFG->add_path = ADD_PATH_TX; }
  | bgp_proto ADD PATHS bool ';' { BGP_CFG->add_path = $4 ? ADD_PATH_FULL : 0; }
+ | bgp_proto ALLOW BGP_LOCAL_PREF bool ';' { BGP_CFG->allow_local_pref = $4; }
  | bgp_proto ALLOW LOCAL AS ';' { BGP_CFG->allow_local_as = -1; }
  | bgp_proto ALLOW LOCAL AS expr ';' { BGP_CFG->allow_local_as = $5; }
  | bgp_proto GRACEFUL RESTART bool ';' { BGP_CFG->gr_mode = $4; }