@@ -36,8 +36,10 @@ START_TEST(test_route_nexthop_api_set_get_all)
3636 _nl_auto_nl_addr struct nl_addr * via6 = NULL ;
3737 _nl_auto_nl_addr struct nl_addr * mpls = NULL ;
3838 _nl_auto_rtnl_nexthop struct rtnl_nexthop * clone = NULL ;
39+ _nl_auto_rtnl_nexthop struct rtnl_nexthop * clone_with_encap = NULL ;
3940 struct rtnl_nh_encap * encap = NULL ;
4041 struct rtnl_nh_encap * got = NULL ;
42+ struct rtnl_nh_encap * encap_clone = NULL ;
4143 uint32_t realms = 0xAABBCCDDu ;
4244 char flags_buf [64 ];
4345 int flags_parsed ;
@@ -141,6 +143,28 @@ START_TEST(test_route_nexthop_api_set_get_all)
141143 ck_assert_ptr_nonnull (rtnl_nh_get_encap_mpls_dst (got ));
142144 ck_assert_int_eq (rtnl_nh_get_encap_mpls_ttl (got ), 64 );
143145
146+ /* Exercise rtnl_nh_encap_clone() directly */
147+ encap_clone = rtnl_nh_encap_clone (encap );
148+ ck_assert_ptr_nonnull (encap_clone );
149+ ck_assert_ptr_nonnull (rtnl_nh_get_encap_mpls_dst (encap_clone ));
150+ ck_assert_int_eq (
151+ nl_addr_cmp (rtnl_nh_get_encap_mpls_dst (encap_clone ), mpls ), 0 );
152+ ck_assert_uint_eq (rtnl_nh_get_encap_mpls_ttl (encap_clone ), 64 );
153+ /* Free the cloned encap explicitly */
154+ rtnl_nh_encap_free (encap_clone );
155+ encap_clone = NULL ;
156+
157+ /* Exercise nexthop clone with encap: encap should be deep-cloned */
158+ clone_with_encap = rtnl_route_nh_clone (nh );
159+ ck_assert_ptr_nonnull (clone_with_encap );
160+ encap_clone = rtnl_route_nh_get_encap (clone_with_encap );
161+ ck_assert_ptr_nonnull (encap_clone );
162+ /* The encap on the clone must not be the same pointer */
163+ ck_assert_ptr_ne (encap_clone , encap );
164+ ck_assert_int_eq (
165+ nl_addr_cmp (rtnl_nh_get_encap_mpls_dst (encap_clone ), mpls ), 0 );
166+ ck_assert_uint_eq (rtnl_nh_get_encap_mpls_ttl (encap_clone ), 64 );
167+
144168 /* Clear encap and verify it is removed */
145169 ck_assert_int_eq (rtnl_route_nh_set_encap (nh , NULL ), 0 );
146170 ck_assert_ptr_eq (rtnl_route_nh_get_encap (nh ), NULL );
0 commit comments