Commit graph

199 commits

Author SHA1 Message Date
Enke Chen 96ba273e4e bgpd: remove unused BATTR_REFLECTED for rmap_change_flags
Remove unused BATTR_REFLECTED for rmap_change_flags.

Signed-off-by: Enke Chen <enchen@paloaltonetworks.com>
2025-01-14 08:46:54 -08:00
Enke Chen b89e66a3bc bgpd: use igpmetric in bgp_aigp_metric_total()
Use igpmetric from bgp_path_info in bgp_igp_metric_total() to be
consistent with all other cases, e.g., as in bgp_path_info_cmp().

Signed-off-by: Enke Chen <enchen@paloaltonetworks.com>
2025-01-09 12:02:02 -08:00
Donatas Abraitis 601db6d4a6 bgpd: Check for the extended community size before setting the flag
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-10-22 09:01:04 +03:00
Enke Chen fc82d7750f bgpd: fix AIGP calculation in route advertisement
Currently the AIGP is always incremented when a route with the
attribute is advertised. That is incorrect when the nexthop is
unchanged, as is commonly the case in route reflection.

Adjust the AIGP for propagation only when the nexthop is set
to ourselves.

Signed-off-by: Enke Chen <enchen@paloaltonetworks.com>
2024-10-21 18:03:08 -07:00
Enke Chen f65356d8bb bgpd: fix several issues in sourcing AIGP attribute
Fix several issues in sourcing AIGP attribute:

1) AIGP should not be set as default for a redistributed route or a
   static network. It should be set by config instead.

2) AIGP sourced by "set aigp-metric igp-metric" in a route-map does
   not set the correct value for a redistributed route.

3) When redistribute a connected route like loopback, the AGIP (with
   value 0) is sourced by "set aigp-metric igp-metric", but the
   attribute is not propagated as the attribute flag is not set.

Signed-off-by: Enke Chen <enchen@paloaltonetworks.com>
2024-10-16 11:15:28 -07:00
Donatas Abraitis 5a05dbeb13 bgpd: Set MED using a helper bgp_attr_set_med()
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-10-15 17:36:50 +03:00
Enke Chen 081422e8e7 bgpd: fix route selection with AIGP
The nexthop metric should be added to AIGP when calculating the
bestpath in bgp_path_info_cmp().

Signed-off-by: Enke Chen <enchen@paloaltonetworks.com>
2024-10-14 18:45:06 -07:00
sri-mohan1 80c8b988b0 bgpd: changes for code maintainability
these changes are for improving the code maintainability and readability

Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
2024-09-18 11:24:19 +05:30
Donatas Abraitis 5eb80edf97 bgpd: Free epvn_overlay memory on error
When parsing EVPN NLRIs, and an error occurred, do no forget to free the memory.

Fixes: 4ace11d010 ("bgpd: Move evpn_overlay to a pointer")

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-08-24 11:58:48 +03:00
Donatas Abraitis 4ace11d010 bgpd: Move evpn_overlay to a pointer
Before this convertion:

```
	/* --- cacheline 3 boundary (192 bytes) --- */
	struct bgp_attr_encap_subtlv * encap_subtlvs;    /*   192     8 */
	struct bgp_attr_encap_subtlv * vnc_subtlvs;      /*   200     8 */
	struct bgp_route_evpn      evpn_overlay;         /*   208    36 */
```

After this convertion:

```
	/* --- cacheline 3 boundary (192 bytes) --- */
	struct bgp_attr_encap_subtlv * encap_subtlvs;    /*   192     8 */
	struct bgp_attr_encap_subtlv * vnc_subtlvs;      /*   200     8 */
	struct bgp_route_evpn *    evpn_overlay;         /*   208     8 */
```

Saving 28 bytes when EVPN is not used.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-08-11 13:59:13 +03:00
Donatas Abraitis 5c84cddab8 bgpd: Shrink rmap_change_flags to 2-bytes
4 bytes is not needed for this thing clearly.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-08-09 21:33:50 +03:00
Donatas Abraitis 8b66a236e8 bgpd: Reduce encap_tunneltype to 1 byte
It's not used as a bitmask, no point to use it as 2 bytes.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-08-09 21:33:46 +03:00
Donatas Abraitis d4c577e483 bgpd: Move sticky, default_gw, router_flag into a single flags variable
Instead of using 3 uint8_t variables under struct attr, let's use a single
uint8_t as the flags. Saving 2-bytes. Not a big deal, but it's even easier to
track EVPN-related flags/variables.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-07-04 09:47:07 +03:00
Louis Scalbert a6de910448 bgpd: store number of labels with 8 bits
8 bits are sufficient to store the number of labels because the current
maximum is 2.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-06-05 13:11:29 +02:00
Russ White 1a9c3a710d
Merge pull request #15782 from opensourcerouting/fix/drop_srte_color_flag
bgpd: Drop SRTE_COLOR attribute flag
2024-04-27 08:19:09 -04:00
Donatas Abraitis e0b64f2414 bgpd: Convert 32-bit to 64-bit link bandwidth variable (link_bw)
This is needed to implement and use larger bandwidths rather than limiting only
to theoretical 34Gbps max bandwidth.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-04-22 17:48:37 +03:00
Donatas Abraitis 619321de78 bgpd: Drop SRTE_COLOR attribute flag
SRTE_COLOR is not defined at all as an attribute, it was a mistake from the
beginning.

SRTE_COLOR is extended community, can't see the reason having it as a community,
and a separate attribute.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-04-17 22:50:44 +03:00
Philippe Guibert 37488b573f bgpd: fix install BGP route with appropriate colored ext. community
When receiving a BGP update that includes a colored extended community,
the nexthop is tracked in the bgp nexthop tracking context, but the
color is never recorded. Adding to this, the BGP route is not prevented
from being installed without hte color.

Actually, the srte color is set only when the SRTE_COLOR attribute is set.
And that attribute value is only set when an ext. community is locally
created, or an srte value is set, but not when a BGP update with a color
ext. community is received.

Fix this by setting the SRTE_COLOR attribute on this last case.

Fixes: 442e2edcfa ("bgpd: add functions related to srte_color management")

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-04-04 22:10:33 +02:00
Louis Scalbert 58c1206112 bgpd: move mp_nexthop_prefer_global boolean attribute to nh_flags
Move mp_nexthop_prefer_global boolean attribute to nh_flags. It does
not currently save memory because of the packing.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-02-22 18:20:34 +01:00
Louis Scalbert b45c5cd959 bgpd: update route leak when vrf state changes
Locally leaked routes remain active after the nexthop VRF interface goes
down.

Update route leaking when the loopback or a VRF interface state change is
received from zebra.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-02-14 16:39:51 +01:00
Donatas Abraitis 0223b98c5c bgpd: One more attr struct memory optimization
```
struct attr {
	struct aspath *            aspath;               /*     0     8 */
	struct community *         community;            /*     8     8 */
	long unsigned int          refcnt;               /*    16     8 */
	_uint64_t                  flag;                 /*    24     8 */
	struct in_addr             nexthop;              /*    32     4 */
	uint32_t                   med;                  /*    36     4 */
	uint32_t                   local_pref;           /*    40     4 */
	ifindex_t                  nh_ifindex;           /*    44     4 */
	uint8_t                    nh_flags;             /*    48     1 */
	uint8_t                    origin;               /*    49     1 */
	uint8_t                    es_flags;             /*    50     1 */
	uint8_t                    router_flag;          /*    51     1 */
	uint8_t                    distance;             /*    52     1 */
	uint8_t                    df_alg;               /*    53     1 */
	uint16_t                   df_pref;              /*    54     2 */
	enum pta_type              pmsi_tnl_type;        /*    56     4 */
	uint32_t                   rmap_change_flags;    /*    60     4 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	struct in6_addr            mp_nexthop_global;    /*    64    16 */
	struct in6_addr            mp_nexthop_local;     /*    80    16 */
	ifindex_t                  nh_lla_ifindex;       /*    96     4 */
	mpls_label_t               label;                /*   100     4 */
	struct ecommunity *        ecommunity;           /*   104     8 */
	struct ecommunity *        ipv6_ecommunity;      /*   112     8 */
	struct lcommunity *        lcommunity;           /*   120     8 */
	/* --- cacheline 2 boundary (128 bytes) --- */
	struct cluster_list *      cluster1;             /*   128     8 */
	struct transit *           transit;              /*   136     8 */
	struct in_addr             mp_nexthop_global_in; /*   144     4 */
	struct in_addr             aggregator_addr;      /*   148     4 */
	struct in_addr             originator_id;        /*   152     4 */
	uint32_t                   weight;               /*   156     4 */
	as_t                       aggregator_as;        /*   160     4 */
	uint8_t                    mp_nexthop_len;       /*   164     1 */
	uint8_t                    mp_nexthop_prefer_global; /*   165     1 */
	uint8_t                    sticky;               /*   166     1 */
	uint8_t                    default_gw;           /*   167     1 */
	route_tag_t                tag;                  /*   168     4 */
	uint32_t                   label_index;          /*   172     4 */
	struct bgp_attr_srv6_vpn * srv6_vpn;             /*   176     8 */
	struct bgp_attr_srv6_l3vpn * srv6_l3vpn;         /*   184     8 */
	/* --- cacheline 3 boundary (192 bytes) --- */
	struct bgp_attr_encap_subtlv * encap_subtlvs;    /*   192     8 */
	struct bgp_attr_encap_subtlv * vnc_subtlvs;      /*   200     8 */
	struct bgp_route_evpn      evpn_overlay;         /*   208    36 */
	uint32_t                   mm_seqnum;            /*   244     4 */
	uint32_t                   mm_sync_seqnum;       /*   248     4 */
	struct ethaddr             rmac;                 /*   252     6 */
	/* --- cacheline 4 boundary (256 bytes) was 2 bytes ago --- */
	uint16_t                   encap_tunneltype;     /*   258     2 */
	uint32_t                   rmap_table_id;        /*   260     4 */
	uint32_t                   link_bw;              /*   264     4 */
	esi_t                      esi;                  /*   268    10 */

	/* XXX 2 bytes hole, try to pack */

	uint32_t                   srte_color;           /*   280     4 */
	enum nexthop_types_t       nh_type;              /*   284     4 */
	enum blackhole_type        bh_type;              /*   288     4 */
	uint32_t                   otc;                  /*   292     4 */
	_uint64_t                  aigp_metric;          /*   296     8 */

	/* size: 304, cachelines: 5, members: 54 */
	/* sum members: 302, holes: 1, sum holes: 2 */
	/* last cacheline: 48 bytes */
};   /* saved 8 bytes! */
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-02-01 17:28:42 +02:00
Donald Sharp d633a81dbf
Merge pull request #15250 from opensourcerouting/fix/memory_optimizations
bgpd: Some memory optimizations
2024-01-30 10:56:35 -05:00
Donatas Abraitis 4821e7a0d8 bgpd: Optimize memory usage for attr struct
```
struct attr {
	struct aspath *            aspath;               /*     0     8 */
	struct community *         community;            /*     8     8 */
	long unsigned int          refcnt;               /*    16     8 */
	_uint64_t                  flag;                 /*    24     8 */
	struct in_addr             nexthop;              /*    32     4 */
	uint32_t                   med;                  /*    36     4 */
	uint32_t                   local_pref;           /*    40     4 */
	ifindex_t                  nh_ifindex;           /*    44     4 */
	uint8_t                    origin;               /*    48     1 */
	uint8_t                    es_flags;             /*    49     1 */
	uint8_t                    router_flag;          /*    50     1 */
	uint8_t                    default_gw;           /*    51     1 */
	enum pta_type              pmsi_tnl_type;        /*    52     4 */
	uint32_t                   rmap_change_flags;    /*    56     4 */
	struct in6_addr            mp_nexthop_global;    /*    60    16 */
	/* --- cacheline 1 boundary (64 bytes) was 12 bytes ago --- */
	struct in6_addr            mp_nexthop_local;     /*    76    16 */
	ifindex_t                  nh_lla_ifindex;       /*    92     4 */
	struct ecommunity *        ecommunity;           /*    96     8 */
	struct ecommunity *        ipv6_ecommunity;      /*   104     8 */
	struct lcommunity *        lcommunity;           /*   112     8 */
	struct cluster_list *      cluster1;             /*   120     8 */
	/* --- cacheline 2 boundary (128 bytes) --- */
	struct transit *           transit;              /*   128     8 */
	struct in_addr             mp_nexthop_global_in; /*   136     4 */
	struct in_addr             aggregator_addr;      /*   140     4 */
	struct in_addr             originator_id;        /*   144     4 */
	uint32_t                   weight;               /*   148     4 */
	as_t                       aggregator_as;        /*   152     4 */
	uint8_t                    mp_nexthop_len;       /*   156     1 */
	uint8_t                    mp_nexthop_prefer_global; /*   157     1 */
	uint8_t                    sticky;               /*   158     1 */
	uint8_t                    distance;             /*   159     1 */
	uint16_t                   encap_tunneltype;     /*   160     2 */
	uint8_t                    df_alg;               /*   162     1 */

	/* XXX 1 byte hole, try to pack */

	route_tag_t                tag;                  /*   164     4 */
	uint32_t                   label_index;          /*   168     4 */
	mpls_label_t               label;                /*   172     4 */
	struct bgp_attr_srv6_vpn * srv6_vpn;             /*   176     8 */
	struct bgp_attr_srv6_l3vpn * srv6_l3vpn;         /*   184     8 */
	/* --- cacheline 3 boundary (192 bytes) --- */
	struct bgp_attr_encap_subtlv * encap_subtlvs;    /*   192     8 */
	struct bgp_attr_encap_subtlv * vnc_subtlvs;      /*   200     8 */
	struct bgp_route_evpn      evpn_overlay;         /*   208    36 */
	uint32_t                   mm_seqnum;            /*   244     4 */
	uint32_t                   mm_sync_seqnum;       /*   248     4 */
	struct ethaddr             rmac;                 /*   252     6 */
	/* --- cacheline 4 boundary (256 bytes) was 2 bytes ago --- */
	uint16_t                   df_pref;              /*   258     2 */
	uint32_t                   rmap_table_id;        /*   260     4 */
	uint32_t                   link_bw;              /*   264     4 */
	esi_t                      esi;                  /*   268    10 */

	/* XXX 2 bytes hole, try to pack */

	uint32_t                   srte_color;           /*   280     4 */
	uint32_t                   otc;                  /*   284     4 */
	enum nexthop_types_t       nh_type;              /*   288     4 */
	enum blackhole_type        bh_type;              /*   292     4 */
	_uint64_t                  aigp_metric;          /*   296     8 */

	/* size: 304, cachelines: 5, members: 53 */
	/* sum members: 301, holes: 2, sum holes: 3 */
	/* last cacheline: 48 bytes */
};   /* saved 16 bytes! */
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-30 08:12:58 +02:00
Louis Scalbert 879bfc01c8 bgpd: fix VRF leaking with 'network import-check' (3/4)
If 'bgp network import-check' is defined on the source BGP session,
prefixes that are defined with the network command cannot be leaked to
the other VRFs BGP table even if they are present in the origin VRF RIB
if the 'rt import' statement is defined after the 'network <prefix>'
ones.

When a prefix nexthop is updated, update the prefix route leaking. The
current state of nexthop validation is now stored in the attributes of
the bgp path info. Attributes are compared with the previous ones at
route leaking update so that a nexthop validation change now triggers
the update of destination VRF BGP table.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-29 10:46:43 +01:00
Donatas Abraitis c37119df45 bgpd: Ignore handling NLRIs if we received MP_UNREACH_NLRI
If we receive MP_UNREACH_NLRI, we should stop handling remaining NLRIs if
no mandatory path attributes received.

In other words, if MP_UNREACH_NLRI received, the remaining NLRIs should be handled
as a new data, but without mandatory attributes, it's a malformed packet.

In normal case, this MUST not happen at all, but to avoid crashing bgpd, we MUST
handle that.

Reported-by: Iggy Frankovic <iggyfran@amazon.com>
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-10-31 17:22:00 +02:00
Donatas Abraitis b08afc81c6 bgpd: Handle MP_REACH_NLRI malformed packets with session reset
Avoid crashing bgpd.

```
(gdb)
bgp_mp_reach_parse (args=<optimized out>, mp_update=0x7fffffffe140) at bgpd/bgp_attr.c:2341
2341			stream_get(&attr->mp_nexthop_global, s, IPV6_MAX_BYTELEN);
(gdb)
stream_get (dst=0x7fffffffe1ac, s=0x7ffff0006e80, size=16) at lib/stream.c:320
320	{
(gdb)
321		STREAM_VERIFY_SANE(s);
(gdb)
323		if (STREAM_READABLE(s) < size) {
(gdb)
34	  return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
(gdb)

Thread 1 "bgpd" received signal SIGSEGV, Segmentation fault.
0x00005555556e37be in route_set_aspath_prepend (rule=0x555555aac0d0, prefix=0x7fffffffe050,
    object=0x7fffffffdb00) at bgpd/bgp_routemap.c:2282
2282		if (path->attr->aspath->refcnt)
(gdb)
```

With the configuration:

```
 neighbor 127.0.0.1 remote-as external
 neighbor 127.0.0.1 passive
 neighbor 127.0.0.1 ebgp-multihop
 neighbor 127.0.0.1 disable-connected-check
 neighbor 127.0.0.1 update-source 127.0.0.2
 neighbor 127.0.0.1 timers 3 90
 neighbor 127.0.0.1 timers connect 1
 address-family ipv4 unicast
  redistribute connected
  neighbor 127.0.0.1 default-originate
  neighbor 127.0.0.1 route-map RM_IN in
 exit-address-family
!
route-map RM_IN permit 10
 set as-path prepend 200
exit
```

Reported-by: Iggy Frankovic <iggyfran@amazon.com>
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-10-24 15:22:52 +03:00
Donald Sharp 166e52d6a3 Revert "bgpd: store and send bgp link-state attributes"
This reverts commit 8b531b1107.
2023-10-10 16:42:47 -04:00
Louis Scalbert 8b531b1107 bgpd: store and send bgp link-state attributes
Add the ability to store a raw copy of the incoming BGP Link-State
attributes and to redistribute them as is to other routes.

New types of data BGP_ATTR_LS and BGP_ATTR_LS_DATA are defined.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2023-09-18 15:07:32 +02:00
Donatas Abraitis dd58cd4d38 bgpd: Use SET_FLAG when setting AIGP attribute flag
Just reuse an existing more-readable code.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-08-03 22:54:54 +03:00
Donatas Abraitis 0a0137da85 bgpd: Handle cluster attribute the same way as others using setters/getters
To be consistent and error-safe.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-08-03 22:44:17 +03:00
Donatas Abraitis 4199f032e5
Merge pull request #13722 from fdumontet6WIND/color_extcomm
bgpd,lib,yang: add colored extended communities support
2023-06-27 13:03:22 +03:00
Francois Dumontet 442e2edcfa bgpd: add functions related to srte_color management
Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
2023-06-26 14:27:27 +02:00
Trey Aspelund badc4857aa bgpd: add EVPN reimport handler for martian change
Adds a generalized martian reimport function used for triggering a
relearn/reimport of EVPN routes that were previously filtered/deleted
as a result of a "self" check (either during import or by a martian
change handler). The MAC-VRF SoO is the first consumer of this function,
but can be expanded for use with Martian Tunnel-IPs, Interface-IPs,
Interface-MACs, and RMACs.

Signed-off-by: Trey Aspelund <taspelund@nvidia.com>
2023-05-30 15:20:35 +00:00
Donald Sharp 8383d53e43
Merge pull request #12780 from opensourcerouting/spdx-license-id
*: convert to SPDX License identifiers
2023-02-17 09:43:05 -05:00
David Lamparter acddc0ed3c *: auto-convert to SPDX License IDs
Done with a combination of regex'ing and banging my head against a wall.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +01:00
Donatas Abraitis e2863b4ff5 bgpd: Add neighbor path-attribute treat-as-withdraw command
To filter out routes with unwanted prefixes.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-02-01 22:57:34 +02:00
Donatas Abraitis b986d7f41a bgpd: Add missing no form for neighbor path-attribute discard cmd
Just forgot this _somehow_ :)

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-01-22 22:17:39 +02:00
Donatas Abraitis a5c6a9b18e bgpd: Add neighbor path-attribute discard command
The idea is to drop unwanted attributes from the BGP UPDATE messages and
continue by just ignoring them. This improves the security, flexiblity, etc.

This is the command that Cisco has also.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-01-14 21:29:41 +02:00
Donald Sharp 2bb8b49ce1 Revert "Merge pull request #11127 from louis-6wind/bgp-leak"
This reverts commit 16aa1809e7, reversing
changes made to f616e71608.
2023-01-13 08:13:52 -05:00
Louis Scalbert 5f6c0ba6d2 bgpd: resend routes deleted by kernel after interface addresses deletion
When the last IPv4 address of an interface is deleted, Linux removes all
routes includes BGP ones using this interface without any Netlink
advertisement. bgpd keeps them in RIB as valid (e.g. installed in FIB).

The previous patch invalidates the associated nexthop groups in zebra
but bgpd is not notified of the event.

> 2022/05/09 17:37:52.925 ZEBRA: [TQKA8-0276P] Not Notifying Owner: connected about prefix 29.0.0.0/24(40) 3 vrf: 7

Look for the bgp_path_info that are unsynchronized with the kernel and
flag them for refresh in their attributes. A VPN route leaking update is
calles and the refresh flag triggers a route refresh to zebra and then a
kernel FIB installation.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2022-12-16 15:07:49 +01:00
Louis Scalbert 667a4e92da bgpd: move mp_nexthop_prefer_global boolean attribute to nh_flag
Previous commits have introduced a new 8 bits nh_flag in the attr
struct that has increased the memory footprint.

Move the mp_nexthop_prefer_global boolean in the attr structure that
takes 8 bits to the new nh_flag in order to go back to the previous
memory utilization.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2022-12-16 15:07:00 +01:00
Louis Scalbert 6030b8b40d bgpd: update route leaking when a VRF loopback is received
At bgpd startup, VRF instances are sent from zebra before the
interfaces. When importing a l3vpn prefix from another local VRF
instance, the interfaces are not known yet. The prefix nexthop interface
cannot be set to the loopback or the VRF interface, which causes setting
invalid routes in zebra.

Update route leaking when the loopback or a VRF interface is received
from zebra.

At a VRF interface deletion, zebra voluntarily sends a
ZEBRA_INTERFACE_ADD message to move it to VRF_DEFAULT. Do not update if
such a message is received. VRF destruction will destroy all the related
routes without adding codes.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2022-12-16 14:52:47 +01:00
Louis Scalbert 1e24860bf7 bgpd: fix prefix VRF leaking with 'network import-check' (4/5)
If 'network import-check' is defined on the source BGP session, prefixes
that are stated in the network command cannot be leaked to the other
VRFs BGP table even if they are present in the origin VRF RIB if the
'rt import' statement is defined after the 'network <prefix>' ones.

When a prefix nexthop is updated, update the prefix route leaking. The
current state of nexthop validation is now stored in the attributes of
the bgp path info. Attributes are compared with the previous ones at
route leaking update so that a nexthop validation change now triggers
the update of destination VRF BGP table.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2022-12-16 14:52:47 +01:00
Donatas Abraitis 6dad190d56 bgpd: Convert bgp_rmap_nhop_changed to bool from int
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-11-18 16:17:15 +02:00
Donatas Abraitis 6eeb925545 bgpd: Allow overriding MPLS VPN next-hops via route-maps
Just do not reset next-hop for MPLS VPN routes.

Example of 172.16.255.1/32 (using extended next-hop capability):

```
pe2# sh bgp ipv4 vpn
BGP table version is 4, local router ID is 10.10.10.20, vrf id 0
Default local pref 100, local AS 65001
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

    Network          Next Hop            Metric LocPrf Weight Path
Route Distinguisher: 192.168.1.2:2
 *>i10.0.0.0/24      2001:db8:1::1            0    100      0 65000 ?
    UN=2001:db8:1::1 EC{192.168.1.2:2} label=1111 type=bgp, subtype=0
 *>i172.16.255.1/32  2001:db8::1              0    100      0 65000 ?
    UN=2001:db8::1 EC{192.168.1.2:2} label=1111 type=bgp, subtype=0
 *>i192.168.1.0/24   2001:db8:1::1            0    100      0 65000 ?
    UN=2001:db8:1::1 EC{192.168.1.2:2} label=1111 type=bgp, subtype=0
 *>i192.168.2.0/24   2001:db8:1::1                 100      0 65000 ?
    UN=2001:db8:1::1 EC{192.168.1.2:2} label=1111 type=bgp, subtype=0
Route Distinguisher: 192.168.2.2:2
 *> 10.0.0.0/24      192.168.2.1@4<           0     50      0 65000 ?
    UN=192.168.2.1 EC{192.168.2.2:2} label=2222 type=bgp, subtype=5
 *> 172.16.255.1/32  192.168.2.1@4<                 50      0 65000 ?
    UN=192.168.2.1 EC{192.168.2.2:2} label=2222 type=bgp, subtype=5
 *> 192.168.1.0/24   192.168.2.1@4<                 50      0 65000 ?
    UN=192.168.2.1 EC{192.168.2.2:2} label=2222 type=bgp, subtype=5
 *> 192.168.2.0/24   192.168.2.1@4<           0     50      0 65000 ?
    UN=192.168.2.1 EC{192.168.2.2:2} label=2222 type=bgp, subtype=5

Displayed  8 routes and 8 total paths
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-11-18 16:17:15 +02:00
Donatas Abraitis 97a52c82a5 bgpd: Implement Accumulated IGP Metric Attribute for BGP
https://www.rfc-editor.org/rfc/rfc7311.html

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-10-26 11:26:57 +03:00
Ryoga Saito bee2e7d08f bgpd: save srv6_locator_chunk in vpn_policy
In order to send correct SRv6 L3VPN advertisement, we need to save
srv6_locator_chunk in vpn_policy. With this information, we can
construct correct SRv6 L3VPN advertisement packets.

Signed-off-by: Ryoga Saito <ryoga.saito@linecorp.com>
2022-10-07 18:26:48 +09:00
Philippe Guibert 1bb550b63c bgpd: add resolution for l3vpn traffic over gre interfaces
When a route imported from l3vpn is analysed, the nexthop from default
VRF is looked up against a valid MPLS path. Generally, this is done on
backbones with a MPLS signalisation transport layer like LDP. Generally,
the BGP connection is multiple hops away. That scenario is already
working.

There is case where it is possible to run L3VPN over GRE interfaces, and
where there is no LSP path over that GRE interface: GRE is just here to
tunnel MPLS traffic. On that case, the nexthop given in the path does not
have MPLS path, but should be authorized to convey MPLS traffic provided
that the user permits it via a configuration command.

That commit introduces a new command that can be activated in route-map:
 > set l3vpn next-hop encapsulation gre

That command authorizes the nexthop tracking engine to accept paths that
o have a GRE interface as output, independently of the presence of an LSP
path or not.

A configuration example is given below. When bgp incoming vpnv4 updates
are received, the nexthop of NLRI is 192.168.0.2. Based on nexthop
tracking service from zebra, BGP knows that the output interface to reach
192.168.0.2 is r1-gre0. Because that interface is not MPLS based, but is
a GRE tunnel, then the update will be using that nexthop to be installed.

    interface r1-gre0
     ip address 192.168.0.1/24
    exit
    router bgp 65500
     bgp router-id 1.1.1.1
     neighbor 192.168.0.2 remote-as 65500
     !
     address-family ipv4 unicast
      no neighbor 192.168.0.2 activate
     exit-address-family
     !
     address-family ipv4 vpn
      neighbor 192.168.0.2 activate
      neighbor 192.168.0.2 route-map rmap in
     exit-address-family
    exit
    !
    router bgp 65500 vrf vrf1
     bgp router-id 1.1.1.1
     no bgp network import-check
     !
     address-family ipv4 unicast
      network 10.201.0.0/24
      redistribute connected
      label vpn export 101
      rd vpn export 444:1
      rt vpn both 52:100
      export vpn
      import vpn
     exit-address-family
    exit
    !
    route-map rmap permit 1
     set l3vpn next-hop encapsulation gre
    exit

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2022-09-05 22:26:25 +02:00
Eugene Bogomazov d864dd9eb1 bgpd: Add RFC9234 implementation
RFC9234 is a way to establish correct connection roles (Customer/
Provider, Peer or with RS) between bgp speakers. This patch:
- Add a new configuration/terminal option to set the appropriate local
role;
- Add a mechanism for checking used roles, implemented by exchanging
the corresponding capabilities in OPEN messages;
- Add strict mode to force other party to use this feature;
- Add basic support for a new transitive optional bgp attribute - OTC
(Only to Customer);
- Add logic for default setting OTC attribute and filtering routes with
this attribute by the edge speakers, if the appropriate conditions are
met;
- Add two test stands to check role negotiation and route filtering
during role usage.

Signed-off-by: Eugene Bogomazov <eb@qrator.net>
2022-06-17 13:14:46 +03:00
Donatas Abraitis 0f05ea43b0 bgpd: Initialize attr->local_pref to the configured default value
When we use network/redistribute local_preference is configured inproperly
when using route-maps something like:

```
network 100.100.100.100/32 route-map rm1
network 100.100.100.200/32 route-map rm2

route-map rm1 permit 10
 set local-preference +10
route-map rm2 permit 10
 set local-preference -10
```

Before:
```
root@spine1-debian-11:~# vtysh -c 'show bgp ipv4 unicast 100.100.100.100/32 json' | jq '.paths[].locPrf'
10
root@spine1-debian-11:~# vtysh -c 'show bgp ipv4 unicast 100.100.100.200/32 json' | jq '.paths[].locPrf'
0
```

After:
```
root@spine1-debian-11:~# vtysh -c 'show bgp ipv4 unicast 100.100.100.100/32 json' | jq '.paths[].locPrf'
110
root@spine1-debian-11:~# vtysh -c 'show bgp ipv4 unicast 100.100.100.200/32 json' | jq '.paths[].locPrf'
90
```

Set local-preference as the default value configured per BGP instance, but
do not set LOCAL_PREF flag by default.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-06-06 10:28:50 +03:00