Lines Matching full:ri

152     def is_recursive_for_op(self, ri):  argument
153 return self.is_recursive() and not ri.op
170 def _complex_member_type(self, ri): argument
176 def _free_lines(self, ri, var, ref): argument
181 def free(self, ri, var, ref): argument
182 lines = self._free_lines(ri, var, ref)
184 ri.cw.p(line)
186 def arg_member(self, ri): argument
187 member = self._complex_member_type(ri)
196 def struct_member(self, ri): argument
197 member = self._complex_member_type(ri)
200 if self.is_recursive_for_op(ri):
203 ri.cw.p(f"{member}{spc}{ptr}{self.c_name};")
205 members = self.arg_member(ri)
207 ri.cw.p(one + ';')
228 def _attr_put_line(self, ri, var, line): argument
231 ri.cw.p(f"if ({var}->_{presence}.{self.c_name})")
232 ri.cw.p(f"{line};")
234 def _attr_put_simple(self, ri, var, put_type): argument
236 self._attr_put_line(ri, var, line)
238 def attr_put(self, ri, var): argument
241 def _attr_get(self, ri, var): argument
244 def attr_get(self, ri, var, first): argument
245 lines, init_lines, _ = self._attr_get(ri, var)
252 ri.cw.block_start(line=f"{kw} (type == {self.enum_name})")
255 ri.cw.p("if (ynl_attr_validate(yarg, attr))")
256 ri.cw.p("return YNL_PARSE_CB_ERROR;")
258 ri.cw.p(f"{var}->_present.{self.c_name} = 1;")
261 ri.cw.nl()
263 ri.cw.p(line)
266 ri.cw.p(line)
267 ri.cw.block_end()
270 def _setter_lines(self, ri, member, presence): argument
273 def setter(self, ri, space, direction, deref=False, ref=None, var="req"): argument
294 code += self._free_lines(ri, var, ref_path)
295 code += self._setter_lines(ri, member, presence)
297 func_name = f"{op_prefix(ri, direction, deref=deref)}_set_{'_'.join(ref)}"
302 ri.cw.write_func('static inline void', func_name, local_vars=local_vars,
304 … args=[f'{type_name(ri, direction, deref=deref)} *{var}'] + self.arg_member(ri))
311 def arg_member(self, ri): argument
314 def _attr_get(self, ri, var): argument
323 def attr_put(self, ri, var): argument
326 def attr_get(self, ri, var, first): argument
329 def setter(self, ri, space, direction, deref=False, ref=None, var=None): argument
337 def arg_member(self, ri): argument
343 def attr_put(self, ri, var): argument
346 def attr_get(self, ri, var, first): argument
352 def setter(self, ri, space, direction, deref=False, ref=None, var=None): argument
442 def arg_member(self, ri): argument
445 def attr_put(self, ri, var): argument
446 self._attr_put_simple(ri, var, self.type)
448 def _attr_get(self, ri, var): argument
451 def _setter_lines(self, ri, member, presence): argument
456 def arg_member(self, ri): argument
462 def attr_put(self, ri, var): argument
463 self._attr_put_line(ri, var, f"ynl_attr_put(nlh, {self.enum_name}, NULL, 0)")
465 def _attr_get(self, ri, var): argument
468 def _setter_lines(self, ri, member, presence): argument
473 def arg_member(self, ri): argument
479 def struct_member(self, ri): argument
480 ri.cw.p(f"char *{self.c_name};")
507 def attr_put(self, ri, var): argument
508 self._attr_put_simple(ri, var, 'str')
510 def _attr_get(self, ri, var): argument
519 def _setter_lines(self, ri, member, presence): argument
527 def arg_member(self, ri): argument
533 def struct_member(self, ri): argument
534 ri.cw.p(f"void *{self.c_name};")
560 def attr_put(self, ri, var): argument
561 self._attr_put_line(ri, var, f"ynl_attr_put(nlh, {self.enum_name}, " +
564 def _attr_get(self, ri, var): argument
572 def _setter_lines(self, ri, member, presence): argument
579 def struct_member(self, ri): argument
580 ri.cw.p(f'struct {c_lower(self.get("struct"))} *{self.c_name};')
582 def _attr_get(self, ri, var): argument
596 def arg_member(self, ri): argument
602 def struct_member(self, ri): argument
603 ri.cw.p(f'__{self.get("sub-type")} *{self.c_name};')
605 def attr_put(self, ri, var): argument
607 ri.cw.block_start(line=f"if ({var}->_{presence}.{self.c_name})")
608 ri.cw.p(f"i = {var}->_{presence}.{self.c_name} * sizeof(__{self.get('sub-type')});")
609 ri.cw.p(f"ynl_attr_put(nlh, {self.enum_name}, " +
611 ri.cw.block_end()
613 def _attr_get(self, ri, var): argument
622 def _setter_lines(self, ri, member, presence): argument
630 def _complex_member_type(self, ri): argument
643 def attr_put(self, ri, var): argument
645 self._attr_put_line(ri, var, line)
647 def _attr_get(self, ri, var): argument
650 def _setter_lines(self, ri, member, presence): argument
658 def _complex_member_type(self, ri): argument
661 def _free_lines(self, ri, var, ref): argument
664 if self.is_recursive_for_op(ri):
676 def attr_put(self, ri, var): argument
677 at = '' if self.is_recursive_for_op(ri) else '&'
678 self._attr_put_line(ri, var, f"{self.nested_render_name}_put(nlh, " +
681 def _attr_get(self, ri, var): argument
692 def setter(self, ri, space, direction, deref=False, ref=None, var="req"): argument
695 for _, attr in ri.family.pure_nested_structs[self.nested_attrs].member_list():
698 attr.setter(ri, self.nested_attrs, direction, deref=deref, ref=ref,
714 def _complex_member_type(self, ri): argument
722 scalar_pfx = '__' if ri.ku_space == 'user' else ''
731 def arg_member(self, ri): argument
735 return super().arg_member(ri)
740 def _free_lines(self, ri, var, ref): argument
768 def _attr_get(self, ri, var): argument
771 def attr_put(self, ri, var): argument
774 ri.cw.p(f"for (i = 0; i < {var}->_count.{self.c_name}; i++)")
775 ri.cw.p(f"ynl_attr_put_{put_type}(nlh, {self.enum_name}, {var}->{self.c_name}[i]);")
777 ri.cw.p(f"for (i = 0; i < {var}->_count.{self.c_name}; i++)")
778ri.cw.p(f"ynl_attr_put(nlh, {self.enum_name}, &{var}->{self.c_name}[i], sizeof(struct {c_lower(sel…
780 ri.cw.p(f"for (i = 0; i < {var}->_count.{self.c_name}; i++)")
781 ri.cw.p(f"ynl_attr_put_str(nlh, {self.enum_name}, {var}->{self.c_name}[i]->str);")
783 ri.cw.p(f"for (i = 0; i < {var}->_count.{self.c_name}; i++)")
784 self._attr_put_line(ri, var, f"{self.nested_render_name}_put(nlh, " +
789 def _setter_lines(self, ri, member, presence): argument
801 def _complex_member_type(self, ri): argument
805 scalar_pfx = '__' if ri.ku_space == 'user' else ''
812 def arg_member(self, ri): argument
816 return super().arg_member(ri)
833 def _attr_get(self, ri, var): argument
843 def attr_put(self, ri, var): argument
844 ri.cw.p(f'array = ynl_attr_nest_start(nlh, {self.enum_name});')
847 ri.cw.block_start(line=f'for (i = 0; i < {var}->_count.{self.c_name}; i++)')
848 ri.cw.p(f"ynl_attr_put_{put_type}(nlh, i, {var}->{self.c_name}[i]);")
849 ri.cw.block_end()
851 ri.cw.p(f'for (i = 0; i < {var}->_count.{self.c_name}; i++)')
852 ri.cw.p(f"ynl_attr_put(nlh, i, {var}->{self.c_name}[i], {self.checks['exact-len']});")
854 ri.cw.p(f'for (i = 0; i < {var}->_count.{self.c_name}; i++)')
855 ri.cw.p(f"{self.nested_render_name}_put(nlh, i, &{var}->{self.c_name}[i]);")
858 ri.cw.p('ynl_attr_nest_end(nlh, array);')
860 def _setter_lines(self, ri, member, presence): argument
866 def _complex_member_type(self, ri): argument
872 def _attr_get(self, ri, var): argument
911 def _attr_get(self, ri, var): argument
1885 def op_prefix(ri, direction, deref=False): argument
1886 suffix = f"_{ri.type_name}"
1888 if not ri.op_mode:
1890 elif ri.op_mode == 'do':
1895 if not ri.type_oneside:
1898 if ri.type_consistent:
1902 suffix += op_mode_to_wrapper[ri.op_mode]
1907 return f"{ri.family.c_name}{suffix}"
1910 def type_name(ri, direction, deref=False): argument
1911 return f"struct {op_prefix(ri, direction, deref=deref)}"
1914 def print_prototype(ri, direction, terminate=True, doc=None): argument
1917 fname = ri.op.render_name
1918 if ri.op_mode == 'dump':
1922 if 'request' in ri.op[ri.op_mode]:
1923 args.append(f"{type_name(ri, direction)} *" + f"{direction_to_suffix[direction][1:]}")
1926 if 'reply' in ri.op[ri.op_mode]:
1927 ret = f"{type_name(ri, rdir(direction))} *"
1929 ri.cw.write_func_prot(ret, fname, args, doc=doc, suffix=suffix)
1932 def print_req_prototype(ri): argument
1933 print_prototype(ri, "request", doc=ri.op['doc'])
1936 def print_dump_prototype(ri): argument
1937 print_prototype(ri, "request")
2057 def put_req_nested_prototype(ri, struct, suffix=';'): argument
2062 ri.cw.write_func_prot('int', f'{struct.render_name}_put', func_args,
2066 def put_req_nested(ri, struct): argument
2081 put_req_nested_prototype(ri, struct, suffix='')
2082 ri.cw.block_start()
2083 ri.cw.write_func_lvar(local_vars)
2086 ri.cw.p(line)
2089 arg.attr_put(ri, "obj")
2092 ri.cw.p("ynl_attr_nest_end(nlh, nest);")
2094 ri.cw.nl()
2095 ri.cw.p('return 0;')
2096 ri.cw.block_end()
2097 ri.cw.nl()
2100 def _multi_parse(ri, struct, init_lines, local_vars): argument
2110 if ri.op.fixed_header != ri.family.fixed_header:
2111 if ri.family.is_classic():
2136 _, _, l_vars = aspec._attr_get(ri, '')
2152 ri.cw.block_start()
2153 ri.cw.write_func_lvar(local_vars)
2156 ri.cw.p(line)
2157 ri.cw.nl()
2160 ri.cw.p(f'dst->{arg} = {arg};')
2164 ri.cw.p('hdr = ynl_attr_data(nested);')
2165 elif ri.family.is_classic():
2166 ri.cw.p('hdr = ynl_nlmsg_data(nlh);')
2168 ri.cw.p('hdr = ynl_nlmsg_data_offset(nlh, sizeof(struct genlmsghdr));')
2169 ri.cw.p(f"memcpy(&dst->_hdr, hdr, sizeof({struct.fixed_header}));")
2172 ri.cw.p(f"if (dst->{aspec.c_name})")
2173ri.cw.p(f'return ynl_error_parse(yarg, "attribute already present ({struct.attr_set.name}.{aspec.n…
2175 ri.cw.nl()
2176 ri.cw.block_start(line=iter_line)
2177 ri.cw.p('unsigned int type = ynl_attr_type(attr);')
2178 ri.cw.nl()
2182 good = arg.attr_get(ri, 'dst', first=first)
2186 ri.cw.block_end()
2187 ri.cw.nl()
2192 ri.cw.block_start(line=f"if (n_{aspec.c_name})")
2193 ri.cw.p(f"dst->{aspec.c_name} = calloc(n_{aspec.c_name}, sizeof(*dst->{aspec.c_name}));")
2194 ri.cw.p(f"dst->_count.{aspec.c_name} = n_{aspec.c_name};")
2195 ri.cw.p('i = 0;')
2197 ri.cw.p(f"parg.rsp_policy = &{aspec.nested_render_name}_nest;")
2198 ri.cw.block_start(line=f"ynl_attr_for_each_nested(attr, attr_{aspec.c_name})")
2200 ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
2201 ri.cw.p(f"if ({aspec.nested_render_name}_parse(&parg, attr, ynl_attr_type(attr)))")
2202 ri.cw.p('return YNL_PARSE_CB_ERROR;')
2204 ri.cw.p(f"dst->{aspec.c_name}[i] = ynl_attr_get_{aspec.sub_type}(attr);")
2207ri.cw.p(f'memcpy(dst->{aspec.c_name}[i], ynl_attr_data(attr), {aspec.checks["exact-len"]});')
2210 ri.cw.p('i++;')
2211 ri.cw.block_end()
2212 ri.cw.block_end()
2213 ri.cw.nl()
2217 ri.cw.block_start(line=f"if (n_{aspec.c_name})")
2218 ri.cw.p(f"dst->{aspec.c_name} = calloc(n_{aspec.c_name}, sizeof(*dst->{aspec.c_name}));")
2219 ri.cw.p(f"dst->_count.{aspec.c_name} = n_{aspec.c_name};")
2220 ri.cw.p('i = 0;')
2222 ri.cw.p(f"parg.rsp_policy = &{aspec.nested_render_name}_nest;")
2223 ri.cw.block_start(line=iter_line)
2224 ri.cw.block_start(line=f"if (ynl_attr_type(attr) == {aspec.enum_name})")
2226 ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
2227 ri.cw.p(f"if ({aspec.nested_render_name}_parse(&parg, attr))")
2228 ri.cw.p('return YNL_PARSE_CB_ERROR;')
2230 ri.cw.p(f"dst->{aspec.c_name}[i] = ynl_attr_get_{aspec.type}(attr);")
2232 ri.cw.p('size_t len = ynl_attr_data_len(attr);')
2233 ri.cw.nl()
2234 ri.cw.p(f'if (len > sizeof(dst->{aspec.c_name}[0]))')
2235 ri.cw.p(f'len = sizeof(dst->{aspec.c_name}[0]);')
2236 ri.cw.p(f"memcpy(&dst->{aspec.c_name}[i], ynl_attr_data(attr), len);")
2238 ri.cw.p('unsigned int len;')
2239 ri.cw.nl()
2240 ri.cw.p('len = strnlen(ynl_attr_get_str(attr), ynl_attr_data_len(attr));')
2241 ri.cw.p(f'dst->{aspec.c_name}[i] = malloc(sizeof(struct ynl_string) + len + 1);')
2242 ri.cw.p(f"dst->{aspec.c_name}[i]->len = len;")
2243 ri.cw.p(f"memcpy(dst->{aspec.c_name}[i]->str, ynl_attr_get_str(attr), len);")
2244 ri.cw.p(f"dst->{aspec.c_name}[i]->str[len] = 0;")
2247 ri.cw.p('i++;')
2248 ri.cw.block_end()
2249 ri.cw.block_end()
2250 ri.cw.block_end()
2251 ri.cw.nl()
2254 ri.cw.p('return 0;')
2256 ri.cw.p('return YNL_PARSE_CB_OK;')
2257 ri.cw.block_end()
2258 ri.cw.nl()
2261 def parse_rsp_submsg(ri, struct): argument
2262 parse_rsp_nested_prototype(ri, struct, suffix='')
2270 _, _, l_vars = arg._attr_get(ri, var)
2273 ri.cw.block_start()
2274 ri.cw.write_func_lvar(list(local_vars))
2275 ri.cw.p('parg.ys = yarg->ys;')
2276 ri.cw.nl()
2283 ri.cw.block_start(line=f'{kw} (!strcmp(sel, "{name}"))')
2284 get_lines, init_lines, _ = arg._attr_get(ri, var)
2286 ri.cw.p(line)
2288 ri.cw.p(line)
2290 ri.cw.p(f"{var}->_present.{arg.c_name} = 1;")
2291 ri.cw.block_end()
2292 ri.cw.p('return 0;')
2293 ri.cw.block_end()
2294 ri.cw.nl()
2297 def parse_rsp_nested_prototype(ri, struct, suffix=';'): argument
2307 ri.cw.write_func_prot('int', f'{struct.render_name}_parse', func_args,
2311 def parse_rsp_nested(ri, struct): argument
2313 return parse_rsp_submsg(ri, struct)
2315 parse_rsp_nested_prototype(ri, struct, suffix='')
2322 _multi_parse(ri, struct, init_lines, local_vars)
2325 ri.cw.block_start()
2326 ri.cw.p('return 0;')
2327 ri.cw.block_end()
2328 ri.cw.nl()
2331 def parse_rsp_msg(ri, deref=False): argument
2332 if 'reply' not in ri.op[ri.op_mode] and ri.op_mode != 'event':
2338 local_vars = [f'{type_name(ri, "reply", deref=deref)} *dst;',
2342 ri.cw.write_func_prot('int', f'{op_prefix(ri, "reply", deref=deref)}_parse', func_args)
2344 if ri.struct["reply"].member_list():
2345 _multi_parse(ri, ri.struct["reply"], init_lines, local_vars)
2348 ri.cw.block_start()
2349 ri.cw.p('return YNL_PARSE_CB_OK;')
2350 ri.cw.block_end()
2351 ri.cw.nl()
2354 def print_req(ri): argument
2362 if 'reply' in ri.op[ri.op_mode]:
2365 local_vars += [f'{type_name(ri, rdir(direction))} *rsp;']
2367 if ri.struct["request"].fixed_header:
2371 local_vars += put_local_vars(ri.struct['request'])
2373 print_prototype(ri, direction, terminate=False)
2374 ri.cw.block_start()
2375 ri.cw.write_func_lvar(local_vars)
2377 if ri.family.is_classic():
2378 ri.cw.p(f"nlh = ynl_msg_start_req(ys, {ri.op.enum_name}, req->_nlmsg_flags);")
2380 ri.cw.p(f"nlh = ynl_gemsg_start_req(ys, {ri.nl.get_family_id()}, {ri.op.enum_name}, 1);")
2382 ri.cw.p(f"ys->req_policy = &{ri.struct['request'].render_name}_nest;")
2383 ri.cw.p(f"ys->req_hdr_len = {ri.fixed_hdr_len};")
2384 if 'reply' in ri.op[ri.op_mode]:
2385 ri.cw.p(f"yrs.yarg.rsp_policy = &{ri.struct['reply'].render_name}_nest;")
2386 ri.cw.nl()
2388 if ri.struct['request'].fixed_header:
2389 ri.cw.p("hdr_len = sizeof(req->_hdr);")
2390 ri.cw.p("hdr = ynl_nlmsg_put_extra_header(nlh, hdr_len);")
2391 ri.cw.p("memcpy(hdr, &req->_hdr, hdr_len);")
2392 ri.cw.nl()
2394 for _, attr in ri.struct["request"].member_list():
2395 attr.attr_put(ri, "req")
2396 ri.cw.nl()
2398 if 'reply' in ri.op[ri.op_mode]:
2399 ri.cw.p('rsp = calloc(1, sizeof(*rsp));')
2400 ri.cw.p('yrs.yarg.data = rsp;')
2401 ri.cw.p(f"yrs.cb = {op_prefix(ri, 'reply')}_parse;")
2402 if ri.op.value is not None:
2403 ri.cw.p(f'yrs.rsp_cmd = {ri.op.enum_name};')
2405 ri.cw.p(f'yrs.rsp_cmd = {ri.op.rsp_value};')
2406 ri.cw.nl()
2407 ri.cw.p("err = ynl_exec(ys, nlh, &yrs);")
2408 ri.cw.p('if (err < 0)')
2409 if 'reply' in ri.op[ri.op_mode]:
2410 ri.cw.p('goto err_free;')
2412 ri.cw.p('return -1;')
2413 ri.cw.nl()
2415 ri.cw.p(f"return {ret_ok};")
2416 ri.cw.nl()
2418 if 'reply' in ri.op[ri.op_mode]:
2419 ri.cw.p('err_free:')
2420 ri.cw.p(f"{call_free(ri, rdir(direction), 'rsp')}")
2421 ri.cw.p(f"return {ret_err};")
2423 ri.cw.block_end()
2426 def print_dump(ri): argument
2428 print_prototype(ri, direction, terminate=False)
2429 ri.cw.block_start()
2434 if ri.struct['request'].fixed_header:
2438 if 'request' in ri.op[ri.op_mode]:
2439 local_vars += put_local_vars(ri.struct['request'])
2441 ri.cw.write_func_lvar(local_vars)
2443 ri.cw.p('yds.yarg.ys = ys;')
2444 ri.cw.p(f"yds.yarg.rsp_policy = &{ri.struct['reply'].render_name}_nest;")
2445 ri.cw.p("yds.yarg.data = NULL;")
2446 ri.cw.p(f"yds.alloc_sz = sizeof({type_name(ri, rdir(direction))});")
2447 ri.cw.p(f"yds.cb = {op_prefix(ri, 'reply', deref=True)}_parse;")
2448 if ri.op.value is not None:
2449 ri.cw.p(f'yds.rsp_cmd = {ri.op.enum_name};')
2451 ri.cw.p(f'yds.rsp_cmd = {ri.op.rsp_value};')
2452 ri.cw.nl()
2453 if ri.family.is_classic():
2454 ri.cw.p(f"nlh = ynl_msg_start_dump(ys, {ri.op.enum_name});")
2456 ri.cw.p(f"nlh = ynl_gemsg_start_dump(ys, {ri.nl.get_family_id()}, {ri.op.enum_name}, 1);")
2458 if ri.struct['request'].fixed_header:
2459 ri.cw.p("hdr_len = sizeof(req->_hdr);")
2460 ri.cw.p("hdr = ynl_nlmsg_put_extra_header(nlh, hdr_len);")
2461 ri.cw.p("memcpy(hdr, &req->_hdr, hdr_len);")
2462 ri.cw.nl()
2464 if "request" in ri.op[ri.op_mode]:
2465 ri.cw.p(f"ys->req_policy = &{ri.struct['request'].render_name}_nest;")
2466 ri.cw.p(f"ys->req_hdr_len = {ri.fixed_hdr_len};")
2467 ri.cw.nl()
2468 for _, attr in ri.struct["request"].member_list():
2469 attr.attr_put(ri, "req")
2470 ri.cw.nl()
2472 ri.cw.p('err = ynl_exec_dump(ys, nlh, &yds);')
2473 ri.cw.p('if (err < 0)')
2474 ri.cw.p('goto free_list;')
2475 ri.cw.nl()
2477 ri.cw.p('return yds.first;')
2478 ri.cw.nl()
2479 ri.cw.p('free_list:')
2480 ri.cw.p(call_free(ri, rdir(direction), 'yds.first'))
2481 ri.cw.p('return NULL;')
2482 ri.cw.block_end()
2485 def call_free(ri, direction, var): argument
2486 return f"{op_prefix(ri, direction)}_free({var});"
2495 def print_alloc_wrapper(ri, direction, struct=None): argument
2496 name = op_prefix(ri, direction)
2498 if ri.type_name_conflict:
2507 ri.cw.write_func_prot(f'static inline struct {struct_name} *',
2509 ri.cw.block_start()
2510 ri.cw.p(f'return calloc({cnt}, sizeof(struct {struct_name}));')
2511 ri.cw.block_end()
2514 def print_free_prototype(ri, direction, suffix=';'): argument
2515 name = op_prefix(ri, direction)
2517 if ri.type_name_conflict:
2520 ri.cw.write_func_prot('void', f"{name}_free", [f"struct {struct_name} *{arg}"], suffix=suffix)
2523 def print_nlflags_set(ri, direction): argument
2524 name = op_prefix(ri, direction)
2525 ri.cw.write_func_prot('static inline void', f"{name}_set_nlflags",
2527 ri.cw.block_start()
2528 ri.cw.p('req->_nlmsg_flags = nl_flags;')
2529 ri.cw.block_end()
2530 ri.cw.nl()
2533 def _print_type(ri, direction, struct): argument
2534 suffix = f'_{ri.type_name}{direction_to_suffix[direction]}'
2535 if not direction and ri.type_name_conflict:
2538 if ri.op_mode == 'dump' and not ri.type_oneside:
2541 ri.cw.block_start(line=f"struct {ri.family.c_name}{suffix}")
2543 if ri.needs_nlflags(direction):
2544 ri.cw.p('__u16 _nlmsg_flags;')
2545 ri.cw.nl()
2547 ri.cw.p(struct.fixed_header + ' _hdr;')
2548 ri.cw.nl()
2553 line = attr.presence_member(ri.ku_space, type_filter)
2556 ri.cw.block_start(line="struct")
2558 ri.cw.p(line)
2560 ri.cw.block_end(line=f'_{type_filter};')
2561 ri.cw.nl()
2564 ri.cw.p(f"__u32 {arg};")
2567 attr.struct_member(ri)
2569 ri.cw.block_end(line=';')
2570 ri.cw.nl()
2573 def print_type(ri, direction): argument
2574 _print_type(ri, direction, ri.struct[direction])
2577 def print_type_full(ri, struct): argument
2578 _print_type(ri, "", struct)
2581 print_alloc_wrapper(ri, "", struct)
2582 ri.cw.nl()
2583 free_rsp_nested_prototype(ri)
2584 ri.cw.nl()
2588 if ri.ku_space == 'user' and not ri.type_name_conflict:
2590 attr.setter(ri, ri.attr_set, "", var="obj")
2591 ri.cw.nl()
2594 def print_type_helpers(ri, direction, deref=False): argument
2595 print_free_prototype(ri, direction)
2596 ri.cw.nl()
2598 if ri.needs_nlflags(direction):
2599 print_nlflags_set(ri, direction)
2601 if ri.ku_space == 'user' and direction == 'request':
2602 for _, attr in ri.struct[direction].member_list():
2603 attr.setter(ri, ri.attr_set, direction, deref=deref)
2604 ri.cw.nl()
2607 def print_req_type_helpers(ri): argument
2608 if ri.type_empty("request"):
2610 print_alloc_wrapper(ri, "request")
2611 print_type_helpers(ri, "request")
2614 def print_rsp_type_helpers(ri): argument
2615 if 'reply' not in ri.op[ri.op_mode]:
2617 print_type_helpers(ri, "reply")
2620 def print_parse_prototype(ri, direction, terminate=True): argument
2624 ri.cw.write_func_prot('void', f"{ri.op.render_name}{suffix}_parse",
2626 f"struct {ri.op.render_name}{suffix} *req"],
2630 def print_req_type(ri): argument
2631 if ri.type_empty("request"):
2633 print_type(ri, "request")
2636 def print_req_free(ri): argument
2637 if 'request' not in ri.op[ri.op_mode]:
2639 _free_type(ri, 'request', ri.struct['request'])
2642 def print_rsp_type(ri): argument
2643 if (ri.op_mode == 'do' or ri.op_mode == 'dump') and 'reply' in ri.op[ri.op_mode]:
2645 elif ri.op_mode == 'event':
2649 print_type(ri, direction)
2652 def print_wrapped_type(ri): argument
2653 ri.cw.block_start(line=f"{type_name(ri, 'reply')}")
2654 if ri.op_mode == 'dump':
2655 ri.cw.p(f"{type_name(ri, 'reply')} *next;")
2656 elif ri.op_mode == 'notify' or ri.op_mode == 'event':
2657 ri.cw.p('__u16 family;')
2658 ri.cw.p('__u8 cmd;')
2659 ri.cw.p('struct ynl_ntf_base_type *next;')
2660 ri.cw.p(f"void (*free)({type_name(ri, 'reply')} *ntf);")
2661 ri.cw.p(f"{type_name(ri, 'reply', deref=True)} obj __attribute__((aligned(8)));")
2662 ri.cw.block_end(line=';')
2663 ri.cw.nl()
2664 print_free_prototype(ri, 'reply')
2665 ri.cw.nl()
2668 def _free_type_members_iter(ri, struct): argument
2670 ri.cw.p('unsigned int i;')
2671 ri.cw.nl()
2674 def _free_type_members(ri, var, struct, ref=''): argument
2676 attr.free(ri, var, ref)
2679 def _free_type(ri, direction, struct): argument
2682 print_free_prototype(ri, direction, suffix='')
2683 ri.cw.block_start()
2684 _free_type_members_iter(ri, struct)
2685 _free_type_members(ri, var, struct)
2687 ri.cw.p(f'free({var});')
2688 ri.cw.block_end()
2689 ri.cw.nl()
2692 def free_rsp_nested_prototype(ri): argument
2693 print_free_prototype(ri, "")
2696 def free_rsp_nested(ri, struct): argument
2697 _free_type(ri, "", struct)
2700 def print_rsp_free(ri): argument
2701 if 'reply' not in ri.op[ri.op_mode]:
2703 _free_type(ri, 'reply', ri.struct['reply'])
2706 def print_dump_type_free(ri): argument
2707 sub_type = type_name(ri, 'reply')
2709 print_free_prototype(ri, 'reply', suffix='')
2710 ri.cw.block_start()
2711 ri.cw.p(f"{sub_type} *next = rsp;")
2712 ri.cw.nl()
2713 ri.cw.block_start(line='while ((void *)next != YNL_LIST_END)')
2714 _free_type_members_iter(ri, ri.struct['reply'])
2715 ri.cw.p('rsp = next;')
2716 ri.cw.p('next = rsp->next;')
2717 ri.cw.nl()
2719 _free_type_members(ri, 'rsp', ri.struct['reply'], ref='obj.')
2720 ri.cw.p('free(rsp);')
2721 ri.cw.block_end()
2722 ri.cw.block_end()
2723 ri.cw.nl()
2726 def print_ntf_type_free(ri): argument
2727 print_free_prototype(ri, 'reply', suffix='')
2728 ri.cw.block_start()
2729 _free_type_members_iter(ri, ri.struct['reply'])
2730 _free_type_members(ri, 'rsp', ri.struct['reply'], ref='obj.')
2731 ri.cw.p('free(rsp);')
2732 ri.cw.block_end()
2733 ri.cw.nl()
2736 def print_req_policy_fwd(cw, struct, ri=None, terminate=True): argument
2737 if terminate and ri and policy_should_be_static(struct.family):
2743 if ri and policy_should_be_static(struct.family):
2751 if ri:
2752 name = ri.op.render_name
2753 if ri.op.dual_policy:
2754 name += '_' + ri.op_mode
2760 def print_req_policy(cw, struct, ri=None): argument
2761 if ri and ri.op:
2762 cw.ifdef_block(ri.op.get('config-cond', None))
2763 print_req_policy_fwd(cw, struct, ri=ri, terminate=False)
3305 def _render_user_ntf_entry(ri, op): argument
3306 if not ri.family.is_classic():
3307 ri.cw.block_start(line=f"[{op.enum_name}] = ")
3309 crud_op = ri.family.req_by_value[op.rsp_value]
3310 ri.cw.block_start(line=f"[{crud_op.enum_name}] = ")
3311 ri.cw.p(f".alloc_sz\t= sizeof({type_name(ri, 'event')}),")
3312 ri.cw.p(f".cb\t\t= {op_prefix(ri, 'reply', deref=True)}_parse,")
3313 ri.cw.p(f".policy\t\t= &{ri.struct['reply'].render_name}_nest,")
3314 ri.cw.p(f".free\t\t= (void *){op_prefix(ri, 'notify')}_free,")
3315 ri.cw.block_end(line=',')
3329 ri = RenderInfo(cw, family, "user", op, "notify")
3331 ri = RenderInfo(cw, family, "user", ntf_op, "event")
3334 _render_user_ntf_entry(ri, ntf_op)
3338 ri = RenderInfo(cw, family, "user", op, "event")
3339 _render_user_ntf_entry(ri, op)
3509 ri = RenderInfo(cw, parsed, args.mode, op, "do")
3510 print_req_policy_fwd(cw, ri.struct['request'], ri=ri)
3541 ri = RenderInfo(cw, parsed, args.mode, op, op_mode)
3542 print_req_policy(cw, ri.struct['request'], ri=ri)
3561 ri = RenderInfo(cw, parsed, args.mode, "", "", attr_set)
3562 print_type_full(ri, struct)
3569 ri = RenderInfo(cw, parsed, args.mode, op, "do")
3570 print_req_type(ri)
3571 print_req_type_helpers(ri)
3573 print_rsp_type(ri)
3574 print_rsp_type_helpers(ri)
3576 print_req_prototype(ri)
3581 ri = RenderInfo(cw, parsed, args.mode, op, 'dump')
3582 print_req_type(ri)
3583 print_req_type_helpers(ri)
3584 if not ri.type_consistent or ri.type_oneside:
3585 print_rsp_type(ri)
3586 print_wrapped_type(ri)
3587 print_dump_prototype(ri)
3592 ri = RenderInfo(cw, parsed, args.mode, op, 'notify')
3593 if not ri.type_consistent:
3595 print_wrapped_type(ri)
3599 ri = RenderInfo(cw, parsed, args.mode, op, 'event')
3601 print_rsp_type(ri)
3603 print_wrapped_type(ri)
3631 ri = RenderInfo(cw, parsed, args.mode, "", "", attr_set)
3632 free_rsp_nested_prototype(ri)
3634 put_req_nested_prototype(ri, struct)
3636 parse_rsp_nested_prototype(ri, struct)
3639 ri = RenderInfo(cw, parsed, args.mode, "", "", attr_set)
3641 free_rsp_nested(ri, struct)
3643 put_req_nested(ri, struct)
3645 parse_rsp_nested(ri, struct)
3651 ri = RenderInfo(cw, parsed, args.mode, op, "do")
3652 print_req_free(ri)
3653 print_rsp_free(ri)
3654 parse_rsp_msg(ri)
3655 print_req(ri)
3660 ri = RenderInfo(cw, parsed, args.mode, op, "dump")
3661 if not ri.type_consistent or ri.type_oneside:
3662 parse_rsp_msg(ri, deref=True)
3663 print_req_free(ri)
3664 print_dump_type_free(ri)
3665 print_dump(ri)
3670 ri = RenderInfo(cw, parsed, args.mode, op, 'notify')
3671 if not ri.type_consistent:
3673 print_ntf_type_free(ri)
3679 ri = RenderInfo(cw, parsed, args.mode, op, "do")
3680 parse_rsp_msg(ri)
3682 ri = RenderInfo(cw, parsed, args.mode, op, "event")
3683 print_ntf_type_free(ri)