2 * Copyright 2008 Juan Lang
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(inetmib1
);
37 static DWORD
copyInt(AsnAny
*value
, void *src
)
39 value
->asnType
= ASN_INTEGER
;
40 value
->asnValue
.number
= *(DWORD
*)src
;
41 return SNMP_ERRORSTATUS_NOERROR
;
44 static void setStringValue(AsnAny
*value
, BYTE type
, DWORD len
, BYTE
*str
)
48 strValue
.asnType
= type
;
49 strValue
.asnValue
.string
.stream
= str
;
50 strValue
.asnValue
.string
.length
= len
;
51 strValue
.asnValue
.string
.dynamic
= FALSE
;
52 SnmpUtilAsnAnyCpy(value
, &strValue
);
55 typedef DWORD (*copyValueFunc
)(AsnAny
*value
, void *src
);
57 struct structToAsnValue
63 static AsnInteger32
mapStructEntryToValue(struct structToAsnValue
*map
,
64 UINT mapLen
, void *record
, UINT id
, SnmpVarBind
*pVarBind
)
66 /* OIDs are 1-based */
68 return SNMP_ERRORSTATUS_NOSUCHNAME
;
71 return SNMP_ERRORSTATUS_NOSUCHNAME
;
73 return SNMP_ERRORSTATUS_NOSUCHNAME
;
74 return map
[id
].copy(&pVarBind
->value
, (BYTE
*)record
+ map
[id
].offset
);
77 static DWORD
copyIpAddr(AsnAny
*value
, void *src
)
79 setStringValue(value
, ASN_IPADDRESS
, sizeof(DWORD
), src
);
80 return SNMP_ERRORSTATUS_NOERROR
;
83 static UINT mib2
[] = { 1,3,6,1,2,1 };
84 static UINT mib2System
[] = { 1,3,6,1,2,1,1 };
86 typedef BOOL (*varqueryfunc
)(BYTE bPduType
, SnmpVarBind
*pVarBind
,
87 AsnInteger32
*pErrorStatus
);
89 struct mibImplementation
91 AsnObjectIdentifier name
;
94 void (*cleanup
)(void);
97 static UINT mib2IfNumber
[] = { 1,3,6,1,2,1,2,1 };
98 static PMIB_IFTABLE ifTable
;
100 static void mib2IfNumberInit(void)
102 DWORD size
= 0, ret
= GetIfTable(NULL
, &size
, FALSE
);
104 if (ret
== ERROR_INSUFFICIENT_BUFFER
)
106 MIB_IFTABLE
*table
= HeapAlloc(GetProcessHeap(), 0, size
);
109 if (!GetIfTable(table
, &size
, FALSE
)) ifTable
= table
;
110 else HeapFree(GetProcessHeap(), 0, table
);
115 static void mib2IfNumberCleanup(void)
117 HeapFree(GetProcessHeap(), 0, ifTable
);
120 static BOOL
mib2IfNumberQuery(BYTE bPduType
, SnmpVarBind
*pVarBind
,
121 AsnInteger32
*pErrorStatus
)
123 AsnObjectIdentifier numberOid
= DEFINE_OID(mib2IfNumber
);
126 TRACE("(0x%02x, %s, %p)\n", bPduType
, SnmpUtilOidToA(&pVarBind
->name
),
132 case SNMP_PDU_GETNEXT
:
133 if ((bPduType
== SNMP_PDU_GET
&&
134 !SnmpUtilOidNCmp(&pVarBind
->name
, &numberOid
, numberOid
.idLength
))
135 || SnmpUtilOidNCmp(&pVarBind
->name
, &numberOid
, numberOid
.idLength
)
138 DWORD numIfs
= ifTable
? ifTable
->dwNumEntries
: 0;
140 copyInt(&pVarBind
->value
, &numIfs
);
141 if (bPduType
== SNMP_PDU_GETNEXT
)
143 SnmpUtilOidFree(&pVarBind
->name
);
144 SnmpUtilOidCpy(&pVarBind
->name
, &numberOid
);
146 *pErrorStatus
= SNMP_ERRORSTATUS_NOERROR
;
150 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
151 /* Caller deals with OID if bPduType == SNMP_PDU_GETNEXT, so don't
152 * need to set it here.
157 *pErrorStatus
= SNMP_ERRORSTATUS_READONLY
;
161 FIXME("0x%02x: unsupported PDU type\n", bPduType
);
162 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
167 static DWORD
copyOperStatus(AsnAny
*value
, void *src
)
169 value
->asnType
= ASN_INTEGER
;
170 /* The IPHlpApi definition of operational status differs from the MIB2 one,
171 * so map it to the MIB2 value.
173 switch (*(DWORD
*)src
)
175 case MIB_IF_OPER_STATUS_OPERATIONAL
:
176 value
->asnValue
.number
= MIB_IF_ADMIN_STATUS_UP
;
178 case MIB_IF_OPER_STATUS_CONNECTING
:
179 case MIB_IF_OPER_STATUS_CONNECTED
:
180 value
->asnValue
.number
= MIB_IF_ADMIN_STATUS_TESTING
;
183 value
->asnValue
.number
= MIB_IF_ADMIN_STATUS_DOWN
;
185 return SNMP_ERRORSTATUS_NOERROR
;
188 /* Given an OID and a base OID that it must begin with, finds the item and
189 * integer instance from the OID. E.g., given an OID foo.1.2 and a base OID
190 * foo, returns item 1 and instance 2.
191 * If bPduType is not SNMP_PDU_GETNEXT and either the item or instance is
192 * missing, returns SNMP_ERRORSTATUS_NOSUCHNAME.
193 * If bPduType is SNMP_PDU_GETNEXT, returns the successor to the item and
194 * instance, or item 1, instance 1 if either is missing.
196 static AsnInteger32
getItemAndIntegerInstanceFromOid(AsnObjectIdentifier
*oid
,
197 AsnObjectIdentifier
*base
, BYTE bPduType
, UINT
*item
, UINT
*instance
)
199 AsnInteger32 ret
= SNMP_ERRORSTATUS_NOERROR
;
203 case SNMP_PDU_GETNEXT
:
204 if (SnmpUtilOidNCmp(oid
, base
, base
->idLength
) < 0)
209 else if (!SnmpUtilOidNCmp(oid
, base
, base
->idLength
))
211 if (oid
->idLength
== base
->idLength
||
212 oid
->idLength
== base
->idLength
+ 1)
214 /* Either the table or an item within the table is specified,
215 * but the instance is not. Get the first instance.
218 if (oid
->idLength
== base
->idLength
+ 1)
219 *item
= oid
->ids
[base
->idLength
];
225 *item
= oid
->ids
[base
->idLength
];
226 *instance
= oid
->ids
[base
->idLength
+ 1] + 1;
230 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
233 if (!SnmpUtilOidNCmp(oid
, base
, base
->idLength
))
235 if (oid
->idLength
== base
->idLength
||
236 oid
->idLength
== base
->idLength
+ 1)
238 /* Either the table or an item within the table is specified,
239 * but the instance is not.
241 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
245 *item
= oid
->ids
[base
->idLength
];
246 *instance
= oid
->ids
[base
->idLength
+ 1];
250 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
255 /* Given an OID and a base OID that it must begin with, finds the item from the
256 * OID. E.g., given an OID foo.1 and a base OID foo, returns item 1.
257 * If bPduType is not SNMP_PDU_GETNEXT and the item is missing, returns
258 * SNMP_ERRORSTATUS_NOSUCHNAME.
259 * If bPduType is SNMP_PDU_GETNEXT, returns the successor to the item, or item
260 * 1 if the item is missing.
262 static AsnInteger32
getItemFromOid(AsnObjectIdentifier
*oid
,
263 AsnObjectIdentifier
*base
, BYTE bPduType
, UINT
*item
)
265 AsnInteger32 ret
= SNMP_ERRORSTATUS_NOERROR
;
269 case SNMP_PDU_GETNEXT
:
270 if (SnmpUtilOidNCmp(oid
, base
, base
->idLength
) < 0)
272 else if (!SnmpUtilOidNCmp(oid
, base
, base
->idLength
))
274 if (oid
->idLength
== base
->idLength
)
276 /* The item is missing, assume the first item */
280 *item
= oid
->ids
[base
->idLength
] + 1;
283 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
286 if (!SnmpUtilOidNCmp(oid
, base
, base
->idLength
))
288 if (oid
->idLength
== base
->idLength
)
290 /* The item is missing */
291 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
295 *item
= oid
->ids
[base
->idLength
];
297 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
301 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
312 static DWORD
oidToIpAddr(AsnObjectIdentifier
*oid
)
314 assert(oid
&& oid
->idLength
>= 4);
315 /* Map the IDs to an IP address in little-endian order */
316 return (BYTE
)oid
->ids
[3] << 24 | (BYTE
)oid
->ids
[2] << 16 |
317 (BYTE
)oid
->ids
[1] << 8 | (BYTE
)oid
->ids
[0];
320 typedef void (*oidToKeyFunc
)(AsnObjectIdentifier
*oid
, void *dst
);
321 typedef int (*compareFunc
)(const void *key
, const void *value
);
323 /* Finds the first value in the table that matches key. Returns its 1-based
324 * index if found, or 0 if not found.
326 static UINT
findValueInTable(const void *key
,
327 struct GenericTable
*table
, size_t tableEntrySize
, compareFunc compare
)
332 value
= bsearch(key
, table
->entries
, table
->numEntries
, tableEntrySize
,
335 index
= ((BYTE
*)value
- (BYTE
*)table
->entries
) / tableEntrySize
+ 1;
339 /* Finds the first value in the table that matches oid, using makeKey to
340 * convert the oid to a key for comparison. Returns the value's 1-based
341 * index if found, or 0 if not found.
343 static UINT
findOidInTable(AsnObjectIdentifier
*oid
,
344 struct GenericTable
*table
, size_t tableEntrySize
, oidToKeyFunc makeKey
,
348 void *key
= HeapAlloc(GetProcessHeap(), 0, tableEntrySize
);
353 index
= findValueInTable(key
, table
, tableEntrySize
, compare
);
354 HeapFree(GetProcessHeap(), 0, key
);
359 /* Finds the first successor to the value in the table that does matches oid,
360 * using makeKey to convert the oid to a key for comparison. A successor is
361 * a value that does not match oid, so if multiple entries match an oid, only
362 * the first will ever be returned using this method.
363 * Returns the successor's 1-based index if found, or 0 if not found.
365 static UINT
findNextOidInTable(AsnObjectIdentifier
*oid
,
366 struct GenericTable
*table
, size_t tableEntrySize
, oidToKeyFunc makeKey
,
370 void *key
= HeapAlloc(GetProcessHeap(), 0, tableEntrySize
);
375 index
= findValueInTable(key
, table
, tableEntrySize
, compare
);
378 /* Not found in table. If it's less than the first entry, return
379 * the first index. Otherwise just return 0 and let the caller
380 * handle finding the successor.
382 if (compare(key
, table
->entries
) < 0)
387 /* Skip any entries that match the same key. This enumeration will
388 * be incomplete, but it's what Windows appears to do if there are
389 * multiple entries with the same index in a table, and it avoids
392 for (++index
; index
<= table
->numEntries
&& compare(key
,
393 &table
->entries
[tableEntrySize
* (index
- 1)]) == 0; ++index
)
396 HeapFree(GetProcessHeap(), 0, key
);
401 /* Given an OID and a base OID that it must begin with, finds the item and
402 * element of the table whose value matches the instance from the OID.
403 * The OID is converted to a key with the function makeKey, and compared
404 * against entries in the table with the function compare.
405 * If bPduType is not SNMP_PDU_GETNEXT and either the item or instance is
406 * missing, returns SNMP_ERRORSTATUS_NOSUCHNAME.
407 * If bPduType is SNMP_PDU_GETNEXT, returns the successor to the item and
408 * instance, or item 1, instance 1 if either is missing.
410 static AsnInteger32
getItemAndInstanceFromTable(AsnObjectIdentifier
*oid
,
411 AsnObjectIdentifier
*base
, UINT instanceLen
, BYTE bPduType
,
412 struct GenericTable
*table
, size_t tableEntrySize
, oidToKeyFunc makeKey
,
413 compareFunc compare
, UINT
*item
, UINT
*instance
)
415 AsnInteger32 ret
= SNMP_ERRORSTATUS_NOERROR
;
418 return SNMP_ERRORSTATUS_NOSUCHNAME
;
422 case SNMP_PDU_GETNEXT
:
423 if (SnmpUtilOidNCmp(oid
, base
, base
->idLength
) < 0)
425 /* Return the first item and instance from the table */
429 else if (!SnmpUtilOidNCmp(oid
, base
, base
->idLength
) &&
430 oid
->idLength
< base
->idLength
+ instanceLen
+ 1)
432 /* Either the table or an item is specified, but the instance is
436 if (oid
->idLength
>= base
->idLength
+ 1)
438 *item
= oid
->ids
[base
->idLength
];
445 else if (!SnmpUtilOidNCmp(oid
, base
, base
->idLength
) &&
446 oid
->idLength
== base
->idLength
+ instanceLen
+ 1)
448 *item
= oid
->ids
[base
->idLength
];
456 AsnObjectIdentifier instanceOid
= { instanceLen
,
457 oid
->ids
+ base
->idLength
+ 1 };
459 *instance
= findNextOidInTable(&instanceOid
, table
,
460 tableEntrySize
, makeKey
, compare
);
461 if (!*instance
|| *instance
> table
->numEntries
)
462 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
466 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
469 if (!SnmpUtilOidNCmp(oid
, base
, base
->idLength
) &&
470 oid
->idLength
== base
->idLength
+ instanceLen
+ 1)
472 *item
= oid
->ids
[base
->idLength
];
474 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
477 AsnObjectIdentifier instanceOid
= { instanceLen
,
478 oid
->ids
+ base
->idLength
+ 1 };
480 *instance
= findOidInTable(&instanceOid
, table
, tableEntrySize
,
483 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
487 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
492 static INT
setOidWithItem(AsnObjectIdentifier
*dst
, AsnObjectIdentifier
*base
,
496 AsnObjectIdentifier oid
;
499 SnmpUtilOidFree(dst
);
500 ret
= SnmpUtilOidCpy(dst
, base
);
506 ret
= SnmpUtilOidAppend(dst
, &oid
);
511 static INT
setOidWithItemAndIpAddr(AsnObjectIdentifier
*dst
,
512 AsnObjectIdentifier
*base
, UINT item
, DWORD addr
)
516 AsnObjectIdentifier oid
;
519 ret
= setOidWithItem(dst
, base
, item
);
524 for (ptr
= (BYTE
*)&addr
; ret
&& ptr
< (BYTE
*)&addr
+ sizeof(DWORD
);
528 ret
= SnmpUtilOidAppend(dst
, &oid
);
534 static INT
setOidWithItemAndInteger(AsnObjectIdentifier
*dst
,
535 AsnObjectIdentifier
*base
, UINT item
, UINT instance
)
537 AsnObjectIdentifier oid
;
540 ret
= setOidWithItem(dst
, base
, item
);
545 ret
= SnmpUtilOidAppend(dst
, &oid
);
550 static DWORD
copyIfRowDescr(AsnAny
*value
, void *src
)
552 PMIB_IFROW row
= (PMIB_IFROW
)((BYTE
*)src
-
553 FIELD_OFFSET(MIB_IFROW
, dwDescrLen
));
558 setStringValue(value
, ASN_OCTETSTRING
, row
->dwDescrLen
, row
->bDescr
);
559 ret
= SNMP_ERRORSTATUS_NOERROR
;
562 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
566 static DWORD
copyIfRowPhysAddr(AsnAny
*value
, void *src
)
568 PMIB_IFROW row
= (PMIB_IFROW
)((BYTE
*)src
-
569 FIELD_OFFSET(MIB_IFROW
, dwPhysAddrLen
));
572 if (row
->dwPhysAddrLen
)
574 setStringValue(value
, ASN_OCTETSTRING
, row
->dwPhysAddrLen
,
576 ret
= SNMP_ERRORSTATUS_NOERROR
;
579 ret
= SNMP_ERRORSTATUS_NOSUCHNAME
;
583 static struct structToAsnValue mib2IfEntryMap
[] = {
584 { FIELD_OFFSET(MIB_IFROW
, dwIndex
), copyInt
},
585 { FIELD_OFFSET(MIB_IFROW
, dwDescrLen
), copyIfRowDescr
},
586 { FIELD_OFFSET(MIB_IFROW
, dwType
), copyInt
},
587 { FIELD_OFFSET(MIB_IFROW
, dwMtu
), copyInt
},
588 { FIELD_OFFSET(MIB_IFROW
, dwSpeed
), copyInt
},
589 { FIELD_OFFSET(MIB_IFROW
, dwPhysAddrLen
), copyIfRowPhysAddr
},
590 { FIELD_OFFSET(MIB_IFROW
, dwAdminStatus
), copyInt
},
591 { FIELD_OFFSET(MIB_IFROW
, dwOperStatus
), copyOperStatus
},
592 { FIELD_OFFSET(MIB_IFROW
, dwLastChange
), copyInt
},
593 { FIELD_OFFSET(MIB_IFROW
, dwInOctets
), copyInt
},
594 { FIELD_OFFSET(MIB_IFROW
, dwInUcastPkts
), copyInt
},
595 { FIELD_OFFSET(MIB_IFROW
, dwInNUcastPkts
), copyInt
},
596 { FIELD_OFFSET(MIB_IFROW
, dwInDiscards
), copyInt
},
597 { FIELD_OFFSET(MIB_IFROW
, dwInErrors
), copyInt
},
598 { FIELD_OFFSET(MIB_IFROW
, dwInUnknownProtos
), copyInt
},
599 { FIELD_OFFSET(MIB_IFROW
, dwOutOctets
), copyInt
},
600 { FIELD_OFFSET(MIB_IFROW
, dwOutUcastPkts
), copyInt
},
601 { FIELD_OFFSET(MIB_IFROW
, dwOutNUcastPkts
), copyInt
},
602 { FIELD_OFFSET(MIB_IFROW
, dwOutDiscards
), copyInt
},
603 { FIELD_OFFSET(MIB_IFROW
, dwOutErrors
), copyInt
},
604 { FIELD_OFFSET(MIB_IFROW
, dwOutQLen
), copyInt
},
607 static UINT mib2IfEntry
[] = { 1,3,6,1,2,1,2,2,1 };
609 static BOOL
mib2IfEntryQuery(BYTE bPduType
, SnmpVarBind
*pVarBind
,
610 AsnInteger32
*pErrorStatus
)
612 AsnObjectIdentifier entryOid
= DEFINE_OID(mib2IfEntry
);
615 TRACE("(0x%02x, %s, %p)\n", bPduType
, SnmpUtilOidToA(&pVarBind
->name
),
621 case SNMP_PDU_GETNEXT
:
624 /* There is no interface present, so let the caller deal
625 * with finding the successor.
627 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
631 UINT tableIndex
= 0, item
= 0;
633 *pErrorStatus
= getItemAndIntegerInstanceFromOid(&pVarBind
->name
,
634 &entryOid
, bPduType
, &item
, &tableIndex
);
639 if (tableIndex
> ifTable
->dwNumEntries
)
640 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
643 *pErrorStatus
= mapStructEntryToValue(mib2IfEntryMap
,
644 DEFINE_SIZEOF(mib2IfEntryMap
),
645 &ifTable
->table
[tableIndex
- 1], item
,
647 if (bPduType
== SNMP_PDU_GETNEXT
)
648 ret
= setOidWithItemAndInteger(&pVarBind
->name
,
649 &entryOid
, item
, tableIndex
);
655 *pErrorStatus
= SNMP_ERRORSTATUS_READONLY
;
659 FIXME("0x%02x: unsupported PDU type\n", bPduType
);
660 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
665 static UINT mib2Ip
[] = { 1,3,6,1,2,1,4 };
666 static MIB_IPSTATS ipStats
;
668 static void mib2IpStatsInit(void)
670 GetIpStatistics(&ipStats
);
673 static struct structToAsnValue mib2IpMap
[] = {
674 { FIELD_OFFSET(MIB_IPSTATS
, u
.dwForwarding
), copyInt
}, /* 1 */
675 { FIELD_OFFSET(MIB_IPSTATS
, dwDefaultTTL
), copyInt
}, /* 2 */
676 { FIELD_OFFSET(MIB_IPSTATS
, dwInReceives
), copyInt
}, /* 3 */
677 { FIELD_OFFSET(MIB_IPSTATS
, dwInHdrErrors
), copyInt
}, /* 4 */
678 { FIELD_OFFSET(MIB_IPSTATS
, dwInAddrErrors
), copyInt
}, /* 5 */
679 { FIELD_OFFSET(MIB_IPSTATS
, dwForwDatagrams
), copyInt
}, /* 6 */
680 { FIELD_OFFSET(MIB_IPSTATS
, dwInUnknownProtos
), copyInt
}, /* 7 */
681 { FIELD_OFFSET(MIB_IPSTATS
, dwInDiscards
), copyInt
}, /* 8 */
682 { FIELD_OFFSET(MIB_IPSTATS
, dwInDelivers
), copyInt
}, /* 9 */
683 { FIELD_OFFSET(MIB_IPSTATS
, dwOutRequests
), copyInt
}, /* 10 */
684 { FIELD_OFFSET(MIB_IPSTATS
, dwOutDiscards
), copyInt
}, /* 11 */
685 { FIELD_OFFSET(MIB_IPSTATS
, dwOutNoRoutes
), copyInt
}, /* 12 */
686 { FIELD_OFFSET(MIB_IPSTATS
, dwReasmTimeout
), copyInt
}, /* 13 */
687 { FIELD_OFFSET(MIB_IPSTATS
, dwReasmReqds
), copyInt
}, /* 14 */
688 { FIELD_OFFSET(MIB_IPSTATS
, dwReasmOks
), copyInt
}, /* 15 */
689 { FIELD_OFFSET(MIB_IPSTATS
, dwReasmFails
), copyInt
}, /* 16 */
690 { FIELD_OFFSET(MIB_IPSTATS
, dwFragOks
), copyInt
}, /* 17 */
691 { FIELD_OFFSET(MIB_IPSTATS
, dwFragFails
), copyInt
}, /* 18 */
692 { FIELD_OFFSET(MIB_IPSTATS
, dwFragCreates
), copyInt
}, /* 19 */
693 { 0, NULL
}, /* 20: not used, IP addr table */
694 { 0, NULL
}, /* 21: not used, route table */
695 { 0, NULL
}, /* 22: not used, net to media (ARP) table */
696 { FIELD_OFFSET(MIB_IPSTATS
, dwRoutingDiscards
), copyInt
}, /* 23 */
699 static BOOL
mib2IpStatsQuery(BYTE bPduType
, SnmpVarBind
*pVarBind
,
700 AsnInteger32
*pErrorStatus
)
702 AsnObjectIdentifier myOid
= DEFINE_OID(mib2Ip
);
706 TRACE("(0x%02x, %s, %p)\n", bPduType
, SnmpUtilOidToA(&pVarBind
->name
),
712 case SNMP_PDU_GETNEXT
:
713 *pErrorStatus
= getItemFromOid(&pVarBind
->name
, &myOid
, bPduType
,
717 *pErrorStatus
= mapStructEntryToValue(mib2IpMap
,
718 DEFINE_SIZEOF(mib2IpMap
), &ipStats
, item
, pVarBind
);
719 if (!*pErrorStatus
&& bPduType
== SNMP_PDU_GETNEXT
)
720 ret
= setOidWithItem(&pVarBind
->name
, &myOid
, item
);
724 *pErrorStatus
= SNMP_ERRORSTATUS_READONLY
;
728 FIXME("0x%02x: unsupported PDU type\n", bPduType
);
729 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
734 static UINT mib2IpAddr
[] = { 1,3,6,1,2,1,4,20,1 };
735 static PMIB_IPADDRTABLE ipAddrTable
;
737 static struct structToAsnValue mib2IpAddrMap
[] = {
738 { FIELD_OFFSET(MIB_IPADDRROW
, dwAddr
), copyIpAddr
},
739 { FIELD_OFFSET(MIB_IPADDRROW
, dwIndex
), copyInt
},
740 { FIELD_OFFSET(MIB_IPADDRROW
, dwMask
), copyIpAddr
},
741 { FIELD_OFFSET(MIB_IPADDRROW
, dwBCastAddr
), copyInt
},
742 { FIELD_OFFSET(MIB_IPADDRROW
, dwReasmSize
), copyInt
},
745 static void mib2IpAddrInit(void)
747 DWORD size
= 0, ret
= GetIpAddrTable(NULL
, &size
, TRUE
);
749 if (ret
== ERROR_INSUFFICIENT_BUFFER
)
751 MIB_IPADDRTABLE
*table
= HeapAlloc(GetProcessHeap(), 0, size
);
754 if (!GetIpAddrTable(table
, &size
, TRUE
)) ipAddrTable
= table
;
755 else HeapFree(GetProcessHeap(), 0, table
);
760 static void mib2IpAddrCleanup(void)
762 HeapFree(GetProcessHeap(), 0, ipAddrTable
);
765 static void oidToIpAddrRow(AsnObjectIdentifier
*oid
, void *dst
)
767 MIB_IPADDRROW
*row
= dst
;
769 row
->dwAddr
= oidToIpAddr(oid
);
772 static int compareIpAddrRow(const void *a
, const void *b
)
774 const MIB_IPADDRROW
*key
= a
, *value
= b
;
776 return key
->dwAddr
- value
->dwAddr
;
779 static BOOL
mib2IpAddrQuery(BYTE bPduType
, SnmpVarBind
*pVarBind
,
780 AsnInteger32
*pErrorStatus
)
782 AsnObjectIdentifier myOid
= DEFINE_OID(mib2IpAddr
);
783 UINT tableIndex
= 0, item
= 0;
786 TRACE("(0x%02x, %s, %p)\n", bPduType
, SnmpUtilOidToA(&pVarBind
->name
),
792 case SNMP_PDU_GETNEXT
:
793 *pErrorStatus
= getItemAndInstanceFromTable(&pVarBind
->name
,
794 &myOid
, 4, bPduType
, (struct GenericTable
*)ipAddrTable
,
795 sizeof(MIB_IPADDRROW
), oidToIpAddrRow
, compareIpAddrRow
, &item
,
801 *pErrorStatus
= mapStructEntryToValue(mib2IpAddrMap
,
802 DEFINE_SIZEOF(mib2IpAddrMap
),
803 &ipAddrTable
->table
[tableIndex
- 1], item
, pVarBind
);
804 if (!*pErrorStatus
&& bPduType
== SNMP_PDU_GETNEXT
)
805 ret
= setOidWithItemAndIpAddr(&pVarBind
->name
, &myOid
, item
,
806 ipAddrTable
->table
[tableIndex
- 1].dwAddr
);
810 *pErrorStatus
= SNMP_ERRORSTATUS_READONLY
;
814 FIXME("0x%02x: unsupported PDU type\n", bPduType
);
815 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
820 static UINT mib2IpRoute
[] = { 1,3,6,1,2,1,4,21,1 };
821 static PMIB_IPFORWARDTABLE ipRouteTable
;
823 static struct structToAsnValue mib2IpRouteMap
[] = {
824 { FIELD_OFFSET(MIB_IPFORWARDROW
, dwForwardDest
), copyIpAddr
},
825 { FIELD_OFFSET(MIB_IPFORWARDROW
, dwForwardIfIndex
), copyInt
},
826 { FIELD_OFFSET(MIB_IPFORWARDROW
, dwForwardMetric1
), copyInt
},
827 { FIELD_OFFSET(MIB_IPFORWARDROW
, dwForwardMetric2
), copyInt
},
828 { FIELD_OFFSET(MIB_IPFORWARDROW
, dwForwardMetric3
), copyInt
},
829 { FIELD_OFFSET(MIB_IPFORWARDROW
, dwForwardMetric4
), copyInt
},
830 { FIELD_OFFSET(MIB_IPFORWARDROW
, dwForwardNextHop
), copyIpAddr
},
831 { FIELD_OFFSET(MIB_IPFORWARDROW
, u1
.dwForwardType
), copyInt
},
832 { FIELD_OFFSET(MIB_IPFORWARDROW
, u2
.dwForwardProto
), copyInt
},
833 { FIELD_OFFSET(MIB_IPFORWARDROW
, dwForwardAge
), copyInt
},
834 { FIELD_OFFSET(MIB_IPFORWARDROW
, dwForwardMask
), copyIpAddr
},
835 { FIELD_OFFSET(MIB_IPFORWARDROW
, dwForwardMetric5
), copyInt
},
838 static void mib2IpRouteInit(void)
840 DWORD size
= 0, ret
= GetIpForwardTable(NULL
, &size
, TRUE
);
842 if (ret
== ERROR_INSUFFICIENT_BUFFER
)
844 MIB_IPFORWARDTABLE
*table
= HeapAlloc(GetProcessHeap(), 0, size
);
847 if (!GetIpForwardTable(table
, &size
, TRUE
)) ipRouteTable
= table
;
848 else HeapFree(GetProcessHeap(), 0, table
);
853 static void mib2IpRouteCleanup(void)
855 HeapFree(GetProcessHeap(), 0, ipRouteTable
);
858 static void oidToIpForwardRow(AsnObjectIdentifier
*oid
, void *dst
)
860 MIB_IPFORWARDROW
*row
= dst
;
862 row
->dwForwardDest
= oidToIpAddr(oid
);
865 static int compareIpForwardRow(const void *a
, const void *b
)
867 const MIB_IPFORWARDROW
*key
= a
, *value
= b
;
869 return key
->dwForwardDest
- value
->dwForwardDest
;
872 static BOOL
mib2IpRouteQuery(BYTE bPduType
, SnmpVarBind
*pVarBind
,
873 AsnInteger32
*pErrorStatus
)
875 AsnObjectIdentifier myOid
= DEFINE_OID(mib2IpRoute
);
876 UINT tableIndex
= 0, item
= 0;
879 TRACE("(0x%02x, %s, %p)\n", bPduType
, SnmpUtilOidToA(&pVarBind
->name
),
885 case SNMP_PDU_GETNEXT
:
886 *pErrorStatus
= getItemAndInstanceFromTable(&pVarBind
->name
,
887 &myOid
, 4, bPduType
, (struct GenericTable
*)ipRouteTable
,
888 sizeof(MIB_IPFORWARDROW
), oidToIpForwardRow
, compareIpForwardRow
,
894 *pErrorStatus
= mapStructEntryToValue(mib2IpRouteMap
,
895 DEFINE_SIZEOF(mib2IpRouteMap
),
896 &ipRouteTable
->table
[tableIndex
- 1], item
, pVarBind
);
897 if (!*pErrorStatus
&& bPduType
== SNMP_PDU_GETNEXT
)
898 ret
= setOidWithItemAndIpAddr(&pVarBind
->name
, &myOid
, item
,
899 ipRouteTable
->table
[tableIndex
- 1].dwForwardDest
);
903 *pErrorStatus
= SNMP_ERRORSTATUS_READONLY
;
907 FIXME("0x%02x: unsupported PDU type\n", bPduType
);
908 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
913 static UINT mib2IpNet
[] = { 1,3,6,1,2,1,4,22,1 };
914 static PMIB_IPNETTABLE ipNetTable
;
916 static DWORD
copyIpNetPhysAddr(AsnAny
*value
, void *src
)
918 PMIB_IPNETROW row
= (PMIB_IPNETROW
)((BYTE
*)src
- FIELD_OFFSET(MIB_IPNETROW
,
921 setStringValue(value
, ASN_OCTETSTRING
, row
->dwPhysAddrLen
, row
->bPhysAddr
);
922 return SNMP_ERRORSTATUS_NOERROR
;
925 static struct structToAsnValue mib2IpNetMap
[] = {
926 { FIELD_OFFSET(MIB_IPNETROW
, dwIndex
), copyInt
},
927 { FIELD_OFFSET(MIB_IPNETROW
, dwPhysAddrLen
), copyIpNetPhysAddr
},
928 { FIELD_OFFSET(MIB_IPNETROW
, dwAddr
), copyIpAddr
},
929 { FIELD_OFFSET(MIB_IPNETROW
, u
.dwType
), copyInt
},
932 static void mib2IpNetInit(void)
934 DWORD size
= 0, ret
= GetIpNetTable(NULL
, &size
, FALSE
);
936 if (ret
== ERROR_INSUFFICIENT_BUFFER
)
938 MIB_IPNETTABLE
*table
= HeapAlloc(GetProcessHeap(), 0, size
);
941 if (!GetIpNetTable(table
, &size
, FALSE
)) ipNetTable
= table
;
942 else HeapFree(GetProcessHeap(), 0, table
);
947 static void mib2IpNetCleanup(void)
949 HeapFree(GetProcessHeap(), 0, ipNetTable
);
952 static BOOL
mib2IpNetQuery(BYTE bPduType
, SnmpVarBind
*pVarBind
,
953 AsnInteger32
*pErrorStatus
)
955 AsnObjectIdentifier myOid
= DEFINE_OID(mib2IpNet
);
958 TRACE("(0x%02x, %s, %p)\n", bPduType
, SnmpUtilOidToA(&pVarBind
->name
),
964 case SNMP_PDU_GETNEXT
:
966 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
969 UINT tableIndex
= 0, item
= 0;
971 *pErrorStatus
= getItemAndIntegerInstanceFromOid(&pVarBind
->name
,
972 &myOid
, bPduType
, &item
, &tableIndex
);
977 if (tableIndex
> ipNetTable
->dwNumEntries
)
978 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
981 *pErrorStatus
= mapStructEntryToValue(mib2IpNetMap
,
982 DEFINE_SIZEOF(mib2IpNetMap
),
983 &ipNetTable
[tableIndex
- 1], item
, pVarBind
);
984 if (!*pErrorStatus
&& bPduType
== SNMP_PDU_GETNEXT
)
985 ret
= setOidWithItemAndInteger(&pVarBind
->name
, &myOid
,
992 *pErrorStatus
= SNMP_ERRORSTATUS_READONLY
;
996 FIXME("0x%02x: unsupported PDU type\n", bPduType
);
997 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
1002 static UINT mib2Icmp
[] = { 1,3,6,1,2,1,5 };
1003 static MIB_ICMP icmpStats
;
1005 static void mib2IcmpInit(void)
1007 GetIcmpStatistics(&icmpStats
);
1010 static struct structToAsnValue mib2IcmpMap
[] = {
1011 { FIELD_OFFSET(MIBICMPINFO
, icmpInStats
.dwMsgs
), copyInt
},
1012 { FIELD_OFFSET(MIBICMPINFO
, icmpInStats
.dwErrors
), copyInt
},
1013 { FIELD_OFFSET(MIBICMPINFO
, icmpInStats
.dwDestUnreachs
), copyInt
},
1014 { FIELD_OFFSET(MIBICMPINFO
, icmpInStats
.dwTimeExcds
), copyInt
},
1015 { FIELD_OFFSET(MIBICMPINFO
, icmpInStats
.dwParmProbs
), copyInt
},
1016 { FIELD_OFFSET(MIBICMPINFO
, icmpInStats
.dwSrcQuenchs
), copyInt
},
1017 { FIELD_OFFSET(MIBICMPINFO
, icmpInStats
.dwRedirects
), copyInt
},
1018 { FIELD_OFFSET(MIBICMPINFO
, icmpInStats
.dwEchos
), copyInt
},
1019 { FIELD_OFFSET(MIBICMPINFO
, icmpInStats
.dwEchoReps
), copyInt
},
1020 { FIELD_OFFSET(MIBICMPINFO
, icmpInStats
.dwTimestamps
), copyInt
},
1021 { FIELD_OFFSET(MIBICMPINFO
, icmpInStats
.dwTimestampReps
), copyInt
},
1022 { FIELD_OFFSET(MIBICMPINFO
, icmpInStats
.dwAddrMasks
), copyInt
},
1023 { FIELD_OFFSET(MIBICMPINFO
, icmpInStats
.dwAddrMaskReps
), copyInt
},
1024 { FIELD_OFFSET(MIBICMPINFO
, icmpOutStats
.dwMsgs
), copyInt
},
1025 { FIELD_OFFSET(MIBICMPINFO
, icmpOutStats
.dwErrors
), copyInt
},
1026 { FIELD_OFFSET(MIBICMPINFO
, icmpOutStats
.dwDestUnreachs
), copyInt
},
1027 { FIELD_OFFSET(MIBICMPINFO
, icmpOutStats
.dwTimeExcds
), copyInt
},
1028 { FIELD_OFFSET(MIBICMPINFO
, icmpOutStats
.dwParmProbs
), copyInt
},
1029 { FIELD_OFFSET(MIBICMPINFO
, icmpOutStats
.dwSrcQuenchs
), copyInt
},
1030 { FIELD_OFFSET(MIBICMPINFO
, icmpOutStats
.dwRedirects
), copyInt
},
1031 { FIELD_OFFSET(MIBICMPINFO
, icmpOutStats
.dwEchos
), copyInt
},
1032 { FIELD_OFFSET(MIBICMPINFO
, icmpOutStats
.dwEchoReps
), copyInt
},
1033 { FIELD_OFFSET(MIBICMPINFO
, icmpOutStats
.dwTimestamps
), copyInt
},
1034 { FIELD_OFFSET(MIBICMPINFO
, icmpOutStats
.dwTimestampReps
), copyInt
},
1035 { FIELD_OFFSET(MIBICMPINFO
, icmpOutStats
.dwAddrMasks
), copyInt
},
1036 { FIELD_OFFSET(MIBICMPINFO
, icmpOutStats
.dwAddrMaskReps
), copyInt
},
1039 static BOOL
mib2IcmpQuery(BYTE bPduType
, SnmpVarBind
*pVarBind
,
1040 AsnInteger32
*pErrorStatus
)
1042 AsnObjectIdentifier myOid
= DEFINE_OID(mib2Icmp
);
1046 TRACE("(0x%02x, %s, %p)\n", bPduType
, SnmpUtilOidToA(&pVarBind
->name
),
1052 case SNMP_PDU_GETNEXT
:
1053 *pErrorStatus
= getItemFromOid(&pVarBind
->name
, &myOid
, bPduType
,
1057 *pErrorStatus
= mapStructEntryToValue(mib2IcmpMap
,
1058 DEFINE_SIZEOF(mib2IcmpMap
), &icmpStats
, item
,
1060 if (!*pErrorStatus
&& bPduType
== SNMP_PDU_GETNEXT
)
1061 ret
= setOidWithItem(&pVarBind
->name
, &myOid
, item
);
1065 *pErrorStatus
= SNMP_ERRORSTATUS_READONLY
;
1069 FIXME("0x%02x: unsupported PDU type\n", bPduType
);
1070 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
1075 static UINT mib2Tcp
[] = { 1,3,6,1,2,1,6 };
1076 static MIB_TCPSTATS tcpStats
;
1078 static void mib2TcpInit(void)
1080 GetTcpStatistics(&tcpStats
);
1083 static struct structToAsnValue mib2TcpMap
[] = {
1084 { FIELD_OFFSET(MIB_TCPSTATS
, u
.dwRtoAlgorithm
), copyInt
},
1085 { FIELD_OFFSET(MIB_TCPSTATS
, dwRtoMin
), copyInt
},
1086 { FIELD_OFFSET(MIB_TCPSTATS
, dwRtoMax
), copyInt
},
1087 { FIELD_OFFSET(MIB_TCPSTATS
, dwMaxConn
), copyInt
},
1088 { FIELD_OFFSET(MIB_TCPSTATS
, dwActiveOpens
), copyInt
},
1089 { FIELD_OFFSET(MIB_TCPSTATS
, dwPassiveOpens
), copyInt
},
1090 { FIELD_OFFSET(MIB_TCPSTATS
, dwAttemptFails
), copyInt
},
1091 { FIELD_OFFSET(MIB_TCPSTATS
, dwEstabResets
), copyInt
},
1092 { FIELD_OFFSET(MIB_TCPSTATS
, dwCurrEstab
), copyInt
},
1093 { FIELD_OFFSET(MIB_TCPSTATS
, dwInSegs
), copyInt
},
1094 { FIELD_OFFSET(MIB_TCPSTATS
, dwOutSegs
), copyInt
},
1095 { FIELD_OFFSET(MIB_TCPSTATS
, dwRetransSegs
), copyInt
},
1096 { FIELD_OFFSET(MIB_TCPSTATS
, dwInErrs
), copyInt
},
1097 { FIELD_OFFSET(MIB_TCPSTATS
, dwOutRsts
), copyInt
},
1098 { FIELD_OFFSET(MIB_TCPSTATS
, dwNumConns
), copyInt
},
1101 static BOOL
mib2TcpQuery(BYTE bPduType
, SnmpVarBind
*pVarBind
,
1102 AsnInteger32
*pErrorStatus
)
1104 AsnObjectIdentifier myOid
= DEFINE_OID(mib2Tcp
);
1108 TRACE("(0x%02x, %s, %p)\n", bPduType
, SnmpUtilOidToA(&pVarBind
->name
),
1114 case SNMP_PDU_GETNEXT
:
1115 *pErrorStatus
= getItemFromOid(&pVarBind
->name
, &myOid
, bPduType
,
1119 *pErrorStatus
= mapStructEntryToValue(mib2TcpMap
,
1120 DEFINE_SIZEOF(mib2TcpMap
), &tcpStats
, item
, pVarBind
);
1121 if (!*pErrorStatus
&& bPduType
== SNMP_PDU_GETNEXT
)
1122 ret
= setOidWithItem(&pVarBind
->name
, &myOid
, item
);
1126 *pErrorStatus
= SNMP_ERRORSTATUS_READONLY
;
1130 FIXME("0x%02x: unsupported PDU type\n", bPduType
);
1131 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
1136 static UINT mib2Udp
[] = { 1,3,6,1,2,1,7 };
1137 static MIB_UDPSTATS udpStats
;
1139 static void mib2UdpInit(void)
1141 GetUdpStatistics(&udpStats
);
1144 static struct structToAsnValue mib2UdpMap
[] = {
1145 { FIELD_OFFSET(MIB_UDPSTATS
, dwInDatagrams
), copyInt
},
1146 { FIELD_OFFSET(MIB_UDPSTATS
, dwNoPorts
), copyInt
},
1147 { FIELD_OFFSET(MIB_UDPSTATS
, dwInErrors
), copyInt
},
1148 { FIELD_OFFSET(MIB_UDPSTATS
, dwOutDatagrams
), copyInt
},
1151 static BOOL
mib2UdpQuery(BYTE bPduType
, SnmpVarBind
*pVarBind
,
1152 AsnInteger32
*pErrorStatus
)
1154 AsnObjectIdentifier myOid
= DEFINE_OID(mib2Udp
);
1158 TRACE("(0x%02x, %s, %p)\n", bPduType
, SnmpUtilOidToA(&pVarBind
->name
),
1164 case SNMP_PDU_GETNEXT
:
1165 *pErrorStatus
= getItemFromOid(&pVarBind
->name
, &myOid
, bPduType
,
1169 *pErrorStatus
= mapStructEntryToValue(mib2UdpMap
,
1170 DEFINE_SIZEOF(mib2UdpMap
), &udpStats
, item
, pVarBind
);
1171 if (!*pErrorStatus
&& bPduType
== SNMP_PDU_GETNEXT
)
1172 ret
= setOidWithItem(&pVarBind
->name
, &myOid
, item
);
1176 *pErrorStatus
= SNMP_ERRORSTATUS_READONLY
;
1180 FIXME("0x%02x: unsupported PDU type\n", bPduType
);
1181 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
1186 static UINT mib2UdpEntry
[] = { 1,3,6,1,2,1,7,5,1 };
1187 static PMIB_UDPTABLE udpTable
;
1189 static void mib2UdpEntryInit(void)
1191 DWORD size
= 0, ret
= GetUdpTable(NULL
, &size
, TRUE
);
1193 if (ret
== ERROR_INSUFFICIENT_BUFFER
)
1195 MIB_UDPTABLE
*table
= HeapAlloc(GetProcessHeap(), 0, size
);
1198 if (!GetUdpTable(table
, &size
, TRUE
)) udpTable
= table
;
1199 else HeapFree(GetProcessHeap(), 0, table
);
1204 static void mib2UdpEntryCleanup(void)
1206 HeapFree(GetProcessHeap(), 0, udpTable
);
1209 static struct structToAsnValue mib2UdpEntryMap
[] = {
1210 { FIELD_OFFSET(MIB_UDPROW
, dwLocalAddr
), copyIpAddr
},
1211 { FIELD_OFFSET(MIB_UDPROW
, dwLocalPort
), copyInt
},
1214 static void oidToUdpRow(AsnObjectIdentifier
*oid
, void *dst
)
1216 MIB_UDPROW
*row
= dst
;
1218 assert(oid
&& oid
->idLength
>= 5);
1219 row
->dwLocalAddr
= oidToIpAddr(oid
);
1220 row
->dwLocalPort
= oid
->ids
[4];
1223 static int compareUdpRow(const void *a
, const void *b
)
1225 const MIB_UDPROW
*key
= a
, *value
= b
;
1228 ret
= key
->dwLocalAddr
- value
->dwLocalAddr
;
1230 ret
= key
->dwLocalPort
- value
->dwLocalPort
;
1234 static BOOL
mib2UdpEntryQuery(BYTE bPduType
, SnmpVarBind
*pVarBind
,
1235 AsnInteger32
*pErrorStatus
)
1237 AsnObjectIdentifier myOid
= DEFINE_OID(mib2UdpEntry
);
1240 TRACE("(0x%02x, %s, %p)\n", bPduType
, SnmpUtilOidToA(&pVarBind
->name
),
1246 case SNMP_PDU_GETNEXT
:
1248 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
1251 UINT tableIndex
= 0, item
= 0;
1253 *pErrorStatus
= getItemAndInstanceFromTable(&pVarBind
->name
, &myOid
,
1254 5, bPduType
, (struct GenericTable
*)udpTable
,
1255 sizeof(MIB_UDPROW
), oidToUdpRow
, compareUdpRow
, &item
,
1261 *pErrorStatus
= mapStructEntryToValue(mib2UdpEntryMap
,
1262 DEFINE_SIZEOF(mib2UdpEntryMap
),
1263 &udpTable
->table
[tableIndex
- 1], item
, pVarBind
);
1264 if (!*pErrorStatus
&& bPduType
== SNMP_PDU_GETNEXT
)
1266 AsnObjectIdentifier oid
;
1268 ret
= setOidWithItemAndIpAddr(&pVarBind
->name
, &myOid
, item
,
1269 udpTable
->table
[tableIndex
- 1].dwLocalAddr
);
1273 oid
.ids
= &udpTable
->table
[tableIndex
- 1].dwLocalPort
;
1274 ret
= SnmpUtilOidAppend(&pVarBind
->name
, &oid
);
1281 *pErrorStatus
= SNMP_ERRORSTATUS_READONLY
;
1285 FIXME("0x%02x: unsupported PDU type\n", bPduType
);
1286 *pErrorStatus
= SNMP_ERRORSTATUS_NOSUCHNAME
;
1291 /* This list MUST BE lexicographically sorted */
1292 static struct mibImplementation supportedIDs
[] = {
1293 { DEFINE_OID(mib2IfNumber
), mib2IfNumberInit
, mib2IfNumberQuery
,
1294 mib2IfNumberCleanup
},
1295 { DEFINE_OID(mib2IfEntry
), NULL
, mib2IfEntryQuery
, NULL
},
1296 { DEFINE_OID(mib2Ip
), mib2IpStatsInit
, mib2IpStatsQuery
, NULL
},
1297 { DEFINE_OID(mib2IpAddr
), mib2IpAddrInit
, mib2IpAddrQuery
,
1298 mib2IpAddrCleanup
},
1299 { DEFINE_OID(mib2IpRoute
), mib2IpRouteInit
, mib2IpRouteQuery
,
1300 mib2IpRouteCleanup
},
1301 { DEFINE_OID(mib2IpNet
), mib2IpNetInit
, mib2IpNetQuery
, mib2IpNetCleanup
},
1302 { DEFINE_OID(mib2Icmp
), mib2IcmpInit
, mib2IcmpQuery
, NULL
},
1303 { DEFINE_OID(mib2Tcp
), mib2TcpInit
, mib2TcpQuery
, NULL
},
1304 { DEFINE_OID(mib2Udp
), mib2UdpInit
, mib2UdpQuery
, NULL
},
1305 { DEFINE_OID(mib2UdpEntry
), mib2UdpEntryInit
, mib2UdpEntryQuery
,
1306 mib2UdpEntryCleanup
},
1308 static UINT minSupportedIDLength
;
1310 /*****************************************************************************
1311 * SnmpExtensionInit [INETMIB1.@]
1313 BOOL WINAPI
SnmpExtensionInit(DWORD dwUptimeReference
,
1314 HANDLE
*phSubagentTrapEvent
, AsnObjectIdentifier
*pFirstSupportedRegion
)
1316 AsnObjectIdentifier myOid
= DEFINE_OID(mib2System
);
1319 TRACE("(%d, %p, %p)\n", dwUptimeReference
, phSubagentTrapEvent
,
1320 pFirstSupportedRegion
);
1322 minSupportedIDLength
= UINT_MAX
;
1323 for (i
= 0; i
< ARRAY_SIZE(supportedIDs
); i
++)
1325 if (supportedIDs
[i
].init
)
1326 supportedIDs
[i
].init();
1327 if (supportedIDs
[i
].name
.idLength
< minSupportedIDLength
)
1328 minSupportedIDLength
= supportedIDs
[i
].name
.idLength
;
1330 *phSubagentTrapEvent
= NULL
;
1331 SnmpUtilOidCpy(pFirstSupportedRegion
, &myOid
);
1335 static void cleanup(void)
1339 for (i
= 0; i
< ARRAY_SIZE(supportedIDs
); i
++)
1340 if (supportedIDs
[i
].cleanup
)
1341 supportedIDs
[i
].cleanup();
1344 static struct mibImplementation
*findSupportedQuery(UINT
*ids
, UINT idLength
,
1345 UINT
*matchingIndex
)
1347 int indexHigh
= DEFINE_SIZEOF(supportedIDs
) - 1, indexLow
= 0;
1348 AsnObjectIdentifier oid1
= { idLength
, ids
};
1353 while (indexLow
<= indexHigh
)
1355 INT cmp
, i
= (indexLow
+ indexHigh
) / 2;
1356 if (!(cmp
= SnmpUtilOidNCmp(&oid1
, &supportedIDs
[i
].name
, idLength
)))
1359 return &supportedIDs
[i
];
1369 /*****************************************************************************
1370 * SnmpExtensionQuery [INETMIB1.@]
1372 BOOL WINAPI
SnmpExtensionQuery(BYTE bPduType
, SnmpVarBindList
*pVarBindList
,
1373 AsnInteger32
*pErrorStatus
, AsnInteger32
*pErrorIndex
)
1375 AsnObjectIdentifier mib2oid
= DEFINE_OID(mib2
);
1376 AsnInteger32 error
= SNMP_ERRORSTATUS_NOERROR
, errorIndex
= 0;
1380 TRACE("(0x%02x, %p, %p, %p)\n", bPduType
, pVarBindList
,
1381 pErrorStatus
, pErrorIndex
);
1383 for (i
= 0; !error
&& i
< pVarBindList
->len
; i
++)
1385 /* Ignore any OIDs not in MIB2 */
1386 if (!SnmpUtilOidNCmp(&pVarBindList
->list
[i
].name
, &mib2oid
,
1389 struct mibImplementation
*impl
= NULL
;
1390 UINT len
, matchingIndex
= 0;
1392 TRACE("%s\n", SnmpUtilOidToA(&pVarBindList
->list
[i
].name
));
1393 /* Search for an implementation matching as many octets as possible
1395 for (len
= pVarBindList
->list
[i
].name
.idLength
;
1396 len
>= minSupportedIDLength
&& !impl
; len
--)
1397 impl
= findSupportedQuery(pVarBindList
->list
[i
].name
.ids
, len
,
1399 if (impl
&& impl
->query
)
1400 ret
= impl
->query(bPduType
, &pVarBindList
->list
[i
], &error
);
1402 error
= SNMP_ERRORSTATUS_NOSUCHNAME
;
1403 if (error
== SNMP_ERRORSTATUS_NOSUCHNAME
&&
1404 bPduType
== SNMP_PDU_GETNEXT
)
1406 /* GetNext is special: it finds the successor to the given OID,
1407 * so we have to continue until an implementation handles the
1408 * query or we exhaust the table of supported OIDs.
1410 for (matchingIndex
++; error
== SNMP_ERRORSTATUS_NOSUCHNAME
&&
1411 matchingIndex
< DEFINE_SIZEOF(supportedIDs
);
1414 error
= SNMP_ERRORSTATUS_NOERROR
;
1415 impl
= &supportedIDs
[matchingIndex
];
1417 ret
= impl
->query(bPduType
, &pVarBindList
->list
[i
],
1420 error
= SNMP_ERRORSTATUS_NOSUCHNAME
;
1422 /* If the query still isn't resolved, set the OID to the
1423 * successor to the last entry in the table.
1425 if (error
== SNMP_ERRORSTATUS_NOSUCHNAME
)
1427 SnmpUtilOidFree(&pVarBindList
->list
[i
].name
);
1428 ret
= SnmpUtilOidCpy(&pVarBindList
->list
[i
].name
,
1429 &supportedIDs
[matchingIndex
- 1].name
);
1430 pVarBindList
->list
[i
].name
.ids
[
1431 pVarBindList
->list
[i
].name
.idLength
- 1] += 1;
1438 *pErrorStatus
= error
;
1439 *pErrorIndex
= errorIndex
;
1443 /*****************************************************************************
1444 * DllMain [INETMIB1.@]
1446 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1448 TRACE("(0x%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
1452 case DLL_PROCESS_ATTACH
:
1453 DisableThreadLibraryCalls(hinstDLL
);
1455 case DLL_PROCESS_DETACH
:
1456 if (lpvReserved
) break;