19static bool validate_route_add_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command,
int index)
21 if (command->length - index >= 9)
23 send_message(info,
"Too few argument for route add command\n");
27static bool validate_route_delete_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command,
int index)
29 if (command->length - index >= 1)
31 send_message(info,
"Too few argument for route delete command\n");
35bool validate_route_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command,
int index)
37 if (command->length - index < 2)
39 send_message(info,
"Too less argument for route command\n");
43 if (!_stricmp(command->commands[index + 1],
"add"))
44 return validate_route_add_command(info, command, index + 1);
46 else if (!_stricmp(command->commands[index + 1],
"print"))
49 else if (!_stricmp(command->commands[index + 1],
"delete"))
50 return validate_route_delete_command(info, command, index + 1);
52 send_message(info,
"%s is not valid argument for route command\n",
53 command->commands[index + 1]);
57static void execute_route_add_command(ptrCLIENTINFO info,
58 ptrCOMMANDARRAY command,
62 NETSIM_IPAddress dest = NULL;
63 NETSIM_IPAddress mask = NULL;
64 NETSIM_IPAddress gateway = NULL;
68 int ipType = STR_GET_IP_TYPE(command->commands[index + 1]);
71 fnNetSimError(
"%s ip address is not valid.\n", command->commands[index + 1]);
73 dest = STR_TO_IP(command->commands[index + 1], ipType);
76 mask = STR_TO_IP4(command->commands[index + 3]);
78 prefix = atoi(command->commands[index + 3]);
80 gateway = STR_TO_IP(command->commands[index + 4], ipType);
82 metric = atoi(command->commands[index + 6]);
84 in = atoi(command->commands[index + 8]);
86 iptable_add(IP_WRAPPER_GET(d), dest, mask, prefix, gateway, 1, &DEVICE_NWADDRESS(d, in), &in, metric,
"STATIC");
87 send_message(info,
"OK!\n");
90static void execute_route_print_command(ptrCLIENTINFO info,
91 ptrCOMMANDARRAY command,
98 ptrIP_WRAPPER w = IP_WRAPPER_GET(d);
99 ptrIP_ROUTINGTABLE table = (ptrIP_ROUTINGTABLE)w->table;
100 send_message(info,
"===========================================\n\n");
101 send_message(info,
" IP Route Table\n");
102 send_message(info,
"===========================================\n\n");
104 send_message(info,
"%30s\t%15s\t%30s\t%30s\t%10s\t%10s\n",
105 "Network Destination",
114 send_message(info,
"%30s\t",
115 table->networkDestination->str_ip);
117 if (table->networkDestination->type == 4)
118 send_message(info,
"%15s\t", table->netMask->str_ip);
120 send_message(info,
"%15d\t", table->prefix_len);
123 send_message(info,
"%30s\t", table->gateway->str_ip);
125 send_message(info,
"%30s\t",
"on-link");
127 send_message(info,
"%30s\t%10d\t%10s\n",
128 table->Interface[0]->str_ip,
133 table = LIST_NEXT(table);
135 send_message(info,
"================================================\n");
136 send_message(info,
"\n\n");
139static void execute_route_delete_command(ptrCLIENTINFO info,
140 ptrCOMMANDARRAY command,
144 NETSIM_IPAddress dest = STR_TO_IP(command->commands[index + 1],
145 STR_GET_IP_TYPE(command->commands[index + 1]));
146 iptable_delete(IP_WRAPPER_GET(d), dest, NULL, NULL);
147 send_message(info,
"OK!\n");
150void execute_route_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command,
int index, NETSIM_ID d)
152 if (!_stricmp(command->commands[index + 1],
"add"))
153 execute_route_add_command(info, command, index + 1, d);
155 else if (!_stricmp(command->commands[index + 1],
"print"))
156 execute_route_print_command(info, command, index + 1, d);
158 else if (!_stricmp(command->commands[index + 1],
"delete"))
159 execute_route_delete_command(info, command, index + 1, d);