Lines Matching +full:exact +full:- +full:len

2 # SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
20 return name.upper().replace('-', '_')
24 return name.lower().replace('-', '_')
29 Turn a string limit like u32-max or s64-min into its numerical value
31 if name[0] == 'u' and name.endswith('-min'):
33 width = int(name[1:-4])
35 width -= 1
36 value = (1 << width) - 1
37 if name[0] == 's' and name.endswith('-min'):
38 value = -value - 1
44 return 'ys->family_id'
61 if 'len' in attr:
62 self.len = attr['len']
64 if 'nested-attributes' in attr:
65 nested = attr['nested-attributes']
66 elif 'sub-message' in attr:
67 nested = attr['sub-message']
127 return c_upper(f"{self.family['name']}-{value}")
131 if 'parent-sub-message' in self.attr:
132 enum_name = self.attr['parent-sub-message'].enum_name
133 elif 'name-prefix' in self.attr:
134 enum_name = f"{self.attr['name-prefix']}{self.name}"
166 if self.presence_type() in {'len', 'count'}:
177 if self.is_multi_val() or self.presence_type() in {'count', 'len'}:
178 return [f'free({var}->{ref}{self.c_name});']
189 spc = ' ' if member[-1] != '*' else ''
202 spc = ' ' if member[-1] != '*' else ''
214 if self.attr.get('byte-order') == 'big-endian':
230 if presence in {'present', 'len'}:
231 ri.cw.p(f"if ({var}->_{presence}.{self.c_name})")
235 line = f"ynl_attr_put_{put_type}(nlh, {self.enum_name}, {var}->{self.c_name})"
258 ri.cw.p(f"{var}->_present.{self.c_name} = 1;")
275 member = f"{var}->{'.'.join(ref)}"
283 for i in range(0, len(ref)):
284 presence = f"{var}->{'.'.join(ref[:i] + [''])}_present.{ref[i]}"
287 if i == len(ref) - 1 and self.presence_type() != 'present':
288 presence = f"{var}->{'.'.join(ref[:i] + [''])}_{self.presence_type()}.{ref[i]}"
291 ref_path = '.'.join(ref[:-1])
361 if 'byte-order' in attr:
362 self.byte_order_comment = f" /* {attr['byte-order']} */"
378 if 'enum-as-flags' in self.attr and self.attr['enum-as-flags']:
414 if low < -32768 or high > 32767:
415 self.checks['full-range'] = True
418 if 'flags-mask' in self.checks or self.is_bitfield:
423 flags = self.family.consts[self.checks['flags-mask']]
424 flag_cnt = len(flags['entries'])
425 mask = (1 << flag_cnt) - 1
427 elif 'full-range' in self.checks:
449 return f"{var}->{self.c_name} = ynl_attr_get_{self.type}(attr);", None, None
477 return 'len'
489 if 'exact-len' in self.checks:
490 mem = 'NLA_POLICY_EXACT_LEN(' + self.get_limit_str('exact-len') + ')'
493 if 'max-len' in self.checks:
494 mem += ', .len = ' + self.get_limit_str('max-len')
499 if self.checks.get('unterminated-ok', False):
511 len_mem = var + '->_len.' + self.c_name
512 return [f"{len_mem} = len;",
513 f"{var}->{self.c_name} = malloc(len + 1);",
514 f"memcpy({var}->{self.c_name}, ynl_attr_get_str(attr), len);",
515 f"{var}->{self.c_name}[len] = 0;"], \
516 ['len = strnlen(ynl_attr_get_str(attr), ynl_attr_data_len(attr));'], \
517 ['unsigned int len;']
528 return [f"const void *{self.c_name}", 'size_t len']
531 return 'len'
540 if len(self.checks) == 0:
542 elif len(self.checks) == 1:
544 if check_name not in {'exact-len', 'min-len', 'max-len'}:
549 if len(self.checks) == 0:
551 elif 'exact-len' in self.checks:
552 mem = 'NLA_POLICY_EXACT_LEN(' + self.get_limit_str('exact-len') + ')'
553 elif 'min-len' in self.checks:
554 mem = 'NLA_POLICY_MIN_LEN(' + self.get_limit_str('min-len') + ')'
555 elif 'max-len' in self.checks:
556 mem = 'NLA_POLICY_MAX_LEN(' + self.get_limit_str('max-len') + ')'
562 f"{var}->{self.c_name}, {var}->_len.{self.c_name})")
565 len_mem = var + '->_len.' + self.c_name
566 return [f"{len_mem} = len;",
567 f"{var}->{self.c_name} = malloc(len);",
568 f"memcpy({var}->{self.c_name}, ynl_attr_data(attr), len);"], \
569 ['len = ynl_attr_data_len(attr);'], \
570 ['unsigned int len;']
573 return [f"{presence} = len;",
584 len_mem = var + '->_' + self.presence_type() + '.' + self.c_name
585 return [f"{len_mem} = len;",
586 f"if (len < {struct_sz})",
587 f"{var}->{self.c_name} = calloc(1, {struct_sz});",
589 f"{var}->{self.c_name} = malloc(len);",
590 f"memcpy({var}->{self.c_name}, ynl_attr_data(attr), len);"], \
591 ['len = ynl_attr_data_len(attr);'], \
592 ['unsigned int len;']
597 return [f'__{self.get("sub-type")} *{self.c_name}', 'size_t count']
603 ri.cw.p(f'__{self.get("sub-type")} *{self.c_name};')
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')});")
610 f"{var}->{self.c_name}, i);")
614 len_mem = var + '->_count.' + self.c_name
615 return [f"{len_mem} = len / sizeof(__{self.get('sub-type')});",
616 f"len = {len_mem} * sizeof(__{self.get('sub-type')});",
617 f"{var}->{self.c_name} = malloc(len);",
618 f"memcpy({var}->{self.c_name}, ynl_attr_data(attr), len);"], \
619 ['len = ynl_attr_data_len(attr);'], \
620 ['unsigned int len;']
624 f"count *= sizeof(__{self.get('sub-type')});",
644 …line = f"ynl_attr_put(nlh, {self.enum_name}, &{var}->{self.c_name}, sizeof(struct nla_bitfield32))"
648 …return f"memcpy(&{var}->{self.c_name}, ynl_attr_data(attr), sizeof(struct nla_bitfield32));", None…
666 lines += [f'if ({var}->{ref}{self.c_name})']
667 lines += [f'{self.nested_render_name}_free({at}{var}->{ref}{self.c_name});']
679 f"{self.enum_name}, {at}{var}->{self.c_name})")
685 args.append(f'{var}->{sel.name}')
689 f"parg.data = &{var}->{self.c_name};"]
729 raise Exception(f"Sub-type {self.attr['type']} not supported yet")
743 lines += [f"free({var}->{ref}{self.c_name});"]
745 lines += [f"free({var}->{ref}{self.c_name});"]
748 f"for (i = 0; i < {var}->{ref}_count.{self.c_name}; i++)",
749 f"free({var}->{ref}{self.c_name}[i]);",
750 f"free({var}->{ref}{self.c_name});",
754 f"for (i = 0; i < {var}->{ref}_count.{self.c_name}; i++)",
755 f'{self.nested_render_name}_free(&{var}->{ref}{self.c_name}[i]);',
756 f"free({var}->{ref}{self.c_name});",
759 raise Exception(f"Free of MultiAttr sub-type {self.attr['type']} not supported yet")
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++)")
778 …ri.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++)")
785 f"{self.enum_name}, &{var}->{self.c_name}[i])")
787 raise Exception(f"Put of MultiAttr sub-type {self.attr['type']} not supported yet")
802 if 'sub-type' not in self.attr or self.attr['sub-type'] == 'nest':
804 elif self.attr['sub-type'] in scalars:
806 return scalar_pfx + self.attr['sub-type']
807 elif self.attr['sub-type'] == 'binary' and 'exact-len' in self.checks:
810 raise Exception(f"Sub-type {self.attr['sub-type']} not supported yet")
813 if self.sub_type == 'binary' and 'exact-len' in self.checks:
814 return [f'unsigned char (*{self.c_name})[{self.checks["exact-len"]}]',
819 if self.attr['sub-type'] == 'nest':
824 if self.attr['sub-type'] in scalars:
826 elif self.attr['sub-type'] == 'binary' and 'exact-len' in self.checks:
827 return f'.type = YNL_PT_BINARY, .len = {self.checks["exact-len"]}, '
828 elif self.attr['sub-type'] == 'nest':
831 … raise Exception(f"Typol for IndexedArray sub-type {self.attr['sub-type']} not supported, yet")
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]);")
850 elif self.sub_type == 'binary' and 'exact-len' in self.checks:
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]);")
857 … raise Exception(f"Put for IndexedArray sub-type {self.attr['sub-type']} not supported, yet")
871 f"for (i = 0; i < {var}->{ref}_count.{self.c_name}; i++)",
872 f'{self.nested_render_name}_free(&{var}->{ref}{self.c_name}[i]);',
874 lines += f"free({var}->{ref}{self.c_name});",
890 f"parg.data = &{var}->{self.c_name};"]
891 if 'type-value' in self.attr:
892 tv_names = [c_lower(x) for x in self.attr["type-value"]]
895 for level in self.attr["type-value"]:
916 # Reverse-parsing of the policy (ynl_err_walk() in ynl.c) does not
917 # support external selectors. No family uses sub-messages with external
928 sel_var = f"{var}->{sel}"
935 f"parg.data = &{var}->{self.c_name};"]
977 self.render_name = c_lower(family.ident_name + '-' + space_name)
1057 self.render_name = c_lower(family.ident_name + '-' + yaml['name'])
1059 if 'enum-name' in yaml:
1060 if yaml['enum-name']:
1061 self.enum_name = 'enum ' + c_lower(yaml['enum-name'])
1073 self.value_pfx = yaml.get('name-prefix', f"{family.ident_name}-{yaml['name']}-")
1075 self.enum_cnt_name = yaml.get('enum-cnt-name', None)
1086 if high - low + 1 != len(self.entries):
1097 if 'name-prefix' in yaml:
1098 pfx = yaml['name-prefix']
1100 pfx = family.ident_name + '-a-'
1102 pfx = f"{family.ident_name}-a-{self.name}-"
1104 self.max_name = c_upper(self.yaml.get('attr-max-name', f"{self.name_prefix}max"))
1105 self.cnt_name = c_upper(self.yaml.get('attr-cnt-name', f"__{self.name_prefix}max"))
1136 elif elem.get('sub-type') in scalars:
1144 elif elem['type'] == 'indexed-array' and 'sub-type' in elem:
1145 if elem["sub-type"] in ['binary', 'nest', 'u32']:
1148 raise Exception(f'new_attr: unsupported sub-type {elem["sub-type"]}')
1149 elif elem['type'] == 'nest-type-value':
1151 elif elem['type'] == 'sub-message':
1156 if 'multi-attr' in elem and elem['multi-attr']:
1164 # Fill in missing operation properties (for fixed hdr-only msgs)
1201 self.render_name = c_lower(family.ident_name + '-' + yaml['name'])
1225 self.fam_key = c_upper(self.yaml.get('c-family-name', self.yaml["name"] + '_FAMILY_NAME'))
1226 … self.ver_key = c_upper(self.yaml.get('c-version-name', self.yaml["name"] + '_FAMILY_VERSION'))
1231 if 'uapi-header' in self.yaml:
1232 self.uapi_header = self.yaml['uapi-header']
1236 self.uapi_header_name = self.uapi_header[6:-2]
1244 if 'name-prefix' in self.yaml['operations']:
1245 self.op_prefix = c_upper(self.yaml['operations']['name-prefix'])
1247 self.op_prefix = c_upper(self.yaml['name'] + '-cmd-')
1248 if 'async-prefix' in self.yaml['operations']:
1249 self.async_op_prefix = c_upper(self.yaml['operations']['async-prefix'])
1253 self.mcgrps = self.yaml.get('mcast-groups', {'list': []})
1263 # dict space-name -> 'request': set(attrs), 'reply': set(attrs)
1265 # dict space-name -> Struct
1277 self.kernel_policy = self.yaml.get('kernel-policy', 'split')
1294 return self.proto == 'netlink-raw'
1313 if 'attribute-set' not in op:
1326 if op['attribute-set'] not in self.root_sets:
1327 self.root_sets[op['attribute-set']] = {'request': req_attrs, 'reply': rsp_attrs}
1329 self.root_sets[op['attribute-set']]['request'].update(req_attrs)
1330 self.root_sets[op['attribute-set']]['reply'].update(rsp_attrs)
1336 rounds = len(pns_key_list) ** 2 # it's basically bubble sort
1338 if len(pns_key_list) == 0:
1343 if 'nested-attributes' in spec:
1344 nested = spec['nested-attributes']
1345 elif 'sub-message' in spec:
1366 nested = spec['nested-attributes']
1371 fixed_header=spec.get('fixed-header'))
1373 raise Exception(f'Using attr set as root and nested not supported - {nested}')
1375 if 'type-value' in spec:
1378 inherit.update(set(spec['type-value']))
1379 elif spec['type'] == 'indexed-array':
1386 # Fake the struct type for the sub-message itself
1388 submsg = self.sub_msgs[spec["sub-message"]]
1395 "parent-sub-message": spec,
1397 if 'attribute-set' in fmt:
1400 "nested-attributes": fmt['attribute-set'],
1402 if 'fixed-header' in fmt:
1403 attr |= { "fixed-header": fmt["fixed-header"] }
1404 elif 'fixed-header' in fmt:
1407 "struct": fmt["fixed-header"],
1415 "name-pfx": self.name + '-' + spec.name + '-',
1428 while len(attr_set_queue):
1431 if 'nested-attributes' in spec:
1433 elif 'sub-message' in spec:
1444 if 'nested-attributes' in spec:
1445 nested = spec['nested-attributes']
1446 elif 'sub-message' in spec:
1469 if 'nested-attributes' in spec:
1470 child_name = spec['nested-attributes']
1471 elif 'sub-message' in spec:
1513 if 'nested-attributes' in spec:
1514 child_name = spec['nested-attributes']
1515 elif 'sub-message' in spec:
1534 if 'attribute-set' not in op:
1538 attr_set_name = op['attribute-set']
1539 if attr_set_name != op['attribute-set']:
1578 self.fixed_hdr_len = 'ys->family->hdr_len'
1584 raise Exception("Per-op fixed header not supported, yet")
1602 self.attr_set = op['attribute-set']
1631 return len(self.struct[key].attr_list) == 0 and \
1688 if line[-1] == ':':
1689 ind -= 1
1712 self._ind -= 1
1726 if len(line) + len(word) >= 79:
1744 if qual_ret[-1] != '*':
1748 if len(oneline) < 80:
1753 if len(v) > 3:
1756 elif qual_ret[-1] != '*':
1759 ind = '\t' * (len(v) // 8) + ' ' * (len(v) % 8)
1760 delta_ind = len(v) - len(ind)
1763 while i < len(args):
1764 next_len = len(v) + len(args[i])
1783 local_vars.sort(key=len, reverse=True)
1800 if len(define[0]) > longest:
1801 longest = len(define[0])
1805 line += '\t' * ((longest - len(define[0]) + 7) // 8)
1813 longest = max([len(x[0]) for x in members])
1818 line += '\t' * ((longest - len(one[0]) - 1 + 7) // 8)
1968 cw.p(f'.max_attr = {i - 1},')
2006 cw.p(f'{arg_name} = ffs({arg_name}) - 1;')
2060 has_array |= arg.type == 'indexed-array'
2089 init_lines.append(f"memcpy(hdr, &obj->_hdr, {struct_sz});")
2121 iter_line = "ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len)"
2126 raise Exception("Per-op fixed header not supported, yet")
2133 if aspec['type'] == 'indexed-array' and 'sub-type' in aspec:
2134 if aspec["sub-type"] in {'binary', 'nest'}:
2137 elif aspec['sub-type'] in scalars:
2141 raise Exception(f'Not supported sub-type {aspec["sub-type"]}')
2142 if 'multi-attr' in aspec:
2144 needs_parg |= 'nested-attributes' in aspec
2145 needs_parg |= 'sub-message' in aspec
2157 init_lines.append('parg.ys = yarg->ys;')
2172 ri.cw.p(f'dst->{arg} = {arg};')
2181 ri.cw.p(f"memcpy(&dst->_hdr, hdr, sizeof({struct.fixed_header}));")
2184 ri.cw.p(f"if (dst->{aspec.c_name})")
2205 ri.cw.p(f"dst->{aspec.c_name} = calloc(n_{aspec.c_name}, sizeof(*dst->{aspec.c_name}));")
2206 ri.cw.p(f"dst->_count.{aspec.c_name} = n_{aspec.c_name};")
2208 if 'nested-attributes' in aspec:
2211 if 'nested-attributes' in aspec:
2212 ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
2216 ri.cw.p(f"dst->{aspec.c_name}[i] = ynl_attr_get_{aspec.sub_type}(attr);")
2217 elif aspec.sub_type == 'binary' and 'exact-len' in aspec.checks:
2219 … ri.cw.p(f'memcpy(dst->{aspec.c_name}[i], ynl_attr_data(attr), {aspec.checks["exact-len"]});')
2230 ri.cw.p(f"dst->{aspec.c_name} = calloc(n_{aspec.c_name}, sizeof(*dst->{aspec.c_name}));")
2231 ri.cw.p(f"dst->_count.{aspec.c_name} = n_{aspec.c_name};")
2233 if 'nested-attributes' in aspec:
2237 if 'nested-attributes' in aspec:
2238 ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
2242 ri.cw.p(f"dst->{aspec.c_name}[i] = ynl_attr_get_{aspec.type}(attr);")
2244 ri.cw.p('size_t len = ynl_attr_data_len(attr);')
2246 ri.cw.p(f'if (len > sizeof(dst->{aspec.c_name}[0]))')
2247 ri.cw.p(f'len = sizeof(dst->{aspec.c_name}[0]);')
2248 ri.cw.p(f"memcpy(&dst->{aspec.c_name}[i], ynl_attr_data(attr), len);")
2250 ri.cw.p('unsigned int len;')
2252 ri.cw.p('len = strnlen(ynl_attr_get_str(attr), ynl_attr_data_len(attr));')
2253 ri.cw.p(f'dst->{aspec.c_name}[i] = malloc(sizeof(struct ynl_string) + len + 1);')
2254 ri.cw.p(f"dst->{aspec.c_name}[i]->len = len;")
2255 ri.cw.p(f"memcpy(dst->{aspec.c_name}[i]->str, ynl_attr_get_str(attr), len);")
2256 ri.cw.p(f"dst->{aspec.c_name}[i]->str[len] = 0;")
2278 f'{struct.ptr_name}{var} = yarg->data;',
2287 ri.cw.p('parg.ys = yarg->ys;')
2302 ri.cw.p(f"{var}->_present.{arg.c_name} = 1;")
2330 f'{struct.ptr_name}dst = yarg->data;']
2352 init_lines = ['dst = yarg->data;']
2368 ret_err = '-1'
2390 ri.cw.p(f"nlh = ynl_msg_start_req(ys, {ri.op.enum_name}, req->_nlmsg_flags);")
2394 ri.cw.p(f"ys->req_policy = &{ri.struct['request'].render_name}_nest;")
2395 ri.cw.p(f"ys->req_hdr_len = {ri.fixed_hdr_len};")
2401 ri.cw.p("hdr_len = sizeof(req->_hdr);")
2403 ri.cw.p("memcpy(hdr, &req->_hdr, hdr_len);")
2424 ri.cw.p('return -1;')
2471 ri.cw.p("hdr_len = sizeof(req->_hdr);")
2473 ri.cw.p("memcpy(hdr, &req->_hdr, hdr_len);")
2477 ri.cw.p(f"ys->req_policy = &{ri.struct['request'].render_name}_nest;")
2478 ri.cw.p(f"ys->req_hdr_len = {ri.fixed_hdr_len};")
2540 ri.cw.p('req->_nlmsg_flags = nl_flags;')
2562 for type_filter in ['present', 'len', 'count']:
2728 ri.cw.p('next = rsp->next;')
2774 cw.ifdef_block(ri.op.get('config-cond', None))
2800 if 'full-range' not in attr.checks:
2853 cw.p('return -EINVAL;')
2865 'per-op': 'genl_ops',
2879 cnt = len(family.ops)
2914 name = c_lower(f"{family.ident_name}-nl-{op_name}-doit")
2919 name = c_lower(f"{family.ident_name}-nl-{op_name}-dumpit")
2931 if family.kernel_policy == 'global' or family.kernel_policy == 'per-op':
2936 cw.ifdef_block(op.get('config-cond', None))
2939 if 'dont-validate' in op:
2941 ' | '.join([c_upper('genl-dont-validate-' + x)
2942 for x in op['dont-validate']])), )
2945 name = c_lower(f"{family.ident_name}-nl-{op_name}-{op_mode}it")
2947 if family.kernel_policy == 'per-op':
2948 struct = Struct(family, op['attribute-set'],
2951 name = c_lower(f"{family.ident_name}-{op_name}-nl-policy")
2955 members.append(('flags', ' | '.join([c_upper('genl-' + x) for x in op['flags']])))
2967 cw.ifdef_block(op.get('config-cond', None))
2970 if 'dont-validate' in op:
2972 for x in op['dont-validate']:
2973 if op_mode == 'do' and x in ['dump', 'dump-strict']:
2981 ' | '.join([c_upper('genl-dont-validate-' + x)
2983 name = c_lower(f"{family.ident_name}-nl-{op_name}-{op_mode}it")
2990 struct = Struct(family, op['attribute-set'],
2994 name = c_lower(f"{family.ident_name}-{op_name}-{op_mode}-nl-policy")
2996 name = c_lower(f"{family.ident_name}-{op_name}-nl-policy")
2999 flags = (op['flags'] if 'flags' in op else []) + ['cmd-cap-' + op_mode]
3000 members.append(('flags', ' | '.join([c_upper('genl-' + x) for x in flags])))
3015 grp_id = c_upper(f"{family.ident_name}-nlgrp-{grp['name']},")
3028 grp_id = c_upper(f"{family.ident_name}-nlgrp-{name}")
3040 if 'sock-priv' in family.kernel_family:
3041 cw.p(f'void {family.c_name}_nl_sock_priv_init({family.kernel_family["sock-priv"]} *priv);')
3042 … cw.p(f'void {family.c_name}_nl_sock_priv_destroy({family.kernel_family["sock-priv"]} *priv);')
3050 if 'sock-priv' in family.kernel_family:
3067 if family.kernel_policy == 'per-op':
3076 if 'sock-priv' in family.kernel_family:
3077 cw.p(f'.sock_priv_size\t= sizeof({family.kernel_family["sock-priv"]}),')
3083 def uapi_enum_start(family, cw, obj, ckey='', enum_name='enum-name'):
3094 max_name = c_upper(family.get('cmd-max-name', f"{family.op_prefix}MAX"))
3095 cnt_name = c_upper(family.get('cmd-cnt-name', f"__{family.op_prefix}MAX"))
3096 max_value = f"({cnt_name} - 1)"
3098 uapi_enum_start(family, cw, family['operations'], 'enum-name')
3123 max_value = f"({cnt_name} - 1)"
3147 max_value = f"({cnt_name} - 1)"
3208 doc = ' - ' + enum['doc']
3220 name_pfx = const.get('name-prefix', f"{family.ident_name}-{const['name']}-")
3227 if const.get('render-max', False):
3240 cw.p(max_name + ' = (' + c_upper(cnt_name) + ' - 1)')
3244 name_pfx = const.get('name-prefix', f"{family.ident_name}-")
3245 defines.append([c_upper(family.get('c-define-name',
3253 max_by_define = family.get('max-by-define', False)
3259 max_value = f"({attr_set.cnt_name} - 1)"
3262 uapi_enum_start(family, cw, attr_set.yaml, 'enum-name')
3281 separate_ntf = 'async-prefix' in family['operations']
3288 raise Exception(f'Unsupported message enum-model {family.msg_id_model}')
3291 uapi_enum_start(family, cw, family['operations'], enum_name='async-enum')
3307 defines.append([c_upper(grp.get('c-define-name', f"{family.ident_name}-mcgrp-{name}")),
3390 return full_path, sub_path[:-1]
3395 parser.add_argument('--mode', dest='mode', type=str, required=True,
3397 parser.add_argument('--spec', dest='spec', type=str, required=True)
3398 parser.add_argument('--header', dest='header', action='store_true', default=None)
3399 parser.add_argument('--source', dest='header', action='store_false')
3400 parser.add_argument('--user-header', nargs='+', default=[])
3401 parser.add_argument('--cmp-out', action='store_true', default=None,
3403 parser.add_argument('--exclude-op', action='append', default=[])
3404 parser.add_argument('-o', dest='out_file', type=str, default=None)
3408 parser.error("--header or --source is required")
3414 if parsed.license != '((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)':
3416 print('License must be: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)')
3427 cw.p(f'/* SPDX-License-Identifier: {parsed.license} */')
3429 cw.p(f'// SPDX-License-Identifier: {parsed.license}')
3430 cw.p("/* Do not edit directly, auto-generated from: */")
3432 cw.p(f"/* YNL-GEN {args.mode} {'header' if args.header else 'source'} */")
3435 line += ' --user-header '.join([''] + args.user_header)
3436 line += ' --exclude-op '.join([''] + args.exclude_op)
3437 cw.p(f'/* YNL-ARG{line} */')
3451 hdr_file = os.path.basename(args.out_file[:-2]) + ".h"
3476 for definition in parsed['definitions'] + parsed['attribute-sets']:
3518 if parsed.kernel_policy in {'per-op', 'split'}:
3549 if parsed.kernel_policy in {'per-op', 'split'}:
3552 cw.p(f"/* {op.enum_name} - {op_mode} */")
3580 cw.p(f"/* {op.enum_name} - do */")
3592 cw.p(f"/* {op.enum_name} - dump */")
3603 cw.p(f"/* {op.enum_name} - notify */")
3612 cw.p(f"/* {op.enum_name} - event */")
3662 cw.p(f"/* {op.enum_name} - do */")
3671 cw.p(f"/* {op.enum_name} - dump */")
3681 cw.p(f"/* {op.enum_name} - notify */")
3689 cw.p(f"/* {op.enum_name} - event */")