blob: 8b9d5f348e7c4cc5ed039db1b9f7134df4b7b737 [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 */
123
124 unsigned long refcnt;
125 struct ospf6_lsa *refsrc;
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
hasso508e53e2004-05-18 18:57:06 +0000131#define OSPF6_LSA_FLOODBACK 0x01
132#define OSPF6_LSA_DUPLICATE 0x02
133#define OSPF6_LSA_IMPLIEDACK 0x04
134#define OSPF6_LSA_REFRESH 0x08
135
136struct ospf6_lstype
paul718e3742002-12-13 20:15:29 +0000137{
hasso508e53e2004-05-18 18:57:06 +0000138 char *name;
139 int (*reoriginate) (struct ospf6_lsa *);
140 int (*show) (struct vty *, struct ospf6_lsa *);
paul718e3742002-12-13 20:15:29 +0000141};
142
hasso508e53e2004-05-18 18:57:06 +0000143extern struct ospf6_lstype ospf6_lstype[OSPF6_LSTYPE_SIZE];
144#define OSPF6_LSTYPE_INDEX(type) \
145 (((type) & OSPF6_LSTYPE_FCODE_MASK) < OSPF6_LSTYPE_SIZE ? \
146 ((type) & OSPF6_LSTYPE_FCODE_MASK) : OSPF6_LSTYPE_UNKNOWN)
paul718e3742002-12-13 20:15:29 +0000147
hasso508e53e2004-05-18 18:57:06 +0000148#if 0
149extern char *ospf6_lstype_str[OSPF6_LSTYPE_SIZE];
150#define OSPF6_LSTYPE_NAME(type) \
151 ((ntohs (type) & OSPF6_LSTYPE_FCODE_MASK) < OSPF6_LSTYPE_SIZE ? \
152 ospf6_lstype_str[ntohs (type) & OSPF6_LSTYPE_FCODE_MASK] : \
153 ospf6_lstype_str[OSPF6_LSTYPE_UNKNOWN])
154#else /*0*/
155#define OSPF6_LSTYPE_NAME(type) (ospf6_lstype_name (type))
156#endif /*0*/
paul718e3742002-12-13 20:15:29 +0000157
hasso508e53e2004-05-18 18:57:06 +0000158/* Macro for LSA Origination */
159/* void (CONTINUE_IF_...) (struct prefix *addr); */
paul718e3742002-12-13 20:15:29 +0000160
hasso508e53e2004-05-18 18:57:06 +0000161#define CONTINUE_IF_ADDRESS_LINKLOCAL(addr)\
162 if (IN6_IS_ADDR_LINKLOCAL (&(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 Linklocal: %s", buf); \
168 continue; \
paul718e3742002-12-13 20:15:29 +0000169 }
170
hasso508e53e2004-05-18 18:57:06 +0000171#define CONTINUE_IF_ADDRESS_UNSPECIFIED(addr) \
172 if (IN6_IS_ADDR_UNSPECIFIED (&(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 Unspecified: %s", buf); \
178 continue; \
paul718e3742002-12-13 20:15:29 +0000179 }
180
hasso508e53e2004-05-18 18:57:06 +0000181#define CONTINUE_IF_ADDRESS_LOOPBACK(addr) \
182 if (IN6_IS_ADDR_LOOPBACK (&(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 Loopback: %s", buf); \
188 continue; \
189 }
paul718e3742002-12-13 20:15:29 +0000190
hasso508e53e2004-05-18 18:57:06 +0000191#define CONTINUE_IF_ADDRESS_V4COMPAT(addr) \
192 if (IN6_IS_ADDR_V4COMPAT (&(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 V4Compat: %s", buf); \
198 continue; \
199 }
200
201#define CONTINUE_IF_ADDRESS_V4MAPPED(addr) \
202 if (IN6_IS_ADDR_V4MAPPED (&(addr)->u.prefix6)) \
203 { \
204 char buf[64]; \
205 prefix2str (addr, buf, sizeof (buf)); \
206 if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \
207 zlog_info ("Filter out V4Mapped: %s", buf); \
208 continue; \
209 }
210
211
paul718e3742002-12-13 20:15:29 +0000212/* Function Prototypes */
hasso508e53e2004-05-18 18:57:06 +0000213char *ospf6_lstype_name (u_int16_t type);
214int ospf6_lsa_is_differ (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
215int ospf6_lsa_is_changed (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
216u_int16_t ospf6_lsa_age_current (struct ospf6_lsa *);
217void ospf6_lsa_age_update_to_send (struct ospf6_lsa *, u_int32_t);
218void ospf6_lsa_premature_aging (struct ospf6_lsa *);
219int ospf6_lsa_compare (struct ospf6_lsa *, struct ospf6_lsa *);
paul718e3742002-12-13 20:15:29 +0000220
hasso508e53e2004-05-18 18:57:06 +0000221char *ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size);
222void ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header);
223void ospf6_lsa_header_print (struct ospf6_lsa *lsa);
224void ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa);
225void ospf6_lsa_show_summary_header (struct vty *vty);
226void ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa);
227void ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa);
228void ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa);
paul718e3742002-12-13 20:15:29 +0000229
hasso508e53e2004-05-18 18:57:06 +0000230u_int32_t ospf6_lsa_new_seqnum (u_int16_t type, u_int32_t id,
231 u_int32_t adv_router, void *scope);
paul718e3742002-12-13 20:15:29 +0000232
hasso508e53e2004-05-18 18:57:06 +0000233struct ospf6_lsa *ospf6_lsa_create (struct ospf6_lsa_header *header);
234struct ospf6_lsa *ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header);
235void ospf6_lsa_delete (struct ospf6_lsa *lsa);
236struct ospf6_lsa *ospf6_lsa_copy (struct ospf6_lsa *);
paul718e3742002-12-13 20:15:29 +0000237
238void ospf6_lsa_lock (struct ospf6_lsa *);
239void ospf6_lsa_unlock (struct ospf6_lsa *);
240
hasso508e53e2004-05-18 18:57:06 +0000241void ospf6_lsa_originate (struct ospf6_lsa *);
242void ospf6_lsa_re_originate (struct ospf6_lsa *lsa);
paul718e3742002-12-13 20:15:29 +0000243int ospf6_lsa_expire (struct thread *);
244int ospf6_lsa_refresh (struct thread *);
245
hasso508e53e2004-05-18 18:57:06 +0000246unsigned short ospf6_lsa_checksum (struct ospf6_lsa_header *);
247int ospf6_lsa_prohibited_duration (u_int16_t type, u_int32_t id,
248 u_int32_t adv_router, void *scope);
paul718e3742002-12-13 20:15:29 +0000249
hasso508e53e2004-05-18 18:57:06 +0000250void ospf6_lsa_init ();
paul718e3742002-12-13 20:15:29 +0000251
hasso508e53e2004-05-18 18:57:06 +0000252int config_write_ospf6_debug_lsa (struct vty *vty);
253void install_element_ospf6_debug_lsa ();
paul718e3742002-12-13 20:15:29 +0000254
255#endif /* OSPF6_LSA_H */
256