Skip to content

Commit 7c59c9c

Browse files
committed
tools: ynl: generate code for ovs families
Add ovs_flow, ovs_vport and ovs_datapath to the families supported in C. ovs-flow has some circular nesting which is fun to deal with, but the necessary support has been added already in the previous release cycle. Add a sample that proves that dealing with fixed headers does actually work correctly. Reviewed-by: Jiri Pirko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 8f109e9 commit 7c59c9c

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

tools/net/ynl/generated/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ YNL_GEN_ARG_ethtool:=--user-header linux/ethtool_netlink.h \
1414

1515
TOOL:=../ynl-gen-c.py
1616

17-
GENS:=ethtool devlink dpll handshake fou mptcp_pm netdev nfsd
17+
GENS:=ethtool devlink dpll handshake fou mptcp_pm netdev nfsd ovs_datapath ovs_vport ovs_flow
1818
SRCS=$(patsubst %,%-user.c,${GENS})
1919
HDRS=$(patsubst %,%-user.h,${GENS})
2020
OBJS=$(patsubst %,%-user.o,${GENS})

tools/net/ynl/samples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ethtool
22
devlink
33
netdev
4+
ovs
45
page-pool

tools/net/ynl/samples/ovs.c

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

0 commit comments

Comments
 (0)