blob: 15022aa9cced2cf0bd0cdf972b00c82a7752ad25 [file] [log] [blame]
Arnd Bergmannd63a9b22009-12-26 11:22:57 -08001/*
2 * iplink_vlan.c VLAN 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 * Authors: Patrick McHardy <kaber@trash.net>
10 * Arnd Bergmann <arnd@arndb.de>
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16#include <sys/socket.h>
17#include <linux/if_link.h>
18
19#include "rt_names.h"
20#include "utils.h"
21#include "ip_common.h"
22
23static void explain(void)
24{
25 fprintf(stderr,
Sridhar Samudralaf0612d52011-03-16 17:01:58 -070026 "Usage: ... macvlan mode { private | vepa | bridge | passthru }\n"
Arnd Bergmannd63a9b22009-12-26 11:22:57 -080027 );
28}
29
30static int mode_arg(void)
31{
32 fprintf(stderr, "Error: argument of \"mode\" must be \"private\", "
Sridhar Samudralaf0612d52011-03-16 17:01:58 -070033 "\"vepa\", \"bridge\" or \"passthru\" \n");
Arnd Bergmannd63a9b22009-12-26 11:22:57 -080034 return -1;
35}
36
37static int macvlan_parse_opt(struct link_util *lu, int argc, char **argv,
38 struct nlmsghdr *n)
39{
40 while (argc > 0) {
41 if (matches(*argv, "mode") == 0) {
42 __u32 mode = 0;
43 NEXT_ARG();
44
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;
Sridhar Samudralaf0612d52011-03-16 17:01:58 -070051 else if (strcmp(*argv, "passthru") == 0)
52 mode = MACVLAN_MODE_PASSTHRU;
Arnd Bergmannd63a9b22009-12-26 11:22:57 -080053 else
54 return mode_arg();
55
56 addattr32(n, 1024, IFLA_MACVLAN_MODE, mode);
57 } else if (matches(*argv, "help") == 0) {
58 explain();
59 return -1;
60 } else {
61 fprintf(stderr, "macvlan: what is \"%s\"?\n", *argv);
62 explain();
63 return -1;
64 }
65 argc--, argv++;
66 }
67
68 return 0;
69}
70
71static void macvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
72{
73 __u32 mode;
74
75 if (!tb)
76 return;
77
78 if (!tb[IFLA_MACVLAN_MODE] ||
79 RTA_PAYLOAD(tb[IFLA_MACVLAN_MODE]) < sizeof(__u32))
80 return;
81
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"
Sridhar Samudralaf0612d52011-03-16 17:01:58 -070087 : mode == MACVLAN_MODE_PASSTHRU ? "passthru"
Arnd Bergmannd63a9b22009-12-26 11:22:57 -080088 : "unknown");
89}
90
91struct link_util macvlan_link_util = {
92 .id = "macvlan",
93 .maxattr = IFLA_MACVLAN_MAX,
94 .parse_opt = macvlan_parse_opt,
95 .print_opt = macvlan_print_opt,
96};