NetSim Source Code Help
Loading...
Searching...
No Matches
ACLCommand.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2020 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* Author: Shashi kant suman
12* *
13* ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include <signal.h>
16#include "CLI.h"
17#include "../IP/IP.h"
18#include "../Firewall/Firewall.h"
19
21 ptrCOMMANDARRAY command,
22 int index,
23 NETSIM_ID d,
24 bool status)
25{
26 (void)command;
27 (void)index;
28
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");
33}
34
36{
37 if (!_stricmp(command->commands[index + 1], "enable"))
38 execute_acl_status_command(info, command, index + 1, d, true);
39
40 else if (!_stricmp(command->commands[index + 1], "disable"))
41 execute_acl_status_command(info, command, index + 1, d, false);
42
43 else
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]);
47}
48
50{
51 if (command->length - index < 2)
52 {
53 send_message(info, "Too less argument for ACL command\n");
54 return false;
55 }
56 return true;
57}
58
60{
61 (void)command;
62 (void)index;
63
64 IP_DEVVAR* ip = GET_IP_DEVVAR(d);
65 if (ip && !ip->isFirewallConfigured)
66 {
67 send_message(info, "ACL is not enable.\n");
68 return;
69 }
70
71 info->promptString = calloc(strlen(DEVICE_NAME(d)) +
72 strlen(CMD_ACLCONFIG) + 10, sizeof(char));
73
74 sprintf(info->promptString, "%s/%s",
75 DEVICE_NAME(d),
77
78 send_message(info, "%s %s",
80 info->promptString);
81}
82
83static bool isProto(char* s)
84{
85 if (!_stricmp(s, "TCP"))
86 return true;
87 else if (!_stricmp(s, "UDP"))
88 return true;
89 else if (!_stricmp(s, "ANY"))
90 return true;
91 else
92 return false;
93}
94
96{
97 if (!_stricmp(command->commands[index], "print"))
98 return true;
99
100 if (command->length - index < 8)
101 {
102 send_message(info, "Usage: [PERMIT,DENY] [INBOUND,OUTBOUND,BOTH]"
103 " PROTO SRC DEST SPORT DPORT IFID\n");
104 return false;
105 }
106
107 if (_stricmp(command->commands[index], "PERMIT") &&
108 _stricmp(command->commands[index], "DENY"))
109 {
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");
113 return false;
114 }
115
116 if (_stricmp(command->commands[index + 1], "INBOUND") &&
117 _stricmp(command->commands[index + 1], "OUTBOUND") &&
118 _stricmp(command->commands[index + 1], "BOTH"))
119 {
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");
123 return false;
124 }
125
126 if (!isProto(command->commands[index + 2]))
127 {
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");
131 return false;
132 }
133
134 return true;
135}
136
137
138
140{
141 if (!_stricmp(command->commands[index], "print"))
142 {
143 char* a = acl_print(d);
144 if (a)
145 send_message(info, a);
146 else
147 send_message(info, "ACL list is empty.\n");
148 return;
149 }
150
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++];
159
160 char s[BUFSIZ];
161 sprintf(s, "%s %s %s %s %s %s %s %s",
162 action,
163 direction,
164 proto,
165 srcIP,
166 destIP,
167 sport,
168 dport,
169 in);
170 acl_add_new_line(d, s);
171 send_message(info, "OK!");
172}
static bool isProto(char *s)
Definition: ACLCommand.c:83
void execute_acl_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index, NETSIM_ID d)
Definition: ACLCommand.c:35
bool validate_aclconfig_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index)
Definition: ACLCommand.c:95
static void execute_acl_status_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index, NETSIM_ID d, bool status)
Definition: ACLCommand.c:20
void execute_prompt_aclconfig_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index, NETSIM_ID d)
Definition: ACLCommand.c:139
void execute_aclconfig_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index, NETSIM_ID d)
Definition: ACLCommand.c:59
bool validate_acl_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index)
Definition: ACLCommand.c:49
unsigned int NETSIM_ID
Definition: Animation.h:45
#define CMD_CHANGEPROMPT
Definition: CLI.h:12
void send_message(ptrCLIENTINFO info, char *msg,...)
#define CMD_ACLCONFIG
Definition: CLI.h:18
#define GET_IP_DEVVAR(d)
Definition: IP.h:49
#define _stricmp
Definition: Linux.h:127
#define calloc(c, s)
Definition: Memory.h:29
static struct stru_802_11_Phy_Parameters_HT a
#define DEVICE_NAME(DeviceId)
Definition: Stack.h:774
void acl_add_new_line(NETSIM_ID d, char *s)
Definition: firewall.c:185
char * acl_print(NETSIM_ID d)
Definition: firewall.c:346
Structure to store the device ip details.
Definition: IP.h:226
bool isFirewallConfigured
Definition: IP.h:232
char * promptString
Definition: CLI.h:82