core: add options to delegate BPFFS token creation
Add four new options BPFDelegate{Commands,Maps,Programs,Attachments}=
in order to delegate to a BPFFS instance the permission to create tokens.
The value is a list of options taken from:
https://github.com/torvalds/linux/blob/v6.14/include/uapi/linux/bpf.h#L922-L1121
The special value "any" means to allow every possible values.
More informations about BPF tokens here:
https://lwn.net/Articles/947173/
This commit is contained in:
Executable
+76
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
# Convert the bpf_{cmd,map_type,prog_type,attach_type} enums into a string
|
||||
# array to be used as configuration options
|
||||
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def print_usage_and_exit() -> None:
|
||||
print(f'Usage: {sys.argv[0]} <code|doc> <header>')
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print_usage_and_exit()
|
||||
|
||||
output = sys.argv[1]
|
||||
header = sys.argv[2]
|
||||
|
||||
if output not in ['code', 'doc']:
|
||||
print(f'Invalid format: {format}')
|
||||
print_usage_and_exit()
|
||||
|
||||
with open(header) as file:
|
||||
inEnum = False
|
||||
enumValues: list[str] = []
|
||||
enumName = ''
|
||||
|
||||
if output == 'doc':
|
||||
print("""\
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE bpf-delegates PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
|
||||
<para>
|
||||
""")
|
||||
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
|
||||
if inEnum:
|
||||
# Inside an enum definition
|
||||
if re.match(r'^\s*}', line):
|
||||
# End of an enum definition
|
||||
inEnum = False
|
||||
# Print the enum values as a static const char* array
|
||||
if output == 'code':
|
||||
print(f'static const char* const {enumName}_table[] = {{')
|
||||
else:
|
||||
print(f'<para id="{enumName}">')
|
||||
for enumValue in enumValues:
|
||||
words = enumValue.split('_')
|
||||
enumValue = words[0] + ''.join(word.capitalize() for word in words[1:])
|
||||
if output == 'code':
|
||||
print(f'\t"{enumValue}",')
|
||||
else:
|
||||
print(f'<literal>{enumValue}</literal>')
|
||||
if output == 'code':
|
||||
print('};')
|
||||
else:
|
||||
print('</para>')
|
||||
enumValues = []
|
||||
else:
|
||||
# Collect enum values
|
||||
match = re.fullmatch(r'(\w+)\b,', line)
|
||||
if match and len(match.groups()) > 0 and not match[1].startswith('__'):
|
||||
enumValues.append(match[1])
|
||||
elif match := re.match(r'^\s*enum\s+bpf_(cmd|map_type|prog_type|attach_type)+\s*{', line):
|
||||
# Start of a new enum
|
||||
inEnum = True
|
||||
enumName = 'bpf_delegate_' + match[1]
|
||||
|
||||
if output == 'doc':
|
||||
print('</para>')
|
||||
+11
-2
@@ -273,8 +273,17 @@ filesystem_switch_case_inc = custom_target(
|
||||
'@INPUT@'],
|
||||
capture : true)
|
||||
|
||||
generated_sources += [filesystem_list_inc, filesystem_switch_case_inc, filesystems_gperf_h]
|
||||
basic_sources += [filesystem_list_inc, filesystem_switch_case_inc, filesystems_gperf_h]
|
||||
generate_bpf_delegate_configs = find_program('generate-bpf-delegate-configs.py')
|
||||
bpf_delegate_configs_inc = custom_target(
|
||||
input : files('include/linux/bpf.h'),
|
||||
output : 'bpf-delegate-configs.inc',
|
||||
command : [generate_bpf_delegate_configs,
|
||||
'code',
|
||||
'@INPUT@'],
|
||||
capture : true)
|
||||
|
||||
generated_sources += [filesystem_list_inc, filesystem_switch_case_inc, filesystems_gperf_h, bpf_delegate_configs_inc]
|
||||
basic_sources += [filesystem_list_inc, filesystem_switch_case_inc, filesystems_gperf_h, bpf_delegate_configs_inc]
|
||||
|
||||
libbasic_static = static_library(
|
||||
'basic',
|
||||
|
||||
Reference in New Issue
Block a user