]> git.proxmox.com Git - mirror_iproute2.git/blob - rdma/rdma.c
rdma: Add dev object
[mirror_iproute2.git] / rdma / rdma.c
1 /*
2 * rdma.c RDMA tool
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 * Authors: Leon Romanovsky <leonro@mellanox.com>
10 */
11
12 #include "rdma.h"
13 #include "SNAPSHOT.h"
14
15 static void help(char *name)
16 {
17 pr_out("Usage: %s [ OPTIONS ] OBJECT { COMMAND | help }\n"
18 "where OBJECT := { dev | help }\n"
19 " OPTIONS := { -V[ersion] | -d[etails]}\n", name);
20 }
21
22 static int cmd_help(struct rd *rd)
23 {
24 help(rd->filename);
25 return 0;
26 }
27
28 static int rd_cmd(struct rd *rd)
29 {
30 const struct rd_cmd cmds[] = {
31 { NULL, cmd_help },
32 { "help", cmd_help },
33 { "dev", cmd_dev },
34 { 0 }
35 };
36
37 return rd_exec_cmd(rd, cmds, "object");
38 }
39
40 static int rd_init(struct rd *rd, int argc, char **argv, char *filename)
41 {
42 uint32_t seq;
43 int ret;
44
45 rd->filename = filename;
46 rd->argc = argc;
47 rd->argv = argv;
48 INIT_LIST_HEAD(&rd->dev_map_list);
49 rd->buff = malloc(MNL_SOCKET_BUFFER_SIZE);
50 if (!rd->buff)
51 return -ENOMEM;
52
53 rd_prepare_msg(rd, RDMA_NLDEV_CMD_GET,
54 &seq, (NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP));
55 ret = rd_send_msg(rd);
56 if (ret)
57 return ret;
58
59 return rd_recv_msg(rd, rd_dev_init_cb, rd, seq);
60 }
61
62 static void rd_free(struct rd *rd)
63 {
64 free(rd->buff);
65 rd_free_devmap(rd);
66 }
67
68 int main(int argc, char **argv)
69 {
70 static const struct option long_options[] = {
71 { "version", no_argument, NULL, 'V' },
72 { "help", no_argument, NULL, 'h' },
73 { "details", no_argument, NULL, 'd' },
74 { NULL, 0, NULL, 0 }
75 };
76 bool show_details = false;
77 char *filename;
78 struct rd rd;
79 int opt;
80 int err;
81
82 filename = basename(argv[0]);
83
84 while ((opt = getopt_long(argc, argv, "Vhd",
85 long_options, NULL)) >= 0) {
86 switch (opt) {
87 case 'V':
88 printf("%s utility, iproute2-ss%s\n",
89 filename, SNAPSHOT);
90 return EXIT_SUCCESS;
91 case 'd':
92 show_details = true;
93 break;
94 case 'h':
95 help(filename);
96 return EXIT_SUCCESS;
97 default:
98 pr_err("Unknown option.\n");
99 help(filename);
100 return EXIT_FAILURE;
101 }
102 }
103
104 argc -= optind;
105 argv += optind;
106
107 err = rd_init(&rd, argc, argv, filename);
108 if (err)
109 goto out;
110
111 rd.show_details = show_details;
112 err = rd_cmd(&rd);
113 out:
114 /* Always cleanup */
115 rd_free(&rd);
116 return err ? EXIT_FAILURE : EXIT_SUCCESS;
117 }