In DLT_SLIP packet direction is the first and the only byte of the
link-layer header, so it ought to be trivial to test, which the
optimized filter program seems to implement:
$ ./testprogs/filtertest SLIP outbound
(000) ldb [0]
(001) jeq #0x0 jt 2 jf 3
(002) ret #0
(003) ret #262144
However, the C code in gen_inbound_outbound() looks more complicated
than the above requires: since libpcap 0.0 (June 1994) it has been a
combination of four functions, and the unoptimized filter program it
produces looks more complicated than it needs to be:
$ ./testprogs/filtertest -O SLIP outbound
(000) ld #0x0
(001) st M[1]
(002) ldx M[1]
(003) ldb [x + 0]
(004) st M[2]
(005) ld #0x0
(006) st M[0]
(007) ldx M[0]
(008) ld M[2]
(009) sub x
(010) jeq #0x0 jt 11 jf 12
(011) ret #0
(012) ret #262144
The C code means loading 1 byte from offset 0 of the link-layer header,
testing it to be equal to 0 and reversing the result if testing for
"outbound". The test for "inbound" correctly matches direction value 0
(received packets). The test for "outbound" matches direction value 1
(transmitted packets), as well as any other non-zero direction value,
which is invalid in DLT_SLIP.
Replace the custom code with gen_cmp() consistently with the other cases
in the same switch block. This makes the unoptimized and the optimized
filter programs identical, also fixes "outbound" to match Tx packets
only. Update the affected filter tests to reflect these developments.
Fix the != comparison for ATM and MTP field values.
Deprecate bpf_filter().
Require a live capture for all Linux BPF extensions.
+ Have "outbound" mean Tx only for DLT_SLIP.
rpcap:
Support user names and passwords in rpcap:// and rpcaps:// URLs.
Add a -t flag to rpcapd to specify the data channel port; from
*/
switch (cstate->linktype) {
case DLT_SLIP:
- b0 = gen_relation_internal(cstate, BPF_JEQ,
- gen_load_internal(cstate, Q_LINK, gen_loadi_internal(cstate, 0), 1),
- gen_loadi_internal(cstate, 0),
+ b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B,
outbound ? SLIPDIR_OUT : SLIPDIR_IN);
break;
DLT => 'SLIP',
snaplen => 100,
aliases => ['inbound'],
- opt => '
+ unopt => '
(000) ldb [0]
(001) jeq #0x0 jt 2 jf 3
(002) ret #100
DLT => 'SLIP',
snaplen => 100,
aliases => ['outbound'],
- opt => '
+ unopt => '
(000) ldb [0]
- (001) jeq #0x0 jt 2 jf 3
- (002) ret #0
- (003) ret #100
+ (001) jeq #0x1 jt 2 jf 3
+ (002) ret #100
+ (003) ret #0
',
}, # slip_outbound
ipnet_inbound => {
slip_outbound_on_invalid => {
savefile => 'slip-bad-direction.pcap',
expr => 'outbound',
- results => [262144],
+ results => [0],
},
slip_inbound_on_rx => {
savefile => 'slip-compressed_sl_print-oobr.pcap',