/*++
Copyright (c) 1997 Microsoft Corporation
Module Name:
sample\ip\api.c
Abstract:
Functions exported by the Sample Routing Protocol DLL
Revision History:
--*/
#include "logtrdef.h"
#define PROTOCOL_STATE_STOPPED 0
#define PROTOCOL_STATE_STOPPING 1
#define PROTOCOL_STATE_RUNNING 2
#define NUM_STATES 3
#define BINDING_DOWN 0
#define BINDING_UP 1
#define QUERY_TYPE_GET 0
#define QUERY_TYPE_GET_NEXT 1
#define QUERY_TYPE_GET_FIRST 2
#define QUERY_TYPE_SET 3
#define QUERY_TYPE_CREATE 4
#define QUERY_TYPE_DELETE 5
#define NUM_WAIT_EVENTS 3
//
// Define this to be your compiler's ASSERTs
//
#define ASSERT( exp )
//
// VOID
// InitializeListHead(
// PLIST_ENTRY ListHead
// );
//
#define InitializeListHead(ListHead) (\
(ListHead)->Flink = (ListHead)->Blink = (ListHead))
//
// BOOLEAN
// IsListEmpty(
// PLIST_ENTRY ListHead
// );
//
#define IsListEmpty(ListHead) \
((ListHead)->Flink == (ListHead))
//
// PLIST_ENTRY
// RemoveHeadList(
// PLIST_ENTRY ListHead
// );
//
#define RemoveHeadList(ListHead) \
(ListHead)->Flink;\
{RemoveEntryList((ListHead)->Flink)}
//
// PLIST_ENTRY
// RemoveTailList(
// PLIST_ENTRY ListHead
// );
//
#define RemoveTailList(ListHead) \
(ListHead)->Blink;\
{RemoveEntryList((ListHead)->Blink)}
//
// VOID
// RemoveEntryList(
// PLIST_ENTRY Entry
// );
//
#define RemoveEntryList(Entry) {\
PLIST_ENTRY _EX_Blink;\
PLIST_ENTRY _EX_Flink;\
_EX_Flink = (Entry)->Flink;\
_EX_Blink = (Entry)->Blink;\
_EX_Blink->Flink = _EX_Flink;\
_EX_Flink->Blink = _EX_Blink;\
}
//
// VOID
// InsertTailList(
// PLIST_ENTRY ListHead,
// PLIST_ENTRY Entry
// );
//
#define InsertTailList(ListHead,Entry) {\
PLIST_ENTRY _EX_Blink;\
PLIST_ENTRY _EX_ListHead;\
_EX_ListHead = (ListHead);\
_EX_Blink = _EX_ListHead->Blink;\
(Entry)->Flink = _EX_ListHead;\
(Entry)->Blink = _EX_Blink;\
_EX_Blink->Flink = (Entry);\
_EX_ListHead->Blink = (Entry);\
}
//
// VOID
// InsertHeadList(
// PLIST_ENTRY ListHead,
// PLIST_ENTRY Entry
// );
//
#define InsertHeadList(ListHead,Entry) {\
PLIST_ENTRY _EX_Flink;\
PLIST_ENTRY _EX_ListHead;\
_EX_ListHead = (ListHead);\
_EX_Flink = _EX_ListHead->Flink;\
(Entry)->Flink = _EX_Flink;\
(Entry)->Blink = _EX_ListHead;\
_EX_Flink->Blink = (Entry);\
_EX_ListHead->Flink = (Entry);\
}
//
// Macros called each time an api is called and exited. This is to
// facilitate StopProtocol() functionality.
//
#define EnterProtocolApi() \
{ \
EnterCriticalSection(&g_csProtocolStateLock); \
\
if(g_dwProtocolState == PROTOCOL_STATE_RUNNING) \
{ \
g_dwProtocolRefCount++; \
LeaveCriticalSection(&g_csProtocolStateLock); \
} \
else \
{ \
LeaveCriticalSection(&g_csProtocolStateLock); \
return ERROR_CAN_NOT_COMPLETE; \
} \
}
#define ExitProtocolApi() \
{ \
EnterCriticalSection(&g_csProtocolStateLock); \
g_dwProtocolRefCount++; \
LeaveCriticalSection(&g_csProtocolStateLock); \
}
#define PRINT_ADDRESS(x) \
((x)&0x000000FF),(((x)&0x0000FF00)>>8),(((x)&0x00FF0000)>>16),(((x)&0xFF000000)>>24)
//
// VOID
// PrintRoute(PRTM_IP_ROUTE pRoute)
//
#define PrintRoute(FL,pRoute) \
{ \
Trace4(FL, \
"Dest: %d.%d.%d.%d(%d.%d.%d.%d) Nexthop: %d.%d.%d.%d(%d.%d.%d.%d)", \
PRINT_ADDRESS((pRoute)->RR_Network.N_NetNumber), \
PRINT_ADDRESS((pRoute)->RR_Network.N_NetMask), \
PRINT_ADDRESS((pRoute)->RR_NextHopAddress.N_NetNumber), \
PRINT_ADDRESS((pRoute)->RR_NextHopAddress.N_NetMask)); \
Trace5(FL,"I/F: %d Proto: %d Metric: %d Priority: %d Validity: %s.\n", \
(pRoute)->RR_InterfaceID, \
(pRoute)->RR_RoutingProtocol, \
(pRoute)->RR_FamilySpecificData.FSD_Metric, \
(pRoute)->RR_FamilySpecificData.FSD_Priority, \
(IsRouteValid((pRoute)))?"TRUE":"FALSE"); \
}