tree data FEATURE dup option not to duplicate ext nodes
diff --git a/src/tree_data.c b/src/tree_data.c
index 46668a7..eee87c8 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -1562,6 +1562,11 @@
     LY_CHECK_ARG_RET(NULL, node, LY_EINVAL);
 
     if (node->flags & LYD_EXT) {
+        if (options & LYD_DUP_NO_EXT) {
+            /* no not duplicate this subtree */
+            return LY_SUCCESS;
+        }
+
         /* we need to use the same context */
         trg_ctx = LYD_CTX(node);
     }
diff --git a/src/tree_data.h b/src/tree_data.h
index d1f64f9..0f8db3f 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -1951,6 +1951,7 @@
                                         Keys are also duplicated for lists. Return value does not change! */
 #define LYD_DUP_WITH_FLAGS   0x08  /**< Also copy any data node flags. That will cause the duplicated data to preserve
                                         its validation/default node state. */
+#define LYD_DUP_NO_EXT       0x10  /**< Do not duplicate nodes with the ::LYD_EXT flag (nested extension instance data). */
 
 /** @} dupoptions */