diff options
Diffstat (limited to 'src/fnet/main.c')
-rw-r--r-- | src/fnet/main.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/fnet/main.c b/src/fnet/main.c new file mode 100644 index 000000000..f17287cb9 --- /dev/null +++ b/src/fnet/main.c | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014-2016 Firejail Authors | ||
3 | * | ||
4 | * This file is part of firejail project | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along | ||
17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | */ | ||
20 | #include "fnet.h" | ||
21 | |||
22 | static void usage(void) { | ||
23 | printf("Usage:\n"); | ||
24 | printf("\tfnet create veth dev1 dev2 bridge child\n"); | ||
25 | printf("\tfnet create macvlan dev parent child\n"); | ||
26 | printf("\tfnet moveif dev proc\n"); | ||
27 | } | ||
28 | |||
29 | int main(int argc, char **argv) { | ||
30 | #if 0 | ||
31 | { | ||
32 | system("cat /proc/self/status"); | ||
33 | int i; | ||
34 | for (i = 0; i < argc; i++) | ||
35 | printf("*%s* ", argv[i]); | ||
36 | printf("\n"); | ||
37 | } | ||
38 | #endif | ||
39 | if (argc < 2) | ||
40 | return 1; | ||
41 | |||
42 | |||
43 | |||
44 | if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") ==0) { | ||
45 | usage(); | ||
46 | return 0; | ||
47 | } | ||
48 | else if (argc == 7 && strcmp(argv[1], "create") == 0 && strcmp(argv[2], "veth") == 0) { | ||
49 | // create veth pair and move one end in the the namespace | ||
50 | net_create_veth(argv[3], argv[4], atoi(argv[6])); | ||
51 | |||
52 | // connect the ohter veth end to the bridge ... | ||
53 | net_bridge_add_interface(argv[5], argv[3]); | ||
54 | |||
55 | // ... and bring it up | ||
56 | net_if_up(argv[3]); | ||
57 | } | ||
58 | else if (argc == 6 && strcmp(argv[1], "create") == 0 && strcmp(argv[2], "macvlan") == 0) { | ||
59 | net_create_macvlan(argv[3], argv[4], atoi(argv[5])); | ||
60 | } | ||
61 | else if (argc == 4 && strcmp(argv[1], "moveif") == 0) { | ||
62 | net_move_interface(argv[2], atoi(argv[3])); | ||
63 | } | ||
64 | else { | ||
65 | fprintf(stderr, "Error fnet: invalid arguments\n"); | ||
66 | return 1; | ||
67 | } | ||
68 | |||
69 | return 0; | ||
70 | } | ||