]> git.proxmox.com Git - mirror_frr.git/blob - lib/nexthop.h
Merge branch 'cmaster' of ssh://stash.cumulusnetworks.com:7999/quag/quagga into cmaster
[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
19 * along with Quagga; see the file COPYING. If not, write to the Free
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"
28
29 union g_addr {
30 struct in_addr ipv4;
31 struct in6_addr ipv6;
32 };
33
34 enum nexthop_types_t
35 {
36 NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
37 NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
38 NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
39 NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
40 NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
41 NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
42 };
43
44 /* Nexthop structure. */
45 struct nexthop
46 {
47 struct nexthop *next;
48 struct nexthop *prev;
49
50 /* Interface index. */
51 unsigned int ifindex;
52
53 enum nexthop_types_t type;
54
55 u_char flags;
56 #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
57 #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
58 #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
59 #define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed onlink. */
60 #define NEXTHOP_FLAG_MATCHED (1 << 4) /* Already matched vs a nexthop */
61 #define NEXTHOP_FLAG_FILTERED (1 << 5) /* rmap filtered, used by static only */
62
63 /* Nexthop address */
64 union g_addr gate;
65 union g_addr src;
66 union g_addr rmap_src; /* Src is set via routemap */
67
68 /* Nexthops obtained by recursive resolution.
69 *
70 * If the nexthop struct needs to be resolved recursively,
71 * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops
72 * obtained by recursive resolution will be added to `resolved'.
73 * Only one level of recursive resolution is currently supported. */
74 struct nexthop *resolved;
75 };
76
77 extern int zebra_rnh_ip_default_route;
78 extern int zebra_rnh_ipv6_default_route;
79
80 static inline int
81 nh_resolve_via_default(int family)
82 {
83 if (((family == AF_INET) && zebra_rnh_ip_default_route) ||
84 ((family == AF_INET6) && zebra_rnh_ipv6_default_route))
85 return 1;
86 else
87 return 0;
88 }
89
90 struct nexthop *nexthop_new (void);
91 void nexthop_add (struct nexthop **target, struct nexthop *nexthop);
92
93 void copy_nexthops (struct nexthop **tnh, struct nexthop *nh);
94 void nexthop_free (struct nexthop *nexthop);
95 void nexthops_free (struct nexthop *nexthop);
96
97 extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type);
98 extern int nexthop_same_no_recurse (struct nexthop *next1, struct nexthop *next2);
99
100 #endif /*_LIB_NEXTHOP_H */