2019年12月27日 星期五

ser2net

https://linux.die.net/man/8/ser2net
https://groups.google.com/forum/#!topic/beagleboard/6am1GKyo60s
http://single9.net/2015/07/beaglebone-black-開啟-gpio-上的-uart-接腳/
tmux
tmate

2019年12月7日 星期六

A-law

A-law 將 signed magnitude 表示的 13-bit 線性語音編碼成 8-bit 值,如下表:
Linear inputCompressed code
XOR 01010101
Linear output
s0000000abcdxs000abcds0000000abcd1
s0000001abcdxs001abcds0000001abcd1
s000001abcdxxs010abcds000001abcd10
s00001abcdxxxs011abcds00001abcd100
s0001abcdxxxxs100abcds0001abcd1000
s001abcdxxxxxs101abcds001abcd10000
s01abcdxxxxxxs110abcds01abcd100000
s1abcdxxxxxxxs111abcds1abcd1000000
x: ignored
十進位二進位segEBI 前EBI 後解碼
3968~4095
...
2048~2175
011111xxxxxxx
...
010000xxxxxxx
11111111111
...
11110000
10101010 (0xAA)
...
10100101 (0xA5)
4032
...
2112
1984~2047
...
1024~1087
0011111xxxxxx
...
0010000xxxxxx
11011101111
...
11100000
10111010 (0xBA)
...
10110101 (0xB5)
2016
...
1056
992~1023
...
512~543
00011111xxxxx
...
00010000xxxxx
10111011111
...
11010000
10001010 (0x8A)
...
10000101 (0x85)
1008
...
528
496~511
...
256~271
000011111xxxx
...
000010000xxxx
10011001111
...
11000000
10011010 (0x9A)
...
10010101 (0x95)
504
...
264
248~255
...
128~135
0000011111xxx
...
0000010000xxx
01110111111
...
10110000
11101010 (0xEA)
...
11100101 (0xE5)
252
...
132
124~127
...
64~67
00000011111xx
...
00000010000xx
01010101111
...
10100000
11111010 (0xFA)
...
11110101 (0xF5)
126
...
66
62, 63
...
32, 33
000000011111x
...
000000010000x
00110011111
...
10010000
11001010 (0xCA)
...
11000101 (0xC5)
63
...
33
30, 31
...
0, 1
000000001111x
...
000000000000x
00010001111
...
10000000
11011010 (0xDA)
...
11010101 (0xD5)
31
...
1
-0, -1
...
-30, -31
100000000000x
...
100000001111x
00000000000
...
00001111
01010101 (0x55)
...
01011010 (0x5A)
-1
...
-31
-32, -33
...
-62, -63
100000010000x
...
100000011111x
00100010000
...
00011111
01000101 (0x45)
...
01001010 (0x4A)
-33
...
-63
-64~-67
...
-124~-127
10000010000xx
...
10000011111xx
01000100000
...
00101111
01111010 (0x7A)
...
01110101 (0x75)
-66
...
-126

2019年12月1日 星期日

Network Slicing

4G 網路主要是連接智慧型手機來服務人,應用場景較單純只需要一種網路。5G 加入了不同應用場景,除了擴充行動寬頻、還有萬物聯網 (IoT) 和關鍵任務型服務 (如車聯網) 的各種應用,都建制各自網路太昂貴,而是應該把一個實體網路切成多個虛擬網路,每個符合特定應用的容量、安全性、延遲、可靠度、計費方式等需求,各自不受干擾,這就是網路切片 (Network Slicing)。

使用 4G 網路主要終端設備是手機,網路部份包括無線接入網路 (RAN) 和核心網路 (Core Network),採用專用設備。為了做網路切片,需要網路功能虛擬化 (NFV,Network Function Virtualization),將 RAN 和 Core Network 專用設備的軟硬體轉移到商用虛擬主機 (VM),RAN 的部份叫邊緣雲 (Edge Cloud),核心網部分叫核心雲 (Core Cloud)。這些 VM 透過 SDN 互通。

針對不同應用的切片
手機切片:核心雲放 IMS
高解析影片切片:邊緣雲可能需要儲存設備暫存,經過核心雲上影片提供者網路
物聯網切片:不需要移動管理
車聯網切片:為了減低延遲,許多功能都放到邊緣雲。

RAN 佈建因基地台遠近等因數可能有好幾階 (tier),但延遲考量會使用越接近基地台的 VM,甚至擺到基地台裡。

SDN Controller 控制 SDN,SDN 需要保證切割的頻寬又不能造成太多延遲。
  • OTN (optical transport network) and Wavelength Slicing (Hard slicing):依據波長共用光纖網路 (DWDM、ROADM)。
  • Flexible Ethernet (FlexE) (Soft slicing):透過 TDM 方式減少延遲來提供動態頻寬。
  • Service Provisioning (L3 slicing): Segment Routing (TE) and Enhanced VPN:透過集中的 path computation element (PCE) 使用 source-based routing。

user plane functions (UPFs)、multi-access edge computing(MEC)、eCPRI、Time Sensitive Networking(TSN)、Telecom Infra Project (TIP) fronthaul

參考:
  1. 5G這把瑞士軍刀,如何網路切片?
  2. https://www.ecitele.com/wp-content/uploads/2019/03/Network-slicing-WP-F.pdf
  3. https://www.2cm.com.tw/2cm/zh-tw/market/FEB3C8CEEC624761B9F9276F9D93ABB6 
  4. http://www.telecom-marketforum.com/2019/exhibition16.html 
  5. http://www.ieee802.org/1/files/public/docs2018/detnet-tsn-wang-for-servcice-provider-networks-1118-v01.pdf
  6. https://www.fujitsu.com/us/Images/New-Transport-Network-Architectures-for-5G-RAN.pdf 
  7. https://www.itu.int/dms_pub/itu-t/opb/tut/T-TUT-HOME-2018-PDF-E.pdf

2019年11月29日 星期五

Cut-through Switching

傳統 Ethernet Switch 轉送封包的方式是 Store and forward,整個封包收到檢查 CRC 後再轉送,延遲計算是收到最後一個 bit 到送出第一個 bit 的時間。

而 Cut through 收到封包的 Destination MAC 就馬上開始進行轉送,減少接收剩下資料的延遲,但沒檢查 CRC 錯誤的封包沒丟棄。延遲計算是收到第一個 bit 到送出第一的 bit 的時間。

Fragment free

應用:需要很低延遲的應用。

Adaptive switching 是動態切換 cut-throught 或 store-and-forward。

Wormhole switching:封包切成 flits (flow control units)。通常第一個 flit (header flit) 有位址資訊建立到輸出口的連線,剩下 flits 沿用直到最後 flit (tail flits) 關閉連線。出口 buffer 滿了,後送 "back-pressure" 告知來源暫停傳送。

參考
  1. https://hlchang.com/2010/08/cut-through-捲土重來/
  2. https://en.wikipedia.org/wiki/Cut-through_switching
  3. https://en.wikipedia.org/wiki/Wormhole_switching

2019年11月23日 星期六

OpenWrt REVISION

由 scripts/getver.sh 產生


用途
  • base-files VERSION 一部分
  • VERSION_SED 取代 %R:用在 /etc/banner, /etc/openwrt_version, /etc/openwrt_release, /etc/device_info, /etc/opkg/distfeeds.conf
  • repositories.conf
  • mac80211 編譯 compat_version
  • netgear-dni、tplink-safeloader

ssh client

ssh client 的系統設定在 /etc/ssh/ssh_config,如果要個人設定,是寫在 ~/.ssh/config。

有個方便的用處是,當 ssh 伺服器不是使用預設通訊埠時,可以寫在設定檔裡,這樣 ssh 連線時就不用再額外指定通訊埠。此外也可以設定別名。

連線到伺服器有些情況會有 locale 問題,可以關掉 SendEnv。但由於 SendEnv 是累加的,不是不設 SendEnv 或將 SendEnv 設為空白就可以,如果 /etc/ssh/ssh_config 有設 SendEnv,也需要移除。

問題:no matching key exchange method found. Their offer: diffie-hellman-group1-sha1
  • 加參數 -oKexAlgorithms=+diffie-hellman-group1-sha1
  • 設定加入連線加密方法
  • 參考
ssh 是一個透過 SSH 加密連線登入遠端機器執行指令的程式,同時這個連線也可以用來轉送 X11 連線、任意 TCP port、和 UNIX-domain socket。

指令參數

  • -N:不執行遠端指令
  • -nNT:不開 tty
  • -f:背景執行 
  • -L:local port forwarding
  • -D:dynamic port forwarding
  • -R:remote port forwarding
  • -X:X11 Forwarding

SSH tunnel

local port forwarding

ssh client 近端一個 port 透過 SSH 通到 ssh server,然後存取遠端 remotehost:remoteport:

ssh -L localport:remotehost:remoteport user@example.com

連 ssh client 的 localport,相當於連到遠端的 remotehost:remoteport,SSH server 會去解析 remotehost。遠端位置可能是 Web Server、RDP Server、VNC Server 等。

dynamic port forwording

同 local port forwarding,但最終位置不指定,改依 L5 SOCKS 協定的 handshake 得知。可用於任何 TCP/UDP socket 連線。provide a local SOCKS 4/4A/5 proxy on a local port

ssh -D localport user@example.com

所有連 ssh client 的 localport,都會連到 SSH server 再去進行連線到最終位置。例如 Firefox 等瀏覽器可設定 SOCKS proxy 為 SSH client 的 localport,網頁就會透過 SSH server 去連線。參考:https://linuxize.com/post/how-to-setup-ssh-socks-tunnel-for-private-browsing/

remote port forwarding

遠端 ssh server 的一個 port 透過 SSH 通到 ssh client,然後存取近端的 localhost:port:

ssh -R 9000:localhost:3000 user@example.com

SSH server 預設不允許 remote port forwarding,啟用需要在 /etc/ssh/sshd_config

GatewayPorts yes

然後重啟

sudo service ssh restart

連遠端 ssh server 的 port,相當於連到近端的 localhost:port。

ssh client


PuTTY pieTTY Xshell FireSSH zterm
安裝 可免安裝 可免安裝 需要安裝,個人用免費 JavaScript 版,給 Firefox 使用 Java 版,用於各式瀏覽器,需要 Java 執行環境
拖曳傳擋
有 (sftp,需要輸入密碼、選目錄) 有 (sftp)

Tab



中文



判斷字元自動輸入



其它說明
基於 PuTTY,但沒隨時跟上更新

選項設定

ssh 依照下列優先來源取得設定:

  1. command-line options
  2. 個人設定檔:~/.ssh/config
  3. 系統設定檔:/etc/ssh/ssh_config

設定檔包含 host 規範的 section,只要符合指令行的主機名稱就有效 (見 CanonicalizeHostname)。由於每個參數使用第一個取得的值,越 host 特殊的宣告應該要放在前面,越通用的放後面。

設定檔包含 keyword-argument 對,每對一行。# 開始的行和空白行是註解。argument 可用双引號包起來,為了包含空白。Configuration options may be separated by whitespace or optional whitespace and exactly one ‘=’; the latter format is useful to avoid the need to quote whitespace when specifying configuration options using the ssh, scp, and sftp -o option.

keyword argument

keyword=argument

keyword =arguemnt

keyword 不分大小寫,argument 分大小寫。

Host

接下來設定區塊 (到下個的 Host 或 Match 為止) 適用的 host,多個用 whitespace 分隔。「*」表示所有 host。The host is usually the hostname argument given on the command line (見 CanonicalizeHostname).

A pattern entry may be negated by prefixing it with an exclamation mark (‘!’).  If a negated entry is matched, then the Host entry is ignored, regardless of whether any other patterns on the line match.  Negated matches are therefore useful to provide exceptions for wildcard matches.

See PATTERNS for more information on patterns.

Match

接下來設定區塊 (到下個的 Host 或 Match 為止) 適用的條件,可多個,前置驚嘆號否定。

all: 都符合。必須單獨使用或緊接著 canonicalfinal 之後。

canonical:遠端 hostname 有 canonicalization 時額外套用。

final:最後額外套用。

exec 指令:在 shell 在執行指令回 0 時。指令有 whitespace characters 要quoted,接受 token %%、%h、%i、%L、%l、%n、%p、%r、和 %u。

The other keywords' criteria must be single entries or comma-separated lists and may use the wildcard and negation operators described in the PATTERNS section.

host hostname:比對 HostnameCanonicalizeHostname 轉換過後 hostname 符合。

originalhost hostname:比對指令行原始 hostname 符合。

user user:比對遠端帳號符合。

localuser user:比對本地帳號符合。在系統設定檔較有用。

BatchMode
如果設為 yes,user interaction such as password prompts and host key confirmation requests will be disabled. In addition, the ServerAliveInterval option will be set to 300 seconds by default (Debian-specific). This option is useful in scripts and other batch jobs where no user is present to interact with ssh(1), and where it is desirable to detect a broken network swiftly. The argument must be yes or no (the default).
CanonicalizeHostname
控制是否進行 hostname canonicalization。參考:https://sleeplessbeastie.eu/2020/08/24/how-to-perform-hostname-canonicalization/

預設 no:使用系統 resolver 處理 hostname lookups。

設為 yes:不用 ProxyCommand 或 ProxyJump 的連線,嘗試使用 CanonicalDomains 後綴和 CanonicalizePermittedCNAMEs 規則來canonicalize 指令行的 hostname。

設為 always:也用在 proxied 的連線。

設為 enabled:the configuration files are processed again using the new target name to pick up any new configuration in matching Host and Match stanzas.

CheckHostIP

預設是 yes,額外檢查 known_hosts 檔的 host IP 位址,無論 StrictHostKeyChecking 的設定都會加 host 位址到 ~/.ssh/known_hosts,用來偵測 host key 是否因為 DNS spoofing 而改變。

If the option is set to no, the check will not be executed.

Hostname
實際要登入的 host name,可以是 nicknames or abbreviations,接受 token %% and %h,可以是數字 IP (both on the command line and in Hostname specifications). The default is the name given on the command line.
KexAlgorithms
指定可用的 KEX (Key Exchange) 演算法. Multiple algorithms must be comma-separated. If the specified list begins with a ‘+’ character, then the specified methods will be appended to the default set instead of replacing them. If the specified list begins with a ‘-’ character, then the specified methods (in‐ cluding wildcards) will be removed from the default set instead of replacing them. If the specified list begins with a ‘^’ char‐ acter, then the specified methods will be placed at the head of the default set. The default is: curve25519-sha256,curve25519-sha256@libssh.org, ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521, diffie-hellman-group-exchange-sha256, diffie-hellman-group16-sha512, diffie-hellman-group18-sha512, diffie-hellman-group14-sha256 The list of available key exchange algorithms may also be ob‐ tained using "ssh -Q kex".
NumberOfPasswordPrompts
密碼嘗試次數,預設是 3。
PasswordAuthentication
是否使用密碼認證,yes (預設) 或 no。
Port
遠端 port,方便不是預設的 22。
PreferredAuthentications
嘗試認證方式的順序,預設是 gssapi-with-mic,hostbased,publickey,keyboard-interactive,password。
ServerAliveInterval
Sets a timeout interval 秒數 after which if no data has been received from the server, ssh 會送 message to request a response from the server. The default is 0, indicating that these messages will not be sent to the server, or 300 if the BatchMode option is set (Debian-spe‐ cific). ProtocolKeepAlives and SetupTimeOut are Debian-specific compatibility aliases for this option.
StrictHostKeyChecking

預設是 ask,新 host 的 key 在使用者同意後加入 ~/.ssh/known_hosts。host key 改變會拒絕連線。

設為 accept-new,自動加新 host 的 key。host key 改變會拒絕連線。

設為 yes,使用者必須手動加入新 host 的 key。host key 改變會拒絕連線。提供 man-in-the-middle (MITM) 攻擊最大的保護, though it can be annoying when the /etc/ssh/ssh_known_hosts file is poorly maintained or when connections to new hosts are frequently made.

設為 no 或 off,自動加新 host 的 key。host key 改變會檢查,除了一些限制外,仍允許連線。

User
指定登入帳號。
UserKnownHostsFile

Specifies one or more files to use for the user host key database, separated by whitespace. 預設是「~/.ssh/known_hosts ~/.ssh/known_hosts2」。

設為 UserKnownHostsFile=/dev/null

VerifyHostKeyDNS

Specifies whether to verify the remote key using DNS and SSHFP resource records.

設為 yes, the client will implicitly trust keys that match a secure fingerprint from DNS. Insecure fingerprints will be handled as if this option was set to ask.

設為 ask, information on fingerprint match will be displayed, but the user will still need to confirm new host keys according to the StrictHostKeyChecking option.

預設是 no。

See also VERIFYING HOST KEYS in ssh(1).

PATTERNS

pattern 是 0 或更多 non-whitespace characters

*:代表 0 或更多 characters

?:代表 1 個 character

pattern-list 是逗號分隔的 pattern 列表。裡面的 pattern 可以前置驚嘆號來否定。要注意的是否定符合本身不會變成正面的符合結果,例如下列結果 host3 並不符合:

from="!host1,!host2"

一種解決方式是包含一項達到正面符合,如 wildcard:

from="!host1,!host2,*"

TOKENS

有些 keyword 的 argument 可用 token,意思如下:

%%%
%CHash of %l%h%p%r。
%d自己的家目錄。
%h遠端 hostname。
%i自己 user ID。
%L自己 hostname。
%l自己 hostname, including the domain name。
%n原始指令行的遠端 hostname。
%p遠端 port。
%r遠端 username。
%T請求 tunnel forwarding 指定的 tun 或 tap 網路界面,無則 "NONE"。
%u自己 username。

      CertificateFile accepts the tokens %%, %d, %h, %i, %l, %r, and %u.

      ControlPath accepts the tokens %%, %C, %h, %i, %L, %l, %n, %p, %r, and
     %u.

    

     IdentityAgent and IdentityFile accept the tokens %%, %d, %h, %i, %l, %r,
     and %u.

     LocalCommand accepts the tokens %%, %C, %d, %h, %i, %l, %n, %p, %r, %T,
     and %u.

     ProxyCommand accepts the tokens %%, %h, %n, %p, and %r.

     RemoteCommand accepts the tokens %%, %C, %d, %h, %i, %l, %n, %p, %r, and
     %u.

問題

參考

  1. http://stackoverflow.com/questions/7332124/gitolite-with-non-default-port
  2. man ssh
  3. 基於 sftp 的 sshfs
  4. http://blog.trackets.com/2014/05/17/ssh-tunnel-local-and-remote-port-forwarding-explained-with-examples.html
  5. Bash ssh 由歷史資料來自動補齊主機名稱
  6. man ssh_config

SEE ALSO

     scp(1), ssh-add(1), ssh-agent(1), ssh-argv0(1), ssh-keygen(1),
     ssh-keyscan(1), tun(4), ssh-keysign(8), sshd(8)
待讀
https://www.bitvise.com/remote-desktop
http://www.howtogeek.com/114812/5-cool-things-you-can-do-with-an-ssh-server/
http://www.linuxjournal.com/content/more-secure-ssh-connections?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+linuxjournalcom+%28Linux+Journal+-+The+Original+Magazine+of+the+Linux+Community%29
http://www.cyberciti.biz/faq/install-ssh-identity-key-remote-host/
[Linux 透過 SSH SOCKS 連線 來 使用 Firefox / Pidgin(MSN, GTalk..)](https://blog.longwin.com.tw/2010/01/linux-ssh-socks-firefox-pidgin-2010/)

2019年11月16日 星期六

sftp

sftp 是一個類似 ftp 的互動式檔案傳送程式,但使用加密的 ssh 傳輸,可使用許多 ssh 功能,例如公鑰認證和壓縮。和 ftp 一樣。sftp 也可以直接取得特定檔案。

指令格式
sftp [-46aCfpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
     [-D sftp_server_path] [-F ssh_config] [-i identity_file] [-l limit]
     [-o ssh_option] [-P port] [-R num_requests] [-S program]
     [-s subsystem | sftp_server] host

sftp [user@]host[:file ...] #取得特定檔案
sftp [user@]host[:dir[/]] #指定遠端起始目錄
sftp -b batchfile [user@]host #自動 session

因為有些用法使用分號區隔主機名稱和檔名路徑,IPv6 位址需要用方括號來區別。

參數:見 man sftp。

指令:類似 ftp 用的指令,不分大小寫,有 space 的檔名路徑需要加 quotes,pathname 的特殊字元 (見 glob() 函數) 需要 backslashes (‘\’) 跳脫。見 man sftp。

參考:

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...