Allwinner A40i android7.1 adds Vlan function

1. Basic knowledge of VLAN

1. Definition of VLAN:

VLAN (Virtual Local Area Network) is a communication technology that logically divides a physical LAN into multiple broadcast domains. Hosts within a VLAN can communicate directly with each other, but cannot communicate directly with each other, thus limiting broadcast packets to one VLAN.

2.Purpose:

Ethernet is a data network communication technology based on CSMA/CD shared communication medium. When the number of hosts is large, problems such as serious conflicts, flooding of broadcasts, significant performance degradation, and even network unavailability may occur. Although LAN interconnection through switches can solve the problem of serious conflicts, it still cannot isolate broadcast messages and improve network quality.
In this case, VLAN technology emerged. This technology can divide a LAN into multiple logical VLANs. Each VLAN is a broadcast domain, and the communication between hosts in the VLAN is as simple as It is the same within a LAN, but VLANs cannot directly communicate with each other. In this way, broadcast packets are limited to one VLAN.

3. Function:

(1) Control broadcast: Each vlan is an independent broadcast domain, which reduces the broadcast's occupation of network bandwidth and improves network transmission efficiency, and a broadcast storm in one VLAN will not affect other VLAN.
(2) Enhance network security: Since data can only be exchanged between ports in the same VLAN, and ports in different VLANs cannot be directly accessed, vlan can restrict individual hosts from accessing the server. and other resources. Therefore, network security can be improved by dividing VLAN
(3) Simplifying network management: A VLAN can divide users in different geographical locations into a logical network segment based on internal functions and object composition applications. Workstations can be moved between workgroups or subnets without changing the physical connections to the network. The use of VLAN technology greatly reduces the burden of network management and maintenance work and reduces network maintenance costs.


2. 8021Q VLAN

1. Configure the kernel to support VLAN

Source code path: lichee/linux-3.10/arch/arm/configs/sun8iw11p1smp_androidm_defconfig
Modify kernel configuration file

# CONFIG_L2TP is not set
# CONFIG_BRIDGE is not set
CONFIG_HAVE_NET_DSA=y
-# CONFIG_VLAN_8021Q is not set
+CONFIG_VLAN_8021Q=y
# CONFIG_DECNET is not set
# CONFIG_LLC2 is not set
# CONFIG_IPX is not set

2. Determine whether the kernel has compiled vlan

cat /proc/kallsyms | grep vlan_netdev_ops

If you cannot see the information, it means that vlan is not compiled into the kernel.


3. Operation steps for handling VLAN network equipment

1. Configure the physical interface:

requires configuration of the physical interface to connect it to the switch or router. This includes ensuring proper network cabling and correct interface configuration (such as speed and duplex mode).
Use the following command:

ip link set eth0 up
或者
ifconfig eth0 up

2. Create a VLAN interface:

needs to create a VLAN interface and associate it with a physical interface. This will allow VLAN traffic to pass through the physical interface.
Use the following command:

ip link add link eth0 name vlan10 type vlan id 10

注释:ip link add link <物理接口名称> name <VLAN接口名称> type vlan id <VLAN ID>
      <物理接口名称>:eth0
      <VLAN接口名称>: vlan10
      <VLAN ID>:为VLAN分配的ID,10

3. Configure VLAN interface:

Once the VLAN interface is created, it can be assigned an IP address and subnet mask, as well as other necessary network configurations.
Use the following command:

ip addr add 192.168.0.10/24 dev vlan10

注释:ip addr add <IP地址>/<子网掩码> dev <VLAN接口名称>
      <IP地址>/<子网掩码>:想要为VLAN接口分配的IP地址和子网掩码,即192.168.0.10/24
      <VLAN接口名称>:vlan10

4. Enable VLAN interface:

needs to enable the VLAN interface so that it can start receiving and sending packets.
Use the following command:

ip link set vlan10 up
或者
ifconfig vlan10 up

5. Make sure the vlan10 interface is up and active, and has the correct IP address and subnet mask assigned

You can use the following command to check the interface status as well as the IP configuration

ip link show vlan10 //如果接口状态为UP,则表示接口已启动

ip addr show vlan10 //如果IP地址和子网掩码与配置的信息一致,则表示接口已正确配置

6. View the VLAN interface:

Ifconfig is executed on the terminal, the vlan10 network interface can be seen.
Use the following command:

ifconfig

vlan10    Link encap:Ethernet  HWaddr 8c:fc:a0:f6:82:7f
          inet addr:192.168.0.10  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::8efc:a0ff:fef6:827f/64 Scope: Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 TX bytes:468

After completing the above steps, the VLAN network device has been configured and can start communicating. You can use ping or other network tools to test the connection.


Fourth, integrate into a shell script

1. Script and analysis

Integrate the commands required for the entire operation into the script build_vlan.sh, which can be executed directly for convenient operation.

#!/system/bin/sh

VLAN_NAME=vlan10
VLAN_ID=10

IP_address=192.168.0.10
SUBNET_MASK=24

start(){
    
    
        ip link set eth0 up
        ip link add link eth0 name $VLAN_NAME type vlan id $VLAN_ID
        ip addr add $IP_address/$SUBNET_MASK dev $VLAN_NAME
        ip link set $VLAN_NAME up

        echo "VLAN-interfaces status:"
        ip link show $VLAN_NAME
        echo "VLAN-interfaces ip address and subnet mask:\n"
        ip addr show $VLAN_NAME
}

echo "Starts to generate VLAN-interfaces!\n"
start
echo "Creating the VLAN-interface succeeded!"

build_vlan.sh parameter analysis:
VLAN_NAME=vlan10 //Name of the created VLAN interface, vlan10
VLAN_ID=10 //Assigned for VLAN ID,10
IP_address=192.168.0.10 //The IP address assigned to the VLAN interface, 192.168.0.10
SUBNET_MASK=24 //The subnet assigned to the VLAN interface netmask,24

The script parameters can be modified to自定义VLAN接口名称,为VLAN分配的ID,VLAN接口分配的IP地址以及子网掩码.

2. Operation steps

  1. adb devices sees the device;
  2. Execute the following command:
  adb root
  adb remount
  adb push "build_vlan.sh脚本" ./system/bin/
  adb shell
  chmod +x ./system/bin/build_vlan.sh
  ./system/bin/build_vlan.sh
  1. After completing the above steps, the VLAN network device has been configured. You can see the vlan10 network interface by executing ifconfig;

Guess you like

Origin blog.csdn.net/weixin_45639314/article/details/134080552