bond_options.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  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_info(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_info(bond->dev, "Setting MII monitoring interval to %d\n",
  692. bond->params.miimon);
  693. }
  694. /* don't cache arp_validate between modes */
  695. bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
  696. bond->params.mode = newval->value;
  697. return 0;
  698. }
  699. static int bond_option_active_slave_set(struct bonding *bond,
  700. const struct bond_opt_value *newval)
  701. {
  702. char ifname[IFNAMSIZ] = { 0, };
  703. struct net_device *slave_dev;
  704. int ret = 0;
  705. sscanf(newval->string, "%15s", ifname); /* IFNAMSIZ */
  706. if (!strlen(ifname) || newval->string[0] == '\n') {
  707. slave_dev = NULL;
  708. } else {
  709. slave_dev = __dev_get_by_name(dev_net(bond->dev), ifname);
  710. if (!slave_dev)
  711. return -ENODEV;
  712. }
  713. if (slave_dev) {
  714. if (!netif_is_bond_slave(slave_dev)) {
  715. netdev_err(bond->dev, "Device %s is not bonding slave\n",
  716. slave_dev->name);
  717. return -EINVAL;
  718. }
  719. if (bond->dev != netdev_master_upper_dev_get(slave_dev)) {
  720. netdev_err(bond->dev, "Device %s is not our slave\n",
  721. slave_dev->name);
  722. return -EINVAL;
  723. }
  724. }
  725. block_netpoll_tx();
  726. /* check to see if we are clearing active */
  727. if (!slave_dev) {
  728. netdev_info(bond->dev, "Clearing current active slave\n");
  729. RCU_INIT_POINTER(bond->curr_active_slave, NULL);
  730. bond_select_active_slave(bond);
  731. } else {
  732. struct slave *old_active = rtnl_dereference(bond->curr_active_slave);
  733. struct slave *new_active = bond_slave_get_rtnl(slave_dev);
  734. BUG_ON(!new_active);
  735. if (new_active == old_active) {
  736. /* do nothing */
  737. netdev_info(bond->dev, "%s is already the current active slave\n",
  738. new_active->dev->name);
  739. } else {
  740. if (old_active && (new_active->link == BOND_LINK_UP) &&
  741. bond_slave_is_up(new_active)) {
  742. netdev_info(bond->dev, "Setting %s as active slave\n",
  743. new_active->dev->name);
  744. bond_change_active_slave(bond, new_active);
  745. } else {
  746. netdev_err(bond->dev, "Could not set %s as active slave; either %s is down or the link is down\n",
  747. new_active->dev->name,
  748. new_active->dev->name);
  749. ret = -EINVAL;
  750. }
  751. }
  752. }
  753. unblock_netpoll_tx();
  754. return ret;
  755. }
  756. /* There are two tricky bits here. First, if MII monitoring is activated, then
  757. * we must disable ARP monitoring. Second, if the timer isn't running, we must
  758. * start it.
  759. */
  760. static int bond_option_miimon_set(struct bonding *bond,
  761. const struct bond_opt_value *newval)
  762. {
  763. netdev_info(bond->dev, "Setting MII monitoring interval to %llu\n",
  764. newval->value);
  765. bond->params.miimon = newval->value;
  766. if (bond->params.updelay)
  767. netdev_info(bond->dev, "Note: Updating updelay (to %d) since it is a multiple of the miimon value\n",
  768. bond->params.updelay * bond->params.miimon);
  769. if (bond->params.downdelay)
  770. netdev_info(bond->dev, "Note: Updating downdelay (to %d) since it is a multiple of the miimon value\n",
  771. bond->params.downdelay * bond->params.miimon);
  772. if (newval->value && bond->params.arp_interval) {
  773. netdev_info(bond->dev, "MII monitoring cannot be used with ARP monitoring - disabling ARP monitoring...\n");
  774. bond->params.arp_interval = 0;
  775. if (bond->params.arp_validate)
  776. bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
  777. }
  778. if (bond->dev->flags & IFF_UP) {
  779. /* If the interface is up, we may need to fire off
  780. * the MII timer. If the interface is down, the
  781. * timer will get fired off when the open function
  782. * is called.
  783. */
  784. if (!newval->value) {
  785. cancel_delayed_work_sync(&bond->mii_work);
  786. } else {
  787. cancel_delayed_work_sync(&bond->arp_work);
  788. queue_delayed_work(bond->wq, &bond->mii_work, 0);
  789. }
  790. }
  791. return 0;
  792. }
  793. /* Set up and down delays. These must be multiples of the
  794. * MII monitoring value, and are stored internally as the multiplier.
  795. * Thus, we must translate to MS for the real world.
  796. */
  797. static int bond_option_updelay_set(struct bonding *bond,
  798. const struct bond_opt_value *newval)
  799. {
  800. int value = newval->value;
  801. if (!bond->params.miimon) {
  802. netdev_err(bond->dev, "Unable to set up delay as MII monitoring is disabled\n");
  803. return -EPERM;
  804. }
  805. if ((value % bond->params.miimon) != 0) {
  806. netdev_warn(bond->dev, "up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
  807. value, bond->params.miimon,
  808. (value / bond->params.miimon) *
  809. bond->params.miimon);
  810. }
  811. bond->params.updelay = value / bond->params.miimon;
  812. netdev_info(bond->dev, "Setting up delay to %d\n",
  813. bond->params.updelay * bond->params.miimon);
  814. return 0;
  815. }
  816. static int bond_option_downdelay_set(struct bonding *bond,
  817. const struct bond_opt_value *newval)
  818. {
  819. int value = newval->value;
  820. if (!bond->params.miimon) {
  821. netdev_err(bond->dev, "Unable to set down delay as MII monitoring is disabled\n");
  822. return -EPERM;
  823. }
  824. if ((value % bond->params.miimon) != 0) {
  825. netdev_warn(bond->dev, "down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
  826. value, bond->params.miimon,
  827. (value / bond->params.miimon) *
  828. bond->params.miimon);
  829. }
  830. bond->params.downdelay = value / bond->params.miimon;
  831. netdev_info(bond->dev, "Setting down delay to %d\n",
  832. bond->params.downdelay * bond->params.miimon);
  833. return 0;
  834. }
  835. static int bond_option_use_carrier_set(struct bonding *bond,
  836. const struct bond_opt_value *newval)
  837. {
  838. netdev_info(bond->dev, "Setting use_carrier to %llu\n",
  839. newval->value);
  840. bond->params.use_carrier = newval->value;
  841. return 0;
  842. }
  843. /* There are two tricky bits here. First, if ARP monitoring is activated, then
  844. * we must disable MII monitoring. Second, if the ARP timer isn't running,
  845. * we must start it.
  846. */
  847. static int bond_option_arp_interval_set(struct bonding *bond,
  848. const struct bond_opt_value *newval)
  849. {
  850. netdev_info(bond->dev, "Setting ARP monitoring interval to %llu\n",
  851. newval->value);
  852. bond->params.arp_interval = newval->value;
  853. if (newval->value) {
  854. if (bond->params.miimon) {
  855. netdev_info(bond->dev, "ARP monitoring cannot be used with MII monitoring. Disabling MII monitoring\n");
  856. bond->params.miimon = 0;
  857. }
  858. if (!bond->params.arp_targets[0])
  859. netdev_info(bond->dev, "ARP monitoring has been set up, but no ARP targets have been specified\n");
  860. }
  861. if (bond->dev->flags & IFF_UP) {
  862. /* If the interface is up, we may need to fire off
  863. * the ARP timer. If the interface is down, the
  864. * timer will get fired off when the open function
  865. * is called.
  866. */
  867. if (!newval->value) {
  868. if (bond->params.arp_validate)
  869. bond->recv_probe = NULL;
  870. cancel_delayed_work_sync(&bond->arp_work);
  871. } else {
  872. /* arp_validate can be set only in active-backup mode */
  873. bond->recv_probe = bond_arp_rcv;
  874. cancel_delayed_work_sync(&bond->mii_work);
  875. queue_delayed_work(bond->wq, &bond->arp_work, 0);
  876. }
  877. }
  878. return 0;
  879. }
  880. static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot,
  881. __be32 target,
  882. unsigned long last_rx)
  883. {
  884. __be32 *targets = bond->params.arp_targets;
  885. struct list_head *iter;
  886. struct slave *slave;
  887. if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) {
  888. bond_for_each_slave(bond, slave, iter)
  889. slave->target_last_arp_rx[slot] = last_rx;
  890. targets[slot] = target;
  891. }
  892. }
  893. static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
  894. {
  895. __be32 *targets = bond->params.arp_targets;
  896. int ind;
  897. if (!bond_is_ip_target_ok(target)) {
  898. netdev_err(bond->dev, "invalid ARP target %pI4 specified for addition\n",
  899. &target);
  900. return -EINVAL;
  901. }
  902. if (bond_get_targets_ip(targets, target) != -1) { /* dup */
  903. netdev_err(bond->dev, "ARP target %pI4 is already present\n",
  904. &target);
  905. return -EINVAL;
  906. }
  907. ind = bond_get_targets_ip(targets, 0); /* first free slot */
  908. if (ind == -1) {
  909. netdev_err(bond->dev, "ARP target table is full!\n");
  910. return -EINVAL;
  911. }
  912. netdev_info(bond->dev, "Adding ARP target %pI4\n", &target);
  913. _bond_options_arp_ip_target_set(bond, ind, target, jiffies);
  914. return 0;
  915. }
  916. static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
  917. {
  918. return _bond_option_arp_ip_target_add(bond, target);
  919. }
  920. static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target)
  921. {
  922. __be32 *targets = bond->params.arp_targets;
  923. struct list_head *iter;
  924. struct slave *slave;
  925. unsigned long *targets_rx;
  926. int ind, i;
  927. if (!bond_is_ip_target_ok(target)) {
  928. netdev_err(bond->dev, "invalid ARP target %pI4 specified for removal\n",
  929. &target);
  930. return -EINVAL;
  931. }
  932. ind = bond_get_targets_ip(targets, target);
  933. if (ind == -1) {
  934. netdev_err(bond->dev, "unable to remove nonexistent ARP target %pI4\n",
  935. &target);
  936. return -EINVAL;
  937. }
  938. if (ind == 0 && !targets[1] && bond->params.arp_interval)
  939. netdev_warn(bond->dev, "Removing last arp target with arp_interval on\n");
  940. netdev_info(bond->dev, "Removing ARP target %pI4\n", &target);
  941. bond_for_each_slave(bond, slave, iter) {
  942. targets_rx = slave->target_last_arp_rx;
  943. for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
  944. targets_rx[i] = targets_rx[i+1];
  945. targets_rx[i] = 0;
  946. }
  947. for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
  948. targets[i] = targets[i+1];
  949. targets[i] = 0;
  950. return 0;
  951. }
  952. void bond_option_arp_ip_targets_clear(struct bonding *bond)
  953. {
  954. int i;
  955. for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
  956. _bond_options_arp_ip_target_set(bond, i, 0, 0);
  957. }
  958. static int bond_option_arp_ip_targets_set(struct bonding *bond,
  959. const struct bond_opt_value *newval)
  960. {
  961. int ret = -EPERM;
  962. __be32 target;
  963. if (newval->string) {
  964. if (!in4_pton(newval->string+1, -1, (u8 *)&target, -1, NULL)) {
  965. netdev_err(bond->dev, "invalid ARP target %pI4 specified\n",
  966. &target);
  967. return ret;
  968. }
  969. if (newval->string[0] == '+')
  970. ret = bond_option_arp_ip_target_add(bond, target);
  971. else if (newval->string[0] == '-')
  972. ret = bond_option_arp_ip_target_rem(bond, target);
  973. else
  974. netdev_err(bond->dev, "no command found in arp_ip_targets file - use +<addr> or -<addr>\n");
  975. } else {
  976. target = newval->value;
  977. ret = bond_option_arp_ip_target_add(bond, target);
  978. }
  979. return ret;
  980. }
  981. static int bond_option_arp_validate_set(struct bonding *bond,
  982. const struct bond_opt_value *newval)
  983. {
  984. netdev_info(bond->dev, "Setting arp_validate to %s (%llu)\n",
  985. newval->string, newval->value);
  986. if (bond->dev->flags & IFF_UP) {
  987. if (!newval->value)
  988. bond->recv_probe = NULL;
  989. else if (bond->params.arp_interval)
  990. bond->recv_probe = bond_arp_rcv;
  991. }
  992. bond->params.arp_validate = newval->value;
  993. return 0;
  994. }
  995. static int bond_option_arp_all_targets_set(struct bonding *bond,
  996. const struct bond_opt_value *newval)
  997. {
  998. netdev_info(bond->dev, "Setting arp_all_targets to %s (%llu)\n",
  999. newval->string, newval->value);
  1000. bond->params.arp_all_targets = newval->value;
  1001. return 0;
  1002. }
  1003. static int bond_option_primary_set(struct bonding *bond,
  1004. const struct bond_opt_value *newval)
  1005. {
  1006. char *p, *primary = newval->string;
  1007. struct list_head *iter;
  1008. struct slave *slave;
  1009. block_netpoll_tx();
  1010. p = strchr(primary, '\n');
  1011. if (p)
  1012. *p = '\0';
  1013. /* check to see if we are clearing primary */
  1014. if (!strlen(primary)) {
  1015. netdev_info(bond->dev, "Setting primary slave to None\n");
  1016. RCU_INIT_POINTER(bond->primary_slave, NULL);
  1017. memset(bond->params.primary, 0, sizeof(bond->params.primary));
  1018. bond_select_active_slave(bond);
  1019. goto out;
  1020. }
  1021. bond_for_each_slave(bond, slave, iter) {
  1022. if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) {
  1023. netdev_info(bond->dev, "Setting %s as primary slave\n",
  1024. slave->dev->name);
  1025. rcu_assign_pointer(bond->primary_slave, slave);
  1026. strcpy(bond->params.primary, slave->dev->name);
  1027. bond_select_active_slave(bond);
  1028. goto out;
  1029. }
  1030. }
  1031. if (rtnl_dereference(bond->primary_slave)) {
  1032. netdev_info(bond->dev, "Setting primary slave to None\n");
  1033. RCU_INIT_POINTER(bond->primary_slave, NULL);
  1034. bond_select_active_slave(bond);
  1035. }
  1036. strncpy(bond->params.primary, primary, IFNAMSIZ);
  1037. bond->params.primary[IFNAMSIZ - 1] = 0;
  1038. netdev_info(bond->dev, "Recording %s as primary, but it has not been enslaved to %s yet\n",
  1039. primary, bond->dev->name);
  1040. out:
  1041. unblock_netpoll_tx();
  1042. return 0;
  1043. }
  1044. static int bond_option_primary_reselect_set(struct bonding *bond,
  1045. const struct bond_opt_value *newval)
  1046. {
  1047. netdev_info(bond->dev, "Setting primary_reselect to %s (%llu)\n",
  1048. newval->string, newval->value);
  1049. bond->params.primary_reselect = newval->value;
  1050. block_netpoll_tx();
  1051. bond_select_active_slave(bond);
  1052. unblock_netpoll_tx();
  1053. return 0;
  1054. }
  1055. static int bond_option_fail_over_mac_set(struct bonding *bond,
  1056. const struct bond_opt_value *newval)
  1057. {
  1058. netdev_info(bond->dev, "Setting fail_over_mac to %s (%llu)\n",
  1059. newval->string, newval->value);
  1060. bond->params.fail_over_mac = newval->value;
  1061. return 0;
  1062. }
  1063. static int bond_option_xmit_hash_policy_set(struct bonding *bond,
  1064. const struct bond_opt_value *newval)
  1065. {
  1066. netdev_info(bond->dev, "Setting xmit hash policy to %s (%llu)\n",
  1067. newval->string, newval->value);
  1068. bond->params.xmit_policy = newval->value;
  1069. return 0;
  1070. }
  1071. static int bond_option_resend_igmp_set(struct bonding *bond,
  1072. const struct bond_opt_value *newval)
  1073. {
  1074. netdev_info(bond->dev, "Setting resend_igmp to %llu\n",
  1075. newval->value);
  1076. bond->params.resend_igmp = newval->value;
  1077. return 0;
  1078. }
  1079. static int bond_option_num_peer_notif_set(struct bonding *bond,
  1080. const struct bond_opt_value *newval)
  1081. {
  1082. bond->params.num_peer_notif = newval->value;
  1083. return 0;
  1084. }
  1085. static int bond_option_all_slaves_active_set(struct bonding *bond,
  1086. const struct bond_opt_value *newval)
  1087. {
  1088. struct list_head *iter;
  1089. struct slave *slave;
  1090. if (newval->value == bond->params.all_slaves_active)
  1091. return 0;
  1092. bond->params.all_slaves_active = newval->value;
  1093. bond_for_each_slave(bond, slave, iter) {
  1094. if (!bond_is_active_slave(slave)) {
  1095. if (newval->value)
  1096. slave->inactive = 0;
  1097. else
  1098. slave->inactive = 1;
  1099. }
  1100. }
  1101. return 0;
  1102. }
  1103. static int bond_option_min_links_set(struct bonding *bond,
  1104. const struct bond_opt_value *newval)
  1105. {
  1106. netdev_info(bond->dev, "Setting min links value to %llu\n",
  1107. newval->value);
  1108. bond->params.min_links = newval->value;
  1109. bond_set_carrier(bond);
  1110. return 0;
  1111. }
  1112. static int bond_option_lp_interval_set(struct bonding *bond,
  1113. const struct bond_opt_value *newval)
  1114. {
  1115. bond->params.lp_interval = newval->value;
  1116. return 0;
  1117. }
  1118. static int bond_option_pps_set(struct bonding *bond,
  1119. const struct bond_opt_value *newval)
  1120. {
  1121. bond->params.packets_per_slave = newval->value;
  1122. if (newval->value > 0) {
  1123. bond->params.reciprocal_packets_per_slave =
  1124. reciprocal_value(newval->value);
  1125. } else {
  1126. /* reciprocal_packets_per_slave is unused if
  1127. * packets_per_slave is 0 or 1, just initialize it
  1128. */
  1129. bond->params.reciprocal_packets_per_slave =
  1130. (struct reciprocal_value) { 0 };
  1131. }
  1132. return 0;
  1133. }
  1134. static int bond_option_lacp_rate_set(struct bonding *bond,
  1135. const struct bond_opt_value *newval)
  1136. {
  1137. netdev_info(bond->dev, "Setting LACP rate to %s (%llu)\n",
  1138. newval->string, newval->value);
  1139. bond->params.lacp_fast = newval->value;
  1140. bond_3ad_update_lacp_rate(bond);
  1141. return 0;
  1142. }
  1143. static int bond_option_ad_select_set(struct bonding *bond,
  1144. const struct bond_opt_value *newval)
  1145. {
  1146. netdev_info(bond->dev, "Setting ad_select to %s (%llu)\n",
  1147. newval->string, newval->value);
  1148. bond->params.ad_select = newval->value;
  1149. return 0;
  1150. }
  1151. static int bond_option_queue_id_set(struct bonding *bond,
  1152. const struct bond_opt_value *newval)
  1153. {
  1154. struct slave *slave, *update_slave;
  1155. struct net_device *sdev;
  1156. struct list_head *iter;
  1157. char *delim;
  1158. int ret = 0;
  1159. u16 qid;
  1160. /* delim will point to queue id if successful */
  1161. delim = strchr(newval->string, ':');
  1162. if (!delim)
  1163. goto err_no_cmd;
  1164. /* Terminate string that points to device name and bump it
  1165. * up one, so we can read the queue id there.
  1166. */
  1167. *delim = '\0';
  1168. if (sscanf(++delim, "%hd\n", &qid) != 1)
  1169. goto err_no_cmd;
  1170. /* Check buffer length, valid ifname and queue id */
  1171. if (!dev_valid_name(newval->string) ||
  1172. qid > bond->dev->real_num_tx_queues)
  1173. goto err_no_cmd;
  1174. /* Get the pointer to that interface if it exists */
  1175. sdev = __dev_get_by_name(dev_net(bond->dev), newval->string);
  1176. if (!sdev)
  1177. goto err_no_cmd;
  1178. /* Search for thes slave and check for duplicate qids */
  1179. update_slave = NULL;
  1180. bond_for_each_slave(bond, slave, iter) {
  1181. if (sdev == slave->dev)
  1182. /* We don't need to check the matching
  1183. * slave for dups, since we're overwriting it
  1184. */
  1185. update_slave = slave;
  1186. else if (qid && qid == slave->queue_id) {
  1187. goto err_no_cmd;
  1188. }
  1189. }
  1190. if (!update_slave)
  1191. goto err_no_cmd;
  1192. /* Actually set the qids for the slave */
  1193. update_slave->queue_id = qid;
  1194. out:
  1195. return ret;
  1196. err_no_cmd:
  1197. netdev_info(bond->dev, "invalid input for queue_id set\n");
  1198. ret = -EPERM;
  1199. goto out;
  1200. }
  1201. static int bond_option_slaves_set(struct bonding *bond,
  1202. const struct bond_opt_value *newval)
  1203. {
  1204. char command[IFNAMSIZ + 1] = { 0, };
  1205. struct net_device *dev;
  1206. char *ifname;
  1207. int ret;
  1208. sscanf(newval->string, "%16s", command); /* IFNAMSIZ*/
  1209. ifname = command + 1;
  1210. if ((strlen(command) <= 1) ||
  1211. !dev_valid_name(ifname))
  1212. goto err_no_cmd;
  1213. dev = __dev_get_by_name(dev_net(bond->dev), ifname);
  1214. if (!dev) {
  1215. netdev_info(bond->dev, "interface %s does not exist!\n",
  1216. ifname);
  1217. ret = -ENODEV;
  1218. goto out;
  1219. }
  1220. switch (command[0]) {
  1221. case '+':
  1222. netdev_info(bond->dev, "Adding slave %s\n", dev->name);
  1223. ret = bond_enslave(bond->dev, dev);
  1224. break;
  1225. case '-':
  1226. netdev_info(bond->dev, "Removing slave %s\n", dev->name);
  1227. ret = bond_release(bond->dev, dev);
  1228. break;
  1229. default:
  1230. goto err_no_cmd;
  1231. }
  1232. out:
  1233. return ret;
  1234. err_no_cmd:
  1235. netdev_err(bond->dev, "no command found in slaves file - use +ifname or -ifname\n");
  1236. ret = -EPERM;
  1237. goto out;
  1238. }
  1239. static int bond_option_tlb_dynamic_lb_set(struct bonding *bond,
  1240. const struct bond_opt_value *newval)
  1241. {
  1242. netdev_info(bond->dev, "Setting dynamic-lb to %s (%llu)\n",
  1243. newval->string, newval->value);
  1244. bond->params.tlb_dynamic_lb = newval->value;
  1245. return 0;
  1246. }
  1247. static int bond_option_ad_actor_sys_prio_set(struct bonding *bond,
  1248. const struct bond_opt_value *newval)
  1249. {
  1250. netdev_info(bond->dev, "Setting ad_actor_sys_prio to %llu\n",
  1251. newval->value);
  1252. bond->params.ad_actor_sys_prio = newval->value;
  1253. bond_3ad_update_ad_actor_settings(bond);
  1254. return 0;
  1255. }
  1256. static int bond_option_ad_actor_system_set(struct bonding *bond,
  1257. const struct bond_opt_value *newval)
  1258. {
  1259. u8 macaddr[ETH_ALEN];
  1260. u8 *mac;
  1261. int i;
  1262. if (newval->string) {
  1263. i = sscanf(newval->string, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
  1264. &macaddr[0], &macaddr[1], &macaddr[2],
  1265. &macaddr[3], &macaddr[4], &macaddr[5]);
  1266. if (i != ETH_ALEN)
  1267. goto err;
  1268. mac = macaddr;
  1269. } else {
  1270. mac = (u8 *)&newval->value;
  1271. }
  1272. if (!is_valid_ether_addr(mac))
  1273. goto err;
  1274. netdev_info(bond->dev, "Setting ad_actor_system to %pM\n", mac);
  1275. ether_addr_copy(bond->params.ad_actor_system, mac);
  1276. bond_3ad_update_ad_actor_settings(bond);
  1277. return 0;
  1278. err:
  1279. netdev_err(bond->dev, "Invalid MAC address.\n");
  1280. return -EINVAL;
  1281. }
  1282. static int bond_option_ad_user_port_key_set(struct bonding *bond,
  1283. const struct bond_opt_value *newval)
  1284. {
  1285. netdev_info(bond->dev, "Setting ad_user_port_key to %llu\n",
  1286. newval->value);
  1287. bond->params.ad_user_port_key = newval->value;
  1288. return 0;
  1289. }