s4:NBT-WINSREPLICATION: test replication with names including scopes
[ira/wip.git] / source4 / torture / nbt / winsreplication.c
index b427843b80e445aa60e6ca3d7649a09172763b3a..f363c9ee5c23e02d26c3460df5c28aff64e6b503 100644 (file)
@@ -24,7 +24,6 @@
 #include "libcli/wrepl/winsrepl.h"
 #include "lib/events/events.h"
 #include "lib/socket/socket.h"
-#include "libcli/resolve/resolve.h"
 #include "system/network.h"
 #include "lib/socket/netif.h"
 #include "librpc/gen_ndr/ndr_nbt.h"
@@ -103,14 +102,14 @@ static bool test_assoc_ctx1(struct torture_context *tctx)
 
        torture_comment(tctx, "Test if assoc_ctx is only valid on the conection it was created on\n");
 
-       wrepl_socket1 = wrepl_socket_init(tctx, NULL);
-       wrepl_socket2 = wrepl_socket_init(tctx, NULL);
+       wrepl_socket1 = wrepl_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
+       wrepl_socket2 = wrepl_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
 
        torture_comment(tctx, "Setup 2 wrepl connections\n");
-       status = wrepl_connect(wrepl_socket1, NULL, address);
+       status = wrepl_connect(wrepl_socket1, wrepl_best_ip(tctx->lp_ctx, address), address);
        CHECK_STATUS(tctx, status, NT_STATUS_OK);
 
-       status = wrepl_connect(wrepl_socket2, NULL, address);
+       status = wrepl_connect(wrepl_socket2, wrepl_best_ip(tctx->lp_ctx, address), address);
        CHECK_STATUS(tctx, status, NT_STATUS_OK);
 
        torture_comment(tctx, "Send a start association request (conn1)\n");
@@ -186,10 +185,10 @@ static bool test_assoc_ctx2(struct torture_context *tctx)
 
        torture_comment(tctx, "Test if we always get back the same assoc_ctx\n");
 
-       wrepl_socket = wrepl_socket_init(tctx, NULL);
+       wrepl_socket = wrepl_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
        
        torture_comment(tctx, "Setup wrepl connections\n");
-       status = wrepl_connect(wrepl_socket, NULL, address);
+       status = wrepl_connect(wrepl_socket, wrepl_best_ip(tctx->lp_ctx, address), address);
        CHECK_STATUS(tctx, status, NT_STATUS_OK);
 
        torture_comment(tctx, "Send 1st start association request\n");
@@ -255,10 +254,10 @@ static bool test_wins_replication(struct torture_context *tctx)
 
        torture_comment(tctx, "Test one pull replication cycle\n");
 
-       wrepl_socket = wrepl_socket_init(tctx, NULL);
+       wrepl_socket = wrepl_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
        
        torture_comment(tctx, "Setup wrepl connections\n");
-       status = wrepl_connect(wrepl_socket, NULL, address);
+       status = wrepl_connect(wrepl_socket, wrepl_best_ip(tctx->lp_ctx, address), address);
        CHECK_STATUS(tctx, status, NT_STATUS_OK);
 
        torture_comment(tctx, "Send a start association request\n");
@@ -547,16 +546,17 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx(
        struct socket_address *nbt_srv_addr;
        NTSTATUS status;
        uint32_t i;
+       struct interface *ifaces;
 
        ctx = talloc_zero(tctx, struct test_wrepl_conflict_conn);
        if (!ctx) return NULL;
 
        ctx->address    = address;
-       ctx->pull       = wrepl_socket_init(ctx, NULL);
+       ctx->pull       = wrepl_socket_init(ctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
        if (!ctx->pull) return NULL;
 
        torture_comment(tctx, "Setup wrepl conflict pull connection\n");
-       status = wrepl_connect(ctx->pull, NULL, ctx->address);
+       status = wrepl_connect(ctx->pull, wrepl_best_ip(tctx->lp_ctx, ctx->address), ctx->address);
        if (!NT_STATUS_IS_OK(status)) return NULL;
 
        status = wrepl_associate(ctx->pull, &associate);
@@ -609,15 +609,17 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx(
 
        talloc_free(pull_table.out.partners);
 
-       ctx->nbtsock = nbt_name_socket_init(ctx, NULL);
+       ctx->nbtsock = nbt_name_socket_init(ctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
        if (!ctx->nbtsock) return NULL;
 
-       ctx->myaddr = socket_address_from_strings(tctx, ctx->nbtsock->sock->backend_name, iface_best_ip(tctx->lp_ctx, address), 0);
+       load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces);
+
+       ctx->myaddr = socket_address_from_strings(tctx, ctx->nbtsock->sock->backend_name, iface_best_ip(ifaces, address), 0);
        if (!ctx->myaddr) return NULL;
 
-       for (i = 0; i < iface_count(tctx->lp_ctx); i++) {
-               if (strcmp(ctx->myaddr->addr, iface_n_ip(tctx->lp_ctx, i)) == 0) continue;
-               ctx->myaddr2 = socket_address_from_strings(tctx, ctx->nbtsock->sock->backend_name, iface_n_ip(tctx->lp_ctx, i), 0);
+       for (i = 0; i < iface_count(ifaces); i++) {
+               if (strcmp(ctx->myaddr->addr, iface_n_ip(ifaces, i)) == 0) continue;
+               ctx->myaddr2 = socket_address_from_strings(tctx, ctx->nbtsock->sock->backend_name, iface_n_ip(ifaces, i), 0);
                if (!ctx->myaddr2) return NULL;
                break;
        }
@@ -625,7 +627,7 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx(
        status = socket_listen(ctx->nbtsock->sock, ctx->myaddr, 0, 0);
        if (!NT_STATUS_IS_OK(status)) return NULL;
 
-       ctx->nbtsock_srv = nbt_name_socket_init(ctx, NULL);
+       ctx->nbtsock_srv = nbt_name_socket_init(ctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
        if (!ctx->nbtsock_srv) return NULL;
 
        /* Make a port 137 version of ctx->myaddr */
@@ -642,13 +644,13 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx(
        }
 
        if (ctx->myaddr2 && ctx->nbtsock_srv) {
-               ctx->nbtsock2 = nbt_name_socket_init(ctx, NULL);
+               ctx->nbtsock2 = nbt_name_socket_init(ctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
                if (!ctx->nbtsock2) return NULL;
 
                status = socket_listen(ctx->nbtsock2->sock, ctx->myaddr2, 0, 0);
                if (!NT_STATUS_IS_OK(status)) return NULL;
 
-               ctx->nbtsock_srv2 = nbt_name_socket_init(ctx, ctx->nbtsock_srv->event_ctx);
+               ctx->nbtsock_srv2 = nbt_name_socket_init(ctx, ctx->nbtsock_srv->event_ctx, lp_iconv_convenience(tctx->lp_ctx));
                if (!ctx->nbtsock_srv2) return NULL;
 
                /* Make a port 137 version of ctx->myaddr2 */
@@ -674,12 +676,12 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx(
        ctx->addresses_best[0].owner    = ctx->b.address;
        ctx->addresses_best[0].ip       = ctx->myaddr->addr;
 
-       ctx->addresses_all_num = iface_count(tctx->lp_ctx);
+       ctx->addresses_all_num = iface_count(ifaces);
        ctx->addresses_all = talloc_array(ctx, struct wrepl_ip, ctx->addresses_all_num);
        if (!ctx->addresses_all) return NULL;
        for (i=0; i < ctx->addresses_all_num; i++) {
                ctx->addresses_all[i].owner     = ctx->b.address;
-               ctx->addresses_all[i].ip        = talloc_strdup(ctx->addresses_all, iface_n_ip(tctx->lp_ctx, i));
+               ctx->addresses_all[i].ip        = talloc_strdup(ctx->addresses_all, iface_n_ip(ifaces, i));
                if (!ctx->addresses_all[i].ip) return NULL;
        }
 
@@ -719,9 +721,9 @@ static bool test_wrepl_update_one(struct torture_context *tctx,
        uint32_t assoc_ctx;
        NTSTATUS status;
 
-       wrepl_socket = wrepl_socket_init(ctx, NULL);
+       wrepl_socket = wrepl_socket_init(ctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
 
-       status = wrepl_connect(wrepl_socket, NULL, ctx->address);
+       status = wrepl_connect(wrepl_socket, wrepl_best_ip(tctx->lp_ctx, ctx->address), ctx->address);
        CHECK_STATUS(tctx, status, NT_STATUS_OK);
 
        status = wrepl_associate(wrepl_socket, &associate);
@@ -797,9 +799,16 @@ static bool test_wrepl_is_applied(struct torture_context *tctx,
                                                  names[0].state,
                                                  names[0].node,
                                                  names[0].is_static);
+               char *expected_scope = NULL;
                CHECK_VALUE(tctx, names[0].name.type, name->name->type);
                CHECK_VALUE_STRING(tctx, names[0].name.name, name->name->name);
-               CHECK_VALUE_STRING(tctx, names[0].name.scope, name->name->scope);
+
+               if (names[0].name.scope) {
+                       expected_scope = talloc_strndup(tctx,
+                                                       name->name->scope,
+                                                       237);
+               }
+               CHECK_VALUE_STRING(tctx, names[0].name.scope, expected_scope);
                CHECK_VALUE(tctx, flags, name->flags);
                CHECK_VALUE_UINT64(tctx, names[0].version_id, name->id);
 
@@ -1002,18 +1011,63 @@ static bool test_wrepl_sgroup_merged(struct torture_context *tctx,
        return true;
 }
 
+static char *test_nbt_winsrepl_scope_string(TALLOC_CTX *mem_ctx, uint8_t count)
+{
+       char *res;
+       uint8_t i;
+
+       res = talloc_array(mem_ctx, char, count+1);
+       if (res == NULL) {
+               return NULL;
+       }
+
+       for (i=0; i < count; i++) {
+               res[i] = '0' + (i%10);
+       }
+
+       res[count] = '\0';
+
+       talloc_set_name_const(res, res);
+
+       return res;
+}
+
 static bool test_conflict_same_owner(struct torture_context *tctx, 
                                                                         struct test_wrepl_conflict_conn *ctx)
 {
        static bool ret = true;
-       struct nbt_name name;
        struct wrepl_wins_name wins_name1;
        struct wrepl_wins_name wins_name2;
        struct wrepl_wins_name *wins_name_tmp;
        struct wrepl_wins_name *wins_name_last;
        struct wrepl_wins_name *wins_name_cur;
        uint32_t i,j;
-       uint8_t types[] = { 0x00, 0x1C };
+       struct nbt_name names[] = {
+               _NBT_NAME("_SAME_OWNER_A", 0x00, NULL),
+               _NBT_NAME("_SAME_OWNER_A", 0x00,
+                         test_nbt_winsrepl_scope_string(tctx, 1)),
+               _NBT_NAME("_SAME_OWNER_A", 0x00,
+                         test_nbt_winsrepl_scope_string(tctx, 2)),
+               _NBT_NAME("_SAME_OWNER_A", 0x00,
+                         test_nbt_winsrepl_scope_string(tctx, 3)),
+               _NBT_NAME("_SAME_OWNER_A", 0x00,
+                         test_nbt_winsrepl_scope_string(tctx, 4)),
+               _NBT_NAME("_SAME_OWNER_A", 0x00,
+                         test_nbt_winsrepl_scope_string(tctx, 5)),
+               _NBT_NAME("_SAME_OWNER_A", 0x00,
+                         test_nbt_winsrepl_scope_string(tctx, 6)),
+               _NBT_NAME("_SAME_OWNER_A", 0x00,
+                         test_nbt_winsrepl_scope_string(tctx, 7)),
+               _NBT_NAME("_SAME_OWNER_A", 0x00,
+                         test_nbt_winsrepl_scope_string(tctx, 8)),
+               _NBT_NAME("_SAME_OWNER_A", 0x00,
+                         test_nbt_winsrepl_scope_string(tctx, 9)),
+               _NBT_NAME("_SAME_OWNER_A", 0x00,
+                         test_nbt_winsrepl_scope_string(tctx, 237)),
+               _NBT_NAME("_SAME_OWNER_A", 0x00,
+                         test_nbt_winsrepl_scope_string(tctx, 238)),
+               _NBT_NAME("_SAME_OWNER_A", 0x1C, NULL),
+       };
        struct {
                enum wrepl_name_type type;
                enum wrepl_name_state state;
@@ -1110,18 +1164,13 @@ static bool test_conflict_same_owner(struct torture_context *tctx,
                }
        };
 
-       name.name       = "_SAME_OWNER_A";
-       name.type       = 0;
-       name.scope      = NULL;
-
        wins_name_tmp   = NULL;
        wins_name_last  = &wins_name2;
        wins_name_cur   = &wins_name1;
 
-       for (j=0; ret && j < ARRAY_SIZE(types); j++) {
-               name.type = types[j];
+       for (j=0; ret && j < ARRAY_SIZE(names); j++) {
                torture_comment(tctx, "Test Replica Conflicts with same owner[%s] for %s\n",
-                       nbt_name_string(ctx, &name), ctx->a.address);
+                       nbt_name_string(ctx, &names[j]), ctx->a.address);
 
                for(i=0; ret && i < ARRAY_SIZE(records); i++) {
                        wins_name_tmp   = wins_name_last;
@@ -1140,7 +1189,7 @@ static bool test_conflict_same_owner(struct torture_context *tctx,
                                        "REPLACE");
                        }
 
-                       wins_name_cur->name     = &name;
+                       wins_name_cur->name     = &names[j];
                        wins_name_cur->flags    = WREPL_NAME_FLAGS(records[i].type,
                                                                   records[i].state,
                                                                   records[i].node,
@@ -1148,7 +1197,8 @@ static bool test_conflict_same_owner(struct torture_context *tctx,
                        wins_name_cur->id       = ++ctx->a.max_version;
                        if (wins_name_cur->flags & 2) {
                                wins_name_cur->addresses.addresses.num_ips = records[i].num_ips;
-                               wins_name_cur->addresses.addresses.ips     = discard_const(records[i].ips);
+                               wins_name_cur->addresses.addresses.ips     = discard_const_p(struct wrepl_ip,
+                                                                            records[i].ips);
                        } else {
                                wins_name_cur->addresses.ip = records[i].ips[0].ip;
                        }
@@ -4831,7 +4881,8 @@ static bool test_conflict_different_owner(struct torture_context *tctx,
                wins_name_r1->id        = ++records[i].r1.owner->max_version;
                if (wins_name_r1->flags & 2) {
                        wins_name_r1->addresses.addresses.num_ips = records[i].r1.num_ips;
-                       wins_name_r1->addresses.addresses.ips     = discard_const(records[i].r1.ips);
+                       wins_name_r1->addresses.addresses.ips     = discard_const_p(struct wrepl_ip,
+                                                                   records[i].r1.ips);
                } else {
                        wins_name_r1->addresses.ip = records[i].r1.ips[0].ip;
                }
@@ -4853,7 +4904,8 @@ static bool test_conflict_different_owner(struct torture_context *tctx,
                wins_name_r2->id        = ++records[i].r2.owner->max_version;
                if (wins_name_r2->flags & 2) {
                        wins_name_r2->addresses.addresses.num_ips = records[i].r2.num_ips;
-                       wins_name_r2->addresses.addresses.ips     = discard_const(records[i].r2.ips);
+                       wins_name_r2->addresses.addresses.ips     = discard_const_p(struct wrepl_ip,
+                                                                   records[i].r2.ips);
                } else {
                        wins_name_r2->addresses.ip = records[i].r2.ips[0].ip;
                }
@@ -4930,7 +4982,8 @@ static bool test_conflict_different_owner(struct torture_context *tctx,
                                                                   WREPL_NODE_B, false);
                        wins_name_r2->id        = ++records[i].r2.owner->max_version;
                        wins_name_r2->addresses.addresses.num_ips = ARRAY_SIZE(addresses_B_1);
-                       wins_name_r2->addresses.addresses.ips     = discard_const(addresses_B_1);
+                       wins_name_r2->addresses.addresses.ips     = discard_const_p(struct wrepl_ip,
+                                                                   addresses_B_1);
                        wins_name_r2->unknown   = "255.255.255.255";
                        ret &= test_wrepl_update_one(tctx, ctx, records[i].r2.owner, wins_name_r2);
                        ret &= test_wrepl_is_applied(tctx, ctx, records[i].r2.owner, wins_name_r2, true);
@@ -4942,7 +4995,8 @@ static bool test_conflict_different_owner(struct torture_context *tctx,
                                                                   WREPL_NODE_B, false);
                        wins_name_r2->id        = ++records[i].r2.owner->max_version;
                        wins_name_r2->addresses.addresses.num_ips = ARRAY_SIZE(addresses_B_1);
-                       wins_name_r2->addresses.addresses.ips     = discard_const(addresses_B_1);
+                       wins_name_r2->addresses.addresses.ips     = discard_const_p(struct wrepl_ip,
+                                                                   addresses_B_1);
                        wins_name_r2->unknown   = "255.255.255.255";
                        ret &= test_wrepl_update_one(tctx, ctx, records[i].r2.owner, wins_name_r2);
                        ret &= test_wrepl_is_applied(tctx, ctx, records[i].r2.owner, wins_name_r2, true);
@@ -6530,6 +6584,7 @@ static bool test_conflict_owned_released_vs_replica(struct torture_context *tctx
                 */
                name_register->in.name          = records[i].name;
                name_register->in.dest_addr     = ctx->address;
+               name_register->in.dest_port     = lp_nbt_port(tctx->lp_ctx);
                name_register->in.address       = records[i].wins.ips[0].ip;
                name_register->in.nb_flags      = records[i].wins.nb_flags;
                name_register->in.register_demand= false;
@@ -6558,6 +6613,7 @@ static bool test_conflict_owned_released_vs_replica(struct torture_context *tctx
 
                /* release the record */
                release->in.name        = records[i].name;
+               release->in.dest_port   = lp_nbt_port(tctx->lp_ctx);
                release->in.dest_addr   = ctx->address;
                release->in.address     = records[i].wins.ips[0].ip;
                release->in.nb_flags    = records[i].wins.nb_flags;
@@ -6588,7 +6644,8 @@ static bool test_conflict_owned_released_vs_replica(struct torture_context *tctx
                wins_name->id           = ++ctx->b.max_version;
                if (wins_name->flags & 2) {
                        wins_name->addresses.addresses.num_ips = records[i].replica.num_ips;
-                       wins_name->addresses.addresses.ips     = discard_const(records[i].replica.ips);
+                       wins_name->addresses.addresses.ips     = discard_const_p(struct wrepl_ip,
+                                                                records[i].replica.ips);
                } else {
                        wins_name->addresses.ip = records[i].replica.ips[0].ip;
                }
@@ -6612,6 +6669,7 @@ static bool test_conflict_owned_released_vs_replica(struct torture_context *tctx
                } else {
                        release->in.name        = records[i].name;
                        release->in.dest_addr   = ctx->address;
+                       release->in.dest_port   = lp_nbt_port(tctx->lp_ctx);
                        release->in.address     = records[i].wins.ips[0].ip;
                        release->in.nb_flags    = records[i].wins.nb_flags;
                        release->in.broadcast   = false;
@@ -6695,7 +6753,6 @@ static bool test_conflict_owned_active_vs_replica(struct torture_context *tctx,
 /* 
  * unique vs. unique section
  */
-#if METZE_NEEDS_TO_LOOK_AT_THIS_ONE
        /*
         * unique,active vs. unique,active with same ip(s), unchecked
         */
@@ -6722,7 +6779,6 @@ static bool test_conflict_owned_active_vs_replica(struct torture_context *tctx,
                        .apply_expected = true
                },
        },
-#endif
        /*
         * unique,active vs. unique,active with different ip(s), positive response
         */
@@ -8961,7 +9017,6 @@ static bool test_conflict_owned_active_vs_replica(struct torture_context *tctx,
                        .sgroup_merge   = true
                },
        },
-#if 0
        /*
         * sgroup,active vs. sgroup,active with same ip(s)
         */
@@ -9151,7 +9206,6 @@ static bool test_conflict_owned_active_vs_replica(struct torture_context *tctx,
                        .apply_expected = false
                },
        },
-#endif
        };
 
        if (!ctx->nbtsock_srv) {
@@ -9218,6 +9272,7 @@ static bool test_conflict_owned_active_vs_replica(struct torture_context *tctx,
 
                        name_register->in.name          = records[i].name;
                        name_register->in.dest_addr     = ctx->address;
+                       name_register->in.dest_port     = lp_nbt_port(tctx->lp_ctx);
                        name_register->in.address       = records[i].wins.ips[j].ip;
                        name_register->in.nb_flags      = records[i].wins.nb_flags;
                        name_register->in.register_demand= false;
@@ -9287,7 +9342,8 @@ static bool test_conflict_owned_active_vs_replica(struct torture_context *tctx,
                wins_name->id           = ++ctx->b.max_version;
                if (wins_name->flags & 2) {
                        wins_name->addresses.addresses.num_ips = records[i].replica.num_ips;
-                       wins_name->addresses.addresses.ips     = discard_const(records[i].replica.ips);
+                       wins_name->addresses.addresses.ips     = discard_const_p(struct wrepl_ip,
+                                                                records[i].replica.ips);
                } else {
                        wins_name->addresses.ip = records[i].replica.ips[0].ip;
                }
@@ -9363,6 +9419,7 @@ static bool test_conflict_owned_active_vs_replica(struct torture_context *tctx,
 
                                release->in.name        = records[i].name;
                                release->in.dest_addr   = ctx->address;
+                               release->in.dest_port   = lp_nbt_port(tctx->lp_ctx);
                                release->in.address     = records[i].wins.ips[j].ip;
                                release->in.nb_flags    = records[i].wins.nb_flags;
                                release->in.broadcast   = false;
@@ -9401,7 +9458,8 @@ static bool test_conflict_owned_active_vs_replica(struct torture_context *tctx,
                                                                           WREPL_NODE_B, false);
                                wins_name->id           = ++ctx->b.max_version;
                                wins_name->addresses.addresses.num_ips = ARRAY_SIZE(addresses_B_1);
-                               wins_name->addresses.addresses.ips     = discard_const(addresses_B_1);
+                               wins_name->addresses.addresses.ips     = discard_const_p(struct wrepl_ip,
+                                                                        addresses_B_1);
                                wins_name->unknown      = "255.255.255.255";
                                ret &= test_wrepl_update_one(tctx, ctx, &ctx->b, wins_name);
                                ret &= test_wrepl_is_applied(tctx, ctx, &ctx->b, wins_name, true);
@@ -9453,7 +9511,7 @@ static void test_conflict_owned_active_vs_replica_handler_query(struct nbt_name_
        struct nbt_name *name;
        struct nbt_name_packet *rep_packet;
        struct test_conflict_owned_active_vs_replica_struct *rec = 
-               (struct test_conflict_owned_active_vs_replica_struct *)nbtsock->incoming.private;
+               (struct test_conflict_owned_active_vs_replica_struct *)nbtsock->incoming.private_data;
 
        _NBT_ASSERT(req_packet->qdcount, 1);
        _NBT_ASSERT(req_packet->questions[0].question_type, NBT_QTYPE_NETBIOS);
@@ -9535,7 +9593,9 @@ static void test_conflict_owned_active_vs_replica_handler_query(struct nbt_name_
        talloc_free(rep_packet);
 
        /* make sure we push the reply to the wire */
-       event_loop_once(nbtsock->event_ctx);
+       while (nbtsock->send_queue) {
+               event_loop_once(nbtsock->event_ctx);
+       }
        msleep(1000);
 
        rec->defend.timeout     = 0;
@@ -9550,7 +9610,7 @@ static void test_conflict_owned_active_vs_replica_handler_release(
        struct nbt_name *name;
        struct nbt_name_packet *rep_packet;
        struct test_conflict_owned_active_vs_replica_struct *rec = 
-               (struct test_conflict_owned_active_vs_replica_struct *)nbtsock->incoming.private;
+               (struct test_conflict_owned_active_vs_replica_struct *)nbtsock->incoming.private_data;
 
        _NBT_ASSERT(req_packet->qdcount, 1);
        _NBT_ASSERT(req_packet->questions[0].question_type, NBT_QTYPE_NETBIOS);
@@ -9590,7 +9650,9 @@ static void test_conflict_owned_active_vs_replica_handler_release(
        talloc_free(rep_packet);
 
        /* make sure we push the reply to the wire */
-       event_loop_once(nbtsock->event_ctx);
+       while (nbtsock->send_queue) {
+               event_loop_once(nbtsock->event_ctx);
+       }
        msleep(1000);
 
        rec->defend.timeout     = 0;
@@ -9602,7 +9664,7 @@ static void test_conflict_owned_active_vs_replica_handler(struct nbt_name_socket
                                                          struct socket_address *src)
 {
        struct test_conflict_owned_active_vs_replica_struct *rec = 
-               (struct test_conflict_owned_active_vs_replica_struct *)nbtsock->incoming.private;
+               (struct test_conflict_owned_active_vs_replica_struct *)nbtsock->incoming.private_data;
 
        rec->defend.ret = false;