paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 25 | /* Debug option */ |
| 26 | extern 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) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 41 | |
| 42 | /* LSA definition */ |
| 43 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 44 | #define OSPF6_MAX_LSASIZE 4096 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 45 | |
| 46 | /* Type */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 47 | #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 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 58 | |
| 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 |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 62 | #define OSPF6_LSTYPE_FCODE_MASK 0x1fff |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 63 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 64 | /* LSA scope */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 65 | #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 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 69 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 70 | #define OSPF6_LSA_SCOPE(type) \ |
| 71 | (ntohs (type) & OSPF6_LSTYPE_SCOPE_MASK) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 72 | |
| 73 | /* LSA Header */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 74 | struct ospf6_lsa_header |
| 75 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 76 | 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 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 85 | #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) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 103 | |
| 104 | struct ospf6_lsa |
| 105 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 106 | char name[64]; /* dump string */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 107 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 108 | 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 */ |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 123 | int onretrans; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 124 | |
| 125 | /* lsa instance */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 126 | struct ospf6_lsa_header *header; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 129 | #define OSPF6_LSA_FLOODBACK 0x01 |
| 130 | #define OSPF6_LSA_DUPLICATE 0x02 |
| 131 | #define OSPF6_LSA_IMPLIEDACK 0x04 |
| 132 | #define OSPF6_LSA_REFRESH 0x08 |
| 133 | |
| 134 | struct ospf6_lstype |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 135 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 136 | char *name; |
| 137 | int (*reoriginate) (struct ospf6_lsa *); |
| 138 | int (*show) (struct vty *, struct ospf6_lsa *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 141 | extern 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) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 145 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 146 | #if 0 |
| 147 | extern 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*/ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 155 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 156 | /* Macro for LSA Origination */ |
| 157 | /* void (CONTINUE_IF_...) (struct prefix *addr); */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 158 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 159 | #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; \ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 167 | } |
| 168 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 169 | #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; \ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 177 | } |
| 178 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 179 | #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 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 188 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 189 | #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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 210 | /* Function Prototypes */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 211 | char *ospf6_lstype_name (u_int16_t type); |
| 212 | int ospf6_lsa_is_differ (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2); |
| 213 | int ospf6_lsa_is_changed (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2); |
| 214 | u_int16_t ospf6_lsa_age_current (struct ospf6_lsa *); |
| 215 | void ospf6_lsa_age_update_to_send (struct ospf6_lsa *, u_int32_t); |
| 216 | void ospf6_lsa_premature_aging (struct ospf6_lsa *); |
| 217 | int ospf6_lsa_compare (struct ospf6_lsa *, struct ospf6_lsa *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 218 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 219 | char *ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size); |
| 220 | void ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header); |
| 221 | void ospf6_lsa_header_print (struct ospf6_lsa *lsa); |
| 222 | void ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa); |
| 223 | void ospf6_lsa_show_summary_header (struct vty *vty); |
| 224 | void ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa); |
| 225 | void ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa); |
| 226 | void ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 227 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 228 | struct ospf6_lsa *ospf6_lsa_create (struct ospf6_lsa_header *header); |
| 229 | struct ospf6_lsa *ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header); |
| 230 | void ospf6_lsa_delete (struct ospf6_lsa *lsa); |
| 231 | struct ospf6_lsa *ospf6_lsa_copy (struct ospf6_lsa *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 232 | |
| 233 | void ospf6_lsa_lock (struct ospf6_lsa *); |
| 234 | void ospf6_lsa_unlock (struct ospf6_lsa *); |
| 235 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 236 | void ospf6_lsa_originate (struct ospf6_lsa *); |
| 237 | void ospf6_lsa_re_originate (struct ospf6_lsa *lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 238 | int ospf6_lsa_expire (struct thread *); |
| 239 | int ospf6_lsa_refresh (struct thread *); |
| 240 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 241 | unsigned short ospf6_lsa_checksum (struct ospf6_lsa_header *); |
| 242 | int ospf6_lsa_prohibited_duration (u_int16_t type, u_int32_t id, |
| 243 | u_int32_t adv_router, void *scope); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 244 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 245 | void ospf6_lsa_init (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 246 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 247 | int config_write_ospf6_debug_lsa (struct vty *vty); |
| 248 | void install_element_ospf6_debug_lsa (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 249 | |
| 250 | #endif /* OSPF6_LSA_H */ |
| 251 | |