You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

797 lines
22 KiB

  1. From 409f98ab443682ec360e3e76954f1c8985b3371d Mon Sep 17 00:00:00 2001
  2. From: Igor Ryzhov <iryzhov@nfware.com>
  3. Date: Thu, 28 Jan 2021 02:41:07 +0300
  4. Subject: [PATCH 1/2] ospfd: don't rely on instance existence in vty
  5. Store instance index at startup and use it when processing vty commands.
  6. The instance itself may be created and deleted by the user in runtime
  7. using `[no] router ospf X` command.
  8. Fixes #7908
  9. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
  10. ---
  11. ospfd/ospf_dump.c | 70 ++++++---------
  12. ospfd/ospf_main.c | 20 +----
  13. ospfd/ospf_vty.c | 220 +++++++++++++++++++++++-----------------------
  14. ospfd/ospfd.c | 26 +++---
  15. ospfd/ospfd.h | 3 +-
  16. 5 files changed, 154 insertions(+), 185 deletions(-)
  17. --- a/ospfd/ospf_dump.c
  18. +++ b/ospfd/ospf_dump.c
  19. @@ -607,7 +607,7 @@ DEFUN (debug_ospf_packet,
  20. if (inst) // user passed instance ID
  21. {
  22. - if (!ospf_lookup_instance(strtoul(argv[2]->arg, NULL, 10)))
  23. + if (inst != ospf_instance)
  24. return CMD_NOT_MY_INSTANCE;
  25. }
  26. @@ -683,7 +683,7 @@ DEFUN (no_debug_ospf_packet,
  27. if (inst) // user passed instance ID
  28. {
  29. - if (!ospf_lookup_instance(strtoul(argv[3]->arg, NULL, 10)))
  30. + if (inst != ospf_instance)
  31. return CMD_NOT_MY_INSTANCE;
  32. }
  33. @@ -754,7 +754,7 @@ DEFUN (debug_ospf_ism,
  34. if (inst) // user passed instance ID
  35. {
  36. - if (!ospf_lookup_instance(strtoul(argv[2]->arg, NULL, 10)))
  37. + if (inst != ospf_instance)
  38. return CMD_NOT_MY_INSTANCE;
  39. }
  40. @@ -805,7 +805,7 @@ DEFUN (no_debug_ospf_ism,
  41. if (inst) // user passed instance ID
  42. {
  43. - if (!ospf_lookup_instance(strtoul(argv[3]->arg, NULL, 10)))
  44. + if (inst != ospf_instance)
  45. return CMD_NOT_MY_INSTANCE;
  46. }
  47. @@ -900,8 +900,8 @@ DEFUN (debug_ospf_instance_nsm,
  48. unsigned short instance = 0;
  49. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  50. - if (!ospf_lookup_instance(instance))
  51. - return CMD_SUCCESS;
  52. + if (instance != ospf_instance)
  53. + return CMD_NOT_MY_INSTANCE;
  54. return debug_ospf_nsm_common(vty, 4, argc, argv);
  55. }
  56. @@ -972,7 +972,7 @@ DEFUN (no_debug_ospf_instance_nsm,
  57. unsigned short instance = 0;
  58. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  59. - if (!ospf_lookup_instance(instance))
  60. + if (instance != ospf_instance)
  61. return CMD_NOT_MY_INSTANCE;
  62. return no_debug_ospf_nsm_common(vty, 5, argc, argv);
  63. @@ -1046,7 +1046,7 @@ DEFUN (debug_ospf_instance_lsa,
  64. unsigned short instance = 0;
  65. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  66. - if (!ospf_lookup_instance(instance))
  67. + if (instance != ospf_instance)
  68. return CMD_NOT_MY_INSTANCE;
  69. return debug_ospf_lsa_common(vty, 4, argc, argv);
  70. @@ -1122,7 +1122,7 @@ DEFUN (no_debug_ospf_instance_lsa,
  71. unsigned short instance = 0;
  72. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  73. - if (!ospf_lookup_instance(instance))
  74. + if (instance != ospf_instance)
  75. return CMD_NOT_MY_INSTANCE;
  76. return no_debug_ospf_lsa_common(vty, 5, argc, argv);
  77. @@ -1184,7 +1184,7 @@ DEFUN (debug_ospf_instance_zebra,
  78. unsigned short instance = 0;
  79. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  80. - if (!ospf_lookup_instance(instance))
  81. + if (instance != ospf_instance)
  82. return CMD_NOT_MY_INSTANCE;
  83. return debug_ospf_zebra_common(vty, 4, argc, argv);
  84. @@ -1248,8 +1248,8 @@ DEFUN (no_debug_ospf_instance_zebra,
  85. unsigned short instance = 0;
  86. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  87. - if (!ospf_lookup_instance(instance))
  88. - return CMD_SUCCESS;
  89. + if (instance != ospf_instance)
  90. + return CMD_NOT_MY_INSTANCE;
  91. return no_debug_ospf_zebra_common(vty, 5, argc, argv);
  92. }
  93. @@ -1294,8 +1294,8 @@ DEFUN (debug_ospf_instance_event,
  94. unsigned short instance = 0;
  95. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  96. - if (!ospf_lookup_instance(instance))
  97. - return CMD_SUCCESS;
  98. + if (instance != ospf_instance)
  99. + return CMD_NOT_MY_INSTANCE;
  100. if (vty->node == CONFIG_NODE)
  101. CONF_DEBUG_ON(event, EVENT);
  102. @@ -1316,8 +1316,8 @@ DEFUN (no_debug_ospf_instance_event,
  103. unsigned short instance = 0;
  104. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  105. - if (!ospf_lookup_instance(instance))
  106. - return CMD_SUCCESS;
  107. + if (instance != ospf_instance)
  108. + return CMD_NOT_MY_INSTANCE;
  109. if (vty->node == CONFIG_NODE)
  110. CONF_DEBUG_OFF(event, EVENT);
  111. @@ -1364,8 +1364,8 @@ DEFUN (debug_ospf_instance_nssa,
  112. unsigned short instance = 0;
  113. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  114. - if (!ospf_lookup_instance(instance))
  115. - return CMD_SUCCESS;
  116. + if (instance != ospf_instance)
  117. + return CMD_NOT_MY_INSTANCE;
  118. if (vty->node == CONFIG_NODE)
  119. CONF_DEBUG_ON(nssa, NSSA);
  120. @@ -1386,8 +1386,8 @@ DEFUN (no_debug_ospf_instance_nssa,
  121. unsigned short instance = 0;
  122. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  123. - if (!ospf_lookup_instance(instance))
  124. - return CMD_SUCCESS;
  125. + if (instance != ospf_instance)
  126. + return CMD_NOT_MY_INSTANCE;
  127. if (vty->node == CONFIG_NODE)
  128. CONF_DEBUG_OFF(nssa, NSSA);
  129. @@ -1536,12 +1536,12 @@ DEFUN (no_debug_ospf,
  130. return CMD_SUCCESS;
  131. }
  132. -static int show_debugging_ospf_common(struct vty *vty, struct ospf *ospf)
  133. +static int show_debugging_ospf_common(struct vty *vty)
  134. {
  135. int i;
  136. - if (ospf->instance)
  137. - vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
  138. + if (ospf_instance)
  139. + vty_out(vty, "\nOSPF Instance: %d\n\n", ospf_instance);
  140. vty_out(vty, "OSPF debugging status:\n");
  141. @@ -1645,13 +1645,7 @@ DEFUN_NOSH (show_debugging_ospf,
  142. DEBUG_STR
  143. OSPF_STR)
  144. {
  145. - struct ospf *ospf = NULL;
  146. -
  147. - ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
  148. - if (ospf == NULL)
  149. - return CMD_SUCCESS;
  150. -
  151. - return show_debugging_ospf_common(vty, ospf);
  152. + return show_debugging_ospf_common(vty);
  153. }
  154. DEFUN_NOSH (show_debugging_ospf_instance,
  155. @@ -1663,14 +1657,13 @@ DEFUN_NOSH (show_debugging_ospf_instance
  156. "Instance ID\n")
  157. {
  158. int idx_number = 3;
  159. - struct ospf *ospf;
  160. unsigned short instance = 0;
  161. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  162. - if ((ospf = ospf_lookup_instance(instance)) == NULL)
  163. - return CMD_SUCCESS;
  164. + if (instance != ospf_instance)
  165. + return CMD_NOT_MY_INSTANCE;
  166. - return show_debugging_ospf_common(vty, ospf);
  167. + return show_debugging_ospf_common(vty);
  168. }
  169. static int config_write_debug(struct vty *vty);
  170. @@ -1693,16 +1686,11 @@ static int config_write_debug(struct vty
  171. "", " send", " recv", "",
  172. " detail", " send detail", " recv detail", " detail"};
  173. - struct ospf *ospf;
  174. char str[16];
  175. memset(str, 0, 16);
  176. - ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
  177. - if (ospf == NULL)
  178. - return CMD_SUCCESS;
  179. -
  180. - if (ospf->instance)
  181. - snprintf(str, sizeof(str), " %u", ospf->instance);
  182. + if (ospf_instance)
  183. + snprintf(str, sizeof(str), " %u", ospf_instance);
  184. /* debug ospf ism (status|events|timers). */
  185. if (IS_CONF_DEBUG_OSPF(ism, ISM) == OSPF_DEBUG_ISM)
  186. --- a/ospfd/ospf_main.c
  187. +++ b/ospfd/ospf_main.c
  188. @@ -145,9 +145,6 @@ FRR_DAEMON_INFO(ospfd, OSPF, .vty_port =
  189. /* OSPFd main routine. */
  190. int main(int argc, char **argv)
  191. {
  192. - unsigned short instance = 0;
  193. - bool created = false;
  194. -
  195. #ifdef SUPPORT_OSPF_API
  196. /* OSPF apiserver is disabled by default. */
  197. ospf_apiserver_enable = 0;
  198. @@ -168,8 +165,8 @@ int main(int argc, char **argv)
  199. switch (opt) {
  200. case 'n':
  201. - ospfd_di.instance = instance = atoi(optarg);
  202. - if (instance < 1)
  203. + ospfd_di.instance = ospf_instance = atoi(optarg);
  204. + if (ospf_instance < 1)
  205. exit(0);
  206. break;
  207. case 0:
  208. @@ -207,7 +204,7 @@ int main(int argc, char **argv)
  209. /* OSPFd inits. */
  210. ospf_if_init();
  211. - ospf_zebra_init(master, instance);
  212. + ospf_zebra_init(master, ospf_instance);
  213. /* OSPF vty inits. */
  214. ospf_vty_init();
  215. @@ -223,17 +220,6 @@ int main(int argc, char **argv)
  216. /* OSPF errors init */
  217. ospf_error_init();
  218. - /*
  219. - * Need to initialize the default ospf structure, so the interface mode
  220. - * commands can be duly processed if they are received before 'router
  221. - * ospf', when ospfd is restarted
  222. - */
  223. - if (instance && !ospf_get_instance(instance, &created)) {
  224. - flog_err(EC_OSPF_INIT_FAIL, "OSPF instance init failed: %s",
  225. - strerror(errno));
  226. - exit(1);
  227. - }
  228. -
  229. frr_config_fork();
  230. frr_run(master);
  231. --- a/ospfd/ospf_vty.c
  232. +++ b/ospfd/ospf_vty.c
  233. @@ -136,44 +136,37 @@ int ospf_oi_count(struct interface *ifp)
  234. all_vrf = strmatch(vrf_name, "all"); \
  235. }
  236. -static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty,
  237. - struct cmd_token *argv[],
  238. - const int argc, uint32_t enable,
  239. - unsigned short *instance)
  240. +static int ospf_router_cmd_parse(struct vty *vty, struct cmd_token *argv[],
  241. + const int argc, unsigned short *instance,
  242. + const char **vrf_name)
  243. {
  244. - struct ospf *ospf = NULL;
  245. int idx_vrf = 0, idx_inst = 0;
  246. - const char *vrf_name = NULL;
  247. - bool created = false;
  248. *instance = 0;
  249. - if (argv_find(argv, argc, "(1-65535)", &idx_inst))
  250. + if (argv_find(argv, argc, "(1-65535)", &idx_inst)) {
  251. + if (ospf_instance == 0) {
  252. + vty_out(vty,
  253. + "%% OSPF is not running in instance mode\n");
  254. + return CMD_WARNING_CONFIG_FAILED;
  255. + }
  256. +
  257. *instance = strtoul(argv[idx_inst]->arg, NULL, 10);
  258. + }
  259. + *vrf_name = NULL;
  260. if (argv_find(argv, argc, "vrf", &idx_vrf)) {
  261. - vrf_name = argv[idx_vrf + 1]->arg;
  262. - if (vrf_name == NULL || strmatch(vrf_name, VRF_DEFAULT_NAME))
  263. - vrf_name = NULL;
  264. - if (enable) {
  265. - /* Allocate VRF aware instance */
  266. - ospf = ospf_get(*instance, vrf_name, &created);
  267. - } else {
  268. - ospf = ospf_lookup_by_inst_name(*instance, vrf_name);
  269. - }
  270. - } else {
  271. - if (enable) {
  272. - ospf = ospf_get(*instance, NULL, &created);
  273. - } else {
  274. - ospf = ospf_lookup_instance(*instance);
  275. + if (ospf_instance != 0) {
  276. + vty_out(vty,
  277. + "%% VRF is not supported in instance mode\n");
  278. + return CMD_WARNING_CONFIG_FAILED;
  279. }
  280. - }
  281. - if (created) {
  282. - if (DFLT_OSPF_LOG_ADJACENCY_CHANGES)
  283. - SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
  284. + *vrf_name = argv[idx_vrf + 1]->arg;
  285. + if (*vrf_name && strmatch(*vrf_name, VRF_DEFAULT_NAME))
  286. + *vrf_name = NULL;
  287. }
  288. - return ospf;
  289. + return CMD_SUCCESS;
  290. }
  291. static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty,
  292. @@ -209,28 +202,35 @@ DEFUN_NOSH (router_ospf,
  293. "Instance ID\n"
  294. VRF_CMD_HELP_STR)
  295. {
  296. - struct ospf *ospf = NULL;
  297. - int ret = CMD_SUCCESS;
  298. - unsigned short instance = 0;
  299. + unsigned short instance;
  300. + const char *vrf_name;
  301. + bool created = false;
  302. + struct ospf *ospf;
  303. + int ret;
  304. - ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 1, &instance);
  305. - if (!ospf)
  306. - return CMD_WARNING_CONFIG_FAILED;
  307. + ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name);
  308. + if (ret != CMD_SUCCESS)
  309. + return ret;
  310. - /* The following logic to set the vty qobj index is in place to be able
  311. - to ignore the commands which dont belong to this instance. */
  312. - if (ospf->instance != instance) {
  313. + if (instance != ospf_instance) {
  314. VTY_PUSH_CONTEXT_NULL(OSPF_NODE);
  315. - ret = CMD_NOT_MY_INSTANCE;
  316. - } else {
  317. - if (IS_DEBUG_OSPF_EVENT)
  318. - zlog_debug(
  319. - "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
  320. - instance, ospf->name ? ospf->name : "NIL",
  321. - ospf->vrf_id, ospf->oi_running);
  322. - VTY_PUSH_CONTEXT(OSPF_NODE, ospf);
  323. + return CMD_NOT_MY_INSTANCE;
  324. }
  325. + ospf = ospf_get(instance, vrf_name, &created);
  326. +
  327. + if (created)
  328. + if (DFLT_OSPF_LOG_ADJACENCY_CHANGES)
  329. + SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
  330. +
  331. + if (IS_DEBUG_OSPF_EVENT)
  332. + zlog_debug(
  333. + "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
  334. + ospf->instance, ospf->name ? ospf->name : "NIL",
  335. + ospf->vrf_id, ospf->oi_running);
  336. +
  337. + VTY_PUSH_CONTEXT(OSPF_NODE, ospf);
  338. +
  339. return ret;
  340. }
  341. @@ -243,19 +243,25 @@ DEFUN (no_router_ospf,
  342. "Instance ID\n"
  343. VRF_CMD_HELP_STR)
  344. {
  345. + unsigned short instance;
  346. + const char *vrf_name;
  347. struct ospf *ospf;
  348. - unsigned short instance = 0;
  349. + int ret;
  350. - ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 0, &instance);
  351. - if (ospf == NULL) {
  352. - if (instance)
  353. - return CMD_NOT_MY_INSTANCE;
  354. - else
  355. - return CMD_WARNING;
  356. - }
  357. - ospf_finish(ospf);
  358. + ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name);
  359. + if (ret != CMD_SUCCESS)
  360. + return ret;
  361. - return CMD_SUCCESS;
  362. + if (instance != ospf_instance)
  363. + return CMD_NOT_MY_INSTANCE;
  364. +
  365. + ospf = ospf_lookup(instance, vrf_name);
  366. + if (ospf)
  367. + ospf_finish(ospf);
  368. + else
  369. + ret = CMD_WARNING_CONFIG_FAILED;
  370. +
  371. + return ret;
  372. }
  373. @@ -3324,11 +3330,11 @@ DEFUN (show_ip_ospf_instance,
  374. json_object *json = NULL;
  375. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  376. - ospf = ospf_lookup_instance(instance);
  377. - if (ospf == NULL)
  378. + if (instance != ospf_instance)
  379. return CMD_NOT_MY_INSTANCE;
  380. - if (!ospf->oi_running)
  381. + ospf = ospf_lookup_instance(instance);
  382. + if (!ospf || !ospf->oi_running)
  383. return CMD_SUCCESS;
  384. if (uj)
  385. @@ -4014,11 +4020,11 @@ DEFUN (show_ip_ospf_instance_interface,
  386. json_object *json = NULL;
  387. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  388. - ospf = ospf_lookup_instance(instance);
  389. - if (ospf == NULL)
  390. + if (instance != ospf_instance)
  391. return CMD_NOT_MY_INSTANCE;
  392. - if (!ospf->oi_running)
  393. + ospf = ospf_lookup_instance(instance);
  394. + if (!ospf || !ospf->oi_running)
  395. return CMD_SUCCESS;
  396. if (uj)
  397. @@ -4407,11 +4413,11 @@ DEFUN (show_ip_ospf_instance_neighbor,
  398. int ret = CMD_SUCCESS;
  399. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  400. - ospf = ospf_lookup_instance(instance);
  401. - if (ospf == NULL)
  402. + if (instance != ospf_instance)
  403. return CMD_NOT_MY_INSTANCE;
  404. - if (!ospf->oi_running)
  405. + ospf = ospf_lookup_instance(instance);
  406. + if (!ospf || !ospf->oi_running)
  407. return CMD_SUCCESS;
  408. if (uj)
  409. @@ -4619,11 +4625,11 @@ DEFUN (show_ip_ospf_instance_neighbor_al
  410. int ret = CMD_SUCCESS;
  411. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  412. - ospf = ospf_lookup_instance(instance);
  413. - if (ospf == NULL)
  414. + if (instance != ospf_instance)
  415. return CMD_NOT_MY_INSTANCE;
  416. - if (!ospf->oi_running)
  417. + ospf = ospf_lookup_instance(instance);
  418. + if (!ospf || !ospf->oi_running)
  419. return CMD_SUCCESS;
  420. if (uj)
  421. json = json_object_new_object();
  422. @@ -4759,11 +4765,11 @@ DEFUN (show_ip_ospf_instance_neighbor_in
  423. show_ip_ospf_neighbour_header(vty);
  424. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  425. - ospf = ospf_lookup_instance(instance);
  426. - if (ospf == NULL)
  427. + if (instance != ospf_instance)
  428. return CMD_NOT_MY_INSTANCE;
  429. - if (!ospf->oi_running)
  430. + ospf = ospf_lookup_instance(instance);
  431. + if (!ospf || !ospf->oi_running)
  432. return CMD_SUCCESS;
  433. if (!uj)
  434. @@ -5168,11 +5174,11 @@ DEFPY (show_ip_ospf_instance_neighbor_id
  435. {
  436. struct ospf *ospf;
  437. - ospf = ospf_lookup_instance(instance);
  438. - if (ospf == NULL)
  439. + if (instance != ospf_instance)
  440. return CMD_NOT_MY_INSTANCE;
  441. - if (!ospf->oi_running)
  442. + ospf = ospf_lookup_instance(instance);
  443. + if (!ospf || !ospf->oi_running)
  444. return CMD_SUCCESS;
  445. return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json,
  446. @@ -5341,11 +5347,11 @@ DEFUN (show_ip_ospf_instance_neighbor_de
  447. int ret = CMD_SUCCESS;
  448. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  449. - ospf = ospf_lookup_instance(instance);
  450. - if (ospf == NULL)
  451. + if (instance != ospf_instance)
  452. return CMD_NOT_MY_INSTANCE;
  453. - if (!ospf->oi_running)
  454. + ospf = ospf_lookup_instance(instance);
  455. + if (!ospf || !ospf->oi_running)
  456. return CMD_SUCCESS;
  457. if (uj)
  458. @@ -5536,11 +5542,11 @@ DEFUN (show_ip_ospf_instance_neighbor_de
  459. int ret = CMD_SUCCESS;
  460. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  461. - ospf = ospf_lookup_instance(instance);
  462. - if (ospf == NULL)
  463. + if (instance != ospf_instance)
  464. return CMD_NOT_MY_INSTANCE;
  465. - if (!ospf->oi_running)
  466. + ospf = ospf_lookup_instance(instance);
  467. + if (!ospf || !ospf->oi_running)
  468. return CMD_SUCCESS;
  469. if (uj)
  470. @@ -5668,11 +5674,11 @@ DEFUN (show_ip_ospf_instance_neighbor_in
  471. bool uj = use_json(argc, argv);
  472. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  473. - ospf = ospf_lookup_instance(instance);
  474. - if (ospf == NULL)
  475. + if (instance != ospf_instance)
  476. return CMD_NOT_MY_INSTANCE;
  477. - if (!ospf->oi_running)
  478. + ospf = ospf_lookup_instance(instance);
  479. + if (!ospf || !ospf->oi_running)
  480. return CMD_SUCCESS;
  481. return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname,
  482. @@ -6418,10 +6424,11 @@ DEFUN (show_ip_ospf_instance_database,
  483. if (argv_find(argv, argc, "(1-65535)", &idx)) {
  484. instance = strtoul(argv[idx]->arg, NULL, 10);
  485. - ospf = ospf_lookup_instance(instance);
  486. - if (ospf == NULL)
  487. + if (instance != ospf_instance)
  488. return CMD_NOT_MY_INSTANCE;
  489. - if (!ospf->oi_running)
  490. +
  491. + ospf = ospf_lookup_instance(instance);
  492. + if (!ospf || !ospf->oi_running)
  493. return CMD_SUCCESS;
  494. return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0,
  495. @@ -6482,15 +6489,12 @@ DEFUN (show_ip_ospf_instance_database_ma
  496. unsigned short instance = 0;
  497. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  498. -
  499. - ospf = ospf_lookup_instance(instance);
  500. - if (ospf == NULL)
  501. + if (instance != ospf_instance)
  502. return CMD_NOT_MY_INSTANCE;
  503. - if (!ospf->oi_running) {
  504. - vty_out(vty, "%% OSPF instance not found\n");
  505. + ospf = ospf_lookup_instance(instance);
  506. + if (!ospf || !ospf->oi_running)
  507. return CMD_SUCCESS;
  508. - }
  509. return show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0);
  510. }
  511. @@ -6576,13 +6580,12 @@ DEFUN (show_ip_ospf_instance_database_ty
  512. if (argv_find(argv, argc, "(1-65535)", &idx)) {
  513. instance = strtoul(argv[idx]->arg, NULL, 10);
  514. - ospf = ospf_lookup_instance(instance);
  515. - if (ospf == NULL)
  516. + if (instance != ospf_instance)
  517. return CMD_NOT_MY_INSTANCE;
  518. - if (!ospf->oi_running) {
  519. - vty_out(vty, "%% OSPF instance not found\n");
  520. +
  521. + ospf = ospf_lookup_instance(instance);
  522. + if (!ospf || !ospf->oi_running)
  523. return CMD_SUCCESS;
  524. - }
  525. return (show_ip_ospf_database_type_adv_router_common(
  526. vty, ospf, idx ? 1 : 0, argc, argv, use_vrf));
  527. @@ -8033,7 +8036,7 @@ DEFUN (ip_ospf_area,
  528. else
  529. ospf = ospf_lookup_instance(instance);
  530. - if (instance && ospf == NULL) {
  531. + if (instance && instance != ospf_instance) {
  532. /*
  533. * At this point we know we have received
  534. * an instance and there is no ospf instance
  535. @@ -8158,7 +8161,7 @@ DEFUN (no_ip_ospf_area,
  536. else
  537. ospf = ospf_lookup_instance(instance);
  538. - if (instance && ospf == NULL)
  539. + if (instance && instance != ospf_instance)
  540. return CMD_NOT_MY_INSTANCE;
  541. argv_find(argv, argc, "area", &idx);
  542. @@ -9519,11 +9522,11 @@ DEFUN (show_ip_ospf_instance_border_rout
  543. unsigned short instance = 0;
  544. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  545. - ospf = ospf_lookup_instance(instance);
  546. - if (ospf == NULL)
  547. + if (instance != ospf_instance)
  548. return CMD_NOT_MY_INSTANCE;
  549. - if (!ospf->oi_running)
  550. + ospf = ospf_lookup_instance(instance);
  551. + if (!ospf || !ospf->oi_running)
  552. return CMD_SUCCESS;
  553. return show_ip_ospf_border_routers_common(vty, ospf, 0);
  554. @@ -9687,11 +9690,11 @@ DEFUN (show_ip_ospf_instance_route,
  555. unsigned short instance = 0;
  556. instance = strtoul(argv[idx_number]->arg, NULL, 10);
  557. - ospf = ospf_lookup_instance(instance);
  558. - if (ospf == NULL)
  559. + if (instance != ospf_instance)
  560. return CMD_NOT_MY_INSTANCE;
  561. - if (!ospf->oi_running)
  562. + ospf = ospf_lookup_instance(instance);
  563. + if (!ospf || !ospf->oi_running)
  564. return CMD_SUCCESS;
  565. return show_ip_ospf_route_common(vty, ospf, NULL, 0);
  566. @@ -9787,8 +9790,7 @@ DEFPY (clear_ip_ospf_neighbor,
  567. */
  568. if (instance != 0) {
  569. /* This means clear only the particular ospf process */
  570. - ospf = ospf_lookup_instance(instance);
  571. - if (ospf == NULL)
  572. + if (instance != ospf_instance)
  573. return CMD_NOT_MY_INSTANCE;
  574. }
  575. @@ -9818,8 +9820,7 @@ DEFPY (clear_ip_ospf_process,
  576. /* Check if instance is not passed as an argument */
  577. if (instance != 0) {
  578. /* This means clear only the particular ospf process */
  579. - ospf = ospf_lookup_instance(instance);
  580. - if (ospf == NULL)
  581. + if (instance != ospf_instance)
  582. return CMD_NOT_MY_INSTANCE;
  583. }
  584. @@ -9860,7 +9861,6 @@ static int config_write_interface_one(st
  585. struct route_node *rn = NULL;
  586. struct ospf_if_params *params;
  587. int write = 0;
  588. - struct ospf *ospf = vrf->info;
  589. FOR_ALL_INTERFACES (vrf, ifp) {
  590. @@ -10039,9 +10039,9 @@ static int config_write_interface_one(st
  591. /* Area print. */
  592. if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
  593. - if (ospf && ospf->instance)
  594. + if (ospf_instance)
  595. vty_out(vty, " ip ospf %d",
  596. - ospf->instance);
  597. + ospf_instance);
  598. else
  599. vty_out(vty, " ip ospf");
  600. --- a/ospfd/ospfd.c
  601. +++ b/ospfd/ospfd.c
  602. @@ -67,6 +67,8 @@ static struct ospf_master ospf_master;
  603. /* OSPF process wide configuration pointer to export. */
  604. struct ospf_master *om;
  605. +unsigned short ospf_instance;
  606. +
  607. extern struct zclient *zclient;
  608. @@ -468,36 +470,28 @@ static void ospf_init(struct ospf *ospf)
  609. ospf_router_id_update(ospf);
  610. }
  611. -struct ospf *ospf_get(unsigned short instance, const char *name, bool *created)
  612. +struct ospf *ospf_lookup(unsigned short instance, const char *name)
  613. {
  614. struct ospf *ospf;
  615. - /* vrf name provided call inst and name based api
  616. - * in case of no name pass default ospf instance */
  617. - if (name)
  618. + if (ospf_instance) {
  619. + ospf = ospf_lookup_instance(instance);
  620. + } else {
  621. ospf = ospf_lookup_by_inst_name(instance, name);
  622. - else
  623. - ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
  624. -
  625. - *created = (ospf == NULL);
  626. - if (ospf == NULL) {
  627. - ospf = ospf_new(instance, name);
  628. - ospf_add(ospf);
  629. -
  630. - ospf_init(ospf);
  631. }
  632. return ospf;
  633. }
  634. -struct ospf *ospf_get_instance(unsigned short instance, bool *created)
  635. +struct ospf *ospf_get(unsigned short instance, const char *name, bool *created)
  636. {
  637. struct ospf *ospf;
  638. - ospf = ospf_lookup_instance(instance);
  639. + ospf = ospf_lookup(instance, name);
  640. +
  641. *created = (ospf == NULL);
  642. if (ospf == NULL) {
  643. - ospf = ospf_new(instance, NULL /* VRF_DEFAULT*/);
  644. + ospf = ospf_new(instance, name);
  645. ospf_add(ospf);
  646. ospf_init(ospf);
  647. --- a/ospfd/ospfd.h
  648. +++ b/ospfd/ospfd.h
  649. @@ -507,6 +507,7 @@ struct ospf_nbr_nbma {
  650. /* Extern variables. */
  651. extern struct ospf_master *om;
  652. +extern unsigned short ospf_instance;
  653. extern const int ospf_redistributed_proto_max;
  654. extern struct zclient *zclient;
  655. extern struct thread_master *master;
  656. @@ -516,9 +517,9 @@ extern struct zebra_privs_t ospfd_privs;
  657. /* Prototypes. */
  658. extern const char *ospf_redist_string(unsigned int route_type);
  659. extern struct ospf *ospf_lookup_instance(unsigned short);
  660. +extern struct ospf *ospf_lookup(unsigned short instance, const char *name);
  661. extern struct ospf *ospf_get(unsigned short instance, const char *name,
  662. bool *created);
  663. -extern struct ospf *ospf_get_instance(unsigned short, bool *created);
  664. extern struct ospf *ospf_lookup_by_inst_name(unsigned short instance,
  665. const char *name);
  666. extern struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id);
  667. --- a/vtysh/vtysh.c
  668. +++ b/vtysh/vtysh.c
  669. @@ -2487,7 +2487,7 @@ static int show_per_daemon(const char *l
  670. int ret = CMD_SUCCESS;
  671. for (i = 0; i < array_size(vtysh_client); i++)
  672. - if (vtysh_client[i].fd >= 0) {
  673. + if (vtysh_client[i].fd >= 0 || vtysh_client[i].next) {
  674. vty_out(vty, headline, vtysh_client[i].name);
  675. ret = vtysh_client_execute(&vtysh_client[i], line);
  676. vty_out(vty, "\n");