]>
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 "where OBJECT := { dev | link | resource | help }\n"
19 " OPTIONS := { -V[ersion] | -d[etails] | -j[son] | -p[retty]}\n", name
);
22 static int cmd_help(struct rd
*rd
)
28 static int rd_cmd(struct rd
*rd
)
30 const struct rd_cmd cmds
[] = {
35 { "resource", cmd_res
},
39 return rd_exec_cmd(rd
, cmds
, "object");
42 static int rd_init(struct rd
*rd
, int argc
, char **argv
, char *filename
)
47 rd
->filename
= filename
;
50 INIT_LIST_HEAD(&rd
->dev_map_list
);
51 INIT_LIST_HEAD(&rd
->filter_list
);
53 if (rd
->json_output
) {
54 rd
->jw
= jsonw_new(stdout
);
56 pr_err("Failed to create JSON writer\n");
59 jsonw_pretty(rd
->jw
, rd
->pretty_output
);
62 rd
->buff
= malloc(MNL_SOCKET_BUFFER_SIZE
);
66 rd_prepare_msg(rd
, RDMA_NLDEV_CMD_GET
,
67 &seq
, (NLM_F_REQUEST
| NLM_F_ACK
| NLM_F_DUMP
));
68 ret
= rd_send_msg(rd
);
72 return rd_recv_msg(rd
, rd_dev_init_cb
, rd
, seq
);
75 static void rd_cleanup(struct rd
*rd
)
78 jsonw_destroy(&rd
->jw
);
82 int main(int argc
, char **argv
)
84 static const struct option long_options
[] = {
85 { "version", no_argument
, NULL
, 'V' },
86 { "help", no_argument
, NULL
, 'h' },
87 { "json", no_argument
, NULL
, 'j' },
88 { "pretty", no_argument
, NULL
, 'p' },
89 { "details", no_argument
, NULL
, 'd' },
92 bool pretty_output
= false;
93 bool show_details
= false;
94 bool json_output
= false;
100 filename
= basename(argv
[0]);
102 while ((opt
= getopt_long(argc
, argv
, "Vhdpj",
103 long_options
, NULL
)) >= 0) {
106 printf("%s utility, iproute2-ss%s\n",
110 pretty_output
= true;
122 pr_err("Unknown option.\n");
131 rd
.show_details
= show_details
;
132 rd
.json_output
= json_output
;
133 rd
.pretty_output
= pretty_output
;
135 err
= rd_init(&rd
, argc
, argv
, filename
);
143 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;