2022年9月23日 星期五

IPv6

Fragment

IPv6 基本上不做 Fragment,先透過 Path MTU Discovery 讓傳送端依照 MTU 送,就不需要 Fragment,所以標準 IPv6 封頭沒有 Fragmentation 支援。

透過 extension header,仍可以包含 fragmentation 資訊。

https://lirobo.blogspot.com/2022/09/internet-protocol.html

IPv4

16-bit Identification (ID)

  • 規定在特定來源位址、目的位址、和協定下,每個 datagram 要有不同值,但實際只用在 Fragmentation 和 Reassembly,Fragment 後沿用同樣 ID。其它有些實作並不改變 ID。
  • 在 maximum datagram lifetime (MDL) 內會有唯一的值,和建議的 reassembly timeout 有關,典型 MDL 是 2 分鐘 [RFC791] [RFC1122]。這樣限制了兩點間單一協定在典型 MTU 1500 時的速度上限為 6.4 Mbps [RFC4963],在高速裝置常會違反而變得沒有意義。
  • RFC1122 提到的 datagram de-duplication 用途,仍可以如同 IPv6 unfragmented datagrams 用 hash-based duplicate detection 達成 [RFC6621]。
  • 不改變 ID 導致如 RObust Header Compression (ROHC) [RFC5225] 支援。
  • 參考 RFC6864

3-bit Flags (0DM)

  • 0-bit:保留,沒用。
  • D-bit 表示 Do not Fragment (DF),不進行 Fragment。可用做 path MTU discovery。
  • M-bit 表示 More Fragments (MF)。Fragment 後沿用同樣 ID,除了最後封包外都設 M-bit。

13-bit Fragment Offset

  • IP Payload 的 Offset,採 8 的倍數。

IPv4 位址

https://lirobo.blogspot.com/2022/09/internet-protocol.html

https://lirobo.blogspot.com/2018/08/ipv4-and-ipv6-identification-and.html

https://lirobo.blogspot.com/2010/03/ipv4-link-local-addressing.html

https://lirobo.blogspot.com/2014/09/ether-type.html

2022年9月16日 星期五

Internet Protocol

IPv4

IPv6

https://lirobo.blogspot.com/2018/08/simple-history-of-ip-protocol_23.html

https://lirobo.blogspot.com/2018/08/ipv4-and-ipv6-identification-and.html

https://lirobo.blogspot.com/2020/03/ip-multicast.html

https://lirobo.blogspot.com/2010/10/ipsec.html

2022年9月10日 星期六

參數 (Parameter) vs. 引數 (Argument)

參數 (Parameter) 是函數的變數,宣告在函數的方法宣告。

引數 (Argument) 用來呼叫函數。

參考:https://notfalse.net/6/arg-vs-param

PWM 馬達調速電路

555 控制 PWM 馬達控制

https://www.circuits-diy.com/dc-motor-speed-control-circuit-using-555-timer-ic/

工作電壓:DC4.5-35V

輸出電流:0-5A

輸出功率:90W max.

靜態電流:7uA

PWM 占空比:1-100%

PWM 頻率:20kHz

https://www.circuits-diy.com/pwm-dc-motor-controller-using-ne555-timer-ic-electronics-project/ 

https://jin-hua.com.tw/webc/html/product/show.aspx?num=29768 (5-35V 或 3-15V)

2022年7月23日 星期六

stty

類比 tcgetattr() 和 tcsetattr() 改變終端機屬性的指令。

顯示精簡屬性 (settings that deviate from sane values.):

$ stty
speed 38400 baud; line = 0;
-brkint -imaxbel iutf8

顯示所有屬性 (here carried out on a virtual console):

$ stty -a
speed 38400 baud; rows 25; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke
  • 第 1 行:終端機 line speed、window size、和 line discipline (0 代表 N_TTY,new line discipline)。
  • 再來 3 行:終端機特殊字元設定。min 和 time 用在 noncanonical 模式輸入。
  • 剩下依序是 c_cflag, c_iflag, c_oflag, and c_lflag,前置 hyphen (-) 代表關閉,否則啟用。

將中斷字元改為 Ctrl-L:

$ stty intr Ctrl-L
$ stty intr 014
$ stty intr 0xC
$ stty intr <實際字元>

如果要設定的字元會被 shell 或終端機驅動程式特別解釋,需要前置 literal next character (通常是 ^V):

$ stty intr Ctrl-VCtrl-L

啟用或停用 TOSTOP

$ stty tostop
$ stty -tostop

有時程式改變終端機屬性而當掉卡住,可輸入:

Ctrl-J stty sane Ctrl-J

來回復 terminal flags 和特殊字元為 reasonable 狀態。Ctrl-J (ASCII 10) 是換行。在有些模式,終端機驅動程式不再對應 Enter 鍵 (ASCII 13) 到換行字元。第一個 Ctr-J 確保全新的指令行。

操作在指定終端機,不是 standard input,需要有權限:

# stty -a -F /dev/tty3
# stty -a < /dev/tty3

將中斷字元改為 Ctrl-L:

$ stty intr Ctrl-L
$ stty
speed 38400 baud; line = 0;
intr = ^L;

開始 sleep,發現 Ctrl-C 沒作用,只是 echoed:

$ sleep 10
^C

Ctrl-L 結束 sleep,顯示 termination status:

$ echo $?
130

130 表示程式由 signal number 130 – 128 = 2 (SIGINT) 所殺。

然後停用中斷字元:

$ stty intr undef
$ stty
speed 38400 baud; line = 0;
intr = <undef>;

現在 Ctrl-C 和 Ctrl-L 都不會產生 SIGINT signal,必須用 Ctrl-\ 代替來結束程式:

$ sleep 10
^C^L Control-C and Control-L are simply echoed
Type Control-\ to generate SIGQUIT
Quit
$ stty sane Return terminal to a sane state

參考

  1. TLPI §62

2022年7月9日 星期六

kernel Link Layer Multicast

struct dev_mc_list *mc_list; // multicast 位址列表,透過 dev_mc_add() 和 dev_mc_delete() 新增和移除。

int mc_count; // multicast 位址數目

int allmult; // 接收所有 multicast 封包

SIP header Via

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