netlink.h 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. #ifndef __NET_NETLINK_H
  2. #define __NET_NETLINK_H
  3. #include <linux/types.h>
  4. #include <linux/netlink.h>
  5. #include <linux/jiffies.h>
  6. #include <linux/in6.h>
  7. /* ========================================================================
  8. * Netlink Messages and Attributes Interface (As Seen On TV)
  9. * ------------------------------------------------------------------------
  10. * Messages Interface
  11. * ------------------------------------------------------------------------
  12. *
  13. * Message Format:
  14. * <--- nlmsg_total_size(payload) --->
  15. * <-- nlmsg_msg_size(payload) ->
  16. * +----------+- - -+-------------+- - -+-------- - -
  17. * | nlmsghdr | Pad | Payload | Pad | nlmsghdr
  18. * +----------+- - -+-------------+- - -+-------- - -
  19. * nlmsg_data(nlh)---^ ^
  20. * nlmsg_next(nlh)-----------------------+
  21. *
  22. * Payload Format:
  23. * <---------------------- nlmsg_len(nlh) --------------------->
  24. * <------ hdrlen ------> <- nlmsg_attrlen(nlh, hdrlen) ->
  25. * +----------------------+- - -+--------------------------------+
  26. * | Family Header | Pad | Attributes |
  27. * +----------------------+- - -+--------------------------------+
  28. * nlmsg_attrdata(nlh, hdrlen)---^
  29. *
  30. * Data Structures:
  31. * struct nlmsghdr netlink message header
  32. *
  33. * Message Construction:
  34. * nlmsg_new() create a new netlink message
  35. * nlmsg_put() add a netlink message to an skb
  36. * nlmsg_put_answer() callback based nlmsg_put()
  37. * nlmsg_end() finalize netlink message
  38. * nlmsg_get_pos() return current position in message
  39. * nlmsg_trim() trim part of message
  40. * nlmsg_cancel() cancel message construction
  41. * nlmsg_free() free a netlink message
  42. *
  43. * Message Sending:
  44. * nlmsg_multicast() multicast message to several groups
  45. * nlmsg_unicast() unicast a message to a single socket
  46. * nlmsg_notify() send notification message
  47. *
  48. * Message Length Calculations:
  49. * nlmsg_msg_size(payload) length of message w/o padding
  50. * nlmsg_total_size(payload) length of message w/ padding
  51. * nlmsg_padlen(payload) length of padding at tail
  52. *
  53. * Message Payload Access:
  54. * nlmsg_data(nlh) head of message payload
  55. * nlmsg_len(nlh) length of message payload
  56. * nlmsg_attrdata(nlh, hdrlen) head of attributes data
  57. * nlmsg_attrlen(nlh, hdrlen) length of attributes data
  58. *
  59. * Message Parsing:
  60. * nlmsg_ok(nlh, remaining) does nlh fit into remaining bytes?
  61. * nlmsg_next(nlh, remaining) get next netlink message
  62. * nlmsg_parse() parse attributes of a message
  63. * nlmsg_find_attr() find an attribute in a message
  64. * nlmsg_for_each_msg() loop over all messages
  65. * nlmsg_validate() validate netlink message incl. attrs
  66. * nlmsg_for_each_attr() loop over all attributes
  67. *
  68. * Misc:
  69. * nlmsg_report() report back to application?
  70. *
  71. * ------------------------------------------------------------------------
  72. * Attributes Interface
  73. * ------------------------------------------------------------------------
  74. *
  75. * Attribute Format:
  76. * <------- nla_total_size(payload) ------->
  77. * <---- nla_attr_size(payload) ----->
  78. * +----------+- - -+- - - - - - - - - +- - -+-------- - -
  79. * | Header | Pad | Payload | Pad | Header
  80. * +----------+- - -+- - - - - - - - - +- - -+-------- - -
  81. * <- nla_len(nla) -> ^
  82. * nla_data(nla)----^ |
  83. * nla_next(nla)-----------------------------'
  84. *
  85. * Data Structures:
  86. * struct nlattr netlink attribute header
  87. *
  88. * Attribute Construction:
  89. * nla_reserve(skb, type, len) reserve room for an attribute
  90. * nla_reserve_nohdr(skb, len) reserve room for an attribute w/o hdr
  91. * nla_put(skb, type, len, data) add attribute to skb
  92. * nla_put_nohdr(skb, len, data) add attribute w/o hdr
  93. * nla_append(skb, len, data) append data to skb
  94. *
  95. * Attribute Construction for Basic Types:
  96. * nla_put_u8(skb, type, value) add u8 attribute to skb
  97. * nla_put_u16(skb, type, value) add u16 attribute to skb
  98. * nla_put_u32(skb, type, value) add u32 attribute to skb
  99. * nla_put_u64(skb, type, value) add u64 attribute to skb
  100. * nla_put_s8(skb, type, value) add s8 attribute to skb
  101. * nla_put_s16(skb, type, value) add s16 attribute to skb
  102. * nla_put_s32(skb, type, value) add s32 attribute to skb
  103. * nla_put_s64(skb, type, value) add s64 attribute to skb
  104. * nla_put_string(skb, type, str) add string attribute to skb
  105. * nla_put_flag(skb, type) add flag attribute to skb
  106. * nla_put_msecs(skb, type, jiffies) add msecs attribute to skb
  107. * nla_put_in_addr(skb, type, addr) add IPv4 address attribute to skb
  108. * nla_put_in6_addr(skb, type, addr) add IPv6 address attribute to skb
  109. *
  110. * Nested Attributes Construction:
  111. * nla_nest_start(skb, type) start a nested attribute
  112. * nla_nest_end(skb, nla) finalize a nested attribute
  113. * nla_nest_cancel(skb, nla) cancel nested attribute construction
  114. *
  115. * Attribute Length Calculations:
  116. * nla_attr_size(payload) length of attribute w/o padding
  117. * nla_total_size(payload) length of attribute w/ padding
  118. * nla_padlen(payload) length of padding
  119. *
  120. * Attribute Payload Access:
  121. * nla_data(nla) head of attribute payload
  122. * nla_len(nla) length of attribute payload
  123. *
  124. * Attribute Payload Access for Basic Types:
  125. * nla_get_u8(nla) get payload for a u8 attribute
  126. * nla_get_u16(nla) get payload for a u16 attribute
  127. * nla_get_u32(nla) get payload for a u32 attribute
  128. * nla_get_u64(nla) get payload for a u64 attribute
  129. * nla_get_s8(nla) get payload for a s8 attribute
  130. * nla_get_s16(nla) get payload for a s16 attribute
  131. * nla_get_s32(nla) get payload for a s32 attribute
  132. * nla_get_s64(nla) get payload for a s64 attribute
  133. * nla_get_flag(nla) return 1 if flag is true
  134. * nla_get_msecs(nla) get payload for a msecs attribute
  135. *
  136. * Attribute Misc:
  137. * nla_memcpy(dest, nla, count) copy attribute into memory
  138. * nla_memcmp(nla, data, size) compare attribute with memory area
  139. * nla_strlcpy(dst, nla, size) copy attribute to a sized string
  140. * nla_strcmp(nla, str) compare attribute with string
  141. *
  142. * Attribute Parsing:
  143. * nla_ok(nla, remaining) does nla fit into remaining bytes?
  144. * nla_next(nla, remaining) get next netlink attribute
  145. * nla_validate() validate a stream of attributes
  146. * nla_validate_nested() validate a stream of nested attributes
  147. * nla_find() find attribute in stream of attributes
  148. * nla_find_nested() find attribute in nested attributes
  149. * nla_parse() parse and validate stream of attrs
  150. * nla_parse_nested() parse nested attribuets
  151. * nla_for_each_attr() loop over all attributes
  152. * nla_for_each_nested() loop over the nested attributes
  153. *=========================================================================
  154. */
  155. /**
  156. * Standard attribute types to specify validation policy
  157. */
  158. enum {
  159. NLA_UNSPEC,
  160. NLA_U8,
  161. NLA_U16,
  162. NLA_U32,
  163. NLA_U64,
  164. NLA_STRING,
  165. NLA_FLAG,
  166. NLA_MSECS,
  167. NLA_NESTED,
  168. NLA_NESTED_COMPAT,
  169. NLA_NUL_STRING,
  170. NLA_BINARY,
  171. NLA_S8,
  172. NLA_S16,
  173. NLA_S32,
  174. NLA_S64,
  175. __NLA_TYPE_MAX,
  176. };
  177. #define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1)
  178. /**
  179. * struct nla_policy - attribute validation policy
  180. * @type: Type of attribute or NLA_UNSPEC
  181. * @len: Type specific length of payload
  182. *
  183. * Policies are defined as arrays of this struct, the array must be
  184. * accessible by attribute type up to the highest identifier to be expected.
  185. *
  186. * Meaning of `len' field:
  187. * NLA_STRING Maximum length of string
  188. * NLA_NUL_STRING Maximum length of string (excluding NUL)
  189. * NLA_FLAG Unused
  190. * NLA_BINARY Maximum length of attribute payload
  191. * NLA_NESTED Don't use `len' field -- length verification is
  192. * done by checking len of nested header (or empty)
  193. * NLA_NESTED_COMPAT Minimum length of structure payload
  194. * NLA_U8, NLA_U16,
  195. * NLA_U32, NLA_U64,
  196. * NLA_S8, NLA_S16,
  197. * NLA_S32, NLA_S64,
  198. * NLA_MSECS Leaving the length field zero will verify the
  199. * given type fits, using it verifies minimum length
  200. * just like "All other"
  201. * All other Minimum length of attribute payload
  202. *
  203. * Example:
  204. * static const struct nla_policy my_policy[ATTR_MAX+1] = {
  205. * [ATTR_FOO] = { .type = NLA_U16 },
  206. * [ATTR_BAR] = { .type = NLA_STRING, .len = BARSIZ },
  207. * [ATTR_BAZ] = { .len = sizeof(struct mystruct) },
  208. * };
  209. */
  210. struct nla_policy {
  211. u16 type;
  212. u16 len;
  213. };
  214. /**
  215. * struct nl_info - netlink source information
  216. * @nlh: Netlink message header of original request
  217. * @portid: Netlink PORTID of requesting application
  218. */
  219. struct nl_info {
  220. struct nlmsghdr *nlh;
  221. struct net *nl_net;
  222. u32 portid;
  223. };
  224. int netlink_rcv_skb(struct sk_buff *skb,
  225. int (*cb)(struct sk_buff *, struct nlmsghdr *));
  226. int nlmsg_notify(struct sock *sk, struct sk_buff *skb, u32 portid,
  227. unsigned int group, int report, gfp_t flags);
  228. int nla_validate(const struct nlattr *head, int len, int maxtype,
  229. const struct nla_policy *policy);
  230. int nla_parse(struct nlattr **tb, int maxtype, const struct nlattr *head,
  231. int len, const struct nla_policy *policy);
  232. int nla_policy_len(const struct nla_policy *, int);
  233. struct nlattr *nla_find(const struct nlattr *head, int len, int attrtype);
  234. size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize);
  235. int nla_memcpy(void *dest, const struct nlattr *src, int count);
  236. int nla_memcmp(const struct nlattr *nla, const void *data, size_t size);
  237. int nla_strcmp(const struct nlattr *nla, const char *str);
  238. struct nlattr *__nla_reserve(struct sk_buff *skb, int attrtype, int attrlen);
  239. void *__nla_reserve_nohdr(struct sk_buff *skb, int attrlen);
  240. struct nlattr *nla_reserve(struct sk_buff *skb, int attrtype, int attrlen);
  241. void *nla_reserve_nohdr(struct sk_buff *skb, int attrlen);
  242. void __nla_put(struct sk_buff *skb, int attrtype, int attrlen,
  243. const void *data);
  244. void __nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data);
  245. int nla_put(struct sk_buff *skb, int attrtype, int attrlen, const void *data);
  246. int nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data);
  247. int nla_append(struct sk_buff *skb, int attrlen, const void *data);
  248. /**************************************************************************
  249. * Netlink Messages
  250. **************************************************************************/
  251. /**
  252. * nlmsg_msg_size - length of netlink message not including padding
  253. * @payload: length of message payload
  254. */
  255. static inline int nlmsg_msg_size(int payload)
  256. {
  257. return NLMSG_HDRLEN + payload;
  258. }
  259. /**
  260. * nlmsg_total_size - length of netlink message including padding
  261. * @payload: length of message payload
  262. */
  263. static inline int nlmsg_total_size(int payload)
  264. {
  265. return NLMSG_ALIGN(nlmsg_msg_size(payload));
  266. }
  267. /**
  268. * nlmsg_padlen - length of padding at the message's tail
  269. * @payload: length of message payload
  270. */
  271. static inline int nlmsg_padlen(int payload)
  272. {
  273. return nlmsg_total_size(payload) - nlmsg_msg_size(payload);
  274. }
  275. /**
  276. * nlmsg_data - head of message payload
  277. * @nlh: netlink message header
  278. */
  279. static inline void *nlmsg_data(const struct nlmsghdr *nlh)
  280. {
  281. return (unsigned char *) nlh + NLMSG_HDRLEN;
  282. }
  283. /**
  284. * nlmsg_len - length of message payload
  285. * @nlh: netlink message header
  286. */
  287. static inline int nlmsg_len(const struct nlmsghdr *nlh)
  288. {
  289. return nlh->nlmsg_len - NLMSG_HDRLEN;
  290. }
  291. /**
  292. * nlmsg_attrdata - head of attributes data
  293. * @nlh: netlink message header
  294. * @hdrlen: length of family specific header
  295. */
  296. static inline struct nlattr *nlmsg_attrdata(const struct nlmsghdr *nlh,
  297. int hdrlen)
  298. {
  299. unsigned char *data = nlmsg_data(nlh);
  300. return (struct nlattr *) (data + NLMSG_ALIGN(hdrlen));
  301. }
  302. /**
  303. * nlmsg_attrlen - length of attributes data
  304. * @nlh: netlink message header
  305. * @hdrlen: length of family specific header
  306. */
  307. static inline int nlmsg_attrlen(const struct nlmsghdr *nlh, int hdrlen)
  308. {
  309. return nlmsg_len(nlh) - NLMSG_ALIGN(hdrlen);
  310. }
  311. /**
  312. * nlmsg_ok - check if the netlink message fits into the remaining bytes
  313. * @nlh: netlink message header
  314. * @remaining: number of bytes remaining in message stream
  315. */
  316. static inline int nlmsg_ok(const struct nlmsghdr *nlh, int remaining)
  317. {
  318. return (remaining >= (int) sizeof(struct nlmsghdr) &&
  319. nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
  320. nlh->nlmsg_len <= remaining);
  321. }
  322. /**
  323. * nlmsg_next - next netlink message in message stream
  324. * @nlh: netlink message header
  325. * @remaining: number of bytes remaining in message stream
  326. *
  327. * Returns the next netlink message in the message stream and
  328. * decrements remaining by the size of the current message.
  329. */
  330. static inline struct nlmsghdr *
  331. nlmsg_next(const struct nlmsghdr *nlh, int *remaining)
  332. {
  333. int totlen = NLMSG_ALIGN(nlh->nlmsg_len);
  334. *remaining -= totlen;
  335. return (struct nlmsghdr *) ((unsigned char *) nlh + totlen);
  336. }
  337. /**
  338. * nlmsg_parse - parse attributes of a netlink message
  339. * @nlh: netlink message header
  340. * @hdrlen: length of family specific header
  341. * @tb: destination array with maxtype+1 elements
  342. * @maxtype: maximum attribute type to be expected
  343. * @policy: validation policy
  344. *
  345. * See nla_parse()
  346. */
  347. static inline int nlmsg_parse(const struct nlmsghdr *nlh, int hdrlen,
  348. struct nlattr *tb[], int maxtype,
  349. const struct nla_policy *policy)
  350. {
  351. if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen))
  352. return -EINVAL;
  353. return nla_parse(tb, maxtype, nlmsg_attrdata(nlh, hdrlen),
  354. nlmsg_attrlen(nlh, hdrlen), policy);
  355. }
  356. /**
  357. * nlmsg_find_attr - find a specific attribute in a netlink message
  358. * @nlh: netlink message header
  359. * @hdrlen: length of familiy specific header
  360. * @attrtype: type of attribute to look for
  361. *
  362. * Returns the first attribute which matches the specified type.
  363. */
  364. static inline struct nlattr *nlmsg_find_attr(const struct nlmsghdr *nlh,
  365. int hdrlen, int attrtype)
  366. {
  367. return nla_find(nlmsg_attrdata(nlh, hdrlen),
  368. nlmsg_attrlen(nlh, hdrlen), attrtype);
  369. }
  370. /**
  371. * nlmsg_validate - validate a netlink message including attributes
  372. * @nlh: netlinket message header
  373. * @hdrlen: length of familiy specific header
  374. * @maxtype: maximum attribute type to be expected
  375. * @policy: validation policy
  376. */
  377. static inline int nlmsg_validate(const struct nlmsghdr *nlh,
  378. int hdrlen, int maxtype,
  379. const struct nla_policy *policy)
  380. {
  381. if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen))
  382. return -EINVAL;
  383. return nla_validate(nlmsg_attrdata(nlh, hdrlen),
  384. nlmsg_attrlen(nlh, hdrlen), maxtype, policy);
  385. }
  386. /**
  387. * nlmsg_report - need to report back to application?
  388. * @nlh: netlink message header
  389. *
  390. * Returns 1 if a report back to the application is requested.
  391. */
  392. static inline int nlmsg_report(const struct nlmsghdr *nlh)
  393. {
  394. return !!(nlh->nlmsg_flags & NLM_F_ECHO);
  395. }
  396. /**
  397. * nlmsg_for_each_attr - iterate over a stream of attributes
  398. * @pos: loop counter, set to current attribute
  399. * @nlh: netlink message header
  400. * @hdrlen: length of familiy specific header
  401. * @rem: initialized to len, holds bytes currently remaining in stream
  402. */
  403. #define nlmsg_for_each_attr(pos, nlh, hdrlen, rem) \
  404. nla_for_each_attr(pos, nlmsg_attrdata(nlh, hdrlen), \
  405. nlmsg_attrlen(nlh, hdrlen), rem)
  406. /**
  407. * nlmsg_put - Add a new netlink message to an skb
  408. * @skb: socket buffer to store message in
  409. * @portid: netlink PORTID of requesting application
  410. * @seq: sequence number of message
  411. * @type: message type
  412. * @payload: length of message payload
  413. * @flags: message flags
  414. *
  415. * Returns NULL if the tailroom of the skb is insufficient to store
  416. * the message header and payload.
  417. */
  418. static inline struct nlmsghdr *nlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
  419. int type, int payload, int flags)
  420. {
  421. if (unlikely(skb_tailroom(skb) < nlmsg_total_size(payload)))
  422. return NULL;
  423. return __nlmsg_put(skb, portid, seq, type, payload, flags);
  424. }
  425. /**
  426. * nlmsg_put_answer - Add a new callback based netlink message to an skb
  427. * @skb: socket buffer to store message in
  428. * @cb: netlink callback
  429. * @type: message type
  430. * @payload: length of message payload
  431. * @flags: message flags
  432. *
  433. * Returns NULL if the tailroom of the skb is insufficient to store
  434. * the message header and payload.
  435. */
  436. static inline struct nlmsghdr *nlmsg_put_answer(struct sk_buff *skb,
  437. struct netlink_callback *cb,
  438. int type, int payload,
  439. int flags)
  440. {
  441. return nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
  442. type, payload, flags);
  443. }
  444. /**
  445. * nlmsg_new - Allocate a new netlink message
  446. * @payload: size of the message payload
  447. * @flags: the type of memory to allocate.
  448. *
  449. * Use NLMSG_DEFAULT_SIZE if the size of the payload isn't known
  450. * and a good default is needed.
  451. */
  452. static inline struct sk_buff *nlmsg_new(size_t payload, gfp_t flags)
  453. {
  454. return alloc_skb(nlmsg_total_size(payload), flags);
  455. }
  456. /**
  457. * nlmsg_end - Finalize a netlink message
  458. * @skb: socket buffer the message is stored in
  459. * @nlh: netlink message header
  460. *
  461. * Corrects the netlink message header to include the appeneded
  462. * attributes. Only necessary if attributes have been added to
  463. * the message.
  464. */
  465. static inline void nlmsg_end(struct sk_buff *skb, struct nlmsghdr *nlh)
  466. {
  467. nlh->nlmsg_len = skb_tail_pointer(skb) - (unsigned char *)nlh;
  468. }
  469. /**
  470. * nlmsg_get_pos - return current position in netlink message
  471. * @skb: socket buffer the message is stored in
  472. *
  473. * Returns a pointer to the current tail of the message.
  474. */
  475. static inline void *nlmsg_get_pos(struct sk_buff *skb)
  476. {
  477. return skb_tail_pointer(skb);
  478. }
  479. /**
  480. * nlmsg_trim - Trim message to a mark
  481. * @skb: socket buffer the message is stored in
  482. * @mark: mark to trim to
  483. *
  484. * Trims the message to the provided mark.
  485. */
  486. static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
  487. {
  488. if (mark) {
  489. WARN_ON((unsigned char *) mark < skb->data);
  490. skb_trim(skb, (unsigned char *) mark - skb->data);
  491. }
  492. }
  493. /**
  494. * nlmsg_cancel - Cancel construction of a netlink message
  495. * @skb: socket buffer the message is stored in
  496. * @nlh: netlink message header
  497. *
  498. * Removes the complete netlink message including all
  499. * attributes from the socket buffer again.
  500. */
  501. static inline void nlmsg_cancel(struct sk_buff *skb, struct nlmsghdr *nlh)
  502. {
  503. nlmsg_trim(skb, nlh);
  504. }
  505. /**
  506. * nlmsg_free - free a netlink message
  507. * @skb: socket buffer of netlink message
  508. */
  509. static inline void nlmsg_free(struct sk_buff *skb)
  510. {
  511. kfree_skb(skb);
  512. }
  513. /**
  514. * nlmsg_multicast - multicast a netlink message
  515. * @sk: netlink socket to spread messages to
  516. * @skb: netlink message as socket buffer
  517. * @portid: own netlink portid to avoid sending to yourself
  518. * @group: multicast group id
  519. * @flags: allocation flags
  520. */
  521. static inline int nlmsg_multicast(struct sock *sk, struct sk_buff *skb,
  522. u32 portid, unsigned int group, gfp_t flags)
  523. {
  524. int err;
  525. NETLINK_CB(skb).dst_group = group;
  526. err = netlink_broadcast(sk, skb, portid, group, flags);
  527. if (err > 0)
  528. err = 0;
  529. return err;
  530. }
  531. /**
  532. * nlmsg_unicast - unicast a netlink message
  533. * @sk: netlink socket to spread message to
  534. * @skb: netlink message as socket buffer
  535. * @portid: netlink portid of the destination socket
  536. */
  537. static inline int nlmsg_unicast(struct sock *sk, struct sk_buff *skb, u32 portid)
  538. {
  539. int err;
  540. err = netlink_unicast(sk, skb, portid, MSG_DONTWAIT);
  541. if (err > 0)
  542. err = 0;
  543. return err;
  544. }
  545. /**
  546. * nlmsg_for_each_msg - iterate over a stream of messages
  547. * @pos: loop counter, set to current message
  548. * @head: head of message stream
  549. * @len: length of message stream
  550. * @rem: initialized to len, holds bytes currently remaining in stream
  551. */
  552. #define nlmsg_for_each_msg(pos, head, len, rem) \
  553. for (pos = head, rem = len; \
  554. nlmsg_ok(pos, rem); \
  555. pos = nlmsg_next(pos, &(rem)))
  556. /**
  557. * nl_dump_check_consistent - check if sequence is consistent and advertise if not
  558. * @cb: netlink callback structure that stores the sequence number
  559. * @nlh: netlink message header to write the flag to
  560. *
  561. * This function checks if the sequence (generation) number changed during dump
  562. * and if it did, advertises it in the netlink message header.
  563. *
  564. * The correct way to use it is to set cb->seq to the generation counter when
  565. * all locks for dumping have been acquired, and then call this function for
  566. * each message that is generated.
  567. *
  568. * Note that due to initialisation concerns, 0 is an invalid sequence number
  569. * and must not be used by code that uses this functionality.
  570. */
  571. static inline void
  572. nl_dump_check_consistent(struct netlink_callback *cb,
  573. struct nlmsghdr *nlh)
  574. {
  575. if (cb->prev_seq && cb->seq != cb->prev_seq)
  576. nlh->nlmsg_flags |= NLM_F_DUMP_INTR;
  577. cb->prev_seq = cb->seq;
  578. }
  579. /**************************************************************************
  580. * Netlink Attributes
  581. **************************************************************************/
  582. /**
  583. * nla_attr_size - length of attribute not including padding
  584. * @payload: length of payload
  585. */
  586. static inline int nla_attr_size(int payload)
  587. {
  588. return NLA_HDRLEN + payload;
  589. }
  590. /**
  591. * nla_total_size - total length of attribute including padding
  592. * @payload: length of payload
  593. */
  594. static inline int nla_total_size(int payload)
  595. {
  596. return NLA_ALIGN(nla_attr_size(payload));
  597. }
  598. /**
  599. * nla_padlen - length of padding at the tail of attribute
  600. * @payload: length of payload
  601. */
  602. static inline int nla_padlen(int payload)
  603. {
  604. return nla_total_size(payload) - nla_attr_size(payload);
  605. }
  606. /**
  607. * nla_type - attribute type
  608. * @nla: netlink attribute
  609. */
  610. static inline int nla_type(const struct nlattr *nla)
  611. {
  612. return nla->nla_type & NLA_TYPE_MASK;
  613. }
  614. /**
  615. * nla_data - head of payload
  616. * @nla: netlink attribute
  617. */
  618. static inline void *nla_data(const struct nlattr *nla)
  619. {
  620. return (char *) nla + NLA_HDRLEN;
  621. }
  622. /**
  623. * nla_len - length of payload
  624. * @nla: netlink attribute
  625. */
  626. static inline int nla_len(const struct nlattr *nla)
  627. {
  628. return nla->nla_len - NLA_HDRLEN;
  629. }
  630. /**
  631. * nla_ok - check if the netlink attribute fits into the remaining bytes
  632. * @nla: netlink attribute
  633. * @remaining: number of bytes remaining in attribute stream
  634. */
  635. static inline int nla_ok(const struct nlattr *nla, int remaining)
  636. {
  637. return remaining >= (int) sizeof(*nla) &&
  638. nla->nla_len >= sizeof(*nla) &&
  639. nla->nla_len <= remaining;
  640. }
  641. /**
  642. * nla_next - next netlink attribute in attribute stream
  643. * @nla: netlink attribute
  644. * @remaining: number of bytes remaining in attribute stream
  645. *
  646. * Returns the next netlink attribute in the attribute stream and
  647. * decrements remaining by the size of the current attribute.
  648. */
  649. static inline struct nlattr *nla_next(const struct nlattr *nla, int *remaining)
  650. {
  651. int totlen = NLA_ALIGN(nla->nla_len);
  652. *remaining -= totlen;
  653. return (struct nlattr *) ((char *) nla + totlen);
  654. }
  655. /**
  656. * nla_find_nested - find attribute in a set of nested attributes
  657. * @nla: attribute containing the nested attributes
  658. * @attrtype: type of attribute to look for
  659. *
  660. * Returns the first attribute which matches the specified type.
  661. */
  662. static inline struct nlattr *
  663. nla_find_nested(const struct nlattr *nla, int attrtype)
  664. {
  665. return nla_find(nla_data(nla), nla_len(nla), attrtype);
  666. }
  667. /**
  668. * nla_parse_nested - parse nested attributes
  669. * @tb: destination array with maxtype+1 elements
  670. * @maxtype: maximum attribute type to be expected
  671. * @nla: attribute containing the nested attributes
  672. * @policy: validation policy
  673. *
  674. * See nla_parse()
  675. */
  676. static inline int nla_parse_nested(struct nlattr *tb[], int maxtype,
  677. const struct nlattr *nla,
  678. const struct nla_policy *policy)
  679. {
  680. return nla_parse(tb, maxtype, nla_data(nla), nla_len(nla), policy);
  681. }
  682. /**
  683. * nla_put_u8 - Add a u8 netlink attribute to a socket buffer
  684. * @skb: socket buffer to add attribute to
  685. * @attrtype: attribute type
  686. * @value: numeric value
  687. */
  688. static inline int nla_put_u8(struct sk_buff *skb, int attrtype, u8 value)
  689. {
  690. return nla_put(skb, attrtype, sizeof(u8), &value);
  691. }
  692. /**
  693. * nla_put_u16 - Add a u16 netlink attribute to a socket buffer
  694. * @skb: socket buffer to add attribute to
  695. * @attrtype: attribute type
  696. * @value: numeric value
  697. */
  698. static inline int nla_put_u16(struct sk_buff *skb, int attrtype, u16 value)
  699. {
  700. return nla_put(skb, attrtype, sizeof(u16), &value);
  701. }
  702. /**
  703. * nla_put_be16 - Add a __be16 netlink attribute to a socket buffer
  704. * @skb: socket buffer to add attribute to
  705. * @attrtype: attribute type
  706. * @value: numeric value
  707. */
  708. static inline int nla_put_be16(struct sk_buff *skb, int attrtype, __be16 value)
  709. {
  710. return nla_put(skb, attrtype, sizeof(__be16), &value);
  711. }
  712. /**
  713. * nla_put_net16 - Add 16-bit network byte order netlink attribute to a socket buffer
  714. * @skb: socket buffer to add attribute to
  715. * @attrtype: attribute type
  716. * @value: numeric value
  717. */
  718. static inline int nla_put_net16(struct sk_buff *skb, int attrtype, __be16 value)
  719. {
  720. return nla_put_be16(skb, attrtype | NLA_F_NET_BYTEORDER, value);
  721. }
  722. /**
  723. * nla_put_le16 - Add a __le16 netlink attribute to a socket buffer
  724. * @skb: socket buffer to add attribute to
  725. * @attrtype: attribute type
  726. * @value: numeric value
  727. */
  728. static inline int nla_put_le16(struct sk_buff *skb, int attrtype, __le16 value)
  729. {
  730. return nla_put(skb, attrtype, sizeof(__le16), &value);
  731. }
  732. /**
  733. * nla_put_u32 - Add a u32 netlink attribute to a socket buffer
  734. * @skb: socket buffer to add attribute to
  735. * @attrtype: attribute type
  736. * @value: numeric value
  737. */
  738. static inline int nla_put_u32(struct sk_buff *skb, int attrtype, u32 value)
  739. {
  740. return nla_put(skb, attrtype, sizeof(u32), &value);
  741. }
  742. /**
  743. * nla_put_be32 - Add a __be32 netlink attribute to a socket buffer
  744. * @skb: socket buffer to add attribute to
  745. * @attrtype: attribute type
  746. * @value: numeric value
  747. */
  748. static inline int nla_put_be32(struct sk_buff *skb, int attrtype, __be32 value)
  749. {
  750. return nla_put(skb, attrtype, sizeof(__be32), &value);
  751. }
  752. /**
  753. * nla_put_net32 - Add 32-bit network byte order netlink attribute to a socket buffer
  754. * @skb: socket buffer to add attribute to
  755. * @attrtype: attribute type
  756. * @value: numeric value
  757. */
  758. static inline int nla_put_net32(struct sk_buff *skb, int attrtype, __be32 value)
  759. {
  760. return nla_put_be32(skb, attrtype | NLA_F_NET_BYTEORDER, value);
  761. }
  762. /**
  763. * nla_put_le32 - Add a __le32 netlink attribute to a socket buffer
  764. * @skb: socket buffer to add attribute to
  765. * @attrtype: attribute type
  766. * @value: numeric value
  767. */
  768. static inline int nla_put_le32(struct sk_buff *skb, int attrtype, __le32 value)
  769. {
  770. return nla_put(skb, attrtype, sizeof(__le32), &value);
  771. }
  772. /**
  773. * nla_put_u64 - Add a u64 netlink attribute to a socket buffer
  774. * @skb: socket buffer to add attribute to
  775. * @attrtype: attribute type
  776. * @value: numeric value
  777. */
  778. static inline int nla_put_u64(struct sk_buff *skb, int attrtype, u64 value)
  779. {
  780. return nla_put(skb, attrtype, sizeof(u64), &value);
  781. }
  782. /**
  783. * nla_put_be64 - Add a __be64 netlink attribute to a socket buffer
  784. * @skb: socket buffer to add attribute to
  785. * @attrtype: attribute type
  786. * @value: numeric value
  787. */
  788. static inline int nla_put_be64(struct sk_buff *skb, int attrtype, __be64 value)
  789. {
  790. return nla_put(skb, attrtype, sizeof(__be64), &value);
  791. }
  792. /**
  793. * nla_put_net64 - Add 64-bit network byte order netlink attribute to a socket buffer
  794. * @skb: socket buffer to add attribute to
  795. * @attrtype: attribute type
  796. * @value: numeric value
  797. */
  798. static inline int nla_put_net64(struct sk_buff *skb, int attrtype, __be64 value)
  799. {
  800. return nla_put_be64(skb, attrtype | NLA_F_NET_BYTEORDER, value);
  801. }
  802. /**
  803. * nla_put_le64 - Add a __le64 netlink attribute to a socket buffer
  804. * @skb: socket buffer to add attribute to
  805. * @attrtype: attribute type
  806. * @value: numeric value
  807. */
  808. static inline int nla_put_le64(struct sk_buff *skb, int attrtype, __le64 value)
  809. {
  810. return nla_put(skb, attrtype, sizeof(__le64), &value);
  811. }
  812. /**
  813. * nla_put_s8 - Add a s8 netlink attribute to a socket buffer
  814. * @skb: socket buffer to add attribute to
  815. * @attrtype: attribute type
  816. * @value: numeric value
  817. */
  818. static inline int nla_put_s8(struct sk_buff *skb, int attrtype, s8 value)
  819. {
  820. return nla_put(skb, attrtype, sizeof(s8), &value);
  821. }
  822. /**
  823. * nla_put_s16 - Add a s16 netlink attribute to a socket buffer
  824. * @skb: socket buffer to add attribute to
  825. * @attrtype: attribute type
  826. * @value: numeric value
  827. */
  828. static inline int nla_put_s16(struct sk_buff *skb, int attrtype, s16 value)
  829. {
  830. return nla_put(skb, attrtype, sizeof(s16), &value);
  831. }
  832. /**
  833. * nla_put_s32 - Add a s32 netlink attribute to a socket buffer
  834. * @skb: socket buffer to add attribute to
  835. * @attrtype: attribute type
  836. * @value: numeric value
  837. */
  838. static inline int nla_put_s32(struct sk_buff *skb, int attrtype, s32 value)
  839. {
  840. return nla_put(skb, attrtype, sizeof(s32), &value);
  841. }
  842. /**
  843. * nla_put_s64 - Add a s64 netlink attribute to a socket buffer
  844. * @skb: socket buffer to add attribute to
  845. * @attrtype: attribute type
  846. * @value: numeric value
  847. */
  848. static inline int nla_put_s64(struct sk_buff *skb, int attrtype, s64 value)
  849. {
  850. return nla_put(skb, attrtype, sizeof(s64), &value);
  851. }
  852. /**
  853. * nla_put_string - Add a string netlink attribute to a socket buffer
  854. * @skb: socket buffer to add attribute to
  855. * @attrtype: attribute type
  856. * @str: NUL terminated string
  857. */
  858. static inline int nla_put_string(struct sk_buff *skb, int attrtype,
  859. const char *str)
  860. {
  861. return nla_put(skb, attrtype, strlen(str) + 1, str);
  862. }
  863. /**
  864. * nla_put_flag - Add a flag netlink attribute to a socket buffer
  865. * @skb: socket buffer to add attribute to
  866. * @attrtype: attribute type
  867. */
  868. static inline int nla_put_flag(struct sk_buff *skb, int attrtype)
  869. {
  870. return nla_put(skb, attrtype, 0, NULL);
  871. }
  872. /**
  873. * nla_put_msecs - Add a msecs netlink attribute to a socket buffer
  874. * @skb: socket buffer to add attribute to
  875. * @attrtype: attribute type
  876. * @njiffies: number of jiffies to convert to msecs
  877. */
  878. static inline int nla_put_msecs(struct sk_buff *skb, int attrtype,
  879. unsigned long njiffies)
  880. {
  881. u64 tmp = jiffies_to_msecs(njiffies);
  882. return nla_put(skb, attrtype, sizeof(u64), &tmp);
  883. }
  884. /**
  885. * nla_put_in_addr - Add an IPv4 address netlink attribute to a socket
  886. * buffer
  887. * @skb: socket buffer to add attribute to
  888. * @attrtype: attribute type
  889. * @addr: IPv4 address
  890. */
  891. static inline int nla_put_in_addr(struct sk_buff *skb, int attrtype,
  892. __be32 addr)
  893. {
  894. return nla_put_be32(skb, attrtype, addr);
  895. }
  896. /**
  897. * nla_put_in6_addr - Add an IPv6 address netlink attribute to a socket
  898. * buffer
  899. * @skb: socket buffer to add attribute to
  900. * @attrtype: attribute type
  901. * @addr: IPv6 address
  902. */
  903. static inline int nla_put_in6_addr(struct sk_buff *skb, int attrtype,
  904. const struct in6_addr *addr)
  905. {
  906. return nla_put(skb, attrtype, sizeof(*addr), addr);
  907. }
  908. /**
  909. * nla_get_u32 - return payload of u32 attribute
  910. * @nla: u32 netlink attribute
  911. */
  912. static inline u32 nla_get_u32(const struct nlattr *nla)
  913. {
  914. return *(u32 *) nla_data(nla);
  915. }
  916. /**
  917. * nla_get_be32 - return payload of __be32 attribute
  918. * @nla: __be32 netlink attribute
  919. */
  920. static inline __be32 nla_get_be32(const struct nlattr *nla)
  921. {
  922. return *(__be32 *) nla_data(nla);
  923. }
  924. /**
  925. * nla_get_u16 - return payload of u16 attribute
  926. * @nla: u16 netlink attribute
  927. */
  928. static inline u16 nla_get_u16(const struct nlattr *nla)
  929. {
  930. return *(u16 *) nla_data(nla);
  931. }
  932. /**
  933. * nla_get_be16 - return payload of __be16 attribute
  934. * @nla: __be16 netlink attribute
  935. */
  936. static inline __be16 nla_get_be16(const struct nlattr *nla)
  937. {
  938. return *(__be16 *) nla_data(nla);
  939. }
  940. /**
  941. * nla_get_le16 - return payload of __le16 attribute
  942. * @nla: __le16 netlink attribute
  943. */
  944. static inline __le16 nla_get_le16(const struct nlattr *nla)
  945. {
  946. return *(__le16 *) nla_data(nla);
  947. }
  948. /**
  949. * nla_get_u8 - return payload of u8 attribute
  950. * @nla: u8 netlink attribute
  951. */
  952. static inline u8 nla_get_u8(const struct nlattr *nla)
  953. {
  954. return *(u8 *) nla_data(nla);
  955. }
  956. /**
  957. * nla_get_u64 - return payload of u64 attribute
  958. * @nla: u64 netlink attribute
  959. */
  960. static inline u64 nla_get_u64(const struct nlattr *nla)
  961. {
  962. u64 tmp;
  963. nla_memcpy(&tmp, nla, sizeof(tmp));
  964. return tmp;
  965. }
  966. /**
  967. * nla_get_be64 - return payload of __be64 attribute
  968. * @nla: __be64 netlink attribute
  969. */
  970. static inline __be64 nla_get_be64(const struct nlattr *nla)
  971. {
  972. __be64 tmp;
  973. nla_memcpy(&tmp, nla, sizeof(tmp));
  974. return tmp;
  975. }
  976. /**
  977. * nla_get_s32 - return payload of s32 attribute
  978. * @nla: s32 netlink attribute
  979. */
  980. static inline s32 nla_get_s32(const struct nlattr *nla)
  981. {
  982. return *(s32 *) nla_data(nla);
  983. }
  984. /**
  985. * nla_get_s16 - return payload of s16 attribute
  986. * @nla: s16 netlink attribute
  987. */
  988. static inline s16 nla_get_s16(const struct nlattr *nla)
  989. {
  990. return *(s16 *) nla_data(nla);
  991. }
  992. /**
  993. * nla_get_s8 - return payload of s8 attribute
  994. * @nla: s8 netlink attribute
  995. */
  996. static inline s8 nla_get_s8(const struct nlattr *nla)
  997. {
  998. return *(s8 *) nla_data(nla);
  999. }
  1000. /**
  1001. * nla_get_s64 - return payload of s64 attribute
  1002. * @nla: s64 netlink attribute
  1003. */
  1004. static inline s64 nla_get_s64(const struct nlattr *nla)
  1005. {
  1006. s64 tmp;
  1007. nla_memcpy(&tmp, nla, sizeof(tmp));
  1008. return tmp;
  1009. }
  1010. /**
  1011. * nla_get_flag - return payload of flag attribute
  1012. * @nla: flag netlink attribute
  1013. */
  1014. static inline int nla_get_flag(const struct nlattr *nla)
  1015. {
  1016. return !!nla;
  1017. }
  1018. /**
  1019. * nla_get_msecs - return payload of msecs attribute
  1020. * @nla: msecs netlink attribute
  1021. *
  1022. * Returns the number of milliseconds in jiffies.
  1023. */
  1024. static inline unsigned long nla_get_msecs(const struct nlattr *nla)
  1025. {
  1026. u64 msecs = nla_get_u64(nla);
  1027. return msecs_to_jiffies((unsigned long) msecs);
  1028. }
  1029. /**
  1030. * nla_get_in_addr - return payload of IPv4 address attribute
  1031. * @nla: IPv4 address netlink attribute
  1032. */
  1033. static inline __be32 nla_get_in_addr(const struct nlattr *nla)
  1034. {
  1035. return *(__be32 *) nla_data(nla);
  1036. }
  1037. /**
  1038. * nla_get_in6_addr - return payload of IPv6 address attribute
  1039. * @nla: IPv6 address netlink attribute
  1040. */
  1041. static inline struct in6_addr nla_get_in6_addr(const struct nlattr *nla)
  1042. {
  1043. struct in6_addr tmp;
  1044. nla_memcpy(&tmp, nla, sizeof(tmp));
  1045. return tmp;
  1046. }
  1047. /**
  1048. * nla_nest_start - Start a new level of nested attributes
  1049. * @skb: socket buffer to add attributes to
  1050. * @attrtype: attribute type of container
  1051. *
  1052. * Returns the container attribute
  1053. */
  1054. static inline struct nlattr *nla_nest_start(struct sk_buff *skb, int attrtype)
  1055. {
  1056. struct nlattr *start = (struct nlattr *)skb_tail_pointer(skb);
  1057. if (nla_put(skb, attrtype, 0, NULL) < 0)
  1058. return NULL;
  1059. return start;
  1060. }
  1061. /**
  1062. * nla_nest_end - Finalize nesting of attributes
  1063. * @skb: socket buffer the attributes are stored in
  1064. * @start: container attribute
  1065. *
  1066. * Corrects the container attribute header to include the all
  1067. * appeneded attributes.
  1068. *
  1069. * Returns the total data length of the skb.
  1070. */
  1071. static inline int nla_nest_end(struct sk_buff *skb, struct nlattr *start)
  1072. {
  1073. start->nla_len = skb_tail_pointer(skb) - (unsigned char *)start;
  1074. return skb->len;
  1075. }
  1076. /**
  1077. * nla_nest_cancel - Cancel nesting of attributes
  1078. * @skb: socket buffer the message is stored in
  1079. * @start: container attribute
  1080. *
  1081. * Removes the container attribute and including all nested
  1082. * attributes. Returns -EMSGSIZE
  1083. */
  1084. static inline void nla_nest_cancel(struct sk_buff *skb, struct nlattr *start)
  1085. {
  1086. nlmsg_trim(skb, start);
  1087. }
  1088. /**
  1089. * nla_validate_nested - Validate a stream of nested attributes
  1090. * @start: container attribute
  1091. * @maxtype: maximum attribute type to be expected
  1092. * @policy: validation policy
  1093. *
  1094. * Validates all attributes in the nested attribute stream against the
  1095. * specified policy. Attributes with a type exceeding maxtype will be
  1096. * ignored. See documenation of struct nla_policy for more details.
  1097. *
  1098. * Returns 0 on success or a negative error code.
  1099. */
  1100. static inline int nla_validate_nested(const struct nlattr *start, int maxtype,
  1101. const struct nla_policy *policy)
  1102. {
  1103. return nla_validate(nla_data(start), nla_len(start), maxtype, policy);
  1104. }
  1105. /**
  1106. * nla_for_each_attr - iterate over a stream of attributes
  1107. * @pos: loop counter, set to current attribute
  1108. * @head: head of attribute stream
  1109. * @len: length of attribute stream
  1110. * @rem: initialized to len, holds bytes currently remaining in stream
  1111. */
  1112. #define nla_for_each_attr(pos, head, len, rem) \
  1113. for (pos = head, rem = len; \
  1114. nla_ok(pos, rem); \
  1115. pos = nla_next(pos, &(rem)))
  1116. /**
  1117. * nla_for_each_nested - iterate over nested attributes
  1118. * @pos: loop counter, set to current attribute
  1119. * @nla: attribute containing the nested attributes
  1120. * @rem: initialized to len, holds bytes currently remaining in stream
  1121. */
  1122. #define nla_for_each_nested(pos, nla, rem) \
  1123. nla_for_each_attr(pos, nla_data(nla), nla_len(nla), rem)
  1124. /**
  1125. * nla_is_last - Test if attribute is last in stream
  1126. * @nla: attribute to test
  1127. * @rem: bytes remaining in stream
  1128. */
  1129. static inline bool nla_is_last(const struct nlattr *nla, int rem)
  1130. {
  1131. return nla->nla_len == rem;
  1132. }
  1133. #endif