2 * iplink_macvtap.c macvtap device support
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.
13 #include <sys/socket.h>
14 #include <linux/if_link.h>
18 #include "ip_common.h"
20 static void print_explain(FILE *f
)
23 "Usage: ... macvtap mode { private | vepa | bridge | passthru }\n"
27 static void explain(void)
29 print_explain(stderr
);
32 static int mode_arg(const char *arg
)
34 fprintf(stderr
, "Error: argument of \"mode\" must be \"private\", "
35 "\"vepa\", \"bridge\" or \"passthru\", not \"%s\"\n", arg
);
39 static int macvtap_parse_opt(struct link_util
*lu
, int argc
, char **argv
,
43 if (matches(*argv
, "mode") == 0) {
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
;
53 else if (strcmp(*argv
, "passthru") == 0)
54 mode
= MACVLAN_MODE_PASSTHRU
;
56 return mode_arg(*argv
);
58 addattr32(n
, 1024, IFLA_MACVLAN_MODE
, mode
);
59 } else if (matches(*argv
, "help") == 0) {
63 fprintf(stderr
, "macvtap: unknown command \"%s\"?\n", *argv
);
73 static void macvtap_print_opt(struct link_util
*lu
, FILE *f
, struct rtattr
*tb
[])
80 if (!tb
[IFLA_MACVLAN_MODE
] ||
81 RTA_PAYLOAD(tb
[IFLA_MACVLAN_MODE
]) < sizeof(__u32
))
84 mode
= rta_getattr_u32(tb
[IFLA_VLAN_ID
]);
85 fprintf(f
, " mode %s ",
86 mode
== MACVLAN_MODE_PRIVATE
? "private"
87 : mode
== MACVLAN_MODE_VEPA
? "vepa"
88 : mode
== MACVLAN_MODE_BRIDGE
? "bridge"
89 : mode
== MACVLAN_MODE_PASSTHRU
? "passthru"
93 static void macvtap_print_help(struct link_util
*lu
, int argc
, char **argv
,
99 struct link_util macvtap_link_util
= {
101 .maxattr
= IFLA_MACVLAN_MAX
,
102 .parse_opt
= macvtap_parse_opt
,
103 .print_opt
= macvtap_print_opt
,
104 .print_help
= macvtap_print_help
,