From e24ff4c275f0729f75be9f68d08be80ac1e0ec56 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 11 Jun 2024 11:59:37 +0300 Subject: [PATCH 1/3] ospfd: Drop `interfaceIp` from `show ip ospf neigh json` Deprecated. Now it's under interface field directly: ``` { "interfaces":{ "enp3s0":{ "ifUp":true, "ifIndex":2, "mtuBytes":1500, "bandwidthMbit":100, "ifFlags":"", "ospfEnabled":true, "ipAddress":"192.168.10.19", "ipAddressPrefixlen":24, "ospfIfType":"Broadcast", "localIfUsed":"192.168.10.255", "area":"0.0.0.0", "routerId":"100.100.100.100", "networkType":"POINTOPOINT", "cost":1000, "transmitDelaySecs":1, "state":"Point-To-Point", "priority":1, "opaqueCapable":true, "mcastMemberOspfAllRouters":true, "timerMsecs":10000, "timerDeadSecs":40, "timerWaitSecs":40, "timerRetransmitSecs":5, "timerHelloInMsecs":2924, "nbrCount":0, "nbrAdjacentCount":0, "grHelloDelaySecs":10, "prefixSuppression":false, "nbrFilterPrefixList":"N\/A" } } } ``` Signed-off-by: Donatas Abraitis --- ospfd/ospf_vty.c | 192 +++++++---------------------------------------- 1 file changed, 26 insertions(+), 166 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 7cb51976f5..21acd402f4 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -3576,7 +3576,6 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, struct route_node *rn; uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; struct ospf_if_params *params; - json_object *json_ois = NULL; json_object *json_oi = NULL; /* Is interface up? */ @@ -3628,33 +3627,20 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, } } - if (use_json) { - json_ois = json_object_new_object(); - json_object_object_add(json_interface_sub, "interfaceIp", - json_ois); - } - for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { struct ospf_interface *oi = rn->info; if (oi == NULL) continue; -#if CONFDATE > 20240601 - CPP_NOTICE( - "Use all fields following ospfEnabled from interfaceIp hierarchy") -#endif - if (use_json) json_oi = json_object_new_object(); if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { - if (use_json) { - json_object_boolean_true_add(json_interface_sub, - "ifUnnumbered"); + if (use_json) json_object_boolean_true_add(json_oi, "ifUnnumbered"); - } else + else vty_out(vty, " This interface is UNNUMBERED,"); } else { struct in_addr dest; @@ -3668,13 +3654,6 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_object_int_add(json_interface_sub, "ipAddressPrefixlen", oi->address->prefixlen); - - json_object_string_addf( - json_oi, "ipAddress", "%pI4", - &oi->address->u.prefix4); - json_object_int_add(json_oi, - "ipAddressPrefixlen", - oi->address->prefixlen); } else vty_out(vty, " Internet Address %pFX,", oi->address); @@ -3700,26 +3679,14 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_object_string_add(json_interface_sub, "ospfIfType", dstr); - json_object_string_add(json_oi, "ospfIfType", - dstr); - - if (oi->type == OSPF_IFTYPE_VIRTUALLINK) { + if (oi->type == OSPF_IFTYPE_VIRTUALLINK) json_object_string_addf( json_interface_sub, "vlinkPeer", "%pI4", &dest); - - json_object_string_addf(json_oi, - "vlinkPeer", - "%pI4", &dest); - } else { + else json_object_string_addf( json_interface_sub, "localIfUsed", "%pI4", &dest); - - json_object_string_addf(json_oi, - "localIfUsed", - "%pI4", &dest); - } } else vty_out(vty, " %s %pI4,", dstr, &dest); @@ -3728,16 +3695,10 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_object_string_add(json_interface_sub, "area", ospf_area_desc_string(oi->area)); - json_object_string_add(json_oi, "area", - ospf_area_desc_string(oi->area)); - - if (OSPF_IF_PARAM(oi, mtu_ignore)) { - json_object_boolean_true_add( - json_oi, "mtuMismatchDetect"); + if (OSPF_IF_PARAM(oi, mtu_ignore)) json_object_boolean_true_add( json_interface_sub, "mtuMismatchDetect"); - } json_object_string_addf(json_interface_sub, "routerId", "%pI4", &ospf->router_id); @@ -3754,18 +3715,6 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, oi->state, NULL)); json_object_int_add(json_interface_sub, "priority", PRIORITY(oi)); - - json_object_string_addf(json_oi, "routerId", "%pI4", - &ospf->router_id); - json_object_string_add(json_oi, "networkType", - ospf_network_type_str[oi->type]); - json_object_int_add(json_oi, "cost", oi->output_cost); - json_object_int_add(json_oi, "transmitDelaySecs", - OSPF_IF_PARAM(oi, transmit_delay)); - json_object_string_add(json_oi, "state", - lookup_msg(ospf_ism_state_msg, - oi->state, NULL)); - json_object_int_add(json_oi, "priority", PRIORITY(oi)); json_object_boolean_add( json_interface_sub, "opaqueCapable", OSPF_IF_PARAM(oi, opaque_capable)); @@ -3809,13 +3758,6 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_interface_sub, "drAddress", "%pI4", &nbr->address.u.prefix4); - - json_object_string_addf( - json_oi, "drId", "%pI4", - &nbr->router_id); - json_object_string_addf( - json_oi, "drAddress", "%pI4", - &nbr->address.u.prefix4); } else { vty_out(vty, " Designated Router (ID) %pI4", @@ -3841,13 +3783,6 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_interface_sub, "bdrAddress", "%pI4", &nbr->address.u.prefix4); - - json_object_string_addf( - json_oi, "bdrId", "%pI4", - &nbr->router_id); - json_object_string_addf( - json_oi, "bdrAddress", "%pI4", - &nbr->address.u.prefix4); } else { vty_out(vty, " Backup Designated Router (ID) %pI4,", @@ -3863,43 +3798,28 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, if (oi->params && ntohl(oi->params->network_lsa_seqnum) != OSPF_INITIAL_SEQUENCE_NUMBER) { - if (use_json) { + if (use_json) json_object_int_add( json_interface_sub, "networkLsaSequence", ntohl(oi->params->network_lsa_seqnum)); - - json_object_int_add( - json_oi, "networkLsaSequence", - ntohl(oi->params->network_lsa_seqnum)); - } else { + else vty_out(vty, " Saved Network-LSA sequence number 0x%x\n", ntohl(oi->params->network_lsa_seqnum)); - } } if (use_json) { if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { - if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) { + if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) json_object_boolean_true_add( json_interface_sub, "mcastMemberOspfAllRouters"); - - json_object_boolean_true_add( - json_oi, - "mcastMemberOspfAllRouters"); - } - if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { + if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) json_object_boolean_true_add( json_interface_sub, "mcastMemberOspfDesignatedRouters"); - - json_object_boolean_true_add( - json_oi, - "mcastMemberOspfDesignatedRouters"); - } } } else { vty_out(vty, " Multicast group memberships:"); @@ -3915,23 +3835,14 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, } if (use_json) { - if (OSPF_IF_PARAM(oi, fast_hello) == 0) { + if (OSPF_IF_PARAM(oi, fast_hello) == 0) json_object_int_add( json_interface_sub, "timerMsecs", OSPF_IF_PARAM(oi, v_hello) * 1000); - - json_object_int_add(json_oi, "timerMsecs", - OSPF_IF_PARAM(oi, v_hello) * - 1000); - } else { + else json_object_int_add( json_interface_sub, "timerMsecs", 1000 / OSPF_IF_PARAM(oi, fast_hello)); - - json_object_int_add( - json_oi, "timerMsecs", - 1000 / OSPF_IF_PARAM(oi, fast_hello)); - } json_object_int_add(json_interface_sub, "timerDeadSecs", OSPF_IF_PARAM(oi, v_wait)); json_object_int_add(json_interface_sub, "timerWaitSecs", @@ -3939,14 +3850,6 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_object_int_add( json_interface_sub, "timerRetransmitSecs", OSPF_IF_PARAM(oi, retransmit_interval)); - - json_object_int_add(json_oi, "timerDeadSecs", - OSPF_IF_PARAM(oi, v_wait)); - json_object_int_add(json_oi, "timerWaitSecs", - OSPF_IF_PARAM(oi, v_wait)); - json_object_int_add( - json_oi, "timerRetransmitSecs", - OSPF_IF_PARAM(oi, retransmit_interval)); } else { vty_out(vty, " Timer intervals configured,"); vty_out(vty, " Hello "); @@ -3975,23 +3878,17 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_object_int_add(json_interface_sub, "timerHelloInMsecs", time_store); - json_object_int_add(json_oi, - "timerHelloInMsecs", - time_store); } else vty_out(vty, " Hello due in %s\n", ospf_timer_dump(oi->t_hello, timebuf, sizeof(timebuf))); } else /* passive-interface is set */ { - if (use_json) { + if (use_json) json_object_boolean_true_add( json_interface_sub, "timerPassiveIface"); - - json_object_boolean_true_add( - json_oi, "timerPassiveIface"); - } else + else vty_out(vty, " No Hellos (Passive interface)\n"); } @@ -4002,11 +3899,6 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_object_int_add(json_interface_sub, "nbrAdjacentCount", ospf_nbr_count(oi, NSM_Full)); - - json_object_int_add(json_oi, "nbrCount", - ospf_nbr_count(oi, 0)); - json_object_int_add(json_oi, "nbrAdjacentCount", - ospf_nbr_count(oi, NSM_Full)); } else vty_out(vty, " Neighbor Count is %d, Adjacent neighbor count is %d\n", @@ -4016,14 +3908,11 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, params = IF_DEF_PARAMS(ifp); if (params && OSPF_IF_PARAM_CONFIGURED(params, v_gr_hello_delay)) { - if (use_json) { + if (use_json) json_object_int_add(json_interface_sub, "grHelloDelaySecs", params->v_gr_hello_delay); - - json_object_int_add(json_oi, "grHelloDelaySecs", - params->v_gr_hello_delay); - } else + else vty_out(vty, " Graceful Restart hello delay: %us\n", params->v_gr_hello_delay); @@ -4031,19 +3920,14 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, ospf_interface_bfd_show(vty, ifp, json_interface_sub); - if (use_json) { + if (use_json) json_object_boolean_add(json_interface_sub, "prefixSuppression", OSPF_IF_PARAM(oi, prefix_suppression)); - json_object_boolean_add(json_oi, "prefixSuppression", - OSPF_IF_PARAM(oi, - prefix_suppression)); - } else { - if (OSPF_IF_PARAM(oi, prefix_suppression)) - vty_out(vty, - " Suppress advertisement of interface IP prefix\n"); - } + else if (OSPF_IF_PARAM(oi, prefix_suppression)) + vty_out(vty, + " Suppress advertisement of interface IP prefix\n"); /* OSPF Authentication information */ ospf_interface_auth_show(vty, oi, json_interface_sub, use_json); @@ -4052,63 +3936,39 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, /* Point-to-Multipoint Interface options. */ if (oi->type == OSPF_IFTYPE_POINTOMULTIPOINT) { - if (use_json) { + if (use_json) json_object_boolean_add(json_interface_sub, "p2mpDelayReflood", oi->p2mp_delay_reflood); - - json_object_boolean_add(json_oi, - "p2mpDelayReflood", - oi->p2mp_delay_reflood); - } else { + else vty_out(vty, " %sDelay reflooding LSAs received on P2MP interface\n", oi->p2mp_delay_reflood ? "" : "Don't "); - } - if (use_json) { + if (use_json) json_object_boolean_add(json_interface_sub, "p2mpNonBroadcast", oi->p2mp_non_broadcast); - - json_object_boolean_add(json_oi, - "p2mpNonBroadcast", - oi->p2mp_non_broadcast); - } else { + else vty_out(vty, " P2MP interface does %ssupport broadcast\n", oi->p2mp_non_broadcast ? "not " : ""); - } } - /* Add ospf_interface object to main json blob using SIP as key - */ - if (use_json) - json_object_object_addf(json_ois, json_oi, "%pI4", - &oi->address->u.prefix4); - if (oi->nbr_filter) { - if (use_json) { + if (use_json) json_object_string_add(json_interface_sub, "nbrFilterPrefixList", prefix_list_name( oi->nbr_filter)); - json_object_string_add(json_oi, - "nbrFilterPrefixList", - prefix_list_name( - oi->nbr_filter)); - } else + else vty_out(vty, " Neighbor filter prefix-list: %s\n", prefix_list_name(oi->nbr_filter)); } else { - if (use_json) { + if (use_json) json_object_string_add(json_interface_sub, "nbrFilterPrefixList", "N/A"); - json_object_string_add(json_oi, - "nbrFilterPrefixList", - "N/A"); - } } } } From 3cc01bb00b85d9ff74c00130dadeb53913f02e79 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 11 Jun 2024 15:48:23 +0300 Subject: [PATCH 2/3] tests: Drop `interfaceIp` from OSPF tests Deprecated. Signed-off-by: Donatas Abraitis --- .../ospf_p2mp/test_ospf_p2mp_broadcast.py | 27 ------------------- .../ospf_p2mp/test_ospf_p2mp_non_broadcast.py | 16 ----------- 2 files changed, 43 deletions(-) diff --git a/tests/topotests/ospf_p2mp/test_ospf_p2mp_broadcast.py b/tests/topotests/ospf_p2mp/test_ospf_p2mp_broadcast.py index 1f0f87959a..791d7cb09b 100644 --- a/tests/topotests/ospf_p2mp/test_ospf_p2mp_broadcast.py +++ b/tests/topotests/ospf_p2mp/test_ospf_p2mp_broadcast.py @@ -140,22 +140,6 @@ def verify_p2mp_interface(tgen, router, nbr_cnt, nbr_adj_cnt, nbr_filter): "interfaces": { "r1-eth0": { "ospfEnabled": True, - "interfaceIp": { - "10.1.0.1": { - "ipAddress": "10.1.0.1", - "ipAddressPrefixlen": 24, - "ospfIfType": "Broadcast", - "routerId": "1.1.1.1", - "networkType": "POINTOMULTIPOINT", - "cost": 10, - "state": "Point-To-Point", - "nbrCount": nbr_cnt, - "nbrAdjacentCount": nbr_adj_cnt, - "prefixSuppression": False, - "p2mpDelayReflood": False, - "nbrFilterPrefixList": nbr_filter, - } - }, "ipAddress": "10.1.0.1", "ipAddressPrefixlen": 24, "ospfIfType": "Broadcast", @@ -201,17 +185,6 @@ def verify_non_p2mp_interface(tgen): "interfaces": { "r1-eth0": { "ospfEnabled": True, - "interfaceIp": { - "10.1.0.1": { - "ipAddress": "10.1.0.1", - "ipAddressPrefixlen": 24, - "ospfIfType": "Broadcast", - "routerId": "1.1.1.1", - "networkType": "BROADCAST", - "cost": 10, - "prefixSuppression": False, - } - }, "ipAddress": "10.1.0.1", "ipAddressPrefixlen": 24, "ospfIfType": "Broadcast", diff --git a/tests/topotests/ospf_p2mp/test_ospf_p2mp_non_broadcast.py b/tests/topotests/ospf_p2mp/test_ospf_p2mp_non_broadcast.py index 175dca74e7..f100aa624a 100644 --- a/tests/topotests/ospf_p2mp/test_ospf_p2mp_non_broadcast.py +++ b/tests/topotests/ospf_p2mp/test_ospf_p2mp_non_broadcast.py @@ -144,22 +144,6 @@ def verify_p2mp_interface(tgen, router, nbr_cnt, nbr_adj_cnt, non_broadcast): "interfaces": { "r1-eth0": { "ospfEnabled": True, - "interfaceIp": { - "10.1.0.1": { - "ipAddress": "10.1.0.1", - "ipAddressPrefixlen": 24, - "ospfIfType": "Broadcast", - "routerId": "1.1.1.1", - "networkType": "POINTOMULTIPOINT", - "cost": 10, - "state": "Point-To-Point", - "nbrCount": nbr_cnt, - "nbrAdjacentCount": nbr_adj_cnt, - "prefixSuppression": False, - "p2mpDelayReflood": False, - "p2mpNonBroadcast": non_broadcast, - } - }, "ipAddress": "10.1.0.1", "ipAddressPrefixlen": 24, "ospfIfType": "Broadcast", From e8f5caa21bde40148bc5a8f6cecfe2ca78016fe2 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Wed, 12 Jun 2024 16:28:38 +0300 Subject: [PATCH 3/3] ospfd: Fix memory leak after cleaning cleaning up interfaceIp JSON field ``` ================================================================= ==6717==ERROR: LeakSanitizer: detected memory leaks Direct leak of 1008 byte(s) in 14 object(s) allocated from: 0 0x7f9ea0dc7d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28) 1 0x7f9ea034d51f in json_object_new_object (/lib/x86_64-linux-gnu/libjson-c.so.3+0x351f) 2 0x564b56d0fed6 in show_ip_ospf_interface_common ospfd/ospf_vty.c:4011 3 0x564b56d1068c in show_ip_ospf_interface ospfd/ospf_vty.c:4285 4 0x7f9ea06fe1c0 in cmd_execute_command_real lib/command.c:1002 5 0x7f9ea06fe684 in cmd_execute_command lib/command.c:1060 6 0x7f9ea06feb03 in cmd_execute lib/command.c:1227 7 0x7f9ea08415b2 in vty_command lib/vty.c:616 8 0x7f9ea0841a5d in vty_execute lib/vty.c:1379 9 0x7f9ea084b367 in vtysh_read lib/vty.c:2374 10 0x7f9ea08350cd in event_call lib/event.c:2011 11 0x7f9ea0764386 in frr_run lib/libfrr.c:1217 12 0x564b56c25b18 in main ospfd/ospf_main.c:295 13 0x7f9e9fd5bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) Indirect leak of 7168 byte(s) in 14 object(s) allocated from: 0 0x7f9ea0dc7d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28) 1 0x7f9ea0350fa4 in lh_table_new (/lib/x86_64-linux-gnu/libjson-c.so.3+0x6fa4) Indirect leak of 1232 byte(s) in 14 object(s) allocated from: 0 0x7f9ea0dc7d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28) 1 0x7f9ea0350f82 in lh_table_new (/lib/x86_64-linux-gnu/libjson-c.so.3+0x6f82) SUMMARY: AddressSanitizer: 9408 byte(s) leaked in 42 allocation(s). *********************************************************************************** ``` Fixes: e24ff4c275f0729f75be9f68d08be80ac1e0ec56 ("ospfd: Drop `interfaceIp` from `show ip ospf neigh json") Signed-off-by: Donatas Abraitis --- ospfd/ospf_vty.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 21acd402f4..3a11b21232 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -3576,7 +3576,6 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, struct route_node *rn; uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; struct ospf_if_params *params; - json_object *json_oi = NULL; /* Is interface up? */ if (use_json) { @@ -3633,12 +3632,9 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, if (oi == NULL) continue; - if (use_json) - json_oi = json_object_new_object(); - if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { if (use_json) - json_object_boolean_true_add(json_oi, + json_object_boolean_true_add(json_interface_sub, "ifUnnumbered"); else vty_out(vty, " This interface is UNNUMBERED,"); @@ -3932,8 +3928,6 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, /* OSPF Authentication information */ ospf_interface_auth_show(vty, oi, json_interface_sub, use_json); - ospf_interface_auth_show(vty, oi, json_oi, use_json); - /* Point-to-Multipoint Interface options. */ if (oi->type == OSPF_IFTYPE_POINTOMULTIPOINT) { if (use_json)