ovs.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ynl.h>
  5. #include "ovs_datapath-user.h"
  6. int main(int argc, char **argv)
  7. {
  8. struct ynl_sock *ys;
  9. int err;
  10. ys = ynl_sock_create(&ynl_ovs_datapath_family, NULL);
  11. if (!ys)
  12. return 1;
  13. if (argc > 1) {
  14. struct ovs_datapath_new_req *req;
  15. req = ovs_datapath_new_req_alloc();
  16. if (!req)
  17. goto err_close;
  18. ovs_datapath_new_req_set_upcall_pid(req, 1);
  19. ovs_datapath_new_req_set_name(req, argv[1]);
  20. err = ovs_datapath_new(ys, req);
  21. ovs_datapath_new_req_free(req);
  22. if (err)
  23. goto err_close;
  24. } else {
  25. struct ovs_datapath_get_req_dump *req;
  26. struct ovs_datapath_get_list *dps;
  27. printf("Dump:\n");
  28. req = ovs_datapath_get_req_dump_alloc();
  29. dps = ovs_datapath_get_dump(ys, req);
  30. ovs_datapath_get_req_dump_free(req);
  31. if (!dps)
  32. goto err_close;
  33. ynl_dump_foreach(dps, dp) {
  34. printf(" %s(%d): pid:%u cache:%u\n",
  35. dp->name, dp->_hdr.dp_ifindex,
  36. dp->upcall_pid, dp->masks_cache_size);
  37. }
  38. ovs_datapath_get_list_free(dps);
  39. }
  40. ynl_sock_destroy(ys);
  41. return 0;
  42. err_close:
  43. fprintf(stderr, "YNL (%d): %s\n", ys->err.code, ys->err.msg);
  44. ynl_sock_destroy(ys);
  45. return 2;
  46. }