-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathl2tp_config.c
6641 lines (6090 loc) · 233 KB
/
l2tp_config.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) 2004-2010 Katalix Systems Ltd
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*****************************************************************************/
/*
* Command Line Interface for OpenL2TP.
* This started out as a quick hack but just grew and grew. There's duplicate
* code and memory leaks all over the place.
* Command syntax is defined in a syntax table near the bottom of this file.
* The guts of the CLI is implemented in a library.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <rpc/rpc.h>
#include <signal.h>
#include "usl.h"
#include "cli_api.h"
#include "l2tp_private.h"
#include "l2tp_rpc.h"
static char *empty_string = "";
static char *opt_rpc_protocol = "udp";
static int opt_quiet;
static int interactive = 0;
static CLIENT *cl;
static char server[48];
static char *l2tp_histfile = NULL;
static int l2tp_histfile_maxsize = -1;
#define L2TP_ACT_DECLARATIONS(_max_args, _ids_type, _clnt_res_type) \
struct cli_node *args[_max_args]; \
char *arg_values[_max_args]; \
int num_args = _max_args; \
int arg; \
int result; \
_ids_type arg_id; \
_clnt_res_type clnt_res;
#define L2TP_ACT_BEGIN() \
result = cli_find_args(argc, argv, node, &args[0], &arg_values[0], &num_args); \
if (result == 0) { \
for (arg = 0; arg < num_args; arg++) { \
if (args[arg] && args[arg]->arg) { \
arg_id = args[arg]->arg->id;
#define L2TP_ACT_END() \
} \
} \
} else { \
/* tell caller which arg failed */ \
*arg_num = num_args; \
result = -EINVAL; \
goto out; \
}
#define L2TP_ACT_PARSE_ARG(_arg_node, _arg_value, _field, _flag_var, _flag) \
result = _arg_node->arg->parser(_arg_node, _arg_value, &_field); \
if (result < 0) { \
goto out; \
} \
_flag_var |= _flag;
/* Include code shared with openl2tpd */
#define L2TP_FEATURE_LOCAL_STAT_FILE
#include "l2tp_common.c"
/*****************************************************************************
* server ...
*****************************************************************************/
#define ARG(id, name, flag, type, doc) \
{ name, { L2TP_SERVER_ARGID_##id, flag, cli_arg_parse_##type, doc } }
#define FLG(id, name, doc) \
{ name, { L2TP_SERVER_ARGID_##id, CLI_ARG_FLAG_NO_VALUE, NULL, doc } }
typedef enum {
L2TP_SERVER_ARGID_NAME,
} l2tp_server_arg_ids_t;
static struct cli_arg_entry l2tp_args_server_modify[] = {
ARG(NAME, "name", 0, string, "IP address or hostname of L2TP daemon to attach to. Default=localhost."),
{ NULL, },
};
static void l2tp_set_prompt(char *server_name)
{
static char prompt[48];
snprintf(prompt, sizeof(prompt), "l2tp-%s", server_name);
cli_set_prompt(prompt);
}
static int l2tp_act_server_modify(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
char *server_name = NULL;
L2TP_ACT_DECLARATIONS(4, l2tp_server_arg_ids_t, int);
clnt_res = 0;
L2TP_ACT_BEGIN() {
switch (arg_id) {
case L2TP_SERVER_ARGID_NAME:
server_name = arg_values[arg];
break;
}
} L2TP_ACT_END();
if (server_name == NULL) {
fprintf(stderr, "Required name argument is missing.\n");
goto out;
}
if (strcmp(server_name, &server[0])) {
strncpy(&server[0], server_name, sizeof(server));
clnt_destroy(cl);
cl = clnt_create(server, L2TP_PROG, L2TP_VERSION, opt_rpc_protocol);
if (cl == NULL) {
clnt_pcreateerror(server);
exit(1);
}
l2tp_set_prompt(server_name);
}
out:
return 0;
}
static int l2tp_act_server_show(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
printf("Connected to server: %s\n", server);
return 0;
}
/*****************************************************************************
* system ...
*****************************************************************************/
#undef ARG
#define ARG(id, name, flag, type, doc) \
{ name, { L2TP_SYSTEM_ARGID_##id, flag, cli_arg_parse_##type, doc } }
#undef FLG
#define FLG(id, name, doc) \
{ name, { L2TP_SYSTEM_ARGID_##id, CLI_ARG_FLAG_NO_VALUE, NULL, doc } }
typedef enum {
L2TP_SYSTEM_ARGID_TRACE_FLAGS,
L2TP_SYSTEM_ARGID_MAX_TUNNELS,
L2TP_SYSTEM_ARGID_MAX_SESSIONS,
L2TP_SYSTEM_ARGID_DRAIN_TUNNELS,
L2TP_SYSTEM_ARGID_TUNNEL_ESTTO,
L2TP_SYSTEM_ARGID_TUNNEL_PERSIST_PENDTO,
L2TP_SYSTEM_ARGID_SESSION_PERSIST_PENDTO,
L2TP_SYSTEM_ARGID_SESSION_ESTTO,
L2TP_SYSTEM_ARGID_DENY_LOCAL_TUNNEL_CREATES,
L2TP_SYSTEM_ARGID_DENY_REMOTE_TUNNEL_CREATES,
L2TP_SYSTEM_ARGID_RESET_STATISTICS,
} l2tp_system_arg_ids_t;
static struct cli_arg_entry l2tp_args_system_modify[] = {
ARG(TRACE_FLAGS, "trace_flags", 0, string, "Default trace flags to use if not otherwise overridden."),
ARG(MAX_TUNNELS, "max_tunnels", 0, uint32, "Maximum number of tunnels permitted. Default=0 (no limit)."),
ARG(MAX_SESSIONS, "max_sessions", 0, uint32, "Maximum number of sessions permitted. Default=0 (no limit)."),
ARG(DRAIN_TUNNELS, "drain_tunnels", 0, bool, "Enable the draining of existing tunnels (prevent new tunnels "
"from being created."),
ARG(TUNNEL_ESTTO, "tunnel_establish_timeout", 0, uint32, "Timeout for tunnel establishment. Default=120 seconds.."),
ARG(SESSION_ESTTO, "session_establish_timeout", 0, uint32, "Timeout for session establishment. Default=120 seconds.."),
ARG(TUNNEL_PERSIST_PENDTO, "tunnel_persist_pend_timeout", 0, uint32, "Timeout to hold persistent tunnels before retrying. Default=300 seconds.."),
ARG(SESSION_PERSIST_PENDTO, "session_persist_pend_timeout", 0, uint32, "Timeout to hold persistent sessions before retrying. Default=60 seconds.."),
ARG(DENY_LOCAL_TUNNEL_CREATES, "deny_local_tunnel_creates", 0, bool, "Deny the creation of new tunnels by local request."),
ARG(DENY_REMOTE_TUNNEL_CREATES, "deny_remote_tunnel_creates", 0, bool, "Deny the creation of new tunnels by remote peers."),
FLG(RESET_STATISTICS, "reset_statistics", "Reset statistics."),
{ NULL, },
};
static int l2tp_act_exit(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
exit(0);
}
static int l2tp_act_help(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
printf("The help command is deprecated. Please see the l2tpconfig man page for help.\n");
return 0;
}
static int l2tp_act_system_modify(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
cli_bool_t bool_arg;
struct l2tp_api_system_msg_data msg = { { 0, } };
L2TP_ACT_DECLARATIONS(10, l2tp_system_arg_ids_t, int);
L2TP_ACT_BEGIN() {
switch (arg_id) {
case L2TP_SYSTEM_ARGID_TRACE_FLAGS:
result = l2tp_parse_debug_mask(&msg.config.trace_flags, arg_values[arg], 1);
if (result < 0) {
goto out;
}
msg.config.flags |= L2TP_API_CONFIG_FLAG_TRACE_FLAGS;
break;
case L2TP_SYSTEM_ARGID_DRAIN_TUNNELS:
L2TP_ACT_PARSE_ARG(args[arg], arg_values[arg], bool_arg, msg.config.flags, L2TP_API_CONFIG_FLAG_DRAIN_TUNNELS);
msg.config.drain_tunnels = bool_arg;
break;
case L2TP_SYSTEM_ARGID_MAX_TUNNELS:
L2TP_ACT_PARSE_ARG(args[arg], arg_values[arg], msg.config.max_tunnels, msg.config.flags, L2TP_API_CONFIG_FLAG_MAX_TUNNELS);
break;
case L2TP_SYSTEM_ARGID_MAX_SESSIONS:
L2TP_ACT_PARSE_ARG(args[arg], arg_values[arg], msg.config.max_sessions, msg.config.flags, L2TP_API_CONFIG_FLAG_MAX_SESSIONS);
break;
case L2TP_SYSTEM_ARGID_TUNNEL_ESTTO:
L2TP_ACT_PARSE_ARG(args[arg], arg_values[arg], msg.config.tunnel_establish_timeout, msg.config.flags,
L2TP_API_CONFIG_FLAG_TUNNEL_ESTABLISH_TIMEOUT);
break;
case L2TP_SYSTEM_ARGID_SESSION_ESTTO:
L2TP_ACT_PARSE_ARG(args[arg], arg_values[arg], msg.config.session_establish_timeout, msg.config.flags,
L2TP_API_CONFIG_FLAG_SESSION_ESTABLISH_TIMEOUT);
break;
case L2TP_SYSTEM_ARGID_TUNNEL_PERSIST_PENDTO:
L2TP_ACT_PARSE_ARG(args[arg], arg_values[arg], msg.config.tunnel_persist_pend_timeout, msg.config.flags,
L2TP_API_CONFIG_FLAG_TUNNEL_PERSIST_PEND_TIMEOUT);
break;
case L2TP_SYSTEM_ARGID_SESSION_PERSIST_PENDTO:
L2TP_ACT_PARSE_ARG(args[arg], arg_values[arg], msg.config.session_persist_pend_timeout, msg.config.flags,
L2TP_API_CONFIG_FLAG_SESSION_PERSIST_PEND_TIMEOUT);
break;
case L2TP_SYSTEM_ARGID_DENY_LOCAL_TUNNEL_CREATES:
L2TP_ACT_PARSE_ARG(args[arg], arg_values[arg], msg.config.deny_local_tunnel_creates, msg.config.flags,
L2TP_API_CONFIG_FLAG_DENY_LOCAL_TUNNEL_CREATES);
break;
case L2TP_SYSTEM_ARGID_DENY_REMOTE_TUNNEL_CREATES:
L2TP_ACT_PARSE_ARG(args[arg], arg_values[arg], msg.config.deny_remote_tunnel_creates, msg.config.flags,
L2TP_API_CONFIG_FLAG_DENY_REMOTE_TUNNEL_CREATES);
break;
case L2TP_SYSTEM_ARGID_RESET_STATISTICS:
msg.config.flags |= L2TP_API_CONFIG_FLAG_RESET_STATISTICS;
break;
}
} L2TP_ACT_END();
result = l2tp_system_modify_1(msg, &clnt_res, cl);
if (result != RPC_SUCCESS) {
clnt_perror(cl, server);
exit(1);
}
if (clnt_res < 0) {
fprintf(stderr, "Operation failed: %s\n", l2tp_strerror(-clnt_res));
return 0;
}
if (!opt_quiet) {
fprintf(stderr, "Modified system config\n");
}
out:
return result;
}
static int l2tp_act_system_show_version(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
struct l2tp_api_app_msg_data app;
int result;
memset(&app, 0, sizeof(app));
result = l2tp_app_info_get_1(&app, cl);
if (result != RPC_SUCCESS) {
clnt_perror(cl, server);
result = -EAGAIN;
goto out;
}
l2tp_show_app_version(stdout, &app);
out:
return result;
}
static int l2tp_act_system_show_config(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
struct l2tp_api_app_msg_data app;
struct l2tp_api_system_msg_data sys;
int result;
memset(&app, 0, sizeof(app));
result = l2tp_app_info_get_1(&app, cl);
if (result != RPC_SUCCESS) {
clnt_perror(cl, server);
result = -EAGAIN;
goto out;
}
memset(&sys, 0, sizeof(sys));
result = l2tp_system_get_1(&sys, cl);
if (result != RPC_SUCCESS) {
clnt_perror(cl, server);
result = -EAGAIN;
goto out;
}
if (app.cookie != L2TP_APP_COOKIE) {
printf("*** WARNING: CONTROL APPLICATION AND DAEMON ARE OUT OF SYNC. ***\n");
printf("*** UNDEFINED BAHAVIOR MAY RESULT. REINSTALL TO FIX. ***\n\n");
}
l2tp_show_system_config(stdout, &sys);
out:
return result;
}
static int l2tp_act_system_show_status(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
struct l2tp_api_system_msg_data sys;
int result;
memset(&sys, 0, sizeof(sys));
result = l2tp_system_get_1(&sys, cl);
if (result != RPC_SUCCESS) {
clnt_perror(cl, server);
result = -EAGAIN;
goto out;
}
l2tp_show_system_status(stdout, &sys);
out:
return result;
}
static int l2tp_act_system_show_stats(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
struct l2tp_api_system_msg_data sys;
int result;
memset(&sys, 0, sizeof(sys));
result = l2tp_system_get_1(&sys, cl);
if (result != RPC_SUCCESS) {
clnt_perror(cl, server);
result = -EAGAIN;
goto out;
}
l2tp_show_system_stats(stdout, &sys);
out:
return result;
}
/*****************************************************************************
* Tunnel...
*****************************************************************************/
typedef enum {
L2TP_TUNNEL_ARGID_TRACE_FLAGS,
L2TP_TUNNEL_ARGID_AUTH_MODE,
L2TP_TUNNEL_ARGID_HIDE_AVPS,
L2TP_TUNNEL_ARGID_UDP_CSUMS,
L2TP_TUNNEL_ARGID_DO_PMTU_DISCOVERY,
L2TP_TUNNEL_ARGID_PERSIST,
L2TP_TUNNEL_ARGID_MTU,
L2TP_TUNNEL_ARGID_HELLO_TIMEOUT,
L2TP_TUNNEL_ARGID_MAX_RETRIES,
L2TP_TUNNEL_ARGID_RX_WINDOW_SIZE,
L2TP_TUNNEL_ARGID_TX_WINDOW_SIZE,
L2TP_TUNNEL_ARGID_RETRY_TIMEOUT,
L2TP_TUNNEL_ARGID_IDLE_TIMEOUT,
L2TP_TUNNEL_ARGID_DEST_IPADDR,
L2TP_TUNNEL_ARGID_CONFIG_ID,
L2TP_TUNNEL_ARGID_SRC_IPADDR,
L2TP_TUNNEL_ARGID_OUR_UDP_PORT,
L2TP_TUNNEL_ARGID_PEER_UDP_PORT,
L2TP_TUNNEL_ARGID_PROFILE_NAME,
L2TP_TUNNEL_ARGID_USE_TIEBREAKER,
L2TP_TUNNEL_ARGID_ALLOW_PPP_PROXY,
L2TP_TUNNEL_ARGID_FRAMING_CAP,
L2TP_TUNNEL_ARGID_BEARER_CAP,
L2TP_TUNNEL_ARGID_HOST_NAME,
L2TP_TUNNEL_ARGID_SECRET,
L2TP_TUNNEL_ARGID_TUNNEL_ID,
L2TP_TUNNEL_ARGID_MAX_SESSIONS,
L2TP_TUNNEL_ARGID_TUNNEL_NAME,
L2TP_TUNNEL_ARGID_PEER_PROFILE_NAME,
L2TP_TUNNEL_ARGID_SESSION_PROFILE_NAME,
L2TP_TUNNEL_ARGID_PPP_PROFILE_NAME,
L2TP_TUNNEL_ARGID_INTERFACE_NAME,
L2TP_TUNNEL_ARGID_SHOW_CONFIG,
L2TP_TUNNEL_ARGID_SHOW_TRANSPORT,
L2TP_TUNNEL_ARGID_LIST_LOCAL_ONLY,
L2TP_TUNNEL_ARGID_LIST_REMOTE_ONLY,
L2TP_TUNNEL_ARGID_LIST_NAMES,
} l2tp_tunnel_arg_ids_t;
#undef ARG
#define ARG(id, name, flag, type, doc) \
{ name, { L2TP_TUNNEL_ARGID_##id, flag, cli_arg_parse_##type, doc } }
#undef FLG
#define FLG(id, name, doc) \
{ name, { L2TP_TUNNEL_ARGID_##id, CLI_ARG_FLAG_NO_VALUE, NULL, doc } }
/* Paremeters for Create and Modify operations */
#define L2TP_TUNNEL_MODIFY_ARGS \
ARG(TRACE_FLAGS, "trace_flags", 0, string, "Trace flags, for debugging network problems"), \
ARG(UDP_CSUMS, "use_udp_checksums", 0, bool, "Use UDP checksums in data frames. Default: ON"), \
ARG(PERSIST, "persist", 0, bool, "Persist (recreate automatically if tunnel fails). Default: OFF"), \
ARG(HELLO_TIMEOUT, "hello_timeout", 0, int32, ("Set timeout used for periodic L2TP Hello messages (in seconds). " \
"Default: 0 (no hello messages are generated.")), \
ARG(MAX_RETRIES, "max_retries", 0, int32, "Maximum transmit retries before assuming tunnel failure."), \
ARG(RETRY_TIMEOUT, "retry_timeout", 0, int32, "Retry timeout - initial delay between retries."), \
ARG(IDLE_TIMEOUT, "idle_timeout", 0, int32, "Idle timeout - automatically delete tunnel if no sessions."), \
ARG(MAX_SESSIONS, "max_sessions", 0, int32, "Maximum number of sessions allowed on tunnel. Default=0 (limited only " \
"by max_sessions limit in system parameters)."), \
ARG(MTU, "mtu", 0, int32, "MTU for all sessions in tunnel. Default: 1460."), \
ARG(PEER_PROFILE_NAME, "peer_profile_name", 0, string, ("Name of peer profile which will be used for default values of the " \
"tunnel's parameters.")), \
ARG(SESSION_PROFILE_NAME, "session_profile_name", 0, string, ("Name of session profile which will be used for default values of the " \
"tunnel's session parameters.")), \
ARG(PPP_PROFILE_NAME, "ppp_profile_name", 0, string, ("Name of ppp profile which will be used for default values of the " \
"tunnel's session PPP parameters.")), \
ARG(INTERFACE_NAME, "interface_name", 0, string, ("Name of system interface for the tunnel. Default: l2tpN where N is tunnel_id.")) \
/* Paremeters for Create operations */
#define L2TP_TUNNEL_CREATE_ARGS \
ARG(SRC_IPADDR, "src_ipaddr", 0, ipaddr, "Source IP address"), \
ARG(PEER_UDP_PORT, "peer_udp_port", 0, uint16, "UDP port number with which to contact peer L2TP server. Default: 1701"), \
ARG(OUR_UDP_PORT, "our_udp_port", 0, uint16, "Local UDP port number with which to contact peer L2TP server. " \
"Default: autogenerated"), \
ARG(USE_TIEBREAKER, "use_tiebreaker", 0, bool, "Enable use of a tiebreaker when setting up the tunnel. Default: ON"), \
ARG(ALLOW_PPP_PROXY, "allow_ppp_proxy", 0, bool, "Allow PPP proxy"), \
ARG(FRAMING_CAP, "framing_caps", 0, string, ("Framing capabilities:-\n" \
"none, sync, async, any")), \
ARG(BEARER_CAP, "bearer_caps", 0, string, ("Bearer capabilities:-\n" \
"none, digital, analog, any")), \
ARG(HOST_NAME, "host_name", 0, string, "Name to advertise to peer when setting up the tunnel."), \
ARG(SECRET, "secret", 0, string, ("Optional secret which is shared with tunnel peer. Must be specified when " \
"hide_avps is enabled.")), \
ARG(AUTH_MODE, "auth_mode", 0, string, ("Tunnel authentication mode:-\n" \
"none - no authentication, unless secret is given\n" \
"simple - check peer hostname\n" \
"challenge - require tunnel secret\n")), \
ARG(HIDE_AVPS, "hide_avps", 0, bool, "Hide AVPs. Default OFF"), \
ARG(RX_WINDOW_SIZE, "rx_window_size", 0, uint16, "Rx window size"), \
ARG(TX_WINDOW_SIZE, "tx_window_size", 0, uint16, "Tx window size"), \
ARG(DO_PMTU_DISCOVERY, "do_pmtu_discovery", 0, bool, "Do Path MTU Discovery. Default: OFF") \
#define L2TP_TUNNEL_ID_ARGS \
ARG(TUNNEL_ID, "tunnel_id", 0, uint16, "Tunnel ID of tunnel."), \
ARG(TUNNEL_NAME, "tunnel_name", 0, string, "Administrative name of tunnel.") \
static struct cli_arg_entry l2tp_args_tunnel_create[] = {
ARG(DEST_IPADDR, "dest_ipaddr", 0, ipaddr, "Destination IP address"),
ARG(CONFIG_ID, "config_id", 0, uint32, ("Optional configuration id, used to uniquify a tunnel when there is more "
"the one tunnel between the same two IP addresses")),
ARG(TUNNEL_NAME, "tunnel_name", 0, string, "Administrative name of tunnel."),
#ifdef L2TP_TEST
ARG(TUNNEL_ID, "tunnel_id", 0, uint16, "Optional tunnel id of new tunnel. Usually auto-generated. For testing only."),
#endif
ARG(PROFILE_NAME, "profile_name", 0, string, ("Name of tunnel profile which will be used for default values of this "
"tunnel's parameters.")),
L2TP_TUNNEL_CREATE_ARGS,
L2TP_TUNNEL_MODIFY_ARGS,
{ NULL, },
};
static struct cli_arg_entry l2tp_args_tunnel_delete[] = {
L2TP_TUNNEL_ID_ARGS,
{ NULL, },
};
static struct cli_arg_entry l2tp_args_tunnel_modify[] = {
L2TP_TUNNEL_ID_ARGS,
L2TP_TUNNEL_MODIFY_ARGS, \
{ NULL, },
};
static struct cli_arg_entry l2tp_args_tunnel_show[] = {
L2TP_TUNNEL_ID_ARGS,
FLG(SHOW_CONFIG, "config", "Display only tunnel configuration/status information."),
FLG(SHOW_TRANSPORT, "transport", "Display only tunnel transport information."),
{ NULL, },
};
static struct cli_arg_entry l2tp_args_tunnel_list[] = {
FLG(LIST_LOCAL_ONLY, "local_only", "List only locally created tunnels."),
FLG(LIST_REMOTE_ONLY, "remote_only", "List only remotely created tunnels."),
FLG(LIST_NAMES, "names", "List only named tunnels."),
{ NULL, },
};
static int l2tp_parse_tunnel_arg(l2tp_tunnel_arg_ids_t arg_id, struct cli_node *arg, char *arg_value, struct l2tp_api_tunnel_msg_data *msg)
{
int result = -EINVAL;
if (arg_value == NULL) {
arg_value = empty_string;
}
switch (arg_id) {
case L2TP_TUNNEL_ARGID_PROFILE_NAME:
OPTSTRING(msg->tunnel_profile_name) = strdup(arg_value);
if (OPTSTRING(msg->tunnel_profile_name) == NULL) {
result = -ENOMEM;
goto out;
}
msg->tunnel_profile_name.valid = 1;
msg->flags |= L2TP_API_TUNNEL_FLAG_PROFILE_NAME;
break;
case L2TP_TUNNEL_ARGID_TRACE_FLAGS:
result = l2tp_parse_debug_mask(&msg->trace_flags, arg_value, 1);
if (result < 0) {
goto out;
}
msg->flags |= L2TP_API_TUNNEL_FLAG_TRACE_FLAGS;
break;
case L2TP_TUNNEL_ARGID_AUTH_MODE:
if (strcasecmp(arg_value, "none") == 0) {
msg->auth_mode = L2TP_API_TUNNEL_AUTH_MODE_NONE;
} else if (strcasecmp(arg_value, "simple") == 0) {
msg->auth_mode = L2TP_API_TUNNEL_AUTH_MODE_SIMPLE;
} else if (strcasecmp(arg_value, "challenge") == 0) {
msg->auth_mode = L2TP_API_TUNNEL_AUTH_MODE_CHALLENGE;
} else {
fprintf(stderr, "Bad authmode %s: expecting none|simple|challenge\n", arg_value);
result = -EINVAL;
goto out;
}
msg->flags |= L2TP_API_TUNNEL_FLAG_AUTH_MODE;
break;
case L2TP_TUNNEL_ARGID_MAX_SESSIONS:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->max_sessions, msg->flags, L2TP_API_TUNNEL_FLAG_MAX_SESSIONS);
break;
case L2TP_TUNNEL_ARGID_HIDE_AVPS:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->hide_avps, msg->flags, L2TP_API_TUNNEL_FLAG_HIDE_AVPS);
break;
case L2TP_TUNNEL_ARGID_UDP_CSUMS:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->use_udp_checksums, msg->flags, L2TP_API_TUNNEL_FLAG_USE_UDP_CHECKSUMS);
break;
case L2TP_TUNNEL_ARGID_PERSIST:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->persist, msg->flags, L2TP_API_TUNNEL_FLAG_PERSIST);
break;
case L2TP_TUNNEL_ARGID_DO_PMTU_DISCOVERY:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->do_pmtu_discovery, msg->flags, L2TP_API_TUNNEL_FLAG_DO_PMTU_DISCOVERY);
break;
case L2TP_TUNNEL_ARGID_MTU:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->mtu, msg->flags, L2TP_API_TUNNEL_FLAG_MTU);
break;
case L2TP_TUNNEL_ARGID_HELLO_TIMEOUT:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->hello_timeout, msg->flags, L2TP_API_TUNNEL_FLAG_HELLO_TIMEOUT);
break;
case L2TP_TUNNEL_ARGID_MAX_RETRIES:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->max_retries, msg->flags, L2TP_API_TUNNEL_FLAG_MAX_RETRIES);
break;
case L2TP_TUNNEL_ARGID_RX_WINDOW_SIZE:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->rx_window_size, msg->flags, L2TP_API_TUNNEL_FLAG_RX_WINDOW_SIZE);
break;
case L2TP_TUNNEL_ARGID_TX_WINDOW_SIZE:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->tx_window_size, msg->flags, L2TP_API_TUNNEL_FLAG_TX_WINDOW_SIZE);
break;
case L2TP_TUNNEL_ARGID_RETRY_TIMEOUT:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->retry_timeout, msg->flags, L2TP_API_TUNNEL_FLAG_RETRY_TIMEOUT);
break;
case L2TP_TUNNEL_ARGID_IDLE_TIMEOUT:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->idle_timeout, msg->flags, L2TP_API_TUNNEL_FLAG_IDLE_TIMEOUT);
break;
case L2TP_TUNNEL_ARGID_DEST_IPADDR:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->peer_addr, msg->flags, L2TP_API_TUNNEL_FLAG_PEER_ADDR);
break;
case L2TP_TUNNEL_ARGID_CONFIG_ID:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->config_id, msg->flags, L2TP_API_TUNNEL_FLAG_CONFIG_ID);
break;
case L2TP_TUNNEL_ARGID_SRC_IPADDR:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->our_addr, msg->flags, L2TP_API_TUNNEL_FLAG_OUR_ADDR);
break;
case L2TP_TUNNEL_ARGID_OUR_UDP_PORT:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->our_udp_port, msg->flags, L2TP_API_TUNNEL_FLAG_OUR_UDP_PORT);
break;
case L2TP_TUNNEL_ARGID_PEER_UDP_PORT:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->peer_udp_port, msg->flags, L2TP_API_TUNNEL_FLAG_PEER_UDP_PORT);
break;
case L2TP_TUNNEL_ARGID_USE_TIEBREAKER:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->use_tiebreaker, msg->flags, L2TP_API_TUNNEL_FLAG_USE_TIEBREAKER);
break;
case L2TP_TUNNEL_ARGID_ALLOW_PPP_PROXY:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->allow_ppp_proxy, msg->flags, L2TP_API_TUNNEL_FLAG_ALLOW_PPP_PROXY);
break;
case L2TP_TUNNEL_ARGID_FRAMING_CAP:
if (strcasecmp(arg_value, "sync") == 0) {
msg->framing_cap_sync = TRUE;
msg->framing_cap_async = FALSE;
} else if (strcasecmp(arg_value, "async") == 0) {
msg->framing_cap_sync = FALSE;
msg->framing_cap_async = TRUE;
} else if (strcasecmp(arg_value, "any") == 0) {
msg->framing_cap_sync = TRUE;
msg->framing_cap_async = TRUE;
} else if (strcasecmp(arg_value, "none") == 0) {
msg->framing_cap_sync = FALSE;
msg->framing_cap_async = FALSE;
} else {
fprintf(stderr, "Bad framing capabilities %s: expecting none|sync|async|any\n", arg_value);
result = -EINVAL;
goto out;
}
msg->flags |= L2TP_API_TUNNEL_FLAG_FRAMING_CAP;
break;
case L2TP_TUNNEL_ARGID_BEARER_CAP:
if (strcasecmp(arg_value, "digital") == 0) {
msg->bearer_cap_digital = TRUE;
msg->bearer_cap_analog = FALSE;
} else if (strcasecmp(arg_value, "analog") == 0) {
msg->bearer_cap_digital = FALSE;
msg->bearer_cap_analog = TRUE;
} else if (strcasecmp(arg_value, "any") == 0) {
msg->bearer_cap_digital = TRUE;
msg->bearer_cap_analog = TRUE;
} else if (strcasecmp(arg_value, "none") == 0) {
msg->bearer_cap_digital = FALSE;
msg->bearer_cap_analog = FALSE;
} else {
fprintf(stderr, "Bad bearer capabilities %s: expecting none|digital|analog|any\n", arg_value);
result = -EINVAL;
goto out;
}
msg->flags |= L2TP_API_TUNNEL_FLAG_BEARER_CAP;
break;
case L2TP_TUNNEL_ARGID_HOST_NAME:
OPTSTRING(msg->host_name) = strdup(arg_value);
if (OPTSTRING(msg->host_name) == NULL) {
result = -ENOMEM;
goto out;
}
msg->host_name.valid = 1;
msg->flags |= L2TP_API_TUNNEL_FLAG_HOST_NAME;
break;
case L2TP_TUNNEL_ARGID_SECRET:
OPTSTRING(msg->secret) = strdup(arg_value);
if (OPTSTRING(msg->secret) == NULL) {
result = -ENOMEM;
goto out;
}
msg->secret.valid = 1;
msg->flags |= L2TP_API_TUNNEL_FLAG_SECRET;
break;
case L2TP_TUNNEL_ARGID_TUNNEL_ID:
L2TP_ACT_PARSE_ARG(arg, arg_value, msg->tunnel_id, msg->flags, L2TP_API_TUNNEL_FLAG_TUNNEL_ID);
break;
case L2TP_TUNNEL_ARGID_TUNNEL_NAME:
OPTSTRING(msg->tunnel_name) = strdup(arg_value);
if (OPTSTRING(msg->tunnel_name) == NULL) {
result = -ENOMEM;
goto out;
}
msg->tunnel_name.valid = 1;
msg->flags |= L2TP_API_TUNNEL_FLAG_TUNNEL_NAME;
break;
case L2TP_TUNNEL_ARGID_PEER_PROFILE_NAME:
OPTSTRING(msg->peer_profile_name) = strdup(arg_value);
if (OPTSTRING(msg->peer_profile_name) == NULL) {
result = -ENOMEM;
goto out;
}
msg->peer_profile_name.valid = 1;
msg->flags |= L2TP_API_TUNNEL_FLAG_PEER_PROFILE_NAME;
break;
case L2TP_TUNNEL_ARGID_SESSION_PROFILE_NAME:
OPTSTRING(msg->session_profile_name) = strdup(arg_value);
if (OPTSTRING(msg->session_profile_name) == NULL) {
result = -ENOMEM;
goto out;
}
msg->session_profile_name.valid = 1;
msg->flags |= L2TP_API_TUNNEL_FLAG_SESSION_PROFILE_NAME;
break;
case L2TP_TUNNEL_ARGID_PPP_PROFILE_NAME:
OPTSTRING(msg->ppp_profile_name) = strdup(arg_value);
if (OPTSTRING(msg->ppp_profile_name) == NULL) {
result = -ENOMEM;
goto out;
}
msg->ppp_profile_name.valid = 1;
msg->flags |= L2TP_API_TUNNEL_FLAG_PPP_PROFILE_NAME;
break;
case L2TP_TUNNEL_ARGID_INTERFACE_NAME:
OPTSTRING(msg->interface_name) = strdup(arg_value);
if (OPTSTRING(msg->interface_name) == NULL) {
result = -ENOMEM;
goto out;
}
msg->interface_name.valid = 1;
msg->flags2 |= L2TP_API_TUNNEL_FLAG_INTERFACE_NAME;
break;
case L2TP_TUNNEL_ARGID_SHOW_CONFIG:
case L2TP_TUNNEL_ARGID_SHOW_TRANSPORT:
case L2TP_TUNNEL_ARGID_LIST_LOCAL_ONLY:
case L2TP_TUNNEL_ARGID_LIST_REMOTE_ONLY:
case L2TP_TUNNEL_ARGID_LIST_NAMES:
break;
}
result = 0;
out:
return result;
}
static int l2tp_act_tunnel_create(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
struct l2tp_api_tunnel_msg_data msg = {0,0, };
L2TP_ACT_DECLARATIONS(60, l2tp_tunnel_arg_ids_t, int);
msg.our_udp_port = 1701;
msg.our_addr.s_addr = INADDR_ANY;
L2TP_ACT_BEGIN() {
result = l2tp_parse_tunnel_arg(arg_id, args[arg], arg_values[arg], &msg);
if (result < 0) {
goto out;
}
} L2TP_ACT_END();
result = l2tp_tunnel_create_1(msg, &clnt_res, cl);
if (result != RPC_SUCCESS) {
clnt_perror(cl, server);
result = -EAGAIN;
goto out;
}
if (clnt_res < 0) {
fprintf(stderr, "Operation failed: %s\n", l2tp_strerror(-clnt_res));
result = clnt_res;
goto out;
}
if (!opt_quiet) {
fprintf(stderr, "Created tunnel %hu\n", clnt_res & 0xffff);
}
out:
return result;
}
static int l2tp_act_tunnel_delete(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
uint16_t tunnel_id = 0;
optstring tunnel_name = { 0, };
optstring reason = { 0, };
int flags;
L2TP_ACT_DECLARATIONS(4, l2tp_tunnel_arg_ids_t, int);
L2TP_ACT_BEGIN() {
switch (arg_id) {
case L2TP_TUNNEL_ARGID_TUNNEL_ID:
L2TP_ACT_PARSE_ARG(args[arg], arg_values[arg], tunnel_id, flags, L2TP_API_TUNNEL_FLAG_TUNNEL_ID);
break;
case L2TP_TUNNEL_ARGID_TUNNEL_NAME:
OPTSTRING(tunnel_name) = strdup(arg_values[arg]);
if (OPTSTRING(tunnel_name) == NULL) {
result = -ENOMEM;
goto out;
}
tunnel_name.valid = 1;
break;
default:
result = -EINVAL;
goto out;
}
} L2TP_ACT_END();
if ((tunnel_id == 0) && (tunnel_name.valid == 0)) {
fprintf(stderr, "Required tunnel_id or tunnel_name argument is missing\n");
result = -EINVAL;
goto out;
}
result = l2tp_tunnel_delete_1(tunnel_id, tunnel_name, reason, &clnt_res, cl);
if (result != RPC_SUCCESS) {
clnt_perror(cl, server);
result = -EAGAIN;
goto out;
}
if (clnt_res < 0) {
fprintf(stderr, "Operation failed: %s\n", l2tp_strerror(-clnt_res));
result = clnt_res;
goto out;
}
if (!opt_quiet) {
if (tunnel_id != 0) {
fprintf(stderr, "Deleted tunnel %hu\n", tunnel_id);
} else {
fprintf(stderr, "Deleted tunnel %s\n", OPTSTRING_PTR(tunnel_name));
}
}
out:
return result;
}
static int l2tp_act_tunnel_modify(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
struct l2tp_api_tunnel_msg_data msg = { 0, };
L2TP_ACT_DECLARATIONS(40, l2tp_tunnel_arg_ids_t, int);
L2TP_ACT_BEGIN() {
result = l2tp_parse_tunnel_arg(arg_id, args[arg], arg_values[arg], &msg);
if (result < 0) {
goto out;
}
} L2TP_ACT_END();
if ((msg.tunnel_id == 0) && (msg.tunnel_name.valid == 0)) {
fprintf(stderr, "Required tunnel_id or tunnel_name argument is missing\n");
result = -EINVAL;
goto out;
}
result = l2tp_tunnel_modify_1(msg, &clnt_res, cl);
if (result != RPC_SUCCESS) {
clnt_perror(cl, server);
result = -EAGAIN;
goto out;
}
if (clnt_res < 0) {
fprintf(stderr, "Operation failed: %s\n", l2tp_strerror(-clnt_res));
result = clnt_res;
goto out;
}
if (!opt_quiet) {
if (msg.tunnel_id != 0) {
fprintf(stderr, "Modified tunnel %hu\n", msg.tunnel_id);
} else {
fprintf(stderr, "Modified tunnel %s\n", OPTSTRING_PTR(msg.tunnel_name));
}
}
out:
return result;
}
static void l2tp_act_tunnel_cleanup(struct l2tp_api_tunnel_msg_data *msg)
{
if (OPTSTRING(msg->state) != NULL) free(OPTSTRING(msg->state));
if (OPTSTRING(msg->host_name) != NULL) free(OPTSTRING(msg->host_name));
if (OPTSTRING(msg->secret) != NULL) free(OPTSTRING(msg->secret));
if (OPTSTRING(msg->tunnel_name) != NULL) free(OPTSTRING(msg->tunnel_name));
if (OPTSTRING(msg->tunnel_profile_name) != NULL) free(OPTSTRING(msg->tunnel_profile_name));
if (msg->tiebreaker.tiebreaker_val != NULL) free(msg->tiebreaker.tiebreaker_val);
if (OPTSTRING(msg->result_code_message) != NULL) free(OPTSTRING(msg->result_code_message));
if (OPTSTRING(msg->peer.host_name) != NULL) free(OPTSTRING(msg->peer.host_name));
if (OPTSTRING(msg->peer.vendor_name) != NULL) free(OPTSTRING(msg->peer.vendor_name));
if (OPTSTRING(msg->peer.result_code_message) != NULL) free(OPTSTRING(msg->peer.result_code_message));
if (msg->peer.tiebreaker.tiebreaker_val != NULL) free(msg->peer.tiebreaker.tiebreaker_val);
}
static int l2tp_act_tunnel_show(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
uint16_t tunnel_id = 0;
optstring tunnel_name = { 0, };
int flags;
L2TP_ACT_DECLARATIONS(8, l2tp_tunnel_arg_ids_t, struct l2tp_api_tunnel_msg_data);
int show_config_only = FALSE;
int show_transport_only = FALSE;
L2TP_ACT_BEGIN() {
switch (arg_id) {
case L2TP_TUNNEL_ARGID_TUNNEL_ID:
L2TP_ACT_PARSE_ARG(args[arg], arg_values[arg], tunnel_id, flags, L2TP_API_TUNNEL_FLAG_TUNNEL_ID);
break;
case L2TP_TUNNEL_ARGID_TUNNEL_NAME:
OPTSTRING(tunnel_name) = strdup(arg_values[arg]);
if (OPTSTRING(tunnel_name) == NULL) {
result = -ENOMEM;
goto out;
}
tunnel_name.valid = 1;
break;
case L2TP_TUNNEL_ARGID_SHOW_CONFIG:
show_config_only = TRUE;
break;
case L2TP_TUNNEL_ARGID_SHOW_TRANSPORT:
show_transport_only = TRUE;
break;
default:
result = -EINVAL;
goto out;
}
} L2TP_ACT_END();
if ((tunnel_id == 0) && (tunnel_name.valid == 0)) {
fprintf(stderr, "Required tunnel_id or tunnel_name argument is missing\n");
result = -EINVAL;
goto out;
}
memset(&clnt_res, 0, sizeof(clnt_res));
result = l2tp_tunnel_get_1(tunnel_id, tunnel_name, &clnt_res, cl);
if (result != RPC_SUCCESS) {
clnt_perror(cl, server);
result = -EAGAIN;
goto out;
}
result = 0;
if (clnt_res.result_code == 0) {
l2tp_show_tunnel(stdout, &clnt_res, show_config_only, show_transport_only);
} else {
fprintf(stderr, "get tunnel failed: %s\n", l2tp_strerror(-clnt_res.result_code));
}
out:
return result;
}
static int l2tp_id_compare(const void *id1, const void *id2)
{
uint16_t my_id1 = *(uint16_t *) id1;
uint16_t my_id2 = *(uint16_t *) id2;
return ((my_id1 > my_id2) ? 1 :
(my_id1 < my_id2) ? -1 : 0);
}
static int l2tp_name_compare(const void *name1, const void *name2)
{
char *my_name1 = *((char **) name1);
char *my_name2 = *((char **) name2);
return strcmp(my_name1, my_name2);
}
static int l2tp_act_tunnel_list(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
struct l2tp_api_tunnel_msg_data config;
int id;
int num_tunnels;
int local_only = 0;
int remote_only = 0;
int names = 0;
int brief;
L2TP_ACT_DECLARATIONS(8, l2tp_tunnel_arg_ids_t, struct l2tp_api_tunnel_list_msg_data);
L2TP_ACT_BEGIN() {
switch (arg_id) {
case L2TP_TUNNEL_ARGID_LIST_LOCAL_ONLY:
local_only = 1;
break;
case L2TP_TUNNEL_ARGID_LIST_REMOTE_ONLY:
remote_only = 1;
break;
case L2TP_TUNNEL_ARGID_LIST_NAMES:
names = 1;
break;
default:
result = -EINVAL;
goto out;
}
} L2TP_ACT_END();
if (local_only && remote_only) {
fprintf(stderr, "Cannot use local_only and remote_only together\n");
result = -EINVAL;
goto out;
}
brief = local_only || remote_only || names;
memset(&clnt_res, 0, sizeof(clnt_res));
result = l2tp_tunnel_list_1(&clnt_res, cl);
if (result != RPC_SUCCESS) {
clnt_perror(cl, server);
result = -EAGAIN;
goto out;
}
if (clnt_res.result != 0) {
fprintf(stderr, "Operation failed: %s\n", l2tp_strerror(-clnt_res.result));
result = clnt_res.result;
goto out;
}
num_tunnels = clnt_res.tunnel_ids.tunnel_ids_len;