genetlink-c.yaml 14 KB

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