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