bond_options.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * drivers/net/bond/bond_options.c - bonding options
  4. * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
  5. * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com>
  6. */
  7. #include <linux/errno.h>
  8. #include <linux/if.h>
  9. #include <linux/netdevice.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/rcupdate.h>
  12. #include <linux/ctype.h>
  13. #include <linux/inet.h>
  14. #include <linux/sched/signal.h>
  15. #include <net/bonding.h>
  16. #include <net/ndisc.h>
  17. static int bond_option_active_slave_set(struct bonding *bond,
  18. const struct bond_opt_value *newval);
  19. static int bond_option_miimon_set(struct bonding *bond,
  20. const struct bond_opt_value *newval);
  21. static int bond_option_updelay_set(struct bonding *bond,
  22. const struct bond_opt_value *newval);
  23. static int bond_option_downdelay_set(struct bonding *bond,
  24. const struct bond_opt_value *newval);
  25. static int bond_option_peer_notif_delay_set(struct bonding *bond,
  26. const struct bond_opt_value *newval);
  27. static int bond_option_use_carrier_set(struct bonding *bond,
  28. const struct bond_opt_value *newval);
  29. static int bond_option_arp_interval_set(struct bonding *bond,
  30. const struct bond_opt_value *newval);
  31. static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target);
  32. static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target);
  33. static int bond_option_arp_ip_targets_set(struct bonding *bond,
  34. const struct bond_opt_value *newval);
  35. static int bond_option_ns_ip6_targets_set(struct bonding *bond,
  36. const struct bond_opt_value *newval);
  37. static int bond_option_arp_validate_set(struct bonding *bond,
  38. const struct bond_opt_value *newval);
  39. static int bond_option_arp_all_targets_set(struct bonding *bond,
  40. const struct bond_opt_value *newval);
  41. static int bond_option_prio_set(struct bonding *bond,
  42. const struct bond_opt_value *newval);
  43. static int bond_option_primary_set(struct bonding *bond,
  44. const struct bond_opt_value *newval);
  45. static int bond_option_primary_reselect_set(struct bonding *bond,
  46. const struct bond_opt_value *newval);
  47. static int bond_option_fail_over_mac_set(struct bonding *bond,
  48. const struct bond_opt_value *newval);
  49. static int bond_option_xmit_hash_policy_set(struct bonding *bond,
  50. const struct bond_opt_value *newval);
  51. static int bond_option_resend_igmp_set(struct bonding *bond,
  52. const struct bond_opt_value *newval);
  53. static int bond_option_num_peer_notif_set(struct bonding *bond,
  54. const struct bond_opt_value *newval);
  55. static int bond_option_all_slaves_active_set(struct bonding *bond,
  56. const struct bond_opt_value *newval);
  57. static int bond_option_min_links_set(struct bonding *bond,
  58. const struct bond_opt_value *newval);
  59. static int bond_option_lp_interval_set(struct bonding *bond,
  60. const struct bond_opt_value *newval);
  61. static int bond_option_pps_set(struct bonding *bond,
  62. const struct bond_opt_value *newval);
  63. static int bond_option_lacp_active_set(struct bonding *bond,
  64. const struct bond_opt_value *newval);
  65. static int bond_option_lacp_rate_set(struct bonding *bond,
  66. const struct bond_opt_value *newval);
  67. static int bond_option_ad_select_set(struct bonding *bond,
  68. const struct bond_opt_value *newval);
  69. static int bond_option_queue_id_set(struct bonding *bond,
  70. const struct bond_opt_value *newval);
  71. static int bond_option_mode_set(struct bonding *bond,
  72. const struct bond_opt_value *newval);
  73. static int bond_option_slaves_set(struct bonding *bond,
  74. const struct bond_opt_value *newval);
  75. static int bond_option_tlb_dynamic_lb_set(struct bonding *bond,
  76. const struct bond_opt_value *newval);
  77. static int bond_option_ad_actor_sys_prio_set(struct bonding *bond,
  78. const struct bond_opt_value *newval);
  79. static int bond_option_ad_actor_system_set(struct bonding *bond,
  80. const struct bond_opt_value *newval);
  81. static int bond_option_ad_user_port_key_set(struct bonding *bond,
  82. const struct bond_opt_value *newval);
  83. static int bond_option_missed_max_set(struct bonding *bond,
  84. const struct bond_opt_value *newval);
  85. static int bond_option_coupled_control_set(struct bonding *bond,
  86. const struct bond_opt_value *newval);
  87. static const struct bond_opt_value bond_mode_tbl[] = {
  88. { "balance-rr", BOND_MODE_ROUNDROBIN, BOND_VALFLAG_DEFAULT},
  89. { "active-backup", BOND_MODE_ACTIVEBACKUP, 0},
  90. { "balance-xor", BOND_MODE_XOR, 0},
  91. { "broadcast", BOND_MODE_BROADCAST, 0},
  92. { "802.3ad", BOND_MODE_8023AD, 0},
  93. { "balance-tlb", BOND_MODE_TLB, 0},
  94. { "balance-alb", BOND_MODE_ALB, 0},
  95. { NULL, -1, 0},
  96. };
  97. static const struct bond_opt_value bond_pps_tbl[] = {
  98. { "default", 1, BOND_VALFLAG_DEFAULT},
  99. { "maxval", USHRT_MAX, BOND_VALFLAG_MAX},
  100. { NULL, -1, 0},
  101. };
  102. static const struct bond_opt_value bond_xmit_hashtype_tbl[] = {
  103. { "layer2", BOND_XMIT_POLICY_LAYER2, BOND_VALFLAG_DEFAULT},
  104. { "layer3+4", BOND_XMIT_POLICY_LAYER34, 0},
  105. { "layer2+3", BOND_XMIT_POLICY_LAYER23, 0},
  106. { "encap2+3", BOND_XMIT_POLICY_ENCAP23, 0},
  107. { "encap3+4", BOND_XMIT_POLICY_ENCAP34, 0},
  108. { "vlan+srcmac", BOND_XMIT_POLICY_VLAN_SRCMAC, 0},
  109. { NULL, -1, 0},
  110. };
  111. static const struct bond_opt_value bond_arp_validate_tbl[] = {
  112. { "none", BOND_ARP_VALIDATE_NONE, BOND_VALFLAG_DEFAULT},
  113. { "active", BOND_ARP_VALIDATE_ACTIVE, 0},
  114. { "backup", BOND_ARP_VALIDATE_BACKUP, 0},
  115. { "all", BOND_ARP_VALIDATE_ALL, 0},
  116. { "filter", BOND_ARP_FILTER, 0},
  117. { "filter_active", BOND_ARP_FILTER_ACTIVE, 0},
  118. { "filter_backup", BOND_ARP_FILTER_BACKUP, 0},
  119. { NULL, -1, 0},
  120. };
  121. static const struct bond_opt_value bond_arp_all_targets_tbl[] = {
  122. { "any", BOND_ARP_TARGETS_ANY, BOND_VALFLAG_DEFAULT},
  123. { "all", BOND_ARP_TARGETS_ALL, 0},
  124. { NULL, -1, 0},
  125. };
  126. static const struct bond_opt_value bond_fail_over_mac_tbl[] = {
  127. { "none", BOND_FOM_NONE, BOND_VALFLAG_DEFAULT},
  128. { "active", BOND_FOM_ACTIVE, 0},
  129. { "follow", BOND_FOM_FOLLOW, 0},
  130. { NULL, -1, 0},
  131. };
  132. static const struct bond_opt_value bond_intmax_tbl[] = {
  133. { "off", 0, BOND_VALFLAG_DEFAULT},
  134. { "maxval", INT_MAX, BOND_VALFLAG_MAX},
  135. { NULL, -1, 0}
  136. };
  137. static const struct bond_opt_value bond_lacp_active[] = {
  138. { "off", 0, 0},
  139. { "on", 1, BOND_VALFLAG_DEFAULT},
  140. { NULL, -1, 0}
  141. };
  142. static const struct bond_opt_value bond_lacp_rate_tbl[] = {
  143. { "slow", AD_LACP_SLOW, 0},
  144. { "fast", AD_LACP_FAST, 0},
  145. { NULL, -1, 0},
  146. };
  147. static const struct bond_opt_value bond_ad_select_tbl[] = {
  148. { "stable", BOND_AD_STABLE, BOND_VALFLAG_DEFAULT},
  149. { "bandwidth", BOND_AD_BANDWIDTH, 0},
  150. { "count", BOND_AD_COUNT, 0},
  151. { NULL, -1, 0},
  152. };
  153. static const struct bond_opt_value bond_num_peer_notif_tbl[] = {
  154. { "off", 0, 0},
  155. { "maxval", 255, BOND_VALFLAG_MAX},
  156. { "default", 1, BOND_VALFLAG_DEFAULT},
  157. { NULL, -1, 0}
  158. };
  159. static const struct bond_opt_value bond_peer_notif_delay_tbl[] = {
  160. { "off", 0, 0},
  161. { "maxval", 300000, BOND_VALFLAG_MAX},
  162. { NULL, -1, 0}
  163. };
  164. static const struct bond_opt_value bond_primary_reselect_tbl[] = {
  165. { "always", BOND_PRI_RESELECT_ALWAYS, BOND_VALFLAG_DEFAULT},
  166. { "better", BOND_PRI_RESELECT_BETTER, 0},
  167. { "failure", BOND_PRI_RESELECT_FAILURE, 0},
  168. { NULL, -1},
  169. };
  170. static const struct bond_opt_value bond_use_carrier_tbl[] = {
  171. { "off", 0, 0},
  172. { "on", 1, BOND_VALFLAG_DEFAULT},
  173. { NULL, -1, 0}
  174. };
  175. static const struct bond_opt_value bond_all_slaves_active_tbl[] = {
  176. { "off", 0, BOND_VALFLAG_DEFAULT},
  177. { "on", 1, 0},
  178. { NULL, -1, 0}
  179. };
  180. static const struct bond_opt_value bond_resend_igmp_tbl[] = {
  181. { "off", 0, 0},
  182. { "maxval", 255, BOND_VALFLAG_MAX},
  183. { "default", 1, BOND_VALFLAG_DEFAULT},
  184. { NULL, -1, 0}
  185. };
  186. static const struct bond_opt_value bond_lp_interval_tbl[] = {
  187. { "minval", 1, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT},
  188. { "maxval", INT_MAX, BOND_VALFLAG_MAX},
  189. { NULL, -1, 0},
  190. };
  191. static const struct bond_opt_value bond_tlb_dynamic_lb_tbl[] = {
  192. { "off", 0, 0},
  193. { "on", 1, BOND_VALFLAG_DEFAULT},
  194. { NULL, -1, 0}
  195. };
  196. static const struct bond_opt_value bond_ad_actor_sys_prio_tbl[] = {
  197. { "minval", 1, BOND_VALFLAG_MIN},
  198. { "maxval", 65535, BOND_VALFLAG_MAX | BOND_VALFLAG_DEFAULT},
  199. { NULL, -1, 0},
  200. };
  201. static const struct bond_opt_value bond_ad_user_port_key_tbl[] = {
  202. { "minval", 0, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT},
  203. { "maxval", 1023, BOND_VALFLAG_MAX},
  204. { NULL, -1, 0},
  205. };
  206. static const struct bond_opt_value bond_missed_max_tbl[] = {
  207. { "minval", 1, BOND_VALFLAG_MIN},
  208. { "maxval", 255, BOND_VALFLAG_MAX},
  209. { "default", 2, BOND_VALFLAG_DEFAULT},
  210. { NULL, -1, 0},
  211. };
  212. static const struct bond_opt_value bond_coupled_control_tbl[] = {
  213. { "on", 1, BOND_VALFLAG_DEFAULT},
  214. { "off", 0, 0},
  215. { NULL, -1, 0},
  216. };
  217. static const struct bond_option bond_opts[BOND_OPT_LAST] = {
  218. [BOND_OPT_MODE] = {
  219. .id = BOND_OPT_MODE,
  220. .name = "mode",
  221. .desc = "bond device mode",
  222. .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN,
  223. .values = bond_mode_tbl,
  224. .set = bond_option_mode_set
  225. },
  226. [BOND_OPT_PACKETS_PER_SLAVE] = {
  227. .id = BOND_OPT_PACKETS_PER_SLAVE,
  228. .name = "packets_per_slave",
  229. .desc = "Packets to send per slave in RR mode",
  230. .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)),
  231. .values = bond_pps_tbl,
  232. .set = bond_option_pps_set
  233. },
  234. [BOND_OPT_XMIT_HASH] = {
  235. .id = BOND_OPT_XMIT_HASH,
  236. .name = "xmit_hash_policy",
  237. .desc = "balance-xor, 802.3ad, and tlb hashing method",
  238. .values = bond_xmit_hashtype_tbl,
  239. .set = bond_option_xmit_hash_policy_set
  240. },
  241. [BOND_OPT_ARP_VALIDATE] = {
  242. .id = BOND_OPT_ARP_VALIDATE,
  243. .name = "arp_validate",
  244. .desc = "validate src/dst of ARP probes",
  245. .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) |
  246. BIT(BOND_MODE_ALB),
  247. .values = bond_arp_validate_tbl,
  248. .set = bond_option_arp_validate_set
  249. },
  250. [BOND_OPT_ARP_ALL_TARGETS] = {
  251. .id = BOND_OPT_ARP_ALL_TARGETS,
  252. .name = "arp_all_targets",
  253. .desc = "fail on any/all arp targets timeout",
  254. .values = bond_arp_all_targets_tbl,
  255. .set = bond_option_arp_all_targets_set
  256. },
  257. [BOND_OPT_FAIL_OVER_MAC] = {
  258. .id = BOND_OPT_FAIL_OVER_MAC,
  259. .name = "fail_over_mac",
  260. .desc = "For active-backup, do not set all slaves to the same MAC",
  261. .flags = BOND_OPTFLAG_NOSLAVES,
  262. .values = bond_fail_over_mac_tbl,
  263. .set = bond_option_fail_over_mac_set
  264. },
  265. [BOND_OPT_ARP_INTERVAL] = {
  266. .id = BOND_OPT_ARP_INTERVAL,
  267. .name = "arp_interval",
  268. .desc = "arp interval in milliseconds",
  269. .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) |
  270. BIT(BOND_MODE_ALB),
  271. .values = bond_intmax_tbl,
  272. .set = bond_option_arp_interval_set
  273. },
  274. [BOND_OPT_MISSED_MAX] = {
  275. .id = BOND_OPT_MISSED_MAX,
  276. .name = "arp_missed_max",
  277. .desc = "Maximum number of missed ARP interval",
  278. .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) |
  279. BIT(BOND_MODE_ALB),
  280. .values = bond_missed_max_tbl,
  281. .set = bond_option_missed_max_set
  282. },
  283. [BOND_OPT_ARP_TARGETS] = {
  284. .id = BOND_OPT_ARP_TARGETS,
  285. .name = "arp_ip_target",
  286. .desc = "arp targets in n.n.n.n form",
  287. .flags = BOND_OPTFLAG_RAWVAL,
  288. .set = bond_option_arp_ip_targets_set
  289. },
  290. [BOND_OPT_NS_TARGETS] = {
  291. .id = BOND_OPT_NS_TARGETS,
  292. .name = "ns_ip6_target",
  293. .desc = "NS targets in ffff:ffff::ffff:ffff form",
  294. .flags = BOND_OPTFLAG_RAWVAL,
  295. .set = bond_option_ns_ip6_targets_set
  296. },
  297. [BOND_OPT_DOWNDELAY] = {
  298. .id = BOND_OPT_DOWNDELAY,
  299. .name = "downdelay",
  300. .desc = "Delay before considering link down, in milliseconds",
  301. .values = bond_intmax_tbl,
  302. .set = bond_option_downdelay_set
  303. },
  304. [BOND_OPT_UPDELAY] = {
  305. .id = BOND_OPT_UPDELAY,
  306. .name = "updelay",
  307. .desc = "Delay before considering link up, in milliseconds",
  308. .values = bond_intmax_tbl,
  309. .set = bond_option_updelay_set
  310. },
  311. [BOND_OPT_LACP_ACTIVE] = {
  312. .id = BOND_OPT_LACP_ACTIVE,
  313. .name = "lacp_active",
  314. .desc = "Send LACPDU frames with configured lacp rate or acts as speak when spoken to",
  315. .flags = BOND_OPTFLAG_IFDOWN,
  316. .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
  317. .values = bond_lacp_active,
  318. .set = bond_option_lacp_active_set
  319. },
  320. [BOND_OPT_LACP_RATE] = {
  321. .id = BOND_OPT_LACP_RATE,
  322. .name = "lacp_rate",
  323. .desc = "LACPDU tx rate to request from 802.3ad partner",
  324. .flags = BOND_OPTFLAG_IFDOWN,
  325. .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
  326. .values = bond_lacp_rate_tbl,
  327. .set = bond_option_lacp_rate_set
  328. },
  329. [BOND_OPT_MINLINKS] = {
  330. .id = BOND_OPT_MINLINKS,
  331. .name = "min_links",
  332. .desc = "Minimum number of available links before turning on carrier",
  333. .values = bond_intmax_tbl,
  334. .set = bond_option_min_links_set
  335. },
  336. [BOND_OPT_AD_SELECT] = {
  337. .id = BOND_OPT_AD_SELECT,
  338. .name = "ad_select",
  339. .desc = "803.ad aggregation selection logic",
  340. .flags = BOND_OPTFLAG_IFDOWN,
  341. .values = bond_ad_select_tbl,
  342. .set = bond_option_ad_select_set
  343. },
  344. [BOND_OPT_NUM_PEER_NOTIF] = {
  345. .id = BOND_OPT_NUM_PEER_NOTIF,
  346. .name = "num_unsol_na",
  347. .desc = "Number of peer notifications to send on failover event",
  348. .values = bond_num_peer_notif_tbl,
  349. .set = bond_option_num_peer_notif_set
  350. },
  351. [BOND_OPT_MIIMON] = {
  352. .id = BOND_OPT_MIIMON,
  353. .name = "miimon",
  354. .desc = "Link check interval in milliseconds",
  355. .values = bond_intmax_tbl,
  356. .set = bond_option_miimon_set
  357. },
  358. [BOND_OPT_PRIO] = {
  359. .id = BOND_OPT_PRIO,
  360. .name = "prio",
  361. .desc = "Link priority for failover re-selection",
  362. .flags = BOND_OPTFLAG_RAWVAL,
  363. .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) |
  364. BIT(BOND_MODE_TLB) |
  365. BIT(BOND_MODE_ALB)),
  366. .set = bond_option_prio_set
  367. },
  368. [BOND_OPT_PRIMARY] = {
  369. .id = BOND_OPT_PRIMARY,
  370. .name = "primary",
  371. .desc = "Primary network device to use",
  372. .flags = BOND_OPTFLAG_RAWVAL,
  373. .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) |
  374. BIT(BOND_MODE_TLB) |
  375. BIT(BOND_MODE_ALB)),
  376. .set = bond_option_primary_set
  377. },
  378. [BOND_OPT_PRIMARY_RESELECT] = {
  379. .id = BOND_OPT_PRIMARY_RESELECT,
  380. .name = "primary_reselect",
  381. .desc = "Reselect primary slave once it comes up",
  382. .values = bond_primary_reselect_tbl,
  383. .set = bond_option_primary_reselect_set
  384. },
  385. [BOND_OPT_USE_CARRIER] = {
  386. .id = BOND_OPT_USE_CARRIER,
  387. .name = "use_carrier",
  388. .desc = "Use netif_carrier_ok (vs MII ioctls) in miimon",
  389. .values = bond_use_carrier_tbl,
  390. .set = bond_option_use_carrier_set
  391. },
  392. [BOND_OPT_ACTIVE_SLAVE] = {
  393. .id = BOND_OPT_ACTIVE_SLAVE,
  394. .name = "active_slave",
  395. .desc = "Currently active slave",
  396. .flags = BOND_OPTFLAG_RAWVAL,
  397. .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) |
  398. BIT(BOND_MODE_TLB) |
  399. BIT(BOND_MODE_ALB)),
  400. .set = bond_option_active_slave_set
  401. },
  402. [BOND_OPT_QUEUE_ID] = {
  403. .id = BOND_OPT_QUEUE_ID,
  404. .name = "queue_id",
  405. .desc = "Set queue id of a slave",
  406. .flags = BOND_OPTFLAG_RAWVAL,
  407. .set = bond_option_queue_id_set
  408. },
  409. [BOND_OPT_ALL_SLAVES_ACTIVE] = {
  410. .id = BOND_OPT_ALL_SLAVES_ACTIVE,
  411. .name = "all_slaves_active",
  412. .desc = "Keep all frames received on an interface by setting active flag for all slaves",
  413. .values = bond_all_slaves_active_tbl,
  414. .set = bond_option_all_slaves_active_set
  415. },
  416. [BOND_OPT_RESEND_IGMP] = {
  417. .id = BOND_OPT_RESEND_IGMP,
  418. .name = "resend_igmp",
  419. .desc = "Number of IGMP membership reports to send on link failure",
  420. .values = bond_resend_igmp_tbl,
  421. .set = bond_option_resend_igmp_set
  422. },
  423. [BOND_OPT_LP_INTERVAL] = {
  424. .id = BOND_OPT_LP_INTERVAL,
  425. .name = "lp_interval",
  426. .desc = "The number of seconds between instances where the bonding driver sends learning packets to each slave's peer switch",
  427. .values = bond_lp_interval_tbl,
  428. .set = bond_option_lp_interval_set
  429. },
  430. [BOND_OPT_SLAVES] = {
  431. .id = BOND_OPT_SLAVES,
  432. .name = "slaves",
  433. .desc = "Slave membership management",
  434. .flags = BOND_OPTFLAG_RAWVAL,
  435. .set = bond_option_slaves_set
  436. },
  437. [BOND_OPT_TLB_DYNAMIC_LB] = {
  438. .id = BOND_OPT_TLB_DYNAMIC_LB,
  439. .name = "tlb_dynamic_lb",
  440. .desc = "Enable dynamic flow shuffling",
  441. .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_TLB) | BIT(BOND_MODE_ALB)),
  442. .values = bond_tlb_dynamic_lb_tbl,
  443. .flags = BOND_OPTFLAG_IFDOWN,
  444. .set = bond_option_tlb_dynamic_lb_set,
  445. },
  446. [BOND_OPT_AD_ACTOR_SYS_PRIO] = {
  447. .id = BOND_OPT_AD_ACTOR_SYS_PRIO,
  448. .name = "ad_actor_sys_prio",
  449. .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
  450. .values = bond_ad_actor_sys_prio_tbl,
  451. .set = bond_option_ad_actor_sys_prio_set,
  452. },
  453. [BOND_OPT_AD_ACTOR_SYSTEM] = {
  454. .id = BOND_OPT_AD_ACTOR_SYSTEM,
  455. .name = "ad_actor_system",
  456. .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
  457. .flags = BOND_OPTFLAG_RAWVAL,
  458. .set = bond_option_ad_actor_system_set,
  459. },
  460. [BOND_OPT_AD_USER_PORT_KEY] = {
  461. .id = BOND_OPT_AD_USER_PORT_KEY,
  462. .name = "ad_user_port_key",
  463. .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
  464. .flags = BOND_OPTFLAG_IFDOWN,
  465. .values = bond_ad_user_port_key_tbl,
  466. .set = bond_option_ad_user_port_key_set,
  467. },
  468. [BOND_OPT_NUM_PEER_NOTIF_ALIAS] = {
  469. .id = BOND_OPT_NUM_PEER_NOTIF_ALIAS,
  470. .name = "num_grat_arp",
  471. .desc = "Number of peer notifications to send on failover event",
  472. .values = bond_num_peer_notif_tbl,
  473. .set = bond_option_num_peer_notif_set
  474. },
  475. [BOND_OPT_PEER_NOTIF_DELAY] = {
  476. .id = BOND_OPT_PEER_NOTIF_DELAY,
  477. .name = "peer_notif_delay",
  478. .desc = "Delay between each peer notification on failover event, in milliseconds",
  479. .values = bond_peer_notif_delay_tbl,
  480. .set = bond_option_peer_notif_delay_set
  481. },
  482. [BOND_OPT_COUPLED_CONTROL] = {
  483. .id = BOND_OPT_COUPLED_CONTROL,
  484. .name = "coupled_control",
  485. .desc = "Opt into using coupled control MUX for LACP states",
  486. .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
  487. .flags = BOND_OPTFLAG_IFDOWN,
  488. .values = bond_coupled_control_tbl,
  489. .set = bond_option_coupled_control_set,
  490. }
  491. };
  492. /* Searches for an option by name */
  493. const struct bond_option *bond_opt_get_by_name(const char *name)
  494. {
  495. const struct bond_option *opt;
  496. int option;
  497. for (option = 0; option < BOND_OPT_LAST; option++) {
  498. opt = bond_opt_get(option);
  499. if (opt && !strcmp(opt->name, name))
  500. return opt;
  501. }
  502. return NULL;
  503. }
  504. /* Searches for a value in opt's values[] table */
  505. const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val)
  506. {
  507. const struct bond_option *opt;
  508. int i;
  509. opt = bond_opt_get(option);
  510. if (WARN_ON(!opt))
  511. return NULL;
  512. for (i = 0; opt->values && opt->values[i].string; i++)
  513. if (opt->values[i].value == val)
  514. return &opt->values[i];
  515. return NULL;
  516. }
  517. /* Searches for a value in opt's values[] table which matches the flagmask */
  518. static const struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt,
  519. u32 flagmask)
  520. {
  521. int i;
  522. for (i = 0; opt->values && opt->values[i].string; i++)
  523. if (opt->values[i].flags & flagmask)
  524. return &opt->values[i];
  525. return NULL;
  526. }
  527. /* If maxval is missing then there's no range to check. In case minval is
  528. * missing then it's considered to be 0.
  529. */
  530. static bool bond_opt_check_range(const struct bond_option *opt, u64 val)
  531. {
  532. const struct bond_opt_value *minval, *maxval;
  533. minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
  534. maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
  535. if (!maxval || (minval && val < minval->value) || val > maxval->value)
  536. return false;
  537. return true;
  538. }
  539. /**
  540. * bond_opt_parse - parse option value
  541. * @opt: the option to parse against
  542. * @val: value to parse
  543. *
  544. * This function tries to extract the value from @val and check if it's
  545. * a possible match for the option and returns NULL if a match isn't found,
  546. * or the struct_opt_value that matched. It also strips the new line from
  547. * @val->string if it's present.
  548. */
  549. const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt,
  550. struct bond_opt_value *val)
  551. {
  552. char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, };
  553. const struct bond_opt_value *tbl;
  554. const struct bond_opt_value *ret = NULL;
  555. bool checkval;
  556. int i, rv;
  557. /* No parsing if the option wants a raw val */
  558. if (opt->flags & BOND_OPTFLAG_RAWVAL)
  559. return val;
  560. tbl = opt->values;
  561. if (!tbl)
  562. goto out;
  563. /* ULLONG_MAX is used to bypass string processing */
  564. checkval = val->value != ULLONG_MAX;
  565. if (!checkval) {
  566. if (!val->string)
  567. goto out;
  568. p = strchr(val->string, '\n');
  569. if (p)
  570. *p = '\0';
  571. for (p = val->string; *p; p++)
  572. if (!(isdigit(*p) || isspace(*p)))
  573. break;
  574. /* The following code extracts the string to match or the value
  575. * and sets checkval appropriately
  576. */
  577. if (*p) {
  578. rv = sscanf(val->string, "%32s", valstr);
  579. } else {
  580. rv = sscanf(val->string, "%llu", &val->value);
  581. checkval = true;
  582. }
  583. if (!rv)
  584. goto out;
  585. }
  586. for (i = 0; tbl[i].string; i++) {
  587. /* Check for exact match */
  588. if (checkval) {
  589. if (val->value == tbl[i].value)
  590. ret = &tbl[i];
  591. } else {
  592. if (!strcmp(valstr, "default") &&
  593. (tbl[i].flags & BOND_VALFLAG_DEFAULT))
  594. ret = &tbl[i];
  595. if (!strcmp(valstr, tbl[i].string))
  596. ret = &tbl[i];
  597. }
  598. /* Found an exact match */
  599. if (ret)
  600. goto out;
  601. }
  602. /* Possible range match */
  603. if (checkval && bond_opt_check_range(opt, val->value))
  604. ret = val;
  605. out:
  606. return ret;
  607. }
  608. /* Check opt's dependencies against bond mode and currently set options */
  609. static int bond_opt_check_deps(struct bonding *bond,
  610. const struct bond_option *opt)
  611. {
  612. struct bond_params *params = &bond->params;
  613. if (test_bit(params->mode, &opt->unsuppmodes))
  614. return -EACCES;
  615. if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond))
  616. return -ENOTEMPTY;
  617. if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP))
  618. return -EBUSY;
  619. return 0;
  620. }
  621. static void bond_opt_dep_print(struct bonding *bond,
  622. const struct bond_option *opt,
  623. struct nlattr *bad_attr,
  624. struct netlink_ext_ack *extack)
  625. {
  626. const struct bond_opt_value *modeval;
  627. struct bond_params *params;
  628. params = &bond->params;
  629. modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode);
  630. if (test_bit(params->mode, &opt->unsuppmodes)) {
  631. netdev_err(bond->dev, "option %s: mode dependency failed, not supported in mode %s(%llu)\n",
  632. opt->name, modeval->string, modeval->value);
  633. NL_SET_ERR_MSG_ATTR(extack, bad_attr,
  634. "option not supported in mode");
  635. }
  636. }
  637. static void bond_opt_error_interpret(struct bonding *bond,
  638. const struct bond_option *opt,
  639. int error, const struct bond_opt_value *val,
  640. struct nlattr *bad_attr,
  641. struct netlink_ext_ack *extack)
  642. {
  643. const struct bond_opt_value *minval, *maxval;
  644. char *p;
  645. switch (error) {
  646. case -EINVAL:
  647. NL_SET_ERR_MSG_ATTR(extack, bad_attr, "invalid option value");
  648. if (val) {
  649. if (val->string) {
  650. /* sometimes RAWVAL opts may have new lines */
  651. p = strchr(val->string, '\n');
  652. if (p)
  653. *p = '\0';
  654. netdev_err(bond->dev, "option %s: invalid value (%s)\n",
  655. opt->name, val->string);
  656. } else {
  657. netdev_err(bond->dev, "option %s: invalid value (%llu)\n",
  658. opt->name, val->value);
  659. }
  660. }
  661. minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
  662. maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
  663. if (!maxval)
  664. break;
  665. netdev_err(bond->dev, "option %s: allowed values %llu - %llu\n",
  666. opt->name, minval ? minval->value : 0, maxval->value);
  667. break;
  668. case -EACCES:
  669. bond_opt_dep_print(bond, opt, bad_attr, extack);
  670. break;
  671. case -ENOTEMPTY:
  672. NL_SET_ERR_MSG_ATTR(extack, bad_attr,
  673. "unable to set option because the bond device has slaves");
  674. netdev_err(bond->dev, "option %s: unable to set because the bond device has slaves\n",
  675. opt->name);
  676. break;
  677. case -EBUSY:
  678. NL_SET_ERR_MSG_ATTR(extack, bad_attr,
  679. "unable to set option because the bond is up");
  680. netdev_err(bond->dev, "option %s: unable to set because the bond device is up\n",
  681. opt->name);
  682. break;
  683. case -ENODEV:
  684. if (val && val->string) {
  685. p = strchr(val->string, '\n');
  686. if (p)
  687. *p = '\0';
  688. netdev_err(bond->dev, "option %s: interface %s does not exist!\n",
  689. opt->name, val->string);
  690. NL_SET_ERR_MSG_ATTR(extack, bad_attr,
  691. "interface does not exist");
  692. }
  693. break;
  694. default:
  695. break;
  696. }
  697. }
  698. /**
  699. * __bond_opt_set - set a bonding option
  700. * @bond: target bond device
  701. * @option: option to set
  702. * @val: value to set it to
  703. * @bad_attr: netlink attribue that caused the error
  704. * @extack: extended netlink error structure, used when an error message
  705. * needs to be returned to the caller via netlink
  706. *
  707. * This function is used to change the bond's option value, it can be
  708. * used for both enabling/changing an option and for disabling it. RTNL lock
  709. * must be obtained before calling this function.
  710. */
  711. int __bond_opt_set(struct bonding *bond,
  712. unsigned int option, struct bond_opt_value *val,
  713. struct nlattr *bad_attr, struct netlink_ext_ack *extack)
  714. {
  715. const struct bond_opt_value *retval = NULL;
  716. const struct bond_option *opt;
  717. int ret = -ENOENT;
  718. ASSERT_RTNL();
  719. opt = bond_opt_get(option);
  720. if (WARN_ON(!val) || WARN_ON(!opt))
  721. goto out;
  722. ret = bond_opt_check_deps(bond, opt);
  723. if (ret)
  724. goto out;
  725. retval = bond_opt_parse(opt, val);
  726. if (!retval) {
  727. ret = -EINVAL;
  728. goto out;
  729. }
  730. ret = opt->set(bond, retval);
  731. out:
  732. if (ret)
  733. bond_opt_error_interpret(bond, opt, ret, val, bad_attr, extack);
  734. return ret;
  735. }
  736. /**
  737. * __bond_opt_set_notify - set a bonding option
  738. * @bond: target bond device
  739. * @option: option to set
  740. * @val: value to set it to
  741. *
  742. * This function is used to change the bond's option value and trigger
  743. * a notification to user sapce. It can be used for both enabling/changing
  744. * an option and for disabling it. RTNL lock must be obtained before calling
  745. * this function.
  746. */
  747. int __bond_opt_set_notify(struct bonding *bond,
  748. unsigned int option, struct bond_opt_value *val)
  749. {
  750. int ret;
  751. ASSERT_RTNL();
  752. ret = __bond_opt_set(bond, option, val, NULL, NULL);
  753. if (!ret && (bond->dev->reg_state == NETREG_REGISTERED))
  754. call_netdevice_notifiers(NETDEV_CHANGEINFODATA, bond->dev);
  755. return ret;
  756. }
  757. /**
  758. * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set
  759. * @bond: target bond device
  760. * @option: option to set
  761. * @buf: value to set it to
  762. *
  763. * This function tries to acquire RTNL without blocking and if successful
  764. * calls __bond_opt_set. It is mainly used for sysfs option manipulation.
  765. */
  766. int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf)
  767. {
  768. struct bond_opt_value optval;
  769. int ret;
  770. if (!rtnl_trylock())
  771. return restart_syscall();
  772. bond_opt_initstr(&optval, buf);
  773. ret = __bond_opt_set_notify(bond, option, &optval);
  774. rtnl_unlock();
  775. return ret;
  776. }
  777. /**
  778. * bond_opt_get - get a pointer to an option
  779. * @option: option for which to return a pointer
  780. *
  781. * This function checks if option is valid and if so returns a pointer
  782. * to its entry in the bond_opts[] option array.
  783. */
  784. const struct bond_option *bond_opt_get(unsigned int option)
  785. {
  786. if (!BOND_OPT_VALID(option))
  787. return NULL;
  788. return &bond_opts[option];
  789. }
  790. static bool bond_set_xfrm_features(struct bonding *bond)
  791. {
  792. if (!IS_ENABLED(CONFIG_XFRM_OFFLOAD))
  793. return false;
  794. if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP)
  795. bond->dev->wanted_features |= BOND_XFRM_FEATURES;
  796. else
  797. bond->dev->wanted_features &= ~BOND_XFRM_FEATURES;
  798. return true;
  799. }
  800. static int bond_option_mode_set(struct bonding *bond,
  801. const struct bond_opt_value *newval)
  802. {
  803. if (!bond_mode_uses_arp(newval->value)) {
  804. if (bond->params.arp_interval) {
  805. netdev_dbg(bond->dev, "%s mode is incompatible with arp monitoring, start mii monitoring\n",
  806. newval->string);
  807. /* disable arp monitoring */
  808. bond->params.arp_interval = 0;
  809. }
  810. if (!bond->params.miimon) {
  811. /* set miimon to default value */
  812. bond->params.miimon = BOND_DEFAULT_MIIMON;
  813. netdev_dbg(bond->dev, "Setting MII monitoring interval to %d\n",
  814. bond->params.miimon);
  815. }
  816. }
  817. if (newval->value == BOND_MODE_ALB)
  818. bond->params.tlb_dynamic_lb = 1;
  819. /* don't cache arp_validate between modes */
  820. bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
  821. bond->params.mode = newval->value;
  822. if (bond->dev->reg_state == NETREG_REGISTERED) {
  823. bool update = false;
  824. update |= bond_set_xfrm_features(bond);
  825. if (update)
  826. netdev_update_features(bond->dev);
  827. }
  828. bond_xdp_set_features(bond->dev);
  829. return 0;
  830. }
  831. static int bond_option_active_slave_set(struct bonding *bond,
  832. const struct bond_opt_value *newval)
  833. {
  834. char ifname[IFNAMSIZ] = { 0, };
  835. struct net_device *slave_dev;
  836. int ret = 0;
  837. sscanf(newval->string, "%15s", ifname); /* IFNAMSIZ */
  838. if (!strlen(ifname) || newval->string[0] == '\n') {
  839. slave_dev = NULL;
  840. } else {
  841. slave_dev = __dev_get_by_name(dev_net(bond->dev), ifname);
  842. if (!slave_dev)
  843. return -ENODEV;
  844. }
  845. if (slave_dev) {
  846. if (!netif_is_bond_slave(slave_dev)) {
  847. slave_err(bond->dev, slave_dev, "Device is not bonding slave\n");
  848. return -EINVAL;
  849. }
  850. if (bond->dev != netdev_master_upper_dev_get(slave_dev)) {
  851. slave_err(bond->dev, slave_dev, "Device is not our slave\n");
  852. return -EINVAL;
  853. }
  854. }
  855. block_netpoll_tx();
  856. /* check to see if we are clearing active */
  857. if (!slave_dev) {
  858. netdev_dbg(bond->dev, "Clearing current active slave\n");
  859. bond_change_active_slave(bond, NULL);
  860. bond_select_active_slave(bond);
  861. } else {
  862. struct slave *old_active = rtnl_dereference(bond->curr_active_slave);
  863. struct slave *new_active = bond_slave_get_rtnl(slave_dev);
  864. BUG_ON(!new_active);
  865. if (new_active == old_active) {
  866. /* do nothing */
  867. slave_dbg(bond->dev, new_active->dev, "is already the current active slave\n");
  868. } else {
  869. if (old_active && (new_active->link == BOND_LINK_UP) &&
  870. bond_slave_is_up(new_active)) {
  871. slave_dbg(bond->dev, new_active->dev, "Setting as active slave\n");
  872. bond_change_active_slave(bond, new_active);
  873. } else {
  874. slave_err(bond->dev, new_active->dev, "Could not set as active slave; either %s is down or the link is down\n",
  875. new_active->dev->name);
  876. ret = -EINVAL;
  877. }
  878. }
  879. }
  880. unblock_netpoll_tx();
  881. return ret;
  882. }
  883. /* There are two tricky bits here. First, if MII monitoring is activated, then
  884. * we must disable ARP monitoring. Second, if the timer isn't running, we must
  885. * start it.
  886. */
  887. static int bond_option_miimon_set(struct bonding *bond,
  888. const struct bond_opt_value *newval)
  889. {
  890. netdev_dbg(bond->dev, "Setting MII monitoring interval to %llu\n",
  891. newval->value);
  892. bond->params.miimon = newval->value;
  893. if (bond->params.updelay)
  894. netdev_dbg(bond->dev, "Note: Updating updelay (to %d) since it is a multiple of the miimon value\n",
  895. bond->params.updelay * bond->params.miimon);
  896. if (bond->params.downdelay)
  897. netdev_dbg(bond->dev, "Note: Updating downdelay (to %d) since it is a multiple of the miimon value\n",
  898. bond->params.downdelay * bond->params.miimon);
  899. if (bond->params.peer_notif_delay)
  900. netdev_dbg(bond->dev, "Note: Updating peer_notif_delay (to %d) since it is a multiple of the miimon value\n",
  901. bond->params.peer_notif_delay * bond->params.miimon);
  902. if (newval->value && bond->params.arp_interval) {
  903. netdev_dbg(bond->dev, "MII monitoring cannot be used with ARP monitoring - disabling ARP monitoring...\n");
  904. bond->params.arp_interval = 0;
  905. if (bond->params.arp_validate)
  906. bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
  907. }
  908. if (bond->dev->flags & IFF_UP) {
  909. /* If the interface is up, we may need to fire off
  910. * the MII timer. If the interface is down, the
  911. * timer will get fired off when the open function
  912. * is called.
  913. */
  914. if (!newval->value) {
  915. cancel_delayed_work_sync(&bond->mii_work);
  916. } else {
  917. cancel_delayed_work_sync(&bond->arp_work);
  918. queue_delayed_work(bond->wq, &bond->mii_work, 0);
  919. }
  920. }
  921. return 0;
  922. }
  923. /* Set up, down and peer notification delays. These must be multiples
  924. * of the MII monitoring value, and are stored internally as the
  925. * multiplier. Thus, we must translate to MS for the real world.
  926. */
  927. static int _bond_option_delay_set(struct bonding *bond,
  928. const struct bond_opt_value *newval,
  929. const char *name,
  930. int *target)
  931. {
  932. int value = newval->value;
  933. if (!bond->params.miimon) {
  934. netdev_err(bond->dev, "Unable to set %s as MII monitoring is disabled\n",
  935. name);
  936. return -EPERM;
  937. }
  938. if ((value % bond->params.miimon) != 0) {
  939. netdev_warn(bond->dev,
  940. "%s (%d) is not a multiple of miimon (%d), value rounded to %d ms\n",
  941. name,
  942. value, bond->params.miimon,
  943. (value / bond->params.miimon) *
  944. bond->params.miimon);
  945. }
  946. *target = value / bond->params.miimon;
  947. netdev_dbg(bond->dev, "Setting %s to %d\n",
  948. name,
  949. *target * bond->params.miimon);
  950. return 0;
  951. }
  952. static int bond_option_updelay_set(struct bonding *bond,
  953. const struct bond_opt_value *newval)
  954. {
  955. return _bond_option_delay_set(bond, newval, "up delay",
  956. &bond->params.updelay);
  957. }
  958. static int bond_option_downdelay_set(struct bonding *bond,
  959. const struct bond_opt_value *newval)
  960. {
  961. return _bond_option_delay_set(bond, newval, "down delay",
  962. &bond->params.downdelay);
  963. }
  964. static int bond_option_peer_notif_delay_set(struct bonding *bond,
  965. const struct bond_opt_value *newval)
  966. {
  967. int ret = _bond_option_delay_set(bond, newval,
  968. "peer notification delay",
  969. &bond->params.peer_notif_delay);
  970. return ret;
  971. }
  972. static int bond_option_use_carrier_set(struct bonding *bond,
  973. const struct bond_opt_value *newval)
  974. {
  975. netdev_dbg(bond->dev, "Setting use_carrier to %llu\n",
  976. newval->value);
  977. bond->params.use_carrier = newval->value;
  978. return 0;
  979. }
  980. /* There are two tricky bits here. First, if ARP monitoring is activated, then
  981. * we must disable MII monitoring. Second, if the ARP timer isn't running,
  982. * we must start it.
  983. */
  984. static int bond_option_arp_interval_set(struct bonding *bond,
  985. const struct bond_opt_value *newval)
  986. {
  987. netdev_dbg(bond->dev, "Setting ARP monitoring interval to %llu\n",
  988. newval->value);
  989. bond->params.arp_interval = newval->value;
  990. if (newval->value) {
  991. if (bond->params.miimon) {
  992. netdev_dbg(bond->dev, "ARP monitoring cannot be used with MII monitoring. Disabling MII monitoring\n");
  993. bond->params.miimon = 0;
  994. }
  995. if (!bond->params.arp_targets[0])
  996. netdev_dbg(bond->dev, "ARP monitoring has been set up, but no ARP targets have been specified\n");
  997. }
  998. if (bond->dev->flags & IFF_UP) {
  999. /* If the interface is up, we may need to fire off
  1000. * the ARP timer. If the interface is down, the
  1001. * timer will get fired off when the open function
  1002. * is called.
  1003. */
  1004. if (!newval->value) {
  1005. if (bond->params.arp_validate)
  1006. bond->recv_probe = NULL;
  1007. cancel_delayed_work_sync(&bond->arp_work);
  1008. } else {
  1009. /* arp_validate can be set only in active-backup mode */
  1010. bond->recv_probe = bond_rcv_validate;
  1011. cancel_delayed_work_sync(&bond->mii_work);
  1012. queue_delayed_work(bond->wq, &bond->arp_work, 0);
  1013. }
  1014. }
  1015. return 0;
  1016. }
  1017. static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot,
  1018. __be32 target,
  1019. unsigned long last_rx)
  1020. {
  1021. __be32 *targets = bond->params.arp_targets;
  1022. struct list_head *iter;
  1023. struct slave *slave;
  1024. if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) {
  1025. bond_for_each_slave(bond, slave, iter)
  1026. slave->target_last_arp_rx[slot] = last_rx;
  1027. targets[slot] = target;
  1028. }
  1029. }
  1030. static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
  1031. {
  1032. __be32 *targets = bond->params.arp_targets;
  1033. int ind;
  1034. if (!bond_is_ip_target_ok(target)) {
  1035. netdev_err(bond->dev, "invalid ARP target %pI4 specified for addition\n",
  1036. &target);
  1037. return -EINVAL;
  1038. }
  1039. if (bond_get_targets_ip(targets, target) != -1) { /* dup */
  1040. netdev_err(bond->dev, "ARP target %pI4 is already present\n",
  1041. &target);
  1042. return -EINVAL;
  1043. }
  1044. ind = bond_get_targets_ip(targets, 0); /* first free slot */
  1045. if (ind == -1) {
  1046. netdev_err(bond->dev, "ARP target table is full!\n");
  1047. return -EINVAL;
  1048. }
  1049. netdev_dbg(bond->dev, "Adding ARP target %pI4\n", &target);
  1050. _bond_options_arp_ip_target_set(bond, ind, target, jiffies);
  1051. return 0;
  1052. }
  1053. static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
  1054. {
  1055. return _bond_option_arp_ip_target_add(bond, target);
  1056. }
  1057. static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target)
  1058. {
  1059. __be32 *targets = bond->params.arp_targets;
  1060. struct list_head *iter;
  1061. struct slave *slave;
  1062. unsigned long *targets_rx;
  1063. int ind, i;
  1064. if (!bond_is_ip_target_ok(target)) {
  1065. netdev_err(bond->dev, "invalid ARP target %pI4 specified for removal\n",
  1066. &target);
  1067. return -EINVAL;
  1068. }
  1069. ind = bond_get_targets_ip(targets, target);
  1070. if (ind == -1) {
  1071. netdev_err(bond->dev, "unable to remove nonexistent ARP target %pI4\n",
  1072. &target);
  1073. return -EINVAL;
  1074. }
  1075. if (ind == 0 && !targets[1] && bond->params.arp_interval)
  1076. netdev_warn(bond->dev, "Removing last arp target with arp_interval on\n");
  1077. netdev_dbg(bond->dev, "Removing ARP target %pI4\n", &target);
  1078. bond_for_each_slave(bond, slave, iter) {
  1079. targets_rx = slave->target_last_arp_rx;
  1080. for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
  1081. targets_rx[i] = targets_rx[i+1];
  1082. targets_rx[i] = 0;
  1083. }
  1084. for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
  1085. targets[i] = targets[i+1];
  1086. targets[i] = 0;
  1087. return 0;
  1088. }
  1089. void bond_option_arp_ip_targets_clear(struct bonding *bond)
  1090. {
  1091. int i;
  1092. for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
  1093. _bond_options_arp_ip_target_set(bond, i, 0, 0);
  1094. }
  1095. static int bond_option_arp_ip_targets_set(struct bonding *bond,
  1096. const struct bond_opt_value *newval)
  1097. {
  1098. int ret = -EPERM;
  1099. __be32 target;
  1100. if (newval->string) {
  1101. if (strlen(newval->string) < 1 ||
  1102. !in4_pton(newval->string + 1, -1, (u8 *)&target, -1, NULL)) {
  1103. netdev_err(bond->dev, "invalid ARP target specified\n");
  1104. return ret;
  1105. }
  1106. if (newval->string[0] == '+')
  1107. ret = bond_option_arp_ip_target_add(bond, target);
  1108. else if (newval->string[0] == '-')
  1109. ret = bond_option_arp_ip_target_rem(bond, target);
  1110. else
  1111. netdev_err(bond->dev, "no command found in arp_ip_targets file - use +<addr> or -<addr>\n");
  1112. } else {
  1113. target = newval->value;
  1114. ret = bond_option_arp_ip_target_add(bond, target);
  1115. }
  1116. return ret;
  1117. }
  1118. #if IS_ENABLED(CONFIG_IPV6)
  1119. static bool slave_can_set_ns_maddr(const struct bonding *bond, struct slave *slave)
  1120. {
  1121. return BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP &&
  1122. !bond_is_active_slave(slave) &&
  1123. slave->dev->flags & IFF_MULTICAST;
  1124. }
  1125. /**
  1126. * slave_set_ns_maddrs - add/del all NS mac addresses for slave
  1127. * @bond: bond device
  1128. * @slave: slave device
  1129. * @add: add or remove all the NS mac addresses
  1130. *
  1131. * This function tries to add or delete all the NS mac addresses on the slave
  1132. *
  1133. * Note, the IPv6 NS target address is the unicast address in Neighbor
  1134. * Solicitation (NS) message. The dest address of NS message should be
  1135. * solicited-node multicast address of the target. The dest mac of NS message
  1136. * is converted from the solicited-node multicast address.
  1137. *
  1138. * This function is called when
  1139. * * arp_validate changes
  1140. * * enslaving, releasing new slaves
  1141. */
  1142. static void slave_set_ns_maddrs(struct bonding *bond, struct slave *slave, bool add)
  1143. {
  1144. struct in6_addr *targets = bond->params.ns_targets;
  1145. char slot_maddr[MAX_ADDR_LEN];
  1146. struct in6_addr mcaddr;
  1147. int i;
  1148. if (!slave_can_set_ns_maddr(bond, slave))
  1149. return;
  1150. for (i = 0; i < BOND_MAX_NS_TARGETS; i++) {
  1151. if (ipv6_addr_any(&targets[i]))
  1152. break;
  1153. addrconf_addr_solict_mult(&targets[i], &mcaddr);
  1154. if (!ndisc_mc_map(&mcaddr, slot_maddr, slave->dev, 0)) {
  1155. if (add)
  1156. dev_mc_add(slave->dev, slot_maddr);
  1157. else
  1158. dev_mc_del(slave->dev, slot_maddr);
  1159. }
  1160. }
  1161. }
  1162. void bond_slave_ns_maddrs_add(struct bonding *bond, struct slave *slave)
  1163. {
  1164. if (!bond->params.arp_validate)
  1165. return;
  1166. slave_set_ns_maddrs(bond, slave, true);
  1167. }
  1168. void bond_slave_ns_maddrs_del(struct bonding *bond, struct slave *slave)
  1169. {
  1170. if (!bond->params.arp_validate)
  1171. return;
  1172. slave_set_ns_maddrs(bond, slave, false);
  1173. }
  1174. /**
  1175. * slave_set_ns_maddr - set new NS mac address for slave
  1176. * @bond: bond device
  1177. * @slave: slave device
  1178. * @target: the new IPv6 target
  1179. * @slot: the old IPv6 target in the slot
  1180. *
  1181. * This function tries to replace the old mac address to new one on the slave.
  1182. *
  1183. * Note, the target/slot IPv6 address is the unicast address in Neighbor
  1184. * Solicitation (NS) message. The dest address of NS message should be
  1185. * solicited-node multicast address of the target. The dest mac of NS message
  1186. * is converted from the solicited-node multicast address.
  1187. *
  1188. * This function is called when
  1189. * * An IPv6 NS target is added or removed.
  1190. */
  1191. static void slave_set_ns_maddr(struct bonding *bond, struct slave *slave,
  1192. struct in6_addr *target, struct in6_addr *slot)
  1193. {
  1194. char mac_addr[MAX_ADDR_LEN];
  1195. struct in6_addr mcast_addr;
  1196. if (!bond->params.arp_validate || !slave_can_set_ns_maddr(bond, slave))
  1197. return;
  1198. /* remove the previous mac addr from slave */
  1199. addrconf_addr_solict_mult(slot, &mcast_addr);
  1200. if (!ipv6_addr_any(slot) &&
  1201. !ndisc_mc_map(&mcast_addr, mac_addr, slave->dev, 0))
  1202. dev_mc_del(slave->dev, mac_addr);
  1203. /* add new mac addr on slave if target is set */
  1204. addrconf_addr_solict_mult(target, &mcast_addr);
  1205. if (!ipv6_addr_any(target) &&
  1206. !ndisc_mc_map(&mcast_addr, mac_addr, slave->dev, 0))
  1207. dev_mc_add(slave->dev, mac_addr);
  1208. }
  1209. static void _bond_options_ns_ip6_target_set(struct bonding *bond, int slot,
  1210. struct in6_addr *target,
  1211. unsigned long last_rx)
  1212. {
  1213. struct in6_addr *targets = bond->params.ns_targets;
  1214. struct list_head *iter;
  1215. struct slave *slave;
  1216. if (slot >= 0 && slot < BOND_MAX_NS_TARGETS) {
  1217. bond_for_each_slave(bond, slave, iter) {
  1218. slave->target_last_arp_rx[slot] = last_rx;
  1219. slave_set_ns_maddr(bond, slave, target, &targets[slot]);
  1220. }
  1221. targets[slot] = *target;
  1222. }
  1223. }
  1224. void bond_option_ns_ip6_targets_clear(struct bonding *bond)
  1225. {
  1226. struct in6_addr addr_any = in6addr_any;
  1227. int i;
  1228. for (i = 0; i < BOND_MAX_NS_TARGETS; i++)
  1229. _bond_options_ns_ip6_target_set(bond, i, &addr_any, 0);
  1230. }
  1231. static int bond_option_ns_ip6_targets_set(struct bonding *bond,
  1232. const struct bond_opt_value *newval)
  1233. {
  1234. struct in6_addr *target = (struct in6_addr *)newval->extra;
  1235. struct in6_addr *targets = bond->params.ns_targets;
  1236. struct in6_addr addr_any = in6addr_any;
  1237. int index;
  1238. if (!bond_is_ip6_target_ok(target)) {
  1239. netdev_err(bond->dev, "invalid NS target %pI6c specified for addition\n",
  1240. target);
  1241. return -EINVAL;
  1242. }
  1243. if (bond_get_targets_ip6(targets, target) != -1) { /* dup */
  1244. netdev_err(bond->dev, "NS target %pI6c is already present\n",
  1245. target);
  1246. return -EINVAL;
  1247. }
  1248. index = bond_get_targets_ip6(targets, &addr_any); /* first free slot */
  1249. if (index == -1) {
  1250. netdev_err(bond->dev, "NS target table is full!\n");
  1251. return -EINVAL;
  1252. }
  1253. netdev_dbg(bond->dev, "Adding NS target %pI6c\n", target);
  1254. _bond_options_ns_ip6_target_set(bond, index, target, jiffies);
  1255. return 0;
  1256. }
  1257. #else
  1258. static int bond_option_ns_ip6_targets_set(struct bonding *bond,
  1259. const struct bond_opt_value *newval)
  1260. {
  1261. return -EPERM;
  1262. }
  1263. static void slave_set_ns_maddrs(struct bonding *bond, struct slave *slave, bool add) {}
  1264. void bond_slave_ns_maddrs_add(struct bonding *bond, struct slave *slave) {}
  1265. void bond_slave_ns_maddrs_del(struct bonding *bond, struct slave *slave) {}
  1266. #endif
  1267. static int bond_option_arp_validate_set(struct bonding *bond,
  1268. const struct bond_opt_value *newval)
  1269. {
  1270. bool changed = !!bond->params.arp_validate != !!newval->value;
  1271. struct list_head *iter;
  1272. struct slave *slave;
  1273. netdev_dbg(bond->dev, "Setting arp_validate to %s (%llu)\n",
  1274. newval->string, newval->value);
  1275. bond->params.arp_validate = newval->value;
  1276. if (changed) {
  1277. bond_for_each_slave(bond, slave, iter)
  1278. slave_set_ns_maddrs(bond, slave, !!bond->params.arp_validate);
  1279. }
  1280. return 0;
  1281. }
  1282. static int bond_option_arp_all_targets_set(struct bonding *bond,
  1283. const struct bond_opt_value *newval)
  1284. {
  1285. netdev_dbg(bond->dev, "Setting arp_all_targets to %s (%llu)\n",
  1286. newval->string, newval->value);
  1287. bond->params.arp_all_targets = newval->value;
  1288. return 0;
  1289. }
  1290. static int bond_option_missed_max_set(struct bonding *bond,
  1291. const struct bond_opt_value *newval)
  1292. {
  1293. netdev_dbg(bond->dev, "Setting missed max to %s (%llu)\n",
  1294. newval->string, newval->value);
  1295. bond->params.missed_max = newval->value;
  1296. return 0;
  1297. }
  1298. static int bond_option_prio_set(struct bonding *bond,
  1299. const struct bond_opt_value *newval)
  1300. {
  1301. struct slave *slave;
  1302. slave = bond_slave_get_rtnl(newval->slave_dev);
  1303. if (!slave) {
  1304. netdev_dbg(newval->slave_dev, "%s called on NULL slave\n", __func__);
  1305. return -ENODEV;
  1306. }
  1307. slave->prio = newval->value;
  1308. if (rtnl_dereference(bond->primary_slave))
  1309. slave_warn(bond->dev, slave->dev,
  1310. "prio updated, but will not affect failover re-selection as primary slave have been set\n");
  1311. else
  1312. bond_select_active_slave(bond);
  1313. return 0;
  1314. }
  1315. static int bond_option_primary_set(struct bonding *bond,
  1316. const struct bond_opt_value *newval)
  1317. {
  1318. char *p, *primary = newval->string;
  1319. struct list_head *iter;
  1320. struct slave *slave;
  1321. block_netpoll_tx();
  1322. p = strchr(primary, '\n');
  1323. if (p)
  1324. *p = '\0';
  1325. /* check to see if we are clearing primary */
  1326. if (!strlen(primary)) {
  1327. netdev_dbg(bond->dev, "Setting primary slave to None\n");
  1328. RCU_INIT_POINTER(bond->primary_slave, NULL);
  1329. memset(bond->params.primary, 0, sizeof(bond->params.primary));
  1330. bond_select_active_slave(bond);
  1331. goto out;
  1332. }
  1333. bond_for_each_slave(bond, slave, iter) {
  1334. if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) {
  1335. slave_dbg(bond->dev, slave->dev, "Setting as primary slave\n");
  1336. rcu_assign_pointer(bond->primary_slave, slave);
  1337. strcpy(bond->params.primary, slave->dev->name);
  1338. bond->force_primary = true;
  1339. bond_select_active_slave(bond);
  1340. goto out;
  1341. }
  1342. }
  1343. if (rtnl_dereference(bond->primary_slave)) {
  1344. netdev_dbg(bond->dev, "Setting primary slave to None\n");
  1345. RCU_INIT_POINTER(bond->primary_slave, NULL);
  1346. bond_select_active_slave(bond);
  1347. }
  1348. strscpy_pad(bond->params.primary, primary, IFNAMSIZ);
  1349. netdev_dbg(bond->dev, "Recording %s as primary, but it has not been enslaved yet\n",
  1350. primary);
  1351. out:
  1352. unblock_netpoll_tx();
  1353. return 0;
  1354. }
  1355. static int bond_option_primary_reselect_set(struct bonding *bond,
  1356. const struct bond_opt_value *newval)
  1357. {
  1358. netdev_dbg(bond->dev, "Setting primary_reselect to %s (%llu)\n",
  1359. newval->string, newval->value);
  1360. bond->params.primary_reselect = newval->value;
  1361. block_netpoll_tx();
  1362. bond_select_active_slave(bond);
  1363. unblock_netpoll_tx();
  1364. return 0;
  1365. }
  1366. static int bond_option_fail_over_mac_set(struct bonding *bond,
  1367. const struct bond_opt_value *newval)
  1368. {
  1369. netdev_dbg(bond->dev, "Setting fail_over_mac to %s (%llu)\n",
  1370. newval->string, newval->value);
  1371. bond->params.fail_over_mac = newval->value;
  1372. return 0;
  1373. }
  1374. static int bond_option_xmit_hash_policy_set(struct bonding *bond,
  1375. const struct bond_opt_value *newval)
  1376. {
  1377. netdev_dbg(bond->dev, "Setting xmit hash policy to %s (%llu)\n",
  1378. newval->string, newval->value);
  1379. bond->params.xmit_policy = newval->value;
  1380. return 0;
  1381. }
  1382. static int bond_option_resend_igmp_set(struct bonding *bond,
  1383. const struct bond_opt_value *newval)
  1384. {
  1385. netdev_dbg(bond->dev, "Setting resend_igmp to %llu\n",
  1386. newval->value);
  1387. bond->params.resend_igmp = newval->value;
  1388. return 0;
  1389. }
  1390. static int bond_option_num_peer_notif_set(struct bonding *bond,
  1391. const struct bond_opt_value *newval)
  1392. {
  1393. bond->params.num_peer_notif = newval->value;
  1394. return 0;
  1395. }
  1396. static int bond_option_all_slaves_active_set(struct bonding *bond,
  1397. const struct bond_opt_value *newval)
  1398. {
  1399. struct list_head *iter;
  1400. struct slave *slave;
  1401. if (newval->value == bond->params.all_slaves_active)
  1402. return 0;
  1403. bond->params.all_slaves_active = newval->value;
  1404. bond_for_each_slave(bond, slave, iter) {
  1405. if (!bond_is_active_slave(slave)) {
  1406. if (newval->value)
  1407. slave->inactive = 0;
  1408. else
  1409. slave->inactive = 1;
  1410. }
  1411. }
  1412. return 0;
  1413. }
  1414. static int bond_option_min_links_set(struct bonding *bond,
  1415. const struct bond_opt_value *newval)
  1416. {
  1417. netdev_dbg(bond->dev, "Setting min links value to %llu\n",
  1418. newval->value);
  1419. bond->params.min_links = newval->value;
  1420. bond_set_carrier(bond);
  1421. return 0;
  1422. }
  1423. static int bond_option_lp_interval_set(struct bonding *bond,
  1424. const struct bond_opt_value *newval)
  1425. {
  1426. bond->params.lp_interval = newval->value;
  1427. return 0;
  1428. }
  1429. static int bond_option_pps_set(struct bonding *bond,
  1430. const struct bond_opt_value *newval)
  1431. {
  1432. netdev_dbg(bond->dev, "Setting packets per slave to %llu\n",
  1433. newval->value);
  1434. bond->params.packets_per_slave = newval->value;
  1435. if (newval->value > 0) {
  1436. bond->params.reciprocal_packets_per_slave =
  1437. reciprocal_value(newval->value);
  1438. } else {
  1439. /* reciprocal_packets_per_slave is unused if
  1440. * packets_per_slave is 0 or 1, just initialize it
  1441. */
  1442. bond->params.reciprocal_packets_per_slave =
  1443. (struct reciprocal_value) { 0 };
  1444. }
  1445. return 0;
  1446. }
  1447. static int bond_option_lacp_active_set(struct bonding *bond,
  1448. const struct bond_opt_value *newval)
  1449. {
  1450. netdev_dbg(bond->dev, "Setting LACP active to %s (%llu)\n",
  1451. newval->string, newval->value);
  1452. bond->params.lacp_active = newval->value;
  1453. bond_3ad_update_lacp_active(bond);
  1454. return 0;
  1455. }
  1456. static int bond_option_lacp_rate_set(struct bonding *bond,
  1457. const struct bond_opt_value *newval)
  1458. {
  1459. netdev_dbg(bond->dev, "Setting LACP rate to %s (%llu)\n",
  1460. newval->string, newval->value);
  1461. bond->params.lacp_fast = newval->value;
  1462. bond_3ad_update_lacp_rate(bond);
  1463. return 0;
  1464. }
  1465. static int bond_option_ad_select_set(struct bonding *bond,
  1466. const struct bond_opt_value *newval)
  1467. {
  1468. netdev_dbg(bond->dev, "Setting ad_select to %s (%llu)\n",
  1469. newval->string, newval->value);
  1470. bond->params.ad_select = newval->value;
  1471. return 0;
  1472. }
  1473. static int bond_option_queue_id_set(struct bonding *bond,
  1474. const struct bond_opt_value *newval)
  1475. {
  1476. struct slave *slave, *update_slave;
  1477. struct net_device *sdev;
  1478. struct list_head *iter;
  1479. char *delim;
  1480. int ret = 0;
  1481. u16 qid;
  1482. /* delim will point to queue id if successful */
  1483. delim = strchr(newval->string, ':');
  1484. if (!delim)
  1485. goto err_no_cmd;
  1486. /* Terminate string that points to device name and bump it
  1487. * up one, so we can read the queue id there.
  1488. */
  1489. *delim = '\0';
  1490. if (sscanf(++delim, "%hd\n", &qid) != 1)
  1491. goto err_no_cmd;
  1492. /* Check buffer length, valid ifname and queue id */
  1493. if (!dev_valid_name(newval->string) ||
  1494. qid > bond->dev->real_num_tx_queues)
  1495. goto err_no_cmd;
  1496. /* Get the pointer to that interface if it exists */
  1497. sdev = __dev_get_by_name(dev_net(bond->dev), newval->string);
  1498. if (!sdev)
  1499. goto err_no_cmd;
  1500. /* Search for thes slave and check for duplicate qids */
  1501. update_slave = NULL;
  1502. bond_for_each_slave(bond, slave, iter) {
  1503. if (sdev == slave->dev)
  1504. /* We don't need to check the matching
  1505. * slave for dups, since we're overwriting it
  1506. */
  1507. update_slave = slave;
  1508. else if (qid && qid == slave->queue_id) {
  1509. goto err_no_cmd;
  1510. }
  1511. }
  1512. if (!update_slave)
  1513. goto err_no_cmd;
  1514. /* Actually set the qids for the slave */
  1515. WRITE_ONCE(update_slave->queue_id, qid);
  1516. out:
  1517. return ret;
  1518. err_no_cmd:
  1519. netdev_dbg(bond->dev, "invalid input for queue_id set\n");
  1520. ret = -EPERM;
  1521. goto out;
  1522. }
  1523. static int bond_option_slaves_set(struct bonding *bond,
  1524. const struct bond_opt_value *newval)
  1525. {
  1526. char command[IFNAMSIZ + 1] = { 0, };
  1527. struct net_device *dev;
  1528. char *ifname;
  1529. int ret;
  1530. sscanf(newval->string, "%16s", command); /* IFNAMSIZ*/
  1531. ifname = command + 1;
  1532. if ((strlen(command) <= 1) ||
  1533. (command[0] != '+' && command[0] != '-') ||
  1534. !dev_valid_name(ifname))
  1535. goto err_no_cmd;
  1536. dev = __dev_get_by_name(dev_net(bond->dev), ifname);
  1537. if (!dev) {
  1538. netdev_dbg(bond->dev, "interface %s does not exist!\n",
  1539. ifname);
  1540. ret = -ENODEV;
  1541. goto out;
  1542. }
  1543. switch (command[0]) {
  1544. case '+':
  1545. slave_dbg(bond->dev, dev, "Enslaving interface\n");
  1546. ret = bond_enslave(bond->dev, dev, NULL);
  1547. break;
  1548. case '-':
  1549. slave_dbg(bond->dev, dev, "Releasing interface\n");
  1550. ret = bond_release(bond->dev, dev);
  1551. break;
  1552. default:
  1553. /* should not run here. */
  1554. goto err_no_cmd;
  1555. }
  1556. out:
  1557. return ret;
  1558. err_no_cmd:
  1559. netdev_err(bond->dev, "no command found in slaves file - use +ifname or -ifname\n");
  1560. ret = -EPERM;
  1561. goto out;
  1562. }
  1563. static int bond_option_tlb_dynamic_lb_set(struct bonding *bond,
  1564. const struct bond_opt_value *newval)
  1565. {
  1566. netdev_dbg(bond->dev, "Setting dynamic-lb to %s (%llu)\n",
  1567. newval->string, newval->value);
  1568. bond->params.tlb_dynamic_lb = newval->value;
  1569. return 0;
  1570. }
  1571. static int bond_option_ad_actor_sys_prio_set(struct bonding *bond,
  1572. const struct bond_opt_value *newval)
  1573. {
  1574. netdev_dbg(bond->dev, "Setting ad_actor_sys_prio to %llu\n",
  1575. newval->value);
  1576. bond->params.ad_actor_sys_prio = newval->value;
  1577. bond_3ad_update_ad_actor_settings(bond);
  1578. return 0;
  1579. }
  1580. static int bond_option_ad_actor_system_set(struct bonding *bond,
  1581. const struct bond_opt_value *newval)
  1582. {
  1583. u8 macaddr[ETH_ALEN];
  1584. u8 *mac;
  1585. if (newval->string) {
  1586. if (!mac_pton(newval->string, macaddr))
  1587. goto err;
  1588. mac = macaddr;
  1589. } else {
  1590. mac = (u8 *)&newval->value;
  1591. }
  1592. if (is_multicast_ether_addr(mac))
  1593. goto err;
  1594. netdev_dbg(bond->dev, "Setting ad_actor_system to %pM\n", mac);
  1595. ether_addr_copy(bond->params.ad_actor_system, mac);
  1596. bond_3ad_update_ad_actor_settings(bond);
  1597. return 0;
  1598. err:
  1599. netdev_err(bond->dev, "Invalid ad_actor_system MAC address.\n");
  1600. return -EINVAL;
  1601. }
  1602. static int bond_option_ad_user_port_key_set(struct bonding *bond,
  1603. const struct bond_opt_value *newval)
  1604. {
  1605. netdev_dbg(bond->dev, "Setting ad_user_port_key to %llu\n",
  1606. newval->value);
  1607. bond->params.ad_user_port_key = newval->value;
  1608. return 0;
  1609. }
  1610. static int bond_option_coupled_control_set(struct bonding *bond,
  1611. const struct bond_opt_value *newval)
  1612. {
  1613. netdev_info(bond->dev, "Setting coupled_control to %s (%llu)\n",
  1614. newval->string, newval->value);
  1615. bond->params.coupled_control = newval->value;
  1616. return 0;
  1617. }