All of lore.kernel.org
 help / color / mirror / Atom feed
* ebtables and iptables different behavior between 2.6.18 on fc6 and 2.6.23 on fc8
@ 2008-03-25  1:18 Greg Scott
  2008-03-25  2:28 ` Jan Engelhardt
  0 siblings, 1 reply; 25+ messages in thread
From: Greg Scott @ 2008-03-25  1:18 UTC (permalink / raw)
  To: netfilter-devel

This issue cost me most of a night's sleep and it will take me a few
paragraphs to describe.  The one sentence summary is, marking packets
with ebtables and reading later with iptables seems to behave
differently with 2.6.23 than it did with 2.6.18 and earlier.  

I put together a firewall system based on fc8 and the RedHat kernel that
ships with fc8.  I think this one is 2.6.23-2.  My previous latest and
greatest was with a 2.6.18 variant that shipped with fc6.  

This config requires that I bridge.  I need to bridge because I have
various H.323 videoconference codecs behind the firewall system and some
of these, especially older ones, do not work very well with NAT.  The
other choice besides bridging is proxy ARP, but I learned the hard way
that proxy ARP is horrible in colocation situations.  So I need to
bridge.  

But I also need NAT to handle traditional PCs and other stuff behind the
firewall.  

To make this work, I need to know which way packets are headed.  I need
to know on which interface packets come in, and which interface they go
out.  This is easy with routing, more challenging with bridging.
iptables had a facility that would let me test --physdev with bridged
packets.  It might still be there but I remember reading a discussion
about how this violated layering and would not be supported long term.  

So I found another way.  Ebtables lets me mark packets based on the
physical interface in or out.  In the broute table of ebtables, I can
mark packets in from the Internet with "1", and packets in from the LAN
side with "2".  I also need to know the interface on which packets go
out, so I mark those with "3" in the FORWARD and OUTPUT chains of the
filter table.  

And then later on, I can test the marks with iptables and take
appropriate actions depending on the direction of packet travel.  

Here is the ebtables code to do that, extracted from a very long
rc.firewall script - hopefully this won't be garbled in this post.  


echo "Flushing and zeroing all ebtables tables and chains"
$EBTABLES -t broute -F
$EBTABLES -t broute -Z
$EBTABLES -t filter -F
$EBTABLES -t filter -Z
$EBTABLES -t nat -F
$EBTABLES -t nat -Z

#
# Use ebtables to mark packets based on the in/out interface.
# 1 - (bit 0 set) for packets entering on the Internet physical
interface
# 2 - (bit 1 set) for packets entering on the trusted physical interface
# 3 - (bits 0 and 1) for packets exiting via the Internet physical
interface

echo "Marking bridged packets at layer 2 for later layer 3 filtering."
$EBTABLES -t broute -A BROUTING -i $INET_IFACE \
	-j mark --mark-set 1 --mark-target CONTINUE
$EBTABLES -t broute -A BROUTING -i $TRUSTED1_IFACE \
	-j mark --mark-set 2 --mark-target CONTINUE
$EBTABLES -t filter -A FORWARD -o $INET_IFACE \
	-j mark --mark-set 3 --mark-target CONTINUE
$EBTABLES -t filter -A OUTPUT -o $INET_IFACE \
	-j mark --mark-set 3 --mark-target CONTINUE


With that background, here is the problem.

None of my packets that were supposed to have that "3" mark ever kept
them.  For some reason, they either never were marked or they were
marked and then the mark disappeared.  The packets with "1" and "2"
worked just fine.  I set up tons of logging to chase that down.  But the
packets with "3" were not marked.  

Needless to say, this created major havoc with my network routing.  The
good news is, it only kept me up all night and none of the users at this
site ever knew anything was messed up.  

I built two nearly identical systems.  One with fc6, the other with fc8.
I set them up with the exact same IP Addresses and identical copies of
my rc.firewall script.  The only difference between them were various
logging and debug lines I inserted into my rc.firewall script at
different times to chase down the marking.  The fc6 system worked as I
expected, the fc8 system did not.

And now I can reproduce the problem here under controlled conditions.  

So my questions - what changed with the interaction betweem iptables and
ebtables?  Is there a supported way I can track the physical interfaces
on which packets come in and go out that I can count on for the
indefinite future?  Or did I uncover an obscure bug with
ebtables/iptables?  

I have test systems and a simulated environment right here so I can try
different kernel combinations if needed.  

Thanks

- Greg Scott

^ permalink raw reply	[flat|nested] 25+ messages in thread
* RE: Ebtables hook order anomaly
@ 2008-03-25 13:32 Greg Scott
  2008-03-25 13:49 ` Patrick McHardy
  0 siblings, 1 reply; 25+ messages in thread
From: Greg Scott @ 2008-03-25 13:32 UTC (permalink / raw)
  To: Patrick McHardy, Jan Engelhardt; +Cc: Netfilter Developer Mailing List

> Indeed, on output bridge netfilter will run after IPv4 netfilter.
> Does that explain things?

Well, not really.  2.6.23-2 behaves differently than 2.6.18.  My
ebtables marks get set and read by iptables in 2.6.18.  iptables does
not see them in 2.6.23.

It could be something in the order of execution changed.  I'm using
RedHat kernels right now and I know they tweak the kernels a little bit.
But surely the RedHat guys would not change something this fundamental?


I set my ebtables mark for outbound packets in two places - in the
OUTPUT chain and the FORWARD chain.  I was looking mostly at the
ebtables FORWARD chain for packets that pass thru the box.  I set the
mark in ebtables FORWARD and OUTPUT.  Iptables POSTROUTING needs to see
them so it knows to MASQUERADE.  Otherwise, things get really weird.  :)
iptables sees the marks in 2.6.18, but does not see them in 2.6.23.  

I have a couple of 2.6.23 systems here and I can brew up a 2.6.18 fc6
system later on for testing if needed.  (All the 2.6.18 stuff I have
built up right now is in production.)  I can set up some tests similarly
to Jan's testing from last night for packets passing through the box.  

Or if there's a better way to do this, I'm open.  

- Greg

^ permalink raw reply	[flat|nested] 25+ messages in thread
* RE: Ebtables hook order anomaly
@ 2008-03-25 14:17 Greg Scott
  0 siblings, 0 replies; 25+ messages in thread
From: Greg Scott @ 2008-03-25 14:17 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: Jan Engelhardt, Netfilter Developer Mailing List

> For routed packets you can't make any decisions in iptables based on 
> the outgoing bridge port, thats only possible for purely bridged 
> traffic.

Bummer - but at least I now know the rules.  I guess I'll test using
source IP Address.  That kind of works - I know what stuff is on either
side - but it's messy.  

Thanks

- GReg

^ permalink raw reply	[flat|nested] 25+ messages in thread
* RE: Ebtables hook order anomaly
@ 2008-03-25 17:02 Greg Scott
  2008-03-26  7:16 ` Patrick McHardy
  0 siblings, 1 reply; 25+ messages in thread
From: Greg Scott @ 2008-03-25 17:02 UTC (permalink / raw)
  To: Patrick McHardy, Jan Engelhardt; +Cc: Netfilter Developer Mailing List

> Thats indeed inconsistent. I don't believe this has changed however, 
> the IPv4 POSTROUTING hook was always called from the bridge 
> POSTROUTING hook (with similar priorities).

Well, OK - so I guess the most important question now is, are there any
other behavior changes of this nature coming up so I can get ready for
them in advance?  I'm kind of hoping for no more rude midnight
surprises.  :)

Thanks

- Greg

^ permalink raw reply	[flat|nested] 25+ messages in thread
* RE: Ebtables hook order anomaly
@ 2008-03-27  7:55 Greg Scott
  0 siblings, 0 replies; 25+ messages in thread
From: Greg Scott @ 2008-03-27  7:55 UTC (permalink / raw)
  To: Patrick McHardy, Jan Engelhardt; +Cc: Netfilter Developer Mailing List

>>> and POSTROUTING hook until the outgoing bridge port was determined
by 
>>> the bridge code. This "feature" was removed because it broke all 
>>> kinds of things, now the order matches the layering and IPv4 hooks 
>>> are always processed entirely before bridging.
>> 
>> Now the order is .. non-consistent.
>> On a pure bridge forward (-i br -o br), as I have determined, 
>> ebtables-nat-POSTROUTING comes _before_ the IPv4 hooks.
>
> Thats indeed inconsistent. I don't believe this has changed however, 
> the IPv4 POSTROUTING hook was always called from the bridge
POSTROUTING 
> hook (with similar priorities).

This woke me up in the middle of the night - I also mark packets in
ebtables BROUTE based on the incoming interface and then test all over
the place in iptables based on that mark.  One of the most important is
a test for -s {private IP Address} coming in from the Internet.  But
there are lots of other tests based on source IP and incoming interface.
I really really really need to know the incoming interface.  

This still seems to work - ebtables BROUTE still seems to come before
iptables NAT PREROUTING and my ebtables BROUTE marks all show up in
iptables.  Am I on solid ground for the future if I keep this up?

Thanks

- Greg

^ permalink raw reply	[flat|nested] 25+ messages in thread
* RE: Ebtables hook order anomaly
@ 2008-03-30 21:21 Greg Scott
  0 siblings, 0 replies; 25+ messages in thread
From: Greg Scott @ 2008-03-30 21:21 UTC (permalink / raw)
  To: Patrick McHardy, Jan Engelhardt; +Cc: Netfilter Developer Mailing List

> This still seems to work - ebtables BROUTE still seems to come 
> before iptables NAT PREROUTING and my ebtables BROUTE marks all 
> show up in iptables.  Am I on solid ground for the future if I 
> keep this up?

So can I count on this working for the long term?

ie - Can I mark packets in ebtables-BROUTE based on the in-interface and
then read the mark later on in iptables?  (I already know I can't do
this any more for the out-interface.)

Thanks

- Greg

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2008-04-09 16:18 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-25  1:18 ebtables and iptables different behavior between 2.6.18 on fc6 and 2.6.23 on fc8 Greg Scott
2008-03-25  2:28 ` Jan Engelhardt
2008-03-25  6:48   ` Ebtables hook order anomaly (was: ebtables and iptables different behavior between 2.6.18 on fc6 and 2.6.23 on fc8) Jan Engelhardt
2008-03-25 12:57     ` Ebtables hook order anomaly Patrick McHardy
2008-04-09 14:07       ` Jan Engelhardt
2008-04-09 14:36         ` Patrick McHardy
2008-04-09 14:54           ` Jan Engelhardt
2008-04-09 15:04             ` Patrick McHardy
2008-04-09 15:12               ` Greg Scott
2008-04-09 16:11               ` Jan Engelhardt
2008-04-09 16:18                 ` Greg Scott
2008-04-09 15:05             ` Greg Scott
2008-04-09 15:11               ` Patrick McHardy
2008-04-09 15:21                 ` Greg Scott
2008-04-09 15:23                   ` Patrick McHardy
2008-04-09 15:39                     ` Greg Scott
  -- strict thread matches above, loose matches on Subject: below --
2008-03-25 13:32 Greg Scott
2008-03-25 13:49 ` Patrick McHardy
2008-03-25 15:22   ` Jan Engelhardt
2008-03-25 15:30     ` Patrick McHardy
2008-03-25 14:17 Greg Scott
2008-03-25 17:02 Greg Scott
2008-03-26  7:16 ` Patrick McHardy
2008-03-27  7:55 Greg Scott
2008-03-30 21:21 Greg Scott

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.