dcbnl.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217
  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. int dcbnl_notify(struct net_device *dev, int event, int cmd,
  1079. u32 seq, u32 pid)
  1080. {
  1081. struct net *net = dev_net(dev);
  1082. struct sk_buff *skb;
  1083. struct nlmsghdr *nlh;
  1084. struct dcbmsg *dcb;
  1085. const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
  1086. int err;
  1087. if (!ops)
  1088. return -EOPNOTSUPP;
  1089. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1090. if (!skb)
  1091. return -ENOBUFS;
  1092. nlh = nlmsg_put(skb, pid, 0, event, sizeof(*dcb), 0);
  1093. if (nlh == NULL) {
  1094. nlmsg_free(skb);
  1095. return -EMSGSIZE;
  1096. }
  1097. dcb = NLMSG_DATA(nlh);
  1098. dcb->dcb_family = AF_UNSPEC;
  1099. dcb->cmd = cmd;
  1100. err = dcbnl_ieee_fill(skb, dev);
  1101. if (err < 0) {
  1102. /* Report error to broadcast listeners */
  1103. nlmsg_cancel(skb, nlh);
  1104. kfree_skb(skb);
  1105. rtnl_set_sk_err(net, RTNLGRP_DCB, err);
  1106. } else {
  1107. /* End nlmsg and notify broadcast listeners */
  1108. nlmsg_end(skb, nlh);
  1109. rtnl_notify(skb, net, 0, RTNLGRP_DCB, NULL, GFP_KERNEL);
  1110. }
  1111. return err;
  1112. }
  1113. EXPORT_SYMBOL(dcbnl_notify);
  1114. /* Handle IEEE 802.1Qaz SET commands. If any requested operation can not
  1115. * be completed the entire msg is aborted and error value is returned.
  1116. * No attempt is made to reconcile the case where only part of the
  1117. * cmd can be completed.
  1118. */
  1119. static int dcbnl_ieee_set(struct net_device *netdev, struct nlattr **tb,
  1120. u32 pid, u32 seq, u16 flags)
  1121. {
  1122. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1123. struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
  1124. int err = -EOPNOTSUPP;
  1125. if (!ops)
  1126. return err;
  1127. if (!tb[DCB_ATTR_IEEE])
  1128. return -EINVAL;
  1129. err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX,
  1130. tb[DCB_ATTR_IEEE], dcbnl_ieee_policy);
  1131. if (err)
  1132. return err;
  1133. if (ieee[DCB_ATTR_IEEE_ETS] && ops->ieee_setets) {
  1134. struct ieee_ets *ets = nla_data(ieee[DCB_ATTR_IEEE_ETS]);
  1135. err = ops->ieee_setets(netdev, ets);
  1136. if (err)
  1137. goto err;
  1138. }
  1139. if (ieee[DCB_ATTR_IEEE_PFC] && ops->ieee_setpfc) {
  1140. struct ieee_pfc *pfc = nla_data(ieee[DCB_ATTR_IEEE_PFC]);
  1141. err = ops->ieee_setpfc(netdev, pfc);
  1142. if (err)
  1143. goto err;
  1144. }
  1145. if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
  1146. struct nlattr *attr;
  1147. int rem;
  1148. nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
  1149. struct dcb_app *app_data;
  1150. if (nla_type(attr) != DCB_ATTR_IEEE_APP)
  1151. continue;
  1152. app_data = nla_data(attr);
  1153. if (ops->ieee_setapp)
  1154. err = ops->ieee_setapp(netdev, app_data);
  1155. else
  1156. err = dcb_ieee_setapp(netdev, app_data);
  1157. if (err)
  1158. goto err;
  1159. }
  1160. }
  1161. err:
  1162. dcbnl_reply(err, RTM_SETDCB, DCB_CMD_IEEE_SET, DCB_ATTR_IEEE,
  1163. pid, seq, flags);
  1164. dcbnl_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, seq, 0);
  1165. return err;
  1166. }
  1167. static int dcbnl_ieee_get(struct net_device *netdev, struct nlattr **tb,
  1168. u32 pid, u32 seq, u16 flags)
  1169. {
  1170. struct net *net = dev_net(netdev);
  1171. struct sk_buff *skb;
  1172. struct nlmsghdr *nlh;
  1173. struct dcbmsg *dcb;
  1174. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1175. int err;
  1176. if (!ops)
  1177. return -EOPNOTSUPP;
  1178. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1179. if (!skb)
  1180. return -ENOBUFS;
  1181. nlh = nlmsg_put(skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1182. if (nlh == NULL) {
  1183. nlmsg_free(skb);
  1184. return -EMSGSIZE;
  1185. }
  1186. dcb = NLMSG_DATA(nlh);
  1187. dcb->dcb_family = AF_UNSPEC;
  1188. dcb->cmd = DCB_CMD_IEEE_GET;
  1189. err = dcbnl_ieee_fill(skb, netdev);
  1190. if (err < 0) {
  1191. nlmsg_cancel(skb, nlh);
  1192. kfree_skb(skb);
  1193. } else {
  1194. nlmsg_end(skb, nlh);
  1195. err = rtnl_unicast(skb, net, pid);
  1196. }
  1197. return err;
  1198. }
  1199. static int dcbnl_ieee_del(struct net_device *netdev, struct nlattr **tb,
  1200. u32 pid, u32 seq, u16 flags)
  1201. {
  1202. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1203. struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
  1204. int err = -EOPNOTSUPP;
  1205. if (!ops)
  1206. return -EOPNOTSUPP;
  1207. if (!tb[DCB_ATTR_IEEE])
  1208. return -EINVAL;
  1209. err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX,
  1210. tb[DCB_ATTR_IEEE], dcbnl_ieee_policy);
  1211. if (err)
  1212. return err;
  1213. if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
  1214. struct nlattr *attr;
  1215. int rem;
  1216. nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
  1217. struct dcb_app *app_data;
  1218. if (nla_type(attr) != DCB_ATTR_IEEE_APP)
  1219. continue;
  1220. app_data = nla_data(attr);
  1221. if (ops->ieee_delapp)
  1222. err = ops->ieee_delapp(netdev, app_data);
  1223. else
  1224. err = dcb_ieee_delapp(netdev, app_data);
  1225. if (err)
  1226. goto err;
  1227. }
  1228. }
  1229. err:
  1230. dcbnl_reply(err, RTM_SETDCB, DCB_CMD_IEEE_DEL, DCB_ATTR_IEEE,
  1231. pid, seq, flags);
  1232. dcbnl_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_DEL, seq, 0);
  1233. return err;
  1234. }
  1235. /* DCBX configuration */
  1236. static int dcbnl_getdcbx(struct net_device *netdev, struct nlattr **tb,
  1237. u32 pid, u32 seq, u16 flags)
  1238. {
  1239. int ret;
  1240. if (!netdev->dcbnl_ops->getdcbx)
  1241. return -EOPNOTSUPP;
  1242. ret = dcbnl_reply(netdev->dcbnl_ops->getdcbx(netdev), RTM_GETDCB,
  1243. DCB_CMD_GDCBX, DCB_ATTR_DCBX, pid, seq, flags);
  1244. return ret;
  1245. }
  1246. static int dcbnl_setdcbx(struct net_device *netdev, struct nlattr **tb,
  1247. u32 pid, u32 seq, u16 flags)
  1248. {
  1249. int ret;
  1250. u8 value;
  1251. if (!netdev->dcbnl_ops->setdcbx)
  1252. return -EOPNOTSUPP;
  1253. if (!tb[DCB_ATTR_DCBX])
  1254. return -EINVAL;
  1255. value = nla_get_u8(tb[DCB_ATTR_DCBX]);
  1256. ret = dcbnl_reply(netdev->dcbnl_ops->setdcbx(netdev, value),
  1257. RTM_SETDCB, DCB_CMD_SDCBX, DCB_ATTR_DCBX,
  1258. pid, seq, flags);
  1259. return ret;
  1260. }
  1261. static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlattr **tb,
  1262. u32 pid, u32 seq, u16 flags)
  1263. {
  1264. struct sk_buff *dcbnl_skb;
  1265. struct nlmsghdr *nlh;
  1266. struct dcbmsg *dcb;
  1267. struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1], *nest;
  1268. u8 value;
  1269. int ret, i;
  1270. int getall = 0;
  1271. if (!netdev->dcbnl_ops->getfeatcfg)
  1272. return -EOPNOTSUPP;
  1273. if (!tb[DCB_ATTR_FEATCFG])
  1274. return -EINVAL;
  1275. ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
  1276. dcbnl_featcfg_nest);
  1277. if (ret)
  1278. goto err_out;
  1279. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1280. if (!dcbnl_skb) {
  1281. ret = -ENOBUFS;
  1282. goto err_out;
  1283. }
  1284. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1285. dcb = NLMSG_DATA(nlh);
  1286. dcb->dcb_family = AF_UNSPEC;
  1287. dcb->cmd = DCB_CMD_GFEATCFG;
  1288. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_FEATCFG);
  1289. if (!nest) {
  1290. ret = -EMSGSIZE;
  1291. goto nla_put_failure;
  1292. }
  1293. if (data[DCB_FEATCFG_ATTR_ALL])
  1294. getall = 1;
  1295. for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
  1296. if (!getall && !data[i])
  1297. continue;
  1298. ret = netdev->dcbnl_ops->getfeatcfg(netdev, i, &value);
  1299. if (!ret)
  1300. ret = nla_put_u8(dcbnl_skb, i, value);
  1301. if (ret) {
  1302. nla_nest_cancel(dcbnl_skb, nest);
  1303. goto nla_put_failure;
  1304. }
  1305. }
  1306. nla_nest_end(dcbnl_skb, nest);
  1307. nlmsg_end(dcbnl_skb, nlh);
  1308. return rtnl_unicast(dcbnl_skb, &init_net, pid);
  1309. nla_put_failure:
  1310. nlmsg_cancel(dcbnl_skb, nlh);
  1311. nlmsg_failure:
  1312. kfree_skb(dcbnl_skb);
  1313. err_out:
  1314. return ret;
  1315. }
  1316. static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlattr **tb,
  1317. u32 pid, u32 seq, u16 flags)
  1318. {
  1319. struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1];
  1320. int ret, i;
  1321. u8 value;
  1322. if (!netdev->dcbnl_ops->setfeatcfg)
  1323. return -ENOTSUPP;
  1324. if (!tb[DCB_ATTR_FEATCFG])
  1325. return -EINVAL;
  1326. ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
  1327. dcbnl_featcfg_nest);
  1328. if (ret)
  1329. goto err;
  1330. for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
  1331. if (data[i] == NULL)
  1332. continue;
  1333. value = nla_get_u8(data[i]);
  1334. ret = netdev->dcbnl_ops->setfeatcfg(netdev, i, value);
  1335. if (ret)
  1336. goto err;
  1337. }
  1338. err:
  1339. dcbnl_reply(ret, RTM_SETDCB, DCB_CMD_SFEATCFG, DCB_ATTR_FEATCFG,
  1340. pid, seq, flags);
  1341. return ret;
  1342. }
  1343. static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev,
  1344. int dir)
  1345. {
  1346. u8 pgid, up_map, prio, tc_pct;
  1347. const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
  1348. int i = dir ? DCB_ATTR_CEE_TX_PG : DCB_ATTR_CEE_RX_PG;
  1349. struct nlattr *pg = nla_nest_start(skb, i);
  1350. if (!pg)
  1351. goto nla_put_failure;
  1352. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  1353. struct nlattr *tc_nest = nla_nest_start(skb, i);
  1354. if (!tc_nest)
  1355. goto nla_put_failure;
  1356. pgid = DCB_ATTR_VALUE_UNDEFINED;
  1357. prio = DCB_ATTR_VALUE_UNDEFINED;
  1358. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  1359. up_map = DCB_ATTR_VALUE_UNDEFINED;
  1360. if (!dir)
  1361. ops->getpgtccfgrx(dev, i - DCB_PG_ATTR_TC_0,
  1362. &prio, &pgid, &tc_pct, &up_map);
  1363. else
  1364. ops->getpgtccfgtx(dev, i - DCB_PG_ATTR_TC_0,
  1365. &prio, &pgid, &tc_pct, &up_map);
  1366. NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_PGID, pgid);
  1367. NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
  1368. NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
  1369. NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_BW_PCT, tc_pct);
  1370. nla_nest_end(skb, tc_nest);
  1371. }
  1372. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  1373. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  1374. if (!dir)
  1375. ops->getpgbwgcfgrx(dev, i - DCB_PG_ATTR_BW_ID_0,
  1376. &tc_pct);
  1377. else
  1378. ops->getpgbwgcfgtx(dev, i - DCB_PG_ATTR_BW_ID_0,
  1379. &tc_pct);
  1380. NLA_PUT_U8(skb, i, tc_pct);
  1381. }
  1382. nla_nest_end(skb, pg);
  1383. return 0;
  1384. nla_put_failure:
  1385. return -EMSGSIZE;
  1386. }
  1387. /* Handle CEE DCBX GET commands. */
  1388. static int dcbnl_cee_get(struct net_device *netdev, struct nlattr **tb,
  1389. u32 pid, u32 seq, u16 flags)
  1390. {
  1391. struct sk_buff *skb;
  1392. struct nlmsghdr *nlh;
  1393. struct dcbmsg *dcb;
  1394. struct nlattr *cee, *app;
  1395. struct dcb_app_type *itr;
  1396. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1397. int dcbx, i, err = -EMSGSIZE;
  1398. u8 value;
  1399. if (!ops)
  1400. return -EOPNOTSUPP;
  1401. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1402. if (!skb)
  1403. return -ENOBUFS;
  1404. nlh = NLMSG_NEW(skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1405. dcb = NLMSG_DATA(nlh);
  1406. dcb->dcb_family = AF_UNSPEC;
  1407. dcb->cmd = DCB_CMD_CEE_GET;
  1408. NLA_PUT_STRING(skb, DCB_ATTR_IFNAME, netdev->name);
  1409. cee = nla_nest_start(skb, DCB_ATTR_CEE);
  1410. if (!cee)
  1411. goto nla_put_failure;
  1412. /* local pg */
  1413. if (ops->getpgtccfgtx && ops->getpgbwgcfgtx) {
  1414. err = dcbnl_cee_pg_fill(skb, netdev, 1);
  1415. if (err)
  1416. goto nla_put_failure;
  1417. }
  1418. if (ops->getpgtccfgrx && ops->getpgbwgcfgrx) {
  1419. err = dcbnl_cee_pg_fill(skb, netdev, 0);
  1420. if (err)
  1421. goto nla_put_failure;
  1422. }
  1423. /* local pfc */
  1424. if (ops->getpfccfg) {
  1425. struct nlattr *pfc_nest = nla_nest_start(skb, DCB_ATTR_CEE_PFC);
  1426. if (!pfc_nest)
  1427. goto nla_put_failure;
  1428. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  1429. ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, &value);
  1430. NLA_PUT_U8(skb, i, value);
  1431. }
  1432. nla_nest_end(skb, pfc_nest);
  1433. }
  1434. /* local app */
  1435. spin_lock(&dcb_lock);
  1436. app = nla_nest_start(skb, DCB_ATTR_CEE_APP_TABLE);
  1437. if (!app)
  1438. goto nla_put_failure;
  1439. list_for_each_entry(itr, &dcb_app_list, list) {
  1440. if (strncmp(itr->name, netdev->name, IFNAMSIZ) == 0) {
  1441. struct nlattr *app_nest = nla_nest_start(skb,
  1442. DCB_ATTR_APP);
  1443. if (!app_nest)
  1444. goto dcb_unlock;
  1445. err = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE,
  1446. itr->app.selector);
  1447. if (err)
  1448. goto dcb_unlock;
  1449. err = nla_put_u16(skb, DCB_APP_ATTR_ID,
  1450. itr->app.protocol);
  1451. if (err)
  1452. goto dcb_unlock;
  1453. err = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY,
  1454. itr->app.priority);
  1455. if (err)
  1456. goto dcb_unlock;
  1457. nla_nest_end(skb, app_nest);
  1458. }
  1459. }
  1460. nla_nest_end(skb, app);
  1461. if (netdev->dcbnl_ops->getdcbx)
  1462. dcbx = netdev->dcbnl_ops->getdcbx(netdev);
  1463. else
  1464. dcbx = -EOPNOTSUPP;
  1465. spin_unlock(&dcb_lock);
  1466. /* features flags */
  1467. if (ops->getfeatcfg) {
  1468. struct nlattr *feat = nla_nest_start(skb, DCB_ATTR_CEE_FEAT);
  1469. if (!feat)
  1470. goto nla_put_failure;
  1471. for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX;
  1472. i++)
  1473. if (!ops->getfeatcfg(netdev, i, &value))
  1474. NLA_PUT_U8(skb, i, value);
  1475. nla_nest_end(skb, feat);
  1476. }
  1477. /* peer info if available */
  1478. if (ops->cee_peer_getpg) {
  1479. struct cee_pg pg;
  1480. err = ops->cee_peer_getpg(netdev, &pg);
  1481. if (!err)
  1482. NLA_PUT(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg);
  1483. }
  1484. if (ops->cee_peer_getpfc) {
  1485. struct cee_pfc pfc;
  1486. err = ops->cee_peer_getpfc(netdev, &pfc);
  1487. if (!err)
  1488. NLA_PUT(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc);
  1489. }
  1490. if (ops->peer_getappinfo && ops->peer_getapptable) {
  1491. err = dcbnl_build_peer_app(netdev, skb,
  1492. DCB_ATTR_CEE_PEER_APP_TABLE,
  1493. DCB_ATTR_CEE_PEER_APP_INFO,
  1494. DCB_ATTR_CEE_PEER_APP);
  1495. if (err)
  1496. goto nla_put_failure;
  1497. }
  1498. nla_nest_end(skb, cee);
  1499. /* DCBX state */
  1500. if (dcbx >= 0) {
  1501. err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx);
  1502. if (err)
  1503. goto nla_put_failure;
  1504. }
  1505. nlmsg_end(skb, nlh);
  1506. return rtnl_unicast(skb, &init_net, pid);
  1507. dcb_unlock:
  1508. spin_unlock(&dcb_lock);
  1509. nla_put_failure:
  1510. nlmsg_cancel(skb, nlh);
  1511. nlmsg_failure:
  1512. nlmsg_free(skb);
  1513. return err;
  1514. }
  1515. static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
  1516. {
  1517. struct net *net = sock_net(skb->sk);
  1518. struct net_device *netdev;
  1519. struct dcbmsg *dcb = (struct dcbmsg *)NLMSG_DATA(nlh);
  1520. struct nlattr *tb[DCB_ATTR_MAX + 1];
  1521. u32 pid = skb ? NETLINK_CB(skb).pid : 0;
  1522. int ret = -EINVAL;
  1523. if (!net_eq(net, &init_net))
  1524. return -EINVAL;
  1525. ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
  1526. dcbnl_rtnl_policy);
  1527. if (ret < 0)
  1528. return ret;
  1529. if (!tb[DCB_ATTR_IFNAME])
  1530. return -EINVAL;
  1531. netdev = dev_get_by_name(&init_net, nla_data(tb[DCB_ATTR_IFNAME]));
  1532. if (!netdev)
  1533. return -EINVAL;
  1534. if (!netdev->dcbnl_ops)
  1535. goto errout;
  1536. switch (dcb->cmd) {
  1537. case DCB_CMD_GSTATE:
  1538. ret = dcbnl_getstate(netdev, tb, pid, nlh->nlmsg_seq,
  1539. nlh->nlmsg_flags);
  1540. goto out;
  1541. case DCB_CMD_PFC_GCFG:
  1542. ret = dcbnl_getpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  1543. nlh->nlmsg_flags);
  1544. goto out;
  1545. case DCB_CMD_GPERM_HWADDR:
  1546. ret = dcbnl_getperm_hwaddr(netdev, tb, pid, nlh->nlmsg_seq,
  1547. nlh->nlmsg_flags);
  1548. goto out;
  1549. case DCB_CMD_PGTX_GCFG:
  1550. ret = dcbnl_pgtx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1551. nlh->nlmsg_flags);
  1552. goto out;
  1553. case DCB_CMD_PGRX_GCFG:
  1554. ret = dcbnl_pgrx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1555. nlh->nlmsg_flags);
  1556. goto out;
  1557. case DCB_CMD_BCN_GCFG:
  1558. ret = dcbnl_bcn_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1559. nlh->nlmsg_flags);
  1560. goto out;
  1561. case DCB_CMD_SSTATE:
  1562. ret = dcbnl_setstate(netdev, tb, pid, nlh->nlmsg_seq,
  1563. nlh->nlmsg_flags);
  1564. goto out;
  1565. case DCB_CMD_PFC_SCFG:
  1566. ret = dcbnl_setpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  1567. nlh->nlmsg_flags);
  1568. goto out;
  1569. case DCB_CMD_SET_ALL:
  1570. ret = dcbnl_setall(netdev, tb, pid, nlh->nlmsg_seq,
  1571. nlh->nlmsg_flags);
  1572. goto out;
  1573. case DCB_CMD_PGTX_SCFG:
  1574. ret = dcbnl_pgtx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1575. nlh->nlmsg_flags);
  1576. goto out;
  1577. case DCB_CMD_PGRX_SCFG:
  1578. ret = dcbnl_pgrx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1579. nlh->nlmsg_flags);
  1580. goto out;
  1581. case DCB_CMD_GCAP:
  1582. ret = dcbnl_getcap(netdev, tb, pid, nlh->nlmsg_seq,
  1583. nlh->nlmsg_flags);
  1584. goto out;
  1585. case DCB_CMD_GNUMTCS:
  1586. ret = dcbnl_getnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  1587. nlh->nlmsg_flags);
  1588. goto out;
  1589. case DCB_CMD_SNUMTCS:
  1590. ret = dcbnl_setnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  1591. nlh->nlmsg_flags);
  1592. goto out;
  1593. case DCB_CMD_PFC_GSTATE:
  1594. ret = dcbnl_getpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  1595. nlh->nlmsg_flags);
  1596. goto out;
  1597. case DCB_CMD_PFC_SSTATE:
  1598. ret = dcbnl_setpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  1599. nlh->nlmsg_flags);
  1600. goto out;
  1601. case DCB_CMD_BCN_SCFG:
  1602. ret = dcbnl_bcn_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1603. nlh->nlmsg_flags);
  1604. goto out;
  1605. case DCB_CMD_GAPP:
  1606. ret = dcbnl_getapp(netdev, tb, pid, nlh->nlmsg_seq,
  1607. nlh->nlmsg_flags);
  1608. goto out;
  1609. case DCB_CMD_SAPP:
  1610. ret = dcbnl_setapp(netdev, tb, pid, nlh->nlmsg_seq,
  1611. nlh->nlmsg_flags);
  1612. goto out;
  1613. case DCB_CMD_IEEE_SET:
  1614. ret = dcbnl_ieee_set(netdev, tb, pid, nlh->nlmsg_seq,
  1615. nlh->nlmsg_flags);
  1616. goto out;
  1617. case DCB_CMD_IEEE_GET:
  1618. ret = dcbnl_ieee_get(netdev, tb, pid, nlh->nlmsg_seq,
  1619. nlh->nlmsg_flags);
  1620. goto out;
  1621. case DCB_CMD_IEEE_DEL:
  1622. ret = dcbnl_ieee_del(netdev, tb, pid, nlh->nlmsg_seq,
  1623. nlh->nlmsg_flags);
  1624. goto out;
  1625. case DCB_CMD_GDCBX:
  1626. ret = dcbnl_getdcbx(netdev, tb, pid, nlh->nlmsg_seq,
  1627. nlh->nlmsg_flags);
  1628. goto out;
  1629. case DCB_CMD_SDCBX:
  1630. ret = dcbnl_setdcbx(netdev, tb, pid, nlh->nlmsg_seq,
  1631. nlh->nlmsg_flags);
  1632. goto out;
  1633. case DCB_CMD_GFEATCFG:
  1634. ret = dcbnl_getfeatcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1635. nlh->nlmsg_flags);
  1636. goto out;
  1637. case DCB_CMD_SFEATCFG:
  1638. ret = dcbnl_setfeatcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1639. nlh->nlmsg_flags);
  1640. goto out;
  1641. case DCB_CMD_CEE_GET:
  1642. ret = dcbnl_cee_get(netdev, tb, pid, nlh->nlmsg_seq,
  1643. nlh->nlmsg_flags);
  1644. goto out;
  1645. default:
  1646. goto errout;
  1647. }
  1648. errout:
  1649. ret = -EINVAL;
  1650. out:
  1651. dev_put(netdev);
  1652. return ret;
  1653. }
  1654. /**
  1655. * dcb_getapp - retrieve the DCBX application user priority
  1656. *
  1657. * On success returns a non-zero 802.1p user priority bitmap
  1658. * otherwise returns 0 as the invalid user priority bitmap to
  1659. * indicate an error.
  1660. */
  1661. u8 dcb_getapp(struct net_device *dev, struct dcb_app *app)
  1662. {
  1663. struct dcb_app_type *itr;
  1664. u8 prio = 0;
  1665. spin_lock(&dcb_lock);
  1666. list_for_each_entry(itr, &dcb_app_list, list) {
  1667. if (itr->app.selector == app->selector &&
  1668. itr->app.protocol == app->protocol &&
  1669. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1670. prio = itr->app.priority;
  1671. break;
  1672. }
  1673. }
  1674. spin_unlock(&dcb_lock);
  1675. return prio;
  1676. }
  1677. EXPORT_SYMBOL(dcb_getapp);
  1678. /**
  1679. * dcb_setapp - add CEE dcb application data to app list
  1680. *
  1681. * Priority 0 is an invalid priority in CEE spec. This routine
  1682. * removes applications from the app list if the priority is
  1683. * set to zero.
  1684. */
  1685. int dcb_setapp(struct net_device *dev, struct dcb_app *new)
  1686. {
  1687. struct dcb_app_type *itr;
  1688. struct dcb_app_type event;
  1689. memcpy(&event.name, dev->name, sizeof(event.name));
  1690. memcpy(&event.app, new, sizeof(event.app));
  1691. spin_lock(&dcb_lock);
  1692. /* Search for existing match and replace */
  1693. list_for_each_entry(itr, &dcb_app_list, list) {
  1694. if (itr->app.selector == new->selector &&
  1695. itr->app.protocol == new->protocol &&
  1696. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1697. if (new->priority)
  1698. itr->app.priority = new->priority;
  1699. else {
  1700. list_del(&itr->list);
  1701. kfree(itr);
  1702. }
  1703. goto out;
  1704. }
  1705. }
  1706. /* App type does not exist add new application type */
  1707. if (new->priority) {
  1708. struct dcb_app_type *entry;
  1709. entry = kmalloc(sizeof(struct dcb_app_type), GFP_ATOMIC);
  1710. if (!entry) {
  1711. spin_unlock(&dcb_lock);
  1712. return -ENOMEM;
  1713. }
  1714. memcpy(&entry->app, new, sizeof(*new));
  1715. strncpy(entry->name, dev->name, IFNAMSIZ);
  1716. list_add(&entry->list, &dcb_app_list);
  1717. }
  1718. out:
  1719. spin_unlock(&dcb_lock);
  1720. call_dcbevent_notifiers(DCB_APP_EVENT, &event);
  1721. return 0;
  1722. }
  1723. EXPORT_SYMBOL(dcb_setapp);
  1724. /**
  1725. * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority
  1726. *
  1727. * Helper routine which on success returns a non-zero 802.1Qaz user
  1728. * priority bitmap otherwise returns 0 to indicate the dcb_app was
  1729. * not found in APP list.
  1730. */
  1731. u8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app)
  1732. {
  1733. struct dcb_app_type *itr;
  1734. u8 prio = 0;
  1735. spin_lock(&dcb_lock);
  1736. list_for_each_entry(itr, &dcb_app_list, list) {
  1737. if (itr->app.selector == app->selector &&
  1738. itr->app.protocol == app->protocol &&
  1739. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1740. prio |= 1 << itr->app.priority;
  1741. }
  1742. }
  1743. spin_unlock(&dcb_lock);
  1744. return prio;
  1745. }
  1746. EXPORT_SYMBOL(dcb_ieee_getapp_mask);
  1747. /**
  1748. * dcb_ieee_setapp - add IEEE dcb application data to app list
  1749. *
  1750. * This adds Application data to the list. Multiple application
  1751. * entries may exists for the same selector and protocol as long
  1752. * as the priorities are different.
  1753. */
  1754. int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new)
  1755. {
  1756. struct dcb_app_type *itr, *entry;
  1757. struct dcb_app_type event;
  1758. int err = 0;
  1759. memcpy(&event.name, dev->name, sizeof(event.name));
  1760. memcpy(&event.app, new, sizeof(event.app));
  1761. spin_lock(&dcb_lock);
  1762. /* Search for existing match and abort if found */
  1763. list_for_each_entry(itr, &dcb_app_list, list) {
  1764. if (itr->app.selector == new->selector &&
  1765. itr->app.protocol == new->protocol &&
  1766. itr->app.priority == new->priority &&
  1767. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1768. err = -EEXIST;
  1769. goto out;
  1770. }
  1771. }
  1772. /* App entry does not exist add new entry */
  1773. entry = kmalloc(sizeof(struct dcb_app_type), GFP_ATOMIC);
  1774. if (!entry) {
  1775. err = -ENOMEM;
  1776. goto out;
  1777. }
  1778. memcpy(&entry->app, new, sizeof(*new));
  1779. strncpy(entry->name, dev->name, IFNAMSIZ);
  1780. list_add(&entry->list, &dcb_app_list);
  1781. out:
  1782. spin_unlock(&dcb_lock);
  1783. if (!err)
  1784. call_dcbevent_notifiers(DCB_APP_EVENT, &event);
  1785. return err;
  1786. }
  1787. EXPORT_SYMBOL(dcb_ieee_setapp);
  1788. /**
  1789. * dcb_ieee_delapp - delete IEEE dcb application data from list
  1790. *
  1791. * This removes a matching APP data from the APP list
  1792. */
  1793. int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del)
  1794. {
  1795. struct dcb_app_type *itr;
  1796. struct dcb_app_type event;
  1797. int err = -ENOENT;
  1798. memcpy(&event.name, dev->name, sizeof(event.name));
  1799. memcpy(&event.app, del, sizeof(event.app));
  1800. spin_lock(&dcb_lock);
  1801. /* Search for existing match and remove it. */
  1802. list_for_each_entry(itr, &dcb_app_list, list) {
  1803. if (itr->app.selector == del->selector &&
  1804. itr->app.protocol == del->protocol &&
  1805. itr->app.priority == del->priority &&
  1806. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1807. list_del(&itr->list);
  1808. kfree(itr);
  1809. err = 0;
  1810. goto out;
  1811. }
  1812. }
  1813. out:
  1814. spin_unlock(&dcb_lock);
  1815. if (!err)
  1816. call_dcbevent_notifiers(DCB_APP_EVENT, &event);
  1817. return err;
  1818. }
  1819. EXPORT_SYMBOL(dcb_ieee_delapp);
  1820. static void dcb_flushapp(void)
  1821. {
  1822. struct dcb_app_type *app;
  1823. struct dcb_app_type *tmp;
  1824. spin_lock(&dcb_lock);
  1825. list_for_each_entry_safe(app, tmp, &dcb_app_list, list) {
  1826. list_del(&app->list);
  1827. kfree(app);
  1828. }
  1829. spin_unlock(&dcb_lock);
  1830. }
  1831. static int __init dcbnl_init(void)
  1832. {
  1833. INIT_LIST_HEAD(&dcb_app_list);
  1834. rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, NULL);
  1835. rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, NULL);
  1836. return 0;
  1837. }
  1838. module_init(dcbnl_init);
  1839. static void __exit dcbnl_exit(void)
  1840. {
  1841. rtnl_unregister(PF_UNSPEC, RTM_GETDCB);
  1842. rtnl_unregister(PF_UNSPEC, RTM_SETDCB);
  1843. dcb_flushapp();
  1844. }
  1845. module_exit(dcbnl_exit);