Пример #1
0
DWORD deleteIpForwardEntry( PMIB_IPFORWARDROW pRoute ) {
    HANDLE tcpFile;
    NTSTATUS status = openTcpFile( &tcpFile );
    TCP_REQUEST_SET_INFORMATION_EX_ROUTE_ENTRY req =
        TCP_REQUEST_SET_INFORMATION_INIT;
    IPRouteEntry *rte;
    TDIEntityID   id;
    DWORD         returnSize = 0;

    TRACE("Called.\n");

    if( NT_SUCCESS(status) ) {
        status = getNthIpEntity( tcpFile, pRoute->dwForwardIfIndex, &id );

        if( NT_SUCCESS(status) ) {
            req.Req.ID.toi_class                = INFO_CLASS_PROTOCOL;
            req.Req.ID.toi_type                 = INFO_TYPE_PROVIDER;
            req.Req.ID.toi_id                   = IP_MIB_ARPTABLE_ENTRY_ID;
            req.Req.ID.toi_entity.tei_instance  = id.tei_instance;
            req.Req.ID.toi_entity.tei_entity    = CL_NL_ENTITY;
            req.Req.BufferSize                  = sizeof(*rte);
            rte                                 =
                (IPRouteEntry *)&req.Req.Buffer[0];

            // dwForwardPolicy
            // dwForwardNextHopAS
            rte->ire_dest    = pRoute->dwForwardDest;
            rte->ire_mask    = INADDR_NONE;
            rte->ire_gw      = pRoute->dwForwardNextHop;
            rte->ire_index   = pRoute->dwForwardIfIndex;
            rte->ire_type    = IP_FORWARD_DEL;
            rte->ire_proto   = pRoute->dwForwardProto;
            rte->ire_age     = pRoute->dwForwardAge;
            rte->ire_metric1 = pRoute->dwForwardMetric1;
            rte->ire_metric2 = INADDR_NONE;
            rte->ire_metric3 = INADDR_NONE;
            rte->ire_metric4 = INADDR_NONE;
            rte->ire_metric5 = INADDR_NONE;

            status = DeviceIoControl( tcpFile,
                                      IOCTL_TCP_SET_INFORMATION_EX,
                                      &req,
                                      sizeof(req),
                                      NULL,
                                      0,
                                      &returnSize,
                                      NULL );
        }

        closeTcpFile( tcpFile );
    }

    TRACE("Returning: %08x (IOCTL was %08x)\n", status, IOCTL_TCP_SET_INFORMATION_EX);

    if( NT_SUCCESS(status) )
	return NO_ERROR;
    else
	return status;
}
Пример #2
0
RouteTable *getRouteTable(void)
{
    RouteTable *out_route_table;
    DWORD numRoutes = getNumRoutes(), routesAdded = 0;
    TDIEntityID ent;
    HANDLE tcpFile;
    NTSTATUS status = openTcpFile( &tcpFile );
    int i;

    if( !NT_SUCCESS(status) )
        return 0;

    TRACE("GETTING ROUTE TABLE\n");

    out_route_table = HeapAlloc( GetProcessHeap(), 0,
                                 sizeof(RouteTable) +
                                 (sizeof(RouteEntry) * (numRoutes - 1)) );
    if (!out_route_table) {
        closeTcpFile(tcpFile);
        return NULL;
    }

    out_route_table->numRoutes = numRoutes;

    for( i = 0; routesAdded < out_route_table->numRoutes; i++ ) {
        int j;
        IPRouteEntry *route_set;

        getNthIpEntity( tcpFile, i, &ent );

        tdiGetRoutesForIpEntity( tcpFile, &ent, &route_set, &numRoutes );
        
        if( !route_set ) {
            closeTcpFile( tcpFile );
            HeapFree( GetProcessHeap(), 0, out_route_table );
            return 0;
        }

        TRACE( "%d routes in instance %d\n", numRoutes, i );
#if 0
        HexDump( route_set,
                 sizeof( IPRouteEntry ) *
                 snmpInfo.ipsi_numroutes );
#endif

        for( j = 0; j < numRoutes; j++ ) {
            int routeNum = j + routesAdded;
            out_route_table->routes[routeNum].dest =
                route_set[j].ire_dest;
            out_route_table->routes[routeNum].mask =
                route_set[j].ire_mask;
            out_route_table->routes[routeNum].gateway =
                route_set[j].ire_gw;
            out_route_table->routes[routeNum].ifIndex =
                route_set[j].ire_index;
            out_route_table->routes[routeNum].metric =
                route_set[j].ire_metric1;
        }

        if( route_set ) tdiFreeThingSet( route_set );

        routesAdded += numRoutes;
    }

    closeTcpFile( tcpFile );

    TRACE("Return: %08x, %08x\n", status, out_route_table);

    return out_route_table;
}
Пример #3
0
static NTSTATUS getInterfaceInfoSet( HANDLE tcpFile,
                                     IFInfo **infoSet,
                                     PDWORD numInterfaces ) {
    DWORD numEntities;
    TDIEntityID *entIDSet = 0;
    NTSTATUS status = tdiGetEntityIDSet( tcpFile, &entIDSet, &numEntities );
    IFInfo *infoSetInt = 0;
    int curInterf = 0, i;

    if (!NT_SUCCESS(status)) {
        ERR("getInterfaceInfoSet: tdiGetEntityIDSet() failed: 0x%lx\n", status);
        return status;
    }

    infoSetInt = HeapAlloc( GetProcessHeap(), 0,
                            sizeof(IFInfo) * numEntities );

    if( infoSetInt ) {
        for( i = 0; i < numEntities; i++ ) {
            if( isInterface( &entIDSet[i] ) ) {
                infoSetInt[curInterf].entity_id = entIDSet[i];
                status = tdiGetMibForIfEntity
                    ( tcpFile,
                      &entIDSet[i],
                      &infoSetInt[curInterf].if_info );
                TRACE("tdiGetMibForIfEntity: %08x\n", status);
                if( NT_SUCCESS(status) ) {
                    DWORD numAddrs;
                    IPAddrEntry *addrs;
                    TDIEntityID ip_ent;
                    int j;

		    status = getNthIpEntity( tcpFile, curInterf, &ip_ent );
		    if( NT_SUCCESS(status) )
			status = tdiGetIpAddrsForIpEntity
			    ( tcpFile, &ip_ent, &addrs, &numAddrs );
		    for( j = 0; j < numAddrs && NT_SUCCESS(status); j++ ) {
			TRACE("ADDR %d: index %d (target %d)\n", j, addrs[j].iae_index, infoSetInt[curInterf].if_info.ent.if_index);
			if( addrs[j].iae_index ==
			    infoSetInt[curInterf].if_info.ent.if_index ) {
			    memcpy( &infoSetInt[curInterf].ip_addr,
				    &addrs[j],
				    sizeof( addrs[j] ) );
			    curInterf++;
			    break;
			}
		    }
                }
            }
        }

        tdiFreeThingSet(entIDSet);

        if (NT_SUCCESS(status)) {
            *infoSet = infoSetInt;
            *numInterfaces = curInterf;
        } else {
            HeapFree(GetProcessHeap(), 0, infoSetInt);
        }

        return status;
    } else {
        return STATUS_INSUFFICIENT_RESOURCES;
    }
}