載點:https://sourceforge.net/projects/extraputty/
PHY暫存器的地址空間為5位,從0到31最多可以定義32個暫存器(隨著晶片功能不斷增加,很多PHY晶片採用分頁技術來擴充套件地址空間以定義更多的暫存器),IEEE802.3定義了地址為0-15這16個暫存器的功能,地址16-31的暫存器留給晶片製造商自由定義,如下表所示。
(1)官方介紹請參考IEEE802.3標準的22.2.4 Management functions節。
(2)上圖的B和E表示了,在特定介面下,暫存器是基本的還是擴充套件的。例如:MII介面下只有0和1暫存器是基本的,其它的是擴充套件的。注意:所為擴充套件是指留給IEEE以後的擴充套件特性用,不是給PHY廠商的擴充套件,PHY廠商自定義的只能是16~31號暫存器
(3)在IEEE標準文件及某些PHY手冊中,某暫存器的位元(bit)用X.y表示,如0.15表示第0暫存器的第15位。
暫存器0是PHY控制暫存器,通過Control Register可以對PHY的主要工作狀態進行設定。應該保證控制暫存器每個位的預設值,以便在沒有管理干預的情況下,上電或復位時PHY的初始狀態為正常操作狀態。Control Register的每一位完成的功能見下。
(1)一般要改變埠的工作模式(如速率、雙工、流控或協商資訊等)時,在設定完相應位置的暫存器之後,需要通過Reset位復位PHY來使配置生效。
(2)該位元位的預設值為 0。
(1)需要注意的是,很多時候PHY設定Loopback後端口可能就Link down了,MAC無法向該埠發幀,這時就需要通過設定埠Force Link up才能使用Loopback功能。
(2)該位元位的預設值為 0。
如果PHY通過位元1.15:9和位元15.15:12報告它不能工作在所有速度時,則位元0.6和0.13的值應該與PHY可以操作的速度相對應。並且任何試圖將該位設定為無效的操作均將被忽略。
(1)對Speed Selection的修改設定,往往需要復位端口才能配置生效。因此在設定該位置的時候需要檢查自動協商的設定並通過Bit15復位埠。
(2)位0.6和0.13的預設值是根據位1.15:9和15.15:12所指示的PHY可以操作的***最高資料速率***的編碼組合。
必須注意的是,對於1000BASE-T介面,自動協商必須開啟。
(1)Power Down模式一般在軟體shut down埠的時候使用,需要注意的是埠從Power Down模式恢復,需要復位埠以保證埠可靠的連線。
(2)該位的預設值為 0。
(1)IEEE802.3沒有對Isolate 時MDI介面的狀態進行規範,此時MDI端可能還在正常執行。Isolate在實際應用中並沒有用到。
(2)由於目前很多百兆的PHY晶片其MAC介面主流的都是SMII/S3MII,8個埠的介面是相互關聯的,一個埠設定Isolate可能會影響其他埠的正常使用,因此在使用中注意不要隨意更改bit10的狀態。
一般在修改埠的自動協商能力資訊之後通過Bit9置1重新啟動自動協商來使埠按照新的配置建立link。
如果PHY通過位1.15:9和15.15:12報告它只能在一個雙工模式下工作,則位0.8的值應該與PHY可以工作的模式相對應,並且任何嘗試改變將該位0.8修改為無效指的操作應被忽略。
對Duplex Mode的修改配置也需要復位端口才能生效。
暫存器1是PHY狀態暫存器,主要包含PHY的狀態資訊,大多數bit的值都是由晶片廠家確定的,每一個bit的功能在表3種已有詳細說明。
暫存器中各位的詳細說明如下:
在除錯以及異常故障處理時,可以通過該位暫存器的狀態判斷AN是否成功,從而進一步的檢查AN相關的設定是否正確,或者晶片的AN功能是否正常等。
暫存器2和3存放PHY晶片的型號程式碼,暫存器2(PHY ID1)為高16位,而暫存器3(PHY ID2)為低16位。由晶片製造商自行定義,實際應用中軟體通過讀取這兩個暫存器的內容可以識別PHY的型號和版本。
PHY識別符號應由由IEEE分配給PHY製造商的組織唯一識別符號(OUI)的(只需要使用第3至第24位,共22位),加上6位製造商的型號以及4位製造商的修訂版編號組成。 PHY識別符號旨在提供足夠的資訊來支援30.1.2中所要求的oResourceTypeID物件。
OUI的第三位分配給位2.15,OUI的第四位分配給位2.14,依此類推。 位2.0包含OUI的第十八位。 位3.15包含OUI的第十九位,位3.10包含OUI的第二十四位。 位3.9包含製造商型號的MSB。 位3.4包含製造商型號的LSB。 位3.3包含製造商版本號的MSB,位3.0包含製造商版本號的LSB。具體如下圖所示:
暫存器4是自動協商的能力通告暫存器,在AN Enable的前提下(見暫存器0),埠根據該暫存器的相關配置將自動協商資訊通過FLP在MDI上進行通告。當AN配置為Disable狀態的時候,暫存器4的配置將不起作用,埠的工作模式由控制暫存器中的配置決定。
該暫存器包含PHY的通告能力,它們將在自動協商期間傳送給其連結夥伴。 基本頁的位定義在IEEE標準的28.2.1.2中定義。 上電時,在自動協商開始之前,該暫存器應具有以下預設配置:
在FLP Burst內傳輸的基本鏈路程式碼字(基本頁面)應該傳達如圖28-7所示的編碼。 自動協商功能可以使用下一頁功能支援其他頁面。 下一頁交換中使用的連結程式碼字的編碼在28.2.3.4中定義。 在FLP Burst中,D0應該是第一個傳輸的位。
下一頁功能使用標準的自動協商仲裁機制來允許交換任意的資料。 資料由可選的下一頁資訊攜帶,其遵循用於基本連結碼字的傳輸和確認過程。 定義了四種類型的下一頁編碼:訊息頁面,未格式化頁面,擴充套件訊息頁面和擴充套件的未格式化頁面。
關於該部分,具體見IEEE標準的28.2.3.4 Next Page function。
在IEEE標準中,Auto-Negotiation Advertisement Register中的各部分全部是在獨立章節中進行介紹的。具體如下:
暫存器5儲存的是本端PHY接收到的對端PHY所通告的埠能力,暫存器5的結構和暫存器4基本一致。
暫存器6儲存了PHY自動協商過程的異常資訊。從這個寄存其中我們可以獲取到Link Partner子否支援自動協商以及自動協商下一頁有沒有收到的資訊。
自動協商下一頁傳送暫存器包含在支援下一頁功能時要傳送的下一頁連結碼字。 (見表28-6)內容在28.2.3.4中定義。 上電時,該暫存器應包含預設值2001H,該值表示訊息程式碼設定為Null訊息的訊息頁面。 該值可以由裝置希望傳輸的任何有效的下一頁訊息程式碼替換。 寫入該暫存器應將mr_next_page_loaded設定為true。
https://blog.csdn.net/sternlycore/article/details/89065789
from:https://blog.csdn.net/derek_yi/article/details/8743146
GPON TYPE B保護的組網圖如圖1所示,相應的保護範圍包括OLT的主用和備用PON端口,主用和備用光纖。

場景一:PON口工作過程中主用光纖斷,如圖2所示。

Standby PON口在進入Standby狀態後,啟動上行光信號檢測功能。
Active PON口檢測到LOS告警(主用光纖斷引起的LOS告警),立即關閉主用GPON端口光模塊發送功能。
Standby PON口檢測到主用PON口LOS告警,打開GPON端口光模塊發送功能並進行ONU測試操作。
如果Standby PON口光纖正常,並發現ONU,便上報端口LOS恢復告警。
Active PON口切換為Standby狀態,並啟動上行光檢測功能。Standby PON口被設置為Active狀態。至此倒換處理過程結束。
場景二:PON口相關聯的ONU全部離線,如圖3所示。

Standby PON口在進入Standby狀態後,啟動上行光信號檢測功能。
Active PON口檢測到LOS告警(所有ONU全部離線引起的LOS告警),立即關閉GPON端口光模塊發送功能。
Standby PON口檢測到主用PON口LOS告警,打開GPON端口光模塊發送功能並進行ONU測試操作。
由於PON口下沒有ONU在線,設備會一直進行主用端口與備用端口的循環檢測,直到有ONU上線。
當ONU上線的時候,PON端口沒有進行倒換。
Starting with kernel 4.6, support for MACsec has been added in Linux so it won’t be needed to use a release candidate to test this feature.
There are two ways to implement MACsec:
This is the topology that is being used to demonstrate most of the implementation of MACsec on Linux and the purpose is to have connectivity between the two hosts using MACsec.

Between the two hosts there is a L2VPN that is provided by the QFX10K switches.
I won’t discuss how to set up the L2VPN as we already did this several times, one example being L2circuit for L2 protocol tunneling.
On top of this, we want to have additional security at Layer 2 between the two Linux hosts, hence MACsec is the suitable option here.
There are few prerequisites for running MACsec on Linux. I won’t mention here that you need a kernel that supports MACsec:
This is how you perform these two operations
git clone git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git cd iproute2/ ./configure make make install modprobe macsec
So let’s move further with the configuration.
The required steps to configure MACsec are the following:
First we need to know the MAC addresses of the two hosts between which MACsec will be configured. Each host needs to know from what MAC address will receive protected traffic.
This is UBUNTU-1:
root@UBUNTU-1:~# ifconfig eth1 eth1 Link encap:Ethernet HWaddr 56:68:a6:6f:08:d1 inet6 addr: fe80::5468:a6ff:fe6f:8d1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:114 errors:2 dropped:91 overruns:0 frame:2 TX packets:158 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:30957 (30.9 KB) TX bytes:26724 (26.7 KB) root@UBUNTU-1:~#
And this is UBUNTU-2:
root@UBUNTU-2:~# ifconfig eth1 eth1 Link encap:Ethernet HWaddr 56:68:a6:6f:08:d6 inet6 addr: fe80::5468:a6ff:fe6f:8d6/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:63 errors:2 dropped:36 overruns:0 frame:2 TX packets:163 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:15079 (15.0 KB) TX bytes:27392 (27.3 KB) root@UBUNTU-2:~#
Let’s see the configuration for UBUNTU-1(the last two commands are also adding an IP address on the newly created interface and bring it up so we can test later on the IP reachability between the hosts):
ip link add link eth1 macsec0 type macsec
Creates the MACsec device on eth1 interface
ip macsec add macsec0 tx sa 0 pn 1 on key 01 12345678901234567890123456789012
Configure the transmit secure association, the packet number used as the start ID for the packets sent through this SA and the key.
ip macsec add macsec0 rx address 56:68:a5:c2:37:76 port 1 ip macsec add macsec0 rx address 56:68:a5:c2:37:76 port 1 sa 0 pn 1 on key 02 09876543210987654321098765432109
Configure the receive channel and receive association based on the peer MAC address, the port number, the first packet number expected and the key.
ip link set dev macsec0 up ifconfig macsec0 10.10.12.1/24
These two bring up the interface and configure an IP address on macsec0 interface.
Remember that the transmit SA key has to match the peer’s receive SA key and the other way around.
And this is the configuration for UBUNTU-2:
ip link add link eth1 macsec0 type macsec ip macsec add macsec0 tx sa 0 pn 1 on key 02 09876543210987654321098765432109 ip macsec add macsec0 rx address 56:68:a5:c2:4c:14 port 1 ip macsec add macsec0 rx address 56:68:a5:c2:4c:14 port 1 sa 0 pn 1 on key 01 12345678901234567890123456789012 ip link set dev macsec0 up ifconfig macsec0 10.10.12.2/24
Once the configuration is applied on both sides, you can check the MACsec configuration:
root@UBUNTU-1:~# ip macsec show 8: macsec0: protect on validate strict sc off sa off encrypt off send_sci on end_station off scb off replay off cipher suite: GCM-AES-128, using ICV length 16 TXSC: 5668a5c24c140001 on SA 0 0: PN 12, state on, key 12345678901234567890123456789012 RXSC: 5668a5c237760001, state on 0: PN 12, state on, key 09876543210987654321098765432109 root@UBUNTU-1:~#
As you can see the traffic is authenticated and encrypted by default using AES-GCM-128.
From the above output, some packets protected by MACsec exited and entered this device(“PN 12” shows this, we started at 1).
Let’s send some packets between the two hosts:
root@UBUNTU-1:~# ping 10.10.12.2 -c 3 PING 10.10.12.2 (10.10.12.2) 56(84) bytes of data. 64 bytes from 10.10.12.2: icmp_seq=1 ttl=64 time=24.3 ms 64 bytes from 10.10.12.2: icmp_seq=2 ttl=64 time=20.8 ms 64 bytes from 10.10.12.2: icmp_seq=3 ttl=64 time=19.3 ms --- 10.10.12.2 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 19.367/21.533/24.388/2.106 ms root@UBUNTU-1:~# ip macsec show 8: macsec0: protect on validate strict sc off sa off encrypt off send_sci on end_station off scb off replay off cipher suite: GCM-AES-128, using ICV length 16 TXSC: 5668a5c24c140001 on SA 0 0: PN 15, state on, key 12345678901234567890123456789012 RXSC: 5668a5c237760001, state on 0: PN 15, state on, key 09876543210987654321098765432109 root@UBUNTU-1:~#
As you can see, the packet number increased.
You can also check detailed statistics about the MACsec traffic like this:
root@UBUNTU-1:~# ip -s macsec show 8: macsec0: protect on validate strict sc off sa off encrypt off send_sci on end_station off scb off replay off cipher suite: GCM-AES-128, using ICV length 16 TXSC: 5668a5c24c140001 on SA 0 stats: OutPktsUntagged InPktsUntagged OutPktsTooLong InPktsNoTag InPktsBadTag InPktsUnknownSCI InPktsNoSCI InPktsOverrun 0 0 0 9 0 0 0 0 stats: OutOctetsProtected OutOctetsEncrypted OutPktsProtected OutPktsEncrypted 14 0 1572 0 0: PN 15, state on, key 12345678901234567890123456789012 OutPktsProtected OutPktsEncrypted 14 0 RXSC: 5668a5c237760001, state on stats: InOctetsValidated InOctetsDecrypted InPktsUnchecked InPktsDelayed InPktsOK InPktsInvalid InPktsLate InPktsNotValid InPktsNotUsingSA InPktsUnusedSA 668 0 0 0 6 0 0 0 0 0 0: PN 15, state on, key 09876543210987654321098765432109 InPktsOK InPktsInvalid InPktsNotValid InPktsNotUsingSA InPktsUnusedSA 6 0 0 0 0 root@UBUNTU-1:~#
Two optional features that increase the security on MACsec traffic are encryption and replay protection.
Let’s see how these are configured.
First the encryption:
ip link set macsec0 type macsec encrypt on
Remember that we were at PN 15. Let’s send another 3 packets using ping and then check the statistics:
root@UBUNTU-1:~# ip macsec show 8: macsec0: protect on validate strict sc off sa off encrypt on send_sci on end_station off scb off replay off cipher suite: GCM-AES-128, using ICV length 16 TXSC: 5668a5c24c140001 on SA 0 0: PN 19, state on, key 12345678901234567890123456789012 RXSC: 5668a5c237760001, state on 0: PN 19, state on, key 09876543210987654321098765432109 root@UBUNTU-1:~# ip -s macsec show 8: macsec0: protect on validate strict sc off sa off encrypt on send_sci on end_station off scb off replay off cipher suite: GCM-AES-128, using ICV length 16 TXSC: 5668a5c24c140001 on SA 0 stats: OutPktsUntagged InPktsUntagged OutPktsTooLong InPktsNoTag InPktsBadTag InPktsUnknownSCI InPktsNoSCI InPktsOverrun 0 0 0 23 0 0 0 0 stats: OutOctetsProtected OutOctetsEncrypted OutPktsProtected OutPktsEncrypted 14 4 1572 464 0: PN 19, state on, key 12345678901234567890123456789012 OutPktsProtected OutPktsEncrypted 14 4 RXSC: 5668a5c237760001, state on stats: InOctetsValidated InOctetsDecrypted InPktsUnchecked InPktsDelayed InPktsOK InPktsInvalid InPktsLate InPktsNotValid InPktsNotUsingSA InPktsUnusedSA 668 464 0 0 10 0 0 0 0 0 0: PN 19, state on, key 09876543210987654321098765432109 InPktsOK InPktsInvalid InPktsNotValid InPktsNotUsingSA InPktsUnusedSA 10 0 0 0 0 root@UBUNTU-1:~#
As you can see, we are now at PN 19, which means that actually there were 4 packets that were sent.
Three of them were the ICMP packets and one of them was the ARP Request.
The 4 packets have a total size of 464B. Let’s decompose the ICMP Request packet:
IP – 20B
ICMP – 64B
ICV – 16B
SecTag – 16B
Ethernet – 14
So a total of 130B and this means that 3 ICMP Request packets are 390B, which leave us 74B for the ARP Request packet which is broken down like this:
ARP – 28B
ICV – 16B
SecTag – 16B
Ethernet – 14
Actually doing a tcpdump on UBUNTU-2 while an ICMP Request/Reply was received/sent, you can see that the size is 130B:
root@UBUNTU-2:~# tcpdump -i eth1 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes 07:51:20.389014 56:68:a5:c2:4c:14 (oui Unknown) > 56:68:a5:c2:37:76 (oui Unknown), ethertype Unknown (0x88e5), length 130: 07:51:20.389190 56:68:a5:c2:37:76 (oui Unknown) > 56:68:a5:c2:4c:14 (oui Unknown), ethertype Unknown (0x88e5), length 130: ^C 2 packets captured 2 packets received by filter 0 packets dropped by kernel root@UBUNTU-2:~#
You can also see the MACsec ether-type, 0x88e5.
This is how you can enable the replay protection:
ip link set macsec0 type macsec replay on window 128
You can see that encryption and replay protection are enabled by checking the MACsec configuration:
root@UBUNTU-1:~# ip macsec show 8: macsec0: protect on validate strict sc off sa off encrypt on send_sci on end_station off scb off replay on window 128 cipher suite: GCM-AES-128, using ICV length 16 TXSC: 5668a5c24c140001 on SA 0 0: PN 40, state on, key 12345678901234567890123456789012 RXSC: 5668a5c237760001, state on 0: PN 40, state on, key 09876543210987654321098765432109 root@UBUNTU-1:~#
And this would be the basic configuration that you need to enable MACsec to protect the Layer 2 traffic.
I also tried to enable MACsec on bond links(aggregated interfaces or port-channels how they are named in networking vendors terminology), but I wasn’t able to do it.
In case of bond interfaces, the macsec devices are enslaved instead of the physical links and the macsec devices are created on the physical links. However, I wasn’t allowed to enslave the macsec devices in the bond for some reason.
I hope you found this post useful.
References:
ddrescue is a tool that can be used to repair and clone disks on a Linux system . This includes hard drives, partitions, DVD discs, flas...