]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
508e53e2 | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
718e3744 | 3 | * |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * GNU Zebra is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
896014f4 DL |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 19 | */ |
20 | ||
21 | #ifndef OSPF6_LSA_H | |
22 | #define OSPF6_LSA_H | |
beadc736 | 23 | #include "ospf6_top.h" |
e4bacbaa | 24 | #include "lib/json.h" |
718e3744 | 25 | |
508e53e2 | 26 | /* Debug option */ |
1e05838a | 27 | #define OSPF6_LSA_DEBUG 0x01 |
28 | #define OSPF6_LSA_DEBUG_ORIGINATE 0x02 | |
29 | #define OSPF6_LSA_DEBUG_EXAMIN 0x04 | |
30 | #define OSPF6_LSA_DEBUG_FLOOD 0x08 | |
31 | ||
c4122b55 YR |
32 | /* OSPF LSA Default metric values */ |
33 | #define DEFAULT_DEFAULT_METRIC 20 | |
34 | #define DEFAULT_DEFAULT_ORIGINATE_METRIC 10 | |
35 | #define DEFAULT_DEFAULT_ALWAYS_METRIC 1 | |
36 | #define DEFAULT_METRIC_TYPE 2 | |
37 | ||
d62a17ae | 38 | #define IS_OSPF6_DEBUG_LSA(name) \ |
39 | (ospf6_lstype_debug(htons(OSPF6_LSTYPE_##name)) & OSPF6_LSA_DEBUG) | |
40 | #define IS_OSPF6_DEBUG_ORIGINATE(name) \ | |
41 | (ospf6_lstype_debug(htons(OSPF6_LSTYPE_##name)) \ | |
42 | & OSPF6_LSA_DEBUG_ORIGINATE) | |
43 | #define IS_OSPF6_DEBUG_EXAMIN(name) \ | |
44 | (ospf6_lstype_debug(htons(OSPF6_LSTYPE_##name)) \ | |
45 | & OSPF6_LSA_DEBUG_EXAMIN) | |
46 | #define IS_OSPF6_DEBUG_LSA_TYPE(type) \ | |
47 | (ospf6_lstype_debug(type) & OSPF6_LSA_DEBUG) | |
48 | #define IS_OSPF6_DEBUG_ORIGINATE_TYPE(type) \ | |
49 | (ospf6_lstype_debug(type) & OSPF6_LSA_DEBUG_ORIGINATE) | |
50 | #define IS_OSPF6_DEBUG_EXAMIN_TYPE(type) \ | |
51 | (ospf6_lstype_debug(type) & OSPF6_LSA_DEBUG_EXAMIN) | |
52 | #define IS_OSPF6_DEBUG_FLOOD_TYPE(type) \ | |
53 | (ospf6_lstype_debug(type) & OSPF6_LSA_DEBUG_FLOOD) | |
718e3744 | 54 | |
55 | /* LSA definition */ | |
56 | ||
508e53e2 | 57 | #define OSPF6_MAX_LSASIZE 4096 |
718e3744 | 58 | |
59 | /* Type */ | |
508e53e2 | 60 | #define OSPF6_LSTYPE_UNKNOWN 0x0000 |
61 | #define OSPF6_LSTYPE_ROUTER 0x2001 | |
62 | #define OSPF6_LSTYPE_NETWORK 0x2002 | |
63 | #define OSPF6_LSTYPE_INTER_PREFIX 0x2003 | |
64 | #define OSPF6_LSTYPE_INTER_ROUTER 0x2004 | |
65 | #define OSPF6_LSTYPE_AS_EXTERNAL 0x4005 | |
66 | #define OSPF6_LSTYPE_GROUP_MEMBERSHIP 0x2006 | |
67 | #define OSPF6_LSTYPE_TYPE_7 0x2007 | |
68 | #define OSPF6_LSTYPE_LINK 0x0008 | |
69 | #define OSPF6_LSTYPE_INTRA_PREFIX 0x2009 | |
70 | #define OSPF6_LSTYPE_SIZE 0x000a | |
718e3744 | 71 | |
72 | /* Masks for LS Type : RFC 2740 A.4.2.1 "LS type" */ | |
73 | #define OSPF6_LSTYPE_UBIT_MASK 0x8000 | |
74 | #define OSPF6_LSTYPE_SCOPE_MASK 0x6000 | |
508e53e2 | 75 | #define OSPF6_LSTYPE_FCODE_MASK 0x1fff |
718e3744 | 76 | |
508e53e2 | 77 | /* LSA scope */ |
6452df09 | 78 | #define OSPF6_SCOPE_LINKLOCAL 0x0000 |
79 | #define OSPF6_SCOPE_AREA 0x2000 | |
80 | #define OSPF6_SCOPE_AS 0x4000 | |
81 | #define OSPF6_SCOPE_RESERVED 0x6000 | |
718e3744 | 82 | |
ad500b22 K |
83 | /* AS-external-LSA refresh method. */ |
84 | #define LSA_REFRESH_IF_CHANGED 0 | |
85 | #define LSA_REFRESH_FORCE 1 | |
86 | ||
87 | ||
6452df09 | 88 | /* XXX U-bit handling should be treated here */ |
d62a17ae | 89 | #define OSPF6_LSA_SCOPE(type) (ntohs(type) & OSPF6_LSTYPE_SCOPE_MASK) |
718e3744 | 90 | |
91 | /* LSA Header */ | |
abc7ef44 | 92 | #define OSPF6_LSA_HEADER_SIZE 20U |
d62a17ae | 93 | struct ospf6_lsa_header { |
d7c0a89a QY |
94 | uint16_t age; /* LS age */ |
95 | uint16_t type; /* LS type */ | |
858f9c08 DL |
96 | in_addr_t id; /* Link State ID */ |
97 | in_addr_t adv_router; /* Advertising Router */ | |
d7c0a89a QY |
98 | uint32_t seqnum; /* LS sequence number */ |
99 | uint16_t checksum; /* LS checksum */ | |
100 | uint16_t length; /* LSA length */ | |
718e3744 | 101 | }; |
102 | ||
d62a17ae | 103 | #define OSPF6_LSA_HEADER_END(h) ((caddr_t)(h) + sizeof(struct ospf6_lsa_header)) |
104 | #define OSPF6_LSA_SIZE(h) (ntohs(((struct ospf6_lsa_header *)(h))->length)) | |
105 | #define OSPF6_LSA_END(h) \ | |
106 | ((caddr_t)(h) + ntohs(((struct ospf6_lsa_header *)(h))->length)) | |
107 | #define OSPF6_LSA_IS_TYPE(t, L) \ | |
108 | ((L)->header->type == htons(OSPF6_LSTYPE_##t) ? 1 : 0) | |
109 | #define OSPF6_LSA_IS_SAME(L1, L2) \ | |
110 | ((L1)->header->adv_router == (L2)->header->adv_router \ | |
111 | && (L1)->header->id == (L2)->header->id \ | |
112 | && (L1)->header->type == (L2)->header->type) | |
113 | #define OSPF6_LSA_IS_MATCH(t, i, a, L) \ | |
114 | ((L)->header->adv_router == (a) && (L)->header->id == (i) \ | |
115 | && (L)->header->type == (t)) | |
508e53e2 | 116 | #define OSPF6_LSA_IS_DIFFER(L1, L2) ospf6_lsa_is_differ (L1, L2) |
8551e6da | 117 | #define OSPF6_LSA_IS_MAXAGE(L) (ospf6_lsa_age_current (L) == OSPF_LSA_MAXAGE) |
508e53e2 | 118 | #define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2) |
3b220289 DD |
119 | #define OSPF6_LSA_IS_SEQWRAP(L) ((L)->header->seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER + 1)) |
120 | ||
ad500b22 | 121 | |
d62a17ae | 122 | struct ospf6_lsa { |
123 | char name[64]; /* dump string */ | |
718e3744 | 124 | |
d62a17ae | 125 | struct route_node *rn; |
718e3744 | 126 | |
d62a17ae | 127 | unsigned char lock; /* reference counter */ |
128 | unsigned char flag; /* special meaning (e.g. floodback) */ | |
718e3744 | 129 | |
d62a17ae | 130 | struct timeval birth; /* tv_sec when LS age 0 */ |
131 | struct timeval originated; /* used by MinLSInterval check */ | |
132 | struct timeval received; /* used by MinLSArrival check */ | |
133 | struct timeval installed; | |
718e3744 | 134 | |
d62a17ae | 135 | struct thread *expire; |
136 | struct thread *refresh; /* For self-originated LSA */ | |
718e3744 | 137 | |
d62a17ae | 138 | int retrans_count; |
718e3744 | 139 | |
d62a17ae | 140 | struct ospf6_lsdb *lsdb; |
6452df09 | 141 | |
ad500b22 K |
142 | in_addr_t external_lsa_id; |
143 | ||
d62a17ae | 144 | /* lsa instance */ |
145 | struct ospf6_lsa_header *header; | |
718e3744 | 146 | }; |
147 | ||
6452df09 | 148 | #define OSPF6_LSA_HEADERONLY 0x01 |
149 | #define OSPF6_LSA_FLOODBACK 0x02 | |
150 | #define OSPF6_LSA_DUPLICATE 0x04 | |
151 | #define OSPF6_LSA_IMPLIEDACK 0x08 | |
ca1f4309 | 152 | #define OSPF6_LSA_UNAPPROVED 0x10 |
3b220289 | 153 | #define OSPF6_LSA_SEQWRAPPED 0x20 |
ad500b22 | 154 | #define OSPF6_LSA_FLUSH 0x40 |
508e53e2 | 155 | |
d62a17ae | 156 | struct ospf6_lsa_handler { |
01db90cd DL |
157 | uint16_t lh_type; /* host byte order */ |
158 | const char *lh_name; | |
159 | const char *lh_short_name; | |
e4bacbaa YR |
160 | int (*lh_show)(struct vty *, struct ospf6_lsa *, json_object *json_obj, |
161 | bool use_json); | |
162 | char *(*lh_get_prefix_str)(struct ospf6_lsa *, char *buf, int buflen, | |
163 | int pos); | |
01db90cd DL |
164 | |
165 | uint8_t lh_debug; | |
508e53e2 | 166 | }; |
167 | ||
3981b5c7 | 168 | #define OSPF6_LSA_IS_KNOWN(t) \ |
0ab50080 | 169 | (ospf6_get_lsa_handler(t)->lh_type != OSPF6_LSTYPE_UNKNOWN ? 1 : 0) |
2680aa2b | 170 | |
4dfd8aff DW |
171 | extern vector ospf6_lsa_handler_vector; |
172 | ||
508e53e2 | 173 | /* Macro for LSA Origination */ |
1e05838a | 174 | /* addr is (struct prefix *) */ |
d62a17ae | 175 | #define CONTINUE_IF_ADDRESS_LINKLOCAL(debug, addr) \ |
176 | if (IN6_IS_ADDR_LINKLOCAL(&(addr)->u.prefix6)) { \ | |
d62a17ae | 177 | if (debug) \ |
2dbe669b | 178 | zlog_debug("Filter out Linklocal: %pFX", addr); \ |
d62a17ae | 179 | continue; \ |
180 | } | |
181 | ||
182 | #define CONTINUE_IF_ADDRESS_UNSPECIFIED(debug, addr) \ | |
183 | if (IN6_IS_ADDR_UNSPECIFIED(&(addr)->u.prefix6)) { \ | |
d62a17ae | 184 | if (debug) \ |
2dbe669b | 185 | zlog_debug("Filter out Unspecified: %pFX", addr); \ |
d62a17ae | 186 | continue; \ |
187 | } | |
188 | ||
189 | #define CONTINUE_IF_ADDRESS_LOOPBACK(debug, addr) \ | |
190 | if (IN6_IS_ADDR_LOOPBACK(&(addr)->u.prefix6)) { \ | |
d62a17ae | 191 | if (debug) \ |
2dbe669b | 192 | zlog_debug("Filter out Loopback: %pFX", addr); \ |
d62a17ae | 193 | continue; \ |
194 | } | |
195 | ||
196 | #define CONTINUE_IF_ADDRESS_V4COMPAT(debug, addr) \ | |
197 | if (IN6_IS_ADDR_V4COMPAT(&(addr)->u.prefix6)) { \ | |
d62a17ae | 198 | if (debug) \ |
2dbe669b | 199 | zlog_debug("Filter out V4Compat: %pFX", addr); \ |
d62a17ae | 200 | continue; \ |
201 | } | |
202 | ||
203 | #define CONTINUE_IF_ADDRESS_V4MAPPED(debug, addr) \ | |
204 | if (IN6_IS_ADDR_V4MAPPED(&(addr)->u.prefix6)) { \ | |
d62a17ae | 205 | if (debug) \ |
2dbe669b | 206 | zlog_debug("Filter out V4Mapped: %pFX", addr); \ |
d62a17ae | 207 | continue; \ |
208 | } | |
718e3744 | 209 | |
6b0655a2 | 210 | |
718e3744 | 211 | /* Function Prototypes */ |
d7c0a89a QY |
212 | extern const char *ospf6_lstype_name(uint16_t type); |
213 | extern const char *ospf6_lstype_short_name(uint16_t type); | |
214 | extern uint8_t ospf6_lstype_debug(uint16_t type); | |
c4122b55 YR |
215 | extern int metric_type(struct ospf6 *ospf6, int type, uint8_t instance); |
216 | extern int metric_value(struct ospf6 *ospf6, int type, uint8_t instance); | |
d62a17ae | 217 | extern int ospf6_lsa_is_differ(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2); |
218 | extern int ospf6_lsa_is_changed(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2); | |
d7c0a89a QY |
219 | extern uint16_t ospf6_lsa_age_current(struct ospf6_lsa *); |
220 | extern void ospf6_lsa_age_update_to_send(struct ospf6_lsa *, uint32_t); | |
d62a17ae | 221 | extern void ospf6_lsa_premature_aging(struct ospf6_lsa *); |
222 | extern int ospf6_lsa_compare(struct ospf6_lsa *, struct ospf6_lsa *); | |
223 | ||
224 | extern char *ospf6_lsa_printbuf(struct ospf6_lsa *lsa, char *buf, int size); | |
225 | extern void ospf6_lsa_header_print_raw(struct ospf6_lsa_header *header); | |
226 | extern void ospf6_lsa_header_print(struct ospf6_lsa *lsa); | |
227 | extern void ospf6_lsa_show_summary_header(struct vty *vty); | |
e4bacbaa YR |
228 | extern void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa, |
229 | json_object *json, bool use_json); | |
230 | extern void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa, | |
231 | json_object *json, bool use_json); | |
232 | extern void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa, | |
233 | json_object *json, bool use_json); | |
234 | extern void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, | |
235 | json_object *json, bool use_json); | |
d62a17ae | 236 | |
771e1fbe | 237 | extern struct ospf6_lsa *ospf6_lsa_alloc(size_t lsa_length); |
d62a17ae | 238 | extern struct ospf6_lsa *ospf6_lsa_create(struct ospf6_lsa_header *header); |
239 | extern struct ospf6_lsa * | |
240 | ospf6_lsa_create_headeronly(struct ospf6_lsa_header *header); | |
241 | extern void ospf6_lsa_delete(struct ospf6_lsa *lsa); | |
242 | extern struct ospf6_lsa *ospf6_lsa_copy(struct ospf6_lsa *); | |
243 | ||
62270cc3 DS |
244 | extern struct ospf6_lsa *ospf6_lsa_lock(struct ospf6_lsa *lsa); |
245 | extern struct ospf6_lsa *ospf6_lsa_unlock(struct ospf6_lsa *lsa); | |
d62a17ae | 246 | |
247 | extern int ospf6_lsa_expire(struct thread *); | |
248 | extern int ospf6_lsa_refresh(struct thread *); | |
249 | ||
250 | extern unsigned short ospf6_lsa_checksum(struct ospf6_lsa_header *); | |
251 | extern int ospf6_lsa_checksum_valid(struct ospf6_lsa_header *); | |
d7c0a89a QY |
252 | extern int ospf6_lsa_prohibited_duration(uint16_t type, uint32_t id, |
253 | uint32_t adv_router, void *scope); | |
d62a17ae | 254 | |
4062abfa DS |
255 | extern void ospf6_install_lsa_handler(struct ospf6_lsa_handler *handler); |
256 | extern struct ospf6_lsa_handler *ospf6_get_lsa_handler(uint16_t type); | |
d62a17ae | 257 | |
258 | extern void ospf6_lsa_init(void); | |
259 | extern void ospf6_lsa_terminate(void); | |
260 | ||
261 | extern int config_write_ospf6_debug_lsa(struct vty *vty); | |
262 | extern void install_element_ospf6_debug_lsa(void); | |
da086a3b | 263 | extern void ospf6_lsa_age_set(struct ospf6_lsa *lsa); |
beadc736 | 264 | extern void ospf6_flush_self_originated_lsas_now(struct ospf6 *ospf6); |
265 | extern struct ospf6 *ospf6_get_by_lsdb(struct ospf6_lsa *lsa); | |
718e3744 | 266 | #endif /* OSPF6_LSA_H */ |