blob: 5974c75794f20b05f9153e19cf5e312188a1ceda [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include <sys/ioctl.h>
5#include <fcntl.h>
6#include <getopt.h>
7#include <strings.h>
8#include <unistd.h>
9#ifndef CONFIG_SUPPORT_OPENWRT
10#include <linux/autoconf.h>
11#endif
12
13#if defined CONFIG_COLGIN_SUPPORT
14#include "hnat_ioctl.h"
15#else
16#include "hwnat_ioctl.h"
17#endif
18#include "hwnat_api.h"
19#include "util.h"
20
21void show_usage(void)
22{
23 printf("Add Static Entry\n");
xj112b9672022-01-25 16:13:48 +080024 printf("hw_nat -a -P [PPE_INDEX] -h [SMAC] -i [DMAC] -1 [type:hnapt(0)/ipv6_rout(5)]-j [Sip] -2 [Dip] -l [Sp] -3 [Dp]\n");
xjb04a4022021-11-25 15:01:52 +080025 printf(" -n [New_Sip] -o [New_Dip] -p [New_Sp] -q [New_Dp] -4 [Vlan_layer] -5 [dscp]\n");
26 printf(" -s [VLAN1_ID] -S [VLAN2_ID] -v [Tcp/Udp] -w [OutIf:CPU/GE1/GE2]\n");
xj112b9672022-01-25 16:13:48 +080027 printf("Ex(ipv4): hw_nat -a -P 0 -h 00:0C:43:28:80:11 -i E0:18:77:BD:D5:18 -1 0 -j 10.10.10.3 -2 10.10.20.3\n");
xjb04a4022021-11-25 15:01:52 +080028 printf("-l 1000 -3 2000 -n 10.10.20.254 -o 10.10.20.3 -p 1000 -q 2000 -4 1 -s 1 -v Tcp -w GE2 -5 32\n\n");
29
xj112b9672022-01-25 16:13:48 +080030 printf("Ex(ipv6): hw_nat -a -P 0 -h 00:0C:43:28:02:14 -i 00:1B:21:00:9B:03 -1 5 -6 2001:1111:2222:3333:0000:0000:0000:2\n");
xjb04a4022021-11-25 15:01:52 +080031 printf("-7 2001:aaa:6401:101:8000:0000:0000:2 -l 3000 -3 2000 -4 0 -v Tcp -w GE1 -5 32\n\n");
32
33 printf("Del Static Entry\n");
xj112b9672022-01-25 16:13:48 +080034 printf("hw_nat -b -P [PPE_INDEX] -1 [type:hnapt(0)/ipv6_rout(5)] -j [Sip] -2 [Dip] -l [Sp] -3 [Dp] -v [Tcp/Udp] \n");
35 printf("Ex: hw_nat -b -P 0 -j 10.10.10.3 -k 10.10.20.3 -l 30 -m 40 -v Tcp\n\n");
xjb04a4022021-11-25 15:01:52 +080036#if defined (CONFIG_HW_NAT_SEMI_AUTO_MODE)
37 printf("Add semi-auto Entry\n");
38 printf("hw_nat -a -1 [type:hnapt(0)/ipv6_rout(5)]-j [Sip] -2 [Dip] -l [Sp] -m [Dp]\n");
39 printf("hw_nat -a -1 0 -j 10.10.10.3 -2 10.10.20.3 -l 1000 -3 2000 \n");
40 printf("hw_nat -a -1 5 -j 2001:1111:2222:3333:0000:0000:0000:2 -2 2001:aaa:6401:101:8000:0000:0000:2 -l 3000 -3 2000\n");
41 printf("Delete semi-auto Entry\n");
42 printf("hw_nat -b -1 0 -j 10.10.10.3 -2 10.10.20.3 -l 1000 -3 2000\n");
43 printf("hw_nat -b -1 5 -j 2001:1111:2222:3333:0000:0000:0000:2 -2 2001:aaa:6401:101:8000:0000:0000:2 -l 3000 -3 2000\n");
44#endif
45 printf("Show Foe Entry\n");
xj112b9672022-01-25 16:13:48 +080046 printf("hw_nat -c [entry_num] -P [ppe_index]\n");
47 printf("Ex: hw_nat -c 1234 -P 0\n\n");
xjb04a4022021-11-25 15:01:52 +080048
49 printf("Set Debug Level (0:disable) \n");
50 printf("hw_nat -d [0~7]\n");
51 printf("Ex: hw_nat -d \n\n");
52
53 printf("Show All Foe Invalid Entry\n");
54 printf("Ex: hw_nat -e\n\n");
55
56 printf("Show All Foe Unbinded Entry\n");
57 printf("Ex: hw_nat -f\n\n");
58
59 printf("Show All Foe Binded Entry\n");
60 printf("Ex: hw_nat -g\n\n");
61
xj112b9672022-01-25 16:13:48 +080062 printf("Invalid Foe Entry\n");
63 printf("hw_nat -I [entry_num] -P [ppe_index]\n");
64 printf("Ex: hw_nat -I 1234 -P 0\n\n");
65
xjb04a4022021-11-25 15:01:52 +080066 printf("Unbind Foe Entry\n");
xj112b9672022-01-25 16:13:48 +080067 printf("hw_nat -x [entry_num] -P [ppe_index]\n");
68 printf("Ex: hw_nat -x 1234 -P 0\n\n");
xjb04a4022021-11-25 15:01:52 +080069
70 printf("Set Foe Entry to PacketDrop\n");
xj112b9672022-01-25 16:13:48 +080071 printf("hw_nat -k [entry_num] -P [ppe_index]\n");
72 printf("Ex: hw_nat -k 1234 -P 0\n\n");
xjb04a4022021-11-25 15:01:52 +080073
74
75#if defined (CONFIG_PPE_MCAST)
76 printf("Add member port in multicast entry\n");
77 printf("Ex: hw_nat -B [vid] [mac] [px_en] [px_qos_en] [mc_qos_qid]\n\n");
78
79 printf("Del member port multicast entry\n");
80 printf("Ex: hw_nat -C [vid] [mac] [px_en] [px_qos_en] [mc_qos_qid]\n\n");
81
82 printf("Dump all multicast entry\n");
83 printf("Ex: hw_nat -D\n\n");
84#endif
85
86 printf("Set PPE Cofigurations:\n");
87 printf("Set HNAT binding threshold per second (d=30)\n");
88 printf("Ex: hw_nat -N [1~65535]\n\n");
89
90
91 printf("Set HNAT TCP/UDP keepalive interval (d=1, 1)(unit:4sec)\n");
92 printf("Ex: hw_nat -Q [1~255][1~255]\n\n");
93
xj112b9672022-01-25 16:13:48 +080094 printf("Disable Hook API (hook_id: 0=ETH, 1=MD, 2=WIFI, 3=RNDIS, 4=EXT, 5=SNPS)\n");
95 printf("Ex: hw_nat -O <hook_id>, hwnat -O [0/1/2/3/4/5]\n\n");
xjb04a4022021-11-25 15:01:52 +080096
xj112b9672022-01-25 16:13:48 +080097 printf("Restore Hook API (hook_id: 0=ETH, 1=MD, 2=WIFI, 3=RNDIS, 4=EXT, 5=SNPS)\n");
98 printf("Ex: hw_nat -T <hook_id>, hwnat -T [0/1/2/3/4/5]\n\n");
xjb04a4022021-11-25 15:01:52 +080099
xj112b9672022-01-25 16:13:48 +0800100 printf("Disable Hook API on specific direction (hook_id: 0=ETH, 1=MD, 2=WIFI, 3=RNDIS, 4=EXT, 5=SNPS) (dir: 1:rx, 2:tx)\n");
101 printf("Ex: hw_nat -O <hook_id> -P <dir_id>, hwnat -O [0/1/2/3/4/5] -P[1/2]\n\n");
xjb04a4022021-11-25 15:01:52 +0800102
xj112b9672022-01-25 16:13:48 +0800103 printf("Restore Hook API on specific direction (hook_id: 0=ETH, 1=MD, 2=WIFI, 3=RNDIS, 4=EXT, 5=SNPS) (dir: 1:rx, 2:tx)\n");
104 printf("Ex: hw_nat -T <hook_id> -P <dir_id>, hwnat -T [0/1/2/3/4/5] -P[1/2]\n\n");
xjb04a4022021-11-25 15:01:52 +0800105
106 printf("Set HNAT Life time of Binded TCP/UDP/FIN entry(d=5, 5, 5)(unit:1Sec) \n");
107 printf("Ex: hw_nat -U [1~65535][1~65535][1~65535]\n\n");
108
109 printf("Set LAN/WAN port VLAN ID\n");
110 printf("Ex: hw_nat -V [LAN_VID] [WAN_VID]\n\n");
111 printf("Ex: hw_nat -V 1 2\n\n");
112
113 printf("Only Speed UP (0=Upstream, 1=Downstream, 2=Bi-Direction) flow \n");
114 printf("Ex: hw_nat -Z 1\n\n");
115
116#if defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621)
117 printf("Switch Ds-Lite and Map-E(0=Ds-Lite, 1=Map-E,(d=0)):\n");
118 printf("Ex: hw_nat -W [0/1]\n\n");
119#endif
120#if defined (CONFIG_PPE_MIB)
121 printf("Get ppe entry mib counter\n");
122 printf("hw_nat -M -1 [type:hnapt(0)/ipv6_rout(5)]-j [Sip] -2 [Dip] -l [Sp] -m [Dp]\n");
123 printf("hw_nat -M -1 0 -j 10.10.10.3 -2 10.10.20.3 -l 1000 -3 2000 \n");
124 printf("hw_nat -M -1 5 -j 2001:1111:2222:3333:0000:0000:0000:2 -2 2001:aaa:6401:101:8000:0000:0000:2 -l 3000 -3 2000\n");
125 printf("Get ppe entry all mib counter sort by IP\n");
126 printf("hw_nat -X\n");
127#endif
128#if defined (CONFIG_HW_NAT_IPI)
129 printf("Set HNAT IPI control from extif:\n");
130 printf("EX: hw_nat -G [ipi_enable] [queue_thresh] [drop_pkt] [ipi_cnt_mod]\n\n");
131 printf("Set HNAT IPI control from ppehit:\n");
132 printf("EX: hw_nat -L [ipi_enable] [queue_thresh] [drop_pkt] [ipi_cnt_mod]\n\n");
133 printf("hw_nat -G 1 1000 20000 5\n");
134 printf("hw_nat -L 1 1000 20000 44\n");
135#endif
136}
137#if defined CONFIG_COLGIN_SUPPORT
138static void dump_all_ip_cnt(struct hwnat_mib_all_ip_args *args)
139{
140 int i;
141 if(args->entry_num > 0)
142 printf("IP tx_packets tx_bytes rx_packets rx_bytes\n");
143 for(i=0; i<args->entry_num; i++) {
144 if(args->entries[i].is_ipv4) { //IPV4_NAPT
145 printf("%8x %10ld %10ld %10ld %10ld\n",
146 args->entries[i].ip.ipv4_addr,
147 args->entries[i].tx_packets,
148 args->entries[i].tx_bytes,
149 args->entries[i].rx_packets,
150 args->entries[i].rx_bytes);
151 } else { //IPV6_5T_ROUTE
152 printf(" %4x:%4x:%4x:%4x:%4x:%4x:%4x:%4x %10ld %10ld %10ld %10ld\n",
153 NIPHALF(args->entries[i].ip.ipv6_addr[0]),
154 NIPHALF(args->entries[i].ip.ipv6_addr[1]),
155 NIPHALF(args->entries[i].ip.ipv6_addr[2]),
156 NIPHALF(args->entries[i].ip.ipv6_addr[3]),
157 args->entries[i].tx_packets,
158 args->entries[i].tx_bytes,
159 args->entries[i].rx_packets,
160 args->entries[i].rx_bytes);
161 }
162 }
163}
164#endif
165int main(int argc, char *argv[])
166{
167 int opt;
168
169 //char options[] = "aefgy?c:x:k:d:A:B:C:DN:O:P:Q:T:U:V:Z:";
170 char options[] = "abefgyzMD?c:m:r:A:B:C:G:I:J:K:L:S:d:h:i:j:1:k:2:l:3:n:o:p:q:4:s:P:t:u:v:w:5:x:y:N:O:Q:T:U:Z:L:7:8:9:E:F:H:R:6:X";
171
172 int fd, method = -1;
173 int i=0;
174 unsigned int entry_num;
175 unsigned int debug;
176 unsigned int type;
xj112b9672022-01-25 16:13:48 +0800177 struct hwnat_args *args = {0};
xjb04a4022021-11-25 15:01:52 +0800178 struct hwnat_tuple args2 = {0};
179 struct hwnat_ac_args args3;
180 struct hwnat_config_args args4;
181#if defined (CONFIG_HW_NAT_IPI)
182 struct hwnat_ipi_args args6;
183 struct hwnat_ipi_args args7;
184#endif
185
186#if defined (CONFIG_PPE_MCAST)
187 struct hwnat_mcast_args args5;
188 unsigned char mac[6];
189#endif
190#if defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621)
191 unsigned int swit;
192#endif
193 int result;
194#if defined CONFIG_COLGIN_SUPPORT
195 int org_tot_len = 1362;
196 int org_id = 0;
197 int org_frag =0;
198 int chksum_tmp, tot_len_tmp, id_tmp, frag_tmp;
199 int chksum_base = 0;
200 struct hwnat_mib_all_ip_args *args8;
201#endif
202 fd = open("/dev/"HW_NAT_DEVNAME, O_RDONLY);
203 if (fd < 0)
204 {
205 printf("Open %s pseudo device failed\n","/dev/"HW_NAT_DEVNAME);
206 return 0;
207 }
208
209 if(argc < 2) {
210 show_usage();
211 close(fd);
212 return 0;
213 }
214
215 /* Max table size is 16K */
216 args=malloc(sizeof(struct hwnat_args)+sizeof(struct hwnat_tuple)*1024*16);
217 if (NULL == args)
218 {
219 printf(" Allocate memory for hwnat_args and hwnat_tuple failed.\n");
220 close(fd);
221 return 0;
222 }
223
224 while ((opt = getopt (argc, argv, options)) != -1) {
225 switch (opt) {
226 case 'h':
227 str_to_mac(args2.smac, optarg);
228 break;
229 case 'i':
230 str_to_mac(args2.dmac, optarg);
231 break;
232 case '1':
233 type = strtoll(optarg, NULL, 10);
234 args2.pkt_type = type;
235 break;
236 case 'j':
237 if ((type == 0) || (type == 7)) {
238 str_to_ip(&args2.ing_sipv4, optarg);
239 } else if((type == 5) || (type == 3)) {
240 str_to_ipv6(&args2.ing_sipv6_0, optarg, 0);
241 str_to_ipv6(&args2.ing_sipv6_1, optarg, 1);
242 str_to_ipv6(&args2.ing_sipv6_2, optarg, 2);
243 str_to_ipv6(&args2.ing_sipv6_3, optarg, 3);
244 } else {
245 printf("hwnat type error\n");
246 free(args);
247 close(fd);
248 return 0;
249 }
250 break;
251 case '2':
252 if ((type == 0) || (type == 7)) {
253 str_to_ip(&args2.ing_dipv4, optarg);
254 } else if((type == 5) || (type == 3)) {
255 str_to_ipv6(&args2.ing_dipv6_0, optarg, 0);
256 str_to_ipv6(&args2.ing_dipv6_1, optarg, 1);
257 str_to_ipv6(&args2.ing_dipv6_2, optarg, 2);
258 str_to_ipv6(&args2.ing_dipv6_3, optarg, 3);
259 } else {
260 printf("hwnat type error\n");
261 free(args);
262 close(fd);
263 return 0;
264 }
265 break;
266 case 'l':
267 args2.ing_sp = strtoll(optarg, NULL, 10);
268 break;
269 case '3':
270 args2.ing_dp = strtoll(optarg, NULL, 10);
271 break;
272 case 'n':
273 str_to_ip(&args2.eg_sipv4, optarg);
274 break;
275 case 'o':
276 str_to_ip(&args2.eg_dipv4, optarg);
277 break;
278 case 'p':
279 args2.eg_sp = strtoll(optarg, NULL, 10);
280 break;
281 case 'q':
282 args2.eg_dp = strtoll(optarg, NULL, 10);
283 break;
284 case '4':
285 args2.vlan_layer = strtoll(optarg, NULL, 10);
286 break;
287 case 's':
288 args2.vlan1 = strtoll(optarg, NULL, 10);
289 break;
290 case 'S':
291 args2.vlan2 = strtoll(optarg, NULL, 10);
292 break;
293#if defined CONFIG_COLGIN_SUPPORT
294 case 'P':
xj112b9672022-01-25 16:13:48 +0800295 args2.set_idx = strtoll(optarg, NULL, 16);
xjb04a4022021-11-25 15:01:52 +0800296 break;
297#endif
298 case 't':
299 if(strcasecmp(optarg,"Ins")==0){
300 args2.pppoe_act=1;
301 }else if(strcasecmp(optarg,"Del")==0){
302 args2.pppoe_act=0;
303 }else{
304 printf("Error: -t No/Mod/Ins/Del\n");
305 free(args);
306 close(fd);
307 return 0;
308 }
309 break;
310 case 'u':
311 args2.pppoe_id = strtoll(optarg, NULL, 10);
312 break;
313 case 'v':
314 if(strcasecmp(optarg,"Tcp")==0){
315 args2.is_udp=0;
316 }else if(strcasecmp(optarg,"Udp")==0){
317 args2.is_udp=1;
318 }else {
319 printf("Error: -v Tcp/Udp\n");
320 free(args);
321 close(fd);
322 return 0;
323 }
324 break;
325 case 'w':
326 if(strcasecmp(optarg,"CPU")==0){
327 args2.dst_port=0;
328 }else if(strcasecmp(optarg,"GE1")==0){
329 args2.dst_port=1;
330 }else if(strcasecmp(optarg,"GE2")==0){
331 args2.dst_port=2;
xj112b9672022-01-25 16:13:48 +0800332 }else if(strcasecmp(optarg,"P7")==0){
333 args2.dst_port=7;
xjb04a4022021-11-25 15:01:52 +0800334 }else if(strcasecmp(optarg,"P8")==0){
335 args2.dst_port=8;
xj112b9672022-01-25 16:13:48 +0800336 }else if(strcasecmp(optarg,"P9")==0){
337 args2.dst_port=9;
xjb04a4022021-11-25 15:01:52 +0800338 }else if(strcasecmp(optarg,"p10")==0){
339 args2.dst_port=10;
340 }else if(strcasecmp(optarg,"p11")==0){
341 args2.dst_port=11;
342 }else if(strcasecmp(optarg,"p12")==0){
343 args2.dst_port=12;
344 }else {
xj112b9672022-01-25 16:13:48 +0800345 printf("Error: -w CPU/GE1/GE2/P7/P8/P9/P10/P11/P12\n");
xjb04a4022021-11-25 15:01:52 +0800346 free(args);
347 close(fd);
348 return 0;
349 }
350 break;
351 case '5':
352 args2.dscp = strtoll(optarg, NULL, 10);
353 break;
354 case '7':
355 str_to_ipv6(&args2.ing_sipv6_0, optarg, 0);
356 str_to_ipv6(&args2.ing_sipv6_1, optarg, 1);
357 str_to_ipv6(&args2.ing_sipv6_2, optarg, 2);
358 str_to_ipv6(&args2.ing_sipv6_3, optarg, 3);
359 break;
360 case '8':
361 str_to_ipv6(&args2.ing_dipv6_0, optarg, 0);
362 str_to_ipv6(&args2.ing_dipv6_1, optarg, 1);
363 str_to_ipv6(&args2.ing_dipv6_2, optarg, 2);
364 str_to_ipv6(&args2.ing_dipv6_3, optarg, 3);
365 break;
366#if defined CONFIG_COLGIN_SUPPORT
367 case '9':
368 args2.rmt = strtoll(optarg, NULL, 10);
369 break;
370#endif
371 case 'E':
372 args2.hash_index = strtoll(optarg, NULL, 10);
373 break;
374#if defined CONFIG_COLGIN_SUPPORT
375 case 'F':
376 args2.frag = strtoll(optarg, NULL, 10);
377 break;
378 case 'H':
379 chksum_tmp = strtoll(optarg, NULL, 16);
380 chksum_tmp = (0xffff-chksum_tmp);
381 chksum_tmp = (chksum_tmp - org_tot_len - org_id);
382 chksum_base = chksum_tmp & 0xFFFF;
383 printf("chksum_base = %x\n", chksum_base);
384 args2.checksum = chksum_base;
385 break;
386 case 'R':
387 args2.ttl = strtoll(optarg, NULL, 10);
388 break;
389#endif
390 case 'a':
391 method = HW_NAT_ADD_ENTRY;
392 break;
393
394 case 'b':
395 method = HW_NAT_DEL_ENTRY;
396 break;
397 case 'z':
398 method = HW_NAT_DUMP_CACHE_ENTRY;
399 break;
400 case 'c':
401 method = HW_NAT_DUMP_ENTRY;
402 entry_num = strtoll(optarg, NULL, 10);
403 break;
404 case 'I':
405 method = HW_NAT_INVALID_ENTRY;
406 entry_num = strtoll(optarg, NULL, 10);
407 break;
408 case 'x':
409 method = HW_NAT_UNBIND_ENTRY;
410 entry_num = strtoll(optarg, NULL, 10);
411 break;
412 case 'k':
413 method = HW_NAT_DROP_ENTRY;
414 entry_num = strtoll(optarg, NULL, 10);
415 break;
416 case 'd':
417 method = HW_NAT_DEBUG;
418 debug = strtoll(optarg, NULL, 10);
419 break;
420#if defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621)
421 case 'W':
422 method = HW_NAT_SWITCH_DSL_MAPE;
423 swit = strtoll(optarg, NULL, 10);
424 break;
425#endif
426 case 'e':
427 method = HW_NAT_GET_ALL_ENTRIES;
428 args->entry_state=0; /* invalid entry */
429 break;
430 case 'f':
431 method = HW_NAT_GET_ALL_ENTRIES;
432 args->entry_state=1; /* unbinded entry */
433 break;
434 case 'g':
435 method = HW_NAT_GET_ALL_ENTRIES;
436 args->entry_state=2; /* binded entry */
437 break;
438 case 'y':
439 method = HW_NAT_TBL_CLEAR;
440 break;
441 case 'A':
442 method = HW_NAT_GET_AC_CNT;
443 args3.ag_index = strtoll(optarg, NULL, 10);
444 break;
445#if defined (CONFIG_PPE_MCAST)
446 case 'B':
447 method = HW_NAT_MCAST_INS;
448 args5.mc_vid = strtoll(argv[2], NULL, 10);
449 str_to_mac(mac, argv[3]);
450 memcpy(args5.dst_mac, mac, sizeof(mac));
451 args5.mc_px_en = strtoll(argv[4], NULL, 10);
452 args5.mc_px_qos_en = strtoll(argv[5], NULL, 10);
453 args5.mc_qos_qid = strtoll(argv[6], NULL, 10);
454 break;
455 case 'C':
456 method = HW_NAT_MCAST_DEL;
457 args5.mc_vid = strtoll(argv[2], NULL, 10);
458 str_to_mac(mac, argv[3]);
459 memcpy(args5.dst_mac, mac, sizeof(mac));
460 memcpy(args5.dst_mac, mac, sizeof(mac));
461 args5.mc_px_en = strtoll(argv[4], NULL, 10);
462 args5.mc_px_qos_en = strtoll(argv[5], NULL, 10);
463 args5.mc_qos_qid = strtoll(argv[6], NULL, 10);
464 break;
465 case 'D':
466 method = HW_NAT_MCAST_DUMP;
467 break;
468#endif
469#if defined (CONFIG_PPE_MIB)
470 case 'm':
471 method = HW_NAT_MIB_DUMP;
472 entry_num = strtoll(optarg, NULL, 10);
473 break;
474 case 'r':
475 method = HW_NAT_MIB_DRAM_DUMP;
476 entry_num = strtoll(optarg, NULL, 10);
477 break;
478 case 'M':
479 method = HW_NAT_MIB_GET;
480 break;
481#if defined CONFIG_COLGIN_SUPPORT
482 case 'X':
483 method = HW_NAT_MIB_GET_ALL_IP;
484 break;
485#endif
486#endif
487 case 'N':
488 method = HW_NAT_BIND_THRESHOLD;
489 args4.bind_threshold = strtoll(argv[2], NULL, 10);
490 break;
491 case 'Q':
492 method = HW_NAT_KA_INTERVAL;
493 args4.foe_tcp_ka = strtoll(argv[2], NULL, 10);
494 args4.foe_udp_ka = strtoll(argv[3], NULL, 10);
495 break;
496 case 'U':
497 method = HW_NAT_BIND_LIFETIME;
498 args4.foe_tcp_dlta = strtoll(argv[2], NULL, 10);
499 args4.foe_udp_dlta = strtoll(argv[3], NULL, 10);
500 args4.foe_fin_dlta = strtoll(argv[4], NULL, 10);
501 break;
502 case 'V':
503 method = HW_NAT_VLAN_ID;
504 args4.lan_vid = strtoll(argv[2], NULL, 10);
505 args4.wan_vid = strtoll(argv[3], NULL, 10);
506 break;
507 case 'Z':
508 method = HW_NAT_BIND_DIRECTION;
509 args4.bind_dir = strtoll(optarg, NULL, 10);
510 break;
511#if defined (CONFIG_HW_NAT_IPI)
512 case 'G': /*FIXME..........................*/
513 method = HW_NAT_IPI_CTRL_FROM_EXTIF;
514 args6.hnat_ipi_enable = strtoll(argv[2], NULL, 10);
515 args6.queue_thresh = strtoll(argv[3], NULL, 10);
516 args6.drop_pkt = strtoll(argv[4], NULL, 10);
517 args6.ipi_cnt_mod = strtoll(argv[5], NULL, 10);
518 //printf("##### hnat_ipi_enable=%d, queue_thresh=%d, drop_pkt=%d #####\n",
519 // args6.hnat_ipi_enable, args6.queue_thresh, args6.drop_pkt);
520 break;
521 case 'L': /*FIXME..........................*/
522 method = HW_NAT_IPI_CTRL_FROM_PPEHIT;
523 args7.hnat_ipi_enable = strtoll(argv[2], NULL, 10);
524 args7.queue_thresh = strtoll(argv[3], NULL, 10);
525 args7.drop_pkt = strtoll(argv[4], NULL, 10);
526 args7.ipi_cnt_mod = strtoll(argv[5], NULL, 10);
527 //printf("##### hnat_ipi_enable2=%d, queue_thresh2=%d, drop_pkt2=%d #####\n",
528 // args7.hnat_ipi_enable2, args7.queue_thresh2, args7.drop_pkt);
529 break;
530#endif
531 case '6':
532 method = HW_NAT_DPORT;
533 break;
534 case 'O':
535 method = HW_NAT_CLEAR_HOOK;
536 args2.dst_port = strtoll(optarg, NULL, 10);
537 break;
538 case 'T':
539 method = HW_NAT_RESTORE_HOOK;
540 args2.dst_port = strtoll(optarg, NULL, 10);
541 break;
542 case '?':
543 show_usage();
544
545 }
546 }
547
548 switch(method){
549//#if defined (CONFIG_HW_NAT_MANUAL_MODE) || defined (CONFIG_HW_NAT_SEMI_AUTO_MODE)
550 case HW_NAT_ADD_ENTRY:
551 result = HwNatAddEntry(&args2);
552 break;
553 case HW_NAT_DEL_ENTRY:
554 result = HwNatDelEntry(&args2);
555 break;
556//#endif
557 case HW_NAT_GET_ALL_ENTRIES:
558 HwNatGetAllEntries(args);
559
560 printf("Total Entry Count = %d\n",args->num_of_entries);
561 for(i=0;i<args->num_of_entries;i++){
562 if(args->entries[i].pkt_type==0) { //IPV4_NAPT
563 printf("IPv4_NAPT=%d : %u.%u.%u.%u:%d->%u.%u.%u.%u:%d => %u.%u.%u.%u:%d->%u.%u.%u.%u:%d (RX=%d FP=%d FQOS=%d QID=%d)\n",
564 args->entries[i].hash_index,
565 NIPQUAD(args->entries[i].ing_sipv4),
566 args->entries[i].ing_sp,
567 NIPQUAD(args->entries[i].ing_dipv4),
568 args->entries[i].ing_dp,
569 NIPQUAD(args->entries[i].eg_sipv4),
570 args->entries[i].eg_sp,
571 NIPQUAD(args->entries[i].eg_dipv4),
572 args->entries[i].eg_dp,
573 args->entries[i].rxif_idx,
574 args->entries[i].fport,
575 args->entries[i].fqos,
576 args->entries[i].qid);
577
578 } else if(args->entries[i].pkt_type==1) { //IPV4_NAT
579 printf("IPv4_NAT=%d : %u.%u.%u.%u->%u.%u.%u.%u => %u.%u.%u.%u->%u.%u.%u.%u (RX=%d FP=%d FQOS=%d QID=%d)\n",
580 args->entries[i].hash_index,
581 NIPQUAD(args->entries[i].ing_sipv4),
582 NIPQUAD(args->entries[i].ing_dipv4),
583 NIPQUAD(args->entries[i].eg_sipv4),
584 NIPQUAD(args->entries[i].eg_dipv4),
585 args->entries[i].rxif_idx,
586 args->entries[i].fport,
587 args->entries[i].fqos,
588 args->entries[i].qid);
589
590 } else if(args->entries[i].pkt_type==2) { //IPV6_ROUTING
591 printf("IPv6_1T= %d /DIP: %x:%x:%x:%x:%x:%x:%x:%x (RX=%d FP=%d FQOS=%d QID=%d)\n",
592 args->entries[i].hash_index,
593 NIPHALF(args->entries[i].ing_dipv6_0),
594 NIPHALF(args->entries[i].ing_dipv6_1),
595 NIPHALF(args->entries[i].ing_dipv6_2),
596 NIPHALF(args->entries[i].ing_dipv6_3),
597 args->entries[i].rxif_idx,
598 args->entries[i].fport,
599 args->entries[i].fqos,
600 args->entries[i].qid);
601
602 } else if(args->entries[i].pkt_type==3) { //IPV4_DSLITE
603 printf("DS-Lite= %d : %u.%u.%u.%u:%d->%u.%u.%u.%u:%d (%x:%x:%x:%x:%x:%x:%x:%x -> %x:%x:%x:%x:%x:%x:%x:%x)(RX=%d FP=%d FQOS=%d QID=%d)\n", \
604 args->entries[i].hash_index,
605 NIPQUAD(args->entries[i].ing_sipv4),
606 args->entries[i].ing_sp,
607 NIPQUAD(args->entries[i].ing_dipv4),
608 args->entries[i].ing_dp,
609 NIPHALF(args->entries[i].eg_sipv6_0),
610 NIPHALF(args->entries[i].eg_sipv6_1),
611 NIPHALF(args->entries[i].eg_sipv6_2),
612 NIPHALF(args->entries[i].eg_sipv6_3),
613 NIPHALF(args->entries[i].eg_dipv6_0),
614 NIPHALF(args->entries[i].eg_dipv6_1),
615 NIPHALF(args->entries[i].eg_dipv6_2),
616 NIPHALF(args->entries[i].eg_dipv6_3),
617 args->entries[i].rxif_idx,
618 args->entries[i].fport,
619 args->entries[i].fqos,
620 args->entries[i].qid);
621
622 } else if(args->entries[i].pkt_type==4) { //IPV6_3T_ROUTE
623 printf("IPv6_3T= %d SIP: %x:%x:%x:%x:%x:%x:%x:%x DIP: %x:%x:%x:%x:%x:%x:%x:%x (RX=%d FP=%d FQOS=%d QID=%d)\n",
624 args->entries[i].hash_index,
625 NIPHALF(args->entries[i].ing_sipv6_0),
626 NIPHALF(args->entries[i].ing_sipv6_1),
627 NIPHALF(args->entries[i].ing_sipv6_2),
628 NIPHALF(args->entries[i].ing_sipv6_3),
629 NIPHALF(args->entries[i].ing_dipv6_0),
630 NIPHALF(args->entries[i].ing_dipv6_1),
631 NIPHALF(args->entries[i].ing_dipv6_2),
632 NIPHALF(args->entries[i].ing_dipv6_3),
633 args->entries[i].rxif_idx,
634 args->entries[i].fport,
635 args->entries[i].fqos,
636 args->entries[i].qid);
637
638 } else if(args->entries[i].pkt_type==5) { //IPV6_5T_ROUTE
639 if(args->entries[i].ipv6_flowlabel==1) {
640 printf("IPv6_5T= %d SIP: %x:%x:%x:%x:%x:%x:%x:%x DIP: %x:%x:%x:%x:%x:%x:%x:%x (Flow Label=%x) (RX=%d FP=%d FQOS=%d QID=%d)\n",
641 args->entries[i].hash_index,
642 NIPHALF(args->entries[i].ing_sipv6_0),
643 NIPHALF(args->entries[i].ing_sipv6_1),
644 NIPHALF(args->entries[i].ing_sipv6_2),
645 NIPHALF(args->entries[i].ing_sipv6_3),
646 NIPHALF(args->entries[i].ing_dipv6_0),
647 NIPHALF(args->entries[i].ing_dipv6_1),
648 NIPHALF(args->entries[i].ing_dipv6_2),
649 NIPHALF(args->entries[i].ing_dipv6_3),
650 ((args->entries[i].ing_sp << 16) | (args->entries[i].ing_dp))&0xFFFFF,
651 args->entries[i].rxif_idx,
652 args->entries[i].fport,
653 args->entries[i].fqos,
654 args->entries[i].qid);
655
656 }else {
657 printf("IPv6_5T= %d SIP: %x:%x:%x:%x:%x:%x:%x:%x %d DIP: %x:%x:%x:%x:%x:%x:%x:%x %d (RX=%d FP=%d FQOS=%d QID=%d)\n",
658 args->entries[i].hash_index,
659 NIPHALF(args->entries[i].ing_sipv6_0),
660 NIPHALF(args->entries[i].ing_sipv6_1),
661 NIPHALF(args->entries[i].ing_sipv6_2),
662 NIPHALF(args->entries[i].ing_sipv6_3),
663 args->entries[i].ing_sp,
664 NIPHALF(args->entries[i].ing_dipv6_0),
665 NIPHALF(args->entries[i].ing_dipv6_1),
666 NIPHALF(args->entries[i].ing_dipv6_2),
667 NIPHALF(args->entries[i].ing_dipv6_3),
668 args->entries[i].ing_dp,
669 args->entries[i].rxif_idx,
670 args->entries[i].fport,
671 args->entries[i].fqos,
672 args->entries[i].qid);
673 }
674
675 } else if(args->entries[i].pkt_type==7) { //IPV6_6RD
676 if(args->entries[i].ipv6_flowlabel==1) {
677 printf("6RD= %d %x:%x:%x:%x:%x:%x:%x:%x->%x:%x:%x:%x:%x:%x:%x:%x [Flow Label=%x]\n",
678 args->entries[i].hash_index, \
679 NIPHALF(args->entries[i].ing_sipv6_0),
680 NIPHALF(args->entries[i].ing_sipv6_1),
681 NIPHALF(args->entries[i].ing_sipv6_2),
682 NIPHALF(args->entries[i].ing_sipv6_3),
683 NIPHALF(args->entries[i].ing_dipv6_0),
684 NIPHALF(args->entries[i].ing_dipv6_1),
685 NIPHALF(args->entries[i].ing_dipv6_2),
686 NIPHALF(args->entries[i].ing_dipv6_3),
687 ((args->entries[i].ing_sp << 16) | (args->entries[i].ing_dp))&0xFFFFF);
688 printf("(%u.%u.%u.%u->%u.%u.%u.%u)(RX=%d FP=%d FQOS=%d QID=%d)\n",
689 NIPQUAD(args->entries[i].eg_sipv4),
690 NIPQUAD(args->entries[i].eg_dipv4),
691 args->entries[i].rxif_idx,
692 args->entries[i].fport,
693 args->entries[i].fqos,
694 args->entries[i].qid);
695 }else {
696 printf("6RD= %d /SIP: %x:%x:%x:%x:%x:%x:%x:%x [SP:%d] /DIP: %x:%x:%x:%x:%x:%x:%x:%x [DP=%d]",
697 args->entries[i].hash_index,
698 NIPHALF(args->entries[i].ing_sipv6_0),
699 NIPHALF(args->entries[i].ing_sipv6_1),
700 NIPHALF(args->entries[i].ing_sipv6_2),
701 NIPHALF(args->entries[i].ing_sipv6_3),
702 args->entries[i].ing_sp,
703 NIPHALF(args->entries[i].ing_dipv6_0),
704 NIPHALF(args->entries[i].ing_dipv6_1),
705 NIPHALF(args->entries[i].ing_dipv6_2),
706 NIPHALF(args->entries[i].ing_dipv6_3),
707 args->entries[i].ing_dp);
708 printf("(%u.%u.%u.%u->%u.%u.%u.%u)(RX=%d FP=%d FQOS=%d QID=%d)\n",
709 NIPQUAD(args->entries[i].eg_sipv4),
710 NIPQUAD(args->entries[i].eg_dipv4),
711 args->entries[i].rxif_idx,
712 args->entries[i].fport,
713 args->entries[i].fqos,
714 args->entries[i].qid);
715 }
716 } else{
717 printf("unknown packet type! (pkt_type=%d) \n", args->entries[i].pkt_type);
718 }
719 }
720 result = args->result;
721 break;
722 case HW_NAT_DUMP_CACHE_ENTRY:
723 result = HwNatCacheDumpEntry();
724 break;
725 case HW_NAT_DUMP_ENTRY:
xj112b9672022-01-25 16:13:48 +0800726 result = HwNatDumpEntry(entry_num, args2.set_idx);
xjb04a4022021-11-25 15:01:52 +0800727 break;
728 case HW_NAT_UNBIND_ENTRY:
xj112b9672022-01-25 16:13:48 +0800729 result = HwNatUnBindEntry(entry_num, args2.set_idx);
xjb04a4022021-11-25 15:01:52 +0800730 break;
731 case HW_NAT_DROP_ENTRY:
xj112b9672022-01-25 16:13:48 +0800732 result = HwNatDropEntry(entry_num, args2.set_idx);
xjb04a4022021-11-25 15:01:52 +0800733 break;
734 case HW_NAT_DEBUG:
735 result = HwNatDebug(debug);
736 break;
737#if defined (CONFIG_RALINK_MT7620) || defined (CONFIG_RALINK_MT7621)
738 case HW_NAT_SWITCH_DSL_MAPE:
739 result = HwNatSwitchDsliteMape(swit);
740 break;
741#endif
742 case HW_NAT_GET_AC_CNT:
743 HwNatGetAGCnt(&args3);
744 printf("Byte cnt=%llu\n", args3.ag_byte_cnt);
745 printf("Pkt cnt=%llu\n", args3.ag_pkt_cnt);
746 result = args3.result;
747 break;
748
749 case HW_NAT_BIND_THRESHOLD:
750 result = HwNatSetBindThreshold(&args4);
751 break;
752 case HW_NAT_MAX_ENTRY_LMT:
753 HwNatSetMaxEntryRateLimit(&args4);
754 result = args4.result;
755 break;
756 case HW_NAT_RULE_SIZE:
757 HwNatSetRuleSize(&args4);
758 result = args4.result;
759 break;
760 case HW_NAT_KA_INTERVAL:
761 HwNatSetKaInterval(&args4);
762 result = args4.result;
763 break;
764 case HW_NAT_UB_LIFETIME:
765 HwNatSetUnbindLifeTime(&args4);
766 result = args4.result;
767 break;
768 case HW_NAT_BIND_LIFETIME:
769 result = HwNatSetBindLifeTime(&args4);
770 break;
771 case HW_NAT_VLAN_ID:
772 result = HwNatSetVID(&args4);
773 break;
774 case HW_NAT_BIND_DIRECTION:
775 result = HwNatSetBindDir(&args4);
776 break;
777#if defined (CONFIG_PPE_MCAST)
778 case HW_NAT_MCAST_INS:
779 result = HwNatMcastIns(&args5);
780 break;
781 case HW_NAT_MCAST_DEL:
782 result = HwNatMcastDel(&args5);
783 break;
784 case HW_NAT_MCAST_DUMP:
785 result = HwNatMcastDump();
786 break;
787#endif
788#if defined (CONFIG_PPE_MIB)
789 case HW_NAT_MIB_DUMP:
790 result = HwNatMibDumpEntry(entry_num);
791 break;
792 case HW_NAT_MIB_DRAM_DUMP:
793 result = HwNatMibDramDumpEntry(entry_num);
794 break;
795 case HW_NAT_MIB_GET:
796 result = HwNatMibGet(&args2);
797 break;
798#if defined CONFIG_COLGIN_SUPPORT
799 case HW_NAT_MIB_GET_ALL_IP:
800 args8=malloc(sizeof(struct hwnat_mib_all_ip_args));
801 if (NULL == args8)
802 {
803 printf(" Allocate memory for hwnat_mib_all_ip_args failed.\n");
804 close(fd);
805 return 0;
806 }
807 memset(args8, 0, sizeof(struct hwnat_mib_all_ip_args));
808 result = HwNatMibGetAllIP(args8);
809 dump_all_ip_cnt(args8);
810 free(args8);
811 break;
812#endif
813#endif
814 case HW_NAT_TBL_CLEAR:
815 result = HwNatTblClear();
816 break;
817#if defined (CONFIG_HW_NAT_IPI)
818 case HW_NAT_IPI_CTRL_FROM_EXTIF:
819 result = HwNatIPICtrlFromExtIf(&args6);
820 break;
821 case HW_NAT_IPI_CTRL_FROM_PPEHIT:
822 result = HwNatIPICtrlFromPPEHit(&args7);
823 break;
824#endif
825 case HW_NAT_DPORT:
826 result = HwNatDumpDport();
827 break;
828 case HW_NAT_INVALID_ENTRY:
xj112b9672022-01-25 16:13:48 +0800829 result = HwNatInvalEntry(entry_num, args2.set_idx);
xjb04a4022021-11-25 15:01:52 +0800830 break;
831 case HW_NAT_CLEAR_HOOK:
832 result = HwNatHookModify(&args2, 1);
833 break;
834 case HW_NAT_RESTORE_HOOK:
835 result = HwNatHookModify(&args2, 0);
836 break;
837 default:
838 result = HWNAT_FAIL;
839
840 }
841
842 if(result==HWNAT_SUCCESS){
843 printf("done\n");
844 }else if(result==HWNAT_ENTRY_NOT_FOUND) {
845 printf("entry not found\n");
846 }else {
847 printf("fail\n");
848 }
849
850 free(args);
851 close(fd);
852 return 0;
853}