OpenWrt交换机手册(Switch Documentation)

来源:互联网 发布:mysql from not in 编辑:程序博客网 时间:2024/06/10 23:39

如果你的设备含有不少于1个的LAN接口,那这个设备在不同的接口之间可能有一个被称为交换(switch)的特殊连接。大多数的内部构造如下图所示:

这里写图片描述

如果你想要更改这些端口如何互相连接的,你需要配置你的switch设备。 (see also network.interfaces)

UCI config, swconfig style

假设

设备运行在kernel 2.6 或 3 的版本,设备使用swconfig类型的switch配置
—————————————————
switch位于eth1上。(有许多是在eth0上,判断方法:/proc/switch目录包含了正确的设备号,请确认)[Howto find out:/proc/switch directory appears to contain the right eth number for the switch. please confirm],例如:rtl8366s的芯片.

5个接口的交换设备,其中0-3连接外部,4没有连接,5连接到CPU的eth1接口(which adds up to six ports except that 4 is not counted)
vlan0 仅表示所有的对外接口除了最后的那个。
vlan1 仅表示最后的那个对外接口。[Howto find out which Port corresponds:]
vlan0 是默认vlan,这意味着如果数据包是未加标签的,它将被视为vlan0的数据包。

配置

交换配置

在 /etc/config/network

config 'switch' 'eth1'   option 'enable'      '1'   option 'enable_vlan' '1'   option 'reset'       '1'   option 'pvid'        '100'

VLAN: switch config
in /etc/config/network

Notes

VLAN标识号是由option vlan行来指定。一个VLAN的VID(VLAN ID)默认是与相同VLAN标识号关联的。这个标识号可以被option pvid行更改。例如,VLAN1可以使用VID 100。

在option ports行,端口号表明指定的vlan包括这个端口号,如果端口号后跟着”t”那么从这个端口发出的分组是加标签的(tagged),并且这个端口收到的分组可能是附带VLAN标识的。5通常是CPU或者内部端口并且经常被用于标识端口(tagged)。在使用swconfig的设备上其他后缀会被忽略,除了Broadcom kmod-switch
类型接口(/proc/switch/)使用”*”和”u”分别表示PVID和未标识(untagged)端口(因为CPU 端口暗中是被加标签的,需要使用”u”来untag)。

因此,‘0 1 2 3 5t’代表在这个VLAN中当分组(packets)离开端口0,1,2和3发送时是未加标签的,但离开端口5是发送时是加标签的(通常是上面所述的CPU内部端口)。

一个端口收到的标识分组将被指向包含在分组里的VID指明的VLAN。未标识分组将被指向到默认端口VLAN(通常称作PVID)。一个单独的用于设置默认端口VLAN的 switch_port config section是必须的。

相关标准文档802.1q上说VID值0和4095不能被用作标识分组因为它们是预留值 - VID 0 是默认本地vlan - 中间留有4094个有效值,尽管VID 1经常预留为网络管理(举例查看 Dell 2708)。这表明vlan0可在设备内或者设备之间作为一个vlan使用,但是你不能使用vlan0来标识分组。

The config sections

config 'switch_vlan'   option 'vlan'       '0'   option 'device'     'eth1'   option 'ports'      '0 1 2 5t'config 'switch_vlan'   option 'vlan'       '1'   option 'device'     'eth1'   option 'ports'      '3 5t'config 'switch_port'    option 'port'      '3'    option 'pvid'      '1'

VLAN: interface/network config

VLAN 接口sections看起来就像常规接口sections,除了替代eth1(或者eth0或无论什么),你有eth1.0,eth1.1等等。在一个’.’之后的数字是一个VLAN号。(那是用于内核2.6;2.4内核有所不同)
下面的例子是两个接口的路由器,eth0用作 WAN 口,eth1如上面一样作为5端口交换机来配置。过程见 /etc/config/network

e.g.

config 'interface' 'lan'    option 'ifname' 'eth1.0'    option 'proto' 'static'    option 'ipaddr' '192.168.1.1'    option 'netmask' '255.255.255.0'    option 'defaultroute' '0'    option 'peerdns' '0'    option 'nat'    '1'config 'interface' 'extranet'    option 'ifname'  'eth1.1'    option 'proto'   'dhcp'config 'interface'  'wan'   option 'ifname'  'eth0.2'   option 'proto'   'pppoe'   option 'username' 'szabozsolt-em'   option 'password' 'M3IuWBt4'

当然,如果你只有一个5端口交换机eth0(而且没有其他接口),你可能要用匹配恰当的switch,switch_vlan和switch_port sections配置 wan 接口为eth0.1,lan接口eth0.0。

原文链接:交换机手册(Switch Documentation)

2 0