netlink_compat.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. /*
  2. * Copyright (c) 2014, Ericsson AB
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the names of the copyright holders nor the names of its
  14. * contributors may be used to endorse or promote products derived from
  15. * this software without specific prior written permission.
  16. *
  17. * Alternatively, this software may be distributed under the terms of the
  18. * GNU General Public License ("GPL") version 2 as published by the Free
  19. * Software Foundation.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. * POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #include "core.h"
  34. #include "bearer.h"
  35. #include "link.h"
  36. #include "name_table.h"
  37. #include "socket.h"
  38. #include "node.h"
  39. #include "net.h"
  40. #include <net/genetlink.h>
  41. #include <linux/tipc_config.h>
  42. /* The legacy API had an artificial message length limit called
  43. * ULTRA_STRING_MAX_LEN.
  44. */
  45. #define ULTRA_STRING_MAX_LEN 32768
  46. #define TIPC_SKB_MAX TLV_SPACE(ULTRA_STRING_MAX_LEN)
  47. #define REPLY_TRUNCATED "<truncated>\n"
  48. struct tipc_nl_compat_msg {
  49. u16 cmd;
  50. int rep_type;
  51. int rep_size;
  52. int req_type;
  53. struct sk_buff *rep;
  54. struct tlv_desc *req;
  55. struct sock *dst_sk;
  56. };
  57. struct tipc_nl_compat_cmd_dump {
  58. int (*header)(struct tipc_nl_compat_msg *);
  59. int (*dumpit)(struct sk_buff *, struct netlink_callback *);
  60. int (*format)(struct tipc_nl_compat_msg *msg, struct nlattr **attrs);
  61. };
  62. struct tipc_nl_compat_cmd_doit {
  63. int (*doit)(struct sk_buff *skb, struct genl_info *info);
  64. int (*transcode)(struct sk_buff *skb, struct tipc_nl_compat_msg *msg);
  65. };
  66. static int tipc_skb_tailroom(struct sk_buff *skb)
  67. {
  68. int tailroom;
  69. int limit;
  70. tailroom = skb_tailroom(skb);
  71. limit = TIPC_SKB_MAX - skb->len;
  72. if (tailroom < limit)
  73. return tailroom;
  74. return limit;
  75. }
  76. static int tipc_add_tlv(struct sk_buff *skb, u16 type, void *data, u16 len)
  77. {
  78. struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(skb);
  79. if (tipc_skb_tailroom(skb) < TLV_SPACE(len))
  80. return -EMSGSIZE;
  81. skb_put(skb, TLV_SPACE(len));
  82. tlv->tlv_type = htons(type);
  83. tlv->tlv_len = htons(TLV_LENGTH(len));
  84. if (len && data)
  85. memcpy(TLV_DATA(tlv), data, len);
  86. return 0;
  87. }
  88. static void tipc_tlv_init(struct sk_buff *skb, u16 type)
  89. {
  90. struct tlv_desc *tlv = (struct tlv_desc *)skb->data;
  91. TLV_SET_LEN(tlv, 0);
  92. TLV_SET_TYPE(tlv, type);
  93. skb_put(skb, sizeof(struct tlv_desc));
  94. }
  95. static int tipc_tlv_sprintf(struct sk_buff *skb, const char *fmt, ...)
  96. {
  97. int n;
  98. u16 len;
  99. u32 rem;
  100. char *buf;
  101. struct tlv_desc *tlv;
  102. va_list args;
  103. rem = tipc_skb_tailroom(skb);
  104. tlv = (struct tlv_desc *)skb->data;
  105. len = TLV_GET_LEN(tlv);
  106. buf = TLV_DATA(tlv) + len;
  107. va_start(args, fmt);
  108. n = vscnprintf(buf, rem, fmt, args);
  109. va_end(args);
  110. TLV_SET_LEN(tlv, n + len);
  111. skb_put(skb, n);
  112. return n;
  113. }
  114. static struct sk_buff *tipc_tlv_alloc(int size)
  115. {
  116. int hdr_len;
  117. struct sk_buff *buf;
  118. size = TLV_SPACE(size);
  119. hdr_len = nlmsg_total_size(GENL_HDRLEN + TIPC_GENL_HDRLEN);
  120. buf = alloc_skb(hdr_len + size, GFP_KERNEL);
  121. if (!buf)
  122. return NULL;
  123. skb_reserve(buf, hdr_len);
  124. return buf;
  125. }
  126. static struct sk_buff *tipc_get_err_tlv(char *str)
  127. {
  128. int str_len = strlen(str) + 1;
  129. struct sk_buff *buf;
  130. buf = tipc_tlv_alloc(TLV_SPACE(str_len));
  131. if (buf)
  132. tipc_add_tlv(buf, TIPC_TLV_ERROR_STRING, str, str_len);
  133. return buf;
  134. }
  135. static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
  136. struct tipc_nl_compat_msg *msg,
  137. struct sk_buff *arg)
  138. {
  139. int len = 0;
  140. int err;
  141. struct sk_buff *buf;
  142. struct nlmsghdr *nlmsg;
  143. struct netlink_callback cb;
  144. memset(&cb, 0, sizeof(cb));
  145. cb.nlh = (struct nlmsghdr *)arg->data;
  146. cb.skb = arg;
  147. buf = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  148. if (!buf)
  149. return -ENOMEM;
  150. buf->sk = msg->dst_sk;
  151. do {
  152. int rem;
  153. len = (*cmd->dumpit)(buf, &cb);
  154. nlmsg_for_each_msg(nlmsg, nlmsg_hdr(buf), len, rem) {
  155. struct nlattr **attrs;
  156. err = tipc_nlmsg_parse(nlmsg, &attrs);
  157. if (err)
  158. goto err_out;
  159. err = (*cmd->format)(msg, attrs);
  160. if (err)
  161. goto err_out;
  162. if (tipc_skb_tailroom(msg->rep) <= 1) {
  163. err = -EMSGSIZE;
  164. goto err_out;
  165. }
  166. }
  167. skb_reset_tail_pointer(buf);
  168. buf->len = 0;
  169. } while (len);
  170. err = 0;
  171. err_out:
  172. kfree_skb(buf);
  173. if (err == -EMSGSIZE) {
  174. /* The legacy API only considered messages filling
  175. * "ULTRA_STRING_MAX_LEN" to be truncated.
  176. */
  177. if ((TIPC_SKB_MAX - msg->rep->len) <= 1) {
  178. char *tail = skb_tail_pointer(msg->rep);
  179. if (*tail != '\0')
  180. sprintf(tail - sizeof(REPLY_TRUNCATED) - 1,
  181. REPLY_TRUNCATED);
  182. }
  183. return 0;
  184. }
  185. return err;
  186. }
  187. static int tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
  188. struct tipc_nl_compat_msg *msg)
  189. {
  190. int err;
  191. struct sk_buff *arg;
  192. if (msg->req_type && !TLV_CHECK_TYPE(msg->req, msg->req_type))
  193. return -EINVAL;
  194. msg->rep = tipc_tlv_alloc(msg->rep_size);
  195. if (!msg->rep)
  196. return -ENOMEM;
  197. if (msg->rep_type)
  198. tipc_tlv_init(msg->rep, msg->rep_type);
  199. if (cmd->header)
  200. (*cmd->header)(msg);
  201. arg = nlmsg_new(0, GFP_KERNEL);
  202. if (!arg) {
  203. kfree_skb(msg->rep);
  204. return -ENOMEM;
  205. }
  206. err = __tipc_nl_compat_dumpit(cmd, msg, arg);
  207. if (err)
  208. kfree_skb(msg->rep);
  209. kfree_skb(arg);
  210. return err;
  211. }
  212. static int __tipc_nl_compat_doit(struct tipc_nl_compat_cmd_doit *cmd,
  213. struct tipc_nl_compat_msg *msg)
  214. {
  215. int err;
  216. struct sk_buff *doit_buf;
  217. struct sk_buff *trans_buf;
  218. struct nlattr **attrbuf;
  219. struct genl_info info;
  220. trans_buf = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
  221. if (!trans_buf)
  222. return -ENOMEM;
  223. err = (*cmd->transcode)(trans_buf, msg);
  224. if (err)
  225. goto trans_out;
  226. attrbuf = kmalloc((tipc_genl_family.maxattr + 1) *
  227. sizeof(struct nlattr *), GFP_KERNEL);
  228. if (!attrbuf) {
  229. err = -ENOMEM;
  230. goto trans_out;
  231. }
  232. err = nla_parse(attrbuf, tipc_genl_family.maxattr,
  233. (const struct nlattr *)trans_buf->data,
  234. trans_buf->len, NULL);
  235. if (err)
  236. goto parse_out;
  237. doit_buf = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
  238. if (!doit_buf) {
  239. err = -ENOMEM;
  240. goto parse_out;
  241. }
  242. doit_buf->sk = msg->dst_sk;
  243. memset(&info, 0, sizeof(info));
  244. info.attrs = attrbuf;
  245. err = (*cmd->doit)(doit_buf, &info);
  246. kfree_skb(doit_buf);
  247. parse_out:
  248. kfree(attrbuf);
  249. trans_out:
  250. kfree_skb(trans_buf);
  251. return err;
  252. }
  253. static int tipc_nl_compat_doit(struct tipc_nl_compat_cmd_doit *cmd,
  254. struct tipc_nl_compat_msg *msg)
  255. {
  256. int err;
  257. if (msg->req_type && !TLV_CHECK_TYPE(msg->req, msg->req_type))
  258. return -EINVAL;
  259. err = __tipc_nl_compat_doit(cmd, msg);
  260. if (err)
  261. return err;
  262. /* The legacy API considered an empty message a success message */
  263. msg->rep = tipc_tlv_alloc(0);
  264. if (!msg->rep)
  265. return -ENOMEM;
  266. return 0;
  267. }
  268. static int tipc_nl_compat_bearer_dump(struct tipc_nl_compat_msg *msg,
  269. struct nlattr **attrs)
  270. {
  271. struct nlattr *bearer[TIPC_NLA_BEARER_MAX + 1];
  272. nla_parse_nested(bearer, TIPC_NLA_BEARER_MAX, attrs[TIPC_NLA_BEARER],
  273. NULL);
  274. return tipc_add_tlv(msg->rep, TIPC_TLV_BEARER_NAME,
  275. nla_data(bearer[TIPC_NLA_BEARER_NAME]),
  276. nla_len(bearer[TIPC_NLA_BEARER_NAME]));
  277. }
  278. static int tipc_nl_compat_bearer_enable(struct sk_buff *skb,
  279. struct tipc_nl_compat_msg *msg)
  280. {
  281. struct nlattr *prop;
  282. struct nlattr *bearer;
  283. struct tipc_bearer_config *b;
  284. b = (struct tipc_bearer_config *)TLV_DATA(msg->req);
  285. bearer = nla_nest_start(skb, TIPC_NLA_BEARER);
  286. if (!bearer)
  287. return -EMSGSIZE;
  288. if (nla_put_string(skb, TIPC_NLA_BEARER_NAME, b->name))
  289. return -EMSGSIZE;
  290. if (nla_put_u32(skb, TIPC_NLA_BEARER_DOMAIN, ntohl(b->disc_domain)))
  291. return -EMSGSIZE;
  292. if (ntohl(b->priority) <= TIPC_MAX_LINK_PRI) {
  293. prop = nla_nest_start(skb, TIPC_NLA_BEARER_PROP);
  294. if (!prop)
  295. return -EMSGSIZE;
  296. if (nla_put_u32(skb, TIPC_NLA_PROP_PRIO, ntohl(b->priority)))
  297. return -EMSGSIZE;
  298. nla_nest_end(skb, prop);
  299. }
  300. nla_nest_end(skb, bearer);
  301. return 0;
  302. }
  303. static int tipc_nl_compat_bearer_disable(struct sk_buff *skb,
  304. struct tipc_nl_compat_msg *msg)
  305. {
  306. char *name;
  307. struct nlattr *bearer;
  308. name = (char *)TLV_DATA(msg->req);
  309. bearer = nla_nest_start(skb, TIPC_NLA_BEARER);
  310. if (!bearer)
  311. return -EMSGSIZE;
  312. if (nla_put_string(skb, TIPC_NLA_BEARER_NAME, name))
  313. return -EMSGSIZE;
  314. nla_nest_end(skb, bearer);
  315. return 0;
  316. }
  317. static inline u32 perc(u32 count, u32 total)
  318. {
  319. return (count * 100 + (total / 2)) / total;
  320. }
  321. static void __fill_bc_link_stat(struct tipc_nl_compat_msg *msg,
  322. struct nlattr *prop[], struct nlattr *stats[])
  323. {
  324. tipc_tlv_sprintf(msg->rep, " Window:%u packets\n",
  325. nla_get_u32(prop[TIPC_NLA_PROP_WIN]));
  326. tipc_tlv_sprintf(msg->rep,
  327. " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
  328. nla_get_u32(stats[TIPC_NLA_STATS_RX_INFO]),
  329. nla_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTS]),
  330. nla_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTED]),
  331. nla_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLES]),
  332. nla_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLED]));
  333. tipc_tlv_sprintf(msg->rep,
  334. " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
  335. nla_get_u32(stats[TIPC_NLA_STATS_TX_INFO]),
  336. nla_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTS]),
  337. nla_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTED]),
  338. nla_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLES]),
  339. nla_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLED]));
  340. tipc_tlv_sprintf(msg->rep, " RX naks:%u defs:%u dups:%u\n",
  341. nla_get_u32(stats[TIPC_NLA_STATS_RX_NACKS]),
  342. nla_get_u32(stats[TIPC_NLA_STATS_RX_DEFERRED]),
  343. nla_get_u32(stats[TIPC_NLA_STATS_DUPLICATES]));
  344. tipc_tlv_sprintf(msg->rep, " TX naks:%u acks:%u dups:%u\n",
  345. nla_get_u32(stats[TIPC_NLA_STATS_TX_NACKS]),
  346. nla_get_u32(stats[TIPC_NLA_STATS_TX_ACKS]),
  347. nla_get_u32(stats[TIPC_NLA_STATS_RETRANSMITTED]));
  348. tipc_tlv_sprintf(msg->rep,
  349. " Congestion link:%u Send queue max:%u avg:%u",
  350. nla_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]),
  351. nla_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]),
  352. nla_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE]));
  353. }
  354. static int tipc_nl_compat_link_stat_dump(struct tipc_nl_compat_msg *msg,
  355. struct nlattr **attrs)
  356. {
  357. char *name;
  358. struct nlattr *link[TIPC_NLA_LINK_MAX + 1];
  359. struct nlattr *prop[TIPC_NLA_PROP_MAX + 1];
  360. struct nlattr *stats[TIPC_NLA_STATS_MAX + 1];
  361. nla_parse_nested(link, TIPC_NLA_LINK_MAX, attrs[TIPC_NLA_LINK], NULL);
  362. nla_parse_nested(prop, TIPC_NLA_PROP_MAX, link[TIPC_NLA_LINK_PROP],
  363. NULL);
  364. nla_parse_nested(stats, TIPC_NLA_STATS_MAX, link[TIPC_NLA_LINK_STATS],
  365. NULL);
  366. name = (char *)TLV_DATA(msg->req);
  367. if (strcmp(name, nla_data(link[TIPC_NLA_LINK_NAME])) != 0)
  368. return 0;
  369. tipc_tlv_sprintf(msg->rep, "\nLink <%s>\n",
  370. nla_data(link[TIPC_NLA_LINK_NAME]));
  371. if (link[TIPC_NLA_LINK_BROADCAST]) {
  372. __fill_bc_link_stat(msg, prop, stats);
  373. return 0;
  374. }
  375. if (link[TIPC_NLA_LINK_ACTIVE])
  376. tipc_tlv_sprintf(msg->rep, " ACTIVE");
  377. else if (link[TIPC_NLA_LINK_UP])
  378. tipc_tlv_sprintf(msg->rep, " STANDBY");
  379. else
  380. tipc_tlv_sprintf(msg->rep, " DEFUNCT");
  381. tipc_tlv_sprintf(msg->rep, " MTU:%u Priority:%u",
  382. nla_get_u32(link[TIPC_NLA_LINK_MTU]),
  383. nla_get_u32(prop[TIPC_NLA_PROP_PRIO]));
  384. tipc_tlv_sprintf(msg->rep, " Tolerance:%u ms Window:%u packets\n",
  385. nla_get_u32(prop[TIPC_NLA_PROP_TOL]),
  386. nla_get_u32(prop[TIPC_NLA_PROP_WIN]));
  387. tipc_tlv_sprintf(msg->rep,
  388. " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
  389. nla_get_u32(link[TIPC_NLA_LINK_RX]) -
  390. nla_get_u32(stats[TIPC_NLA_STATS_RX_INFO]),
  391. nla_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTS]),
  392. nla_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTED]),
  393. nla_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLES]),
  394. nla_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLED]));
  395. tipc_tlv_sprintf(msg->rep,
  396. " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
  397. nla_get_u32(link[TIPC_NLA_LINK_TX]) -
  398. nla_get_u32(stats[TIPC_NLA_STATS_TX_INFO]),
  399. nla_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTS]),
  400. nla_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTED]),
  401. nla_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLES]),
  402. nla_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLED]));
  403. tipc_tlv_sprintf(msg->rep,
  404. " TX profile sample:%u packets average:%u octets\n",
  405. nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_CNT]),
  406. nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_TOT]) /
  407. nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT]));
  408. tipc_tlv_sprintf(msg->rep,
  409. " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% ",
  410. perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P0]),
  411. nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])),
  412. perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P1]),
  413. nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])),
  414. perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P2]),
  415. nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])),
  416. perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P3]),
  417. nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])));
  418. tipc_tlv_sprintf(msg->rep, "-16384:%u%% -32768:%u%% -66000:%u%%\n",
  419. perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P4]),
  420. nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])),
  421. perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P5]),
  422. nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])),
  423. perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P6]),
  424. nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])));
  425. tipc_tlv_sprintf(msg->rep,
  426. " RX states:%u probes:%u naks:%u defs:%u dups:%u\n",
  427. nla_get_u32(stats[TIPC_NLA_STATS_RX_STATES]),
  428. nla_get_u32(stats[TIPC_NLA_STATS_RX_PROBES]),
  429. nla_get_u32(stats[TIPC_NLA_STATS_RX_NACKS]),
  430. nla_get_u32(stats[TIPC_NLA_STATS_RX_DEFERRED]),
  431. nla_get_u32(stats[TIPC_NLA_STATS_DUPLICATES]));
  432. tipc_tlv_sprintf(msg->rep,
  433. " TX states:%u probes:%u naks:%u acks:%u dups:%u\n",
  434. nla_get_u32(stats[TIPC_NLA_STATS_TX_STATES]),
  435. nla_get_u32(stats[TIPC_NLA_STATS_TX_PROBES]),
  436. nla_get_u32(stats[TIPC_NLA_STATS_TX_NACKS]),
  437. nla_get_u32(stats[TIPC_NLA_STATS_TX_ACKS]),
  438. nla_get_u32(stats[TIPC_NLA_STATS_RETRANSMITTED]));
  439. tipc_tlv_sprintf(msg->rep,
  440. " Congestion link:%u Send queue max:%u avg:%u",
  441. nla_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]),
  442. nla_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]),
  443. nla_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE]));
  444. return 0;
  445. }
  446. static int tipc_nl_compat_link_dump(struct tipc_nl_compat_msg *msg,
  447. struct nlattr **attrs)
  448. {
  449. struct nlattr *link[TIPC_NLA_LINK_MAX + 1];
  450. struct tipc_link_info link_info;
  451. nla_parse_nested(link, TIPC_NLA_LINK_MAX, attrs[TIPC_NLA_LINK], NULL);
  452. link_info.dest = nla_get_flag(link[TIPC_NLA_LINK_DEST]);
  453. link_info.up = htonl(nla_get_flag(link[TIPC_NLA_LINK_UP]));
  454. strcpy(link_info.str, nla_data(link[TIPC_NLA_LINK_NAME]));
  455. return tipc_add_tlv(msg->rep, TIPC_TLV_LINK_INFO,
  456. &link_info, sizeof(link_info));
  457. }
  458. static int tipc_nl_compat_link_set(struct sk_buff *skb,
  459. struct tipc_nl_compat_msg *msg)
  460. {
  461. struct nlattr *link;
  462. struct nlattr *prop;
  463. struct tipc_link_config *lc;
  464. lc = (struct tipc_link_config *)TLV_DATA(msg->req);
  465. link = nla_nest_start(skb, TIPC_NLA_LINK);
  466. if (!link)
  467. return -EMSGSIZE;
  468. if (nla_put_string(skb, TIPC_NLA_LINK_NAME, lc->name))
  469. return -EMSGSIZE;
  470. prop = nla_nest_start(skb, TIPC_NLA_LINK_PROP);
  471. if (!prop)
  472. return -EMSGSIZE;
  473. if (msg->cmd == TIPC_CMD_SET_LINK_PRI) {
  474. if (nla_put_u32(skb, TIPC_NLA_PROP_PRIO, ntohl(lc->value)))
  475. return -EMSGSIZE;
  476. } else if (msg->cmd == TIPC_CMD_SET_LINK_TOL) {
  477. if (nla_put_u32(skb, TIPC_NLA_PROP_TOL, ntohl(lc->value)))
  478. return -EMSGSIZE;
  479. } else if (msg->cmd == TIPC_CMD_SET_LINK_WINDOW) {
  480. if (nla_put_u32(skb, TIPC_NLA_PROP_WIN, ntohl(lc->value)))
  481. return -EMSGSIZE;
  482. }
  483. nla_nest_end(skb, prop);
  484. nla_nest_end(skb, link);
  485. return 0;
  486. }
  487. static int tipc_nl_compat_link_reset_stats(struct sk_buff *skb,
  488. struct tipc_nl_compat_msg *msg)
  489. {
  490. char *name;
  491. struct nlattr *link;
  492. name = (char *)TLV_DATA(msg->req);
  493. link = nla_nest_start(skb, TIPC_NLA_LINK);
  494. if (!link)
  495. return -EMSGSIZE;
  496. if (nla_put_string(skb, TIPC_NLA_LINK_NAME, name))
  497. return -EMSGSIZE;
  498. nla_nest_end(skb, link);
  499. return 0;
  500. }
  501. static int tipc_nl_compat_name_table_dump_header(struct tipc_nl_compat_msg *msg)
  502. {
  503. int i;
  504. u32 depth;
  505. struct tipc_name_table_query *ntq;
  506. static const char * const header[] = {
  507. "Type ",
  508. "Lower Upper ",
  509. "Port Identity ",
  510. "Publication Scope"
  511. };
  512. ntq = (struct tipc_name_table_query *)TLV_DATA(msg->req);
  513. depth = ntohl(ntq->depth);
  514. if (depth > 4)
  515. depth = 4;
  516. for (i = 0; i < depth; i++)
  517. tipc_tlv_sprintf(msg->rep, header[i]);
  518. tipc_tlv_sprintf(msg->rep, "\n");
  519. return 0;
  520. }
  521. static int tipc_nl_compat_name_table_dump(struct tipc_nl_compat_msg *msg,
  522. struct nlattr **attrs)
  523. {
  524. char port_str[27];
  525. struct tipc_name_table_query *ntq;
  526. struct nlattr *nt[TIPC_NLA_NAME_TABLE_MAX + 1];
  527. struct nlattr *publ[TIPC_NLA_PUBL_MAX + 1];
  528. u32 node, depth, type, lowbound, upbound;
  529. static const char * const scope_str[] = {"", " zone", " cluster",
  530. " node"};
  531. nla_parse_nested(nt, TIPC_NLA_NAME_TABLE_MAX,
  532. attrs[TIPC_NLA_NAME_TABLE], NULL);
  533. nla_parse_nested(publ, TIPC_NLA_PUBL_MAX, nt[TIPC_NLA_NAME_TABLE_PUBL],
  534. NULL);
  535. ntq = (struct tipc_name_table_query *)TLV_DATA(msg->req);
  536. depth = ntohl(ntq->depth);
  537. type = ntohl(ntq->type);
  538. lowbound = ntohl(ntq->lowbound);
  539. upbound = ntohl(ntq->upbound);
  540. if (!(depth & TIPC_NTQ_ALLTYPES) &&
  541. (type != nla_get_u32(publ[TIPC_NLA_PUBL_TYPE])))
  542. return 0;
  543. if (lowbound && (lowbound > nla_get_u32(publ[TIPC_NLA_PUBL_UPPER])))
  544. return 0;
  545. if (upbound && (upbound < nla_get_u32(publ[TIPC_NLA_PUBL_LOWER])))
  546. return 0;
  547. tipc_tlv_sprintf(msg->rep, "%-10u ",
  548. nla_get_u32(publ[TIPC_NLA_PUBL_TYPE]));
  549. if (depth == 1)
  550. goto out;
  551. tipc_tlv_sprintf(msg->rep, "%-10u %-10u ",
  552. nla_get_u32(publ[TIPC_NLA_PUBL_LOWER]),
  553. nla_get_u32(publ[TIPC_NLA_PUBL_UPPER]));
  554. if (depth == 2)
  555. goto out;
  556. node = nla_get_u32(publ[TIPC_NLA_PUBL_NODE]);
  557. sprintf(port_str, "<%u.%u.%u:%u>", tipc_zone(node), tipc_cluster(node),
  558. tipc_node(node), nla_get_u32(publ[TIPC_NLA_PUBL_REF]));
  559. tipc_tlv_sprintf(msg->rep, "%-26s ", port_str);
  560. if (depth == 3)
  561. goto out;
  562. tipc_tlv_sprintf(msg->rep, "%-10u %s",
  563. nla_get_u32(publ[TIPC_NLA_PUBL_REF]),
  564. scope_str[nla_get_u32(publ[TIPC_NLA_PUBL_SCOPE])]);
  565. out:
  566. tipc_tlv_sprintf(msg->rep, "\n");
  567. return 0;
  568. }
  569. static int __tipc_nl_compat_publ_dump(struct tipc_nl_compat_msg *msg,
  570. struct nlattr **attrs)
  571. {
  572. u32 type, lower, upper;
  573. struct nlattr *publ[TIPC_NLA_PUBL_MAX + 1];
  574. nla_parse_nested(publ, TIPC_NLA_PUBL_MAX, attrs[TIPC_NLA_PUBL], NULL);
  575. type = nla_get_u32(publ[TIPC_NLA_PUBL_TYPE]);
  576. lower = nla_get_u32(publ[TIPC_NLA_PUBL_LOWER]);
  577. upper = nla_get_u32(publ[TIPC_NLA_PUBL_UPPER]);
  578. if (lower == upper)
  579. tipc_tlv_sprintf(msg->rep, " {%u,%u}", type, lower);
  580. else
  581. tipc_tlv_sprintf(msg->rep, " {%u,%u,%u}", type, lower, upper);
  582. return 0;
  583. }
  584. static int tipc_nl_compat_publ_dump(struct tipc_nl_compat_msg *msg, u32 sock)
  585. {
  586. int err;
  587. void *hdr;
  588. struct nlattr *nest;
  589. struct sk_buff *args;
  590. struct tipc_nl_compat_cmd_dump dump;
  591. args = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  592. if (!args)
  593. return -ENOMEM;
  594. hdr = genlmsg_put(args, 0, 0, &tipc_genl_family, NLM_F_MULTI,
  595. TIPC_NL_PUBL_GET);
  596. nest = nla_nest_start(args, TIPC_NLA_SOCK);
  597. if (!nest) {
  598. kfree_skb(args);
  599. return -EMSGSIZE;
  600. }
  601. if (nla_put_u32(args, TIPC_NLA_SOCK_REF, sock)) {
  602. kfree_skb(args);
  603. return -EMSGSIZE;
  604. }
  605. nla_nest_end(args, nest);
  606. genlmsg_end(args, hdr);
  607. dump.dumpit = tipc_nl_publ_dump;
  608. dump.format = __tipc_nl_compat_publ_dump;
  609. err = __tipc_nl_compat_dumpit(&dump, msg, args);
  610. kfree_skb(args);
  611. return err;
  612. }
  613. static int tipc_nl_compat_sk_dump(struct tipc_nl_compat_msg *msg,
  614. struct nlattr **attrs)
  615. {
  616. int err;
  617. u32 sock_ref;
  618. struct nlattr *sock[TIPC_NLA_SOCK_MAX + 1];
  619. nla_parse_nested(sock, TIPC_NLA_SOCK_MAX, attrs[TIPC_NLA_SOCK], NULL);
  620. sock_ref = nla_get_u32(sock[TIPC_NLA_SOCK_REF]);
  621. tipc_tlv_sprintf(msg->rep, "%u:", sock_ref);
  622. if (sock[TIPC_NLA_SOCK_CON]) {
  623. u32 node;
  624. struct nlattr *con[TIPC_NLA_CON_MAX + 1];
  625. nla_parse_nested(con, TIPC_NLA_CON_MAX, sock[TIPC_NLA_SOCK_CON],
  626. NULL);
  627. node = nla_get_u32(con[TIPC_NLA_CON_NODE]);
  628. tipc_tlv_sprintf(msg->rep, " connected to <%u.%u.%u:%u>",
  629. tipc_zone(node),
  630. tipc_cluster(node),
  631. tipc_node(node),
  632. nla_get_u32(con[TIPC_NLA_CON_SOCK]));
  633. if (con[TIPC_NLA_CON_FLAG])
  634. tipc_tlv_sprintf(msg->rep, " via {%u,%u}\n",
  635. nla_get_u32(con[TIPC_NLA_CON_TYPE]),
  636. nla_get_u32(con[TIPC_NLA_CON_INST]));
  637. else
  638. tipc_tlv_sprintf(msg->rep, "\n");
  639. } else if (sock[TIPC_NLA_SOCK_HAS_PUBL]) {
  640. tipc_tlv_sprintf(msg->rep, " bound to");
  641. err = tipc_nl_compat_publ_dump(msg, sock_ref);
  642. if (err)
  643. return err;
  644. }
  645. tipc_tlv_sprintf(msg->rep, "\n");
  646. return 0;
  647. }
  648. static int tipc_nl_compat_media_dump(struct tipc_nl_compat_msg *msg,
  649. struct nlattr **attrs)
  650. {
  651. struct nlattr *media[TIPC_NLA_MEDIA_MAX + 1];
  652. nla_parse_nested(media, TIPC_NLA_MEDIA_MAX, attrs[TIPC_NLA_MEDIA],
  653. NULL);
  654. return tipc_add_tlv(msg->rep, TIPC_TLV_MEDIA_NAME,
  655. nla_data(media[TIPC_NLA_MEDIA_NAME]),
  656. nla_len(media[TIPC_NLA_MEDIA_NAME]));
  657. }
  658. static int tipc_nl_compat_node_dump(struct tipc_nl_compat_msg *msg,
  659. struct nlattr **attrs)
  660. {
  661. struct tipc_node_info node_info;
  662. struct nlattr *node[TIPC_NLA_NODE_MAX + 1];
  663. nla_parse_nested(node, TIPC_NLA_NODE_MAX, attrs[TIPC_NLA_NODE], NULL);
  664. node_info.addr = htonl(nla_get_u32(node[TIPC_NLA_NODE_ADDR]));
  665. node_info.up = htonl(nla_get_flag(node[TIPC_NLA_NODE_UP]));
  666. return tipc_add_tlv(msg->rep, TIPC_TLV_NODE_INFO, &node_info,
  667. sizeof(node_info));
  668. }
  669. static int tipc_nl_compat_net_set(struct sk_buff *skb,
  670. struct tipc_nl_compat_msg *msg)
  671. {
  672. u32 val;
  673. struct nlattr *net;
  674. val = ntohl(*(__be32 *)TLV_DATA(msg->req));
  675. net = nla_nest_start(skb, TIPC_NLA_NET);
  676. if (!net)
  677. return -EMSGSIZE;
  678. if (msg->cmd == TIPC_CMD_SET_NODE_ADDR) {
  679. if (nla_put_u32(skb, TIPC_NLA_NET_ADDR, val))
  680. return -EMSGSIZE;
  681. } else if (msg->cmd == TIPC_CMD_SET_NETID) {
  682. if (nla_put_u32(skb, TIPC_NLA_NET_ID, val))
  683. return -EMSGSIZE;
  684. }
  685. nla_nest_end(skb, net);
  686. return 0;
  687. }
  688. static int tipc_nl_compat_net_dump(struct tipc_nl_compat_msg *msg,
  689. struct nlattr **attrs)
  690. {
  691. __be32 id;
  692. struct nlattr *net[TIPC_NLA_NET_MAX + 1];
  693. nla_parse_nested(net, TIPC_NLA_NET_MAX, attrs[TIPC_NLA_NET], NULL);
  694. id = htonl(nla_get_u32(net[TIPC_NLA_NET_ID]));
  695. return tipc_add_tlv(msg->rep, TIPC_TLV_UNSIGNED, &id, sizeof(id));
  696. }
  697. static int tipc_cmd_show_stats_compat(struct tipc_nl_compat_msg *msg)
  698. {
  699. msg->rep = tipc_tlv_alloc(ULTRA_STRING_MAX_LEN);
  700. if (!msg->rep)
  701. return -ENOMEM;
  702. tipc_tlv_init(msg->rep, TIPC_TLV_ULTRA_STRING);
  703. tipc_tlv_sprintf(msg->rep, "TIPC version " TIPC_MOD_VER "\n");
  704. return 0;
  705. }
  706. static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg)
  707. {
  708. struct tipc_nl_compat_cmd_dump dump;
  709. struct tipc_nl_compat_cmd_doit doit;
  710. memset(&dump, 0, sizeof(dump));
  711. memset(&doit, 0, sizeof(doit));
  712. switch (msg->cmd) {
  713. case TIPC_CMD_NOOP:
  714. msg->rep = tipc_tlv_alloc(0);
  715. if (!msg->rep)
  716. return -ENOMEM;
  717. return 0;
  718. case TIPC_CMD_GET_BEARER_NAMES:
  719. msg->rep_size = MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME);
  720. dump.dumpit = tipc_nl_bearer_dump;
  721. dump.format = tipc_nl_compat_bearer_dump;
  722. return tipc_nl_compat_dumpit(&dump, msg);
  723. case TIPC_CMD_ENABLE_BEARER:
  724. msg->req_type = TIPC_TLV_BEARER_CONFIG;
  725. doit.doit = tipc_nl_bearer_enable;
  726. doit.transcode = tipc_nl_compat_bearer_enable;
  727. return tipc_nl_compat_doit(&doit, msg);
  728. case TIPC_CMD_DISABLE_BEARER:
  729. msg->req_type = TIPC_TLV_BEARER_NAME;
  730. doit.doit = tipc_nl_bearer_disable;
  731. doit.transcode = tipc_nl_compat_bearer_disable;
  732. return tipc_nl_compat_doit(&doit, msg);
  733. case TIPC_CMD_SHOW_LINK_STATS:
  734. msg->req_type = TIPC_TLV_LINK_NAME;
  735. msg->rep_size = ULTRA_STRING_MAX_LEN;
  736. msg->rep_type = TIPC_TLV_ULTRA_STRING;
  737. dump.dumpit = tipc_nl_link_dump;
  738. dump.format = tipc_nl_compat_link_stat_dump;
  739. return tipc_nl_compat_dumpit(&dump, msg);
  740. case TIPC_CMD_GET_LINKS:
  741. msg->req_type = TIPC_TLV_NET_ADDR;
  742. msg->rep_size = ULTRA_STRING_MAX_LEN;
  743. dump.dumpit = tipc_nl_link_dump;
  744. dump.format = tipc_nl_compat_link_dump;
  745. return tipc_nl_compat_dumpit(&dump, msg);
  746. case TIPC_CMD_SET_LINK_TOL:
  747. case TIPC_CMD_SET_LINK_PRI:
  748. case TIPC_CMD_SET_LINK_WINDOW:
  749. msg->req_type = TIPC_TLV_LINK_CONFIG;
  750. doit.doit = tipc_nl_link_set;
  751. doit.transcode = tipc_nl_compat_link_set;
  752. return tipc_nl_compat_doit(&doit, msg);
  753. case TIPC_CMD_RESET_LINK_STATS:
  754. msg->req_type = TIPC_TLV_LINK_NAME;
  755. doit.doit = tipc_nl_link_reset_stats;
  756. doit.transcode = tipc_nl_compat_link_reset_stats;
  757. return tipc_nl_compat_doit(&doit, msg);
  758. case TIPC_CMD_SHOW_NAME_TABLE:
  759. msg->req_type = TIPC_TLV_NAME_TBL_QUERY;
  760. msg->rep_size = ULTRA_STRING_MAX_LEN;
  761. msg->rep_type = TIPC_TLV_ULTRA_STRING;
  762. dump.header = tipc_nl_compat_name_table_dump_header;
  763. dump.dumpit = tipc_nl_name_table_dump;
  764. dump.format = tipc_nl_compat_name_table_dump;
  765. return tipc_nl_compat_dumpit(&dump, msg);
  766. case TIPC_CMD_SHOW_PORTS:
  767. msg->rep_size = ULTRA_STRING_MAX_LEN;
  768. msg->rep_type = TIPC_TLV_ULTRA_STRING;
  769. dump.dumpit = tipc_nl_sk_dump;
  770. dump.format = tipc_nl_compat_sk_dump;
  771. return tipc_nl_compat_dumpit(&dump, msg);
  772. case TIPC_CMD_GET_MEDIA_NAMES:
  773. msg->rep_size = MAX_MEDIA * TLV_SPACE(TIPC_MAX_MEDIA_NAME);
  774. dump.dumpit = tipc_nl_media_dump;
  775. dump.format = tipc_nl_compat_media_dump;
  776. return tipc_nl_compat_dumpit(&dump, msg);
  777. case TIPC_CMD_GET_NODES:
  778. msg->rep_size = ULTRA_STRING_MAX_LEN;
  779. dump.dumpit = tipc_nl_node_dump;
  780. dump.format = tipc_nl_compat_node_dump;
  781. return tipc_nl_compat_dumpit(&dump, msg);
  782. case TIPC_CMD_SET_NODE_ADDR:
  783. msg->req_type = TIPC_TLV_NET_ADDR;
  784. doit.doit = tipc_nl_net_set;
  785. doit.transcode = tipc_nl_compat_net_set;
  786. return tipc_nl_compat_doit(&doit, msg);
  787. case TIPC_CMD_SET_NETID:
  788. msg->req_type = TIPC_TLV_UNSIGNED;
  789. doit.doit = tipc_nl_net_set;
  790. doit.transcode = tipc_nl_compat_net_set;
  791. return tipc_nl_compat_doit(&doit, msg);
  792. case TIPC_CMD_GET_NETID:
  793. msg->rep_size = sizeof(u32);
  794. dump.dumpit = tipc_nl_net_dump;
  795. dump.format = tipc_nl_compat_net_dump;
  796. return tipc_nl_compat_dumpit(&dump, msg);
  797. case TIPC_CMD_SHOW_STATS:
  798. return tipc_cmd_show_stats_compat(msg);
  799. }
  800. return -EOPNOTSUPP;
  801. }
  802. static int tipc_nl_compat_recv(struct sk_buff *skb, struct genl_info *info)
  803. {
  804. int err;
  805. int len;
  806. struct tipc_nl_compat_msg msg;
  807. struct nlmsghdr *req_nlh;
  808. struct nlmsghdr *rep_nlh;
  809. struct tipc_genlmsghdr *req_userhdr = info->userhdr;
  810. struct net *net = genl_info_net(info);
  811. memset(&msg, 0, sizeof(msg));
  812. req_nlh = (struct nlmsghdr *)skb->data;
  813. msg.req = nlmsg_data(req_nlh) + GENL_HDRLEN + TIPC_GENL_HDRLEN;
  814. msg.cmd = req_userhdr->cmd;
  815. msg.dst_sk = info->dst_sk;
  816. if ((msg.cmd & 0xC000) && (!netlink_net_capable(skb, CAP_NET_ADMIN))) {
  817. msg.rep = tipc_get_err_tlv(TIPC_CFG_NOT_NET_ADMIN);
  818. err = -EACCES;
  819. goto send;
  820. }
  821. len = nlmsg_attrlen(req_nlh, GENL_HDRLEN + TIPC_GENL_HDRLEN);
  822. if (TLV_GET_LEN(msg.req) && !TLV_OK(msg.req, len)) {
  823. msg.rep = tipc_get_err_tlv(TIPC_CFG_NOT_SUPPORTED);
  824. err = -EOPNOTSUPP;
  825. goto send;
  826. }
  827. err = tipc_nl_compat_handle(&msg);
  828. if (err == -EOPNOTSUPP)
  829. msg.rep = tipc_get_err_tlv(TIPC_CFG_NOT_SUPPORTED);
  830. else if (err == -EINVAL)
  831. msg.rep = tipc_get_err_tlv(TIPC_CFG_TLV_ERROR);
  832. send:
  833. if (!msg.rep)
  834. return err;
  835. len = nlmsg_total_size(GENL_HDRLEN + TIPC_GENL_HDRLEN);
  836. skb_push(msg.rep, len);
  837. rep_nlh = nlmsg_hdr(msg.rep);
  838. memcpy(rep_nlh, info->nlhdr, len);
  839. rep_nlh->nlmsg_len = msg.rep->len;
  840. genlmsg_unicast(net, msg.rep, NETLINK_CB(skb).portid);
  841. return err;
  842. }
  843. static struct genl_family tipc_genl_compat_family = {
  844. .id = GENL_ID_GENERATE,
  845. .name = TIPC_GENL_NAME,
  846. .version = TIPC_GENL_VERSION,
  847. .hdrsize = TIPC_GENL_HDRLEN,
  848. .maxattr = 0,
  849. .netnsok = true,
  850. };
  851. static struct genl_ops tipc_genl_compat_ops[] = {
  852. {
  853. .cmd = TIPC_GENL_CMD,
  854. .doit = tipc_nl_compat_recv,
  855. },
  856. };
  857. int tipc_netlink_compat_start(void)
  858. {
  859. int res;
  860. res = genl_register_family_with_ops(&tipc_genl_compat_family,
  861. tipc_genl_compat_ops);
  862. if (res) {
  863. pr_err("Failed to register legacy compat interface\n");
  864. return res;
  865. }
  866. return 0;
  867. }
  868. void tipc_netlink_compat_stop(void)
  869. {
  870. genl_unregister_family(&tipc_genl_compat_family);
  871. }