]>
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 | |
54d48ea1 | 53 | /* Nexthop label structure. */ |
d62a17ae | 54 | struct nexthop_label { |
55 | u_int8_t num_labels; | |
56 | u_int8_t reserved[3]; | |
57 | mpls_label_t label[0]; /* 1 or more labels. */ | |
54d48ea1 | 58 | }; |
59 | ||
fb018d25 | 60 | /* Nexthop structure. */ |
d62a17ae | 61 | struct nexthop { |
62 | struct nexthop *next; | |
63 | struct nexthop *prev; | |
fb018d25 | 64 | |
d62a17ae | 65 | /* Interface index. */ |
66 | ifindex_t ifindex; | |
fb018d25 | 67 | |
d62a17ae | 68 | enum nexthop_types_t type; |
fb018d25 | 69 | |
d62a17ae | 70 | u_char flags; |
fb018d25 DS |
71 | #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */ |
72 | #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */ | |
73 | #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */ | |
74 | #define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed onlink. */ | |
75 | #define NEXTHOP_FLAG_MATCHED (1 << 4) /* Already matched vs a nexthop */ | |
6e26278c | 76 | #define NEXTHOP_FLAG_FILTERED (1 << 5) /* rmap filtered, used by static only */ |
fb018d25 | 77 | |
d62a17ae | 78 | /* Nexthop address */ |
79 | union g_addr gate; | |
80 | union g_addr src; | |
81 | union g_addr rmap_src; /* Src is set via routemap */ | |
82 | ||
83 | /* Nexthops obtained by recursive resolution. | |
84 | * | |
85 | * If the nexthop struct needs to be resolved recursively, | |
86 | * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops | |
87 | * obtained by recursive resolution will be added to `resolved'. | |
88 | */ | |
89 | struct nexthop *resolved; | |
90 | /* Recursive parent */ | |
91 | struct nexthop *rparent; | |
92 | ||
93 | /* Type of label(s), if any */ | |
94 | enum lsp_types_t nh_label_type; | |
95 | ||
96 | /* Label(s) associated with this nexthop. */ | |
97 | struct nexthop_label *nh_label; | |
fb018d25 DS |
98 | }; |
99 | ||
9fb47c05 CF |
100 | /* The following for loop allows to iterate over the nexthop |
101 | * structure of routes. | |
102 | * | |
103 | * head: The pointer to the first nexthop in the chain. | |
104 | * | |
105 | * nexthop: The pointer to the current nexthop, either in the | |
106 | * top-level chain or in a resolved chain. | |
107 | */ | |
d62a17ae | 108 | #define ALL_NEXTHOPS(head, nexthop) \ |
109 | (nexthop) = (head); \ | |
110 | (nexthop); \ | |
111 | (nexthop) = nexthop_next(nexthop) | |
9fb47c05 | 112 | |
18ff3edd DS |
113 | extern int zebra_rnh_ip_default_route; |
114 | extern int zebra_rnh_ipv6_default_route; | |
115 | ||
d62a17ae | 116 | static inline int nh_resolve_via_default(int family) |
18ff3edd | 117 | { |
d62a17ae | 118 | if (((family == AF_INET) && zebra_rnh_ip_default_route) |
119 | || ((family == AF_INET6) && zebra_rnh_ipv6_default_route)) | |
120 | return 1; | |
121 | else | |
122 | return 0; | |
18ff3edd DS |
123 | } |
124 | ||
d62a17ae | 125 | struct nexthop *nexthop_new(void); |
126 | void nexthop_add(struct nexthop **target, struct nexthop *nexthop); | |
a399694f | 127 | |
d62a17ae | 128 | void copy_nexthops(struct nexthop **tnh, struct nexthop *nh, |
129 | struct nexthop *rparent); | |
130 | void nexthop_free(struct nexthop *nexthop); | |
131 | void nexthops_free(struct nexthop *nexthop); | |
a399694f | 132 | |
d62a17ae | 133 | void nexthop_add_labels(struct nexthop *, enum lsp_types_t, u_int8_t, |
134 | mpls_label_t *); | |
135 | void nexthop_del_labels(struct nexthop *); | |
40c7bdb0 | 136 | |
d62a17ae | 137 | extern const char *nexthop_type_to_str(enum nexthop_types_t nh_type); |
fd36be7e DL |
138 | extern int nexthop_same_no_recurse(const struct nexthop *next1, |
139 | const struct nexthop *next2); | |
d62a17ae | 140 | extern int nexthop_labels_match(struct nexthop *nh1, struct nexthop *nh2); |
fb018d25 | 141 | |
d62a17ae | 142 | extern const char *nexthop2str(struct nexthop *nexthop, char *str, int size); |
9fb47c05 | 143 | extern struct nexthop *nexthop_next(struct nexthop *nexthop); |
e3054ee9 | 144 | extern unsigned int nexthop_level(struct nexthop *nexthop); |
fb018d25 | 145 | #endif /*_LIB_NEXTHOP_H */ |