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 } ]\n");
26 static void explain(void)
28 ipvlan_explain(stderr
);
31 static int mode_arg(void)
33 fprintf(stderr
, "Error: argument of \"mode\" must be either \"l2\", "
38 static int ipvlan_parse_opt(struct link_util
*lu
, int argc
, char **argv
,
42 if (matches(*argv
, "mode") == 0) {
46 if (strcmp(*argv
, "l2") == 0)
47 mode
= IPVLAN_MODE_L2
;
48 else if (strcmp(*argv
, "l3") == 0)
49 mode
= IPVLAN_MODE_L3
;
53 addattr16(n
, 1024, IFLA_IPVLAN_MODE
, mode
);
54 } else if (matches(*argv
, "help") == 0) {
58 fprintf(stderr
, "ipvlan: unknown option \"%s\"?\n",
69 static void ipvlan_print_opt(struct link_util
*lu
, FILE *f
, struct rtattr
*tb
[])
75 if (tb
[IFLA_IPVLAN_MODE
]) {
76 if (RTA_PAYLOAD(tb
[IFLA_IPVLAN_MODE
]) == sizeof(__u16
)) {
77 __u16 mode
= rta_getattr_u16(tb
[IFLA_IPVLAN_MODE
]);
79 fprintf(f
, " mode %s ",
80 mode
== IPVLAN_MODE_L2
? "l2" :
81 mode
== IPVLAN_MODE_L3
? "l3" : "unknown");
86 static void ipvlan_print_help(struct link_util
*lu
, int argc
, char **argv
,
92 struct link_util ipvlan_link_util
= {
94 .maxattr
= IFLA_IPVLAN_MAX
,
95 .parse_opt
= ipvlan_parse_opt
,
96 .print_opt
= ipvlan_print_opt
,
97 .print_help
= ipvlan_print_help
,