Commit Graph

7516 Commits

Author SHA1 Message Date
Louis Scalbert
db7cf73a33 bgpd: fix interface on leaks from redistribute connected
In the target VRF's Routing Information Base (RIB), routes that are
leaked and originate from the 'redistribute connected' command have
their next-hop interface set as the interface from the source VRF.
This prevents the IP address of the connected interface from being
reachable from the target VRF.

> router bgp 5227 vrf r1-cust1
>  address-family ipv4 unicast
>   redistribute connected
>   rd vpn export 10:1
>   rt vpn import 52:100
>   rt vpn export 52:101
>   export vpn
>   import vpn
>  exit-address-family
> exit
> !
> router bgp 5227 vrf r1-cust4
>  address-family ipv4 unicast
>   network 192.0.2.0/24
>   rd vpn export 10:1
>   rt vpn import 52:101
>   rt vpn export 52:100
>   export vpn
>   import vpn
>  exit-address-family
> exit
> !
> vrf r1-cust1
>  ip route 192.0.2.0/24 r1-cust4 nexthop-vrf r1-cust4

Extract from the routing table:
> VRF r1-cust1:
> C>* 172.16.29.0/24 is directly connected, r1-eth4, 00:44:15
> S>* 192.0.2.0/24 [1/0] is directly connected, r1-cust4 (vrf r1-cust4), weight 1, 00:00:30
>
> VRF r1-cust4:
> B>* 172.16.29.0/24 [20/0] is directly connected, r1-eth4 (vrf r1-cust1), weight 1, 00:00:02

In r1-cust4 VRF, the nexthop interface of 172.16.29.0/24 is r1-eth4,
which is unknown in the context. The following ping does not work:

> # tcpdump -lnni r1-cust1 'icmp' &
> # ip vrf exec r1-cust4 ping -c1 -I 192.0.2.1 172.16.29.1
> PING 172.16.29.1 (172.16.29.1) 56(84) bytes of data.
PING 172.16.29.1 (172.16.29.1) from 192.0.2.1 : 56(84) bytes of data.
18:49:20.635638 IP 192.0.2.1 > 172.16.29.1: ICMP echo request, id 15897, seq 1, length 64
18:49:27.113827 IP 192.0.2.1 > 192.0.2.1: ICMP host 172.16.29.1 unreachable, length 92

Fix the issue by setting nh_ifindex to the index of the VRF master
interface of the incoming BGP instance. The result is:

> VRF r1-cust4:
> C>* 192.0.2.0/24 is directly connected, r1-cust5, 00:27:40
> B>* 172.16.29.0/24 [20/0] is directly connected, r1-cust1 (vrf r1-cust1), weight 1, 00:00:08

> # tcpdump -lnni r1-cust1 'icmp' &
> # ping -c1 172.16.29.1 -I 192.0.2.1
> PING 172.16.29.1 (172.16.29.1) from 192.0.2.1 : 56(84) bytes of data.
> 18:48:32.506281 IP 192.0.2.1 > 172.16.29.1: ICMP echo request, id 15870, seq 1, length 64
> 64 bytes from 172.16.29.1: icmp_seq=1 ttl=64 time=0.050 ms
> 18:48:32.506304 IP 172.16.29.1 > 192.0.2.1: ICMP echo reply, id 15870, seq 1, length 64

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-02-01 10:21:43 +01:00
Louis Scalbert
067fbab4e4 bgpd: fix interface on leaks from network statement
Leaked routes from prefixes defined with 'network <prefix>' are inactive
because they have no valid nexthop interface.

> vrf r1-cust1
>  ip route 172.16.29.0/24 192.168.1.2
> router bgp 5227 vrf r1-cust1
>  no bgp network import-check
>  address-family ipv4 unicast
>   network 172.16.29.0/24
>   rd vpn export 10:1
>   rt vpn import 52:100
>   rt vpn export 52:101
>   export vpn
>   import vpn
>  exit-address-family
> exit
> !
> router bgp 5227 vrf r1-cust4
>  bgp router-id 192.168.1.1
> !
>  address-family ipv4 unicast
>   network 192.0.2/24
>   rd vpn export 10:1
>   rt vpn import 52:101
>   rt vpn export 52:100
>   export vpn
>   import vpn
>  exit-address-family
> exit

Extract from the routing table:

> VRF r1-cust1:
> S>* 172.16.29.0/24 [1/0] via 192.168.1.2, r1-eth4, weight 1, 00:47:53
>
> VRF r1-cust4:
> B   172.16.29.0/24 [20/0] is directly connected, unknown (vrf r1-cust1) inactive, weight 1, 00:03:40

Routes imported through the "network" command, as opposed to those
redistributed from the routing table, do not associate with any specific
interface.

When leaking prefix from other VRFs, if the route was imported from the
network statement (ie. static sub-type), set nh_ifindex to the index of
the VRF master interface of the incoming BGP instance.

The result is:

> VRF r1-cust4:
> B>* 172.16.29.0/24 [20/0] is directly connected, r1-cust1 (vrf r1-cust1), weight 1, 00:00:08

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-02-01 10:21:43 +01:00
Donatas Abraitis
bd3b17d27d
Merge pull request #15258 from louis-6wind/fix-adj-in-attr
bgpd: fix attr comparaison bgp_adj_in_set
2024-01-31 15:06:40 +02:00
Donatas Abraitis
0fd46e3f4e bgpd: Optimize memory for rd_ip struct
```
struct rd_ip {
	uint16_t                   type;                 /*     0     2 */
	uint16_t                   val;                  /*     2     2 */
	struct in_addr             ip;                   /*     4     4 */

	/* size: 8, cachelines: 1, members: 3 */
	/* last cacheline: 8 bytes */
};   /* saved 4 bytes! */
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-31 11:29:30 +02:00
Russ White
61aa468a04
Merge pull request #15257 from opensourcerouting/fix/reinstall_aggregate_route_if_rmap
bgpd: Reinstall aggregated routes if using route-maps and it was changed
2024-01-30 15:08:08 -05: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
Dmytro Shytyi
b3ac50287d bgpd: srv6 sid reachability verification
In the case of SRv6-VPN we track the reachability
to the SID. We check that the SID is available
in the BGP update and then we check the nexthop
reachability.

Fixes 7f8c7d9 ("bgpd: ignore nexthop validation for srv6-vpn")

Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-01-30 16:15:17 +01:00
Dmytro Shytyi
26c747ed6c bgpd: extend make_prefix to form srv6-based prefix
Enable the SRv6 SID prefix generation in make_prefix()
function of bgp_nht.c.

Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>

fixup: bgpd: extend make_prefix to form srv6-based prefix
2024-01-30 16:15:13 +01:00
Louis Scalbert
5c0aab103d bgpd: fix attr comparaison bgp_adj_in_set
In bgp_adj_in_set(), attr has not yet been interned. adj->attr is always
different from attr. adj->attr is always uninterned and interned even if
attr and adj->attr are identical.

Fix the comparison.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-30 15:24:32 +01:00
Donatas Abraitis
ee1986f1b5 bgpd: Reinstall aggregated routes if using route-maps and it was changed
Without this change when we change the route-map, we never reinstall the route
if the route-map has changed.

We checked only some attributes like aspath, communities, large-communities,
extended-communities, but ignoring the rest of attributes.

With this change, let's check if the route-map has changed.

bgp_route_map_process_update() is triggered on route-map change, and we set
`changed` to true, which treats aggregated route as not the same as it was before.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-30 15:47:49 +02:00
Donatas Abraitis
48856741bd bgpd: Optimize memory usage for bgp_damp_config struct
```
struct bgp_damp_config {
        unsigned int               suppress_value;       /*     0     4 */
        unsigned int               reuse_limit;          /*     4     4 */
        time_t                     max_suppress_time;    /*     8     8 */
        time_t                     half_life;            /*    16     8 */
        unsigned int               reuse_list_size;      /*    24     4 */
        unsigned int               reuse_index_size;     /*    28     4 */
        unsigned int               ceiling;              /*    32     4 */
        unsigned int               decay_rate_per_tick;  /*    36     4 */
        unsigned int               decay_array_size;     /*    40     4 */
        unsigned int               reuse_scale_factor;   /*    44     4 */
        double                     scale_factor;         /*    48     8 */
        double *                   decay_array;          /*    56     8 */
        /* --- cacheline 1 boundary (64 bytes) --- */
        int *                      reuse_index;          /*    64     8 */
        struct bgp_damp_info * *   reuse_list;           /*    72     8 */
        int                        reuse_offset;         /*    80     4 */
        safi_t                     safi;                 /*    84     4 */
        struct bgp_damp_info *     no_reuse_list;        /*    88     8 */
        struct event *             t_reuse;              /*    96     8 */
        afi_t                      afi;                  /*   104     4 */

        /* size: 112, cachelines: 2, members: 19 */
        /* padding: 4 */
        /* last cacheline: 48 bytes */
};   /* saved 8 bytes! */
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-30 08:12:59 +02:00
Donatas Abraitis
a699cc1796 bgpd: Optimize memory usage for bgp_aggregate struct
```
struct bgp_aggregate {
        uint8_t                    summary_only;         /*     0     1 */
        uint8_t                    as_set;               /*     1     1 */
        uint8_t                    origin;               /*     2     1 */
        _Bool                      med_mismatched;       /*     3     1 */
        _Bool                      med_initialized;      /*     4     1 */
        _Bool                      match_med;            /*     5     1 */

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

        struct {
                char *             name;                 /*     8     8 */
                struct route_map * map;                  /*    16     8 */
        } rmap;                                          /*     8    16 */
        long unsigned int          count;                /*    24     8 */
        long unsigned int          incomplete_origin_count; /*    32     8 */
        long unsigned int          egp_origin_count;     /*    40     8 */
        struct hash *              community_hash;       /*    48     8 */
        struct hash *              ecommunity_hash;      /*    56     8 */
        /* --- cacheline 1 boundary (64 bytes) --- */
        struct hash *              lcommunity_hash;      /*    64     8 */
        struct hash *              aspath_hash;          /*    72     8 */
        struct community *         community;            /*    80     8 */
        struct ecommunity *        ecommunity;           /*    88     8 */
        struct lcommunity *        lcommunity;           /*    96     8 */
        struct aspath *            aspath;               /*   104     8 */
        safi_t                     safi;                 /*   112     4 */
        uint32_t                   med_matched_value;    /*   116     4 */
        char *                     suppress_map_name;    /*   120     8 */
        /* --- cacheline 2 boundary (128 bytes) --- */
        struct route_map *         suppress_map;         /*   128     8 */

        /* size: 136, cachelines: 3, members: 22 */
        /* sum members: 134, holes: 1, sum holes: 2 */
        /* last cacheline: 8 bytes */
};
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-30 08:12:59 +02:00
Donatas Abraitis
0804038916 bgpd: Optimize memory usage for bgp_static struct
```
struct bgp_static {
        int                        backdoor;             /*     0     4 */
        uint32_t                   label_index;          /*     4     4 */
        uint8_t                    valid;                /*     8     1 */

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

        uint16_t                   encap_tunneltype;     /*    10     2 */
        uint32_t                   igpmetric;            /*    12     4 */
        struct in_addr             igpnexthop;           /*    16     4 */
        uint32_t                   atomic;               /*    20     4 */
        struct {
                char *             name;                 /*    24     8 */
                struct route_map * map;                  /*    32     8 */
        } rmap;                                          /*    24    16 */
        struct prefix_rd           prd __attribute__((__aligned__(8))); /*    40    16 */
        char *                     prd_pretty;           /*    56     8 */
        /* --- cacheline 1 boundary (64 bytes) --- */
        mpls_label_t               label;                /*    64     4 */

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

        esi_t *                    eth_s_id;             /*    72     8 */
        struct ethaddr *           router_mac;           /*    80     8 */
        struct prefix              gatewayIp __attribute__((__aligned__(8))); /*    88    56 */

        /* size: 144, cachelines: 3, members: 14 */
        /* sum members: 139, holes: 2, sum holes: 5 */
        /* forced alignments: 2 */
        /* last cacheline: 16 bytes */
} __attribute__((__aligned__(8)));   /* saved 8 bytes! */
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-30 08:12:59 +02: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
Donatas Abraitis
89e124f042 bgpd: Optimize memory usage for bgp_nlri struct
```
struct bgp_nlri {
	uint16_t                   afi;                  /*     0     2 */
	uint8_t                    safi;                 /*     2     1 */

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

	bgp_size_t                 length;               /*     4     2 */

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

	uint8_t *                  nlri;                 /*     8     8 */

	/* size: 16, cachelines: 1, members: 4 */
	/* sum members: 13, holes: 2, sum holes: 3 */
	/* last cacheline: 16 bytes */
};   /* saved 8 bytes! */
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-29 15:37:23 +02:00
Donatas Abraitis
7133cce196 bgpd: Optimize memory usage for bgp_notify struct
```
struct bgp_notify {
	uint8_t                    code;                 /*     0     1 */
	uint8_t                    subcode;              /*     1     1 */
	bgp_size_t                 length;               /*     2     2 */
	_Bool                      hard_reset;           /*     4     1 */

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

	char *                     data;                 /*     8     8 */
	uint8_t *                  raw_data;             /*    16     8 */

	/* size: 24, cachelines: 1, members: 6 */
	/* sum members: 21, holes: 1, sum holes: 3 */
	/* last cacheline: 24 bytes */
};   /* saved 16 bytes! */
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-29 15:29:25 +02:00
Louis Scalbert
14e51be394 bgpd: fix VRF leaking with 'network import-check' (4/4)
The following configuration creates an infinite routing leaking loop
because 'rt vpn both' parameters are the same in both VRFs.

> router bgp 5227 vrf r1-cust4
>    no bgp network import-check
>    bgp router-id 192.168.1.1
>    address-family ipv4 unicast
>      network 28.0.0.0/24
>      rd vpn export 10:12
>      rt vpn both 52:100
>      import vpn
>      export vpn
>    exit-address-family
> !
> router bgp 5227 vrf r1-cust5
>    no bgp network import-check
>    bgp router id 192.168.1.1
>    address-family ipv4 unicast
>      network 29.0.0.0/24
>      rd vpn export 10:13
>      rt vpn both 52:100
>      import vpn
>      export vpn
>    exit-address-family

The previous commit has added a routing leak update when a nexthop
update is received from zebra. It indirectly calls
bgp_find_or_add_nexthop() in which a static route triggers a nexthop
cache entry registration that triggers a nexthop update from zebra.

Do not register again the nexthop cache entry if the BGP_STATIC_ROUTE is
already set.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-29 10:47:00 +01: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
Louis Scalbert
bb71bc02fd bgpd: fix VRF leaking with 'network import-check' (2/4)
"if not XX else" statements are confusing.

Replace two "if not XX else" statements by "if XX else" to prepare next
commits. The patch is only cosmetic.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-29 10:30:37 +01:00
Louis Scalbert
6de0cd9bdf bgpd: fix VRF leaking with 'network import-check' (1/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.

Always validate the nexthop of BGP static routes (i.e. defined with the
network statement) if 'network import-check' is defined on the source
BGP session and the prefix is present in source RIB.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-29 10:30:37 +01:00
Donald Sharp
259e3d4dac
Merge pull request #15243 from opensourcerouting/autoconf-dir-mess
*: fix a pile of directory and/or state retention related issues
2024-01-28 14:30:28 -05:00
Donald Sharp
4d92badcde
Merge pull request #15236 from louis-6wind/fix-label-cmp
bgpd: fix mpls label pointer comparison
2024-01-28 09:20:56 -05:00
David Lamparter
634f481113 *: fix frr_daemon_info indentation
clang-format doesn't understand FRR_DAEMON_INFO is a long macro where
laying out items semantically makes sense.

(Also use only one `FRR_DAEMON_INFO(` in isisd so editors don't get
confused with the mismatching `( ( )`.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-01-27 19:02:51 +01:00
Donatas Abraitis
d48b99ad4f
Merge pull request #15233 from louis-6wind/bgp-leak-no-network
bgpd: fix VRF leaking with 'no bgp network import-check'
2024-01-26 13:09:33 +02:00
Louis Scalbert
db1bb52c4b bgpd: use bgp_labels_same in bgp_update()
Use bgp_labels_same() for all label comparisons in bgpd.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-26 12:07:01 +01:00
Philippe Guibert
f254f4b6bd bgpd: fix mpls label pointer comparison
Comparing pointers is not the appropriate way to know
if the label values are the same or not. Perform a
memcmp call instead is better.

Fixes: 8ba7105057 ("bgpd: fix valgrind flagged errors")
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-26 10:16:11 +01:00
Louis Scalbert
45bf46441a bgpd: fix VRF leaking with 'no bgp network import-check'
BGP static routes are defined using the network statement, e.g.:

> router bgp XXX
>  address-family ipv4 unicast
>   network 192.168.0.0/24

When "no bgp network import-check" is set, it is impossible to
successfully import the static routes into the BGP VPN table. The prefix
is present in the table but is not marked as valid. This issue applies
regardless of whether or not routes are present in the router's RIB.

Always mark as valid the nexthops of BGP static routes when "no bgp
network import-check" is set.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-01-25 15:06:13 +01:00
Donald Sharp
7d7f90a487
Merge pull request #15223 from opensourcerouting/fix/bgp_peer_cap_uint32_to_uint64
bgpd: Increase peer's struct cap from uint32 to uint64
2024-01-25 07:32:36 -05:00
Donatas Abraitis
f31bc32196
Merge pull request #15215 from donaldsharp/pceplib_fixup
Compile issue fixups
2024-01-25 09:59:59 +02:00
Donald Sharp
aa474cf7b0 bgpd: Convert free/strdup to XSTRDUP in bgp_rfapi_cfg.c
Lots of usage of free and strdup instead of using
our internal code.  Convert over.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-24 19:03:11 -05:00
Donatas Abraitis
5298c05bd7 bgpd: Increase peer's struct cap from uint32 to uint64
Approaching the limits of uint32.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-24 23:09:52 +02:00
Donald Sharp
a5613bd36d
Merge pull request #15210 from opensourcerouting/fix/use_enum_for_graceful_restart_prints
bgpd: Fix format overflow for graceful-restart debug logs
2024-01-24 12:25:57 -05:00
Donald Sharp
1ea73983fd
Merge pull request #15209 from opensourcerouting/fix/whitespaces
bgpd: Use single whitespace when displaying show bgp summary
2024-01-24 10:48:22 -05:00
Donald Sharp
e208a7e2cc bgpd: Fix printf formatter mistake
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-24 09:11:09 -05:00
Donatas Abraitis
2c69b4b516 bgpd: Fix format overflow for graceful-restart debug logs
Use enum instead of int, and make the compiler happy when using -format-overflow.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-24 09:06:43 +02:00
Donatas Abraitis
a1baf9e84f bgpd: Use single whitespace when displaying show bgp summary
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-23 20:41:49 +02:00
Louis Scalbert
efdb5f144c bgpd: check sockopt returns in rpki_create_socket
Check (g|s)etsockopt returns in rpki_create_socket(). Coverity scanner
issues 1575916 and 1575924.

Fixes: a951752d4a ("bgpd: create cache server socket in vrf")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-23 13:13:13 +01:00
Louis Scalbert
a1d4769eca bgpd: fix memory leak in rpki_create_socket
Fix memory leak in rpki_create_socket. Coverity scanner issue 1575914.

Fixes: a951752 ("bgpd: create cache server socket in vrf")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-23 13:13:13 +01:00
Louis Scalbert
b28fd4e527 bgpd: fix res validity in rpki_create_socket
Fix coverity scanner issue 1575912 where res pointer is supposed to
valid in:

> socket = vrf_socket(res->ai_family, ...)

but is checked for validity a few lines later.

Note that vrf_getaddrinfo returns an error code if getaddrinfo() fails
to allocate res and in this case, rpki_create_socket() returns.

Fixes: a951752 ("bgpd: create cache server socket in vrf")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-23 13:12:59 +01:00
Louis Scalbert
39c8c97d41 bgpd: fix deference before check in rpki_create_socket
Fix deference before check coverity scanner issue 1575918 in
rpki_create_socket()

Fixes: a951752d4a ("bgpd: create cache server socket in vrf")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-23 12:04:52 +01:00
Louis Scalbert
8c8bb3568a bgpd: fix potential null pointers in rpki
Fix potential NULL pointer in RPKI code. Coverity scanner issues: 1575911
1575913, 1575915, 1575917, 1575919 to 1575923, 1575925 and 1575926.

Fixes: 1420189c11 ("bgpd: add support of rpki in vrf configure context")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-23 12:04:49 +01:00
Igor Ryzhov
7006880bc2 bgpd: fix route-map match probability deconfiguration callback
Add missing break. Currently, lib_route_map_entry_match_destroy is
called on every commit stage, but it should run only on APPLY.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-22 22:31:21 +02:00
Philippe Guibert
98e965565b bgpd: add show bgp rpki prefix-count command
Add "show bgp rpki prefix-count" command to show the number of received
prefixes from RPKI cache servers.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-18 13:23:42 +01:00
Philippe Guibert
36cef51cdb bgpd: add vrf name to some rpki logs
Add VRF name to some rpki logs

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-18 13:23:38 +01:00
Philippe Guibert
a54050ae75 bgpd: set rpki validation state in vrf table
Set the RPKI validation state in the VRF BGP table. It allows applying
a route-maps with "match rpki <state>" on a VRF neighbor.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-18 13:23:37 +01:00
Philippe Guibert
a42d490ac2 bgpd: show per vrf rpki configuration in show run
Show per VRF RPKI configuration in "show run".

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-18 13:23:36 +01:00
Philippe Guibert
1420189c11 bgpd: add support of rpki in vrf configure context
Add support of RPKI commands in the VRF configure context.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-18 13:23:33 +01:00
Philippe Guibert
fd83486a29 bgpd: add support of vrf to rpki in enable mode
Add a "vrf <vrfname>" argument to "show rpki" and "rpki" commands in
enable mode

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-18 13:23:30 +01:00
Philippe Guibert
a951752d4a bgpd: create cache server socket in vrf
Create cache server socket in vrf

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-18 13:22:19 +01:00
Louis Scalbert
a3bd9bad37 bgpd: start or stop rpki at vrf creation or deletion
Start or stop a RPKI cache servers in VRF when they are created or
deleted.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-18 13:22:18 +01:00
Philippe Guibert
b9d64870c1 bgpd: add a hook to inform a vrf is enabled/disabled
Add a hook to call a future callback function when bgpd knows from zebra
about the activation of de-activation of a VRF. It will be used by the
RPKI module in next commits.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-18 13:22:17 +01:00
Philippe Guibert
9746175a02 bgpd: remove rpki config command from enable node
Remove rpki config command from enable node. It cannot work.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-18 13:22:12 +01:00
Philippe Guibert
f1916d436a bgpd: move rpki variables in a per vrf fist
RPKI stores its data in global variables. It does not allow specific
date per VRF.

Move global variable to a new structure named rpki_vrf and maintain a
per VRF list of rpki_vrf. The changes are cosmetic because only the
default VRF is supported yet.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-18 12:01:53 +01:00
Donald Sharp
5eb2ddaa10
Merge pull request #15162 from opensourcerouting/fix/aspath4_set_flag
bgpd: Set capability received flag only after sanity checks
2024-01-17 08:19:34 -05:00
Donatas Abraitis
02a5da440b bgpd: Send notification if AS4 capability failed to parse (malformed)
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-16 15:29:32 +02:00
Donatas Abraitis
722195d4ec bgpd: Set role capability received flag only if parsed correctly
If we receive a malformed packet, we might end-up with a bad state.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-16 14:37:51 +02:00
Donatas Abraitis
0c74220c6e bgpd: Set hostname capability received flag only if parsed correctly
If we receive a malformed packet, we might end-up with a bad state.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-16 14:37:16 +02:00
Donatas Abraitis
9b178d246e bgpd: Set ADD-PATH capability received flag only if parsed correctly
If we receive a malformed packet, we might end-up with a bad state.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-16 14:36:20 +02:00
Donatas Abraitis
b571176aea bgpd: Set AS4 capability received flag only if parsed correctly
If we receive a malformed packet, we might end-up with a bad state.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-16 14:35:10 +02:00
Donatas Abraitis
563c2cd95c
Merge pull request #15034 from louis-6wind/topotest-rpki
bgpd, topotests: add bgp_rpki_topo1 and RPKI fixes
2024-01-15 11:26:43 +02:00
Donald Sharp
8006207a92
Merge pull request #15138 from opensourcerouting/fix/drop_unused_var_bgp_damp
bgpd: Drop dampening `tmax` variable from struct
2024-01-12 14:34:46 -05:00
Donatas Abraitis
945318802e
Merge pull request #15121 from routingrocks/rajesh/bgp_peer_ttl
bgpd: Set correct TTL for the dynamic neighbor peers
2024-01-12 20:26:34 +02:00
Donatas Abraitis
a3ad0d21fb bgpd: Drop dampening tmax variable from struct
Not used anywhere.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-12 11:29:43 +02:00
Rajesh Varatharaj
68573c34d4 bgpd: Set correct TTL for the dynamic neighbor peers
In an EBGP multihop configuration with dynamic neighbors, the TTL configured is not being updated for the socket.

Issue:
Assume the following topology:
Host (Dynamic peer to spine - 192.168.1.100) - Leaf - Spine (192.168.1.1)

When the host establishes a BGP multihop session to the spine,
the connection uses the MAXTTL value instead of the configured TTL (in this case, 2).
This issue is only observed with dynamic peers.

Logs: look at the TTL is still MAXTTL, instead of “2” configured.

18:13:18.872395 48:b0:2d:0c:58:0b > 48:b0:2d:66:64:6b, ethertype IPv4 (0x0800), length 85: (tos 0xc0, ttl 255, id 32078, offset 0, flags [DF], proto TCP (6), length 71)
192.168.1.100.179 > 192.168.1.1.40967: Flags [P.], cksum 0xfe89 (correct), seq 28406:28425, ack 28424, win 255, options [nop,nop,TS val 4192664793 ecr 2814447051], length 19: BGP
Keepalive Message (4), length: 19

Fix:
Whenever a dynamic peer is created, the socket TTL should be updated with the configured TTL, in this case 2.

19:13:24.894890 48:b0:2d:0c:58:0b > 48:b0:2d:66:64:6b, ethertype IPv4 (0x0800), length 85: (tos 0xc0, ttl 2, id 1131, offset 0, flags [DF], proto TCP (6), length 71)
    192.168.1.100.179 > 192.168.1.1.41937: Flags [P.], cksum 0x7a67 (correct), seq 2046150759:2046150778, ack 4286110599, win 255, options [nop,nop,TS val 4196270815 ecr 2818051226], length 19: BGP
        Keepalive Message (4), length: 19

Testing: UT

UT logs:
2023-12-29T19:13:21.892205+00:00 host bgpd[1591425]: [WWPV7-YSZB5] Dynamic Neighbor 192.168.1.1/32 matches group test listen range 192.168.1.0/30
2023-12-29T19:13:21.892654+00:00 host bgpd[1591425]: [GBPAR-M31QF] 192.168.1.1 Dynamic Neighbor added, group test count 1
2023-12-29T19:13:21.892993+00:00 host bgpd[1591425]: [GPE2H-K9QRE] bgp_set_socket_ttl:  set TxTTL on peer (rtrid 0.0.0.0) socket, err = 2, peer ttl 2

 Conflicts:
	bgpd/bgp_network.c

Ticket: #
Signed-off-by: Rajesh Varatharaj <rvaratharaj@nvidia.com>
2024-01-11 10:18:03 -08:00
Donald Sharp
86cbd5831e
Merge pull request #15128 from opensourcerouting/fix/bgp_oad_ECOMMUNITY_ORIGIN_VALIDATION_STATE
bgpd: Recent EBGP-OAD improvements
2024-01-11 09:07:31 -05:00
Philippe Guibert
93f05b03f8 bgpd: fix debug rpki display in show run
Only include "debug rpki" in "show run" if it was requested from the
configure mode but not it was from the enabled mode.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-11 14:41:58 +01:00
Philippe Guibert
fc7b905959 bgpd: add hooks for displaying module debug messages
when a plugin is attached, some debugs may be attached to that plugin.
For that, add one hook that is interacting with vty: a boolean indicates
what the usage is for: either for impacting the 'show running-config',
or for impacting the 'show debugging' command.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-11 14:38:23 +01:00
Philippe Guibert
da94769756 bgpd: do not show default rpki timers in show run
"show run" displays the default RPKI timers when at least one cache
server is configured.

Only display the RPKI timers that differs from the default values.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-11 14:38:08 +01:00
Philippe Guibert
9d87a567f9 bgpd: remove double spaces with rpki running config & ssh
remove double spaces when doing show running-config.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-11 14:13:46 +01:00
Louis Scalbert
baf0bda268 bgpd: fix resetting rpki timer at no rpki
RPKI configuration is not totally flushed when doing "no rpki". Timers
remains to default values.

> r2# sh run bgpd
> [...]
> rpki
>  rpki retry_interval 5
>  rpki cache 192.0.2.1 15432 preference 1
> exit
> [...]
> r2# conf t
> r2(config)# no rpki
> r2(config)# do sh run
> [...]
> rpki
>  rpki retry_interval 5
> exit

Reset the timers after doing "no rpki"

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-11 14:13:46 +01:00
Louis Scalbert
51a97a07d8 bgpd: fix crash when re-adding a rpki server
Fix a crash when re-adding a rpki server:

> r2# sh run bgpd
> [...]
> rpki
>  rpki retry_interval 5
>  rpki cache 192.0.2.1 15432 preference 1
> exit
> [...]
> r2# conf t
> r2(config)# rpki
> r2(config-rpki)# no rpki cache 192.0.2.1 15432 preference 1
> r2(config-rpki)# do show rpki cache-connection
> Cannot find a connected group.
> r2(config-rpki)# rpki cache 192.0.2.1 15432 preference 1
> r2(config-rpki)# do show rpki cache-connection
> vtysh: error reading from bgpd: Resource temporarily unavailable (11)Warning: closing connection to bgpd because of an I/O error!

> #0  raise (sig=<optimized out>) at ../sysdeps/unix/sysv/linux/raise.c:50
> #1  0x00007f3fd2d16e57 in core_handler (signo=11, siginfo=0x7ffffd5931b0, context=0x7ffffd593080) at lib/sigevent.c:246
> #2  <signal handler called>
> #3  0x00007f3fd26926b4 in tommy_list_head (list=0x2e322e302e323931) at /home/lscalber/git/rtrlib/./third-party/tommyds/tommylist.h:125
> #4  0x00007f3fd2693812 in rtr_mgr_get_first_group (config=0x55fbf31d7f00) at /home/lscalber/git/rtrlib/rtrlib/rtr_mgr.c:409
> #5  0x00007f3fd2ebef59 in get_connected_group () at bgpd/bgp_rpki.c:718
> #6  0x00007f3fd2ec0b39 in show_rpki_cache_connection_magic (self=0x7f3fd2ec69c0 <show_rpki_cache_connection_cmd>, vty=0x55fbf31f9ef0, argc=3, argv=0x55fbf31f99d0, uj=0x0)
> #   at bgpd/bgp_rpki.c:1575
> #7  0x00007f3fd2ebd4da in show_rpki_cache_connection (self=0x7f3fd2ec69c0 <show_rpki_cache_connection_cmd>, vty=0x55fbf31f9ef0, argc=3, argv=0x55fbf31f99d0) at ./bgpd/bgp_rpki_clippy.c:648
> #8  0x00007f3fd2c8a142 in cmd_execute_command_real (vline=0x55fbf31f9990, vty=0x55fbf31f9ef0, cmd=0x0, up_level=0) at lib/command.c:978
> #9  0x00007f3fd2c8a25c in cmd_execute_command (vline=0x55fbf31e5260, vty=0x55fbf31f9ef0, cmd=0x0, vtysh=0) at lib/command.c:1028
> #10 0x00007f3fd2c8a7f1 in cmd_execute (vty=0x55fbf31f9ef0, cmd=0x55fbf3200680 "do show rpki cache-connection ", matched=0x0, vtysh=0) at lib/command.c:1203
> #11 0x00007f3fd2d36548 in vty_command (vty=0x55fbf31f9ef0, buf=0x55fbf3200680 "do show rpki cache-connection ") at lib/vty.c:594
> #12 0x00007f3fd2d382e1 in vty_execute (vty=0x55fbf31f9ef0) at lib/vty.c:1357
> #13 0x00007f3fd2d3a519 in vtysh_read (thread=0x7ffffd5963c0) at lib/vty.c:2365
> #14 0x00007f3fd2d2faf6 in event_call (thread=0x7ffffd5963c0) at lib/event.c:1974
> #15 0x00007f3fd2cc238e in frr_run (master=0x55fbf2a0cd60) at lib/libfrr.c:1214
> #16 0x000055fbf073de40 in main (argc=9, argv=0x7ffffd596618) at bgpd/bgp_main.c:510

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-11 14:13:46 +01:00
Louis Scalbert
f8875f53d6 bgpd: fix rpki compilation without rtrlib ssh
Fix RPKI module compilation when rtrlib is compiled without SSH support,
ie. with cmake option:

> -D RTRLIB_TRANSPORT_SSH=No

> bgpd/bgp_rpki.c: In function ‘config_write’:
> bgpd/bgp_rpki.c:1062:3: error: enumeration value ‘SSH’ not handled in switch [-Werror=switch-enum]
>  1062 |   switch (cache->type) {
>       |   ^~~~~~
> bgpd/bgp_rpki.c: In function ‘show_rpki_cache_connection_magic’:
> bgpd/bgp_rpki.c:1598:3: error: enumeration value ‘SSH’ not handled in switch [-Werror=switch-enum]
>  1598 |   switch (cache->type) {
>       |   ^~~~~~
> cc1: all warnings being treated as errors

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-11 14:13:46 +01:00
Louis Scalbert
aecdab5bd4 bgpd: add json error message to rpki
Add error messages to rpki JSON output instead of an empty JSON.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-11 14:13:46 +01:00
Louis Scalbert
4011682a1a bgpd: fix show rpki json void output
"show rpki XX json" should not return a void output because json.loads()
considers it to be an incorrect JSON.

> >>> json.loads("")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
>     return _default_decoder.decode(s)
>   File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
>     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
>   File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode
>     raise JSONDecodeError("Expecting value", s, err.value) from None
> json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
> >>> json.loads("{}")
> {}

Return "{}" instead in such a case.

Link: https://github.com/FRRouting/frr/pull/15034
Fixes: dff41cc8a9 ("bgpd: Add JSON output for `show rpki prefix` and other show commands")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-11 14:13:46 +01:00
Donatas Abraitis
67e8ef293f
Merge pull request #15098 from donaldsharp/lib_zebra_h_cleanup_2
Lib zebra h cleanup 2
2024-01-11 14:50:21 +02:00
Donatas Abraitis
a56beac98b bgpd: Allow sending Origin Validation State extended community over EBGP-OAD
https://datatracker.ietf.org/doc/html/draft-uttaro-idr-bgp-oad#section-3.13

Extended communities which are non-transitive across an AS boundary MAY be
advertised over an EBGP-OAD session if allowed by explicit policy configuration.

If allowed, all the members of the OAD SHOULD be configured to use the same
criteria.

For example, the Origin Validation State Extended Community, defined as
non-transitive in [RFC8097], can be advertised to peers in the same OAD.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-11 11:35:20 +02:00
Donatas Abraitis
584b031a4d bgpd: Show external session sub-type (OAD) if exists
```
r1# sh ip bgp 10.10.10.10/32
BGP routing table entry for 10.10.10.10/32, version 1
Paths: (2 available, best #2, table default)
  Advertised to non peer-group peers:
  192.168.1.2 192.168.1.4
  65002 65003
    192.168.1.2 from 192.168.1.2 (192.168.2.2)
      Origin incomplete, metric 123, localpref 123, valid, external (oad)
      Last update: Thu Jan 11 10:46:32 2024
  65004 65005
    192.168.1.4 from 192.168.1.4 (192.168.4.4)
      Origin incomplete, metric 123, localpref 123, valid, external, best (Peer Type)
      Last update: Thu Jan 11 10:46:30 2024
r1#
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-11 10:53:57 +02:00
Donatas Abraitis
a8474e4a46 bgpd: Prefer routes over eBGP versus eBGP-OAD
If at least one of the candidate routes was received via EBGP, remove from
consideration all routes that were received via EBGP-OAD and IBGP.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-11 10:53:56 +02:00
Donald Sharp
3f03ec1021 bgpd: data is set but never used
I've kept the assignment in a comment because I am concerned
about new code being added later that the data pointer would
not be set correctly.  Next coder can see the commented
out line and uncomment it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-09 13:03:43 -05:00
Donald Sharp
e92a7e9c14 bgpd: Clean up issues found in SA with clang 14
3 different issues:

a) length never used
b) safi never used
c) length never used.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-09 13:03:43 -05:00
Donald Sharp
c6d94a7056 *: zebra.h should not have fcntl.h
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-09 12:50:40 -05:00
Donald Sharp
848dcf3d03 *: remove sys/stat.h from zebra.h
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-09 12:39:23 -05:00
Donald Sharp
153ab6eb43
Merge pull request #15122 from opensourcerouting/fix/drop_packet_send_debugs
bgpd: Change printing format show debugging for debug bgp updates
2024-01-09 12:21:09 -05:00
Russ White
6c8706802a
Merge pull request #15108 from opensourcerouting/fix/debug_bgp_updates_detail
bgpd: Add `debug bgp updates detail` command
2024-01-09 10:18:50 -05:00
Russ White
d5a0a70bbf
Merge pull request #15001 from pguibert6WIND/zebra_nexthop_rework
Zebra nexthop rework
2024-01-09 10:11:35 -05:00
Donald Sharp
92d0242a51
Merge pull request #15120 from opensourcerouting/fix/memory_leak_for_default_originate
bgpd: Fix memory leak for default-originate with route-map
2024-01-09 10:03:29 -05:00
Donatas Abraitis
546fe3144c bgpd: Change printing format show debugging for debug bgp updates
Before:

```
BGP debugging status:
  BGP updates debugging is on (inbound) for 127.0.0.1 with prefix-list rn-dummy 192.168.10.18 with prefix-list rn-dummy 1.1.1.1
```

After:

```
BGP debugging status:
  BGP updates debugging is on (inbound) for:
   127.0.0.1 with prefix-list rn-dummy
   192.168.10.18 with prefix-list rn-dummy
   192.168.10.20
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-09 10:08:54 +02:00
Donatas Abraitis
8f3d99b495 bgpd: Drop BGP_DEBUG_PACKET_SEND_DETAIL/BGP_DEBUG_PACKET_SEND consts
Not used anywhere.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-09 09:58:00 +02:00
Donatas Abraitis
74c1d4f8c0 bgpd: Fix memory leak for default-originate with route-map
```
Direct leak of 40 byte(s) in 1 object(s) allocated from:
    0 0x7fc4b81eed28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    1 0x7fc4b7bd60bb in qcalloc lib/memory.c:105
    2 0x56221dc19207 in aspath_dup bgpd/bgp_aspath.c:689
    3 0x56221daacd42 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    4 0x7fc4b7c3891a in route_map_apply_ext lib/routemap.c:2687
    5 0x56221dace552 in subgroup_default_originate bgpd/bgp_updgrp_adv.c:906
    6 0x56221dabf79c in update_group_default_originate_route_map_walkcb bgpd/bgp_updgrp.c:2105
    7 0x56221dabde4e in update_group_walkcb bgpd/bgp_updgrp.c:1721
    8 0x7fc4b7b9d398 in hash_walk lib/hash.c:270
    9 0x56221dac94cb in update_group_af_walk bgpd/bgp_updgrp.c:2062
    10 0x56221dac9b0f in update_group_walk bgpd/bgp_updgrp.c:2071
    11 0x56221dac9fd5 in update_group_refresh_default_originate_route_map bgpd/bgp_updgrp.c:2118
    12 0x7fc4b7c7fc54 in event_call lib/event.c:1974
    13 0x7fc4b7bb9276 in frr_run lib/libfrr.c:1214
    14 0x56221d9217fd in main bgpd/bgp_main.c:510
    15 0x7fc4b6bf2c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)
```

tmp_pi.attr should be flushed since it's already interned (new_attr) or the
origin value is used (attr).

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-08 20:48:56 +02:00
Donald Sharp
bed55ecc8e bgpd: show_adj_route_vpn always leaked json memory
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-07 15:55:15 -05:00
Donald Sharp
733511782f
Merge pull request #15102 from opensourcerouting/Revert-memleak-PR14811
Revert "bgpd: On shutdown do not create a workqueue for the self peer"
2024-01-07 12:30:22 -05:00
Donatas Abraitis
7a474b8754 bgpd: Add debug bgp updates detail command
When filtering with `debug bgp updates in x.x.x.x prefix-list plist`, we want
to filter out unnecessary messages like:

```
127.0.0.1(Unknown) rcvd UPDATE wlen 0 attrlen 20 alen 5
```

Such a line as above will be repeated for all the paths received and it's useless
without knowing the prefix (because NLRIs are not parsed yet).

But want to see only relevant ones:

```
127.0.0.1(Unknown) rcvd UPDATE w/ attr: nexthop 127.0.0.1, origin i, path 65002
127.0.0.1(Unknown) rcvd 10.255.255.1/32 IPv4 unicast
```

With `debug bgp updates detail` we can combine this to something like:

```
127.0.0.1(Unknown) rcvd UPDATE w/ attr: nexthop 127.0.0.1, origin i, path 65002
127.0.0.1(Unknown) rcvd UPDATE wlen 0 attrlen 20 alen 5
127.0.0.1(Unknown) rcvd 10.255.255.1/32 IPv4 unicast
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-07 16:17:11 +02:00
Donatas Abraitis
fa62132278
Merge pull request #15104 from donaldsharp/label_pool_manager
bgpd: bgp_sync_label_manager failure case
2024-01-07 15:11:38 +02:00
Donald Sharp
02049ffb13 bgpd: bgp_sync_label_manager failure case
There are several problems with the bgp_sync_label_manager
function:

a) It is possible that a request in the lp->requests
fifo will be unable to be filled at this point in time
and the lf will be leaked and not ever fullfilled.

b) The bgp_sync_label_manager runs one time a second
irrelevant if there is work to do or not.

To fix (a) just add the request back to the requests
fifo and set the timer to pop in the future.

To fix (b) just every time something is put into
the request pool start a timer to run in 1 second
and do not restart it if all the work is done.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-06 20:26:14 -05:00
Martin Winter
0222f553fb
Revert "bgpd: On shutdown do not create a workqueue for the self peer"
This reverts commit 7bf3c2fb19.
Commit reverted as it introduces a memoery leak during the tests

Signed-off-by: Martin Winter <mwinter@opensourcerouting.org>
2024-01-06 15:57:12 +01:00
Christian Hopps
43331c0d78
Merge pull request #15092 from donaldsharp/lib_zebra_h_cleanup
Lib zebra h cleanup
2024-01-05 09:40:56 -05:00
Donald Sharp
a57379fa14 bgpd: rfapi was not using internal zlog_backtrace()
The rfapi code was not using the zlog_backtrace()
functionality.  Let's just convert over to using
the proper functionality that we have built in now.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-04 14:18:16 -05:00
Louis Scalbert
6001c765e2 bgpd: fix ecommunity_fill_pbr_action heap-buffer-overflow
Fix the following heap-buffer-overflow:

> ==3901635==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020003a5940 at pc 0x56260067bb48 bp 0x7ffe8a4f3840 sp 0x7ffe8a4f3838
> READ of size 4 at 0x6020003a5940 thread T0
>     #0 0x56260067bb47 in ecommunity_fill_pbr_action bgpd/bgp_ecommunity.c:1587
>     #1 0x5626007a246e in bgp_pbr_build_and_validate_entry bgpd/bgp_pbr.c:939
>     #2 0x5626007b25e6 in bgp_pbr_update_entry bgpd/bgp_pbr.c:2933
>     #3 0x562600909d18 in bgp_zebra_announce bgpd/bgp_zebra.c:1351
>     #4 0x5626007d5efd in bgp_process_main_one bgpd/bgp_route.c:3528
>     #5 0x5626007d6b43 in bgp_process_wq bgpd/bgp_route.c:3641
>     #6 0x7f450f34c2cc in work_queue_run lib/workqueue.c:266
>     #7 0x7f450f327a27 in event_call lib/event.c:1970
>     #8 0x7f450f21a637 in frr_run lib/libfrr.c:1213
>     #9 0x56260062fc04 in main bgpd/bgp_main.c:540
>     #10 0x7f450ee2dd09 in __libc_start_main ../csu/libc-start.c:308
>     #11 0x56260062ca29 in _start (/usr/lib/frr/bgpd+0x2e3a29)
>
> 0x6020003a5940 is located 0 bytes to the right of 16-byte region [0x6020003a5930,0x6020003a5940)
> allocated by thread T0 here:
>     #0 0x7f450f6aa1f8 in __interceptor_realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:164
>     #1 0x7f450f244f8a in qrealloc lib/memory.c:112
>     #2 0x562600673313 in ecommunity_add_val_internal bgpd/bgp_ecommunity.c:143
>     #3 0x5626006735bc in ecommunity_uniq_sort_internal bgpd/bgp_ecommunity.c:193
>     #4 0x5626006737e3 in ecommunity_parse_internal bgpd/bgp_ecommunity.c:228
>     #5 0x562600673890 in ecommunity_parse bgpd/bgp_ecommunity.c:236
>     #6 0x562600640469 in bgp_attr_ext_communities bgpd/bgp_attr.c:2674
>     #7 0x562600646eb3 in bgp_attr_parse bgpd/bgp_attr.c:3893
>     #8 0x562600791b7e in bgp_update_receive bgpd/bgp_packet.c:2141
>     #9 0x56260079ba6b in bgp_process_packet bgpd/bgp_packet.c:3406
>     #10 0x7f450f327a27 in event_call lib/event.c:1970
>     #11 0x7f450f21a637 in frr_run lib/libfrr.c:1213
>     #12 0x56260062fc04 in main bgpd/bgp_main.c:540
>     #13 0x7f450ee2dd09 in __libc_start_main ../csu/libc-start.c:308

Fixes: dacf6ec120 ("bgpd: utility routine to convert flowspec actions into pbr actions")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-04 17:32:01 +01:00
Russ White
2aef6958f8
Merge pull request #15074 from chiragshah6/fdev4
bgpd: unimport evpn routes when implicit withdraw
2024-01-02 17:22:11 -05:00
Donatas Abraitis
bfe52f8929
Merge pull request #15068 from chiragshah6/zdev
bgpd: lttng tp add ethtag to macip zebra send
2024-01-02 10:42:28 +02:00