]> git.proxmox.com Git - mirror_iproute2.git/blob - ip/iplink_ipvlan.c
tc/m_gact: Drop dead code
[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 | l3s } ]\n");
24 }
25
26 static int ipvlan_parse_opt(struct link_util *lu, int argc, char **argv,
27 struct nlmsghdr *n)
28 {
29 while (argc > 0) {
30 if (matches(*argv, "mode") == 0) {
31 __u16 mode = 0;
32
33 NEXT_ARG();
34
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;
41 else {
42 fprintf(stderr, "Error: argument of \"mode\" must be either \"l2\", \"l3\" or \"l3s\"\n");
43 return -1;
44 }
45 addattr16(n, 1024, IFLA_IPVLAN_MODE, mode);
46 } else if (matches(*argv, "help") == 0) {
47 ipvlan_explain(stderr);
48 return -1;
49 } else {
50 fprintf(stderr, "ipvlan: unknown option \"%s\"?\n",
51 *argv);
52 ipvlan_explain(stderr);
53 return -1;
54 }
55 argc--;
56 argv++;
57 }
58
59 return 0;
60 }
61
62 static void ipvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
63 {
64
65 if (!tb)
66 return;
67
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
72 fprintf(f, " mode %s ",
73 mode == IPVLAN_MODE_L2 ? "l2" :
74 mode == IPVLAN_MODE_L3 ? "l3" :
75 mode == IPVLAN_MODE_L3S ? "l3s" : "unknown");
76 }
77 }
78 }
79
80 static void ipvlan_print_help(struct link_util *lu, int argc, char **argv,
81 FILE *f)
82 {
83 ipvlan_explain(f);
84 }
85
86 struct link_util ipvlan_link_util = {
87 .id = "ipvlan",
88 .maxattr = IFLA_IPVLAN_MAX,
89 .parse_opt = ipvlan_parse_opt,
90 .print_opt = ipvlan_print_opt,
91 .print_help = ipvlan_print_help,
92 };