osrg / gobgp

BGP implemented in the Go Programming Language
https://osrg.github.io/gobgp/
Apache License 2.0
3.66k stars 699 forks source link

Regular Expression not Matching with Community #2652

Open RajdeepMondal opened 1 year ago

RajdeepMondal commented 1 year ago

I have a the following router configuration at startup:

global:
  apply-policy:
    config:
      default-import-policy: reject-route
      import-policy-list:
      - example-policy
  config:
    as: 65001
    router-id: 192.2.3.4
neighbors:
- config:
    neighbor-address: 3.0.0.3
    peer-as: 65002
  transport:
    config:
      local-address: 3.0.0.2
defined-sets:
  bgp-defined-sets:
    community-sets:
      community-list:
      - ^0:1$
      community-set-name: c1
policy-definitions:
- name: example-policy
  statements:
  - actions:
      route-disposition: accept-route
    conditions:
      bgp-conditions:
        match-community-set:
          community-set: c1
          match-set-options: any
    name: statement1

With this configuration if I have incoming routes that have the communities [0:1 0:12] then they are matched against statement1 of example-policy. However, this should not be the case because ^0:1$ should only match against the community [0:1].

To reproduce:

  1. Create a network and peer an ExaBGP with GoBGP.
  2. Configure GoBGP with the configuration shown above.
  3. Announce the community through ExaBGP.

Expected behavior: The route must be denied.

RajdeepMondal commented 1 year ago

I also found that if I only give 0:1 in the regular expression, then it is converted to ^0:1$ internally. Also, the regex ^[10][10]?:[1-2][1-2] [20]:[1-2][1-2]$ does not match with [0:1 0:12].