2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-05-20 02:40:34 +02:00
|
|
|
/*
|
|
|
|
* Nexthop structure definition.
|
2015-11-27 17:46:54 +01:00
|
|
|
* Copyright (C) 1997, 98, 99, 2001 Kunihiro Ishiguro
|
2015-05-20 02:40:34 +02:00
|
|
|
* Copyright (C) 2013 Cumulus Networks, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LIB_NEXTHOP_H
|
|
|
|
#define _LIB_NEXTHOP_H
|
|
|
|
|
|
|
|
#include "prefix.h"
|
2016-04-15 19:29:51 +02:00
|
|
|
#include "mpls.h"
|
2020-01-13 20:34:03 +01:00
|
|
|
#include "vxlan.h"
|
2020-08-19 02:46:33 +02:00
|
|
|
#include "srv6.h"
|
2015-05-20 02:40:34 +02:00
|
|
|
|
2019-02-07 23:10:31 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-09-08 18:38:53 +02:00
|
|
|
/* Maximum next hop string length - gateway + ifindex */
|
|
|
|
#define NEXTHOP_STRLEN (INET6_ADDRSTRLEN + 30)
|
|
|
|
|
2015-05-20 02:40:34 +02:00
|
|
|
union g_addr {
|
|
|
|
struct in_addr ipv4;
|
|
|
|
struct in6_addr ipv6;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum nexthop_types_t {
|
|
|
|
NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
|
|
|
|
NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
|
|
|
|
NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
|
|
|
|
NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
|
|
|
|
NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
|
|
|
|
NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
|
|
|
|
};
|
2012-04-11 23:52:46 +02:00
|
|
|
|
|
|
|
enum blackhole_type {
|
|
|
|
BLACKHOLE_UNSPEC = 0,
|
|
|
|
BLACKHOLE_NULL,
|
|
|
|
BLACKHOLE_REJECT,
|
|
|
|
BLACKHOLE_ADMINPROHIB,
|
|
|
|
};
|
2015-05-20 02:40:34 +02:00
|
|
|
|
2020-01-13 20:34:03 +01:00
|
|
|
enum nh_encap_type {
|
|
|
|
NET_VXLAN = 100, /* value copied from FPM_NH_ENCAP_VXLAN. */
|
|
|
|
};
|
|
|
|
|
2020-06-30 21:52:37 +02:00
|
|
|
/* Fixed limit on the number of backup nexthops per primary nexthop */
|
|
|
|
#define NEXTHOP_MAX_BACKUPS 8
|
|
|
|
|
|
|
|
/* Backup index value is limited */
|
|
|
|
#define NEXTHOP_BACKUP_IDX_MAX 255
|
|
|
|
|
2015-05-20 02:40:34 +02:00
|
|
|
/* Nexthop structure. */
|
|
|
|
struct nexthop {
|
|
|
|
struct nexthop *next;
|
|
|
|
struct nexthop *prev;
|
|
|
|
|
2018-02-08 15:12:12 +01:00
|
|
|
/*
|
|
|
|
* What vrf is this nexthop associated with?
|
|
|
|
*/
|
|
|
|
vrf_id_t vrf_id;
|
|
|
|
|
2015-05-20 02:40:34 +02:00
|
|
|
/* Interface index. */
|
2016-01-18 11:12:10 +01:00
|
|
|
ifindex_t ifindex;
|
2015-05-20 02:40:34 +02:00
|
|
|
|
|
|
|
enum nexthop_types_t type;
|
|
|
|
|
2022-06-23 16:22:45 +02:00
|
|
|
uint16_t flags;
|
2015-05-20 02:40:34 +02:00
|
|
|
#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
|
|
|
|
#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
|
|
|
|
#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
|
2020-02-11 17:14:37 +01:00
|
|
|
#define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed
|
|
|
|
* onlink.
|
|
|
|
*/
|
|
|
|
#define NEXTHOP_FLAG_DUPLICATE (1 << 4) /* nexthop duplicates another
|
|
|
|
* active one
|
|
|
|
*/
|
|
|
|
#define NEXTHOP_FLAG_RNH_FILTERED (1 << 5) /* rmap filtered, used by rnh */
|
2020-01-16 22:24:16 +01:00
|
|
|
#define NEXTHOP_FLAG_HAS_BACKUP (1 << 6) /* Backup nexthop index is set */
|
2020-07-20 13:43:54 +02:00
|
|
|
#define NEXTHOP_FLAG_SRTE (1 << 7) /* SR-TE color used for BGP traffic */
|
2022-02-22 10:22:45 +01:00
|
|
|
#define NEXTHOP_FLAG_EVPN (1 << 8) /* nexthop is EVPN */
|
2022-06-23 16:27:56 +02:00
|
|
|
#define NEXTHOP_FLAG_LINKDOWN (1 << 9) /* is not removed on link down */
|
2020-01-16 22:24:16 +01:00
|
|
|
|
2017-05-30 16:14:42 +02:00
|
|
|
#define NEXTHOP_IS_ACTIVE(flags) \
|
|
|
|
(CHECK_FLAG(flags, NEXTHOP_FLAG_ACTIVE) \
|
|
|
|
&& !CHECK_FLAG(flags, NEXTHOP_FLAG_DUPLICATE))
|
2015-05-20 02:40:34 +02:00
|
|
|
|
|
|
|
/* Nexthop address */
|
2010-02-05 04:31:56 +01:00
|
|
|
union {
|
|
|
|
union g_addr gate;
|
|
|
|
enum blackhole_type bh_type;
|
|
|
|
};
|
2015-05-20 02:40:34 +02:00
|
|
|
union g_addr src;
|
2015-05-20 02:47:24 +02:00
|
|
|
union g_addr rmap_src; /* Src is set via routemap */
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-20 02:40:34 +02:00
|
|
|
/* Nexthops obtained by recursive resolution.
|
|
|
|
*
|
|
|
|
* If the nexthop struct needs to be resolved recursively,
|
|
|
|
* NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops
|
|
|
|
* obtained by recursive resolution will be added to `resolved'.
|
2017-06-27 12:49:49 +02:00
|
|
|
*/
|
2015-05-20 02:40:34 +02:00
|
|
|
struct nexthop *resolved;
|
2017-06-27 12:49:49 +02:00
|
|
|
/* Recursive parent */
|
|
|
|
struct nexthop *rparent;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-06-01 19:19:30 +02:00
|
|
|
/* Type of label(s), if any */
|
|
|
|
enum lsp_types_t nh_label_type;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-04-16 04:19:37 +02:00
|
|
|
/* Label(s) associated with this nexthop. */
|
2018-01-21 22:11:50 +01:00
|
|
|
struct mpls_label_stack *nh_label;
|
2019-12-06 14:58:47 +01:00
|
|
|
|
|
|
|
/* Weight of the nexthop ( for unequal cost ECMP ) */
|
|
|
|
uint8_t weight;
|
2020-01-16 22:24:16 +01:00
|
|
|
|
2020-06-30 21:52:37 +02:00
|
|
|
/* Count and index of corresponding backup nexthop(s) in a backup list;
|
2020-01-16 22:24:16 +01:00
|
|
|
* only meaningful if the HAS_BACKUP flag is set.
|
|
|
|
*/
|
2020-06-30 21:52:37 +02:00
|
|
|
uint8_t backup_num;
|
|
|
|
uint8_t backup_idx[NEXTHOP_MAX_BACKUPS];
|
2020-01-13 20:34:03 +01:00
|
|
|
|
|
|
|
/* Encapsulation information. */
|
|
|
|
enum nh_encap_type nh_encap_type;
|
|
|
|
union {
|
|
|
|
vni_t vni;
|
|
|
|
} nh_encap;
|
2020-07-20 13:43:54 +02:00
|
|
|
|
2022-12-15 10:04:32 +01:00
|
|
|
/* EVPN router's MAC.
|
|
|
|
* Don't support multiple RMAC from the same VTEP yet, so it's not
|
|
|
|
* included in hash key.
|
|
|
|
*/
|
|
|
|
struct ethaddr rmac;
|
|
|
|
|
2020-07-20 13:43:54 +02:00
|
|
|
/* SR-TE color used for matching SR-TE policies */
|
|
|
|
uint32_t srte_color;
|
2020-08-19 02:46:33 +02:00
|
|
|
|
2021-04-05 15:29:12 +02:00
|
|
|
/* SRv6 information */
|
|
|
|
struct nexthop_srv6 *nh_srv6;
|
2015-05-20 02:40:34 +02:00
|
|
|
};
|
|
|
|
|
2019-11-08 20:13:33 +01:00
|
|
|
/* Utility to append one nexthop to another. */
|
|
|
|
#define NEXTHOP_APPEND(to, new) \
|
|
|
|
do { \
|
|
|
|
(to)->next = (new); \
|
|
|
|
(new)->prev = (to); \
|
|
|
|
(new)->next = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
2015-11-27 17:46:54 +01:00
|
|
|
struct nexthop *nexthop_new(void);
|
|
|
|
|
|
|
|
void nexthop_free(struct nexthop *nexthop);
|
|
|
|
void nexthops_free(struct nexthop *nexthop);
|
|
|
|
|
2019-11-08 20:13:33 +01:00
|
|
|
void nexthop_add_labels(struct nexthop *nexthop, enum lsp_types_t ltype,
|
|
|
|
uint8_t num_labels, const mpls_label_t *labels);
|
2016-04-16 04:19:37 +02:00
|
|
|
void nexthop_del_labels(struct nexthop *);
|
lib, zebra: Do not have duplicate memory type problems
In zebra_mpls.c it has a usage of MTYPE_NH_LABEL which is
defined in both lib/nexthop.c and zebra/zebra_mpls.c. The
usage in zebra_mpls.c is a realloc. This leads to a crash:
(gdb) bt
0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=126487246404032) at ./nptl/pthread_kill.c:44
1 __pthread_kill_internal (signo=6, threadid=126487246404032) at ./nptl/pthread_kill.c:78
2 __GI___pthread_kill (threadid=126487246404032, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
3 0x0000730a1b442476 in __GI_raise (sig=6) at ../sysdeps/posix/raise.c:26
4 0x0000730a1b94fb18 in core_handler (signo=6, siginfo=0x7ffeed1e07b0, context=0x7ffeed1e0680) at lib/sigevent.c:268
5 <signal handler called>
6 __pthread_kill_implementation (no_tid=0, signo=6, threadid=126487246404032) at ./nptl/pthread_kill.c:44
7 __pthread_kill_internal (signo=6, threadid=126487246404032) at ./nptl/pthread_kill.c:78
8 __GI___pthread_kill (threadid=126487246404032, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
9 0x0000730a1b442476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
10 0x0000730a1b4287f3 in __GI_abort () at ./stdlib/abort.c:79
11 0x0000730a1b9984f5 in _zlog_assert_failed (xref=0x730a1ba59480 <_xref.16>, extra=0x0) at lib/zlog.c:789
12 0x0000730a1b8f8908 in mt_count_free (mt=0x576e0edda520 <MTYPE_NH_LABEL>, ptr=0x576e36617b80) at lib/memory.c:74
13 0x0000730a1b8f8a59 in qrealloc (mt=0x576e0edda520 <MTYPE_NH_LABEL>, ptr=0x576e36617b80, size=16) at lib/memory.c:112
14 0x0000576e0ec85e2e in nhlfe_out_label_update (nhlfe=0x576e368895f0, nh_label=0x576e3660e9b0) at zebra/zebra_mpls.c:1462
15 0x0000576e0ec833ff in lsp_install (zvrf=0x576e3655fb50, label=17, rn=0x576e366197c0, re=0x576e3660a590) at zebra/zebra_mpls.c:224
16 0x0000576e0ec87c34 in zebra_mpls_lsp_install (zvrf=0x576e3655fb50, rn=0x576e366197c0, re=0x576e3660a590) at zebra/zebra_mpls.c:2215
17 0x0000576e0ecbb427 in rib_process_update_fib (zvrf=0x576e3655fb50, rn=0x576e366197c0, old=0x576e36619660, new=0x576e3660a590) at zebra/zebra_rib.c:1084
18 0x0000576e0ecbc230 in rib_process (rn=0x576e366197c0) at zebra/zebra_rib.c:1480
19 0x0000576e0ecbee04 in process_subq_route (lnode=0x576e368e0270, qindex=8 '\b') at zebra/zebra_rib.c:2661
20 0x0000576e0ecc0711 in process_subq (subq=0x576e3653fc80, qindex=META_QUEUE_BGP) at zebra/zebra_rib.c:3226
21 0x0000576e0ecc07f9 in meta_queue_process (dummy=0x576e3653fae0, data=0x576e3653fb80) at zebra/zebra_rib.c:3265
22 0x0000730a1b97d2a9 in work_queue_run (thread=0x7ffeed1e3f30) at lib/workqueue.c:282
23 0x0000730a1b96b039 in event_call (thread=0x7ffeed1e3f30) at lib/event.c:1996
24 0x0000730a1b8e4d2d in frr_run (master=0x576e36277e10) at lib/libfrr.c:1232
25 0x0000576e0ec35ca9 in main (argc=7, argv=0x7ffeed1e4208) at zebra/main.c:536
Clearly replacing a label stack is an operation that should be owned by
lib/nexthop.c. So lets move this function into there and have
zebra_mpls.c just call the function to replace the label stack.
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-11-22 17:02:15 +01:00
|
|
|
void nexthop_change_labels(struct nexthop *nexthop, struct mpls_label_stack *new_stack);
|
|
|
|
|
2021-04-05 15:29:12 +02:00
|
|
|
void nexthop_add_srv6_seg6local(struct nexthop *nexthop, uint32_t action,
|
|
|
|
const struct seg6local_context *ctx);
|
|
|
|
void nexthop_del_srv6_seg6local(struct nexthop *nexthop);
|
2023-07-26 17:56:32 +02:00
|
|
|
void nexthop_add_srv6_seg6(struct nexthop *nexthop, const struct in6_addr *seg,
|
|
|
|
int num_segs);
|
2021-04-05 15:29:12 +02:00
|
|
|
void nexthop_del_srv6_seg6(struct nexthop *nexthop);
|
2016-04-16 04:19:37 +02:00
|
|
|
|
2019-11-22 17:10:42 +01:00
|
|
|
/*
|
|
|
|
* Allocate a new nexthop object and initialize it from various args.
|
|
|
|
*/
|
|
|
|
struct nexthop *nexthop_from_ifindex(ifindex_t ifindex, vrf_id_t vrf_id);
|
|
|
|
struct nexthop *nexthop_from_ipv4(const struct in_addr *ipv4,
|
|
|
|
const struct in_addr *src,
|
|
|
|
vrf_id_t vrf_id);
|
|
|
|
struct nexthop *nexthop_from_ipv4_ifindex(const struct in_addr *ipv4,
|
|
|
|
const struct in_addr *src,
|
|
|
|
ifindex_t ifindex, vrf_id_t vrf_id);
|
|
|
|
struct nexthop *nexthop_from_ipv6(const struct in6_addr *ipv6,
|
|
|
|
vrf_id_t vrf_id);
|
|
|
|
struct nexthop *nexthop_from_ipv6_ifindex(const struct in6_addr *ipv6,
|
|
|
|
ifindex_t ifindex, vrf_id_t vrf_id);
|
2021-08-24 16:53:29 +02:00
|
|
|
struct nexthop *nexthop_from_blackhole(enum blackhole_type bh_type,
|
|
|
|
vrf_id_t nh_vrf_id);
|
2019-11-22 17:10:42 +01:00
|
|
|
|
2018-03-19 14:01:52 +01:00
|
|
|
/*
|
|
|
|
* Hash a nexthop. Suitable for use with hash tables.
|
|
|
|
*
|
|
|
|
* This function uses the following values when computing the hash:
|
|
|
|
* - vrf_id
|
|
|
|
* - ifindex
|
|
|
|
* - type
|
|
|
|
* - gate
|
|
|
|
*
|
|
|
|
* nexthop
|
|
|
|
* The nexthop to hash
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 32-bit hash of nexthop
|
|
|
|
*/
|
2019-04-02 19:57:48 +02:00
|
|
|
uint32_t nexthop_hash(const struct nexthop *nexthop);
|
2019-08-12 17:27:09 +02:00
|
|
|
/*
|
|
|
|
* Hash a nexthop only on word-sized attributes:
|
|
|
|
* - vrf_id
|
|
|
|
* - ifindex
|
|
|
|
* - type
|
|
|
|
* - (some) flags
|
|
|
|
*/
|
|
|
|
uint32_t nexthop_hash_quick(const struct nexthop *nexthop);
|
2018-03-19 14:01:52 +01:00
|
|
|
|
2018-03-10 21:12:52 +01:00
|
|
|
extern bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2);
|
2019-05-22 21:34:07 +02:00
|
|
|
extern bool nexthop_same_no_labels(const struct nexthop *nh1,
|
|
|
|
const struct nexthop *nh2);
|
2018-06-02 01:26:53 +02:00
|
|
|
extern int nexthop_cmp(const struct nexthop *nh1, const struct nexthop *nh2);
|
2024-08-20 14:28:17 +02:00
|
|
|
extern int nexthop_cmp_no_weight(const struct nexthop *nh1,
|
|
|
|
const struct nexthop *nh2);
|
2019-08-19 21:56:45 +02:00
|
|
|
extern int nexthop_g_addr_cmp(enum nexthop_types_t type,
|
|
|
|
const union g_addr *addr1,
|
|
|
|
const union g_addr *addr2);
|
2018-03-10 21:12:52 +01:00
|
|
|
|
2021-03-29 22:09:40 +02:00
|
|
|
/* More-limited comparison function used to detect duplicate nexthops.
|
|
|
|
* Returns -1, 0, 1
|
|
|
|
*/
|
|
|
|
int nexthop_cmp_basic(const struct nexthop *nh1, const struct nexthop *nh2);
|
|
|
|
|
2015-05-20 02:40:34 +02:00
|
|
|
extern const char *nexthop_type_to_str(enum nexthop_types_t nh_type);
|
2019-05-14 19:26:22 +02:00
|
|
|
extern bool nexthop_labels_match(const struct nexthop *nh1,
|
|
|
|
const struct nexthop *nh2);
|
2015-05-20 02:40:34 +02:00
|
|
|
|
2019-04-02 18:33:06 +02:00
|
|
|
extern const char *nexthop2str(const struct nexthop *nexthop,
|
|
|
|
char *str, int size);
|
2019-10-23 20:37:20 +02:00
|
|
|
extern struct nexthop *nexthop_next(const struct nexthop *nexthop);
|
2022-12-28 15:49:53 +01:00
|
|
|
extern struct nexthop *nexthop_next_resolution(const struct nexthop *nexthop,
|
|
|
|
bool nexthop_resolution);
|
2019-10-23 20:37:20 +02:00
|
|
|
extern struct nexthop *
|
|
|
|
nexthop_next_active_resolved(const struct nexthop *nexthop);
|
2020-07-09 21:07:50 +02:00
|
|
|
extern unsigned int nexthop_level(const struct nexthop *nexthop);
|
2019-06-24 17:37:49 +02:00
|
|
|
/* Copies to an already allocated nexthop struct */
|
2019-05-15 00:40:27 +02:00
|
|
|
extern void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop,
|
|
|
|
struct nexthop *rparent);
|
2020-01-13 19:29:58 +01:00
|
|
|
/* Copies to an already allocated nexthop struct, not including recurse info */
|
|
|
|
extern void nexthop_copy_no_recurse(struct nexthop *copy,
|
|
|
|
const struct nexthop *nexthop,
|
|
|
|
struct nexthop *rparent);
|
2019-06-24 17:37:49 +02:00
|
|
|
/* Duplicates a nexthop and returns the newly allocated nexthop */
|
|
|
|
extern struct nexthop *nexthop_dup(const struct nexthop *nexthop,
|
|
|
|
struct nexthop *rparent);
|
2020-01-13 19:29:58 +01:00
|
|
|
/* Duplicates a nexthop and returns the newly allocated nexthop */
|
|
|
|
extern struct nexthop *nexthop_dup_no_recurse(const struct nexthop *nexthop,
|
|
|
|
struct nexthop *rparent);
|
2019-02-07 23:10:31 +01:00
|
|
|
|
2024-04-19 18:13:32 +02:00
|
|
|
/* Is this nexthop a blackhole? */
|
|
|
|
extern bool nexthop_is_blackhole(const struct nexthop *nh);
|
2023-04-19 20:35:25 +02:00
|
|
|
|
2020-07-01 21:55:16 +02:00
|
|
|
/*
|
|
|
|
* Parse one or more backup index values, as comma-separated numbers,
|
|
|
|
* into caller's array of uint8_ts. The array must be NEXTHOP_MAX_BACKUPS
|
|
|
|
* in size. Mails back the number of values converted, and returns 0 on
|
|
|
|
* success, <0 if an error in parsing.
|
|
|
|
*/
|
|
|
|
int nexthop_str2backups(const char *str, int *num_backups,
|
|
|
|
uint8_t *backups);
|
|
|
|
|
2024-01-03 21:33:58 +01:00
|
|
|
void nexthop_json_helper(json_object *json_nexthop,
|
|
|
|
const struct nexthop *nexthop, bool display_vrfid,
|
|
|
|
uint8_t rn_family);
|
|
|
|
void nexthop_vty_helper(struct vty *vty, const struct nexthop *nexthop,
|
|
|
|
bool display_vrfid, uint8_t rn_family);
|
|
|
|
|
2019-08-02 17:42:06 +02:00
|
|
|
#ifdef _FRR_ATTRIBUTE_PRINTFRR
|
|
|
|
#pragma FRR printfrr_ext "%pNH" (struct nexthop *)
|
|
|
|
#endif
|
|
|
|
|
2022-06-14 20:42:11 +02:00
|
|
|
ssize_t printfrr_nhs(struct fbuf *buf, const struct nexthop *nh);
|
2019-02-07 23:10:31 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-05-20 02:40:34 +02:00
|
|
|
#endif /*_LIB_NEXTHOP_H */
|