bond_options.c 42 KB

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