]> git.proxmox.com Git - mirror_frr.git/blame - lib/nexthop.h
babeld: Remove comment (fixed by 64682f5e69).
[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 *
18 * You should have received a copy of the GNU General Public License
a399694f 19 * along with Quagga; see the file COPYING. If not, write to the Free
fb018d25
DS
20 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 * 02111-1307, USA.
22 */
23
24#ifndef _LIB_NEXTHOP_H
25#define _LIB_NEXTHOP_H
26
27#include "prefix.h"
54d48ea1 28#include "mpls.h"
fb018d25 29
80c2442a 30/* Maximum next hop string length - gateway + ifindex */
31#define NEXTHOP_STRLEN (INET6_ADDRSTRLEN + 30)
32
fb018d25
DS
33union g_addr {
34 struct in_addr ipv4;
fb018d25 35 struct in6_addr ipv6;
fb018d25
DS
36};
37
38enum nexthop_types_t
39{
40 NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
fb018d25
DS
41 NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
42 NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
fb018d25
DS
43 NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
44 NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
fb018d25
DS
45 NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
46};
47
54d48ea1 48/* Nexthop label structure. */
49struct nexthop_label
50{
51 u_int8_t num_labels;
52 u_int8_t reserved[3];
53 mpls_label_t label[0]; /* 1 or more labels. */
54};
55
fb018d25
DS
56/* Nexthop structure. */
57struct nexthop
58{
59 struct nexthop *next;
60 struct nexthop *prev;
61
62 /* Interface index. */
b892f1dd 63 ifindex_t ifindex;
fb018d25
DS
64
65 enum nexthop_types_t type;
66
67 u_char flags;
68#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
69#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
70#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
71#define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed onlink. */
72#define NEXTHOP_FLAG_MATCHED (1 << 4) /* Already matched vs a nexthop */
6e26278c 73#define NEXTHOP_FLAG_FILTERED (1 << 5) /* rmap filtered, used by static only */
fb018d25
DS
74
75 /* Nexthop address */
76 union g_addr gate;
77 union g_addr src;
c52ef59f 78 union g_addr rmap_src; /* Src is set via routemap */
fb018d25
DS
79
80 /* Nexthops obtained by recursive resolution.
81 *
82 * If the nexthop struct needs to be resolved recursively,
83 * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops
84 * obtained by recursive resolution will be added to `resolved'.
85 * Only one level of recursive resolution is currently supported. */
86 struct nexthop *resolved;
40c7bdb0 87
ce549947
RW
88 /* Type of label(s), if any */
89 enum lsp_types_t nh_label_type;
90
40c7bdb0 91 /* Label(s) associated with this nexthop. */
92 struct nexthop_label *nh_label;
fb018d25
DS
93};
94
18ff3edd
DS
95extern int zebra_rnh_ip_default_route;
96extern int zebra_rnh_ipv6_default_route;
97
98static inline int
99nh_resolve_via_default(int family)
100{
101 if (((family == AF_INET) && zebra_rnh_ip_default_route) ||
102 ((family == AF_INET6) && zebra_rnh_ipv6_default_route))
103 return 1;
104 else
105 return 0;
106}
107
a399694f
DS
108struct nexthop *nexthop_new (void);
109void nexthop_add (struct nexthop **target, struct nexthop *nexthop);
110
111void copy_nexthops (struct nexthop **tnh, struct nexthop *nh);
112void nexthop_free (struct nexthop *nexthop);
113void nexthops_free (struct nexthop *nexthop);
114
ce549947 115void nexthop_add_labels (struct nexthop *, enum lsp_types_t, u_int8_t, mpls_label_t *);
40c7bdb0 116void nexthop_del_labels (struct nexthop *);
117
fb018d25
DS
118extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type);
119extern int nexthop_same_no_recurse (struct nexthop *next1, struct nexthop *next2);
a64448ba 120extern int nexthop_labels_match (struct nexthop *nh1, struct nexthop *nh2);
fb018d25 121
80c2442a 122extern const char * nexthop2str (struct nexthop *nexthop, char *str, int size);
fb018d25 123#endif /*_LIB_NEXTHOP_H */