forked from yellowman/nsh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.c
3669 lines (3245 loc) · 101 KB
/
commands.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2002-2008 Chris Cappuccio <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Copyright (c) 1988, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <sys/reboot.h>
#include <sys/sockio.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <net/route.h>
#include <limits.h>
#include <util.h>
#include <pwd.h>
#include "editing.h"
#include "stringlist.h"
#include "externs.h"
#include "sysctl.h"
#include "ctl.h"
char hname[HSIZE];
char hbuf[MAXHOSTNAMELEN]; /* host name */
char ifname[IFNAMSIZ]; /* interface name */
char next_ifname[IFNAMSIZ]; /* switch interfaces in interface context */
struct intlist *whichlist;
pid_t child;
extern volatile sig_atomic_t caught_sigwinch;
static int disable(void);
static int clear(void);
static int doverbose(int, char**);
static int doediting(int, char**);
static int doconfig(int, char**);
static int exitconfig(int, char**);
int rtable(int, char**);
int group(int, char**);
static int pr_crontab(int, char **, FILE *);
static int pr_routes(int, char **);
static int pr_routes6(int, char **);
static int pr_arp(int, char **);
static int pr_ndp(int, char **);
static int pr_sadb(int, char **);
static int pr_kernel(int, char **);
static int pr_dhcp(int, char **);
static int pr_conf(int, char **);
static int pr_s_conf(int, char **);
static int pr_a_conf(int, char **);
static int pr_conf_diff(int, char **);
static int pr_environment(int, char **);
static int show_hostname(int, char **);
static int wr_startup(void);
static int wr_conf(char *);
static int sysctlhelp(int, char **, char **, int);
static int flush_pf(char *);
static int flush_help(void);
static int flush_line(char *);
static int flush_ip_routes(void);
static int flush_arp_cache(void);
static int flush_ndp_cache(void);
static int flush_history(void);
static int is_bad_input(const char *, size_t);
static int read_command_line(EditLine *, History *);
static int int_logger(char *, int, int, char **);
static int int_ping(char *, int, int, char **);
static int int_ping6(char *, int, int, char **);
static int int_traceroute(char *, int, int, char **);
static int int_traceroute6(char *, int, int, char **);
static int int_ssh(char *, int, int, char **);
static int int_telnet(char *, int, int, char **);
static int int_do(char *, int, int, char **);
static int int_setenv(char *, int, int, char **);
static int int_unsetenv(char *, int, int, char **);
static int int_saveenv(char *, int, int, char **);
static int int_show(char *, int, int, char **);
static int int_who(char *, int, int, char **);
static int int_doverbose(char *, int, int, char **);
static int int_doediting(char *, int, int, char **);
static int int_manual(char *, int, int, char **);
static int int_shell(char *, int, int, char **);
static int int_clear(void);
static int int_help(void);
static int int_exit(void);
static int hostname(int, char **);
static int logger(int, char **);
static int manual(int, char**);
static int nocmd(int, char **);
static int docmd(int, char **);
static int setenvcmd(int, char **);
static int unsetenvcmd(int, char **);
static int saveenvcmd(int, char **);
static int shell(int, char*[]);
static int ping(int, char*[]);
static int ping6(int, char*[]);
static int traceroute(int, char*[]);
static int traceroute6(int, char*[]);
static int ssh(int, char*[]);
static int telnet(int, char*[]);
void p_argv(int, char **);
static int nreboot(void);
static int halt(void);
static int powerdown(void);
static void pf_stats(void);
static int int_interface(char *, int, int, char **);
#include "commands.h"
void sigalarm(int blahfart)
{
if (child != -1) {
kill(child, SIGKILL);
}
}
static struct fpf {
char *name;
char *help;
char *cmd;
char *arg;
} fpfs[] = {
{ "all", "all PF elements", PFCTL, "-Fall" },
{ "nat", "NAT rules", PFCTL, "-Fnat" },
{ "queue", "queue rules", PFCTL, "-Fqueue" },
{ "filter", "filter rules", PFCTL, "-Frules" },
{ "states", "NAT/filter states", PFCTL, "-Fstate" },
{ "stats", "PF statistics", PFCTL, "-Finfo" },
{ "tables", "PF address tables", PFCTL, "-FTables" },
{ 0, 0, 0, 0 }
};
static struct stt {
char *name;
char *help;
void (*handler) ();
} stts[] = {
{ "ip", "Internet Protocol", ip_stats },
{ "ah", "Authentication Header", ah_stats },
{ "esp", "Encapsulated Security Payload", esp_stats },
{ "tcp", "Transmission Control Protocol", tcp_stats },
{ "udp", "Unreliable Datagram Protocol", udp_stats },
{ "icmp", "Internet Control Message Protocol", icmp_stats },
{ "igmp", "Internet Group Management Protocol", igmp_stats },
{ "ipcomp", "IP Compression", ipcomp_stats },
{ "route", "Routing", rt_stats },
{ "carp", "Common Address Redundancy Protocol", carp_stats },
{ "mbuf", "Packet memory buffer", mbpr },
{ "pf", "Packet Filter", pf_stats },
{ 0, 0, 0 }
};
struct prot1 oscs[] = {
{ "fib", "Forward Information Base",
{ OSPFCTL, "show", "fib", OPT, OPT, NULL } },
{ "database", "Link State Database",
{ OSPFCTL, "show", "database", OPT, OPT, NULL } },
{ "interfaces", "Interface",
{ OSPFCTL, "show", "interfaces", OPT, NULL } },
{ "neighbor", "Neighbor",
{ OSPFCTL, "show", "neighbor", OPT, NULL } },
{ "rib", "Routing Information Base",
{ OSPFCTL, "show", "rib", OPT, NULL } },
{ "summary", "Summary",
{ OSPFCTL, "show", "summary", NULL } },
{ 0, 0, { 0 } }
};
struct prot1 os6cs[] = {
{ "fib", "Forward Information Base",
{ OSPF6CTL, "show", "fib", OPT, OPT, NULL } },
{ "database", "Link State Database",
{ OSPF6CTL, "show", "database", OPT, OPT, NULL } },
{ "interfaces", "Interface",
{ OSPF6CTL, "show", "interfaces", OPT, NULL } },
{ "neighbor", "Neighbor",
{ OSPF6CTL, "show", "neighbor", OPT, NULL } },
{ "rib", "Routing Information Base",
{ OSPF6CTL, "show", "rib", OPT, NULL } },
{ "summary", "Summary",
{ OSPF6CTL, "show", "summary", NULL } },
{ 0, 0, { 0 } }
};
struct prot1 pfcs[] = {
{ "all", "all pf info except fingerprints and interfaces",
{ PFCTL, "-sall", NULL, NULL, NULL, NULL } },
{ "anchors", "currently loaded anchors in main pf ruleset",
{ PFCTL, "-sAnchors", NULL, NULL, NULL } },
{ "info ", "pf filter statistics, counters and tracking",
{ PFCTL, "-sinfo", "-v", NULL, NULL, NULL } },
{ "labels", "per rule stats (bytes, packets and states)",
{ PFCTL, "-slabels", NULL, NULL, NULL, NULL } },
{ "memory", "current pf pool memory hard limit",
{ PFCTL, "-smemory", NULL, NULL, NULL, NULL } },
{ "queues", "currently loaded pf queue definition",
{ PFCTL, "-squeue", "-v", NULL, NULL, NULL } },
{ "rules", "active pf firewall rule",
{ PFCTL, "-srules", NULL, NULL, NULL, NULL } },
{ "sources", "contents of the pf source tracking table",
{ PFCTL, "-sSources", NULL, NULL, NULL, NULL } },
{ "states", "contents of the pf state table",
{ PFCTL, "-sstates", NULL, NULL, NULL, NULL } },
{ "tables", "pf table",
{ PFCTL, "-sTables", NULL, NULL, NULL, NULL } },
{ "timeouts", "current pf global timeout",
{ PFCTL, "-stimeouts", NULL, NULL, NULL, NULL } },
{ "osfingerprint", "pf Operating System fingerprint",
{ PFCTL, "-sosfp", NULL, NULL, NULL, NULL } },
{ "interfaces", "pf usable interfaces/ interface group",
{ PFCTL, "-sInterfaces", NULL, NULL, NULL, NULL } },
{ 0, 0, { 0 } }
};
struct prot1 eics[] = {
{ "interfaces", "Interface",
{ EIGRPCTL, "show", "interfaces", OPT, OPT, NULL } },
{ "neighbor", "Neighbor",
{ EIGRPCTL, "show", "neighbor", OPT, OPT, NULL } },
{ "topology", "Topology",
{ EIGRPCTL, "show", "topology", OPT, OPT, NULL } },
{ "traffic", "Traffic",
{ EIGRPCTL, "show", "traffic", OPT, OPT, NULL } },
{ 0, 0, { 0 } }
};
struct prot1 rics[] = {
{ "fib", "Forward Information Base",
{ RIPCTL, "show", "fib", OPT, NULL } },
{ "interfaces", "Interfaces",
{ RIPCTL, "show", "interfaces", NULL } },
{ "neighbor", "Neighbor",
{ RIPCTL, "show", "neighbor", NULL } },
{ "rib", "Routing Information Base",
{ RIPCTL, "show", "rib", NULL } },
{ 0, 0, { 0 } }
};
struct prot1 lics[] = {
{ "fib", "Forward Information Base",
{ LDPCTL, "show", "fib", OPT, NULL } },
{ "interfaces", "Interfaces",
{ LDPCTL, "show", "interfaces", NULL } },
{ "neighbor", "Neighbors",
{ LDPCTL, "show", "neighbor", NULL } },
{ "lib", "Label Information Base",
{ LDPCTL, "show", "lib", NULL } },
{ "discovery", "Adjacencies",
{ LDPCTL, "show", "discovery", NULL } },
{ "l2vpn", "Pseudowire",
{ LDPCTL, "show", "l2vpn", OPT, NULL } },
{ 0, 0, { 0 } }
};
struct prot1 iscs[] = {
{ "flows", "Display IPsec flows",
{ IPSECCTL, "-sf", NULL } },
{ "sadb", "Display SADB",
{ IPSECCTL, "-ss", NULL } },
{ 0, 0, { 0 } }
};
struct prot1 ikcs[] = {
{ "monitor", "Monitor internal iked messages",
{ IKECTL, "monitor", NULL } },
{ 0, 0, { 0 } }
};
struct prot1 dvcs[] = {
{ "igmp", "Internet Group Message Protocol",
{ DVMRPCTL, "show", "igmp", NULL } },
{ "interfaces", "Interfaces",
{ DVMRPCTL, "show", "interfaces", OPT, NULL } },
{ "mfc", "Multicast Forwarding Cache",
{ DVMRPCTL, "show", "mfc", OPT, NULL } },
{ "neighbor", "Neighbor",
{ DVMRPCTL, "show", "neighbor", OPT, NULL } },
{ "rib", "Routing Information Base",
{ DVMRPCTL, "show", "rib", OPT, NULL } },
{ "summary", "Summary",
{ DVMRPCTL, "show", "summary", NULL } },
{ 0, 0, { 0 } }
};
struct prot1 rlcs[] = {
{ "hosts", "hosts",
{ RELAYCTL, "show", "hosts", NULL } },
{ "redirects", "redirects",
{ RELAYCTL, "show", "redirects", NULL } },
{ "status", "status",
{ RELAYCTL, "show", "relays", NULL } },
{ "sessions", "sessions",
{ RELAYCTL, "show", "sessions", NULL } },
{ "summary", "summary",
{ RELAYCTL, "show", "summary", NULL } },
{ 0, 0, { 0 } }
};
struct prot1 smcs[] = {
{ "queue", "envelopes in queue",
{ SMTPCTL, "show", "queue", NULL } },
{ "runqueue", "envelopes scheduled for delivery",
{ SMTPCTL, "show", "runqueue", NULL } },
{ "stats", "runtime statistics",
{ SMTPCTL, "show", "stats", NULL } },
{ 0, 0, { 0 } }
};
struct prot1 dhcs[] = {
{ "leases", "leases", { 0 } },
{ 0, 0, { 0 } }
};
struct prot1 ldcs[] = {
{ "stats", "statistics counters",
{ LDAPCTL, "stats", NULL } },
{ 0, 0, { 0 } }
};
extern struct prot1 bgcs[];
/* show yyy zzz */
struct prot prots[] = {
{ "bgp", bgcs },
{ "ospf", oscs },
{ "ospf6", os6cs },
{ "pf", pfcs },
{ "eigrp", eics },
{ "rip", rics },
{ "ike", ikcs },
{ "ipsec", iscs },
{ "ldp", lics },
{ "dvmrp", dvcs },
{ "relay", rlcs },
{ "smtp", smcs },
{ "ldap", ldcs },
{ 0, 0 }
};
/*
* Quit command
*/
int
quit(void)
{
if (privexec) {
exit(NSH_REXEC_EXIT_CODE_QUIT);
} else {
if (interactive_mode)
printf("%% Session terminated.\n");
exit(0);
}
return 0;
}
struct ghs showroutetab[] = {
{ "<cr>", "Type Enter to run command", CMPL0 NULL, 0 },
{ "<address[/prefix-length]>", "IP address parameter" , CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs showarptab[] = {
{ "<cr>", "Type Enter to run command", CMPL0 NULL, 0 },
{ "<IPv4-address>", "IPv4 address parameter", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs showndptab[] = {
{ "<cr>", "Type Enter to run command", CMPL0 NULL, 0 },
{ "<IPv6-address>", "IPv6 address parameter", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs showvlantab[] = {
{ "<cr>", "Type Enter to run command", CMPL0 NULL, 0 },
{ "<VLAN Tag>", "VLAN tag parameter", CMPL0 NULL, 0 },
{ "<VLAN Start Tag> <VLAN End Tag>", "VLAN tag range parameters", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
/*
* Data structures and routines for the "show" command.
*/
Menu showlist[] = {
{ "hostname", "Router hostname", CMPL0 0, 0, 0, 0, show_hostname },
{ "interface", "Interface config", CMPL(i) 0, 0, 0, 2, show_int },
{ "autoconf", "IPv4/IPv6 autoconf state", CMPL(i) 0, 0, 0, 1, show_autoconf },
{ "ip", "IP address information", CMPL0 0, 0, 0, 0, show_ip },
{ "inet", "IPv4 address information", CMPL0 0, 0, 0, 0, show_ip },
{ "inet6", "IPv6 address information", CMPL0 0, 0, 0, 0, show_ip },
{ "route", "IPv4 route table or route lookup", CMPL(h) (char **)showroutetab, sizeof(struct ghs), 0, 1, pr_routes },
{ "route6", "IPv6 route table or route lookup", CMPL(h) (char **)showroutetab, sizeof(struct ghs), 0, 1, pr_routes6 },
{ "sadb", "Security Association Database", CMPL0 0, 0, 0, 0, pr_sadb },
{ "arp", "ARP table", CMPL(h) (char **)showarptab, sizeof(struct ghs), 0, 1, pr_arp },
{ "ndp", "NDP table", CMPL(h) (char **)showndptab, sizeof(struct ghs), 0, 1, pr_ndp },
{ "vlan", "802.1Q/802.1ad VLANs", CMPL(h) (char **)showvlantab, sizeof(struct ghs), 0, 2, show_vlans },
{ "bridge", "Ethernet bridges", CMPL(b) 0, 0, 0, 1, show_bridges },
{ "kernel", "Kernel statistics", CMPL(ta) (char **)stts, sizeof(struct stt), 0, 1, pr_kernel },
{ "bgp", "BGP information", CMPL(ta) (char **)bgcs, sizeof(struct prot1), 0, 4, pr_prot1 },
{ "ospf", "OSPF information", CMPL(ta) (char **)oscs, sizeof(struct prot1), 0, 3, pr_prot1 },
{ "ospf6", "OSPF6 information", CMPL(ta) (char **)os6cs, sizeof(struct prot1), 0, 3, pr_prot1 },
{ "pf", "Packet Filter firewall information", CMPL(ta) (char **)pfcs, sizeof(struct prot1), 0, 3, pr_prot1 },
{ "eigrp", "EIGRP information", CMPL(ta) (char **)eics, sizeof(struct prot1), 0, 3, pr_prot1 },
{ "rip", "RIP information", CMPL(ta) (char **)rics, sizeof(struct prot1), 0, 3, pr_prot1 },
{ "ldp", "LDP information", CMPL(ta) (char **)lics, sizeof(struct prot1), 0, 3, pr_prot1 },
{ "ike", "IKE information", CMPL(ta) (char **)ikcs, sizeof(struct prot1), 0, 3, pr_prot1 },
{ "ipsec", "IPsec information", CMPL(ta) (char **)iscs, sizeof(struct prot1), 0, 1, pr_prot1 },
{ "dvmrp", "DVMRP information", CMPL(ta) (char **)dvcs, sizeof(struct prot1), 0, 2, pr_prot1 },
{ "relay", "Relay server", CMPL(ta) (char **)rlcs, sizeof(struct prot1), 0, 1, pr_prot1 },
{ "dhcp", "DHCP server", CMPL(ta) (char **)dhcs, sizeof(struct prot1), 0, 1, pr_dhcp },
{ "smtp", "SMTP server", CMPL(ta) (char **)smcs, sizeof(struct prot1), 0, 1, pr_prot1 },
{ "ldap", "LDAP server", CMPL(ta) (char **)ldcs, sizeof(struct prot1), 0, 1, pr_prot1 },
{ "monitor", "Monitor routing/arp table changes", CMPL0 0, 0, 0, 0, monitor },
{ "version", "Software information", CMPL0 0, 0, 0, 0, version },
{ "users", "System users", CMPL0 0, 0, 0, 0, who },
{ "crontab", "Scheduled background jobs", CMPL0 0, 0, 0, 0, pr_crontab },
{ "scheduler", "Scheduled background jobs", CMPL0 0, 0, 0, 0, pr_crontab },
{ "running-config", "Operating configuration", CMPL0 0, 0, 0, 0, pr_conf },
{ "startup-config", "Startup configuration", CMPL0 0, 0, 0, 0, pr_s_conf },
{ "active-config", "Configuration of active context", CMPL0 0, 0, 0, 0, pr_a_conf },
{ "diff-config", "Show differences between startup and running config", CMPL0 0, 0, 0, 0, pr_conf_diff },
{ "environment", "Show environment variables", CMPL(e) 0, 0, 0, 1, pr_environment },
{ "?", "Options", CMPL0 0, 0, 0, 0, show_help },
{ "help", 0, CMPL0 0, 0, 0, 0, show_help },
{ 0, 0, 0, 0, 0 }
};
static int
showcmd(int argc, char **argv)
{
Menu *s; /* pointer to current command */
int error = 0, outfd = -1;
char outpath[PATH_MAX];
struct stat sb;
if (argc < 2) {
show_help(argc, argv);
return 0;
}
/*
* Validate show argument
*/
s = (Menu *) genget(argv[1], (char **) showlist, sizeof(Menu));
if (s == 0) {
printf("%% Invalid argument %s\n", argv[1]);
return 0;
} else if (Ambiguous(s)) {
printf("%% Ambiguous argument %s\n", argv[1]);
return 0;
}
if (((s->minarg + 2) > argc) || ((s->maxarg + 2) < argc)) {
printf("%% Wrong number of argument%s to 'show %s' command"
" (min %i, max %i)\n", argc <= 2 ? "" : "s", s->name,
s->minarg, s->maxarg);
return 0;
}
if (strlcpy(outpath, "/tmp/nsh.show.XXXXXXXX", sizeof(outpath)) >=
sizeof(outpath))
return 0;
outfd = mkstemp(outpath);
if (outfd == -1) {
printf("%% mkstemp %s: %s\n", outpath, strerror(errno));
return 0;
}
if (fstat(outfd, &sb) == -1) {
printf("%% fstat %s: %s\n", outpath, strerror(errno));
goto done;
}
if (s->handler) {
FILE *f;
int fd;
fd = dup(outfd);
if (fd == -1) {
printf("%% dup %s\n", strerror(errno));
goto done;
}
f = fdopen(fd, "w+");
if (f == NULL) {
printf("%% dup %s\n", strerror(errno));
close(fd);
goto done;
}
error = (*s->handler)(argc, argv, f);
if (fflush(f) == EOF)
printf("%% fflush %s: %s\n", outpath, strerror(errno));
fclose(f); /* fd is closed via f */
}
/*
* Until all show commands have been converted to write to the output
* file we need to check here whether the file has been modified before
* piping it to the pager.
*/
if (error == 0) {
struct stat sb2;
lseek(outfd, 0, SEEK_SET);
if (fstat(outfd, &sb2) == -1) {
printf("%% fstat %s: %s\n", outpath, strerror(errno));
goto done;
}
if (sb.st_size != sb2.st_size ||
sb.st_mtim.tv_sec != sb2.st_mtim.tv_sec ||
sb.st_mtim.tv_nsec != sb2.st_mtim.tv_nsec)
more(outpath);
}
done:
if (close(outfd) == EOF)
printf("%% close %s: %s\n", outpath, strerror(errno));
if (unlink(outpath) == -1)
printf("%% unlink %s: %s\n", outpath, strerror(errno));
return(error);
}
/*
* Data structures and routines for the "ip" command.
*/
struct ghs arptimeouttab[] = {
{ "<seconds>", "Seconds for ARP entries to remain in cache", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs arpdowntab[] = {
{ "<seconds>", "Seconds before resending unanswered ARP requests", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs carptab[] = {
{ "^no ip carp <cr>", "Disallow CARP", CMPL0 NULL, 0 },
{ "^ip carp <cr>", "Allow CARP", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs carploggingtab[] = {
{ "0", "CARP logging priority 0", CMPL0 NULL, 0 },
{ "1", "CARP logging priority 1", CMPL0 NULL, 0 },
{ "2", "CARP logging priority 2", CMPL0 NULL, 0 },
{ "3", "CARP logging priority 3", CMPL0 NULL, 0 },
{ "4", "CARP logging priority 4", CMPL0 NULL, 0 },
{ "5", "CARP logging priority 5", CMPL0 NULL, 0 },
{ "6", "CARP logging priority 6", CMPL0 NULL, 0 },
{ "7", "CARP logging priority 7", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs carppreempttab[] = {
{ "^no ip carp-preempt <cr>", "Disallow virtual CARP hosts to preempt each other", CMPL0 NULL, 0 },
{ "^ip carp-preempt <cr>", "Allow virtual CARP hosts to preempt each other", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs forwardingtab[] = {
{ "^no ip forwarding <cr>", "Disable IPv4 Forwarding", CMPL0 NULL, 0 },
{ "^ip forwarding <cr>", "Enable IPv4 Forwarding", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs mforwardingtab[] = {
{ "^no ip mforwarding <cr>", "Disable IPv4 Multicast Forwarding", CMPL0 NULL, 0 },
{ "^ip mforwarding <cr>", "Enable IPv4 Multicast Forwarding", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ipiptab[] = {
{ "^no ip ipip <cr>", "Disallow IP-in-IP Encapsulation", CMPL0 NULL, 0 },
{ "^ip ipip <cr>", "Allow IP-in-IP Encapsulation", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs gretab[] = {
{ "^no ip gre <cr>", "Disallow Generic Routing Encapsulation", CMPL0 NULL, 0 },
{ "^ip gre <cr>", "Allow Generic Routing Encapsulation", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs wccptab[] = {
{ "^no ip wccp <cr>", "Disallow Web Cache Control Protocol", CMPL0 NULL, 0 },
{ "^ip wccp <cr>", "Allow Web Cache Control Protocol", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs etheriptab[] = {
{ "^no ip etherip <cr>", "Disallow Ether-IP Encapsulation", CMPL0 NULL, 0 },
{ "^ip etherip <cr>", "Allow Ether-IP Encapsulation", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ipcomptab[] = {
{ "^no ip ipcomp <cr>", "Disallow IP Compression", CMPL0 NULL, 0 },
{ "^ip ipcomp <cr>", "Allow IP Compression", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs esptab[] = {
{ "^no ip esp <cr>", "Disallow Encapsulated Security Payload", CMPL0 NULL, 0 },
{ "^ip esp <cr>", "Allow Encapsulated Security Payload", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs espudpencaptab[] = {
{ "^no ip esp-udpencap <cr>", "Disallow ESP encapsulation within UDP", CMPL0 NULL, 0 },
{ "^ip esp-udpencap <cr>", "Allow ESP encapsulation within UDP", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs espudpencapporttab[] = {
{ "<number>", "UDP port number for encapsulation", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ahtab[] = {
{ "^no ip ah <cr>", "Disallow Authentication Header", CMPL0 NULL, 0 },
{ "^ip ah <cr>", "Allow Authentication Header", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs sourceroutetab[] = {
{ "^no ip sourceroute <cr>", "Disallow Forwarding of Source-Routed Packets", CMPL0 NULL, 0 },
{ "^ip sourceroute <cr>", "Allow Forwarding of Source-Routed Packets", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs encdebugtab[] = {
{ "^no ip encdebug <cr>", "Disable enc(4) interface debugging", CMPL0 NULL, 0 },
{ "^ip encdebug <cr>", "Enable enc(4) interface debugging", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs sendredirectstab[] = {
{ "^no ip send-redirects <cr>", "Do not send ICMP redirects", CMPL0 NULL, 0 },
{ "^ip send-redirects <cr>", "Send ICMP redirects", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs directedbroadcaststab[] = {
{ "^no ip directed-broadcast <cr>", "Disallow directed broadcasts", CMPL0 NULL, 0 },
{ "^ip directed-broadcast <cr>", "Allow directed broadcasts", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs multipathtab[] = {
{ "^no ip multipath <cr>", "Disable Multipath Routing", CMPL0 NULL, 0 },
{ "^ip multipath <cr>", "Enable Multipath Routing", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs maxqueuetab[] = {
{ "<number>", "Maximum unassembled IP fragments in the fragment queue", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs mtudisctab[] = {
{ "^no ip mtudisc <cr>", "Disable Path MTU Discovery", CMPL0 NULL, 0 },
{ "^ip mtudisc <cr>", "Enable Path MTU Discovery", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs mtudisctimeouttab[] = {
{ "<seconds>", "Timeout in seconds for routes added by Path MTU discovery engine", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ipsectimeouttab[] = {
{ "<seconds>", "Seconds after a SA is established before it will expire", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ipsecsofttimeouttab[] = {
{ "<seconds>", "Seconds after a SA is established before being renegotiated", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ipsecallocstab[] = {
{ "<number>", "Maximum IPSEC flows that can use a SA before it expires", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ipsecsoftallocstab[] = {
{ "<number>", "Maximum IPSEC flows that can use a SA before being renegotiated", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ipsecbytestab[] = {
{ "<number>", "Maximum bytes processed by a security association before it expires", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ipsecsoftbytestab[] = {
{ "<number>", "Maximum bytes processed by a security association before being renegotiated", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ipsecexpireacquiretab[] = {
{ "<seconds>", "Seconds the kernel allows to dynamically acquire SAs before a request", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ipsecfirstusetab[] = {
{ "<seconds>", "Seconds after security association is first used before it expires", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ipsecsoftfirstusetab[] = {
{ "<seconds>", "Seconds after a SA is first used before it is sent for renegotiation", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ipsecinvalidlifetab[] = {
{ "<seconds>", "Lifetime of Embryonic SAs in seconds", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs ipsecpfstab[] = {
{ "^no ip ipsec-pfs <cr>", "Disable Perfect Forward Secrecy", CMPL0 NULL, 0 },
{ "^ip ipsec-pfs <cr>", "Enable Perfect Forward Secrecy", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs portfirsttab[] = {
{ "<number>", "Minimum registered port number for TCP/UDP port allocation", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs porthifirsttab[] = {
{ "<number>", "Minimum dynamic/private port number for TCP/UDP port allocation", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs porthilasttab[] = {
{ "<number>", "Maximum dynamic/private port number for TCP/UDP port allocation", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
struct ghs portlasttab[] = {
{ "<number>", "Maximum registered port number for TCP/UDP port allocation", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
#ifdef notyet
struct ghs defaultmtutab[] = {
{ "<number>", "Default interface MTU", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
#endif
struct ghs defaultttltab[] = {
{ "<number>", "Default IP packet TTL", CMPL0 NULL, 0 },
{ NULL, NULL, NULL, NULL, 0 }
};
Menu iptab[] = {
{ "arptimeout", "Seconds for ARP entries to remain in cache", CMPL(h) (char **)arptimeouttab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "arpdown", "Seconds before resending unanswered ARP requests", CMPL(h) (char **)arpdowntab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "carp", "Allow CARP", CMPL(h) (char **)carptab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "carp-log", "CARP Logging Priority", CMPL(h) (char **)carploggingtab, sizeof(struct ghs), 0, 1, ipsysctl },
{ "carp-preempt", "CARP Virtual Host Preemption", CMPL(h) (char **)carppreempttab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "forwarding", "Enable IPv4 Forwarding", CMPL(h) (char **)forwardingtab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "mforwarding", "Enable IPv4 Multicast Forwarding", CMPL(h) (char **)mforwardingtab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "ipip", "Allow IP-in-IP Encapsulation", CMPL(h) (char **)ipiptab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "gre", "Allow Generic Route Encapsulation", CMPL(h) (char **)gretab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "wccp", "Allow Web Cache Control Protocol", CMPL(h) (char **)wccptab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "etherip", "Allow Ether-IP Encapsulation", CMPL(h) (char **)etheriptab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "ipcomp", "Allow IP Compression", CMPL(h) (char **)ipcomptab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "esp", "Allow Encapsulated Security Payload", CMPL(h) (char **)esptab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "esp-udpencap","Allow ESP encapsulation within UDP", CMPL(h) (char **)espudpencaptab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "esp-udpencap-port","UDP port number for encapsulation", CMPL(h) (char **)espudpencapporttab, sizeof(struct ghs), 0, 1, ipsysctl },
{ "ah", "Allow Authentication Header", CMPL(h) (char**)ahtab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "sourceroute", "Process Loose/Strict Source Route Options", CMPL(h) (char**)sourceroutetab, sizeof(struct ghs), 0, 1, ipsysctl },
{ "encdebug", "Enable if_enc debugging", CMPL(h) (char **)encdebugtab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "send-redirects", "Send ICMP redirects", CMPL(h) (char **)sendredirectstab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "directed-broadcast", "Allow directed broadcasts", CMPL(h) (char **)directedbroadcaststab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "multipath", "Multipath routing", CMPL(h) (char **)multipathtab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "maxqueue", "Maximum unassembled IP fragments in the fragment queue", CMPL(h) (char **)maxqueuetab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "mtudisc", "Enable Path MTU Discovery", CMPL(h) (char **)mtudisctab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "mtudisctimeout", "Timeout in seconds for routes added by Path MTU discovery engine", CMPL(h) (char **)mtudisctimeouttab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "ipsec-timeout", "Seconds after a SA is established before it will expire", CMPL(h) (char **)ipsectimeouttab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "ipsec-soft-timeout", "Seconds after a SA is established before being renegotiated", CMPL(h) (char **)ipsecsofttimeouttab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "ipsec-allocs", "Maximum IPSEC flows that can use a SA before it expires", CMPL(h) (char **)ipsecallocstab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "ipsec-soft-allocs", "Maximum IPSEC flows a SA uses before renegotiation", CMPL(h) (char **)ipsecsoftallocstab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "ipsec-bytes", "Maximum bytes processed by a security association before it expires", CMPL(h) (char **)ipsecbytestab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "ipsec-soft-bytes", "Maximum bytes a SA processes before renegotiation", CMPL(h) (char **)ipsecsoftbytestab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "ipsec-expire-acquire", "Seconds the kernel allows to dynamically acquire SAs before a request", CMPL(h) (char **)ipsecexpireacquiretab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "ipsec-firstuse", "Seconds after security association is first used before it expires", CMPL(h) (char **)ipsecfirstusetab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "ipsec-soft-firstuse", "Seconds after a SA is first used before it is sent for renegotiation", CMPL(h) (char **)ipsecsoftfirstusetab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "ipsec-invalid-life", "Lifetime of Embryonic SAs in seconds", CMPL(h) (char **)ipsecinvalidlifetab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "ipsec-pfs", "Enables Perfect Forward Secrecy when establishing SAs", CMPL(h) (char **)ipsecpfstab, sizeof(struct ghs), 0, 0, ipsysctl },
{ "portfirst", "Minimum registered port number for TCP/UDP port allocation", CMPL(h) (char **)portfirsttab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "porthifirst", "Minimum dynamic/private port number for TCP/UDP port allocation", CMPL(h) (char **)porthifirsttab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "porthilast", "Maximum dynamic/private port number for TCP/UDP port allocation", CMPL(h) (char **)porthilasttab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "portlast", "Maximum registered port number for TCP/UDP port allocation", CMPL(h) (char **)portlasttab, sizeof(struct ghs), 1, 1, ipsysctl },
#ifdef notyet
{ "default-mtu", "Default interface MTU", CMPL(h) (char **)defaultmtutab, sizeof(struct ghs), 1, 1, ipsysctl },
#endif
{ "default-ttl", "Default IP packet TTL", CMPL(h) (char **)defaultttltab, sizeof(struct ghs), 1, 1, ipsysctl },
{ "?", "Options", CMPL0 0, 0, 0, 0, sysctlhelp },
{ 0, 0, 0, 0, 0, 0, 0, 0 }
};
Menu ip6tab[] = {
{ "auto_flowlabel", "Fill the IPv6 flowlabel field to help intermediate routers identify packet flows", CMPL0 0, 0, 0, 0, ipsysctl },
{ "dad_count", "Configures the number of IPv6 D.A.D. probe packets", CMPL0 0, 0, 0, 0, ipsysctl },
{ "dad_pending", "Displays number of pending IPv6 D.A.D. before completion", CMPL0 0, 0, 0, 0, ipsysctl },
{ "defmcasthlim", "The default hop limit value for an IPv6 multicast packet sourced by the system", CMPL0 0, 0, 1, 1, ipsysctl },
{ "forwarding", "Enable IPv6 Forwarding", CMPL0 0, 0, 0, 0, ipsysctl },
{ "hdrnestlimit", "The number of IPv6 extension headers permitted on incoming IPv6 packets", CMPL0 0, 0, 1, 1, ipsysctl },
{ "hoplimit", "The default hop limit for IPv6 unicast packet sourced by the system", CMPL0 0, 0, 1, 1, ipsysctl },
{ "log_interval", "Configures the amount of logs generated by the IPv6 packet forwarding engine", CMPL0 0, 0, 1, 1, ipsysctl },
{ "maxdynroutes", "Max IPv6 Dyn Routes", CMPL0 0, 0, 0, 0, ipsysctl },
{ "maxfragpackets", "The maximum number of fragmented packets the system will accept", CMPL0 0, 0, 1, 1, ipsysctl },
{ "maxfrags", "The maximum number of fragments the node will accept", CMPL0 0, 0, 1, 1, ipsysctl },
{ "maxifdefrouters", "Max if IPv6 Def Routers", CMPL0 0, 0, 0, 0, ipsysctl },
{ "maxifprefixes", "Max if IPv6 Prefixes", CMPL0 0, 0, 0, 0, ipsysctl },
{ "mforwarding", "Enable IPv6 Multicast Forwarding", CMPL0 0, 0, 0, 0, ipsysctl },
{ "mtudisctimeout", "Seconds after which a route added by the Path MTU Discovery engine will time out", CMPL0 0, 0, 1, 1, ipsysctl },
{ "multicast_mtudisc", "Enables ICMPv6 too big messages when machine is an IPv6 multicast router", CMPL0 0, 0, 0, 0, ipsysctl },
{ "multipath", "Multipath routing", CMPL0 0, 0, 0, 0, ipsysctl },
{ "neighborgcthresh", "Maximum number of entries in neighbor cache", CMPL0 0, 0, 0, 0, ipsysctl },
{ "send-redirect", "Enables sending ICMPv6 redirects by the system", CMPL0 0, 0, 0, 0, ipsysctl },
{ "?", "Help", CMPL0 0, 0, 0, 0, sysctlhelp },
{ 0, 0, 0, 0, 0, 0, 0, 0 }
};
Menu mplstab[] = {
{ "ttl", "MPLS ttl", CMPL0 0, 0, 0, 1, ipsysctl },
{ "mapttl-ip", "MPLS mapttl IPv4", CMPL0 0, 0, 0, 1, ipsysctl },
{ "mapttl-ip6", "MPLS mapttl IPv6", CMPL0 0, 0, 0, 1, ipsysctl },
{ "?", "Help", CMPL0 0, 0, 0, 0, sysctlhelp },
{ 0, 0, 0, 0, 0, 0, 0, 0 }
};
Menu ddbtab[] = {
{ "panic", "DDB panic", CMPL0 0, 0, 0, 0, ipsysctl },
{ "console", "DDB console", CMPL0 0, 0, 0, 0, ipsysctl },
{ "log", "DDB log", CMPL0 0, 0, 0, 0, ipsysctl },
{ "?", "Help", CMPL0 0, 0, 0, 0, sysctlhelp },
{ 0, 0, 0, 0, 0, 0, 0, 0 }
};
Menu pipextab[] = {
{ "enable", "PIPEX enable", CMPL0 0, 0, 0, 0, ipsysctl },
{ "?", "Help", CMPL0 0, 0, 0, 0, sysctlhelp },
{ 0, 0, 0, 0, 0, 0, 0, 0 }
};
static int
ipcmd(int argc, char **argv)
{
Menu *i; /* pointer to current command */
struct sysctltab *stab;
int set, success = 0;
if (NO_ARG(argv[0])) {
argv++;
argc--;
set = 0;
} else
set = 1;
/*
* Find ourself in the great divide
*/
stab = (struct sysctltab *)genget(argv[0], (char **)sysctls,
sizeof(struct sysctltab));
if (stab == 0) {
printf("%% Invalid argument %s\n", argv[0]);
return 0;
} else if (Ambiguous(stab)) {
printf("%% Ambiguous argument %s\n", argv[0]);
return 0;
}
if (argc < 2) {
sysctlhelp(0, NULL, NULL, stab->pf);
return 0;
}
/*
* Validate ip argument
*/
i = (Menu *)genget(argv[1], (char **)stab->table, sizeof(Menu));
if (i == 0) {
printf("%% Invalid argument %s\n", argv[1]);
return 0;
} else if (Ambiguous(i)) {
printf("%% Ambiguous argument %s\n", argv[1]);
return 0;
}
if (((i->minarg + 2) > argc) || ((i->maxarg + 2) < argc)) {
printf("%% Wrong argument%s to '%s %s' command.\n",
argc <= 2 ? "" : "s", argv[0], i->name);
return 0;
}
if (i->handler)
success = (*i->handler)(set, argv[1],
(i->maxarg > 0) ? argv[2] : 0, stab->pf);
return(success);
}
static int
sysctlhelp(int unused1, char **unused2, char **unused3, int type)
{
Menu *i = NULL, *j = NULL; /* pointer to current command */
char *prefix = NULL;
u_int z = 0;
struct sysctltab *stab;
for (stab = sysctls; stab->name != NULL; stab++)
if (stab->pf == type) {
prefix = stab->name;
i = j = stab->table;
break;
}
if (stab->pf != type) {
printf("%% table lookup failed (%d)\n", type);
return 0;
}
printf("%% Commands may be abbreviated.\n");
printf("%% '%s' commands are:\n\n", prefix);
for (; i && i->name; i++) {
if (strlen(i->name) > z)
z = strlen(i->name);
}
for (; j && j->name; j++) {
if (j->help)
printf(" %-*s %s\n", z, j->name, j->help);
}
return 0;
}
/*
* Data structures and routines for the "flush" command.
*/
Menu flushlist[] = {
{ "routes", "IP routes", CMPL0 0, 0, 0, 0, flush_ip_routes },
{ "arp", "ARP cache", CMPL0 0, 0, 0, 0, flush_arp_cache },