u32 *dst_cow_metrics_generic(struct dst_entry *dst, unsigned long old);
 extern const u32 dst_default_metrics[];
 
-#define DST_METRICS_READ_ONLY  0x1UL
+#define DST_METRICS_READ_ONLY          0x1UL
+#define DST_METRICS_FORCE_OVERWRITE    0x2UL
+#define DST_METRICS_FLAGS              0x3UL
 #define __DST_METRICS_PTR(Y)   \
-       ((u32 *)((Y) & ~DST_METRICS_READ_ONLY))
+       ((u32 *)((Y) & ~DST_METRICS_FLAGS))
 #define DST_METRICS_PTR(X)     __DST_METRICS_PTR((X)->_metrics)
 
 static inline bool dst_metrics_read_only(const struct dst_entry *dst)
        return dst->_metrics & DST_METRICS_READ_ONLY;
 }
 
+static inline void dst_metrics_set_force_overwrite(struct dst_entry *dst)
+{
+       dst->_metrics |= DST_METRICS_FORCE_OVERWRITE;
+}
+
 void __dst_destroy_metrics_generic(struct dst_entry *dst, unsigned long old);
 
 static inline void dst_destroy_metrics_generic(struct dst_entry *dst)
 
 void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *arg),
                    void *arg);
 
-int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info);
+int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info,
+            struct nlattr *mx, int mx_len);
 
 int fib6_del(struct rt6_info *rt, struct nl_info *info);
 
 
               RTF_GATEWAY;
 }
 
+static int fib6_commit_metrics(struct dst_entry *dst,
+                              struct nlattr *mx, int mx_len)
+{
+       struct nlattr *nla;
+       int remaining;
+       u32 *mp;
+
+       if (dst->flags & DST_HOST) {
+               mp = dst_metrics_write_ptr(dst);
+       } else {
+               mp = kzalloc(sizeof(u32) * RTAX_MAX, GFP_KERNEL);
+               if (!mp)
+                       return -ENOMEM;
+               dst_init_metrics(dst, mp, 0);
+       }
+
+       nla_for_each_attr(nla, mx, mx_len, remaining) {
+               int type = nla_type(nla);
+
+               if (type) {
+                       if (type > RTAX_MAX)
+                               return -EINVAL;
+
+                       mp[type - 1] = nla_get_u32(nla);
+               }
+       }
+       return 0;
+}
+
 /*
  *     Insert routing information in a node.
  */
 
 static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
-                           struct nl_info *info)
+                           struct nl_info *info, struct nlattr *mx, int mx_len)
 {
        struct rt6_info *iter = NULL;
        struct rt6_info **ins;
                   (info->nlh->nlmsg_flags & NLM_F_CREATE));
        int found = 0;
        bool rt_can_ecmp = rt6_qualify_for_ecmp(rt);
+       int err;
 
        ins = &fn->leaf;
 
                        pr_warn("NLM_F_CREATE should be set when creating new route\n");
 
 add:
+               if (mx) {
+                       err = fib6_commit_metrics(&rt->dst, mx, mx_len);
+                       if (err)
+                               return err;
+               }
                rt->dst.rt6_next = iter;
                *ins = rt;
                rt->rt6i_node = fn;
                        pr_warn("NLM_F_REPLACE set, but no existing node found!\n");
                        return -ENOENT;
                }
+               if (mx) {
+                       err = fib6_commit_metrics(&rt->dst, mx, mx_len);
+                       if (err)
+                               return err;
+               }
                *ins = rt;
                rt->rt6i_node = fn;
                rt->dst.rt6_next = iter->dst.rt6_next;
  *     with source addr info in sub-trees
  */
 
-int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
+int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info,
+            struct nlattr *mx, int mx_len)
 {
        struct fib6_node *fn, *pn = NULL;
        int err = -ENOMEM;
        }
 #endif
 
-       err = fib6_add_rt2node(fn, rt, info);
+       err = fib6_add_rt2node(fn, rt, info, mx, mx_len);
        if (!err) {
                fib6_start_gc(info->nl_net, rt);
                if (!(rt->rt6i_flags & RTF_CACHE))
 
                unsigned long prev, new;
 
                p = peer->metrics;
-               if (inet_metrics_new(peer))
+               if (inet_metrics_new(peer) ||
+                   (old & DST_METRICS_FORCE_OVERWRITE))
                        memcpy(p, old_p, sizeof(u32) * RTAX_MAX);
 
                new = (unsigned long) p;
    be destroyed.
  */
 
-static int __ip6_ins_rt(struct rt6_info *rt, struct nl_info *info)
+static int __ip6_ins_rt(struct rt6_info *rt, struct nl_info *info,
+                       struct nlattr *mx, int mx_len)
 {
        int err;
        struct fib6_table *table;
 
        table = rt->rt6i_table;
        write_lock_bh(&table->tb6_lock);
-       err = fib6_add(&table->tb6_root, rt, info);
+       err = fib6_add(&table->tb6_root, rt, info, mx, mx_len);
        write_unlock_bh(&table->tb6_lock);
 
        return err;
        struct nl_info info = {
                .nl_net = dev_net(rt->dst.dev),
        };
-       return __ip6_ins_rt(rt, &info);
+       return __ip6_ins_rt(rt, &info, NULL, 0);
 }
 
 static struct rt6_info *rt6_alloc_cow(struct rt6_info *ort,
 
        ipv6_addr_prefix(&rt->rt6i_dst.addr, &cfg->fc_dst, cfg->fc_dst_len);
        rt->rt6i_dst.plen = cfg->fc_dst_len;
-       if (rt->rt6i_dst.plen == 128)
-              rt->dst.flags |= DST_HOST;
-
-       if (!(rt->dst.flags & DST_HOST) && cfg->fc_mx) {
-               u32 *metrics = kzalloc(sizeof(u32) * RTAX_MAX, GFP_KERNEL);
-               if (!metrics) {
-                       err = -ENOMEM;
-                       goto out;
-               }
-               dst_init_metrics(&rt->dst, metrics, 0);
+       if (rt->rt6i_dst.plen == 128) {
+               rt->dst.flags |= DST_HOST;
+               dst_metrics_set_force_overwrite(&rt->dst);
        }
+
 #ifdef CONFIG_IPV6_SUBTREES
        ipv6_addr_prefix(&rt->rt6i_src.addr, &cfg->fc_src, cfg->fc_src_len);
        rt->rt6i_src.plen = cfg->fc_src_len;
        rt->rt6i_flags = cfg->fc_flags;
 
 install_route:
-       if (cfg->fc_mx) {
-               struct nlattr *nla;
-               int remaining;
-
-               nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) {
-                       int type = nla_type(nla);
-
-                       if (type) {
-                               if (type > RTAX_MAX) {
-                                       err = -EINVAL;
-                                       goto out;
-                               }
-
-                               dst_metric_set(&rt->dst, type, nla_get_u32(nla));
-                       }
-               }
-       }
-
        rt->dst.dev = dev;
        rt->rt6i_idev = idev;
        rt->rt6i_table = table;
 
        cfg->fc_nlinfo.nl_net = dev_net(dev);
 
-       return __ip6_ins_rt(rt, &cfg->fc_nlinfo);
+       return __ip6_ins_rt(rt, &cfg->fc_nlinfo, cfg->fc_mx, cfg->fc_mx_len);
 
 out:
        if (dev)