]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/blob - ip/iplink_macvtap.c
iproute: rename 'get_jiffies' since it uses msecs
[lisovros/iproute2_canprio.git] / ip / iplink_macvtap.c
1 /*
2  * iplink_macvtap.c     macvtap 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
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <sys/socket.h>
14 #include <linux/if_link.h>
15
16 #include "rt_names.h"
17 #include "utils.h"
18 #include "ip_common.h"
19
20 static void explain(void)
21 {
22         fprintf(stderr,
23                 "Usage: ... macvtap mode { private | vepa | bridge }\n"
24         );
25 }
26
27 static int mode_arg(void)
28 {
29         fprintf(stderr, "Error: argument of \"mode\" must be \"private\", "
30                 "\"vepa\" or \"bridge\"\n");
31         return -1;
32 }
33
34 static int macvtap_parse_opt(struct link_util *lu, int argc, char **argv,
35                           struct nlmsghdr *n)
36 {
37         while (argc > 0) {
38                 if (matches(*argv, "mode") == 0) {
39                         __u32 mode = 0;
40                         NEXT_ARG();
41
42                         if (strcmp(*argv, "private") == 0)
43                                 mode = MACVLAN_MODE_PRIVATE;
44                         else if (strcmp(*argv, "vepa") == 0)
45                                 mode = MACVLAN_MODE_VEPA;
46                         else if (strcmp(*argv, "bridge") == 0)
47                                 mode = MACVLAN_MODE_BRIDGE;
48                         else
49                                 return mode_arg();
50
51                         addattr32(n, 1024, IFLA_MACVLAN_MODE, mode);
52                 } else if (matches(*argv, "help") == 0) {
53                         explain();
54                         return -1;
55                 } else {
56                         fprintf(stderr, "macvtap: what is \"%s\"?\n", *argv);
57                         explain();
58                         return -1;
59                 }
60                 argc--, argv++;
61         }
62
63         return 0;
64 }
65
66 static void macvtap_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
67 {
68         __u32 mode;
69
70         if (!tb)
71                 return;
72
73         if (!tb[IFLA_MACVLAN_MODE] ||
74             RTA_PAYLOAD(tb[IFLA_MACVLAN_MODE]) < sizeof(__u32))
75                 return;
76
77         mode = *(__u32 *)RTA_DATA(tb[IFLA_VLAN_ID]);
78         fprintf(f, " mode %s ",
79                   mode == MACVLAN_MODE_PRIVATE ? "private"
80                 : mode == MACVLAN_MODE_VEPA    ? "vepa"
81                 : mode == MACVLAN_MODE_BRIDGE  ? "bridge"
82                 :                                "unknown");
83 }
84
85 struct link_util macvtap_link_util = {
86         .id             = "macvtap",
87         .maxattr        = IFLA_MACVLAN_MAX,
88         .parse_opt      = macvtap_parse_opt,
89         .print_opt      = macvtap_print_opt,
90 };