]> git.proxmox.com Git - mirror_iproute2.git/blame - ip/iplink_macvtap.c
ip netns: Allow exec on each netns
[mirror_iproute2.git] / ip / iplink_macvtap.c
CommitLineData
3f0a7b4c
SS
1/*
2 * iplink_macvtap.c macvtap device support
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <sys/socket.h>
14#include <linux/if_link.h>
15
16#include "rt_names.h"
17#include "utils.h"
18#include "ip_common.h"
19
561e650e 20static void print_explain(FILE *f)
3f0a7b4c
SS
21{
22 fprintf(stderr,
f0612d56 23 "Usage: ... macvtap mode { private | vepa | bridge | passthru }\n"
3f0a7b4c
SS
24 );
25}
26
561e650e 27static void explain(void)
28{
29 print_explain(stderr);
30}
31
14645ec2 32static int mode_arg(const char *arg)
3f0a7b4c
SS
33{
34 fprintf(stderr, "Error: argument of \"mode\" must be \"private\", "
14645ec2 35 "\"vepa\", \"bridge\" or \"passthru\", not \"%s\"\n", arg);
3f0a7b4c
SS
36 return -1;
37}
38
39static int macvtap_parse_opt(struct link_util *lu, int argc, char **argv,
40 struct nlmsghdr *n)
41{
42 while (argc > 0) {
43 if (matches(*argv, "mode") == 0) {
44 __u32 mode = 0;
45 NEXT_ARG();
46
47 if (strcmp(*argv, "private") == 0)
48 mode = MACVLAN_MODE_PRIVATE;
49 else if (strcmp(*argv, "vepa") == 0)
50 mode = MACVLAN_MODE_VEPA;
51 else if (strcmp(*argv, "bridge") == 0)
52 mode = MACVLAN_MODE_BRIDGE;
f0612d56
SS
53 else if (strcmp(*argv, "passthru") == 0)
54 mode = MACVLAN_MODE_PASSTHRU;
3f0a7b4c 55 else
14645ec2 56 return mode_arg(*argv);
3f0a7b4c
SS
57
58 addattr32(n, 1024, IFLA_MACVLAN_MODE, mode);
59 } else if (matches(*argv, "help") == 0) {
60 explain();
61 return -1;
62 } else {
14645ec2 63 fprintf(stderr, "macvtap: unknown command \"%s\"?\n", *argv);
3f0a7b4c
SS
64 explain();
65 return -1;
66 }
67 argc--, argv++;
68 }
69
70 return 0;
71}
72
73static void macvtap_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
74{
75 __u32 mode;
76
77 if (!tb)
78 return;
79
80 if (!tb[IFLA_MACVLAN_MODE] ||
81 RTA_PAYLOAD(tb[IFLA_MACVLAN_MODE]) < sizeof(__u32))
82 return;
83
ff24746c 84 mode = rta_getattr_u32(tb[IFLA_VLAN_ID]);
3f0a7b4c
SS
85 fprintf(f, " mode %s ",
86 mode == MACVLAN_MODE_PRIVATE ? "private"
87 : mode == MACVLAN_MODE_VEPA ? "vepa"
88 : mode == MACVLAN_MODE_BRIDGE ? "bridge"
f0612d56 89 : mode == MACVLAN_MODE_PASSTHRU ? "passthru"
3f0a7b4c
SS
90 : "unknown");
91}
92
561e650e 93static void macvtap_print_help(struct link_util *lu, int argc, char **argv,
94 FILE *f)
95{
96 print_explain(f);
97}
98
3f0a7b4c
SS
99struct link_util macvtap_link_util = {
100 .id = "macvtap",
101 .maxattr = IFLA_MACVLAN_MAX,
102 .parse_opt = macvtap_parse_opt,
103 .print_opt = macvtap_print_opt,
561e650e 104 .print_help = macvtap_print_help,
3f0a7b4c 105};