]>
git.proxmox.com Git - mirror_iproute2.git/blob - rdma/rdma.c
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.
9 * Authors: Leon Romanovsky <leonro@mellanox.com>
15 static void help(char *name
)
17 pr_out("Usage: %s [ OPTIONS ] OBJECT { COMMAND | help }\n"
18 " %s [ -f[orce] ] -b[atch] filename\n"
19 "where OBJECT := { dev | link | resource | help }\n"
20 " OPTIONS := { -V[ersion] | -d[etails] | -j[son] | -p[retty]}\n", name
, name
);
23 static int cmd_help(struct rd
*rd
)
29 static int rd_cmd(struct rd
*rd
, int argc
, char **argv
)
31 const struct rd_cmd cmds
[] = {
36 { "resource", cmd_res
},
43 return rd_exec_cmd(rd
, cmds
, "object");
46 static int rd_batch(struct rd
*rd
, const char *name
, bool force
)
52 if (name
&& strcmp(name
, "-") != 0) {
53 if (!freopen(name
, "r", stdin
)) {
54 pr_err("Cannot open file \"%s\" for reading: %s\n",
55 name
, strerror(errno
));
61 while (getcmdline(&line
, &len
, stdin
) != -1) {
65 largc
= makeargs(line
, largv
, ARRAY_SIZE(largv
));
67 continue; /* blank line */
69 ret
= rd_cmd(rd
, largc
, largv
);
71 pr_err("Command failed %s:%d\n", name
, cmdlineno
);
82 static int rd_init(struct rd
*rd
, char *filename
)
87 rd
->filename
= filename
;
88 INIT_LIST_HEAD(&rd
->dev_map_list
);
89 INIT_LIST_HEAD(&rd
->filter_list
);
91 if (rd
->json_output
) {
92 rd
->jw
= jsonw_new(stdout
);
94 pr_err("Failed to create JSON writer\n");
97 jsonw_pretty(rd
->jw
, rd
->pretty_output
);
100 rd
->buff
= malloc(MNL_SOCKET_BUFFER_SIZE
);
104 rd_prepare_msg(rd
, RDMA_NLDEV_CMD_GET
,
105 &seq
, (NLM_F_REQUEST
| NLM_F_ACK
| NLM_F_DUMP
));
106 ret
= rd_send_msg(rd
);
110 return rd_recv_msg(rd
, rd_dev_init_cb
, rd
, seq
);
113 static void rd_cleanup(struct rd
*rd
)
116 jsonw_destroy(&rd
->jw
);
120 int main(int argc
, char **argv
)
122 static const struct option long_options
[] = {
123 { "version", no_argument
, NULL
, 'V' },
124 { "help", no_argument
, NULL
, 'h' },
125 { "json", no_argument
, NULL
, 'j' },
126 { "pretty", no_argument
, NULL
, 'p' },
127 { "details", no_argument
, NULL
, 'd' },
128 { "force", no_argument
, NULL
, 'f' },
129 { "batch", required_argument
, NULL
, 'b' },
132 const char *batch_file
= NULL
;
133 bool pretty_output
= false;
134 bool show_details
= false;
135 bool json_output
= false;
142 filename
= basename(argv
[0]);
144 while ((opt
= getopt_long(argc
, argv
, ":Vhdpjfb:",
145 long_options
, NULL
)) >= 0) {
148 printf("%s utility, iproute2-ss%s\n",
152 pretty_output
= true;
170 pr_err("-%c option requires an argument\n", optopt
);
173 pr_err("Unknown option.\n");
182 rd
.show_details
= show_details
;
183 rd
.json_output
= json_output
;
184 rd
.pretty_output
= pretty_output
;
186 err
= rd_init(&rd
, filename
);
191 err
= rd_batch(&rd
, batch_file
, force
);
193 err
= rd_cmd(&rd
, argc
, argv
);
197 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;