2 * iplink_vlan.c VLAN 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.
9 * Authors: Patrick McHardy <kaber@trash.net>
10 * Arnd Bergmann <arnd@arndb.de>
16 #include <sys/socket.h>
17 #include <linux/if_link.h>
21 #include "ip_common.h"
23 static void explain(void)
26 "Usage: ... macvlan mode { private | vepa | bridge | passthru }\n"
30 static int mode_arg(void)
32 fprintf(stderr, "Error: argument of \"mode\" must be \"private\", "
33 "\"vepa\", \"bridge\" or \"passthru\" \n");
37 static int macvlan_parse_opt(struct link_util *lu, int argc, char **argv,
41 if (matches(*argv, "mode") == 0) {
45 if (strcmp(*argv, "private") == 0)
46 mode = MACVLAN_MODE_PRIVATE;
47 else if (strcmp(*argv, "vepa") == 0)
48 mode = MACVLAN_MODE_VEPA;
49 else if (strcmp(*argv, "bridge") == 0)
50 mode = MACVLAN_MODE_BRIDGE;
51 else if (strcmp(*argv, "passthru") == 0)
52 mode = MACVLAN_MODE_PASSTHRU;
56 addattr32(n, 1024, IFLA_MACVLAN_MODE, mode);
57 } else if (matches(*argv, "help") == 0) {
61 fprintf(stderr, "macvlan: what is \"%s\"?\n", *argv);
71 static void macvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
78 if (!tb[IFLA_MACVLAN_MODE] ||
79 RTA_PAYLOAD(tb[IFLA_MACVLAN_MODE]) < sizeof(__u32))
82 mode = *(__u32 *)RTA_DATA(tb[IFLA_VLAN_ID]);
83 fprintf(f, " mode %s ",
84 mode == MACVLAN_MODE_PRIVATE ? "private"
85 : mode == MACVLAN_MODE_VEPA ? "vepa"
86 : mode == MACVLAN_MODE_BRIDGE ? "bridge"
87 : mode == MACVLAN_MODE_PASSTHRU ? "passthru"
91 struct link_util macvlan_link_util = {
93 .maxattr = IFLA_MACVLAN_MAX,
94 .parse_opt = macvlan_parse_opt,
95 .print_opt = macvlan_print_opt,