15#define _NETSIM_FIREWALL_CODE_
16#pragma comment(lib,"NetworkStack.lib")
40#define ACL_ALLOC() (ptrACL)list_alloc(sizeof(NETSIM_ACL),offsetof(NETSIM_ACL,ele))
41#define ACL_NEXT(acl) acl=(ptrACL)LIST_NEXT(acl)
42#define ACL_ADD(lacl,acl) LIST_ADD_LAST((void**)lacl,acl)
43#define ACL_GET(d) ((ptrACL)(GET_IP_DEVVAR(d)->ACL))
44#define ACL_SET(d,acl) (GET_IP_DEVVAR(d)->ACL = (void*)acl)
53 fnNetSimError(
"Unknown acl action %s. It must be either permit or deny.", s);
61 for (i = 0; i < 4; i++)
72 char bin[9] =
"00000000";
73 for (
int j = 0; j < num; j++)
82 for (
int k = i+1; k < 4; k++)
98 while (mask->
bin_ip[i] ==
'1')
165 else if (!
_stricmp(str,
"OUTBOUND"))
175 for (i = 0; i <
DEVICE(d)->nNumOfInterface; i++)
242 FILE* fp = fopen(p,
"r");
250 while (fgets(buf, BUFSIZ, fp))
257 if (*s ==
'\n' || *s == 0)
275 bool ismatched =
true;
299 if (ismatched && acl->
source)
305 if (ismatched && acl->
dest)
356 sprintf(s,
"%s %s %s %s/%d %s/%d %d %d %d\n",
370 ret =
realloc(ret, (size + strlen(s) + 1) *
sizeof(
char));
375 ret =
calloc(strlen(s) + 1,
sizeof(
char));
379 size += (
UINT)strlen(s);
NETSIM_IPAddress STR_TO_IP(char *ipStr, int type)
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)
bool isMulticastIP(NETSIM_IPAddress ip)
#define _declspec(dllexport)
This function is used to trigger the update.
#define fnNetSimError(x,...)
static const char pathSeperator[5]
#define fnSystemError(x,...)
#define LIST_FREE(ls, mem)
UINT64 binary_to_decimal(char bin[])
char * find_word(char **s)
char * lskip(const char *s)
NETSIM_ID * get_dest_from_packet(NetSim_PACKET *packet, UINT *count)
EXPORTED char * pszIOPath
#define DEVICE_NWADDRESS(DeviceId, InterfaceId)
NETSIM_IPAddress fn_NetSim_Stack_GetFirstIPAddressAsId(NETSIM_ID nDeviceId, unsigned int type)
void acl_add_new_line(NETSIM_ID d, char *s)
static ACL_ACTION action_from_str(char *s)
static char * str_from_proto(IP_PROTOCOL_NUMBER num)
static ACL_TYPE type_from_str(char *str)
static void ip_from_str(char *s, NETSIM_IPAddress *ip, NETSIM_IPAddress *subnet)
static bool check_mac_block(NETSIM_ID d, NETSIM_ID in)
static int perfix_from_mask(NETSIM_IPAddress mask)
int fn_NetSim_FirewallConfig(NETSIM_ID nDeviceId)
static NETSIM_IPAddress get_dest_ip(NetSim_PACKET *packet)
ACL_ACTION fn_NetSim_MAC_Firewall(NETSIM_ID nDeviceId, NETSIM_ID interfaceId, NetSim_PACKET *packet, ACL_TYPE type)
ACL_ACTION fn_NetSim_NETWORK_Firewall(NETSIM_ID nDeviceId, NETSIM_ID interfaceId, NetSim_PACKET *packet, ACL_TYPE type)
static IP_PROTOCOL_NUMBER ipprotocol_from_str(char *pro)
#define ACL_ADD(lacl, acl)
void fn_NetSim_Firewall_Free(NETSIM_ID d)
struct stru_IP_ACL NETSIM_ACL
static NETSIM_IPAddress num_to_subnet(int num)
struct stru_IP_ACL * ptrACL
char * acl_print(NETSIM_ID d)
static ACL_ACTION fn_NetSim_Firewall(NETSIM_ID nDeviceId, NETSIM_ID interfaceId, NetSim_PACKET *packet, ACL_TYPE type, bool isMAC)
NETSIM_IPAddress srcSubnet
IP_PROTOCOL_NUMBER protocol
NETSIM_IPAddress destSubnet
Structure to store the device ip details.
bool isFirewallConfigured
IP_PROTOCOL_NUMBER IPProtocol
NETSIM_IPAddress szDestIP
NETSIM_IPAddress szSourceIP
unsigned short int nSourcePort
unsigned short int nDestinationPort
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
struct stru_NetSim_Packet_TransportLayer * pstruTransportData
char str_ip[_NETSIM_IP_LEN]