# doesn't dummynet work with vlan?



## maslakyavuz (Jun 7, 2012)

Hello there, 

I use freebsd8.2 FreeBSD 8.2. I added dummynet and the following to the kernel;


```
options         IPFIREWALL              #firewall
options         IPFIREWALL_VERBOSE      #print information about
options         IPFIREWALL_FORWARD      #enable trasparent proxy support     
options         IPFIREWALL_DEFAULT_TO_ACCEPT    #allow everything by default
options         HZ=1000
options         DUMMYNET
options         IPDIVERT
options         DEVICE_POLLING
```

I have four networks which seperate from each other with VLANs. I wish to limit bandwidth for every VLAN network using dummynet. I have two ethernet cards for that. *O*ne of them is WAN, the other one is inbound is tagged. VLAN works well. I configured a network to limit using dummynet; ipfw.sh:


```
###
ipfw -f flush

ipfw pipe 11 config bw 2Mbit/s     # Vlan104
ipfw pipe 12 config bw 2Mbit/s     # 6.Port on the switch

ipfw add pipe 11 ip from any to 10.12.4.0/24  in via em0
ipfw add pipe 12 ip from 10.12.4.0/24 to any out xmit em0
###
```

em0 is for outside in the server. *A*s a client my PC is in vlan104 namely *I* am behind the firewall. *W*hen *I* execute the ipfw.sh, I can't reach the internet.


```
ipfw add pipe 12 ip from 10.12.4.0/24 to any out xmit em0
```

*A*bove line works it actually limits but


```
ipfw add pipe 11 ip from any to 10.12.4.0/24  in via em0
```

*A*bove line doesn't work properly, it obstructs my http and ICMP requests. *S*o *I* can't reach the internet.

When *I* remove 
	
	



```
ipfw add pipe 11 ip from any to 10.12.4.0/24  in via em0
```
 from ipfw.sh I can either ping outbound or reach the internet.

I tried vlan104 instead of em0

```
in via em0
```
*T*hat doesn't help me.

What can be the problem?

Thanks


----------



## ecazamir (Jun 7, 2012)

Try adding a rule to pass and/or log some packets, only to check counters. I like a different approach for dummynet on routers: match only egress packets (the out keyword), but I also specify the ingress and egress interfaces (recv/xmit keywords), to make sure packets are sent to dummynet pipes/queues only once. I use:


```
ipfw add 500 pipe 200 ip from 10.x.x.x to any out recv em0 xmit vlan200
```


----------



## phoenix (Jun 8, 2012)

Dummynet works fine with vlans.  We use it on our main fibre router to limit each fibre site to 900 Mbps total (pipe) and 100 Mbps each (queue).

How it works with vlans depends on how the vlans are configured: tagged (as in separate vlan virtual interface in FreeBSD) or untagged (single physical interface in FreeBSD).  If you are using tagged vlans, then you will have separate *vlanX* or *em.X* interfaces in FreeBSD.  Use those interfaces in your rules, not the physical interface.


----------



## maslakyavuz (Jun 8, 2012)

*my problem continues*

*O*k my configuration is below;

```
# cat rc.conf;
cloned_interfaces="vlan100 vlan101 vlan102 vlan103 vlan104 vlan105 vlan106"
# WAN
ifconfig_em0="inet 87.255.91.194  netmask 255.255.255.0"  # UST KART
# LAN                                                 
ifconfig_em1="UP"                                       # ALT KART
ifconfig_vlan100="inet 10.12.0.1/24 vlan 100 vlandev em1"
ifconfig_vlan101="inet 10.12.1.1/24 vlan 101 vlandev em1"
ifconfig_vlan102="inet 10.12.2.1/24 vlan 102 vlandev em1"
ifconfig_vlan103="inet 10.12.3.1/24 vlan 103 vlandev em1"
ifconfig_vlan104="inet 10.12.4.1/24 vlan 104 vlandev em1"
```


```
# cat ipfw.sh
ipfw pipe 104 config bw 2Mbit/s     # Vlan104
ipfw add 500 pipe 104 ip from 10.12.4.0/24 to any out recv em0 xmit vlan104
```

I also used below one before;

```
ipfw pipe 11 config bw 2Mbit/s     # Vlan104
ipfw pipe 12 config bw 2Mbit/s     # 
ipfw add pipe 11 ip from any to 10.12.4.0/24  in via em0
ipfw add pipe 12 ip from 10.12.4.0/24 to any out xmit em0
ipfw add pass ip from 10.12.4.0/24 to any
ipfw add pass ip from any to 10.12.4.0/24
```

But it is the same. it causes obstruct me to reach to internet. Actually it limits for bandwidth. *I* don't use a proxy server. *I* use NAT. *I*f *I* remove the dummynet lines (above lines) everything is OK except limit. *I*f *I* use outbound (xmit) and remove recv (inbound) *I* can reach the internet but *I* can't limit inbound traffic. 
*W*hat should my configuration be?


----------



## phoenix (Jun 8, 2012)

Okay, so traffic comes in on the vlan interface, gets NAT'd as it goes out the public interface (em0).  And you want to use dummynet to rate-limit the traffic on a per-vlan basis.  Correct?

So, something like the following would be your generic, starting rules, to allow traffic via NAT:

```
ipfw add 500 allow ip from 10.12.4.0/24 to any in recv vlan104
ipfw add 501 nat 104 ip from 10.12.4.0/24 to any out xmit em0
ipfw add 502 nat 104 ip from any to <public_IP> in recv em0
ipfw add 502 allow ip from any to 10.12.4.0/24 out xmit vlan104
```

So, you change your vlan104 rules to do the rate-limiting:

```
ipfw pipe 104 bw 2Mbit/s
ipfw add 500 pipe 104 from 10.12.4.0/24 to any in recv vlan104
ipfw add 501 nat 104 ip from 10.12.4.0/24 to any out xmit em0
ipfw add 502 nat 104 ip from any to <public_IP> in recv em0
ipfw add 502 pipe 104 from any to 10.12.4.0/24 out xmit vlan104
```


----------



## maslakyavuz (Jun 8, 2012)

Ok. *I* am going to try it. *I*t may be help. I use PF for NAT.

*M*y pf.conf is:

```
ext_if="em0"    # external interface name
int_if="em1"    # internal interface name
nat on $ext_if from !$ext_if to any -> $ext_if
```

*H*ow can *I* do what you said using pf? I am also going to try NAT with IPFW.


----------



## phoenix (Jun 8, 2012)

You really shouldn't mix PF and IPFW together.  You are introducing a lot of extra latency and processin, as every packet is now processed twice (once by each packet filter).

Pick one, and do everything with it.  Either PF+ALTQ for NAT/queuing, or IPFW+Dummynet for same.


----------



## ecazamir (Jun 9, 2012)

NAT and dummynet require some precautions, because of the address change at NAT layer. IPFW tags should help.


----------



## ecazamir (Jun 9, 2012)

phoenix said:
			
		

> You really shouldn't mix PF and IPFW together.  You are introducing a lot of extra latency and processin, as every packet is now processed twice (once by each packet filter).
> 
> Pick one, and do everything with it.  Either PF+ALTQ for NAT/queuing, or IPFW+Dummynet for same.



Technically, IPFW can work with pf, I used pf for NAT and IPFW for filtering and queueing with success on a single machine. Few 2 Mbps pipes shouldn't kill current x86 hardware.


----------



## maslakyavuz (Jun 9, 2012)

Ok

*M*y rc.conf is:

*I* have two ethernet cards, em0 is WAN and em1 is LAN, and assigned VLANs.  


```
# cat rc.conf;
cloned_interfaces="vlan100 vlan101 vlan102 vlan103 vlan104 vlan105 vlan106"
# WAN
ifconfig_em0="inet 87.255.91.194  netmask 255.255.255.0"  # UST KART
# LAN                                                 
ifconfig_em1="UP"                                       # ALT KART
ifconfig_vlan100="inet 10.12.0.1/24 vlan 100 vlandev em1"
ifconfig_vlan101="inet 10.12.1.1/24 vlan 101 vlandev em1"
ifconfig_vlan102="inet 10.12.2.1/24 vlan 102 vlandev em1"
ifconfig_vlan103="inet 10.12.3.1/24 vlan 103 vlandev em1"
ifconfig_vlan104="inet 10.12.4.1/24 vlan 104 vlandev em1"
############################
```

*I* want to limit vlan104 to 2 *M*bps and vlan103 to 1 *M*bps.
*H*ow can *I* do that? *A*nd *I* use PF for NAT

pf.conf:

```
#####
ext_if="em0"    # external interface name
int_if="em1"    # internal interface name
nat on $ext_if from !$ext_if to any -> $ext_if
####
```


----------



## DutchDaemon (Jun 9, 2012)

@maslakyavuz, read your PM.


----------



## maslakyavuz (Jun 12, 2012)

Ok *I* got it. *M*ay *I* go on my issue?


----------



## DutchDaemon (Jun 12, 2012)

You obviously didn't get it, so try again.


----------

