]>
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 | |
5e244469 RW |
29 | #ifdef __cplusplus |
30 | extern "C" { | |
31 | #endif | |
32 | ||
80c2442a | 33 | /* Maximum next hop string length - gateway + ifindex */ |
34 | #define NEXTHOP_STRLEN (INET6_ADDRSTRLEN + 30) | |
35 | ||
fb018d25 | 36 | union g_addr { |
d62a17ae | 37 | struct in_addr ipv4; |
38 | struct in6_addr ipv6; | |
fb018d25 DS |
39 | }; |
40 | ||
d62a17ae | 41 | enum nexthop_types_t { |
42 | NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */ | |
43 | NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */ | |
44 | NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */ | |
45 | NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */ | |
46 | NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */ | |
47 | NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */ | |
fb018d25 | 48 | }; |
09a484dd DL |
49 | |
50 | enum blackhole_type { | |
51 | BLACKHOLE_UNSPEC = 0, | |
52 | BLACKHOLE_NULL, | |
53 | BLACKHOLE_REJECT, | |
54 | BLACKHOLE_ADMINPROHIB, | |
55 | }; | |
fb018d25 | 56 | |
25b9cb0c | 57 | /* IPV[46] -> IPV[46]_IFINDEX */ |
996c9314 LB |
58 | #define NEXTHOP_FIRSTHOPTYPE(type) \ |
59 | ((type) == NEXTHOP_TYPE_IFINDEX || (type) == NEXTHOP_TYPE_BLACKHOLE) \ | |
60 | ? (type) \ | |
61 | : ((type) | 1) | |
25b9cb0c | 62 | |
fb018d25 | 63 | /* Nexthop structure. */ |
d62a17ae | 64 | struct nexthop { |
65 | struct nexthop *next; | |
66 | struct nexthop *prev; | |
fb018d25 | 67 | |
4a7371e9 DS |
68 | /* |
69 | * What vrf is this nexthop associated with? | |
70 | */ | |
71 | vrf_id_t vrf_id; | |
72 | ||
d62a17ae | 73 | /* Interface index. */ |
74 | ifindex_t ifindex; | |
fb018d25 | 75 | |
d62a17ae | 76 | enum nexthop_types_t type; |
fb018d25 | 77 | |
d7c0a89a | 78 | uint8_t flags; |
fb018d25 DS |
79 | #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */ |
80 | #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */ | |
81 | #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */ | |
82 | #define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed onlink. */ | |
83 | #define NEXTHOP_FLAG_MATCHED (1 << 4) /* Already matched vs a nexthop */ | |
dd50eeb1 | 84 | #define NEXTHOP_FLAG_DUPLICATE (1 << 5) /* nexthop duplicates another active one */ |
e47c4d3c | 85 | #define NEXTHOP_FLAG_RNH_FILTERED (1 << 6) /* rmap filtered, used by rnh */ |
996c9314 LB |
86 | #define NEXTHOP_IS_ACTIVE(flags) \ |
87 | (CHECK_FLAG(flags, NEXTHOP_FLAG_ACTIVE) \ | |
88 | && !CHECK_FLAG(flags, NEXTHOP_FLAG_DUPLICATE)) | |
fb018d25 | 89 | |
d62a17ae | 90 | /* Nexthop address */ |
a8309422 DL |
91 | union { |
92 | union g_addr gate; | |
93 | enum blackhole_type bh_type; | |
94 | }; | |
d62a17ae | 95 | union g_addr src; |
96 | union g_addr rmap_src; /* Src is set via routemap */ | |
97 | ||
98 | /* Nexthops obtained by recursive resolution. | |
99 | * | |
100 | * If the nexthop struct needs to be resolved recursively, | |
101 | * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops | |
102 | * obtained by recursive resolution will be added to `resolved'. | |
103 | */ | |
104 | struct nexthop *resolved; | |
105 | /* Recursive parent */ | |
106 | struct nexthop *rparent; | |
107 | ||
108 | /* Type of label(s), if any */ | |
109 | enum lsp_types_t nh_label_type; | |
110 | ||
111 | /* Label(s) associated with this nexthop. */ | |
8ecdb26e | 112 | struct mpls_label_stack *nh_label; |
fb018d25 DS |
113 | }; |
114 | ||
d62a17ae | 115 | struct nexthop *nexthop_new(void); |
a399694f | 116 | |
d62a17ae | 117 | void nexthop_free(struct nexthop *nexthop); |
118 | void nexthops_free(struct nexthop *nexthop); | |
a399694f | 119 | |
d7c0a89a | 120 | void nexthop_add_labels(struct nexthop *, enum lsp_types_t, uint8_t, |
d62a17ae | 121 | mpls_label_t *); |
122 | void nexthop_del_labels(struct nexthop *); | |
40c7bdb0 | 123 | |
d36d0d57 QY |
124 | /* |
125 | * Hash a nexthop. Suitable for use with hash tables. | |
126 | * | |
127 | * This function uses the following values when computing the hash: | |
128 | * - vrf_id | |
129 | * - ifindex | |
130 | * - type | |
131 | * - gate | |
132 | * | |
133 | * nexthop | |
134 | * The nexthop to hash | |
135 | * | |
136 | * Returns: | |
137 | * 32-bit hash of nexthop | |
138 | */ | |
1b1fe1c4 | 139 | uint32_t nexthop_hash(const struct nexthop *nexthop); |
d36d0d57 | 140 | |
31919191 | 141 | extern bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2); |
a5a2d802 SW |
142 | extern bool nexthop_same_no_labels(const struct nexthop *nh1, |
143 | const struct nexthop *nh2); | |
776c3e90 | 144 | extern int nexthop_cmp(const struct nexthop *nh1, const struct nexthop *nh2); |
31919191 | 145 | |
d62a17ae | 146 | extern const char *nexthop_type_to_str(enum nexthop_types_t nh_type); |
89dc3160 SW |
147 | extern bool nexthop_labels_match(const struct nexthop *nh1, |
148 | const struct nexthop *nh2); | |
996c9314 | 149 | extern int nexthop_same_firsthop(struct nexthop *next1, struct nexthop *next2); |
fb018d25 | 150 | |
55f93d4b MS |
151 | extern const char *nexthop2str(const struct nexthop *nexthop, |
152 | char *str, int size); | |
9fb47c05 | 153 | extern struct nexthop *nexthop_next(struct nexthop *nexthop); |
e3054ee9 | 154 | extern unsigned int nexthop_level(struct nexthop *nexthop); |
5e244469 RW |
155 | |
156 | #ifdef __cplusplus | |
157 | } | |
158 | #endif | |
159 | ||
fb018d25 | 160 | #endif /*_LIB_NEXTHOP_H */ |