genetlink-c.yaml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. # SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
  2. %YAML 1.2
  3. ---
  4. $id: http://kernel.org/schemas/netlink/genetlink-c.yaml#
  5. $schema: https://json-schema.org/draft-07/schema
  6. # Common defines
  7. $defs:
  8. uint:
  9. type: integer
  10. minimum: 0
  11. len-or-define:
  12. type: [ string, integer ]
  13. pattern: ^[0-9A-Za-z_-]+( - 1)?$
  14. minimum: 0
  15. len-or-limit:
  16. # literal int or limit based on fixed-width type e.g. u8-min, u16-max, etc.
  17. type: [ string, integer ]
  18. pattern: ^[su](8|16|32|64)-(min|max)$
  19. minimum: 0
  20. # Schema for specs
  21. title: Protocol
  22. description: Specification of a genetlink protocol
  23. type: object
  24. required: [ name, doc, attribute-sets, operations ]
  25. additionalProperties: False
  26. properties:
  27. name:
  28. description: Name of the genetlink family.
  29. type: string
  30. doc:
  31. type: string
  32. protocol:
  33. description: Schema compatibility level. Default is "genetlink".
  34. enum: [ genetlink, genetlink-c ]
  35. uapi-header:
  36. description: Path to the uAPI header, default is linux/${family-name}.h
  37. type: string
  38. # Start genetlink-c
  39. c-family-name:
  40. description: Name of the define for the family name.
  41. type: string
  42. c-version-name:
  43. description: Name of the define for the version of the family.
  44. type: string
  45. max-by-define:
  46. description: Makes the number of attributes and commands be specified by a define, not an enum value.
  47. type: boolean
  48. cmd-max-name:
  49. description: Name of the define for the last operation in the list.
  50. type: string
  51. cmd-cnt-name:
  52. description: The explicit name for constant holding the count of operations (last operation + 1).
  53. type: string
  54. # End genetlink-c
  55. definitions:
  56. description: List of type and constant definitions (enums, flags, defines).
  57. type: array
  58. items:
  59. type: object
  60. required: [ type, name ]
  61. additionalProperties: False
  62. properties:
  63. name:
  64. type: string
  65. header:
  66. description: For C-compatible languages, header which already defines this value.
  67. type: string
  68. type:
  69. enum: [ const, enum, flags ]
  70. doc:
  71. type: string
  72. # For const
  73. value:
  74. description: For const - the value.
  75. type: [ string, integer ]
  76. # For enum and flags
  77. value-start:
  78. description: For enum or flags the literal initializer for the first value.
  79. type: [ string, integer ]
  80. entries:
  81. description: For enum or flags array of values.
  82. type: array
  83. items:
  84. oneOf:
  85. - type: string
  86. - type: object
  87. required: [ name ]
  88. additionalProperties: False
  89. properties:
  90. name:
  91. type: string
  92. value:
  93. type: integer
  94. doc:
  95. type: string
  96. render-max:
  97. description: Render the max members for this enum.
  98. type: boolean
  99. # Start genetlink-c
  100. enum-name:
  101. description: Name for enum, if empty no name will be used.
  102. type: [ string, "null" ]
  103. name-prefix:
  104. description: For enum the prefix of the values, optional.
  105. type: string
  106. # End genetlink-c
  107. attribute-sets:
  108. description: Definition of attribute spaces for this family.
  109. type: array
  110. items:
  111. description: Definition of a single attribute space.
  112. type: object
  113. required: [ name, attributes ]
  114. additionalProperties: False
  115. properties:
  116. name:
  117. description: |
  118. Name used when referring to this space in other definitions, not used outside of the spec.
  119. type: string
  120. name-prefix:
  121. description: |
  122. Prefix for the C enum name of the attributes. Default family[name]-set[name]-a-
  123. type: string
  124. enum-name:
  125. description: |
  126. Name for the enum type of the attribute, if empty no name will be used.
  127. type: [ string, "null" ]
  128. doc:
  129. description: Documentation of the space.
  130. type: string
  131. subset-of:
  132. description: |
  133. Name of another space which this is a logical part of. Sub-spaces can be used to define
  134. a limited group of attributes which are used in a nest.
  135. type: string
  136. # Start genetlink-c
  137. attr-cnt-name:
  138. description: The explicit name for constant holding the count of attributes (last attr + 1).
  139. type: string
  140. attr-max-name:
  141. description: The explicit name for last member of attribute enum.
  142. type: string
  143. # End genetlink-c
  144. attributes:
  145. description: List of attributes in the space.
  146. type: array
  147. items:
  148. type: object
  149. required: [ name ]
  150. additionalProperties: False
  151. properties:
  152. name:
  153. type: string
  154. type: &attr-type
  155. enum: [ unused, pad, flag, binary,
  156. uint, sint, u8, u16, u32, u64, s32, s64,
  157. string, nest, indexed-array, nest-type-value ]
  158. doc:
  159. description: Documentation of the attribute.
  160. type: string
  161. value:
  162. description: Value for the enum item representing this attribute in the uAPI.
  163. $ref: '#/$defs/uint'
  164. type-value:
  165. description: Name of the value extracted from the type of a nest-type-value attribute.
  166. type: array
  167. items:
  168. type: string
  169. byte-order:
  170. enum: [ little-endian, big-endian ]
  171. multi-attr:
  172. type: boolean
  173. nested-attributes:
  174. description: Name of the space (sub-space) used inside the attribute.
  175. type: string
  176. enum:
  177. description: Name of the enum type used for the attribute.
  178. type: string
  179. enum-as-flags:
  180. description: |
  181. Treat the enum as flags. In most cases enum is either used as flags or as values.
  182. Sometimes, however, both forms are necessary, in which case header contains the enum
  183. form while specific attributes may request to convert the values into a bitfield.
  184. type: boolean
  185. checks:
  186. description: Kernel input validation.
  187. type: object
  188. additionalProperties: False
  189. properties:
  190. flags-mask:
  191. description: Name of the flags constant on which to base mask (unsigned scalar types only).
  192. type: string
  193. min:
  194. description: Min value for an integer attribute.
  195. $ref: '#/$defs/len-or-limit'
  196. max:
  197. description: Max value for an integer attribute.
  198. $ref: '#/$defs/len-or-limit'
  199. min-len:
  200. description: Min length for a binary attribute.
  201. $ref: '#/$defs/len-or-define'
  202. max-len:
  203. description: Max length for a string or a binary attribute.
  204. $ref: '#/$defs/len-or-define'
  205. exact-len:
  206. description: Exact length for a string or a binary attribute.
  207. $ref: '#/$defs/len-or-define'
  208. unterminated-ok:
  209. description: |
  210. For string attributes, do not check whether attribute
  211. contains the terminating null character.
  212. type: boolean
  213. sub-type: *attr-type
  214. display-hint: &display-hint
  215. description: |
  216. Optional format indicator that is intended only for choosing
  217. the right formatting mechanism when displaying values of this
  218. type.
  219. enum: [ hex, mac, fddi, ipv4, ipv6, uuid ]
  220. # Start genetlink-c
  221. name-prefix:
  222. type: string
  223. # End genetlink-c
  224. # Make sure name-prefix does not appear in subsets (subsets inherit naming)
  225. dependencies:
  226. name-prefix:
  227. not:
  228. required: [ subset-of ]
  229. subset-of:
  230. not:
  231. required: [ name-prefix ]
  232. # type property is only required if not in subset definition
  233. if:
  234. properties:
  235. subset-of:
  236. not:
  237. type: string
  238. then:
  239. properties:
  240. attributes:
  241. items:
  242. required: [ type ]
  243. operations:
  244. description: Operations supported by the protocol.
  245. type: object
  246. required: [ list ]
  247. additionalProperties: False
  248. properties:
  249. enum-model:
  250. description: |
  251. The model of assigning values to the operations.
  252. "unified" is the recommended model where all message types belong
  253. to a single enum.
  254. "directional" has the messages sent to the kernel and from the kernel
  255. enumerated separately.
  256. enum: [ unified ]
  257. name-prefix:
  258. description: |
  259. Prefix for the C enum name of the command. The name is formed by concatenating
  260. the prefix with the upper case name of the command, with dashes replaced by underscores.
  261. type: string
  262. enum-name:
  263. description: |
  264. Name for the enum type with commands, if empty no name will be used.
  265. type: [ string, "null" ]
  266. async-prefix:
  267. description: Same as name-prefix but used to render notifications and events to separate enum.
  268. type: string
  269. async-enum:
  270. description: |
  271. Name for the enum type with commands, if empty no name will be used.
  272. type: [ string, "null" ]
  273. list:
  274. description: List of commands
  275. type: array
  276. items:
  277. type: object
  278. additionalProperties: False
  279. required: [ name, doc ]
  280. properties:
  281. name:
  282. description: Name of the operation, also defining its C enum value in uAPI.
  283. type: string
  284. doc:
  285. description: Documentation for the command.
  286. type: string
  287. value:
  288. description: Value for the enum in the uAPI.
  289. $ref: '#/$defs/uint'
  290. attribute-set:
  291. description: |
  292. Attribute space from which attributes directly in the requests and replies
  293. to this command are defined.
  294. type: string
  295. flags: &cmd_flags
  296. description: Command flags.
  297. type: array
  298. items:
  299. enum: [ admin-perm ]
  300. dont-validate:
  301. description: Kernel attribute validation flags.
  302. type: array
  303. items:
  304. enum: [ strict, dump, dump-strict ]
  305. config-cond:
  306. description: |
  307. Name of the kernel config option gating the presence of
  308. the operation, without the 'CONFIG_' prefix.
  309. type: string
  310. do: &subop-type
  311. description: Main command handler.
  312. type: object
  313. additionalProperties: False
  314. properties:
  315. request: &subop-attr-list
  316. description: Definition of the request message for a given command.
  317. type: object
  318. additionalProperties: False
  319. properties:
  320. attributes:
  321. description: |
  322. Names of attributes from the attribute-set (not full attribute
  323. definitions, just names).
  324. type: array
  325. items:
  326. type: string
  327. reply: *subop-attr-list
  328. pre:
  329. description: Hook for a function to run before the main callback (pre_doit or start).
  330. type: string
  331. post:
  332. description: Hook for a function to run after the main callback (post_doit or done).
  333. type: string
  334. dump: *subop-type
  335. notify:
  336. description: Name of the command sharing the reply type with this notification.
  337. type: string
  338. event:
  339. type: object
  340. additionalProperties: False
  341. properties:
  342. attributes:
  343. description: Explicit list of the attributes for the notification.
  344. type: array
  345. items:
  346. type: string
  347. mcgrp:
  348. description: Name of the multicast group generating given notification.
  349. type: string
  350. mcast-groups:
  351. description: List of multicast groups.
  352. type: object
  353. required: [ list ]
  354. additionalProperties: False
  355. properties:
  356. list:
  357. description: List of groups.
  358. type: array
  359. items:
  360. type: object
  361. required: [ name ]
  362. additionalProperties: False
  363. properties:
  364. name:
  365. description: |
  366. The name for the group, used to form the define and the value of the define.
  367. type: string
  368. # Start genetlink-c
  369. c-define-name:
  370. description: Override for the name of the define in C uAPI.
  371. type: string
  372. # End genetlink-c
  373. flags: *cmd_flags
  374. kernel-family:
  375. description: Additional global attributes used for kernel C code generation.
  376. type: object
  377. additionalProperties: False
  378. properties:
  379. headers:
  380. description: |
  381. List of extra headers which should be included in the source
  382. of the generated code.
  383. type: array
  384. items:
  385. type: string
  386. sock-priv:
  387. description: |
  388. Literal name of the type which is used within the kernel
  389. to store the socket state. The type / structure is internal
  390. to the kernel, and is not defined in the spec.
  391. type: string