Lines Matching +full:async +full:- +full:prefix

2 # SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
17 return name.upper().replace('-', '_')
21 return name.lower().replace('-', '_')
26 Turn a string limit like u32-max or s64-min into its numerical value
28 if name[0] == 'u' and name.endswith('-min'):
30 width = int(name[1:-4])
32 width -= 1
33 value = (1 << width) - 1
34 if name[0] == 's' and name.endswith('-min'):
35 value = -value - 1
41 return 'ys->family_id'
59 if 'nested-attributes' in attr:
60 self.nested_attrs = attr['nested-attributes']
84 return c_upper(f"{self.family['name']}-{value}")
90 if 'name-prefix' in self.attr:
91 enum_name = f"{self.attr['name-prefix']}{self.name}"
131 ri.cw.p(f'free({var}->{ref}{self.c_name});')
160 policy = c_upper('nla-' + self.attr['type'])
174 ri.cw.p(f"if ({var}->_present.{self.c_name})")
176 ri.cw.p(f"if ({var}->_present.{self.c_name}_len)")
180 line = f"ynl_attr_put_{put_type}(nlh, {self.enum_name}, {var}->{self.c_name})"
207 ri.cw.p(f"{var}->_present.{self.c_name} = 1;")
225 member = f"{var}->{'.'.join(ref)}"
230 presence = f"{var}->{'.'.join(ref[:i] + [''])}_present.{ref[i]}"
233 if i == len(ref) - 1 and self.presence_type() != 'bit':
301 if 'byte-order' in attr:
302 self.byte_order_comment = f" /* {attr['byte-order']} */"
322 if low < -32768 or high > 32767:
323 self.checks['full-range'] = True
334 if 'enum-as-flags' in self.attr and self.attr['enum-as-flags']:
349 if 'flags-mask' in self.checks or self.is_bitfield:
354 flags = self.family.consts[self.checks['flags-mask']]
356 mask = (1 << flag_cnt) - 1
358 elif 'full-range' in self.checks:
378 return f"{var}->{self.c_name} = ynl_attr_get_{self.type}(attr);", None, None
415 if 'exact-len' in self.checks:
416 mem = 'NLA_POLICY_EXACT_LEN(' + str(self.get_limit('exact-len')) + ')'
419 if 'max-len' in self.checks:
420 mem += ', .len = ' + str(self.get_limit('max-len'))
425 if self.checks.get('unterminated-ok', False):
437 len_mem = var + '->_present.' + self.c_name + '_len'
439 f"{var}->{self.c_name} = malloc(len + 1);",
440 f"memcpy({var}->{self.c_name}, ynl_attr_get_str(attr), len);",
441 f"{var}->{self.c_name}[len] = 0;"], \
467 if 'exact-len' in self.checks:
468 mem = 'NLA_POLICY_EXACT_LEN(' + str(self.get_limit('exact-len')) + ')'
471 if len(self.checks) == 1 and 'min-len' in self.checks:
472 mem += '.len = ' + str(self.get_limit('min-len'))
482 f"{var}->{self.c_name}, {var}->_present.{self.c_name}_len)")
485 len_mem = var + '->_present.' + self.c_name + '_len'
487 f"{var}->{self.c_name} = malloc(len);",
488 f"memcpy({var}->{self.c_name}, ynl_attr_data(attr), len);"], \
514 …line = f"ynl_attr_put(nlh, {self.enum_name}, &{var}->{self.c_name}, sizeof(struct nla_bitfield32))"
518 …return f"memcpy(&{var}->{self.c_name}, ynl_attr_data(attr), sizeof(struct nla_bitfield32));", None…
535 ri.cw.p(f'if ({var}->{ref}{self.c_name})')
536 ri.cw.p(f'{self.nested_render_name}_free({at}{var}->{ref}{self.c_name});')
547 f"{self.enum_name}, {at}{var}->{self.c_name})")
553 f"parg.data = &{var}->{self.c_name};"]
584 raise Exception(f"Sub-type {self.attr['type']} not supported yet")
591 ri.cw.p(f"free({var}->{ref}{self.c_name});")
593 ri.cw.p(f"for (i = 0; i < {var}->{ref}n_{self.c_name}; i++)")
594 ri.cw.p(f'{self.nested_render_name}_free(&{var}->{ref}{self.c_name}[i]);')
595 ri.cw.p(f"free({var}->{ref}{self.c_name});")
597 raise Exception(f"Free of MultiAttr sub-type {self.attr['type']} not supported yet")
611 ri.cw.p(f"for (unsigned int i = 0; i < {var}->n_{self.c_name}; i++)")
612 ri.cw.p(f"ynl_attr_put_{put_type}(nlh, {self.enum_name}, {var}->{self.c_name}[i]);")
614 ri.cw.p(f"for (unsigned int i = 0; i < {var}->n_{self.c_name}; i++)")
616 f"{self.enum_name}, &{var}->{self.c_name}[i])")
618 raise Exception(f"Put of MultiAttr sub-type {self.attr['type']} not supported yet")
621 # For multi-attr we have a count, not presence, hack up the presence
622 presence = presence[:-(len('_present.') + len(self.c_name))] + "n_" + self.c_name
636 if 'sub-type' not in self.attr or self.attr['sub-type'] == 'nest':
638 elif self.attr['sub-type'] in scalars:
640 return scalar_pfx + self.attr['sub-type']
642 raise Exception(f"Sub-type {self.attr['sub-type']} not supported yet")
651 f'\t{var}->n_{self.c_name}++;']
668 f"parg.data = &{var}->{self.c_name};"]
669 if 'type-value' in self.attr:
670 tv_names = [c_lower(x) for x in self.attr["type-value"]]
673 for level in self.attr["type-value"]:
698 self.render_name = c_lower(family.ident_name + '-' + space_name)
764 self.render_name = c_lower(family.ident_name + '-' + yaml['name'])
766 if 'enum-name' in yaml:
767 if yaml['enum-name']:
768 self.enum_name = 'enum ' + c_lower(yaml['enum-name'])
780 self.value_pfx = yaml.get('name-prefix', f"{family.ident_name}-{yaml['name']}-")
791 if high - low + 1 != len(self.entries):
802 if 'name-prefix' in yaml:
803 pfx = yaml['name-prefix']
805 pfx = family.ident_name + '-a-'
807 pfx = f"{family.ident_name}-a-{self.name}-"
809 self.max_name = c_upper(self.yaml.get('attr-max-name', f"{self.name_prefix}max"))
810 self.cnt_name = c_upper(self.yaml.get('attr-cnt-name', f"__{self.name_prefix}max"))
844 elif elem['type'] == 'indexed-array' and 'sub-type' in elem:
845 if elem["sub-type"] == 'nest':
848 raise Exception(f'new_attr: unsupported sub-type {elem["sub-type"]}')
849 elif elem['type'] == 'nest-type-value':
854 if 'multi-attr' in elem and elem['multi-attr']:
905 self.fam_key = c_upper(self.yaml.get('c-family-name', self.yaml["name"] + '_FAMILY_NAME'))
906 … self.ver_key = c_upper(self.yaml.get('c-version-name', self.yaml["name"] + '_FAMILY_VERSION'))
911 if 'uapi-header' in self.yaml:
912 self.uapi_header = self.yaml['uapi-header']
916 self.uapi_header_name = self.uapi_header[6:-2]
923 … if self.yaml.get('protocol', 'genetlink') not in {'genetlink', 'genetlink-c', 'genetlink-legacy'}:
927 if 'name-prefix' in self.yaml['operations']:
928 self.op_prefix = c_upper(self.yaml['operations']['name-prefix'])
930 self.op_prefix = c_upper(self.yaml['name'] + '-cmd-')
931 if 'async-prefix' in self.yaml['operations']:
932 self.async_op_prefix = c_upper(self.yaml['operations']['async-prefix'])
936 self.mcgrps = self.yaml.get('mcast-groups', {'list': []})
946 # dict space-name -> 'request': set(attrs), 'reply': set(attrs)
948 # dict space-name -> set('request', 'reply')
959 self.kernel_policy = self.yaml.get('kernel-policy', 'split')
989 if 'attribute-set' not in op:
1002 if op['attribute-set'] not in self.root_sets:
1003 self.root_sets[op['attribute-set']] = {'request': req_attrs, 'reply': rsp_attrs}
1005 self.root_sets[op['attribute-set']]['request'].update(req_attrs)
1006 self.root_sets[op['attribute-set']]['reply'].update(rsp_attrs)
1019 if 'nested-attributes' in spec:
1020 nested = spec['nested-attributes']
1042 if 'nested-attributes' not in spec:
1045 nested = spec['nested-attributes']
1055 raise Exception(f'Using attr set as root and nested not supported - {nested}')
1057 if 'type-value' in spec:
1060 inherit.update(set(spec['type-value']))
1061 elif spec['type'] == 'indexed-array':
1067 if 'nested-attributes' in spec:
1068 nested = spec['nested-attributes']
1079 if 'nested-attributes' in spec:
1080 child_name = spec['nested-attributes']
1115 if 'attribute-set' not in op:
1119 attr_set_name = op['attribute-set']
1120 if attr_set_name != op['attribute-set']:
1175 self.attr_set = op['attribute-set']
1250 if line[-1] == ':':
1251 ind -= 1
1273 self._ind -= 1
1305 if qual_ret[-1] != '*':
1317 elif qual_ret[-1] != '*':
1321 delta_ind = len(v) - len(ind)
1366 line += '\t' * ((longest - len(define[0]) + 7) // 8)
1379 line += '\t' * ((longest - len(one[0]) - 1 + 7) // 8)
1537 cw.p(f'{arg_name} = ffs({arg_name}) - 1;')
1619 iter_line = "ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len)"
1625 if aspec['type'] == 'indexed-array' and 'sub-type' in aspec:
1626 if aspec["sub-type"] == 'nest':
1630 raise Exception(f'Not supported sub-type {aspec["sub-type"]}')
1631 if 'multi-attr' in aspec:
1633 needs_parg |= 'nested-attributes' in aspec
1638 init_lines.append('parg.ys = yarg->ys;')
1653 ri.cw.p(f'dst->{arg} = {arg};')
1657 ri.cw.p(f"memcpy(&dst->_hdr, hdr, sizeof({ri.fixed_hdr}));")
1660 ri.cw.p(f"if (dst->{aspec.c_name})")
1681 ri.cw.p(f"dst->{aspec.c_name} = calloc(n_{aspec.c_name}, sizeof(*dst->{aspec.c_name}));")
1682 ri.cw.p(f"dst->n_{aspec.c_name} = n_{aspec.c_name};")
1686 ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
1697 ri.cw.p(f"dst->{aspec.c_name} = calloc(n_{aspec.c_name}, sizeof(*dst->{aspec.c_name}));")
1698 ri.cw.p(f"dst->n_{aspec.c_name} = n_{aspec.c_name};")
1700 if 'nested-attributes' in aspec:
1704 if 'nested-attributes' in aspec:
1705 ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
1709 ri.cw.p(f"dst->{aspec.c_name}[i] = ynl_attr_get_{aspec.type}(attr);")
1740 f'{struct.ptr_name}dst = yarg->data;']
1755 init_lines = ['dst = yarg->data;']
1771 ret_err = '-1'
1792 ri.cw.p(f"ys->req_policy = &{ri.struct['request'].render_name}_nest;")
1798 ri.cw.p("hdr_len = sizeof(req->_hdr);")
1800 ri.cw.p("memcpy(hdr, &req->_hdr, hdr_len);")
1821 ri.cw.p('return -1;')
1862 ri.cw.p("hdr_len = sizeof(req->_hdr);")
1864 ri.cw.p("memcpy(hdr, &req->_hdr, hdr_len);")
1868 ri.cw.p(f"ys->req_policy = &{ri.struct['request'].render_name}_nest;")
2080 ri.cw.p('next = rsp->next;')
2105 prefix = 'extern '
2108 prefix = 'static '
2110 prefix = ''
2121 cw.p(f"{prefix}const struct nla_policy {name}_nl_policy[{max_attr.enum_name} + 1]{suffix}")
2126 cw.ifdef_block(ri.op.get('config-cond', None))
2152 if 'full-range' not in attr.checks:
2179 'per-op': 'genl_ops',
2228 name = c_lower(f"{family.ident_name}-nl-{op_name}-doit")
2233 name = c_lower(f"{family.ident_name}-nl-{op_name}-dumpit")
2245 if family.kernel_policy == 'global' or family.kernel_policy == 'per-op':
2250 cw.ifdef_block(op.get('config-cond', None))
2253 if 'dont-validate' in op:
2255 ' | '.join([c_upper('genl-dont-validate-' + x)
2256 for x in op['dont-validate']])), )
2259 name = c_lower(f"{family.ident_name}-nl-{op_name}-{op_mode}it")
2261 if family.kernel_policy == 'per-op':
2262 struct = Struct(family, op['attribute-set'],
2265 name = c_lower(f"{family.ident_name}-{op_name}-nl-policy")
2269 members.append(('flags', ' | '.join([c_upper('genl-' + x) for x in op['flags']])))
2281 cw.ifdef_block(op.get('config-cond', None))
2284 if 'dont-validate' in op:
2286 for x in op['dont-validate']:
2287 if op_mode == 'do' and x in ['dump', 'dump-strict']:
2295 ' | '.join([c_upper('genl-dont-validate-' + x)
2297 name = c_lower(f"{family.ident_name}-nl-{op_name}-{op_mode}it")
2304 struct = Struct(family, op['attribute-set'],
2308 name = c_lower(f"{family.ident_name}-{op_name}-{op_mode}-nl-policy")
2310 name = c_lower(f"{family.ident_name}-{op_name}-nl-policy")
2313 flags = (op['flags'] if 'flags' in op else []) + ['cmd-cap-' + op_mode]
2314 members.append(('flags', ' | '.join([c_upper('genl-' + x) for x in flags])))
2329 grp_id = c_upper(f"{family.ident_name}-nlgrp-{grp['name']},")
2342 grp_id = c_upper(f"{family.ident_name}-nlgrp-{name}")
2354 if 'sock-priv' in family.kernel_family:
2355 cw.p(f'void {family.c_name}_nl_sock_priv_init({family.kernel_family["sock-priv"]} *priv);')
2356 … cw.p(f'void {family.c_name}_nl_sock_priv_destroy({family.kernel_family["sock-priv"]} *priv);')
2370 if family.kernel_policy == 'per-op':
2379 if 'sock-priv' in family.kernel_family:
2380 cw.p(f'.sock_priv_size\t= sizeof({family.kernel_family["sock-priv"]}),')
2387 def uapi_enum_start(family, cw, obj, ckey='', enum_name='enum-name'):
2423 doc = ' - ' + enum['doc']
2432 name_pfx = const.get('name-prefix', f"{family.ident_name}-{const['name']}-")
2439 if const.get('render-max', False):
2449 cw.p(max_name + ' = (__' + max_name + ' - 1)')
2453 defines.append([c_upper(family.get('c-define-name',
2454 f"{family.ident_name}-{const['name']}")),
2461 max_by_define = family.get('max-by-define', False)
2467 max_value = f"({attr_set.cnt_name} - 1)"
2470 uapi_enum_start(family, cw, attr_set.yaml, 'enum-name')
2488 separate_ntf = 'async-prefix' in family['operations']
2490 max_name = c_upper(family.get('cmd-max-name', f"{family.op_prefix}MAX"))
2491 cnt_name = c_upper(family.get('cmd-cnt-name', f"__{family.op_prefix}MAX"))
2492 max_value = f"({cnt_name} - 1)"
2494 uapi_enum_start(family, cw, family['operations'], 'enum-name')
2516 uapi_enum_start(family, cw, family['operations'], enum_name='async-enum')
2532 defines.append([c_upper(grp.get('c-define-name', f"{family.ident_name}-mcgrp-{name}")),
2605 return full_path, sub_path[:-1]
2610 parser.add_argument('--mode', dest='mode', type=str, required=True)
2611 parser.add_argument('--spec', dest='spec', type=str, required=True)
2612 parser.add_argument('--header', dest='header', action='store_true', default=None)
2613 parser.add_argument('--source', dest='header', action='store_false')
2614 parser.add_argument('--user-header', nargs='+', default=[])
2615 parser.add_argument('--cmp-out', action='store_true', default=None,
2617 parser.add_argument('--exclude-op', action='append', default=[])
2618 parser.add_argument('-o', dest='out_file', type=str, default=None)
2622 parser.error("--header or --source is required")
2628 if parsed.license != '((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)':
2630 print('License must be: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)')
2641 print(f'Message enum-model {parsed.msg_id_model} not supported for {args.mode} generation')
2648 cw.p(f'/* SPDX-License-Identifier: {parsed.license} */')
2650 cw.p(f'// SPDX-License-Identifier: {parsed.license}')
2651 cw.p("/* Do not edit directly, auto-generated from: */")
2653 cw.p(f"/* YNL-GEN {args.mode} {'header' if args.header else 'source'} */")
2656 line += ' --user-header '.join([''] + args.user_header)
2657 line += ' --exclude-op '.join([''] + args.exclude_op)
2658 cw.p(f'/* YNL-ARG{line} */')
2671 hdr_file=os.path.basename(args.out_file[:-2]) + ".h"
2731 if parsed.kernel_policy in {'per-op', 'split'}:
2761 if parsed.kernel_policy in {'per-op', 'split'}:
2764 cw.p(f"/* {op.enum_name} - {op_mode} */")
2792 cw.p(f"/* {op.enum_name} - do */")
2804 cw.p(f"/* {op.enum_name} - dump */")
2815 cw.p(f"/* {op.enum_name} - notify */")
2824 cw.p(f"/* {op.enum_name} - event */")
2875 cw.p(f"/* {op.enum_name} - do */")
2884 cw.p(f"/* {op.enum_name} - dump */")
2894 cw.p(f"/* {op.enum_name} - notify */")
2902 cw.p(f"/* {op.enum_name} - event */")