Skip to content

Commit 2a35cb2

Browse files
authored
Merge pull request #18895 from FRRouting/mergify/bp/stable/10.2/pr-18785
ospfd: Fix crash when ospf client connects before configuring an OSPF instance (backport #18785)
2 parents 4bc34cc + 4cf1501 commit 2a35cb2

File tree

1 file changed

+54
-15
lines changed

1 file changed

+54
-15
lines changed

ospfd/ospf_apiserver.c

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,8 @@ void ospf_apiserver_notify_ready_type9(struct ospf_apiserver *apiserv)
10051005
struct registered_opaque_type *r;
10061006

10071007
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1008+
if (!ospf)
1009+
goto out;
10081010

10091011
for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi)) {
10101012
/* Check if this interface is indeed ready for type 9 */
@@ -1053,6 +1055,8 @@ void ospf_apiserver_notify_ready_type10(struct ospf_apiserver *apiserv)
10531055
struct ospf_area *area;
10541056

10551057
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1058+
if (!ospf)
1059+
goto out;
10561060

10571061
for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) {
10581062
struct registered_opaque_type *r;
@@ -1100,6 +1104,8 @@ void ospf_apiserver_notify_ready_type11(struct ospf_apiserver *apiserv)
11001104
struct registered_opaque_type *r;
11011105

11021106
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1107+
if (!ospf)
1108+
goto out;
11031109

11041110
/* Can type 11 be originated? */
11051111
if (!ospf_apiserver_is_ready_type11(ospf))
@@ -1276,10 +1282,13 @@ int ospf_apiserver_handle_sync_lsdb(struct ospf_apiserver *apiserv,
12761282
struct ospf *ospf;
12771283
struct ospf_area *area;
12781284

1279-
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1280-
12811285
/* Get request sequence number */
12821286
seqnum = msg_get_seq(msg);
1287+
1288+
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1289+
if (!ospf)
1290+
goto out;
1291+
12831292
/* Set sync msg. */
12841293
smsg = (struct msg_sync_lsdb *)STREAM_DATA(msg->s);
12851294

@@ -1357,6 +1366,7 @@ int ospf_apiserver_handle_sync_lsdb(struct ospf_apiserver *apiserv,
13571366
seqnum);
13581367
}
13591368

1369+
out:
13601370
/* Send a reply back to client with return code */
13611371
rc = ospf_apiserver_send_reply(apiserv, seqnum, rc);
13621372
return rc;
@@ -1371,14 +1381,19 @@ int ospf_apiserver_handle_sync_lsdb(struct ospf_apiserver *apiserv,
13711381
int ospf_apiserver_handle_sync_reachable(struct ospf_apiserver *apiserv,
13721382
struct msg *msg)
13731383
{
1384+
int _rc, rc = 0;
1385+
uint32_t seqnum = msg_get_seq(msg);
13741386
struct ospf *ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1387+
1388+
if (!ospf)
1389+
goto out;
1390+
13751391
struct route_table *rt = ospf->all_rtrs;
1376-
uint32_t seqnum = msg_get_seq(msg);
13771392
struct in_addr *a, *abuf;
13781393
struct msg_reachable_change *areach;
13791394
struct msg *amsg;
13801395
uint mcount, count;
1381-
int _rc, rc = 0;
1396+
13821397

13831398
if (!rt)
13841399
goto out;
@@ -1416,13 +1431,17 @@ int ospf_apiserver_handle_sync_reachable(struct ospf_apiserver *apiserv,
14161431
int ospf_apiserver_handle_sync_ism(struct ospf_apiserver *apiserv,
14171432
struct msg *msg)
14181433
{
1434+
uint32_t seqnum = msg_get_seq(msg);
1435+
int _rc, rc = 0;
14191436
struct ospf *ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1437+
1438+
if (!ospf)
1439+
goto out;
1440+
14201441
struct listnode *anode, *inode;
14211442
struct ospf_area *area;
14221443
struct ospf_interface *oi;
14231444
struct msg *m;
1424-
uint32_t seqnum = msg_get_seq(msg);
1425-
int _rc, rc = 0;
14261445

14271446
/* walk all areas */
14281447
for (ALL_LIST_ELEMENTS_RO(ospf->areas, anode, area)) {
@@ -1438,6 +1457,7 @@ int ospf_apiserver_handle_sync_ism(struct ospf_apiserver *apiserv,
14381457
if (rc)
14391458
break;
14401459
}
1460+
out:
14411461
/* Send a reply back to client with return code */
14421462
_rc = ospf_apiserver_send_reply(apiserv, seqnum, rc);
14431463
return rc ? rc : _rc;
@@ -1447,15 +1467,19 @@ int ospf_apiserver_handle_sync_ism(struct ospf_apiserver *apiserv,
14471467
int ospf_apiserver_handle_sync_nsm(struct ospf_apiserver *apiserv,
14481468
struct msg *msg)
14491469
{
1470+
uint32_t seqnum = msg_get_seq(msg);
1471+
int _rc, rc = 0;
14501472
struct ospf *ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1473+
1474+
if (!ospf)
1475+
goto out;
1476+
14511477
struct listnode *anode, *inode;
14521478
struct ospf_area *area;
14531479
struct ospf_interface *oi;
14541480
struct ospf_neighbor *nbr;
14551481
struct route_node *rn;
14561482
struct msg *m;
1457-
uint32_t seqnum = msg_get_seq(msg);
1458-
int _rc, rc = 0;
14591483

14601484
/* walk all areas */
14611485
for (ALL_LIST_ELEMENTS_RO(ospf->areas, anode, area)) {
@@ -1481,6 +1505,7 @@ int ospf_apiserver_handle_sync_nsm(struct ospf_apiserver *apiserv,
14811505
if (rc)
14821506
break;
14831507
}
1508+
out:
14841509
/* Send a reply back to client with return code */
14851510
_rc = ospf_apiserver_send_reply(apiserv, seqnum, rc);
14861511
return rc ? rc : _rc;
@@ -1490,15 +1515,20 @@ int ospf_apiserver_handle_sync_nsm(struct ospf_apiserver *apiserv,
14901515
int ospf_apiserver_handle_sync_router_id(struct ospf_apiserver *apiserv,
14911516
struct msg *msg)
14921517
{
1493-
struct ospf *ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
14941518
uint32_t seqnum = msg_get_seq(msg);
14951519
struct msg *m;
14961520
int _rc, rc = 0;
1521+
struct ospf *ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1522+
1523+
if (!ospf)
1524+
goto out;
1525+
14971526

14981527
m = new_msg_router_id_change(seqnum, ospf->router_id);
14991528
rc = ospf_apiserver_send_msg(apiserv, m);
15001529
msg_free(m);
15011530

1531+
out:
15021532
/* Send a reply back to client with return code */
15031533
_rc = ospf_apiserver_send_reply(apiserv, seqnum, rc);
15041534
return rc ? rc : _rc;
@@ -1533,7 +1563,8 @@ struct ospf_lsa *ospf_apiserver_opaque_lsa_new(struct ospf_area *area,
15331563
else
15341564
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
15351565

1536-
assert(ospf);
1566+
if (!ospf)
1567+
return NULL;
15371568

15381569
/* Create a stream for internal opaque LSA */
15391570
if ((s = stream_new(OSPF_MAX_LSA_SIZE)) == NULL) {
@@ -1621,6 +1652,9 @@ int ospf_apiserver_handle_originate_request(struct ospf_apiserver *apiserv,
16211652

16221653
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
16231654

1655+
if (!ospf)
1656+
goto out;
1657+
16241658
/* Extract opaque LSA data from message */
16251659
omsg = (struct msg_originate_request *)STREAM_DATA(msg->s);
16261660
data = &omsg->data;
@@ -1761,7 +1795,8 @@ void ospf_apiserver_flood_opaque_lsa(struct ospf_lsa *lsa)
17611795
struct ospf *ospf;
17621796

17631797
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1764-
assert(ospf);
1798+
if (!ospf)
1799+
return;
17651800

17661801
/* Increment counters? XXX */
17671802

@@ -1777,7 +1812,8 @@ int ospf_apiserver_originate1(struct ospf_lsa *lsa, struct ospf_lsa *old)
17771812
struct ospf *ospf;
17781813

17791814
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1780-
assert(ospf);
1815+
if (!ospf)
1816+
return -1;
17811817

17821818
if (old) {
17831819
/*
@@ -1876,7 +1912,8 @@ struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa)
18761912
assert(lsa);
18771913

18781914
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1879-
assert(ospf);
1915+
if (!ospf)
1916+
return NULL;
18801917

18811918
if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
18821919
zlog_debug("LSA[Type%d:%pI4]: OSPF API Server LSA Refresher",
@@ -1965,7 +2002,8 @@ int ospf_apiserver_handle_delete_request(struct ospf_apiserver *apiserv,
19652002
struct ospf *ospf;
19662003

19672004
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1968-
assert(ospf);
2005+
if (!ospf)
2006+
goto out;
19692007

19702008
/* Extract opaque LSA from message */
19712009
dmsg = (struct msg_delete_request *)STREAM_DATA(msg->s);
@@ -2089,7 +2127,8 @@ void ospf_apiserver_flush_opaque_lsa(struct ospf_apiserver *apiserv,
20892127
struct ospf_area *area;
20902128

20912129
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
2092-
assert(ospf);
2130+
if (!ospf)
2131+
return;
20932132

20942133
/* Set parameter struct. */
20952134
param.apiserv = apiserv;

0 commit comments

Comments
 (0)