29#ifndef _NETSIM_IP_LIB_
30#pragma comment(lib,"IP.lib")
35#define IP_IGMP_STATUS_DEFAULT false
36#define IP_PIM_STATUS_DEFAULT false
37#define IP_ICMP_STATUS_DEFAULT false
38#define IP_STATIC_IP_ROUTE_DEFAULT _strdup("")
39#define IP_PROCESSING_DELAY_DEFAULT 0
42#define DEFAULT_METRIC 999
43#define ONLINK_METRIC 300
44#define MULTICAST_METRIC 306
45#define IPV4_HEADER_SIZE 20
49#define GET_IP_DEVVAR(d) (DEVICE_NWLAYER(d)?(IP_DEVVAR*)(DEVICE_NWLAYER(d)->ipVar):NULL)
56 RoutingType_DEFAULT=1,
64 PACKET_ICMP_DstUnreachableMsg=NW_PROTOCOL_IPV4*100+10,
65 PACKET_ICMP_ECHORequest,
66 PACKET_ICMP_ECHOReply,
67 PACKET_ROUTER_ADVERTISEMENT,
70 PACKET_VPN = NW_PROTOCOL_IPV4*100+20,
73 PACKET_IGMP_QUERY = NW_PROTOCOL_IPV4*100+30,
78 PACKET_PIM_HELLO = NW_PROTOCOL_IPV4*100+40,
80 PACKET_PIM_REGISTERSTOP,
86 PACKET_PIM_CANDRPADVER,
88#define isPIMPacket(packet) (packet->pstruNetworkData->IPProtocol == IPPROTOCOL_PIM)
94 EVENT_ICMP_POLL=NW_PROTOCOL_IPV4*100+1,
95 EVENT_ADVERTISE_ROUTER,
98 EVENT_IGMP_Unsolicited_report,
99 EVENT_IGMP_SendStartupQuery,
100 EVENT_IGMP_SendQuery,
101 EVENT_IGMP_OtherQuerierPresentTimer,
102 EVENT_IGMP_DelayTimer,
103 EVENT_IGMP_GroupMembershipTimer,
106 EVENT_PIM_SEND_HELLO,
107 EVENT_PIM_NEIGHBOR_TIMEOUT,
114 EVENT_ICMP_SEND_ECHO,
117 EVENT_IP_PROCESSING_DELAY,
126 GATEWAYSTATE_NOTIFICATION_PENDING,
127 GATEWAYSTATE_CLEARANCE_PENDING,
147 NETSIM_IPAddress* nextHop;
148 NETSIM_IPAddress* gateway;
149 NETSIM_ID* interfaceId;
150 NETSIM_ID* nextHopId;
152 }IP_FORWARD_ROUTE,*ptrIP_FORWARD_ROUTE;
153 void free_ip_route(ptrIP_FORWARD_ROUTE route);
158 NETSIM_IPAddress networkDestination;
159 NETSIM_IPAddress netMask;
160 NETSIM_IPAddress gateway;
162 NETSIM_IPAddress* Interface;
163 unsigned int prefix_len;
170 NETSIM_ID* nInterfaceId;
171 NETSIM_ID nGatewayId;
172}IP_ROUTINGTABLE, *ptrIP_ROUTINGTABLE,**pptrIP_ROUTINGTABLE;
228 char* staticIPTableFile;
232 bool isFirewallConfigured;
233 char* firewallConfig;
238 unsigned int nRouterAdvertisementFlag;
239 unsigned int nRouterAdverMinInterval;
240 unsigned int nRouterAdverMaxInterval;
241 unsigned int nRouterAdverLifeTime;
243 unsigned int nICMPPollingTime;
244 unsigned int nGatewayCount;
245 NETSIM_IPAddress* GatewayIPAddress;
246 NETSIM_ID* nGatewayId;
247 NETSIM_ID* nInterfaceId;
248 IP_GATEWAYSTATE* nGatewayState;
251 VPN_STATE nVPNStatus;
255 NETSIM_IPAddress serverIP;
257 NETSIM_IPAddress ipPoolStart;
258 NETSIM_IPAddress ipPoolEnd;
259 NETSIM_IPAddress ipPoolMask;
270 bool isIGMPConfigured;
274 bool isPIMConfigured;
278 double processingDelay;
284 unsigned int nPacketSent;
285 unsigned int nPacketReceived;
286 unsigned int nPacketForwarded;
287 unsigned int nPacketDiscarded;
288 unsigned int nFirewallBlocked;
289 unsigned int nTTLDrop;
299#define DNS_ALLOC() (struct stru_dnsList*)list_alloc(sizeof(struct stru_dnsList),offsetof(struct stru_dnsList,ele))
301#define IPROUTINGTABLE_ALLOC() (ptrIP_ROUTINGTABLE)list_alloc(sizeof(IP_ROUTINGTABLE),offsetof(IP_ROUTINGTABLE,ele))
302#define IPROUTINGTABLE_ADD(table,current,fun) list_add(((void**)(table)),current,offsetof(IP_ROUTINGTABLE,ele),fun)
306int iptable_add_check(ptrIP_ROUTINGTABLE current,ptrIP_ROUTINGTABLE mem);
307ptrIP_ROUTINGTABLE iptable_check(ptrIP_ROUTINGTABLE* table,NETSIM_IPAddress dest,NETSIM_IPAddress subnet);
308int iptable_change(ptrIP_WRAPPER wrapper,
309 NETSIM_IPAddress dest,
310 NETSIM_IPAddress subnet,
312 NETSIM_IPAddress gateway,
314 NETSIM_IPAddress* interfaceIp,
315 NETSIM_ID* interfaceId,
316 unsigned int metric);
317int iptable_change_byRoute(ptrIP_WRAPPER wrapper,
318 ptrIP_ROUTINGTABLE route,
319 NETSIM_IPAddress subnet,
320 unsigned int prefix_len,
321 NETSIM_IPAddress gateway,
323 NETSIM_IPAddress* interfaceIp,
324 NETSIM_ID* interfaceId,
325 unsigned int metric);
326int iptable_delete(ptrIP_WRAPPER wrapper,
327 NETSIM_IPAddress dest,
330int iptable_delete_by_type(ptrIP_WRAPPER wrapper,
332int iptable_delete_by_route(ptrIP_WRAPPER wrapper,
333 ptrIP_ROUTINGTABLE route);
334ptrIP_ROUTINGTABLE iptable_add(ptrIP_WRAPPER wrapper,
335 NETSIM_IPAddress dest,
336 NETSIM_IPAddress subnet,
337 unsigned int prefix_len,
338 NETSIM_IPAddress gateway,
340 NETSIM_IPAddress* interfaceIp,
341 NETSIM_ID* interfaceId,
344int iptable_print(FILE* fp, ptrIP_ROUTINGTABLE routeTable);
345ptrIP_ROUTINGTABLE* iptable_get_table_by_type(ptrIP_ROUTINGTABLE table,
char* type, UINT* count);
347_declspec(dllexport) NETSIM_IPAddress dns_query(NETSIM_ID nDeviceId,NETSIM_ID
id);
350_declspec(dllexport)
int fn_NetSim_IP_VPN_Run();
353ptrIP_FORWARD_ROUTE fn_NetSim_IP_RoutePacket(NetSim_PACKET* packet,
355ptrIP_FORWARD_ROUTE fn_NetSim_IP_RoutePacketViaStaticEntry(NetSim_PACKET* packet, NETSIM_ID dev);
356void pass_to_lower_layer(NetSim_PACKET* packet, ptrIP_FORWARD_ROUTE route, UINT c);
359int fn_NetSim_NAT_NetworkOut(NETSIM_ID ndev,NetSim_PACKET* packet);
360int fn_NetSim_NAT_NetworkIn(NETSIM_ID ndev,NetSim_PACKET* packet);
363void ICMP_copyPacket(NetSim_PACKET* d, NetSim_PACKET* s);
364void process_icmp_packet();
365_declspec(dllexport)
int ICMP_CHECKSTATE(NETSIM_IPAddress ip);
368void multicast_join_group();
369IP_PROTOCOL_ACTION check_ip_in_multicastgroup(NETSIM_IPAddress ip, NETSIM_ID d, NetSim_PACKET* packet);
370bool is_reserved_multicast_address(NETSIM_IPAddress ip);
371bool isCorrectRoute(pptrIP_ROUTINGTABLE table, NETSIM_IPAddress dest, NETSIM_IPAddress src);
374void igmp_configure(NETSIM_ID d,
void* xmlNode);
375void igmp_init(NETSIM_ID d);
376void igmp_host_join_group(NETSIM_ID d, NETSIM_IPAddress group);
377void host_handle_unsolicited_report_timer();
378void process_igmp_packet();
379void IGMP_FreePacket(NetSim_PACKET* packet);
380IP_PROTOCOL_ACTION host_is_ip_present_in_db(NETSIM_ID d, NETSIM_IPAddress ip, NetSim_PACKET* packet);
381IP_PROTOCOL_ACTION router_is_ip_present_in_db(NETSIM_ID d, NETSIM_IPAddress ip, NetSim_PACKET* packet);
382void send_query_msg(NETSIM_ID d, NETSIM_IPAddress groupAddr,
double time);
383void igmp_router_processOtherQuerierPresentTime();
384void host_send_report();
385void igmp_router_ProcessGroupMembershipTimer();
386void copy_igmp_packet(NetSim_PACKET* d, NetSim_PACKET* s);
387void igmp_free(NETSIM_ID d);
390void pim_configure(NETSIM_ID d,
void* xmlNetSimNode);
391void Router_PIM_Init(NETSIM_ID d);
392void pim_handle_timer_event();
393void pim_join_group(NETSIM_ID d, NETSIM_IPAddress group);
394IP_PROTOCOL_ACTION pim_decide_action(NetSim_PACKET* packet, NETSIM_ID d);
395void process_pim_packet();
398void ip_write_to_pcap(NetSim_PACKET* packet,
404_declspec(dllexport)
void* ICMP_StartPingRequest(NETSIM_ID src,
407 bool(*resp)(
void*,
char*,
bool),
409void icmp_send_echo_request();
Structure to store the device ip details.
Structure to store the IP metrics.
Structure to store ip routing table.