1 /* iplink_ipvlan.c IPVLAN/IPVTAP device support
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version
6 * 2 of the License, or (at your option) any later version.
8 * Authors: Mahesh Bandewar <maheshb@google.com>
14 #include <sys/socket.h>
15 #include <linux/if_link.h>
19 #include "ip_common.h"
21 static void print_explain(struct link_util
*lu
, FILE *f
)
24 "Usage: ... %s [ mode MODE ] [ FLAGS ]\n"
26 "MODE: l3 | l3s | l2\n"
27 "FLAGS: bridge | private | vepa\n"
28 "(first values are the defaults if nothing is specified).\n",
32 static int ipvlan_parse_opt(struct link_util
*lu
, int argc
, char **argv
,
36 bool mflag_given
= false;
39 if (matches(*argv
, "mode") == 0) {
44 if (strcmp(*argv
, "l2") == 0)
45 mode
= IPVLAN_MODE_L2
;
46 else if (strcmp(*argv
, "l3") == 0)
47 mode
= IPVLAN_MODE_L3
;
48 else if (strcmp(*argv
, "l3s") == 0)
49 mode
= IPVLAN_MODE_L3S
;
51 fprintf(stderr
, "Error: argument of \"mode\" must be either \"l2\", \"l3\" or \"l3s\"\n");
54 addattr16(n
, 1024, IFLA_IPVLAN_MODE
, mode
);
55 } else if (matches(*argv
, "private") == 0 && !mflag_given
) {
56 flags
|= IPVLAN_F_PRIVATE
;
58 } else if (matches(*argv
, "vepa") == 0 && !mflag_given
) {
59 flags
|= IPVLAN_F_VEPA
;
61 } else if (matches(*argv
, "bridge") == 0 && !mflag_given
) {
63 } else if (matches(*argv
, "help") == 0) {
64 print_explain(lu
, stderr
);
67 fprintf(stderr
, "%s: unknown option \"%s\"?\n",
69 print_explain(lu
, stderr
);
75 addattr16(n
, 1024, IFLA_IPVLAN_FLAGS
, flags
);
80 static void ipvlan_print_opt(struct link_util
*lu
, FILE *f
, struct rtattr
*tb
[])
86 if (tb
[IFLA_IPVLAN_MODE
]) {
87 if (RTA_PAYLOAD(tb
[IFLA_IPVLAN_MODE
]) == sizeof(__u16
)) {
88 __u16 mode
= rta_getattr_u16(tb
[IFLA_IPVLAN_MODE
]);
89 const char *mode_str
= mode
== IPVLAN_MODE_L2
? "l2" :
90 mode
== IPVLAN_MODE_L3
? "l3" :
91 mode
== IPVLAN_MODE_L3S
? "l3s" : "unknown";
93 print_string(PRINT_ANY
, "mode", " mode %s ", mode_str
);
96 if (tb
[IFLA_IPVLAN_FLAGS
]) {
97 if (RTA_PAYLOAD(tb
[IFLA_IPVLAN_FLAGS
]) == sizeof(__u16
)) {
98 __u16 flags
= rta_getattr_u16(tb
[IFLA_IPVLAN_FLAGS
]);
100 if (flags
& IPVLAN_F_PRIVATE
)
101 print_bool(PRINT_ANY
, "private", "private ",
103 else if (flags
& IPVLAN_F_VEPA
)
104 print_bool(PRINT_ANY
, "vepa", "vepa ",
107 print_bool(PRINT_ANY
, "bridge", "bridge ",
113 static void ipvlan_print_help(struct link_util
*lu
, int argc
, char **argv
,
116 print_explain(lu
, f
);
119 struct link_util ipvlan_link_util
= {
121 .maxattr
= IFLA_IPVLAN_MAX
,
122 .parse_opt
= ipvlan_parse_opt
,
123 .print_opt
= ipvlan_print_opt
,
124 .print_help
= ipvlan_print_help
,
127 struct link_util ipvtap_link_util
= {
129 .maxattr
= IFLA_IPVLAN_MAX
,
130 .parse_opt
= ipvlan_parse_opt
,
131 .print_opt
= ipvlan_print_opt
,
132 .print_help
= ipvlan_print_help
,