Wiki
Clone wikirt-n56u / RU / Управление свитчем
Управление свитчем
Возможности по конфигурированию LAN-портов роутера зависят от модели роутера. Предполагается, что вы знаете какой порт свитча за что отвечает, что такое VLAN'ы и можете составить битовые маски, передаваемые утилитам в качестве параметров.
Утилиты rtl8367 и mtk_esw
Присутствие той или иной утилиты определяется моделью вашего роутера, в примерах ниже для единообразия будет использоваться rtl8367
.
Совет: в утилитах нет «защиты от дурака», поэтому будьте предельно внимательны. Если потеряете управление свитчем, то вылечить это можно будет только перезагрузкой.
Обе утилиты имеют схожий синтаксис, который можно увидеть, запустив их без параметров:
Usage: rtl8367 COMMAND [ARG1] [ARG2] COMMAND: 10 [PORT] Show port link status 11 Show WAN ports link status 12 Show LAN ports link status 20 [PORT] Show port speed status 30 [PORT] Show port MIB counters 38 Reset all ports MIB counters 40 [0x25252525] Full reset and reinit switch 41 [MASK] [0|1] Set power off/on for ports mask 42 [W|L] [0|1] Set power off/on for WAN or LAN ports 43 Clear switch L2 MAC table 50 [0..8] [0..3] Config WAN bridge mode and isolation ** 51 [0|1] Toggle iNIC isolation from LAN ports ** 52 [0|1] Toggle iNIC disable RGMII port link ** 55 [MASK] [PORT] Override port forward mask * 55 [MASK] [PORT] Override port matrix mask 60 Reset VLAN table and init VLAN1 61 Show untagged WAN PVID 62 [MASK] [0..2] Set VLAN accept mode for ports mask 63 [MASK] [DATA] Create port-based VLAN entry 64 [MASK] [DATA] Create VLAN entry ** 70 [1..1024] Set Unknown Unicast storm rate limit for all ports ** 71 [1..1024] Set Unknown Multicast storm rate limit for all port ** 72 [1..1024] Set Multicast storm rate limit for all ports ** 73 [1..1024] Set Broadcast storm rate limit for all ports * 73 [1..1000] Set Broadcast storm rate limit for all ports 75 [1|0] Set Jumbo Frames accept on/off ** 76 [1|0] Set Green Ethernet on/off 77 [1|0] Set 802.3az EEE on/off 78 [1|0] Set IGMP/MLD snooping on/off 79 [MASK] Set IGMP/MLD static ports mask ** 80 [0..11] Set LED action group0 * 80 [7,11] Set EPHY LED action ** 81 [0..11] Set LED action group1 ** 82 [0..11] Set LED action group2 90 [MODE] [PORT] Set port link mode (fc|link) **100 [0..7] Set ExtIf RGMII delay RX **101 [0..1] Set ExtIf RGMII delay TX **110 Dump IGMP/MLD static LUT entries from ASIC **111 Dump L2 MAC entries from ASIC **112 Dump ASIC ports isolation **120 [REG] Get ASIC register **121 [REG] [VALUE] Set ASIC register **122 [REG] Get PHY register **123 [REG] [VALUE] Set PHY register * for mtk_esw only ** for rtl8367 only
Несколько примеров использования утилит есть ниже.
Пример: Перезапуск ethernet-соединения с провайдером
rtl8367 42 1 0 sleep 1 rtl8367 42 1 1
Пример: Присоединить WAN-порт к другим LAN-портам
rtl8367 50 8 0
Пример: Сделать порты WAN и LAN4 членами VID 20
rtl8367 64 0x00000018 0x00140014
0x00000018
вычисляется по формуле((untag & 0xFF) << 16) | (member & 0xFF)
, где member
:
#define SWAPI_PORTMASK_LAN1 (1<<0) #define SWAPI_PORTMASK_LAN2 (1<<1) #define SWAPI_PORTMASK_LAN3 (1<<2) #define SWAPI_PORTMASK_LAN4 (1<<3) #define SWAPI_PORTMASK_WAN (1<<4) #define SWAPI_PORTMASK_CPU_LAN (1<<5) #define SWAPI_PORTMASK_CPU_WAN (1<<6) #define SWAPI_PORTMASK_INIC (1<<7)
SWAPI_PORTMASK_*
для rtl8367
или mtk_esw
соответственно здесь или здесь.
Значение 0x00140014
получено подстановкой VID в выражение ((fid & 0x0FFF) << 16) | (vid & 0x0FFF)
Утилита switch
switch --help Usage: switch acl etype add [ethtype] [portmap] - drop etherytype packets switch acl dip add [dip] [portmap] - drop dip packets switch acl dip meter [dip] [portmap][meter:kbps] - rate limit dip packets switch acl dip trtcm [dip] [portmap][CIR:kbps][CBS][PIR][PBS] - TrTCM dip packets switch acl port add [sport] [portmap] - drop src port packets switch acl L4 add [2byes] [portmap] - drop L4 packets with 2bytes payload switch add [mac] [portmap] - add an entry to switch table switch add [mac] [portmap] [vlan id] - add an entry to switch table switch add [mac] [portmap] [vlan id] [age] - add an entry to switch table switch clear - clear switch table switch del [mac] - delete an entry from switch table switch del [mac] [fid] - delete an entry from switch table switch dip add [dip] [portmap] - add a dip entry to switch table switch dip del [dip] - del a dip entry to switch table switch dip dump - dump switch dip table switch dip clear - clear switch dip table switch dump - dump switch table switch ingress-rate on [port] [Mbps] - set ingress rate limit on port 0~4 switch egress-rate on [port] [Mbps] - set egress rate limit on port 0~4 switch ingress-rate off [port] - del ingress rate limit on port 0~4 switch egress-rate off [port] - del egress rate limit on port 0~4 switch filt [mac] - add a SA filtering entry (with portmap 1111111) to switch table switch filt [mac] [portmap] - add a SA filtering entry to switch table switch filt [mac] [portmap] [vlan id] - add a SA filtering entry to switch table switch filt [mac] [portmap] [vlan id] [age] - add a SA filtering entry to switch table switch mymac [mac] [portmap] - add a mymac entry to switch table switch mirror monitor [portnumber] - enable port mirror and indicate monitor port number switch mirror target [portnumber] [0:off, 1:rx, 2:tx, 3:all] - set port mirror target switch phy [phy_addr] - dump phy register of specific port switch phy - dump all phy registers switch reg r [offset] - register read from offset switch reg w [offset] [value] - register write value to offset switch reg d [offset] - register dump switch sip add [sip] [dip] [portmap] - add a sip entry to switch table switch sip del [sip] [dip] - del a sip entry to switch table switch sip dump - dump switch sip table switch sip clear - clear switch sip table switch vlan dump - dump switch vlan table switch tag on [port] - egress tag on port 0~6 switch tag off [port] - egress untag on port 0~6 switch tag swap [port] - egress swap cvid<->stag on port 0~6 switch tag stack [port] - egress stack stag on port 0~6 switch pvid [port] [pvid] - set pvid on port 0~6 switch vlan set [idx] [vid] [portmap] <stag> <eg_con> <eg_tag> - set vlan id and associated member /opt/home/admin # switch vlan dump idx vid portmap eg-tag eg-con stag ivl fid 0 1 -1111-11 -uuuu-tt 0 0 1 - 1 2 1-----11 u-----tt 0 0 1 - 2 3 invalid 3 4 invalid 4 5 invalid 5 6 invalid 6 7 invalid 7 8 invalid 8 9 invalid 9 10 invalid 10 11 invalid 11 12 invalid 12 13 invalid 13 14 invalid 14 15 invalid 15 16 invalid PVID: port pvid prio 0 2 0 1 1 0 2 1 0 3 1 0 4 1 0 5 1 0 6 1 0 7 1 0
Updated