From 65536c82c3b5b784f21c65223b0ce374f74e0a04 Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Tue, 26 Sep 2017 11:29:33 -0700 Subject: [PATCH 1/5] ospfd: fix virtual-link config command Signed-off-by: Chirag Shah --- ospfd/ospf_vty.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 4cbd4b4a99..4f0c27a33b 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -1016,7 +1016,7 @@ DEFUN (ospf_area_vlink, } /* Deal with other parameters */ - for (i = 5; i < argc; i++) { + for (i = 4; i < argc; i++) { /* vty_out (vty, "argv[%d]->arg - %s\n", i, argv[i]->text); */ @@ -1027,10 +1027,8 @@ DEFUN (ospf_area_vlink, || strncmp(argv[i]->arg, "authentication-", 15) == 0) { /* authentication-key - this option can occur - anywhere on - command line. At start - of command line - must check for + anywhere on command line. At start + of command line must check for authentication option. */ memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); strncpy(auth_key, argv[i + 1]->text, @@ -1040,8 +1038,7 @@ DEFUN (ospf_area_vlink, } else if (strncmp(argv[i]->arg, "authentication", 14) == 0) { /* authentication - this option can only occur - at start - of command line */ + at start of command line */ vl_config.auth_type = OSPF_AUTH_SIMPLE; if ((i + 1) < argc) { if (strncmp(argv[i + 1]->arg, "n", 1) @@ -1054,9 +1051,9 @@ DEFUN (ospf_area_vlink, strncmp(argv[i + 1]->arg, "m", 1) == 0 - && !strmatch( + && strmatch( argv[i + 1]->text, - "message-digest-")) { + "message-digest")) { /* "authentication * message-digest" */ vl_config.auth_type = @@ -1153,29 +1150,28 @@ DEFUN (no_ospf_area_vlink, /* If we are down here, we are reseting parameters */ /* Deal with other parameters */ - for (i = 6; i < argc; i++) { + for (i = 5; i < argc; i++) { /* vty_out (vty, "argv[%d] - %s\n", i, argv[i]); */ switch (argv[i]->arg[0]) { case 'a': - if (i > 2 + if (i > 6 || strncmp(argv[i]->text, "authentication-", 15) == 0) { /* authentication-key - this option can occur - anywhere on - command line. At start - of command line - must check for + anywhere on command line. At start + of command line must check for authentication option. */ memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); vl_config.auth_key = auth_key; } else if (strncmp(argv[i]->text, "authentication", 14) == 0) { /* authentication - this option can only occur - at start - of command line */ + at start of command line */ vl_config.auth_type = OSPF_AUTH_NOTSET; + if ((i + 1) < argc) + i++; } break; @@ -1186,6 +1182,7 @@ DEFUN (no_ospf_area_vlink, if (i < argc) { vl_config.crypto_key_id = strtol(argv[i]->arg, NULL, 10); + i++; /* skip md5_key arg for delete */ if (vl_config.crypto_key_id < 0) return CMD_WARNING_CONFIG_FAILED; vl_config.md5_key = NULL; From 3d1c6dc2c6f0a0de42a89057a4f7dde2433b62dc Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Wed, 27 Sep 2017 13:51:16 -0700 Subject: [PATCH 2/5] ospfd: fix ospf virtual-link command options use argv_find to extract ospf area virtual-link command options. Signed-off-by: Chirag Shah --- ospfd/ospf_vty.c | 190 +++++++++++++++++------------------------------ 1 file changed, 69 insertions(+), 121 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 4f0c27a33b..30cf9f4182 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -974,15 +974,16 @@ static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) DEFUN (ospf_area_vlink, ospf_area_vlink_cmd, - "area virtual-link A.B.C.D [authentication] [] []", + "area virtual-link A.B.C.D [authentication []] []", VLINK_HELPSTR_IPADDR - "Enable authentication on this virtual link\n" \ - "Use null authentication\n" \ + "Enable authentication on this virtual link\n" "Use message-digest authentication\n" - "Message digest authentication password (key)\n" \ - "Key ID\n" \ - "Use MD5 algorithm\n" \ - "The OSPF password (key)") + "Use null authentication\n" + "Message digest authentication password (key)\n" + "Key ID\n" + "Use MD5 algorithm\n" + "The OSPF password (key)\n" + "Authentication password (key)") { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); int idx_ipv4_number = 1; @@ -990,8 +991,8 @@ DEFUN (ospf_area_vlink, struct ospf_vl_config_data vl_config; char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; char md5_key[OSPF_AUTH_MD5_SIZE + 1]; - int i; int ret; + int idx; ospf_vl_config_data_init(&vl_config, vty); @@ -1015,77 +1016,44 @@ DEFUN (ospf_area_vlink, return ospf_vl_set(ospf, &vl_config); } - /* Deal with other parameters */ - for (i = 4; i < argc; i++) { - - /* vty_out (vty, "argv[%d]->arg - %s\n", i, argv[i]->text); */ - - switch (argv[i]->arg[0]) { - - case 'a': - if (i > 5 - || strncmp(argv[i]->arg, "authentication-", 15) - == 0) { - /* authentication-key - this option can occur - anywhere on command line. At start - of command line must check for - authentication option. */ - memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); - strncpy(auth_key, argv[i + 1]->text, - OSPF_AUTH_SIMPLE_SIZE); - vl_config.auth_key = auth_key; - i++; - } else if (strncmp(argv[i]->arg, "authentication", 14) - == 0) { - /* authentication - this option can only occur - at start of command line */ - vl_config.auth_type = OSPF_AUTH_SIMPLE; - if ((i + 1) < argc) { - if (strncmp(argv[i + 1]->arg, "n", 1) - == 0) { - /* "authentication null" */ - vl_config.auth_type = - OSPF_AUTH_NULL; - i++; - } else if ( - strncmp(argv[i + 1]->arg, "m", - 1) - == 0 - && strmatch( - argv[i + 1]->text, - "message-digest")) { - /* "authentication - * message-digest" */ - vl_config.auth_type = - OSPF_AUTH_CRYPTOGRAPHIC; - i++; - } - } - } - break; - - case 'm': - /* message-digest-key */ - i++; - if (i < argc) { - vl_config.crypto_key_id = - strtol(argv[i]->arg, NULL, 10); - if (vl_config.crypto_key_id < 0) - return CMD_WARNING_CONFIG_FAILED; - i++; - if (i < argc) { - memset(md5_key, 0, - OSPF_AUTH_MD5_SIZE + 1); - strncpy(md5_key, argv[i]->arg, - OSPF_AUTH_MD5_SIZE); - vl_config.md5_key = md5_key; - } - } else - vl_config.md5_key = NULL; - break; - } + if (argv_find(argv, argc, "authentication", &idx)) { + /* authentication - this option can only occur + at start of command line */ + vl_config.auth_type = OSPF_AUTH_SIMPLE; } + idx = 2; + if (argv_find(argv, argc, "message-digest", &idx)) { + /* authentication - this option can only occur + at start of command line */ + vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; + } else if (argv_find(argv, argc, "null", &idx)) { + /* "authentication null" */ + vl_config.auth_type = OSPF_AUTH_NULL; + } + + idx = 3; + if (argv_find(argv, argc, "message-digest-key", &idx)) { + idx = idx + 1; /* Fetch key_id */ + + vl_config.md5_key = NULL; + vl_config.crypto_key_id = strtol(argv[idx]->arg, NULL, 10); + if (vl_config.crypto_key_id < 0) + return CMD_WARNING_CONFIG_FAILED; + + idx = idx + 1; /* Fetch md5_key */ + memset(md5_key, 0, OSPF_AUTH_MD5_SIZE + 1); + strncpy(md5_key, argv[idx]->arg, OSPF_AUTH_MD5_SIZE); + vl_config.md5_key = md5_key; + } + + idx = 3; + if (argv_find(argv, argc, "authentication-key", &idx)) { + idx = idx + 1; + memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); + strncpy(auth_key, argv[idx]->text, OSPF_AUTH_SIMPLE_SIZE); + vl_config.auth_key = auth_key; + } /* Action configuration */ @@ -1094,16 +1062,17 @@ DEFUN (ospf_area_vlink, DEFUN (no_ospf_area_vlink, no_ospf_area_vlink_cmd, - "no area virtual-link A.B.C.D [authentication] [] []", + "no area virtual-link A.B.C.D [authentication []] []", NO_STR VLINK_HELPSTR_IPADDR "Enable authentication on this virtual link\n" \ + "Use message-digest authentication\n" \ "Use null authentication\n" \ - "Use message-digest authentication\n" "Message digest authentication password (key)\n" \ "Key ID\n" \ "Use MD5 algorithm\n" \ - "The OSPF password (key)") + "The OSPF password (key)\n" \ + "Authentication password (key)") { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); int idx_ipv4_number = 2; @@ -1112,7 +1081,7 @@ DEFUN (no_ospf_area_vlink, struct ospf_vl_config_data vl_config; struct ospf_vl_data *vl_data = NULL; char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; - int i; + int idx = 0; int ret, format; ospf_vl_config_data_init(&vl_config, vty); @@ -1148,50 +1117,29 @@ DEFUN (no_ospf_area_vlink, } /* If we are down here, we are reseting parameters */ - /* Deal with other parameters */ - for (i = 5; i < argc; i++) { - /* vty_out (vty, "argv[%d] - %s\n", i, argv[i]); */ - switch (argv[i]->arg[0]) { - - case 'a': - if (i > 6 - || strncmp(argv[i]->text, "authentication-", 15) - == 0) { - /* authentication-key - this option can occur - anywhere on command line. At start - of command line must check for - authentication option. */ - memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); - vl_config.auth_key = auth_key; - } else if (strncmp(argv[i]->text, "authentication", 14) - == 0) { - /* authentication - this option can only occur - at start of command line */ - vl_config.auth_type = OSPF_AUTH_NOTSET; - if ((i + 1) < argc) - i++; - } - break; - - case 'm': - /* message-digest-key */ - /* Delete one key */ - i++; - if (i < argc) { - vl_config.crypto_key_id = - strtol(argv[i]->arg, NULL, 10); - i++; /* skip md5_key arg for delete */ - if (vl_config.crypto_key_id < 0) - return CMD_WARNING_CONFIG_FAILED; - vl_config.md5_key = NULL; - } else - return CMD_WARNING_CONFIG_FAILED; - break; - } + if (argv_find(argv, argc, "authentication", &idx)) { + /* authentication - this option can only occur + at start of command line */ + vl_config.auth_type = OSPF_AUTH_NOTSET; } + idx = 3; + if (argv_find(argv, argc, "message-digest-key", &idx)) { + idx = idx + 1; /* Fetch key_id */ + vl_config.md5_key = NULL; + vl_config.crypto_key_id = strtol(argv[idx]->arg, NULL, 10); + if (vl_config.crypto_key_id < 0) + return CMD_WARNING_CONFIG_FAILED; + } + + idx = 3; + if (argv_find(argv, argc, "authentication-key", &idx)) { + idx = idx + 1; + memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); + vl_config.auth_key = auth_key; + } /* Action configuration */ From 55d1da2490e428ad4b73c413c229e2277ab91571 Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Fri, 29 Sep 2017 10:52:11 -0700 Subject: [PATCH 3/5] ospfd: ospf virtual-link fix Initialize idx to 0 and remove reassignment of idx Signed-off-by: Chirag Shah --- ospfd/ospf_vty.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 30cf9f4182..c8ab62b96c 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -992,7 +992,7 @@ DEFUN (ospf_area_vlink, char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; char md5_key[OSPF_AUTH_MD5_SIZE + 1]; int ret; - int idx; + int idx = 0; ospf_vl_config_data_init(&vl_config, vty); @@ -1022,7 +1022,6 @@ DEFUN (ospf_area_vlink, vl_config.auth_type = OSPF_AUTH_SIMPLE; } - idx = 2; if (argv_find(argv, argc, "message-digest", &idx)) { /* authentication - this option can only occur at start of command line */ @@ -1032,7 +1031,6 @@ DEFUN (ospf_area_vlink, vl_config.auth_type = OSPF_AUTH_NULL; } - idx = 3; if (argv_find(argv, argc, "message-digest-key", &idx)) { idx = idx + 1; /* Fetch key_id */ @@ -1047,7 +1045,6 @@ DEFUN (ospf_area_vlink, vl_config.md5_key = md5_key; } - idx = 3; if (argv_find(argv, argc, "authentication-key", &idx)) { idx = idx + 1; memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); @@ -1125,7 +1122,6 @@ DEFUN (no_ospf_area_vlink, vl_config.auth_type = OSPF_AUTH_NOTSET; } - idx = 3; if (argv_find(argv, argc, "message-digest-key", &idx)) { idx = idx + 1; /* Fetch key_id */ vl_config.md5_key = NULL; @@ -1134,7 +1130,6 @@ DEFUN (no_ospf_area_vlink, return CMD_WARNING_CONFIG_FAILED; } - idx = 3; if (argv_find(argv, argc, "authentication-key", &idx)) { idx = idx + 1; memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); From cbb9b53d32f2c325520734e9a7402b4c09204de5 Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Sat, 30 Sep 2017 19:14:18 -0700 Subject: [PATCH 4/5] ospfd: fix area virtual-link command Adjust to review comments Signed-off-by: Chirag Shah --- ospfd/ospf_vty.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index c8ab62b96c..927e8c0c31 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -983,7 +983,8 @@ DEFUN (ospf_area_vlink, "Key ID\n" "Use MD5 algorithm\n" "The OSPF password (key)\n" - "Authentication password (key)") + "Authentication password (key)\n" + "The OSPF password (key)") { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); int idx_ipv4_number = 1; @@ -1032,23 +1033,19 @@ DEFUN (ospf_area_vlink, } if (argv_find(argv, argc, "message-digest-key", &idx)) { - idx = idx + 1; /* Fetch key_id */ - vl_config.md5_key = NULL; - vl_config.crypto_key_id = strtol(argv[idx]->arg, NULL, 10); + vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); if (vl_config.crypto_key_id < 0) return CMD_WARNING_CONFIG_FAILED; - idx = idx + 1; /* Fetch md5_key */ memset(md5_key, 0, OSPF_AUTH_MD5_SIZE + 1); - strncpy(md5_key, argv[idx]->arg, OSPF_AUTH_MD5_SIZE); + strncpy(md5_key, argv[idx + 3]->arg, OSPF_AUTH_MD5_SIZE); vl_config.md5_key = md5_key; } if (argv_find(argv, argc, "authentication-key", &idx)) { - idx = idx + 1; memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); - strncpy(auth_key, argv[idx]->text, OSPF_AUTH_SIMPLE_SIZE); + strncpy(auth_key, argv[idx + 1]->arg, OSPF_AUTH_SIMPLE_SIZE); vl_config.auth_key = auth_key; } @@ -1069,7 +1066,8 @@ DEFUN (no_ospf_area_vlink, "Key ID\n" \ "Use MD5 algorithm\n" \ "The OSPF password (key)\n" \ - "Authentication password (key)") + "Authentication password (key)\n" \ + "The OSPF password (key)") { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); int idx_ipv4_number = 2; @@ -1123,15 +1121,14 @@ DEFUN (no_ospf_area_vlink, } if (argv_find(argv, argc, "message-digest-key", &idx)) { - idx = idx + 1; /* Fetch key_id */ vl_config.md5_key = NULL; - vl_config.crypto_key_id = strtol(argv[idx]->arg, NULL, 10); + vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); if (vl_config.crypto_key_id < 0) return CMD_WARNING_CONFIG_FAILED; } if (argv_find(argv, argc, "authentication-key", &idx)) { - idx = idx + 1; + /* Reset authentication-key to 0 */ memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); vl_config.auth_key = auth_key; } From baf9eaad50d9f18c06edaa583d77dbd0ab904882 Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Mon, 2 Oct 2017 09:17:33 -0700 Subject: [PATCH 5/5] ospfd: ospf use macro for authentication Signed-off-by: Chirag Shah --- ospfd/ospf_vty.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 927e8c0c31..f6a101de80 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -963,14 +963,13 @@ static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) #define VLINK_HELPSTR_AUTH_SIMPLE \ "Authentication password (key)\n" \ - "The OSPF password (key)" + "The OSPF password (key)\n" #define VLINK_HELPSTR_AUTH_MD5 \ "Message digest authentication password (key)\n" \ - "dummy string \n" \ "Key ID\n" \ "Use MD5 algorithm\n" \ - "The OSPF password (key)" + "The OSPF password (key)\n" DEFUN (ospf_area_vlink, ospf_area_vlink_cmd, @@ -979,12 +978,8 @@ DEFUN (ospf_area_vlink, "Enable authentication on this virtual link\n" "Use message-digest authentication\n" "Use null authentication\n" - "Message digest authentication password (key)\n" - "Key ID\n" - "Use MD5 algorithm\n" - "The OSPF password (key)\n" - "Authentication password (key)\n" - "The OSPF password (key)") + VLINK_HELPSTR_AUTH_MD5 + VLINK_HELPSTR_AUTH_SIMPLE) { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); int idx_ipv4_number = 1; @@ -1024,8 +1019,7 @@ DEFUN (ospf_area_vlink, } if (argv_find(argv, argc, "message-digest", &idx)) { - /* authentication - this option can only occur - at start of command line */ + /* authentication message-digest */ vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; } else if (argv_find(argv, argc, "null", &idx)) { /* "authentication null" */ @@ -1062,12 +1056,8 @@ DEFUN (no_ospf_area_vlink, "Enable authentication on this virtual link\n" \ "Use message-digest authentication\n" \ "Use null authentication\n" \ - "Message digest authentication password (key)\n" \ - "Key ID\n" \ - "Use MD5 algorithm\n" \ - "The OSPF password (key)\n" \ - "Authentication password (key)\n" \ - "The OSPF password (key)") + VLINK_HELPSTR_AUTH_MD5 + VLINK_HELPSTR_AUTH_SIMPLE) { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); int idx_ipv4_number = 2; @@ -5808,8 +5798,7 @@ DEFUN_HIDDEN (ospf_authentication_key, ospf_authentication_key_cmd, "ospf authentication-key AUTH_KEY [A.B.C.D]", "OSPF interface commands\n" - "Authentication password (key)\n" - "The OSPF password (key)\n" + VLINK_HELPSTR_AUTH_SIMPLE "Address of interface\n") { return ip_ospf_authentication_key(self, vty, argc, argv); @@ -5821,8 +5810,8 @@ DEFUN (no_ip_ospf_authentication_key, NO_STR "IP Information\n" "OSPF interface commands\n" - "Authentication password (key)\n" - "The OSPF password (key)") + VLINK_HELPSTR_AUTH_SIMPLE + "Address of interface\n") { VTY_DECLVAR_CONTEXT(interface, ifp); int idx = 0; @@ -5858,8 +5847,8 @@ DEFUN_HIDDEN (no_ospf_authentication_key, "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", NO_STR "OSPF interface commands\n" - "Authentication password (key)\n" - "The OSPF password (key)") + VLINK_HELPSTR_AUTH_SIMPLE + "Address of interface\n") { return no_ip_ospf_authentication_key(self, vty, argc, argv); }