netlink.h 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  1. /*++
  2. Copyright (c) 2016 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. netlink.h
  5. Abstract:
  6. This header contains definitions for netlink sockets.
  7. Author:
  8. Chris Stevens 9-Feb-2016
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // --------------------------------------------------------------------- Macros
  15. //
  16. //
  17. // This macro returns the required alignment for a given length. All headers,
  18. // attributes, and messages must be aligned.
  19. //
  20. #define NETLINK_ALIGN(_Length) ALIGN_RANGE_UP(_Length, NETLINK_ALIGNMENT)
  21. //
  22. // This macro returns the aligned size of a netlink message header.
  23. //
  24. #define NETLINK_HEADER_LENGTH NETLINK_ALIGN(sizeof(NETLINK_HEADER))
  25. //
  26. // This macro evaluates to a pointer to the ancillary data following a netlink
  27. // header structure.
  28. //
  29. #define NETLINK_DATA(_Header) ((PVOID)(_Header) + NETLINK_HEADER_LENGTH)
  30. //
  31. // This macro returns the aligned aize of a netlink message header.
  32. //
  33. #define NETLINK_ATTRIBUTE_HEADER_LENGTH NETLINK_ALIGN(sizeof(NETLINK_ATTRIBUTE))
  34. //
  35. // This macro evaluates to a pointer to the ancillary data following a netlink
  36. // attribute header structure.
  37. //
  38. #define NETLINK_ATTRIBUTE_DATA(_Header) \
  39. ((PVOID)(_Header) + NETLINK_ATTRIBUTE_HEADER_LENGTH)
  40. //
  41. // This macro returns the length of the netlink attribute, based on the data
  42. // length, that should be set in the attribute header.
  43. //
  44. #define NETLINK_ATTRIBUTE_LENGTH(_DataLength) \
  45. (NETLINK_ATTRIBUTE_HEADER_LENGTH + (_DataLength))
  46. //
  47. // This macro returns the total size, in bytes, consumed by a netlink
  48. // attribute with the given data length, accounting for alignment.
  49. //
  50. #define NETLINK_ATTRIBUTE_SIZE(_DataLength) \
  51. NETLINK_ALIGN(NETLINK_ATTRIBUTE_LENGTH(_DataLength))
  52. //
  53. // This macro returns the aligned size of the generic netlink message header.
  54. //
  55. #define NETLINK_GENERIC_HEADER_LENGTH \
  56. NETLINK_ALIGN(sizeof(NETLINK_GENERIC_HEADER))
  57. //
  58. // This macro evaluates to a pointer to the ancillary data following a netlink
  59. // generic header structure.
  60. //
  61. #define NETLINK_GENERIC_DATA(_Header) \
  62. ((PVOID)(_Header) + NETLINK_GENERIC_HEADER_LENGTH)
  63. //
  64. // This macro determines the index into an socket's multicast bitmap array for
  65. // a given multicast group ID.
  66. //
  67. #define NETLINK_SOCKET_BITMAP_INDEX(_GroupId) \
  68. ((_GroupId) / (sizeof(ULONG) * BITS_PER_BYTE))
  69. //
  70. // This macro determines in the mask for a particular group ID within an
  71. // netlink socket's multicast bitmap.
  72. //
  73. #define NETLINK_SOCKET_BITMAP_MASK(_GroupId) \
  74. (1 << ((_GroupId) % (sizeof(ULONG) * BITS_PER_BYTE)))
  75. //
  76. // This macro determines the number of group IDs that the socket multicast
  77. // bitmap currently supports.
  78. //
  79. #define NETLINK_SOCKET_BITMAP_GROUP_ID_COUNT(_Socket) \
  80. ((_Socket)->MulticastBitmapSize * BITS_PER_BYTE)
  81. //
  82. // ---------------------------------------------------------------- Definitions
  83. //
  84. //
  85. // Define the current version number of netlink properties structure.
  86. //
  87. #define NETLINK_PROPERTIES_VERSION 1
  88. //
  89. // Define the alignment for all netlink messages, message headers, and message
  90. // attributes.
  91. //
  92. #define NETLINK_ALIGNMENT 4
  93. //
  94. // Define the standard netlink message types common to all netlink families.
  95. //
  96. #define NETLINK_MESSAGE_TYPE_NOP 1
  97. #define NETLINK_MESSAGE_TYPE_ERROR 2
  98. #define NETLINK_MESSAGE_TYPE_DONE 3
  99. #define NETLINK_MESSAGE_TYPE_OVERRUN 4
  100. #define NETLINK_MESSAGE_TYPE_PROTOCOL_MINIMUM 16
  101. //
  102. // Define the netlink message header flags.
  103. //
  104. #define NETLINK_HEADER_FLAG_REQUEST 0x0001
  105. #define NETLINK_HEADER_FLAG_MULTIPART 0x0002
  106. #define NETLINK_HEADER_FLAG_ACK 0x0004
  107. #define NETLINK_HEADER_FLAG_ECHO 0x0008
  108. #define NETLINK_HEADER_FLAG_ROOT 0x0010
  109. #define NETLINK_HEADER_FLAG_MATCH 0x0020
  110. #define NETLINK_HEADER_FLAG_ATOMIC 0x0040
  111. #define NETLINK_HEADER_FLAG_DUMP \
  112. (NETLINK_HEADER_FLAG_ROOT | NETLINK_HEADER_FLAG_MATCH)
  113. //
  114. // Define the port ID of the kernel.
  115. //
  116. #define NETLINK_KERNEL_PORT_ID 0
  117. //
  118. // Define the alignment for netlink attribute headers.
  119. //
  120. #define NETLINK_ATTRIBUTE_ALIGNMENT 4
  121. //
  122. // Define the maximum netlink packet size, including the header.
  123. //
  124. #define NETLINK_MAX_PACKET_SIZE MAX_ULONG
  125. //
  126. // Define the current version of the generic netlink family properties
  127. // structure.
  128. //
  129. #define NETLINK_GENERIC_FAMILY_PROPERTIES_VERSION 1
  130. //
  131. // Define the maximum length of a generic netlink family name.
  132. //
  133. #define NETLINK_GENERIC_MAX_FAMILY_NAME_LENGTH 16
  134. //
  135. // Define the maximum length of a multicast group name.
  136. //
  137. #define NETLINK_GENERIC_MAX_MULTICAST_GROUP_NAME 16
  138. //
  139. // Define the standard generic netlink message types.
  140. //
  141. #define NETLINK_GENERIC_ID_CONTROL NETLINK_MESSAGE_TYPE_PROTOCOL_MINIMUM
  142. //
  143. // Define the names of the netlink generic families.
  144. //
  145. #define NETLINK_GENERIC_CONTROL_NAME "nlctrl"
  146. #define NETLINK_GENERIC_80211_NAME "nl80211"
  147. //
  148. // Define the generic control command values.
  149. //
  150. #define NETLINK_CONTROL_COMMAND_NEW_FAMILY 1
  151. #define NETLINK_CONTROL_COMMAND_DELETE_FAMILY 2
  152. #define NETLINK_CONTROL_COMMAND_GET_FAMILY 3
  153. #define NETLINK_CONTROL_COMMAND_NEW_MULTICAST_GROUP 7
  154. #define NETLINK_CONTROL_COMMAND_DELETE_MULTICAST_GROUP 8
  155. #define NETLINK_CONTROL_COMMAND_MAX 255
  156. //
  157. // Define the generic control attributes.
  158. //
  159. #define NETLINK_CONTROL_ATTRIBUTE_FAMILY_ID 1
  160. #define NETLINK_CONTROL_ATTRIBUTE_FAMILY_NAME 2
  161. #define NETLINK_CONTROL_ATTRIBUTE_VERSION 3
  162. #define NETLINK_CONTROL_ATTRIBUTE_HEADER_SIZE 4
  163. #define NETLINK_CONTROL_ATTRIBUTE_MAX_ATTRIBUTE 5
  164. #define NETLINK_CONTROL_ATTRIBUTE_OPERATIONS 6
  165. #define NETLINK_CONTROL_ATTRIBUTE_MULTICAST_GROUPS 7
  166. //
  167. // Define the generic control multicast group names.
  168. //
  169. #define NETLINK_CONTROL_MULTICAST_NOTIFY_NAME "notify"
  170. //
  171. // Define the generic multicast group attributes.
  172. //
  173. #define NETLINK_CONTROL_MULTICAST_GROUP_ATTRIBUTE_NAME 1
  174. #define NETLINK_CONTROL_MULTICAST_GROUP_ATTRIBUTE_ID 2
  175. //
  176. // Define the generic 802.11 command values.
  177. //
  178. #define NETLINK_80211_COMMAND_JOIN 1
  179. #define NETLINK_80211_COMMAND_LEAVE 2
  180. #define NETLINK_80211_COMMAND_SCAN_START 3
  181. #define NETLINK_80211_COMMAND_SCAN_RESULT 4
  182. #define NETLINK_80211_COMMAND_SCAN_GET_RESULTS 5
  183. #define NETLINK_80211_COMMAND_SCAN_ABORTED 6
  184. #define NETLINK_80211_COMMAND_MAX 255
  185. //
  186. // Define the generic 802.11 attributes.
  187. //
  188. #define NETLINK_80211_ATTRIBUTE_DEVICE_ID 1
  189. #define NETLINK_80211_ATTRIBUTE_SSID 2
  190. #define NETLINK_80211_ATTRIBUTE_BSSID 3
  191. #define NETLINK_80211_ATTRIBUTE_PASSPHRASE 4
  192. #define NETLINK_80211_ATTRIBUTE_BSS 5
  193. //
  194. // Define the 802.11 BSS attributes.
  195. //
  196. #define NETLINK_80211_BSS_ATTRIBUTE_BSSID 1
  197. #define NETLINK_80211_BSS_ATTRIBUTE_CAPABILITY 2
  198. #define NETLINK_80211_BSS_ATTRIBUTE_BEACON_INTERVAL 3
  199. #define NETLINK_80211_BSS_ATTRIBUTE_SIGNAL_MBM 4
  200. #define NETLINK_80211_BSS_ATTRIBUTE_STATUS 5
  201. #define NETLINK_80211_BSS_ATTRIBUTE_INFORMATION_ELEMENTS 6
  202. //
  203. // Define the status values for the BSS status attribute.
  204. //
  205. #define NETLINK_80211_BSS_STATUS_NOT_CONNECTED 0
  206. #define NETLINK_80211_BSS_STATUS_AUTHENTICATED 1
  207. #define NETLINK_80211_BSS_STATUS_ASSOCIATED 2
  208. //
  209. // Define the generic 802.11 multicast group names.
  210. //
  211. #define NETLINK_80211_MULTICAST_SCAN_NAME "scan"
  212. //
  213. // ------------------------------------------------------ Data Type Definitions
  214. //
  215. #define NETLINK_API NET_API
  216. typedef struct _NETLINK_GENERIC_FAMILY
  217. NETLINK_GENERIC_FAMILY, *PNETLINK_GENERIC_FAMILY;
  218. /*++
  219. Structure Description:
  220. This structure defines an netlink address.
  221. Members:
  222. Domain - Stores the network domain of this address.
  223. Port - Stores the 32 bit port ID.
  224. Group - Stores the 32 bit group ID.
  225. NetworkAddress - Stores the unioned opaque version, used to ensure the
  226. structure is the proper size.
  227. --*/
  228. typedef struct _NETLINK_ADDRESS {
  229. union {
  230. struct {
  231. NET_DOMAIN_TYPE Domain;
  232. ULONG Port;
  233. ULONG Group;
  234. };
  235. NETWORK_ADDRESS NetworkAddress;
  236. };
  237. } NETLINK_ADDRESS, *PNETLINK_ADDRESS;
  238. /*++
  239. Structure Description:
  240. This structure defines the header of a netlink data message.
  241. Members:
  242. Length - Stores the length of the netlink message, including the header.
  243. Type - Stores the message type. See NETLINK_MESSAGE_TYPE_* for global
  244. definitions. Otherwise this stores protocol-specific message types.
  245. Flags - Stores a bitmask of message flags. See NETLINK_HEADER_FLAG_* for
  246. definitions.
  247. SequenceNumber - Stores the sequence number of the netlink message.
  248. PortId - Stores the port ID of the sending socket.
  249. --*/
  250. typedef struct _NETLINK_HEADER {
  251. ULONG Length;
  252. USHORT Type;
  253. USHORT Flags;
  254. ULONG SequenceNumber;
  255. ULONG PortId;
  256. } PACKED NETLINK_HEADER, *PNETLINK_HEADER;
  257. /*++
  258. Structure Description:
  259. This structure defines the data portion of a netlink error message.
  260. Members:
  261. Error - Stores the error caused by the bad message.
  262. Header - Stores the header of the bad netlink message that caused the error.
  263. The rest of the message payload follows the header.
  264. --*/
  265. typedef struct _NETLINK_ERROR_MESSAGE {
  266. INT Error;
  267. NETLINK_HEADER Header;
  268. } PACKED NETLINK_ERROR_MESSAGE, *PNETLINK_ERROR_MESSAGE;
  269. /*++
  270. Structure Description:
  271. This structure defines a netlink attribute.
  272. Members:
  273. Length - Stores the length of the attribute, in bytes, including the header.
  274. Type - Stores the message-specific attribute type.
  275. --*/
  276. typedef struct _NETLINK_ATTRIBUTE {
  277. USHORT Length;
  278. USHORT Type;
  279. } PACKED NETLINK_ATTRIBUTE, *PNETLINK_ATTRIBUTE;
  280. /*++
  281. Structure Description:
  282. This structure defines the header for a generic netlink message.
  283. Members:
  284. Command - Stores the generic message command value.
  285. Version - Stores the generic message version.
  286. Reserved - Stores 2 reserved bytes.
  287. --*/
  288. typedef struct _NETLINK_GENERIC_HEADER {
  289. UCHAR Command;
  290. UCHAR Version;
  291. USHORT Reserved;
  292. } PACKED NETLINK_GENERIC_HEADER, *PNETLINK_GENERIC_HEADER;
  293. /*++
  294. Structure Description:
  295. This structure defines the already parsed information for the message.
  296. Members:
  297. SourceAddress - Stores a pointer to the source address for the command.
  298. This memory will not be referenced once the function returns; it can be
  299. stack allocated.
  300. DestinationAddress - Stores a pointer to the destination address for the
  301. command. This memory will not be referenced once the function returns;
  302. it can be stack allocated.
  303. SequenceNumber - Stores the sequence number of the command.
  304. Type - Stores the netlink message type.
  305. --*/
  306. typedef struct _NETLINK_MESSAGE_INFORMATION {
  307. PNETWORK_ADDRESS SourceAddress;
  308. PNETWORK_ADDRESS DestinationAddress;
  309. ULONG SequenceNumber;
  310. USHORT Type;
  311. } NETLINK_MESSAGE_INFORMATION, *PNETLINK_MESSAGE_INFORMATION;
  312. /*++
  313. Structure Description:
  314. This structure defines the already parsed information for the command.
  315. Members:
  316. Message - Stores the base message parameters.
  317. Command - Stores the generic command value.
  318. Version - Stores the generic command version.
  319. --*/
  320. typedef struct _NETLINK_GENERIC_COMMAND_INFORMATION {
  321. NETLINK_MESSAGE_INFORMATION Message;
  322. UCHAR Command;
  323. UCHAR Version;
  324. } NETLINK_GENERIC_COMMAND_INFORMATION, *PNETLINK_GENERIC_COMMAND_INFORMATION;
  325. typedef
  326. KSTATUS
  327. (*PNETLINK_GENERIC_PROCESS_COMMAND) (
  328. PNET_SOCKET Socket,
  329. PNET_PACKET_BUFFER Packet,
  330. PNETLINK_GENERIC_COMMAND_INFORMATION Command
  331. );
  332. /*++
  333. Routine Description:
  334. This routine is called to process a received generic netlink packet for
  335. a given command type.
  336. Arguments:
  337. Socket - Supplies a pointer to the socket that received the packet.
  338. Packet - Supplies a pointer to a structure describing the incoming packet.
  339. This structure may be used as a scratch space while this routine
  340. executes and the packet travels up the stack, but will not be accessed
  341. after this routine returns.
  342. Command - Supplies a pointer to the command information.
  343. Return Value:
  344. Status code.
  345. --*/
  346. /*++
  347. Structure Description:
  348. This structure defines a netlink generic command.
  349. Members:
  350. CommandId - Stores the command ID value. This should match the generic
  351. netlink header values for the command's family.
  352. RequiredFlags - Stores a bitmask of flags that must be set in the
  353. requesting netlink message for this command to be processed.
  354. ProcessCommand - Stores a pointer to a function called when a packet of
  355. this command type is received by a generic netlink socket.
  356. --*/
  357. typedef struct _NETLINK_GENERIC_COMMAND {
  358. UCHAR CommandId;
  359. USHORT RequiredFlags;
  360. PNETLINK_GENERIC_PROCESS_COMMAND ProcessCommand;
  361. } NETLINK_GENERIC_COMMAND, *PNETLINK_GENERIC_COMMAND;
  362. /*++
  363. Structure Description:
  364. This structure defines a generic netlink multicast group. The group's ID is
  365. dynamic and is based off the family's assigned group ID offset.
  366. Members:
  367. Id - Stores the ID of the multicast group.
  368. NameLength - Stores the length of the multicast group name, in bytes.
  369. Name - Stores the name of the multicast group.
  370. --*/
  371. typedef struct _NETLINK_GENERIC_MULTICAST_GROUP {
  372. ULONG Id;
  373. ULONG NameLength;
  374. CHAR Name[NETLINK_GENERIC_MAX_MULTICAST_GROUP_NAME];
  375. } NETLINK_GENERIC_MULTICAST_GROUP, *PNETLINK_GENERIC_MULTICAST_GROUP;
  376. /*++
  377. Structure Description:
  378. This structure defines a generic netlink family properties.
  379. Members:
  380. Version - Stores the generic netlink family structure version. Set to
  381. NETLINK_GENERIC_FAMILY_PROPERTIES_VERSION.
  382. Id - Stores the generic netlink family's ID. Set to zero upon registration
  383. to have the netlink core allocate an ID.
  384. NameLength - Stores the length of the family name, in bytes.
  385. Name - Stores the name of the generic family.
  386. Commands - Stores a pointer to an array of netlink generic commands.
  387. CommandCount - Stores the number of commands in the array.
  388. MulticastGroups - Stores a pointer to an array of multicast groups.
  389. MulticastGroupCount - Stores the number of multicast groups in the array.
  390. --*/
  391. typedef struct _NETLINK_GENERIC_FAMILY_PROPERTIES {
  392. ULONG Version;
  393. ULONG Id;
  394. ULONG NameLength;
  395. CHAR Name[NETLINK_GENERIC_MAX_FAMILY_NAME_LENGTH];
  396. PNETLINK_GENERIC_COMMAND Commands;
  397. ULONG CommandCount;
  398. PNETLINK_GENERIC_MULTICAST_GROUP MulticastGroups;
  399. ULONG MulticastGroupCount;
  400. } NETLINK_GENERIC_FAMILY_PROPERTIES, *PNETLINK_GENERIC_FAMILY_PROPERTIES;
  401. typedef
  402. KSTATUS
  403. (*PNETLINK_PROTOCOL_JOIN_MULTICAST_GROUP) (
  404. PNET_SOCKET Socket,
  405. ULONG GroupId
  406. );
  407. /*++
  408. Routine Description:
  409. This routine attempts to join the given multicast group by validating the
  410. group ID for the protocol and then joining the multicast group.
  411. Arguments:
  412. Socket - Supplies a pointer to the network socket requesting to join a
  413. multicast group.
  414. GroupId - Supplies the ID of the multicast group to join.
  415. Return Value:
  416. Status code.
  417. --*/
  418. /*++
  419. Structure Description:
  420. This structure defines the protocol layer interface specific to netlink
  421. sockets.
  422. Members:
  423. JoinMulticastGroup - Supplies a pointer to a function used to join a
  424. multicast group.
  425. --*/
  426. typedef struct _NETLINK_PROTOCOL_INTERFACE {
  427. PNETLINK_PROTOCOL_JOIN_MULTICAST_GROUP JoinMulticastGroup;
  428. } NETLINK_PROTOCOL_INTERFACE, *PNETLINK_PROTOCOL_INTERFACE;
  429. /*++
  430. Structure Description:
  431. This structure defines a netlink socket.
  432. Members:
  433. NetSocket - Stores the common core networking parameters.
  434. MulticastListEntry - Stores the socket's entry into the list of sockets
  435. signed up for at least one multicast group.
  436. MulticastBitmap - Stores a pointer to bitmap describing the multicast
  437. groups to which the socket belongs.
  438. MulticastBitmapSize - Stores the size of the multicast bitmap, in bytes.
  439. MulticastGroupCount - Stores the number of multicast groups to which the
  440. socket is joined.
  441. ProtocolInterface - Stores the interface presented to the netlink network
  442. layer for this type of netlink socket.
  443. --*/
  444. typedef struct _NETLINK_SOCKET {
  445. NET_SOCKET NetSocket;
  446. LIST_ENTRY MulticastListEntry;
  447. PULONG MulticastBitmap;
  448. ULONG MulticastBitmapSize;
  449. ULONG MulticastGroupCount;
  450. NETLINK_PROTOCOL_INTERFACE ProtocolInterface;
  451. } NETLINK_SOCKET, *PNETLINK_SOCKET;
  452. /*++
  453. Enumeration Description:
  454. This enumeration describes the various socket options for the basic socket
  455. information class.
  456. Values:
  457. NetlinkSocketOptionInvalid - Indicates an invalid option.
  458. NetlinkSocketOptionJoinMulticastGroup - Indicates that the socket intends
  459. to join a multicast group.
  460. NetlinkSocketOptionLeaveMulticastGroup - Indicates that the socket intends
  461. to leave a multicast group.
  462. --*/
  463. typedef enum _NETLINK_SOCKET_OPTION {
  464. NetlinkSocketOptionInvalid,
  465. NetlinkSocketOptionJoinMulticastGroup,
  466. NetlinkSocketOptionLeaveMulticastGroup
  467. } NETLINK_SOCKET_OPTION, *PNETLINK_SOCKET_OPTION;
  468. //
  469. // -------------------------------------------------------------------- Globals
  470. //
  471. //
  472. // -------------------------------------------------------- Function Prototypes
  473. //
  474. NETLINK_API
  475. KSTATUS
  476. NetlinkSendMessage (
  477. PNET_SOCKET Socket,
  478. PNET_PACKET_BUFFER Packet,
  479. PNETWORK_ADDRESS DestinationAddress
  480. );
  481. /*++
  482. Routine Description:
  483. This routine sends a netlink message to the given destination address. The
  484. caller should have already filled the buffer with the netlink header.
  485. Arguments:
  486. Socket - Supplies a pointer to the netlink socket over which to send the
  487. message.
  488. Packet - Supplies a pointer to the network packet to be sent.
  489. DestinationAddress - Supplies a pointer to the destination address to which
  490. the message will be sent.
  491. Return Value:
  492. Status code.
  493. --*/
  494. NETLINK_API
  495. KSTATUS
  496. NetlinkSendMultipartMessage (
  497. PNET_SOCKET Socket,
  498. PNET_PACKET_BUFFER Packet,
  499. PNETWORK_ADDRESS DestinationAddress,
  500. ULONG SequenceNumber
  501. );
  502. /*++
  503. Routine Description:
  504. This routine sends a multipart message packet. It will append the final
  505. DONE message, which the packet must have space for, reset the packet's data
  506. offset to the beginning and then send the entire packet off to the
  507. destination address.
  508. Arguments:
  509. Socket - Supplies a pointer to the network socket from which the packet
  510. will be sent.
  511. Packet - Supplies a pointer to the network packet to send.
  512. DestinationAddress - Supplies a pointer to the network address to which the
  513. packet will be sent.
  514. SequenceNumber - Supplies the sequence number to set in the header of the
  515. DONE message that is appended to the packet.
  516. Return Value:
  517. Status code.
  518. --*/
  519. NETLINK_API
  520. KSTATUS
  521. NetlinkAppendHeader (
  522. PNET_SOCKET Socket,
  523. PNET_PACKET_BUFFER Packet,
  524. ULONG Length,
  525. ULONG SequenceNumber,
  526. USHORT Type,
  527. USHORT Flags
  528. );
  529. /*++
  530. Routine Description:
  531. This routine appends a base netlink header to the given network packet. It
  532. validates if there is enough space remaining in the packet and moves the
  533. data offset forwards to the first byte after the header on success.
  534. Arguments:
  535. Socket - Supplies a pointer to the socket that will send the packet. The
  536. header's port ID is taken from the socket's local address.
  537. Packet - Supplies a pointer to the network packet to which a base netlink
  538. header will be added.
  539. Length - Supplies the length of the netlink message, not including the
  540. header.
  541. SequenceNumber - Supplies the desired sequence number for the netlink
  542. message.
  543. Type - Supplies the message type to be set in the header.
  544. Flags - Supplies a bitmask of netlink message flags to be set. See
  545. NETLINK_HEADER_FLAG_* for definitions.
  546. Return Value:
  547. Status code.
  548. --*/
  549. NETLINK_API
  550. KSTATUS
  551. NetlinkAppendAttribute (
  552. PNET_PACKET_BUFFER Packet,
  553. USHORT Type,
  554. PVOID Data,
  555. USHORT DataLength
  556. );
  557. /*++
  558. Routine Description:
  559. This routine appends a netlink attribute to the given network packet. It
  560. validates that there is enough space for the attribute and moves the
  561. packet's data offset to the first byte after the attribute. The exception
  562. to this rule is if a NULL data buffer is supplied; the packet's data offset
  563. is only moved to the first byte after the attribute header.
  564. Arguments:
  565. Packet - Supplies a pointer to the network packet to which the attribute
  566. will be added.
  567. Type - Supplies the netlink attribute type.
  568. Data - Supplies an optional pointer to the attribute data to be stored in
  569. the network packet. Even if no data buffer is supplied, a data length
  570. may be supplied for the case of child attributes that are yet to be
  571. appended.
  572. DataLength - Supplies the length of the data, in bytes.
  573. Return Value:
  574. Status code.
  575. --*/
  576. NETLINK_API
  577. KSTATUS
  578. NetlinkGetAttribute (
  579. PVOID Attributes,
  580. ULONG AttributesLength,
  581. USHORT Type,
  582. PVOID *Data,
  583. PUSHORT DataLength
  584. );
  585. /*++
  586. Routine Description:
  587. This routine parses the given attributes buffer and returns a pointer to
  588. the desired attribute.
  589. Arguments:
  590. Attributes - Supplies a pointer to the start of the generic command
  591. attributes.
  592. AttributesLength - Supplies the length of the attributes buffer, in bytes.
  593. Type - Supplies the netlink generic attribute type.
  594. Data - Supplies a pointer that receives a pointer to the data for the
  595. requested attribute type.
  596. DataLength - Supplies a pointer that receives the length of the requested
  597. attribute data.
  598. Return Value:
  599. Status code.
  600. --*/
  601. NETLINK_API
  602. KSTATUS
  603. NetlinkJoinMulticastGroup (
  604. PNET_SOCKET Socket,
  605. ULONG GroupId
  606. );
  607. /*++
  608. Routine Description:
  609. This routine joins a socket to a multicast group by updating the socket's
  610. multicast group bitmap and adding the socket to the global list of socket's
  611. joined to multicast groups.
  612. Arguments:
  613. Socket - Supplies a pointer to the socket that is requesting to join a
  614. multicast group.
  615. GroupId - Supplies the ID of the multicast group to join.
  616. Return Value:
  617. Status code.
  618. --*/
  619. NETLINK_API
  620. VOID
  621. NetlinkRemoveSocketsFromMulticastGroups (
  622. ULONG ParentProtocolNumber,
  623. ULONG GroupOffset,
  624. ULONG GroupCount
  625. );
  626. /*++
  627. Routine Description:
  628. This routine removes any socket listening for multicast message from the
  629. groups specified by the offset and count. It will only match sockets for
  630. the given protocol.
  631. Arguments:
  632. ParentProtocolNumber - Supplies the protocol number of the protocol that
  633. owns the given range of multicast groups.
  634. GroupOffset - Supplies the offset into the multicast namespace for the
  635. range of multicast groups from which the sockets should be removed.
  636. GroupCount - Supplies the number of multicast groups from which the sockets
  637. should be removed.
  638. Return Value:
  639. None.
  640. --*/
  641. NETLINK_API
  642. KSTATUS
  643. NetlinkGenericRegisterFamily (
  644. PNETLINK_GENERIC_FAMILY_PROPERTIES Properties,
  645. PNETLINK_GENERIC_FAMILY *Family
  646. );
  647. /*++
  648. Routine Description:
  649. This routine registers a generic netlink family with the generic netlink
  650. core. The core will route messages with a message type equal to the
  651. family's ID to the provided interface.
  652. Arguments:
  653. Properties - Supplies a pointer to the family properties. The netlink
  654. library will not reference this memory after the function returns, a
  655. copy will be made.
  656. Family - Supplies an optional pointer that receives a handle to the
  657. registered family.
  658. Return Value:
  659. Status code.
  660. --*/
  661. NETLINK_API
  662. VOID
  663. NetlinkGenericUnregisterFamily (
  664. PNETLINK_GENERIC_FAMILY Family
  665. );
  666. /*++
  667. Routine Description:
  668. This routine unregisters the given generic netlink family.
  669. Arguments:
  670. Family - Supplies a pointer to the generic netlink family to unregister.
  671. Return Value:
  672. None.
  673. --*/
  674. NETLINK_API
  675. KSTATUS
  676. NetlinkGenericSendCommand (
  677. PNETLINK_GENERIC_FAMILY Family,
  678. PNET_PACKET_BUFFER Packet,
  679. PNETWORK_ADDRESS DestinationAddress
  680. );
  681. /*++
  682. Routine Description:
  683. This routine sends a generic netlink command. The generic header should
  684. already be filled out.
  685. Arguments:
  686. Family - Supplies a pointer to the generic netlink family sending the
  687. command.
  688. Packet - Supplies a pointer to the network packet to be sent.
  689. DestinationAddress - Supplies a pointer to the destination address to which
  690. the command will be sent.
  691. Return Value:
  692. Status code.
  693. --*/
  694. NETLINK_API
  695. KSTATUS
  696. NetlinkGenericSendMulticastCommand (
  697. PNETLINK_GENERIC_FAMILY Family,
  698. PNET_PACKET_BUFFER Packet,
  699. ULONG GroupId
  700. );
  701. /*++
  702. Routine Description:
  703. This routine multicasts the given packet to the specified group after
  704. filling its generic header and base netlink header in with the given
  705. command and information stored in the family structure.
  706. Arguments:
  707. Family - Supplies a pointer to the generic netlink family sending the
  708. multicast command.
  709. Packet - Supplies a pointer to the network packet to be sent.
  710. GroupId - Supplies the family's multicast group ID over which to send the
  711. command.
  712. Return Value:
  713. Status code.
  714. --*/
  715. NETLINK_API
  716. KSTATUS
  717. NetlinkGenericAppendHeaders (
  718. PNETLINK_GENERIC_FAMILY Family,
  719. PNET_PACKET_BUFFER Packet,
  720. ULONG Length,
  721. ULONG SequenceNumber,
  722. USHORT Flags,
  723. UCHAR Command,
  724. UCHAR Version
  725. );
  726. /*++
  727. Routine Description:
  728. This routine appends the base and generic netlink headers to the given
  729. packet, validating that there is enough space remaining in the buffer and
  730. moving the data offset forward to the first byte after the headers once
  731. they have been added.
  732. Arguments:
  733. Family - Supplies a pointer to the netlink generic family to which the
  734. packet belongs.
  735. Packet - Supplies a pointer to the network packet to which the headers will
  736. be appended.
  737. Length - Supplies the length of the generic command payload, not including
  738. any headers.
  739. SequenceNumber - Supplies the desired sequence number for the netlink
  740. message.
  741. Flags - Supplies a bitmask of netlink message flags to be set. See
  742. NETLINK_HEADER_FLAG_* for definitions.
  743. Command - Supplies the generic netlink command to bet set in the header.
  744. Version - Supplies the version number of the command.
  745. Return Value:
  746. Status code.
  747. --*/