]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_lsa.h
ospf6d: CVE-2011-3323 (fortify packet reception)
[mirror_frr.git] / ospf6d / ospf6_lsa.h
CommitLineData
718e3744 1/*
508e53e2 2 * Copyright (C) 2003 Yasuhiro Ohara
718e3744 3 *
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
508e53e2 25/* Debug option */
1e05838a 26#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)
718e3744 48
49/* LSA definition */
50
508e53e2 51#define OSPF6_MAX_LSASIZE 4096
718e3744 52
53/* Type */
508e53e2 54#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
718e3744 65
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
508e53e2 69#define OSPF6_LSTYPE_FCODE_MASK 0x1fff
718e3744 70
508e53e2 71/* LSA scope */
6452df09 72#define OSPF6_SCOPE_LINKLOCAL 0x0000
73#define OSPF6_SCOPE_AREA 0x2000
74#define OSPF6_SCOPE_AS 0x4000
75#define OSPF6_SCOPE_RESERVED 0x6000
718e3744 76
6452df09 77/* XXX U-bit handling should be treated here */
508e53e2 78#define OSPF6_LSA_SCOPE(type) \
79 (ntohs (type) & OSPF6_LSTYPE_SCOPE_MASK)
718e3744 80
81/* LSA Header */
abc7ef44 82#define OSPF6_LSA_HEADER_SIZE 20U
718e3744 83struct ospf6_lsa_header
718e3744 84{
85 u_int16_t age; /* LS age */
86 u_int16_t type; /* LS type */
87 u_int32_t id; /* Link State ID */
88 u_int32_t adv_router; /* Advertising Router */
89 u_int32_t seqnum; /* LS sequence number */
90 u_int16_t checksum; /* LS checksum */
91 u_int16_t length; /* LSA length */
92};
93
508e53e2 94#define OSPF6_LSA_HEADER_END(h) \
95 ((caddr_t)(h) + sizeof (struct ospf6_lsa_header))
96#define OSPF6_LSA_SIZE(h) \
97 (ntohs (((struct ospf6_lsa_header *) (h))->length))
98#define OSPF6_LSA_END(h) \
99 ((caddr_t)(h) + ntohs (((struct ospf6_lsa_header *) (h))->length))
100#define OSPF6_LSA_IS_TYPE(t, L) \
101 ((L)->header->type == htons (OSPF6_LSTYPE_ ## t) ? 1 : 0)
102#define OSPF6_LSA_IS_SAME(L1, L2) \
103 ((L1)->header->adv_router == (L2)->header->adv_router && \
104 (L1)->header->id == (L2)->header->id && \
105 (L1)->header->type == (L2)->header->type)
106#define OSPF6_LSA_IS_MATCH(t, i, a, L) \
107 ((L)->header->adv_router == (a) && (L)->header->id == (i) && \
108 (L)->header->type == (t))
109#define OSPF6_LSA_IS_DIFFER(L1, L2) ospf6_lsa_is_differ (L1, L2)
110#define OSPF6_LSA_IS_MAXAGE(L) (ospf6_lsa_age_current (L) == MAXAGE)
111#define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2)
718e3744 112
113struct ospf6_lsa
114{
6452df09 115 char name[64]; /* dump string */
718e3744 116
6452df09 117 struct ospf6_lsa *prev;
118 struct ospf6_lsa *next;
718e3744 119
6452df09 120 unsigned char lock; /* reference counter */
121 unsigned char flag; /* special meaning (e.g. floodback) */
718e3744 122
6452df09 123 struct timeval birth; /* tv_sec when LS age 0 */
6452df09 124 struct timeval originated; /* used by MinLSInterval check */
ccb59b11 125 struct timeval received; /* used by MinLSArrival check */
126 struct timeval installed;
718e3744 127
6452df09 128 struct thread *expire;
129 struct thread *refresh; /* For self-originated LSA */
718e3744 130
6452df09 131 int retrans_count;
132
6452df09 133 struct ospf6_lsdb *lsdb;
718e3744 134
508e53e2 135 /* lsa instance */
136 struct ospf6_lsa_header *header;
718e3744 137};
138
6452df09 139#define OSPF6_LSA_HEADERONLY 0x01
140#define OSPF6_LSA_FLOODBACK 0x02
141#define OSPF6_LSA_DUPLICATE 0x04
142#define OSPF6_LSA_IMPLIEDACK 0x08
508e53e2 143
6452df09 144struct ospf6_lsa_handler
508e53e2 145{
1e05838a 146 u_int16_t type; /* host byte order */
0c083ee9 147 const char *name;
508e53e2 148 int (*show) (struct vty *, struct ospf6_lsa *);
1e05838a 149 u_char debug;
508e53e2 150};
151
2680aa2b 152extern struct ospf6_lsa_handler unknown_handler;
153#define OSPF6_LSA_IS_KNOWN(type) \
154 (ospf6_get_lsa_handler (type) != &unknown_handler ? 1 : 0)
155
508e53e2 156/* Macro for LSA Origination */
1e05838a 157/* addr is (struct prefix *) */
158#define CONTINUE_IF_ADDRESS_LINKLOCAL(debug,addr) \
508e53e2 159 if (IN6_IS_ADDR_LINKLOCAL (&(addr)->u.prefix6)) \
160 { \
161 char buf[64]; \
162 prefix2str (addr, buf, sizeof (buf)); \
1e05838a 163 if (debug) \
d1db06fa 164 zlog_debug ("Filter out Linklocal: %s", buf); \
508e53e2 165 continue; \
718e3744 166 }
167
1e05838a 168#define CONTINUE_IF_ADDRESS_UNSPECIFIED(debug,addr) \
508e53e2 169 if (IN6_IS_ADDR_UNSPECIFIED (&(addr)->u.prefix6)) \
170 { \
171 char buf[64]; \
172 prefix2str (addr, buf, sizeof (buf)); \
1e05838a 173 if (debug) \
d1db06fa 174 zlog_debug ("Filter out Unspecified: %s", buf);\
508e53e2 175 continue; \
718e3744 176 }
508e53e2 177
1e05838a 178#define CONTINUE_IF_ADDRESS_LOOPBACK(debug,addr) \
508e53e2 179 if (IN6_IS_ADDR_LOOPBACK (&(addr)->u.prefix6)) \
180 { \
181 char buf[64]; \
182 prefix2str (addr, buf, sizeof (buf)); \
1e05838a 183 if (debug) \
d1db06fa 184 zlog_debug ("Filter out Loopback: %s", buf); \
508e53e2 185 continue; \
718e3744 186 }
508e53e2 187
1e05838a 188#define CONTINUE_IF_ADDRESS_V4COMPAT(debug,addr) \
508e53e2 189 if (IN6_IS_ADDR_V4COMPAT (&(addr)->u.prefix6)) \
190 { \
191 char buf[64]; \
192 prefix2str (addr, buf, sizeof (buf)); \
1e05838a 193 if (debug) \
d1db06fa 194 zlog_debug ("Filter out V4Compat: %s", buf); \
508e53e2 195 continue; \
718e3744 196 }
197
1e05838a 198#define CONTINUE_IF_ADDRESS_V4MAPPED(debug,addr) \
508e53e2 199 if (IN6_IS_ADDR_V4MAPPED (&(addr)->u.prefix6)) \
200 { \
201 char buf[64]; \
202 prefix2str (addr, buf, sizeof (buf)); \
1e05838a 203 if (debug) \
d1db06fa 204 zlog_debug ("Filter out V4Mapped: %s", buf); \
508e53e2 205 continue; \
206 }
718e3744 207
508e53e2 208\f
718e3744 209/* Function Prototypes */
6ac29a51
PJ
210extern const char *ospf6_lstype_name (u_int16_t type);
211extern u_char ospf6_lstype_debug (u_int16_t type);
212extern int ospf6_lsa_is_differ (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
213extern int ospf6_lsa_is_changed (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
214extern u_int16_t ospf6_lsa_age_current (struct ospf6_lsa *);
215extern void ospf6_lsa_age_update_to_send (struct ospf6_lsa *, u_int32_t);
216extern void ospf6_lsa_premature_aging (struct ospf6_lsa *);
217extern int ospf6_lsa_compare (struct ospf6_lsa *, struct ospf6_lsa *);
218
219extern char *ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size);
220extern void ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header);
221extern void ospf6_lsa_header_print (struct ospf6_lsa *lsa);
222extern void ospf6_lsa_show_summary_header (struct vty *vty);
223extern void ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa);
224extern void ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa);
225extern void ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa);
226extern void ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa);
227
228extern struct ospf6_lsa *ospf6_lsa_create (struct ospf6_lsa_header *header);
229extern struct ospf6_lsa *ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header);
230extern void ospf6_lsa_delete (struct ospf6_lsa *lsa);
231extern struct ospf6_lsa *ospf6_lsa_copy (struct ospf6_lsa *);
232
233extern void ospf6_lsa_lock (struct ospf6_lsa *);
234extern void ospf6_lsa_unlock (struct ospf6_lsa *);
235
236extern int ospf6_lsa_expire (struct thread *);
237extern int ospf6_lsa_refresh (struct thread *);
238
239extern unsigned short ospf6_lsa_checksum (struct ospf6_lsa_header *);
240extern int ospf6_lsa_prohibited_duration (u_int16_t type, u_int32_t id,
241 u_int32_t adv_router, void *scope);
242
243extern void ospf6_install_lsa_handler (struct ospf6_lsa_handler *handler);
244extern struct ospf6_lsa_handler *ospf6_get_lsa_handler (u_int16_t type);
245
246extern void ospf6_lsa_init (void);
ae2254aa 247extern void ospf6_lsa_terminate (void);
6ac29a51
PJ
248extern void ospf6_lsa_cmd_init (void);
249
250extern int config_write_ospf6_debug_lsa (struct vty *vty);
251extern void install_element_ospf6_debug_lsa (void);
718e3744 252
253#endif /* OSPF6_LSA_H */
254