blob: 1f88f926481a6c55f7d877ace265dba7206f0976 [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 */
paul718e3742002-12-13 20:15:29 +000065#define OSPF6_LSA_SCOPE_LINKLOCAL 0x0000
66#define OSPF6_LSA_SCOPE_AREA 0x2000
67#define OSPF6_LSA_SCOPE_AS 0x4000
68#define OSPF6_LSA_SCOPE_RESERVED 0x6000
paul718e3742002-12-13 20:15:29 +000069
hasso508e53e2004-05-18 18:57:06 +000070#define OSPF6_LSA_SCOPE(type) \
71 (ntohs (type) & OSPF6_LSTYPE_SCOPE_MASK)
paul718e3742002-12-13 20:15:29 +000072
73/* LSA Header */
paul718e3742002-12-13 20:15:29 +000074struct ospf6_lsa_header
75{
paul718e3742002-12-13 20:15:29 +000076 u_int16_t age; /* LS age */
77 u_int16_t type; /* LS type */
78 u_int32_t id; /* Link State ID */
79 u_int32_t adv_router; /* Advertising Router */
80 u_int32_t seqnum; /* LS sequence number */
81 u_int16_t checksum; /* LS checksum */
82 u_int16_t length; /* LSA length */
83};
84
hasso508e53e2004-05-18 18:57:06 +000085#define OSPF6_LSA_HEADER_END(h) \
86 ((caddr_t)(h) + sizeof (struct ospf6_lsa_header))
87#define OSPF6_LSA_SIZE(h) \
88 (ntohs (((struct ospf6_lsa_header *) (h))->length))
89#define OSPF6_LSA_END(h) \
90 ((caddr_t)(h) + ntohs (((struct ospf6_lsa_header *) (h))->length))
91#define OSPF6_LSA_IS_TYPE(t, L) \
92 ((L)->header->type == htons (OSPF6_LSTYPE_ ## t) ? 1 : 0)
93#define OSPF6_LSA_IS_SAME(L1, L2) \
94 ((L1)->header->adv_router == (L2)->header->adv_router && \
95 (L1)->header->id == (L2)->header->id && \
96 (L1)->header->type == (L2)->header->type)
97#define OSPF6_LSA_IS_MATCH(t, i, a, L) \
98 ((L)->header->adv_router == (a) && (L)->header->id == (i) && \
99 (L)->header->type == (t))
100#define OSPF6_LSA_IS_DIFFER(L1, L2) ospf6_lsa_is_differ (L1, L2)
101#define OSPF6_LSA_IS_MAXAGE(L) (ospf6_lsa_age_current (L) == MAXAGE)
102#define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2)
paul718e3742002-12-13 20:15:29 +0000103
104struct ospf6_lsa
105{
hasso508e53e2004-05-18 18:57:06 +0000106 char name[64]; /* dump string */
paul718e3742002-12-13 20:15:29 +0000107
hasso508e53e2004-05-18 18:57:06 +0000108 struct ospf6_lsa *prev;
109 struct ospf6_lsa *next;
110
111 unsigned char lock; /* reference counter */
112 unsigned char flag; /* special meaning (e.g. floodback) */
113
114 struct timeval birth; /* tv_sec when LS age 0 */
115 struct timeval installed; /* used by MinLSArrival check */
116 struct timeval originated; /* used by MinLSInterval check */
117
118 struct thread *expire;
119 struct thread *refresh; /* For self-originated LSA */
120
121 void *scope; /* pointer to scope data structure */
122 int headeronly; /* indicate this is LS header only */
hasso3b4cd3a2004-05-18 19:28:32 +0000123 int onretrans;
paul718e3742002-12-13 20:15:29 +0000124
125 /* lsa instance */
hasso508e53e2004-05-18 18:57:06 +0000126 struct ospf6_lsa_header *header;
paul718e3742002-12-13 20:15:29 +0000127};
128
hasso508e53e2004-05-18 18:57:06 +0000129#define OSPF6_LSA_FLOODBACK 0x01
130#define OSPF6_LSA_DUPLICATE 0x02
131#define OSPF6_LSA_IMPLIEDACK 0x04
132#define OSPF6_LSA_REFRESH 0x08
133
134struct ospf6_lstype
paul718e3742002-12-13 20:15:29 +0000135{
hasso508e53e2004-05-18 18:57:06 +0000136 char *name;
137 int (*reoriginate) (struct ospf6_lsa *);
138 int (*show) (struct vty *, struct ospf6_lsa *);
paul718e3742002-12-13 20:15:29 +0000139};
140
hasso508e53e2004-05-18 18:57:06 +0000141extern struct ospf6_lstype ospf6_lstype[OSPF6_LSTYPE_SIZE];
142#define OSPF6_LSTYPE_INDEX(type) \
143 (((type) & OSPF6_LSTYPE_FCODE_MASK) < OSPF6_LSTYPE_SIZE ? \
144 ((type) & OSPF6_LSTYPE_FCODE_MASK) : OSPF6_LSTYPE_UNKNOWN)
paul718e3742002-12-13 20:15:29 +0000145
hasso508e53e2004-05-18 18:57:06 +0000146#if 0
147extern char *ospf6_lstype_str[OSPF6_LSTYPE_SIZE];
148#define OSPF6_LSTYPE_NAME(type) \
149 ((ntohs (type) & OSPF6_LSTYPE_FCODE_MASK) < OSPF6_LSTYPE_SIZE ? \
150 ospf6_lstype_str[ntohs (type) & OSPF6_LSTYPE_FCODE_MASK] : \
151 ospf6_lstype_str[OSPF6_LSTYPE_UNKNOWN])
152#else /*0*/
153#define OSPF6_LSTYPE_NAME(type) (ospf6_lstype_name (type))
154#endif /*0*/
paul718e3742002-12-13 20:15:29 +0000155
hasso508e53e2004-05-18 18:57:06 +0000156/* Macro for LSA Origination */
157/* void (CONTINUE_IF_...) (struct prefix *addr); */
paul718e3742002-12-13 20:15:29 +0000158
hasso508e53e2004-05-18 18:57:06 +0000159#define CONTINUE_IF_ADDRESS_LINKLOCAL(addr)\
160 if (IN6_IS_ADDR_LINKLOCAL (&(addr)->u.prefix6)) \
161 { \
162 char buf[64]; \
163 prefix2str (addr, buf, sizeof (buf)); \
164 if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
165 zlog_info ("Filter out Linklocal: %s", buf); \
166 continue; \
paul718e3742002-12-13 20:15:29 +0000167 }
168
hasso508e53e2004-05-18 18:57:06 +0000169#define CONTINUE_IF_ADDRESS_UNSPECIFIED(addr) \
170 if (IN6_IS_ADDR_UNSPECIFIED (&(addr)->u.prefix6)) \
171 { \
172 char buf[64]; \
173 prefix2str (addr, buf, sizeof (buf)); \
174 if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
175 zlog_info ("Filter out Unspecified: %s", buf); \
176 continue; \
paul718e3742002-12-13 20:15:29 +0000177 }
178
hasso508e53e2004-05-18 18:57:06 +0000179#define CONTINUE_IF_ADDRESS_LOOPBACK(addr) \
180 if (IN6_IS_ADDR_LOOPBACK (&(addr)->u.prefix6)) \
181 { \
182 char buf[64]; \
183 prefix2str (addr, buf, sizeof (buf)); \
184 if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
185 zlog_info ("Filter out Loopback: %s", buf); \
186 continue; \
187 }
paul718e3742002-12-13 20:15:29 +0000188
hasso508e53e2004-05-18 18:57:06 +0000189#define CONTINUE_IF_ADDRESS_V4COMPAT(addr) \
190 if (IN6_IS_ADDR_V4COMPAT (&(addr)->u.prefix6)) \
191 { \
192 char buf[64]; \
193 prefix2str (addr, buf, sizeof (buf)); \
194 if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
195 zlog_info ("Filter out V4Compat: %s", buf); \
196 continue; \
197 }
198
199#define CONTINUE_IF_ADDRESS_V4MAPPED(addr) \
200 if (IN6_IS_ADDR_V4MAPPED (&(addr)->u.prefix6)) \
201 { \
202 char buf[64]; \
203 prefix2str (addr, buf, sizeof (buf)); \
204 if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
205 zlog_info ("Filter out V4Mapped: %s", buf); \
206 continue; \
207 }
208
209
paul718e3742002-12-13 20:15:29 +0000210/* Function Prototypes */
hasso508e53e2004-05-18 18:57:06 +0000211char *ospf6_lstype_name (u_int16_t type);
212int ospf6_lsa_is_differ (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
213int ospf6_lsa_is_changed (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
214u_int16_t ospf6_lsa_age_current (struct ospf6_lsa *);
215void ospf6_lsa_age_update_to_send (struct ospf6_lsa *, u_int32_t);
216void ospf6_lsa_premature_aging (struct ospf6_lsa *);
217int ospf6_lsa_compare (struct ospf6_lsa *, struct ospf6_lsa *);
paul718e3742002-12-13 20:15:29 +0000218
hasso508e53e2004-05-18 18:57:06 +0000219char *ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size);
220void ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header);
221void ospf6_lsa_header_print (struct ospf6_lsa *lsa);
222void ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa);
223void ospf6_lsa_show_summary_header (struct vty *vty);
224void ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa);
225void ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa);
226void ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa);
paul718e3742002-12-13 20:15:29 +0000227
hasso508e53e2004-05-18 18:57:06 +0000228u_int32_t ospf6_lsa_new_seqnum (u_int16_t type, u_int32_t id,
229 u_int32_t adv_router, void *scope);
paul718e3742002-12-13 20:15:29 +0000230
hasso508e53e2004-05-18 18:57:06 +0000231struct ospf6_lsa *ospf6_lsa_create (struct ospf6_lsa_header *header);
232struct ospf6_lsa *ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header);
233void ospf6_lsa_delete (struct ospf6_lsa *lsa);
234struct ospf6_lsa *ospf6_lsa_copy (struct ospf6_lsa *);
paul718e3742002-12-13 20:15:29 +0000235
236void ospf6_lsa_lock (struct ospf6_lsa *);
237void ospf6_lsa_unlock (struct ospf6_lsa *);
238
hasso508e53e2004-05-18 18:57:06 +0000239void ospf6_lsa_originate (struct ospf6_lsa *);
240void ospf6_lsa_re_originate (struct ospf6_lsa *lsa);
paul718e3742002-12-13 20:15:29 +0000241int ospf6_lsa_expire (struct thread *);
242int ospf6_lsa_refresh (struct thread *);
243
hasso508e53e2004-05-18 18:57:06 +0000244unsigned short ospf6_lsa_checksum (struct ospf6_lsa_header *);
245int ospf6_lsa_prohibited_duration (u_int16_t type, u_int32_t id,
246 u_int32_t adv_router, void *scope);
paul718e3742002-12-13 20:15:29 +0000247
hasso508e53e2004-05-18 18:57:06 +0000248void ospf6_lsa_init ();
paul718e3742002-12-13 20:15:29 +0000249
hasso508e53e2004-05-18 18:57:06 +0000250int config_write_ospf6_debug_lsa (struct vty *vty);
251void install_element_ospf6_debug_lsa ();
paul718e3742002-12-13 20:15:29 +0000252
253#endif /* OSPF6_LSA_H */
254