]> git.proxmox.com Git - mirror_iproute2.git/blob - ip/iplink_ipvlan.c
Use one func to print timestamp from nlmsg
[mirror_iproute2.git] / ip / iplink_ipvlan.c
1 /* iplink_ipvlan.c IPVLAN device support
2 *
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.
7 *
8 * Authors: Mahesh Bandewar <maheshb@google.com>
9 */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <sys/socket.h>
15 #include <linux/if_link.h>
16
17 #include "rt_names.h"
18 #include "utils.h"
19 #include "ip_common.h"
20
21 static void ipvlan_explain(FILE *f)
22 {
23 fprintf(f, "Usage: ... ipvlan [ mode { l2 | l3 } ]\n");
24 }
25
26 static void explain(void)
27 {
28 ipvlan_explain(stderr);
29 }
30
31 static int mode_arg(void)
32 {
33 fprintf(stderr, "Error: argument of \"mode\" must be either \"l2\", "
34 "or \"l3\"\n");
35 return -1;
36 }
37
38 static int ipvlan_parse_opt(struct link_util *lu, int argc, char **argv,
39 struct nlmsghdr *n)
40 {
41 while (argc > 0) {
42 if (matches(*argv, "mode") == 0) {
43 __u16 mode = 0;
44 NEXT_ARG();
45
46 if (strcmp(*argv, "l2") == 0)
47 mode = IPVLAN_MODE_L2;
48 else if (strcmp(*argv, "l3") == 0)
49 mode = IPVLAN_MODE_L3;
50 else
51 return mode_arg();
52
53 addattr16(n, 1024, IFLA_IPVLAN_MODE, mode);
54 } else if (matches(*argv, "help") == 0) {
55 explain();
56 return -1;
57 } else {
58 fprintf(stderr, "ipvlan: unknown option \"%s\"?\n",
59 *argv);
60 explain();
61 return -1;
62 }
63 argc--, argv++;
64 }
65
66 return 0;
67 }
68
69 static void ipvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
70 {
71
72 if (!tb)
73 return;
74
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]);
78
79 fprintf(f, " mode %s ",
80 mode == IPVLAN_MODE_L2 ? "l2" :
81 mode == IPVLAN_MODE_L3 ? "l3" : "unknown");
82 }
83 }
84 }
85
86 static void ipvlan_print_help(struct link_util *lu, int argc, char **argv,
87 FILE *f)
88 {
89 ipvlan_explain(f);
90 }
91
92 struct link_util ipvlan_link_util = {
93 .id = "ipvlan",
94 .maxattr = IFLA_IPVLAN_MAX,
95 .parse_opt = ipvlan_parse_opt,
96 .print_opt = ipvlan_print_opt,
97 .print_help = ipvlan_print_help,
98 };