目录
1:先看看高通的8327是如何虚拟网络接口
2: Linux 内核中选上802.1Q
3: 实际效果展示
4:配置使用
1:先看看高通的8327是如何虚拟网络接口
root@OpenWrt:~# cat /etc/config/wireless
config wifi-device 'wifi0'
option type 'qcawifi'
option macaddr '68:89:75:04:e9:c0'
option hwmode '11ng'
option htmode 'HT20'
option channel '4'
option txpower '0'
config wifi-iface
option device 'wifi0'
option mode 'ap'
option ssid 'OpenWrttest'
option network 'lan'
option encryption 'psk2'
option key '12345678'
config wifi-device 'wifi1'
option type 'qcawifi'
option channel 'auto'
option macaddr '68:89:75:04:e9:c1'
option hwmode '11ac'
option disabled '1'
config wifi-iface
option device 'wifi1'
option network 'lan'
option mode 'ap'
option ssid 'OpenWrt'
option encryption 'none'
root@OpenWrt:~# ifconfig
ath0 Link encap:Ethernet HWaddr 68:89:75:04:E9:C0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1099 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:158 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:244211 (238.4 KiB) TX bytes:0 (0.0 B)
br-lan Link encap:Ethernet HWaddr 68:89:75:04:E9:BB
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::6a89:75ff:fe04:e9bb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1480 errors:0 dropped:0 overruns:0 frame:0
TX packets:919 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:246795 (241.0 KiB) TX bytes:279067 (272.5 KiB)
eth0 Link encap:Ethernet HWaddr 68:89:75:04:E9:BB
inet6 addr: fe80::6a89:75ff:fe04:e9bb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1520 errors:0 dropped:74 overruns:0 frame:0
TX packets:1505 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:392488 (383.2 KiB) TX bytes:271968 (265.5 KiB)
Interrupt:4
eth0.88 Link encap:Ethernet HWaddr 68:89:75:04:E9:BB
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:380 errors:0 dropped:0 overruns:0 frame:0
TX packets:732 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:42182 (41.1 KiB) TX bytes:122441 (119.5 KiB)
eth0.99 Link encap:Ethernet HWaddr 68:89:75:04:E9:BB
inet addr:192.168.50.165 Bcast:192.168.50.255 Mask:255.255.255.0
inet6 addr: fdac:5b71:2b57:0:6a89:75ff:fe04:e9bb/64 Scope:Global
inet6 addr: fe80::6a89:75ff:fe04:e9bb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:988 errors:0 dropped:0 overruns:0 frame:0
TX packets:766 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:305141 (297.9 KiB) TX bytes:142917 (139.5 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wifi0 Link encap:UNSPEC HWaddr 68-89-75-04-E9-C0-00-00-00-00-00-00-00-00-00-00
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4654 errors:0 dropped:0 overruns:0 frame:0
TX packets:2979 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:2699
RX bytes:958592 (936.1 KiB) TX bytes:841975 (822.2 KiB)
Interrupt:47 Memory:b8100000-b8120000
root@OpenWrt:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.50.1 0.0.0.0 UG 0 0 0 eth0.99
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 br-lan
192.168.50.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.99
root@OpenWrt:~# cat /etc/config/network
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config interface 'lan'
option ifname 'eth0.88'
option type 'bridge'
option proto 'static'
option ipaddr '192.168.1.1'
option netmask '255.255.255.0'
option ieee1905managed '1'
config interface 'wan'
option ifname 'eth0.99'
option proto 'dhcp'
config switch
option name 'switch0'
option reset '1'
option enable_vlan '1'
config switch_vlan
option device 'switch0'
option vlan '44'
option ports '0t 1 2 3 4'
option vid '88'
config switch_vlan
option device 'switch0'
option vlan '55'
option ports '0t 5'
option vid '99'
在openwrt中,我们需要注意的是字段:option vid '99' 和 option vid '88',这个表示switch内部使用的VID是多少,跟option vlan '55'和option vlan '44'没有任何关系,个人觉得是VLAN的名称而已,可以任意设置.
2: Linux 内核中选上802.1Q
3: 实际效果展示
root@yachtsense-main:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.50.1 0.0.0.0 UG 10 0 0 eth0.99
192.168.50.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.99
198.18.0.0 0.0.0.0 255.255.248.0 U 203 0 0 eth0
root@yachtsense-main:~# ping www.baidu.com
PING www.a.shifen.com (183.2.172.185) 56(84) bytes of data.
64 bytes from 183.2.172.185 (183.2.172.185): icmp_seq=1 ttl=50 time=9.04 ms
64 bytes from 183.2.172.185 (183.2.172.185): icmp_seq=2 ttl=50 time=8.90 ms
64 bytes from 183.2.172.185 (183.2.172.185): icmp_seq=3 ttl=50 time=8.90 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 6018ms
rtt min/avg/max/mdev = 8.904/8.953/9.047/0.101 ms
root@yachtsense-main:~# cat /etc/resolv.conf
nameserver 240e:1f:1:0:0:0:0:1 # IPV6 wwan0
nameserver 240e:1f:1:0:0:0:0:33 # IPV6 wwan0
nameserver 202.96.128.86
nameserver 202.96.134.133
root@yachtsense-main:~# ifconfig
can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
UP NOARP MTU:16 Metric:1
RX packets:1865 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14920 (14.5 KiB) TX bytes:0 (0.0 B)
Interrupt:191
eth0 Link encap:Ethernet HWaddr 00:11:c7:11:10:88
inet addr:198.18.2.99 Bcast:198.18.7.255 Mask:255.255.248.0
inet6 addr: fe80::211:c7ff:fe11:1088/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1295 errors:0 dropped:0 overruns:0 frame:0
TX packets:1055 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:249867 (244.0 KiB) TX bytes:416396 (406.6 KiB)
eth0.99 Link encap:Ethernet HWaddr 00:11:c7:11:10:88
inet addr:192.168.50.56 Bcast:192.168.50.255 Mask:255.255.255.0
inet6 addr: fe80::211:c7ff:fe11:1088/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:242 errors:0 dropped:0 overruns:0 frame:0
TX packets:123 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:30250 (29.5 KiB) TX bytes:13675 (13.3 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:404308 errors:0 dropped:0 overruns:0 frame:0
TX packets:404308 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:13561857 (12.9 MiB) TX bytes:13561857 (12.9 MiB)
root@yachtsense-main:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.50.1 0.0.0.0 UG 10 0 0 eth0.99
192.168.50.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.99
198.18.0.0 0.0.0.0 255.255.248.0 U 203 0 0 eth0
root@yachtsense-main:~# udhcpc -i eth0.99
udhcpc: started, v1.27.2
udhcpc: sending discover
udhcpc: sending select for 192.168.50.56
udhcpc: lease of 192.168.50.56 obtained, lease time 86400
/etc/udhcpc.d/50default: Adding DNS 192.168.50.1
root@yachtsense-main:~# cat /etc/resolv.conf
nameserver 192.168.50.1
root@yachtsense-main:~# ping www.baidu.com
PING www.a.shifen.com (183.2.172.42) 56(84) bytes of data.
64 bytes from 183.2.172.42 (183.2.172.42): icmp_seq=1 ttl=50 time=7.90 ms
64 bytes from 183.2.172.42 (183.2.172.42): icmp_seq=2 ttl=50 time=7.84 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 5022ms
rtt min/avg/max/mdev = 7.844/7.875/7.906/0.031 ms
root@yachtsense-main:~#
4:配置使用
由于KSZ9897 有5个带phy的端口,在当前的项目中,5个port都是LAN口,即接到电脑下面的PC都从设备上面获取IP地址,即设备提供DHCP server 的功能。
目前希望将5个port中的任何一个用来做WAN口,使这个port作为设备的上行有线网络接口。此处我们使用port2
每一个端口使用一个bit来表示
All=0x7F, port2=0x2, port3=0x4, ports 2&3=0x6, port4=0x8, port5=0x10
port1 =0x01 sw0
port2 =0x02 sw1
port3 =0x04 sw2
port4 =0x08 sw3
port5 =0x10 sw4
下面的port6和port7用来与主控CPU进行连接
port6 =0x20
port7 =0x40 -
ifconfig eth0 up
vconfig add eth0 99
iptables -t nat -A POSTROUTING -o eth0.99 -j MASQUERADE
cd /sys/devices/platform/30a40000.i2c/i2c-2/2-005f
echo 99 > sw1/1_vid
echo 1 > sw/vlan
echo 99 > sw/vlan_index
echo 0 > sw2/1_ingress
echo 99 > sw/vlan_fid
echo 0x42 > sw/vlan_ports
echo 0x2 > sw/vlan_untag
echo 0x1 > sw/vlan_valid
#==========================================
echo 1 > sw/vlan
echo 8 > sw/vlan_index
echo 8 > sw/vlan_fid
echo 0x7D > sw/vlan_ports
echo 0x7D > sw/vlan_untag
echo 0x1 > sw/vlan_valid
udhcpc -i eth0.99 &
上面的配置参考下面的资料