ssize_t hncp_io_sendto(hncp o, void *buf, size_t len, const char *ifname, const struct in6_addr *dst) { if (check_send) { sput_fail_unless(o, "hncp"); sput_fail_unless(o && o->udp_socket == 1, "hncp_io ready"); smock_pull_string_is("sendto_ifname", ifname); struct in6_addr *e_dst = smock_pull("sendto_dst"); sput_fail_unless(e_dst && memcmp(e_dst, dst, sizeof(*dst)) == 0, "dst match"); /* Two optional verification steps.. */ if (_smock_get_queue("sendto_len", false)) { int r_len = smock_pull_int("sendto_len"); sput_fail_unless(r_len == (int) len, "len"); } if (_smock_get_queue("sendto_buf", false)) { unsigned char *r = smock_pull("sendto_buf"); sput_fail_unless(memcmp(r, buf, len), "buf"); } return smock_pull_int("sendto_return"); } else { want_send++; return 1; } }
void dncp_ext_readable(dncp o) { char buf[1024]; size_t len = sizeof(buf); int r; struct sockaddr_in6 *src, *dst; dncp_ep ep; int flags; r = o->ext->cb.recv(o->ext, &ep, &src, &dst, &flags, buf, len); smock_pull_int_is("dncp_poll_io_recvfrom", r); if (r >= 0) { void *b = smock_pull("dncp_poll_io_recvfrom_buf"); char *ifn = smock_pull("dncp_poll_io_recvfrom_ifname"); struct sockaddr_in6 *esrc = smock_pull("dncp_poll_io_recvfrom_src"); struct sockaddr_in6 *edst = smock_pull("dncp_poll_io_recvfrom_dst"); sput_fail_unless(memcmp(b, buf, r)==0, "buf mismatch"); sput_fail_unless(strcmp(ifn, ep->ifname) == 0, "ifname mismatch"); sput_fail_unless(memcmp(src, esrc, sizeof(*src))==0, "src mismatch"); sput_fail_unless(memcmp(&dst->sin6_addr, &edst->sin6_addr, sizeof(dst->sin6_addr))==0, "dst mismatch"); if (!--pending_packets) uloop_end(); } }
int hncp_io_get_hwaddrs(unsigned char *buf, int buf_left) { unsigned char *r = smock_pull("get_hwaddrs_buf"); int r_len = smock_pull_int("get_hwaddrs_len"); memcpy(buf, r, r_len); sput_fail_unless(r_len <= buf_left, "result length reasonable"); return r_len; }
ssize_t hncp_io_recvfrom(hncp o, void *buf, size_t len, char *ifname, struct in6_addr *src, struct in6_addr *dst) { unsigned char *r = smock_pull("recvfrom_buf"); int r_len = smock_pull_int("recvfrom_len"); struct in6_addr *r_src = smock_pull("recvfrom_src"); struct in6_addr *r_dst = smock_pull("recvfrom_dst"); smock_pull_string_is("recvfrom_ifname", ifname); sput_fail_unless(o, "hncp"); sput_fail_unless(o && o->udp_socket == 1, "hncp_io_schedule valid"); sput_fail_unless(r_len <= ((int) len), "result length reasonable"); *src = *r_src; *dst = *r_dst; memcpy(buf, r, r_len); return r_len; }
void hncp_io_uninit(hncp o) { o->udp_socket = 0; sput_fail_unless(o, "hncp"); smock_pull("uninit"); }
static void dummy_republish_cb(hncp_subscriber s __unused) { L_NOTICE("republish callback"); smock_pull("republish_callback"); }
void dncp_ext_timeout(dncp o) { smock_pull("dncp_run"); }
void iface_test_new_managed(void) { struct in_addr v4source = {INADDR_LOOPBACK}; iface_register_user(&user_mock); struct prefix p = {IN6ADDR_LOOPBACK_INIT, 0}; char test[] = "test"; struct iface *iface00 = iface_create("test00", "test00", 0); iface_update_ipv4_uplink(iface00); iface_set_ipv4_uplink(iface00, &v4source, 24); iface_commit_ipv4_uplink(iface00); /* smock_pull_bool_is("test00", false); */ /* this was removed in the commit a5293745c235a057b6a477ffbd817937eaa9bc12 at 5/2015(!); */ struct iface *iface = iface_create("test0", "test0", 0); iface->carrier = true; iface_discover_border(iface); sput_fail_unless(!!iface, "alloc managed"); struct iface *iface2 = iface_get("test0"); sput_fail_unless(iface == iface2, "get after create"); struct iface *iface3 = iface_create("test0", "test0", 0); sput_fail_unless(iface == iface3, "create after create"); /* smock_pull_bool_is("test0", false); */ /* this was removed in the commit a5293745c235a057b6a477ffbd817937eaa9bc12 at 5/2015(!); */ uloop_cancelled = false; uloop_run(); smock_pull_bool_is("test0", true); iface_update_ipv4_uplink(iface); iface_set_ipv4_uplink(iface, &v4source, 24); iface_commit_ipv4_uplink(iface); smock_pull_bool_is("test0", false); iface_update_ipv4_uplink(iface); iface_commit_ipv4_uplink(iface); uloop_cancelled = false; uloop_run(); smock_pull_bool_is("test0", true); iface_update_ipv6_uplink(iface); iface_add_delegated(iface, &p, NULL, HNETD_TIME_MAX, 0, test, sizeof(test)); iface_commit_ipv6_uplink(iface); smock_pull_bool_is("test0", false); sput_fail_unless(!prefix_cmp(&p, (struct prefix *)smock_pull("prefix_prefix")), "prefix address"); smock_pull_int64_is("prefix_valid", HNETD_TIME_MAX); smock_pull_int64_is("prefix_preferred", 0); sput_fail_unless(!strcmp(smock_pull("dhcpv6_data"), "test"), "dhcpv6_data"); smock_pull_int_is("dhcpv6_len", sizeof(test)); iface_update_ipv4_uplink(iface); iface_set_ipv4_uplink(iface, &v4source, 24); iface_commit_ipv4_uplink(iface); iface_update_ipv6_uplink(iface); iface_commit_ipv6_uplink(iface); smock_pull_bool_is("prefix_remove", true); iface_update_ipv4_uplink(iface); iface_commit_ipv4_uplink(iface); uloop_cancelled = false; uloop_run(); smock_pull_bool_is("test0", true); iface_remove(iface); sput_fail_unless(!iface_get("test0"), "delete"); smock_pull_bool_is("test0", false); smock_is_empty(); iface_unregister_user(&user_mock); }