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 */ |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 65 | #define OSPF6_SCOPE_LINKLOCAL 0x0000 |
| 66 | #define OSPF6_SCOPE_AREA 0x2000 |
| 67 | #define OSPF6_SCOPE_AS 0x4000 |
| 68 | #define OSPF6_SCOPE_RESERVED 0x6000 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 69 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 70 | /* XXX U-bit handling should be treated here */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 71 | #define OSPF6_LSA_SCOPE(type) \ |
| 72 | (ntohs (type) & OSPF6_LSTYPE_SCOPE_MASK) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 73 | |
| 74 | /* LSA Header */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 75 | struct ospf6_lsa_header |
| 76 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 77 | u_int16_t age; /* LS age */ |
| 78 | u_int16_t type; /* LS type */ |
| 79 | u_int32_t id; /* Link State ID */ |
| 80 | u_int32_t adv_router; /* Advertising Router */ |
| 81 | u_int32_t seqnum; /* LS sequence number */ |
| 82 | u_int16_t checksum; /* LS checksum */ |
| 83 | u_int16_t length; /* LSA length */ |
| 84 | }; |
| 85 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 86 | #define OSPF6_LSA_HEADER_END(h) \ |
| 87 | ((caddr_t)(h) + sizeof (struct ospf6_lsa_header)) |
| 88 | #define OSPF6_LSA_SIZE(h) \ |
| 89 | (ntohs (((struct ospf6_lsa_header *) (h))->length)) |
| 90 | #define OSPF6_LSA_END(h) \ |
| 91 | ((caddr_t)(h) + ntohs (((struct ospf6_lsa_header *) (h))->length)) |
| 92 | #define OSPF6_LSA_IS_TYPE(t, L) \ |
| 93 | ((L)->header->type == htons (OSPF6_LSTYPE_ ## t) ? 1 : 0) |
| 94 | #define OSPF6_LSA_IS_SAME(L1, L2) \ |
| 95 | ((L1)->header->adv_router == (L2)->header->adv_router && \ |
| 96 | (L1)->header->id == (L2)->header->id && \ |
| 97 | (L1)->header->type == (L2)->header->type) |
| 98 | #define OSPF6_LSA_IS_MATCH(t, i, a, L) \ |
| 99 | ((L)->header->adv_router == (a) && (L)->header->id == (i) && \ |
| 100 | (L)->header->type == (t)) |
| 101 | #define OSPF6_LSA_IS_DIFFER(L1, L2) ospf6_lsa_is_differ (L1, L2) |
| 102 | #define OSPF6_LSA_IS_MAXAGE(L) (ospf6_lsa_age_current (L) == MAXAGE) |
| 103 | #define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 104 | |
| 105 | struct ospf6_lsa |
| 106 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 107 | char name[64]; /* dump string */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 108 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 109 | struct ospf6_lsa *prev; |
| 110 | struct ospf6_lsa *next; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 111 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 112 | unsigned char lock; /* reference counter */ |
| 113 | unsigned char flag; /* special meaning (e.g. floodback) */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 114 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 115 | struct timeval birth; /* tv_sec when LS age 0 */ |
| 116 | struct timeval installed; /* used by MinLSArrival check */ |
| 117 | struct timeval originated; /* used by MinLSInterval check */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 118 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 119 | struct thread *expire; |
| 120 | struct thread *refresh; /* For self-originated LSA */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 121 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 122 | int retrans_count; |
| 123 | |
| 124 | struct ospf6_lsdb; |
| 125 | struct ospf6_lsdb *lsdb; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 126 | |
| 127 | /* lsa instance */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 128 | struct ospf6_lsa_header *header; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 131 | #define OSPF6_LSA_HEADERONLY 0x01 |
| 132 | #define OSPF6_LSA_FLOODBACK 0x02 |
| 133 | #define OSPF6_LSA_DUPLICATE 0x04 |
| 134 | #define OSPF6_LSA_IMPLIEDACK 0x08 |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 135 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 136 | struct ospf6_lsa_handler |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 137 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 138 | u_int16_t type; /* network byte order */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 139 | char *name; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 140 | int (*show) (struct vty *, struct ospf6_lsa *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 143 | #define OSPF6_LSTYPE_INDEX(type) \ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 144 | ((ntohs (type) & OSPF6_LSTYPE_FCODE_MASK) < OSPF6_LSTYPE_SIZE ? \ |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 145 | (ntohs (type) & OSPF6_LSTYPE_FCODE_MASK) : OSPF6_LSTYPE_UNKNOWN) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 146 | #define OSPF6_LSTYPE_NAME(type) (ospf6_lstype_name (type)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 147 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 148 | /* Macro for LSA Origination */ |
| 149 | /* void (CONTINUE_IF_...) (struct prefix *addr); */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 150 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 151 | #define CONTINUE_IF_ADDRESS_LINKLOCAL(addr)\ |
| 152 | if (IN6_IS_ADDR_LINKLOCAL (&(addr)->u.prefix6)) \ |
| 153 | { \ |
| 154 | char buf[64]; \ |
| 155 | prefix2str (addr, buf, sizeof (buf)); \ |
| 156 | if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) \ |
| 157 | zlog_info ("Filter out Linklocal: %s", buf); \ |
| 158 | continue; \ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 159 | } |
| 160 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 161 | #define CONTINUE_IF_ADDRESS_UNSPECIFIED(addr) \ |
| 162 | if (IN6_IS_ADDR_UNSPECIFIED (&(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 Unspecified: %s", buf); \ |
| 168 | continue; \ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 169 | } |
| 170 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 171 | #define CONTINUE_IF_ADDRESS_LOOPBACK(addr) \ |
| 172 | if (IN6_IS_ADDR_LOOPBACK (&(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 Loopback: %s", buf); \ |
| 178 | continue; \ |
| 179 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 180 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 181 | #define CONTINUE_IF_ADDRESS_V4COMPAT(addr) \ |
| 182 | if (IN6_IS_ADDR_V4COMPAT (&(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 V4Compat: %s", buf); \ |
| 188 | continue; \ |
| 189 | } |
| 190 | |
| 191 | #define CONTINUE_IF_ADDRESS_V4MAPPED(addr) \ |
| 192 | if (IN6_IS_ADDR_V4MAPPED (&(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 V4Mapped: %s", buf); \ |
| 198 | continue; \ |
| 199 | } |
| 200 | |
| 201 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 202 | /* Function Prototypes */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 203 | char *ospf6_lstype_name (u_int16_t type); |
| 204 | int ospf6_lsa_is_differ (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2); |
| 205 | int ospf6_lsa_is_changed (struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2); |
| 206 | u_int16_t ospf6_lsa_age_current (struct ospf6_lsa *); |
| 207 | void ospf6_lsa_age_update_to_send (struct ospf6_lsa *, u_int32_t); |
| 208 | void ospf6_lsa_premature_aging (struct ospf6_lsa *); |
| 209 | int ospf6_lsa_compare (struct ospf6_lsa *, struct ospf6_lsa *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 210 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 211 | char *ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size); |
| 212 | void ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header); |
| 213 | void ospf6_lsa_header_print (struct ospf6_lsa *lsa); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 214 | void ospf6_lsa_show_summary_header (struct vty *vty); |
| 215 | void ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa); |
| 216 | void ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa); |
| 217 | void ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 218 | void ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 219 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 220 | struct ospf6_lsa *ospf6_lsa_create (struct ospf6_lsa_header *header); |
| 221 | struct ospf6_lsa *ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header); |
| 222 | void ospf6_lsa_delete (struct ospf6_lsa *lsa); |
| 223 | struct ospf6_lsa *ospf6_lsa_copy (struct ospf6_lsa *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 224 | |
| 225 | void ospf6_lsa_lock (struct ospf6_lsa *); |
| 226 | void ospf6_lsa_unlock (struct ospf6_lsa *); |
| 227 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 228 | int ospf6_lsa_expire (struct thread *); |
| 229 | int ospf6_lsa_refresh (struct thread *); |
| 230 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 231 | unsigned short ospf6_lsa_checksum (struct ospf6_lsa_header *); |
| 232 | int ospf6_lsa_prohibited_duration (u_int16_t type, u_int32_t id, |
| 233 | u_int32_t adv_router, void *scope); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 234 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 235 | void ospf6_install_lsa_handler (struct ospf6_lsa_handler *handler); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 236 | void ospf6_lsa_init (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 237 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 238 | int config_write_ospf6_debug_lsa (struct vty *vty); |
| 239 | void install_element_ospf6_debug_lsa (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 240 | |
| 241 | #endif /* OSPF6_LSA_H */ |
| 242 | |