Lines Matching full:dl

203 struct dl {  struct
222 static int dl_argc(struct dl *dl) in dl_argc() argument
224 return dl->argc; in dl_argc()
227 static char *dl_argv(struct dl *dl) in dl_argv() argument
229 if (dl_argc(dl) == 0) in dl_argv()
231 return *dl->argv; in dl_argv()
234 static void dl_arg_inc(struct dl *dl) in dl_arg_inc() argument
236 if (dl_argc(dl) == 0) in dl_arg_inc()
238 dl->argc--; in dl_arg_inc()
239 dl->argv++; in dl_arg_inc()
242 static char *dl_argv_next(struct dl *dl) in dl_argv_next() argument
246 if (dl_argc(dl) == 0) in dl_argv_next()
249 ret = *dl->argv; in dl_argv_next()
250 dl_arg_inc(dl); in dl_argv_next()
254 static char *dl_argv_index(struct dl *dl, unsigned int index) in dl_argv_index() argument
256 if (index >= dl_argc(dl)) in dl_argv_index()
258 return dl->argv[index]; in dl_argv_index()
268 static bool dl_argv_match(struct dl *dl, const char *pattern) in dl_argv_match() argument
270 if (dl_argc(dl) == 0) in dl_argv_match()
272 return strcmpx(dl_argv(dl), pattern) == 0; in dl_argv_match()
275 static bool dl_no_arg(struct dl *dl) in dl_no_arg() argument
277 return dl_argc(dl) == 0; in dl_no_arg()
360 struct dl *dl = data; in ifname_map_cb() local
383 list_add(&ifname_map->list, &dl->ifname_map_list); in ifname_map_cb()
388 static void ifname_map_fini(struct dl *dl) in ifname_map_fini() argument
393 &dl->ifname_map_list, list) { in ifname_map_fini()
399 static int ifname_map_init(struct dl *dl) in ifname_map_init() argument
404 INIT_LIST_HEAD(&dl->ifname_map_list); in ifname_map_init()
406 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_GET, in ifname_map_init()
409 err = _mnlg_socket_sndrcv(dl->nlg, nlh, ifname_map_cb, dl); in ifname_map_init()
411 ifname_map_fini(dl); in ifname_map_init()
417 static int ifname_map_lookup(struct dl *dl, const char *ifname, in ifname_map_lookup() argument
423 list_for_each_entry(ifname_map, &dl->ifname_map_list, list) { in ifname_map_lookup()
434 static int ifname_map_rev_lookup(struct dl *dl, const char *bus_name, in ifname_map_rev_lookup() argument
440 list_for_each_entry(ifname_map, &dl->ifname_map_list, list) { in ifname_map_rev_lookup()
510 static int dl_argv_handle(struct dl *dl, char **p_bus_name, char **p_dev_name) in dl_argv_handle() argument
512 char *str = dl_argv_next(dl); in dl_argv_handle()
553 static int __dl_argv_handle_port_ifname(struct dl *dl, char *str, in __dl_argv_handle_port_ifname() argument
559 err = ifname_map_lookup(dl, str, p_bus_name, p_dev_name, in __dl_argv_handle_port_ifname()
568 static int dl_argv_handle_port(struct dl *dl, char **p_bus_name, in dl_argv_handle_port() argument
571 char *str = dl_argv_next(dl); in dl_argv_handle_port()
581 return __dl_argv_handle_port_ifname(dl, str, p_bus_name, in dl_argv_handle_port()
593 static int dl_argv_handle_both(struct dl *dl, char **p_bus_name, in dl_argv_handle_both() argument
597 char *str = dl_argv_next(dl); in dl_argv_handle_both()
620 err = __dl_argv_handle_port_ifname(dl, str, p_bus_name, in dl_argv_handle_both()
633 static int dl_argv_uint32_t(struct dl *dl, uint32_t *p_val) in dl_argv_uint32_t() argument
635 char *str = dl_argv_next(dl); in dl_argv_uint32_t()
651 static int dl_argv_uint16_t(struct dl *dl, uint16_t *p_val) in dl_argv_uint16_t() argument
653 char *str = dl_argv_next(dl); in dl_argv_uint16_t()
669 static int dl_argv_str(struct dl *dl, const char **p_str) in dl_argv_str() argument
671 const char *str = dl_argv_next(dl); in dl_argv_str()
782 static int dl_argv_parse(struct dl *dl, uint32_t o_required, in dl_argv_parse() argument
785 struct dl_opts *opts = &dl->opts; in dl_argv_parse()
793 err = dl_argv_handle_both(dl, &opts->bus_name, &opts->dev_name, in dl_argv_parse()
799 err = dl_argv_handle(dl, &opts->bus_name, &opts->dev_name); in dl_argv_parse()
804 err = dl_argv_handle_port(dl, &opts->bus_name, &opts->dev_name, in dl_argv_parse()
811 while (dl_argc(dl)) { in dl_argv_parse()
812 if (dl_argv_match(dl, "type") && in dl_argv_parse()
816 dl_arg_inc(dl); in dl_argv_parse()
817 err = dl_argv_str(dl, &typestr); in dl_argv_parse()
824 } else if (dl_argv_match(dl, "count") && in dl_argv_parse()
826 dl_arg_inc(dl); in dl_argv_parse()
827 err = dl_argv_uint32_t(dl, &opts->port_count); in dl_argv_parse()
831 } else if (dl_argv_match(dl, "sb") && in dl_argv_parse()
833 dl_arg_inc(dl); in dl_argv_parse()
834 err = dl_argv_uint32_t(dl, &opts->sb_index); in dl_argv_parse()
838 } else if (dl_argv_match(dl, "pool") && in dl_argv_parse()
840 dl_arg_inc(dl); in dl_argv_parse()
841 err = dl_argv_uint16_t(dl, &opts->sb_pool_index); in dl_argv_parse()
845 } else if (dl_argv_match(dl, "size") && in dl_argv_parse()
847 dl_arg_inc(dl); in dl_argv_parse()
848 err = dl_argv_uint32_t(dl, &opts->sb_pool_size); in dl_argv_parse()
852 } else if (dl_argv_match(dl, "type") && in dl_argv_parse()
856 dl_arg_inc(dl); in dl_argv_parse()
857 err = dl_argv_str(dl, &typestr); in dl_argv_parse()
864 } else if (dl_argv_match(dl, "thtype") && in dl_argv_parse()
868 dl_arg_inc(dl); in dl_argv_parse()
869 err = dl_argv_str(dl, &typestr); in dl_argv_parse()
877 } else if (dl_argv_match(dl, "th") && in dl_argv_parse()
879 dl_arg_inc(dl); in dl_argv_parse()
880 err = dl_argv_uint32_t(dl, &opts->sb_threshold); in dl_argv_parse()
884 } else if (dl_argv_match(dl, "tc") && in dl_argv_parse()
886 dl_arg_inc(dl); in dl_argv_parse()
887 err = dl_argv_uint16_t(dl, &opts->sb_tc_index); in dl_argv_parse()
891 } else if (dl_argv_match(dl, "mode") && in dl_argv_parse()
895 dl_arg_inc(dl); in dl_argv_parse()
896 err = dl_argv_str(dl, &typestr); in dl_argv_parse()
903 } else if (dl_argv_match(dl, "inline-mode") && in dl_argv_parse()
907 dl_arg_inc(dl); in dl_argv_parse()
908 err = dl_argv_str(dl, &typestr); in dl_argv_parse()
916 } else if (dl_argv_match(dl, "name") && in dl_argv_parse()
918 dl_arg_inc(dl); in dl_argv_parse()
919 err = dl_argv_str(dl, &opts->dpipe_table_name); in dl_argv_parse()
923 } else if (dl_argv_match(dl, "counters") && in dl_argv_parse()
927 dl_arg_inc(dl); in dl_argv_parse()
928 err = dl_argv_str(dl, &typestr); in dl_argv_parse()
936 } else if (dl_argv_match(dl, "encap") && in dl_argv_parse()
940 dl_arg_inc(dl); in dl_argv_parse()
941 err = dl_argv_str(dl, &typestr); in dl_argv_parse()
950 pr_err("Unknown option \"%s\"\n", dl_argv(dl)); in dl_argv_parse()
1036 static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl) in dl_opts_put() argument
1038 struct dl_opts *opts = &dl->opts; in dl_opts_put()
1093 static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl, in dl_argv_parse_put() argument
1098 err = dl_argv_parse(dl, o_required, o_optional); in dl_argv_parse_put()
1101 dl_opts_put(nlh, dl); in dl_argv_parse_put()
1105 static bool dl_dump_filter(struct dl *dl, struct nlattr **tb) in dl_dump_filter() argument
1107 struct dl_opts *opts = &dl->opts; in dl_dump_filter()
1151 static bool cmp_arr_last_handle(struct dl *dl, const char *bus_name, in cmp_arr_last_handle() argument
1154 if (!dl->arr_last.present) in cmp_arr_last_handle()
1156 return strcmp(dl->arr_last.bus_name, bus_name) == 0 && in cmp_arr_last_handle()
1157 strcmp(dl->arr_last.dev_name, dev_name) == 0; in cmp_arr_last_handle()
1160 static void arr_last_handle_set(struct dl *dl, const char *bus_name, in arr_last_handle_set() argument
1163 dl->arr_last.present = true; in arr_last_handle_set()
1164 free(dl->arr_last.dev_name); in arr_last_handle_set()
1165 free(dl->arr_last.bus_name); in arr_last_handle_set()
1166 dl->arr_last.bus_name = strdup(bus_name); in arr_last_handle_set()
1167 dl->arr_last.dev_name = strdup(dev_name); in arr_last_handle_set()
1170 static bool should_arr_last_handle_start(struct dl *dl, const char *bus_name, in should_arr_last_handle_start() argument
1173 return !cmp_arr_last_handle(dl, bus_name, dev_name); in should_arr_last_handle_start()
1176 static bool should_arr_last_handle_end(struct dl *dl, const char *bus_name, in should_arr_last_handle_end() argument
1179 return dl->arr_last.present && in should_arr_last_handle_end()
1180 !cmp_arr_last_handle(dl, bus_name, dev_name); in should_arr_last_handle_end()
1183 static void __pr_out_handle_start(struct dl *dl, struct nlattr **tb, in __pr_out_handle_start() argument
1192 if (dl->json_output) { in __pr_out_handle_start()
1194 if (should_arr_last_handle_end(dl, bus_name, dev_name)) in __pr_out_handle_start()
1195 jsonw_end_array(dl->jw); in __pr_out_handle_start()
1196 if (should_arr_last_handle_start(dl, bus_name, in __pr_out_handle_start()
1198 jsonw_name(dl->jw, buf); in __pr_out_handle_start()
1199 jsonw_start_array(dl->jw); in __pr_out_handle_start()
1200 jsonw_start_object(dl->jw); in __pr_out_handle_start()
1201 arr_last_handle_set(dl, bus_name, dev_name); in __pr_out_handle_start()
1203 jsonw_start_object(dl->jw); in __pr_out_handle_start()
1206 jsonw_name(dl->jw, buf); in __pr_out_handle_start()
1207 jsonw_start_object(dl->jw); in __pr_out_handle_start()
1211 if (should_arr_last_handle_end(dl, bus_name, dev_name)) in __pr_out_handle_start()
1213 if (should_arr_last_handle_start(dl, bus_name, in __pr_out_handle_start()
1218 arr_last_handle_set(dl, bus_name, dev_name); in __pr_out_handle_start()
1226 static void pr_out_handle_start_arr(struct dl *dl, struct nlattr **tb) in pr_out_handle_start_arr() argument
1228 __pr_out_handle_start(dl, tb, true, true); in pr_out_handle_start_arr()
1231 static void pr_out_handle_end(struct dl *dl) in pr_out_handle_end() argument
1233 if (dl->json_output) in pr_out_handle_end()
1234 jsonw_end_object(dl->jw); in pr_out_handle_end()
1239 static void pr_out_handle(struct dl *dl, struct nlattr **tb) in pr_out_handle() argument
1241 __pr_out_handle_start(dl, tb, false, false); in pr_out_handle()
1242 pr_out_handle_end(dl); in pr_out_handle()
1245 static bool cmp_arr_last_port_handle(struct dl *dl, const char *bus_name, in cmp_arr_last_port_handle() argument
1248 return cmp_arr_last_handle(dl, bus_name, dev_name) && in cmp_arr_last_port_handle()
1249 dl->arr_last.port_index == port_index; in cmp_arr_last_port_handle()
1252 static void arr_last_port_handle_set(struct dl *dl, const char *bus_name, in arr_last_port_handle_set() argument
1255 arr_last_handle_set(dl, bus_name, dev_name); in arr_last_port_handle_set()
1256 dl->arr_last.port_index = port_index; in arr_last_port_handle_set()
1259 static bool should_arr_last_port_handle_start(struct dl *dl, in should_arr_last_port_handle_start() argument
1264 return !cmp_arr_last_port_handle(dl, bus_name, dev_name, port_index); in should_arr_last_port_handle_start()
1267 static bool should_arr_last_port_handle_end(struct dl *dl, in should_arr_last_port_handle_end() argument
1272 return dl->arr_last.present && in should_arr_last_port_handle_end()
1273 !cmp_arr_last_port_handle(dl, bus_name, dev_name, port_index); in should_arr_last_port_handle_end()
1276 static void __pr_out_port_handle_start(struct dl *dl, const char *bus_name, in __pr_out_port_handle_start() argument
1284 if (dl->no_nice_names || !try_nice || in __pr_out_port_handle_start()
1285 ifname_map_rev_lookup(dl, bus_name, dev_name, in __pr_out_port_handle_start()
1291 if (dl->json_output) { in __pr_out_port_handle_start()
1293 if (should_arr_last_port_handle_end(dl, bus_name, in __pr_out_port_handle_start()
1296 jsonw_end_array(dl->jw); in __pr_out_port_handle_start()
1297 if (should_arr_last_port_handle_start(dl, bus_name, in __pr_out_port_handle_start()
1300 jsonw_name(dl->jw, buf); in __pr_out_port_handle_start()
1301 jsonw_start_array(dl->jw); in __pr_out_port_handle_start()
1302 jsonw_start_object(dl->jw); in __pr_out_port_handle_start()
1303 arr_last_port_handle_set(dl, bus_name, dev_name, in __pr_out_port_handle_start()
1306 jsonw_start_object(dl->jw); in __pr_out_port_handle_start()
1309 jsonw_name(dl->jw, buf); in __pr_out_port_handle_start()
1310 jsonw_start_object(dl->jw); in __pr_out_port_handle_start()
1317 static void pr_out_port_handle_start(struct dl *dl, struct nlattr **tb, bool try_nice) in pr_out_port_handle_start() argument
1326 __pr_out_port_handle_start(dl, bus_name, dev_name, port_index, try_nice, false); in pr_out_port_handle_start()
1329 static void pr_out_port_handle_start_arr(struct dl *dl, struct nlattr **tb, bool try_nice) in pr_out_port_handle_start_arr() argument
1338 __pr_out_port_handle_start(dl, bus_name, dev_name, port_index, try_nice, true); in pr_out_port_handle_start_arr()
1341 static void pr_out_port_handle_end(struct dl *dl) in pr_out_port_handle_end() argument
1343 if (dl->json_output) in pr_out_port_handle_end()
1344 jsonw_end_object(dl->jw); in pr_out_port_handle_end()
1350 static void pr_out_str(struct dl *dl, const char *name, const char *val) in pr_out_str() argument
1352 if (dl->json_output) { in pr_out_str()
1353 jsonw_string_field(dl->jw, name, val); in pr_out_str()
1362 static void pr_out_uint(struct dl *dl, const char *name, unsigned int val) in pr_out_uint() argument
1364 if (dl->json_output) { in pr_out_uint()
1365 jsonw_uint_field(dl->jw, name, val); in pr_out_uint()
1374 static void pr_out_dev(struct dl *dl, struct nlattr **tb) in pr_out_dev() argument
1376 pr_out_handle(dl, tb); in pr_out_dev()
1379 static void pr_out_section_start(struct dl *dl, const char *name) in pr_out_section_start() argument
1381 if (dl->json_output) { in pr_out_section_start()
1382 jsonw_start_object(dl->jw); in pr_out_section_start()
1383 jsonw_name(dl->jw, name); in pr_out_section_start()
1384 jsonw_start_object(dl->jw); in pr_out_section_start()
1388 static void pr_out_section_end(struct dl *dl) in pr_out_section_end() argument
1390 if (dl->json_output) { in pr_out_section_end()
1391 if (dl->arr_last.present) in pr_out_section_end()
1392 jsonw_end_array(dl->jw); in pr_out_section_end()
1393 jsonw_end_object(dl->jw); in pr_out_section_end()
1394 jsonw_end_object(dl->jw); in pr_out_section_end()
1398 static void pr_out_array_start(struct dl *dl, const char *name) in pr_out_array_start() argument
1400 if (dl->json_output) { in pr_out_array_start()
1401 jsonw_name(dl->jw, name); in pr_out_array_start()
1402 jsonw_start_array(dl->jw); in pr_out_array_start()
1412 static void pr_out_array_end(struct dl *dl) in pr_out_array_end() argument
1414 if (dl->json_output) in pr_out_array_end()
1415 jsonw_end_array(dl->jw); in pr_out_array_end()
1420 static void pr_out_entry_start(struct dl *dl) in pr_out_entry_start() argument
1422 if (dl->json_output) in pr_out_entry_start()
1423 jsonw_start_object(dl->jw); in pr_out_entry_start()
1426 static void pr_out_entry_end(struct dl *dl) in pr_out_entry_end() argument
1428 if (dl->json_output) in pr_out_entry_end()
1429 jsonw_end_object(dl->jw); in pr_out_entry_end()
1459 static void pr_out_eswitch(struct dl *dl, struct nlattr **tb) in pr_out_eswitch() argument
1461 __pr_out_handle_start(dl, tb, true, false); in pr_out_eswitch()
1464 pr_out_str(dl, "mode", in pr_out_eswitch()
1468 pr_out_str(dl, "inline-mode", in pr_out_eswitch()
1475 pr_out_str(dl, "encap", encap_mode ? "enable" : "disable"); in pr_out_eswitch()
1478 pr_out_handle_end(dl); in pr_out_eswitch()
1483 struct dl *dl = data; in cmd_dev_eswitch_show_cb() local
1490 pr_out_eswitch(dl, tb); in cmd_dev_eswitch_show_cb()
1494 static int cmd_dev_eswitch_show(struct dl *dl) in cmd_dev_eswitch_show() argument
1499 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_ESWITCH_GET, in cmd_dev_eswitch_show()
1502 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0); in cmd_dev_eswitch_show()
1506 pr_out_section_start(dl, "dev"); in cmd_dev_eswitch_show()
1507 err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_eswitch_show_cb, dl); in cmd_dev_eswitch_show()
1508 pr_out_section_end(dl); in cmd_dev_eswitch_show()
1512 static int cmd_dev_eswitch_set(struct dl *dl) in cmd_dev_eswitch_set() argument
1517 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_ESWITCH_SET, in cmd_dev_eswitch_set()
1520 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, in cmd_dev_eswitch_set()
1528 if (dl->opts.present == 1) { in cmd_dev_eswitch_set()
1533 return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); in cmd_dev_eswitch_set()
1536 static int cmd_dev_eswitch(struct dl *dl) in cmd_dev_eswitch() argument
1538 if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { in cmd_dev_eswitch()
1541 } else if (dl_argv_match(dl, "set")) { in cmd_dev_eswitch()
1542 dl_arg_inc(dl); in cmd_dev_eswitch()
1543 return cmd_dev_eswitch_set(dl); in cmd_dev_eswitch()
1544 } else if (dl_argv_match(dl, "show")) { in cmd_dev_eswitch()
1545 dl_arg_inc(dl); in cmd_dev_eswitch()
1546 return cmd_dev_eswitch_show(dl); in cmd_dev_eswitch()
1548 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_dev_eswitch()
1554 struct dl *dl = data; in cmd_dev_show_cb() local
1561 pr_out_dev(dl, tb); in cmd_dev_show_cb()
1565 static int cmd_dev_show(struct dl *dl) in cmd_dev_show() argument
1571 if (dl_argc(dl) == 0) in cmd_dev_show()
1574 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_GET, flags); in cmd_dev_show()
1576 if (dl_argc(dl) > 0) { in cmd_dev_show()
1577 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0); in cmd_dev_show()
1582 pr_out_section_start(dl, "dev"); in cmd_dev_show()
1583 err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_show_cb, dl); in cmd_dev_show()
1584 pr_out_section_end(dl); in cmd_dev_show()
1588 static int cmd_dev(struct dl *dl) in cmd_dev() argument
1590 if (dl_argv_match(dl, "help")) { in cmd_dev()
1593 } else if (dl_argv_match(dl, "show") || in cmd_dev()
1594 dl_argv_match(dl, "list") || dl_no_arg(dl)) { in cmd_dev()
1595 dl_arg_inc(dl); in cmd_dev()
1596 return cmd_dev_show(dl); in cmd_dev()
1597 } else if (dl_argv_match(dl, "eswitch")) { in cmd_dev()
1598 dl_arg_inc(dl); in cmd_dev()
1599 return cmd_dev_eswitch(dl); in cmd_dev()
1601 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_dev()
1624 static void pr_out_port(struct dl *dl, struct nlattr **tb) in pr_out_port() argument
1629 pr_out_port_handle_start(dl, tb, false); in pr_out_port()
1633 pr_out_str(dl, "type", port_type_name(port_type)); in pr_out_port()
1638 pr_out_str(dl, "des_type", in pr_out_port()
1643 pr_out_str(dl, "netdev", in pr_out_port()
1646 pr_out_str(dl, "ibdev", in pr_out_port()
1649 pr_out_uint(dl, "split_group", in pr_out_port()
1651 pr_out_port_handle_end(dl); in pr_out_port()
1656 struct dl *dl = data; in cmd_port_show_cb() local
1664 pr_out_port(dl, tb); in cmd_port_show_cb()
1668 static int cmd_port_show(struct dl *dl) in cmd_port_show() argument
1674 if (dl_argc(dl) == 0) in cmd_port_show()
1677 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_GET, flags); in cmd_port_show()
1679 if (dl_argc(dl) > 0) { in cmd_port_show()
1680 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP, 0); in cmd_port_show()
1685 pr_out_section_start(dl, "port"); in cmd_port_show()
1686 err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_port_show_cb, dl); in cmd_port_show()
1687 pr_out_section_end(dl); in cmd_port_show()
1691 static int cmd_port_set(struct dl *dl) in cmd_port_set() argument
1696 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_SET, in cmd_port_set()
1699 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_PORT_TYPE, 0); in cmd_port_set()
1703 return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); in cmd_port_set()
1706 static int cmd_port_split(struct dl *dl) in cmd_port_split() argument
1711 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_SPLIT, in cmd_port_split()
1714 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_PORT_COUNT, 0); in cmd_port_split()
1718 return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); in cmd_port_split()
1721 static int cmd_port_unsplit(struct dl *dl) in cmd_port_unsplit() argument
1726 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_UNSPLIT, in cmd_port_unsplit()
1729 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP, 0); in cmd_port_unsplit()
1733 return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); in cmd_port_unsplit()
1736 static int cmd_port(struct dl *dl) in cmd_port() argument
1738 if (dl_argv_match(dl, "help")) { in cmd_port()
1741 } else if (dl_argv_match(dl, "show") || in cmd_port()
1742 dl_argv_match(dl, "list") || dl_no_arg(dl)) { in cmd_port()
1743 dl_arg_inc(dl); in cmd_port()
1744 return cmd_port_show(dl); in cmd_port()
1745 } else if (dl_argv_match(dl, "set")) { in cmd_port()
1746 dl_arg_inc(dl); in cmd_port()
1747 return cmd_port_set(dl); in cmd_port()
1748 } else if (dl_argv_match(dl, "split")) { in cmd_port()
1749 dl_arg_inc(dl); in cmd_port()
1750 return cmd_port_split(dl); in cmd_port()
1751 } else if (dl_argv_match(dl, "unsplit")) { in cmd_port()
1752 dl_arg_inc(dl); in cmd_port()
1753 return cmd_port_unsplit(dl); in cmd_port()
1755 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_port()
1779 static void pr_out_sb(struct dl *dl, struct nlattr **tb) in pr_out_sb() argument
1781 pr_out_handle_start_arr(dl, tb); in pr_out_sb()
1782 pr_out_uint(dl, "sb", in pr_out_sb()
1784 pr_out_uint(dl, "size", in pr_out_sb()
1786 pr_out_uint(dl, "ing_pools", in pr_out_sb()
1788 pr_out_uint(dl, "eg_pools", in pr_out_sb()
1790 pr_out_uint(dl, "ing_tcs", in pr_out_sb()
1792 pr_out_uint(dl, "eg_tcs", in pr_out_sb()
1794 pr_out_handle_end(dl); in pr_out_sb()
1799 struct dl *dl = data; in cmd_sb_show_cb() local
1811 pr_out_sb(dl, tb); in cmd_sb_show_cb()
1815 static int cmd_sb_show(struct dl *dl) in cmd_sb_show() argument
1821 if (dl_argc(dl) == 0) in cmd_sb_show()
1824 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_GET, flags); in cmd_sb_show()
1826 if (dl_argc(dl) > 0) { in cmd_sb_show()
1827 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_SB); in cmd_sb_show()
1832 pr_out_section_start(dl, "sb"); in cmd_sb_show()
1833 err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_sb_show_cb, dl); in cmd_sb_show()
1834 pr_out_section_end(dl); in cmd_sb_show()
1856 static void pr_out_sb_pool(struct dl *dl, struct nlattr **tb) in pr_out_sb_pool() argument
1858 pr_out_handle_start_arr(dl, tb); in pr_out_sb_pool()
1859 pr_out_uint(dl, "sb", in pr_out_sb_pool()
1861 pr_out_uint(dl, "pool", in pr_out_sb_pool()
1863 pr_out_str(dl, "type", in pr_out_sb_pool()
1865 pr_out_uint(dl, "size", in pr_out_sb_pool()
1867 pr_out_str(dl, "thtype", in pr_out_sb_pool()
1869 pr_out_handle_end(dl); in pr_out_sb_pool()
1874 struct dl *dl = data; in cmd_sb_pool_show_cb() local
1884 pr_out_sb_pool(dl, tb); in cmd_sb_pool_show_cb()
1888 static int cmd_sb_pool_show(struct dl *dl) in cmd_sb_pool_show() argument
1894 if (dl_argc(dl) == 0) in cmd_sb_pool_show()
1897 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_POOL_GET, flags); in cmd_sb_pool_show()
1899 if (dl_argc(dl) > 0) { in cmd_sb_pool_show()
1900 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_SB_POOL, in cmd_sb_pool_show()
1906 pr_out_section_start(dl, "pool"); in cmd_sb_pool_show()
1907 err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_sb_pool_show_cb, dl); in cmd_sb_pool_show()
1908 pr_out_section_end(dl); in cmd_sb_pool_show()
1912 static int cmd_sb_pool_set(struct dl *dl) in cmd_sb_pool_set() argument
1917 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_POOL_SET, in cmd_sb_pool_set()
1920 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_SB_POOL | in cmd_sb_pool_set()
1925 return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); in cmd_sb_pool_set()
1928 static int cmd_sb_pool(struct dl *dl) in cmd_sb_pool() argument
1930 if (dl_argv_match(dl, "help")) { in cmd_sb_pool()
1933 } else if (dl_argv_match(dl, "show") || in cmd_sb_pool()
1934 dl_argv_match(dl, "list") || dl_no_arg(dl)) { in cmd_sb_pool()
1935 dl_arg_inc(dl); in cmd_sb_pool()
1936 return cmd_sb_pool_show(dl); in cmd_sb_pool()
1937 } else if (dl_argv_match(dl, "set")) { in cmd_sb_pool()
1938 dl_arg_inc(dl); in cmd_sb_pool()
1939 return cmd_sb_pool_set(dl); in cmd_sb_pool()
1941 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_sb_pool()
1945 static void pr_out_sb_port_pool(struct dl *dl, struct nlattr **tb) in pr_out_sb_port_pool() argument
1947 pr_out_port_handle_start_arr(dl, tb, true); in pr_out_sb_port_pool()
1948 pr_out_uint(dl, "sb", in pr_out_sb_port_pool()
1950 pr_out_uint(dl, "pool", in pr_out_sb_port_pool()
1952 pr_out_uint(dl, "threshold", in pr_out_sb_port_pool()
1954 pr_out_port_handle_end(dl); in pr_out_sb_port_pool()
1959 struct dl *dl = data; in cmd_sb_port_pool_show_cb() local
1968 pr_out_sb_port_pool(dl, tb); in cmd_sb_port_pool_show_cb()
1972 static int cmd_sb_port_pool_show(struct dl *dl) in cmd_sb_port_pool_show() argument
1978 if (dl_argc(dl) == 0) in cmd_sb_port_pool_show()
1981 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_PORT_POOL_GET, flags); in cmd_sb_port_pool_show()
1983 if (dl_argc(dl) > 0) { in cmd_sb_port_pool_show()
1984 err = dl_argv_parse_put(nlh, dl, in cmd_sb_port_pool_show()
1991 pr_out_section_start(dl, "port_pool"); in cmd_sb_port_pool_show()
1992 err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_sb_port_pool_show_cb, dl); in cmd_sb_port_pool_show()
1993 pr_out_section_end(dl); in cmd_sb_port_pool_show()
1997 static int cmd_sb_port_pool_set(struct dl *dl) in cmd_sb_port_pool_set() argument
2002 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_PORT_POOL_SET, in cmd_sb_port_pool_set()
2005 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_SB_POOL | in cmd_sb_port_pool_set()
2010 return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); in cmd_sb_port_pool_set()
2013 static int cmd_sb_port_pool(struct dl *dl) in cmd_sb_port_pool() argument
2015 if (dl_argv_match(dl, "help")) { in cmd_sb_port_pool()
2018 } else if (dl_argv_match(dl, "show") || in cmd_sb_port_pool()
2019 dl_argv_match(dl, "list") || dl_no_arg(dl)) { in cmd_sb_port_pool()
2020 dl_arg_inc(dl); in cmd_sb_port_pool()
2021 return cmd_sb_port_pool_show(dl); in cmd_sb_port_pool()
2022 } else if (dl_argv_match(dl, "set")) { in cmd_sb_port_pool()
2023 dl_arg_inc(dl); in cmd_sb_port_pool()
2024 return cmd_sb_port_pool_set(dl); in cmd_sb_port_pool()
2026 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_sb_port_pool()
2030 static int cmd_sb_port(struct dl *dl) in cmd_sb_port() argument
2032 if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { in cmd_sb_port()
2035 } else if (dl_argv_match(dl, "pool")) { in cmd_sb_port()
2036 dl_arg_inc(dl); in cmd_sb_port()
2037 return cmd_sb_port_pool(dl); in cmd_sb_port()
2039 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_sb_port()
2043 static void pr_out_sb_tc_bind(struct dl *dl, struct nlattr **tb) in pr_out_sb_tc_bind() argument
2045 pr_out_port_handle_start_arr(dl, tb, true); in pr_out_sb_tc_bind()
2046 pr_out_uint(dl, "sb", in pr_out_sb_tc_bind()
2048 pr_out_uint(dl, "tc", in pr_out_sb_tc_bind()
2050 pr_out_str(dl, "type", in pr_out_sb_tc_bind()
2052 pr_out_uint(dl, "pool", in pr_out_sb_tc_bind()
2054 pr_out_uint(dl, "threshold", in pr_out_sb_tc_bind()
2056 pr_out_port_handle_end(dl); in pr_out_sb_tc_bind()
2061 struct dl *dl = data; in cmd_sb_tc_bind_show_cb() local
2071 pr_out_sb_tc_bind(dl, tb); in cmd_sb_tc_bind_show_cb()
2075 static int cmd_sb_tc_bind_show(struct dl *dl) in cmd_sb_tc_bind_show() argument
2081 if (dl_argc(dl) == 0) in cmd_sb_tc_bind_show()
2084 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_TC_POOL_BIND_GET, flags); in cmd_sb_tc_bind_show()
2086 if (dl_argc(dl) > 0) { in cmd_sb_tc_bind_show()
2087 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_SB_TC | in cmd_sb_tc_bind_show()
2093 pr_out_section_start(dl, "tc_bind"); in cmd_sb_tc_bind_show()
2094 err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_sb_tc_bind_show_cb, dl); in cmd_sb_tc_bind_show()
2095 pr_out_section_end(dl); in cmd_sb_tc_bind_show()
2099 static int cmd_sb_tc_bind_set(struct dl *dl) in cmd_sb_tc_bind_set() argument
2104 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_TC_POOL_BIND_SET, in cmd_sb_tc_bind_set()
2107 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_SB_TC | in cmd_sb_tc_bind_set()
2113 return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); in cmd_sb_tc_bind_set()
2116 static int cmd_sb_tc_bind(struct dl *dl) in cmd_sb_tc_bind() argument
2118 if (dl_argv_match(dl, "help")) { in cmd_sb_tc_bind()
2121 } else if (dl_argv_match(dl, "show") || in cmd_sb_tc_bind()
2122 dl_argv_match(dl, "list") || dl_no_arg(dl)) { in cmd_sb_tc_bind()
2123 dl_arg_inc(dl); in cmd_sb_tc_bind()
2124 return cmd_sb_tc_bind_show(dl); in cmd_sb_tc_bind()
2125 } else if (dl_argv_match(dl, "set")) { in cmd_sb_tc_bind()
2126 dl_arg_inc(dl); in cmd_sb_tc_bind()
2127 return cmd_sb_tc_bind_set(dl); in cmd_sb_tc_bind()
2129 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_sb_tc_bind()
2133 static int cmd_sb_tc(struct dl *dl) in cmd_sb_tc() argument
2135 if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { in cmd_sb_tc()
2138 } else if (dl_argv_match(dl, "bind")) { in cmd_sb_tc()
2139 dl_arg_inc(dl); in cmd_sb_tc()
2140 return cmd_sb_tc_bind(dl); in cmd_sb_tc()
2142 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_sb_tc()
2166 struct dl *dl; member
2207 static struct occ_show *occ_show_alloc(struct dl *dl) in occ_show_alloc() argument
2214 occ_show->dl = dl; in occ_show_alloc()
2269 static void pr_out_json_occ_show_item_list(struct dl *dl, const char *label, in pr_out_json_occ_show_item_list() argument
2276 jsonw_name(dl->jw, label); in pr_out_json_occ_show_item_list()
2277 jsonw_start_object(dl->jw); in pr_out_json_occ_show_item_list()
2280 jsonw_name(dl->jw, buf); in pr_out_json_occ_show_item_list()
2281 jsonw_start_object(dl->jw); in pr_out_json_occ_show_item_list()
2283 jsonw_uint_field(dl->jw, "bound_pool", in pr_out_json_occ_show_item_list()
2285 jsonw_uint_field(dl->jw, "current", occ_item->cur); in pr_out_json_occ_show_item_list()
2286 jsonw_uint_field(dl->jw, "max", occ_item->max); in pr_out_json_occ_show_item_list()
2287 jsonw_end_object(dl->jw); in pr_out_json_occ_show_item_list()
2289 jsonw_end_object(dl->jw); in pr_out_json_occ_show_item_list()
2292 static void pr_out_occ_show_port(struct dl *dl, struct occ_port *occ_port) in pr_out_occ_show_port() argument
2294 if (dl->json_output) { in pr_out_occ_show_port()
2295 pr_out_json_occ_show_item_list(dl, "pool", in pr_out_occ_show_port()
2297 pr_out_json_occ_show_item_list(dl, "itc", in pr_out_occ_show_port()
2299 pr_out_json_occ_show_item_list(dl, "etc", in pr_out_occ_show_port()
2311 struct dl *dl = occ_show->dl; in pr_out_occ_show() local
2312 struct dl_opts *opts = &dl->opts; in pr_out_occ_show()
2316 __pr_out_port_handle_start(dl, opts->bus_name, opts->dev_name, in pr_out_occ_show()
2318 pr_out_occ_show_port(dl, occ_port); in pr_out_occ_show()
2319 pr_out_port_handle_end(dl); in pr_out_occ_show()
2329 if (occ_show->err || !dl_dump_filter(occ_show->dl, tb)) in cmd_sb_occ_port_pool_process()
2372 if (occ_show->err || !dl_dump_filter(occ_show->dl, tb)) in cmd_sb_occ_tc_pool_process()
2417 static int cmd_sb_occ_show(struct dl *dl) in cmd_sb_occ_show() argument
2424 err = dl_argv_parse(dl, DL_OPT_HANDLE | DL_OPT_HANDLEP, DL_OPT_SB); in cmd_sb_occ_show()
2428 occ_show = occ_show_alloc(dl); in cmd_sb_occ_show()
2432 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_PORT_POOL_GET, flags); in cmd_sb_occ_show()
2434 err = _mnlg_socket_sndrcv(dl->nlg, nlh, in cmd_sb_occ_show()
2439 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_TC_POOL_BIND_GET, flags); in cmd_sb_occ_show()
2441 err = _mnlg_socket_sndrcv(dl->nlg, nlh, in cmd_sb_occ_show()
2446 pr_out_section_start(dl, "occupancy"); in cmd_sb_occ_show()
2448 pr_out_section_end(dl); in cmd_sb_occ_show()
2455 static int cmd_sb_occ_snapshot(struct dl *dl) in cmd_sb_occ_snapshot() argument
2460 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_OCC_SNAPSHOT, in cmd_sb_occ_snapshot()
2463 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_SB); in cmd_sb_occ_snapshot()
2467 return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); in cmd_sb_occ_snapshot()
2470 static int cmd_sb_occ_clearmax(struct dl *dl) in cmd_sb_occ_clearmax() argument
2475 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_SB_OCC_MAX_CLEAR, in cmd_sb_occ_clearmax()
2478 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_SB); in cmd_sb_occ_clearmax()
2482 return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); in cmd_sb_occ_clearmax()
2485 static int cmd_sb_occ(struct dl *dl) in cmd_sb_occ() argument
2487 if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { in cmd_sb_occ()
2490 } else if (dl_argv_match(dl, "show") || in cmd_sb_occ()
2491 dl_argv_match(dl, "list")) { in cmd_sb_occ()
2492 dl_arg_inc(dl); in cmd_sb_occ()
2493 return cmd_sb_occ_show(dl); in cmd_sb_occ()
2494 } else if (dl_argv_match(dl, "snapshot")) { in cmd_sb_occ()
2495 dl_arg_inc(dl); in cmd_sb_occ()
2496 return cmd_sb_occ_snapshot(dl); in cmd_sb_occ()
2497 } else if (dl_argv_match(dl, "clearmax")) { in cmd_sb_occ()
2498 dl_arg_inc(dl); in cmd_sb_occ()
2499 return cmd_sb_occ_clearmax(dl); in cmd_sb_occ()
2501 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_sb_occ()
2505 static int cmd_sb(struct dl *dl) in cmd_sb() argument
2507 if (dl_argv_match(dl, "help")) { in cmd_sb()
2510 } else if (dl_argv_match(dl, "show") || in cmd_sb()
2511 dl_argv_match(dl, "list") || dl_no_arg(dl)) { in cmd_sb()
2512 dl_arg_inc(dl); in cmd_sb()
2513 return cmd_sb_show(dl); in cmd_sb()
2514 } else if (dl_argv_match(dl, "pool")) { in cmd_sb()
2515 dl_arg_inc(dl); in cmd_sb()
2516 return cmd_sb_pool(dl); in cmd_sb()
2517 } else if (dl_argv_match(dl, "port")) { in cmd_sb()
2518 dl_arg_inc(dl); in cmd_sb()
2519 return cmd_sb_port(dl); in cmd_sb()
2520 } else if (dl_argv_match(dl, "tc")) { in cmd_sb()
2521 dl_arg_inc(dl); in cmd_sb()
2522 return cmd_sb_tc(dl); in cmd_sb()
2523 } else if (dl_argv_match(dl, "occupancy")) { in cmd_sb()
2524 dl_arg_inc(dl); in cmd_sb()
2525 return cmd_sb_occ(dl); in cmd_sb()
2527 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_sb()
2570 static bool cmd_filter_check(struct dl *dl, uint8_t cmd) in cmd_filter_check() argument
2576 if (dl_no_arg(dl)) in cmd_filter_check()
2578 while ((cur_obj = dl_argv_index(dl, index++))) { in cmd_filter_check()
2587 struct dl *dl = data; in cmd_mon_show_cb() local
2592 if (!cmd_filter_check(dl, cmd)) in cmd_mon_show_cb()
2604 pr_out_dev(dl, tb); in cmd_mon_show_cb()
2615 pr_out_port(dl, tb); in cmd_mon_show_cb()
2621 static int cmd_mon_show(struct dl *dl) in cmd_mon_show() argument
2627 while ((cur_obj = dl_argv_index(dl, index++))) { in cmd_mon_show()
2635 err = _mnlg_socket_group_add(dl->nlg, DEVLINK_GENL_MCGRP_CONFIG_NAME); in cmd_mon_show()
2638 err = _mnlg_socket_recv_run(dl->nlg, cmd_mon_show_cb, dl); in cmd_mon_show()
2650 static int cmd_mon(struct dl *dl) in cmd_mon() argument
2652 if (dl_argv_match(dl, "help")) { in cmd_mon()
2655 } else if (dl_no_arg(dl)) { in cmd_mon()
2656 dl_arg_inc(dl); in cmd_mon()
2657 return cmd_mon_show(dl); in cmd_mon()
2659 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_mon()
2679 struct dl *dl; member
2736 static struct dpipe_ctx *dpipe_ctx_alloc(struct dl *dl) in dpipe_ctx_alloc() argument
2743 ctx->dl = dl; in dpipe_ctx_alloc()
2852 pr_out_entry_start(ctx->dl); in pr_out_dpipe_fields()
2853 pr_out_str(ctx->dl, "name", field->name); in pr_out_dpipe_fields()
2854 if (ctx->dl->verbose) in pr_out_dpipe_fields()
2855 pr_out_uint(ctx->dl, "id", field->id); in pr_out_dpipe_fields()
2856 pr_out_uint(ctx->dl, "bitwidth", field->bitwidth); in pr_out_dpipe_fields()
2858 pr_out_str(ctx->dl, "mapping_type", in pr_out_dpipe_fields()
2860 pr_out_entry_end(ctx->dl); in pr_out_dpipe_fields()
2868 pr_out_handle_start_arr(ctx->dl, tb); in pr_out_dpipe_header()
2869 pr_out_str(ctx->dl, "name", header->name); in pr_out_dpipe_header()
2870 if (ctx->dl->verbose) { in pr_out_dpipe_header()
2871 pr_out_uint(ctx->dl, "id", header->id); in pr_out_dpipe_header()
2872 pr_out_str(ctx->dl, "global", in pr_out_dpipe_header()
2875 pr_out_array_start(ctx->dl, "field"); in pr_out_dpipe_header()
2878 pr_out_array_end(ctx->dl); in pr_out_dpipe_header()
2879 pr_out_handle_end(ctx->dl); in pr_out_dpipe_header()
3022 static int cmd_dpipe_headers_show(struct dl *dl) in cmd_dpipe_headers_show() argument
3029 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags); in cmd_dpipe_headers_show()
3031 err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0); in cmd_dpipe_headers_show()
3035 ctx = dpipe_ctx_alloc(dl); in cmd_dpipe_headers_show()
3041 pr_out_section_start(dl, "header"); in cmd_dpipe_headers_show()
3042 err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, ctx); in cmd_dpipe_headers_show()
3045 pr_out_section_end(dl); in cmd_dpipe_headers_show()
3057 static int cmd_dpipe_header(struct dl *dl) in cmd_dpipe_header() argument
3059 if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { in cmd_dpipe_header()
3062 } else if (dl_argv_match(dl, "show")) { in cmd_dpipe_header()
3063 dl_arg_inc(dl); in cmd_dpipe_header()
3064 return cmd_dpipe_headers_show(dl); in cmd_dpipe_header()
3066 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_dpipe_header()
3098 pr_out_str(ctx->dl, "type", in pr_out_dpipe_action()
3100 pr_out_str(ctx->dl, "header", in pr_out_dpipe_action()
3103 pr_out_str(ctx->dl, "field", in pr_out_dpipe_action()
3111 pr_out_str(ctx->dl, "mapping", mapping); in pr_out_dpipe_action()
3145 pr_out_entry_start(ctx->dl); in dpipe_table_actions_show()
3149 pr_out_entry_end(ctx->dl); in dpipe_table_actions_show()
3154 pr_out_entry_end(ctx->dl); in dpipe_table_actions_show()
3180 pr_out_str(ctx->dl, "type", in pr_out_dpipe_match()
3182 pr_out_str(ctx->dl, "header", in pr_out_dpipe_match()
3185 pr_out_str(ctx->dl, "field", in pr_out_dpipe_match()
3193 pr_out_str(ctx->dl, "mapping", mapping); in pr_out_dpipe_match()
3229 pr_out_entry_start(ctx->dl); in dpipe_table_matches_show()
3233 pr_out_entry_end(ctx->dl); in dpipe_table_matches_show()
3238 pr_out_entry_end(ctx->dl); in dpipe_table_matches_show()
3266 pr_out_str(ctx->dl, "name", name); in dpipe_table_show()
3267 pr_out_uint(ctx->dl, "size", size); in dpipe_table_show()
3268 pr_out_str(ctx->dl, "counters_enabled", in dpipe_table_show()
3271 pr_out_array_start(ctx->dl, "match"); in dpipe_table_show()
3274 pr_out_array_end(ctx->dl); in dpipe_table_show()
3276 pr_out_array_start(ctx->dl, "action"); in dpipe_table_show()
3279 pr_out_array_end(ctx->dl); in dpipe_table_show()
3285 pr_out_array_end(ctx->dl); in dpipe_table_show()
3295 pr_out_handle_start_arr(ctx->dl, tb); in dpipe_tables_show()
3298 pr_out_handle_end(ctx->dl); in dpipe_tables_show()
3303 pr_out_handle_end(ctx->dl); in dpipe_tables_show()
3323 static int cmd_dpipe_table_show(struct dl *dl) in cmd_dpipe_table_show() argument
3330 ctx = dpipe_ctx_alloc(dl); in cmd_dpipe_table_show()
3334 err = dl_argv_parse(dl, DL_OPT_HANDLE, DL_OPT_DPIPE_TABLE_NAME); in cmd_dpipe_table_show()
3338 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags); in cmd_dpipe_table_show()
3339 dl_opts_put(nlh, dl); in cmd_dpipe_table_show()
3340 err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, ctx); in cmd_dpipe_table_show()
3347 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_TABLE_GET, flags); in cmd_dpipe_table_show()
3348 dl_opts_put(nlh, dl); in cmd_dpipe_table_show()
3350 pr_out_section_start(dl, "table"); in cmd_dpipe_table_show()
3351 _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_show_cb, ctx); in cmd_dpipe_table_show()
3352 pr_out_section_end(dl); in cmd_dpipe_table_show()
3359 static int cmd_dpipe_table_set(struct dl *dl) in cmd_dpipe_table_set() argument
3364 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET, in cmd_dpipe_table_set()
3367 err = dl_argv_parse_put(nlh, dl, in cmd_dpipe_table_set()
3373 return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); in cmd_dpipe_table_set()
3412 pr_out_str(ctx->dl, dpipe_value_type_e2s(type), inet_ntoa(ip_addr)); in dpipe_field_printer_ipv4_addr()
3420 pr_out_str(ctx->dl, dpipe_value_type_e2s(type), in dpipe_field_printer_ethernet_addr()
3431 pr_out_str(ctx->dl, dpipe_value_type_e2s(type), str); in dpipe_field_printer_ipv6_addr()
3521 pr_out_uint(ctx->dl, dpipe_value_type_e2s(type), *value_32); in __pr_out_entry_value()
3542 pr_out_uint(ctx->dl, "mapping_value", value_mapping); in pr_out_dpipe_entry_value()
3570 pr_out_entry_start(ctx->dl); in dpipe_entry_match_value_show()
3576 pr_out_entry_end(ctx->dl); in dpipe_entry_match_value_show()
3581 pr_out_entry_end(ctx->dl); in dpipe_entry_match_value_show()
3601 pr_out_entry_start(ctx->dl); in dpipe_entry_action_value_show()
3607 pr_out_entry_end(ctx->dl); in dpipe_entry_action_value_show()
3612 pr_out_entry_end(ctx->dl); in dpipe_entry_action_value_show()
3660 pr_out_uint(ctx->dl, "index", entry_index); in dpipe_entry_show()
3664 pr_out_uint(ctx->dl, "counter", counter); in dpipe_entry_show()
3667 pr_out_array_start(ctx->dl, "match_value"); in dpipe_entry_show()
3671 pr_out_array_end(ctx->dl); in dpipe_entry_show()
3673 pr_out_array_start(ctx->dl, "action_value"); in dpipe_entry_show()
3677 pr_out_array_end(ctx->dl); in dpipe_entry_show()
3682 pr_out_array_end(ctx->dl); in dpipe_entry_show()
3692 pr_out_handle_start_arr(ctx->dl, tb); in dpipe_table_entries_show()
3695 pr_out_handle_end(ctx->dl); in dpipe_table_entries_show()
3700 pr_out_handle_end(ctx->dl); in dpipe_table_entries_show()
3720 static int cmd_dpipe_table_dump(struct dl *dl) in cmd_dpipe_table_dump() argument
3727 ctx = dpipe_ctx_alloc(dl); in cmd_dpipe_table_dump()
3731 err = dl_argv_parse(dl, DL_OPT_HANDLE | DL_OPT_DPIPE_TABLE_NAME, 0); in cmd_dpipe_table_dump()
3735 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags); in cmd_dpipe_table_dump()
3736 dl_opts_put(nlh, dl); in cmd_dpipe_table_dump()
3737 err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, ctx); in cmd_dpipe_table_dump()
3744 nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_ENTRIES_GET, flags); in cmd_dpipe_table_dump()
3745 dl_opts_put(nlh, dl); in cmd_dpipe_table_dump()
3747 pr_out_section_start(dl, "table_entry"); in cmd_dpipe_table_dump()
3748 _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_entry_dump_cb, ctx); in cmd_dpipe_table_dump()
3749 pr_out_section_end(dl); in cmd_dpipe_table_dump()
3762 static int cmd_dpipe_table(struct dl *dl) in cmd_dpipe_table() argument
3764 if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { in cmd_dpipe_table()
3767 } else if (dl_argv_match(dl, "show")) { in cmd_dpipe_table()
3768 dl_arg_inc(dl); in cmd_dpipe_table()
3769 return cmd_dpipe_table_show(dl); in cmd_dpipe_table()
3770 } else if (dl_argv_match(dl, "set")) { in cmd_dpipe_table()
3771 dl_arg_inc(dl); in cmd_dpipe_table()
3772 return cmd_dpipe_table_set(dl); in cmd_dpipe_table()
3773 } else if (dl_argv_match(dl, "dump")) { in cmd_dpipe_table()
3774 dl_arg_inc(dl); in cmd_dpipe_table()
3775 return cmd_dpipe_table_dump(dl); in cmd_dpipe_table()
3777 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_dpipe_table()
3787 static int cmd_dpipe(struct dl *dl) in cmd_dpipe() argument
3789 if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { in cmd_dpipe()
3792 } else if (dl_argv_match(dl, "header")) { in cmd_dpipe()
3793 dl_arg_inc(dl); in cmd_dpipe()
3794 return cmd_dpipe_header(dl); in cmd_dpipe()
3795 } else if (dl_argv_match(dl, "table")) { in cmd_dpipe()
3796 dl_arg_inc(dl); in cmd_dpipe()
3797 return cmd_dpipe_table(dl); in cmd_dpipe()
3799 pr_err("Command \"%s\" not found\n", dl_argv(dl)); in cmd_dpipe()
3811 static int dl_cmd(struct dl *dl, int argc, char **argv) in dl_cmd() argument
3813 dl->argc = argc; in dl_cmd()
3814 dl->argv = argv; in dl_cmd()
3816 if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { in dl_cmd()
3819 } else if (dl_argv_match(dl, "dev")) { in dl_cmd()
3820 dl_arg_inc(dl); in dl_cmd()
3821 return cmd_dev(dl); in dl_cmd()
3822 } else if (dl_argv_match(dl, "port")) { in dl_cmd()
3823 dl_arg_inc(dl); in dl_cmd()
3824 return cmd_port(dl); in dl_cmd()
3825 } else if (dl_argv_match(dl, "sb")) { in dl_cmd()
3826 dl_arg_inc(dl); in dl_cmd()
3827 return cmd_sb(dl); in dl_cmd()
3828 } else if (dl_argv_match(dl, "monitor")) { in dl_cmd()
3829 dl_arg_inc(dl); in dl_cmd()
3830 return cmd_mon(dl); in dl_cmd()
3831 } else if (dl_argv_match(dl, "dpipe")) { in dl_cmd()
3832 dl_arg_inc(dl); in dl_cmd()
3833 return cmd_dpipe(dl); in dl_cmd()
3835 pr_err("Object \"%s\" not found\n", dl_argv(dl)); in dl_cmd()
3839 static int dl_init(struct dl *dl) in dl_init() argument
3843 dl->nlg = mnlg_socket_open(DEVLINK_GENL_NAME, DEVLINK_GENL_VERSION); in dl_init()
3844 if (!dl->nlg) { in dl_init()
3849 err = ifname_map_init(dl); in dl_init()
3854 if (dl->json_output) { in dl_init()
3855 dl->jw = jsonw_new(stdout); in dl_init()
3856 if (!dl->jw) { in dl_init()
3860 jsonw_pretty(dl->jw, dl->pretty_output); in dl_init()
3865 ifname_map_fini(dl); in dl_init()
3867 mnlg_socket_close(dl->nlg); in dl_init()
3871 static void dl_fini(struct dl *dl) in dl_fini() argument
3873 if (dl->json_output) in dl_fini()
3874 jsonw_destroy(&dl->jw); in dl_fini()
3875 ifname_map_fini(dl); in dl_fini()
3876 mnlg_socket_close(dl->nlg); in dl_fini()
3879 static struct dl *dl_alloc(void) in dl_alloc()
3881 struct dl *dl; in dl_alloc() local
3883 dl = calloc(1, sizeof(*dl)); in dl_alloc()
3884 if (!dl) in dl_alloc()
3886 return dl; in dl_alloc()
3889 static void dl_free(struct dl *dl) in dl_free() argument
3891 free(dl); in dl_free()
3894 static int dl_batch(struct dl *dl, const char *name, bool force) in dl_batch() argument
3918 if (dl_cmd(dl, largc, largv)) { in dl_batch()
3947 struct dl *dl; in main() local
3952 dl = dl_alloc(); in main()
3953 if (!dl) { in main()
3973 dl->no_nice_names = true; in main()
3976 dl->json_output = true; in main()
3979 dl->pretty_output = true; in main()
3982 dl->verbose = true; in main()
3995 err = dl_init(dl); in main()
4002 err = dl_batch(dl, batch_file, force); in main()
4004 err = dl_cmd(dl, argc, argv); in main()
4014 dl_fini(dl); in main()
4016 dl_free(dl); in main()