Right now, we have 'neighbor-as' that can be used as magic syntax sugar for filter rules. I want to have magic syntax sugar for 'local-as', which expands to our ASN. It already plays nicely with the local-as diff I sent, and can be committed in either order.
match in from $neighbor set community local-as:neighbor-as ^^^^^^^^ OK? Index: bgpd.conf.5 =================================================================== RCS file: /cvs/openbsd/src/usr.sbin/bgpd/bgpd.conf.5,v retrieving revision 1.152 diff -u -p -u -p -r1.152 bgpd.conf.5 --- bgpd.conf.5 13 Jan 2017 18:59:12 -0000 1.152 +++ bgpd.conf.5 27 May 2017 10:12:23 -0000 @@ -1079,7 +1079,9 @@ is an AS number as explained above under .Sx GLOBAL CONFIGURATION . It may be set to .Ic neighbor-as , -which is expanded to the current neighbor remote AS number. +which is expanded to the current neighbor remote AS number, or +.Ic self-as , +which is expanded to the locally assigned AS number. .Pp The .Ar operator @@ -1149,7 +1151,9 @@ and .Ar local may be set to .Ic neighbor-as , -which is expanded to the current neighbor remote AS number. +which is expanded to the current neighbor remote AS number, or +.Ic self-as , +which is expanded to the locally assigned AS number. .Pp .It Xo .Ic large-community @@ -1181,7 +1185,9 @@ and .Ar local may be set to .Ic neighbor-as , -which is expanded to the current neighbor remote AS number. +which is expanded to the current neighbor remote AS number, +.Ic self-as , +which is expanded to the locally assigned AS number. .Pp .It Xo .Ic ext-community Index: bgpd.h =================================================================== RCS file: /cvs/openbsd/src/usr.sbin/bgpd/bgpd.h,v retrieving revision 1.300 diff -u -p -u -p -r1.300 bgpd.h --- bgpd.h 25 Jan 2017 00:11:07 -0000 1.300 +++ bgpd.h 27 May 2017 09:31:25 -0000 @@ -739,7 +739,8 @@ struct filter_peers { #define COMMUNITY_ERROR -1 #define COMMUNITY_ANY -2 #define COMMUNITY_NEIGHBOR_AS -3 -#define COMMUNITY_UNSET -4 +#define COMMUNITY_LOCAL_AS -4 +#define COMMUNITY_UNSET -5 #define COMMUNITY_WELLKNOWN 0xffff #define COMMUNITY_BLACKHOLE 0x029A /* draft-ymbk-grow-blackholing-01 */ #define COMMUNITY_NO_EXPORT 0xff01 Index: parse.y =================================================================== RCS file: /cvs/openbsd/src/usr.sbin/bgpd/parse.y,v retrieving revision 1.301 diff -u -p -u -p -r1.301 parse.y --- parse.y 26 May 2017 20:55:30 -0000 1.301 +++ parse.y 27 May 2017 09:30:58 -0000 @@ -2953,6 +2953,8 @@ getcommunity(char *s) return (COMMUNITY_ANY); if (strcmp(s, "neighbor-as") == 0) return (COMMUNITY_NEIGHBOR_AS); + if (strcmp(s, "local-as") == 0) + return (COMMUNITY_LOCAL_AS); val = strtonum(s, 0, USHRT_MAX, &errstr); if (errstr) { yyerror("Community %s is %s (max: %u)", s, errstr, USHRT_MAX); @@ -3022,6 +3024,8 @@ getlargecommunity(char *s) return (COMMUNITY_ANY); if (strcmp(s, "neighbor-as") == 0) return (COMMUNITY_NEIGHBOR_AS); + if (strcmp(s, "local-as") == 0) + return (COMMUNITY_LOCAL_AS); val = strtonum(s, 0, UINT_MAX, &errstr); if (errstr) { yyerror("Large Community %s is %s (max: %u)", Index: printconf.c =================================================================== RCS file: /cvs/openbsd/src/usr.sbin/bgpd/printconf.c,v retrieving revision 1.100 diff -u -p -u -p -r1.100 printconf.c --- printconf.c 24 Jan 2017 04:22:42 -0000 1.100 +++ printconf.c 27 May 2017 10:10:42 -0000 @@ -94,6 +94,8 @@ print_community(int as, int type) printf("*:"); else if (as == COMMUNITY_NEIGHBOR_AS) printf("neighbor-as:"); + else if (as == COMMUNITY_LOCAL_AS) + printf("local-as:"); else printf("%u:", (unsigned int)as); @@ -101,6 +103,8 @@ print_community(int as, int type) printf("* "); else if (type == COMMUNITY_NEIGHBOR_AS) printf("neighbor-as "); + else if (type == COMMUNITY_LOCAL_AS) + printf("local-as"); else printf("%d ", type); } @@ -112,6 +116,8 @@ print_largecommunity(int64_t as, int64_t printf("*:"); else if (as == COMMUNITY_NEIGHBOR_AS) printf("neighbor-as:"); + else if (as == COMMUNITY_LOCAL_AS) + printf("local-as:"); else printf("%lld:", as); @@ -119,6 +125,8 @@ print_largecommunity(int64_t as, int64_t printf("*:"); else if (ld1 == COMMUNITY_NEIGHBOR_AS) printf("neighbor-as:"); + else if (ld1 == COMMUNITY_LOCAL_AS) + printf("local-as:"); else printf("%lld:", ld1); @@ -126,6 +134,8 @@ print_largecommunity(int64_t as, int64_t printf("* "); else if (ld2 == COMMUNITY_NEIGHBOR_AS) printf("neighbor-as "); + else if (ld2 == COMMUNITY_LOCAL_AS) + printf("local-as "); else printf("%lld ", ld2); Index: rde_filter.c =================================================================== RCS file: /cvs/openbsd/src/usr.sbin/bgpd/rde_filter.c,v retrieving revision 1.80 diff -u -p -u -p -r1.80 rde_filter.c --- rde_filter.c 24 Jan 2017 04:22:42 -0000 1.80 +++ rde_filter.c 27 May 2017 10:09:21 -0000 @@ -139,6 +139,9 @@ rde_apply_set(struct rde_aspath *asp, st case COMMUNITY_NEIGHBOR_AS: as = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + as = peer->conf.local_as; + break; default: as = set->action.community.as; break; @@ -151,6 +154,9 @@ rde_apply_set(struct rde_aspath *asp, st case COMMUNITY_NEIGHBOR_AS: type = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + type = peer->conf.local_as; + break; default: type = set->action.community.type; break; @@ -165,6 +171,9 @@ rde_apply_set(struct rde_aspath *asp, st case COMMUNITY_NEIGHBOR_AS: as = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + as = peer->conf.local_as; + break; case COMMUNITY_ANY: default: as = set->action.community.as; @@ -177,6 +186,9 @@ rde_apply_set(struct rde_aspath *asp, st case COMMUNITY_NEIGHBOR_AS: type = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + type = peer->conf.local_as; + break; case COMMUNITY_ANY: default: type = set->action.community.type; @@ -192,6 +204,9 @@ rde_apply_set(struct rde_aspath *asp, st case COMMUNITY_NEIGHBOR_AS: las = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + las = peer->conf.local_as; + break; case COMMUNITY_ANY: default: las = set->action.large_community.as; @@ -204,6 +219,9 @@ rde_apply_set(struct rde_aspath *asp, st case COMMUNITY_NEIGHBOR_AS: ld1 = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + ld1 = peer->conf.local_as; + break; case COMMUNITY_ANY: default: ld1 = set->action.large_community.ld1; @@ -216,6 +234,9 @@ rde_apply_set(struct rde_aspath *asp, st case COMMUNITY_NEIGHBOR_AS: ld2 = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + ld2 = peer->conf.local_as; + break; case COMMUNITY_ANY: default: ld2 = set->action.large_community.ld2; @@ -231,6 +252,9 @@ rde_apply_set(struct rde_aspath *asp, st case COMMUNITY_NEIGHBOR_AS: las = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + las = peer->conf.local_as; + break; case COMMUNITY_ANY: default: las = set->action.large_community.as; @@ -243,6 +267,9 @@ rde_apply_set(struct rde_aspath *asp, st case COMMUNITY_NEIGHBOR_AS: ld1 = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + ld1 = peer->conf.local_as; + break; case COMMUNITY_ANY: default: ld1 = set->action.large_community.ld1; @@ -255,6 +282,9 @@ rde_apply_set(struct rde_aspath *asp, st case COMMUNITY_NEIGHBOR_AS: ld2 = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + ld2 = peer->conf.local_as; + break; case COMMUNITY_ANY: default: ld2 = set->action.large_community.ld2; @@ -329,6 +359,9 @@ rde_filter_match(struct filter_rule *f, case COMMUNITY_NEIGHBOR_AS: cas = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + cas = peer->conf.local_as; + break; default: cas = f->match.community.as; break; @@ -340,6 +373,9 @@ rde_filter_match(struct filter_rule *f, case COMMUNITY_NEIGHBOR_AS: type = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + type = peer->conf.local_as; + break; default: type = f->match.community.type; break; @@ -361,6 +397,9 @@ rde_filter_match(struct filter_rule *f, case COMMUNITY_NEIGHBOR_AS: las = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + las = peer->conf.local_as; + break; default: las = f->match.large_community.as; break; @@ -372,6 +411,9 @@ rde_filter_match(struct filter_rule *f, case COMMUNITY_NEIGHBOR_AS: ld1 = peer->conf.remote_as; break; + case COMMUNITY_LOCAL_AS: + ld1 = peer->conf.local_as; + break; default: ld1 = f->match.large_community.ld1; break; @@ -382,6 +424,9 @@ rde_filter_match(struct filter_rule *f, fatalx("rde_apply_set bad community string"); case COMMUNITY_NEIGHBOR_AS: ld2 = peer->conf.remote_as; + break; + case COMMUNITY_LOCAL_AS: + ld2 = peer->conf.local_as; break; default: ld2 = f->match.large_community.ld2; -- Time is an illusion; lunchtime, doubly so. -- Ford Prefect