2 * Copyright (C) 2003 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
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
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.
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
23 #include "ospf6_top.h"
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
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
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)
57 #define OSPF6_MAX_LSASIZE 4096
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
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
75 #define OSPF6_LSTYPE_FCODE_MASK 0x1fff
78 #define OSPF6_SCOPE_LINKLOCAL 0x0000
79 #define OSPF6_SCOPE_AREA 0x2000
80 #define OSPF6_SCOPE_AS 0x4000
81 #define OSPF6_SCOPE_RESERVED 0x6000
83 /* XXX U-bit handling should be treated here */
84 #define OSPF6_LSA_SCOPE(type) (ntohs(type) & OSPF6_LSTYPE_SCOPE_MASK)
87 #define OSPF6_LSA_HEADER_SIZE 20U
88 struct ospf6_lsa_header
{
89 uint16_t age
; /* LS age */
90 uint16_t type
; /* LS type */
91 in_addr_t id
; /* Link State ID */
92 in_addr_t adv_router
; /* Advertising Router */
93 uint32_t seqnum
; /* LS sequence number */
94 uint16_t checksum
; /* LS checksum */
95 uint16_t length
; /* LSA length */
98 #define OSPF6_LSA_HEADER_END(h) ((caddr_t)(h) + sizeof(struct ospf6_lsa_header))
99 #define OSPF6_LSA_SIZE(h) (ntohs(((struct ospf6_lsa_header *)(h))->length))
100 #define OSPF6_LSA_END(h) \
101 ((caddr_t)(h) + ntohs(((struct ospf6_lsa_header *)(h))->length))
102 #define OSPF6_LSA_IS_TYPE(t, L) \
103 ((L)->header->type == htons(OSPF6_LSTYPE_##t) ? 1 : 0)
104 #define OSPF6_LSA_IS_SAME(L1, L2) \
105 ((L1)->header->adv_router == (L2)->header->adv_router \
106 && (L1)->header->id == (L2)->header->id \
107 && (L1)->header->type == (L2)->header->type)
108 #define OSPF6_LSA_IS_MATCH(t, i, a, L) \
109 ((L)->header->adv_router == (a) && (L)->header->id == (i) \
110 && (L)->header->type == (t))
111 #define OSPF6_LSA_IS_DIFFER(L1, L2) ospf6_lsa_is_differ (L1, L2)
112 #define OSPF6_LSA_IS_MAXAGE(L) (ospf6_lsa_age_current (L) == OSPF_LSA_MAXAGE)
113 #define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2)
114 #define OSPF6_LSA_IS_SEQWRAP(L) ((L)->header->seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER + 1))
117 char name
[64]; /* dump string */
119 struct route_node
*rn
;
121 unsigned char lock
; /* reference counter */
122 unsigned char flag
; /* special meaning (e.g. floodback) */
124 struct timeval birth
; /* tv_sec when LS age 0 */
125 struct timeval originated
; /* used by MinLSInterval check */
126 struct timeval received
; /* used by MinLSArrival check */
127 struct timeval installed
;
129 struct thread
*expire
;
130 struct thread
*refresh
; /* For self-originated LSA */
134 struct ospf6_lsdb
*lsdb
;
137 struct ospf6_lsa_header
*header
;
140 #define OSPF6_LSA_HEADERONLY 0x01
141 #define OSPF6_LSA_FLOODBACK 0x02
142 #define OSPF6_LSA_DUPLICATE 0x04
143 #define OSPF6_LSA_IMPLIEDACK 0x08
144 #define OSPF6_LSA_UNAPPROVED 0x10
145 #define OSPF6_LSA_SEQWRAPPED 0x20
147 struct ospf6_lsa_handler
{
148 uint16_t lh_type
; /* host byte order */
150 const char *lh_short_name
;
151 int (*lh_show
)(struct vty
*, struct ospf6_lsa
*, json_object
*json_obj
,
153 char *(*lh_get_prefix_str
)(struct ospf6_lsa
*, char *buf
, int buflen
,
159 #define OSPF6_LSA_IS_KNOWN(t) \
160 (ospf6_get_lsa_handler(t)->lh_type != OSPF6_LSTYPE_UNKNOWN ? 1 : 0)
162 extern vector ospf6_lsa_handler_vector
;
164 /* Macro for LSA Origination */
165 /* addr is (struct prefix *) */
166 #define CONTINUE_IF_ADDRESS_LINKLOCAL(debug, addr) \
167 if (IN6_IS_ADDR_LINKLOCAL(&(addr)->u.prefix6)) { \
169 zlog_debug("Filter out Linklocal: %pFX", addr); \
173 #define CONTINUE_IF_ADDRESS_UNSPECIFIED(debug, addr) \
174 if (IN6_IS_ADDR_UNSPECIFIED(&(addr)->u.prefix6)) { \
176 zlog_debug("Filter out Unspecified: %pFX", addr); \
180 #define CONTINUE_IF_ADDRESS_LOOPBACK(debug, addr) \
181 if (IN6_IS_ADDR_LOOPBACK(&(addr)->u.prefix6)) { \
183 zlog_debug("Filter out Loopback: %pFX", addr); \
187 #define CONTINUE_IF_ADDRESS_V4COMPAT(debug, addr) \
188 if (IN6_IS_ADDR_V4COMPAT(&(addr)->u.prefix6)) { \
190 zlog_debug("Filter out V4Compat: %pFX", addr); \
194 #define CONTINUE_IF_ADDRESS_V4MAPPED(debug, addr) \
195 if (IN6_IS_ADDR_V4MAPPED(&(addr)->u.prefix6)) { \
197 zlog_debug("Filter out V4Mapped: %pFX", addr); \
202 /* Function Prototypes */
203 extern const char *ospf6_lstype_name(uint16_t type
);
204 extern const char *ospf6_lstype_short_name(uint16_t type
);
205 extern uint8_t ospf6_lstype_debug(uint16_t type
);
206 extern int metric_type(struct ospf6
*ospf6
, int type
, uint8_t instance
);
207 extern int metric_value(struct ospf6
*ospf6
, int type
, uint8_t instance
);
208 extern int ospf6_lsa_is_differ(struct ospf6_lsa
*lsa1
, struct ospf6_lsa
*lsa2
);
209 extern int ospf6_lsa_is_changed(struct ospf6_lsa
*lsa1
, struct ospf6_lsa
*lsa2
);
210 extern uint16_t ospf6_lsa_age_current(struct ospf6_lsa
*);
211 extern void ospf6_lsa_age_update_to_send(struct ospf6_lsa
*, uint32_t);
212 extern void ospf6_lsa_premature_aging(struct ospf6_lsa
*);
213 extern int ospf6_lsa_compare(struct ospf6_lsa
*, struct ospf6_lsa
*);
215 extern char *ospf6_lsa_printbuf(struct ospf6_lsa
*lsa
, char *buf
, int size
);
216 extern void ospf6_lsa_header_print_raw(struct ospf6_lsa_header
*header
);
217 extern void ospf6_lsa_header_print(struct ospf6_lsa
*lsa
);
218 extern void ospf6_lsa_show_summary_header(struct vty
*vty
);
219 extern void ospf6_lsa_show_summary(struct vty
*vty
, struct ospf6_lsa
*lsa
,
220 json_object
*json
, bool use_json
);
221 extern void ospf6_lsa_show_dump(struct vty
*vty
, struct ospf6_lsa
*lsa
,
222 json_object
*json
, bool use_json
);
223 extern void ospf6_lsa_show_internal(struct vty
*vty
, struct ospf6_lsa
*lsa
,
224 json_object
*json
, bool use_json
);
225 extern void ospf6_lsa_show(struct vty
*vty
, struct ospf6_lsa
*lsa
,
226 json_object
*json
, bool use_json
);
228 extern struct ospf6_lsa
*ospf6_lsa_alloc(size_t lsa_length
);
229 extern struct ospf6_lsa
*ospf6_lsa_create(struct ospf6_lsa_header
*header
);
230 extern struct ospf6_lsa
*
231 ospf6_lsa_create_headeronly(struct ospf6_lsa_header
*header
);
232 extern void ospf6_lsa_delete(struct ospf6_lsa
*lsa
);
233 extern struct ospf6_lsa
*ospf6_lsa_copy(struct ospf6_lsa
*);
235 extern struct ospf6_lsa
*ospf6_lsa_lock(struct ospf6_lsa
*lsa
);
236 extern struct ospf6_lsa
*ospf6_lsa_unlock(struct ospf6_lsa
*lsa
);
238 extern int ospf6_lsa_expire(struct thread
*);
239 extern int ospf6_lsa_refresh(struct thread
*);
241 extern unsigned short ospf6_lsa_checksum(struct ospf6_lsa_header
*);
242 extern int ospf6_lsa_checksum_valid(struct ospf6_lsa_header
*);
243 extern int ospf6_lsa_prohibited_duration(uint16_t type
, uint32_t id
,
244 uint32_t adv_router
, void *scope
);
246 extern void ospf6_install_lsa_handler(struct ospf6_lsa_handler
*handler
);
247 extern struct ospf6_lsa_handler
*ospf6_get_lsa_handler(uint16_t type
);
249 extern void ospf6_lsa_init(void);
250 extern void ospf6_lsa_terminate(void);
252 extern int config_write_ospf6_debug_lsa(struct vty
*vty
);
253 extern void install_element_ospf6_debug_lsa(void);
254 extern void ospf6_lsa_age_set(struct ospf6_lsa
*lsa
);
255 extern void ospf6_flush_self_originated_lsas_now(struct ospf6
*ospf6
);
256 extern struct ospf6
*ospf6_get_by_lsdb(struct ospf6_lsa
*lsa
);
257 #endif /* OSPF6_LSA_H */