bgpctl bits for RFC 9234 support.
authorclaudio <claudio@openbsd.org>
Mon, 27 Jun 2022 13:27:38 +0000 (13:27 +0000)
committerclaudio <claudio@openbsd.org>
Mon, 27 Jun 2022 13:27:38 +0000 (13:27 +0000)
OK tb@

usr.sbin/bgpctl/bgpctl.c
usr.sbin/bgpctl/output.c
usr.sbin/bgpctl/output_json.c

index 9c50ab6..f4857d1 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: bgpctl.c,v 1.278 2022/06/23 12:40:32 claudio Exp $ */
+/*     $OpenBSD: bgpctl.c,v 1.279 2022/06/27 13:27:38 claudio Exp $ */
 
 /*
  * Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -684,6 +684,8 @@ fmt_flags(uint8_t flags, int sum)
        if (sum) {
                if (flags & F_PREF_INVALID)
                        *p++ = 'E';
+               if (flags & F_PREF_OTC_LOOP)
+                       *p++ = 'L';
                if (flags & F_PREF_ANNOUNCE)
                        *p++ = 'A';
                if (flags & F_PREF_INTERNAL)
@@ -702,6 +704,10 @@ fmt_flags(uint8_t flags, int sum)
                else
                        strlcpy(buf, "external", sizeof(buf));
 
+               if (flags & F_PREF_INVALID)
+                       strlcat(buf, ", invalid", sizeof(buf));
+               if (flags & F_PREF_OTC_LOOP)
+                       strlcat(buf, ", otc loop", sizeof(buf));
                if (flags & F_PREF_STALE)
                        strlcat(buf, ", stale", sizeof(buf));
                if (flags & F_PREF_ELIGIBLE)
@@ -882,6 +888,10 @@ fmt_attr(uint8_t type, int flags)
                CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL);
                strlcpy(cstr, "Large Communities", sizeof(cstr));
                break;
+       case ATTR_OTC:
+               CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL);
+               strlcpy(cstr, "OTC", sizeof(cstr));
+               break;
        default:
                /* ignore unknown attributes */
                snprintf(cstr, sizeof(cstr), "Unknown Attribute #%u", type);
index d22e6d0..3a8e38b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: output.c,v 1.22 2022/06/22 14:49:51 claudio Exp $ */
+/*     $OpenBSD: output.c,v 1.23 2022/06/27 13:27:38 claudio Exp $ */
 
 /*
  * Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -325,7 +325,7 @@ show_neighbor_full(struct peer *p, struct parse_result *res)
        }
        if (hascapamp || hascapaap || p->capa.peer.grestart.restart ||
            p->capa.peer.refresh || p->capa.peer.enhanced_rr ||
-           p->capa.peer.as4byte) {
+           p->capa.peer.as4byte || p->capa.peer.role_ena) {
                printf("  Neighbor capabilities:\n");
                if (hascapamp)
                        show_neighbor_capa_mp(&p->capa.peer);
@@ -339,6 +339,10 @@ show_neighbor_full(struct peer *p, struct parse_result *res)
                        show_neighbor_capa_restart(&p->capa.peer);
                if (hascapaap)
                        show_neighbor_capa_add_path(&p->capa.peer);
+               if (p->capa.peer.role_ena)
+                       printf("    Open Policy role %s (local %s)\n",
+                           log_policy(p->capa.peer.role),
+                           log_policy(p->capa.ann.role));
        }
 
        hascapamp = 0;
@@ -351,7 +355,7 @@ show_neighbor_full(struct peer *p, struct parse_result *res)
        }
        if (hascapamp || hascapaap || p->capa.neg.grestart.restart ||
            p->capa.neg.refresh || p->capa.neg.enhanced_rr ||
-           p->capa.neg.as4byte) {
+           p->capa.neg.as4byte || p->capa.neg.role_ena) {
                printf("  Negotiated capabilities:\n");
                if (hascapamp)
                        show_neighbor_capa_mp(&p->capa.neg);
@@ -365,6 +369,10 @@ show_neighbor_full(struct peer *p, struct parse_result *res)
                        show_neighbor_capa_restart(&p->capa.neg);
                if (hascapaap)
                        show_neighbor_capa_add_path(&p->capa.neg);
+               if (p->capa.neg.role_ena)
+                       printf("    Open Policy role %s (local %s)\n",
+                           log_policy(p->capa.neg.role),
+                           log_policy(p->capa.ann.role));
        }
        printf("\n");
 
@@ -875,6 +883,15 @@ show_attr(u_char *data, size_t len, int reqflags, int addpath)
        case ATTR_LARGE_COMMUNITIES:
                show_large_community(data, alen);
                break;
+       case ATTR_OTC:
+               if (alen == 4) {
+                       memcpy(&as, data, sizeof(as));
+                       as = ntohl(as);
+                       printf("%s", log_as(as));
+               } else {
+                       printf("bad length");
+               }
+               break;
        case ATTR_ATOMIC_AGGREGATE:
        default:
                printf(" len %u", alen);
index 8e02a1e..78ff0eb 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: output_json.c,v 1.16 2022/06/22 14:49:51 claudio Exp $ */
+/*     $OpenBSD: output_json.c,v 1.17 2022/06/27 13:27:38 claudio Exp $ */
 
 /*
  * Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org>
@@ -125,6 +125,12 @@ json_neighbor_capabilities(struct capabilities *capa)
                json_do_end();
        }
 
+       if (capa->role_ena) {
+               json_do_printf("open_policy_role", "%s%s",
+                   log_policy(capa->role),
+                   capa->role_ena == 2 ? " enforce" : "");
+       }
+
        json_do_end();
 }
 
@@ -812,6 +818,14 @@ bad_len:
        case ATTR_LARGE_COMMUNITIES:
                json_do_large_community(data, alen);
                break;
+       case ATTR_OTC:
+               if (alen == 4) {
+                       memcpy(&as, data, sizeof(as));
+                       as = ntohl(as);
+                       json_do_uint("as", as);
+               } else
+                       json_do_printf("error", "bad length");
+               break;
        case ATTR_ATOMIC_AGGREGATE:
        default:
                if (alen)