dcbnl.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252
  1. /*
  2. * Copyright (c) 2008-2011, 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 <linux/slab.h>
  22. #include <net/netlink.h>
  23. #include <net/rtnetlink.h>
  24. #include <linux/dcbnl.h>
  25. #include <net/dcbevent.h>
  26. #include <linux/rtnetlink.h>
  27. #include <net/sock.h>
  28. /**
  29. * Data Center Bridging (DCB) is a collection of Ethernet enhancements
  30. * intended to allow network traffic with differing requirements
  31. * (highly reliable, no drops vs. best effort vs. low latency) to operate
  32. * and co-exist on Ethernet. Current DCB features are:
  33. *
  34. * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
  35. * framework for assigning bandwidth guarantees to traffic classes.
  36. *
  37. * Priority-based Flow Control (PFC) - provides a flow control mechanism which
  38. * can work independently for each 802.1p priority.
  39. *
  40. * Congestion Notification - provides a mechanism for end-to-end congestion
  41. * control for protocols which do not have built-in congestion management.
  42. *
  43. * More information about the emerging standards for these Ethernet features
  44. * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
  45. *
  46. * This file implements an rtnetlink interface to allow configuration of DCB
  47. * features for capable devices.
  48. */
  49. MODULE_AUTHOR("Lucy Liu, <lucy.liu@intel.com>");
  50. MODULE_DESCRIPTION("Data Center Bridging netlink interface");
  51. MODULE_LICENSE("GPL");
  52. /**************** DCB attribute policies *************************************/
  53. /* DCB netlink attributes policy */
  54. static const struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = {
  55. [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1},
  56. [DCB_ATTR_STATE] = {.type = NLA_U8},
  57. [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED},
  58. [DCB_ATTR_PG_CFG] = {.type = NLA_NESTED},
  59. [DCB_ATTR_SET_ALL] = {.type = NLA_U8},
  60. [DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG},
  61. [DCB_ATTR_CAP] = {.type = NLA_NESTED},
  62. [DCB_ATTR_PFC_STATE] = {.type = NLA_U8},
  63. [DCB_ATTR_BCN] = {.type = NLA_NESTED},
  64. [DCB_ATTR_APP] = {.type = NLA_NESTED},
  65. [DCB_ATTR_IEEE] = {.type = NLA_NESTED},
  66. [DCB_ATTR_DCBX] = {.type = NLA_U8},
  67. [DCB_ATTR_FEATCFG] = {.type = NLA_NESTED},
  68. };
  69. /* DCB priority flow control to User Priority nested attributes */
  70. static const struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = {
  71. [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8},
  72. [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8},
  73. [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8},
  74. [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8},
  75. [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8},
  76. [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8},
  77. [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8},
  78. [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8},
  79. [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG},
  80. };
  81. /* DCB priority grouping nested attributes */
  82. static const struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = {
  83. [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED},
  84. [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED},
  85. [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED},
  86. [DCB_PG_ATTR_TC_3] = {.type = NLA_NESTED},
  87. [DCB_PG_ATTR_TC_4] = {.type = NLA_NESTED},
  88. [DCB_PG_ATTR_TC_5] = {.type = NLA_NESTED},
  89. [DCB_PG_ATTR_TC_6] = {.type = NLA_NESTED},
  90. [DCB_PG_ATTR_TC_7] = {.type = NLA_NESTED},
  91. [DCB_PG_ATTR_TC_ALL] = {.type = NLA_NESTED},
  92. [DCB_PG_ATTR_BW_ID_0] = {.type = NLA_U8},
  93. [DCB_PG_ATTR_BW_ID_1] = {.type = NLA_U8},
  94. [DCB_PG_ATTR_BW_ID_2] = {.type = NLA_U8},
  95. [DCB_PG_ATTR_BW_ID_3] = {.type = NLA_U8},
  96. [DCB_PG_ATTR_BW_ID_4] = {.type = NLA_U8},
  97. [DCB_PG_ATTR_BW_ID_5] = {.type = NLA_U8},
  98. [DCB_PG_ATTR_BW_ID_6] = {.type = NLA_U8},
  99. [DCB_PG_ATTR_BW_ID_7] = {.type = NLA_U8},
  100. [DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG},
  101. };
  102. /* DCB traffic class nested attributes. */
  103. static const struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = {
  104. [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8},
  105. [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8},
  106. [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8},
  107. [DCB_TC_ATTR_PARAM_BW_PCT] = {.type = NLA_U8},
  108. [DCB_TC_ATTR_PARAM_ALL] = {.type = NLA_FLAG},
  109. };
  110. /* DCB capabilities nested attributes. */
  111. static const struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = {
  112. [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG},
  113. [DCB_CAP_ATTR_PG] = {.type = NLA_U8},
  114. [DCB_CAP_ATTR_PFC] = {.type = NLA_U8},
  115. [DCB_CAP_ATTR_UP2TC] = {.type = NLA_U8},
  116. [DCB_CAP_ATTR_PG_TCS] = {.type = NLA_U8},
  117. [DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8},
  118. [DCB_CAP_ATTR_GSP] = {.type = NLA_U8},
  119. [DCB_CAP_ATTR_BCN] = {.type = NLA_U8},
  120. [DCB_CAP_ATTR_DCBX] = {.type = NLA_U8},
  121. };
  122. /* DCB capabilities nested attributes. */
  123. static const struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = {
  124. [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG},
  125. [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8},
  126. [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8},
  127. };
  128. /* DCB BCN nested attributes. */
  129. static const struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = {
  130. [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8},
  131. [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8},
  132. [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8},
  133. [DCB_BCN_ATTR_RP_3] = {.type = NLA_U8},
  134. [DCB_BCN_ATTR_RP_4] = {.type = NLA_U8},
  135. [DCB_BCN_ATTR_RP_5] = {.type = NLA_U8},
  136. [DCB_BCN_ATTR_RP_6] = {.type = NLA_U8},
  137. [DCB_BCN_ATTR_RP_7] = {.type = NLA_U8},
  138. [DCB_BCN_ATTR_RP_ALL] = {.type = NLA_FLAG},
  139. [DCB_BCN_ATTR_BCNA_0] = {.type = NLA_U32},
  140. [DCB_BCN_ATTR_BCNA_1] = {.type = NLA_U32},
  141. [DCB_BCN_ATTR_ALPHA] = {.type = NLA_U32},
  142. [DCB_BCN_ATTR_BETA] = {.type = NLA_U32},
  143. [DCB_BCN_ATTR_GD] = {.type = NLA_U32},
  144. [DCB_BCN_ATTR_GI] = {.type = NLA_U32},
  145. [DCB_BCN_ATTR_TMAX] = {.type = NLA_U32},
  146. [DCB_BCN_ATTR_TD] = {.type = NLA_U32},
  147. [DCB_BCN_ATTR_RMIN] = {.type = NLA_U32},
  148. [DCB_BCN_ATTR_W] = {.type = NLA_U32},
  149. [DCB_BCN_ATTR_RD] = {.type = NLA_U32},
  150. [DCB_BCN_ATTR_RU] = {.type = NLA_U32},
  151. [DCB_BCN_ATTR_WRTT] = {.type = NLA_U32},
  152. [DCB_BCN_ATTR_RI] = {.type = NLA_U32},
  153. [DCB_BCN_ATTR_C] = {.type = NLA_U32},
  154. [DCB_BCN_ATTR_ALL] = {.type = NLA_FLAG},
  155. };
  156. /* DCB APP nested attributes. */
  157. static const struct nla_policy dcbnl_app_nest[DCB_APP_ATTR_MAX + 1] = {
  158. [DCB_APP_ATTR_IDTYPE] = {.type = NLA_U8},
  159. [DCB_APP_ATTR_ID] = {.type = NLA_U16},
  160. [DCB_APP_ATTR_PRIORITY] = {.type = NLA_U8},
  161. };
  162. /* IEEE 802.1Qaz nested attributes. */
  163. static const struct nla_policy dcbnl_ieee_policy[DCB_ATTR_IEEE_MAX + 1] = {
  164. [DCB_ATTR_IEEE_ETS] = {.len = sizeof(struct ieee_ets)},
  165. [DCB_ATTR_IEEE_PFC] = {.len = sizeof(struct ieee_pfc)},
  166. [DCB_ATTR_IEEE_APP_TABLE] = {.type = NLA_NESTED},
  167. };
  168. static const struct nla_policy dcbnl_ieee_app[DCB_ATTR_IEEE_APP_MAX + 1] = {
  169. [DCB_ATTR_IEEE_APP] = {.len = sizeof(struct dcb_app)},
  170. };
  171. /* DCB number of traffic classes nested attributes. */
  172. static const struct nla_policy dcbnl_featcfg_nest[DCB_FEATCFG_ATTR_MAX + 1] = {
  173. [DCB_FEATCFG_ATTR_ALL] = {.type = NLA_FLAG},
  174. [DCB_FEATCFG_ATTR_PG] = {.type = NLA_U8},
  175. [DCB_FEATCFG_ATTR_PFC] = {.type = NLA_U8},
  176. [DCB_FEATCFG_ATTR_APP] = {.type = NLA_U8},
  177. };
  178. static LIST_HEAD(dcb_app_list);
  179. static DEFINE_SPINLOCK(dcb_lock);
  180. /* standard netlink reply call */
  181. static int dcbnl_reply(u8 value, u8 event, u8 cmd, u8 attr, u32 pid,
  182. u32 seq, u16 flags)
  183. {
  184. struct sk_buff *dcbnl_skb;
  185. struct dcbmsg *dcb;
  186. struct nlmsghdr *nlh;
  187. int ret = -EINVAL;
  188. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  189. if (!dcbnl_skb)
  190. return ret;
  191. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, event, sizeof(*dcb), flags);
  192. dcb = NLMSG_DATA(nlh);
  193. dcb->dcb_family = AF_UNSPEC;
  194. dcb->cmd = cmd;
  195. dcb->dcb_pad = 0;
  196. ret = nla_put_u8(dcbnl_skb, attr, value);
  197. if (ret)
  198. goto err;
  199. /* end the message, assign the nlmsg_len. */
  200. nlmsg_end(dcbnl_skb, nlh);
  201. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  202. if (ret)
  203. return -EINVAL;
  204. return 0;
  205. nlmsg_failure:
  206. err:
  207. kfree_skb(dcbnl_skb);
  208. return ret;
  209. }
  210. static int dcbnl_getstate(struct net_device *netdev, struct nlattr **tb,
  211. u32 pid, u32 seq, u16 flags)
  212. {
  213. int ret = -EINVAL;
  214. /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
  215. if (!netdev->dcbnl_ops->getstate)
  216. return ret;
  217. ret = dcbnl_reply(netdev->dcbnl_ops->getstate(netdev), RTM_GETDCB,
  218. DCB_CMD_GSTATE, DCB_ATTR_STATE, pid, seq, flags);
  219. return ret;
  220. }
  221. static int dcbnl_getpfccfg(struct net_device *netdev, struct nlattr **tb,
  222. u32 pid, u32 seq, u16 flags)
  223. {
  224. struct sk_buff *dcbnl_skb;
  225. struct nlmsghdr *nlh;
  226. struct dcbmsg *dcb;
  227. struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest;
  228. u8 value;
  229. int ret = -EINVAL;
  230. int i;
  231. int getall = 0;
  232. if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->getpfccfg)
  233. return ret;
  234. ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
  235. tb[DCB_ATTR_PFC_CFG],
  236. dcbnl_pfc_up_nest);
  237. if (ret)
  238. goto err_out;
  239. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  240. if (!dcbnl_skb)
  241. goto err_out;
  242. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  243. dcb = NLMSG_DATA(nlh);
  244. dcb->dcb_family = AF_UNSPEC;
  245. dcb->cmd = DCB_CMD_PFC_GCFG;
  246. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PFC_CFG);
  247. if (!nest)
  248. goto err;
  249. if (data[DCB_PFC_UP_ATTR_ALL])
  250. getall = 1;
  251. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  252. if (!getall && !data[i])
  253. continue;
  254. netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0,
  255. &value);
  256. ret = nla_put_u8(dcbnl_skb, i, value);
  257. if (ret) {
  258. nla_nest_cancel(dcbnl_skb, nest);
  259. goto err;
  260. }
  261. }
  262. nla_nest_end(dcbnl_skb, nest);
  263. nlmsg_end(dcbnl_skb, nlh);
  264. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  265. if (ret)
  266. goto err_out;
  267. return 0;
  268. nlmsg_failure:
  269. err:
  270. kfree_skb(dcbnl_skb);
  271. err_out:
  272. return -EINVAL;
  273. }
  274. static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlattr **tb,
  275. u32 pid, u32 seq, u16 flags)
  276. {
  277. struct sk_buff *dcbnl_skb;
  278. struct nlmsghdr *nlh;
  279. struct dcbmsg *dcb;
  280. u8 perm_addr[MAX_ADDR_LEN];
  281. int ret = -EINVAL;
  282. if (!netdev->dcbnl_ops->getpermhwaddr)
  283. return ret;
  284. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  285. if (!dcbnl_skb)
  286. goto err_out;
  287. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  288. dcb = NLMSG_DATA(nlh);
  289. dcb->dcb_family = AF_UNSPEC;
  290. dcb->cmd = DCB_CMD_GPERM_HWADDR;
  291. netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
  292. ret = nla_put(dcbnl_skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr),
  293. perm_addr);
  294. nlmsg_end(dcbnl_skb, nlh);
  295. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  296. if (ret)
  297. goto err_out;
  298. return 0;
  299. nlmsg_failure:
  300. kfree_skb(dcbnl_skb);
  301. err_out:
  302. return -EINVAL;
  303. }
  304. static int dcbnl_getcap(struct net_device *netdev, struct nlattr **tb,
  305. u32 pid, u32 seq, u16 flags)
  306. {
  307. struct sk_buff *dcbnl_skb;
  308. struct nlmsghdr *nlh;
  309. struct dcbmsg *dcb;
  310. struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest;
  311. u8 value;
  312. int ret = -EINVAL;
  313. int i;
  314. int getall = 0;
  315. if (!tb[DCB_ATTR_CAP] || !netdev->dcbnl_ops->getcap)
  316. return ret;
  317. ret = nla_parse_nested(data, DCB_CAP_ATTR_MAX, tb[DCB_ATTR_CAP],
  318. dcbnl_cap_nest);
  319. if (ret)
  320. goto err_out;
  321. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  322. if (!dcbnl_skb)
  323. goto err_out;
  324. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  325. dcb = NLMSG_DATA(nlh);
  326. dcb->dcb_family = AF_UNSPEC;
  327. dcb->cmd = DCB_CMD_GCAP;
  328. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_CAP);
  329. if (!nest)
  330. goto err;
  331. if (data[DCB_CAP_ATTR_ALL])
  332. getall = 1;
  333. for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) {
  334. if (!getall && !data[i])
  335. continue;
  336. if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) {
  337. ret = nla_put_u8(dcbnl_skb, i, value);
  338. if (ret) {
  339. nla_nest_cancel(dcbnl_skb, nest);
  340. goto err;
  341. }
  342. }
  343. }
  344. nla_nest_end(dcbnl_skb, nest);
  345. nlmsg_end(dcbnl_skb, nlh);
  346. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  347. if (ret)
  348. goto err_out;
  349. return 0;
  350. nlmsg_failure:
  351. err:
  352. kfree_skb(dcbnl_skb);
  353. err_out:
  354. return -EINVAL;
  355. }
  356. static int dcbnl_getnumtcs(struct net_device *netdev, struct nlattr **tb,
  357. u32 pid, u32 seq, u16 flags)
  358. {
  359. struct sk_buff *dcbnl_skb;
  360. struct nlmsghdr *nlh;
  361. struct dcbmsg *dcb;
  362. struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest;
  363. u8 value;
  364. int ret = -EINVAL;
  365. int i;
  366. int getall = 0;
  367. if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->getnumtcs)
  368. return ret;
  369. ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
  370. dcbnl_numtcs_nest);
  371. if (ret) {
  372. ret = -EINVAL;
  373. goto err_out;
  374. }
  375. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  376. if (!dcbnl_skb) {
  377. ret = -EINVAL;
  378. goto err_out;
  379. }
  380. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  381. dcb = NLMSG_DATA(nlh);
  382. dcb->dcb_family = AF_UNSPEC;
  383. dcb->cmd = DCB_CMD_GNUMTCS;
  384. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_NUMTCS);
  385. if (!nest) {
  386. ret = -EINVAL;
  387. goto err;
  388. }
  389. if (data[DCB_NUMTCS_ATTR_ALL])
  390. getall = 1;
  391. for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
  392. if (!getall && !data[i])
  393. continue;
  394. ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value);
  395. if (!ret) {
  396. ret = nla_put_u8(dcbnl_skb, i, value);
  397. if (ret) {
  398. nla_nest_cancel(dcbnl_skb, nest);
  399. ret = -EINVAL;
  400. goto err;
  401. }
  402. } else {
  403. goto err;
  404. }
  405. }
  406. nla_nest_end(dcbnl_skb, nest);
  407. nlmsg_end(dcbnl_skb, nlh);
  408. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  409. if (ret) {
  410. ret = -EINVAL;
  411. goto err_out;
  412. }
  413. return 0;
  414. nlmsg_failure:
  415. err:
  416. kfree_skb(dcbnl_skb);
  417. err_out:
  418. return ret;
  419. }
  420. static int dcbnl_setnumtcs(struct net_device *netdev, struct nlattr **tb,
  421. u32 pid, u32 seq, u16 flags)
  422. {
  423. struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1];
  424. int ret = -EINVAL;
  425. u8 value;
  426. int i;
  427. if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->setnumtcs)
  428. return ret;
  429. ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
  430. dcbnl_numtcs_nest);
  431. if (ret) {
  432. ret = -EINVAL;
  433. goto err;
  434. }
  435. for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
  436. if (data[i] == NULL)
  437. continue;
  438. value = nla_get_u8(data[i]);
  439. ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value);
  440. if (ret)
  441. goto operr;
  442. }
  443. operr:
  444. ret = dcbnl_reply(!!ret, RTM_SETDCB, DCB_CMD_SNUMTCS,
  445. DCB_ATTR_NUMTCS, pid, seq, flags);
  446. err:
  447. return ret;
  448. }
  449. static int dcbnl_getpfcstate(struct net_device *netdev, struct nlattr **tb,
  450. u32 pid, u32 seq, u16 flags)
  451. {
  452. int ret = -EINVAL;
  453. if (!netdev->dcbnl_ops->getpfcstate)
  454. return ret;
  455. ret = dcbnl_reply(netdev->dcbnl_ops->getpfcstate(netdev), RTM_GETDCB,
  456. DCB_CMD_PFC_GSTATE, DCB_ATTR_PFC_STATE,
  457. pid, seq, flags);
  458. return ret;
  459. }
  460. static int dcbnl_setpfcstate(struct net_device *netdev, struct nlattr **tb,
  461. u32 pid, u32 seq, u16 flags)
  462. {
  463. int ret = -EINVAL;
  464. u8 value;
  465. if (!tb[DCB_ATTR_PFC_STATE] || !netdev->dcbnl_ops->setpfcstate)
  466. return ret;
  467. value = nla_get_u8(tb[DCB_ATTR_PFC_STATE]);
  468. netdev->dcbnl_ops->setpfcstate(netdev, value);
  469. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SSTATE, DCB_ATTR_PFC_STATE,
  470. pid, seq, flags);
  471. return ret;
  472. }
  473. static int dcbnl_getapp(struct net_device *netdev, struct nlattr **tb,
  474. u32 pid, u32 seq, u16 flags)
  475. {
  476. struct sk_buff *dcbnl_skb;
  477. struct nlmsghdr *nlh;
  478. struct dcbmsg *dcb;
  479. struct nlattr *app_nest;
  480. struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1];
  481. u16 id;
  482. u8 up, idtype;
  483. int ret = -EINVAL;
  484. if (!tb[DCB_ATTR_APP])
  485. goto out;
  486. ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP],
  487. dcbnl_app_nest);
  488. if (ret)
  489. goto out;
  490. ret = -EINVAL;
  491. /* all must be non-null */
  492. if ((!app_tb[DCB_APP_ATTR_IDTYPE]) ||
  493. (!app_tb[DCB_APP_ATTR_ID]))
  494. goto out;
  495. /* either by eth type or by socket number */
  496. idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]);
  497. if ((idtype != DCB_APP_IDTYPE_ETHTYPE) &&
  498. (idtype != DCB_APP_IDTYPE_PORTNUM))
  499. goto out;
  500. id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]);
  501. if (netdev->dcbnl_ops->getapp) {
  502. up = netdev->dcbnl_ops->getapp(netdev, idtype, id);
  503. } else {
  504. struct dcb_app app = {
  505. .selector = idtype,
  506. .protocol = id,
  507. };
  508. up = dcb_getapp(netdev, &app);
  509. }
  510. /* send this back */
  511. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  512. if (!dcbnl_skb)
  513. goto out;
  514. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  515. dcb = NLMSG_DATA(nlh);
  516. dcb->dcb_family = AF_UNSPEC;
  517. dcb->cmd = DCB_CMD_GAPP;
  518. app_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_APP);
  519. if (!app_nest)
  520. goto out_cancel;
  521. ret = nla_put_u8(dcbnl_skb, DCB_APP_ATTR_IDTYPE, idtype);
  522. if (ret)
  523. goto out_cancel;
  524. ret = nla_put_u16(dcbnl_skb, DCB_APP_ATTR_ID, id);
  525. if (ret)
  526. goto out_cancel;
  527. ret = nla_put_u8(dcbnl_skb, DCB_APP_ATTR_PRIORITY, up);
  528. if (ret)
  529. goto out_cancel;
  530. nla_nest_end(dcbnl_skb, app_nest);
  531. nlmsg_end(dcbnl_skb, nlh);
  532. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  533. if (ret)
  534. goto nlmsg_failure;
  535. goto out;
  536. out_cancel:
  537. nla_nest_cancel(dcbnl_skb, app_nest);
  538. nlmsg_failure:
  539. kfree_skb(dcbnl_skb);
  540. out:
  541. return ret;
  542. }
  543. static int dcbnl_setapp(struct net_device *netdev, struct nlattr **tb,
  544. u32 pid, u32 seq, u16 flags)
  545. {
  546. int err, ret = -EINVAL;
  547. u16 id;
  548. u8 up, idtype;
  549. struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1];
  550. if (!tb[DCB_ATTR_APP])
  551. goto out;
  552. ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP],
  553. dcbnl_app_nest);
  554. if (ret)
  555. goto out;
  556. ret = -EINVAL;
  557. /* all must be non-null */
  558. if ((!app_tb[DCB_APP_ATTR_IDTYPE]) ||
  559. (!app_tb[DCB_APP_ATTR_ID]) ||
  560. (!app_tb[DCB_APP_ATTR_PRIORITY]))
  561. goto out;
  562. /* either by eth type or by socket number */
  563. idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]);
  564. if ((idtype != DCB_APP_IDTYPE_ETHTYPE) &&
  565. (idtype != DCB_APP_IDTYPE_PORTNUM))
  566. goto out;
  567. id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]);
  568. up = nla_get_u8(app_tb[DCB_APP_ATTR_PRIORITY]);
  569. if (netdev->dcbnl_ops->setapp) {
  570. err = netdev->dcbnl_ops->setapp(netdev, idtype, id, up);
  571. } else {
  572. struct dcb_app app;
  573. app.selector = idtype;
  574. app.protocol = id;
  575. app.priority = up;
  576. err = dcb_setapp(netdev, &app);
  577. }
  578. ret = dcbnl_reply(err, RTM_SETDCB, DCB_CMD_SAPP, DCB_ATTR_APP,
  579. pid, seq, flags);
  580. out:
  581. return ret;
  582. }
  583. static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlattr **tb,
  584. u32 pid, u32 seq, u16 flags, int dir)
  585. {
  586. struct sk_buff *dcbnl_skb;
  587. struct nlmsghdr *nlh;
  588. struct dcbmsg *dcb;
  589. struct nlattr *pg_nest, *param_nest, *data;
  590. struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
  591. struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
  592. u8 prio, pgid, tc_pct, up_map;
  593. int ret = -EINVAL;
  594. int getall = 0;
  595. int i;
  596. if (!tb[DCB_ATTR_PG_CFG] ||
  597. !netdev->dcbnl_ops->getpgtccfgtx ||
  598. !netdev->dcbnl_ops->getpgtccfgrx ||
  599. !netdev->dcbnl_ops->getpgbwgcfgtx ||
  600. !netdev->dcbnl_ops->getpgbwgcfgrx)
  601. return ret;
  602. ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
  603. tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
  604. if (ret)
  605. goto err_out;
  606. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  607. if (!dcbnl_skb)
  608. goto err_out;
  609. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  610. dcb = NLMSG_DATA(nlh);
  611. dcb->dcb_family = AF_UNSPEC;
  612. dcb->cmd = (dir) ? DCB_CMD_PGRX_GCFG : DCB_CMD_PGTX_GCFG;
  613. pg_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PG_CFG);
  614. if (!pg_nest)
  615. goto err;
  616. if (pg_tb[DCB_PG_ATTR_TC_ALL])
  617. getall = 1;
  618. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  619. if (!getall && !pg_tb[i])
  620. continue;
  621. if (pg_tb[DCB_PG_ATTR_TC_ALL])
  622. data = pg_tb[DCB_PG_ATTR_TC_ALL];
  623. else
  624. data = pg_tb[i];
  625. ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
  626. data, dcbnl_tc_param_nest);
  627. if (ret)
  628. goto err_pg;
  629. param_nest = nla_nest_start(dcbnl_skb, i);
  630. if (!param_nest)
  631. goto err_pg;
  632. pgid = DCB_ATTR_VALUE_UNDEFINED;
  633. prio = DCB_ATTR_VALUE_UNDEFINED;
  634. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  635. up_map = DCB_ATTR_VALUE_UNDEFINED;
  636. if (dir) {
  637. /* Rx */
  638. netdev->dcbnl_ops->getpgtccfgrx(netdev,
  639. i - DCB_PG_ATTR_TC_0, &prio,
  640. &pgid, &tc_pct, &up_map);
  641. } else {
  642. /* Tx */
  643. netdev->dcbnl_ops->getpgtccfgtx(netdev,
  644. i - DCB_PG_ATTR_TC_0, &prio,
  645. &pgid, &tc_pct, &up_map);
  646. }
  647. if (param_tb[DCB_TC_ATTR_PARAM_PGID] ||
  648. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  649. ret = nla_put_u8(dcbnl_skb,
  650. DCB_TC_ATTR_PARAM_PGID, pgid);
  651. if (ret)
  652. goto err_param;
  653. }
  654. if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] ||
  655. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  656. ret = nla_put_u8(dcbnl_skb,
  657. DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
  658. if (ret)
  659. goto err_param;
  660. }
  661. if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] ||
  662. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  663. ret = nla_put_u8(dcbnl_skb,
  664. DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
  665. if (ret)
  666. goto err_param;
  667. }
  668. if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] ||
  669. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  670. ret = nla_put_u8(dcbnl_skb, DCB_TC_ATTR_PARAM_BW_PCT,
  671. tc_pct);
  672. if (ret)
  673. goto err_param;
  674. }
  675. nla_nest_end(dcbnl_skb, param_nest);
  676. }
  677. if (pg_tb[DCB_PG_ATTR_BW_ID_ALL])
  678. getall = 1;
  679. else
  680. getall = 0;
  681. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  682. if (!getall && !pg_tb[i])
  683. continue;
  684. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  685. if (dir) {
  686. /* Rx */
  687. netdev->dcbnl_ops->getpgbwgcfgrx(netdev,
  688. i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
  689. } else {
  690. /* Tx */
  691. netdev->dcbnl_ops->getpgbwgcfgtx(netdev,
  692. i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
  693. }
  694. ret = nla_put_u8(dcbnl_skb, i, tc_pct);
  695. if (ret)
  696. goto err_pg;
  697. }
  698. nla_nest_end(dcbnl_skb, pg_nest);
  699. nlmsg_end(dcbnl_skb, nlh);
  700. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  701. if (ret)
  702. goto err_out;
  703. return 0;
  704. err_param:
  705. nla_nest_cancel(dcbnl_skb, param_nest);
  706. err_pg:
  707. nla_nest_cancel(dcbnl_skb, pg_nest);
  708. nlmsg_failure:
  709. err:
  710. kfree_skb(dcbnl_skb);
  711. err_out:
  712. ret = -EINVAL;
  713. return ret;
  714. }
  715. static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlattr **tb,
  716. u32 pid, u32 seq, u16 flags)
  717. {
  718. return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 0);
  719. }
  720. static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlattr **tb,
  721. u32 pid, u32 seq, u16 flags)
  722. {
  723. return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 1);
  724. }
  725. static int dcbnl_setstate(struct net_device *netdev, struct nlattr **tb,
  726. u32 pid, u32 seq, u16 flags)
  727. {
  728. int ret = -EINVAL;
  729. u8 value;
  730. if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->setstate)
  731. return ret;
  732. value = nla_get_u8(tb[DCB_ATTR_STATE]);
  733. ret = dcbnl_reply(netdev->dcbnl_ops->setstate(netdev, value),
  734. RTM_SETDCB, DCB_CMD_SSTATE, DCB_ATTR_STATE,
  735. pid, seq, flags);
  736. return ret;
  737. }
  738. static int dcbnl_setpfccfg(struct net_device *netdev, struct nlattr **tb,
  739. u32 pid, u32 seq, u16 flags)
  740. {
  741. struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1];
  742. int i;
  743. int ret = -EINVAL;
  744. u8 value;
  745. if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->setpfccfg)
  746. return ret;
  747. ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
  748. tb[DCB_ATTR_PFC_CFG],
  749. dcbnl_pfc_up_nest);
  750. if (ret)
  751. goto err;
  752. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  753. if (data[i] == NULL)
  754. continue;
  755. value = nla_get_u8(data[i]);
  756. netdev->dcbnl_ops->setpfccfg(netdev,
  757. data[i]->nla_type - DCB_PFC_UP_ATTR_0, value);
  758. }
  759. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SCFG, DCB_ATTR_PFC_CFG,
  760. pid, seq, flags);
  761. err:
  762. return ret;
  763. }
  764. static int dcbnl_setall(struct net_device *netdev, struct nlattr **tb,
  765. u32 pid, u32 seq, u16 flags)
  766. {
  767. int ret = -EINVAL;
  768. if (!tb[DCB_ATTR_SET_ALL] || !netdev->dcbnl_ops->setall)
  769. return ret;
  770. ret = dcbnl_reply(netdev->dcbnl_ops->setall(netdev), RTM_SETDCB,
  771. DCB_CMD_SET_ALL, DCB_ATTR_SET_ALL, pid, seq, flags);
  772. return ret;
  773. }
  774. static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlattr **tb,
  775. u32 pid, u32 seq, u16 flags, int dir)
  776. {
  777. struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
  778. struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
  779. int ret = -EINVAL;
  780. int i;
  781. u8 pgid;
  782. u8 up_map;
  783. u8 prio;
  784. u8 tc_pct;
  785. if (!tb[DCB_ATTR_PG_CFG] ||
  786. !netdev->dcbnl_ops->setpgtccfgtx ||
  787. !netdev->dcbnl_ops->setpgtccfgrx ||
  788. !netdev->dcbnl_ops->setpgbwgcfgtx ||
  789. !netdev->dcbnl_ops->setpgbwgcfgrx)
  790. return ret;
  791. ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
  792. tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
  793. if (ret)
  794. goto err;
  795. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  796. if (!pg_tb[i])
  797. continue;
  798. ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
  799. pg_tb[i], dcbnl_tc_param_nest);
  800. if (ret)
  801. goto err;
  802. pgid = DCB_ATTR_VALUE_UNDEFINED;
  803. prio = DCB_ATTR_VALUE_UNDEFINED;
  804. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  805. up_map = DCB_ATTR_VALUE_UNDEFINED;
  806. if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO])
  807. prio =
  808. nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]);
  809. if (param_tb[DCB_TC_ATTR_PARAM_PGID])
  810. pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]);
  811. if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT])
  812. tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]);
  813. if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING])
  814. up_map =
  815. nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]);
  816. /* dir: Tx = 0, Rx = 1 */
  817. if (dir) {
  818. /* Rx */
  819. netdev->dcbnl_ops->setpgtccfgrx(netdev,
  820. i - DCB_PG_ATTR_TC_0,
  821. prio, pgid, tc_pct, up_map);
  822. } else {
  823. /* Tx */
  824. netdev->dcbnl_ops->setpgtccfgtx(netdev,
  825. i - DCB_PG_ATTR_TC_0,
  826. prio, pgid, tc_pct, up_map);
  827. }
  828. }
  829. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  830. if (!pg_tb[i])
  831. continue;
  832. tc_pct = nla_get_u8(pg_tb[i]);
  833. /* dir: Tx = 0, Rx = 1 */
  834. if (dir) {
  835. /* Rx */
  836. netdev->dcbnl_ops->setpgbwgcfgrx(netdev,
  837. i - DCB_PG_ATTR_BW_ID_0, tc_pct);
  838. } else {
  839. /* Tx */
  840. netdev->dcbnl_ops->setpgbwgcfgtx(netdev,
  841. i - DCB_PG_ATTR_BW_ID_0, tc_pct);
  842. }
  843. }
  844. ret = dcbnl_reply(0, RTM_SETDCB,
  845. (dir ? DCB_CMD_PGRX_SCFG : DCB_CMD_PGTX_SCFG),
  846. DCB_ATTR_PG_CFG, pid, seq, flags);
  847. err:
  848. return ret;
  849. }
  850. static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlattr **tb,
  851. u32 pid, u32 seq, u16 flags)
  852. {
  853. return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 0);
  854. }
  855. static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlattr **tb,
  856. u32 pid, u32 seq, u16 flags)
  857. {
  858. return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 1);
  859. }
  860. static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlattr **tb,
  861. u32 pid, u32 seq, u16 flags)
  862. {
  863. struct sk_buff *dcbnl_skb;
  864. struct nlmsghdr *nlh;
  865. struct dcbmsg *dcb;
  866. struct nlattr *bcn_nest;
  867. struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1];
  868. u8 value_byte;
  869. u32 value_integer;
  870. int ret = -EINVAL;
  871. bool getall = false;
  872. int i;
  873. if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->getbcnrp ||
  874. !netdev->dcbnl_ops->getbcncfg)
  875. return ret;
  876. ret = nla_parse_nested(bcn_tb, DCB_BCN_ATTR_MAX,
  877. tb[DCB_ATTR_BCN], dcbnl_bcn_nest);
  878. if (ret)
  879. goto err_out;
  880. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  881. if (!dcbnl_skb)
  882. goto err_out;
  883. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  884. dcb = NLMSG_DATA(nlh);
  885. dcb->dcb_family = AF_UNSPEC;
  886. dcb->cmd = DCB_CMD_BCN_GCFG;
  887. bcn_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_BCN);
  888. if (!bcn_nest)
  889. goto err;
  890. if (bcn_tb[DCB_BCN_ATTR_ALL])
  891. getall = true;
  892. for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
  893. if (!getall && !bcn_tb[i])
  894. continue;
  895. netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0,
  896. &value_byte);
  897. ret = nla_put_u8(dcbnl_skb, i, value_byte);
  898. if (ret)
  899. goto err_bcn;
  900. }
  901. for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
  902. if (!getall && !bcn_tb[i])
  903. continue;
  904. netdev->dcbnl_ops->getbcncfg(netdev, i,
  905. &value_integer);
  906. ret = nla_put_u32(dcbnl_skb, i, value_integer);
  907. if (ret)
  908. goto err_bcn;
  909. }
  910. nla_nest_end(dcbnl_skb, bcn_nest);
  911. nlmsg_end(dcbnl_skb, nlh);
  912. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  913. if (ret)
  914. goto err_out;
  915. return 0;
  916. err_bcn:
  917. nla_nest_cancel(dcbnl_skb, bcn_nest);
  918. nlmsg_failure:
  919. err:
  920. kfree_skb(dcbnl_skb);
  921. err_out:
  922. ret = -EINVAL;
  923. return ret;
  924. }
  925. static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlattr **tb,
  926. u32 pid, u32 seq, u16 flags)
  927. {
  928. struct nlattr *data[DCB_BCN_ATTR_MAX + 1];
  929. int i;
  930. int ret = -EINVAL;
  931. u8 value_byte;
  932. u32 value_int;
  933. if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->setbcncfg ||
  934. !netdev->dcbnl_ops->setbcnrp)
  935. return ret;
  936. ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX,
  937. tb[DCB_ATTR_BCN],
  938. dcbnl_pfc_up_nest);
  939. if (ret)
  940. goto err;
  941. for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
  942. if (data[i] == NULL)
  943. continue;
  944. value_byte = nla_get_u8(data[i]);
  945. netdev->dcbnl_ops->setbcnrp(netdev,
  946. data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte);
  947. }
  948. for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
  949. if (data[i] == NULL)
  950. continue;
  951. value_int = nla_get_u32(data[i]);
  952. netdev->dcbnl_ops->setbcncfg(netdev,
  953. i, value_int);
  954. }
  955. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_BCN_SCFG, DCB_ATTR_BCN,
  956. pid, seq, flags);
  957. err:
  958. return ret;
  959. }
  960. static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
  961. int app_nested_type, int app_info_type,
  962. int app_entry_type)
  963. {
  964. struct dcb_peer_app_info info;
  965. struct dcb_app *table = NULL;
  966. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  967. u16 app_count;
  968. int err;
  969. /**
  970. * retrieve the peer app configuration form the driver. If the driver
  971. * handlers fail exit without doing anything
  972. */
  973. err = ops->peer_getappinfo(netdev, &info, &app_count);
  974. if (!err && app_count) {
  975. table = kmalloc(sizeof(struct dcb_app) * app_count, GFP_KERNEL);
  976. if (!table)
  977. return -ENOMEM;
  978. err = ops->peer_getapptable(netdev, table);
  979. }
  980. if (!err) {
  981. u16 i;
  982. struct nlattr *app;
  983. /**
  984. * build the message, from here on the only possible failure
  985. * is due to the skb size
  986. */
  987. err = -EMSGSIZE;
  988. app = nla_nest_start(skb, app_nested_type);
  989. if (!app)
  990. goto nla_put_failure;
  991. if (app_info_type)
  992. NLA_PUT(skb, app_info_type, sizeof(info), &info);
  993. for (i = 0; i < app_count; i++)
  994. NLA_PUT(skb, app_entry_type, sizeof(struct dcb_app),
  995. &table[i]);
  996. nla_nest_end(skb, app);
  997. }
  998. err = 0;
  999. nla_put_failure:
  1000. kfree(table);
  1001. return err;
  1002. }
  1003. /* Handle IEEE 802.1Qaz GET commands. */
  1004. static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
  1005. {
  1006. struct nlattr *ieee, *app;
  1007. struct dcb_app_type *itr;
  1008. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1009. int dcbx;
  1010. int err = -EMSGSIZE;
  1011. NLA_PUT_STRING(skb, DCB_ATTR_IFNAME, netdev->name);
  1012. ieee = nla_nest_start(skb, DCB_ATTR_IEEE);
  1013. if (!ieee)
  1014. goto nla_put_failure;
  1015. if (ops->ieee_getets) {
  1016. struct ieee_ets ets;
  1017. err = ops->ieee_getets(netdev, &ets);
  1018. if (!err)
  1019. NLA_PUT(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets);
  1020. }
  1021. if (ops->ieee_getpfc) {
  1022. struct ieee_pfc pfc;
  1023. err = ops->ieee_getpfc(netdev, &pfc);
  1024. if (!err)
  1025. NLA_PUT(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc);
  1026. }
  1027. app = nla_nest_start(skb, DCB_ATTR_IEEE_APP_TABLE);
  1028. if (!app)
  1029. goto nla_put_failure;
  1030. spin_lock(&dcb_lock);
  1031. list_for_each_entry(itr, &dcb_app_list, list) {
  1032. if (strncmp(itr->name, netdev->name, IFNAMSIZ) == 0) {
  1033. err = nla_put(skb, DCB_ATTR_IEEE_APP, sizeof(itr->app),
  1034. &itr->app);
  1035. if (err) {
  1036. spin_unlock(&dcb_lock);
  1037. goto nla_put_failure;
  1038. }
  1039. }
  1040. }
  1041. if (netdev->dcbnl_ops->getdcbx)
  1042. dcbx = netdev->dcbnl_ops->getdcbx(netdev);
  1043. else
  1044. dcbx = -EOPNOTSUPP;
  1045. spin_unlock(&dcb_lock);
  1046. nla_nest_end(skb, app);
  1047. /* get peer info if available */
  1048. if (ops->ieee_peer_getets) {
  1049. struct ieee_ets ets;
  1050. err = ops->ieee_peer_getets(netdev, &ets);
  1051. if (!err)
  1052. NLA_PUT(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets);
  1053. }
  1054. if (ops->ieee_peer_getpfc) {
  1055. struct ieee_pfc pfc;
  1056. err = ops->ieee_peer_getpfc(netdev, &pfc);
  1057. if (!err)
  1058. NLA_PUT(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc);
  1059. }
  1060. if (ops->peer_getappinfo && ops->peer_getapptable) {
  1061. err = dcbnl_build_peer_app(netdev, skb,
  1062. DCB_ATTR_IEEE_PEER_APP,
  1063. DCB_ATTR_IEEE_APP_UNSPEC,
  1064. DCB_ATTR_IEEE_APP);
  1065. if (err)
  1066. goto nla_put_failure;
  1067. }
  1068. nla_nest_end(skb, ieee);
  1069. if (dcbx >= 0) {
  1070. err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx);
  1071. if (err)
  1072. goto nla_put_failure;
  1073. }
  1074. return 0;
  1075. nla_put_failure:
  1076. return err;
  1077. }
  1078. static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev,
  1079. int dir)
  1080. {
  1081. u8 pgid, up_map, prio, tc_pct;
  1082. const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
  1083. int i = dir ? DCB_ATTR_CEE_TX_PG : DCB_ATTR_CEE_RX_PG;
  1084. struct nlattr *pg = nla_nest_start(skb, i);
  1085. if (!pg)
  1086. goto nla_put_failure;
  1087. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  1088. struct nlattr *tc_nest = nla_nest_start(skb, i);
  1089. if (!tc_nest)
  1090. goto nla_put_failure;
  1091. pgid = DCB_ATTR_VALUE_UNDEFINED;
  1092. prio = DCB_ATTR_VALUE_UNDEFINED;
  1093. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  1094. up_map = DCB_ATTR_VALUE_UNDEFINED;
  1095. if (!dir)
  1096. ops->getpgtccfgrx(dev, i - DCB_PG_ATTR_TC_0,
  1097. &prio, &pgid, &tc_pct, &up_map);
  1098. else
  1099. ops->getpgtccfgtx(dev, i - DCB_PG_ATTR_TC_0,
  1100. &prio, &pgid, &tc_pct, &up_map);
  1101. NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_PGID, pgid);
  1102. NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
  1103. NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
  1104. NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_BW_PCT, tc_pct);
  1105. nla_nest_end(skb, tc_nest);
  1106. }
  1107. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  1108. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  1109. if (!dir)
  1110. ops->getpgbwgcfgrx(dev, i - DCB_PG_ATTR_BW_ID_0,
  1111. &tc_pct);
  1112. else
  1113. ops->getpgbwgcfgtx(dev, i - DCB_PG_ATTR_BW_ID_0,
  1114. &tc_pct);
  1115. NLA_PUT_U8(skb, i, tc_pct);
  1116. }
  1117. nla_nest_end(skb, pg);
  1118. return 0;
  1119. nla_put_failure:
  1120. return -EMSGSIZE;
  1121. }
  1122. static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
  1123. {
  1124. struct nlattr *cee, *app;
  1125. struct dcb_app_type *itr;
  1126. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1127. int dcbx, i, err = -EMSGSIZE;
  1128. u8 value;
  1129. NLA_PUT_STRING(skb, DCB_ATTR_IFNAME, netdev->name);
  1130. cee = nla_nest_start(skb, DCB_ATTR_CEE);
  1131. if (!cee)
  1132. goto nla_put_failure;
  1133. /* local pg */
  1134. if (ops->getpgtccfgtx && ops->getpgbwgcfgtx) {
  1135. err = dcbnl_cee_pg_fill(skb, netdev, 1);
  1136. if (err)
  1137. goto nla_put_failure;
  1138. }
  1139. if (ops->getpgtccfgrx && ops->getpgbwgcfgrx) {
  1140. err = dcbnl_cee_pg_fill(skb, netdev, 0);
  1141. if (err)
  1142. goto nla_put_failure;
  1143. }
  1144. /* local pfc */
  1145. if (ops->getpfccfg) {
  1146. struct nlattr *pfc_nest = nla_nest_start(skb, DCB_ATTR_CEE_PFC);
  1147. if (!pfc_nest)
  1148. goto nla_put_failure;
  1149. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  1150. ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, &value);
  1151. NLA_PUT_U8(skb, i, value);
  1152. }
  1153. nla_nest_end(skb, pfc_nest);
  1154. }
  1155. /* local app */
  1156. spin_lock(&dcb_lock);
  1157. app = nla_nest_start(skb, DCB_ATTR_CEE_APP_TABLE);
  1158. if (!app)
  1159. goto dcb_unlock;
  1160. list_for_each_entry(itr, &dcb_app_list, list) {
  1161. if (strncmp(itr->name, netdev->name, IFNAMSIZ) == 0) {
  1162. struct nlattr *app_nest = nla_nest_start(skb,
  1163. DCB_ATTR_APP);
  1164. if (!app_nest)
  1165. goto dcb_unlock;
  1166. err = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE,
  1167. itr->app.selector);
  1168. if (err)
  1169. goto dcb_unlock;
  1170. err = nla_put_u16(skb, DCB_APP_ATTR_ID,
  1171. itr->app.protocol);
  1172. if (err)
  1173. goto dcb_unlock;
  1174. err = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY,
  1175. itr->app.priority);
  1176. if (err)
  1177. goto dcb_unlock;
  1178. nla_nest_end(skb, app_nest);
  1179. }
  1180. }
  1181. nla_nest_end(skb, app);
  1182. if (netdev->dcbnl_ops->getdcbx)
  1183. dcbx = netdev->dcbnl_ops->getdcbx(netdev);
  1184. else
  1185. dcbx = -EOPNOTSUPP;
  1186. spin_unlock(&dcb_lock);
  1187. /* features flags */
  1188. if (ops->getfeatcfg) {
  1189. struct nlattr *feat = nla_nest_start(skb, DCB_ATTR_CEE_FEAT);
  1190. if (!feat)
  1191. goto nla_put_failure;
  1192. for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX;
  1193. i++)
  1194. if (!ops->getfeatcfg(netdev, i, &value))
  1195. NLA_PUT_U8(skb, i, value);
  1196. nla_nest_end(skb, feat);
  1197. }
  1198. /* peer info if available */
  1199. if (ops->cee_peer_getpg) {
  1200. struct cee_pg pg;
  1201. err = ops->cee_peer_getpg(netdev, &pg);
  1202. if (!err)
  1203. NLA_PUT(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg);
  1204. }
  1205. if (ops->cee_peer_getpfc) {
  1206. struct cee_pfc pfc;
  1207. err = ops->cee_peer_getpfc(netdev, &pfc);
  1208. if (!err)
  1209. NLA_PUT(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc);
  1210. }
  1211. if (ops->peer_getappinfo && ops->peer_getapptable) {
  1212. err = dcbnl_build_peer_app(netdev, skb,
  1213. DCB_ATTR_CEE_PEER_APP_TABLE,
  1214. DCB_ATTR_CEE_PEER_APP_INFO,
  1215. DCB_ATTR_CEE_PEER_APP);
  1216. if (err)
  1217. goto nla_put_failure;
  1218. }
  1219. nla_nest_end(skb, cee);
  1220. /* DCBX state */
  1221. if (dcbx >= 0) {
  1222. err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx);
  1223. if (err)
  1224. goto nla_put_failure;
  1225. }
  1226. return 0;
  1227. dcb_unlock:
  1228. spin_unlock(&dcb_lock);
  1229. nla_put_failure:
  1230. return err;
  1231. }
  1232. static int dcbnl_notify(struct net_device *dev, int event, int cmd,
  1233. u32 seq, u32 pid, int dcbx_ver)
  1234. {
  1235. struct net *net = dev_net(dev);
  1236. struct sk_buff *skb;
  1237. struct nlmsghdr *nlh;
  1238. struct dcbmsg *dcb;
  1239. const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
  1240. int err;
  1241. if (!ops)
  1242. return -EOPNOTSUPP;
  1243. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1244. if (!skb)
  1245. return -ENOBUFS;
  1246. nlh = nlmsg_put(skb, pid, 0, event, sizeof(*dcb), 0);
  1247. if (nlh == NULL) {
  1248. nlmsg_free(skb);
  1249. return -EMSGSIZE;
  1250. }
  1251. dcb = NLMSG_DATA(nlh);
  1252. dcb->dcb_family = AF_UNSPEC;
  1253. dcb->cmd = cmd;
  1254. if (dcbx_ver == DCB_CAP_DCBX_VER_IEEE)
  1255. err = dcbnl_ieee_fill(skb, dev);
  1256. else
  1257. err = dcbnl_cee_fill(skb, dev);
  1258. if (err < 0) {
  1259. /* Report error to broadcast listeners */
  1260. nlmsg_cancel(skb, nlh);
  1261. kfree_skb(skb);
  1262. rtnl_set_sk_err(net, RTNLGRP_DCB, err);
  1263. } else {
  1264. /* End nlmsg and notify broadcast listeners */
  1265. nlmsg_end(skb, nlh);
  1266. rtnl_notify(skb, net, 0, RTNLGRP_DCB, NULL, GFP_KERNEL);
  1267. }
  1268. return err;
  1269. }
  1270. int dcbnl_ieee_notify(struct net_device *dev, int event, int cmd,
  1271. u32 seq, u32 pid)
  1272. {
  1273. return dcbnl_notify(dev, event, cmd, seq, pid, DCB_CAP_DCBX_VER_IEEE);
  1274. }
  1275. EXPORT_SYMBOL(dcbnl_ieee_notify);
  1276. int dcbnl_cee_notify(struct net_device *dev, int event, int cmd,
  1277. u32 seq, u32 pid)
  1278. {
  1279. return dcbnl_notify(dev, event, cmd, seq, pid, DCB_CAP_DCBX_VER_CEE);
  1280. }
  1281. EXPORT_SYMBOL(dcbnl_cee_notify);
  1282. /* Handle IEEE 802.1Qaz SET commands. If any requested operation can not
  1283. * be completed the entire msg is aborted and error value is returned.
  1284. * No attempt is made to reconcile the case where only part of the
  1285. * cmd can be completed.
  1286. */
  1287. static int dcbnl_ieee_set(struct net_device *netdev, struct nlattr **tb,
  1288. u32 pid, u32 seq, u16 flags)
  1289. {
  1290. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1291. struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
  1292. int err = -EOPNOTSUPP;
  1293. if (!ops)
  1294. return err;
  1295. if (!tb[DCB_ATTR_IEEE])
  1296. return -EINVAL;
  1297. err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX,
  1298. tb[DCB_ATTR_IEEE], dcbnl_ieee_policy);
  1299. if (err)
  1300. return err;
  1301. if (ieee[DCB_ATTR_IEEE_ETS] && ops->ieee_setets) {
  1302. struct ieee_ets *ets = nla_data(ieee[DCB_ATTR_IEEE_ETS]);
  1303. err = ops->ieee_setets(netdev, ets);
  1304. if (err)
  1305. goto err;
  1306. }
  1307. if (ieee[DCB_ATTR_IEEE_PFC] && ops->ieee_setpfc) {
  1308. struct ieee_pfc *pfc = nla_data(ieee[DCB_ATTR_IEEE_PFC]);
  1309. err = ops->ieee_setpfc(netdev, pfc);
  1310. if (err)
  1311. goto err;
  1312. }
  1313. if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
  1314. struct nlattr *attr;
  1315. int rem;
  1316. nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
  1317. struct dcb_app *app_data;
  1318. if (nla_type(attr) != DCB_ATTR_IEEE_APP)
  1319. continue;
  1320. app_data = nla_data(attr);
  1321. if (ops->ieee_setapp)
  1322. err = ops->ieee_setapp(netdev, app_data);
  1323. else
  1324. err = dcb_ieee_setapp(netdev, app_data);
  1325. if (err)
  1326. goto err;
  1327. }
  1328. }
  1329. err:
  1330. dcbnl_reply(err, RTM_SETDCB, DCB_CMD_IEEE_SET, DCB_ATTR_IEEE,
  1331. pid, seq, flags);
  1332. dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, seq, 0);
  1333. return err;
  1334. }
  1335. static int dcbnl_ieee_get(struct net_device *netdev, struct nlattr **tb,
  1336. u32 pid, u32 seq, u16 flags)
  1337. {
  1338. struct net *net = dev_net(netdev);
  1339. struct sk_buff *skb;
  1340. struct nlmsghdr *nlh;
  1341. struct dcbmsg *dcb;
  1342. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1343. int err;
  1344. if (!ops)
  1345. return -EOPNOTSUPP;
  1346. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1347. if (!skb)
  1348. return -ENOBUFS;
  1349. nlh = nlmsg_put(skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1350. if (nlh == NULL) {
  1351. nlmsg_free(skb);
  1352. return -EMSGSIZE;
  1353. }
  1354. dcb = NLMSG_DATA(nlh);
  1355. dcb->dcb_family = AF_UNSPEC;
  1356. dcb->cmd = DCB_CMD_IEEE_GET;
  1357. err = dcbnl_ieee_fill(skb, netdev);
  1358. if (err < 0) {
  1359. nlmsg_cancel(skb, nlh);
  1360. kfree_skb(skb);
  1361. } else {
  1362. nlmsg_end(skb, nlh);
  1363. err = rtnl_unicast(skb, net, pid);
  1364. }
  1365. return err;
  1366. }
  1367. static int dcbnl_ieee_del(struct net_device *netdev, struct nlattr **tb,
  1368. u32 pid, u32 seq, u16 flags)
  1369. {
  1370. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1371. struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
  1372. int err = -EOPNOTSUPP;
  1373. if (!ops)
  1374. return -EOPNOTSUPP;
  1375. if (!tb[DCB_ATTR_IEEE])
  1376. return -EINVAL;
  1377. err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX,
  1378. tb[DCB_ATTR_IEEE], dcbnl_ieee_policy);
  1379. if (err)
  1380. return err;
  1381. if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
  1382. struct nlattr *attr;
  1383. int rem;
  1384. nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
  1385. struct dcb_app *app_data;
  1386. if (nla_type(attr) != DCB_ATTR_IEEE_APP)
  1387. continue;
  1388. app_data = nla_data(attr);
  1389. if (ops->ieee_delapp)
  1390. err = ops->ieee_delapp(netdev, app_data);
  1391. else
  1392. err = dcb_ieee_delapp(netdev, app_data);
  1393. if (err)
  1394. goto err;
  1395. }
  1396. }
  1397. err:
  1398. dcbnl_reply(err, RTM_SETDCB, DCB_CMD_IEEE_DEL, DCB_ATTR_IEEE,
  1399. pid, seq, flags);
  1400. dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_DEL, seq, 0);
  1401. return err;
  1402. }
  1403. /* DCBX configuration */
  1404. static int dcbnl_getdcbx(struct net_device *netdev, struct nlattr **tb,
  1405. u32 pid, u32 seq, u16 flags)
  1406. {
  1407. int ret;
  1408. if (!netdev->dcbnl_ops->getdcbx)
  1409. return -EOPNOTSUPP;
  1410. ret = dcbnl_reply(netdev->dcbnl_ops->getdcbx(netdev), RTM_GETDCB,
  1411. DCB_CMD_GDCBX, DCB_ATTR_DCBX, pid, seq, flags);
  1412. return ret;
  1413. }
  1414. static int dcbnl_setdcbx(struct net_device *netdev, struct nlattr **tb,
  1415. u32 pid, u32 seq, u16 flags)
  1416. {
  1417. int ret;
  1418. u8 value;
  1419. if (!netdev->dcbnl_ops->setdcbx)
  1420. return -EOPNOTSUPP;
  1421. if (!tb[DCB_ATTR_DCBX])
  1422. return -EINVAL;
  1423. value = nla_get_u8(tb[DCB_ATTR_DCBX]);
  1424. ret = dcbnl_reply(netdev->dcbnl_ops->setdcbx(netdev, value),
  1425. RTM_SETDCB, DCB_CMD_SDCBX, DCB_ATTR_DCBX,
  1426. pid, seq, flags);
  1427. return ret;
  1428. }
  1429. static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlattr **tb,
  1430. u32 pid, u32 seq, u16 flags)
  1431. {
  1432. struct sk_buff *dcbnl_skb;
  1433. struct nlmsghdr *nlh;
  1434. struct dcbmsg *dcb;
  1435. struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1], *nest;
  1436. u8 value;
  1437. int ret, i;
  1438. int getall = 0;
  1439. if (!netdev->dcbnl_ops->getfeatcfg)
  1440. return -EOPNOTSUPP;
  1441. if (!tb[DCB_ATTR_FEATCFG])
  1442. return -EINVAL;
  1443. ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
  1444. dcbnl_featcfg_nest);
  1445. if (ret)
  1446. goto err_out;
  1447. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1448. if (!dcbnl_skb) {
  1449. ret = -ENOBUFS;
  1450. goto err_out;
  1451. }
  1452. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1453. dcb = NLMSG_DATA(nlh);
  1454. dcb->dcb_family = AF_UNSPEC;
  1455. dcb->cmd = DCB_CMD_GFEATCFG;
  1456. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_FEATCFG);
  1457. if (!nest) {
  1458. ret = -EMSGSIZE;
  1459. goto nla_put_failure;
  1460. }
  1461. if (data[DCB_FEATCFG_ATTR_ALL])
  1462. getall = 1;
  1463. for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
  1464. if (!getall && !data[i])
  1465. continue;
  1466. ret = netdev->dcbnl_ops->getfeatcfg(netdev, i, &value);
  1467. if (!ret)
  1468. ret = nla_put_u8(dcbnl_skb, i, value);
  1469. if (ret) {
  1470. nla_nest_cancel(dcbnl_skb, nest);
  1471. goto nla_put_failure;
  1472. }
  1473. }
  1474. nla_nest_end(dcbnl_skb, nest);
  1475. nlmsg_end(dcbnl_skb, nlh);
  1476. return rtnl_unicast(dcbnl_skb, &init_net, pid);
  1477. nla_put_failure:
  1478. nlmsg_cancel(dcbnl_skb, nlh);
  1479. nlmsg_failure:
  1480. kfree_skb(dcbnl_skb);
  1481. err_out:
  1482. return ret;
  1483. }
  1484. static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlattr **tb,
  1485. u32 pid, u32 seq, u16 flags)
  1486. {
  1487. struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1];
  1488. int ret, i;
  1489. u8 value;
  1490. if (!netdev->dcbnl_ops->setfeatcfg)
  1491. return -ENOTSUPP;
  1492. if (!tb[DCB_ATTR_FEATCFG])
  1493. return -EINVAL;
  1494. ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
  1495. dcbnl_featcfg_nest);
  1496. if (ret)
  1497. goto err;
  1498. for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
  1499. if (data[i] == NULL)
  1500. continue;
  1501. value = nla_get_u8(data[i]);
  1502. ret = netdev->dcbnl_ops->setfeatcfg(netdev, i, value);
  1503. if (ret)
  1504. goto err;
  1505. }
  1506. err:
  1507. dcbnl_reply(ret, RTM_SETDCB, DCB_CMD_SFEATCFG, DCB_ATTR_FEATCFG,
  1508. pid, seq, flags);
  1509. return ret;
  1510. }
  1511. /* Handle CEE DCBX GET commands. */
  1512. static int dcbnl_cee_get(struct net_device *netdev, struct nlattr **tb,
  1513. u32 pid, u32 seq, u16 flags)
  1514. {
  1515. struct net *net = dev_net(netdev);
  1516. struct sk_buff *skb;
  1517. struct nlmsghdr *nlh;
  1518. struct dcbmsg *dcb;
  1519. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1520. int err;
  1521. if (!ops)
  1522. return -EOPNOTSUPP;
  1523. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1524. if (!skb)
  1525. return -ENOBUFS;
  1526. nlh = nlmsg_put(skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1527. if (nlh == NULL) {
  1528. nlmsg_free(skb);
  1529. return -EMSGSIZE;
  1530. }
  1531. dcb = NLMSG_DATA(nlh);
  1532. dcb->dcb_family = AF_UNSPEC;
  1533. dcb->cmd = DCB_CMD_CEE_GET;
  1534. err = dcbnl_cee_fill(skb, netdev);
  1535. if (err < 0) {
  1536. nlmsg_cancel(skb, nlh);
  1537. nlmsg_free(skb);
  1538. } else {
  1539. nlmsg_end(skb, nlh);
  1540. err = rtnl_unicast(skb, net, pid);
  1541. }
  1542. return err;
  1543. }
  1544. static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
  1545. {
  1546. struct net *net = sock_net(skb->sk);
  1547. struct net_device *netdev;
  1548. struct dcbmsg *dcb = (struct dcbmsg *)NLMSG_DATA(nlh);
  1549. struct nlattr *tb[DCB_ATTR_MAX + 1];
  1550. u32 pid = skb ? NETLINK_CB(skb).pid : 0;
  1551. int ret = -EINVAL;
  1552. if (!net_eq(net, &init_net))
  1553. return -EINVAL;
  1554. ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
  1555. dcbnl_rtnl_policy);
  1556. if (ret < 0)
  1557. return ret;
  1558. if (!tb[DCB_ATTR_IFNAME])
  1559. return -EINVAL;
  1560. netdev = dev_get_by_name(&init_net, nla_data(tb[DCB_ATTR_IFNAME]));
  1561. if (!netdev)
  1562. return -EINVAL;
  1563. if (!netdev->dcbnl_ops)
  1564. goto errout;
  1565. switch (dcb->cmd) {
  1566. case DCB_CMD_GSTATE:
  1567. ret = dcbnl_getstate(netdev, tb, pid, nlh->nlmsg_seq,
  1568. nlh->nlmsg_flags);
  1569. goto out;
  1570. case DCB_CMD_PFC_GCFG:
  1571. ret = dcbnl_getpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  1572. nlh->nlmsg_flags);
  1573. goto out;
  1574. case DCB_CMD_GPERM_HWADDR:
  1575. ret = dcbnl_getperm_hwaddr(netdev, tb, pid, nlh->nlmsg_seq,
  1576. nlh->nlmsg_flags);
  1577. goto out;
  1578. case DCB_CMD_PGTX_GCFG:
  1579. ret = dcbnl_pgtx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1580. nlh->nlmsg_flags);
  1581. goto out;
  1582. case DCB_CMD_PGRX_GCFG:
  1583. ret = dcbnl_pgrx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1584. nlh->nlmsg_flags);
  1585. goto out;
  1586. case DCB_CMD_BCN_GCFG:
  1587. ret = dcbnl_bcn_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1588. nlh->nlmsg_flags);
  1589. goto out;
  1590. case DCB_CMD_SSTATE:
  1591. ret = dcbnl_setstate(netdev, tb, pid, nlh->nlmsg_seq,
  1592. nlh->nlmsg_flags);
  1593. goto out;
  1594. case DCB_CMD_PFC_SCFG:
  1595. ret = dcbnl_setpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  1596. nlh->nlmsg_flags);
  1597. goto out;
  1598. case DCB_CMD_SET_ALL:
  1599. ret = dcbnl_setall(netdev, tb, pid, nlh->nlmsg_seq,
  1600. nlh->nlmsg_flags);
  1601. goto out;
  1602. case DCB_CMD_PGTX_SCFG:
  1603. ret = dcbnl_pgtx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1604. nlh->nlmsg_flags);
  1605. goto out;
  1606. case DCB_CMD_PGRX_SCFG:
  1607. ret = dcbnl_pgrx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1608. nlh->nlmsg_flags);
  1609. goto out;
  1610. case DCB_CMD_GCAP:
  1611. ret = dcbnl_getcap(netdev, tb, pid, nlh->nlmsg_seq,
  1612. nlh->nlmsg_flags);
  1613. goto out;
  1614. case DCB_CMD_GNUMTCS:
  1615. ret = dcbnl_getnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  1616. nlh->nlmsg_flags);
  1617. goto out;
  1618. case DCB_CMD_SNUMTCS:
  1619. ret = dcbnl_setnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  1620. nlh->nlmsg_flags);
  1621. goto out;
  1622. case DCB_CMD_PFC_GSTATE:
  1623. ret = dcbnl_getpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  1624. nlh->nlmsg_flags);
  1625. goto out;
  1626. case DCB_CMD_PFC_SSTATE:
  1627. ret = dcbnl_setpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  1628. nlh->nlmsg_flags);
  1629. goto out;
  1630. case DCB_CMD_BCN_SCFG:
  1631. ret = dcbnl_bcn_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1632. nlh->nlmsg_flags);
  1633. goto out;
  1634. case DCB_CMD_GAPP:
  1635. ret = dcbnl_getapp(netdev, tb, pid, nlh->nlmsg_seq,
  1636. nlh->nlmsg_flags);
  1637. goto out;
  1638. case DCB_CMD_SAPP:
  1639. ret = dcbnl_setapp(netdev, tb, pid, nlh->nlmsg_seq,
  1640. nlh->nlmsg_flags);
  1641. goto out;
  1642. case DCB_CMD_IEEE_SET:
  1643. ret = dcbnl_ieee_set(netdev, tb, pid, nlh->nlmsg_seq,
  1644. nlh->nlmsg_flags);
  1645. goto out;
  1646. case DCB_CMD_IEEE_GET:
  1647. ret = dcbnl_ieee_get(netdev, tb, pid, nlh->nlmsg_seq,
  1648. nlh->nlmsg_flags);
  1649. goto out;
  1650. case DCB_CMD_IEEE_DEL:
  1651. ret = dcbnl_ieee_del(netdev, tb, pid, nlh->nlmsg_seq,
  1652. nlh->nlmsg_flags);
  1653. goto out;
  1654. case DCB_CMD_GDCBX:
  1655. ret = dcbnl_getdcbx(netdev, tb, pid, nlh->nlmsg_seq,
  1656. nlh->nlmsg_flags);
  1657. goto out;
  1658. case DCB_CMD_SDCBX:
  1659. ret = dcbnl_setdcbx(netdev, tb, pid, nlh->nlmsg_seq,
  1660. nlh->nlmsg_flags);
  1661. goto out;
  1662. case DCB_CMD_GFEATCFG:
  1663. ret = dcbnl_getfeatcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1664. nlh->nlmsg_flags);
  1665. goto out;
  1666. case DCB_CMD_SFEATCFG:
  1667. ret = dcbnl_setfeatcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1668. nlh->nlmsg_flags);
  1669. goto out;
  1670. case DCB_CMD_CEE_GET:
  1671. ret = dcbnl_cee_get(netdev, tb, pid, nlh->nlmsg_seq,
  1672. nlh->nlmsg_flags);
  1673. goto out;
  1674. default:
  1675. goto errout;
  1676. }
  1677. errout:
  1678. ret = -EINVAL;
  1679. out:
  1680. dev_put(netdev);
  1681. return ret;
  1682. }
  1683. /**
  1684. * dcb_getapp - retrieve the DCBX application user priority
  1685. *
  1686. * On success returns a non-zero 802.1p user priority bitmap
  1687. * otherwise returns 0 as the invalid user priority bitmap to
  1688. * indicate an error.
  1689. */
  1690. u8 dcb_getapp(struct net_device *dev, struct dcb_app *app)
  1691. {
  1692. struct dcb_app_type *itr;
  1693. u8 prio = 0;
  1694. spin_lock(&dcb_lock);
  1695. list_for_each_entry(itr, &dcb_app_list, list) {
  1696. if (itr->app.selector == app->selector &&
  1697. itr->app.protocol == app->protocol &&
  1698. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1699. prio = itr->app.priority;
  1700. break;
  1701. }
  1702. }
  1703. spin_unlock(&dcb_lock);
  1704. return prio;
  1705. }
  1706. EXPORT_SYMBOL(dcb_getapp);
  1707. /**
  1708. * dcb_setapp - add CEE dcb application data to app list
  1709. *
  1710. * Priority 0 is an invalid priority in CEE spec. This routine
  1711. * removes applications from the app list if the priority is
  1712. * set to zero.
  1713. */
  1714. int dcb_setapp(struct net_device *dev, struct dcb_app *new)
  1715. {
  1716. struct dcb_app_type *itr;
  1717. struct dcb_app_type event;
  1718. memcpy(&event.name, dev->name, sizeof(event.name));
  1719. memcpy(&event.app, new, sizeof(event.app));
  1720. spin_lock(&dcb_lock);
  1721. /* Search for existing match and replace */
  1722. list_for_each_entry(itr, &dcb_app_list, list) {
  1723. if (itr->app.selector == new->selector &&
  1724. itr->app.protocol == new->protocol &&
  1725. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1726. if (new->priority)
  1727. itr->app.priority = new->priority;
  1728. else {
  1729. list_del(&itr->list);
  1730. kfree(itr);
  1731. }
  1732. goto out;
  1733. }
  1734. }
  1735. /* App type does not exist add new application type */
  1736. if (new->priority) {
  1737. struct dcb_app_type *entry;
  1738. entry = kmalloc(sizeof(struct dcb_app_type), GFP_ATOMIC);
  1739. if (!entry) {
  1740. spin_unlock(&dcb_lock);
  1741. return -ENOMEM;
  1742. }
  1743. memcpy(&entry->app, new, sizeof(*new));
  1744. strncpy(entry->name, dev->name, IFNAMSIZ);
  1745. list_add(&entry->list, &dcb_app_list);
  1746. }
  1747. out:
  1748. spin_unlock(&dcb_lock);
  1749. call_dcbevent_notifiers(DCB_APP_EVENT, &event);
  1750. return 0;
  1751. }
  1752. EXPORT_SYMBOL(dcb_setapp);
  1753. /**
  1754. * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority
  1755. *
  1756. * Helper routine which on success returns a non-zero 802.1Qaz user
  1757. * priority bitmap otherwise returns 0 to indicate the dcb_app was
  1758. * not found in APP list.
  1759. */
  1760. u8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app)
  1761. {
  1762. struct dcb_app_type *itr;
  1763. u8 prio = 0;
  1764. spin_lock(&dcb_lock);
  1765. list_for_each_entry(itr, &dcb_app_list, list) {
  1766. if (itr->app.selector == app->selector &&
  1767. itr->app.protocol == app->protocol &&
  1768. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1769. prio |= 1 << itr->app.priority;
  1770. }
  1771. }
  1772. spin_unlock(&dcb_lock);
  1773. return prio;
  1774. }
  1775. EXPORT_SYMBOL(dcb_ieee_getapp_mask);
  1776. /**
  1777. * dcb_ieee_setapp - add IEEE dcb application data to app list
  1778. *
  1779. * This adds Application data to the list. Multiple application
  1780. * entries may exists for the same selector and protocol as long
  1781. * as the priorities are different.
  1782. */
  1783. int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new)
  1784. {
  1785. struct dcb_app_type *itr, *entry;
  1786. struct dcb_app_type event;
  1787. int err = 0;
  1788. memcpy(&event.name, dev->name, sizeof(event.name));
  1789. memcpy(&event.app, new, sizeof(event.app));
  1790. spin_lock(&dcb_lock);
  1791. /* Search for existing match and abort if found */
  1792. list_for_each_entry(itr, &dcb_app_list, list) {
  1793. if (itr->app.selector == new->selector &&
  1794. itr->app.protocol == new->protocol &&
  1795. itr->app.priority == new->priority &&
  1796. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1797. err = -EEXIST;
  1798. goto out;
  1799. }
  1800. }
  1801. /* App entry does not exist add new entry */
  1802. entry = kmalloc(sizeof(struct dcb_app_type), GFP_ATOMIC);
  1803. if (!entry) {
  1804. err = -ENOMEM;
  1805. goto out;
  1806. }
  1807. memcpy(&entry->app, new, sizeof(*new));
  1808. strncpy(entry->name, dev->name, IFNAMSIZ);
  1809. list_add(&entry->list, &dcb_app_list);
  1810. out:
  1811. spin_unlock(&dcb_lock);
  1812. if (!err)
  1813. call_dcbevent_notifiers(DCB_APP_EVENT, &event);
  1814. return err;
  1815. }
  1816. EXPORT_SYMBOL(dcb_ieee_setapp);
  1817. /**
  1818. * dcb_ieee_delapp - delete IEEE dcb application data from list
  1819. *
  1820. * This removes a matching APP data from the APP list
  1821. */
  1822. int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del)
  1823. {
  1824. struct dcb_app_type *itr;
  1825. struct dcb_app_type event;
  1826. int err = -ENOENT;
  1827. memcpy(&event.name, dev->name, sizeof(event.name));
  1828. memcpy(&event.app, del, sizeof(event.app));
  1829. spin_lock(&dcb_lock);
  1830. /* Search for existing match and remove it. */
  1831. list_for_each_entry(itr, &dcb_app_list, list) {
  1832. if (itr->app.selector == del->selector &&
  1833. itr->app.protocol == del->protocol &&
  1834. itr->app.priority == del->priority &&
  1835. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1836. list_del(&itr->list);
  1837. kfree(itr);
  1838. err = 0;
  1839. goto out;
  1840. }
  1841. }
  1842. out:
  1843. spin_unlock(&dcb_lock);
  1844. if (!err)
  1845. call_dcbevent_notifiers(DCB_APP_EVENT, &event);
  1846. return err;
  1847. }
  1848. EXPORT_SYMBOL(dcb_ieee_delapp);
  1849. static void dcb_flushapp(void)
  1850. {
  1851. struct dcb_app_type *app;
  1852. struct dcb_app_type *tmp;
  1853. spin_lock(&dcb_lock);
  1854. list_for_each_entry_safe(app, tmp, &dcb_app_list, list) {
  1855. list_del(&app->list);
  1856. kfree(app);
  1857. }
  1858. spin_unlock(&dcb_lock);
  1859. }
  1860. static int __init dcbnl_init(void)
  1861. {
  1862. INIT_LIST_HEAD(&dcb_app_list);
  1863. rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, NULL);
  1864. rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, NULL);
  1865. return 0;
  1866. }
  1867. module_init(dcbnl_init);
  1868. static void __exit dcbnl_exit(void)
  1869. {
  1870. rtnl_unregister(PF_UNSPEC, RTM_GETDCB);
  1871. rtnl_unregister(PF_UNSPEC, RTM_SETDCB);
  1872. dcb_flushapp();
  1873. }
  1874. module_exit(dcbnl_exit);