]> git.proxmox.com Git - mirror_frr.git/blob - lib/nexthop.h
Merge pull request #1056 from opensourcerouting/oldbits-0
[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 /* Maximum next hop string length - gateway + ifindex */
30 #define NEXTHOP_STRLEN (INET6_ADDRSTRLEN + 30)
31
32 union g_addr {
33 struct in_addr ipv4;
34 struct in6_addr ipv6;
35 };
36
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. */
44 };
45
46 enum blackhole_type {
47 BLACKHOLE_UNSPEC = 0,
48 BLACKHOLE_NULL,
49 BLACKHOLE_REJECT,
50 BLACKHOLE_ADMINPROHIB,
51 };
52
53 /* Nexthop label structure. */
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. */
58 };
59
60 /* Nexthop structure. */
61 struct nexthop {
62 struct nexthop *next;
63 struct nexthop *prev;
64
65 /* Interface index. */
66 ifindex_t ifindex;
67
68 enum nexthop_types_t type;
69
70 u_char flags;
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 */
76 #define NEXTHOP_FLAG_FILTERED (1 << 5) /* rmap filtered, used by static only */
77
78 /* Nexthop address */
79 union {
80 union g_addr gate;
81 enum blackhole_type bh_type;
82 };
83 union g_addr src;
84 union g_addr rmap_src; /* Src is set via routemap */
85
86 /* Nexthops obtained by recursive resolution.
87 *
88 * If the nexthop struct needs to be resolved recursively,
89 * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops
90 * obtained by recursive resolution will be added to `resolved'.
91 */
92 struct nexthop *resolved;
93 /* Recursive parent */
94 struct nexthop *rparent;
95
96 /* Type of label(s), if any */
97 enum lsp_types_t nh_label_type;
98
99 /* Label(s) associated with this nexthop. */
100 struct nexthop_label *nh_label;
101 };
102
103 /* The following for loop allows to iterate over the nexthop
104 * structure of routes.
105 *
106 * head: The pointer to the first nexthop in the chain.
107 *
108 * nexthop: The pointer to the current nexthop, either in the
109 * top-level chain or in a resolved chain.
110 */
111 #define ALL_NEXTHOPS(head, nexthop) \
112 (nexthop) = (head); \
113 (nexthop); \
114 (nexthop) = nexthop_next(nexthop)
115
116 extern int zebra_rnh_ip_default_route;
117 extern int zebra_rnh_ipv6_default_route;
118
119 static inline int nh_resolve_via_default(int family)
120 {
121 if (((family == AF_INET) && zebra_rnh_ip_default_route)
122 || ((family == AF_INET6) && zebra_rnh_ipv6_default_route))
123 return 1;
124 else
125 return 0;
126 }
127
128 struct nexthop *nexthop_new(void);
129 void nexthop_add(struct nexthop **target, struct nexthop *nexthop);
130
131 void copy_nexthops(struct nexthop **tnh, struct nexthop *nh,
132 struct nexthop *rparent);
133 void nexthop_free(struct nexthop *nexthop);
134 void nexthops_free(struct nexthop *nexthop);
135
136 void nexthop_add_labels(struct nexthop *, enum lsp_types_t, u_int8_t,
137 mpls_label_t *);
138 void nexthop_del_labels(struct nexthop *);
139
140 extern const char *nexthop_type_to_str(enum nexthop_types_t nh_type);
141 extern int nexthop_same_no_recurse(const struct nexthop *next1,
142 const struct nexthop *next2);
143 extern int nexthop_labels_match(struct nexthop *nh1, struct nexthop *nh2);
144
145 extern const char *nexthop2str(struct nexthop *nexthop, char *str, int size);
146 extern struct nexthop *nexthop_next(struct nexthop *nexthop);
147 extern unsigned int nexthop_level(struct nexthop *nexthop);
148 #endif /*_LIB_NEXTHOP_H */