Make p and b filters work on 3rd-party packets. Validate
3rd party packet header validation in tests, too.
This commit is contained in:
parent
b57c07f20c
commit
0a41e69a9f
39
src/filter.c
39
src/filter.c
|
|
@ -1680,7 +1680,22 @@ static int filter_process_one_b(struct client_t *c, struct pbuf_t *pb, struct fi
|
|||
memcpy( ref.callsign, pb->data, i);
|
||||
memset( ref.callsign+i, 0, sizeof(ref.callsign)-i );
|
||||
|
||||
return filter_match_on_callsignset(&ref, i, f, MatchWild);
|
||||
int r = filter_match_on_callsignset(&ref, i, f, MatchWild);
|
||||
|
||||
/* match 3rd-party packets based on their innermost srccall,
|
||||
* only works on non-object/item currently
|
||||
*/
|
||||
if (r == 0 && pb->srcname != pb->data && (pb->packettype & (T_OBJECT|T_ITEM)) == 0) {
|
||||
i = pb->srcname_len;
|
||||
if (i > CALLSIGNLEN_MAX) i = CALLSIGNLEN_MAX;
|
||||
|
||||
memcpy( ref.callsign, pb->srcname, i);
|
||||
memset( ref.callsign+i, 0, sizeof(ref.callsign)-i );
|
||||
|
||||
return filter_match_on_callsignset(&ref, i, f, MatchWild);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int filter_process_one_d(struct client_t *c, struct pbuf_t *pb, struct filter_t *f)
|
||||
|
|
@ -1978,10 +1993,10 @@ static int filter_process_one_o(struct client_t *c, struct pbuf_t *pb, struct fi
|
|||
|
||||
/* parse_aprs() has picked item/object name pointer and length.. */
|
||||
i = pb->srcname_len;
|
||||
if (i < 1) return 0; /* Bad object/item name */
|
||||
if (i < 1 || i > CALLSIGNLEN_MAX) return 0; /* Bad object/item name */
|
||||
|
||||
/* object name */
|
||||
memcpy( ref.callsign, pb->info_start+1, i);
|
||||
memcpy( ref.callsign, pb->srcname, i);
|
||||
memset( ref.callsign+i, 0, sizeof(ref.callsign)-i );
|
||||
|
||||
return filter_match_on_callsignset(&ref, i, f, MatchWild);
|
||||
|
|
@ -2008,7 +2023,23 @@ static int filter_process_one_p(struct client_t *c, struct pbuf_t *pb, struct fi
|
|||
memcpy( ref.callsign, pb->data, i);
|
||||
memset( ref.callsign+i, 0, sizeof(ref.callsign)-i );
|
||||
|
||||
return filter_match_on_callsignset(&ref, i, f, MatchPrefix);
|
||||
int r = filter_match_on_callsignset(&ref, i, f, MatchPrefix);
|
||||
|
||||
/* match 3rd-party packets based on their innermost srccall,
|
||||
* only works on non-object/item currently
|
||||
*/
|
||||
if (r == 0 && pb->srcname != pb->data && (pb->packettype & (T_OBJECT|T_ITEM)) == 0) {
|
||||
i = pb->srcname_len;
|
||||
|
||||
if (i > CALLSIGNLEN_MAX) i = CALLSIGNLEN_MAX;
|
||||
|
||||
memcpy( ref.callsign, pb->srcname, i);
|
||||
memset( ref.callsign+i, 0, sizeof(ref.callsign)-i );
|
||||
|
||||
return filter_match_on_callsignset(&ref, i, f, MatchPrefix);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int filter_process_one_q(struct client_t *c, struct pbuf_t *pb, struct filter_t *f)
|
||||
|
|
|
|||
|
|
@ -1040,7 +1040,12 @@ static int parse_aprs_3rdparty(struct pbuf_t *pb, const char *info_start)
|
|||
if (check_path_calls(dstcall_end, body) != 2)
|
||||
return INERR_INV_3RD_PARTY;
|
||||
|
||||
/* TODO: validate 3rd-party packet header */
|
||||
/* Ok, fill "name" parameter in packet with the 3rd-party packet
|
||||
* srccall, so that filtering can match against it. This will be
|
||||
* overwritten by object/item names.
|
||||
*/
|
||||
pb->srcname = s;
|
||||
pb->srcname_len = src_end - s;
|
||||
|
||||
/* for now, just parse the inner packet content to learn it's type
|
||||
* and coordinates, etc
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#
|
||||
|
||||
use Test;
|
||||
BEGIN { plan tests => 6 + 3 + 3 };
|
||||
BEGIN { plan tests => 6 + 8 + 3 };
|
||||
use runproduct;
|
||||
use istest;
|
||||
use Ham::APRS::IS;
|
||||
|
|
@ -22,7 +22,7 @@ ok(defined $i_tx, 1, "Failed to initialize Ham::APRS::IS");
|
|||
# third for mic-e, fourth for prefix filter test.
|
||||
# The first and last one also test upper-case letters as filter keys.
|
||||
my $i_rx = new Ham::APRS::IS("localhost:55581", "N5CAL-2",
|
||||
'filter' => 'r/60.228/24.8495/5 p/OG p/OI');
|
||||
'filter' => 'r/60.228/24.8495/5 p/OG p/OI p/K2 b/BB7LZB');
|
||||
ok(defined $i_rx, 1, "Failed to initialize Ham::APRS::IS");
|
||||
|
||||
my $ret;
|
||||
|
|
@ -38,6 +38,10 @@ ok($ret, 1, "Failed to connect to the server: " . $i_rx->{'error'});
|
|||
$tx = $rx = "UU0AA>TEST,qAR,IGATE:}OG7LZB>DST,NET,GATE*:>should pass 3rd party inner prefix";
|
||||
istest::txrx(\&ok, $i_tx, $i_rx, $tx, $rx);
|
||||
|
||||
# check that 3rd party packet matches a B filter
|
||||
$tx = $rx = "UU0AA>TEST,qAR,IGATE:}BB7LZB>DST,NET,GATE*:>should pass 3rd party inner prefix with b filter";
|
||||
istest::txrx(\&ok, $i_tx, $i_rx, $tx, $rx);
|
||||
|
||||
# check that 3rd party packet matches a P filter
|
||||
$tx = $rx = "OI0AA>TEST,qAR,IGATE:}ZZ7LZB>DST,NET,GATE*:>should pass 3rd party outer prefix";
|
||||
istest::txrx(\&ok, $i_tx, $i_rx, $tx, $rx);
|
||||
|
|
@ -46,6 +50,23 @@ istest::txrx(\&ok, $i_tx, $i_rx, $tx, $rx);
|
|||
$tx = $rx = "UU1AA>TEST,qAR,IGATE:}OF7LZB>DST,NET,GATE:!6013.69NR02450.97E&";
|
||||
istest::txrx(\&ok, $i_tx, $i_rx, $tx, $rx);
|
||||
|
||||
# check that a nested 3rd party packet matches a coordinate filter
|
||||
$tx = $rx = "UU1AA>TEST,qAR,IGATE:}OF7LZB>DST,NET,GATE:}OF7LZC>DST,NET2,GATE2:!6013.69NR02450.97E&";
|
||||
istest::txrx(\&ok, $i_tx, $i_rx, $tx, $rx);
|
||||
|
||||
# check that a really nested 3rd party packet matches a coordinate filter
|
||||
$tx = $rx = "UU1AA>TEST,qAR,IGATE:}OF7LZB>DST,NET,GATE:}OF7LZC>DST,NET2,GATE2:}OF7LZD>DST,NET2,GATE2:}OF7LZE>DST,NET2,GATE2:!6013.69NR02450.97E&";
|
||||
istest::txrx(\&ok, $i_tx, $i_rx, $tx, $rx);
|
||||
|
||||
# Invalid 3rd-party header, does not have 2 hops
|
||||
$tx = "KG4LAA>APWW08,TCPIP*,qAS,n3wax:}KB3ONM>APK102,KV3B-1,WIDE1,WIDE2,KV3B-1,WIDE1,KG4LAA*::N3HEV-9 :ack26";
|
||||
$helper = "K2SRC>APRS,qAR,$login:>should pass 1";
|
||||
istest::should_drop(\&ok, $i_tx, $i_rx, $tx, $helper);
|
||||
|
||||
# Invalid 3rd-party header, does not have 2 hops
|
||||
$tx = "KG4LAA>APWW08,TCPIP*,qAS,n3wax:}KB3ONM>APK102,KV3B-1::N3HEV-9 :ack26";
|
||||
$helper = "K2SRC>APRS,qAR,$login:>should pass 2";
|
||||
istest::should_drop(\&ok, $i_tx, $i_rx, $tx, $helper);
|
||||
|
||||
# disconnect #################################
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue