]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: Implement BGP dual-as feature
authorDonatas Abraitis <donatas@opensourcerouting.org>
Fri, 13 Sep 2024 07:51:41 +0000 (10:51 +0300)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Fri, 13 Sep 2024 07:51:41 +0000 (10:51 +0300)
This is helpful for migrations, etc.

The neighbor is configured with:

```
router bgp 65000
 neighbor X local-as 65001 no-prepend replace-as dual-as
```

Neighbor X can use either 65000, or 65001 to peer with.

Closes: https://github.com/FRRouting/frr/issues/13928
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
bgpd/bgp_packet.c
bgpd/bgp_updgrp.c
bgpd/bgp_vty.c
bgpd/bgpd.c
bgpd/bgpd.h

index fa03f1d21de5e49100b4deec45abfe32c02a1c09..62be7ffbf73344b901d22a785e1d77079a7f0195 100644 (file)
@@ -2702,6 +2702,19 @@ static int bgp_notify_receive(struct peer_connection *connection,
            inner.subcode == BGP_NOTIFY_OPEN_UNSUP_PARAM)
                UNSET_FLAG(peer->sflags, PEER_STATUS_CAPABILITY_OPEN);
 
+       /* Resend the next OPEN message with a global AS number if we received
+        * a `Bad Peer AS` notification. This is only valid if `dual-as` is
+        * configured.
+        */
+       if (inner.code == BGP_NOTIFY_OPEN_ERR &&
+           inner.subcode == BGP_NOTIFY_OPEN_BAD_PEER_AS &&
+           CHECK_FLAG(peer->flags, PEER_FLAG_DUAL_AS)) {
+               if (peer->change_local_as != peer->bgp->as)
+                       peer->change_local_as = peer->bgp->as;
+               else
+                       peer->change_local_as = peer->local_as;
+       }
+
        /* If Graceful-Restart N-bit (Notification) is exchanged,
         * and it's not a Hard Reset, let's retain the routes.
         */
index 115bc35cdcad695846122cd9e368a23f2964ca8c..90c43b938ffd09d384262d7c3efc7b9c69a3e0ab 100644 (file)
@@ -783,8 +783,11 @@ static int update_group_show_walkcb(struct update_group *updgrp, void *arg)
                                json_updgrp, "replaceLocalAs",
                                CHECK_FLAG(updgrp->conf->flags,
                                           PEER_FLAG_LOCAL_AS_REPLACE_AS));
+                       json_object_boolean_add(json_updgrp, "dualAs",
+                                               CHECK_FLAG(updgrp->conf->flags,
+                                                          PEER_FLAG_DUAL_AS));
                } else {
-                       vty_out(vty, "  Local AS %u%s%s\n",
+                       vty_out(vty, "  Local AS %u%s%s%s\n",
                                updgrp->conf->change_local_as,
                                CHECK_FLAG(updgrp->conf->flags,
                                           PEER_FLAG_LOCAL_AS_NO_PREPEND)
@@ -793,6 +796,10 @@ static int update_group_show_walkcb(struct update_group *updgrp, void *arg)
                                CHECK_FLAG(updgrp->conf->flags,
                                           PEER_FLAG_LOCAL_AS_REPLACE_AS)
                                        ? " replace-as"
+                                       : "",
+                               CHECK_FLAG(updgrp->conf->flags,
+                                          PEER_FLAG_DUAL_AS)
+                                       ? " dual-as"
                                        : "");
                }
        }
index f669564bb84dab70760735f4f4a5ba7a78c3d909..cf4269eb66ee0f0ef5caa4e3f40c2c7c4baf09de 100644 (file)
@@ -5451,7 +5451,7 @@ DEFUN (neighbor_local_as,
                return CMD_WARNING_CONFIG_FAILED;
        }
 
-       ret = peer_local_as_set(peer, as, 0, 0, argv[idx_number]->arg);
+       ret = peer_local_as_set(peer, as, 0, 0, 0, argv[idx_number]->arg);
        return bgp_vty_return(vty, ret);
 }
 
@@ -5480,19 +5480,20 @@ DEFUN (neighbor_local_as_no_prepend,
                return CMD_WARNING_CONFIG_FAILED;
        }
 
-       ret = peer_local_as_set(peer, as, 1, 0, argv[idx_number]->arg);
+       ret = peer_local_as_set(peer, as, 1, 0, 0, argv[idx_number]->arg);
        return bgp_vty_return(vty, ret);
 }
 
-DEFUN (neighbor_local_as_no_prepend_replace_as,
+DEFPY (neighbor_local_as_no_prepend_replace_as,
        neighbor_local_as_no_prepend_replace_as_cmd,
-       "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend replace-as",
+       "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend replace-as [dual-as$dual_as]",
        NEIGHBOR_STR
        NEIGHBOR_ADDR_STR2
        "Specify a local-as number\n"
        "AS number expressed in dotted or plain format used as local AS\n"
        "Do not prepend local-as to updates from ebgp peers\n"
-       "Do not prepend local-as to updates from ibgp peers\n")
+       "Do not prepend local-as to updates from ibgp peers\n"
+       "Allow peering with a global AS number or local-as number\n")
 {
        int idx_peer = 1;
        int idx_number = 3;
@@ -5510,20 +5511,21 @@ DEFUN (neighbor_local_as_no_prepend_replace_as,
                return CMD_WARNING_CONFIG_FAILED;
        }
 
-       ret = peer_local_as_set(peer, as, 1, 1, argv[idx_number]->arg);
+       ret = peer_local_as_set(peer, as, 1, 1, dual_as, argv[idx_number]->arg);
        return bgp_vty_return(vty, ret);
 }
 
 DEFUN (no_neighbor_local_as,
        no_neighbor_local_as_cmd,
-       "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [ASNUM [no-prepend [replace-as]]]",
+       "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [ASNUM [no-prepend [replace-as] [dual-as]]]",
        NO_STR
        NEIGHBOR_STR
        NEIGHBOR_ADDR_STR2
        "Specify a local-as number\n"
        "AS number expressed in dotted or plain format used as local AS\n"
        "Do not prepend local-as to updates from ebgp peers\n"
-       "Do not prepend local-as to updates from ibgp peers\n")
+       "Do not prepend local-as to updates from ibgp peers\n"
+       "Allow peering with a global AS number or local-as number\n")
 {
        int idx_peer = 2;
        struct peer *peer;
@@ -14052,6 +14054,10 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
                if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
                        json_object_boolean_true_add(json_neigh,
                                                     "localAsReplaceAs");
+
+               json_object_boolean_add(json_neigh, "localAsReplaceAsDualAs",
+                                       !!CHECK_FLAG(p->flags,
+                                                    PEER_FLAG_DUAL_AS));
        } else {
                if (p->as_type == AS_SPECIFIED ||
                    CHECK_FLAG(p->as_type, AS_AUTO) ||
@@ -14066,13 +14072,15 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
                vty_out(vty, ASN_FORMAT(bgp->asnotation),
                        p->change_local_as ? &p->change_local_as
                                           : &p->local_as);
-               vty_out(vty, "%s%s, ",
+               vty_out(vty, "%s%s%s, ",
                        CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
                                ? " no-prepend"
                                : "",
                        CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
                                ? " replace-as"
-                               : "");
+                               : "",
+                       CHECK_FLAG(p->flags, PEER_FLAG_DUAL_AS) ? " dual-as"
+                                                               : "");
        }
        /* peer type internal or confed-internal */
        if ((p->as == p->local_as) || (CHECK_FLAG(p->as_type, AS_INTERNAL))) {
@@ -18664,6 +18672,8 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
                        vty_out(vty, " no-prepend");
                if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
                        vty_out(vty, " replace-as");
+               if (peergroup_flag_check(peer, PEER_FLAG_DUAL_AS))
+                       vty_out(vty, " dual-as");
                vty_out(vty, "\n");
        }
 
index 9d36ed90080d712455e7c4a859d09a22f6d06d53..1108b82f4e0038cdeb7c1c3dee720c6f8f0920f5 100644 (file)
@@ -4696,6 +4696,7 @@ static const struct peer_flag_action peer_flag_action_list[] = {
        {PEER_FLAG_LOCAL_AS, 0, peer_change_reset},
        {PEER_FLAG_LOCAL_AS_NO_PREPEND, 0, peer_change_reset},
        {PEER_FLAG_LOCAL_AS_REPLACE_AS, 0, peer_change_reset},
+       {PEER_FLAG_DUAL_AS, 0, peer_change_reset},
        {PEER_FLAG_UPDATE_SOURCE, 0, peer_change_none},
        {PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE, 0, peer_change_none},
        {PEER_FLAG_EXTENDED_OPT_PARAMS, 0, peer_change_reset},
@@ -6638,9 +6639,9 @@ int peer_allowas_in_unset(struct peer *peer, afi_t afi, safi_t safi)
 }
 
 int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend,
-                     bool replace_as, const char *as_str)
+                     bool replace_as, bool dual_as, const char *as_str)
 {
-       bool old_no_prepend, old_replace_as;
+       bool old_no_prepend, old_replace_as, old_dual_as;
        struct bgp *bgp = peer->bgp;
        struct peer *member;
        struct listnode *node, *nnode;
@@ -6653,14 +6654,16 @@ int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend,
                !!CHECK_FLAG(peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND);
        old_replace_as =
                !!CHECK_FLAG(peer->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS);
+       old_dual_as = !!CHECK_FLAG(peer->flags, PEER_FLAG_DUAL_AS);
 
        /* Set flag and configuration on peer. */
        peer_flag_set(peer, PEER_FLAG_LOCAL_AS);
        peer_flag_modify(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND, no_prepend);
        peer_flag_modify(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS, replace_as);
+       peer_flag_modify(peer, PEER_FLAG_DUAL_AS, dual_as);
 
-       if (peer->change_local_as == as && old_no_prepend == no_prepend
-           && old_replace_as == replace_as)
+       if (peer->change_local_as == as && old_no_prepend == no_prepend &&
+           old_replace_as == replace_as && old_dual_as == dual_as)
                return 0;
        peer->change_local_as = as;
        if (as_str) {
@@ -6689,10 +6692,11 @@ int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend,
                                            PEER_FLAG_LOCAL_AS_NO_PREPEND);
                old_replace_as = CHECK_FLAG(member->flags,
                                            PEER_FLAG_LOCAL_AS_REPLACE_AS);
-               if (member->change_local_as == as
-                   && CHECK_FLAG(member->flags, PEER_FLAG_LOCAL_AS)
-                   && old_no_prepend == no_prepend
-                   && old_replace_as == replace_as)
+               old_dual_as = !!CHECK_FLAG(member->flags, PEER_FLAG_DUAL_AS);
+               if (member->change_local_as == as &&
+                   CHECK_FLAG(member->flags, PEER_FLAG_LOCAL_AS) &&
+                   old_no_prepend == no_prepend &&
+                   old_replace_as == replace_as && old_dual_as == dual_as)
                        continue;
 
                /* Set flag and configuration on peer-group member. */
@@ -6701,6 +6705,7 @@ int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend,
                          no_prepend);
                COND_FLAG(member->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS,
                          replace_as);
+               COND_FLAG(member->flags, PEER_FLAG_DUAL_AS, dual_as);
                member->change_local_as = as;
                if (as_str)
                        member->change_local_as_pretty = XSTRDUP(MTYPE_BGP_NAME,
@@ -6723,12 +6728,14 @@ int peer_local_as_unset(struct peer *peer)
                peer_flag_inherit(peer, PEER_FLAG_LOCAL_AS);
                peer_flag_inherit(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND);
                peer_flag_inherit(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS);
+               peer_flag_inherit(peer, PEER_FLAG_DUAL_AS);
                PEER_ATTR_INHERIT(peer, peer->group, change_local_as);
        } else {
                /* Otherwise remove flag and configuration from peer. */
                peer_flag_unset(peer, PEER_FLAG_LOCAL_AS);
                peer_flag_unset(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND);
                peer_flag_unset(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS);
+               peer_flag_unset(peer, PEER_FLAG_DUAL_AS);
                peer->change_local_as = 0;
                XFREE(MTYPE_BGP_NAME, peer->change_local_as_pretty);
        }
@@ -6760,6 +6767,7 @@ int peer_local_as_unset(struct peer *peer)
                UNSET_FLAG(member->flags, PEER_FLAG_LOCAL_AS);
                UNSET_FLAG(member->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND);
                UNSET_FLAG(member->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS);
+               UNSET_FLAG(member->flags, PEER_FLAG_DUAL_AS);
                member->change_local_as = 0;
                XFREE(MTYPE_BGP_NAME, member->change_local_as_pretty);
                member->last_reset = PEER_DOWN_LOCAL_AS_CHANGE;
index def12ee642da0801c3c88e1569a53b0ff1310770..795e4fbc58d3f219c58dce2cdc4b13f60c958e53 100644 (file)
@@ -1507,6 +1507,7 @@ struct peer {
 #define PEER_FLAG_CAPABILITY_FQDN (1ULL << 37)  /* fqdn capability */
 #define PEER_FLAG_AS_LOOP_DETECTION (1ULL << 38) /* as path loop detection */
 #define PEER_FLAG_EXTENDED_LINK_BANDWIDTH (1ULL << 39)
+#define PEER_FLAG_DUAL_AS                (1ULL << 40)
 
        /*
         *GR-Disabled mode means unset PEER_FLAG_GRACEFUL_RESTART
@@ -2443,7 +2444,7 @@ extern int peer_allowas_in_set(struct peer *, afi_t, safi_t, int, int);
 extern int peer_allowas_in_unset(struct peer *, afi_t, safi_t);
 
 extern int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend,
-                            bool replace_as, const char *as_str);
+                            bool replace_as, bool dual_as, const char *as_str);
 extern int peer_local_as_unset(struct peer *);
 
 extern int peer_prefix_list_set(struct peer *, afi_t, safi_t, int,