Adjust ext community handling to support the generic transitive communities
authorclaudio <claudio@openbsd.org>
Fri, 21 Apr 2023 10:49:01 +0000 (10:49 +0000)
committerclaudio <claudio@openbsd.org>
Fri, 21 Apr 2023 10:49:01 +0000 (10:49 +0000)
introduced with flowspec.
OK tb@

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

index 91387b0..e1304a9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: bgpctl.c,v 1.292 2023/04/21 09:12:41 claudio Exp $ */
+/*     $OpenBSD: bgpctl.c,v 1.293 2023/04/21 10:49:01 claudio Exp $ */
 
 /*
  * Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -1051,6 +1051,7 @@ fmt_ext_community(uint8_t *data)
 
        switch (type) {
        case EXT_COMMUNITY_TRANS_TWO_AS:
+       case EXT_COMMUNITY_GEN_TWO_AS:
                memcpy(&as2, data + 2, sizeof(as2));
                memcpy(&u32, data + 4, sizeof(u32));
                snprintf(buf, sizeof(buf), "%s %s:%u",
@@ -1058,6 +1059,7 @@ fmt_ext_community(uint8_t *data)
                    log_as(ntohs(as2)), ntohl(u32));
                return buf;
        case EXT_COMMUNITY_TRANS_IPV4:
+       case EXT_COMMUNITY_GEN_IPV4:
                memcpy(&ip, data + 2, sizeof(ip));
                memcpy(&u16, data + 6, sizeof(u16));
                snprintf(buf, sizeof(buf), "%s %s:%hu",
@@ -1065,6 +1067,7 @@ fmt_ext_community(uint8_t *data)
                    inet_ntoa(ip), ntohs(u16));
                return buf;
        case EXT_COMMUNITY_TRANS_FOUR_AS:
+       case EXT_COMMUNITY_GEN_FOUR_AS:
                memcpy(&as4, data + 2, sizeof(as4));
                memcpy(&u16, data + 6, sizeof(u16));
                snprintf(buf, sizeof(buf), "%s %s:%hu",
@@ -1081,20 +1084,27 @@ fmt_ext_community(uint8_t *data)
        case EXT_COMMUNITY_NON_TRANS_OPAQUE:
                memcpy(&ext, data, sizeof(ext));
                ext = be64toh(ext) & 0xffffffffffffLL;
-               switch (ext) {
-               case EXT_COMMUNITY_OVS_VALID:
-                       snprintf(buf, sizeof(buf), "%s valid",
-                           log_ext_subtype(type, subtype));
-                       return buf;
-               case EXT_COMMUNITY_OVS_NOTFOUND:
-                       snprintf(buf, sizeof(buf), "%s not-found",
-                           log_ext_subtype(type, subtype));
-                       return buf;
-               case EXT_COMMUNITY_OVS_INVALID:
-                       snprintf(buf, sizeof(buf), "%s invalid",
-                           log_ext_subtype(type, subtype));
-                       return buf;
-               default:
+               if (subtype == EXT_COMMUNITY_SUBTYPE_OVS) {
+                       switch (ext) {
+                       case EXT_COMMUNITY_OVS_VALID:
+                               snprintf(buf, sizeof(buf), "%s valid",
+                                   log_ext_subtype(type, subtype));
+                               return buf;
+                       case EXT_COMMUNITY_OVS_NOTFOUND:
+                               snprintf(buf, sizeof(buf), "%s not-found",
+                                   log_ext_subtype(type, subtype));
+                               return buf;
+                       case EXT_COMMUNITY_OVS_INVALID:
+                               snprintf(buf, sizeof(buf), "%s invalid",
+                                   log_ext_subtype(type, subtype));
+                               return buf;
+                       default:
+                               snprintf(buf, sizeof(buf), "%s 0x%llx",
+                                   log_ext_subtype(type, subtype),
+                                   (unsigned long long)ext);
+                               return buf;
+                       }
+               } else {
                        snprintf(buf, sizeof(buf), "%s 0x%llx",
                            log_ext_subtype(type, subtype),
                            (unsigned long long)ext);
index a1bcb31..b12b363 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: output.c,v 1.39 2023/04/20 14:01:50 claudio Exp $ */
+/*     $OpenBSD: output.c,v 1.40 2023/04/21 10:49:01 claudio Exp $ */
 
 /*
  * Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -674,11 +674,10 @@ show_communities(u_char *data, size_t len, struct parse_result *res)
                        break;
                case COMMUNITY_TYPE_EXT:
                        ext = (uint64_t)c.data3 << 48;
-                       switch (c.data3 >> 8) {
+                       switch ((c.data3 >> 8) & EXT_COMMUNITY_VALUE) {
                        case EXT_COMMUNITY_TRANS_TWO_AS:
                        case EXT_COMMUNITY_TRANS_OPAQUE:
                        case EXT_COMMUNITY_TRANS_EVPN:
-                       case EXT_COMMUNITY_NON_TRANS_OPAQUE:
                                ext |= ((uint64_t)c.data1 & 0xffff) << 32;
                                ext |= (uint64_t)c.data2;
                                break;
index 3a70291..6e62301 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: output_json.c,v 1.31 2023/03/28 12:07:09 claudio Exp $ */
+/*     $OpenBSD: output_json.c,v 1.32 2023/04/21 10:49:01 claudio Exp $ */
 
 /*
  * Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org>
@@ -495,11 +495,10 @@ json_communities(u_char *data, size_t len, struct parse_result *res)
                        break;
                case COMMUNITY_TYPE_EXT:
                        ext = (uint64_t)c.data3 << 48;
-                       switch (c.data3 >> 8) {
+                       switch ((c.data3 >> 8) & EXT_COMMUNITY_VALUE) {
                        case EXT_COMMUNITY_TRANS_TWO_AS:
                        case EXT_COMMUNITY_TRANS_OPAQUE:
                        case EXT_COMMUNITY_TRANS_EVPN:
-                       case EXT_COMMUNITY_NON_TRANS_OPAQUE:
                                ext |= ((uint64_t)c.data1 & 0xffff) << 32;
                                ext |= (uint64_t)c.data2;
                                break;
index defe910..ff16473 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: parser.c,v 1.131 2023/04/21 09:12:41 claudio Exp $ */
+/*     $OpenBSD: parser.c,v 1.132 2023/04/21 10:49:01 claudio Exp $ */
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -741,7 +741,7 @@ match_token(int argc, char *argv[], const struct token table[], int *argsused)
                                        rd |= ((uint64_t)ext.data1 & 0xffff)
                                            << 32;
                                        rd |= (uint64_t)ext.data2;
-                               break;
+                                       break;
                                case EXT_COMMUNITY_TRANS_IPV4:
                                        rd = (1ULL << 48);
                                        rd |= (uint64_t)ext.data1 << 16;
@@ -1298,7 +1298,7 @@ parseextvalue(int type, char *s, uint32_t *v, uint32_t *flag)
                type = EXT_COMMUNITY_TRANS_IPV4;
        }
 
-       switch (type) {
+       switch (type & EXT_COMMUNITY_VALUE) {
        case EXT_COMMUNITY_TRANS_TWO_AS:
                uval = strtonum(s, 0, USHRT_MAX, &errstr);
                if (errstr)
@@ -1355,6 +1355,9 @@ parseextcommunity(struct community *c, const char *t, char *s)
        case EXT_COMMUNITY_TRANS_TWO_AS:
        case EXT_COMMUNITY_TRANS_FOUR_AS:
        case EXT_COMMUNITY_TRANS_IPV4:
+       case EXT_COMMUNITY_GEN_TWO_AS:
+       case EXT_COMMUNITY_GEN_FOUR_AS:
+       case EXT_COMMUNITY_GEN_IPV4:
        case -1:
                if (strcmp(s, "*") == 0) {
                        dflag1 = COMMUNITY_ANY;
@@ -1367,10 +1370,13 @@ parseextcommunity(struct community *c, const char *t, char *s)
 
                switch (type) {
                case EXT_COMMUNITY_TRANS_TWO_AS:
+               case EXT_COMMUNITY_GEN_TWO_AS:
                        getcommunity(p, 1, &uval2, &dflag2);
                        break;
                case EXT_COMMUNITY_TRANS_IPV4:
                case EXT_COMMUNITY_TRANS_FOUR_AS:
+               case EXT_COMMUNITY_GEN_IPV4:
+               case EXT_COMMUNITY_GEN_FOUR_AS:
                        getcommunity(p, 0, &uval2, &dflag2);
                        break;
                default: