dcbnl.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121
  1. /*
  2. * Copyright (c) 2008, Intel Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  15. * Place - Suite 330, Boston, MA 02111-1307 USA.
  16. *
  17. * Author: Lucy Liu <lucy.liu@intel.com>
  18. */
  19. #include <linux/netdevice.h>
  20. #include <linux/netlink.h>
  21. #include <net/netlink.h>
  22. #include <net/rtnetlink.h>
  23. #include <linux/dcbnl.h>
  24. #include <linux/rtnetlink.h>
  25. #include <net/sock.h>
  26. /**
  27. * Data Center Bridging (DCB) is a collection of Ethernet enhancements
  28. * intended to allow network traffic with differing requirements
  29. * (highly reliable, no drops vs. best effort vs. low latency) to operate
  30. * and co-exist on Ethernet. Current DCB features are:
  31. *
  32. * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
  33. * framework for assigning bandwidth guarantees to traffic classes.
  34. *
  35. * Priority-based Flow Control (PFC) - provides a flow control mechanism which
  36. * can work independently for each 802.1p priority.
  37. *
  38. * Congestion Notification - provides a mechanism for end-to-end congestion
  39. * control for protocols which do not have built-in congestion management.
  40. *
  41. * More information about the emerging standards for these Ethernet features
  42. * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
  43. *
  44. * This file implements an rtnetlink interface to allow configuration of DCB
  45. * features for capable devices.
  46. */
  47. MODULE_AUTHOR("Lucy Liu, <lucy.liu@intel.com>");
  48. MODULE_DESCRIPTION("Data Center Bridging netlink interface");
  49. MODULE_LICENSE("GPL");
  50. /**************** DCB attribute policies *************************************/
  51. /* DCB netlink attributes policy */
  52. static struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = {
  53. [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1},
  54. [DCB_ATTR_STATE] = {.type = NLA_U8},
  55. [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED},
  56. [DCB_ATTR_PG_CFG] = {.type = NLA_NESTED},
  57. [DCB_ATTR_SET_ALL] = {.type = NLA_U8},
  58. [DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG},
  59. [DCB_ATTR_CAP] = {.type = NLA_NESTED},
  60. [DCB_ATTR_PFC_STATE] = {.type = NLA_U8},
  61. [DCB_ATTR_BCN] = {.type = NLA_NESTED},
  62. };
  63. /* DCB priority flow control to User Priority nested attributes */
  64. static struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = {
  65. [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8},
  66. [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8},
  67. [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8},
  68. [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8},
  69. [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8},
  70. [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8},
  71. [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8},
  72. [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8},
  73. [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG},
  74. };
  75. /* DCB priority grouping nested attributes */
  76. static struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = {
  77. [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED},
  78. [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED},
  79. [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED},
  80. [DCB_PG_ATTR_TC_3] = {.type = NLA_NESTED},
  81. [DCB_PG_ATTR_TC_4] = {.type = NLA_NESTED},
  82. [DCB_PG_ATTR_TC_5] = {.type = NLA_NESTED},
  83. [DCB_PG_ATTR_TC_6] = {.type = NLA_NESTED},
  84. [DCB_PG_ATTR_TC_7] = {.type = NLA_NESTED},
  85. [DCB_PG_ATTR_TC_ALL] = {.type = NLA_NESTED},
  86. [DCB_PG_ATTR_BW_ID_0] = {.type = NLA_U8},
  87. [DCB_PG_ATTR_BW_ID_1] = {.type = NLA_U8},
  88. [DCB_PG_ATTR_BW_ID_2] = {.type = NLA_U8},
  89. [DCB_PG_ATTR_BW_ID_3] = {.type = NLA_U8},
  90. [DCB_PG_ATTR_BW_ID_4] = {.type = NLA_U8},
  91. [DCB_PG_ATTR_BW_ID_5] = {.type = NLA_U8},
  92. [DCB_PG_ATTR_BW_ID_6] = {.type = NLA_U8},
  93. [DCB_PG_ATTR_BW_ID_7] = {.type = NLA_U8},
  94. [DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG},
  95. };
  96. /* DCB traffic class nested attributes. */
  97. static struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = {
  98. [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8},
  99. [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8},
  100. [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8},
  101. [DCB_TC_ATTR_PARAM_BW_PCT] = {.type = NLA_U8},
  102. [DCB_TC_ATTR_PARAM_ALL] = {.type = NLA_FLAG},
  103. };
  104. /* DCB capabilities nested attributes. */
  105. static struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = {
  106. [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG},
  107. [DCB_CAP_ATTR_PG] = {.type = NLA_U8},
  108. [DCB_CAP_ATTR_PFC] = {.type = NLA_U8},
  109. [DCB_CAP_ATTR_UP2TC] = {.type = NLA_U8},
  110. [DCB_CAP_ATTR_PG_TCS] = {.type = NLA_U8},
  111. [DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8},
  112. [DCB_CAP_ATTR_GSP] = {.type = NLA_U8},
  113. [DCB_CAP_ATTR_BCN] = {.type = NLA_U8},
  114. };
  115. /* DCB capabilities nested attributes. */
  116. static struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = {
  117. [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG},
  118. [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8},
  119. [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8},
  120. };
  121. /* DCB BCN nested attributes. */
  122. static struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = {
  123. [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8},
  124. [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8},
  125. [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8},
  126. [DCB_BCN_ATTR_RP_3] = {.type = NLA_U8},
  127. [DCB_BCN_ATTR_RP_4] = {.type = NLA_U8},
  128. [DCB_BCN_ATTR_RP_5] = {.type = NLA_U8},
  129. [DCB_BCN_ATTR_RP_6] = {.type = NLA_U8},
  130. [DCB_BCN_ATTR_RP_7] = {.type = NLA_U8},
  131. [DCB_BCN_ATTR_RP_ALL] = {.type = NLA_FLAG},
  132. [DCB_BCN_ATTR_ALPHA] = {.type = NLA_U32},
  133. [DCB_BCN_ATTR_BETA] = {.type = NLA_U32},
  134. [DCB_BCN_ATTR_GD] = {.type = NLA_U32},
  135. [DCB_BCN_ATTR_GI] = {.type = NLA_U32},
  136. [DCB_BCN_ATTR_TMAX] = {.type = NLA_U32},
  137. [DCB_BCN_ATTR_TD] = {.type = NLA_U32},
  138. [DCB_BCN_ATTR_RMIN] = {.type = NLA_U32},
  139. [DCB_BCN_ATTR_W] = {.type = NLA_U32},
  140. [DCB_BCN_ATTR_RD] = {.type = NLA_U32},
  141. [DCB_BCN_ATTR_RU] = {.type = NLA_U32},
  142. [DCB_BCN_ATTR_WRTT] = {.type = NLA_U32},
  143. [DCB_BCN_ATTR_RI] = {.type = NLA_U32},
  144. [DCB_BCN_ATTR_C] = {.type = NLA_U32},
  145. [DCB_BCN_ATTR_ALL] = {.type = NLA_FLAG},
  146. };
  147. /* standard netlink reply call */
  148. static int dcbnl_reply(u8 value, u8 event, u8 cmd, u8 attr, u32 pid,
  149. u32 seq, u16 flags)
  150. {
  151. struct sk_buff *dcbnl_skb;
  152. struct dcbmsg *dcb;
  153. struct nlmsghdr *nlh;
  154. int ret = -EINVAL;
  155. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  156. if (!dcbnl_skb)
  157. return ret;
  158. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, event, sizeof(*dcb), flags);
  159. dcb = NLMSG_DATA(nlh);
  160. dcb->dcb_family = AF_UNSPEC;
  161. dcb->cmd = cmd;
  162. dcb->dcb_pad = 0;
  163. ret = nla_put_u8(dcbnl_skb, attr, value);
  164. if (ret)
  165. goto err;
  166. /* end the message, assign the nlmsg_len. */
  167. nlmsg_end(dcbnl_skb, nlh);
  168. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  169. if (ret)
  170. goto err;
  171. return 0;
  172. nlmsg_failure:
  173. err:
  174. kfree(dcbnl_skb);
  175. return ret;
  176. }
  177. static int dcbnl_getstate(struct net_device *netdev, struct nlattr **tb,
  178. u32 pid, u32 seq, u16 flags)
  179. {
  180. int ret = -EINVAL;
  181. /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
  182. if (!netdev->dcbnl_ops->getstate)
  183. return ret;
  184. ret = dcbnl_reply(netdev->dcbnl_ops->getstate(netdev), RTM_GETDCB,
  185. DCB_CMD_GSTATE, DCB_ATTR_STATE, pid, seq, flags);
  186. return ret;
  187. }
  188. static int dcbnl_getpfccfg(struct net_device *netdev, struct nlattr **tb,
  189. u32 pid, u32 seq, u16 flags)
  190. {
  191. struct sk_buff *dcbnl_skb;
  192. struct nlmsghdr *nlh;
  193. struct dcbmsg *dcb;
  194. struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest;
  195. u8 value;
  196. int ret = -EINVAL;
  197. int i;
  198. int getall = 0;
  199. if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->getpfccfg)
  200. return ret;
  201. ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
  202. tb[DCB_ATTR_PFC_CFG],
  203. dcbnl_pfc_up_nest);
  204. if (ret)
  205. goto err_out;
  206. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  207. if (!dcbnl_skb)
  208. goto err_out;
  209. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  210. dcb = NLMSG_DATA(nlh);
  211. dcb->dcb_family = AF_UNSPEC;
  212. dcb->cmd = DCB_CMD_PFC_GCFG;
  213. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PFC_CFG);
  214. if (!nest)
  215. goto err;
  216. if (data[DCB_PFC_UP_ATTR_ALL])
  217. getall = 1;
  218. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  219. if (!getall && !data[i])
  220. continue;
  221. netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0,
  222. &value);
  223. ret = nla_put_u8(dcbnl_skb, i, value);
  224. if (ret) {
  225. nla_nest_cancel(dcbnl_skb, nest);
  226. goto err;
  227. }
  228. }
  229. nla_nest_end(dcbnl_skb, nest);
  230. nlmsg_end(dcbnl_skb, nlh);
  231. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  232. if (ret)
  233. goto err;
  234. return 0;
  235. nlmsg_failure:
  236. err:
  237. kfree(dcbnl_skb);
  238. err_out:
  239. return -EINVAL;
  240. }
  241. static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlattr **tb,
  242. u32 pid, u32 seq, u16 flags)
  243. {
  244. struct sk_buff *dcbnl_skb;
  245. struct nlmsghdr *nlh;
  246. struct dcbmsg *dcb;
  247. u8 perm_addr[MAX_ADDR_LEN];
  248. int ret = -EINVAL;
  249. if (!netdev->dcbnl_ops->getpermhwaddr)
  250. return ret;
  251. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  252. if (!dcbnl_skb)
  253. goto err_out;
  254. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  255. dcb = NLMSG_DATA(nlh);
  256. dcb->dcb_family = AF_UNSPEC;
  257. dcb->cmd = DCB_CMD_GPERM_HWADDR;
  258. netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
  259. ret = nla_put(dcbnl_skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr),
  260. perm_addr);
  261. nlmsg_end(dcbnl_skb, nlh);
  262. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  263. if (ret)
  264. goto err;
  265. return 0;
  266. nlmsg_failure:
  267. err:
  268. kfree(dcbnl_skb);
  269. err_out:
  270. return -EINVAL;
  271. }
  272. static int dcbnl_getcap(struct net_device *netdev, struct nlattr **tb,
  273. u32 pid, u32 seq, u16 flags)
  274. {
  275. struct sk_buff *dcbnl_skb;
  276. struct nlmsghdr *nlh;
  277. struct dcbmsg *dcb;
  278. struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest;
  279. u8 value;
  280. int ret = -EINVAL;
  281. int i;
  282. int getall = 0;
  283. if (!tb[DCB_ATTR_CAP] || !netdev->dcbnl_ops->getcap)
  284. return ret;
  285. ret = nla_parse_nested(data, DCB_CAP_ATTR_MAX, tb[DCB_ATTR_CAP],
  286. dcbnl_cap_nest);
  287. if (ret)
  288. goto err_out;
  289. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  290. if (!dcbnl_skb)
  291. goto err_out;
  292. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  293. dcb = NLMSG_DATA(nlh);
  294. dcb->dcb_family = AF_UNSPEC;
  295. dcb->cmd = DCB_CMD_GCAP;
  296. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_CAP);
  297. if (!nest)
  298. goto err;
  299. if (data[DCB_CAP_ATTR_ALL])
  300. getall = 1;
  301. for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) {
  302. if (!getall && !data[i])
  303. continue;
  304. if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) {
  305. ret = nla_put_u8(dcbnl_skb, i, value);
  306. if (ret) {
  307. nla_nest_cancel(dcbnl_skb, nest);
  308. goto err;
  309. }
  310. }
  311. }
  312. nla_nest_end(dcbnl_skb, nest);
  313. nlmsg_end(dcbnl_skb, nlh);
  314. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  315. if (ret)
  316. goto err;
  317. return 0;
  318. nlmsg_failure:
  319. err:
  320. kfree(dcbnl_skb);
  321. err_out:
  322. return -EINVAL;
  323. }
  324. static int dcbnl_getnumtcs(struct net_device *netdev, struct nlattr **tb,
  325. u32 pid, u32 seq, u16 flags)
  326. {
  327. struct sk_buff *dcbnl_skb;
  328. struct nlmsghdr *nlh;
  329. struct dcbmsg *dcb;
  330. struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest;
  331. u8 value;
  332. int ret = -EINVAL;
  333. int i;
  334. int getall = 0;
  335. if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->getnumtcs)
  336. return ret;
  337. ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
  338. dcbnl_numtcs_nest);
  339. if (ret) {
  340. ret = -EINVAL;
  341. goto err_out;
  342. }
  343. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  344. if (!dcbnl_skb) {
  345. ret = -EINVAL;
  346. goto err_out;
  347. }
  348. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  349. dcb = NLMSG_DATA(nlh);
  350. dcb->dcb_family = AF_UNSPEC;
  351. dcb->cmd = DCB_CMD_GNUMTCS;
  352. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_NUMTCS);
  353. if (!nest) {
  354. ret = -EINVAL;
  355. goto err;
  356. }
  357. if (data[DCB_NUMTCS_ATTR_ALL])
  358. getall = 1;
  359. for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
  360. if (!getall && !data[i])
  361. continue;
  362. ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value);
  363. if (!ret) {
  364. ret = nla_put_u8(dcbnl_skb, i, value);
  365. if (ret) {
  366. nla_nest_cancel(dcbnl_skb, nest);
  367. ret = -EINVAL;
  368. goto err;
  369. }
  370. } else {
  371. goto err;
  372. }
  373. }
  374. nla_nest_end(dcbnl_skb, nest);
  375. nlmsg_end(dcbnl_skb, nlh);
  376. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  377. if (ret) {
  378. ret = -EINVAL;
  379. goto err;
  380. }
  381. return 0;
  382. nlmsg_failure:
  383. err:
  384. kfree(dcbnl_skb);
  385. err_out:
  386. return ret;
  387. }
  388. static int dcbnl_setnumtcs(struct net_device *netdev, struct nlattr **tb,
  389. u32 pid, u32 seq, u16 flags)
  390. {
  391. struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1];
  392. int ret = -EINVAL;
  393. u8 value;
  394. int i;
  395. if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->setstate)
  396. return ret;
  397. ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
  398. dcbnl_numtcs_nest);
  399. if (ret) {
  400. ret = -EINVAL;
  401. goto err;
  402. }
  403. for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
  404. if (data[i] == NULL)
  405. continue;
  406. value = nla_get_u8(data[i]);
  407. ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value);
  408. if (ret)
  409. goto operr;
  410. }
  411. operr:
  412. ret = dcbnl_reply(!!ret, RTM_SETDCB, DCB_CMD_SNUMTCS,
  413. DCB_ATTR_NUMTCS, pid, seq, flags);
  414. err:
  415. return ret;
  416. }
  417. static int dcbnl_getpfcstate(struct net_device *netdev, struct nlattr **tb,
  418. u32 pid, u32 seq, u16 flags)
  419. {
  420. int ret = -EINVAL;
  421. if (!netdev->dcbnl_ops->getpfcstate)
  422. return ret;
  423. ret = dcbnl_reply(netdev->dcbnl_ops->getpfcstate(netdev), RTM_GETDCB,
  424. DCB_CMD_PFC_GSTATE, DCB_ATTR_PFC_STATE,
  425. pid, seq, flags);
  426. return ret;
  427. }
  428. static int dcbnl_setpfcstate(struct net_device *netdev, struct nlattr **tb,
  429. u32 pid, u32 seq, u16 flags)
  430. {
  431. int ret = -EINVAL;
  432. u8 value;
  433. if (!tb[DCB_ATTR_PFC_STATE] || !netdev->dcbnl_ops->setpfcstate)
  434. return ret;
  435. value = nla_get_u8(tb[DCB_ATTR_PFC_STATE]);
  436. netdev->dcbnl_ops->setpfcstate(netdev, value);
  437. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SSTATE, DCB_ATTR_PFC_STATE,
  438. pid, seq, flags);
  439. return ret;
  440. }
  441. static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlattr **tb,
  442. u32 pid, u32 seq, u16 flags, int dir)
  443. {
  444. struct sk_buff *dcbnl_skb;
  445. struct nlmsghdr *nlh;
  446. struct dcbmsg *dcb;
  447. struct nlattr *pg_nest, *param_nest, *data;
  448. struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
  449. struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
  450. u8 prio, pgid, tc_pct, up_map;
  451. int ret = -EINVAL;
  452. int getall = 0;
  453. int i;
  454. if (!tb[DCB_ATTR_PG_CFG] ||
  455. !netdev->dcbnl_ops->getpgtccfgtx ||
  456. !netdev->dcbnl_ops->getpgtccfgrx ||
  457. !netdev->dcbnl_ops->getpgbwgcfgtx ||
  458. !netdev->dcbnl_ops->getpgbwgcfgrx)
  459. return ret;
  460. ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
  461. tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
  462. if (ret)
  463. goto err_out;
  464. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  465. if (!dcbnl_skb)
  466. goto err_out;
  467. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  468. dcb = NLMSG_DATA(nlh);
  469. dcb->dcb_family = AF_UNSPEC;
  470. dcb->cmd = (dir) ? DCB_CMD_PGRX_GCFG : DCB_CMD_PGTX_GCFG;
  471. pg_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PG_CFG);
  472. if (!pg_nest)
  473. goto err;
  474. if (pg_tb[DCB_PG_ATTR_TC_ALL])
  475. getall = 1;
  476. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  477. if (!getall && !pg_tb[i])
  478. continue;
  479. if (pg_tb[DCB_PG_ATTR_TC_ALL])
  480. data = pg_tb[DCB_PG_ATTR_TC_ALL];
  481. else
  482. data = pg_tb[i];
  483. ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
  484. data, dcbnl_tc_param_nest);
  485. if (ret)
  486. goto err_pg;
  487. param_nest = nla_nest_start(dcbnl_skb, i);
  488. if (!param_nest)
  489. goto err_pg;
  490. pgid = DCB_ATTR_VALUE_UNDEFINED;
  491. prio = DCB_ATTR_VALUE_UNDEFINED;
  492. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  493. up_map = DCB_ATTR_VALUE_UNDEFINED;
  494. if (dir) {
  495. /* Rx */
  496. netdev->dcbnl_ops->getpgtccfgrx(netdev,
  497. i - DCB_PG_ATTR_TC_0, &prio,
  498. &pgid, &tc_pct, &up_map);
  499. } else {
  500. /* Tx */
  501. netdev->dcbnl_ops->getpgtccfgtx(netdev,
  502. i - DCB_PG_ATTR_TC_0, &prio,
  503. &pgid, &tc_pct, &up_map);
  504. }
  505. if (param_tb[DCB_TC_ATTR_PARAM_PGID] ||
  506. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  507. ret = nla_put_u8(dcbnl_skb,
  508. DCB_TC_ATTR_PARAM_PGID, pgid);
  509. if (ret)
  510. goto err_param;
  511. }
  512. if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] ||
  513. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  514. ret = nla_put_u8(dcbnl_skb,
  515. DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
  516. if (ret)
  517. goto err_param;
  518. }
  519. if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] ||
  520. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  521. ret = nla_put_u8(dcbnl_skb,
  522. DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
  523. if (ret)
  524. goto err_param;
  525. }
  526. if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] ||
  527. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  528. ret = nla_put_u8(dcbnl_skb, DCB_TC_ATTR_PARAM_BW_PCT,
  529. tc_pct);
  530. if (ret)
  531. goto err_param;
  532. }
  533. nla_nest_end(dcbnl_skb, param_nest);
  534. }
  535. if (pg_tb[DCB_PG_ATTR_BW_ID_ALL])
  536. getall = 1;
  537. else
  538. getall = 0;
  539. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  540. if (!getall && !pg_tb[i])
  541. continue;
  542. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  543. if (dir) {
  544. /* Rx */
  545. netdev->dcbnl_ops->getpgbwgcfgrx(netdev,
  546. i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
  547. } else {
  548. /* Tx */
  549. netdev->dcbnl_ops->getpgbwgcfgtx(netdev,
  550. i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
  551. }
  552. ret = nla_put_u8(dcbnl_skb, i, tc_pct);
  553. if (ret)
  554. goto err_pg;
  555. }
  556. nla_nest_end(dcbnl_skb, pg_nest);
  557. nlmsg_end(dcbnl_skb, nlh);
  558. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  559. if (ret)
  560. goto err;
  561. return 0;
  562. err_param:
  563. nla_nest_cancel(dcbnl_skb, param_nest);
  564. err_pg:
  565. nla_nest_cancel(dcbnl_skb, pg_nest);
  566. nlmsg_failure:
  567. err:
  568. kfree(dcbnl_skb);
  569. err_out:
  570. ret = -EINVAL;
  571. return ret;
  572. }
  573. static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlattr **tb,
  574. u32 pid, u32 seq, u16 flags)
  575. {
  576. return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 0);
  577. }
  578. static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlattr **tb,
  579. u32 pid, u32 seq, u16 flags)
  580. {
  581. return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 1);
  582. }
  583. static int dcbnl_setstate(struct net_device *netdev, struct nlattr **tb,
  584. u32 pid, u32 seq, u16 flags)
  585. {
  586. int ret = -EINVAL;
  587. u8 value;
  588. if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->setstate)
  589. return ret;
  590. value = nla_get_u8(tb[DCB_ATTR_STATE]);
  591. netdev->dcbnl_ops->setstate(netdev, value);
  592. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_SSTATE, DCB_ATTR_STATE,
  593. pid, seq, flags);
  594. return ret;
  595. }
  596. static int dcbnl_setpfccfg(struct net_device *netdev, struct nlattr **tb,
  597. u32 pid, u32 seq, u16 flags)
  598. {
  599. struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1];
  600. int i;
  601. int ret = -EINVAL;
  602. u8 value;
  603. if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->setpfccfg)
  604. return ret;
  605. ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
  606. tb[DCB_ATTR_PFC_CFG],
  607. dcbnl_pfc_up_nest);
  608. if (ret)
  609. goto err;
  610. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  611. if (data[i] == NULL)
  612. continue;
  613. value = nla_get_u8(data[i]);
  614. netdev->dcbnl_ops->setpfccfg(netdev,
  615. data[i]->nla_type - DCB_PFC_UP_ATTR_0, value);
  616. }
  617. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SCFG, DCB_ATTR_PFC_CFG,
  618. pid, seq, flags);
  619. err:
  620. return ret;
  621. }
  622. static int dcbnl_setall(struct net_device *netdev, struct nlattr **tb,
  623. u32 pid, u32 seq, u16 flags)
  624. {
  625. int ret = -EINVAL;
  626. if (!tb[DCB_ATTR_SET_ALL] || !netdev->dcbnl_ops->setall)
  627. return ret;
  628. ret = dcbnl_reply(netdev->dcbnl_ops->setall(netdev), RTM_SETDCB,
  629. DCB_CMD_SET_ALL, DCB_ATTR_SET_ALL, pid, seq, flags);
  630. return ret;
  631. }
  632. static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlattr **tb,
  633. u32 pid, u32 seq, u16 flags, int dir)
  634. {
  635. struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
  636. struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
  637. int ret = -EINVAL;
  638. int i;
  639. u8 pgid;
  640. u8 up_map;
  641. u8 prio;
  642. u8 tc_pct;
  643. if (!tb[DCB_ATTR_PG_CFG] ||
  644. !netdev->dcbnl_ops->setpgtccfgtx ||
  645. !netdev->dcbnl_ops->setpgtccfgrx ||
  646. !netdev->dcbnl_ops->setpgbwgcfgtx ||
  647. !netdev->dcbnl_ops->setpgbwgcfgrx)
  648. return ret;
  649. ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
  650. tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
  651. if (ret)
  652. goto err;
  653. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  654. if (!pg_tb[i])
  655. continue;
  656. ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
  657. pg_tb[i], dcbnl_tc_param_nest);
  658. if (ret)
  659. goto err;
  660. pgid = DCB_ATTR_VALUE_UNDEFINED;
  661. prio = DCB_ATTR_VALUE_UNDEFINED;
  662. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  663. up_map = DCB_ATTR_VALUE_UNDEFINED;
  664. if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO])
  665. prio =
  666. nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]);
  667. if (param_tb[DCB_TC_ATTR_PARAM_PGID])
  668. pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]);
  669. if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT])
  670. tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]);
  671. if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING])
  672. up_map =
  673. nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]);
  674. /* dir: Tx = 0, Rx = 1 */
  675. if (dir) {
  676. /* Rx */
  677. netdev->dcbnl_ops->setpgtccfgrx(netdev,
  678. i - DCB_PG_ATTR_TC_0,
  679. prio, pgid, tc_pct, up_map);
  680. } else {
  681. /* Tx */
  682. netdev->dcbnl_ops->setpgtccfgtx(netdev,
  683. i - DCB_PG_ATTR_TC_0,
  684. prio, pgid, tc_pct, up_map);
  685. }
  686. }
  687. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  688. if (!pg_tb[i])
  689. continue;
  690. tc_pct = nla_get_u8(pg_tb[i]);
  691. /* dir: Tx = 0, Rx = 1 */
  692. if (dir) {
  693. /* Rx */
  694. netdev->dcbnl_ops->setpgbwgcfgrx(netdev,
  695. i - DCB_PG_ATTR_BW_ID_0, tc_pct);
  696. } else {
  697. /* Tx */
  698. netdev->dcbnl_ops->setpgbwgcfgtx(netdev,
  699. i - DCB_PG_ATTR_BW_ID_0, tc_pct);
  700. }
  701. }
  702. ret = dcbnl_reply(0, RTM_SETDCB,
  703. (dir ? DCB_CMD_PGRX_SCFG : DCB_CMD_PGTX_SCFG),
  704. DCB_ATTR_PG_CFG, pid, seq, flags);
  705. err:
  706. return ret;
  707. }
  708. static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlattr **tb,
  709. u32 pid, u32 seq, u16 flags)
  710. {
  711. return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 0);
  712. }
  713. static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlattr **tb,
  714. u32 pid, u32 seq, u16 flags)
  715. {
  716. return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 1);
  717. }
  718. static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlattr **tb,
  719. u32 pid, u32 seq, u16 flags)
  720. {
  721. struct sk_buff *dcbnl_skb;
  722. struct nlmsghdr *nlh;
  723. struct dcbmsg *dcb;
  724. struct nlattr *bcn_nest;
  725. struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1];
  726. u8 value_byte;
  727. u32 value_integer;
  728. int ret = -EINVAL;
  729. bool getall = false;
  730. int i;
  731. if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->getbcnrp ||
  732. !netdev->dcbnl_ops->getbcncfg)
  733. return ret;
  734. ret = nla_parse_nested(bcn_tb, DCB_BCN_ATTR_MAX,
  735. tb[DCB_ATTR_BCN], dcbnl_bcn_nest);
  736. if (ret)
  737. goto err_out;
  738. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  739. if (!dcbnl_skb)
  740. goto err_out;
  741. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  742. dcb = NLMSG_DATA(nlh);
  743. dcb->dcb_family = AF_UNSPEC;
  744. dcb->cmd = DCB_CMD_BCN_GCFG;
  745. bcn_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_BCN);
  746. if (!bcn_nest)
  747. goto err;
  748. if (bcn_tb[DCB_BCN_ATTR_ALL])
  749. getall = true;
  750. for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
  751. if (!getall && !bcn_tb[i])
  752. continue;
  753. netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0,
  754. &value_byte);
  755. ret = nla_put_u8(dcbnl_skb, i, value_byte);
  756. if (ret)
  757. goto err_bcn;
  758. }
  759. for (i = DCB_BCN_ATTR_ALPHA; i <= DCB_BCN_ATTR_RI; i++) {
  760. if (!getall && !bcn_tb[i])
  761. continue;
  762. netdev->dcbnl_ops->getbcncfg(netdev, i,
  763. &value_integer);
  764. ret = nla_put_u32(dcbnl_skb, i, value_integer);
  765. if (ret)
  766. goto err_bcn;
  767. }
  768. nla_nest_end(dcbnl_skb, bcn_nest);
  769. nlmsg_end(dcbnl_skb, nlh);
  770. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  771. if (ret)
  772. goto err;
  773. return 0;
  774. err_bcn:
  775. nla_nest_cancel(dcbnl_skb, bcn_nest);
  776. nlmsg_failure:
  777. err:
  778. kfree(dcbnl_skb);
  779. err_out:
  780. ret = -EINVAL;
  781. return ret;
  782. }
  783. static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlattr **tb,
  784. u32 pid, u32 seq, u16 flags)
  785. {
  786. struct nlattr *data[DCB_BCN_ATTR_MAX + 1];
  787. int i;
  788. int ret = -EINVAL;
  789. u8 value_byte;
  790. u32 value_int;
  791. if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->setbcncfg
  792. || !netdev->dcbnl_ops->setbcnrp)
  793. return ret;
  794. ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX,
  795. tb[DCB_ATTR_BCN],
  796. dcbnl_pfc_up_nest);
  797. if (ret)
  798. goto err;
  799. for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
  800. if (data[i] == NULL)
  801. continue;
  802. value_byte = nla_get_u8(data[i]);
  803. netdev->dcbnl_ops->setbcnrp(netdev,
  804. data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte);
  805. }
  806. for (i = DCB_BCN_ATTR_ALPHA; i <= DCB_BCN_ATTR_RI; i++) {
  807. if (data[i] == NULL)
  808. continue;
  809. value_int = nla_get_u32(data[i]);
  810. netdev->dcbnl_ops->setbcncfg(netdev,
  811. i, value_int);
  812. }
  813. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_BCN_SCFG, DCB_ATTR_BCN,
  814. pid, seq, flags);
  815. err:
  816. return ret;
  817. }
  818. static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
  819. {
  820. struct net *net = sock_net(skb->sk);
  821. struct net_device *netdev;
  822. struct dcbmsg *dcb = (struct dcbmsg *)NLMSG_DATA(nlh);
  823. struct nlattr *tb[DCB_ATTR_MAX + 1];
  824. u32 pid = skb ? NETLINK_CB(skb).pid : 0;
  825. int ret = -EINVAL;
  826. if (net != &init_net)
  827. return -EINVAL;
  828. ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
  829. dcbnl_rtnl_policy);
  830. if (ret < 0)
  831. return ret;
  832. if (!tb[DCB_ATTR_IFNAME])
  833. return -EINVAL;
  834. netdev = dev_get_by_name(&init_net, nla_data(tb[DCB_ATTR_IFNAME]));
  835. if (!netdev)
  836. return -EINVAL;
  837. if (!netdev->dcbnl_ops)
  838. goto errout;
  839. switch (dcb->cmd) {
  840. case DCB_CMD_GSTATE:
  841. ret = dcbnl_getstate(netdev, tb, pid, nlh->nlmsg_seq,
  842. nlh->nlmsg_flags);
  843. goto out;
  844. case DCB_CMD_PFC_GCFG:
  845. ret = dcbnl_getpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  846. nlh->nlmsg_flags);
  847. goto out;
  848. case DCB_CMD_GPERM_HWADDR:
  849. ret = dcbnl_getperm_hwaddr(netdev, tb, pid, nlh->nlmsg_seq,
  850. nlh->nlmsg_flags);
  851. goto out;
  852. case DCB_CMD_PGTX_GCFG:
  853. ret = dcbnl_pgtx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  854. nlh->nlmsg_flags);
  855. goto out;
  856. case DCB_CMD_PGRX_GCFG:
  857. ret = dcbnl_pgrx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  858. nlh->nlmsg_flags);
  859. goto out;
  860. case DCB_CMD_BCN_GCFG:
  861. ret = dcbnl_bcn_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  862. nlh->nlmsg_flags);
  863. goto out;
  864. case DCB_CMD_SSTATE:
  865. ret = dcbnl_setstate(netdev, tb, pid, nlh->nlmsg_seq,
  866. nlh->nlmsg_flags);
  867. goto out;
  868. case DCB_CMD_PFC_SCFG:
  869. ret = dcbnl_setpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  870. nlh->nlmsg_flags);
  871. goto out;
  872. case DCB_CMD_SET_ALL:
  873. ret = dcbnl_setall(netdev, tb, pid, nlh->nlmsg_seq,
  874. nlh->nlmsg_flags);
  875. goto out;
  876. case DCB_CMD_PGTX_SCFG:
  877. ret = dcbnl_pgtx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  878. nlh->nlmsg_flags);
  879. goto out;
  880. case DCB_CMD_PGRX_SCFG:
  881. ret = dcbnl_pgrx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  882. nlh->nlmsg_flags);
  883. goto out;
  884. case DCB_CMD_GCAP:
  885. ret = dcbnl_getcap(netdev, tb, pid, nlh->nlmsg_seq,
  886. nlh->nlmsg_flags);
  887. goto out;
  888. case DCB_CMD_GNUMTCS:
  889. ret = dcbnl_getnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  890. nlh->nlmsg_flags);
  891. goto out;
  892. case DCB_CMD_SNUMTCS:
  893. ret = dcbnl_setnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  894. nlh->nlmsg_flags);
  895. goto out;
  896. case DCB_CMD_PFC_GSTATE:
  897. ret = dcbnl_getpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  898. nlh->nlmsg_flags);
  899. goto out;
  900. case DCB_CMD_PFC_SSTATE:
  901. ret = dcbnl_setpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  902. nlh->nlmsg_flags);
  903. goto out;
  904. case DCB_CMD_BCN_SCFG:
  905. ret = dcbnl_bcn_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  906. nlh->nlmsg_flags);
  907. goto out;
  908. default:
  909. goto errout;
  910. }
  911. errout:
  912. ret = -EINVAL;
  913. out:
  914. dev_put(netdev);
  915. return ret;
  916. }
  917. static int __init dcbnl_init(void)
  918. {
  919. rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL);
  920. rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL);
  921. return 0;
  922. }
  923. module_init(dcbnl_init);
  924. static void __exit dcbnl_exit(void)
  925. {
  926. rtnl_unregister(PF_UNSPEC, RTM_GETDCB);
  927. rtnl_unregister(PF_UNSPEC, RTM_SETDCB);
  928. }
  929. module_exit(dcbnl_exit);