From ddb13fd374ee736c20198c1075c855efa7af74e9 Mon Sep 17 00:00:00 2001 From: Don Slice Date: Mon, 12 Sep 2016 06:32:11 -0700 Subject: [PATCH] lib: apply mask to prefix in prefix-list A crash occurred if a prefix was defined in a prefix-list that contained bits in the prefix but a /0 mask. Resolving that crash and improving usability by applying the mask to the supplied prefix and notifying the user if the prefix was modified. Ticket: CM-12744 Signed-off-by: Don Slice Reviewed_By: Testing Done: Manual testing attached to the ticket, bgp-min, bgp-smoke ospf-min, and ospf-smoke all completed before commit --- lib/plist.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/plist.c b/lib/plist.c index a1289801c4..87d46a1054 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -894,7 +894,7 @@ vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name, struct prefix_list *plist; struct prefix_list_entry *pentry; struct prefix_list_entry *dup; - struct prefix p; + struct prefix p, p_tmp; int any = 0; int seqnum = -1; int lenum = 0; @@ -940,6 +940,11 @@ vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name, vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE); return CMD_WARNING; } + + /* make a copy to verify prefix matches mask length */ + prefix_copy (&p_tmp, &p); + apply_mask_ipv4 ((struct prefix_ipv4 *) &p_tmp); + break; case AFI_IP6: if (strncmp ("any", prefix, strlen (prefix)) == 0) @@ -957,9 +962,26 @@ vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name, vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE); return CMD_WARNING; } + + /* make a copy to verify prefix matches mask length */ + prefix_copy (&p_tmp, &p); + apply_mask_ipv6 ((struct prefix_ipv6 *) &p_tmp); + break; } + /* If prefix has bits not under the mask, adjust it to fit */ + if (!prefix_same (&p_tmp, &p)) + { + char buf[PREFIX2STR_BUFFER]; + char buf_tmp[PREFIX2STR_BUFFER]; + prefix2str(&p, buf, sizeof(buf)); + prefix2str(&p_tmp, buf_tmp, sizeof(buf_tmp)); + zlog_warn ("Prefix-list %s prefix changed from %s to %s to match length", + name, buf, buf_tmp); + p = p_tmp; + } + /* ge and le check. */ if (genum && (genum <= p.prefixlen)) return vty_invalid_prefix_range (vty, prefix); @@ -985,14 +1007,6 @@ vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name, if (dup) { prefix_list_entry_free (pentry); - vty_out (vty, "%% Insertion failed - prefix-list entry exists:%s", - VTY_NEWLINE); - vty_out (vty, " seq %u %s %s", dup->seq, typestr, prefix); - if (! any && genum) - vty_out (vty, " ge %d", genum); - if (! any && lenum) - vty_out (vty, " le %d", lenum); - vty_out (vty, "%s", VTY_NEWLINE); return CMD_SUCCESS; } -- 2.39.5