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