ila: Flush netlink command to clear xlat table
authorTom Herbert <tom@herbertland.com>
Wed, 27 Jun 2018 21:39:02 +0000 (14:39 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 29 Jun 2018 02:32:55 +0000 (11:32 +0900)
Add ILA_CMD_FLUSH netlink command to clear the ILA translation table.

Signed-off-by: Tom Herbert <tom@quantonium.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/uapi/linux/ila.h
net/ipv6/ila/ila.h
net/ipv6/ila/ila_main.c
net/ipv6/ila/ila_xlat.c

index 483b77af4eb8bffe4a465337b85686374e192dc0..db45d3e49a12c73669c0063fe44e0e620fcc5218 100644 (file)
@@ -30,6 +30,7 @@ enum {
        ILA_CMD_ADD,
        ILA_CMD_DEL,
        ILA_CMD_GET,
+       ILA_CMD_FLUSH,
 
        __ILA_CMD_MAX,
 };
index faba7824ea56440817b8f02ca9c8725532fa12e0..1f747bcbec295303c8e08307a87c6c55221194d1 100644 (file)
@@ -123,6 +123,7 @@ void ila_xlat_exit_net(struct net *net);
 int ila_xlat_nl_cmd_add_mapping(struct sk_buff *skb, struct genl_info *info);
 int ila_xlat_nl_cmd_del_mapping(struct sk_buff *skb, struct genl_info *info);
 int ila_xlat_nl_cmd_get_mapping(struct sk_buff *skb, struct genl_info *info);
+int ila_xlat_nl_cmd_flush(struct sk_buff *skb, struct genl_info *info);
 int ila_xlat_nl_dump_start(struct netlink_callback *cb);
 int ila_xlat_nl_dump_done(struct netlink_callback *cb);
 int ila_xlat_nl_dump(struct sk_buff *skb, struct netlink_callback *cb);
index f6ac6b14577e73a66e56b8d50ed18c4c8be95b50..18fac76b952052367309ee2ff4b226d7d10415d7 100644 (file)
@@ -26,6 +26,12 @@ static const struct genl_ops ila_nl_ops[] = {
                .policy = ila_nl_policy,
                .flags = GENL_ADMIN_PERM,
        },
+       {
+               .cmd = ILA_CMD_FLUSH,
+               .doit = ila_xlat_nl_cmd_flush,
+               .policy = ila_nl_policy,
+               .flags = GENL_ADMIN_PERM,
+       },
        {
                .cmd = ILA_CMD_GET,
                .doit = ila_xlat_nl_cmd_get_mapping,
index d05de891dfb60001adfc56c59f4f29762cddb5db..51a15ce50a6444c9f0f77079bea70d95ff2a80d2 100644 (file)
@@ -164,9 +164,9 @@ static inline void ila_release(struct ila_map *ila)
        kfree_rcu(ila, rcu);
 }
 
-static void ila_free_cb(void *ptr, void *arg)
+static void ila_free_node(struct ila_map *ila)
 {
-       struct ila_map *ila = (struct ila_map *)ptr, *next;
+       struct ila_map *next;
 
        /* Assume rcu_readlock held */
        while (ila) {
@@ -176,6 +176,11 @@ static void ila_free_cb(void *ptr, void *arg)
        }
 }
 
+static void ila_free_cb(void *ptr, void *arg)
+{
+       ila_free_node((struct ila_map *)ptr);
+}
+
 static int ila_xlat_addr(struct sk_buff *skb, bool sir2ila);
 
 static unsigned int
@@ -365,6 +370,59 @@ int ila_xlat_nl_cmd_del_mapping(struct sk_buff *skb, struct genl_info *info)
        return 0;
 }
 
+static inline spinlock_t *lock_from_ila_map(struct ila_net *ilan,
+                                           struct ila_map *ila)
+{
+       return ila_get_lock(ilan, ila->xp.ip.locator_match);
+}
+
+int ila_xlat_nl_cmd_flush(struct sk_buff *skb, struct genl_info *info)
+{
+       struct net *net = genl_info_net(info);
+       struct ila_net *ilan = net_generic(net, ila_net_id);
+       struct rhashtable_iter iter;
+       struct ila_map *ila;
+       spinlock_t *lock;
+       int ret;
+
+       ret = rhashtable_walk_init(&ilan->xlat.rhash_table, &iter, GFP_KERNEL);
+       if (ret)
+               goto done;
+
+       rhashtable_walk_start(&iter);
+
+       for (;;) {
+               ila = rhashtable_walk_next(&iter);
+
+               if (IS_ERR(ila)) {
+                       if (PTR_ERR(ila) == -EAGAIN)
+                               continue;
+                       ret = PTR_ERR(ila);
+                       goto done;
+               } else if (!ila) {
+                       break;
+               }
+
+               lock = lock_from_ila_map(ilan, ila);
+
+               spin_lock(lock);
+
+               ret = rhashtable_remove_fast(&ilan->xlat.rhash_table,
+                                            &ila->node, rht_params);
+               if (!ret)
+                       ila_free_node(ila);
+
+               spin_unlock(lock);
+
+               if (ret)
+                       break;
+       }
+
+done:
+       rhashtable_walk_stop(&iter);
+       return ret;
+}
+
 static int ila_fill_info(struct ila_map *ila, struct sk_buff *msg)
 {
        if (nla_put_u64_64bit(msg, ILA_ATTR_LOCATOR,