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