]>
git.proxmox.com Git - mirror_iproute2.git/blob - tc/tc_qevent.c
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
4 * Helpers for handling qevents.
10 #include "tc_qevent.h"
13 void qevents_init(struct qevent_util
*qevents
)
18 for (; qevents
->id
; qevents
++)
19 memset(qevents
->data
, 0, qevents
->data_size
);
22 int qevent_parse(struct qevent_util
*qevents
, int *p_argc
, char ***p_argv
)
24 char **argv
= *p_argv
;
26 const char *name
= *argv
;
32 for (; qevents
->id
; qevents
++) {
33 if (strcmp(name
, qevents
->id
) == 0) {
35 err
= qevents
->parse_qevent(qevents
, &argc
, &argv
);
46 fprintf(stderr
, "Unknown qevent `%s'\n", name
);
50 int qevents_read(struct qevent_util
*qevents
, struct rtattr
**tb
)
57 for (; qevents
->id
; qevents
++) {
58 if (tb
[qevents
->attr
]) {
59 err
= qevents
->read_qevent(qevents
, tb
);
68 void qevents_print(struct qevent_util
*qevents
, FILE *f
)
75 for (; qevents
->id
; qevents
++) {
76 struct qevent_base
*qeb
= qevents
->data
;
80 open_json_array(PRINT_JSON
, "qevents");
84 open_json_object(NULL
);
85 print_string(PRINT_ANY
, "kind", "qevent %s", qevents
->id
);
86 qevents
->print_qevent(qevents
, f
);
87 print_string(PRINT_FP
, NULL
, "%s", " ");
93 close_json_array(PRINT_ANY
, "");
96 bool qevents_have_block(struct qevent_util
*qevents
, __u32 block_idx
)
101 for (; qevents
->id
; qevents
++) {
102 struct qevent_base
*qeb
= qevents
->data
;
104 if (qeb
->block_idx
== block_idx
)
111 int qevents_dump(struct qevent_util
*qevents
, struct nlmsghdr
*n
)
118 for (; qevents
->id
; qevents
++) {
119 struct qevent_base
*qeb
= qevents
->data
;
121 if (qeb
->block_idx
) {
122 err
= qevents
->dump_qevent(qevents
, n
);
131 static int parse_block_idx(const char *arg
, struct qevent_base
*qeb
)
133 if (qeb
->block_idx
) {
134 fprintf(stderr
, "Qevent block index already specified\n");
138 if (get_unsigned(&qeb
->block_idx
, arg
, 10) || !qeb
->block_idx
) {
139 fprintf(stderr
, "Illegal qevent block index\n");
146 static int read_block_idx(struct rtattr
*attr
, struct qevent_base
*qeb
)
148 if (qeb
->block_idx
) {
149 fprintf(stderr
, "Qevent block index already specified\n");
153 qeb
->block_idx
= rta_getattr_u32(attr
);
154 if (!qeb
->block_idx
) {
155 fprintf(stderr
, "Illegal qevent block index\n");
162 static void print_block_idx(FILE *f
, __u32 block_idx
)
164 print_uint(PRINT_ANY
, "block", " block %u", block_idx
);
167 int qevent_parse_plain(struct qevent_util
*qu
, int *p_argc
, char ***p_argv
)
169 struct qevent_plain
*qe
= qu
->data
;
170 char **argv
= *p_argv
;
173 if (qe
->base
.block_idx
) {
174 fprintf(stderr
, "Duplicate qevent\n");
179 if (strcmp(*argv
, "block") == 0) {
181 if (parse_block_idx(*argv
, &qe
->base
))
189 if (!qe
->base
.block_idx
) {
190 fprintf(stderr
, "Unspecified qevent block index\n");
199 int qevent_read_plain(struct qevent_util
*qu
, struct rtattr
**tb
)
201 struct qevent_plain
*qe
= qu
->data
;
203 return read_block_idx(tb
[qu
->attr
], &qe
->base
);
206 void qevent_print_plain(struct qevent_util
*qu
, FILE *f
)
208 struct qevent_plain
*qe
= qu
->data
;
210 print_block_idx(f
, qe
->base
.block_idx
);
213 int qevent_dump_plain(struct qevent_util
*qu
, struct nlmsghdr
*n
)
215 struct qevent_plain
*qe
= qu
->data
;
217 return addattr32(n
, 1024, qu
->attr
, qe
->base
.block_idx
);