team.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077
  1. /*
  2. * net/drivers/team/team.c - Network team device driver
  3. * Copyright (c) 2011 Jiri Pirko <jpirko@redhat.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/types.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/slab.h>
  15. #include <linux/rcupdate.h>
  16. #include <linux/errno.h>
  17. #include <linux/ctype.h>
  18. #include <linux/notifier.h>
  19. #include <linux/netdevice.h>
  20. #include <linux/if_vlan.h>
  21. #include <linux/if_arp.h>
  22. #include <linux/socket.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/rtnetlink.h>
  25. #include <net/rtnetlink.h>
  26. #include <net/genetlink.h>
  27. #include <net/netlink.h>
  28. #include <linux/if_team.h>
  29. #define DRV_NAME "team"
  30. /**********
  31. * Helpers
  32. **********/
  33. #define team_port_exists(dev) (dev->priv_flags & IFF_TEAM_PORT)
  34. static struct team_port *team_port_get_rcu(const struct net_device *dev)
  35. {
  36. struct team_port *port = rcu_dereference(dev->rx_handler_data);
  37. return team_port_exists(dev) ? port : NULL;
  38. }
  39. static struct team_port *team_port_get_rtnl(const struct net_device *dev)
  40. {
  41. struct team_port *port = rtnl_dereference(dev->rx_handler_data);
  42. return team_port_exists(dev) ? port : NULL;
  43. }
  44. /*
  45. * Since the ability to change mac address for open port device is tested in
  46. * team_port_add, this function can be called without control of return value
  47. */
  48. static int __set_port_mac(struct net_device *port_dev,
  49. const unsigned char *dev_addr)
  50. {
  51. struct sockaddr addr;
  52. memcpy(addr.sa_data, dev_addr, ETH_ALEN);
  53. addr.sa_family = ARPHRD_ETHER;
  54. return dev_set_mac_address(port_dev, &addr);
  55. }
  56. static int team_port_set_orig_mac(struct team_port *port)
  57. {
  58. return __set_port_mac(port->dev, port->orig.dev_addr);
  59. }
  60. int team_port_set_team_mac(struct team_port *port)
  61. {
  62. return __set_port_mac(port->dev, port->team->dev->dev_addr);
  63. }
  64. EXPORT_SYMBOL(team_port_set_team_mac);
  65. static void team_refresh_port_linkup(struct team_port *port)
  66. {
  67. port->linkup = port->user.linkup_enabled ? port->user.linkup :
  68. port->state.linkup;
  69. }
  70. /*******************
  71. * Options handling
  72. *******************/
  73. struct team_option_inst { /* One for each option instance */
  74. struct list_head list;
  75. struct team_option *option;
  76. struct team_port *port; /* != NULL if per-port */
  77. bool changed;
  78. bool removed;
  79. };
  80. static struct team_option *__team_find_option(struct team *team,
  81. const char *opt_name)
  82. {
  83. struct team_option *option;
  84. list_for_each_entry(option, &team->option_list, list) {
  85. if (strcmp(option->name, opt_name) == 0)
  86. return option;
  87. }
  88. return NULL;
  89. }
  90. static int __team_option_inst_add(struct team *team, struct team_option *option,
  91. struct team_port *port)
  92. {
  93. struct team_option_inst *opt_inst;
  94. opt_inst = kmalloc(sizeof(*opt_inst), GFP_KERNEL);
  95. if (!opt_inst)
  96. return -ENOMEM;
  97. opt_inst->option = option;
  98. opt_inst->port = port;
  99. opt_inst->changed = true;
  100. opt_inst->removed = false;
  101. list_add_tail(&opt_inst->list, &team->option_inst_list);
  102. return 0;
  103. }
  104. static void __team_option_inst_del(struct team_option_inst *opt_inst)
  105. {
  106. list_del(&opt_inst->list);
  107. kfree(opt_inst);
  108. }
  109. static void __team_option_inst_del_option(struct team *team,
  110. struct team_option *option)
  111. {
  112. struct team_option_inst *opt_inst, *tmp;
  113. list_for_each_entry_safe(opt_inst, tmp, &team->option_inst_list, list) {
  114. if (opt_inst->option == option)
  115. __team_option_inst_del(opt_inst);
  116. }
  117. }
  118. static int __team_option_inst_add_option(struct team *team,
  119. struct team_option *option)
  120. {
  121. struct team_port *port;
  122. int err;
  123. if (!option->per_port)
  124. return __team_option_inst_add(team, option, 0);
  125. list_for_each_entry(port, &team->port_list, list) {
  126. err = __team_option_inst_add(team, option, port);
  127. if (err)
  128. goto inst_del_option;
  129. }
  130. return 0;
  131. inst_del_option:
  132. __team_option_inst_del_option(team, option);
  133. return err;
  134. }
  135. static void __team_option_inst_mark_removed_option(struct team *team,
  136. struct team_option *option)
  137. {
  138. struct team_option_inst *opt_inst;
  139. list_for_each_entry(opt_inst, &team->option_inst_list, list) {
  140. if (opt_inst->option == option) {
  141. opt_inst->changed = true;
  142. opt_inst->removed = true;
  143. }
  144. }
  145. }
  146. static void __team_option_inst_del_port(struct team *team,
  147. struct team_port *port)
  148. {
  149. struct team_option_inst *opt_inst, *tmp;
  150. list_for_each_entry_safe(opt_inst, tmp, &team->option_inst_list, list) {
  151. if (opt_inst->option->per_port &&
  152. opt_inst->port == port)
  153. __team_option_inst_del(opt_inst);
  154. }
  155. }
  156. static int __team_option_inst_add_port(struct team *team,
  157. struct team_port *port)
  158. {
  159. struct team_option *option;
  160. int err;
  161. list_for_each_entry(option, &team->option_list, list) {
  162. if (!option->per_port)
  163. continue;
  164. err = __team_option_inst_add(team, option, port);
  165. if (err)
  166. goto inst_del_port;
  167. }
  168. return 0;
  169. inst_del_port:
  170. __team_option_inst_del_port(team, port);
  171. return err;
  172. }
  173. static void __team_option_inst_mark_removed_port(struct team *team,
  174. struct team_port *port)
  175. {
  176. struct team_option_inst *opt_inst;
  177. list_for_each_entry(opt_inst, &team->option_inst_list, list) {
  178. if (opt_inst->port == port) {
  179. opt_inst->changed = true;
  180. opt_inst->removed = true;
  181. }
  182. }
  183. }
  184. static int __team_options_register(struct team *team,
  185. const struct team_option *option,
  186. size_t option_count)
  187. {
  188. int i;
  189. struct team_option **dst_opts;
  190. int err;
  191. dst_opts = kzalloc(sizeof(struct team_option *) * option_count,
  192. GFP_KERNEL);
  193. if (!dst_opts)
  194. return -ENOMEM;
  195. for (i = 0; i < option_count; i++, option++) {
  196. if (__team_find_option(team, option->name)) {
  197. err = -EEXIST;
  198. goto alloc_rollback;
  199. }
  200. dst_opts[i] = kmemdup(option, sizeof(*option), GFP_KERNEL);
  201. if (!dst_opts[i]) {
  202. err = -ENOMEM;
  203. goto alloc_rollback;
  204. }
  205. }
  206. for (i = 0; i < option_count; i++) {
  207. err = __team_option_inst_add_option(team, dst_opts[i]);
  208. if (err)
  209. goto inst_rollback;
  210. list_add_tail(&dst_opts[i]->list, &team->option_list);
  211. }
  212. kfree(dst_opts);
  213. return 0;
  214. inst_rollback:
  215. for (i--; i >= 0; i--)
  216. __team_option_inst_del_option(team, dst_opts[i]);
  217. i = option_count - 1;
  218. alloc_rollback:
  219. for (i--; i >= 0; i--)
  220. kfree(dst_opts[i]);
  221. kfree(dst_opts);
  222. return err;
  223. }
  224. static void __team_options_mark_removed(struct team *team,
  225. const struct team_option *option,
  226. size_t option_count)
  227. {
  228. int i;
  229. for (i = 0; i < option_count; i++, option++) {
  230. struct team_option *del_opt;
  231. del_opt = __team_find_option(team, option->name);
  232. if (del_opt)
  233. __team_option_inst_mark_removed_option(team, del_opt);
  234. }
  235. }
  236. static void __team_options_unregister(struct team *team,
  237. const struct team_option *option,
  238. size_t option_count)
  239. {
  240. int i;
  241. for (i = 0; i < option_count; i++, option++) {
  242. struct team_option *del_opt;
  243. del_opt = __team_find_option(team, option->name);
  244. if (del_opt) {
  245. __team_option_inst_del_option(team, del_opt);
  246. list_del(&del_opt->list);
  247. kfree(del_opt);
  248. }
  249. }
  250. }
  251. static void __team_options_change_check(struct team *team);
  252. int team_options_register(struct team *team,
  253. const struct team_option *option,
  254. size_t option_count)
  255. {
  256. int err;
  257. err = __team_options_register(team, option, option_count);
  258. if (err)
  259. return err;
  260. __team_options_change_check(team);
  261. return 0;
  262. }
  263. EXPORT_SYMBOL(team_options_register);
  264. void team_options_unregister(struct team *team,
  265. const struct team_option *option,
  266. size_t option_count)
  267. {
  268. __team_options_mark_removed(team, option, option_count);
  269. __team_options_change_check(team);
  270. __team_options_unregister(team, option, option_count);
  271. }
  272. EXPORT_SYMBOL(team_options_unregister);
  273. static int team_option_port_add(struct team *team, struct team_port *port)
  274. {
  275. int err;
  276. err = __team_option_inst_add_port(team, port);
  277. if (err)
  278. return err;
  279. __team_options_change_check(team);
  280. return 0;
  281. }
  282. static void team_option_port_del(struct team *team, struct team_port *port)
  283. {
  284. __team_option_inst_mark_removed_port(team, port);
  285. __team_options_change_check(team);
  286. __team_option_inst_del_port(team, port);
  287. }
  288. static int team_option_get(struct team *team,
  289. struct team_option_inst *opt_inst,
  290. struct team_gsetter_ctx *ctx)
  291. {
  292. return opt_inst->option->getter(team, ctx);
  293. }
  294. static int team_option_set(struct team *team,
  295. struct team_option_inst *opt_inst,
  296. struct team_gsetter_ctx *ctx)
  297. {
  298. int err;
  299. err = opt_inst->option->setter(team, ctx);
  300. if (err)
  301. return err;
  302. opt_inst->changed = true;
  303. __team_options_change_check(team);
  304. return err;
  305. }
  306. /****************
  307. * Mode handling
  308. ****************/
  309. static LIST_HEAD(mode_list);
  310. static DEFINE_SPINLOCK(mode_list_lock);
  311. struct team_mode_item {
  312. struct list_head list;
  313. const struct team_mode *mode;
  314. };
  315. static struct team_mode_item *__find_mode(const char *kind)
  316. {
  317. struct team_mode_item *mitem;
  318. list_for_each_entry(mitem, &mode_list, list) {
  319. if (strcmp(mitem->mode->kind, kind) == 0)
  320. return mitem;
  321. }
  322. return NULL;
  323. }
  324. static bool is_good_mode_name(const char *name)
  325. {
  326. while (*name != '\0') {
  327. if (!isalpha(*name) && !isdigit(*name) && *name != '_')
  328. return false;
  329. name++;
  330. }
  331. return true;
  332. }
  333. int team_mode_register(const struct team_mode *mode)
  334. {
  335. int err = 0;
  336. struct team_mode_item *mitem;
  337. if (!is_good_mode_name(mode->kind) ||
  338. mode->priv_size > TEAM_MODE_PRIV_SIZE)
  339. return -EINVAL;
  340. mitem = kmalloc(sizeof(*mitem), GFP_KERNEL);
  341. if (!mitem)
  342. return -ENOMEM;
  343. spin_lock(&mode_list_lock);
  344. if (__find_mode(mode->kind)) {
  345. err = -EEXIST;
  346. kfree(mitem);
  347. goto unlock;
  348. }
  349. mitem->mode = mode;
  350. list_add_tail(&mitem->list, &mode_list);
  351. unlock:
  352. spin_unlock(&mode_list_lock);
  353. return err;
  354. }
  355. EXPORT_SYMBOL(team_mode_register);
  356. void team_mode_unregister(const struct team_mode *mode)
  357. {
  358. struct team_mode_item *mitem;
  359. spin_lock(&mode_list_lock);
  360. mitem = __find_mode(mode->kind);
  361. if (mitem) {
  362. list_del_init(&mitem->list);
  363. kfree(mitem);
  364. }
  365. spin_unlock(&mode_list_lock);
  366. }
  367. EXPORT_SYMBOL(team_mode_unregister);
  368. static const struct team_mode *team_mode_get(const char *kind)
  369. {
  370. struct team_mode_item *mitem;
  371. const struct team_mode *mode = NULL;
  372. spin_lock(&mode_list_lock);
  373. mitem = __find_mode(kind);
  374. if (!mitem) {
  375. spin_unlock(&mode_list_lock);
  376. request_module("team-mode-%s", kind);
  377. spin_lock(&mode_list_lock);
  378. mitem = __find_mode(kind);
  379. }
  380. if (mitem) {
  381. mode = mitem->mode;
  382. if (!try_module_get(mode->owner))
  383. mode = NULL;
  384. }
  385. spin_unlock(&mode_list_lock);
  386. return mode;
  387. }
  388. static void team_mode_put(const struct team_mode *mode)
  389. {
  390. module_put(mode->owner);
  391. }
  392. static bool team_dummy_transmit(struct team *team, struct sk_buff *skb)
  393. {
  394. dev_kfree_skb_any(skb);
  395. return false;
  396. }
  397. rx_handler_result_t team_dummy_receive(struct team *team,
  398. struct team_port *port,
  399. struct sk_buff *skb)
  400. {
  401. return RX_HANDLER_ANOTHER;
  402. }
  403. static void team_adjust_ops(struct team *team)
  404. {
  405. /*
  406. * To avoid checks in rx/tx skb paths, ensure here that non-null and
  407. * correct ops are always set.
  408. */
  409. if (list_empty(&team->port_list) ||
  410. !team->mode || !team->mode->ops->transmit)
  411. team->ops.transmit = team_dummy_transmit;
  412. else
  413. team->ops.transmit = team->mode->ops->transmit;
  414. if (list_empty(&team->port_list) ||
  415. !team->mode || !team->mode->ops->receive)
  416. team->ops.receive = team_dummy_receive;
  417. else
  418. team->ops.receive = team->mode->ops->receive;
  419. }
  420. /*
  421. * We can benefit from the fact that it's ensured no port is present
  422. * at the time of mode change. Therefore no packets are in fly so there's no
  423. * need to set mode operations in any special way.
  424. */
  425. static int __team_change_mode(struct team *team,
  426. const struct team_mode *new_mode)
  427. {
  428. /* Check if mode was previously set and do cleanup if so */
  429. if (team->mode) {
  430. void (*exit_op)(struct team *team) = team->ops.exit;
  431. /* Clear ops area so no callback is called any longer */
  432. memset(&team->ops, 0, sizeof(struct team_mode_ops));
  433. team_adjust_ops(team);
  434. if (exit_op)
  435. exit_op(team);
  436. team_mode_put(team->mode);
  437. team->mode = NULL;
  438. /* zero private data area */
  439. memset(&team->mode_priv, 0,
  440. sizeof(struct team) - offsetof(struct team, mode_priv));
  441. }
  442. if (!new_mode)
  443. return 0;
  444. if (new_mode->ops->init) {
  445. int err;
  446. err = new_mode->ops->init(team);
  447. if (err)
  448. return err;
  449. }
  450. team->mode = new_mode;
  451. memcpy(&team->ops, new_mode->ops, sizeof(struct team_mode_ops));
  452. team_adjust_ops(team);
  453. return 0;
  454. }
  455. static int team_change_mode(struct team *team, const char *kind)
  456. {
  457. const struct team_mode *new_mode;
  458. struct net_device *dev = team->dev;
  459. int err;
  460. if (!list_empty(&team->port_list)) {
  461. netdev_err(dev, "No ports can be present during mode change\n");
  462. return -EBUSY;
  463. }
  464. if (team->mode && strcmp(team->mode->kind, kind) == 0) {
  465. netdev_err(dev, "Unable to change to the same mode the team is in\n");
  466. return -EINVAL;
  467. }
  468. new_mode = team_mode_get(kind);
  469. if (!new_mode) {
  470. netdev_err(dev, "Mode \"%s\" not found\n", kind);
  471. return -EINVAL;
  472. }
  473. err = __team_change_mode(team, new_mode);
  474. if (err) {
  475. netdev_err(dev, "Failed to change to mode \"%s\"\n", kind);
  476. team_mode_put(new_mode);
  477. return err;
  478. }
  479. netdev_info(dev, "Mode changed to \"%s\"\n", kind);
  480. return 0;
  481. }
  482. /************************
  483. * Rx path frame handler
  484. ************************/
  485. static bool team_port_enabled(struct team_port *port);
  486. /* note: already called with rcu_read_lock */
  487. static rx_handler_result_t team_handle_frame(struct sk_buff **pskb)
  488. {
  489. struct sk_buff *skb = *pskb;
  490. struct team_port *port;
  491. struct team *team;
  492. rx_handler_result_t res;
  493. skb = skb_share_check(skb, GFP_ATOMIC);
  494. if (!skb)
  495. return RX_HANDLER_CONSUMED;
  496. *pskb = skb;
  497. port = team_port_get_rcu(skb->dev);
  498. team = port->team;
  499. if (!team_port_enabled(port)) {
  500. /* allow exact match delivery for disabled ports */
  501. res = RX_HANDLER_EXACT;
  502. } else {
  503. res = team->ops.receive(team, port, skb);
  504. }
  505. if (res == RX_HANDLER_ANOTHER) {
  506. struct team_pcpu_stats *pcpu_stats;
  507. pcpu_stats = this_cpu_ptr(team->pcpu_stats);
  508. u64_stats_update_begin(&pcpu_stats->syncp);
  509. pcpu_stats->rx_packets++;
  510. pcpu_stats->rx_bytes += skb->len;
  511. if (skb->pkt_type == PACKET_MULTICAST)
  512. pcpu_stats->rx_multicast++;
  513. u64_stats_update_end(&pcpu_stats->syncp);
  514. skb->dev = team->dev;
  515. } else {
  516. this_cpu_inc(team->pcpu_stats->rx_dropped);
  517. }
  518. return res;
  519. }
  520. /****************
  521. * Port handling
  522. ****************/
  523. static bool team_port_find(const struct team *team,
  524. const struct team_port *port)
  525. {
  526. struct team_port *cur;
  527. list_for_each_entry(cur, &team->port_list, list)
  528. if (cur == port)
  529. return true;
  530. return false;
  531. }
  532. static bool team_port_enabled(struct team_port *port)
  533. {
  534. return port->index != -1;
  535. }
  536. /*
  537. * Enable/disable port by adding to enabled port hashlist and setting
  538. * port->index (Might be racy so reader could see incorrect ifindex when
  539. * processing a flying packet, but that is not a problem). Write guarded
  540. * by team->lock.
  541. */
  542. static void team_port_enable(struct team *team,
  543. struct team_port *port)
  544. {
  545. if (team_port_enabled(port))
  546. return;
  547. port->index = team->en_port_count++;
  548. hlist_add_head_rcu(&port->hlist,
  549. team_port_index_hash(team, port->index));
  550. }
  551. static void __reconstruct_port_hlist(struct team *team, int rm_index)
  552. {
  553. int i;
  554. struct team_port *port;
  555. for (i = rm_index + 1; i < team->en_port_count; i++) {
  556. port = team_get_port_by_index(team, i);
  557. hlist_del_rcu(&port->hlist);
  558. port->index--;
  559. hlist_add_head_rcu(&port->hlist,
  560. team_port_index_hash(team, port->index));
  561. }
  562. }
  563. static void team_port_disable(struct team *team,
  564. struct team_port *port)
  565. {
  566. int rm_index = port->index;
  567. if (!team_port_enabled(port))
  568. return;
  569. hlist_del_rcu(&port->hlist);
  570. __reconstruct_port_hlist(team, rm_index);
  571. team->en_port_count--;
  572. port->index = -1;
  573. }
  574. #define TEAM_VLAN_FEATURES (NETIF_F_ALL_CSUM | NETIF_F_SG | \
  575. NETIF_F_FRAGLIST | NETIF_F_ALL_TSO | \
  576. NETIF_F_HIGHDMA | NETIF_F_LRO)
  577. static void __team_compute_features(struct team *team)
  578. {
  579. struct team_port *port;
  580. u32 vlan_features = TEAM_VLAN_FEATURES;
  581. unsigned short max_hard_header_len = ETH_HLEN;
  582. list_for_each_entry(port, &team->port_list, list) {
  583. vlan_features = netdev_increment_features(vlan_features,
  584. port->dev->vlan_features,
  585. TEAM_VLAN_FEATURES);
  586. if (port->dev->hard_header_len > max_hard_header_len)
  587. max_hard_header_len = port->dev->hard_header_len;
  588. }
  589. team->dev->vlan_features = vlan_features;
  590. team->dev->hard_header_len = max_hard_header_len;
  591. netdev_change_features(team->dev);
  592. }
  593. static void team_compute_features(struct team *team)
  594. {
  595. mutex_lock(&team->lock);
  596. __team_compute_features(team);
  597. mutex_unlock(&team->lock);
  598. }
  599. static int team_port_enter(struct team *team, struct team_port *port)
  600. {
  601. int err = 0;
  602. dev_hold(team->dev);
  603. port->dev->priv_flags |= IFF_TEAM_PORT;
  604. if (team->ops.port_enter) {
  605. err = team->ops.port_enter(team, port);
  606. if (err) {
  607. netdev_err(team->dev, "Device %s failed to enter team mode\n",
  608. port->dev->name);
  609. goto err_port_enter;
  610. }
  611. }
  612. return 0;
  613. err_port_enter:
  614. port->dev->priv_flags &= ~IFF_TEAM_PORT;
  615. dev_put(team->dev);
  616. return err;
  617. }
  618. static void team_port_leave(struct team *team, struct team_port *port)
  619. {
  620. if (team->ops.port_leave)
  621. team->ops.port_leave(team, port);
  622. port->dev->priv_flags &= ~IFF_TEAM_PORT;
  623. dev_put(team->dev);
  624. }
  625. static void __team_port_change_check(struct team_port *port, bool linkup);
  626. static int team_port_add(struct team *team, struct net_device *port_dev)
  627. {
  628. struct net_device *dev = team->dev;
  629. struct team_port *port;
  630. char *portname = port_dev->name;
  631. int err;
  632. if (port_dev->flags & IFF_LOOPBACK ||
  633. port_dev->type != ARPHRD_ETHER) {
  634. netdev_err(dev, "Device %s is of an unsupported type\n",
  635. portname);
  636. return -EINVAL;
  637. }
  638. if (team_port_exists(port_dev)) {
  639. netdev_err(dev, "Device %s is already a port "
  640. "of a team device\n", portname);
  641. return -EBUSY;
  642. }
  643. if (port_dev->flags & IFF_UP) {
  644. netdev_err(dev, "Device %s is up. Set it down before adding it as a team port\n",
  645. portname);
  646. return -EBUSY;
  647. }
  648. port = kzalloc(sizeof(struct team_port), GFP_KERNEL);
  649. if (!port)
  650. return -ENOMEM;
  651. port->dev = port_dev;
  652. port->team = team;
  653. port->orig.mtu = port_dev->mtu;
  654. err = dev_set_mtu(port_dev, dev->mtu);
  655. if (err) {
  656. netdev_dbg(dev, "Error %d calling dev_set_mtu\n", err);
  657. goto err_set_mtu;
  658. }
  659. memcpy(port->orig.dev_addr, port_dev->dev_addr, ETH_ALEN);
  660. err = team_port_enter(team, port);
  661. if (err) {
  662. netdev_err(dev, "Device %s failed to enter team mode\n",
  663. portname);
  664. goto err_port_enter;
  665. }
  666. err = dev_open(port_dev);
  667. if (err) {
  668. netdev_dbg(dev, "Device %s opening failed\n",
  669. portname);
  670. goto err_dev_open;
  671. }
  672. err = vlan_vids_add_by_dev(port_dev, dev);
  673. if (err) {
  674. netdev_err(dev, "Failed to add vlan ids to device %s\n",
  675. portname);
  676. goto err_vids_add;
  677. }
  678. err = netdev_set_master(port_dev, dev);
  679. if (err) {
  680. netdev_err(dev, "Device %s failed to set master\n", portname);
  681. goto err_set_master;
  682. }
  683. err = netdev_rx_handler_register(port_dev, team_handle_frame,
  684. port);
  685. if (err) {
  686. netdev_err(dev, "Device %s failed to register rx_handler\n",
  687. portname);
  688. goto err_handler_register;
  689. }
  690. err = team_option_port_add(team, port);
  691. if (err) {
  692. netdev_err(dev, "Device %s failed to add per-port options\n",
  693. portname);
  694. goto err_option_port_add;
  695. }
  696. port->index = -1;
  697. team_port_enable(team, port);
  698. list_add_tail_rcu(&port->list, &team->port_list);
  699. team_adjust_ops(team);
  700. __team_compute_features(team);
  701. __team_port_change_check(port, !!netif_carrier_ok(port_dev));
  702. netdev_info(dev, "Port device %s added\n", portname);
  703. return 0;
  704. err_option_port_add:
  705. netdev_rx_handler_unregister(port_dev);
  706. err_handler_register:
  707. netdev_set_master(port_dev, NULL);
  708. err_set_master:
  709. vlan_vids_del_by_dev(port_dev, dev);
  710. err_vids_add:
  711. dev_close(port_dev);
  712. err_dev_open:
  713. team_port_leave(team, port);
  714. team_port_set_orig_mac(port);
  715. err_port_enter:
  716. dev_set_mtu(port_dev, port->orig.mtu);
  717. err_set_mtu:
  718. kfree(port);
  719. return err;
  720. }
  721. static int team_port_del(struct team *team, struct net_device *port_dev)
  722. {
  723. struct net_device *dev = team->dev;
  724. struct team_port *port;
  725. char *portname = port_dev->name;
  726. port = team_port_get_rtnl(port_dev);
  727. if (!port || !team_port_find(team, port)) {
  728. netdev_err(dev, "Device %s does not act as a port of this team\n",
  729. portname);
  730. return -ENOENT;
  731. }
  732. port->removed = true;
  733. __team_port_change_check(port, false);
  734. team_port_disable(team, port);
  735. list_del_rcu(&port->list);
  736. team_adjust_ops(team);
  737. team_option_port_del(team, port);
  738. netdev_rx_handler_unregister(port_dev);
  739. netdev_set_master(port_dev, NULL);
  740. vlan_vids_del_by_dev(port_dev, dev);
  741. dev_close(port_dev);
  742. team_port_leave(team, port);
  743. team_port_set_orig_mac(port);
  744. dev_set_mtu(port_dev, port->orig.mtu);
  745. synchronize_rcu();
  746. kfree(port);
  747. netdev_info(dev, "Port device %s removed\n", portname);
  748. __team_compute_features(team);
  749. return 0;
  750. }
  751. /*****************
  752. * Net device ops
  753. *****************/
  754. static const char team_no_mode_kind[] = "*NOMODE*";
  755. static int team_mode_option_get(struct team *team, struct team_gsetter_ctx *ctx)
  756. {
  757. ctx->data.str_val = team->mode ? team->mode->kind : team_no_mode_kind;
  758. return 0;
  759. }
  760. static int team_mode_option_set(struct team *team, struct team_gsetter_ctx *ctx)
  761. {
  762. return team_change_mode(team, ctx->data.str_val);
  763. }
  764. static int team_port_en_option_get(struct team *team,
  765. struct team_gsetter_ctx *ctx)
  766. {
  767. ctx->data.bool_val = team_port_enabled(ctx->port);
  768. return 0;
  769. }
  770. static int team_port_en_option_set(struct team *team,
  771. struct team_gsetter_ctx *ctx)
  772. {
  773. if (ctx->data.bool_val)
  774. team_port_enable(team, ctx->port);
  775. else
  776. team_port_disable(team, ctx->port);
  777. return 0;
  778. }
  779. static int team_user_linkup_option_get(struct team *team,
  780. struct team_gsetter_ctx *ctx)
  781. {
  782. ctx->data.bool_val = ctx->port->user.linkup;
  783. return 0;
  784. }
  785. static int team_user_linkup_option_set(struct team *team,
  786. struct team_gsetter_ctx *ctx)
  787. {
  788. ctx->port->user.linkup = ctx->data.bool_val;
  789. team_refresh_port_linkup(ctx->port);
  790. return 0;
  791. }
  792. static int team_user_linkup_en_option_get(struct team *team,
  793. struct team_gsetter_ctx *ctx)
  794. {
  795. struct team_port *port = ctx->port;
  796. ctx->data.bool_val = port->user.linkup_enabled;
  797. return 0;
  798. }
  799. static int team_user_linkup_en_option_set(struct team *team,
  800. struct team_gsetter_ctx *ctx)
  801. {
  802. struct team_port *port = ctx->port;
  803. port->user.linkup_enabled = ctx->data.bool_val;
  804. team_refresh_port_linkup(ctx->port);
  805. return 0;
  806. }
  807. static const struct team_option team_options[] = {
  808. {
  809. .name = "mode",
  810. .type = TEAM_OPTION_TYPE_STRING,
  811. .getter = team_mode_option_get,
  812. .setter = team_mode_option_set,
  813. },
  814. {
  815. .name = "enabled",
  816. .type = TEAM_OPTION_TYPE_BOOL,
  817. .per_port = true,
  818. .getter = team_port_en_option_get,
  819. .setter = team_port_en_option_set,
  820. },
  821. {
  822. .name = "user_linkup",
  823. .type = TEAM_OPTION_TYPE_BOOL,
  824. .per_port = true,
  825. .getter = team_user_linkup_option_get,
  826. .setter = team_user_linkup_option_set,
  827. },
  828. {
  829. .name = "user_linkup_enabled",
  830. .type = TEAM_OPTION_TYPE_BOOL,
  831. .per_port = true,
  832. .getter = team_user_linkup_en_option_get,
  833. .setter = team_user_linkup_en_option_set,
  834. },
  835. };
  836. static int team_init(struct net_device *dev)
  837. {
  838. struct team *team = netdev_priv(dev);
  839. int i;
  840. int err;
  841. team->dev = dev;
  842. mutex_init(&team->lock);
  843. team->pcpu_stats = alloc_percpu(struct team_pcpu_stats);
  844. if (!team->pcpu_stats)
  845. return -ENOMEM;
  846. for (i = 0; i < TEAM_PORT_HASHENTRIES; i++)
  847. INIT_HLIST_HEAD(&team->en_port_hlist[i]);
  848. INIT_LIST_HEAD(&team->port_list);
  849. team_adjust_ops(team);
  850. INIT_LIST_HEAD(&team->option_list);
  851. INIT_LIST_HEAD(&team->option_inst_list);
  852. err = team_options_register(team, team_options, ARRAY_SIZE(team_options));
  853. if (err)
  854. goto err_options_register;
  855. netif_carrier_off(dev);
  856. return 0;
  857. err_options_register:
  858. free_percpu(team->pcpu_stats);
  859. return err;
  860. }
  861. static void team_uninit(struct net_device *dev)
  862. {
  863. struct team *team = netdev_priv(dev);
  864. struct team_port *port;
  865. struct team_port *tmp;
  866. mutex_lock(&team->lock);
  867. list_for_each_entry_safe(port, tmp, &team->port_list, list)
  868. team_port_del(team, port->dev);
  869. __team_change_mode(team, NULL); /* cleanup */
  870. __team_options_unregister(team, team_options, ARRAY_SIZE(team_options));
  871. mutex_unlock(&team->lock);
  872. }
  873. static void team_destructor(struct net_device *dev)
  874. {
  875. struct team *team = netdev_priv(dev);
  876. free_percpu(team->pcpu_stats);
  877. free_netdev(dev);
  878. }
  879. static int team_open(struct net_device *dev)
  880. {
  881. netif_carrier_on(dev);
  882. return 0;
  883. }
  884. static int team_close(struct net_device *dev)
  885. {
  886. netif_carrier_off(dev);
  887. return 0;
  888. }
  889. /*
  890. * note: already called with rcu_read_lock
  891. */
  892. static netdev_tx_t team_xmit(struct sk_buff *skb, struct net_device *dev)
  893. {
  894. struct team *team = netdev_priv(dev);
  895. bool tx_success = false;
  896. unsigned int len = skb->len;
  897. tx_success = team->ops.transmit(team, skb);
  898. if (tx_success) {
  899. struct team_pcpu_stats *pcpu_stats;
  900. pcpu_stats = this_cpu_ptr(team->pcpu_stats);
  901. u64_stats_update_begin(&pcpu_stats->syncp);
  902. pcpu_stats->tx_packets++;
  903. pcpu_stats->tx_bytes += len;
  904. u64_stats_update_end(&pcpu_stats->syncp);
  905. } else {
  906. this_cpu_inc(team->pcpu_stats->tx_dropped);
  907. }
  908. return NETDEV_TX_OK;
  909. }
  910. static void team_change_rx_flags(struct net_device *dev, int change)
  911. {
  912. struct team *team = netdev_priv(dev);
  913. struct team_port *port;
  914. int inc;
  915. rcu_read_lock();
  916. list_for_each_entry_rcu(port, &team->port_list, list) {
  917. if (change & IFF_PROMISC) {
  918. inc = dev->flags & IFF_PROMISC ? 1 : -1;
  919. dev_set_promiscuity(port->dev, inc);
  920. }
  921. if (change & IFF_ALLMULTI) {
  922. inc = dev->flags & IFF_ALLMULTI ? 1 : -1;
  923. dev_set_allmulti(port->dev, inc);
  924. }
  925. }
  926. rcu_read_unlock();
  927. }
  928. static void team_set_rx_mode(struct net_device *dev)
  929. {
  930. struct team *team = netdev_priv(dev);
  931. struct team_port *port;
  932. rcu_read_lock();
  933. list_for_each_entry_rcu(port, &team->port_list, list) {
  934. dev_uc_sync(port->dev, dev);
  935. dev_mc_sync(port->dev, dev);
  936. }
  937. rcu_read_unlock();
  938. }
  939. static int team_set_mac_address(struct net_device *dev, void *p)
  940. {
  941. struct team *team = netdev_priv(dev);
  942. struct team_port *port;
  943. struct sockaddr *addr = p;
  944. dev->addr_assign_type &= ~NET_ADDR_RANDOM;
  945. memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
  946. rcu_read_lock();
  947. list_for_each_entry_rcu(port, &team->port_list, list)
  948. if (team->ops.port_change_mac)
  949. team->ops.port_change_mac(team, port);
  950. rcu_read_unlock();
  951. return 0;
  952. }
  953. static int team_change_mtu(struct net_device *dev, int new_mtu)
  954. {
  955. struct team *team = netdev_priv(dev);
  956. struct team_port *port;
  957. int err;
  958. /*
  959. * Alhough this is reader, it's guarded by team lock. It's not possible
  960. * to traverse list in reverse under rcu_read_lock
  961. */
  962. mutex_lock(&team->lock);
  963. list_for_each_entry(port, &team->port_list, list) {
  964. err = dev_set_mtu(port->dev, new_mtu);
  965. if (err) {
  966. netdev_err(dev, "Device %s failed to change mtu",
  967. port->dev->name);
  968. goto unwind;
  969. }
  970. }
  971. mutex_unlock(&team->lock);
  972. dev->mtu = new_mtu;
  973. return 0;
  974. unwind:
  975. list_for_each_entry_continue_reverse(port, &team->port_list, list)
  976. dev_set_mtu(port->dev, dev->mtu);
  977. mutex_unlock(&team->lock);
  978. return err;
  979. }
  980. static struct rtnl_link_stats64 *
  981. team_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
  982. {
  983. struct team *team = netdev_priv(dev);
  984. struct team_pcpu_stats *p;
  985. u64 rx_packets, rx_bytes, rx_multicast, tx_packets, tx_bytes;
  986. u32 rx_dropped = 0, tx_dropped = 0;
  987. unsigned int start;
  988. int i;
  989. for_each_possible_cpu(i) {
  990. p = per_cpu_ptr(team->pcpu_stats, i);
  991. do {
  992. start = u64_stats_fetch_begin_bh(&p->syncp);
  993. rx_packets = p->rx_packets;
  994. rx_bytes = p->rx_bytes;
  995. rx_multicast = p->rx_multicast;
  996. tx_packets = p->tx_packets;
  997. tx_bytes = p->tx_bytes;
  998. } while (u64_stats_fetch_retry_bh(&p->syncp, start));
  999. stats->rx_packets += rx_packets;
  1000. stats->rx_bytes += rx_bytes;
  1001. stats->multicast += rx_multicast;
  1002. stats->tx_packets += tx_packets;
  1003. stats->tx_bytes += tx_bytes;
  1004. /*
  1005. * rx_dropped & tx_dropped are u32, updated
  1006. * without syncp protection.
  1007. */
  1008. rx_dropped += p->rx_dropped;
  1009. tx_dropped += p->tx_dropped;
  1010. }
  1011. stats->rx_dropped = rx_dropped;
  1012. stats->tx_dropped = tx_dropped;
  1013. return stats;
  1014. }
  1015. static int team_vlan_rx_add_vid(struct net_device *dev, uint16_t vid)
  1016. {
  1017. struct team *team = netdev_priv(dev);
  1018. struct team_port *port;
  1019. int err;
  1020. /*
  1021. * Alhough this is reader, it's guarded by team lock. It's not possible
  1022. * to traverse list in reverse under rcu_read_lock
  1023. */
  1024. mutex_lock(&team->lock);
  1025. list_for_each_entry(port, &team->port_list, list) {
  1026. err = vlan_vid_add(port->dev, vid);
  1027. if (err)
  1028. goto unwind;
  1029. }
  1030. mutex_unlock(&team->lock);
  1031. return 0;
  1032. unwind:
  1033. list_for_each_entry_continue_reverse(port, &team->port_list, list)
  1034. vlan_vid_del(port->dev, vid);
  1035. mutex_unlock(&team->lock);
  1036. return err;
  1037. }
  1038. static int team_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
  1039. {
  1040. struct team *team = netdev_priv(dev);
  1041. struct team_port *port;
  1042. rcu_read_lock();
  1043. list_for_each_entry_rcu(port, &team->port_list, list)
  1044. vlan_vid_del(port->dev, vid);
  1045. rcu_read_unlock();
  1046. return 0;
  1047. }
  1048. static int team_add_slave(struct net_device *dev, struct net_device *port_dev)
  1049. {
  1050. struct team *team = netdev_priv(dev);
  1051. int err;
  1052. mutex_lock(&team->lock);
  1053. err = team_port_add(team, port_dev);
  1054. mutex_unlock(&team->lock);
  1055. return err;
  1056. }
  1057. static int team_del_slave(struct net_device *dev, struct net_device *port_dev)
  1058. {
  1059. struct team *team = netdev_priv(dev);
  1060. int err;
  1061. mutex_lock(&team->lock);
  1062. err = team_port_del(team, port_dev);
  1063. mutex_unlock(&team->lock);
  1064. return err;
  1065. }
  1066. static netdev_features_t team_fix_features(struct net_device *dev,
  1067. netdev_features_t features)
  1068. {
  1069. struct team_port *port;
  1070. struct team *team = netdev_priv(dev);
  1071. netdev_features_t mask;
  1072. mask = features;
  1073. features &= ~NETIF_F_ONE_FOR_ALL;
  1074. features |= NETIF_F_ALL_FOR_ALL;
  1075. rcu_read_lock();
  1076. list_for_each_entry_rcu(port, &team->port_list, list) {
  1077. features = netdev_increment_features(features,
  1078. port->dev->features,
  1079. mask);
  1080. }
  1081. rcu_read_unlock();
  1082. return features;
  1083. }
  1084. static const struct net_device_ops team_netdev_ops = {
  1085. .ndo_init = team_init,
  1086. .ndo_uninit = team_uninit,
  1087. .ndo_open = team_open,
  1088. .ndo_stop = team_close,
  1089. .ndo_start_xmit = team_xmit,
  1090. .ndo_change_rx_flags = team_change_rx_flags,
  1091. .ndo_set_rx_mode = team_set_rx_mode,
  1092. .ndo_set_mac_address = team_set_mac_address,
  1093. .ndo_change_mtu = team_change_mtu,
  1094. .ndo_get_stats64 = team_get_stats64,
  1095. .ndo_vlan_rx_add_vid = team_vlan_rx_add_vid,
  1096. .ndo_vlan_rx_kill_vid = team_vlan_rx_kill_vid,
  1097. .ndo_add_slave = team_add_slave,
  1098. .ndo_del_slave = team_del_slave,
  1099. .ndo_fix_features = team_fix_features,
  1100. };
  1101. /***********************
  1102. * rt netlink interface
  1103. ***********************/
  1104. static void team_setup(struct net_device *dev)
  1105. {
  1106. ether_setup(dev);
  1107. dev->netdev_ops = &team_netdev_ops;
  1108. dev->destructor = team_destructor;
  1109. dev->tx_queue_len = 0;
  1110. dev->flags |= IFF_MULTICAST;
  1111. dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING);
  1112. /*
  1113. * Indicate we support unicast address filtering. That way core won't
  1114. * bring us to promisc mode in case a unicast addr is added.
  1115. * Let this up to underlay drivers.
  1116. */
  1117. dev->priv_flags |= IFF_UNICAST_FLT;
  1118. dev->features |= NETIF_F_LLTX;
  1119. dev->features |= NETIF_F_GRO;
  1120. dev->hw_features = NETIF_F_HW_VLAN_TX |
  1121. NETIF_F_HW_VLAN_RX |
  1122. NETIF_F_HW_VLAN_FILTER;
  1123. dev->features |= dev->hw_features;
  1124. }
  1125. static int team_newlink(struct net *src_net, struct net_device *dev,
  1126. struct nlattr *tb[], struct nlattr *data[])
  1127. {
  1128. int err;
  1129. if (tb[IFLA_ADDRESS] == NULL)
  1130. eth_hw_addr_random(dev);
  1131. err = register_netdevice(dev);
  1132. if (err)
  1133. return err;
  1134. return 0;
  1135. }
  1136. static int team_validate(struct nlattr *tb[], struct nlattr *data[])
  1137. {
  1138. if (tb[IFLA_ADDRESS]) {
  1139. if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
  1140. return -EINVAL;
  1141. if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
  1142. return -EADDRNOTAVAIL;
  1143. }
  1144. return 0;
  1145. }
  1146. static struct rtnl_link_ops team_link_ops __read_mostly = {
  1147. .kind = DRV_NAME,
  1148. .priv_size = sizeof(struct team),
  1149. .setup = team_setup,
  1150. .newlink = team_newlink,
  1151. .validate = team_validate,
  1152. };
  1153. /***********************************
  1154. * Generic netlink custom interface
  1155. ***********************************/
  1156. static struct genl_family team_nl_family = {
  1157. .id = GENL_ID_GENERATE,
  1158. .name = TEAM_GENL_NAME,
  1159. .version = TEAM_GENL_VERSION,
  1160. .maxattr = TEAM_ATTR_MAX,
  1161. .netnsok = true,
  1162. };
  1163. static const struct nla_policy team_nl_policy[TEAM_ATTR_MAX + 1] = {
  1164. [TEAM_ATTR_UNSPEC] = { .type = NLA_UNSPEC, },
  1165. [TEAM_ATTR_TEAM_IFINDEX] = { .type = NLA_U32 },
  1166. [TEAM_ATTR_LIST_OPTION] = { .type = NLA_NESTED },
  1167. [TEAM_ATTR_LIST_PORT] = { .type = NLA_NESTED },
  1168. };
  1169. static const struct nla_policy
  1170. team_nl_option_policy[TEAM_ATTR_OPTION_MAX + 1] = {
  1171. [TEAM_ATTR_OPTION_UNSPEC] = { .type = NLA_UNSPEC, },
  1172. [TEAM_ATTR_OPTION_NAME] = {
  1173. .type = NLA_STRING,
  1174. .len = TEAM_STRING_MAX_LEN,
  1175. },
  1176. [TEAM_ATTR_OPTION_CHANGED] = { .type = NLA_FLAG },
  1177. [TEAM_ATTR_OPTION_TYPE] = { .type = NLA_U8 },
  1178. [TEAM_ATTR_OPTION_DATA] = { .type = NLA_BINARY },
  1179. };
  1180. static int team_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info)
  1181. {
  1182. struct sk_buff *msg;
  1183. void *hdr;
  1184. int err;
  1185. msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  1186. if (!msg)
  1187. return -ENOMEM;
  1188. hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
  1189. &team_nl_family, 0, TEAM_CMD_NOOP);
  1190. if (IS_ERR(hdr)) {
  1191. err = PTR_ERR(hdr);
  1192. goto err_msg_put;
  1193. }
  1194. genlmsg_end(msg, hdr);
  1195. return genlmsg_unicast(genl_info_net(info), msg, info->snd_pid);
  1196. err_msg_put:
  1197. nlmsg_free(msg);
  1198. return err;
  1199. }
  1200. /*
  1201. * Netlink cmd functions should be locked by following two functions.
  1202. * Since dev gets held here, that ensures dev won't disappear in between.
  1203. */
  1204. static struct team *team_nl_team_get(struct genl_info *info)
  1205. {
  1206. struct net *net = genl_info_net(info);
  1207. int ifindex;
  1208. struct net_device *dev;
  1209. struct team *team;
  1210. if (!info->attrs[TEAM_ATTR_TEAM_IFINDEX])
  1211. return NULL;
  1212. ifindex = nla_get_u32(info->attrs[TEAM_ATTR_TEAM_IFINDEX]);
  1213. dev = dev_get_by_index(net, ifindex);
  1214. if (!dev || dev->netdev_ops != &team_netdev_ops) {
  1215. if (dev)
  1216. dev_put(dev);
  1217. return NULL;
  1218. }
  1219. team = netdev_priv(dev);
  1220. mutex_lock(&team->lock);
  1221. return team;
  1222. }
  1223. static void team_nl_team_put(struct team *team)
  1224. {
  1225. mutex_unlock(&team->lock);
  1226. dev_put(team->dev);
  1227. }
  1228. static int team_nl_send_generic(struct genl_info *info, struct team *team,
  1229. int (*fill_func)(struct sk_buff *skb,
  1230. struct genl_info *info,
  1231. int flags, struct team *team))
  1232. {
  1233. struct sk_buff *skb;
  1234. int err;
  1235. skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  1236. if (!skb)
  1237. return -ENOMEM;
  1238. err = fill_func(skb, info, NLM_F_ACK, team);
  1239. if (err < 0)
  1240. goto err_fill;
  1241. err = genlmsg_unicast(genl_info_net(info), skb, info->snd_pid);
  1242. return err;
  1243. err_fill:
  1244. nlmsg_free(skb);
  1245. return err;
  1246. }
  1247. static int team_nl_fill_options_get(struct sk_buff *skb,
  1248. u32 pid, u32 seq, int flags,
  1249. struct team *team, bool fillall)
  1250. {
  1251. struct nlattr *option_list;
  1252. void *hdr;
  1253. struct team_option_inst *opt_inst;
  1254. int err;
  1255. hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags,
  1256. TEAM_CMD_OPTIONS_GET);
  1257. if (IS_ERR(hdr))
  1258. return PTR_ERR(hdr);
  1259. if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
  1260. goto nla_put_failure;
  1261. option_list = nla_nest_start(skb, TEAM_ATTR_LIST_OPTION);
  1262. if (!option_list)
  1263. return -EMSGSIZE;
  1264. list_for_each_entry(opt_inst, &team->option_inst_list, list) {
  1265. struct nlattr *option_item;
  1266. struct team_option *option = opt_inst->option;
  1267. struct team_gsetter_ctx ctx;
  1268. /* Include only changed options if fill all mode is not on */
  1269. if (!fillall && !opt_inst->changed)
  1270. continue;
  1271. option_item = nla_nest_start(skb, TEAM_ATTR_ITEM_OPTION);
  1272. if (!option_item)
  1273. goto nla_put_failure;
  1274. if (nla_put_string(skb, TEAM_ATTR_OPTION_NAME, option->name))
  1275. goto nla_put_failure;
  1276. if (opt_inst->changed) {
  1277. if (nla_put_flag(skb, TEAM_ATTR_OPTION_CHANGED))
  1278. goto nla_put_failure;
  1279. opt_inst->changed = false;
  1280. }
  1281. if (opt_inst->removed &&
  1282. nla_put_flag(skb, TEAM_ATTR_OPTION_REMOVED))
  1283. goto nla_put_failure;
  1284. if (opt_inst->port &&
  1285. nla_put_u32(skb, TEAM_ATTR_OPTION_PORT_IFINDEX,
  1286. opt_inst->port->dev->ifindex))
  1287. goto nla_put_failure;
  1288. ctx.port = opt_inst->port;
  1289. switch (option->type) {
  1290. case TEAM_OPTION_TYPE_U32:
  1291. if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_U32))
  1292. goto nla_put_failure;
  1293. err = team_option_get(team, opt_inst, &ctx);
  1294. if (err)
  1295. goto errout;
  1296. if (nla_put_u32(skb, TEAM_ATTR_OPTION_DATA,
  1297. ctx.data.u32_val))
  1298. goto nla_put_failure;
  1299. break;
  1300. case TEAM_OPTION_TYPE_STRING:
  1301. if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_STRING))
  1302. goto nla_put_failure;
  1303. err = team_option_get(team, opt_inst, &ctx);
  1304. if (err)
  1305. goto errout;
  1306. if (nla_put_string(skb, TEAM_ATTR_OPTION_DATA,
  1307. ctx.data.str_val))
  1308. goto nla_put_failure;
  1309. break;
  1310. case TEAM_OPTION_TYPE_BINARY:
  1311. if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_BINARY))
  1312. goto nla_put_failure;
  1313. err = team_option_get(team, opt_inst, &ctx);
  1314. if (err)
  1315. goto errout;
  1316. if (nla_put(skb, TEAM_ATTR_OPTION_DATA,
  1317. ctx.data.bin_val.len, ctx.data.bin_val.ptr))
  1318. goto nla_put_failure;
  1319. break;
  1320. case TEAM_OPTION_TYPE_BOOL:
  1321. if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_FLAG))
  1322. goto nla_put_failure;
  1323. err = team_option_get(team, opt_inst, &ctx);
  1324. if (err)
  1325. goto errout;
  1326. if (ctx.data.bool_val &&
  1327. nla_put_flag(skb, TEAM_ATTR_OPTION_DATA))
  1328. goto nla_put_failure;
  1329. break;
  1330. default:
  1331. BUG();
  1332. }
  1333. nla_nest_end(skb, option_item);
  1334. }
  1335. nla_nest_end(skb, option_list);
  1336. return genlmsg_end(skb, hdr);
  1337. nla_put_failure:
  1338. err = -EMSGSIZE;
  1339. errout:
  1340. genlmsg_cancel(skb, hdr);
  1341. return err;
  1342. }
  1343. static int team_nl_fill_options_get_all(struct sk_buff *skb,
  1344. struct genl_info *info, int flags,
  1345. struct team *team)
  1346. {
  1347. return team_nl_fill_options_get(skb, info->snd_pid,
  1348. info->snd_seq, NLM_F_ACK,
  1349. team, true);
  1350. }
  1351. static int team_nl_cmd_options_get(struct sk_buff *skb, struct genl_info *info)
  1352. {
  1353. struct team *team;
  1354. int err;
  1355. team = team_nl_team_get(info);
  1356. if (!team)
  1357. return -EINVAL;
  1358. err = team_nl_send_generic(info, team, team_nl_fill_options_get_all);
  1359. team_nl_team_put(team);
  1360. return err;
  1361. }
  1362. static int team_nl_cmd_options_set(struct sk_buff *skb, struct genl_info *info)
  1363. {
  1364. struct team *team;
  1365. int err = 0;
  1366. int i;
  1367. struct nlattr *nl_option;
  1368. team = team_nl_team_get(info);
  1369. if (!team)
  1370. return -EINVAL;
  1371. err = -EINVAL;
  1372. if (!info->attrs[TEAM_ATTR_LIST_OPTION]) {
  1373. err = -EINVAL;
  1374. goto team_put;
  1375. }
  1376. nla_for_each_nested(nl_option, info->attrs[TEAM_ATTR_LIST_OPTION], i) {
  1377. struct nlattr *opt_attrs[TEAM_ATTR_OPTION_MAX + 1];
  1378. struct nlattr *attr_port_ifindex;
  1379. struct nlattr *attr_data;
  1380. enum team_option_type opt_type;
  1381. int opt_port_ifindex = 0; /* != 0 for per-port options */
  1382. struct team_option_inst *opt_inst;
  1383. char *opt_name;
  1384. bool opt_found = false;
  1385. if (nla_type(nl_option) != TEAM_ATTR_ITEM_OPTION) {
  1386. err = -EINVAL;
  1387. goto team_put;
  1388. }
  1389. err = nla_parse_nested(opt_attrs, TEAM_ATTR_OPTION_MAX,
  1390. nl_option, team_nl_option_policy);
  1391. if (err)
  1392. goto team_put;
  1393. if (!opt_attrs[TEAM_ATTR_OPTION_NAME] ||
  1394. !opt_attrs[TEAM_ATTR_OPTION_TYPE]) {
  1395. err = -EINVAL;
  1396. goto team_put;
  1397. }
  1398. switch (nla_get_u8(opt_attrs[TEAM_ATTR_OPTION_TYPE])) {
  1399. case NLA_U32:
  1400. opt_type = TEAM_OPTION_TYPE_U32;
  1401. break;
  1402. case NLA_STRING:
  1403. opt_type = TEAM_OPTION_TYPE_STRING;
  1404. break;
  1405. case NLA_BINARY:
  1406. opt_type = TEAM_OPTION_TYPE_BINARY;
  1407. break;
  1408. case NLA_FLAG:
  1409. opt_type = TEAM_OPTION_TYPE_BOOL;
  1410. break;
  1411. default:
  1412. goto team_put;
  1413. }
  1414. attr_data = opt_attrs[TEAM_ATTR_OPTION_DATA];
  1415. if (opt_type != TEAM_OPTION_TYPE_BOOL && !attr_data) {
  1416. err = -EINVAL;
  1417. goto team_put;
  1418. }
  1419. opt_name = nla_data(opt_attrs[TEAM_ATTR_OPTION_NAME]);
  1420. attr_port_ifindex = opt_attrs[TEAM_ATTR_OPTION_PORT_IFINDEX];
  1421. if (attr_port_ifindex)
  1422. opt_port_ifindex = nla_get_u32(attr_port_ifindex);
  1423. list_for_each_entry(opt_inst, &team->option_inst_list, list) {
  1424. struct team_option *option = opt_inst->option;
  1425. struct team_gsetter_ctx ctx;
  1426. int tmp_ifindex;
  1427. tmp_ifindex = opt_inst->port ?
  1428. opt_inst->port->dev->ifindex : 0;
  1429. if (option->type != opt_type ||
  1430. strcmp(option->name, opt_name) ||
  1431. tmp_ifindex != opt_port_ifindex)
  1432. continue;
  1433. opt_found = true;
  1434. ctx.port = opt_inst->port;
  1435. switch (opt_type) {
  1436. case TEAM_OPTION_TYPE_U32:
  1437. ctx.data.u32_val = nla_get_u32(attr_data);
  1438. break;
  1439. case TEAM_OPTION_TYPE_STRING:
  1440. if (nla_len(attr_data) > TEAM_STRING_MAX_LEN) {
  1441. err = -EINVAL;
  1442. goto team_put;
  1443. }
  1444. ctx.data.str_val = nla_data(attr_data);
  1445. break;
  1446. case TEAM_OPTION_TYPE_BINARY:
  1447. ctx.data.bin_val.len = nla_len(attr_data);
  1448. ctx.data.bin_val.ptr = nla_data(attr_data);
  1449. break;
  1450. case TEAM_OPTION_TYPE_BOOL:
  1451. ctx.data.bool_val = attr_data ? true : false;
  1452. break;
  1453. default:
  1454. BUG();
  1455. }
  1456. err = team_option_set(team, opt_inst, &ctx);
  1457. if (err)
  1458. goto team_put;
  1459. }
  1460. if (!opt_found) {
  1461. err = -ENOENT;
  1462. goto team_put;
  1463. }
  1464. }
  1465. team_put:
  1466. team_nl_team_put(team);
  1467. return err;
  1468. }
  1469. static int team_nl_fill_port_list_get(struct sk_buff *skb,
  1470. u32 pid, u32 seq, int flags,
  1471. struct team *team,
  1472. bool fillall)
  1473. {
  1474. struct nlattr *port_list;
  1475. void *hdr;
  1476. struct team_port *port;
  1477. hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags,
  1478. TEAM_CMD_PORT_LIST_GET);
  1479. if (IS_ERR(hdr))
  1480. return PTR_ERR(hdr);
  1481. if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
  1482. goto nla_put_failure;
  1483. port_list = nla_nest_start(skb, TEAM_ATTR_LIST_PORT);
  1484. if (!port_list)
  1485. return -EMSGSIZE;
  1486. list_for_each_entry(port, &team->port_list, list) {
  1487. struct nlattr *port_item;
  1488. /* Include only changed ports if fill all mode is not on */
  1489. if (!fillall && !port->changed)
  1490. continue;
  1491. port_item = nla_nest_start(skb, TEAM_ATTR_ITEM_PORT);
  1492. if (!port_item)
  1493. goto nla_put_failure;
  1494. if (nla_put_u32(skb, TEAM_ATTR_PORT_IFINDEX, port->dev->ifindex))
  1495. goto nla_put_failure;
  1496. if (port->changed) {
  1497. if (nla_put_flag(skb, TEAM_ATTR_PORT_CHANGED))
  1498. goto nla_put_failure;
  1499. port->changed = false;
  1500. }
  1501. if ((port->removed &&
  1502. nla_put_flag(skb, TEAM_ATTR_PORT_REMOVED)) ||
  1503. (port->state.linkup &&
  1504. nla_put_flag(skb, TEAM_ATTR_PORT_LINKUP)) ||
  1505. nla_put_u32(skb, TEAM_ATTR_PORT_SPEED, port->state.speed) ||
  1506. nla_put_u8(skb, TEAM_ATTR_PORT_DUPLEX, port->state.duplex))
  1507. goto nla_put_failure;
  1508. nla_nest_end(skb, port_item);
  1509. }
  1510. nla_nest_end(skb, port_list);
  1511. return genlmsg_end(skb, hdr);
  1512. nla_put_failure:
  1513. genlmsg_cancel(skb, hdr);
  1514. return -EMSGSIZE;
  1515. }
  1516. static int team_nl_fill_port_list_get_all(struct sk_buff *skb,
  1517. struct genl_info *info, int flags,
  1518. struct team *team)
  1519. {
  1520. return team_nl_fill_port_list_get(skb, info->snd_pid,
  1521. info->snd_seq, NLM_F_ACK,
  1522. team, true);
  1523. }
  1524. static int team_nl_cmd_port_list_get(struct sk_buff *skb,
  1525. struct genl_info *info)
  1526. {
  1527. struct team *team;
  1528. int err;
  1529. team = team_nl_team_get(info);
  1530. if (!team)
  1531. return -EINVAL;
  1532. err = team_nl_send_generic(info, team, team_nl_fill_port_list_get_all);
  1533. team_nl_team_put(team);
  1534. return err;
  1535. }
  1536. static struct genl_ops team_nl_ops[] = {
  1537. {
  1538. .cmd = TEAM_CMD_NOOP,
  1539. .doit = team_nl_cmd_noop,
  1540. .policy = team_nl_policy,
  1541. },
  1542. {
  1543. .cmd = TEAM_CMD_OPTIONS_SET,
  1544. .doit = team_nl_cmd_options_set,
  1545. .policy = team_nl_policy,
  1546. .flags = GENL_ADMIN_PERM,
  1547. },
  1548. {
  1549. .cmd = TEAM_CMD_OPTIONS_GET,
  1550. .doit = team_nl_cmd_options_get,
  1551. .policy = team_nl_policy,
  1552. .flags = GENL_ADMIN_PERM,
  1553. },
  1554. {
  1555. .cmd = TEAM_CMD_PORT_LIST_GET,
  1556. .doit = team_nl_cmd_port_list_get,
  1557. .policy = team_nl_policy,
  1558. .flags = GENL_ADMIN_PERM,
  1559. },
  1560. };
  1561. static struct genl_multicast_group team_change_event_mcgrp = {
  1562. .name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME,
  1563. };
  1564. static int team_nl_send_event_options_get(struct team *team)
  1565. {
  1566. struct sk_buff *skb;
  1567. int err;
  1568. struct net *net = dev_net(team->dev);
  1569. skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  1570. if (!skb)
  1571. return -ENOMEM;
  1572. err = team_nl_fill_options_get(skb, 0, 0, 0, team, false);
  1573. if (err < 0)
  1574. goto err_fill;
  1575. err = genlmsg_multicast_netns(net, skb, 0, team_change_event_mcgrp.id,
  1576. GFP_KERNEL);
  1577. return err;
  1578. err_fill:
  1579. nlmsg_free(skb);
  1580. return err;
  1581. }
  1582. static int team_nl_send_event_port_list_get(struct team *team)
  1583. {
  1584. struct sk_buff *skb;
  1585. int err;
  1586. struct net *net = dev_net(team->dev);
  1587. skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  1588. if (!skb)
  1589. return -ENOMEM;
  1590. err = team_nl_fill_port_list_get(skb, 0, 0, 0, team, false);
  1591. if (err < 0)
  1592. goto err_fill;
  1593. err = genlmsg_multicast_netns(net, skb, 0, team_change_event_mcgrp.id,
  1594. GFP_KERNEL);
  1595. return err;
  1596. err_fill:
  1597. nlmsg_free(skb);
  1598. return err;
  1599. }
  1600. static int team_nl_init(void)
  1601. {
  1602. int err;
  1603. err = genl_register_family_with_ops(&team_nl_family, team_nl_ops,
  1604. ARRAY_SIZE(team_nl_ops));
  1605. if (err)
  1606. return err;
  1607. err = genl_register_mc_group(&team_nl_family, &team_change_event_mcgrp);
  1608. if (err)
  1609. goto err_change_event_grp_reg;
  1610. return 0;
  1611. err_change_event_grp_reg:
  1612. genl_unregister_family(&team_nl_family);
  1613. return err;
  1614. }
  1615. static void team_nl_fini(void)
  1616. {
  1617. genl_unregister_family(&team_nl_family);
  1618. }
  1619. /******************
  1620. * Change checkers
  1621. ******************/
  1622. static void __team_options_change_check(struct team *team)
  1623. {
  1624. int err;
  1625. err = team_nl_send_event_options_get(team);
  1626. if (err)
  1627. netdev_warn(team->dev, "Failed to send options change via netlink\n");
  1628. }
  1629. /* rtnl lock is held */
  1630. static void __team_port_change_check(struct team_port *port, bool linkup)
  1631. {
  1632. int err;
  1633. if (!port->removed && port->state.linkup == linkup)
  1634. return;
  1635. port->changed = true;
  1636. port->state.linkup = linkup;
  1637. team_refresh_port_linkup(port);
  1638. if (linkup) {
  1639. struct ethtool_cmd ecmd;
  1640. err = __ethtool_get_settings(port->dev, &ecmd);
  1641. if (!err) {
  1642. port->state.speed = ethtool_cmd_speed(&ecmd);
  1643. port->state.duplex = ecmd.duplex;
  1644. goto send_event;
  1645. }
  1646. }
  1647. port->state.speed = 0;
  1648. port->state.duplex = 0;
  1649. send_event:
  1650. err = team_nl_send_event_port_list_get(port->team);
  1651. if (err)
  1652. netdev_warn(port->team->dev, "Failed to send port change of device %s via netlink\n",
  1653. port->dev->name);
  1654. }
  1655. static void team_port_change_check(struct team_port *port, bool linkup)
  1656. {
  1657. struct team *team = port->team;
  1658. mutex_lock(&team->lock);
  1659. __team_port_change_check(port, linkup);
  1660. mutex_unlock(&team->lock);
  1661. }
  1662. /************************************
  1663. * Net device notifier event handler
  1664. ************************************/
  1665. static int team_device_event(struct notifier_block *unused,
  1666. unsigned long event, void *ptr)
  1667. {
  1668. struct net_device *dev = (struct net_device *) ptr;
  1669. struct team_port *port;
  1670. port = team_port_get_rtnl(dev);
  1671. if (!port)
  1672. return NOTIFY_DONE;
  1673. switch (event) {
  1674. case NETDEV_UP:
  1675. if (netif_carrier_ok(dev))
  1676. team_port_change_check(port, true);
  1677. case NETDEV_DOWN:
  1678. team_port_change_check(port, false);
  1679. case NETDEV_CHANGE:
  1680. if (netif_running(port->dev))
  1681. team_port_change_check(port,
  1682. !!netif_carrier_ok(port->dev));
  1683. break;
  1684. case NETDEV_UNREGISTER:
  1685. team_del_slave(port->team->dev, dev);
  1686. break;
  1687. case NETDEV_FEAT_CHANGE:
  1688. team_compute_features(port->team);
  1689. break;
  1690. case NETDEV_CHANGEMTU:
  1691. /* Forbid to change mtu of underlaying device */
  1692. return NOTIFY_BAD;
  1693. case NETDEV_PRE_TYPE_CHANGE:
  1694. /* Forbid to change type of underlaying device */
  1695. return NOTIFY_BAD;
  1696. }
  1697. return NOTIFY_DONE;
  1698. }
  1699. static struct notifier_block team_notifier_block __read_mostly = {
  1700. .notifier_call = team_device_event,
  1701. };
  1702. /***********************
  1703. * Module init and exit
  1704. ***********************/
  1705. static int __init team_module_init(void)
  1706. {
  1707. int err;
  1708. register_netdevice_notifier(&team_notifier_block);
  1709. err = rtnl_link_register(&team_link_ops);
  1710. if (err)
  1711. goto err_rtnl_reg;
  1712. err = team_nl_init();
  1713. if (err)
  1714. goto err_nl_init;
  1715. return 0;
  1716. err_nl_init:
  1717. rtnl_link_unregister(&team_link_ops);
  1718. err_rtnl_reg:
  1719. unregister_netdevice_notifier(&team_notifier_block);
  1720. return err;
  1721. }
  1722. static void __exit team_module_exit(void)
  1723. {
  1724. team_nl_fini();
  1725. rtnl_link_unregister(&team_link_ops);
  1726. unregister_netdevice_notifier(&team_notifier_block);
  1727. }
  1728. module_init(team_module_init);
  1729. module_exit(team_module_exit);
  1730. MODULE_LICENSE("GPL v2");
  1731. MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
  1732. MODULE_DESCRIPTION("Ethernet team device driver");
  1733. MODULE_ALIAS_RTNL_LINK(DRV_NAME);