enum clusterip_hashmode hash_mode;      /* which hashing mode */
        u_int32_t hash_initval;                 /* hash initialization */
        struct rcu_head rcu;
-
+       struct net *net;                        /* netns for pernet list */
        char ifname[IFNAMSIZ];                  /* device ifname */
-       struct notifier_block notifier;         /* refresh c->ifindex in it */
 };
 
 #ifdef CONFIG_PROC_FS
 static const struct file_operations clusterip_proc_fops;
 #endif
 
-static unsigned int clusterip_net_id __read_mostly;
-
 struct clusterip_net {
        struct list_head configs;
        /* lock protects the configs list */
 #endif
 };
 
+static unsigned int clusterip_net_id __read_mostly;
+static inline struct clusterip_net *clusterip_pernet(struct net *net)
+{
+       return net_generic(net, clusterip_net_id);
+}
+
 static inline void
 clusterip_config_get(struct clusterip_config *c)
 {
        refcount_inc(&c->refcount);
 }
 
-
 static void clusterip_config_rcu_free(struct rcu_head *head)
 {
-       kfree(container_of(head, struct clusterip_config, rcu));
+       struct clusterip_config *config;
+       struct net_device *dev;
+
+       config = container_of(head, struct clusterip_config, rcu);
+       dev = dev_get_by_name(config->net, config->ifname);
+       if (dev) {
+               dev_mc_del(dev, config->clustermac);
+               dev_put(dev);
+       }
+       kfree(config);
 }
 
 static inline void
  * entry(rule) is removed, remove the config from lists, but don't free it
  * yet, since proc-files could still be holding references */
 static inline void
-clusterip_config_entry_put(struct net *net, struct clusterip_config *c)
+clusterip_config_entry_put(struct clusterip_config *c)
 {
-       struct clusterip_net *cn = net_generic(net, clusterip_net_id);
+       struct clusterip_net *cn = clusterip_pernet(c->net);
 
        local_bh_disable();
        if (refcount_dec_and_lock(&c->entries, &cn->lock)) {
                spin_unlock(&cn->lock);
                local_bh_enable();
 
-               unregister_netdevice_notifier(&c->notifier);
-
                return;
        }
        local_bh_enable();
 __clusterip_config_find(struct net *net, __be32 clusterip)
 {
        struct clusterip_config *c;
-       struct clusterip_net *cn = net_generic(net, clusterip_net_id);
+       struct clusterip_net *cn = clusterip_pernet(net);
 
        list_for_each_entry_rcu(c, &cn->configs, list) {
                if (c->clusterip == clusterip)
                       void *ptr)
 {
        struct net_device *dev = netdev_notifier_info_to_dev(ptr);
+       struct net *net = dev_net(dev);
+       struct clusterip_net *cn = clusterip_pernet(net);
        struct clusterip_config *c;
 
-       c = container_of(this, struct clusterip_config, notifier);
-       switch (event) {
-       case NETDEV_REGISTER:
-               if (!strcmp(dev->name, c->ifname)) {
-                       c->ifindex = dev->ifindex;
-                       dev_mc_add(dev, c->clustermac);
-               }
-               break;
-       case NETDEV_UNREGISTER:
-               if (dev->ifindex == c->ifindex) {
-                       dev_mc_del(dev, c->clustermac);
-                       c->ifindex = -1;
-               }
-               break;
-       case NETDEV_CHANGENAME:
-               if (!strcmp(dev->name, c->ifname)) {
-                       c->ifindex = dev->ifindex;
-                       dev_mc_add(dev, c->clustermac);
-               } else if (dev->ifindex == c->ifindex) {
-                       dev_mc_del(dev, c->clustermac);
-                       c->ifindex = -1;
+       spin_lock_bh(&cn->lock);
+       list_for_each_entry_rcu(c, &cn->configs, list) {
+               switch (event) {
+               case NETDEV_REGISTER:
+                       if (!strcmp(dev->name, c->ifname)) {
+                               c->ifindex = dev->ifindex;
+                               dev_mc_add(dev, c->clustermac);
+                       }
+                       break;
+               case NETDEV_UNREGISTER:
+                       if (dev->ifindex == c->ifindex) {
+                               dev_mc_del(dev, c->clustermac);
+                               c->ifindex = -1;
+                       }
+                       break;
+               case NETDEV_CHANGENAME:
+                       if (!strcmp(dev->name, c->ifname)) {
+                               c->ifindex = dev->ifindex;
+                               dev_mc_add(dev, c->clustermac);
+                       } else if (dev->ifindex == c->ifindex) {
+                               dev_mc_del(dev, c->clustermac);
+                               c->ifindex = -1;
+                       }
+                       break;
                }
-               break;
        }
+       spin_unlock_bh(&cn->lock);
 
        return NOTIFY_DONE;
 }
 clusterip_config_init(struct net *net, const struct ipt_clusterip_tgt_info *i,
                      __be32 ip, const char *iniface)
 {
-       struct clusterip_net *cn = net_generic(net, clusterip_net_id);
+       struct clusterip_net *cn = clusterip_pernet(net);
        struct clusterip_config *c;
+       struct net_device *dev;
        int err;
 
+       if (iniface[0] == '\0') {
+               pr_info("Please specify an interface name\n");
+               return ERR_PTR(-EINVAL);
+       }
+
        c = kzalloc(sizeof(*c), GFP_ATOMIC);
        if (!c)
                return ERR_PTR(-ENOMEM);
 
-       strcpy(c->ifname, iniface);
-       c->ifindex = -1;
-       c->clusterip = ip;
+       dev = dev_get_by_name(net, iniface);
+       if (!dev) {
+               pr_info("no such interface %s\n", iniface);
+               kfree(c);
+               return ERR_PTR(-ENOENT);
+       }
+       c->ifindex = dev->ifindex;
+       strcpy(c->ifname, dev->name);
        memcpy(&c->clustermac, &i->clustermac, ETH_ALEN);
+       dev_mc_add(dev, c->clustermac);
+       dev_put(dev);
+
+       c->clusterip = ip;
        c->num_total_nodes = i->num_total_nodes;
        clusterip_config_init_nodelist(c, i);
        c->hash_mode = i->hash_mode;
        c->hash_initval = i->hash_initval;
+       c->net = net;
        refcount_set(&c->refcount, 1);
 
        spin_lock_bh(&cn->lock);
        if (__clusterip_config_find(net, ip)) {
-               spin_unlock_bh(&cn->lock);
-               kfree(c);
-
-               return ERR_PTR(-EBUSY);
+               err = -EBUSY;
+               goto out_config_put;
        }
 
        list_add_rcu(&c->list, &cn->configs);
        }
 #endif
 
-       c->notifier.notifier_call = clusterip_netdev_event;
-       err = register_netdevice_notifier(&c->notifier);
-       if (!err) {
-               refcount_set(&c->entries, 1);
-               return c;
-       }
+       refcount_set(&c->entries, 1);
+       return c;
 
 #ifdef CONFIG_PROC_FS
-       proc_remove(c->pde);
 err:
 #endif
        spin_lock_bh(&cn->lock);
        list_del_rcu(&c->list);
+out_config_put:
        spin_unlock_bh(&cn->lock);
        clusterip_config_put(c);
-
        return ERR_PTR(err);
 }
 
                                &e->ip.dst.s_addr);
                        return -EINVAL;
                } else {
-                       struct net_device *dev;
-
-                       if (e->ip.iniface[0] == '\0') {
-                               pr_info("Please specify an interface name\n");
-                               return -EINVAL;
-                       }
-
-                       dev = dev_get_by_name(par->net, e->ip.iniface);
-                       if (!dev) {
-                               pr_info("no such interface %s\n",
-                                       e->ip.iniface);
-                               return -ENOENT;
-                       }
-                       dev_put(dev);
-
                        config = clusterip_config_init(par->net, cipinfo,
                                                       e->ip.dst.s_addr,
                                                       e->ip.iniface);
        if (ret < 0) {
                pr_info("cannot load conntrack support for proto=%u\n",
                        par->family);
-               clusterip_config_entry_put(par->net, config);
+               clusterip_config_entry_put(config);
                clusterip_config_put(config);
                return ret;
        }
 
        /* if no more entries are referencing the config, remove it
         * from the list and destroy the proc entry */
-       clusterip_config_entry_put(par->net, cipinfo->config);
+       clusterip_config_entry_put(cipinfo->config);
 
        clusterip_config_put(cipinfo->config);
 
 
 static int clusterip_net_init(struct net *net)
 {
-       struct clusterip_net *cn = net_generic(net, clusterip_net_id);
+       struct clusterip_net *cn = clusterip_pernet(net);
        int ret;
 
        INIT_LIST_HEAD(&cn->configs);
 
 static void clusterip_net_exit(struct net *net)
 {
-       struct clusterip_net *cn = net_generic(net, clusterip_net_id);
+       struct clusterip_net *cn = clusterip_pernet(net);
 #ifdef CONFIG_PROC_FS
        proc_remove(cn->procdir);
        cn->procdir = NULL;
        .size = sizeof(struct clusterip_net),
 };
 
+struct notifier_block cip_netdev_notifier = {
+       .notifier_call = clusterip_netdev_event
+};
+
 static int __init clusterip_tg_init(void)
 {
        int ret;
        if (ret < 0)
                goto cleanup_subsys;
 
+       ret = register_netdevice_notifier(&cip_netdev_notifier);
+       if (ret < 0)
+               goto unregister_target;
+
        pr_info("ClusterIP Version %s loaded successfully\n",
                CLUSTERIP_VERSION);
 
        return 0;
 
+unregister_target:
+       xt_unregister_target(&clusterip_tg_reg);
 cleanup_subsys:
        unregister_pernet_subsys(&clusterip_net_ops);
        return ret;
 {
        pr_info("ClusterIP Version %s unloading\n", CLUSTERIP_VERSION);
 
+       unregister_netdevice_notifier(&cip_netdev_notifier);
        xt_unregister_target(&clusterip_tg_reg);
        unregister_pernet_subsys(&clusterip_net_ops);