]> git.proxmox.com Git - mirror_frr.git/blame - lib/nexthop.h
zebra: clean up a debug and an api in netlink code
[mirror_frr.git] / lib / nexthop.h
CommitLineData
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
30extern "C" {
31#endif
32
80c2442a 33/* Maximum next hop string length - gateway + ifindex */
34#define NEXTHOP_STRLEN (INET6_ADDRSTRLEN + 30)
35
fb018d25 36union g_addr {
d62a17ae 37 struct in_addr ipv4;
38 struct in6_addr ipv6;
fb018d25
DS
39};
40
d62a17ae 41enum 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
50enum 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 64struct 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. */
0641a955
MS
82#define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed
83 * onlink.
84 */
85#define NEXTHOP_FLAG_DUPLICATE (1 << 4) /* nexthop duplicates another
86 * active one
87 */
88#define NEXTHOP_FLAG_RNH_FILTERED (1 << 5) /* rmap filtered, used by rnh */
996c9314
LB
89#define NEXTHOP_IS_ACTIVE(flags) \
90 (CHECK_FLAG(flags, NEXTHOP_FLAG_ACTIVE) \
91 && !CHECK_FLAG(flags, NEXTHOP_FLAG_DUPLICATE))
fb018d25 92
d62a17ae 93 /* Nexthop address */
a8309422
DL
94 union {
95 union g_addr gate;
96 enum blackhole_type bh_type;
97 };
d62a17ae 98 union g_addr src;
99 union g_addr rmap_src; /* Src is set via routemap */
100
101 /* Nexthops obtained by recursive resolution.
102 *
103 * If the nexthop struct needs to be resolved recursively,
104 * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops
105 * obtained by recursive resolution will be added to `resolved'.
106 */
107 struct nexthop *resolved;
108 /* Recursive parent */
109 struct nexthop *rparent;
110
111 /* Type of label(s), if any */
112 enum lsp_types_t nh_label_type;
113
114 /* Label(s) associated with this nexthop. */
8ecdb26e 115 struct mpls_label_stack *nh_label;
df7fb580
DS
116
117 /* Weight of the nexthop ( for unequal cost ECMP ) */
118 uint8_t weight;
fb018d25
DS
119};
120
e4a1ec74
MS
121
122/* Utility to append one nexthop to another. */
123#define NEXTHOP_APPEND(to, new) \
124 do { \
125 (to)->next = (new); \
126 (new)->prev = (to); \
127 (new)->next = NULL; \
128 } while (0)
129
d62a17ae 130struct nexthop *nexthop_new(void);
a399694f 131
d62a17ae 132void nexthop_free(struct nexthop *nexthop);
133void nexthops_free(struct nexthop *nexthop);
a399694f 134
e4a1ec74
MS
135void nexthop_add_labels(struct nexthop *nexthop, enum lsp_types_t ltype,
136 uint8_t num_labels, const mpls_label_t *labels);
d62a17ae 137void nexthop_del_labels(struct nexthop *);
40c7bdb0 138
f3323df2
MS
139/*
140 * Allocate a new nexthop object and initialize it from various args.
141 */
142struct nexthop *nexthop_from_ifindex(ifindex_t ifindex, vrf_id_t vrf_id);
143struct nexthop *nexthop_from_ipv4(const struct in_addr *ipv4,
144 const struct in_addr *src,
145 vrf_id_t vrf_id);
146struct nexthop *nexthop_from_ipv4_ifindex(const struct in_addr *ipv4,
147 const struct in_addr *src,
148 ifindex_t ifindex, vrf_id_t vrf_id);
149struct nexthop *nexthop_from_ipv6(const struct in6_addr *ipv6,
150 vrf_id_t vrf_id);
151struct nexthop *nexthop_from_ipv6_ifindex(const struct in6_addr *ipv6,
152 ifindex_t ifindex, vrf_id_t vrf_id);
153struct nexthop *nexthop_from_blackhole(enum blackhole_type bh_type);
154
d36d0d57
QY
155/*
156 * Hash a nexthop. Suitable for use with hash tables.
157 *
158 * This function uses the following values when computing the hash:
159 * - vrf_id
160 * - ifindex
161 * - type
162 * - gate
163 *
164 * nexthop
165 * The nexthop to hash
166 *
167 * Returns:
168 * 32-bit hash of nexthop
169 */
1b1fe1c4 170uint32_t nexthop_hash(const struct nexthop *nexthop);
73a38187
SW
171/*
172 * Hash a nexthop only on word-sized attributes:
173 * - vrf_id
174 * - ifindex
175 * - type
176 * - (some) flags
177 */
178uint32_t nexthop_hash_quick(const struct nexthop *nexthop);
d36d0d57 179
31919191 180extern bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2);
a5a2d802
SW
181extern bool nexthop_same_no_labels(const struct nexthop *nh1,
182 const struct nexthop *nh2);
776c3e90 183extern int nexthop_cmp(const struct nexthop *nh1, const struct nexthop *nh2);
3c6e0bd4
SW
184extern int nexthop_g_addr_cmp(enum nexthop_types_t type,
185 const union g_addr *addr1,
186 const union g_addr *addr2);
31919191 187
d62a17ae 188extern const char *nexthop_type_to_str(enum nexthop_types_t nh_type);
89dc3160
SW
189extern bool nexthop_labels_match(const struct nexthop *nh1,
190 const struct nexthop *nh2);
996c9314 191extern int nexthop_same_firsthop(struct nexthop *next1, struct nexthop *next2);
fb018d25 192
55f93d4b
MS
193extern const char *nexthop2str(const struct nexthop *nexthop,
194 char *str, int size);
17c25e03
SW
195extern struct nexthop *nexthop_next(const struct nexthop *nexthop);
196extern struct nexthop *
197nexthop_next_active_resolved(const struct nexthop *nexthop);
e3054ee9 198extern unsigned int nexthop_level(struct nexthop *nexthop);
504d0a40 199/* Copies to an already allocated nexthop struct */
e7addf02
SW
200extern void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop,
201 struct nexthop *rparent);
77bf9504
SW
202/* Copies to an already allocated nexthop struct, not including recurse info */
203extern void nexthop_copy_no_recurse(struct nexthop *copy,
204 const struct nexthop *nexthop,
205 struct nexthop *rparent);
504d0a40
SW
206/* Duplicates a nexthop and returns the newly allocated nexthop */
207extern struct nexthop *nexthop_dup(const struct nexthop *nexthop,
208 struct nexthop *rparent);
77bf9504
SW
209/* Duplicates a nexthop and returns the newly allocated nexthop */
210extern struct nexthop *nexthop_dup_no_recurse(const struct nexthop *nexthop,
211 struct nexthop *rparent);
5e244469
RW
212
213#ifdef __cplusplus
214}
215#endif
216
fb018d25 217#endif /*_LIB_NEXTHOP_H */