Commit 4a8826a4 authored by Pekka Pessi's avatar Pekka Pessi

test_nua: allow nat filter to remove parts of the messages.

darcs-hash:20070206172516-65a35-77f393a3fb7564083b12bb83d67891cdf29610f9.gz
parent 86e57a84
...@@ -948,14 +948,18 @@ int test_mime_negotiation(struct context *ctx) ...@@ -948,14 +948,18 @@ int test_mime_negotiation(struct context *ctx)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int filter_200_OK(void const *message, size_t len) size_t filter_200_OK(void *message, size_t len)
{ {
return len >= 11 && strncasecmp(message, "SIP/2.0 200", 11) == 0; if (len >= 11 && strncasecmp(message, "SIP/2.0 200", 11) == 0)
return 0;
return len;
} }
int filter_ACK(void const *message, size_t len) size_t filter_ACK(void *message, size_t len)
{ {
return len >= 7 && strncasecmp(message, "ACK sip", 7) == 0; if (len >= 7 && strncasecmp(message, "ACK sip", 7) == 0)
return 0;
return len;
} }
int call_with_bad_ack(CONDITION_PARAMS); int call_with_bad_ack(CONDITION_PARAMS);
......
...@@ -160,7 +160,7 @@ LIST_PROTOS(static, nat_filter, struct nat_filter); ...@@ -160,7 +160,7 @@ LIST_PROTOS(static, nat_filter, struct nat_filter);
struct nat_filter struct nat_filter
{ {
struct nat_filter *next, **prev; struct nat_filter *next, **prev;
int (*condition)(void const *message, size_t len); size_t (*condition)(void *message, size_t len);
}; };
/* nat entry point */ /* nat entry point */
...@@ -680,29 +680,35 @@ static int udp_in_to_out(struct nat *nat, su_wait_t *wait, struct binding *b) ...@@ -680,29 +680,35 @@ static int udp_in_to_out(struct nat *nat, su_wait_t *wait, struct binding *b)
{ {
int events; int events;
ssize_t n, m; ssize_t n, m;
size_t len, filtered;
struct nat_filter *f; struct nat_filter *f;
events = su_wait_events(wait, b->in_socket); events = su_wait_events(wait, b->in_socket);
n = su_recv(b->in_socket, nat->buffer, sizeof nat->buffer, 0); n = su_recv(b->in_socket, nat->buffer, sizeof nat->buffer, 0);
if (n < 0) { if (n == -1) {
su_perror("udp_in_to_out: recv"); su_perror("udp_in_to_out: recv");
return 0; return 0;
} }
len = (size_t)n;
for (f = nat->out_filters; f; f = f->next) { for (f = nat->out_filters; f; f = f->next) {
if (f->condition(nat->buffer, (size_t)n)) { filtered = f->condition(nat->buffer, len);
if (filtered != len) {
if (nat->logging) if (nat->logging)
printf("nat: udp filtered %d %s => %s\n", printf("nat: udp filtered "MOD_ZU" from %s => "MOD_ZU" to %s\n",
(int)n, b->in_name, b->out_name); len, b->in_name, filtered, b->out_name);
return 0; if (filtered == 0)
return 0;
len = filtered;
} }
} }
if (nat->symmetric) if (nat->symmetric)
m = su_send(b->out_socket, nat->buffer, n, 0); m = su_send(b->out_socket, nat->buffer, len, 0);
else else
m = su_sendto(b->out_socket, nat->buffer, n, 0, m = su_sendto(b->out_socket, nat->buffer, len, 0,
nat->out_address, nat->out_addrlen); nat->out_address, nat->out_addrlen);
if (nat->logging) if (nat->logging)
...@@ -716,6 +722,7 @@ static int udp_out_to_in(struct nat *nat, su_wait_t *wait, struct binding *b) ...@@ -716,6 +722,7 @@ static int udp_out_to_in(struct nat *nat, su_wait_t *wait, struct binding *b)
{ {
int events; int events;
ssize_t n, m; ssize_t n, m;
size_t len, filtered;
struct nat_filter *f; struct nat_filter *f;
events = su_wait_events(wait, b->out_socket); events = su_wait_events(wait, b->out_socket);
...@@ -726,12 +733,17 @@ static int udp_out_to_in(struct nat *nat, su_wait_t *wait, struct binding *b) ...@@ -726,12 +733,17 @@ static int udp_out_to_in(struct nat *nat, su_wait_t *wait, struct binding *b)
return 0; return 0;
} }
len = (size_t)n;
for (f = nat->in_filters; f; f = f->next) { for (f = nat->in_filters; f; f = f->next) {
if (f->condition(nat->buffer, (size_t)n)) { filtered = f->condition(nat->buffer, len);
if (filtered != len) {
if (nat->logging) if (nat->logging)
printf("nat: udp filtered %d %s => %s\n", printf("nat: udp filtered "MOD_ZU" from %s => "MOD_ZU" to %s\n",
(int)n, b->out_name, b->in_name); len, b->out_name, filtered, b->in_name);
return 0; if (filtered == 0)
return 0;
len = filtered;
} }
} }
...@@ -939,8 +951,8 @@ int execute_nat_filter_remove(void *_args) ...@@ -939,8 +951,8 @@ int execute_nat_filter_remove(void *_args)
} }
struct nat_filter *test_nat_add_filter(struct nat *nat, struct nat_filter *test_nat_add_filter(struct nat *nat,
int (*condition)(void const *message, size_t (*condition)(void *message,
size_t len), size_t len),
int outbound) int outbound)
{ {
struct args a[1]; struct args a[1];
......
...@@ -44,8 +44,8 @@ int test_nat_public(struct nat *nat, void const *address, int addrlen); ...@@ -44,8 +44,8 @@ int test_nat_public(struct nat *nat, void const *address, int addrlen);
int test_nat_flush(struct nat *nat); int test_nat_flush(struct nat *nat);
struct nat_filter *test_nat_add_filter(struct nat *nat, struct nat_filter *test_nat_add_filter(struct nat *nat,
int (*condition)(void const *message, size_t (*condition)(void *message,
size_t len), size_t len),
int outbound); int outbound);
enum { nat_inbound, nat_outbound }; enum { nat_inbound, nat_outbound };
......
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