blob: c23d6f71640a43da71b4db6562557a09e7d05530 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
hasso508e53e2004-05-18 18:57:06 +00002 * Copyright (C) 2003 Yasuhiro Ohara
paul718e3742002-12-13 20:15:29 +00003 *
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 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
22#ifndef OSPF6_LSA_H
23#define OSPF6_LSA_H
24
hasso508e53e2004-05-18 18:57:06 +000025/* Debug option */
hasso1e058382004-09-01 21:36:14 +000026#define OSPF6_LSA_DEBUG 0x01
27#define OSPF6_LSA_DEBUG_ORIGINATE 0x02
28#define OSPF6_LSA_DEBUG_EXAMIN 0x04
29#define OSPF6_LSA_DEBUG_FLOOD 0x08
30
31#define IS_OSPF6_DEBUG_LSA(name) \
32 (ospf6_lstype_debug (htons (OSPF6_LSTYPE_ ## name)) & \
33 OSPF6_LSA_DEBUG)
34#define IS_OSPF6_DEBUG_ORIGINATE(name) \
35 (ospf6_lstype_debug (htons (OSPF6_LSTYPE_ ## name)) & \
36 OSPF6_LSA_DEBUG_ORIGINATE)
37#define IS_OSPF6_DEBUG_EXAMIN(name) \
38 (ospf6_lstype_debug (htons (OSPF6_LSTYPE_ ## name)) & \
39 OSPF6_LSA_DEBUG_EXAMIN)
40#define IS_OSPF6_DEBUG_LSA_TYPE(type) \
41 (ospf6_lstype_debug (type) & OSPF6_LSA_DEBUG)
42#define IS_OSPF6_DEBUG_ORIGINATE_TYPE(type) \
43 (ospf6_lstype_debug (type) & OSPF6_LSA_DEBUG_ORIGINATE)
44#define IS_OSPF6_DEBUG_EXAMIN_TYPE(type) \
45 (ospf6_lstype_debug (type) & OSPF6_LSA_DEBUG_EXAMIN)
46#define IS_OSPF6_DEBUG_FLOOD_TYPE(type) \
47 (ospf6_lstype_debug (type) & OSPF6_LSA_DEBUG_FLOOD)
paul718e3742002-12-13 20:15:29 +000048
49/* LSA definition */
50
hasso508e53e2004-05-18 18:57:06 +000051#define OSPF6_MAX_LSASIZE 4096
paul718e3742002-12-13 20:15:29 +000052
53/* Type */
hasso508e53e2004-05-18 18:57:06 +000054#define OSPF6_LSTYPE_UNKNOWN 0x0000
55#define OSPF6_LSTYPE_ROUTER 0x2001
56#define OSPF6_LSTYPE_NETWORK 0x2002
57#define OSPF6_LSTYPE_INTER_PREFIX 0x2003
58#define OSPF6_LSTYPE_INTER_ROUTER 0x2004
59#define OSPF6_LSTYPE_AS_EXTERNAL 0x4005
60#define OSPF6_LSTYPE_GROUP_MEMBERSHIP 0x2006
61#define OSPF6_LSTYPE_TYPE_7 0x2007
62#define OSPF6_LSTYPE_LINK 0x0008
63#define OSPF6_LSTYPE_INTRA_PREFIX 0x2009
64#define OSPF6_LSTYPE_SIZE 0x000a
paul718e3742002-12-13 20:15:29 +000065
66/* Masks for LS Type : RFC 2740 A.4.2.1 "LS type" */
67#define OSPF6_LSTYPE_UBIT_MASK 0x8000
68#define OSPF6_LSTYPE_SCOPE_MASK 0x6000
hasso508e53e2004-05-18 18:57:06 +000069#define OSPF6_LSTYPE_FCODE_MASK 0x1fff
paul718e3742002-12-13 20:15:29 +000070
hasso508e53e2004-05-18 18:57:06 +000071/* LSA scope */
hasso6452df02004-08-15 05:52:07 +000072#define OSPF6_SCOPE_LINKLOCAL 0x0000
73#define OSPF6_SCOPE_AREA 0x2000
74#define OSPF6_SCOPE_AS 0x4000
75#define OSPF6_SCOPE_RESERVED 0x6000
paul718e3742002-12-13 20:15:29 +000076
hasso6452df02004-08-15 05:52:07 +000077/* XXX U-bit handling should be treated here */
hasso508e53e2004-05-18 18:57:06 +000078#define OSPF6_LSA_SCOPE(type) \
79 (ntohs (type) & OSPF6_LSTYPE_SCOPE_MASK)
paul718e3742002-12-13 20:15:29 +000080
81/* LSA Header */
paul718e3742002-12-13 20:15:29 +000082struct ospf6_lsa_header
83{
paul718e3742002-12-13 20:15:29 +000084 u_int16_t age; /* LS age */
85 u_int16_t type; /* LS type */
86 u_int32_t id; /* Link State ID */
87 u_int32_t adv_router; /* Advertising Router */
88 u_int32_t seqnum; /* LS sequence number */
89 u_int16_t checksum; /* LS checksum */
90 u_int16_t length; /* LSA length */
91};
92
hasso508e53e2004-05-18 18:57:06 +000093#define OSPF6_LSA_HEADER_END(h) \
94 ((caddr_t)(h) + sizeof (struct ospf6_lsa_header))
95#define OSPF6_LSA_SIZE(h) \
96 (ntohs (((struct ospf6_lsa_header *) (h))->length))
97#define OSPF6_LSA_END(h) \
98 ((caddr_t)(h) + ntohs (((struct ospf6_lsa_header *) (h))->length))
99#define OSPF6_LSA_IS_TYPE(t, L) \
100 ((L)->header->type == htons (OSPF6_LSTYPE_ ## t) ? 1 : 0)
101#define OSPF6_LSA_IS_SAME(L1, L2) \
102 ((L1)->header->adv_router == (L2)->header->adv_router && \
103 (L1)->header->id == (L2)->header->id && \
104 (L1)->header->type == (L2)->header->type)
105#define OSPF6_LSA_IS_MATCH(t, i, a, L) \
106 ((L)->header->adv_router == (a) && (L)->header->id == (i) && \
107 (L)->header->type == (t))
108#define OSPF6_LSA_IS_DIFFER(L1, L2) ospf6_lsa_is_differ (L1, L2)
109#define OSPF6_LSA_IS_MAXAGE(L) (ospf6_lsa_age_current (L) == MAXAGE)
110#define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2)
paul718e3742002-12-13 20:15:29 +0000111
112struct ospf6_lsa
113{
hasso6452df02004-08-15 05:52:07 +0000114 char name[64]; /* dump string */
paul718e3742002-12-13 20:15:29 +0000115
hasso6452df02004-08-15 05:52:07 +0000116 struct ospf6_lsa *prev;
117 struct ospf6_lsa *next;
hasso508e53e2004-05-18 18:57:06 +0000118
hasso6452df02004-08-15 05:52:07 +0000119 unsigned char lock; /* reference counter */
120 unsigned char flag; /* special meaning (e.g. floodback) */
hasso508e53e2004-05-18 18:57:06 +0000121
hasso6452df02004-08-15 05:52:07 +0000122 struct timeval birth; /* tv_sec when LS age 0 */
hasso6452df02004-08-15 05:52:07 +0000123 struct timeval originated; /* used by MinLSInterval check */
hassoccb59b12004-08-25 09:10:37 +0000124 struct timeval received; /* used by MinLSArrival check */
125 struct timeval installed;
hasso508e53e2004-05-18 18:57:06 +0000126
hasso6452df02004-08-15 05:52:07 +0000127 struct thread *expire;
128 struct thread *refresh; /* For self-originated LSA */
hasso508e53e2004-05-18 18:57:06 +0000129
hasso6452df02004-08-15 05:52:07 +0000130 int retrans_count;
131
hasso6452df02004-08-15 05:52:07 +0000132 struct ospf6_lsdb *lsdb;
paul718e3742002-12-13 20:15:29 +0000133
134 /* lsa instance */
hasso508e53e2004-05-18 18:57:06 +0000135 struct ospf6_lsa_header *header;
paul718e3742002-12-13 20:15:29 +0000136};
137
hasso6452df02004-08-15 05:52:07 +0000138#define OSPF6_LSA_HEADERONLY 0x01
139#define OSPF6_LSA_FLOODBACK 0x02
140#define OSPF6_LSA_DUPLICATE 0x04
141#define OSPF6_LSA_IMPLIEDACK 0x08
hasso508e53e2004-05-18 18:57:06 +0000142
hasso6452df02004-08-15 05:52:07 +0000143struct ospf6_lsa_handler
paul718e3742002-12-13 20:15:29 +0000144{
hasso1e058382004-09-01 21:36:14 +0000145 u_int16_t type; /* host byte order */
paul0c083ee2004-10-10 12:54:58 +0000146 const char *name;
hasso508e53e2004-05-18 18:57:06 +0000147 int (*show) (struct vty *, struct ospf6_lsa *);
hasso1e058382004-09-01 21:36:14 +0000148 u_char debug;
paul718e3742002-12-13 20:15:29 +0000149};
150
hasso508e53e2004-05-18 18:57:06 +0000151/* Macro for LSA Origination */
hasso1e058382004-09-01 21:36:14 +0000152/* addr is (struct prefix *) */
153#define CONTINUE_IF_ADDRESS_LINKLOCAL(debug,addr) \
hasso508e53e2004-05-18 18:57:06 +0000154 if (IN6_IS_ADDR_LINKLOCAL (&(addr)->u.prefix6)) \
155 { \
156 char buf[64]; \
157 prefix2str (addr, buf, sizeof (buf)); \
hasso1e058382004-09-01 21:36:14 +0000158 if (debug) \
hasso508e53e2004-05-18 18:57:06 +0000159 zlog_info ("Filter out Linklocal: %s", buf); \
160 continue; \
paul718e3742002-12-13 20:15:29 +0000161 }
162
hasso1e058382004-09-01 21:36:14 +0000163#define CONTINUE_IF_ADDRESS_UNSPECIFIED(debug,addr) \
hasso508e53e2004-05-18 18:57:06 +0000164 if (IN6_IS_ADDR_UNSPECIFIED (&(addr)->u.prefix6)) \
165 { \
166 char buf[64]; \
167 prefix2str (addr, buf, sizeof (buf)); \
hasso1e058382004-09-01 21:36:14 +0000168 if (debug) \
hasso508e53e2004-05-18 18:57:06 +0000169 zlog_info ("Filter out Unspecified: %s", buf); \
170 continue; \
paul718e3742002-12-13 20:15:29 +0000171 }
172
hasso1e058382004-09-01 21:36:14 +0000173#define CONTINUE_IF_ADDRESS_LOOPBACK(debug,addr) \
hasso508e53e2004-05-18 18:57:06 +0000174 if (IN6_IS_ADDR_LOOPBACK (&(addr)->u.prefix6)) \
175 { \
176 char buf[64]; \
177 prefix2str (addr, buf, sizeof (buf)); \
hasso1e058382004-09-01 21:36:14 +0000178 if (debug) \
hasso508e53e2004-05-18 18:57:06 +0000179 zlog_info ("Filter out Loopback: %s", buf); \
180 continue; \
181 }
paul718e3742002-12-13 20:15:29 +0000182
hasso1e058382004-09-01 21:36:14 +0000183#define CONTINUE_IF_ADDRESS_V4COMPAT(debug,addr) \
hasso508e53e2004-05-18 18:57:06 +0000184 if (IN6_IS_ADDR_V4COMPAT (&(addr)->u.prefix6)) \
185 { \
186 char buf[64]; \
187 prefix2str (addr, buf, sizeof (buf)); \
hasso1e058382004-09-01 21:36:14 +0000188 if (debug) \
hasso508e53e2004-05-18 18:57:06 +0000189 zlog_info ("Filter out V4Compat: %s", buf); \
190 continue; \
191 }
192
hasso1e058382004-09-01 21:36:14 +0000193#define CONTINUE_IF_ADDRESS_V4MAPPED(debug,addr) \
hasso508e53e2004-05-18 18:57:06 +0000194 if (IN6_IS_ADDR_V4MAPPED (&(addr)->u.prefix6)) \
195 { \
196 char buf[64]; \
197 prefix2str (addr, buf, sizeof (buf)); \
hasso1e058382004-09-01 21:36:14 +0000198 if (debug) \
hasso508e53e2004-05-18 18:57:06 +0000199 zlog_info ("Filter out V4Mapped: %s", buf); \
200 continue; \
201 }
202
203
paul718e3742002-12-13 20:15:29 +0000204/* Function Prototypes */
paul0c083ee2004-10-10 12:54:58 +0000205const char *ospf6_lstype_name (u_int16_t type);
hasso1e058382004-09-01 21:36:14 +0000206u_char ospf6_lstype_debug (u_int16_t type);
hasso508e53e2004-05-18 18:57:06 +0000207int ospf6_lsa_is_differ (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
208int ospf6_lsa_is_changed (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
209u_int16_t ospf6_lsa_age_current (struct ospf6_lsa *);
210void ospf6_lsa_age_update_to_send (struct ospf6_lsa *, u_int32_t);
211void ospf6_lsa_premature_aging (struct ospf6_lsa *);
212int ospf6_lsa_compare (struct ospf6_lsa *, struct ospf6_lsa *);
paul718e3742002-12-13 20:15:29 +0000213
hasso508e53e2004-05-18 18:57:06 +0000214char *ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size);
215void ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header);
216void ospf6_lsa_header_print (struct ospf6_lsa *lsa);
hasso508e53e2004-05-18 18:57:06 +0000217void ospf6_lsa_show_summary_header (struct vty *vty);
218void ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa);
219void ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa);
220void ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa);
hasso6452df02004-08-15 05:52:07 +0000221void ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa);
paul718e3742002-12-13 20:15:29 +0000222
hasso508e53e2004-05-18 18:57:06 +0000223struct ospf6_lsa *ospf6_lsa_create (struct ospf6_lsa_header *header);
224struct ospf6_lsa *ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header);
225void ospf6_lsa_delete (struct ospf6_lsa *lsa);
226struct ospf6_lsa *ospf6_lsa_copy (struct ospf6_lsa *);
paul718e3742002-12-13 20:15:29 +0000227
228void ospf6_lsa_lock (struct ospf6_lsa *);
229void ospf6_lsa_unlock (struct ospf6_lsa *);
230
paul718e3742002-12-13 20:15:29 +0000231int ospf6_lsa_expire (struct thread *);
232int ospf6_lsa_refresh (struct thread *);
233
hasso508e53e2004-05-18 18:57:06 +0000234unsigned short ospf6_lsa_checksum (struct ospf6_lsa_header *);
235int ospf6_lsa_prohibited_duration (u_int16_t type, u_int32_t id,
236 u_int32_t adv_router, void *scope);
paul718e3742002-12-13 20:15:29 +0000237
hasso6452df02004-08-15 05:52:07 +0000238void ospf6_install_lsa_handler (struct ospf6_lsa_handler *handler);
hasso508e53e2004-05-18 18:57:06 +0000239void ospf6_lsa_init ();
hasso1e058382004-09-01 21:36:14 +0000240void ospf6_lsa_cmd_init ();
paul718e3742002-12-13 20:15:29 +0000241
hasso508e53e2004-05-18 18:57:06 +0000242int config_write_ospf6_debug_lsa (struct vty *vty);
243void install_element_ospf6_debug_lsa ();
paul718e3742002-12-13 20:15:29 +0000244
245#endif /* OSPF6_LSA_H */
246