aboutsummaryrefslogtreecommitdiffstats
path: root/src/fnet/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fnet/main.c')
-rw-r--r--src/fnet/main.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/fnet/main.c b/src/fnet/main.c
new file mode 100644
index 000000000..ae780c2ea
--- /dev/null
+++ b/src/fnet/main.c
@@ -0,0 +1,63 @@
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 <stdio.h>
21#include <stdlib.h>
22#include <errno.h>
23#include <sys/prctl.h>
24#include <linux/capability.h>
25
26static void usage(void) {
27 printf("Usage:\n");
28 printf("\tfnet create veth dev1 dev2 bridge child\n");
29 printf("\tfnet create macvlan dev parent child\n");
30 printf("\tfnet moveif dev proc\n");
31}
32
33int main(int argc, char **argv) {
34 if (argc < 2)
35 return 1;
36
37 if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") ==0) {
38 usage();
39 return 0;
40 }
41 else if (argc == 7 && strcmp(argv[1], "create") == 0 && strcmp(argv[2], "veth") == 0) {
42 // create veth pair and move one end in the the namespace
43 net_create_veth(argv[3], argv[4], atoi(argv[6]));
44
45 // connect the ohter veth end to the bridge ...
46 net_bridge_add_interface(argv[5], argv[3]);
47
48 // ... and bring it up
49 net_if_up(argv[3]);
50 }
51 else if (argc == 6 && strcmp(argv[1], "create") == 0 && strcmp(argv[2], "macvlan") == 0) {
52 net_create_macvlan(argv[3], argv[4], atoi(argv[5]));
53 }
54 else if (argc == 4 && strcmp(argv[1], "moveif") == 0) {
55 net_move_interface(argv[2], atoi(argv[3]));
56 }
57 else {
58 fprintf(stderr, "Error fnet: invalid arguments\n");
59 return 1;
60 }
61
62 return 0;
63}