Commit d3baf1dc authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

inetmib1: Support the MIB2 IP route table.

parent 74310cb0
......@@ -678,6 +678,93 @@ static BOOL mib2IpAddrQuery(BYTE bPduType, SnmpVarBind *pVarBind,
return TRUE;
}
static UINT mib2IpRoute[] = { 1,3,6,1,2,1,4,21,1 };
static PMIB_IPFORWARDTABLE ipRouteTable;
static struct structToAsnValue mib2IpRouteMap[] = {
{ FIELD_OFFSET(MIB_IPFORWARDROW, dwForwardDest), copyIpAddr },
{ FIELD_OFFSET(MIB_IPFORWARDROW, dwForwardIfIndex), copyInt },
{ FIELD_OFFSET(MIB_IPFORWARDROW, dwForwardMetric1), copyInt },
{ FIELD_OFFSET(MIB_IPFORWARDROW, dwForwardMetric2), copyInt },
{ FIELD_OFFSET(MIB_IPFORWARDROW, dwForwardMetric3), copyInt },
{ FIELD_OFFSET(MIB_IPFORWARDROW, dwForwardMetric4), copyInt },
{ FIELD_OFFSET(MIB_IPFORWARDROW, dwForwardNextHop), copyIpAddr },
{ FIELD_OFFSET(MIB_IPFORWARDROW, dwForwardType), copyInt },
{ FIELD_OFFSET(MIB_IPFORWARDROW, dwForwardProto), copyInt },
{ FIELD_OFFSET(MIB_IPFORWARDROW, dwForwardAge), copyInt },
{ FIELD_OFFSET(MIB_IPFORWARDROW, dwForwardMask), copyIpAddr },
{ FIELD_OFFSET(MIB_IPFORWARDROW, dwForwardMetric5), copyInt },
};
static void mib2IpRouteInit(void)
{
DWORD size = 0, ret = GetIpForwardTable(NULL, &size, FALSE);
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
ipRouteTable = HeapAlloc(GetProcessHeap(), 0, size);
if (ipRouteTable)
GetIpForwardTable(ipRouteTable, &size, FALSE);
}
}
static BOOL mib2IpRouteQuery(BYTE bPduType, SnmpVarBind *pVarBind,
AsnInteger32 *pErrorStatus)
{
AsnObjectIdentifier myOid = DEFINE_OID(mib2IpRoute);
UINT tableIndex = 0, item = 0;
TRACE("(0x%02x, %s, %p)\n", bPduType, SnmpUtilOidToA(&pVarBind->name),
pErrorStatus);
switch (bPduType)
{
case SNMP_PDU_GET:
case SNMP_PDU_GETNEXT:
*pErrorStatus = getItemAndIpAddressInstanceFromOid(&pVarBind->name,
&myOid, bPduType, (struct GenericTable *)ipRouteTable,
sizeof(MIB_IPFORWARDROW),
FIELD_OFFSET(MIB_IPFORWARDROW, dwForwardDest), &item, &tableIndex);
if (!*pErrorStatus)
{
assert(tableIndex);
assert(item);
*pErrorStatus = mapStructEntryToValue(mib2IpRouteMap,
DEFINE_SIZEOF(mib2IpRouteMap),
&ipRouteTable->table[tableIndex - 1], item, bPduType, pVarBind);
if (!*pErrorStatus && bPduType == SNMP_PDU_GETNEXT)
{
UINT id;
BYTE *ptr;
AsnObjectIdentifier oid;
SnmpUtilOidCpy(&pVarBind->name, &myOid);
oid.idLength = 1;
oid.ids = &id;
id = item;
SnmpUtilOidAppend(&pVarBind->name, &oid);
for (ptr =
(BYTE *)&ipRouteTable->table[tableIndex - 1].dwForwardDest;
ptr <
(BYTE *)&ipRouteTable->table[tableIndex - 1].dwForwardDest
+ sizeof(DWORD); ptr++)
{
id = *ptr;
SnmpUtilOidAppend(&pVarBind->name, &oid);
}
}
}
break;
case SNMP_PDU_SET:
*pErrorStatus = SNMP_ERRORSTATUS_READONLY;
break;
default:
FIXME("0x%02x: unsupported PDU type\n", bPduType);
*pErrorStatus = SNMP_ERRORSTATUS_NOSUCHNAME;
}
return TRUE;
}
static UINT mib2Icmp[] = { 1,3,6,1,2,1,5 };
static MIB_ICMP icmpStats;
......@@ -828,6 +915,7 @@ static struct mibImplementation supportedIDs[] = {
{ DEFINE_OID(mib2IfEntry), NULL, mib2IfEntryQuery },
{ DEFINE_OID(mib2Ip), mib2IpStatsInit, mib2IpStatsQuery },
{ DEFINE_OID(mib2IpAddr), mib2IpAddrInit, mib2IpAddrQuery },
{ DEFINE_OID(mib2IpRoute), mib2IpRouteInit, mib2IpRouteQuery },
{ DEFINE_OID(mib2Icmp), mib2IcmpInit, mib2IcmpQuery },
{ DEFINE_OID(mib2Tcp), mib2TcpInit, mib2TcpQuery },
};
......
......@@ -64,6 +64,7 @@ static void testQuery(void)
UINT mib2IfAdminStatus[] = { 1,3,6,1,2,1,2,2,1,7 };
UINT mib2IfOperStatus[] = { 1,3,6,1,2,1,2,2,1,8 };
UINT mib2IpAddr[] = { 1,3,6,1,2,1,4,20,1,1 };
UINT mib2IpRouteTable[] = { 1,3,6,1,2,1,4,21,1,1 };
SnmpVarBind vars[3], vars2[3];
UINT entry;
......@@ -299,6 +300,62 @@ static void testQuery(void)
}
} while (moreData);
SnmpUtilVarBindFree(&vars2[0]);
/* Check the type and OIDs of the IP route table */
vars[0].name.idLength = DEFINE_SIZEOF(mib2IpRouteTable);
vars[0].name.ids = mib2IpRouteTable;
SnmpUtilOidCpy(&vars2[0].name, &vars[0].name);
vars2[0].value.asnType = 0;
list.len = 1;
list.list = vars2;
moreData = TRUE;
do {
ret = pQuery(SNMP_PDU_GETNEXT, &list, &error, &index);
ok(ret, "SnmpExtensionQuery failed: %d\n", GetLastError());
ok(error == SNMP_ERRORSTATUS_NOERROR,
"expected SNMP_ERRORSTATUS_NOERROR, got %d\n", error);
ok(index == 0, "expected index 0, got %d\n", index);
if (!ret)
moreData = FALSE;
else if (error)
moreData = FALSE;
else if (SnmpUtilOidNCmp(&vars2[0].name, &vars[0].name,
vars[0].name.idLength))
moreData = FALSE;
if (moreData)
{
/* Make sure the size of the OID is right.
* FIXME: don't know if IPv6 addrs are shared with this table.
* Don't think so, but I'm not certain.
*/
ok(vars2[0].name.idLength = vars[0].name.idLength + 4,
"expected length %d, got %d\n", vars[0].name.idLength + 4,
vars2[0].name.idLength);
/* Make sure the type is right */
ok(vars2[0].value.asnType == ASN_IPADDRESS,
"expected type ASN_IPADDRESS, got %02x\n",
vars2[0].value.asnType);
if (vars2[0].value.asnType == ASN_IPADDRESS)
{
UINT i;
/* The base OID for the route table, 1.3.6.1.2.1.4.21.1.1, is
* appended with the dest IP address of the entry. So e.g. a
* route entry for 224.0.0.0 is identified in MIB2 as
* 1.3.6.1.2.1.4.21.1.1.224.0.0.0
*/
for (i = 0; i < vars2[0].value.asnValue.address.length; i++)
{
ok(vars2[0].value.asnValue.address.stream[i] ==
vars2[0].name.ids[vars2[0].name.idLength - 4 + i],
"expected ident byte %d to be %d, got %d\n", i,
vars2[0].value.asnValue.address.stream[i],
vars2[0].name.ids[vars2[0].name.idLength - 4 + i]);
}
}
}
} while (moreData);
SnmpUtilVarBindFree(&vars2[0]);
}
START_TEST(main)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment