TL-WR703N is a very tiny router, made by TP-LINK who markets it as “3G travel router”, although without a builtin 3G modem you cannot really say it is a 3G router, which is still an awesome device for its size. Very neat.
TL-WR703N 是一个非常小的路由器，生产商 TP-LINK 把它宣传为 “3G 旅行路由器”，然而不自带 3G 猫芯的路由器不能算作真正意义上的 3g 设备，不过它仍然是非常赞的东东，因为实在太小巧了。
There are many stories about how to make it a low power 24x7 downloading box, or a wireless audio streaming box with OpenWrt, I still wanna make it a better router. Since it has only one ethernet interface and has no switch built-in, therefore we often change its role as a normal router with wireless clients to a wireless bridge or repeater with wired clients. It would be cool if the only interface can automatically vary its role according to different situation. To be brief, our goal is:
- When a node’s ethernet wire is plugged in, and makes DHCP requests, the router should assign it a LAN IP.
- Otherwise, the router should consider the wire as an WAN path.
- 当有线客户端接入并且请求 DHCP 时，路由器应该分配给它一个 IP，并纳入 LAN。
- 其他情况，一律视作 WAN 接口。
Currently, there is a solution to this on the net is to leverage the linux kernel functionality macvlan, and make a virtual interface based on the physical interface with different MAC. This approach just works, but I don’t like the way it shares all the packets of LAN and WAN on the wire without discrimination, and OpenWrt has no uci config for macvlan so far. So I think VLAN trunk is a better way, at least for me. This approach needs configurations on the wired LAN clients, such as Computers and other linux routers. Since the typical applications of mine involve only my own devices, it’s not a big deal.
目前有一种方法可以解决，就是利用 linux kernel 的 macvlan 功能，创建一个基于物理接口的虚拟接口，只是 MAC 不同。这种方法可以工作，不过我不喜欢它对数据包完全不加以区分的方式，并且 OpenWrt 没有专门针对的 macvlan 的配置文件。这种情况下我更倾向于 VLAN trunk。但是这种办法需要在客户端，比如电脑或者其他路由器上进行配置，不过我的典型应用只涉及到我自己的设备，所以这不是什么大问题。
The config on the OpenWrt side:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
eth0 is WAN, which should work without change; eth0.2 is a VLAN interface created by linux vconfig tagged with ID 2, which is not a hardware VLAN, and eth0.2 is bridged with wireless.
eth0 是 WAN 口，像往常一样不需变动；eth0.2 是 linux vconfig 创建的 VLAN 口, ID 为 2，并非硬件 VLAN，并且 eth0.2 和无线桥接到了一起。
On the client side, the configurations depend on the NIC driver. Most recent intel NICs have VLAN support with official drivers, so do the Realtek ones, but they need additional utility called Windows Diagnostic Program to do this. Here are screen shots:
在客户端这边，配置取决于网卡驱动，大部分现代的 Intel 网卡都支持 VLAN，Realtek 也支持，只不过需要专门的工具来进行配置。截图几枚：