# Bridge + ad-hoc + STP = lots of duplicate frames

## random-feed

Hi.

I have a Gentoo box set up as a home router, and recently added a PCI wi-fi card to add AP functionality. The card is RaLink RT2561/RT61. I am using the driver from portage, net-wireless/rt61-1.1.0_beta2. I managed to get the wireless card working, and I am able to connect to it from my laptop (Arch Linux, with an atmel-based PCMCIA wifi card). After setting up interfaces and routing, everything appears to work.

However, when I set up the router box (Gentoo) to bridge the wireless and LAN interfaces (ra0 and eth0), the wireless throughput drops dramatically. I believe this is because of duplicate packets -- each SYN packet sent from the laptop produces 6 ACK replies, the same with ICMP traffic:

```

laptop ~ # ping google.com

PING google.com (64.233.167.99) 56(84) bytes of data.

64 bytes from py-in-f99.google.com (64.233.167.99): icmp_seq=1 ttl=240 time=209 ms

64 bytes from py-in-f99.google.com (64.233.167.99): icmp_seq=1 ttl=240 time=210 ms (DUP!)

64 bytes from py-in-f99.google.com (64.233.167.99): icmp_seq=1 ttl=240 time=212 ms (DUP!)

64 bytes from py-in-f99.google.com (64.233.167.99): icmp_seq=1 ttl=240 time=217 ms (DUP!)

64 bytes from py-in-f99.google.com (64.233.167.99): icmp_seq=1 ttl=240 time=219 ms (DUP!)

64 bytes from py-in-f99.google.com (64.233.167.99): icmp_seq=1 ttl=240 time=221 ms (DUP!)

64 bytes from py-in-f99.google.com (64.233.167.99): icmp_seq=1 ttl=240 time=225 ms (DUP!)

--- google.com ping statistics ---

1 packets transmitted, 1 received, +6 duplicates, 0% packet loss, time 0ms

rtt min/avg/max/mdev = 209.883/216.770/225.704/5.444 ms

```

Note, that there are NO other hosts connected to either of the bridged segments. The laptop has an ethernet adapter and a wifi card, but the above output is produced with only the wireless interface being up. If I bring down the wifi, and use the cable interface, the ping works normally -- a single reply is received per packet sent.

Here is the setup on the Gentoo box that has the bridge:

```

router ~ # iwconfig ra0

ra0       RT61 Wireless  ESSID:"pancho"  Nickname:""

          Mode:Ad-Hoc  Frequency:2.427 GHz  Cell: 3A:ED:E1:75:0D:19   

          Bit Rate=11 Mb/s   

          RTS thr:off   Fragment thr:off

          Encryption key:****-****-**

          Link Quality=89/100  Signal level:-51 dBm  Noise level:-79 dBm

          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0

          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

router ~ # ifconfig 

br0       Link encap:Ethernet  HWaddr 00:01:02:68:0B:53  

          inet addr:192.168.0.1  Bcast:192.168.0.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:118611 errors:0 dropped:0 overruns:0 frame:0

          TX packets:41376 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:11714812 (11.1 Mb)  TX bytes:11249991 (10.7 Mb)

eth0      Link encap:Ethernet  HWaddr 00:01:02:68:0B:53  

          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1

          RX packets:26228 errors:0 dropped:0 overruns:0 frame:0

          TX packets:25039 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:3043709 (2.9 Mb)  TX bytes:1502496 (1.4 Mb)

          Interrupt:9 Base address:0xe80 

eth1      Link encap:Ethernet  HWaddr 00:0E:2E:71:F7:DE  

          inet addr:89.215.*.*  Bcast:89.215.*.*  Mask:255.255.252.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:98885 errors:0 dropped:0 overruns:0 frame:0

          TX packets:64667 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:20601765 (19.6 Mb)  TX bytes:8486634 (8.0 Mb)

          Interrupt:11 Base address:0x2f00 

lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:2879 errors:0 dropped:0 overruns:0 frame:0

          TX packets:2879 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:218321 (213.2 Kb)  TX bytes:218321 (213.2 Kb)

ra0       Link encap:Ethernet  HWaddr 00:0E:2E:C7:DF:B4  

          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1

          RX packets:176618 errors:0 dropped:0 overruns:0 frame:0

          TX packets:65958 errors:162 dropped:162 overruns:0 carrier:0

          collisions:621 txqueuelen:1000 

          RX bytes:19309677 (18.4 Mb)  TX bytes:13496815 (12.8 Mb)

          Interrupt:10 

```

My /etc/conf.d/net

```

# /etc/conf.d/net:

modules=( "ifconfig" )

config_eth0=( "null" )

config_eth1=( "89.215.*.* netmask 255.255.252.0 broadcast 89.215.*.*" )

routes_eth1=( "default via 89.215.*.*" )

modules_ra0=( "iwconfig" )

mode_ra0=( "ad-hoc" )

essid_ra0=( "pancho" )

channel_ra0="4"

key_pancho="**********"

config_ra0=( "null" )

bridge_br0="eth0 ra0"

config_br0=( "192.168.0.1 netmask 255.255.255.0" )

brctl_br0=( "stp on" )

```

The simple script I use for setting up iptables:

```

#!/bin/bash

#

IPT=/sbin/iptables

# Start off clean

for a in `cat /proc/net/ip_tables_names`; do

        ${IPT} -F -t $a

        ${IPT} -X -t $a

done;

# Set policies

${IPT} -P INPUT DROP

${IPT} -P FORWARD DROP

${IPT} -P OUTPUT ACCEPT

${IPT} -t nat -A POSTROUTING -o eth1 -j MASQUERADE

# Know yourself

${IPT} -I INPUT -i lo   -j ACCEPT

${IPT} -I INPUT -i br0  -j ACCEPT

${IPT} -A FORWARD -i br0  -o eth1 -s 192.168.0.0/24 -j ACCEPT

${IPT} -A FORWARD -i eth1 -o br0 -m state --state ESTABLISHED,RELATED -j ACCEPT

echo 1 > /proc/sys/net/ipv4/ip_forward

```

I am sure I'm not the only one with this problem, but after 2 days of google-ing I was unable to find a solution. Somewhere someone mentioned that this is related to ad-hoc mode, and is an upstream kernel bug?

Please share anything that may shed light on the issue. Thanks.

----------

## The_Tree

to bridge your wireless card needs to be master.  IE act as an AP.

why don't you just set your wireless card on a different subnet and just route between them.

----------

## random-feed

This is what I am doing now, but it would be much more convenient to have the two segments bridged -- I won't have to change any of the settings on the client machines, and the router will be accessible via the same IP (Otherwise, I have to add a route on the client machines, something like

route add -net 192.168.0.0 netmask 255.255.255.0 eth1

where eth1 is the wifi card on the client.

Also, why do I need the wifi in Master mode to allow bridging? When I set this up everything looked fine, except for the duplicate packets. Any STP packets the wireless sent were malformed too.

----------

## The_Tree

because you need the changes that master mode brings to the mac.

you need to have the destination and source mac as on an ethernet network

 and the wireless target mac and wireless source mac.

--------------------------------------------------------------------------

| source MAC                          | Destination Mac                      |

--------------------------------------------------------------------------

| wireless source MAC              | wireless destination MAC         |

---------------------------------------------------------------------------

I take it your configuring your network as follows

router AP ~~~~~~~~~~~~~~~~~~ gentoo box ------------------ extra nodes

if so the mode you need is called WDS

put both the router AP in ap mode and the gentoo boxes card then configure WDS and bridge the WDS connection.

----------

