blob: 913a2892c95b0683f0813fca438141bb70c4d106 [file] [log] [blame]
David Ahern15faa0a2015-08-13 14:59:11 -06001/* iplink_vrf.c VRF 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: Shrijeet Mukherjee <shm@cumulusnetworks.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
21static void vrf_explain(FILE *f)
22{
23 fprintf(f, "Usage: ... vrf table TABLEID \n");
24}
25
26static void explain(void)
27{
28 vrf_explain(stderr);
29}
30
31static int table_arg(void)
32{
33 fprintf(stderr,"Error: argument of \"table\" must be 0-32767 and currently unused\n");
34 return -1;
35}
36
37static int vrf_parse_opt(struct link_util *lu, int argc, char **argv,
38 struct nlmsghdr *n)
39{
40 while (argc > 0) {
41 if (matches(*argv, "table") == 0) {
42 __u32 table;
43
44 NEXT_ARG();
45
46 table = atoi(*argv);
47 if (table > 32767)
48 return table_arg();
49 addattr32(n, 1024, IFLA_VRF_TABLE, table);
50 } else if (matches(*argv, "help") == 0) {
51 explain();
52 return -1;
53 } else {
54 fprintf(stderr, "vrf: unknown option \"%s\"?\n",
55 *argv);
56 explain();
57 return -1;
58 }
59 argc--, argv++;
60 }
61
62 return 0;
63}
64
65static void vrf_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
66{
67 if (!tb)
68 return;
69
70 if (tb[IFLA_VRF_TABLE])
71 fprintf(f, "table %u ", rta_getattr_u32(tb[IFLA_VRF_TABLE]));
72}
73
74static void vrf_print_help(struct link_util *lu, int argc, char **argv,
75 FILE *f)
76{
77 vrf_explain(f);
78}
79
80struct link_util vrf_link_util = {
81 .id = "vrf",
82 .maxattr = IFLA_VRF_MAX,
83 .parse_opt = vrf_parse_opt,
84 .print_opt = vrf_print_opt,
85 .print_help = vrf_print_help,
86};