]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: implement additional CLI prefix list check
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Mon, 4 May 2020 20:32:06 +0000 (17:32 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Fri, 5 Jun 2020 17:36:54 +0000 (14:36 -0300)
Changes:
- Move the `TODO` to the appropriated place and hint how to resolve
  it.
- Apply mask to prefix when storing it in the data structures. We
  can't just add a validation for it otherwise it will break old
  CLIs.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
lib/filter_nb.c

index 9df37d7cccc21ec720fa7127dfbbdcba6807e83a..f2f334d9f4ac7c6515ad3f18967700451b4e33f8 100644 (file)
@@ -761,8 +761,6 @@ static int lib_prefix_list_create(struct nb_cb_create_args *args)
        const char *name;
        int type;
 
-       /* TODO: validate prefix_entry_dup_check() passes. */
-
        if (args->event != NB_EV_APPLY)
                return NB_OK;
 
@@ -907,6 +905,20 @@ static int
 lib_prefix_list_entry_ipv4_prefix_modify(struct nb_cb_modify_args *args)
 {
        struct prefix_list_entry *ple;
+       struct prefix p;
+
+       if (args->event == NB_EV_VALIDATE) {
+               /*
+                * TODO: validate prefix_entry_dup_check() passes.
+                *
+                * This needs to be implemented using YANG lyd_node
+                * navigation, because the `priv` data structures are not
+                * available at `NB_EV_VALIDATE` phase. An easier
+                * alternative would be mark `ipvx-prefix` as unique
+                * (see RFC 7950, Section 7.8.3. The list "unique" Statement).
+                */
+               return NB_OK;
+       }
 
        if (args->event != NB_EV_APPLY)
                return NB_OK;
@@ -918,6 +930,16 @@ lib_prefix_list_entry_ipv4_prefix_modify(struct nb_cb_modify_args *args)
 
        yang_dnode_get_prefix(&ple->prefix, args->dnode, NULL);
 
+       /* Apply mask and correct original address if necessary. */
+       prefix_copy(&p, &ple->prefix);
+       apply_mask(&p);
+       if (!prefix_same(&ple->prefix, &p)) {
+               zlog_info("%s: bad network %pFX correcting it to %pFX",
+                         __func__, &ple->prefix, &p);
+               prefix_copy(&ple->prefix, &p);
+       }
+
+
        /* Finish prefix entry update procedure. */
        prefix_list_entry_update_finish(ple);