Skip to contentSkip to conversation

mac match and FORWARD chain

DISCUSSION Bo Yang 5 participants 10 messages Oct 23, 2006 – Oct 24, 2006 5 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Bo Yang

author
#1 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Wakko Warner :

Quoted 8 lines

Keep me in CC.

I'd like to request that the mac match not be allowed in the FORWARD chain as it does not function the way that some may think.

The tests I've performed indicate that the match will match the MAC address of the transmitting interface (not what one would expect if attempting to allow based on the mac address of the sender and blocking all other

packets)

Quoted 6 lines

I'd like to hear comments about this. If it is not fesable to do this, I'd recommend adding text to the man page so that others do not fall into the same problem I did.

I have already worked around this problem in my setup.

MAC address is some concept in the link layer , so how do you get the packet sender mac if the packet is routed to your box through some other routers ?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFPB8L7tZp58UCwyMRAthwAKDXi4s4YznMzB58lEAYcn/QD5cHrACgo6/I KvAaZB7hBiqKaJt7AE4duxs=
=znkf
-----END PGP SIGNATURE-----

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 8 lines · Bo Yang
Quoted 6 lines

I'd like to request that the mac match not be allowed in the FORWARD chain as it does not function the way that some may think.

The tests I've performed indicate that the match will match the MAC address of the transmitting interface (not what one would expect if attempting to allow based on the mac address of the sender and blocking all other

packets)

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

I'd like to hear comments about this. If it is not fesable to do this, I'd recommend adding text to the man page so that others do not fall into the same problem I did.

I have already worked around this problem in my setup.

MAC address is some concept in the link layer , so how do you get the packet sender mac if the packet is routed to your box through some other routers ?

I understand. However, the machine I was using for this was directly connected to both system. There were no other routers.

Take this for instance:

Box A -> (eth1)firewall/router(eth0) -> Box B

firewall/router does not trust eth1 and uses MAC addresses to allow access, so it does this:
-I FORWARD -j ACCEPT -i eth1 -m mac --mac BOXAMAC
-I FORWARD -j DROP -i eth1

firewall/router knows the mac of both box a and b (obviously, box a doesn't know box b's mac and vice versa). Consider the above the only rules in the firewall and box A and B have no rules at all.

Box A pings Box B and fails. The reason is the mac test above is seeing the MAC of eth0, not of Box A.

This is what I'm referring to and I had to add a MARK rule in PREROUTING to mark packets that I want to allow and then allow in the forward chain based upon the mark.

Signature · 2 lines
 Lab tests show that use of micro$oft causes cancer in lab animals
 Got Gas???
#4 lore raw

Hello,

Review

Quoted 7 lines · Wakko Warner

Box A -> (eth1)firewall/router(eth0) -> Box B

firewall/router does not trust eth1 and uses MAC addresses to allow access, so it does this:

(quoted diff) +0 -2
-I FORWARD -j ACCEPT -i eth1 -m mac --mac BOXAMAC
-I FORWARD -j DROP -i eth1

If the firewall does not trust what is beyond eth1, MAC filtering is pointless : a MAC address can be easily sniffed and spoofed.

Quoted 6 lines

firewall/router knows the mac of both box a and b (obviously, box a doesn't know box b's mac and vice versa). Consider the above the only rules in the firewall and box A and B have no rules at all.

Box A pings Box B and fails. The reason is the mac test above is seeing the MAC of eth0, not of Box A.

There must be a bug in your specific setup/kernel/iptables/whatever. On my box, the FORWARD chain sees the correct MAC source address. Besides, I don't see how iptables could see the outgoing MAC source address which AFAIK is added at the link layer, after the packet has leaved Netfilter.

Quoted 3 lines

This is what I'm referring to and I had to add a MARK rule in PREROUTING to mark packets that I want to allow and then allow in the forward chain based upon the mark.

About your idea of doing this in the nat table PREROUTING chain : it won't work because the nat chains see only the initial packet of a connection.

*Don't you ever use the nat table chains for anything else than NAT*

#5 lore raw
Quoted 10 lines · Pascal Hambourg

Wakko Warner a ?crit :

Review

Quoted 6 lines

Box A -> (eth1)firewall/router(eth0) -> Box B

firewall/router does not trust eth1 and uses MAC addresses to allow access, so it does this:

(quoted diff) +0 -2
-I FORWARD -j ACCEPT -i eth1 -m mac --mac BOXAMAC
-I FORWARD -j DROP -i eth1

If the firewall does not trust what is beyond eth1, MAC filtering is pointless : a MAC address can be easily sniffed and spoofed.

I'm quite well aware of that. The likely hood is quite low, plus doing mac filtering was only the first step. Coming from that interface, I only allow ICMP and a VPN port.

Quoted 8 lines
Quoted 7 lines

firewall/router knows the mac of both box a and b (obviously, box a doesn't know box b's mac and vice versa). Consider the above the only rules in the firewall and box A and B have no rules at all.

Box A pings Box B and fails. The reason is the mac test above is seeing the
MAC of eth0, not of Box A.

Quoted 5 lines

There must be a bug in your specific setup/kernel/iptables/whatever. On my box, the FORWARD chain sees the correct MAC source address. Besides, I don't see how iptables could see the outgoing MAC source address which AFAIK is added at the link layer, after the packet has leaved Netfilter.

As I explained in the other emails, the mac test was using the MAC of the outgoing interface when the packet was forwarded. The kernel is 2.6.8-3-generic from debian (which seems to be the only 2.6 kernel I can run on that machine for some reason. All newer self compiled kernels crash on that machine within an hour w/o any explanation)

Quoted 7 lines
Quoted 3 lines

This is what I'm referring to and I had to add a MARK rule in PREROUTING to mark packets that I want to allow and then allow in the forward chain based upon the mark.

About your idea of doing this in the nat table PREROUTING chain : it won't work because the nat chains see only the initial packet of a connection.

I was using mangle/PREROUTING to do the MARK target, since that's the only place it'll work.

Quoted 1 line

*Don't you ever use the nat table chains for anything else than NAT*

Sometimes you have to, esp if you do not want specific packets to be nat'd

Signature · 2 lines
 Lab tests show that use of micro$oft causes cancer in lab animals
 Got Gas???
#6 lore raw
In reply to Pascal Hambourg
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"PH" == Pascal Hambourg <[email protected]> writes:

PH> Hello, Wakko Warner a écrit :

Quoted 4 lines
Quoted 4 lines

Box A -> (eth1)firewall/router(eth0) -> Box B firewall/router does not trust eth1 and uses MAC addresses to allow access, so it does
this: -I FORWARD -j ACCEPT -i eth1 -m mac --mac BOXAMAC -I FORWARD -j DROP -i eth1

PH> If the firewall does not trust what is beyond eth1, MAC filtering PH> is pointless : a MAC address can be easily sniffed and spoofed.

Unless the switches use MAC-address-based security... Of course these days you can let the switches sniff DHCP and enforce IP's as well.

/Benny

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#8 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Wakko Warner :

Quoted 2 lines
Quoted 1 line · Bo Yang
Quoted 1 line

I'd like to request that the mac match not be allowed in the FORWARD

chain

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

as it does not function the way that some may think.

The tests I've performed indicate that the match will match the MAC

address

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

of the transmitting interface (not what one would expect if attempting to allow based on the mac address of the sender and blocking all other

packets)

Quoted 1 line

I'd like to hear comments about this. If it is not fesable to do

this, I'd

Quoted 20 lines
Quoted 7 lines
Quoted 4 lines

recommend adding text to the man page so that others do not fall into the same problem I did.

I have already worked around this problem in my setup.

MAC address is some concept in the link layer , so how do you get the packet sender mac if the packet is routed to your box through some other routers ?

I understand. However, the machine I was using for this was directly connected to both system. There were no other routers.

Take this for instance:

Box A -> (eth1)firewall/router(eth0) -> Box B

firewall/router does not trust eth1 and uses MAC addresses to allow access, so it does this:

(quoted diff) +0 -2
-I FORWARD -j ACCEPT -i eth1 -m mac --mac BOXAMAC
-I FORWARD -j DROP -i eth1
Quoted 5 lines

firewall/router knows the mac of both box a and b (obviously, box a doesn't know box b's mac and vice versa). Consider the above the only rules in the firewall and box A and B have no rules at all.

Box A pings Box B and fails. The reason is the mac test above is

seeing the

Quoted 6 lines

MAC of eth0, not of Box A.

This is what I'm referring to and I had to add a MARK rule in PREROUTING to mark packets that I want to allow and then allow in the forward chain based upon the mark.

I think when the packet is in the FORWARD chain , the routing must have been affect the packet , so that
is the reason why you see the eth0 mac in the rule .
You can just add a rule in the PREROUTING chain in the mangle table , and DROP the packat you don't
want there . Why you must mark it first , and then drop it in another chain ?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFPKfa7tZp58UCwyMRAs7oAKDBM3ogNgaj4su6dD/i2Uj4LXcCwwCfZHhe L4LTRT9YjEL2AdZOIOHbHtA=
=XWVR
-----END PGP SIGNATURE-----

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw
Quoted 26 lines · Bo Yang

Wakko Warner :

Quoted 17 lines
Quoted 3 lines · Bo Yang

MAC address is some concept in the link layer , so how do you get the packet sender mac if the packet is routed to your box through some other routers ?

I understand. However, the machine I was using for this was directly connected to both system. There were no other routers.

Take this for instance:

Box A -> (eth1)firewall/router(eth0) -> Box B

firewall/router does not trust eth1 and uses MAC addresses to allow access, so it does this:

(quoted diff) +0 -2
-I FORWARD -j ACCEPT -i eth1 -m mac --mac BOXAMAC
-I FORWARD -j DROP -i eth1
Quoted 5 lines

firewall/router knows the mac of both box a and b (obviously, box a doesn't know box b's mac and vice versa). Consider the above the only rules in the firewall and box A and B have no rules at all.

Box A pings Box B and fails. The reason is the mac test above is

seeing the

Quoted 2 lines

MAC of eth0, not of Box A.

Quoted 7 lines
Quoted 4 lines

This is what I'm referring to and I had to add a MARK rule in PREROUTING to mark packets that I want to allow and then allow in the forward chain based upon the mark.

I think when the packet is in the FORWARD chain , the routing must have been affect the packet , so that
is the reason why you see the eth0 mac in the rule .

Yes, and the reason I wanted to request that it not be allowed to match in the FORWARD chain (or have a note in the man page about this)

Quoted 4 lines

You can just add a rule in the PREROUTING chain in the mangle table , and DROP the packat you don't
want there . Why you must mark it first , and then drop it in another chain ?

Actually, I was tinkering and using MARK was the first thing that came to mind. After thinking about it, I think the best place would be in nat/PREROUTING (since nat is already loaded on the firewall machine). I do not need mangle at all if I'm not marking. At the time, I didn't think the filtering place should be in the mangle or nat tables, afterall, that is what the filter table is for =)

In the nat/PREROUTING chain, are all incoming packets passed through this or just the initial packets? In my current setup, I have br0 (eth0 and some vpns) that are routed through ppp0 to get to the internet. eth1 is connected to a wireless ap and I do not want ANY access from anything on that network except ICMP, VPN, and the web/snmp port to the WAP (I need a GUI browser to configure the thing and the firewall has no GUI installed which is why I am using forwarding). On eth1, I only allow specific MACs to be able to connect at all.

I do appreciate the idea to block in the prerouting chain instead of marking then blocking.

Signature · 2 lines
 Lab tests show that use of micro$oft causes cancer in lab animals
 Got Gas???
#11 lore raw

I think you are doing this the hard way. This is what I do and it works
just fine
(MAC's altered, I control eth[0134] via physical access security i.e. locked room):

===============================================
-A FORWARD -i eth2 -j macchk
...
===============================================
-A macchk -m mac --mac-source 00:xx:xx:xx:8F:FD -j RETURN
...
-A macchk -m mac --mac-source 00:xx:xx:xx:8C:B6 -j RETURN -A macchk -j logmac
===============================================
-A logmac -j LOG --log-prefix "PACKET_FROM_MAC_DROPPED " -A logmac -j DROP
===============================================

Remove first line of FORWARD (shown above) to remove the restrictions.

I have a program generate macchk whenever the database of allowed machines changes. It does this by removing the reference to macchk in the forward change, flushing the macchk chain, rebuilding it (with the logmac reference on the end, and it re-inserts the reference to macchk at beginning of FORWARD.

#12 lore raw
Quoted 18 lines · Michael P. Brininstool

I think you are doing this the hard way. This is what I do and it works
just fine
(MAC's altered, I control eth[0134] via physical access security i.e. locked room):

===============================================
-A FORWARD -i eth2 -j macchk
...
===============================================

(quoted diff) +0 -3
-A macchk -m mac --mac-source 00:xx:xx:xx:8F:FD -j RETURN
...
-A macchk -m mac --mac-source 00:xx:xx:xx:8C:B6 -j RETURN
-A macchk -j logmac

===============================================

(quoted diff) +0 -2
-A logmac -j LOG --log-prefix "PACKET_FROM_MAC_DROPPED "
-A logmac -j DROP

===============================================

Quoted 7 lines

Remove first line of FORWARD (shown above) to remove the restrictions.

I have a program generate macchk whenever the database of allowed machines changes. It does this by removing the reference to macchk in the forward change, flushing the macchk chain, rebuilding it (with the logmac reference on the end, and it re-inserts the reference to macchk at beginning of FORWARD.

I tried something almost exactly the same, except it was in the filter table. it simply did not work and the MAC source that was actually tested was that of the outgoing interface (verified when I added a rule testing the mac of the outgoing interface). I want it blocked at both incoming to the local machine and being routed depending on what is used. There is no locked room per se.

In the filter table:
I first test the incoming interface in both FORWARD and INPUT, if it's eth1, jump to the mac testing chain. In that chain, if the mac is an allowed one, jump to the ip testing chain, if that packet is allowed, accept. the next line of FORWARD and INPUT is a jump to DROP (testing for eth1 again).

That is exactly what I want. Your example is more permissive than mine. Instead of using filter/INPUT and filter/FORWARD, either nat/PREROUTING or mangle/PREROUTING with the same rules should handle what I want w/o testing in both INPUT and FORWARD since at the PREROUTING stage, it has not determined where the packet will be going. I just do not know if nat/PREROUTING is traversed every time a packet comes in, or if it only is traversed on the initial packet of a connection (Probably doesn't matter though)

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#14 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Wakko Warner :

Quoted 6 lines
Quoted 5 lines · Bo Yang

Wakko Warner :

Quoted 4 lines
Quoted 3 lines · Bo Yang

MAC address is some concept in the link layer , so how do you get the packet sender mac if the packet is routed to your box through some other routers ?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

I understand. However, the machine I was using for this was directly connected to both system. There were no other routers.

Take this for instance:

Box A -> (eth1)firewall/router(eth0) -> Box B

firewall/router does not trust eth1 and uses MAC addresses to allow

access,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

so it does this:

(quoted diff) +0 -2
-I FORWARD -j ACCEPT -i eth1 -m mac --mac BOXAMAC
-I FORWARD -j DROP -i eth1

firewall/router knows the mac of both box a and b (obviously, box a

doesn't

Quoted 1 line
Quoted 1 line
Quoted 1 line

know box b's mac and vice versa). Consider the above the only rules

in the

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

firewall and box A and B have no rules at all.

Box A pings Box B and fails. The reason is the mac test above is

seeing the

Quoted 3 lines

MAC of eth0, not of Box A.

This is what I'm referring to and I had to add a MARK rule in

PREROUTING to

Quoted 1 line
Quoted 1 line
Quoted 1 line

mark packets that I want to allow and then allow in the forward chain

based

Quoted 14 lines
Quoted 5 lines
Quoted 2 lines

upon the mark.

I think when the packet is in the FORWARD chain , the routing must have been affect the packet , so that
is the reason why you see the eth0 mac in the rule .

Yes, and the reason I wanted to request that it not be allowed to match in the FORWARD chain (or have a note in the man page about this)

Quoted 4 lines

You can just add a rule in the PREROUTING chain in the mangle table , and DROP the packat you don't
want there . Why you must mark it first , and then drop it in another chain ?

Quoted 8 lines

Actually, I was tinkering and using MARK was the first thing that came to mind. After thinking about it, I think the best place would be in nat/PREROUTING (since nat is already loaded on the firewall machine). I do not need mangle at all if I'm not marking. At the time, I didn't think the filtering place should be in the mangle or nat tables, afterall, that is what the filter table is for =)

In the nat/PREROUTING chain, are all incoming packets passed through

this or

Quoted 1 line

just the initial packets?

Yes , I think so .

Quoted 4 lines

In my current setup, I have br0 (eth0 and some
vpns) that are routed through ppp0 to get to the internet. eth1 is connected to a wireless ap and I do not want ANY access from anything on that network except ICMP, VPN, and the web/snmp port to the WAP (I need

a GUI

Quoted 5 lines

browser to configure the thing and the firewall has no GUI installed which is why I am using forwarding). On eth1, I only allow specific MACs to be able to connect at all.

I do appreciate the idea to block in the prerouting chain instead of

marking

Quoted 1 line

then blocking.

It is up to you !

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFPciu7tZp58UCwyMRAp6EAJ9q/sqxoqDoUU1GhruoxrXNM0ldzACgzQLm 95PI7qRc3wr6+ebSnAwTaqs=
=Ay2C
-----END PGP SIGNATURE-----