]> git.proxmox.com Git - mirror_iproute2.git/blame - rdma/rdma.h
rdma: Properly print device and link names in CLI output
[mirror_iproute2.git] / rdma / rdma.h
CommitLineData
835d8321 1/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
74bd75c2
LR
2/*
3 * rdma.c RDMA tool
74bd75c2
LR
4 * Authors: Leon Romanovsky <leonro@mellanox.com>
5 */
6#ifndef _RDMA_TOOL_H_
7#define _RDMA_TOOL_H_
8
9#include <stdlib.h>
10#include <string.h>
11#include <errno.h>
12#include <getopt.h>
5887ff09 13#include <netinet/in.h>
74bd75c2
LR
14#include <libmnl/libmnl.h>
15#include <rdma/rdma_netlink.h>
9a362cc7 16#include <rdma/rdma_user_cm.h>
74bd75c2 17#include <time.h>
9a362cc7 18#include <net/if_arp.h>
74bd75c2
LR
19
20#include "list.h"
40df8263 21#include "utils.h"
b0a688a5 22#include "json_print.h"
74bd75c2
LR
23
24#define pr_err(args...) fprintf(stderr, ##args)
25#define pr_out(args...) fprintf(stdout, ##args)
26
40df8263
LR
27#define RDMA_BITMAP_ENUM(name, bit_no) RDMA_BITMAP_##name = BIT(bit_no),
28#define RDMA_BITMAP_NAMES(name, bit_no) [bit_no] = #name,
29
1174be72
LR
30#define MAX_NUMBER_OF_FILTERS 64
31struct filters {
3b0070f6 32 const char *name;
5a823593
LR
33 uint8_t is_number:1;
34 uint8_t is_doit:1;
1174be72
LR
35};
36
37struct filter_entry {
38 struct list_head list;
39 char *key;
40 char *value;
5a823593
LR
41 /*
42 * This field menas that we can try to issue .doit calback
43 * on value above. This value can be converted to integer
44 * with simple atoi(). Otherwise "is_doit" will be false.
45 */
46 uint8_t is_doit:1;
1174be72
LR
47};
48
74bd75c2
LR
49struct dev_map {
50 struct list_head list;
51 char *dev_name;
52 uint32_t num_ports;
53 uint32_t idx;
54};
55
56struct rd {
57 int argc;
58 char **argv;
59 char *filename;
7c01e0fc
MG
60 uint8_t show_details:1;
61 uint8_t show_driver_details:1;
62 uint8_t show_raw:1;
74bd75c2 63 struct list_head dev_map_list;
40df8263
LR
64 uint32_t dev_idx;
65 uint32_t port_idx;
74bd75c2
LR
66 struct mnl_socket *nl;
67 struct nlmsghdr *nlh;
68 char *buff;
ab6e2b7b 69 json_writer_t *jw;
b0a688a5
IK
70 int json_output;
71 int pretty_output;
8f5cfd23 72 bool suppress_errors;
1174be72 73 struct list_head filter_list;
4336c582
SW
74 char *link_name;
75 char *link_type;
74bd75c2
LR
76};
77
78struct rd_cmd {
79 const char *cmd;
80 int (*func)(struct rd *rd);
81};
82
6ae54b13
DA
83/*
84 * Parser interface
85 */
86bool rd_no_arg(struct rd *rd);
87void rd_arg_inc(struct rd *rd);
88
89char *rd_argv(struct rd *rd);
40df8263 90
40df8263
LR
91/*
92 * Commands interface
93 */
94int cmd_dev(struct rd *rd);
95int cmd_link(struct rd *rd);
923aa825 96int cmd_res(struct rd *rd);
c4572a46 97int cmd_sys(struct rd *rd);
5937552b 98int cmd_stat(struct rd *rd);
74bd75c2 99int rd_exec_cmd(struct rd *rd, const struct rd_cmd *c, const char *str);
8b92a2c9 100int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd));
a14ceed3 101int rd_exec_require_dev(struct rd *rd, int (*cb)(struct rd *rd));
6416d1a0 102int rd_exec_link(struct rd *rd, int (*cb)(struct rd *rd), bool strict_port);
5fc17280 103void rd_free(struct rd *rd);
6e0de6e8 104int rd_set_arg_to_devname(struct rd *rd);
5f4892e2 105int rd_argc(struct rd *rd);
74bd75c2 106
6ae54b13
DA
107int strcmpx(const char *str1, const char *str2);
108
74bd75c2
LR
109/*
110 * Device manipulation
111 */
40df8263 112struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index);
74bd75c2 113
1174be72
LR
114/*
115 * Filter manipulation
116 */
5a823593 117bool rd_doit_index(struct rd *rd, uint32_t *idx);
1174be72 118int rd_build_filter(struct rd *rd, const struct filters valid_filters[]);
78728b7e
LR
119bool rd_is_filtered_attr(struct rd *rd, const char *key, uint32_t val,
120 struct nlattr *attr);
121bool rd_is_string_filtered_attr(struct rd *rd, const char *key, const char *val,
122 struct nlattr *attr);
74bd75c2
LR
123/*
124 * Netlink
125 */
126int rd_send_msg(struct rd *rd);
127int rd_recv_msg(struct rd *rd, mnl_cb_t callback, void *data, uint32_t seq);
8f5cfd23 128int rd_sendrecv_msg(struct rd *rd, unsigned int seq);
74bd75c2
LR
129void rd_prepare_msg(struct rd *rd, uint32_t cmd, uint32_t *seq, uint16_t flags);
130int rd_dev_init_cb(const struct nlmsghdr *nlh, void *data);
131int rd_attr_cb(const struct nlattr *attr, void *data);
6ae54b13 132int rd_attr_check(const struct nlattr *attr, int *typep);
33115275
SW
133
134/*
135 * Print helpers
136 */
137void print_driver_table(struct rd *rd, struct nlattr *tb);
7c01e0fc 138void print_raw_data(struct rd *rd, struct nlattr **nla_line);
33115275 139void newline(struct rd *rd);
6ae54b13 140void newline_indent(struct rd *rd);
8a56ef32 141void print_on_off(struct rd *rd, const char *key_str, bool on);
7c01e0fc 142void print_raw_data(struct rd *rd, struct nlattr **nla_line);
33115275
SW
143#define MAX_LINE_LENGTH 80
144
74bd75c2 145#endif /* _RDMA_TOOL_H_ */