ipmi_lanp6.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. /*
  2. * Copyright (c) 2016 Pentair Technical Products. All right reserved
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * Redistribution of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * Redistribution in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * Neither the name of Pentair Technical Products or the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  23. * PENTAIR TECHNICAL SOLUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  29. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. * POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include <ipmitool/helper.h>
  33. #include <ipmitool/ipmi_cc.h>
  34. #include <ipmitool/ipmi_cfgp.h>
  35. #include <ipmitool/ipmi_lanp.h>
  36. #include <ipmitool/ipmi_lanp6.h>
  37. #include <ipmitool/log.h>
  38. #include <errno.h>
  39. #include <stdio.h>
  40. #include <string.h>
  41. #include <arpa/inet.h>
  42. /*
  43. * LAN6 command values.
  44. */
  45. enum {
  46. LANP_CMD_SAVE,
  47. LANP_CMD_SET,
  48. LANP_CMD_PRINT,
  49. LANP_CMD_LOCK,
  50. LANP_CMD_COMMIT,
  51. LANP_CMD_DISCARD,
  52. LANP_CMD_HELP,
  53. LANP_CMD_ANY = 0xFF
  54. };
  55. /*
  56. * Generic LAN configuration parameters.
  57. */
  58. const struct ipmi_lanp generic_lanp6[] = {
  59. { 0, "Set In Progress", 1 },
  60. { 50, "IPv6/IPv4 Support", 1 },
  61. { 51, "IPv6/IPv4 Addressing Enables", 1 },
  62. { 52, "IPv6 Header Traffic Class", 1 },
  63. { 53, "IPv6 Header Static Hop Limit", 1 },
  64. { 54, "IPv6 Header Flow Label", 3 },
  65. { 55, "IPv6 Status", 3 },
  66. { 56, "IPv6 Static Address", 20 },
  67. { 57, "IPv6 DHCPv6 Static DUID Storage Length", 1 },
  68. { 58, "IPv6 DHCPv6 Static DUID", 18 },
  69. { 59, "IPv6 Dynamic Address", 20 },
  70. { 60, "IPv6 DHCPv6 Dynamic DUID Storage Length", 1 },
  71. { 61, "IPv6 DHCPv6 Dynamic DUID", 18 },
  72. { 62, "IPv6 DHCPv6 Timing Configuration Support", 1 },
  73. { 63, "IPv6 DHCPv6 Timing Configuration", 18 },
  74. { 64, "IPv6 Router Address Configuration Control", 1 },
  75. { 65, "IPv6 Static Router 1 IP Address", 16 },
  76. { 66, "IPv6 Static Router 1 MAC Address", 6 },
  77. { 67, "IPv6 Static Router 1 Prefix Length", 1 },
  78. { 68, "IPv6 Static Router 1 Prefix Value", 16 },
  79. { 69, "IPv6 Static Router 2 IP Address", 16 },
  80. { 70, "IPv6 Static Router 2 MAC Address", 6 },
  81. { 71, "IPv6 Static Router 2 Prefix Length", 1 },
  82. { 72, "IPv6 Static Router 2 Prefix Value", 16 },
  83. { 73, "IPv6 Number of Dynamic Router Info Sets", 1 },
  84. { 74, "IPv6 Dynamic Router Info IP Address", 17 },
  85. { 75, "IPv6 Dynamic Router Info MAC Address", 7 },
  86. { 76, "IPv6 Dynamic Router Info Prefix Length", 2 },
  87. { 77, "IPv6 Dynamic Router Info Prefix Value", 17 },
  88. { 78, "IPv6 Dynamic Router Received Hop Limit", 1 },
  89. { 79, "IPv6 ND/SLAAC Timing Configuration Support", 1 },
  90. { 80, "IPv6 ND/SLAAC Timing Configuration", 18 },
  91. { 0, NULL, 0 }
  92. };
  93. /*
  94. * Set/Get LAN Configuration Parameters
  95. * command-specific completion codes.
  96. */
  97. const struct valstr lanp_cc_vals[] = {
  98. { 0x80, "Parameter not supported" },
  99. { 0x81, "Set already in progress" },
  100. { 0x82, "Parameter is read-only" },
  101. { 0x83, "Write-only parameter" },
  102. { 0x00, NULL }
  103. };
  104. /*
  105. * IPv6/IPv4 Addressing Enables.
  106. */
  107. const struct valstr ip6_enable_vals[] = {
  108. { 0, "ipv4" },
  109. { 1, "ipv6" },
  110. { 2, "both" },
  111. { 0xFF, NULL }
  112. };
  113. /*
  114. * Enable/Disable a static address.
  115. */
  116. const struct valstr ip6_addr_enable_vals[] = {
  117. { 0x00, "disable" },
  118. { 0x80, "enable" },
  119. { 0xFF, NULL }
  120. };
  121. /*
  122. * IPv6 address source values.
  123. */
  124. const struct valstr ip6_addr_sources[] = {
  125. { 0, "static" },
  126. { 1, "SLAAC" },
  127. { 2, "DHCPv6" },
  128. { 0, NULL }
  129. };
  130. /*
  131. * IPv6 address status values.
  132. */
  133. const struct valstr ip6_addr_statuses[] = {
  134. { 0, "active" },
  135. { 1, "disabled" },
  136. { 2, "pending" },
  137. { 3, "failed" },
  138. { 4, "deprecated" },
  139. { 5, "invalid" },
  140. { 0xFF, NULL }
  141. };
  142. /*
  143. * DHCPv6 DUID type values.
  144. */
  145. const struct valstr ip6_duid_types[] = {
  146. { 0, "unknown" },
  147. { 1, "DUID-LLT" },
  148. { 2, "DUID-EN" },
  149. { 3, "DUID-LL" },
  150. { 0xFF, NULL }
  151. };
  152. /*
  153. * Timing Configuration support values.
  154. */
  155. const struct valstr ip6_cfg_sup_vals[] = {
  156. { 0, "not supported" },
  157. { 1, "global" },
  158. { 2, "per interface" },
  159. { 0xFF, NULL }
  160. };
  161. /*
  162. * Router Address Configuration Control values.
  163. */
  164. const struct valstr ip6_rtr_configs[] = {
  165. { 1, "static" },
  166. { 2, "dynamic" },
  167. { 3, "both" },
  168. { 0xFF, NULL }
  169. };
  170. const struct valstr ip6_command_vals[] = {
  171. { LANP_CMD_SET, "set" },
  172. { LANP_CMD_SAVE, "save" },
  173. { LANP_CMD_PRINT, "print" },
  174. { LANP_CMD_LOCK, "lock" },
  175. { LANP_CMD_COMMIT, "commit" },
  176. { LANP_CMD_DISCARD, "discard" },
  177. { LANP_CMD_HELP, "help" },
  178. { LANP_CMD_ANY, NULL }
  179. };
  180. static const struct ipmi_cfgp lan_cfgp[] = {
  181. { .name = "support", .format = NULL, .size = 1,
  182. .access = CFGP_RDONLY,
  183. .is_set = 0, .first_set = 0, .has_blocks = 0, .first_block = 0,
  184. .specific = IPMI_LANP_IP6_SUPPORT
  185. },
  186. { .name = "enables", .format = "{ipv4|ipv6|both}", .size = 1,
  187. .access = CFGP_RDWR,
  188. .is_set = 0, .first_set = 0, .has_blocks = 0, .first_block = 0,
  189. .specific = IPMI_LANP_IP6_ENABLES
  190. },
  191. { .name = "traffic_class", .format = "<value>", .size = 1,
  192. .access = CFGP_RDWR,
  193. .is_set = 0, .first_set = 0, .has_blocks = 0, .first_block = 0,
  194. .specific = IPMI_LANP_IP6_TRAFFIC_CLASS
  195. },
  196. { .name = "static_hops", .format = "<value>", .size = 1,
  197. .access = CFGP_RDWR,
  198. .is_set = 0, .first_set = 0, .has_blocks = 0, .first_block = 0,
  199. .specific = IPMI_LANP_IP6_STATIC_HOPS
  200. },
  201. { .name = "flow_label", .format = "<value>", .size = 3,
  202. .access = CFGP_RDWR,
  203. .is_set = 0, .first_set = 0, .has_blocks = 0, .first_block = 0,
  204. .specific = IPMI_LANP_IP6_FLOW_LABEL
  205. },
  206. { .name = "status", .format = NULL, .size = 3,
  207. .access = CFGP_RDONLY,
  208. .is_set = 0, .first_set = 0, .has_blocks = 0, .first_block = 0,
  209. .specific = IPMI_LANP_IP6_STATUS
  210. },
  211. { .name = "static_addr",
  212. .format = "{enable|disable} <addr> <pfx_len>", .size = 20,
  213. .access = CFGP_RDWR,
  214. .is_set = 1, .first_set = 0, .has_blocks = 0, .first_block = 0,
  215. .specific = IPMI_LANP_IP6_STATIC_ADDR
  216. },
  217. { .name = "static_duid_stg", .format = NULL, .size = 1,
  218. .access = CFGP_RDONLY,
  219. .is_set = 0, .first_set = 0, .has_blocks = 0, .first_block = 0,
  220. .specific = IPMI_LANP_IP6_STATIC_DUID_STG
  221. },
  222. { .name = "static_duid", .format = "<data>", .size = 18,
  223. .access = CFGP_RDWR,
  224. .is_set = 1, .first_set = 0, .has_blocks = 1, .first_block = 0,
  225. .specific = IPMI_LANP_IP6_STATIC_DUID
  226. },
  227. { .name = "dynamic_addr", .format = NULL, .size = 20,
  228. .access = CFGP_RDONLY,
  229. .is_set = 1, .first_set = 0, .has_blocks = 0, .first_block = 0,
  230. .specific = IPMI_LANP_IP6_DYNAMIC_ADDR
  231. },
  232. { .name = "dynamic_duid_stg", .format = NULL, .size = 1,
  233. .access = CFGP_RDONLY,
  234. .is_set = 0, .first_set = 0, .has_blocks = 0, .first_block = 0,
  235. .specific = IPMI_LANP_IP6_DYNAMIC_DUID_STG
  236. },
  237. { .name = "dynamic_duid", .format = "<data>", .size = 18,
  238. .access = CFGP_RDWR,
  239. .is_set = 1, .first_set = 0, .has_blocks = 1, .first_block = 0,
  240. .specific = IPMI_LANP_IP6_DYNAMIC_DUID
  241. },
  242. { .name = "dhcp6_cfg_sup", .format = NULL, .size = 1,
  243. .access = CFGP_RDONLY,
  244. .is_set = 0, .first_set = 0, .has_blocks = 0, .first_block = 0,
  245. .specific = IPMI_LANP_IP6_DHCP6_CFG_SUP
  246. },
  247. { .name = "dhcp6_cfg", .format = "<data> <data>", .size = 36,
  248. .access = CFGP_RDWR,
  249. .is_set = 1, .first_set = 0, .has_blocks = 0, .first_block = 0,
  250. .specific = IPMI_LANP_IP6_DHCP6_CFG
  251. },
  252. { .name = "rtr_cfg", .format = "{static|dynamic|both}", .size = 1,
  253. .access = CFGP_RDWR,
  254. .is_set = 0, .first_set = 0, .has_blocks = 0, .first_block = 0,
  255. .specific = IPMI_LANP_IP6_ROUTER_CFG
  256. },
  257. { .name = "static_rtr",
  258. .format = "<addr> <macaddr> <prefix> <prefix_len>", .size = 43,
  259. .access = CFGP_RDWR,
  260. .is_set = 1, .first_set = 1, .has_blocks = 0, .first_block = 0,
  261. .specific = IPMI_LANP_IP6_STATIC_RTR1_ADDR
  262. },
  263. { .name = "num_dynamic_rtrs", .format = NULL, .size = 1,
  264. .access = CFGP_RDONLY,
  265. .is_set = 0, .first_set = 0, .has_blocks = 0, .first_block = 0,
  266. .specific = IPMI_LANP_IP6_NUM_DYNAMIC_RTRS
  267. },
  268. { .name = "dynamic_rtr", .format = NULL, .size = 43,
  269. .access = CFGP_RDONLY,
  270. .is_set = 1, .first_set = 0, .has_blocks = 0, .first_block = 0,
  271. .specific = IPMI_LANP_IP6_DYNAMIC_RTR_ADDR
  272. },
  273. { .name = "dynamic_hops", .format = NULL, .size = 1,
  274. .access = CFGP_RDONLY,
  275. .is_set = 0, .first_set = 0, .has_blocks = 0, .first_block = 0,
  276. .specific = IPMI_LANP_IP6_DYNAMIC_HOPS
  277. },
  278. { .name = "ndslaac_cfg_sup", .format = NULL, .size = 1,
  279. .access = CFGP_RDONLY,
  280. .is_set = 0, .first_set = 0, .has_blocks = 0, .first_block = 0,
  281. .specific = IPMI_LANP_IP6_NDSLAAC_CFG_SUP
  282. },
  283. { .name = "ndslaac_cfg", .format = "<data>", .size = 18,
  284. .access = CFGP_RDWR,
  285. .is_set = 1, .first_set = 0, .has_blocks = 0, .first_block = 0,
  286. .specific = IPMI_LANP_IP6_NDSLAAC_CFG
  287. }
  288. };
  289. /*
  290. * Lookup LAN parameter descriptor by parameter selector.
  291. */
  292. const struct ipmi_lanp *
  293. lookup_lanp(int param)
  294. {
  295. const struct ipmi_lanp *p = generic_lanp6;
  296. while (p->name) {
  297. if (p->selector == param) {
  298. return p;
  299. }
  300. p++;
  301. }
  302. return NULL;
  303. }
  304. /*
  305. * Print request error.
  306. */
  307. static int
  308. ipmi_lanp_err(const struct ipmi_rs *rsp, const struct ipmi_lanp *p,
  309. const char *action, int quiet)
  310. {
  311. const char *reason;
  312. char cc_msg[10];
  313. int log_level = LOG_ERR;
  314. int err;
  315. if (rsp == NULL) {
  316. reason = "No response";
  317. err = -1;
  318. } else {
  319. err = rsp->ccode;
  320. if (quiet == 1
  321. && (rsp->ccode == 0x80
  322. || rsp->ccode == IPMI_CC_PARAM_OUT_OF_RANGE
  323. || rsp->ccode == IPMI_CC_INV_DATA_FIELD_IN_REQ)) {
  324. /* be quiet */
  325. return err;
  326. }
  327. if (rsp->ccode >= 0xC0) {
  328. /* browse for generic completion codes */
  329. reason = val2str(rsp->ccode, completion_code_vals);
  330. } else {
  331. /* browse for command-specific completion codes first */
  332. reason = val2str(rsp->ccode, lanp_cc_vals);
  333. }
  334. if (reason == NULL) {
  335. /* print completion code value */
  336. snprintf(cc_msg, sizeof(cc_msg), "CC=%02x", rsp->ccode);
  337. reason = cc_msg;
  338. }
  339. if (rsp->ccode == IPMI_CC_OK) {
  340. log_level = LOG_DEBUG;
  341. }
  342. }
  343. lprintf(log_level, "Failed to %s %s: %s", action, p->name, reason);
  344. return err;
  345. }
  346. /*
  347. * Get dynamic OEM LAN configuration parameter from BMC.
  348. * Dynamic in this context is when the base for OEM LAN parameters
  349. * is not known apriori.
  350. */
  351. int
  352. ipmi_get_dynamic_oem_lanp(void *priv, const struct ipmi_lanp *param,
  353. int oem_base, int set_selector, int block_selector,
  354. void *data, int quiet)
  355. {
  356. struct ipmi_lanp_priv *lp = priv;
  357. struct ipmi_rs *rsp;
  358. struct ipmi_rq req;
  359. uint8_t req_data[4];
  360. int length;
  361. if (!priv || !param || !data) {
  362. return -1;
  363. }
  364. req_data[0] = lp->channel;
  365. req_data[1] = param->selector + oem_base;
  366. req_data[2] = set_selector;
  367. req_data[3] = block_selector;
  368. memset(&req, 0, sizeof(req));
  369. req.msg.netfn = IPMI_NETFN_TRANSPORT;
  370. req.msg.cmd = 2;
  371. req.msg.data = req_data;
  372. req.msg.data_len = 4;
  373. lprintf(LOG_INFO, "Getting parameter '%s' set %d block %d",
  374. param->name, set_selector, block_selector);
  375. rsp = lp->intf->sendrecv(lp->intf, &req);
  376. if (rsp == NULL || rsp->ccode) {
  377. return ipmi_lanp_err(rsp, param, "get", quiet);
  378. }
  379. memset(data, 0, param->size);
  380. if (rsp->data_len - 1 < param->size) {
  381. length = rsp->data_len - 1;
  382. } else {
  383. length = param->size;
  384. }
  385. if (length) {
  386. memcpy(data, rsp->data + 1, length);
  387. }
  388. return 0;
  389. }
  390. /*
  391. * Get generic LAN configuration parameter.
  392. */
  393. int
  394. ipmi_get_lanp(void *priv, int param_selector, int set_selector,
  395. int block_selector, void *data, int quiet)
  396. {
  397. return ipmi_get_dynamic_oem_lanp(priv, lookup_lanp(param_selector), 0,
  398. set_selector, block_selector, data, quiet);
  399. }
  400. /*
  401. * Set dynamic OEM LAN configuration parameter to BMC.
  402. * Dynamic in this context is when the base for OEM LAN parameters
  403. * is not known apriori.
  404. */
  405. int
  406. ipmi_set_dynamic_oem_lanp(void *priv, const struct ipmi_lanp *param,
  407. int base, const void *data)
  408. {
  409. struct ipmi_lanp_priv *lp = priv;
  410. struct ipmi_rs *rsp;
  411. struct ipmi_rq req;
  412. uint8_t req_data[32];
  413. if (!priv || !param || !data) {
  414. return -1;
  415. }
  416. /* fill the first two bytes */
  417. req_data[0] = lp->channel;
  418. req_data[1] = param->selector + base;
  419. /* fill the rest data */
  420. memcpy(&req_data[2], data, param->size);
  421. /* fill request */
  422. memset(&req, 0, sizeof(req));
  423. req.msg.netfn = IPMI_NETFN_TRANSPORT;
  424. req.msg.cmd = 1;
  425. req.msg.data = req_data;
  426. req.msg.data_len = param->size + 2;
  427. lprintf(LOG_INFO, "Setting parameter '%s'", param->name);
  428. rsp = lp->intf->sendrecv(lp->intf, &req);
  429. if (rsp == NULL || rsp->ccode) {
  430. return ipmi_lanp_err(rsp, param, "set", 0);
  431. }
  432. return 0;
  433. }
  434. /*
  435. * Set generic LAN configuration parameter.
  436. */
  437. int
  438. ipmi_set_lanp(void *priv, int param_selector, const void *data)
  439. {
  440. return ipmi_set_dynamic_oem_lanp(priv, lookup_lanp(param_selector),
  441. 0, data);
  442. }
  443. static int
  444. lanp_parse_cfgp(const struct ipmi_cfgp *p, int set, int block,
  445. int argc, const char *argv[], unsigned char *data)
  446. {
  447. unsigned int v;
  448. if (argc == 0) {
  449. return -1;
  450. }
  451. switch(p->specific) {
  452. case IPMI_LANP_IP6_ENABLES:
  453. data[0] = str2val(argv[0], ip6_enable_vals);
  454. if (data[0] == 0xFF) {
  455. lprintf(LOG_ERR, "invalid value");
  456. return -1;
  457. }
  458. break;
  459. case IPMI_LANP_IP6_FLOW_LABEL:
  460. if (str2uint(argv[0], &v)) {
  461. lprintf(LOG_ERR, "invalid value");
  462. return -1;
  463. }
  464. data[0] = (v >> 16) & 0x0F;
  465. data[1] = (v >> 8) & 0xFF;
  466. data[2] = v & 0xFF;
  467. break;
  468. case IPMI_LANP_IP6_STATUS:
  469. if (argc < 3) {
  470. return -1;
  471. }
  472. if (str2uchar(argv[0], &data[0])
  473. || str2uchar(argv[1], &data[1])
  474. || str2uchar(argv[2], &data[2])) {
  475. lprintf(LOG_ERR, "invalid value");
  476. return -1;
  477. }
  478. break;
  479. case IPMI_LANP_IP6_STATIC_ADDR:
  480. case IPMI_LANP_IP6_DYNAMIC_ADDR:
  481. if (argc < 3) {
  482. return -1;
  483. }
  484. data[0] = set;
  485. if (p->specific == IPMI_LANP_IP6_STATIC_ADDR) {
  486. data[1] = str2val(argv[0], ip6_addr_enable_vals);
  487. } else {
  488. data[1] = str2val(argv[0], ip6_addr_sources);
  489. }
  490. if (data[1] == 0xFF) {
  491. lprintf(LOG_ERR, "invalid value");
  492. return -1;
  493. }
  494. if (inet_pton(AF_INET6, argv[1], &data[2]) != 1) {
  495. lprintf(LOG_ERR, "invalid value");
  496. return -1;
  497. }
  498. if (str2uchar(argv[2], &data[18])) {
  499. lprintf(LOG_ERR, "invalid value");
  500. return -1;
  501. }
  502. if (argc >= 4) {
  503. data[19] = str2val(argv[3], ip6_addr_statuses);
  504. }
  505. break;
  506. case IPMI_LANP_IP6_STATIC_DUID:
  507. case IPMI_LANP_IP6_DYNAMIC_DUID:
  508. case IPMI_LANP_IP6_NDSLAAC_CFG:
  509. data[0] = set;
  510. data[1] = block;
  511. if (ipmi_parse_hex(argv[0], &data[2], 16) < 0) {
  512. lprintf(LOG_ERR, "invalid value");
  513. return -1;
  514. }
  515. break;
  516. case IPMI_LANP_IP6_DHCP6_CFG:
  517. data[0] = set;
  518. data[1] = 0;
  519. data[18] = set;
  520. data[19] = 1;
  521. if (ipmi_parse_hex(argv[0], &data[2], 16) < 0
  522. || (argc > 1 &&
  523. ipmi_parse_hex(argv[1], &data[20], 6) < 0)) {
  524. lprintf(LOG_ERR, "invalid value");
  525. return -1;
  526. }
  527. break;
  528. case IPMI_LANP_IP6_ROUTER_CFG:
  529. data[0] = str2val(argv[0], ip6_rtr_configs);
  530. if (data[0] == 0xFF) {
  531. lprintf(LOG_ERR, "invalid value");
  532. return -1;
  533. }
  534. break;
  535. case IPMI_LANP_IP6_STATIC_RTR1_ADDR:
  536. if (set > 2) {
  537. lprintf(LOG_ERR, "invalid value");
  538. return -1;
  539. }
  540. case IPMI_LANP_IP6_DYNAMIC_RTR_ADDR:
  541. if (argc < 4) {
  542. return -1;
  543. }
  544. /*
  545. * Data is stored in the following way:
  546. * 0: <set> <addr1>...<addr16>
  547. * 17: <set> <mac1>...<mac6>
  548. * 24: <set> <pfxlen>
  549. * 26: <set> <pfx1>...<pfx16>
  550. */
  551. data[0] = data[17] = data[24] = data[26] = set;
  552. if (inet_pton(AF_INET6, argv[0], &data[1]) != 1
  553. || str2mac(argv[1], &data[18])
  554. || inet_pton(AF_INET6, argv[2], &data[27]) != 1
  555. || str2uchar(argv[3], &data[25])) {
  556. lprintf(LOG_ERR, "invalid value");
  557. return -1;
  558. }
  559. break;
  560. default:
  561. if (str2uchar(argv[0], &data[0])) {
  562. lprintf(LOG_ERR, "invalid value");
  563. return -1;
  564. }
  565. }
  566. return 0;
  567. }
  568. static int
  569. lanp_set_cfgp(void *priv, const struct ipmi_cfgp *p, const unsigned char *data)
  570. {
  571. int ret;
  572. int param = p->specific;
  573. int off = 0;
  574. switch(param) {
  575. case IPMI_LANP_IP6_DHCP6_CFG:
  576. ret = ipmi_set_lanp(priv, param, &data[0]);
  577. if (ret == 0) {
  578. ret = ipmi_set_lanp(priv, param, &data[18]);
  579. }
  580. break;
  581. case IPMI_LANP_IP6_STATIC_RTR1_ADDR:
  582. if (data[0] == 2) {
  583. param = IPMI_LANP_IP6_STATIC_RTR2_ADDR;
  584. }
  585. off = 1;
  586. case IPMI_LANP_IP6_DYNAMIC_RTR_ADDR:
  587. ret = ipmi_set_lanp(priv, param, &data[0 + off]);
  588. if (ret == 0) {
  589. ret = ipmi_set_lanp(priv, param + 1, &data[17 + off]);
  590. }
  591. if (ret == 0) {
  592. ret = ipmi_set_lanp(priv, param + 2, &data[24 + off]);
  593. }
  594. if (ret == 0) {
  595. ret = ipmi_set_lanp(priv, param + 3, &data[26 + off]);
  596. }
  597. break;
  598. default:
  599. ret = ipmi_set_lanp(priv, param, data);
  600. }
  601. return ret;
  602. }
  603. static int
  604. lanp_get_cfgp(void *priv, const struct ipmi_cfgp *p,
  605. int set, int block, unsigned char *data, int quiet)
  606. {
  607. int ret;
  608. int param = p->specific;
  609. int off = 0;
  610. switch(param) {
  611. case IPMI_LANP_IP6_DHCP6_CFG:
  612. ret = ipmi_get_lanp(priv, param, set, 0, &data[0], quiet);
  613. if (ret == 0) {
  614. ret = ipmi_get_lanp(priv, param, set,
  615. 1, &data[18], quiet);
  616. }
  617. break;
  618. case IPMI_LANP_IP6_STATIC_RTR1_ADDR:
  619. if (set > 2) {
  620. return -1;
  621. }
  622. if (set == 2) {
  623. param = IPMI_LANP_IP6_STATIC_RTR2_ADDR;
  624. }
  625. set = 0;
  626. off = 1;
  627. data[0] = data[17] = data[24] = data[26] = set;
  628. case IPMI_LANP_IP6_DYNAMIC_RTR_ADDR:
  629. ret = ipmi_get_lanp(priv, param, set, block,
  630. &data[0 + off], quiet);
  631. if (ret == 0) {
  632. ret = ipmi_get_lanp(priv, param + 1, set, block,
  633. &data[17 + off], 0);
  634. }
  635. if (ret == 0) {
  636. ret = ipmi_get_lanp(priv, param + 2, set, block,
  637. &data[24 + off], 0);
  638. }
  639. if (ret == 0) {
  640. ret = ipmi_get_lanp(priv, param + 3, set, block,
  641. &data[26 + off], 0);
  642. }
  643. break;
  644. default:
  645. ret = ipmi_get_lanp(priv, param, set, block, data, quiet);
  646. }
  647. return ret;
  648. }
  649. static int
  650. lanp_save_cfgp(const struct ipmi_cfgp *p, const unsigned char *data, FILE *file)
  651. {
  652. char addr[INET6_ADDRSTRLEN];
  653. char pfx[INET6_ADDRSTRLEN];
  654. const char *src;
  655. switch(p->specific) {
  656. case IPMI_LANP_IP6_ENABLES:
  657. fputs(val2str(data[0], ip6_enable_vals), file);
  658. break;
  659. case IPMI_LANP_IP6_FLOW_LABEL:
  660. fprintf(file, "0x%xd", (data[0] << 16 ) | (data[1] << 8) | data[2]);
  661. break;
  662. case IPMI_LANP_IP6_STATUS:
  663. fprintf(file, "%d %d %d", data[0], data[1], data[2]);
  664. break;
  665. case IPMI_LANP_IP6_STATIC_ADDR:
  666. case IPMI_LANP_IP6_DYNAMIC_ADDR:
  667. if (p->specific == IPMI_LANP_IP6_STATIC_ADDR) {
  668. src = val2str(data[1], ip6_addr_enable_vals);
  669. } else {
  670. src = val2str(data[1], ip6_addr_sources);
  671. }
  672. fprintf(file, "%s %s %d %s", src,
  673. inet_ntop(AF_INET6, &data[2], addr, sizeof(addr)),
  674. data[18], val2str(data[19], ip6_addr_statuses));
  675. break;
  676. case IPMI_LANP_IP6_STATIC_DUID:
  677. case IPMI_LANP_IP6_DYNAMIC_DUID:
  678. case IPMI_LANP_IP6_NDSLAAC_CFG:
  679. fprintf(file, "%s", buf2str(&data[2], 16));
  680. break;
  681. case IPMI_LANP_IP6_DHCP6_CFG:
  682. fprintf(file, "%s", buf2str(&data[2], 16));
  683. fprintf(file, " %s", buf2str(&data[20], 6));
  684. break;
  685. case IPMI_LANP_IP6_ROUTER_CFG:
  686. fputs(val2str(data[0], ip6_rtr_configs), file);
  687. break;
  688. case IPMI_LANP_IP6_STATIC_RTR1_ADDR:
  689. case IPMI_LANP_IP6_DYNAMIC_RTR_ADDR:
  690. fprintf(file, "%s %s %s %d",
  691. inet_ntop(AF_INET6, &data[1], addr, sizeof(addr)),
  692. mac2str(&data[18]),
  693. inet_ntop(AF_INET6, &data[27], pfx, sizeof(pfx)), data[25]);
  694. break;
  695. default:
  696. fprintf(file, "%d", data[0]);
  697. }
  698. return 0;
  699. }
  700. static int
  701. lanp_print_cfgp(const struct ipmi_cfgp *p,
  702. int set, int block, const unsigned char *data, FILE *file)
  703. {
  704. char addr[INET6_ADDRSTRLEN];
  705. char pfx[INET6_ADDRSTRLEN];
  706. const char *pname;
  707. const struct ipmi_lanp *lanp = lookup_lanp(p->specific);
  708. if (!lanp || !p || !file || !data || !lanp->name) {
  709. return -1;
  710. }
  711. pname = lanp->name;
  712. switch(p->specific) {
  713. case IPMI_LANP_IP6_SUPPORT:
  714. fprintf(file, "%s:\n"
  715. " IPv6 only: %s\n"
  716. " IPv4 and IPv6: %s\n"
  717. " IPv6 Destination Addresses for LAN alerting: %s\n",
  718. pname,
  719. data[0] & 1 ? "yes" : "no",
  720. data[0] & 2 ? "yes" : "no",
  721. data[0] & 4 ? "yes" : "no");
  722. break;
  723. case IPMI_LANP_IP6_ENABLES:
  724. fprintf(file, "%s: %s\n",
  725. pname, val2str(data[0], ip6_enable_vals));
  726. break;
  727. case IPMI_LANP_IP6_FLOW_LABEL:
  728. fprintf(file, "%s: %d\n",
  729. pname, (data[0] << 16 ) | (data[1] << 8) | data[2]);
  730. break;
  731. case IPMI_LANP_IP6_STATUS:
  732. fprintf(file, "%s:\n"
  733. " Static address max: %d\n"
  734. " Dynamic address max: %d\n"
  735. " DHCPv6 support: %s\n"
  736. " SLAAC support: %s\n",
  737. pname,
  738. data[0], data[1],
  739. (data[2] & 1) ? "yes" : "no",
  740. (data[2] & 2) ? "yes" : "no");
  741. break;
  742. case IPMI_LANP_IP6_STATIC_ADDR:
  743. fprintf(file, "%s %d:\n"
  744. " Enabled: %s\n"
  745. " Address: %s/%d\n"
  746. " Status: %s\n",
  747. pname, set,
  748. (data[1] & 0x80) ? "yes" : "no",
  749. inet_ntop(AF_INET6, &data[2], addr, sizeof(addr)),
  750. data[18], val2str(data[19] & 0xF, ip6_addr_statuses));
  751. break;
  752. case IPMI_LANP_IP6_DYNAMIC_ADDR:
  753. fprintf(file, "%s %d:\n"
  754. " Source/Type: %s\n"
  755. " Address: %s/%d\n"
  756. " Status: %s\n",
  757. pname, set,
  758. val2str(data[1] & 0xF, ip6_addr_sources),
  759. inet_ntop(AF_INET6, &data[2], addr, sizeof(addr)),
  760. data[18], val2str(data[19] & 0xF, ip6_addr_statuses));
  761. break;
  762. case IPMI_LANP_IP6_STATIC_DUID:
  763. case IPMI_LANP_IP6_DYNAMIC_DUID:
  764. if (block == 0) {
  765. fprintf(file, "%s %d:\n"
  766. " Length: %d\n"
  767. " Type: %s\n",
  768. pname, set, data[2],
  769. val2str((data[3] << 8) + data[4], ip6_duid_types));
  770. }
  771. fprintf(file, " %s\n", buf2str(&data[2], 16));
  772. break;
  773. case IPMI_LANP_IP6_DHCP6_CFG_SUP:
  774. case IPMI_LANP_IP6_NDSLAAC_CFG_SUP:
  775. fprintf(file, "%s: %s\n",
  776. pname, val2str(data[0], ip6_cfg_sup_vals));
  777. break;
  778. case IPMI_LANP_IP6_DHCP6_CFG:
  779. fprintf(file, "%s %d:\n", pname, set);
  780. fprintf(file,
  781. " SOL_MAX_DELAY: %d\n"
  782. " SOL_TIMEOUT: %d\n"
  783. " SOL_MAX_RT: %d\n"
  784. " REQ_TIMEOUT: %d\n"
  785. " REQ_MAX_RT: %d\n"
  786. " REQ_MAX_RC: %d\n"
  787. " CNF_MAX_DELAY: %d\n"
  788. " CNF_TIMEOUT: %d\n"
  789. " CNF_MAX_RT: %d\n"
  790. " CNF_MAX_RD: %d\n"
  791. " REN_TIMEOUT: %d\n"
  792. " REN_MAX_RT: %d\n"
  793. " REB_TIMEOUT: %d\n"
  794. " REB_MAX_RT: %d\n"
  795. " INF_MAX_DELAY: %d\n"
  796. " INF_TIMEOUT: %d\n"
  797. " INF_MAX_RT: %d\n"
  798. " REL_TIMEOUT: %d\n"
  799. " REL_MAX_RC: %d\n"
  800. " DEC_TIMEOUT: %d\n"
  801. " DEC_MAX_RC: %d\n"
  802. " HOP_COUNT_LIMIT: %d\n",
  803. data[2], data[3], data[4], data[5],
  804. data[6], data[7], data[8], data[9],
  805. data[10], data[11], data[12], data[13],
  806. data[14], data[15], data[16], data[17],
  807. data[20], data[21], data[22], data[23],
  808. data[24], data[25]);
  809. break;
  810. case IPMI_LANP_IP6_ROUTER_CFG:
  811. fprintf(file, "%s:\n"
  812. " Enable static router address: %s\n"
  813. " Enable dynamic router address: %s\n",
  814. pname,
  815. (data[0] & 1) ? "yes" : "no",
  816. (data[0] & 2) ? "yes" : "no");
  817. break;
  818. case IPMI_LANP_IP6_STATIC_RTR1_ADDR:
  819. case IPMI_LANP_IP6_DYNAMIC_RTR_ADDR:
  820. if (p->specific == IPMI_LANP_IP6_STATIC_RTR1_ADDR) {
  821. pname = "IPv6 Static Router";
  822. } else {
  823. pname = "IPv6 Dynamic Router";
  824. }
  825. fprintf(file, "%s %d:\n"
  826. " Address: %s\n"
  827. " MAC: %s\n"
  828. " Prefix: %s/%d\n",
  829. pname, set,
  830. inet_ntop(AF_INET6, &data[1], addr, sizeof(addr)),
  831. mac2str(&data[18]),
  832. inet_ntop(AF_INET6, &data[27], pfx, sizeof(pfx)), data[25]);
  833. break;
  834. case IPMI_LANP_IP6_NDSLAAC_CFG:
  835. fprintf(file, "%s %d:\n"
  836. " MAX_RTR_SOLICITATION_DELAY: %d\n"
  837. " RTR_SOLICITATION_INTERVAL: %d\n"
  838. " MAX_RTR_SOLICITATIONS: %d\n"
  839. " DupAddrDetectTransmits: %d\n"
  840. " MAX_MULTICAST_SOLICIT: %d\n"
  841. " MAX_UNICAST_SOLICIT: %d\n"
  842. " MAX_ANYCAST_DELAY_TIME: %d\n"
  843. " MAX_NEIGHBOR_ADVERTISEMENT: %d\n"
  844. " REACHABLE_TIME: %d\n"
  845. " RETRANS_TIMER: %d\n"
  846. " DELAY_FIRST_PROBE_TIME: %d\n"
  847. " MAX_RANDOM_FACTOR: %d\n"
  848. " MIN_RANDOM_FACTOR: %d\n",
  849. pname, set,
  850. data[2], data[3], data[4], data[5],
  851. data[6], data[7], data[8], data[9],
  852. data[10], data[11], data[12], data[13],
  853. data[14]);
  854. break;
  855. default:
  856. fprintf(file, "%s: %d\n", pname, data[0]);
  857. }
  858. return 0;
  859. }
  860. static int
  861. lanp_ip6_cfgp(void *priv, const struct ipmi_cfgp *p,
  862. const struct ipmi_cfgp_action *action, unsigned char *data)
  863. {
  864. switch (action->type) {
  865. case CFGP_PARSE:
  866. return lanp_parse_cfgp(p, action->set, action->block,
  867. action->argc, action->argv, data);
  868. case CFGP_GET:
  869. return lanp_get_cfgp(priv, p, action->set, action->block,
  870. data, action->quiet);
  871. case CFGP_SET:
  872. return lanp_set_cfgp(priv, p, data);
  873. case CFGP_SAVE:
  874. return lanp_save_cfgp(p, data, action->file);
  875. case CFGP_PRINT:
  876. return lanp_print_cfgp(p, action->set, action->block,
  877. data, action->file);
  878. default:
  879. return -1;
  880. }
  881. return 0;
  882. }
  883. static void lanp_print_usage(int cmd)
  884. {
  885. if (cmd == LANP_CMD_ANY || cmd == LANP_CMD_HELP) {
  886. printf(" help [command]\n");
  887. }
  888. if (cmd == LANP_CMD_ANY || cmd == LANP_CMD_SAVE) {
  889. printf(" save <channel> [<parameter> [<set_sel> [<block_sel>]]]\n");
  890. }
  891. if (cmd == LANP_CMD_ANY || cmd == LANP_CMD_SET) {
  892. printf(" set <channel> [nolock] <parameter> [<set_sel> [<block_sel>]] <values...>\n");
  893. }
  894. if (cmd == LANP_CMD_ANY || cmd == LANP_CMD_PRINT) {
  895. printf(" print <channel> [<parameter> [<set_sel> [<block_sel>]]]\n");
  896. }
  897. if (cmd == LANP_CMD_ANY || cmd == LANP_CMD_LOCK) {
  898. printf(" lock <channel>\n");
  899. }
  900. if (cmd == LANP_CMD_ANY || cmd == LANP_CMD_COMMIT) {
  901. printf(" commit <channel>\n");
  902. }
  903. if (cmd == LANP_CMD_ANY || cmd == LANP_CMD_DISCARD) {
  904. printf(" discard <channel>\n");
  905. }
  906. if (cmd == LANP_CMD_SAVE
  907. || cmd == LANP_CMD_PRINT
  908. || cmd == LANP_CMD_SET) {
  909. printf("\n available parameters:\n");
  910. /* 'save' shall use 'write' filter, since it outputs a block
  911. * of 'set's */
  912. ipmi_cfgp_usage(lan_cfgp,
  913. sizeof(lan_cfgp)/sizeof(lan_cfgp[0]),
  914. cmd != LANP_CMD_PRINT);
  915. }
  916. }
  917. static int
  918. lanp_lock(struct ipmi_lanp_priv *lp)
  919. {
  920. unsigned char byte = 1;
  921. return ipmi_set_lanp(lp, 0, &byte);
  922. }
  923. static int
  924. lanp_discard(struct ipmi_lanp_priv *lp)
  925. {
  926. unsigned char byte = 0;
  927. return ipmi_set_lanp(lp, 0, &byte);
  928. }
  929. static int
  930. lanp_commit(struct ipmi_lanp_priv *lp)
  931. {
  932. unsigned char byte = 2;
  933. int ret;
  934. ret = ipmi_set_lanp(lp, 0, &byte);
  935. if (ret == 0) {
  936. ret = lanp_discard(lp);
  937. }
  938. return ret;
  939. }
  940. int
  941. ipmi_lan6_main(struct ipmi_intf *intf, int argc, char **argv)
  942. {
  943. struct ipmi_cfgp_ctx ctx;
  944. struct ipmi_cfgp_sel sel;
  945. struct ipmi_lanp_priv lp;
  946. int cmd;
  947. int chan;
  948. int nolock = 0;
  949. int ret;
  950. if (argc == 0) {
  951. lanp_print_usage(LANP_CMD_ANY);
  952. return 0;
  953. }
  954. cmd = str2val(argv[0], ip6_command_vals);
  955. if (cmd == LANP_CMD_ANY) {
  956. lanp_print_usage(cmd);
  957. return -1;
  958. }
  959. if (cmd == LANP_CMD_HELP) {
  960. if (argc == 1) {
  961. cmd = LANP_CMD_ANY;
  962. } else {
  963. cmd = str2val(argv[1], ip6_command_vals);
  964. }
  965. lanp_print_usage(cmd);
  966. return 0;
  967. }
  968. /*
  969. * the rest commands expect channel number
  970. * with the exception of 'get' and 'print'
  971. */
  972. if (argc == 1) {
  973. if (cmd == LANP_CMD_SAVE || cmd == LANP_CMD_PRINT) {
  974. chan = find_lan_channel(intf, 1);
  975. if (chan == 0) {
  976. lprintf(LOG_ERR, "No LAN channel found");
  977. return -1;
  978. }
  979. } else {
  980. lanp_print_usage(cmd);
  981. return -1;
  982. }
  983. argc -= 1;
  984. argv += 1;
  985. } else {
  986. if (str2int(argv[1], &chan) != 0) {
  987. lprintf(LOG_ERR, "Invalid channel: %s", argv[1]);
  988. return -1;
  989. }
  990. argc -= 2;
  991. argv += 2;
  992. if (cmd == LANP_CMD_SET) {
  993. if (argc && !strcasecmp(argv[0], "nolock")) {
  994. nolock = 1;
  995. argc -= 1;
  996. argv += 1;
  997. }
  998. }
  999. }
  1000. lp.intf = intf;
  1001. lp.channel = chan;
  1002. /*
  1003. * lock/commit/discard commands do not require parsing
  1004. * of parameter selection
  1005. */
  1006. switch (cmd) {
  1007. case LANP_CMD_LOCK:
  1008. lprintf(LOG_NOTICE, "Lock parameter(s)...");
  1009. return lanp_lock(&lp);
  1010. case LANP_CMD_COMMIT:
  1011. lprintf(LOG_NOTICE, "Commit parameter(s)...");
  1012. return lanp_commit(&lp);
  1013. case LANP_CMD_DISCARD:
  1014. lprintf(LOG_NOTICE, "Discard parameter(s)...");
  1015. return lanp_discard(&lp);
  1016. }
  1017. /*
  1018. * initialize configuration context and parse parameter selection
  1019. */
  1020. ipmi_cfgp_init(&ctx, lan_cfgp,
  1021. sizeof(lan_cfgp)/sizeof(lan_cfgp[0]), "lan6 set nolock",
  1022. lanp_ip6_cfgp, &lp);
  1023. ret = ipmi_cfgp_parse_sel(&ctx, argc, (const char **)argv, &sel);
  1024. if (ret == -1) {
  1025. lanp_print_usage(cmd);
  1026. ipmi_cfgp_uninit(&ctx);
  1027. return -1;
  1028. }
  1029. argc -= ret;
  1030. argv += ret;
  1031. /*
  1032. * handle the rest commands
  1033. */
  1034. switch (cmd) {
  1035. case LANP_CMD_SAVE:
  1036. case LANP_CMD_PRINT:
  1037. lprintf(LOG_NOTICE, "Getting parameter(s)...");
  1038. ret = ipmi_cfgp_get(&ctx, &sel);
  1039. if (ret != 0) {
  1040. break;
  1041. }
  1042. if (cmd == LANP_CMD_SAVE) {
  1043. static char cmd[20];
  1044. FILE *out = stdout;
  1045. snprintf(cmd, sizeof(cmd) - 1, "lan6 set %d nolock",
  1046. lp.channel);
  1047. cmd[sizeof(cmd) - 1] = '\0';
  1048. ctx.cmdname = cmd;
  1049. fprintf(out, "lan6 lock %d\n", lp.channel);
  1050. ret = ipmi_cfgp_save(&ctx, &sel, out);
  1051. fprintf(out, "lan6 commit %d\nlan6 discard %d\nexit\n",
  1052. lp.channel, lp.channel);
  1053. } else {
  1054. ret = ipmi_cfgp_print(&ctx, &sel, stdout);
  1055. }
  1056. break;
  1057. case LANP_CMD_SET:
  1058. ret = ipmi_cfgp_parse_data(&ctx, &sel, argc,
  1059. (const char **)argv);
  1060. if (ret != 0) {
  1061. break;
  1062. }
  1063. lprintf(LOG_NOTICE, "Setting parameter(s)...");
  1064. if (!nolock) {
  1065. ret = lanp_lock(&lp);
  1066. if (ret != 0) {
  1067. break;
  1068. }
  1069. }
  1070. ret = ipmi_cfgp_set(&ctx, &sel);
  1071. if (!nolock) {
  1072. if (ret == 0) {
  1073. ret = lanp_commit(&lp);
  1074. } else {
  1075. lanp_discard(&lp);
  1076. }
  1077. }
  1078. break;
  1079. }
  1080. /*
  1081. * free allocated memory
  1082. */
  1083. ipmi_cfgp_uninit(&ctx);
  1084. return ret;
  1085. }