team.c 47 KB

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