2 * Nexthop structure definition.
3 * Copyright (C) 1997, 98, 99, 2001 Kunihiro Ishiguro
4 * Copyright (C) 2013 Cumulus Networks, Inc.
6 * This file is part of Quagga.
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
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.
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
23 #ifndef _LIB_NEXTHOP_H
24 #define _LIB_NEXTHOP_H
29 /* Maximum next hop string length - gateway + ifindex */
30 #define NEXTHOP_STRLEN (INET6_ADDRSTRLEN + 30)
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. */
46 /* Nexthop label structure. */
47 struct nexthop_label
{
50 mpls_label_t label
[0]; /* 1 or more labels. */
53 /* Nexthop structure. */
58 /* Interface index. */
61 enum nexthop_types_t type
;
64 #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
65 #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
66 #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
67 #define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed onlink. */
68 #define NEXTHOP_FLAG_MATCHED (1 << 4) /* Already matched vs a nexthop */
69 #define NEXTHOP_FLAG_FILTERED (1 << 5) /* rmap filtered, used by static only */
74 union g_addr rmap_src
; /* Src is set via routemap */
76 /* Nexthops obtained by recursive resolution.
78 * If the nexthop struct needs to be resolved recursively,
79 * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops
80 * obtained by recursive resolution will be added to `resolved'.
82 struct nexthop
*resolved
;
83 /* Recursive parent */
84 struct nexthop
*rparent
;
86 /* Type of label(s), if any */
87 enum lsp_types_t nh_label_type
;
89 /* Label(s) associated with this nexthop. */
90 struct nexthop_label
*nh_label
;
93 /* The following for loop allows to iterate over the nexthop
94 * structure of routes.
96 * head: The pointer to the first nexthop in the chain.
98 * nexthop: The pointer to the current nexthop, either in the
99 * top-level chain or in a resolved chain.
101 #define ALL_NEXTHOPS(head, nexthop) \
102 (nexthop) = (head); \
104 (nexthop) = nexthop_next(nexthop)
106 extern int zebra_rnh_ip_default_route
;
107 extern int zebra_rnh_ipv6_default_route
;
109 static inline int nh_resolve_via_default(int family
)
111 if (((family
== AF_INET
) && zebra_rnh_ip_default_route
)
112 || ((family
== AF_INET6
) && zebra_rnh_ipv6_default_route
))
118 struct nexthop
*nexthop_new(void);
119 void nexthop_add(struct nexthop
**target
, struct nexthop
*nexthop
);
121 void copy_nexthops(struct nexthop
**tnh
, struct nexthop
*nh
,
122 struct nexthop
*rparent
);
123 void nexthop_free(struct nexthop
*nexthop
);
124 void nexthops_free(struct nexthop
*nexthop
);
126 void nexthop_add_labels(struct nexthop
*, enum lsp_types_t
, u_int8_t
,
128 void nexthop_del_labels(struct nexthop
*);
130 extern const char *nexthop_type_to_str(enum nexthop_types_t nh_type
);
131 extern int nexthop_same_no_recurse(struct nexthop
*next1
,
132 struct nexthop
*next2
);
133 extern int nexthop_labels_match(struct nexthop
*nh1
, struct nexthop
*nh2
);
135 extern const char *nexthop2str(struct nexthop
*nexthop
, char *str
, int size
);
136 extern struct nexthop
*nexthop_next(struct nexthop
*nexthop
);
137 extern unsigned int nexthop_level(struct nexthop
*nexthop
);
138 #endif /*_LIB_NEXTHOP_H */