Skip to content

Commit 127435b

Browse files
committed
Have "outbound" mean Tx only for DLT_SLIP.
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.
1 parent 66941d5 commit 127435b

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
4949
Fix the != comparison for ATM and MTP field values.
5050
Deprecate bpf_filter().
5151
Require a live capture for all Linux BPF extensions.
52+
Have "outbound" mean Tx only for DLT_SLIP.
5253
rpcap:
5354
Support user names and passwords in rpcap:// and rpcaps:// URLs.
5455
Add a -t flag to rpcapd to specify the data channel port; from

gencode.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8763,9 +8763,7 @@ gen_inbound_outbound(compiler_state_t *cstate, const int outbound)
87638763
*/
87648764
switch (cstate->linktype) {
87658765
case DLT_SLIP:
8766-
b0 = gen_relation_internal(cstate, BPF_JEQ,
8767-
gen_load_internal(cstate, Q_LINK, gen_loadi_internal(cstate, 0), 1),
8768-
gen_loadi_internal(cstate, 0),
8766+
b0 = gen_cmp(cstate, OR_LINKHDR, 0, BPF_B,
87698767
outbound ? SLIPDIR_OUT : SLIPDIR_IN);
87708768
break;
87718769

testprogs/TESTrun

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ my %accept_blocks = (
621621
DLT => 'SLIP',
622622
snaplen => 100,
623623
aliases => ['inbound'],
624-
opt => '
624+
unopt => '
625625
(000) ldb [0]
626626
(001) jeq #0x0 jt 2 jf 3
627627
(002) ret #100
@@ -632,11 +632,11 @@ my %accept_blocks = (
632632
DLT => 'SLIP',
633633
snaplen => 100,
634634
aliases => ['outbound'],
635-
opt => '
635+
unopt => '
636636
(000) ldb [0]
637-
(001) jeq #0x0 jt 2 jf 3
638-
(002) ret #0
639-
(003) ret #100
637+
(001) jeq #0x1 jt 2 jf 3
638+
(002) ret #100
639+
(003) ret #0
640640
',
641641
}, # slip_outbound
642642
ipnet_inbound => {
@@ -10045,7 +10045,7 @@ my %apply_blocks = (
1004510045
slip_outbound_on_invalid => {
1004610046
savefile => 'slip-bad-direction.pcap',
1004710047
expr => 'outbound',
10048-
results => [262144],
10048+
results => [0],
1004910049
},
1005010050
slip_inbound_on_rx => {
1005110051
savefile => 'slip-compressed_sl_print-oobr.pcap',

0 commit comments

Comments
 (0)