]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_lsa.h
zebra/lib: code cleaning
[mirror_frr.git] / ospf6d / ospf6_lsa.h
1 /*
2 * Copyright (C) 2003 Yasuhiro Ohara
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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef OSPF6_LSA_H
22 #define OSPF6_LSA_H
23
24 /* Debug option */
25 #define OSPF6_LSA_DEBUG 0x01
26 #define OSPF6_LSA_DEBUG_ORIGINATE 0x02
27 #define OSPF6_LSA_DEBUG_EXAMIN 0x04
28 #define OSPF6_LSA_DEBUG_FLOOD 0x08
29
30 #define IS_OSPF6_DEBUG_LSA(name) \
31 (ospf6_lstype_debug(htons(OSPF6_LSTYPE_##name)) & OSPF6_LSA_DEBUG)
32 #define IS_OSPF6_DEBUG_ORIGINATE(name) \
33 (ospf6_lstype_debug(htons(OSPF6_LSTYPE_##name)) \
34 & OSPF6_LSA_DEBUG_ORIGINATE)
35 #define IS_OSPF6_DEBUG_EXAMIN(name) \
36 (ospf6_lstype_debug(htons(OSPF6_LSTYPE_##name)) \
37 & OSPF6_LSA_DEBUG_EXAMIN)
38 #define IS_OSPF6_DEBUG_LSA_TYPE(type) \
39 (ospf6_lstype_debug(type) & OSPF6_LSA_DEBUG)
40 #define IS_OSPF6_DEBUG_ORIGINATE_TYPE(type) \
41 (ospf6_lstype_debug(type) & OSPF6_LSA_DEBUG_ORIGINATE)
42 #define IS_OSPF6_DEBUG_EXAMIN_TYPE(type) \
43 (ospf6_lstype_debug(type) & OSPF6_LSA_DEBUG_EXAMIN)
44 #define IS_OSPF6_DEBUG_FLOOD_TYPE(type) \
45 (ospf6_lstype_debug(type) & OSPF6_LSA_DEBUG_FLOOD)
46
47 /* LSA definition */
48
49 #define OSPF6_MAX_LSASIZE 4096
50
51 /* Type */
52 #define OSPF6_LSTYPE_UNKNOWN 0x0000
53 #define OSPF6_LSTYPE_ROUTER 0x2001
54 #define OSPF6_LSTYPE_NETWORK 0x2002
55 #define OSPF6_LSTYPE_INTER_PREFIX 0x2003
56 #define OSPF6_LSTYPE_INTER_ROUTER 0x2004
57 #define OSPF6_LSTYPE_AS_EXTERNAL 0x4005
58 #define OSPF6_LSTYPE_GROUP_MEMBERSHIP 0x2006
59 #define OSPF6_LSTYPE_TYPE_7 0x2007
60 #define OSPF6_LSTYPE_LINK 0x0008
61 #define OSPF6_LSTYPE_INTRA_PREFIX 0x2009
62 #define OSPF6_LSTYPE_SIZE 0x000a
63
64 /* Masks for LS Type : RFC 2740 A.4.2.1 "LS type" */
65 #define OSPF6_LSTYPE_UBIT_MASK 0x8000
66 #define OSPF6_LSTYPE_SCOPE_MASK 0x6000
67 #define OSPF6_LSTYPE_FCODE_MASK 0x1fff
68
69 /* LSA scope */
70 #define OSPF6_SCOPE_LINKLOCAL 0x0000
71 #define OSPF6_SCOPE_AREA 0x2000
72 #define OSPF6_SCOPE_AS 0x4000
73 #define OSPF6_SCOPE_RESERVED 0x6000
74
75 /* XXX U-bit handling should be treated here */
76 #define OSPF6_LSA_SCOPE(type) (ntohs(type) & OSPF6_LSTYPE_SCOPE_MASK)
77
78 /* LSA Header */
79 #define OSPF6_LSA_HEADER_SIZE 20U
80 struct ospf6_lsa_header {
81 uint16_t age; /* LS age */
82 uint16_t type; /* LS type */
83 uint32_t id; /* Link State ID */
84 uint32_t adv_router; /* Advertising Router */
85 uint32_t seqnum; /* LS sequence number */
86 uint16_t checksum; /* LS checksum */
87 uint16_t length; /* LSA length */
88 };
89
90 #define OSPF6_LSA_HEADER_END(h) ((caddr_t)(h) + sizeof(struct ospf6_lsa_header))
91 #define OSPF6_LSA_SIZE(h) (ntohs(((struct ospf6_lsa_header *)(h))->length))
92 #define OSPF6_LSA_END(h) \
93 ((caddr_t)(h) + ntohs(((struct ospf6_lsa_header *)(h))->length))
94 #define OSPF6_LSA_IS_TYPE(t, L) \
95 ((L)->header->type == htons(OSPF6_LSTYPE_##t) ? 1 : 0)
96 #define OSPF6_LSA_IS_SAME(L1, L2) \
97 ((L1)->header->adv_router == (L2)->header->adv_router \
98 && (L1)->header->id == (L2)->header->id \
99 && (L1)->header->type == (L2)->header->type)
100 #define OSPF6_LSA_IS_MATCH(t, i, a, L) \
101 ((L)->header->adv_router == (a) && (L)->header->id == (i) \
102 && (L)->header->type == (t))
103 #define OSPF6_LSA_IS_DIFFER(L1, L2) ospf6_lsa_is_differ (L1, L2)
104 #define OSPF6_LSA_IS_MAXAGE(L) (ospf6_lsa_age_current (L) == OSPF_LSA_MAXAGE)
105 #define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2)
106 #define OSPF6_LSA_IS_SEQWRAP(L) ((L)->header->seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER + 1))
107
108 struct ospf6_lsa {
109 char name[64]; /* dump string */
110
111 struct route_node *rn;
112
113 unsigned char lock; /* reference counter */
114 unsigned char flag; /* special meaning (e.g. floodback) */
115
116 struct timeval birth; /* tv_sec when LS age 0 */
117 struct timeval originated; /* used by MinLSInterval check */
118 struct timeval received; /* used by MinLSArrival check */
119 struct timeval installed;
120
121 struct thread *expire;
122 struct thread *refresh; /* For self-originated LSA */
123
124 int retrans_count;
125
126 struct ospf6_lsdb *lsdb;
127
128 /* lsa instance */
129 struct ospf6_lsa_header *header;
130 };
131
132 #define OSPF6_LSA_HEADERONLY 0x01
133 #define OSPF6_LSA_FLOODBACK 0x02
134 #define OSPF6_LSA_DUPLICATE 0x04
135 #define OSPF6_LSA_IMPLIEDACK 0x08
136 #define OSPF6_LSA_UNAPPROVED 0x10
137 #define OSPF6_LSA_SEQWRAPPED 0x20
138
139 struct ospf6_lsa_handler {
140 const struct {
141 uint16_t type; /* host byte order */
142 const char *name;
143 const char *short_name;
144 int (*show)(struct vty *, struct ospf6_lsa *);
145 char *(*get_prefix_str)(struct ospf6_lsa *, char *buf,
146 int buflen, int pos);
147 } s;
148 #define lh_type s.type
149 #define lh_name s.name
150 #define lh_short_name s.short_name
151 #define lh_show s.show
152 #define lh_get_prefix_str s.get_prefix_str
153 uint8_t debug;
154 #define lh_debug debug
155 };
156
157 #define OSPF6_LSA_IS_KNOWN(t) \
158 (ospf6_get_lsa_handler(t)->lh_type != OSPF6_LSTYPE_UNKNOWN ? 1 : 0)
159
160 extern vector ospf6_lsa_handler_vector;
161
162 /* Macro for LSA Origination */
163 /* addr is (struct prefix *) */
164 #define CONTINUE_IF_ADDRESS_LINKLOCAL(debug, addr) \
165 if (IN6_IS_ADDR_LINKLOCAL(&(addr)->u.prefix6)) { \
166 char buf[PREFIX2STR_BUFFER]; \
167 prefix2str(addr, buf, sizeof(buf)); \
168 if (debug) \
169 zlog_debug("Filter out Linklocal: %s", buf); \
170 continue; \
171 }
172
173 #define CONTINUE_IF_ADDRESS_UNSPECIFIED(debug, addr) \
174 if (IN6_IS_ADDR_UNSPECIFIED(&(addr)->u.prefix6)) { \
175 char buf[PREFIX2STR_BUFFER]; \
176 prefix2str(addr, buf, sizeof(buf)); \
177 if (debug) \
178 zlog_debug("Filter out Unspecified: %s", buf); \
179 continue; \
180 }
181
182 #define CONTINUE_IF_ADDRESS_LOOPBACK(debug, addr) \
183 if (IN6_IS_ADDR_LOOPBACK(&(addr)->u.prefix6)) { \
184 char buf[PREFIX2STR_BUFFER]; \
185 prefix2str(addr, buf, sizeof(buf)); \
186 if (debug) \
187 zlog_debug("Filter out Loopback: %s", buf); \
188 continue; \
189 }
190
191 #define CONTINUE_IF_ADDRESS_V4COMPAT(debug, addr) \
192 if (IN6_IS_ADDR_V4COMPAT(&(addr)->u.prefix6)) { \
193 char buf[PREFIX2STR_BUFFER]; \
194 prefix2str(addr, buf, sizeof(buf)); \
195 if (debug) \
196 zlog_debug("Filter out V4Compat: %s", buf); \
197 continue; \
198 }
199
200 #define CONTINUE_IF_ADDRESS_V4MAPPED(debug, addr) \
201 if (IN6_IS_ADDR_V4MAPPED(&(addr)->u.prefix6)) { \
202 char buf[PREFIX2STR_BUFFER]; \
203 prefix2str(addr, buf, sizeof(buf)); \
204 if (debug) \
205 zlog_debug("Filter out V4Mapped: %s", buf); \
206 continue; \
207 }
208
209
210 /* Function Prototypes */
211 extern const char *ospf6_lstype_name(uint16_t type);
212 extern const char *ospf6_lstype_short_name(uint16_t type);
213 extern uint8_t ospf6_lstype_debug(uint16_t type);
214 extern int ospf6_lsa_is_differ(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
215 extern int ospf6_lsa_is_changed(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
216 extern uint16_t ospf6_lsa_age_current(struct ospf6_lsa *);
217 extern void ospf6_lsa_age_update_to_send(struct ospf6_lsa *, uint32_t);
218 extern void ospf6_lsa_premature_aging(struct ospf6_lsa *);
219 extern int ospf6_lsa_compare(struct ospf6_lsa *, struct ospf6_lsa *);
220
221 extern char *ospf6_lsa_printbuf(struct ospf6_lsa *lsa, char *buf, int size);
222 extern void ospf6_lsa_header_print_raw(struct ospf6_lsa_header *header);
223 extern void ospf6_lsa_header_print(struct ospf6_lsa *lsa);
224 extern void ospf6_lsa_show_summary_header(struct vty *vty);
225 extern void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa);
226 extern void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa);
227 extern void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa);
228 extern void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa);
229
230 extern struct ospf6_lsa *ospf6_lsa_create(struct ospf6_lsa_header *header);
231 extern struct ospf6_lsa *
232 ospf6_lsa_create_headeronly(struct ospf6_lsa_header *header);
233 extern void ospf6_lsa_delete(struct ospf6_lsa *lsa);
234 extern struct ospf6_lsa *ospf6_lsa_copy(struct ospf6_lsa *);
235
236 extern void ospf6_lsa_lock(struct ospf6_lsa *);
237 extern void ospf6_lsa_unlock(struct ospf6_lsa *);
238
239 extern int ospf6_lsa_expire(struct thread *);
240 extern int ospf6_lsa_refresh(struct thread *);
241
242 extern unsigned short ospf6_lsa_checksum(struct ospf6_lsa_header *);
243 extern int ospf6_lsa_checksum_valid(struct ospf6_lsa_header *);
244 extern int ospf6_lsa_prohibited_duration(uint16_t type, uint32_t id,
245 uint32_t adv_router, void *scope);
246
247 extern void ospf6_install_lsa_handler(const struct ospf6_lsa_handler *handler);
248 extern const struct ospf6_lsa_handler *ospf6_get_lsa_handler(uint16_t type);
249
250 extern void ospf6_lsa_init(void);
251 extern void ospf6_lsa_terminate(void);
252
253 extern int config_write_ospf6_debug_lsa(struct vty *vty);
254 extern void install_element_ospf6_debug_lsa(void);
255 extern void ospf6_lsa_age_set(struct ospf6_lsa *lsa);
256 extern void ospf6_flush_self_originated_lsas_now(void);
257
258 #endif /* OSPF6_LSA_H */