]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_pbr.c
isisd: implement the 'lsp-too-large' notification
[mirror_frr.git] / zebra / zebra_pbr.c
index 059930f4e115dbcd2fb093ea2f2b52db50274060..833306bcc4d0561cb3354437fc9dfb7d60e9ddbe 100644 (file)
@@ -103,30 +103,24 @@ static const struct message fragment_value_str[] = {
 };
 
 /* static function declarations */
-DEFINE_HOOK(zebra_pbr_ipset_entry_wrap_script_get_stat, (struct zebra_ns *zns,
-                                   struct zebra_pbr_ipset_entry *ipset,
-                                   uint64_t *pkts, uint64_t *bytes),
-                                    (zns, ipset, pkts, bytes))
-
-DEFINE_HOOK(zebra_pbr_iptable_wrap_script_get_stat, (struct zebra_ns *zns,
-                                   struct zebra_pbr_iptable *iptable,
-                                   uint64_t *pkts, uint64_t *bytes),
-                                    (zns, iptable, pkts, bytes))
-
-DEFINE_HOOK(zebra_pbr_iptable_wrap_script_update, (struct zebra_ns *zns,
-                                            int cmd,
-                                            struct zebra_pbr_iptable *iptable),
-                                           (zns, cmd, iptable));
-
-DEFINE_HOOK(zebra_pbr_ipset_entry_wrap_script_update, (struct zebra_ns *zns,
-                                 int cmd,
-                                 struct zebra_pbr_ipset_entry *ipset),
-                                 (zns, cmd, ipset));
-
-DEFINE_HOOK(zebra_pbr_ipset_wrap_script_update, (struct zebra_ns *zns,
-                                 int cmd,
-                                 struct zebra_pbr_ipset *ipset),
-                                 (zns, cmd, ipset));
+DEFINE_HOOK(zebra_pbr_ipset_entry_get_stat,
+           (struct zebra_pbr_ipset_entry *ipset, uint64_t *pkts,
+            uint64_t *bytes),
+           (ipset, pkts, bytes))
+
+DEFINE_HOOK(zebra_pbr_iptable_get_stat,
+           (struct zebra_pbr_iptable *iptable, uint64_t *pkts,
+            uint64_t *bytes),
+           (iptable, pkts, bytes))
+
+DEFINE_HOOK(zebra_pbr_iptable_update,
+           (int cmd, struct zebra_pbr_iptable *iptable), (cmd, iptable));
+
+DEFINE_HOOK(zebra_pbr_ipset_entry_update,
+           (int cmd, struct zebra_pbr_ipset_entry *ipset), (cmd, ipset));
+
+DEFINE_HOOK(zebra_pbr_ipset_update,
+           (int cmd, struct zebra_pbr_ipset *ipset), (cmd, ipset));
 
 /* Private functions */
 
@@ -233,7 +227,8 @@ static int pbr_rule_lookup_unique_walker(struct hash_backet *b, void *data)
        return HASHWALK_CONTINUE;
 }
 
-static struct zebra_pbr_rule *pbr_rule_lookup_unique(struct zebra_pbr_rule *zrule)
+static struct zebra_pbr_rule *
+pbr_rule_lookup_unique(struct zebra_pbr_rule *zrule)
 {
        struct pbr_rule_unique_lookup pul;
 
@@ -249,15 +244,9 @@ static struct zebra_pbr_rule *pbr_rule_lookup_unique(struct zebra_pbr_rule *zrul
 void zebra_pbr_ipset_free(void *arg)
 {
        struct zebra_pbr_ipset *ipset;
-       struct zebra_ns *zns;
 
        ipset = (struct zebra_pbr_ipset *)arg;
-       if (vrf_is_backend_netns())
-               zns = zebra_ns_lookup(ipset->vrf_id);
-       else
-               zns = zebra_ns_lookup(NS_DEFAULT);
-       hook_call(zebra_pbr_ipset_wrap_script_update,
-                 zns, 0, ipset);
+       hook_call(zebra_pbr_ipset_update, 0, ipset);
        XFREE(MTYPE_TMP, ipset);
 }
 
@@ -265,8 +254,9 @@ uint32_t zebra_pbr_ipset_hash_key(void *arg)
 {
        struct zebra_pbr_ipset *ipset = (struct zebra_pbr_ipset *)arg;
        uint32_t *pnt = (uint32_t *)&ipset->ipset_name;
+       uint32_t key = jhash_1word(ipset->vrf_id, 0x63ab42de);
 
-       return jhash2(pnt, ZEBRA_IPSET_NAME_HASH_SIZE, 0x63ab42de);
+       return jhash2(pnt, ZEBRA_IPSET_NAME_HASH_SIZE, key);
 }
 
 bool zebra_pbr_ipset_hash_equal(const void *arg1, const void *arg2)
@@ -280,6 +270,9 @@ bool zebra_pbr_ipset_hash_equal(const void *arg1, const void *arg2)
                return false;
        if (r1->unique != r2->unique)
                return false;
+       if (r1->vrf_id != r2->vrf_id)
+               return false;
+
        if (strncmp(r1->ipset_name, r2->ipset_name,
                    ZEBRA_IPSET_NAME_SIZE))
                return false;
@@ -289,17 +282,10 @@ bool zebra_pbr_ipset_hash_equal(const void *arg1, const void *arg2)
 void zebra_pbr_ipset_entry_free(void *arg)
 {
        struct zebra_pbr_ipset_entry *ipset;
-       struct zebra_ns *zns;
 
        ipset = (struct zebra_pbr_ipset_entry *)arg;
-       if (ipset->backpointer && vrf_is_backend_netns()) {
-               struct zebra_pbr_ipset *ips = ipset->backpointer;
 
-               zns = zebra_ns_lookup((ns_id_t)ips->vrf_id);
-       } else
-               zns = zebra_ns_lookup(NS_DEFAULT);
-       hook_call(zebra_pbr_ipset_entry_wrap_script_update,
-                 zns, 0, ipset);
+       hook_call(zebra_pbr_ipset_entry_update, 0, ipset);
 
        XFREE(MTYPE_TMP, ipset);
 }
@@ -360,15 +346,9 @@ void zebra_pbr_iptable_free(void *arg)
        struct zebra_pbr_iptable *iptable;
        struct listnode *node, *nnode;
        char *name;
-       struct zebra_ns *zns;
 
        iptable = (struct zebra_pbr_iptable *)arg;
-       if (vrf_is_backend_netns())
-               zns = zebra_ns_lookup((ns_id_t)iptable->vrf_id);
-       else
-               zns =  zebra_ns_lookup(NS_DEFAULT);
-       hook_call(zebra_pbr_iptable_wrap_script_update,
-                 zns, 0, iptable);
+       hook_call(zebra_pbr_iptable_update, 0, iptable);
 
        for (ALL_LIST_ELEMENTS(iptable->interface_name_list,
                                        node, nnode, name)) {
@@ -394,6 +374,8 @@ uint32_t zebra_pbr_iptable_hash_key(void *arg)
        key = jhash_1word(iptable->tcp_mask_flags, key);
        key = jhash_1word(iptable->dscp_value, key);
        key = jhash_1word(iptable->fragment, key);
+       key = jhash_1word(iptable->vrf_id, key);
+
        return jhash_3words(iptable->filter_bm, iptable->type,
                            iptable->unique, key);
 }
@@ -405,6 +387,8 @@ bool zebra_pbr_iptable_hash_equal(const void *arg1, const void *arg2)
        r1 = (const struct zebra_pbr_iptable *)arg1;
        r2 = (const struct zebra_pbr_iptable *)arg2;
 
+       if (r1->vrf_id != r2->vrf_id)
+               return 0;
        if (r1->type != r2->type)
                return false;
        if (r1->unique != r2->unique)
@@ -491,57 +475,48 @@ static void zebra_pbr_cleanup_rules(struct hash_backet *b, void *data)
 
 static void zebra_pbr_cleanup_ipset(struct hash_backet *b, void *data)
 {
-       struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT);
        struct zebra_pbr_ipset *ipset = b->data;
        int *sock = data;
 
        if (ipset->sock == *sock) {
-               hook_call(zebra_pbr_ipset_wrap_script_update,
-                         zns, 0, ipset);
-               hash_release(zns->ipset_hash, ipset);
+               hook_call(zebra_pbr_ipset_update, 0, ipset);
+               hash_release(zrouter.ipset_hash, ipset);
        }
 }
 
 static void zebra_pbr_cleanup_ipset_entry(struct hash_backet *b, void *data)
 {
-       struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT);
        struct zebra_pbr_ipset_entry *ipset = b->data;
        int *sock = data;
 
        if (ipset->sock == *sock) {
-               hook_call(zebra_pbr_ipset_entry_wrap_script_update,
-                         zns, 0, ipset);
-               hash_release(zns->ipset_entry_hash, ipset);
+               hook_call(zebra_pbr_ipset_entry_update, 0, ipset);
+               hash_release(zrouter.ipset_entry_hash, ipset);
        }
 }
 
 static void zebra_pbr_cleanup_iptable(struct hash_backet *b, void *data)
 {
-       struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT);
        struct zebra_pbr_iptable *iptable = b->data;
        int *sock = data;
 
        if (iptable->sock == *sock) {
-               hook_call(zebra_pbr_iptable_wrap_script_update,
-                         zns, 0, iptable);
-               hash_release(zns->iptable_hash, iptable);
+               hook_call(zebra_pbr_iptable_update, 0, iptable);
+               hash_release(zrouter.iptable_hash, iptable);
        }
 }
 
 static int zebra_pbr_client_close_cleanup(struct zserv *client)
 {
        int sock = client->sock;
-       struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT);
 
        if (!sock)
                return 0;
        hash_iterate(zrouter.rules_hash, zebra_pbr_cleanup_rules, &sock);
-       hash_iterate(zns->iptable_hash,
-                    zebra_pbr_cleanup_iptable, &sock);
-       hash_iterate(zns->ipset_entry_hash,
-                    zebra_pbr_cleanup_ipset_entry, &sock);
-       hash_iterate(zns->ipset_hash,
-                    zebra_pbr_cleanup_ipset, &sock);
+       hash_iterate(zrouter.iptable_hash, zebra_pbr_cleanup_iptable, &sock);
+       hash_iterate(zrouter.ipset_entry_hash, zebra_pbr_cleanup_ipset_entry,
+                    &sock);
+       hash_iterate(zrouter.ipset_hash, zebra_pbr_cleanup_ipset, &sock);
        return 1;
 }
 
@@ -564,29 +539,25 @@ static void *pbr_ipset_alloc_intern(void *arg)
        return new;
 }
 
-void zebra_pbr_create_ipset(struct zebra_ns *zns,
-                           struct zebra_pbr_ipset *ipset)
+void zebra_pbr_create_ipset(struct zebra_pbr_ipset *ipset)
 {
        int ret;
 
-       (void)hash_get(zns->ipset_hash, ipset, pbr_ipset_alloc_intern);
-       ret = hook_call(zebra_pbr_ipset_wrap_script_update,
-                 zns, 1, ipset);
+       (void)hash_get(zrouter.ipset_hash, ipset, pbr_ipset_alloc_intern);
+       ret = hook_call(zebra_pbr_ipset_update, 1, ipset);
        kernel_pbr_ipset_add_del_status(ipset,
                                        ret ? ZEBRA_DPLANE_INSTALL_SUCCESS
                                        : ZEBRA_DPLANE_INSTALL_FAILURE);
 }
 
-void zebra_pbr_destroy_ipset(struct zebra_ns *zns,
-                            struct zebra_pbr_ipset *ipset)
+void zebra_pbr_destroy_ipset(struct zebra_pbr_ipset *ipset)
 {
        struct zebra_pbr_ipset *lookup;
 
-       lookup = hash_lookup(zns->ipset_hash, ipset);
-       hook_call(zebra_pbr_ipset_wrap_script_update,
-                 zns, 0, ipset);
+       lookup = hash_lookup(zrouter.ipset_hash, ipset);
+       hook_call(zebra_pbr_ipset_update, 0, ipset);
        if (lookup) {
-               hash_release(zns->ipset_hash, lookup);
+               hash_release(zrouter.ipset_hash, lookup);
                XFREE(MTYPE_TMP, lookup);
        } else
                zlog_debug(
@@ -619,8 +590,7 @@ static int zebra_pbr_ipset_pername_walkcb(struct hash_backet *backet, void *arg)
        return HASHWALK_CONTINUE;
 }
 
-struct zebra_pbr_ipset *zebra_pbr_lookup_ipset_pername(struct zebra_ns *zns,
-                                                      char *ipsetname)
+struct zebra_pbr_ipset *zebra_pbr_lookup_ipset_pername(char *ipsetname)
 {
        struct pbr_ipset_name_lookup pinl;
        struct pbr_ipset_name_lookup *ptr = &pinl;
@@ -630,7 +600,7 @@ struct zebra_pbr_ipset *zebra_pbr_lookup_ipset_pername(struct zebra_ns *zns,
        memset(ptr, 0, sizeof(struct pbr_ipset_name_lookup));
        snprintf((char *)ptr->ipset_name, ZEBRA_IPSET_NAME_SIZE, "%s",
                ipsetname);
-       hash_walk(zns->ipset_hash, zebra_pbr_ipset_pername_walkcb, ptr);
+       hash_walk(zrouter.ipset_hash, zebra_pbr_ipset_pername_walkcb, ptr);
        return ptr->ipset;
 }
 
@@ -648,30 +618,26 @@ static void *pbr_ipset_entry_alloc_intern(void *arg)
        return new;
 }
 
-void zebra_pbr_add_ipset_entry(struct zebra_ns *zns,
-                              struct zebra_pbr_ipset_entry *ipset)
+void zebra_pbr_add_ipset_entry(struct zebra_pbr_ipset_entry *ipset)
 {
        int ret;
 
-       (void)hash_get(zns->ipset_entry_hash, ipset,
+       (void)hash_get(zrouter.ipset_entry_hash, ipset,
                       pbr_ipset_entry_alloc_intern);
-       ret = hook_call(zebra_pbr_ipset_entry_wrap_script_update,
-                 zns, 1, ipset);
+       ret = hook_call(zebra_pbr_ipset_entry_update, 1, ipset);
        kernel_pbr_ipset_entry_add_del_status(ipset,
                                        ret ? ZEBRA_DPLANE_INSTALL_SUCCESS
                                        : ZEBRA_DPLANE_INSTALL_FAILURE);
 }
 
-void zebra_pbr_del_ipset_entry(struct zebra_ns *zns,
-                              struct zebra_pbr_ipset_entry *ipset)
+void zebra_pbr_del_ipset_entry(struct zebra_pbr_ipset_entry *ipset)
 {
        struct zebra_pbr_ipset_entry *lookup;
 
-       lookup = hash_lookup(zns->ipset_entry_hash, ipset);
-       hook_call(zebra_pbr_ipset_entry_wrap_script_update,
-                 zns, 0, ipset);
+       lookup = hash_lookup(zrouter.ipset_entry_hash, ipset);
+       hook_call(zebra_pbr_ipset_entry_update, 0, ipset);
        if (lookup) {
-               hash_release(zns->ipset_entry_hash, lookup);
+               hash_release(zrouter.ipset_entry_hash, lookup);
                XFREE(MTYPE_TMP, lookup);
        } else
                zlog_debug("%s: IPSet being deleted we know nothing about",
@@ -692,31 +658,28 @@ static void *pbr_iptable_alloc_intern(void *arg)
        return new;
 }
 
-void zebra_pbr_add_iptable(struct zebra_ns *zns,
-                          struct zebra_pbr_iptable *iptable)
+void zebra_pbr_add_iptable(struct zebra_pbr_iptable *iptable)
 {
        int ret;
 
-       (void)hash_get(zns->iptable_hash, iptable,
-                      pbr_iptable_alloc_intern);
-       ret = hook_call(zebra_pbr_iptable_wrap_script_update, zns, 1, iptable);
+       (void)hash_get(zrouter.iptable_hash, iptable, pbr_iptable_alloc_intern);
+       ret = hook_call(zebra_pbr_iptable_update, 1, iptable);
        kernel_pbr_iptable_add_del_status(iptable,
                                          ret ? ZEBRA_DPLANE_INSTALL_SUCCESS
                                          : ZEBRA_DPLANE_INSTALL_FAILURE);
 }
 
-void zebra_pbr_del_iptable(struct zebra_ns *zns,
-                          struct zebra_pbr_iptable *iptable)
+void zebra_pbr_del_iptable(struct zebra_pbr_iptable *iptable)
 {
        struct zebra_pbr_iptable *lookup;
 
-       lookup = hash_lookup(zns->iptable_hash, iptable);
-       hook_call(zebra_pbr_iptable_wrap_script_update, zns, 0, iptable);
+       lookup = hash_lookup(zrouter.iptable_hash, iptable);
+       hook_call(zebra_pbr_iptable_update, 0, iptable);
        if (lookup) {
                struct listnode *node, *nnode;
                char *name;
 
-               hash_release(zns->iptable_hash, lookup);
+               hash_release(zrouter.iptable_hash, lookup);
                for (ALL_LIST_ELEMENTS(iptable->interface_name_list,
                                       node, nnode, name)) {
                        XFREE(MTYPE_PBR_IPTABLE_IFNAME, name);
@@ -921,7 +884,6 @@ static int zebra_pbr_show_ipset_entry_walkcb(struct hash_backet *backet,
        struct zebra_pbr_ipset_entry *zpie =
                (struct zebra_pbr_ipset_entry *)backet->data;
        uint64_t pkts = 0, bytes = 0;
-       struct zebra_ns *zns = unique->zns;
        int ret = 0;
 
        if (zpie->backpointer != zpi)
@@ -979,8 +941,8 @@ static int zebra_pbr_show_ipset_entry_walkcb(struct hash_backet *backet,
        }
        vty_out(vty, " (%u)\n", zpie->unique);
 
-       ret = hook_call(zebra_pbr_ipset_entry_wrap_script_get_stat,
-                       zns, zpie, &pkts, &bytes);
+       ret = hook_call(zebra_pbr_ipset_entry_get_stat, zpie, &pkts,
+                       &bytes);
        if (ret && pkts > 0)
                vty_out(vty, "\t pkts %" PRIu64 ", bytes %" PRIu64"\n",
                        pkts, bytes);
@@ -1001,7 +963,7 @@ static int zebra_pbr_show_ipset_walkcb(struct hash_backet *backet, void *arg)
        unique.vty = vty;
        unique.zpi = zpi;
        unique.zns = zns;
-       hash_walk(zns->ipset_entry_hash, zebra_pbr_show_ipset_entry_walkcb,
+       hash_walk(zrouter.ipset_entry_hash, zebra_pbr_show_ipset_entry_walkcb,
                  &unique);
        vty_out(vty, "\n");
        return HASHWALK_CONTINUE;
@@ -1037,7 +999,7 @@ void zebra_pbr_show_ipset_list(struct vty *vty, char *ipsetname)
        struct zebra_pbr_env_display uniqueipset;
 
        if (ipsetname) {
-               zpi = zebra_pbr_lookup_ipset_pername(zns, ipsetname);
+               zpi = zebra_pbr_lookup_ipset_pername(ipsetname);
                if (!zpi) {
                        vty_out(vty, "No IPset %s found\n", ipsetname);
                        return;
@@ -1048,15 +1010,14 @@ void zebra_pbr_show_ipset_list(struct vty *vty, char *ipsetname)
                unique.vty = vty;
                unique.zpi = zpi;
                unique.zns = zns;
-               hash_walk(zns->ipset_entry_hash,
-                         zebra_pbr_show_ipset_entry_walkcb,
-                         &unique);
+               hash_walk(zrouter.ipset_entry_hash,
+                         zebra_pbr_show_ipset_entry_walkcb, &unique);
                return;
        }
        uniqueipset.zns = zns;
        uniqueipset.vty = vty;
        uniqueipset.name = NULL;
-       hash_walk(zns->ipset_hash, zebra_pbr_show_ipset_walkcb,
+       hash_walk(zrouter.ipset_hash, zebra_pbr_show_ipset_walkcb,
                  &uniqueipset);
 }
 
@@ -1134,8 +1095,8 @@ static void zebra_pbr_show_iptable_unit(struct zebra_pbr_iptable *iptable,
                        " not" : "", lookup_msg(fragment_value_str,
                                               iptable->fragment, val_str));
        }
-       ret = hook_call(zebra_pbr_iptable_wrap_script_get_stat,
-                       zns, iptable, &pkts, &bytes);
+       ret = hook_call(zebra_pbr_iptable_get_stat, iptable, &pkts,
+                       &bytes);
        if (ret && pkts > 0)
                vty_out(vty, "\t pkts %" PRIu64 ", bytes %" PRIu64"\n",
                        pkts, bytes);
@@ -1182,8 +1143,7 @@ void zebra_pbr_show_iptable(struct vty *vty, char *iptable_name)
        env.vty = vty;
        env.zns = zns;
        env.name = iptable_name;
-       hash_walk(zns->iptable_hash, zebra_pbr_show_iptable_walkcb,
-                 &env);
+       hash_walk(zrouter.iptable_hash, zebra_pbr_show_iptable_walkcb, &env);
 }
 
 void zebra_pbr_iptable_update_interfacelist(struct stream *s,