-
Notifications
You must be signed in to change notification settings - Fork 1.5k
BGP "Allow list" feature implementation #4563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BGP "Allow list" feature implementation #4563
Conversation
This pull request introduces 2 alerts and fixes 2 when merging 57afc49 into ceb8784 - view on LGTM.com new alerts:
fixed alerts:
|
This pull request introduces 2 alerts and fixes 2 when merging 9f5209e into 8d20030 - view on LGTM.com new alerts:
fixed alerts:
|
@@ -93,6 +125,8 @@ class BGPConfigManager(object): | |||
daemon.add_manager(swsscommon.CONFIG_DB, swsscommon.CFG_DEVICE_NEIGHBOR_METADATA_TABLE_NAME, self.__neighbor_metadata_handler) | |||
daemon.add_manager(swsscommon.CONFIG_DB, swsscommon.CFG_BGP_NEIGHBOR_TABLE_NAME, self.__bgp_handler) | |||
daemon.add_manager(swsscommon.STATE_DB, swsscommon.STATE_INTERFACE_TABLE_NAME, self.__if_handler) | |||
if g_allow_list_enabled: | |||
daemon.add_manager(swsscommon.CONFIG_DB, "BGP_ALLOWED_PREFIXES", self.__bgp_allowed_handler) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pavel,
Introducing new schema for prefixes specific to BGP might confuse the users while the generic schema (IP_PREFIX) is already defined in the below pull request, any thoughts?
Per FRR and mgmt-framework, IP prefix is the generic resource that can be used in multiple protocols (e.g BGP/route-map..etc), defining the prefixes specific to BGP might make the mapping of mgmt-framework's north bound interfaces (openconfig based) difficult, also, allowing two sources (config-DB schema 1) IP_PREFIX 2) BGP_ALLOWED_PREFIXES) to update FRR prefix list will lead to confusions as to which one to use with route-maps.
Per discussion with Guohan, we would like to use new field "bgp_config_mode" in DEVICE_META_DATA to generically make the tables e.g ROUTE_MAP, IP_PREFIX..etc usable for various other protocols as well not just for BGP.
This pull request introduces 2 alerts and fixes 2 when merging 3ad2cf7 into 8d20030 - view on LGTM.com new alerts:
fixed alerts:
|
closed. Check #5309 instead |
This PR implements a new feature: "BGP Allow list."
This feature allows us to control which IP prefixes will be imported from the routes received from BGP neighbors.
The feature can be enabled or disabled using "allow_list_enabled" flag in the /etc/sonic/deployment_id_asn_map.yml`
There is another flag for the feature: "allow_list_default_action". When this flag is equal "permit", this feature will not drop any BGP prefixes. It is useful for debugging. But when the flag is equal to "deny", all prefixes, which are not explicitly listed as "Allowed" will be dropped.
We can control the feature by using the following schema:
The schema above means the following:
a. Import IPv4 prefixes "172.16.0.0/24" and "172.16.1.0/24". The community is not required.
b. Import IPv4 prefixes "172.16.2.0/24" and "172.16.3.0/24" only if they have associated BGP community "1020:123".
c. Import IPv4 prefixes "172.16.4.0/24" and "172.16.5.0/24" only if they have associated BGP community "1020:555".
a. Import IPv6 prefixes "20c0:a810::/64" and "20c0:a820::/64". The community is not required.
b. Import IPv6 prefixes "20c0:a830::/64" and "20c0:a840::/64" only if they have associated BGP community "1020:123".
c. Import IPv6 prefixes "20c0:a850::/64" and "20c0:a860::/64" only if they have associated BGP community "1020:555".
All other prefixes will be dropped (see above for "allow_list_default_action").
When BGP starts and this feature is enabled, all prefixes are enabled to be imported by default. The following BGP configuration is generated when we have one IPv4 neighbor "10.0.0.1" and one IPv6 neighbor "fc00::2"
When we apply the configuration you can find on the top of this PR description, the following BGP configuration will be generated.
As you can see from the output above the feature is isolated inside of "ALLOW_LIST_V4" and "ALLOW_LIST_V6" route-maps. We call the route-maps on top of each "FROM" route-map for each neighbor. When the "ALLOW_LIST_V*" route-map evaluation returns "deny", the "FROM" route-map will return deny. But when "ALLOW_LIST_V*" route-map evaluation returns "permit", the "FROM" route-map will be evaluated.
After each change of configuration the feature "restart" bgp neighbor. The IPv4 neighbor restarts in a soft mode, IPv6 neighbor restarts in a hard mode (quagga doesn't support IPv6 hard mode restart).
To change a list of prefixes inside of each record, you can apply the new list of prefixes with the same key. bgpcfgd will change corrosponding prefix-lists automatically.
When you need to remove the feature from a specific BGP neighbor, you need to remove all "BGP Allow lists" for the neighbor, and BGP will have configuration, which allows the import of all prefixes by default.
When a BGP neighbor is deleted, all BGP configuration related to the feature will be removed.
When a new BGP neighbor is added, the default BGP configuration will be used to allow the import of all prefixes by default.
- Why I did it
I implemented the new feature. See the description above.
- How I did it
I introduced a new functionality into bgpcfgd. All code mostly isolated inside of BGPAllowList class. Also I made some changes inside of bgpd.conf.j2 and bgpd.peer.conf.j2 templates.
- How to verify it
sonic-cfggen -j test_schema.conf --write-to-db
. After that you can useshow runningconfiguration bgp
to check the changed configuration. Also take a look into /var/log/syslog. There you can find the following output:After that you can use
show runningconfiguration bgp
to check the changed configuration.