Skip to content

Commit

Permalink
Merge pull request FRRouting#16178 from y-bharath14/srib-babel-code-r…
Browse files Browse the repository at this point in the history
…efactoring

babel: Added null check after retrieving babel_ifp
  • Loading branch information
mjstapp authored Jul 30, 2024
2 parents 43b9faf + ae885a7 commit 292dc38
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions babeld/babel_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ babel_interface_address_add (ZAPI_CALLBACK_ARGS)
if (prefix->family == AF_INET) {
flush_interface_routes(ifc->ifp, 0);
babel_ifp = babel_get_if_nfo(ifc->ifp);
assert (babel_ifp != NULL);
if (babel_ifp->ipv4 == NULL) {
babel_ifp->ipv4 = malloc(4);
if (babel_ifp->ipv4 == NULL) {
Expand Down Expand Up @@ -144,6 +145,7 @@ babel_interface_address_delete (ZAPI_CALLBACK_ARGS)
if (prefix->family == AF_INET) {
flush_interface_routes(ifc->ifp, 0);
babel_ifp = babel_get_if_nfo(ifc->ifp);
assert (babel_ifp != NULL);
if (babel_ifp->ipv4 != NULL
&& memcmp(babel_ifp->ipv4, &prefix->u.prefix4, IPV4_MAX_BYTELEN)
== 0) {
Expand Down Expand Up @@ -542,7 +544,10 @@ DEFPY (babel_set_channel,
unsigned
jitter(babel_interface_nfo *babel_ifp, int urgent)
{
unsigned interval = babel_ifp->hello_interval;
unsigned interval;

assert (babel_ifp != NULL);
interval = babel_ifp->hello_interval;
if(urgent)
interval = MIN(interval, 100);
else
Expand All @@ -553,7 +558,10 @@ jitter(babel_interface_nfo *babel_ifp, int urgent)
unsigned
update_jitter(babel_interface_nfo *babel_ifp, int urgent)
{
unsigned interval = babel_ifp->hello_interval;
unsigned interval;

assert (babel_ifp != NULL);
interval = babel_ifp->hello_interval;
if(urgent)
interval = MIN(interval, 100);
else
Expand All @@ -566,10 +574,11 @@ update_jitter(babel_interface_nfo *babel_ifp, int urgent)
static int
interface_recalculate(struct interface *ifp)
{
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
unsigned char *tmp = NULL;
int mtu, rc;
struct ipv6_mreq mreq;
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
assert (babel_ifp != NULL);

if (!IS_ENABLE(ifp))
return -1;
Expand Down Expand Up @@ -656,6 +665,7 @@ interface_reset(struct interface *ifp)
int rc;
struct ipv6_mreq mreq;
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
assert (babel_ifp != NULL);

if (!CHECK_FLAG(babel_ifp->flags, BABEL_IF_IS_UP))
return 0;
Expand Down Expand Up @@ -777,6 +787,7 @@ show_babel_interface_sub (struct vty *vty, struct interface *ifp)
return;
}
babel_ifp = babel_get_if_nfo (ifp);
assert (babel_ifp != NULL);
vty_out (vty, " Babel protocol is running on this interface\n");
vty_out (vty, " Operating mode is \"%s\"\n",
CHECK_FLAG(babel_ifp->flags, BABEL_IF_WIRED) ? "wired" : "wireless");
Expand Down Expand Up @@ -1228,6 +1239,7 @@ interface_config_write (struct vty *vty)
if (ifp->desc)
vty_out (vty, " description %s\n",ifp->desc);
babel_interface_nfo *babel_ifp = babel_get_if_nfo (ifp);
assert (babel_ifp != NULL);
/* wireless is the default*/
if (CHECK_FLAG (babel_ifp->flags, BABEL_IF_WIRED))
{
Expand Down Expand Up @@ -1330,6 +1342,7 @@ babel_interface_allocate (void)
{
babel_interface_nfo *babel_ifp;
babel_ifp = XCALLOC(MTYPE_BABEL_IF, sizeof(babel_interface_nfo));
assert (babel_ifp != NULL);
/* All flags are unset */
babel_ifp->bucket_time = babel_now.tv_sec;
babel_ifp->bucket = BUCKET_TOKENS_MAX;
Expand All @@ -1349,6 +1362,8 @@ babel_interface_allocate (void)
static void
babel_interface_free (babel_interface_nfo *babel_ifp)
{
assert (babel_ifp != NULL);

if (babel_ifp->ipv4){
free(babel_ifp->ipv4);
babel_ifp->ipv4 = NULL;
Expand Down

0 comments on commit 292dc38

Please sign in to comment.