18#include "../Firewall/Firewall.h"
20static void execute_acl_status_command(ptrCLIENTINFO info,
21 ptrCOMMANDARRAY command,
29 IP_DEVVAR* ip = GET_IP_DEVVAR(d);
30 if(ip) ip->isFirewallConfigured = status;
31 send_message(info,
"ACL is %s\n",
32 status ?
"enable" :
"disable");
35void execute_acl_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command,
int index, NETSIM_ID d)
37 if (!_stricmp(command->commands[index + 1],
"enable"))
38 execute_acl_status_command(info, command, index + 1, d,
true);
40 else if (!_stricmp(command->commands[index + 1],
"disable"))
41 execute_acl_status_command(info, command, index + 1, d,
false);
44 send_message(info,
"%s is not a valid option for ACL command.\n"
45 "It must be either ENABLE or DISABLE.\n",
46 command->commands[index + 1]);
49bool validate_acl_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command,
int index)
51 if (command->length - index < 2)
53 send_message(info,
"Too less argument for ACL command\n");
59void execute_aclconfig_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command,
int index, NETSIM_ID d)
64 IP_DEVVAR* ip = GET_IP_DEVVAR(d);
65 if (ip && !ip->isFirewallConfigured)
67 send_message(info,
"ACL is not enable.\n");
71 info->promptString = calloc(strlen(DEVICE_NAME(d)) +
72 strlen(CMD_ACLCONFIG) + 10,
sizeof(
char));
74 sprintf(info->promptString,
"%s/%s",
78 send_message(info,
"%s %s",
83static bool isProto(
char* s)
85 if (!_stricmp(s,
"TCP"))
87 else if (!_stricmp(s,
"UDP"))
89 else if (!_stricmp(s,
"ANY"))
95bool validate_aclconfig_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command,
int index)
97 if (!_stricmp(command->commands[index],
"print"))
100 if (command->length - index < 8)
102 send_message(info,
"Usage: [PERMIT,DENY] [INBOUND,OUTBOUND,BOTH]"
103 " PROTO SRC DEST SPORT DPORT IFID\n");
107 if (_stricmp(command->commands[index],
"PERMIT") &&
108 _stricmp(command->commands[index],
"DENY"))
110 send_message(info,
"First command must be either PERMIT or DENY.\n");
111 send_message(info,
"Usage: [PERMIT,DENY] [INBOUND,OUTBOUND,BOTH]"
112 " PROTO SRC DEST SPORT DPORT IFID\n");
116 if (_stricmp(command->commands[index + 1],
"INBOUND") &&
117 _stricmp(command->commands[index + 1],
"OUTBOUND") &&
118 _stricmp(command->commands[index + 1],
"BOTH"))
120 send_message(info,
"Second command must be INBOUND, OUTBOUND or BOTH.\n");
121 send_message(info,
"Usage: [PERMIT,DENY] [INBOUND,OUTBOUND,BOTH]"
122 " PROTO SRC DEST SPORT DPORT IFID\n");
126 if (!isProto(command->commands[index + 2]))
128 send_message(info,
"Protocol is not valid. Valid protocol is TCP, UDP, or ANY\n");
129 send_message(info,
"Usage: [PERMIT,DENY] [INBOUND,OUTBOUND,BOTH]"
130 " PROTO SRC DEST SPORT DPORT IFID\n");
139void execute_prompt_aclconfig_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command,
int index, NETSIM_ID d)
141 if (!_stricmp(command->commands[index],
"print"))
143 char* a = acl_print(d);
145 send_message(info, a);
147 send_message(info,
"ACL list is empty.\n");
151 char* action = command->commands[index++];
152 char* direction = command->commands[index++];
153 char* proto = command->commands[index++];
154 char* srcIP = command->commands[index++];
155 char* destIP = command->commands[index++];
156 char* sport = command->commands[index++];
157 char* dport = command->commands[index++];
158 char* in = command->commands[index++];
161 sprintf(s,
"%s %s %s %s %s %s %s %s",
170 acl_add_new_line(d, s);
171 send_message(info,
"OK!");