---
title: "BGP filter"
description: "Reference for the BGPFilter resource in Calico Open Source that filters routes imported from or exported to BGP peers."
product: "Calico Open Source"
version: "3.33 (latest)"
section: "Reference"
canonical_url: "https://docs.tigera.io/calico/latest/reference/resources/bgpfilter"
---

# BGP filter

A Border Gateway Protocol (BGP) filter resource (BGPFilter) represents a way to control routes imported by and exported to BGP peers specified by a [BGP peer resource](https://docs.tigera.io/calico/latest/reference/resources/bgppeer.md) (BGPPeer). BGPFilter is a cluster-scoped resource.

The BGPFilter rules are applied sequentially: the `action` for the **first** rule that matches is executed immediately. If an address does not match any explicit BGP filter rule, it is accepted on import. On export, it is advertised only if Calico would advertise it to that peer without the filter.

In order for a BGPFilter to be used in a BGP peering, its `name` must be added to `filters` of the corresponding BGPPeer resource.

For `kubectl` commands, you can use the aliases `bgpfilter.projectcalico.org`, `bgpfilters.projectcalico.org`, `bgpfilter.p`, and `bgpfilters.p`.

## Sample YAML

This sample accepts and rejects IPv4 and IPv6 routes by CIDR, route source, and interface, on import and on export.

```yaml
apiVersion: projectcalico.org/v3
kind: BGPFilter
metadata:
  name: my-filter
spec:
  exportV4:
    - action: Accept
      matchOperator: In
      cidr: 77.0.0.0/16
      source: RemotePeers
    - action: Reject
      interface: '*.calico'
  importV4:
    - action: Accept
      matchOperator: In
      cidr: 55.0.0.0/16
      prefixLength:
        min: 30
    - action: Reject
      matchOperator: NotIn
      cidr: 44.0.0.0/16
  exportV6:
    - action: Reject
      source: RemotePeers
    - action: Reject
      interface: '*.calico'
  importV6:
    - action: Accept
      matchOperator: Equal
      cidr: 5000::0/64
    - action: Reject
```

## Definition

### Metadata

| Field  | Description                            | Accepted Values                                                                                                          | Schema | Default |
| ------ | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | ------ | ------- |
| `name` | The name of this BGP filter. Required. | Lowercase alphanumeric characters, `-`, or `.`. Must start and end with an alphanumeric character. Up to 253 characters. | string |         |

### Spec

| Field      | Description                        | Accepted Values | Schema                                      | Default |
| ---------- | ---------------------------------- | --------------- | ------------------------------------------- | ------- |
| `exportV4` | List of v4 CIDRs and export action |                 | list of [BGPFilterRuleV4](#bgpfilterrulev4) |         |
| `importV4` | List of v4 CIDRs and import action |                 | list of [BGPFilterRuleV4](#bgpfilterrulev4) |         |
| `exportV6` | List of v6 CIDRs and export action |                 | list of [BGPFilterRuleV6](#bgpfilterrulev6) |         |
| `importV6` | List of v6 CIDRs and import action |                 | list of [BGPFilterRuleV6](#bgpfilterrulev6) |         |

### BGPFilterRuleV4

| Field           | Description                                                                                                                                  | Accepted Values                                                     | Schema                                              | Default |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | --------------------------------------------------- | ------- |
| `cidr`          | IPv4 range                                                                                                                                   | A valid IPv4 CIDR                                                   | string                                              |         |
| `prefixLength`  | The range of prefix lengths to match.                                                                                                        | Valid integers between `0` and `32`                                 | [BGPFilterPrefixLengthV4](#bgpfilterprefixlengthv4) |         |
| `matchOperator` | Method by which to match candidate routes                                                                                                    | `In`, `NotIn`, `Equal`, `NotEqual`                                  | string                                              |         |
| `source`        | Indicator of the source of route                                                                                                             | `RemotePeers` means any route learned from other BGP peers          | string                                              |         |
| `interface`     | String to match interface names                                                                                                              | A valid pattern to match interfaces. `*` can be used as a wildcard. | string                                              |         |
| `peerType`      | Only apply this rule to routes from/to the specified BGP peer type. If empty, the rule applies to all peers.                                 | `eBGP`, `iBGP`                                                      | string                                              |         |
| `priority`      | Only apply this rule to routes with the given priority (metric). Uses the same units as the `...RoutePriority` fields in FelixConfiguration. | `1` to `2147483646`                                                 | integer                                             |         |
| `communities`   | Only apply this rule to routes carrying the specified BGP community.                                                                         |                                                                     | [BGPFilterCommunityMatch](#bgpfiltercommunitymatch) |         |
| `asPathPrefix`  | Only apply this rule to routes whose AS path begins with the specified sequence of AS numbers.                                               | A list of valid AS numbers.                                         | list of integers                                    |         |
| `action`        | Action to be taken for this rule. Required.                                                                                                  | `Accept` or `Reject`                                                | string                                              |         |
| `operations`    | Ordered list of route modifications to apply when the rule matches. Only valid when `action` is `Accept`. Maximum 10 operations.             |                                                                     | list of [BGPFilterOperation](#bgpfilteroperation)   |         |

### BGPFilterRuleV6

| Field           | Description                                                                                                                                  | Accepted Values                                                     | Schema                                              | Default |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | --------------------------------------------------- | ------- |
| `cidr`          | IPv6 range                                                                                                                                   | A valid IPv6 CIDR                                                   | string                                              |         |
| `prefixLength`  | The range of prefix lengths to match.                                                                                                        | Valid integers between `0` and `128`                                | [BGPFilterPrefixLengthV6](#bgpfilterprefixlengthv6) |         |
| `matchOperator` | Method by which to match candidate routes                                                                                                    | `In`, `NotIn`, `Equal`, `NotEqual`                                  | string                                              |         |
| `source`        | Indicator of the source of route                                                                                                             | `RemotePeers` means any route learned from other BGP peers          | string                                              |         |
| `interface`     | String to match interface names                                                                                                              | A valid pattern to match interfaces. `*` can be used as a wildcard. | string                                              |         |
| `peerType`      | Only apply this rule to routes from/to the specified BGP peer type. If empty, the rule applies to all peers.                                 | `eBGP`, `iBGP`                                                      | string                                              |         |
| `priority`      | Only apply this rule to routes with the given priority (metric). Uses the same units as the `...RoutePriority` fields in FelixConfiguration. | `1` to `2147483646`                                                 | integer                                             |         |
| `communities`   | Only apply this rule to routes carrying the specified BGP community.                                                                         |                                                                     | [BGPFilterCommunityMatch](#bgpfiltercommunitymatch) |         |
| `action`        | Action to be taken for this rule                                                                                                             | `Accept` or `Reject`                                                | string                                              |         |
| `operations`    | Ordered list of route modifications to apply when the rule matches. Only valid when `action` is `Accept`. Maximum 10 operations.             |                                                                     | list of [BGPFilterOperation](#bgpfilteroperation)   |         |

### BGPFilterPrefixLengthV4

| Field | Description                                                  | Accepted Values                     | Schema  | Default |
| ----- | ------------------------------------------------------------ | ----------------------------------- | ------- | ------- |
| `min` | Smallest matched mask size (the CIDR's mask size by default) | Valid integers between `0` and `32` | integer |         |
| `max` | Largest matched mask size (`32` by default)                  | Valid integers between `0` and `32` | integer |         |

### BGPFilterPrefixLengthV6

| Field | Description                                                  | Accepted Values                      | Schema  | Default |
| ----- | ------------------------------------------------------------ | ------------------------------------ | ------- | ------- |
| `min` | Smallest matched mask size (the CIDR's mask size by default) | Valid integers between `0` and `128` | integer |         |
| `max` | Largest matched mask size (`128` by default)                 | Valid integers between `0` and `128` | integer |         |

### BGPFilterCommunityMatch

| Field    | Description                                                                                                          | Accepted Values                                            | Schema          | Default |
| -------- | -------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- | --------------- | ------- |
| `values` | List of BGP community values to match against. Required. Must contain exactly one value, which the route must carry. | Standard (`aa:nn`) or large (`aa:nn:mm`) community values. | list of strings |         |

### BGPFilterOperation

Each operation is an object with exactly one of the following fields set:

| Field           | Description                                 | Accepted Values | Schema                                            | Default |
| --------------- | ------------------------------------------- | --------------- | ------------------------------------------------- | ------- |
| `addCommunity`  | Adds a BGP community to the route.          |                 | [BGPFilterAddCommunity](#bgpfilteraddcommunity)   |         |
| `prependASPath` | Prepends AS numbers to the route's AS path. |                 | [BGPFilterPrependASPath](#bgpfilterprependaspath) |         |
| `setPriority`   | Sets the route's priority (metric).         |                 | [BGPFilterSetPriority](#bgpfiltersetpriority)     |         |

### BGPFilterAddCommunity

| Field   | Description                           | Accepted Values                                           | Schema | Default |
| ------- | ------------------------------------- | --------------------------------------------------------- | ------ | ------- |
| `value` | BGP community value to add. Required. | Standard (`aa:nn`) or large (`aa:nn:mm`) community value. | string |         |

### BGPFilterPrependASPath

| Field    | Description                                                                                                                                                                                                | Accepted Values                         | Schema           | Default |
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- | ---------------- | ------- |
| `prefix` | Sequence of AS numbers to prepend to the route's AS path. Required. The resulting path starts with these AS numbers in the order listed (for example, `[65000, 65001]` produces `65000 65001 <original>`). | A list of `1` to `10` valid AS numbers. | list of integers |         |

### BGPFilterSetPriority

| Field   | Description                                                                                                                | Accepted Values     | Schema  | Default |
| ------- | -------------------------------------------------------------------------------------------------------------------------- | ------------------- | ------- | ------- |
| `value` | The priority (metric) value to set on the route. Required. Uses the same units as FelixConfiguration RoutePriority fields. | `1` to `2147483646` | integer |         |

## Additional resources

- [Configure a BGP filter](https://docs.tigera.io/calico/latest/networking/configuring/bgp.md#configure-a-bgp-filter)
- [Configure a BGP peer with a BGP filter](https://docs.tigera.io/calico/latest/networking/configuring/bgp.md#configure-a-bgp-peer-with-a-bgp-filter)
- [BGP peer](https://docs.tigera.io/calico/latest/reference/resources/bgppeer.md)
- [BGP configuration](https://docs.tigera.io/calico/latest/reference/resources/bgpconfig.md)
