Page MenuHomeFreeBSD

D61676.1795025555.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D61676.1795025555.diff

diff --git a/sys/netinet/ip_fastfwd.c b/sys/netinet/ip_fastfwd.c
--- a/sys/netinet/ip_fastfwd.c
+++ b/sys/netinet/ip_fastfwd.c
@@ -408,6 +408,7 @@
if (!PFIL_HOOKED_OUT(V_inet_pfil_head))
goto passout;
+ odest.s_addr = ip->ip_dst.s_addr;
if (pfil_mbuf_fwd(V_inet_pfil_head, &m, nh->nh_ifp,
NULL) != PFIL_PASS)
goto drop;
@@ -416,16 +417,18 @@
M_ASSERTPKTHDR(m);
ip = mtod(m, struct ip *);
- dest.s_addr = ip->ip_dst.s_addr;
/*
- * Destination address changed?
+ * Destination address changed? If not, dest stays what the route
+ * was looked up for, which is the next hop an inbound hook chose
+ * rather than the packet's destination.
*/
if (m->m_flags & M_IP_NEXTHOP)
fwd_tag = m_tag_find(m, PACKET_TAG_IPFORWARD, NULL);
else
fwd_tag = NULL;
- if (odest.s_addr != dest.s_addr || fwd_tag != NULL) {
+ if (odest.s_addr != ip->ip_dst.s_addr || fwd_tag != NULL) {
+ dest.s_addr = ip->ip_dst.s_addr;
/*
* Is it now for a local address on this host?
*/
diff --git a/tests/sys/netpfil/ipfw/fwd.sh b/tests/sys/netpfil/ipfw/fwd.sh
--- a/tests/sys/netpfil/ipfw/fwd.sh
+++ b/tests/sys/netpfil/ipfw/fwd.sh
@@ -124,8 +124,60 @@
firewall_cleanup $1
}
+atf_test_case "nexthop_v4" "cleanup"
+nexthop_v4_head()
+{
+ atf_set descr 'Test that an inbound IPv4 fwd rule chooses the next hop'
+ atf_set require.user root
+}
+
+nexthop_v4_body()
+{
+ firewall_init "ipfw"
+
+ epair_c=$(vnet_mkepair)
+ epair_1=$(vnet_mkepair)
+ epair_2=$(vnet_mkepair)
+
+ vnet_mkjail rtr ${epair_c}b ${epair_1}a ${epair_2}a
+ vnet_mkjail srv1 ${epair_1}b
+ vnet_mkjail srv2 ${epair_2}b
+
+ atf_check ifconfig ${epair_c}a 192.0.2.2/30 up
+ atf_check -o ignore route add 198.51.100.0/24 192.0.2.1
+
+ atf_check jexec rtr ifconfig ${epair_c}b 192.0.2.1/30 up
+ atf_check jexec rtr ifconfig ${epair_1}a 192.0.2.5/30 up
+ atf_check jexec rtr ifconfig ${epair_2}a 192.0.2.9/30 up
+ atf_check -o ignore jexec rtr sysctl net.inet.ip.forwarding=1
+ atf_check -o ignore jexec rtr route add 198.51.100.0/24 192.0.2.6
+
+ # 198.51.100.1 lives on srv2, but the route points to srv1.
+ atf_check jexec srv1 ifconfig ${epair_1}b 192.0.2.6/30 up
+ atf_check jexec srv2 ifconfig ${epair_2}b 192.0.2.10/30 up
+ atf_check jexec srv2 ifconfig lo0 198.51.100.1/32 up
+ atf_check -o ignore jexec srv2 route add default 192.0.2.9
+
+ firewall_config rtr ipfw ipfw \
+ "ipfw add 20 allow all from any to any"
+ atf_check -s exit:2 -o ignore ping -c 1 -t 1 198.51.100.1
+
+ # The next hop is on a connected network, so the router has to
+ # resolve its address and not the packet's destination.
+ firewall_config rtr ipfw ipfw \
+ "ipfw add 10 fwd 192.0.2.10 ip4 from any to 198.51.100.1 in via ${epair_c}b" \
+ "ipfw add 20 allow all from any to any"
+ atf_check -o ignore ping -c 1 -t 1 198.51.100.1
+}
+
+nexthop_v4_cleanup()
+{
+ firewall_cleanup $1
+}
+
atf_init_test_cases()
{
atf_add_test_case "local"
atf_add_test_case "nexthop_v6"
+ atf_add_test_case "nexthop_v4"
}

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 18, 6:12 PM (23 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41829898
Default Alt Text
D61676.1795025555.diff (2 KB)

Event Timeline