29#include "../Firewall/Firewall.h"
39#define MATCH_ALLOC() (ptrMATCH)list_alloc(sizeof(MATCH),offsetof(MATCH,ele))
43 static FILE* fp = NULL;
44#ifdef PRINT_MATCH_TABLE
47 fp = fopen(
"MatchTable.csv",
"w");
48 fprintf(fp,
"Dest,Gateway,Ifcount,Iflist,\n");
54 fprintf(fp,
" Device %d, dest = %s, Src = %s\n", d, dest->
str_ip, src->
str_ip);
58 fprintf(fp,
"%s,%s,%d,",
103 for (i = 0; i < l; i++)
131 c->bitsCount = dest->
type == 4 ? 32 : 128;
159 if (route == NULL)
return;
278 for (i = 0; i <
DEVICE(d)->nNumOfInterface; i++)
312 for (i = 0; i <
DEVICE(d)->nNumOfInterface; i++)
351#ifdef PRINT_MATCH_TABLE
386 bool isfound =
false;
415 iptable_add(
IP_WRAPPER_GET(d), dest, mask, 0, gateway, 1, &
DEVICE_NWADDRESS(d, in), &in, metric,
"STATIC");
418#define display_error(error, line, file) fnNetSimError("Invalid line in route file %s at line %d: %s", file, line, error)
429 FILE* fp = fopen(input,
"r");
437 while (fgets(input, BUFSIZ, fp))
442 if (*temp ==
'#' || !*temp)
483 UINT metric = atoi(
f);
500 add_table(d, dest, mask, gateway, in, metric);
538#ifdef PRINT_MATCH_TABLE
571 memset(&pevent, 0,
sizeof pevent);
611 fnNetSimError(
"Gateway IP and next hop IP are same. IP address=%s\n",
650 memset(&pevent, 0,
sizeof pevent);
void ip_write_to_pcap(NetSim_PACKET *packet, NETSIM_ID d, NETSIM_ID i, double time)
int ICMP_CHECKSTATE(NETSIM_IPAddress ip)
ptrIP_ROUTINGTABLE iptable_check(ptrIP_ROUTINGTABLE *table, NETSIM_IPAddress dest, NETSIM_IPAddress subnet)
ptrIP_ROUTINGTABLE iptable_add(ptrIP_WRAPPER wrapper, NETSIM_IPAddress dest, NETSIM_IPAddress subnet, unsigned int prefix_len, NETSIM_IPAddress gateway, UINT interfaceCount, NETSIM_IPAddress *interfaceIp, NETSIM_ID *interfaceId, unsigned int metric, char *type)
@ EVENT_IP_PROCESSING_DELAY
struct stru_IP_Metrics ** ipMetrics
bool isCorrectRoute(pptrIP_ROUTINGTABLE table, NETSIM_IPAddress dest, NETSIM_IPAddress src)
struct ForwardRoute * ptrIP_FORWARD_ROUTE
int fn_NetSim_IP_VPN_Run()
bool is_reserved_multicast_address(NETSIM_IPAddress ip)
void IP_TO_BINARY(NETSIM_IPAddress ip, char *binary)
bool isBroadcastIP(NETSIM_IPAddress ip)
NETSIM_IPAddress IP_NETWORK_ADDRESS(NETSIM_IPAddress ip, NETSIM_IPAddress subnet, unsigned int prefix_len)
#define IP_COMPARE(ip1, ip2)
#define STR_TO_IP4(ipstr)
int IP_IS_IN_SAME_NETWORK(NETSIM_IPAddress ip1, NETSIM_IPAddress ip2, NETSIM_IPAddress subnet, unsigned int prefix_len)
bool isMulticastIP(NETSIM_IPAddress ip)
void configure_static_ip_route(NETSIM_ID d, char *file)
static void route_onlink(NETSIM_ID d, NETSIM_IPAddress src, NETSIM_IPAddress dest, ptrIP_FORWARD_ROUTE route)
static ptrMATCH get_match_table(ptrIP_ROUTINGTABLE table, NETSIM_IPAddress dest, bool isStatic)
static int match_check(ptrMATCH m1, ptrMATCH m2)
static void update_route_entry(ptrMATCH match, ptrIP_FORWARD_ROUTE route, NETSIM_IPAddress dest)
static void add_to_match_list(ptrMATCH *l, ptrMATCH c)
ptrIP_FORWARD_ROUTE fn_NetSim_IP_RoutePacketViaStaticEntry(NetSim_PACKET *packet, NETSIM_ID dev)
static void change_table(NETSIM_ID d, ptrIP_ROUTINGTABLE table, NETSIM_IPAddress gateway, NETSIM_ID in, UINT metric)
static ptrIP_FORWARD_ROUTE route_multicast(NetSim_PACKET *packet, NETSIM_ID dev)
ptrIP_FORWARD_ROUTE fn_NetSim_IP_RoutePacket(NetSim_PACKET *packet, NETSIM_ID dev)
void free_ip_route(ptrIP_FORWARD_ROUTE route)
static void free_match_table(ptrMATCH l)
static ptrMATCH choose_match_for_reserved_address(ptrMATCH match, NETSIM_IPAddress dest, NETSIM_IPAddress src)
struct stru_match * ptrMATCH
static UINT get_bit_match_count(NETSIM_IPAddress ip1)
static void add_table(NETSIM_ID d, NETSIM_IPAddress dest, NETSIM_IPAddress mask, NETSIM_IPAddress gateway, NETSIM_ID in, UINT metric)
static ptrIP_FORWARD_ROUTE route_unicast(NetSim_PACKET *packet, NETSIM_ID dev)
static ptrIP_FORWARD_ROUTE static_route_unicast(NetSim_PACKET *packet, NETSIM_ID dev)
static bool check_my_ip(NETSIM_ID d, NETSIM_IPAddress ip)
#define display_error(error, line, file)
static void multicast_update_route_entry(ptrMATCH match, ptrIP_FORWARD_ROUTE route, NETSIM_IPAddress dest, NETSIM_IPAddress src)
static ptrIP_FORWARD_ROUTE static_route_multicast(NetSim_PACKET *packet, NETSIM_ID dev)
static void print_match_table(ptrMATCH match, NETSIM_ID d, NETSIM_IPAddress dest, NETSIM_IPAddress src)
void pass_to_lower_layer(NetSim_PACKET *packet, ptrIP_FORWARD_ROUTE route, UINT c)
#define fnNetSimError(x,...)
static const char pathSeperator[5]
#define LIST_ADD(ls, mem, checker)
#define LIST_FREE(ls, mem)
char * find_word(char **s)
char * lskip(const char *s)
#define PIP_TABLE_GET(DeviceId)
PNETSIM_MACADDRESS multicastIP_to_Mac(NETSIM_IPAddress multicastIP)
EXPORTED char * pszIOPath
EXPORTED PNETSIM_MACADDRESS BROADCAST_MAC
#define DEVICE_TYPE(DeviceId)
#define DEVICE_NWADDRESS(DeviceId, InterfaceId)
NETSIM_ID fn_NetSim_GetInterfaceIdByConfigId(NETSIM_ID devId, NETSIM_ID id)
NETSIM_IPAddress fn_NetSim_Stack_GetFirstIPAddressAsId(NETSIM_ID nDeviceId, unsigned int type)
PNETSIM_MACADDRESS fn_NetSim_Stack_GetMacAddressFromIP(const NETSIM_IPAddress szIPAddress)
NETSIM_ID fn_NetSim_Stack_GetInterfaceIdFromIP(NETSIM_ID nDeviceId, NETSIM_IPAddress ip)
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
#define DEVICE_INTERFACE(DeviceId, InterfaceId)
#define IP_WRAPPER_GET(DeviceId)
NETSIM_ID fn_NetSim_Stack_GetDeviceId_asIP(NETSIM_IPAddress ip, NETSIM_ID *nInterfaceId)
#define IP_TABLE_GET(DeviceId)
uint f(uint state, uchar key[])
ACL_ACTION fn_NetSim_NETWORK_Firewall(NETSIM_ID nDeviceId, NETSIM_ID interfaceId, NetSim_PACKET *packet, ACL_TYPE type)
#define fn_NetSim_Packet_FreePacket(pstruPacket)
#define fnpAddEvent(pstruEvent)
NETSIM_IPAddress * nextHop
NETSIM_IPAddress * gateway
Structure to store the device ip details.
unsigned int nFirewallBlocked
struct stru_NetSim_Packet * pPacket
netsimDEVICE_TYPE nDeviceType
Structure to store ip routing table.
NETSIM_IPAddress * Interface
NETSIM_IPAddress networkDestination
PNETSIM_MACADDRESS szDestMac
PNETSIM_MACADDRESS szSourceMac
NETSIM_IPAddress szGatewayIP
NETWORK_LAYER_PROTOCOL nNetworkProtocol
NETSIM_IPAddress szDestIP
NETSIM_IPAddress szNextHopIp
NETSIM_IPAddress szSourceIP
struct stru_NetSim_Packet_AppLayer * pstruAppData
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
struct stru_NetSim_Packet_MACLayer * pstruMacData
char str_ip[_NETSIM_IP_LEN]