]>
Commit | Line | Data |
---|---|---|
fb018d25 DS |
1 | /* |
2 | * Nexthop structure definition. | |
a399694f | 3 | * Copyright (C) 1997, 98, 99, 2001 Kunihiro Ishiguro |
fb018d25 DS |
4 | * Copyright (C) 2013 Cumulus Networks, Inc. |
5 | * | |
a399694f | 6 | * This file is part of Quagga. |
fb018d25 | 7 | * |
a399694f | 8 | * Quagga is free software; you can redistribute it and/or modify it |
fb018d25 DS |
9 | * under the terms of the GNU General Public License as published by the |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
a399694f | 13 | * Quagga is distributed in the hope that it will be useful, but |
fb018d25 DS |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
896014f4 DL |
18 | * You should have received a copy of the GNU General Public License along |
19 | * with this program; see the file COPYING; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
fb018d25 DS |
21 | */ |
22 | ||
23 | #ifndef _LIB_NEXTHOP_H | |
24 | #define _LIB_NEXTHOP_H | |
25 | ||
26 | #include "prefix.h" | |
54d48ea1 | 27 | #include "mpls.h" |
fb018d25 | 28 | |
80c2442a | 29 | /* Maximum next hop string length - gateway + ifindex */ |
30 | #define NEXTHOP_STRLEN (INET6_ADDRSTRLEN + 30) | |
31 | ||
fb018d25 | 32 | union g_addr { |
d62a17ae | 33 | struct in_addr ipv4; |
34 | struct in6_addr ipv6; | |
fb018d25 DS |
35 | }; |
36 | ||
d62a17ae | 37 | enum nexthop_types_t { |
38 | NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */ | |
39 | NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */ | |
40 | NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */ | |
41 | NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */ | |
42 | NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */ | |
43 | NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */ | |
fb018d25 | 44 | }; |
09a484dd DL |
45 | |
46 | enum blackhole_type { | |
47 | BLACKHOLE_UNSPEC = 0, | |
48 | BLACKHOLE_NULL, | |
49 | BLACKHOLE_REJECT, | |
50 | BLACKHOLE_ADMINPROHIB, | |
51 | }; | |
fb018d25 | 52 | |
25b9cb0c | 53 | /* IPV[46] -> IPV[46]_IFINDEX */ |
996c9314 LB |
54 | #define NEXTHOP_FIRSTHOPTYPE(type) \ |
55 | ((type) == NEXTHOP_TYPE_IFINDEX || (type) == NEXTHOP_TYPE_BLACKHOLE) \ | |
56 | ? (type) \ | |
57 | : ((type) | 1) | |
25b9cb0c | 58 | |
fb018d25 | 59 | /* Nexthop structure. */ |
d62a17ae | 60 | struct nexthop { |
61 | struct nexthop *next; | |
62 | struct nexthop *prev; | |
fb018d25 | 63 | |
4a7371e9 DS |
64 | /* |
65 | * What vrf is this nexthop associated with? | |
66 | */ | |
67 | vrf_id_t vrf_id; | |
68 | ||
d62a17ae | 69 | /* Interface index. */ |
70 | ifindex_t ifindex; | |
fb018d25 | 71 | |
d62a17ae | 72 | enum nexthop_types_t type; |
fb018d25 | 73 | |
d7c0a89a | 74 | uint8_t flags; |
fb018d25 DS |
75 | #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */ |
76 | #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */ | |
77 | #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */ | |
78 | #define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed onlink. */ | |
79 | #define NEXTHOP_FLAG_MATCHED (1 << 4) /* Already matched vs a nexthop */ | |
6e26278c | 80 | #define NEXTHOP_FLAG_FILTERED (1 << 5) /* rmap filtered, used by static only */ |
25b9cb0c | 81 | #define NEXTHOP_FLAG_DUPLICATE (1 << 6) /* nexthop duplicates another active one */ |
19a847a9 | 82 | #define NEXTHOP_FLAG_EVPN_RVTEP (1 << 7) /* EVPN remote vtep nexthop */ |
996c9314 LB |
83 | #define NEXTHOP_IS_ACTIVE(flags) \ |
84 | (CHECK_FLAG(flags, NEXTHOP_FLAG_ACTIVE) \ | |
85 | && !CHECK_FLAG(flags, NEXTHOP_FLAG_DUPLICATE)) | |
fb018d25 | 86 | |
d62a17ae | 87 | /* Nexthop address */ |
a8309422 DL |
88 | union { |
89 | union g_addr gate; | |
90 | enum blackhole_type bh_type; | |
91 | }; | |
d62a17ae | 92 | union g_addr src; |
93 | union g_addr rmap_src; /* Src is set via routemap */ | |
94 | ||
95 | /* Nexthops obtained by recursive resolution. | |
96 | * | |
97 | * If the nexthop struct needs to be resolved recursively, | |
98 | * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops | |
99 | * obtained by recursive resolution will be added to `resolved'. | |
100 | */ | |
101 | struct nexthop *resolved; | |
102 | /* Recursive parent */ | |
103 | struct nexthop *rparent; | |
104 | ||
105 | /* Type of label(s), if any */ | |
106 | enum lsp_types_t nh_label_type; | |
107 | ||
108 | /* Label(s) associated with this nexthop. */ | |
8ecdb26e | 109 | struct mpls_label_stack *nh_label; |
fb018d25 DS |
110 | }; |
111 | ||
d62a17ae | 112 | struct nexthop *nexthop_new(void); |
a399694f | 113 | |
d62a17ae | 114 | void nexthop_free(struct nexthop *nexthop); |
115 | void nexthops_free(struct nexthop *nexthop); | |
a399694f | 116 | |
d7c0a89a | 117 | void nexthop_add_labels(struct nexthop *, enum lsp_types_t, uint8_t, |
d62a17ae | 118 | mpls_label_t *); |
119 | void nexthop_del_labels(struct nexthop *); | |
40c7bdb0 | 120 | |
d36d0d57 QY |
121 | /* |
122 | * Hash a nexthop. Suitable for use with hash tables. | |
123 | * | |
124 | * This function uses the following values when computing the hash: | |
125 | * - vrf_id | |
126 | * - ifindex | |
127 | * - type | |
128 | * - gate | |
129 | * | |
130 | * nexthop | |
131 | * The nexthop to hash | |
132 | * | |
133 | * Returns: | |
134 | * 32-bit hash of nexthop | |
135 | */ | |
136 | uint32_t nexthop_hash(struct nexthop *nexthop); | |
137 | ||
31919191 DS |
138 | extern bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2); |
139 | ||
d62a17ae | 140 | extern const char *nexthop_type_to_str(enum nexthop_types_t nh_type); |
fd36be7e DL |
141 | extern int nexthop_same_no_recurse(const struct nexthop *next1, |
142 | const struct nexthop *next2); | |
d62a17ae | 143 | extern int nexthop_labels_match(struct nexthop *nh1, struct nexthop *nh2); |
996c9314 | 144 | extern int nexthop_same_firsthop(struct nexthop *next1, struct nexthop *next2); |
fb018d25 | 145 | |
d36d0d57 | 146 | extern const char *nexthop2str(const struct nexthop *nexthop, char *str, int size); |
9fb47c05 | 147 | extern struct nexthop *nexthop_next(struct nexthop *nexthop); |
e3054ee9 | 148 | extern unsigned int nexthop_level(struct nexthop *nexthop); |
fb018d25 | 149 | #endif /*_LIB_NEXTHOP_H */ |