paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* OSPFv2 SNMP support |
vincent | ba68253 | 2005-09-29 13:52:57 +0000 | [diff] [blame] | 2 | * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com> |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3 | * Copyright (C) 2000 IP Infusion Inc. |
| 4 | * |
| 5 | * Written by Kunihiro Ishiguro <kunihiro@zebra.org> |
| 6 | * |
| 7 | * This file is part of GNU Zebra. |
| 8 | * |
| 9 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2, or (at your option) any |
| 12 | * later version. |
| 13 | * |
| 14 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 21 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 22 | * 02111-1307, USA. |
| 23 | */ |
| 24 | |
| 25 | #include <zebra.h> |
| 26 | |
| 27 | #ifdef HAVE_SNMP |
paul | 07661cb | 2003-03-18 00:03:05 +0000 | [diff] [blame] | 28 | #ifdef HAVE_NETSNMP |
| 29 | #include <net-snmp/net-snmp-config.h> |
| 30 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 31 | #include <asn1.h> |
| 32 | #include <snmp.h> |
| 33 | #include <snmp_impl.h> |
| 34 | |
| 35 | #include "if.h" |
| 36 | #include "log.h" |
| 37 | #include "prefix.h" |
| 38 | #include "table.h" |
| 39 | #include "command.h" |
| 40 | #include "memory.h" |
| 41 | #include "smux.h" |
| 42 | |
| 43 | #include "ospfd/ospfd.h" |
| 44 | #include "ospfd/ospf_interface.h" |
| 45 | #include "ospfd/ospf_asbr.h" |
| 46 | #include "ospfd/ospf_lsa.h" |
| 47 | #include "ospfd/ospf_lsdb.h" |
| 48 | #include "ospfd/ospf_abr.h" |
| 49 | #include "ospfd/ospf_neighbor.h" |
| 50 | #include "ospfd/ospf_nsm.h" |
| 51 | #include "ospfd/ospf_flood.h" |
vincent | e621787 | 2005-09-29 13:56:14 +0000 | [diff] [blame^] | 52 | #include "ospfd/ospf_ism.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 53 | |
| 54 | /* OSPF2-MIB. */ |
| 55 | #define OSPF2MIB 1,3,6,1,2,1,14 |
| 56 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 57 | /* OSPF MIB General Group values. */ |
| 58 | #define OSPFROUTERID 1 |
| 59 | #define OSPFADMINSTAT 2 |
| 60 | #define OSPFVERSIONNUMBER 3 |
| 61 | #define OSPFAREABDRRTRSTATUS 4 |
| 62 | #define OSPFASBDRRTRSTATUS 5 |
| 63 | #define OSPFEXTERNLSACOUNT 6 |
| 64 | #define OSPFEXTERNLSACKSUMSUM 7 |
| 65 | #define OSPFTOSSUPPORT 8 |
| 66 | #define OSPFORIGINATENEWLSAS 9 |
| 67 | #define OSPFRXNEWLSAS 10 |
| 68 | #define OSPFEXTLSDBLIMIT 11 |
| 69 | #define OSPFMULTICASTEXTENSIONS 12 |
| 70 | #define OSPFEXITOVERFLOWINTERVAL 13 |
| 71 | #define OSPFDEMANDEXTENSIONS 14 |
| 72 | |
| 73 | /* OSPF MIB ospfAreaTable. */ |
| 74 | #define OSPFAREAID 1 |
| 75 | #define OSPFAUTHTYPE 2 |
| 76 | #define OSPFIMPORTASEXTERN 3 |
| 77 | #define OSPFSPFRUNS 4 |
| 78 | #define OSPFAREABDRRTRCOUNT 5 |
| 79 | #define OSPFASBDRRTRCOUNT 6 |
| 80 | #define OSPFAREALSACOUNT 7 |
| 81 | #define OSPFAREALSACKSUMSUM 8 |
| 82 | #define OSPFAREASUMMARY 9 |
| 83 | #define OSPFAREASTATUS 10 |
| 84 | |
| 85 | /* OSPF MIB ospfStubAreaTable. */ |
| 86 | #define OSPFSTUBAREAID 1 |
| 87 | #define OSPFSTUBTOS 2 |
| 88 | #define OSPFSTUBMETRIC 3 |
| 89 | #define OSPFSTUBSTATUS 4 |
| 90 | #define OSPFSTUBMETRICTYPE 5 |
| 91 | |
| 92 | /* OSPF MIB ospfLsdbTable. */ |
| 93 | #define OSPFLSDBAREAID 1 |
| 94 | #define OSPFLSDBTYPE 2 |
| 95 | #define OSPFLSDBLSID 3 |
| 96 | #define OSPFLSDBROUTERID 4 |
| 97 | #define OSPFLSDBSEQUENCE 5 |
| 98 | #define OSPFLSDBAGE 6 |
| 99 | #define OSPFLSDBCHECKSUM 7 |
| 100 | #define OSPFLSDBADVERTISEMENT 8 |
| 101 | |
| 102 | /* OSPF MIB ospfAreaRangeTable. */ |
| 103 | #define OSPFAREARANGEAREAID 1 |
| 104 | #define OSPFAREARANGENET 2 |
| 105 | #define OSPFAREARANGEMASK 3 |
| 106 | #define OSPFAREARANGESTATUS 4 |
| 107 | #define OSPFAREARANGEEFFECT 5 |
| 108 | |
| 109 | /* OSPF MIB ospfHostTable. */ |
| 110 | #define OSPFHOSTIPADDRESS 1 |
| 111 | #define OSPFHOSTTOS 2 |
| 112 | #define OSPFHOSTMETRIC 3 |
| 113 | #define OSPFHOSTSTATUS 4 |
| 114 | #define OSPFHOSTAREAID 5 |
| 115 | |
| 116 | /* OSPF MIB ospfIfTable. */ |
| 117 | #define OSPFIFIPADDRESS 1 |
| 118 | #define OSPFADDRESSLESSIF 2 |
| 119 | #define OSPFIFAREAID 3 |
| 120 | #define OSPFIFTYPE 4 |
| 121 | #define OSPFIFADMINSTAT 5 |
| 122 | #define OSPFIFRTRPRIORITY 6 |
| 123 | #define OSPFIFTRANSITDELAY 7 |
| 124 | #define OSPFIFRETRANSINTERVAL 8 |
| 125 | #define OSPFIFHELLOINTERVAL 9 |
| 126 | #define OSPFIFRTRDEADINTERVAL 10 |
| 127 | #define OSPFIFPOLLINTERVAL 11 |
| 128 | #define OSPFIFSTATE 12 |
| 129 | #define OSPFIFDESIGNATEDROUTER 13 |
| 130 | #define OSPFIFBACKUPDESIGNATEDROUTER 14 |
| 131 | #define OSPFIFEVENTS 15 |
| 132 | #define OSPFIFAUTHKEY 16 |
| 133 | #define OSPFIFSTATUS 17 |
| 134 | #define OSPFIFMULTICASTFORWARDING 18 |
| 135 | #define OSPFIFDEMAND 19 |
| 136 | #define OSPFIFAUTHTYPE 20 |
| 137 | |
| 138 | /* OSPF MIB ospfIfMetricTable. */ |
| 139 | #define OSPFIFMETRICIPADDRESS 1 |
| 140 | #define OSPFIFMETRICADDRESSLESSIF 2 |
| 141 | #define OSPFIFMETRICTOS 3 |
| 142 | #define OSPFIFMETRICVALUE 4 |
| 143 | #define OSPFIFMETRICSTATUS 5 |
| 144 | |
| 145 | /* OSPF MIB ospfVirtIfTable. */ |
| 146 | #define OSPFVIRTIFAREAID 1 |
| 147 | #define OSPFVIRTIFNEIGHBOR 2 |
| 148 | #define OSPFVIRTIFTRANSITDELAY 3 |
| 149 | #define OSPFVIRTIFRETRANSINTERVAL 4 |
| 150 | #define OSPFVIRTIFHELLOINTERVAL 5 |
| 151 | #define OSPFVIRTIFRTRDEADINTERVAL 6 |
| 152 | #define OSPFVIRTIFSTATE 7 |
| 153 | #define OSPFVIRTIFEVENTS 8 |
| 154 | #define OSPFVIRTIFAUTHKEY 9 |
| 155 | #define OSPFVIRTIFSTATUS 10 |
| 156 | #define OSPFVIRTIFAUTHTYPE 11 |
| 157 | |
| 158 | /* OSPF MIB ospfNbrTable. */ |
| 159 | #define OSPFNBRIPADDR 1 |
| 160 | #define OSPFNBRADDRESSLESSINDEX 2 |
| 161 | #define OSPFNBRRTRID 3 |
| 162 | #define OSPFNBROPTIONS 4 |
| 163 | #define OSPFNBRPRIORITY 5 |
| 164 | #define OSPFNBRSTATE 6 |
| 165 | #define OSPFNBREVENTS 7 |
| 166 | #define OSPFNBRLSRETRANSQLEN 8 |
| 167 | #define OSPFNBMANBRSTATUS 9 |
| 168 | #define OSPFNBMANBRPERMANENCE 10 |
| 169 | #define OSPFNBRHELLOSUPPRESSED 11 |
| 170 | |
| 171 | /* OSPF MIB ospfVirtNbrTable. */ |
| 172 | #define OSPFVIRTNBRAREA 1 |
| 173 | #define OSPFVIRTNBRRTRID 2 |
| 174 | #define OSPFVIRTNBRIPADDR 3 |
| 175 | #define OSPFVIRTNBROPTIONS 4 |
| 176 | #define OSPFVIRTNBRSTATE 5 |
| 177 | #define OSPFVIRTNBREVENTS 6 |
| 178 | #define OSPFVIRTNBRLSRETRANSQLEN 7 |
| 179 | #define OSPFVIRTNBRHELLOSUPPRESSED 8 |
| 180 | |
| 181 | /* OSPF MIB ospfExtLsdbTable. */ |
| 182 | #define OSPFEXTLSDBTYPE 1 |
| 183 | #define OSPFEXTLSDBLSID 2 |
| 184 | #define OSPFEXTLSDBROUTERID 3 |
| 185 | #define OSPFEXTLSDBSEQUENCE 4 |
| 186 | #define OSPFEXTLSDBAGE 5 |
| 187 | #define OSPFEXTLSDBCHECKSUM 6 |
| 188 | #define OSPFEXTLSDBADVERTISEMENT 7 |
| 189 | |
| 190 | /* OSPF MIB ospfAreaAggregateTable. */ |
| 191 | #define OSPFAREAAGGREGATEAREAID 1 |
| 192 | #define OSPFAREAAGGREGATELSDBTYPE 2 |
| 193 | #define OSPFAREAAGGREGATENET 3 |
| 194 | #define OSPFAREAAGGREGATEMASK 4 |
| 195 | #define OSPFAREAAGGREGATESTATUS 5 |
| 196 | #define OSPFAREAAGGREGATEEFFECT 6 |
| 197 | |
| 198 | /* SYNTAX Status from OSPF-MIB. */ |
| 199 | #define OSPF_STATUS_ENABLED 1 |
| 200 | #define OSPF_STATUS_DISABLED 2 |
| 201 | |
| 202 | /* SNMP value hack. */ |
| 203 | #define COUNTER ASN_COUNTER |
| 204 | #define INTEGER ASN_INTEGER |
| 205 | #define GAUGE ASN_GAUGE |
| 206 | #define TIMETICKS ASN_TIMETICKS |
| 207 | #define IPADDRESS ASN_IPADDRESS |
| 208 | #define STRING ASN_OCTET_STR |
| 209 | |
| 210 | /* Declare static local variables for convenience. */ |
| 211 | SNMP_LOCAL_VARIABLES |
| 212 | |
| 213 | /* OSPF-MIB instances. */ |
| 214 | oid ospf_oid [] = { OSPF2MIB }; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 215 | |
| 216 | /* IP address 0.0.0.0. */ |
| 217 | static struct in_addr ospf_empty_addr = {0}; |
| 218 | |
| 219 | /* Hook functions. */ |
| 220 | static u_char *ospfGeneralGroup (); |
| 221 | static u_char *ospfAreaEntry (); |
| 222 | static u_char *ospfStubAreaEntry (); |
| 223 | static u_char *ospfLsdbEntry (); |
| 224 | static u_char *ospfAreaRangeEntry (); |
| 225 | static u_char *ospfHostEntry (); |
| 226 | static u_char *ospfIfEntry (); |
| 227 | static u_char *ospfIfMetricEntry (); |
| 228 | static u_char *ospfVirtIfEntry (); |
| 229 | static u_char *ospfNbrEntry (); |
| 230 | static u_char *ospfVirtNbrEntry (); |
| 231 | static u_char *ospfExtLsdbEntry (); |
| 232 | static u_char *ospfAreaAggregateEntry (); |
| 233 | |
| 234 | struct variable ospf_variables[] = |
| 235 | { |
| 236 | /* OSPF general variables */ |
| 237 | {OSPFROUTERID, IPADDRESS, RWRITE, ospfGeneralGroup, |
| 238 | 2, {1, 1}}, |
| 239 | {OSPFADMINSTAT, INTEGER, RWRITE, ospfGeneralGroup, |
| 240 | 2, {1, 2}}, |
| 241 | {OSPFVERSIONNUMBER, INTEGER, RONLY, ospfGeneralGroup, |
| 242 | 2, {1, 3}}, |
| 243 | {OSPFAREABDRRTRSTATUS, INTEGER, RONLY, ospfGeneralGroup, |
| 244 | 2, {1, 4}}, |
| 245 | {OSPFASBDRRTRSTATUS, INTEGER, RWRITE, ospfGeneralGroup, |
| 246 | 2, {1, 5}}, |
| 247 | {OSPFEXTERNLSACOUNT, GAUGE, RONLY, ospfGeneralGroup, |
| 248 | 2, {1, 6}}, |
| 249 | {OSPFEXTERNLSACKSUMSUM, INTEGER, RONLY, ospfGeneralGroup, |
| 250 | 2, {1, 7}}, |
| 251 | {OSPFTOSSUPPORT, INTEGER, RWRITE, ospfGeneralGroup, |
| 252 | 2, {1, 8}}, |
| 253 | {OSPFORIGINATENEWLSAS, COUNTER, RONLY, ospfGeneralGroup, |
| 254 | 2, {1, 9}}, |
| 255 | {OSPFRXNEWLSAS, COUNTER, RONLY, ospfGeneralGroup, |
| 256 | 2, {1, 10}}, |
| 257 | {OSPFEXTLSDBLIMIT, INTEGER, RWRITE, ospfGeneralGroup, |
| 258 | 2, {1, 11}}, |
| 259 | {OSPFMULTICASTEXTENSIONS, INTEGER, RWRITE, ospfGeneralGroup, |
| 260 | 2, {1, 12}}, |
| 261 | {OSPFEXITOVERFLOWINTERVAL, INTEGER, RWRITE, ospfGeneralGroup, |
| 262 | 2, {1, 13}}, |
| 263 | {OSPFDEMANDEXTENSIONS, INTEGER, RWRITE, ospfGeneralGroup, |
| 264 | 2, {1, 14}}, |
| 265 | |
| 266 | /* OSPF area data structure. */ |
| 267 | {OSPFAREAID, IPADDRESS, RONLY, ospfAreaEntry, |
| 268 | 3, {2, 1, 1}}, |
| 269 | {OSPFAUTHTYPE, INTEGER, RWRITE, ospfAreaEntry, |
| 270 | 3, {2, 1, 2}}, |
| 271 | {OSPFIMPORTASEXTERN, INTEGER, RWRITE, ospfAreaEntry, |
| 272 | 3, {2, 1, 3}}, |
| 273 | {OSPFSPFRUNS, COUNTER, RONLY, ospfAreaEntry, |
| 274 | 3, {2, 1, 4}}, |
| 275 | {OSPFAREABDRRTRCOUNT, GAUGE, RONLY, ospfAreaEntry, |
| 276 | 3, {2, 1, 5}}, |
| 277 | {OSPFASBDRRTRCOUNT, GAUGE, RONLY, ospfAreaEntry, |
| 278 | 3, {2, 1, 6}}, |
| 279 | {OSPFAREALSACOUNT, GAUGE, RONLY, ospfAreaEntry, |
| 280 | 3, {2, 1, 7}}, |
| 281 | {OSPFAREALSACKSUMSUM, INTEGER, RONLY, ospfAreaEntry, |
| 282 | 3, {2, 1, 8}}, |
| 283 | {OSPFAREASUMMARY, INTEGER, RWRITE, ospfAreaEntry, |
| 284 | 3, {2, 1, 9}}, |
| 285 | {OSPFAREASTATUS, INTEGER, RWRITE, ospfAreaEntry, |
| 286 | 3, {2, 1, 10}}, |
| 287 | |
| 288 | /* OSPF stub area information. */ |
| 289 | {OSPFSTUBAREAID, IPADDRESS, RONLY, ospfStubAreaEntry, |
| 290 | 3, {3, 1, 1}}, |
| 291 | {OSPFSTUBTOS, INTEGER, RONLY, ospfStubAreaEntry, |
| 292 | 3, {3, 1, 2}}, |
| 293 | {OSPFSTUBMETRIC, INTEGER, RWRITE, ospfStubAreaEntry, |
| 294 | 3, {3, 1, 3}}, |
| 295 | {OSPFSTUBSTATUS, INTEGER, RWRITE, ospfStubAreaEntry, |
| 296 | 3, {3, 1, 4}}, |
| 297 | {OSPFSTUBMETRICTYPE, INTEGER, RWRITE, ospfStubAreaEntry, |
| 298 | 3, {3, 1, 5}}, |
| 299 | |
| 300 | /* OSPF link state database. */ |
| 301 | {OSPFLSDBAREAID, IPADDRESS, RONLY, ospfLsdbEntry, |
| 302 | 3, {4, 1, 1}}, |
| 303 | {OSPFLSDBTYPE, INTEGER, RONLY, ospfLsdbEntry, |
| 304 | 3, {4, 1, 2}}, |
| 305 | {OSPFLSDBLSID, IPADDRESS, RONLY, ospfLsdbEntry, |
| 306 | 3, {4, 1, 3}}, |
| 307 | {OSPFLSDBROUTERID, IPADDRESS, RONLY, ospfLsdbEntry, |
| 308 | 3, {4, 1, 4}}, |
| 309 | {OSPFLSDBSEQUENCE, INTEGER, RONLY, ospfLsdbEntry, |
| 310 | 3, {4, 1, 5}}, |
| 311 | {OSPFLSDBAGE, INTEGER, RONLY, ospfLsdbEntry, |
| 312 | 3, {4, 1, 6}}, |
| 313 | {OSPFLSDBCHECKSUM, INTEGER, RONLY, ospfLsdbEntry, |
| 314 | 3, {4, 1, 7}}, |
| 315 | {OSPFLSDBADVERTISEMENT, STRING, RONLY, ospfLsdbEntry, |
| 316 | 3, {4, 1, 8}}, |
| 317 | |
| 318 | /* Area range table. */ |
| 319 | {OSPFAREARANGEAREAID, IPADDRESS, RONLY, ospfAreaRangeEntry, |
| 320 | 3, {5, 1, 1}}, |
| 321 | {OSPFAREARANGENET, IPADDRESS, RONLY, ospfAreaRangeEntry, |
| 322 | 3, {5, 1, 2}}, |
| 323 | {OSPFAREARANGEMASK, IPADDRESS, RWRITE, ospfAreaRangeEntry, |
| 324 | 3, {5, 1, 3}}, |
| 325 | {OSPFAREARANGESTATUS, INTEGER, RWRITE, ospfAreaRangeEntry, |
| 326 | 3, {5, 1, 4}}, |
| 327 | {OSPFAREARANGEEFFECT, INTEGER, RWRITE, ospfAreaRangeEntry, |
| 328 | 3, {5, 1, 5}}, |
| 329 | |
| 330 | /* OSPF host table. */ |
| 331 | {OSPFHOSTIPADDRESS, IPADDRESS, RONLY, ospfHostEntry, |
| 332 | 3, {6, 1, 1}}, |
| 333 | {OSPFHOSTTOS, INTEGER, RONLY, ospfHostEntry, |
| 334 | 3, {6, 1, 2}}, |
| 335 | {OSPFHOSTMETRIC, INTEGER, RWRITE, ospfHostEntry, |
| 336 | 3, {6, 1, 3}}, |
| 337 | {OSPFHOSTSTATUS, INTEGER, RWRITE, ospfHostEntry, |
| 338 | 3, {6, 1, 4}}, |
| 339 | {OSPFHOSTAREAID, IPADDRESS, RONLY, ospfHostEntry, |
| 340 | 3, {6, 1, 5}}, |
| 341 | |
| 342 | /* OSPF interface table. */ |
| 343 | {OSPFIFIPADDRESS, IPADDRESS, RONLY, ospfIfEntry, |
| 344 | 3, {7, 1, 1}}, |
| 345 | {OSPFADDRESSLESSIF, INTEGER, RONLY, ospfIfEntry, |
| 346 | 3, {7, 1, 2}}, |
| 347 | {OSPFIFAREAID, IPADDRESS, RWRITE, ospfIfEntry, |
| 348 | 3, {7, 1, 3}}, |
| 349 | {OSPFIFTYPE, INTEGER, RWRITE, ospfIfEntry, |
| 350 | 3, {7, 1, 4}}, |
| 351 | {OSPFIFADMINSTAT, INTEGER, RWRITE, ospfIfEntry, |
| 352 | 3, {7, 1, 5}}, |
| 353 | {OSPFIFRTRPRIORITY, INTEGER, RWRITE, ospfIfEntry, |
| 354 | 3, {7, 1, 6}}, |
| 355 | {OSPFIFTRANSITDELAY, INTEGER, RWRITE, ospfIfEntry, |
| 356 | 3, {7, 1, 7}}, |
| 357 | {OSPFIFRETRANSINTERVAL, INTEGER, RWRITE, ospfIfEntry, |
| 358 | 3, {7, 1, 8}}, |
| 359 | {OSPFIFHELLOINTERVAL, INTEGER, RWRITE, ospfIfEntry, |
| 360 | 3, {7, 1, 9}}, |
| 361 | {OSPFIFRTRDEADINTERVAL, INTEGER, RWRITE, ospfIfEntry, |
| 362 | 3, {7, 1, 10}}, |
| 363 | {OSPFIFPOLLINTERVAL, INTEGER, RWRITE, ospfIfEntry, |
| 364 | 3, {7, 1, 11}}, |
| 365 | {OSPFIFSTATE, INTEGER, RONLY, ospfIfEntry, |
| 366 | 3, {7, 1, 12}}, |
| 367 | {OSPFIFDESIGNATEDROUTER, IPADDRESS, RONLY, ospfIfEntry, |
| 368 | 3, {7, 1, 13}}, |
| 369 | {OSPFIFBACKUPDESIGNATEDROUTER, IPADDRESS, RONLY, ospfIfEntry, |
| 370 | 3, {7, 1, 14}}, |
| 371 | {OSPFIFEVENTS, COUNTER, RONLY, ospfIfEntry, |
| 372 | 3, {7, 1, 15}}, |
| 373 | {OSPFIFAUTHKEY, STRING, RWRITE, ospfIfEntry, |
| 374 | 3, {7, 1, 16}}, |
| 375 | {OSPFIFSTATUS, INTEGER, RWRITE, ospfIfEntry, |
| 376 | 3, {7, 1, 17}}, |
| 377 | {OSPFIFMULTICASTFORWARDING, INTEGER, RWRITE, ospfIfEntry, |
| 378 | 3, {7, 1, 18}}, |
| 379 | {OSPFIFDEMAND, INTEGER, RWRITE, ospfIfEntry, |
| 380 | 3, {7, 1, 19}}, |
| 381 | {OSPFIFAUTHTYPE, INTEGER, RWRITE, ospfIfEntry, |
| 382 | 3, {7, 1, 20}}, |
| 383 | |
| 384 | /* OSPF interface metric table. */ |
| 385 | {OSPFIFMETRICIPADDRESS, IPADDRESS, RONLY, ospfIfMetricEntry, |
| 386 | 3, {8, 1, 1}}, |
| 387 | {OSPFIFMETRICADDRESSLESSIF, INTEGER, RONLY, ospfIfMetricEntry, |
| 388 | 3, {8, 1, 2}}, |
| 389 | {OSPFIFMETRICTOS, INTEGER, RONLY, ospfIfMetricEntry, |
| 390 | 3, {8, 1, 3}}, |
| 391 | {OSPFIFMETRICVALUE, INTEGER, RWRITE, ospfIfMetricEntry, |
| 392 | 3, {8, 1, 4}}, |
| 393 | {OSPFIFMETRICSTATUS, INTEGER, RWRITE, ospfIfMetricEntry, |
| 394 | 3, {8, 1, 5}}, |
| 395 | |
| 396 | /* OSPF virtual interface table. */ |
| 397 | {OSPFVIRTIFAREAID, IPADDRESS, RONLY, ospfVirtIfEntry, |
| 398 | 3, {9, 1, 1}}, |
| 399 | {OSPFVIRTIFNEIGHBOR, IPADDRESS, RONLY, ospfVirtIfEntry, |
| 400 | 3, {9, 1, 2}}, |
| 401 | {OSPFVIRTIFTRANSITDELAY, INTEGER, RWRITE, ospfVirtIfEntry, |
| 402 | 3, {9, 1, 3}}, |
| 403 | {OSPFVIRTIFRETRANSINTERVAL, INTEGER, RWRITE, ospfVirtIfEntry, |
| 404 | 3, {9, 1, 4}}, |
| 405 | {OSPFVIRTIFHELLOINTERVAL, INTEGER, RWRITE, ospfVirtIfEntry, |
| 406 | 3, {9, 1, 5}}, |
| 407 | {OSPFVIRTIFRTRDEADINTERVAL, INTEGER, RWRITE, ospfVirtIfEntry, |
| 408 | 3, {9, 1, 6}}, |
| 409 | {OSPFVIRTIFSTATE, INTEGER, RONLY, ospfVirtIfEntry, |
| 410 | 3, {9, 1, 7}}, |
| 411 | {OSPFVIRTIFEVENTS, COUNTER, RONLY, ospfVirtIfEntry, |
| 412 | 3, {9, 1, 8}}, |
| 413 | {OSPFVIRTIFAUTHKEY, STRING, RWRITE, ospfVirtIfEntry, |
| 414 | 3, {9, 1, 9}}, |
| 415 | {OSPFVIRTIFSTATUS, INTEGER, RWRITE, ospfVirtIfEntry, |
| 416 | 3, {9, 1, 10}}, |
| 417 | {OSPFVIRTIFAUTHTYPE, INTEGER, RWRITE, ospfVirtIfEntry, |
| 418 | 3, {9, 1, 11}}, |
| 419 | |
| 420 | /* OSPF neighbor table. */ |
| 421 | {OSPFNBRIPADDR, IPADDRESS, RONLY, ospfNbrEntry, |
| 422 | 3, {10, 1, 1}}, |
| 423 | {OSPFNBRADDRESSLESSINDEX, INTEGER, RONLY, ospfNbrEntry, |
| 424 | 3, {10, 1, 2}}, |
| 425 | {OSPFNBRRTRID, IPADDRESS, RONLY, ospfNbrEntry, |
| 426 | 3, {10, 1, 3}}, |
| 427 | {OSPFNBROPTIONS, INTEGER, RONLY, ospfNbrEntry, |
| 428 | 3, {10, 1, 4}}, |
| 429 | {OSPFNBRPRIORITY, INTEGER, RWRITE, ospfNbrEntry, |
| 430 | 3, {10, 1, 5}}, |
| 431 | {OSPFNBRSTATE, INTEGER, RONLY, ospfNbrEntry, |
| 432 | 3, {10, 1, 6}}, |
| 433 | {OSPFNBREVENTS, COUNTER, RONLY, ospfNbrEntry, |
| 434 | 3, {10, 1, 7}}, |
| 435 | {OSPFNBRLSRETRANSQLEN, GAUGE, RONLY, ospfNbrEntry, |
| 436 | 3, {10, 1, 8}}, |
| 437 | {OSPFNBMANBRSTATUS, INTEGER, RWRITE, ospfNbrEntry, |
| 438 | 3, {10, 1, 9}}, |
| 439 | {OSPFNBMANBRPERMANENCE, INTEGER, RONLY, ospfNbrEntry, |
| 440 | 3, {10, 1, 10}}, |
| 441 | {OSPFNBRHELLOSUPPRESSED, INTEGER, RONLY, ospfNbrEntry, |
| 442 | 3, {10, 1, 11}}, |
| 443 | |
| 444 | /* OSPF virtual neighbor table. */ |
| 445 | {OSPFVIRTNBRAREA, IPADDRESS, RONLY, ospfVirtNbrEntry, |
| 446 | 3, {11, 1, 1}}, |
| 447 | {OSPFVIRTNBRRTRID, IPADDRESS, RONLY, ospfVirtNbrEntry, |
| 448 | 3, {11, 1, 2}}, |
| 449 | {OSPFVIRTNBRIPADDR, IPADDRESS, RONLY, ospfVirtNbrEntry, |
| 450 | 3, {11, 1, 3}}, |
| 451 | {OSPFVIRTNBROPTIONS, INTEGER, RONLY, ospfVirtNbrEntry, |
| 452 | 3, {11, 1, 4}}, |
| 453 | {OSPFVIRTNBRSTATE, INTEGER, RONLY, ospfVirtNbrEntry, |
| 454 | 3, {11, 1, 5}}, |
| 455 | {OSPFVIRTNBREVENTS, COUNTER, RONLY, ospfVirtNbrEntry, |
| 456 | 3, {11, 1, 6}}, |
| 457 | {OSPFVIRTNBRLSRETRANSQLEN, INTEGER, RONLY, ospfVirtNbrEntry, |
| 458 | 3, {11, 1, 7}}, |
| 459 | {OSPFVIRTNBRHELLOSUPPRESSED, INTEGER, RONLY, ospfVirtNbrEntry, |
| 460 | 3, {11, 1, 8}}, |
| 461 | |
| 462 | /* OSPF link state database, external. */ |
| 463 | {OSPFEXTLSDBTYPE, INTEGER, RONLY, ospfExtLsdbEntry, |
| 464 | 3, {12, 1, 1}}, |
| 465 | {OSPFEXTLSDBLSID, IPADDRESS, RONLY, ospfExtLsdbEntry, |
| 466 | 3, {12, 1, 2}}, |
| 467 | {OSPFEXTLSDBROUTERID, IPADDRESS, RONLY, ospfExtLsdbEntry, |
| 468 | 3, {12, 1, 3}}, |
| 469 | {OSPFEXTLSDBSEQUENCE, INTEGER, RONLY, ospfExtLsdbEntry, |
| 470 | 3, {12, 1, 4}}, |
| 471 | {OSPFEXTLSDBAGE, INTEGER, RONLY, ospfExtLsdbEntry, |
| 472 | 3, {12, 1, 5}}, |
| 473 | {OSPFEXTLSDBCHECKSUM, INTEGER, RONLY, ospfExtLsdbEntry, |
| 474 | 3, {12, 1, 6}}, |
| 475 | {OSPFEXTLSDBADVERTISEMENT, STRING, RONLY, ospfExtLsdbEntry, |
| 476 | 3, {12, 1, 7}}, |
| 477 | |
| 478 | /* OSPF area aggregate table. */ |
| 479 | {OSPFAREAAGGREGATEAREAID, IPADDRESS, RONLY, ospfAreaAggregateEntry, |
| 480 | 3, {14, 1, 1}}, |
| 481 | {OSPFAREAAGGREGATELSDBTYPE, INTEGER, RONLY, ospfAreaAggregateEntry, |
| 482 | 3, {14, 1, 2}}, |
| 483 | {OSPFAREAAGGREGATENET, IPADDRESS, RONLY, ospfAreaAggregateEntry, |
| 484 | 3, {14, 1, 3}}, |
| 485 | {OSPFAREAAGGREGATEMASK, IPADDRESS, RONLY, ospfAreaAggregateEntry, |
| 486 | 3, {14, 1, 4}}, |
| 487 | {OSPFAREAAGGREGATESTATUS, INTEGER, RWRITE, ospfAreaAggregateEntry, |
| 488 | 3, {14, 1, 5}}, |
| 489 | {OSPFAREAAGGREGATEEFFECT, INTEGER, RWRITE, ospfAreaAggregateEntry, |
| 490 | 3, {14, 1, 6}} |
| 491 | }; |
| 492 | |
| 493 | /* The administrative status of OSPF. When OSPF is enbled on at least |
| 494 | one interface return 1. */ |
| 495 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 496 | ospf_admin_stat (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 497 | { |
paul | aa20c6f | 2004-10-07 14:19:36 +0000 | [diff] [blame] | 498 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 499 | struct ospf_interface *oi; |
| 500 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 501 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 502 | return 0; |
| 503 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 504 | for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) |
| 505 | if (oi && oi->address) |
| 506 | return 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 507 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | static u_char * |
| 512 | ospfGeneralGroup (struct variable *v, oid *name, size_t *length, |
| 513 | int exact, size_t *var_len, WriteMethod **write_method) |
| 514 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 515 | struct ospf *ospf; |
| 516 | |
| 517 | ospf = ospf_lookup (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 518 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 519 | /* Check whether the instance identifier is valid */ |
| 520 | if (smux_header_generic (v, name, length, exact, var_len, write_method) |
| 521 | == MATCH_FAILED) |
| 522 | return NULL; |
| 523 | |
| 524 | /* Return the current value of the variable */ |
| 525 | switch (v->magic) |
| 526 | { |
| 527 | case OSPFROUTERID: /* 1 */ |
| 528 | /* Router-ID of this OSPF instance. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 529 | if (ospf) |
| 530 | return SNMP_IPADDRESS (ospf->router_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 531 | else |
| 532 | return SNMP_IPADDRESS (ospf_empty_addr); |
| 533 | break; |
| 534 | case OSPFADMINSTAT: /* 2 */ |
| 535 | /* The administrative status of OSPF in the router. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 536 | if (ospf_admin_stat (ospf)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 537 | return SNMP_INTEGER (OSPF_STATUS_ENABLED); |
| 538 | else |
| 539 | return SNMP_INTEGER (OSPF_STATUS_DISABLED); |
| 540 | break; |
| 541 | case OSPFVERSIONNUMBER: /* 3 */ |
| 542 | /* OSPF version 2. */ |
| 543 | return SNMP_INTEGER (OSPF_VERSION); |
| 544 | break; |
| 545 | case OSPFAREABDRRTRSTATUS: /* 4 */ |
| 546 | /* Area Border router status. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 547 | if (ospf && CHECK_FLAG (ospf->flags, OSPF_FLAG_ABR)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 548 | return SNMP_INTEGER (SNMP_TRUE); |
| 549 | else |
| 550 | return SNMP_INTEGER (SNMP_FALSE); |
| 551 | break; |
| 552 | case OSPFASBDRRTRSTATUS: /* 5 */ |
| 553 | /* AS Border router status. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 554 | if (ospf && CHECK_FLAG (ospf->flags, OSPF_FLAG_ASBR)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 555 | return SNMP_INTEGER (SNMP_TRUE); |
| 556 | else |
| 557 | return SNMP_INTEGER (SNMP_FALSE); |
| 558 | break; |
| 559 | case OSPFEXTERNLSACOUNT: /* 6 */ |
| 560 | /* External LSA counts. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 561 | if (ospf) |
| 562 | return SNMP_INTEGER (ospf_lsdb_count_all (ospf->lsdb)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 563 | else |
| 564 | return SNMP_INTEGER (0); |
| 565 | break; |
| 566 | case OSPFEXTERNLSACKSUMSUM: /* 7 */ |
| 567 | /* External LSA checksum. */ |
| 568 | return SNMP_INTEGER (0); |
| 569 | break; |
| 570 | case OSPFTOSSUPPORT: /* 8 */ |
| 571 | /* TOS is not supported. */ |
| 572 | return SNMP_INTEGER (SNMP_FALSE); |
| 573 | break; |
| 574 | case OSPFORIGINATENEWLSAS: /* 9 */ |
| 575 | /* The number of new link-state advertisements. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 576 | if (ospf) |
| 577 | return SNMP_INTEGER (ospf->lsa_originate_count); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 578 | else |
| 579 | return SNMP_INTEGER (0); |
| 580 | break; |
| 581 | case OSPFRXNEWLSAS: /* 10 */ |
| 582 | /* The number of link-state advertisements received determined |
| 583 | to be new instantiations. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 584 | if (ospf) |
| 585 | return SNMP_INTEGER (ospf->rx_lsa_count); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 586 | else |
| 587 | return SNMP_INTEGER (0); |
| 588 | break; |
| 589 | case OSPFEXTLSDBLIMIT: /* 11 */ |
| 590 | /* There is no limit for the number of non-default |
| 591 | AS-external-LSAs. */ |
| 592 | return SNMP_INTEGER (-1); |
| 593 | break; |
| 594 | case OSPFMULTICASTEXTENSIONS: /* 12 */ |
| 595 | /* Multicast Extensions to OSPF is not supported. */ |
| 596 | return SNMP_INTEGER (0); |
| 597 | break; |
| 598 | case OSPFEXITOVERFLOWINTERVAL: /* 13 */ |
| 599 | /* Overflow is not supported. */ |
| 600 | return SNMP_INTEGER (0); |
| 601 | break; |
| 602 | case OSPFDEMANDEXTENSIONS: /* 14 */ |
| 603 | /* Demand routing is not supported. */ |
| 604 | return SNMP_INTEGER (SNMP_FALSE); |
| 605 | break; |
| 606 | default: |
| 607 | return NULL; |
| 608 | } |
| 609 | return NULL; |
| 610 | } |
| 611 | |
| 612 | struct ospf_area * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 613 | ospf_area_lookup_next (struct ospf *ospf, struct in_addr *area_id, int first) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 614 | { |
| 615 | struct ospf_area *area; |
paul | aa20c6f | 2004-10-07 14:19:36 +0000 | [diff] [blame] | 616 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 617 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 618 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 619 | return NULL; |
| 620 | |
| 621 | if (first) |
| 622 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 623 | node = listhead (ospf->areas); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 624 | if (node) |
| 625 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 626 | area = listgetdata (node); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 627 | *area_id = area->area_id; |
| 628 | return area; |
| 629 | } |
| 630 | return NULL; |
| 631 | } |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 632 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 633 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 634 | if (ntohl (area->area_id.s_addr) > ntohl (area_id->s_addr)) |
| 635 | { |
| 636 | *area_id = area->area_id; |
| 637 | return area; |
| 638 | } |
| 639 | } |
| 640 | return NULL; |
| 641 | } |
| 642 | |
| 643 | struct ospf_area * |
| 644 | ospfAreaLookup (struct variable *v, oid name[], size_t *length, |
| 645 | struct in_addr *addr, int exact) |
| 646 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 647 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 648 | struct ospf_area *area; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 649 | int len; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 650 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 651 | ospf = ospf_lookup (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 652 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 653 | return NULL; |
| 654 | |
| 655 | if (exact) |
| 656 | { |
| 657 | /* Length is insufficient to lookup OSPF area. */ |
| 658 | if (*length - v->namelen != sizeof (struct in_addr)) |
| 659 | return NULL; |
| 660 | |
| 661 | oid2in_addr (name + v->namelen, sizeof (struct in_addr), addr); |
| 662 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 663 | area = ospf_area_lookup_by_area_id (ospf, *addr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 664 | |
| 665 | return area; |
| 666 | } |
| 667 | else |
| 668 | { |
| 669 | len = *length - v->namelen; |
| 670 | if (len > 4) |
| 671 | len = 4; |
| 672 | |
| 673 | oid2in_addr (name + v->namelen, len, addr); |
| 674 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 675 | area = ospf_area_lookup_next (ospf, addr, len == 0 ? 1 : 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 676 | |
| 677 | if (area == NULL) |
| 678 | return NULL; |
| 679 | |
| 680 | oid_copy_addr (name + v->namelen, addr, sizeof (struct in_addr)); |
| 681 | *length = sizeof (struct in_addr) + v->namelen; |
| 682 | |
| 683 | return area; |
| 684 | } |
| 685 | return NULL; |
| 686 | } |
| 687 | |
| 688 | static u_char * |
| 689 | ospfAreaEntry (struct variable *v, oid *name, size_t *length, int exact, |
| 690 | size_t *var_len, WriteMethod **write_method) |
| 691 | { |
| 692 | struct ospf_area *area; |
| 693 | struct in_addr addr; |
| 694 | |
| 695 | memset (&addr, 0, sizeof (struct in_addr)); |
| 696 | |
| 697 | area = ospfAreaLookup (v, name, length, &addr, exact); |
| 698 | if (! area) |
| 699 | return NULL; |
| 700 | |
| 701 | /* Return the current value of the variable */ |
| 702 | switch (v->magic) |
| 703 | { |
| 704 | case OSPFAREAID: /* 1 */ |
| 705 | return SNMP_IPADDRESS (area->area_id); |
| 706 | break; |
| 707 | case OSPFAUTHTYPE: /* 2 */ |
| 708 | return SNMP_INTEGER (area->auth_type); |
| 709 | break; |
| 710 | case OSPFIMPORTASEXTERN: /* 3 */ |
| 711 | return SNMP_INTEGER (area->external_routing + 1); |
| 712 | break; |
| 713 | case OSPFSPFRUNS: /* 4 */ |
| 714 | return SNMP_INTEGER (area->spf_calculation); |
| 715 | break; |
| 716 | case OSPFAREABDRRTRCOUNT: /* 5 */ |
| 717 | return SNMP_INTEGER (area->abr_count); |
| 718 | break; |
| 719 | case OSPFASBDRRTRCOUNT: /* 6 */ |
| 720 | return SNMP_INTEGER (area->asbr_count); |
| 721 | break; |
| 722 | case OSPFAREALSACOUNT: /* 7 */ |
| 723 | return SNMP_INTEGER (area->lsdb->total); |
| 724 | break; |
| 725 | case OSPFAREALSACKSUMSUM: /* 8 */ |
| 726 | return SNMP_INTEGER (0); |
| 727 | break; |
| 728 | case OSPFAREASUMMARY: /* 9 */ |
| 729 | #define OSPF_noAreaSummary 1 |
| 730 | #define OSPF_sendAreaSummary 2 |
| 731 | if (area->no_summary) |
| 732 | return SNMP_INTEGER (OSPF_noAreaSummary); |
| 733 | else |
| 734 | return SNMP_INTEGER (OSPF_sendAreaSummary); |
| 735 | break; |
| 736 | case OSPFAREASTATUS: /* 10 */ |
| 737 | return SNMP_INTEGER (SNMP_VALID); |
| 738 | break; |
| 739 | default: |
| 740 | return NULL; |
| 741 | break; |
| 742 | } |
| 743 | return NULL; |
| 744 | } |
| 745 | |
| 746 | struct ospf_area * |
| 747 | ospf_stub_area_lookup_next (struct in_addr *area_id, int first) |
| 748 | { |
| 749 | struct ospf_area *area; |
paul | aa20c6f | 2004-10-07 14:19:36 +0000 | [diff] [blame] | 750 | struct listnode *node; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 751 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 752 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 753 | ospf = ospf_lookup (); |
| 754 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 755 | return NULL; |
| 756 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 757 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 758 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 759 | if (area->external_routing == OSPF_AREA_STUB) |
| 760 | { |
| 761 | if (first) |
| 762 | { |
| 763 | *area_id = area->area_id; |
| 764 | return area; |
| 765 | } |
| 766 | else if (ntohl (area->area_id.s_addr) > ntohl (area_id->s_addr)) |
| 767 | { |
| 768 | *area_id = area->area_id; |
| 769 | return area; |
| 770 | } |
| 771 | } |
| 772 | } |
| 773 | return NULL; |
| 774 | } |
| 775 | |
| 776 | struct ospf_area * |
| 777 | ospfStubAreaLookup (struct variable *v, oid name[], size_t *length, |
| 778 | struct in_addr *addr, int exact) |
| 779 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 780 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 781 | struct ospf_area *area; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 782 | int len; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 783 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 784 | ospf = ospf_lookup (); |
| 785 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 786 | return NULL; |
| 787 | |
| 788 | /* Exact lookup. */ |
| 789 | if (exact) |
| 790 | { |
| 791 | /* ospfStubAreaID + ospfStubTOS. */ |
| 792 | if (*length != v->namelen + sizeof (struct in_addr) + 1) |
| 793 | return NULL; |
| 794 | |
| 795 | /* Check ospfStubTOS is zero. */ |
| 796 | if (name[*length - 1] != 0) |
| 797 | return NULL; |
| 798 | |
| 799 | oid2in_addr (name + v->namelen, sizeof (struct in_addr), addr); |
| 800 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 801 | area = ospf_area_lookup_by_area_id (ospf, *addr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 802 | |
| 803 | if (area->external_routing == OSPF_AREA_STUB) |
| 804 | return area; |
| 805 | else |
| 806 | return NULL; |
| 807 | } |
| 808 | else |
| 809 | { |
| 810 | len = *length - v->namelen; |
| 811 | if (len > 4) |
| 812 | len = 4; |
| 813 | |
| 814 | oid2in_addr (name + v->namelen, len, addr); |
| 815 | |
| 816 | area = ospf_stub_area_lookup_next (addr, len == 0 ? 1 : 0); |
| 817 | |
| 818 | if (area == NULL) |
| 819 | return NULL; |
| 820 | |
| 821 | oid_copy_addr (name + v->namelen, addr, sizeof (struct in_addr)); |
| 822 | /* Set TOS 0. */ |
| 823 | name[v->namelen + sizeof (struct in_addr)] = 0; |
| 824 | *length = v->namelen + sizeof (struct in_addr) + 1; |
| 825 | |
| 826 | return area; |
| 827 | } |
| 828 | return NULL; |
| 829 | } |
| 830 | |
| 831 | static u_char * |
| 832 | ospfStubAreaEntry (struct variable *v, oid *name, size_t *length, |
| 833 | int exact, size_t *var_len, WriteMethod **write_method) |
| 834 | { |
| 835 | struct ospf_area *area; |
| 836 | struct in_addr addr; |
| 837 | |
| 838 | memset (&addr, 0, sizeof (struct in_addr)); |
| 839 | |
| 840 | area = ospfStubAreaLookup (v, name, length, &addr, exact); |
| 841 | if (! area) |
| 842 | return NULL; |
| 843 | |
| 844 | /* Return the current value of the variable */ |
| 845 | switch (v->magic) |
| 846 | { |
| 847 | case OSPFSTUBAREAID: /* 1 */ |
| 848 | /* OSPF stub area id. */ |
| 849 | return SNMP_IPADDRESS (area->area_id); |
| 850 | break; |
| 851 | case OSPFSTUBTOS: /* 2 */ |
| 852 | /* TOS value is not supported. */ |
| 853 | return SNMP_INTEGER (0); |
| 854 | break; |
| 855 | case OSPFSTUBMETRIC: /* 3 */ |
| 856 | /* Default cost to stub area. */ |
| 857 | return SNMP_INTEGER (area->default_cost); |
| 858 | break; |
| 859 | case OSPFSTUBSTATUS: /* 4 */ |
| 860 | /* Status of the stub area. */ |
| 861 | return SNMP_INTEGER (SNMP_VALID); |
| 862 | break; |
| 863 | case OSPFSTUBMETRICTYPE: /* 5 */ |
| 864 | /* OSPF Metric type. */ |
| 865 | #define OSPF_ospfMetric 1 |
| 866 | #define OSPF_comparableCost 2 |
| 867 | #define OSPF_nonComparable 3 |
| 868 | return SNMP_INTEGER (OSPF_ospfMetric); |
| 869 | break; |
| 870 | default: |
| 871 | return NULL; |
| 872 | break; |
| 873 | } |
| 874 | return NULL; |
| 875 | } |
| 876 | |
| 877 | struct ospf_lsa * |
| 878 | lsdb_lookup_next (struct ospf_area *area, u_char *type, int type_next, |
| 879 | struct in_addr *ls_id, int ls_id_next, |
| 880 | struct in_addr *router_id, int router_id_next) |
| 881 | { |
| 882 | struct ospf_lsa *lsa; |
| 883 | int i; |
| 884 | |
| 885 | if (type_next) |
| 886 | i = OSPF_MIN_LSA; |
| 887 | else |
| 888 | i = *type; |
| 889 | |
vincent | ba68253 | 2005-09-29 13:52:57 +0000 | [diff] [blame] | 890 | /* Sanity check, if LSA type unknwon |
| 891 | merley skip any LSA */ |
| 892 | if ((i < OSPF_MIN_LSA) || (i >= OSPF_MAX_LSA)) |
| 893 | { |
| 894 | zlog_debug("Strange request with LSA type %d\n", i); |
| 895 | return NULL; |
| 896 | } |
| 897 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 898 | for (; i < OSPF_MAX_LSA; i++) |
| 899 | { |
| 900 | *type = i; |
| 901 | |
| 902 | lsa = ospf_lsdb_lookup_by_id_next (area->lsdb, *type, *ls_id, *router_id, |
| 903 | ls_id_next); |
| 904 | if (lsa) |
| 905 | return lsa; |
| 906 | |
| 907 | ls_id_next = 1; |
| 908 | } |
| 909 | return NULL; |
| 910 | } |
| 911 | |
| 912 | struct ospf_lsa * |
| 913 | ospfLsdbLookup (struct variable *v, oid *name, size_t *length, |
| 914 | struct in_addr *area_id, u_char *type, |
| 915 | struct in_addr *ls_id, struct in_addr *router_id, int exact) |
| 916 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 917 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 918 | struct ospf_area *area; |
| 919 | struct ospf_lsa *lsa; |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 920 | unsigned int len; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 921 | int type_next; |
| 922 | int ls_id_next; |
| 923 | int router_id_next; |
| 924 | oid *offset; |
| 925 | int offsetlen; |
| 926 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 927 | ospf = ospf_lookup (); |
| 928 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 929 | #define OSPF_LSDB_ENTRY_OFFSET \ |
| 930 | (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE) |
| 931 | |
| 932 | if (exact) |
| 933 | { |
| 934 | /* Area ID + Type + LS ID + Router ID. */ |
| 935 | if (*length - v->namelen != OSPF_LSDB_ENTRY_OFFSET) |
| 936 | return NULL; |
| 937 | |
| 938 | /* Set OID offset for Area ID. */ |
| 939 | offset = name + v->namelen; |
| 940 | |
| 941 | /* Lookup area first. */ |
| 942 | oid2in_addr (offset, IN_ADDR_SIZE, area_id); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 943 | area = ospf_area_lookup_by_area_id (ospf, *area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 944 | if (! area) |
| 945 | return NULL; |
| 946 | offset += IN_ADDR_SIZE; |
| 947 | |
| 948 | /* Type. */ |
| 949 | *type = *offset; |
| 950 | offset++; |
| 951 | |
| 952 | /* LS ID. */ |
| 953 | oid2in_addr (offset, IN_ADDR_SIZE, ls_id); |
| 954 | offset += IN_ADDR_SIZE; |
| 955 | |
| 956 | /* Router ID. */ |
| 957 | oid2in_addr (offset, IN_ADDR_SIZE, router_id); |
| 958 | |
| 959 | /* Lookup LSDB. */ |
| 960 | return ospf_lsdb_lookup_by_id (area->lsdb, *type, *ls_id, *router_id); |
| 961 | } |
| 962 | else |
| 963 | { |
| 964 | /* Get variable length. */ |
| 965 | offset = name + v->namelen; |
| 966 | offsetlen = *length - v->namelen; |
| 967 | len = offsetlen; |
| 968 | |
| 969 | if (len > IN_ADDR_SIZE) |
| 970 | len = IN_ADDR_SIZE; |
| 971 | |
| 972 | oid2in_addr (offset, len, area_id); |
| 973 | |
| 974 | /* First we search area. */ |
| 975 | if (len == IN_ADDR_SIZE) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 976 | area = ospf_area_lookup_by_area_id (ospf, *area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 977 | else |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 978 | area = ospf_area_lookup_next (ospf, area_id, len == 0 ? 1 : 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 979 | |
| 980 | if (area == NULL) |
| 981 | return NULL; |
| 982 | |
| 983 | do |
| 984 | { |
| 985 | /* Next we lookup type. */ |
| 986 | offset += IN_ADDR_SIZE; |
| 987 | offsetlen -= IN_ADDR_SIZE; |
| 988 | len = offsetlen; |
| 989 | |
| 990 | if (len <= 0) |
| 991 | type_next = 1; |
| 992 | else |
| 993 | { |
| 994 | len = 1; |
| 995 | type_next = 0; |
| 996 | *type = *offset; |
| 997 | } |
| 998 | |
| 999 | /* LS ID. */ |
| 1000 | offset++; |
| 1001 | offsetlen--; |
| 1002 | len = offsetlen; |
| 1003 | |
| 1004 | if (len <= 0) |
| 1005 | ls_id_next = 1; |
| 1006 | else |
| 1007 | { |
| 1008 | ls_id_next = 0; |
| 1009 | if (len > IN_ADDR_SIZE) |
| 1010 | len = IN_ADDR_SIZE; |
| 1011 | |
| 1012 | oid2in_addr (offset, len, ls_id); |
| 1013 | } |
| 1014 | |
| 1015 | /* Router ID. */ |
| 1016 | offset += IN_ADDR_SIZE; |
| 1017 | offsetlen -= IN_ADDR_SIZE; |
| 1018 | len = offsetlen; |
| 1019 | |
| 1020 | if (len <= 0) |
| 1021 | router_id_next = 1; |
| 1022 | else |
| 1023 | { |
| 1024 | router_id_next = 0; |
| 1025 | if (len > IN_ADDR_SIZE) |
| 1026 | len = IN_ADDR_SIZE; |
| 1027 | |
| 1028 | oid2in_addr (offset, len, router_id); |
| 1029 | } |
| 1030 | |
| 1031 | lsa = lsdb_lookup_next (area, type, type_next, ls_id, ls_id_next, |
| 1032 | router_id, router_id_next); |
| 1033 | |
| 1034 | if (lsa) |
| 1035 | { |
| 1036 | /* Fill in length. */ |
| 1037 | *length = v->namelen + OSPF_LSDB_ENTRY_OFFSET; |
| 1038 | |
| 1039 | /* Fill in value. */ |
| 1040 | offset = name + v->namelen; |
| 1041 | oid_copy_addr (offset, area_id, IN_ADDR_SIZE); |
| 1042 | offset += IN_ADDR_SIZE; |
| 1043 | *offset = lsa->data->type; |
| 1044 | offset++; |
| 1045 | oid_copy_addr (offset, &lsa->data->id, IN_ADDR_SIZE); |
| 1046 | offset += IN_ADDR_SIZE; |
| 1047 | oid_copy_addr (offset, &lsa->data->adv_router, IN_ADDR_SIZE); |
| 1048 | |
| 1049 | return lsa; |
| 1050 | } |
| 1051 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1052 | while ((area = ospf_area_lookup_next (ospf, area_id, 0)) != NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1053 | } |
| 1054 | return NULL; |
| 1055 | } |
| 1056 | |
| 1057 | static u_char * |
| 1058 | ospfLsdbEntry (struct variable *v, oid *name, size_t *length, int exact, |
| 1059 | size_t *var_len, WriteMethod **write_method) |
| 1060 | { |
| 1061 | struct ospf_lsa *lsa; |
| 1062 | struct lsa_header *lsah; |
| 1063 | struct in_addr area_id; |
| 1064 | u_char type; |
| 1065 | struct in_addr ls_id; |
| 1066 | struct in_addr router_id; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1067 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1068 | |
| 1069 | /* INDEX { ospfLsdbAreaId, ospfLsdbType, |
| 1070 | ospfLsdbLsid, ospfLsdbRouterId } */ |
| 1071 | |
| 1072 | memset (&area_id, 0, sizeof (struct in_addr)); |
| 1073 | type = 0; |
| 1074 | memset (&ls_id, 0, sizeof (struct in_addr)); |
| 1075 | memset (&router_id, 0, sizeof (struct in_addr)); |
| 1076 | |
| 1077 | /* Check OSPF instance. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1078 | ospf = ospf_lookup (); |
| 1079 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1080 | return NULL; |
| 1081 | |
| 1082 | lsa = ospfLsdbLookup (v, name, length, &area_id, &type, &ls_id, &router_id, |
| 1083 | exact); |
| 1084 | if (! lsa) |
| 1085 | return NULL; |
| 1086 | |
| 1087 | lsah = lsa->data; |
| 1088 | |
| 1089 | /* Return the current value of the variable */ |
| 1090 | switch (v->magic) |
| 1091 | { |
| 1092 | case OSPFLSDBAREAID: /* 1 */ |
| 1093 | return SNMP_IPADDRESS (lsa->area->area_id); |
| 1094 | break; |
| 1095 | case OSPFLSDBTYPE: /* 2 */ |
| 1096 | return SNMP_INTEGER (lsah->type); |
| 1097 | break; |
| 1098 | case OSPFLSDBLSID: /* 3 */ |
| 1099 | return SNMP_IPADDRESS (lsah->id); |
| 1100 | break; |
| 1101 | case OSPFLSDBROUTERID: /* 4 */ |
| 1102 | return SNMP_IPADDRESS (lsah->adv_router); |
| 1103 | break; |
| 1104 | case OSPFLSDBSEQUENCE: /* 5 */ |
| 1105 | return SNMP_INTEGER (lsah->ls_seqnum); |
| 1106 | break; |
| 1107 | case OSPFLSDBAGE: /* 6 */ |
| 1108 | return SNMP_INTEGER (lsah->ls_age); |
| 1109 | break; |
| 1110 | case OSPFLSDBCHECKSUM: /* 7 */ |
| 1111 | return SNMP_INTEGER (lsah->checksum); |
| 1112 | break; |
| 1113 | case OSPFLSDBADVERTISEMENT: /* 8 */ |
| 1114 | *var_len = ntohs (lsah->length); |
| 1115 | return (u_char *) lsah; |
| 1116 | break; |
| 1117 | default: |
| 1118 | return NULL; |
| 1119 | break; |
| 1120 | } |
| 1121 | return NULL; |
| 1122 | } |
| 1123 | |
| 1124 | struct ospf_area_range * |
| 1125 | ospfAreaRangeLookup (struct variable *v, oid *name, size_t *length, |
| 1126 | struct in_addr *area_id, struct in_addr *range_net, |
| 1127 | int exact) |
| 1128 | { |
| 1129 | oid *offset; |
| 1130 | int offsetlen; |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 1131 | unsigned int len; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1132 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1133 | struct ospf_area *area; |
| 1134 | struct ospf_area_range *range; |
| 1135 | struct prefix_ipv4 p; |
| 1136 | p.family = AF_INET; |
| 1137 | p.prefixlen = IPV4_MAX_BITLEN; |
| 1138 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1139 | ospf = ospf_lookup (); |
| 1140 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1141 | if (exact) |
| 1142 | { |
| 1143 | /* Area ID + Range Network. */ |
| 1144 | if (v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE != *length) |
| 1145 | return NULL; |
| 1146 | |
| 1147 | /* Set OID offset for Area ID. */ |
| 1148 | offset = name + v->namelen; |
| 1149 | |
| 1150 | /* Lookup area first. */ |
| 1151 | oid2in_addr (offset, IN_ADDR_SIZE, area_id); |
| 1152 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1153 | area = ospf_area_lookup_by_area_id (ospf, *area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1154 | if (! area) |
| 1155 | return NULL; |
| 1156 | |
| 1157 | offset += IN_ADDR_SIZE; |
| 1158 | |
| 1159 | /* Lookup area range. */ |
| 1160 | oid2in_addr (offset, IN_ADDR_SIZE, range_net); |
| 1161 | p.prefix = *range_net; |
| 1162 | |
| 1163 | return ospf_area_range_lookup (area, &p); |
| 1164 | } |
| 1165 | else |
| 1166 | { |
| 1167 | /* Set OID offset for Area ID. */ |
| 1168 | offset = name + v->namelen; |
| 1169 | offsetlen = *length - v->namelen; |
| 1170 | |
| 1171 | len = offsetlen; |
| 1172 | if (len > IN_ADDR_SIZE) |
| 1173 | len = IN_ADDR_SIZE; |
| 1174 | |
| 1175 | oid2in_addr (offset, len, area_id); |
| 1176 | |
| 1177 | /* First we search area. */ |
| 1178 | if (len == IN_ADDR_SIZE) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1179 | area = ospf_area_lookup_by_area_id (ospf,*area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1180 | else |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1181 | area = ospf_area_lookup_next (ospf, area_id, len == 0 ? 1 : 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1182 | |
| 1183 | if (area == NULL) |
| 1184 | return NULL; |
| 1185 | |
| 1186 | do |
| 1187 | { |
| 1188 | offset += IN_ADDR_SIZE; |
| 1189 | offsetlen -= IN_ADDR_SIZE; |
| 1190 | len = offsetlen; |
| 1191 | |
| 1192 | if (len < 0) |
| 1193 | len = 0; |
| 1194 | if (len > IN_ADDR_SIZE) |
| 1195 | len = IN_ADDR_SIZE; |
| 1196 | |
| 1197 | oid2in_addr (offset, len, range_net); |
| 1198 | |
| 1199 | range = ospf_area_range_lookup_next (area, range_net, |
| 1200 | len == 0 ? 1 : 0); |
| 1201 | |
| 1202 | if (range) |
| 1203 | { |
| 1204 | /* Fill in length. */ |
| 1205 | *length = v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE; |
| 1206 | |
| 1207 | /* Fill in value. */ |
| 1208 | offset = name + v->namelen; |
| 1209 | oid_copy_addr (offset, area_id, IN_ADDR_SIZE); |
| 1210 | offset += IN_ADDR_SIZE; |
| 1211 | oid_copy_addr (offset, range_net, IN_ADDR_SIZE); |
| 1212 | |
| 1213 | return range; |
| 1214 | } |
| 1215 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1216 | while ((area = ospf_area_lookup_next (ospf, area_id, 0)) != NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1217 | } |
| 1218 | return NULL; |
| 1219 | } |
| 1220 | |
| 1221 | static u_char * |
| 1222 | ospfAreaRangeEntry (struct variable *v, oid *name, size_t *length, int exact, |
| 1223 | size_t *var_len, WriteMethod **write_method) |
| 1224 | { |
| 1225 | struct ospf_area_range *range; |
| 1226 | struct in_addr area_id; |
| 1227 | struct in_addr range_net; |
| 1228 | struct in_addr mask; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1229 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1230 | |
| 1231 | /* Check OSPF instance. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1232 | ospf = ospf_lookup (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1233 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1234 | return NULL; |
| 1235 | |
| 1236 | memset (&area_id, 0, IN_ADDR_SIZE); |
| 1237 | memset (&range_net, 0, IN_ADDR_SIZE); |
| 1238 | |
| 1239 | range = ospfAreaRangeLookup (v, name, length, &area_id, &range_net, exact); |
| 1240 | if (! range) |
| 1241 | return NULL; |
| 1242 | |
| 1243 | /* Convert prefixlen to network mask format. */ |
| 1244 | masklen2ip (range->subst_masklen, &mask); |
| 1245 | |
| 1246 | /* Return the current value of the variable */ |
| 1247 | switch (v->magic) |
| 1248 | { |
| 1249 | case OSPFAREARANGEAREAID: /* 1 */ |
| 1250 | return SNMP_IPADDRESS (area_id); |
| 1251 | break; |
| 1252 | case OSPFAREARANGENET: /* 2 */ |
| 1253 | return SNMP_IPADDRESS (range_net); |
| 1254 | break; |
| 1255 | case OSPFAREARANGEMASK: /* 3 */ |
| 1256 | return SNMP_IPADDRESS (mask); |
| 1257 | break; |
| 1258 | case OSPFAREARANGESTATUS: /* 4 */ |
| 1259 | return SNMP_INTEGER (SNMP_VALID); |
| 1260 | break; |
| 1261 | case OSPFAREARANGEEFFECT: /* 5 */ |
| 1262 | #define OSPF_advertiseMatching 1 |
| 1263 | #define OSPF_doNotAdvertiseMatching 2 |
| 1264 | return SNMP_INTEGER (OSPF_advertiseMatching); |
| 1265 | break; |
| 1266 | default: |
| 1267 | return NULL; |
| 1268 | break; |
| 1269 | } |
| 1270 | return NULL; |
| 1271 | } |
| 1272 | |
| 1273 | struct ospf_nbr_nbma * |
| 1274 | ospfHostLookup (struct variable *v, oid *name, size_t *length, |
| 1275 | struct in_addr *addr, int exact) |
| 1276 | { |
| 1277 | int len; |
| 1278 | struct ospf_nbr_nbma *nbr_nbma; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1279 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1280 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1281 | ospf = ospf_lookup (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1282 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1283 | return NULL; |
| 1284 | |
| 1285 | if (exact) |
| 1286 | { |
| 1287 | /* INDEX { ospfHostIpAddress, ospfHostTOS } */ |
| 1288 | if (*length != v->namelen + IN_ADDR_SIZE + 1) |
| 1289 | return NULL; |
| 1290 | |
| 1291 | /* Check ospfHostTOS. */ |
| 1292 | if (name[*length - 1] != 0) |
| 1293 | return NULL; |
| 1294 | |
| 1295 | oid2in_addr (name + v->namelen, IN_ADDR_SIZE, addr); |
| 1296 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1297 | nbr_nbma = ospf_nbr_nbma_lookup (ospf, *addr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1298 | |
| 1299 | return nbr_nbma; |
| 1300 | } |
| 1301 | else |
| 1302 | { |
| 1303 | len = *length - v->namelen; |
| 1304 | if (len > 4) |
| 1305 | len = 4; |
| 1306 | |
| 1307 | oid2in_addr (name + v->namelen, len, addr); |
| 1308 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1309 | nbr_nbma = ospf_nbr_nbma_lookup_next (ospf, addr, len == 0 ? 1 : 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1310 | |
| 1311 | if (nbr_nbma == NULL) |
| 1312 | return NULL; |
| 1313 | |
| 1314 | oid_copy_addr (name + v->namelen, addr, IN_ADDR_SIZE); |
| 1315 | |
| 1316 | /* Set TOS 0. */ |
| 1317 | name[v->namelen + IN_ADDR_SIZE] = 0; |
| 1318 | |
| 1319 | *length = v->namelen + IN_ADDR_SIZE + 1; |
| 1320 | |
| 1321 | return nbr_nbma; |
| 1322 | } |
| 1323 | return NULL; |
| 1324 | } |
| 1325 | |
| 1326 | static u_char * |
| 1327 | ospfHostEntry (struct variable *v, oid *name, size_t *length, int exact, |
| 1328 | size_t *var_len, WriteMethod **write_method) |
| 1329 | { |
| 1330 | struct ospf_nbr_nbma *nbr_nbma; |
| 1331 | struct ospf_interface *oi; |
| 1332 | struct in_addr addr; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1333 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1334 | |
| 1335 | /* Check OSPF instance. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1336 | ospf = ospf_lookup (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1337 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1338 | return NULL; |
| 1339 | |
| 1340 | memset (&addr, 0, sizeof (struct in_addr)); |
| 1341 | |
| 1342 | nbr_nbma = ospfHostLookup (v, name, length, &addr, exact); |
| 1343 | if (nbr_nbma == NULL) |
| 1344 | return NULL; |
| 1345 | |
| 1346 | oi = nbr_nbma->oi; |
| 1347 | |
| 1348 | /* Return the current value of the variable */ |
| 1349 | switch (v->magic) |
| 1350 | { |
| 1351 | case OSPFHOSTIPADDRESS: /* 1 */ |
| 1352 | return SNMP_IPADDRESS (nbr_nbma->addr); |
| 1353 | break; |
| 1354 | case OSPFHOSTTOS: /* 2 */ |
| 1355 | return SNMP_INTEGER (0); |
| 1356 | break; |
| 1357 | case OSPFHOSTMETRIC: /* 3 */ |
| 1358 | if (oi) |
| 1359 | return SNMP_INTEGER (oi->output_cost); |
| 1360 | else |
| 1361 | return SNMP_INTEGER (1); |
| 1362 | break; |
| 1363 | case OSPFHOSTSTATUS: /* 4 */ |
| 1364 | return SNMP_INTEGER (SNMP_VALID); |
| 1365 | break; |
| 1366 | case OSPFHOSTAREAID: /* 5 */ |
| 1367 | if (oi && oi->area) |
| 1368 | return SNMP_IPADDRESS (oi->area->area_id); |
| 1369 | else |
| 1370 | return SNMP_IPADDRESS (ospf_empty_addr); |
| 1371 | break; |
| 1372 | default: |
| 1373 | return NULL; |
| 1374 | break; |
| 1375 | } |
| 1376 | return NULL; |
| 1377 | } |
| 1378 | |
| 1379 | struct list *ospf_snmp_iflist; |
| 1380 | |
| 1381 | struct ospf_snmp_if |
| 1382 | { |
| 1383 | struct in_addr addr; |
| 1384 | unsigned int ifindex; |
| 1385 | struct interface *ifp; |
| 1386 | }; |
| 1387 | |
| 1388 | struct ospf_snmp_if * |
| 1389 | ospf_snmp_if_new () |
| 1390 | { |
| 1391 | struct ospf_snmp_if *osif; |
| 1392 | |
| 1393 | osif = XMALLOC (0, sizeof (struct ospf_snmp_if)); |
| 1394 | memset (osif, 0, sizeof (struct ospf_snmp_if)); |
| 1395 | return osif; |
| 1396 | } |
| 1397 | |
| 1398 | void |
| 1399 | ospf_snmp_if_free (struct ospf_snmp_if *osif) |
| 1400 | { |
| 1401 | XFREE (0, osif); |
| 1402 | } |
| 1403 | |
| 1404 | void |
| 1405 | ospf_snmp_if_delete (struct interface *ifp) |
| 1406 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1407 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1408 | struct ospf_snmp_if *osif; |
| 1409 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1410 | for (ALL_LIST_ELEMENTS (ospf_snmp_iflist, node, nnode, osif)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1411 | { |
| 1412 | if (osif->ifp == ifp) |
| 1413 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1414 | list_delete_node (ospf_snmp_iflist, node); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1415 | ospf_snmp_if_free (osif); |
| 1416 | return; |
| 1417 | } |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | void |
| 1422 | ospf_snmp_if_update (struct interface *ifp) |
| 1423 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1424 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1425 | struct listnode *pn; |
| 1426 | struct connected *ifc; |
| 1427 | struct prefix *p; |
| 1428 | struct ospf_snmp_if *osif; |
| 1429 | struct in_addr *addr; |
| 1430 | unsigned int ifindex; |
| 1431 | |
| 1432 | ospf_snmp_if_delete (ifp); |
| 1433 | |
| 1434 | p = NULL; |
| 1435 | addr = NULL; |
| 1436 | ifindex = 0; |
| 1437 | |
| 1438 | /* Lookup first IPv4 address entry. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1439 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1440 | { |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 1441 | if (CONNECTED_POINTOPOINT_HOST(ifc)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1442 | p = ifc->destination; |
| 1443 | else |
| 1444 | p = ifc->address; |
| 1445 | |
| 1446 | if (p->family == AF_INET) |
| 1447 | { |
| 1448 | addr = &p->u.prefix4; |
| 1449 | break; |
| 1450 | } |
| 1451 | } |
| 1452 | if (! addr) |
| 1453 | ifindex = ifp->ifindex; |
| 1454 | |
| 1455 | /* Add interface to the list. */ |
| 1456 | pn = NULL; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1457 | for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, node, osif)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1458 | { |
| 1459 | if (addr) |
| 1460 | { |
| 1461 | if (ntohl (osif->addr.s_addr) > ntohl (addr->s_addr)) |
| 1462 | break; |
| 1463 | } |
| 1464 | else |
| 1465 | { |
| 1466 | /* Unnumbered interface. */ |
| 1467 | if (osif->addr.s_addr != 0 || osif->ifindex > ifindex) |
| 1468 | break; |
| 1469 | } |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1470 | pn = node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | osif = ospf_snmp_if_new (); |
| 1474 | if (addr) |
| 1475 | osif->addr = *addr; |
| 1476 | else |
| 1477 | osif->ifindex = ifindex; |
| 1478 | osif->ifp = ifp; |
| 1479 | |
| 1480 | listnode_add_after (ospf_snmp_iflist, pn, osif); |
| 1481 | } |
| 1482 | |
| 1483 | struct interface * |
| 1484 | ospf_snmp_if_lookup (struct in_addr *ifaddr, unsigned int *ifindex) |
| 1485 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1486 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1487 | struct ospf_snmp_if *osif; |
| 1488 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1489 | for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, node, osif)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1490 | { |
| 1491 | if (ifaddr->s_addr) |
| 1492 | { |
| 1493 | if (IPV4_ADDR_SAME (&osif->addr, ifaddr)) |
| 1494 | return osif->ifp; |
| 1495 | } |
| 1496 | else |
| 1497 | { |
| 1498 | if (osif->ifindex == *ifindex) |
| 1499 | return osif->ifp; |
| 1500 | } |
| 1501 | } |
| 1502 | return NULL; |
| 1503 | } |
| 1504 | |
| 1505 | struct interface * |
| 1506 | ospf_snmp_if_lookup_next (struct in_addr *ifaddr, unsigned int *ifindex, |
| 1507 | int ifaddr_next, int ifindex_next) |
| 1508 | { |
| 1509 | struct ospf_snmp_if *osif; |
| 1510 | struct listnode *nn; |
| 1511 | |
| 1512 | if (ifaddr_next) |
| 1513 | { |
| 1514 | nn = listhead (ospf_snmp_iflist); |
| 1515 | if (nn) |
| 1516 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1517 | osif = listgetdata (nn); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1518 | *ifaddr = osif->addr; |
| 1519 | *ifindex = osif->ifindex; |
| 1520 | return osif->ifp; |
| 1521 | } |
| 1522 | return NULL; |
| 1523 | } |
| 1524 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1525 | for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, nn, osif)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1526 | { |
| 1527 | if (ifaddr->s_addr) |
| 1528 | { |
| 1529 | if (ntohl (osif->addr.s_addr) > ntohl (ifaddr->s_addr)) |
| 1530 | { |
| 1531 | *ifaddr = osif->addr; |
| 1532 | *ifindex = osif->ifindex; |
| 1533 | return osif->ifp; |
| 1534 | } |
| 1535 | } |
| 1536 | else |
| 1537 | { |
| 1538 | if (osif->ifindex > *ifindex || osif->addr.s_addr) |
| 1539 | { |
| 1540 | *ifaddr = osif->addr; |
| 1541 | *ifindex = osif->ifindex; |
| 1542 | return osif->ifp; |
| 1543 | } |
| 1544 | } |
| 1545 | } |
| 1546 | return NULL; |
| 1547 | } |
| 1548 | |
| 1549 | int |
| 1550 | ospf_snmp_iftype (struct interface *ifp) |
| 1551 | { |
| 1552 | #define ospf_snmp_iftype_broadcast 1 |
| 1553 | #define ospf_snmp_iftype_nbma 2 |
| 1554 | #define ospf_snmp_iftype_pointToPoint 3 |
| 1555 | #define ospf_snmp_iftype_pointToMultipoint 5 |
| 1556 | if (if_is_broadcast (ifp)) |
| 1557 | return ospf_snmp_iftype_broadcast; |
| 1558 | if (if_is_pointopoint (ifp)) |
| 1559 | return ospf_snmp_iftype_pointToPoint; |
| 1560 | return ospf_snmp_iftype_broadcast; |
| 1561 | } |
| 1562 | |
| 1563 | struct interface * |
| 1564 | ospfIfLookup (struct variable *v, oid *name, size_t *length, |
| 1565 | struct in_addr *ifaddr, unsigned int *ifindex, int exact) |
| 1566 | { |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 1567 | unsigned int len; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1568 | int ifaddr_next = 0; |
| 1569 | int ifindex_next = 0; |
| 1570 | struct interface *ifp; |
| 1571 | oid *offset; |
| 1572 | |
| 1573 | if (exact) |
| 1574 | { |
| 1575 | if (*length != v->namelen + IN_ADDR_SIZE + 1) |
| 1576 | return NULL; |
| 1577 | |
| 1578 | oid2in_addr (name + v->namelen, IN_ADDR_SIZE, ifaddr); |
| 1579 | *ifindex = name[v->namelen + IN_ADDR_SIZE]; |
| 1580 | |
| 1581 | return ospf_snmp_if_lookup (ifaddr, ifindex); |
| 1582 | } |
| 1583 | else |
| 1584 | { |
| 1585 | len = *length - v->namelen; |
| 1586 | if (len >= IN_ADDR_SIZE) |
| 1587 | len = IN_ADDR_SIZE; |
| 1588 | if (len <= 0) |
| 1589 | ifaddr_next = 1; |
| 1590 | |
| 1591 | oid2in_addr (name + v->namelen, len, ifaddr); |
| 1592 | |
| 1593 | len = *length - v->namelen - IN_ADDR_SIZE; |
| 1594 | if (len >= 1) |
| 1595 | len = 1; |
| 1596 | else |
| 1597 | ifindex_next = 1; |
| 1598 | |
| 1599 | if (len == 1) |
| 1600 | *ifindex = name[v->namelen + IN_ADDR_SIZE]; |
| 1601 | |
| 1602 | ifp = ospf_snmp_if_lookup_next (ifaddr, ifindex, ifaddr_next, |
| 1603 | ifindex_next); |
| 1604 | if (ifp) |
| 1605 | { |
| 1606 | *length = v->namelen + IN_ADDR_SIZE + 1; |
| 1607 | offset = name + v->namelen; |
| 1608 | oid_copy_addr (offset, ifaddr, IN_ADDR_SIZE); |
| 1609 | offset += IN_ADDR_SIZE; |
| 1610 | *offset = *ifindex; |
| 1611 | return ifp; |
| 1612 | } |
| 1613 | } |
| 1614 | return NULL; |
| 1615 | } |
| 1616 | |
| 1617 | static u_char * |
| 1618 | ospfIfEntry (struct variable *v, oid *name, size_t *length, int exact, |
| 1619 | size_t *var_len, WriteMethod **write_method) |
| 1620 | { |
| 1621 | struct interface *ifp; |
| 1622 | unsigned int ifindex; |
| 1623 | struct in_addr ifaddr; |
| 1624 | struct ospf_interface *oi; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1625 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1626 | |
| 1627 | ifindex = 0; |
| 1628 | memset (&ifaddr, 0, sizeof (struct in_addr)); |
| 1629 | |
| 1630 | /* Check OSPF instance. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1631 | ospf = ospf_lookup (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1632 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1633 | return NULL; |
| 1634 | |
| 1635 | ifp = ospfIfLookup (v, name, length, &ifaddr, &ifindex, exact); |
| 1636 | if (ifp == NULL) |
| 1637 | return NULL; |
| 1638 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1639 | oi = ospf_if_lookup_by_local_addr (ospf, ifp, ifaddr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1640 | if (oi == NULL) |
| 1641 | return NULL; |
| 1642 | |
| 1643 | /* Return the current value of the variable */ |
| 1644 | switch (v->magic) |
| 1645 | { |
| 1646 | case OSPFIFIPADDRESS: /* 1 */ |
| 1647 | return SNMP_IPADDRESS (ifaddr); |
| 1648 | break; |
| 1649 | case OSPFADDRESSLESSIF: /* 2 */ |
| 1650 | return SNMP_INTEGER (ifindex); |
| 1651 | break; |
| 1652 | case OSPFIFAREAID: /* 3 */ |
| 1653 | if (oi->area) |
| 1654 | return SNMP_IPADDRESS (oi->area->area_id); |
| 1655 | else |
| 1656 | return SNMP_IPADDRESS (ospf_empty_addr); |
| 1657 | break; |
| 1658 | case OSPFIFTYPE: /* 4 */ |
| 1659 | return SNMP_INTEGER (ospf_snmp_iftype (ifp)); |
| 1660 | break; |
| 1661 | case OSPFIFADMINSTAT: /* 5 */ |
| 1662 | if (oi) |
| 1663 | return SNMP_INTEGER (OSPF_STATUS_ENABLED); |
| 1664 | else |
| 1665 | return SNMP_INTEGER (OSPF_STATUS_DISABLED); |
| 1666 | break; |
| 1667 | case OSPFIFRTRPRIORITY: /* 6 */ |
| 1668 | return SNMP_INTEGER (PRIORITY (oi)); |
| 1669 | break; |
| 1670 | case OSPFIFTRANSITDELAY: /* 7 */ |
| 1671 | return SNMP_INTEGER (OSPF_IF_PARAM (oi, transmit_delay)); |
| 1672 | break; |
| 1673 | case OSPFIFRETRANSINTERVAL: /* 8 */ |
| 1674 | return SNMP_INTEGER (OSPF_IF_PARAM (oi, retransmit_interval)); |
| 1675 | break; |
| 1676 | case OSPFIFHELLOINTERVAL: /* 9 */ |
| 1677 | return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_hello)); |
| 1678 | break; |
| 1679 | case OSPFIFRTRDEADINTERVAL: /* 10 */ |
| 1680 | return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_wait)); |
| 1681 | break; |
| 1682 | case OSPFIFPOLLINTERVAL: /* 11 */ |
| 1683 | return SNMP_INTEGER (OSPF_POLL_INTERVAL_DEFAULT); |
| 1684 | break; |
| 1685 | case OSPFIFSTATE: /* 12 */ |
vincent | ba68253 | 2005-09-29 13:52:57 +0000 | [diff] [blame] | 1686 | return SNMP_INTEGER (ISM_SNMP(oi->state)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1687 | break; |
| 1688 | case OSPFIFDESIGNATEDROUTER: /* 13 */ |
| 1689 | return SNMP_IPADDRESS (DR (oi)); |
| 1690 | break; |
| 1691 | case OSPFIFBACKUPDESIGNATEDROUTER: /* 14 */ |
| 1692 | return SNMP_IPADDRESS (BDR (oi)); |
| 1693 | break; |
| 1694 | case OSPFIFEVENTS: /* 15 */ |
| 1695 | return SNMP_INTEGER (oi->state_change); |
| 1696 | break; |
| 1697 | case OSPFIFAUTHKEY: /* 16 */ |
| 1698 | *var_len = 0; |
| 1699 | return (u_char *) OSPF_IF_PARAM (oi, auth_simple); |
| 1700 | break; |
| 1701 | case OSPFIFSTATUS: /* 17 */ |
| 1702 | return SNMP_INTEGER (SNMP_VALID); |
| 1703 | break; |
| 1704 | case OSPFIFMULTICASTFORWARDING: /* 18 */ |
| 1705 | #define ospf_snmp_multiforward_blocked 1 |
| 1706 | #define ospf_snmp_multiforward_multicast 2 |
| 1707 | #define ospf_snmp_multiforward_unicast 3 |
| 1708 | return SNMP_INTEGER (ospf_snmp_multiforward_blocked); |
| 1709 | break; |
| 1710 | case OSPFIFDEMAND: /* 19 */ |
| 1711 | return SNMP_INTEGER (SNMP_FALSE); |
| 1712 | break; |
| 1713 | case OSPFIFAUTHTYPE: /* 20 */ |
| 1714 | if (oi->area) |
| 1715 | return SNMP_INTEGER (oi->area->auth_type); |
| 1716 | else |
| 1717 | return SNMP_INTEGER (0); |
| 1718 | break; |
| 1719 | default: |
| 1720 | return NULL; |
| 1721 | break; |
| 1722 | } |
| 1723 | return NULL; |
| 1724 | } |
| 1725 | |
| 1726 | #define OSPF_SNMP_METRIC_VALUE 1 |
| 1727 | |
| 1728 | struct interface * |
| 1729 | ospfIfMetricLookup (struct variable *v, oid *name, size_t *length, |
| 1730 | struct in_addr *ifaddr, unsigned int *ifindex, int exact) |
| 1731 | { |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 1732 | unsigned int len; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1733 | int ifaddr_next = 0; |
| 1734 | int ifindex_next = 0; |
| 1735 | struct interface *ifp; |
| 1736 | oid *offset; |
| 1737 | int metric; |
| 1738 | |
| 1739 | if (exact) |
| 1740 | { |
| 1741 | if (*length != v->namelen + IN_ADDR_SIZE + 1 + 1) |
| 1742 | return NULL; |
| 1743 | |
| 1744 | oid2in_addr (name + v->namelen, IN_ADDR_SIZE, ifaddr); |
| 1745 | *ifindex = name[v->namelen + IN_ADDR_SIZE]; |
| 1746 | metric = name[v->namelen + IN_ADDR_SIZE + 1]; |
| 1747 | |
| 1748 | if (metric != OSPF_SNMP_METRIC_VALUE) |
| 1749 | return NULL; |
| 1750 | |
| 1751 | return ospf_snmp_if_lookup (ifaddr, ifindex); |
| 1752 | } |
| 1753 | else |
| 1754 | { |
| 1755 | len = *length - v->namelen; |
| 1756 | if (len >= IN_ADDR_SIZE) |
| 1757 | len = IN_ADDR_SIZE; |
| 1758 | else |
| 1759 | ifaddr_next = 1; |
| 1760 | |
| 1761 | oid2in_addr (name + v->namelen, len, ifaddr); |
| 1762 | |
| 1763 | len = *length - v->namelen - IN_ADDR_SIZE; |
| 1764 | if (len >= 1) |
| 1765 | len = 1; |
| 1766 | else |
| 1767 | ifindex_next = 1; |
| 1768 | |
| 1769 | if (len == 1) |
| 1770 | *ifindex = name[v->namelen + IN_ADDR_SIZE]; |
| 1771 | |
| 1772 | ifp = ospf_snmp_if_lookup_next (ifaddr, ifindex, ifaddr_next, |
| 1773 | ifindex_next); |
| 1774 | if (ifp) |
| 1775 | { |
| 1776 | *length = v->namelen + IN_ADDR_SIZE + 1 + 1; |
| 1777 | offset = name + v->namelen; |
| 1778 | oid_copy_addr (offset, ifaddr, IN_ADDR_SIZE); |
| 1779 | offset += IN_ADDR_SIZE; |
| 1780 | *offset = *ifindex; |
| 1781 | offset++; |
| 1782 | *offset = OSPF_SNMP_METRIC_VALUE; |
| 1783 | return ifp; |
| 1784 | } |
| 1785 | } |
| 1786 | return NULL; |
| 1787 | } |
| 1788 | |
| 1789 | static u_char * |
| 1790 | ospfIfMetricEntry (struct variable *v, oid *name, size_t *length, int exact, |
| 1791 | size_t *var_len, WriteMethod **write_method) |
| 1792 | { |
| 1793 | /* Currently we support metric 1 only. */ |
| 1794 | struct interface *ifp; |
| 1795 | unsigned int ifindex; |
| 1796 | struct in_addr ifaddr; |
| 1797 | struct ospf_interface *oi; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1798 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1799 | |
| 1800 | ifindex = 0; |
| 1801 | memset (&ifaddr, 0, sizeof (struct in_addr)); |
| 1802 | |
| 1803 | /* Check OSPF instance. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1804 | ospf = ospf_lookup (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1805 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1806 | return NULL; |
| 1807 | |
| 1808 | ifp = ospfIfMetricLookup (v, name, length, &ifaddr, &ifindex, exact); |
| 1809 | if (ifp == NULL) |
| 1810 | return NULL; |
| 1811 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1812 | oi = ospf_if_lookup_by_local_addr (ospf, ifp, ifaddr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1813 | if (oi == NULL) |
| 1814 | return NULL; |
| 1815 | |
| 1816 | /* Return the current value of the variable */ |
| 1817 | switch (v->magic) |
| 1818 | { |
| 1819 | case OSPFIFMETRICIPADDRESS: |
| 1820 | return SNMP_IPADDRESS (ifaddr); |
| 1821 | break; |
| 1822 | case OSPFIFMETRICADDRESSLESSIF: |
| 1823 | return SNMP_INTEGER (ifindex); |
| 1824 | break; |
| 1825 | case OSPFIFMETRICTOS: |
| 1826 | return SNMP_INTEGER (0); |
| 1827 | break; |
| 1828 | case OSPFIFMETRICVALUE: |
| 1829 | return SNMP_INTEGER (OSPF_SNMP_METRIC_VALUE); |
| 1830 | break; |
| 1831 | case OSPFIFMETRICSTATUS: |
| 1832 | return SNMP_INTEGER (1); |
| 1833 | break; |
| 1834 | default: |
| 1835 | return NULL; |
| 1836 | break; |
| 1837 | } |
| 1838 | return NULL; |
| 1839 | } |
| 1840 | |
| 1841 | struct route_table *ospf_snmp_vl_table; |
| 1842 | |
| 1843 | void |
| 1844 | ospf_snmp_vl_add (struct ospf_vl_data *vl_data) |
| 1845 | { |
| 1846 | struct prefix_ls lp; |
| 1847 | struct route_node *rn; |
| 1848 | |
| 1849 | memset (&lp, 0, sizeof (struct prefix_ls)); |
| 1850 | lp.family = 0; |
| 1851 | lp.prefixlen = 64; |
| 1852 | lp.id = vl_data->vl_area_id; |
| 1853 | lp.adv_router = vl_data->vl_peer; |
| 1854 | |
| 1855 | rn = route_node_get (ospf_snmp_vl_table, (struct prefix *) &lp); |
| 1856 | rn->info = vl_data; |
| 1857 | } |
| 1858 | |
| 1859 | void |
| 1860 | ospf_snmp_vl_delete (struct ospf_vl_data *vl_data) |
| 1861 | { |
| 1862 | struct prefix_ls lp; |
| 1863 | struct route_node *rn; |
| 1864 | |
| 1865 | memset (&lp, 0, sizeof (struct prefix_ls)); |
| 1866 | lp.family = 0; |
| 1867 | lp.prefixlen = 64; |
| 1868 | lp.id = vl_data->vl_area_id; |
| 1869 | lp.adv_router = vl_data->vl_peer; |
| 1870 | |
| 1871 | rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp); |
| 1872 | if (! rn) |
| 1873 | return; |
| 1874 | rn->info = NULL; |
| 1875 | route_unlock_node (rn); |
| 1876 | route_unlock_node (rn); |
| 1877 | } |
| 1878 | |
| 1879 | struct ospf_vl_data * |
| 1880 | ospf_snmp_vl_lookup (struct in_addr *area_id, struct in_addr *neighbor) |
| 1881 | { |
| 1882 | struct prefix_ls lp; |
| 1883 | struct route_node *rn; |
| 1884 | struct ospf_vl_data *vl_data; |
| 1885 | |
| 1886 | memset (&lp, 0, sizeof (struct prefix_ls)); |
| 1887 | lp.family = 0; |
| 1888 | lp.prefixlen = 64; |
| 1889 | lp.id = *area_id; |
| 1890 | lp.adv_router = *neighbor; |
| 1891 | |
| 1892 | rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp); |
| 1893 | if (rn) |
| 1894 | { |
| 1895 | vl_data = rn->info; |
| 1896 | route_unlock_node (rn); |
| 1897 | return vl_data; |
| 1898 | } |
| 1899 | return NULL; |
| 1900 | } |
| 1901 | |
| 1902 | struct ospf_vl_data * |
| 1903 | ospf_snmp_vl_lookup_next (struct in_addr *area_id, struct in_addr *neighbor, |
| 1904 | int first) |
| 1905 | { |
| 1906 | struct prefix_ls lp; |
| 1907 | struct route_node *rn; |
| 1908 | struct ospf_vl_data *vl_data; |
| 1909 | |
| 1910 | memset (&lp, 0, sizeof (struct prefix_ls)); |
| 1911 | lp.family = 0; |
| 1912 | lp.prefixlen = 64; |
| 1913 | lp.id = *area_id; |
| 1914 | lp.adv_router = *neighbor; |
| 1915 | |
| 1916 | if (first) |
| 1917 | rn = route_top (ospf_snmp_vl_table); |
| 1918 | else |
| 1919 | { |
| 1920 | rn = route_node_get (ospf_snmp_vl_table, (struct prefix *) &lp); |
| 1921 | rn = route_next (rn); |
| 1922 | } |
| 1923 | |
| 1924 | for (; rn; rn = route_next (rn)) |
| 1925 | if (rn->info) |
| 1926 | break; |
| 1927 | |
| 1928 | if (rn && rn->info) |
| 1929 | { |
| 1930 | vl_data = rn->info; |
| 1931 | *area_id = vl_data->vl_area_id; |
| 1932 | *neighbor = vl_data->vl_peer; |
| 1933 | route_unlock_node (rn); |
| 1934 | return vl_data; |
| 1935 | } |
| 1936 | return NULL; |
| 1937 | } |
| 1938 | |
| 1939 | struct ospf_vl_data * |
| 1940 | ospfVirtIfLookup (struct variable *v, oid *name, size_t *length, |
| 1941 | struct in_addr *area_id, struct in_addr *neighbor, int exact) |
| 1942 | { |
| 1943 | int first; |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 1944 | unsigned int len; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1945 | struct ospf_vl_data *vl_data; |
| 1946 | |
| 1947 | if (exact) |
| 1948 | { |
| 1949 | if (*length != v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE) |
| 1950 | return NULL; |
| 1951 | |
| 1952 | oid2in_addr (name + v->namelen, IN_ADDR_SIZE, area_id); |
| 1953 | oid2in_addr (name + v->namelen + IN_ADDR_SIZE, IN_ADDR_SIZE, neighbor); |
| 1954 | |
| 1955 | return ospf_snmp_vl_lookup (area_id, neighbor); |
| 1956 | } |
| 1957 | else |
| 1958 | { |
| 1959 | first = 0; |
| 1960 | |
| 1961 | len = *length - v->namelen; |
| 1962 | if (len <= 0) |
| 1963 | first = 1; |
| 1964 | if (len > IN_ADDR_SIZE) |
| 1965 | len = IN_ADDR_SIZE; |
| 1966 | oid2in_addr (name + v->namelen, len, area_id); |
| 1967 | |
| 1968 | len = *length - v->namelen - IN_ADDR_SIZE; |
| 1969 | if (len > IN_ADDR_SIZE) |
| 1970 | len = IN_ADDR_SIZE; |
| 1971 | oid2in_addr (name + v->namelen + IN_ADDR_SIZE, len, neighbor); |
| 1972 | |
| 1973 | vl_data = ospf_snmp_vl_lookup_next (area_id, neighbor, first); |
| 1974 | |
| 1975 | if (vl_data) |
| 1976 | { |
| 1977 | *length = v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE; |
| 1978 | oid_copy_addr (name + v->namelen, area_id, IN_ADDR_SIZE); |
| 1979 | oid_copy_addr (name + v->namelen + IN_ADDR_SIZE, neighbor, |
| 1980 | IN_ADDR_SIZE); |
| 1981 | return vl_data; |
| 1982 | } |
| 1983 | } |
| 1984 | return NULL; |
| 1985 | } |
| 1986 | |
| 1987 | static u_char * |
| 1988 | ospfVirtIfEntry (struct variable *v, oid *name, size_t *length, int exact, |
| 1989 | size_t *var_len, WriteMethod **write_method) |
| 1990 | { |
| 1991 | struct ospf_vl_data *vl_data; |
| 1992 | struct ospf_interface *oi; |
| 1993 | struct in_addr area_id; |
| 1994 | struct in_addr neighbor; |
| 1995 | |
| 1996 | memset (&area_id, 0, sizeof (struct in_addr)); |
| 1997 | memset (&neighbor, 0, sizeof (struct in_addr)); |
| 1998 | |
| 1999 | vl_data = ospfVirtIfLookup (v, name, length, &area_id, &neighbor, exact); |
| 2000 | if (! vl_data) |
| 2001 | return NULL; |
| 2002 | oi = vl_data->vl_oi; |
| 2003 | if (! oi) |
| 2004 | return NULL; |
| 2005 | |
| 2006 | /* Return the current value of the variable */ |
| 2007 | switch (v->magic) |
| 2008 | { |
| 2009 | case OSPFVIRTIFAREAID: |
| 2010 | return SNMP_IPADDRESS (area_id); |
| 2011 | break; |
| 2012 | case OSPFVIRTIFNEIGHBOR: |
| 2013 | return SNMP_IPADDRESS (neighbor); |
| 2014 | break; |
| 2015 | case OSPFVIRTIFTRANSITDELAY: |
| 2016 | return SNMP_INTEGER (OSPF_IF_PARAM (oi, transmit_delay)); |
| 2017 | break; |
| 2018 | case OSPFVIRTIFRETRANSINTERVAL: |
| 2019 | return SNMP_INTEGER (OSPF_IF_PARAM (oi, retransmit_interval)); |
| 2020 | break; |
| 2021 | case OSPFVIRTIFHELLOINTERVAL: |
| 2022 | return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_hello)); |
| 2023 | break; |
| 2024 | case OSPFVIRTIFRTRDEADINTERVAL: |
| 2025 | return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_wait)); |
| 2026 | break; |
| 2027 | case OSPFVIRTIFSTATE: |
| 2028 | return SNMP_INTEGER (oi->state); |
| 2029 | break; |
| 2030 | case OSPFVIRTIFEVENTS: |
| 2031 | return SNMP_INTEGER (oi->state_change); |
| 2032 | break; |
| 2033 | case OSPFVIRTIFAUTHKEY: |
| 2034 | *var_len = 0; |
| 2035 | return (u_char *) OSPF_IF_PARAM (oi, auth_simple); |
| 2036 | break; |
| 2037 | case OSPFVIRTIFSTATUS: |
| 2038 | return SNMP_INTEGER (SNMP_VALID); |
| 2039 | break; |
| 2040 | case OSPFVIRTIFAUTHTYPE: |
| 2041 | if (oi->area) |
| 2042 | return SNMP_INTEGER (oi->area->auth_type); |
| 2043 | else |
| 2044 | return SNMP_INTEGER (0); |
| 2045 | break; |
| 2046 | default: |
| 2047 | return NULL; |
| 2048 | break; |
| 2049 | } |
| 2050 | return NULL; |
| 2051 | } |
| 2052 | |
| 2053 | struct ospf_neighbor * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2054 | ospf_snmp_nbr_lookup (struct ospf *ospf, struct in_addr *nbr_addr, |
| 2055 | unsigned int *ifindex) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2056 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2057 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2058 | struct ospf_interface *oi; |
| 2059 | struct ospf_neighbor *nbr; |
| 2060 | struct route_node *rn; |
| 2061 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2062 | for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2063 | { |
| 2064 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) |
| 2065 | if ((nbr = rn->info) != NULL |
| 2066 | && nbr != oi->nbr_self |
| 2067 | && nbr->state != NSM_Down |
| 2068 | && nbr->src.s_addr != 0) |
| 2069 | { |
| 2070 | if (IPV4_ADDR_SAME (&nbr->src, nbr_addr)) |
| 2071 | { |
| 2072 | route_unlock_node (rn); |
| 2073 | return nbr; |
| 2074 | } |
| 2075 | } |
| 2076 | } |
| 2077 | return NULL; |
| 2078 | } |
| 2079 | |
| 2080 | struct ospf_neighbor * |
| 2081 | ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, unsigned int *ifindex, |
| 2082 | int first) |
| 2083 | { |
| 2084 | struct listnode *nn; |
| 2085 | struct ospf_interface *oi; |
| 2086 | struct ospf_neighbor *nbr; |
| 2087 | struct route_node *rn; |
| 2088 | struct ospf_neighbor *min = NULL; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2089 | struct ospf *ospf = ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2090 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2091 | ospf = ospf_lookup (); |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2092 | |
| 2093 | for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, nn, oi)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2094 | { |
| 2095 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) |
| 2096 | if ((nbr = rn->info) != NULL |
| 2097 | && nbr != oi->nbr_self |
| 2098 | && nbr->state != NSM_Down |
| 2099 | && nbr->src.s_addr != 0) |
| 2100 | { |
| 2101 | if (first) |
| 2102 | { |
| 2103 | if (! min) |
| 2104 | min = nbr; |
| 2105 | else if (ntohl (nbr->src.s_addr) < ntohl (min->src.s_addr)) |
| 2106 | min = nbr; |
| 2107 | } |
| 2108 | else if (ntohl (nbr->src.s_addr) > ntohl (nbr_addr->s_addr)) |
| 2109 | { |
| 2110 | if (! min) |
| 2111 | min = nbr; |
| 2112 | else if (ntohl (nbr->src.s_addr) < ntohl (min->src.s_addr)) |
| 2113 | min = nbr; |
| 2114 | } |
| 2115 | } |
| 2116 | } |
| 2117 | if (min) |
| 2118 | { |
| 2119 | *nbr_addr = min->src; |
| 2120 | *ifindex = 0; |
| 2121 | return min; |
| 2122 | } |
| 2123 | return NULL; |
| 2124 | } |
| 2125 | |
| 2126 | struct ospf_neighbor * |
| 2127 | ospfNbrLookup (struct variable *v, oid *name, size_t *length, |
| 2128 | struct in_addr *nbr_addr, unsigned int *ifindex, int exact) |
| 2129 | { |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 2130 | unsigned int len; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2131 | int first; |
| 2132 | struct ospf_neighbor *nbr; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2133 | struct ospf *ospf; |
| 2134 | |
| 2135 | ospf = ospf_lookup (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2136 | |
hasso | 1b63904 | 2005-03-27 13:32:25 +0000 | [diff] [blame] | 2137 | if (! ospf) |
| 2138 | return NULL; |
| 2139 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2140 | if (exact) |
| 2141 | { |
| 2142 | if (*length != v->namelen + IN_ADDR_SIZE + 1) |
| 2143 | return NULL; |
| 2144 | |
| 2145 | oid2in_addr (name + v->namelen, IN_ADDR_SIZE, nbr_addr); |
| 2146 | *ifindex = name[v->namelen + IN_ADDR_SIZE]; |
| 2147 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2148 | return ospf_snmp_nbr_lookup (ospf, nbr_addr, ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2149 | } |
| 2150 | else |
| 2151 | { |
| 2152 | first = 0; |
| 2153 | len = *length - v->namelen; |
| 2154 | |
| 2155 | if (len <= 0) |
| 2156 | first = 1; |
| 2157 | |
| 2158 | if (len > IN_ADDR_SIZE) |
| 2159 | len = IN_ADDR_SIZE; |
| 2160 | |
| 2161 | oid2in_addr (name + v->namelen, len, nbr_addr); |
| 2162 | |
| 2163 | len = *length - v->namelen - IN_ADDR_SIZE; |
| 2164 | if (len >= 1) |
| 2165 | *ifindex = name[v->namelen + IN_ADDR_SIZE]; |
| 2166 | |
| 2167 | nbr = ospf_snmp_nbr_lookup_next (nbr_addr, ifindex, first); |
| 2168 | |
| 2169 | if (nbr) |
| 2170 | { |
| 2171 | *length = v->namelen + IN_ADDR_SIZE + 1; |
| 2172 | oid_copy_addr (name + v->namelen, nbr_addr, IN_ADDR_SIZE); |
| 2173 | name[v->namelen + IN_ADDR_SIZE] = *ifindex; |
| 2174 | return nbr; |
| 2175 | } |
| 2176 | } |
| 2177 | return NULL; |
| 2178 | } |
| 2179 | |
| 2180 | static u_char * |
| 2181 | ospfNbrEntry (struct variable *v, oid *name, size_t *length, int exact, |
| 2182 | size_t *var_len, WriteMethod **write_method) |
| 2183 | { |
| 2184 | struct in_addr nbr_addr; |
| 2185 | unsigned int ifindex; |
| 2186 | struct ospf_neighbor *nbr; |
| 2187 | struct ospf_interface *oi; |
| 2188 | |
| 2189 | memset (&nbr_addr, 0, sizeof (struct in_addr)); |
| 2190 | ifindex = 0; |
| 2191 | |
| 2192 | nbr = ospfNbrLookup (v, name, length, &nbr_addr, &ifindex, exact); |
| 2193 | if (! nbr) |
| 2194 | return NULL; |
| 2195 | oi = nbr->oi; |
| 2196 | if (! oi) |
| 2197 | return NULL; |
| 2198 | |
| 2199 | /* Return the current value of the variable */ |
| 2200 | switch (v->magic) |
| 2201 | { |
| 2202 | case OSPFNBRIPADDR: |
| 2203 | return SNMP_IPADDRESS (nbr_addr); |
| 2204 | break; |
| 2205 | case OSPFNBRADDRESSLESSINDEX: |
| 2206 | return SNMP_INTEGER (ifindex); |
| 2207 | break; |
| 2208 | case OSPFNBRRTRID: |
| 2209 | return SNMP_IPADDRESS (nbr->router_id); |
| 2210 | break; |
| 2211 | case OSPFNBROPTIONS: |
| 2212 | return SNMP_INTEGER (oi->nbr_self->options); |
| 2213 | break; |
| 2214 | case OSPFNBRPRIORITY: |
| 2215 | return SNMP_INTEGER (nbr->priority); |
| 2216 | break; |
| 2217 | case OSPFNBRSTATE: |
| 2218 | return SNMP_INTEGER (nbr->state); |
| 2219 | break; |
| 2220 | case OSPFNBREVENTS: |
| 2221 | return SNMP_INTEGER (nbr->state_change); |
| 2222 | break; |
| 2223 | case OSPFNBRLSRETRANSQLEN: |
| 2224 | return SNMP_INTEGER (ospf_ls_retransmit_count (nbr)); |
| 2225 | break; |
| 2226 | case OSPFNBMANBRSTATUS: |
| 2227 | return SNMP_INTEGER (SNMP_VALID); |
| 2228 | break; |
| 2229 | case OSPFNBMANBRPERMANENCE: |
| 2230 | return SNMP_INTEGER (2); |
| 2231 | break; |
| 2232 | case OSPFNBRHELLOSUPPRESSED: |
| 2233 | return SNMP_INTEGER (SNMP_FALSE); |
| 2234 | break; |
| 2235 | default: |
| 2236 | return NULL; |
| 2237 | break; |
| 2238 | } |
| 2239 | return NULL; |
| 2240 | } |
| 2241 | |
| 2242 | static u_char * |
| 2243 | ospfVirtNbrEntry (struct variable *v, oid *name, size_t *length, int exact, |
| 2244 | size_t *var_len, WriteMethod **write_method) |
| 2245 | { |
| 2246 | struct ospf_vl_data *vl_data; |
| 2247 | struct in_addr area_id; |
| 2248 | struct in_addr neighbor; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2249 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2250 | |
| 2251 | memset (&area_id, 0, sizeof (struct in_addr)); |
| 2252 | memset (&neighbor, 0, sizeof (struct in_addr)); |
| 2253 | |
| 2254 | /* Check OSPF instance. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2255 | ospf = ospf_lookup (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2256 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2257 | return NULL; |
| 2258 | |
| 2259 | vl_data = ospfVirtIfLookup (v, name, length, &area_id, &neighbor, exact); |
| 2260 | if (! vl_data) |
| 2261 | return NULL; |
| 2262 | |
| 2263 | /* Return the current value of the variable */ |
| 2264 | switch (v->magic) |
| 2265 | { |
| 2266 | case OSPFVIRTNBRAREA: |
| 2267 | return (u_char *) NULL; |
| 2268 | break; |
| 2269 | case OSPFVIRTNBRRTRID: |
| 2270 | return (u_char *) NULL; |
| 2271 | break; |
| 2272 | case OSPFVIRTNBRIPADDR: |
| 2273 | return (u_char *) NULL; |
| 2274 | break; |
| 2275 | case OSPFVIRTNBROPTIONS: |
| 2276 | return (u_char *) NULL; |
| 2277 | break; |
| 2278 | case OSPFVIRTNBRSTATE: |
| 2279 | return (u_char *) NULL; |
| 2280 | break; |
| 2281 | case OSPFVIRTNBREVENTS: |
| 2282 | return (u_char *) NULL; |
| 2283 | break; |
| 2284 | case OSPFVIRTNBRLSRETRANSQLEN: |
| 2285 | return (u_char *) NULL; |
| 2286 | break; |
| 2287 | case OSPFVIRTNBRHELLOSUPPRESSED: |
| 2288 | return (u_char *) NULL; |
| 2289 | break; |
| 2290 | default: |
| 2291 | return NULL; |
| 2292 | break; |
| 2293 | } |
| 2294 | return NULL; |
| 2295 | } |
| 2296 | |
| 2297 | struct ospf_lsa * |
| 2298 | ospfExtLsdbLookup (struct variable *v, oid *name, size_t *length, u_char *type, |
| 2299 | struct in_addr *ls_id, struct in_addr *router_id, int exact) |
| 2300 | { |
| 2301 | int first; |
| 2302 | oid *offset; |
| 2303 | int offsetlen; |
| 2304 | u_char lsa_type; |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 2305 | unsigned int len; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2306 | struct ospf_lsa *lsa; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2307 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2308 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2309 | ospf = ospf_lookup (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2310 | if (exact) |
| 2311 | { |
| 2312 | if (*length != v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE) |
| 2313 | return NULL; |
| 2314 | |
| 2315 | offset = name + v->namelen; |
| 2316 | |
| 2317 | /* Make it sure given value match to type. */ |
| 2318 | lsa_type = *offset; |
| 2319 | offset++; |
| 2320 | |
| 2321 | if (lsa_type != *type) |
| 2322 | return NULL; |
| 2323 | |
| 2324 | /* LS ID. */ |
| 2325 | oid2in_addr (offset, IN_ADDR_SIZE, ls_id); |
| 2326 | offset += IN_ADDR_SIZE; |
| 2327 | |
| 2328 | /* Router ID. */ |
| 2329 | oid2in_addr (offset, IN_ADDR_SIZE, router_id); |
| 2330 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2331 | return ospf_lsdb_lookup_by_id (ospf->lsdb, *type, *ls_id, *router_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2332 | } |
| 2333 | else |
| 2334 | { |
| 2335 | /* Get variable length. */ |
| 2336 | first = 0; |
| 2337 | offset = name + v->namelen; |
| 2338 | offsetlen = *length - v->namelen; |
| 2339 | |
| 2340 | /* LSA type value. */ |
| 2341 | lsa_type = *offset; |
| 2342 | offset++; |
| 2343 | offsetlen--; |
| 2344 | |
| 2345 | if (offsetlen <= 0 || lsa_type < OSPF_AS_EXTERNAL_LSA) |
| 2346 | first = 1; |
| 2347 | |
| 2348 | /* LS ID. */ |
| 2349 | len = offsetlen; |
| 2350 | if (len > IN_ADDR_SIZE) |
| 2351 | len = IN_ADDR_SIZE; |
| 2352 | |
| 2353 | oid2in_addr (offset, len, ls_id); |
| 2354 | |
| 2355 | offset += IN_ADDR_SIZE; |
| 2356 | offsetlen -= IN_ADDR_SIZE; |
| 2357 | |
| 2358 | /* Router ID. */ |
| 2359 | len = offsetlen; |
| 2360 | if (len > IN_ADDR_SIZE) |
| 2361 | len = IN_ADDR_SIZE; |
| 2362 | |
| 2363 | oid2in_addr (offset, len, router_id); |
| 2364 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2365 | lsa = ospf_lsdb_lookup_by_id_next (ospf->lsdb, *type, *ls_id, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2366 | *router_id, first); |
| 2367 | |
| 2368 | if (lsa) |
| 2369 | { |
| 2370 | /* Fill in length. */ |
| 2371 | *length = v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE; |
| 2372 | |
| 2373 | /* Fill in value. */ |
| 2374 | offset = name + v->namelen; |
| 2375 | |
| 2376 | *offset = OSPF_AS_EXTERNAL_LSA; |
| 2377 | offset++; |
| 2378 | oid_copy_addr (offset, &lsa->data->id, IN_ADDR_SIZE); |
| 2379 | offset += IN_ADDR_SIZE; |
| 2380 | oid_copy_addr (offset, &lsa->data->adv_router, IN_ADDR_SIZE); |
| 2381 | |
| 2382 | return lsa; |
| 2383 | } |
| 2384 | } |
| 2385 | return NULL; |
| 2386 | } |
| 2387 | |
| 2388 | static u_char * |
| 2389 | ospfExtLsdbEntry (struct variable *v, oid *name, size_t *length, int exact, |
| 2390 | size_t *var_len, WriteMethod **write_method) |
| 2391 | { |
| 2392 | struct ospf_lsa *lsa; |
| 2393 | struct lsa_header *lsah; |
| 2394 | u_char type; |
| 2395 | struct in_addr ls_id; |
| 2396 | struct in_addr router_id; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2397 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2398 | |
| 2399 | type = OSPF_AS_EXTERNAL_LSA; |
| 2400 | memset (&ls_id, 0, sizeof (struct in_addr)); |
| 2401 | memset (&router_id, 0, sizeof (struct in_addr)); |
| 2402 | |
| 2403 | /* Check OSPF instance. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2404 | ospf = ospf_lookup (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2405 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2406 | return NULL; |
| 2407 | |
| 2408 | lsa = ospfExtLsdbLookup (v, name, length, &type, &ls_id, &router_id, exact); |
| 2409 | if (! lsa) |
| 2410 | return NULL; |
| 2411 | |
| 2412 | lsah = lsa->data; |
| 2413 | |
| 2414 | /* Return the current value of the variable */ |
| 2415 | switch (v->magic) |
| 2416 | { |
| 2417 | case OSPFEXTLSDBTYPE: |
| 2418 | return SNMP_INTEGER (OSPF_AS_EXTERNAL_LSA); |
| 2419 | break; |
| 2420 | case OSPFEXTLSDBLSID: |
| 2421 | return SNMP_IPADDRESS (lsah->id); |
| 2422 | break; |
| 2423 | case OSPFEXTLSDBROUTERID: |
| 2424 | return SNMP_IPADDRESS (lsah->adv_router); |
| 2425 | break; |
| 2426 | case OSPFEXTLSDBSEQUENCE: |
| 2427 | return SNMP_INTEGER (lsah->ls_seqnum); |
| 2428 | break; |
| 2429 | case OSPFEXTLSDBAGE: |
| 2430 | return SNMP_INTEGER (lsah->ls_age); |
| 2431 | break; |
| 2432 | case OSPFEXTLSDBCHECKSUM: |
| 2433 | return SNMP_INTEGER (lsah->checksum); |
| 2434 | break; |
| 2435 | case OSPFEXTLSDBADVERTISEMENT: |
| 2436 | *var_len = ntohs (lsah->length); |
| 2437 | return (u_char *) lsah; |
| 2438 | break; |
| 2439 | default: |
| 2440 | return NULL; |
| 2441 | break; |
| 2442 | } |
| 2443 | return NULL; |
| 2444 | } |
| 2445 | |
| 2446 | static u_char * |
| 2447 | ospfAreaAggregateEntry (struct variable *v, oid *name, size_t *length, |
| 2448 | int exact, size_t *var_len, WriteMethod **write_method) |
| 2449 | { |
| 2450 | /* Return the current value of the variable */ |
| 2451 | switch (v->magic) |
| 2452 | { |
| 2453 | case OSPFAREAAGGREGATEAREAID: |
| 2454 | return (u_char *) NULL; |
| 2455 | break; |
| 2456 | case OSPFAREAAGGREGATELSDBTYPE: |
| 2457 | return (u_char *) NULL; |
| 2458 | break; |
| 2459 | case OSPFAREAAGGREGATENET: |
| 2460 | return (u_char *) NULL; |
| 2461 | break; |
| 2462 | case OSPFAREAAGGREGATEMASK: |
| 2463 | return (u_char *) NULL; |
| 2464 | break; |
| 2465 | case OSPFAREAAGGREGATESTATUS: |
| 2466 | return (u_char *) NULL; |
| 2467 | break; |
| 2468 | case OSPFAREAAGGREGATEEFFECT: |
| 2469 | return (u_char *) NULL; |
| 2470 | break; |
| 2471 | default: |
| 2472 | return NULL; |
| 2473 | break; |
| 2474 | } |
| 2475 | return NULL; |
| 2476 | } |
| 2477 | |
| 2478 | /* Register OSPF2-MIB. */ |
| 2479 | void |
| 2480 | ospf_snmp_init () |
| 2481 | { |
| 2482 | ospf_snmp_iflist = list_new (); |
| 2483 | ospf_snmp_vl_table = route_table_init (); |
hasso | c75105a | 2004-10-13 10:33:26 +0000 | [diff] [blame] | 2484 | smux_init (om->master); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2485 | REGISTER_MIB("mibII/ospf", ospf_variables, variable, ospf_oid); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2486 | } |
| 2487 | #endif /* HAVE_SNMP */ |