blob: 9b4b7728cf6f146ccd5ddfc2daca20a68f79a87a [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
David Ahern15faa0a2015-08-13 14:59:11 -060031static int vrf_parse_opt(struct link_util *lu, int argc, char **argv,
32 struct nlmsghdr *n)
33{
34 while (argc > 0) {
35 if (matches(*argv, "table") == 0) {
36 __u32 table;
37
38 NEXT_ARG();
39
David Ahern8a23f822015-12-08 12:24:44 -080040 if (rtnl_rttable_a2n(&table, *argv))
41 invarg("invalid table ID\n", *argv);
David Ahern15faa0a2015-08-13 14:59:11 -060042 addattr32(n, 1024, IFLA_VRF_TABLE, table);
43 } else if (matches(*argv, "help") == 0) {
44 explain();
45 return -1;
46 } else {
47 fprintf(stderr, "vrf: unknown option \"%s\"?\n",
48 *argv);
49 explain();
50 return -1;
51 }
52 argc--, argv++;
53 }
54
55 return 0;
56}
57
58static void vrf_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
59{
60 if (!tb)
61 return;
62
63 if (tb[IFLA_VRF_TABLE])
64 fprintf(f, "table %u ", rta_getattr_u32(tb[IFLA_VRF_TABLE]));
65}
66
67static void vrf_print_help(struct link_util *lu, int argc, char **argv,
68 FILE *f)
69{
70 vrf_explain(f);
71}
72
73struct link_util vrf_link_util = {
74 .id = "vrf",
75 .maxattr = IFLA_VRF_MAX,
76 .parse_opt = vrf_parse_opt,
77 .print_opt = vrf_print_opt,
78 .print_help = vrf_print_help,
79};