1 /* iplink_ipvlan.c IPVLAN 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 ipvlan_explain(FILE *f
)
23 fprintf(f
, "Usage: ... ipvlan [ mode { l2 | l3 | l3s } ]\n");
26 static int ipvlan_parse_opt(struct link_util
*lu
, int argc
, char **argv
,
30 if (matches(*argv
, "mode") == 0) {
35 if (strcmp(*argv
, "l2") == 0)
36 mode
= IPVLAN_MODE_L2
;
37 else if (strcmp(*argv
, "l3") == 0)
38 mode
= IPVLAN_MODE_L3
;
39 else if (strcmp(*argv
, "l3s") == 0)
40 mode
= IPVLAN_MODE_L3S
;
42 fprintf(stderr
, "Error: argument of \"mode\" must be either \"l2\", \"l3\" or \"l3s\"\n");
45 addattr16(n
, 1024, IFLA_IPVLAN_MODE
, mode
);
46 } else if (matches(*argv
, "help") == 0) {
47 ipvlan_explain(stderr
);
50 fprintf(stderr
, "ipvlan: unknown option \"%s\"?\n",
52 ipvlan_explain(stderr
);
62 static void ipvlan_print_opt(struct link_util
*lu
, FILE *f
, struct rtattr
*tb
[])
68 if (tb
[IFLA_IPVLAN_MODE
]) {
69 if (RTA_PAYLOAD(tb
[IFLA_IPVLAN_MODE
]) == sizeof(__u16
)) {
70 __u16 mode
= rta_getattr_u16(tb
[IFLA_IPVLAN_MODE
]);
71 const char *mode_str
= mode
== IPVLAN_MODE_L2
? "l2" :
72 mode
== IPVLAN_MODE_L3
? "l3" :
73 mode
== IPVLAN_MODE_L3S
? "l3s" : "unknown";
75 print_string(PRINT_ANY
, "mode", " mode %s ", mode_str
);
80 static void ipvlan_print_help(struct link_util
*lu
, int argc
, char **argv
,
86 struct link_util ipvlan_link_util
= {
88 .maxattr
= IFLA_IPVLAN_MAX
,
89 .parse_opt
= ipvlan_parse_opt
,
90 .print_opt
= ipvlan_print_opt
,
91 .print_help
= ipvlan_print_help
,