]> git.proxmox.com Git - mirror_frr.git/blob - lib/nexthop.h
lib: Fix missing __be16 typedef on CentOS6
[mirror_frr.git] / lib / nexthop.h
1 /*
2 * Nexthop structure definition.
3 * Copyright (C) 1997, 98, 99, 2001 Kunihiro Ishiguro
4 * Copyright (C) 2013 Cumulus Networks, Inc.
5 *
6 * This file is part of Quagga.
7 *
8 * Quagga is free software; you can redistribute it and/or modify it
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 *
13 * Quagga is distributed in the hope that it will be useful, but
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 *
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
21 */
22
23 #ifndef _LIB_NEXTHOP_H
24 #define _LIB_NEXTHOP_H
25
26 #include "prefix.h"
27 #include "mpls.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /* Maximum next hop string length - gateway + ifindex */
34 #define NEXTHOP_STRLEN (INET6_ADDRSTRLEN + 30)
35
36 union g_addr {
37 struct in_addr ipv4;
38 struct in6_addr ipv6;
39 };
40
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. */
48 };
49
50 enum blackhole_type {
51 BLACKHOLE_UNSPEC = 0,
52 BLACKHOLE_NULL,
53 BLACKHOLE_REJECT,
54 BLACKHOLE_ADMINPROHIB,
55 };
56
57 /* IPV[46] -> IPV[46]_IFINDEX */
58 #define NEXTHOP_FIRSTHOPTYPE(type) \
59 ((type) == NEXTHOP_TYPE_IFINDEX || (type) == NEXTHOP_TYPE_BLACKHOLE) \
60 ? (type) \
61 : ((type) | 1)
62
63 /* Nexthop structure. */
64 struct nexthop {
65 struct nexthop *next;
66 struct nexthop *prev;
67
68 /*
69 * What vrf is this nexthop associated with?
70 */
71 vrf_id_t vrf_id;
72
73 /* Interface index. */
74 ifindex_t ifindex;
75
76 enum nexthop_types_t type;
77
78 uint8_t flags;
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 */
84 #define NEXTHOP_FLAG_DUPLICATE (1 << 5) /* nexthop duplicates another active one */
85 #define NEXTHOP_FLAG_RNH_FILTERED (1 << 6) /* rmap filtered, used by rnh */
86 #define NEXTHOP_IS_ACTIVE(flags) \
87 (CHECK_FLAG(flags, NEXTHOP_FLAG_ACTIVE) \
88 && !CHECK_FLAG(flags, NEXTHOP_FLAG_DUPLICATE))
89
90 /* Nexthop address */
91 union {
92 union g_addr gate;
93 enum blackhole_type bh_type;
94 };
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. */
112 struct mpls_label_stack *nh_label;
113
114 /* Weight of the nexthop ( for unequal cost ECMP ) */
115 uint8_t weight;
116 };
117
118 struct nexthop *nexthop_new(void);
119
120 void nexthop_free(struct nexthop *nexthop);
121 void nexthops_free(struct nexthop *nexthop);
122
123 void nexthop_add_labels(struct nexthop *, enum lsp_types_t, uint8_t,
124 mpls_label_t *);
125 void nexthop_del_labels(struct nexthop *);
126
127 /*
128 * Allocate a new nexthop object and initialize it from various args.
129 */
130 struct nexthop *nexthop_from_ifindex(ifindex_t ifindex, vrf_id_t vrf_id);
131 struct nexthop *nexthop_from_ipv4(const struct in_addr *ipv4,
132 const struct in_addr *src,
133 vrf_id_t vrf_id);
134 struct nexthop *nexthop_from_ipv4_ifindex(const struct in_addr *ipv4,
135 const struct in_addr *src,
136 ifindex_t ifindex, vrf_id_t vrf_id);
137 struct nexthop *nexthop_from_ipv6(const struct in6_addr *ipv6,
138 vrf_id_t vrf_id);
139 struct nexthop *nexthop_from_ipv6_ifindex(const struct in6_addr *ipv6,
140 ifindex_t ifindex, vrf_id_t vrf_id);
141 struct nexthop *nexthop_from_blackhole(enum blackhole_type bh_type);
142
143 /*
144 * Hash a nexthop. Suitable for use with hash tables.
145 *
146 * This function uses the following values when computing the hash:
147 * - vrf_id
148 * - ifindex
149 * - type
150 * - gate
151 *
152 * nexthop
153 * The nexthop to hash
154 *
155 * Returns:
156 * 32-bit hash of nexthop
157 */
158 uint32_t nexthop_hash(const struct nexthop *nexthop);
159 /*
160 * Hash a nexthop only on word-sized attributes:
161 * - vrf_id
162 * - ifindex
163 * - type
164 * - (some) flags
165 */
166 uint32_t nexthop_hash_quick(const struct nexthop *nexthop);
167
168 extern bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2);
169 extern bool nexthop_same_no_labels(const struct nexthop *nh1,
170 const struct nexthop *nh2);
171 extern int nexthop_cmp(const struct nexthop *nh1, const struct nexthop *nh2);
172 extern int nexthop_g_addr_cmp(enum nexthop_types_t type,
173 const union g_addr *addr1,
174 const union g_addr *addr2);
175
176 extern const char *nexthop_type_to_str(enum nexthop_types_t nh_type);
177 extern bool nexthop_labels_match(const struct nexthop *nh1,
178 const struct nexthop *nh2);
179 extern int nexthop_same_firsthop(struct nexthop *next1, struct nexthop *next2);
180
181 extern const char *nexthop2str(const struct nexthop *nexthop,
182 char *str, int size);
183 extern struct nexthop *nexthop_next(const struct nexthop *nexthop);
184 extern struct nexthop *
185 nexthop_next_active_resolved(const struct nexthop *nexthop);
186 extern unsigned int nexthop_level(struct nexthop *nexthop);
187 /* Copies to an already allocated nexthop struct */
188 extern void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop,
189 struct nexthop *rparent);
190 /* Copies to an already allocated nexthop struct, not including recurse info */
191 extern void nexthop_copy_no_recurse(struct nexthop *copy,
192 const struct nexthop *nexthop,
193 struct nexthop *rparent);
194 /* Duplicates a nexthop and returns the newly allocated nexthop */
195 extern struct nexthop *nexthop_dup(const struct nexthop *nexthop,
196 struct nexthop *rparent);
197 /* Duplicates a nexthop and returns the newly allocated nexthop */
198 extern struct nexthop *nexthop_dup_no_recurse(const struct nexthop *nexthop,
199 struct nexthop *rparent);
200
201 #ifdef __cplusplus
202 }
203 #endif
204
205 #endif /*_LIB_NEXTHOP_H */