# Concetti: VLAN, tagged, untagged, PVID

## Termini

| Termine | Significato |
|---------|-------------|
| **VLAN** | rete logica identificata da un numero (1–4094) |
| **Untagged** | il pacchetto esce dalla porta senza etichetta VLAN |
| **Tagged** | il pacchetto esce con l'etichetta VLAN (802.1Q) |
| **PVID** | VLAN in cui finisce un pacchetto che **entra senza tag**; una sola per porta |
| **Porta access** | una sola VLAN, untagged + PVID: per PC, stampanti, TV… |
| **Porta trunk** | più VLAN, tagged (con al massimo una untagged "nativa"): tra router, switch e AP |

## Sintassi OpenWrt con DSA

Le VLAN si configurano sul bridge (`br-lan`) con il **VLAN filtering**. Ogni VLAN è una sezione `bridge-vlan`:

```
config bridge-vlan
	option device 'br-lan'
	option vlan '30'
	list ports 'lan4:t'      # tagged
	list ports 'lan2:u*'     # untagged + PVID (access)
```

| Suffisso | Significato |
|----------|-------------|
| `:t` | tagged |
| `:u` | untagged |
| `*` | PVID |
| `:u*` | porta access (caso più comune) |

Per ogni VLAN il bridge espone un dispositivo `br-lan.<numero>` (es. `br-lan.30`), a cui si collega l'interfaccia logica:

```
config interface 'iot'
	option device 'br-lan.30'
	...
```

In **LuCI**: *Network → Interfaces → Devices → br-lan → Configure → Bridge VLAN filtering*.

## Regole pratiche

- **Una porta può essere `u*` in una sola VLAN.**
- **Tieni tutte le porte nello stesso bridge** e separa le reti con le VLAN: evita porte "sciolte" o più bridge. Su alcuni switch, mescolare un bridge con VLAN filtering e porte usate fuori dal bridge crea problemi.
- **Quando attivi il VLAN filtering, sposta l'interfaccia `lan` da `br-lan` a `br-lan.<VLAN>`.** È l'errore più comune e ti chiude fuori dal router.
- **Il Wi-Fi non va nelle sezioni `bridge-vlan`**: un SSID con `option network 'iot'` viene aggiunto da solo come porta untagged della VLAN di quell'interfaccia.
- Sul **router** ogni VLAN ha un'interfaccia con IP. Sull'**access point** le VLAN che deve solo trasportare hanno un'interfaccia `proto 'none'`.