Bug 231143 - [regression] ipfw fwd wrong behaviour with fast forwarding
Summary: [regression] ipfw fwd wrong behaviour with fast forwarding
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 11.2-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Eugene Grosbein
URL:
Keywords: patch, regression
Depends on:
Blocks:
 
Reported: 2018-09-04 06:24 UTC by Runer
Modified: 2018-09-19 03:43 UTC (History)
3 users (show)

See Also:
koobs: mfc-stable11+


Attachments
proposed fix (2.77 KB, patch)
2018-09-04 12:26 UTC, Eugene Grosbein
no flags Details | Diff
proposed fix (2.81 KB, patch)
2018-09-04 12:30 UTC, Eugene Grosbein
no flags Details | Diff
proposed fix (1.74 KB, patch)
2018-09-04 15:09 UTC, Eugene Grosbein
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Runer 2018-09-04 06:24:53 UTC
A situation has arisen in which ipfw fwd stops working when 
RTF_BLACKHOLE or RTF_REJECT, ROUTE (8), is enabled on 
Freebsd 11 release.

 FreeBSD 11.2-RELEASE-p1
route add default 127.0.0.1 -blackhole –iface
ipfw show
00100 30 4056 fwd 10.0.0.5 ip from table(1) to not 10.0.0.0/8 in via em0

 The packet counter changes, but forwarding does not work.
On FreeBSD 10 everything works fine.

 I suppose this is due to changes to forwarding -> fast forwarding by 
default in FreeBSD 11 and man ROUTE (8), “BUGS - unless IP fast forwarding is enabled, in which case the meaning of the flag will always be honored.”
Comment 1 Eugene Grosbein freebsd_committer freebsd_triage 2018-09-04 07:52:21 UTC
Do you use GENERIC kernel?
Comment 2 Eugene Grosbein freebsd_committer freebsd_triage 2018-09-04 12:26:36 UTC
Created attachment 196851 [details]
proposed fix

Please test the patch fixing the problem: fetch it, run "cd /usr/src && patch < /path/to/patch", rebuild and reinstall the kernel, reboot and re-test. It should just work.
Comment 3 Eugene Grosbein freebsd_committer freebsd_triage 2018-09-04 12:30:25 UTC
Created attachment 196852 [details]
proposed fix

re-add same patch with proper paths added
Comment 4 Eugene Grosbein freebsd_committer freebsd_triage 2018-09-04 15:09:28 UTC
Created attachment 196860 [details]
proposed fix

More correct version of the patch following current mode of packet filtering operation that does not skip second pass over filters if "ipfw fwd" matched incoming packet.
Comment 5 Runer 2018-09-04 19:45:10 UTC
(In reply to Eugene Grosbein from comment #4)
Excellent! This patch works for Me.

cd /usr/src && patch < /path/to/patch
|Index: sys/netinet/ip_fastfwd.c
|===================================================================
|--- sys/netinet/ip_fastfwd.c   (revision 338011)
|+++ sys/netinet/ip_fastfwd.c   (working copy)
--------------------------
Patching file sys/netinet/ip_fastfwd.c using Plan A...
Hunk #1 succeeded at 151.
Hunk #2 succeeded at 292.
Hunk #3 succeeded at 312.
Hunk #4 succeeded at 338.
Hunk #5 succeeded at 361.

route add default 127.0.0.1 -blackhole -iface
Internet:
Destination        Gateway            Flags     Netif Expire
default            127.0.0.1          USB         lo0

traffic from the address from table(1) is forwarded.
ipfw show
00100 139 9466 fwd 10.0.0.5 ip from table(1) to not 10.0.0.0/8 in via vtnet0

icmp not from table(1) address, is silently dropped (-blackhole)

Many thanks! Great work! Good luck to you!
Comment 6 commit-hook freebsd_committer freebsd_triage 2018-09-05 14:00:17 UTC
A commit references this bug:

Author: eugen
Date: Wed Sep  5 13:59:36 UTC 2018
New revision: 338468
URL: https://svnweb.freebsd.org/changeset/base/338468

Log:
  Fix "ipfw fwd" to work for incoming IPv4 packets when ip_tryforward() chooses
  fast forwarding path, as it already works for IPv6 and for both of them
  on old slow path.

  PR:			231143
  Reviewed by:		ae
  Approved by:		re (gjb)
  MFC after:		1 week
  Differential Revision:	https://reviews.freebsd.org/D17039

Changes:
  head/sys/netinet/ip_fastfwd.c
Comment 7 commit-hook freebsd_committer freebsd_triage 2018-09-12 08:47:19 UTC
A commit references this bug:

Author: eugen
Date: Wed Sep 12 08:46:50 UTC 2018
New revision: 338611
URL: https://svnweb.freebsd.org/changeset/base/338611

Log:
  MFC r338468: Fix "ipfw fwd" to work for incoming IPv4 packets
  when ip_tryforward() chooses fast forwarding path, as it already works
  for IPv6 and for both of them on old slow path.

  PR:			231143
  Reviewed by:		ae
  Differential Revision:	https://reviews.freebsd.org/D17039

Changes:
_U  stable/11/
  stable/11/sys/netinet/ip_fastfwd.c
Comment 8 Eugene Grosbein freebsd_committer freebsd_triage 2018-09-12 08:57:26 UTC
Committed and merged, thanks for testing.

The fix will be present in upcoming 12.0-RELEASE and 11.3-RELEASE.
Comment 9 Andrey V. Elsukov freebsd_committer freebsd_triage 2018-09-12 09:23:22 UTC
It seems the fix can be applied to stable/10 too. Probably with small modification.
Comment 10 Eugene Grosbein freebsd_committer freebsd_triage 2018-09-12 09:37:36 UTC
(In reply to Andrey V. Elsukov from comment #9)

ip_tryforward() does not exist in 10.x but it has sysctl net.inet.ip.fastforwarding with default value 0 corresponding to slow path, so it is not affected in default configuration.

The change does not apply cleanly to 10.x and I saw no requests to fix fastforwarding for 10.x and ENOTIME. Feel free to patch stable/10, if you wish.