blob: be284498a3f6a629925fbdda71dbe64e3892c811 [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 */
26extern unsigned char conf_debug_ospf6_lsa;
27#define OSPF6_DEBUG_LSA_SEND 0x01
28#define OSPF6_DEBUG_LSA_RECV 0x02
29#define OSPF6_DEBUG_LSA_ORIGINATE 0x04
30#define OSPF6_DEBUG_LSA_TIMER 0x08
31#define OSPF6_DEBUG_LSA_DATABASE 0x10
32#define OSPF6_DEBUG_LSA_MEMORY 0x80
33#define OSPF6_DEBUG_LSA_ALL 0x9f
34#define OSPF6_DEBUG_LSA_DEFAULT 0x0f
35#define OSPF6_DEBUG_LSA_ON(level) \
36 (conf_debug_ospf6_lsa |= (level))
37#define OSPF6_DEBUG_LSA_OFF(level) \
38 (conf_debug_ospf6_lsa &= ~(level))
39#define IS_OSPF6_DEBUG_LSA(e) \
40 (conf_debug_ospf6_lsa & OSPF6_DEBUG_LSA_ ## e)
paul718e3742002-12-13 20:15:29 +000041
42/* LSA definition */
43
hasso508e53e2004-05-18 18:57:06 +000044#define OSPF6_MAX_LSASIZE 4096
paul718e3742002-12-13 20:15:29 +000045
46/* Type */
hasso508e53e2004-05-18 18:57:06 +000047#define OSPF6_LSTYPE_UNKNOWN 0x0000
48#define OSPF6_LSTYPE_ROUTER 0x2001
49#define OSPF6_LSTYPE_NETWORK 0x2002
50#define OSPF6_LSTYPE_INTER_PREFIX 0x2003
51#define OSPF6_LSTYPE_INTER_ROUTER 0x2004
52#define OSPF6_LSTYPE_AS_EXTERNAL 0x4005
53#define OSPF6_LSTYPE_GROUP_MEMBERSHIP 0x2006
54#define OSPF6_LSTYPE_TYPE_7 0x2007
55#define OSPF6_LSTYPE_LINK 0x0008
56#define OSPF6_LSTYPE_INTRA_PREFIX 0x2009
57#define OSPF6_LSTYPE_SIZE 0x000a
paul718e3742002-12-13 20:15:29 +000058
59/* Masks for LS Type : RFC 2740 A.4.2.1 "LS type" */
60#define OSPF6_LSTYPE_UBIT_MASK 0x8000
61#define OSPF6_LSTYPE_SCOPE_MASK 0x6000
hasso508e53e2004-05-18 18:57:06 +000062#define OSPF6_LSTYPE_FCODE_MASK 0x1fff
paul718e3742002-12-13 20:15:29 +000063
hasso508e53e2004-05-18 18:57:06 +000064/* LSA scope */
hasso6452df02004-08-15 05:52:07 +000065#define OSPF6_SCOPE_LINKLOCAL 0x0000
66#define OSPF6_SCOPE_AREA 0x2000
67#define OSPF6_SCOPE_AS 0x4000
68#define OSPF6_SCOPE_RESERVED 0x6000
paul718e3742002-12-13 20:15:29 +000069
hasso6452df02004-08-15 05:52:07 +000070/* XXX U-bit handling should be treated here */
hasso508e53e2004-05-18 18:57:06 +000071#define OSPF6_LSA_SCOPE(type) \
72 (ntohs (type) & OSPF6_LSTYPE_SCOPE_MASK)
paul718e3742002-12-13 20:15:29 +000073
74/* LSA Header */
paul718e3742002-12-13 20:15:29 +000075struct ospf6_lsa_header
76{
paul718e3742002-12-13 20:15:29 +000077 u_int16_t age; /* LS age */
78 u_int16_t type; /* LS type */
79 u_int32_t id; /* Link State ID */
80 u_int32_t adv_router; /* Advertising Router */
81 u_int32_t seqnum; /* LS sequence number */
82 u_int16_t checksum; /* LS checksum */
83 u_int16_t length; /* LSA length */
84};
85
hasso508e53e2004-05-18 18:57:06 +000086#define OSPF6_LSA_HEADER_END(h) \
87 ((caddr_t)(h) + sizeof (struct ospf6_lsa_header))
88#define OSPF6_LSA_SIZE(h) \
89 (ntohs (((struct ospf6_lsa_header *) (h))->length))
90#define OSPF6_LSA_END(h) \
91 ((caddr_t)(h) + ntohs (((struct ospf6_lsa_header *) (h))->length))
92#define OSPF6_LSA_IS_TYPE(t, L) \
93 ((L)->header->type == htons (OSPF6_LSTYPE_ ## t) ? 1 : 0)
94#define OSPF6_LSA_IS_SAME(L1, L2) \
95 ((L1)->header->adv_router == (L2)->header->adv_router && \
96 (L1)->header->id == (L2)->header->id && \
97 (L1)->header->type == (L2)->header->type)
98#define OSPF6_LSA_IS_MATCH(t, i, a, L) \
99 ((L)->header->adv_router == (a) && (L)->header->id == (i) && \
100 (L)->header->type == (t))
101#define OSPF6_LSA_IS_DIFFER(L1, L2) ospf6_lsa_is_differ (L1, L2)
102#define OSPF6_LSA_IS_MAXAGE(L) (ospf6_lsa_age_current (L) == MAXAGE)
103#define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2)
paul718e3742002-12-13 20:15:29 +0000104
105struct ospf6_lsa
106{
hasso6452df02004-08-15 05:52:07 +0000107 char name[64]; /* dump string */
paul718e3742002-12-13 20:15:29 +0000108
hasso6452df02004-08-15 05:52:07 +0000109 struct ospf6_lsa *prev;
110 struct ospf6_lsa *next;
hasso508e53e2004-05-18 18:57:06 +0000111
hasso6452df02004-08-15 05:52:07 +0000112 unsigned char lock; /* reference counter */
113 unsigned char flag; /* special meaning (e.g. floodback) */
hasso508e53e2004-05-18 18:57:06 +0000114
hasso6452df02004-08-15 05:52:07 +0000115 struct timeval birth; /* tv_sec when LS age 0 */
hasso6452df02004-08-15 05:52:07 +0000116 struct timeval originated; /* used by MinLSInterval check */
hassoccb59b12004-08-25 09:10:37 +0000117 struct timeval received; /* used by MinLSArrival check */
118 struct timeval installed;
hasso508e53e2004-05-18 18:57:06 +0000119
hasso6452df02004-08-15 05:52:07 +0000120 struct thread *expire;
121 struct thread *refresh; /* For self-originated LSA */
hasso508e53e2004-05-18 18:57:06 +0000122
hasso6452df02004-08-15 05:52:07 +0000123 int retrans_count;
124
hasso6452df02004-08-15 05:52:07 +0000125 struct ospf6_lsdb *lsdb;
paul718e3742002-12-13 20:15:29 +0000126
127 /* lsa instance */
hasso508e53e2004-05-18 18:57:06 +0000128 struct ospf6_lsa_header *header;
paul718e3742002-12-13 20:15:29 +0000129};
130
hasso6452df02004-08-15 05:52:07 +0000131#define OSPF6_LSA_HEADERONLY 0x01
132#define OSPF6_LSA_FLOODBACK 0x02
133#define OSPF6_LSA_DUPLICATE 0x04
134#define OSPF6_LSA_IMPLIEDACK 0x08
hasso508e53e2004-05-18 18:57:06 +0000135
hasso6452df02004-08-15 05:52:07 +0000136struct ospf6_lsa_handler
paul718e3742002-12-13 20:15:29 +0000137{
hasso6452df02004-08-15 05:52:07 +0000138 u_int16_t type; /* network byte order */
hasso508e53e2004-05-18 18:57:06 +0000139 char *name;
hasso508e53e2004-05-18 18:57:06 +0000140 int (*show) (struct vty *, struct ospf6_lsa *);
paul718e3742002-12-13 20:15:29 +0000141};
142
hasso508e53e2004-05-18 18:57:06 +0000143#define OSPF6_LSTYPE_INDEX(type) \
hasso508e53e2004-05-18 18:57:06 +0000144 ((ntohs (type) & OSPF6_LSTYPE_FCODE_MASK) < OSPF6_LSTYPE_SIZE ? \
hasso6452df02004-08-15 05:52:07 +0000145 (ntohs (type) & OSPF6_LSTYPE_FCODE_MASK) : OSPF6_LSTYPE_UNKNOWN)
hasso508e53e2004-05-18 18:57:06 +0000146#define OSPF6_LSTYPE_NAME(type) (ospf6_lstype_name (type))
paul718e3742002-12-13 20:15:29 +0000147
hasso508e53e2004-05-18 18:57:06 +0000148/* Macro for LSA Origination */
149/* void (CONTINUE_IF_...) (struct prefix *addr); */
paul718e3742002-12-13 20:15:29 +0000150
hasso508e53e2004-05-18 18:57:06 +0000151#define CONTINUE_IF_ADDRESS_LINKLOCAL(addr)\
152 if (IN6_IS_ADDR_LINKLOCAL (&(addr)->u.prefix6)) \
153 { \
154 char buf[64]; \
155 prefix2str (addr, buf, sizeof (buf)); \
156 if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
157 zlog_info ("Filter out Linklocal: %s", buf); \
158 continue; \
paul718e3742002-12-13 20:15:29 +0000159 }
160
hasso508e53e2004-05-18 18:57:06 +0000161#define CONTINUE_IF_ADDRESS_UNSPECIFIED(addr) \
162 if (IN6_IS_ADDR_UNSPECIFIED (&(addr)->u.prefix6)) \
163 { \
164 char buf[64]; \
165 prefix2str (addr, buf, sizeof (buf)); \
166 if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
167 zlog_info ("Filter out Unspecified: %s", buf); \
168 continue; \
paul718e3742002-12-13 20:15:29 +0000169 }
170
hasso508e53e2004-05-18 18:57:06 +0000171#define CONTINUE_IF_ADDRESS_LOOPBACK(addr) \
172 if (IN6_IS_ADDR_LOOPBACK (&(addr)->u.prefix6)) \
173 { \
174 char buf[64]; \
175 prefix2str (addr, buf, sizeof (buf)); \
176 if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
177 zlog_info ("Filter out Loopback: %s", buf); \
178 continue; \
179 }
paul718e3742002-12-13 20:15:29 +0000180
hasso508e53e2004-05-18 18:57:06 +0000181#define CONTINUE_IF_ADDRESS_V4COMPAT(addr) \
182 if (IN6_IS_ADDR_V4COMPAT (&(addr)->u.prefix6)) \
183 { \
184 char buf[64]; \
185 prefix2str (addr, buf, sizeof (buf)); \
186 if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
187 zlog_info ("Filter out V4Compat: %s", buf); \
188 continue; \
189 }
190
191#define CONTINUE_IF_ADDRESS_V4MAPPED(addr) \
192 if (IN6_IS_ADDR_V4MAPPED (&(addr)->u.prefix6)) \
193 { \
194 char buf[64]; \
195 prefix2str (addr, buf, sizeof (buf)); \
196 if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
197 zlog_info ("Filter out V4Mapped: %s", buf); \
198 continue; \
199 }
200
201
paul718e3742002-12-13 20:15:29 +0000202/* Function Prototypes */
hasso508e53e2004-05-18 18:57:06 +0000203char *ospf6_lstype_name (u_int16_t type);
204int ospf6_lsa_is_differ (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
205int ospf6_lsa_is_changed (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
206u_int16_t ospf6_lsa_age_current (struct ospf6_lsa *);
207void ospf6_lsa_age_update_to_send (struct ospf6_lsa *, u_int32_t);
208void ospf6_lsa_premature_aging (struct ospf6_lsa *);
209int ospf6_lsa_compare (struct ospf6_lsa *, struct ospf6_lsa *);
paul718e3742002-12-13 20:15:29 +0000210
hasso508e53e2004-05-18 18:57:06 +0000211char *ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size);
212void ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header);
213void ospf6_lsa_header_print (struct ospf6_lsa *lsa);
hasso508e53e2004-05-18 18:57:06 +0000214void ospf6_lsa_show_summary_header (struct vty *vty);
215void ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa);
216void ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa);
217void ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa);
hasso6452df02004-08-15 05:52:07 +0000218void ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa);
paul718e3742002-12-13 20:15:29 +0000219
hasso508e53e2004-05-18 18:57:06 +0000220struct ospf6_lsa *ospf6_lsa_create (struct ospf6_lsa_header *header);
221struct ospf6_lsa *ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header);
222void ospf6_lsa_delete (struct ospf6_lsa *lsa);
223struct ospf6_lsa *ospf6_lsa_copy (struct ospf6_lsa *);
paul718e3742002-12-13 20:15:29 +0000224
225void ospf6_lsa_lock (struct ospf6_lsa *);
226void ospf6_lsa_unlock (struct ospf6_lsa *);
227
paul718e3742002-12-13 20:15:29 +0000228int ospf6_lsa_expire (struct thread *);
229int ospf6_lsa_refresh (struct thread *);
230
hasso508e53e2004-05-18 18:57:06 +0000231unsigned short ospf6_lsa_checksum (struct ospf6_lsa_header *);
232int ospf6_lsa_prohibited_duration (u_int16_t type, u_int32_t id,
233 u_int32_t adv_router, void *scope);
paul718e3742002-12-13 20:15:29 +0000234
hasso6452df02004-08-15 05:52:07 +0000235void ospf6_install_lsa_handler (struct ospf6_lsa_handler *handler);
hasso508e53e2004-05-18 18:57:06 +0000236void ospf6_lsa_init ();
paul718e3742002-12-13 20:15:29 +0000237
hasso508e53e2004-05-18 18:57:06 +0000238int config_write_ospf6_debug_lsa (struct vty *vty);
239void install_element_ospf6_debug_lsa ();
paul718e3742002-12-13 20:15:29 +0000240
241#endif /* OSPF6_LSA_H */
242