Skip to content

Commit df641c5

Browse files
committed
Add a flag of type_oneside
The patch fixes an issue in the determination of type_consistent. It used to set type_consistent to be False when dump exists but do does not exist. This is inaccurate and will lead to exceptions. This case should be treated as consistent but one-sided. Signed-off-by: Zibo Gong <gongzib@outlook.com>
1 parent 722cdfc commit df641c5

File tree

8 files changed

+54
-52
lines changed

8 files changed

+54
-52
lines changed

generated/netdev-user.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,13 +1045,13 @@ netdev_napi_get_dump(ynl_cpp::ynl_socket& ys, netdev_napi_get_req_dump& req)
10451045

10461046
/* ============== NETDEV_CMD_QSTATS_GET ============== */
10471047
/* NETDEV_CMD_QSTATS_GET - dump */
1048-
int netdev_qstats_get_rsp_dump_parse(const struct nlmsghdr *nlh,
1049-
struct ynl_parse_arg *yarg)
1048+
int netdev_qstats_get_rsp_parse(const struct nlmsghdr *nlh,
1049+
struct ynl_parse_arg *yarg)
10501050
{
1051-
netdev_qstats_get_rsp_dump *dst;
1051+
netdev_qstats_get_rsp *dst;
10521052
const struct nlattr *attr;
10531053

1054-
dst = (netdev_qstats_get_rsp_dump*)yarg->data;
1054+
dst = (netdev_qstats_get_rsp*)yarg->data;
10551055

10561056
ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) {
10571057
unsigned int type = ynl_attr_type(attr);
@@ -1090,20 +1090,19 @@ int netdev_qstats_get_rsp_dump_parse(const struct nlmsghdr *nlh,
10901090
return YNL_PARSE_CB_OK;
10911091
}
10921092

1093-
std::unique_ptr<netdev_qstats_get_rsp_list>
1094-
netdev_qstats_get_dump(ynl_cpp::ynl_socket& ys,
1095-
netdev_qstats_get_req_dump& req)
1093+
std::unique_ptr<netdev_qstats_get_list>
1094+
netdev_qstats_get_dump(ynl_cpp::ynl_socket& ys, netdev_qstats_get_req& req)
10961095
{
10971096
struct ynl_dump_no_alloc_state yds = {};
10981097
struct nlmsghdr *nlh;
10991098
int err;
11001099

1101-
auto ret = std::make_unique<netdev_qstats_get_rsp_list>();
1100+
auto ret = std::make_unique<netdev_qstats_get_list>();
11021101
yds.yarg.ys = ys;
11031102
yds.yarg.rsp_policy = &netdev_qstats_nest;
11041103
yds.yarg.data = ret.get();
1105-
yds.alloc_cb = [](void* arg)->void* {return &(static_cast<netdev_qstats_get_rsp_list*>(arg)->objs.emplace_back());};
1106-
yds.cb = netdev_qstats_get_rsp_dump_parse;
1104+
yds.alloc_cb = [](void* arg)->void* {return &(static_cast<netdev_qstats_get_list*>(arg)->objs.emplace_back());};
1105+
yds.cb = netdev_qstats_get_rsp_parse;
11071106
yds.rsp_cmd = NETDEV_CMD_QSTATS_GET;
11081107

11091108
nlh = ynl_gemsg_start_dump(ys, ((struct ynl_sock*)ys)->family_id, NETDEV_CMD_QSTATS_GET, 1);

generated/netdev-user.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,12 @@ netdev_napi_get_dump(ynl_cpp::ynl_socket& ys, netdev_napi_get_req_dump& req);
228228

229229
/* ============== NETDEV_CMD_QSTATS_GET ============== */
230230
/* NETDEV_CMD_QSTATS_GET - dump */
231-
struct netdev_qstats_get_req_dump {
231+
struct netdev_qstats_get_req {
232232
std::optional<__u32> ifindex;
233233
std::optional<__u64> scope;
234234
};
235235

236-
struct netdev_qstats_get_rsp_dump {
236+
struct netdev_qstats_get_rsp {
237237
std::optional<__u32> ifindex;
238238
std::optional<enum netdev_queue_type> queue_type;
239239
std::optional<__u32> queue_id;
@@ -243,13 +243,12 @@ struct netdev_qstats_get_rsp_dump {
243243
std::optional<__u64> tx_bytes;
244244
};
245245

246-
struct netdev_qstats_get_rsp_list {
247-
std::list<netdev_qstats_get_rsp_dump> objs;
246+
struct netdev_qstats_get_list {
247+
std::list<netdev_qstats_get_rsp> objs;
248248
};
249249

250-
std::unique_ptr<netdev_qstats_get_rsp_list>
251-
netdev_qstats_get_dump(ynl_cpp::ynl_socket& ys,
252-
netdev_qstats_get_req_dump& req);
250+
std::unique_ptr<netdev_qstats_get_list>
251+
netdev_qstats_get_dump(ynl_cpp::ynl_socket& ys, netdev_qstats_get_req& req);
253252

254253
/* ============== NETDEV_CMD_BIND_RX ============== */
255254
/* NETDEV_CMD_BIND_RX - do */

generated/nfsd-user.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,15 @@ int nfsd_sock_parse(struct ynl_parse_arg *yarg, const struct nlattr *nested)
246246

247247
/* ============== NFSD_CMD_RPC_STATUS_GET ============== */
248248
/* NFSD_CMD_RPC_STATUS_GET - dump */
249-
int nfsd_rpc_status_get_rsp_dump_parse(const struct nlmsghdr *nlh,
250-
struct ynl_parse_arg *yarg)
249+
int nfsd_rpc_status_get_rsp_parse(const struct nlmsghdr *nlh,
250+
struct ynl_parse_arg *yarg)
251251
{
252-
nfsd_rpc_status_get_rsp_dump *dst;
253252
unsigned int n_compound_ops = 0;
253+
nfsd_rpc_status_get_rsp *dst;
254254
const struct nlattr *attr;
255255
int i;
256256

257-
dst = (nfsd_rpc_status_get_rsp_dump*)yarg->data;
257+
dst = (nfsd_rpc_status_get_rsp*)yarg->data;
258258

259259
if (dst->compound_ops.size() > 0)
260260
return ynl_error_parse(yarg, "attribute already present (rpc-status.compound-ops)");
@@ -333,19 +333,19 @@ int nfsd_rpc_status_get_rsp_dump_parse(const struct nlmsghdr *nlh,
333333
return YNL_PARSE_CB_OK;
334334
}
335335

336-
std::unique_ptr<nfsd_rpc_status_get_rsp_list>
336+
std::unique_ptr<nfsd_rpc_status_get_list>
337337
nfsd_rpc_status_get_dump(ynl_cpp::ynl_socket& ys)
338338
{
339339
struct ynl_dump_no_alloc_state yds = {};
340340
struct nlmsghdr *nlh;
341341
int err;
342342

343-
auto ret = std::make_unique<nfsd_rpc_status_get_rsp_list>();
343+
auto ret = std::make_unique<nfsd_rpc_status_get_list>();
344344
yds.yarg.ys = ys;
345345
yds.yarg.rsp_policy = &nfsd_rpc_status_nest;
346346
yds.yarg.data = ret.get();
347-
yds.alloc_cb = [](void* arg)->void* {return &(static_cast<nfsd_rpc_status_get_rsp_list*>(arg)->objs.emplace_back());};
348-
yds.cb = nfsd_rpc_status_get_rsp_dump_parse;
347+
yds.alloc_cb = [](void* arg)->void* {return &(static_cast<nfsd_rpc_status_get_list*>(arg)->objs.emplace_back());};
348+
yds.cb = nfsd_rpc_status_get_rsp_parse;
349349
yds.rsp_cmd = NFSD_CMD_RPC_STATUS_GET;
350350

351351
nlh = ynl_gemsg_start_dump(ys, ((struct ynl_sock*)ys)->family_id, NFSD_CMD_RPC_STATUS_GET, 1);

generated/nfsd-user.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct nfsd_sock {
4141

4242
/* ============== NFSD_CMD_RPC_STATUS_GET ============== */
4343
/* NFSD_CMD_RPC_STATUS_GET - dump */
44-
struct nfsd_rpc_status_get_rsp_dump {
44+
struct nfsd_rpc_status_get_rsp {
4545
std::optional<__u32> xid /* big-endian */;
4646
std::optional<__u32> flags;
4747
std::optional<__u32> prog;
@@ -57,11 +57,11 @@ struct nfsd_rpc_status_get_rsp_dump {
5757
std::vector<__u32> compound_ops;
5858
};
5959

60-
struct nfsd_rpc_status_get_rsp_list {
61-
std::list<nfsd_rpc_status_get_rsp_dump> objs;
60+
struct nfsd_rpc_status_get_list {
61+
std::list<nfsd_rpc_status_get_rsp> objs;
6262
};
6363

64-
std::unique_ptr<nfsd_rpc_status_get_rsp_list>
64+
std::unique_ptr<nfsd_rpc_status_get_list>
6565
nfsd_rpc_status_get_dump(ynl_cpp::ynl_socket& ys);
6666

6767
/* ============== NFSD_CMD_THREADS_SET ============== */

generated/rt-addr-user.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ int rt_addr_deladdr(ynl_cpp::ynl_socket& ys, rt_addr_deladdr_req& req)
151151

152152
/* ============== RTM_GETADDR ============== */
153153
/* RTM_GETADDR - dump */
154-
int rt_addr_getaddr_rsp_dump_parse(const struct nlmsghdr *nlh,
155-
struct ynl_parse_arg *yarg)
154+
int rt_addr_getaddr_rsp_parse(const struct nlmsghdr *nlh,
155+
struct ynl_parse_arg *yarg)
156156
{
157-
rt_addr_getaddr_rsp_dump *dst;
158157
const struct nlattr *attr;
158+
rt_addr_getaddr_rsp *dst;
159159
void *hdr;
160160

161-
dst = (rt_addr_getaddr_rsp_dump*)yarg->data;
161+
dst = (rt_addr_getaddr_rsp*)yarg->data;
162162

163163
hdr = ynl_nlmsg_data(nlh);
164164
memcpy(&dst->_hdr, hdr, sizeof(struct ifaddrmsg));
@@ -195,21 +195,21 @@ int rt_addr_getaddr_rsp_dump_parse(const struct nlmsghdr *nlh,
195195
return YNL_PARSE_CB_OK;
196196
}
197197

198-
std::unique_ptr<rt_addr_getaddr_rsp_list>
199-
rt_addr_getaddr_dump(ynl_cpp::ynl_socket& ys, rt_addr_getaddr_req_dump& req)
198+
std::unique_ptr<rt_addr_getaddr_list>
199+
rt_addr_getaddr_dump(ynl_cpp::ynl_socket& ys, rt_addr_getaddr_req& req)
200200
{
201201
struct ynl_dump_no_alloc_state yds = {};
202202
struct nlmsghdr *nlh;
203203
size_t hdr_len;
204204
void *hdr;
205205
int err;
206206

207-
auto ret = std::make_unique<rt_addr_getaddr_rsp_list>();
207+
auto ret = std::make_unique<rt_addr_getaddr_list>();
208208
yds.yarg.ys = ys;
209209
yds.yarg.rsp_policy = &rt_addr_addr_attrs_nest;
210210
yds.yarg.data = ret.get();
211-
yds.alloc_cb = [](void* arg)->void* {return &(static_cast<rt_addr_getaddr_rsp_list*>(arg)->objs.emplace_back());};
212-
yds.cb = rt_addr_getaddr_rsp_dump_parse;
211+
yds.alloc_cb = [](void* arg)->void* {return &(static_cast<rt_addr_getaddr_list*>(arg)->objs.emplace_back());};
212+
yds.cb = rt_addr_getaddr_rsp_parse;
213213
yds.rsp_cmd = 20;
214214

215215
nlh = ynl_msg_start_dump(ys, RTM_GETADDR);

generated/rt-addr-user.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ int rt_addr_deladdr(ynl_cpp::ynl_socket& ys, rt_addr_deladdr_req& req);
6565

6666
/* ============== RTM_GETADDR ============== */
6767
/* RTM_GETADDR - dump */
68-
struct rt_addr_getaddr_req_dump {
68+
struct rt_addr_getaddr_req {
6969
struct ifaddrmsg _hdr;
7070
};
7171

72-
struct rt_addr_getaddr_rsp_dump {
72+
struct rt_addr_getaddr_rsp {
7373
struct ifaddrmsg _hdr;
7474

7575
std::vector<__u8> address;
@@ -78,12 +78,12 @@ struct rt_addr_getaddr_rsp_dump {
7878
std::optional<struct ifa_cacheinfo> cacheinfo;
7979
};
8080

81-
struct rt_addr_getaddr_rsp_list {
82-
std::list<rt_addr_getaddr_rsp_dump> objs;
81+
struct rt_addr_getaddr_list {
82+
std::list<rt_addr_getaddr_rsp> objs;
8383
};
8484

85-
std::unique_ptr<rt_addr_getaddr_rsp_list>
86-
rt_addr_getaddr_dump(ynl_cpp::ynl_socket& ys, rt_addr_getaddr_req_dump& req);
85+
std::unique_ptr<rt_addr_getaddr_list>
86+
rt_addr_getaddr_dump(ynl_cpp::ynl_socket& ys, rt_addr_getaddr_req& req);
8787

8888
/* ============== RTM_GETMULTICAST ============== */
8989
/* RTM_GETMULTICAST - do */

samples/rt-addr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <ynl.hpp>
99

1010
std::ostream &operator<<(std::ostream &os,
11-
const ynl_cpp::rt_addr_getaddr_rsp_dump &rsp) {
11+
const ynl_cpp::rt_addr_getaddr_rsp &rsp) {
1212
char buf[IF_NAMESIZE];
1313
char addr_str[64];
1414

@@ -35,8 +35,8 @@ int main(int argc, char **argv) {
3535
return -1;
3636
}
3737

38-
ynl_cpp::rt_addr_getaddr_req_dump req = {};
39-
std::unique_ptr<ynl_cpp::rt_addr_getaddr_rsp_list> rsp =
38+
ynl_cpp::rt_addr_getaddr_req req = {};
39+
std::unique_ptr<ynl_cpp::rt_addr_getaddr_list> rsp =
4040
ynl_cpp::rt_addr_getaddr_dump(ys, req);
4141
if (rsp == nullptr) {
4242
std::cerr << "Error: rt-addr getaddr dump fails" << std::endl;

ynl-gen-cpp.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,14 +1237,16 @@ def __init__(self, cw, family, ku_space, op, op_mode, attr_set=None):
12371237

12381238
# 'do' and 'dump' response parsing is identical
12391239
self.type_consistent = True
1240+
self.type_oneside = False
12401241
if op_mode != "do" and "dump" in op:
12411242
if "do" in op:
12421243
if ("reply" in op["do"]) != ("reply" in op["dump"]):
12431244
self.type_consistent = False
12441245
elif "reply" in op["do"] and op["do"]["reply"] != op["dump"]["reply"]:
12451246
self.type_consistent = False
12461247
else:
1247-
self.type_consistent = False
1248+
self.type_consistent = True
1249+
self.type_oneside = True
12481250

12491251
self.attr_set = attr_set
12501252
if not self.attr_set:
@@ -1543,7 +1545,9 @@ def op_prefix(ri, direction, deref=False):
15431545
suffix += f"{direction_to_suffix[direction]}"
15441546
else:
15451547
if direction == "request":
1546-
suffix += "_req_dump"
1548+
suffix += "_req"
1549+
if not ri.type_oneside:
1550+
suffix += "_dump"
15471551
else:
15481552
if ri.type_consistent:
15491553
if deref:
@@ -2039,7 +2043,7 @@ def _print_type(ri, direction, struct):
20392043
if not direction and ri.type_name_conflict:
20402044
suffix += "_t"
20412045

2042-
if ri.op_mode == "dump":
2046+
if ri.op_mode == "dump" and not ri.type_oneside:
20432047
suffix += "_dump"
20442048

20452049
ri.cw.block_start(line=f"struct {ri.family.c_name}{suffix}")
@@ -2373,7 +2377,7 @@ def main():
23732377
cw.p(f"/* {op.enum_name} - dump */")
23742378
ri = RenderInfo(cw, parsed, args.mode, op, "dump")
23752379
print_req_type(ri)
2376-
if not ri.type_consistent:
2380+
if not ri.type_consistent or ri.type_oneside:
23772381
print_rsp_type(ri)
23782382
print_wrapped_type(ri)
23792383
print_dump_prototype(ri)
@@ -2451,7 +2455,7 @@ def main():
24512455
if "dump" in op:
24522456
cw.p(f"/* {op.enum_name} - dump */")
24532457
ri = RenderInfo(cw, parsed, args.mode, op, "dump")
2454-
if not ri.type_consistent:
2458+
if not ri.type_consistent or ri.type_oneside:
24552459
parse_rsp_msg(ri, deref=True)
24562460
print_dump(ri)
24572461
cw.nl()

0 commit comments

Comments
 (0)