Commit af3c5f89 authored by Pekka Pessi's avatar Pekka Pessi

test_nua: added a few tests for 200 OK timeout / ACK failing.

darcs-hash:20070201194306-65a35-dd94b1659b7836715bb9ae265b4aeca9927aefe6.gz
parent 3e418f2b
This diff is collapsed.
......@@ -224,7 +224,7 @@ int test_nua_init(struct context *ctx,
NUTAG_URL(a_bind),
TAG_IF(a_bind != a_bind2, NUTAG_SIPS_URL(a_bind2)),
SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
NTATAG_SIP_T1X64(4000),
NTATAG_SIP_T1X64(2000),
NUTAG_INSTANCE(ctx->a.instance),
TAG_IF(ctx->a.logging, TPTAG_LOG(1)),
TAG_END());
......@@ -262,6 +262,8 @@ int test_nua_init(struct context *ctx,
NUTAG_URL("sip:0.0.0.0:*"),
SOATAG_USER_SDP_STR("m=audio 5006 RTP/AVP 8 0"),
NUTAG_INSTANCE(ctx->b.instance),
/* Quicker timeout */
NTATAG_SIP_T1X64(2000),
TAG_IF(ctx->b.logging, TPTAG_LOG(1)),
TAG_END());
TEST_1(ctx->b.nua);
......
......@@ -91,6 +91,8 @@ struct nat {
struct binding *bindings;
struct nat_filter *in_filters, *out_filters;
/* True if we act in symmetric way */
int symmetric;
/* True if we do logging */
......@@ -153,6 +155,14 @@ static int tcp_out_to_in(struct nat *, su_wait_t *wait, struct binding *);
static int invalidate_binding(struct binding *b);
LIST_PROTOS(static, nat_filter, struct nat_filter);
struct nat_filter
{
struct nat_filter *next, **prev;
int (*condition)(void const *message, size_t len);
};
/* nat entry point */
static int
test_nat_init(su_root_t *root, struct nat *nat)
......@@ -670,6 +680,7 @@ static int udp_in_to_out(struct nat *nat, su_wait_t *wait, struct binding *b)
{
int events;
ssize_t n, m;
struct nat_filter *f;
events = su_wait_events(wait, b->in_socket);
......@@ -679,6 +690,15 @@ static int udp_in_to_out(struct nat *nat, su_wait_t *wait, struct binding *b)
return 0;
}
for (f = nat->out_filters; f; f = f->next) {
if (f->condition(nat->buffer, (size_t)n)) {
if (nat->logging)
printf("nat: udp filtered %d %s => %s\n",
(int)n, b->in_name, b->out_name);
return 0;
}
}
if (nat->symmetric)
m = su_send(b->out_socket, nat->buffer, n, 0);
else
......@@ -696,6 +716,7 @@ static int udp_out_to_in(struct nat *nat, su_wait_t *wait, struct binding *b)
{
int events;
ssize_t n, m;
struct nat_filter *f;
events = su_wait_events(wait, b->out_socket);
......@@ -705,6 +726,15 @@ static int udp_out_to_in(struct nat *nat, su_wait_t *wait, struct binding *b)
return 0;
}
for (f = nat->in_filters; f; f = f->next) {
if (f->condition(nat->buffer, (size_t)n)) {
if (nat->logging)
printf("nat: udp filtered %d %s => %s\n",
(int)n, b->out_name, b->in_name);
return 0;
}
}
m = su_send(b->in_socket, nat->buffer, n, 0);
if (nat->logging)
......@@ -882,3 +912,72 @@ static int invalidate_binding(struct binding *b)
return 0;
}
LIST_BODIES(static, nat_filter, struct nat_filter, next, prev);
struct args {
struct nat *nat;
struct nat_filter *f;
int outbound;
};
int execute_nat_filter_insert(void *_args)
{
struct args *a = (struct args *)_args;
if (a->outbound)
nat_filter_insert(&a->nat->out_filters, a->f);
else
nat_filter_insert(&a->nat->in_filters, a->f);
return 0;
}
int execute_nat_filter_remove(void *_args)
{
struct args *a = (struct args *)_args;
nat_filter_remove(a->f);
return 0;
}
struct nat_filter *test_nat_add_filter(struct nat *nat,
int (*condition)(void const *message,
size_t len),
int outbound)
{
struct args a[1];
if (nat == NULL)
return su_seterrno(EFAULT), NULL;
a->nat = nat;
a->f = su_zalloc(nat->home, sizeof *a->f);
a->outbound = outbound;
if (a->f) {
a->f->condition = condition;
if (su_task_execute(su_clone_task(nat->clone),
execute_nat_filter_insert, a, NULL) < 0)
su_free(nat->home, a->f), a->f = NULL;
}
return a->f;
}
int test_nat_remove_filter(struct nat *nat,
struct nat_filter *filter)
{
struct args a[1];
if (nat == NULL)
return su_seterrno(EFAULT);
a->nat = nat;
a->f = filter;
if (su_task_execute(su_clone_task(nat->clone),
execute_nat_filter_remove, a, NULL) < 0)
return -1;
su_free(nat->home, filter);
return 0;
}
......@@ -31,6 +31,7 @@
SOFIA_BEGIN_DECLS
struct nat;
struct nat_filter;
struct nat *test_nat_create(su_root_t *, int family,
tag_type_t, tag_value_t, ...);
......@@ -42,6 +43,16 @@ int test_nat_public(struct nat *nat, void const *address, int addrlen);
int test_nat_flush(struct nat *nat);
struct nat_filter *test_nat_add_filter(struct nat *nat,
int (*condition)(void const *message,
size_t len),
int outbound);
enum { nat_inbound, nat_outbound };
int test_nat_remove_filter(struct nat *nat,
struct nat_filter *filter);
/* Tags */
/** If true, act as symmetric nat. */
......
......@@ -231,9 +231,11 @@ int main(int argc, char *argv[])
else if (argv[i][0] != '-') {
break;
}
else
else {
fprintf(stderr, "test_nua: unknown argument \"%s\"\n\n", argv[i]);
usage(1);
}
}
if (o_attach) {
char line[10], *l;
......@@ -301,13 +303,13 @@ int main(int argc, char *argv[])
retval |= test_nat_timeout(ctx);
while (retval == 0) {
retval |= test_extension(ctx); SINGLE_FAILURE_CHECK();
retval |= test_basic_call(ctx); SINGLE_FAILURE_CHECK();
retval |= test_reject_a(ctx); SINGLE_FAILURE_CHECK();
retval |= test_reject_b(ctx); SINGLE_FAILURE_CHECK();
retval |= test_reject_302(ctx); SINGLE_FAILURE_CHECK();
retval |= test_reject_401(ctx); SINGLE_FAILURE_CHECK();
retval |= test_mime_negotiation(ctx); SINGLE_FAILURE_CHECK();
retval |= test_call_timeouts(ctx); SINGLE_FAILURE_CHECK();
retval |= test_reject_401_aka(ctx); SINGLE_FAILURE_CHECK();
retval |= test_call_cancel(ctx); SINGLE_FAILURE_CHECK();
retval |= test_call_destroy(ctx); SINGLE_FAILURE_CHECK();
......@@ -318,6 +320,7 @@ int main(int argc, char *argv[])
retval |= test_100rel(ctx); SINGLE_FAILURE_CHECK();
retval |= test_events(ctx); SINGLE_FAILURE_CHECK();
retval |= test_simple(ctx); SINGLE_FAILURE_CHECK();
retval |= test_extension(ctx); SINGLE_FAILURE_CHECK();
if (!o_loop)
break;
}
......
......@@ -332,6 +332,7 @@ int test_reject_b(struct context *ctx);
int test_reject_302(struct context *ctx);
int test_reject_401(struct context *ctx);
int test_mime_negotiation(struct context *ctx);
int test_call_timeouts(struct context *ctx);
int test_reject_401_aka(struct context *ctx);
int test_call_cancel(struct context *ctx);
int test_call_destroy(struct context *ctx);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment