Fragment
IPv6 基本上不做 Fragment,先透過 Path MTU Discovery 讓傳送端依照 MTU 送,就不需要 Fragment,所以標準 IPv6 封頭沒有 Fragmentation 支援。
透過 extension header,仍可以包含 fragmentation 資訊。
Fragment
IPv6 基本上不做 Fragment,先透過 Path MTU Discovery 讓傳送端依照 MTU 送,就不需要 Fragment,所以標準 IPv6 封頭沒有 Fragmentation 支援。
透過 extension header,仍可以包含 fragmentation 資訊。
16-bit Identification (ID)
3-bit Flags (0DM)
13-bit Fragment Offset
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/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
Network block devices (NBD) 是 client/server 架構,server 提供遠端儲存裝置或檔案,給 client 對應為本地裝置檔,可開機等。也可以格式化、modify or copy 整個分割,這在 NFS 是不行的,因為這些動作需要 unmount 才能進行,而 unmount 就失去連線了。
問題:NFS 似乎可以提供給多個 client 使用,而 NBD 似乎只能給一個 client 使用。
apt-get install nbd-server modprobe nbd nbd-server 9999 /dev/sda # export a device on port 9999 nbd-server 9998 vmdisk.img # export image file on port 9998Client
apt-get install nbd-client modprobe nbd-client # map remote NBD as local device nbd-client 192.168.1.100 9999 /dev/nbd0 nbd-client 192.168.1.100 9998 /dev/nbd1
然後可以 format it、可以 resize partitions、可以建立檔案系統...
問題:Server export 後,Server 可以使用嗎?
https://medium.com/@aysadx/linux-nbd-introduction-to-linux-network-block-devices-143365f1901b
https://www.kernel.org/doc/html/latest/admin-guide/blockdev/nbd.html
https://nbd.sourceforge.io/
dnsmasq (Wikipedia) 是輕量級的 DNS forwarder 加 DHCP Server:
設定
--server=[/[domain]/[domain/]][ipaddr[#port]][@interface][@source-ip[#port]]
https://thekelleys.org.uk/dnsmasq/doc.html
Remote Authentication Dial-In User Service (RADIUS) 是主從式網路應用協定,提供用戶使用網路服務集中式認證、授權、和記帳 (Authentication, Authorization, and Accounting, AAA) 管理,定義在 RFC2865 和 RFC2866。
+---------+ +------------+ +------+ +-----+ | RADIUS | | RADIUS | | User | | NAS | | Server | | Accounting | +--+---+ +--+--+ +----+----+ +------+-----+ | 連線請求 (用戶名、密碼) | | | |---------------------->| Access-Request | | | |---------------->| | | | Access-Accept | | | 連線通知 |<----------------| | |<----------------------| | | | Accounting-Request start | | |------------------------------->| | | Accounting-Response | | |<-------------------------------| / / / / / / | 斷線請求 | | |---------------------->| Accounting-Request stop | | |------------------------------->| | | Accounting-Response | | 斷線通知 |<-------------------------------| |<----------------------| |
RADIUS Server 使用 UDP port 1812。早期用 UDP port 1645 會和「datametrics」衝突。RADIUS Accounting Server 使用 UDP port 1813。早期用 UDP port 1646 會和「sa-msg-port」衝突。
封包格式 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Code | Identifier | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Authenticator |
| 16 octets |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Attributes ...
+-+-+-+-+-+-+-+-+-+-+-+-+-
0 1 2 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Type | Length | Value ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+Length 值包含 Type、Length、和 Value,最小是 2。Value 的格式和長度由 Type 和 Length 決定,完整 Type 列表見 IANA。Value 的類型有:
| # | type | len | value | 說明 |
|---|---|---|---|---|
| 5 | NAS-Port | 6 | integer | 用戶使用的界面編號。 |
| 26 | Vendor-Specific | ≥7 | vsa | 4-byte Vender-Id + string。Vendor-Id 是 Vendor 的 SMI Network Management Private Enterprise Code。string 由 Vendor 自行定義,例如 1-octet vendor type + 1-octet length + value。 |
| 40 | Acct-Status-Type | 6 | enum | Accounting-Request 記帳開始或結束: 1=Start 2=Stop 3=Interim-Update 7=Accounting-On 8=Accounting-Off 9-14=Reserved for Tunnel Accounting 15=Reserved for Failed |
| 41 | Acct-Delay-Time | 6 | integer | 送這個紀錄時延遲的秒數。 |
| 42 | Acct-Input-Octets | 6 | integer | |
| 43 | Acct-Output-Octets | 6 | integer | |
| 44 | Acct-Session-Id | ≥3 | text | 方便 |
| 45 | Acct-Authentic | 6 | enum | Accounting-Request 時表示認證方式 |
| 46 | Acct-Session-Time | 6 | integer | 服務秒數,Accounting-Request 的 Acct-Status-Type=Stop 時回報。 |
| 47 | Acct-Input-Packets | 6 | integer | |
| 48 | Acct-Output-Packets | 6 | integer | |
| 49 | Acct-Terminate-Cause | 6 | enum | |
| 50 | Acct-Multi-Session-Id | ≥3 | text | |
| 51 | Acct-Link-Count | 6 | integer | |
| 61 | NAS-Port-Type | 6 | enum | 用戶使用的界面類型: 0=Async 1=Sync 2=ISDN Sync 3=ISDN Async V.120 4=ISDN Async V.110 5=Virtual 6=PIAFS 7=HDLC Clear Channel 8=X.25 9=X.75 10=G.3 Fax 11=SDSL 12=ADSL-CAP 13=ADSL-DMT 14=IDSL 15=Ethernet 16=xDSL 17=Cable 18=Wireless - Other 19=Wireless - IEEE 802.11 |
| 87 | NAS-Port-Id | ≥3 | text | 描述用戶使用的界面。例如「ISDN 7/2:D:1」。 |
服務開始:送 Accounting Start (type of service being delivered and the user it is being delivered to) 給 RADIUS Accounting server 服務結束:送 Accounting Stop (type of service that was delivered and optionally statistics such as elapsed time, input and output octets, or input and output packets) 給 RADIUS Accounting server Accounting-Request (whether for Start or Stop) 成功的話 RADIUS Accounting server 回 Accounting-Response acknowledgment 建議 Client continue attempting to send the Accounting-Request 直到收到 acknowledgement, using some form of backoff. alternate server (after a number of tries to the primary server fail, or in a round-robin fashion)
Accounting-Request 的 Attribute如果 Accounting-Request 有 invalid Length,整個 request MUST be silently discarded。
軟體定義網路 (Software-defined networking, SDN) 架構大略分為應用層、控制層以及基礎架構層三層。
| 應用層 |
|---|
| 北向 API |
| 控制層 |
| 南向 API |
| 基礎架構層 |
控制層由控制器 (Controller) 負責,集中管理眾多網路設備,讓網路設備專注於封包傳遞,網管人員能以高階軟體的方式調整網路的決策,提升網路資源管控和管理效率。對應用層界面是 Northbound API,對基礎架構層是 Southbound API。基礎架構層 (資料層、Data Layer、Forwarding Layer)由各種網路設備所組成,透過 Southbound API 將設備資訊送到控制器內做整合,並接受控制器的訊息對 flow table 等設備內的設定作調整。控制層內由許許多多模組組成一個可以應付各種需求的控制器。應用層由許多 Forwarding、Firewall 和 Security 等應用所組成,透過 Northbound API 取得整個 SDN 網路的相關資訊去做相對應處理。
例如有個應用想要建立一條從主機 A 到主機 B 的路線,只需要告訴控制器,控制器根據內部現有的網路拓樸計算出最佳的路徑並自動將設定部署到整個網路,不用對每一個交換機做獨立設定。
Controller 備援
參考:struct sock_filter { /* Filter block */
__u16 code; /* Actual filter code */
__u8 jt; /* Jump offset for true */
__u8 jf; /* Jump offset for false */
__u32 k; /* Generic multiuse field depends on code */
};
| code | 定址模式 | 說明 |
|---|---|---|
| Load | ||
| ld | 1, 2, 3, 4, 10 | Load 32-bit into A |
| ldi | 4 | Load word into A |
| ldh | 1, 2 | Load half-word into A |
| ldb | 1, 2 | Load byte into A |
| ldx | 3, 4, 5, 10 | Load word into X |
| ldxi | 4 | Load word into X |
| ldxb | 5 | Load byte into X |
| Store | ||
| st | 3 | Store A into M[] |
| stx | 3 | Store X into M[] |
| Branch | ||
| jmp | 6 | Jump to label |
| ja | 6 | Jump to label |
| jeq | 7, 8 | Jump on A == k |
| jneq | 8 | Jump on A != k |
| jne | 8 | Jump on A != k |
| jlt | 8 | Jump on A < k |
| jle | 8 | Jump on A <= k |
| jgt | 7, 8 | Jump on A > k |
| jge | 7, 8 | Jump on A >= k |
| jset | 7, 8 | Jump on A & k |
| ALU | ||
| add | 0, 4 | A + <x> |
| sub | 0, 4 | A - <x> |
| mul | 0, 4 | A * <x> |
| div | 0, 4 | A / <x> |
| mod | 0, 4 | A % <x> |
| neg | 無 | !A |
| and | 0, 4 | A & <x> |
| or | 0, 4 | A | <x> |
| xor | 0, 4 | A ^ <x> |
| lsh | 0, 4 | A << <x> |
| rsh | 0, 4 | A >> <x> |
| Miscellaneous | ||
| tax | 無 | Copy A into X |
| txa | 無 | Copy X into A |
| Return | ||
| ret | 4, 9 | Return |
| 定址模式 | Syntax | 說明 |
|---|---|---|
| 0 | x/%x | Register X |
| 1 | [k] | BHW at byte offset k in the packet |
| 2 | [x + k] | BHW at the offset X + k in the packet |
| 3 | M[k] | Word at offset k in M[] |
| 4 | #k | Literal value stored in k |
| 5 | 4*([k]&0xf) | Lower nibble * 4 at byte offset k in the packet |
| 6 | L | Jump label L |
| 7 | #k,Lt,Lf | Jump to Lt if true, otherwise jump to Lf |
| 8 | #k,Lt | Jump to Lt if predicate is true |
| 9 | a/%a | Accumulator A |
| 10 | extension | BPF extension |
len skb->len proto skb->protocol type skb->pkt_type poff Payload start offset ifidx skb->dev->ifindex nla Netlink attribute of type X with offset A nlan Nested Netlink attribute of type X with offset A mark skb->mark queue skb->queue_mapping hatype skb->dev->type rxhash skb->hash cpu raw_smp_processor_id() vlan_tci skb_vlan_tag_get(skb) vlan_avail skb_vlan_tag_present(skb) vlan_tpid skb->vlan_proto rand prandom_u32()BPF 組合語言範例:
ldh [12] /* Load half word offset 12 into A */
jne #0x806, drop /* Jump to drop if != 0x0806 */
ret #-1
drop: ret #0
經過 bpf_asm 轉換成 bytecode:C 語言格式輸出方便複製貼上:$ ./bpf_asm foo 4,40 0 0 12,21 0 1 2054,6 0 0 4294967295,6 0 0 0,
$ ./bpf_asm -c foo
{ 0x28, 0, 0, 0x0000000c },
{ 0x15, 0, 1, 0x00000806 },
{ 0x06, 0, 0, 0xffffffff },
{ 0x06, 0, 0, 0000000000 },
ldh [12]
jne #0x800, drop
ldb [23]
jneq #6, drop
ret #-1
drop: ret #0
(Accelerated) VLAN w/ id 10:ld vlan_tciicmp random packet sampling, 1 in 4
jneq #10, drop
ret #-1
drop: ret #0
ldh [12]SECCOMP filter example:
jne #0x800, drop
ldb [23]
jneq #1, drop
# get a random uint32 number
ld rand
mod #4
jneq #1, drop
ret #-1
drop: ret #0
ld [4] /* offsetof(struct seccomp_data, arch) */
jne #0xc000003e, bad /* AUDIT_ARCH_X86_64 */
ld [0] /* offsetof(struct seccomp_data, nr) */
jeq #15, good /* __NR_rt_sigreturn */
jeq #231, good /* __NR_exit_group */
jeq #60, good /* __NR_exit */
jeq #0, good /* __NR_read */
jeq #1, good /* __NR_write */
jeq #5, good /* __NR_fstat */
jeq #9, good /* __NR_mmap */
jeq #14, good /* __NR_rt_sigprocmas
k */ jeq #13, good /* __NR_rt_sigaction */
jeq #35, good /* __NR_nanosleep */
bad: ret #0 /* SECCOMP_RET_KILL_THREAD */
good: ret #0x7fff0000 /* SECCOMP_RET_ALLOW */
libpcap 是封包擷取的 C/C++ 函式庫,可以過濾網路界面或 pcap 檔的封包,存成 pcap 檔。
使用前都要開啟取得 pcap handle,此時可以設定過濾條件,然後才能讀取封包。封包讀取後可以作各種處理,包括存成 pcap 檔。
無論是網路界面或 pcap 檔,都需要開啟取得 pcap handle -- pcap_t。即使沒有者兩個來源,只是要產生過濾程式碼或寫 pcap 檔,也需要開啟一個「假」的。
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Option Code | Option Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ / Option Value / / variable length, aligned to 32 bits / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ / / / . . . other options . . . / / / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Option Code == opt_endofopt | Option Length == 0 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
wireshark 是功能強大的圖形界面網路分析程式。用 libpcap 或 winpcap 擷取封包
顯示過濾
#include <arpa/inet.h>
// 轉換 IPv4 或 IPv6 數字位址 (表示字串) src_str 為二進位格式 addrptr
int inet_pton(
int family, // AF_INET 或 AF_INET6
const char *src_str,
void *addrptr);
// 回傳 1:成功、0:src_str 格式不是表示字串、–1 on error
// 轉換二進位格式 addrptr 為表示字串 dst_str
const char *inet_ntop(
int family,
const void *addrptr,
char *dst_str,
size_t len);
// 回傳 指向 dst_str 的文字字串: 成功, NULL: 錯誤
| net-tools | iproute2 | 說明 |
|---|---|---|
| ifconfig if[:n] ip[/len| netmask nm] | ip addr add ip[/len] dev if | 界面 if 設定或新增 (有 :n) IPv4 位址 ip。netmask nm。nm 需轉換成 prefix 長度 len。 |
| ifconfig if add ip/len | 界面 if 新增 IPv6 位址 ip,prefix 長度為 len。 | |
| ifconfig | ip addr, ip link, ip -s | 其它 Address and link 設定 |
| route | ip route | Routing tables |
| arp | ip neigh | Neighbors |
| iptunnel | ip tunnel | Tunnels |
| nameif | ifrename, ip link set name | 網路界面改名 |
| ipmaddr | ip maddr | 群播 |
| netstat | ip -s, ss, ip route | 顯示網路統計 |
| Layer | OSI | Internet Protocol Suit | ||
|---|---|---|---|---|
| 7 | Application | 應用層 | Application | HTTP, FTP, ... |
| 6 | Presentation | 表現層 (表達層) | ||
| 5 | Session | 會談層 (會議層) | ||
| 4 | Transport | 傳輸層 (傳送層) | Transport | TCP, UDP |
| 3 | Network | 網路層 | Network | IP, ICMP |
| 2 | Data Link | 資料連結層 | Link | Ethernet, ARP, Serial, ATM |
| 1 | Physical | 實體層 | ||
|
區塊雖然是一維線性串起來的,但有邏輯上的階層,最頂層一定是叫 Section Header Block 的區塊,一個檔案可以有多個頂層的 Section Header Block。
Section Header Block +- Interface Description Block +- Enhanced Packet Block +- Enhanced Packet Block +- ... +- Enhanced Packet Block
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Option Code | Option Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ / Option Value / / variable length, padded to 32 bits / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ / / / . . . other options . . . / / / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Option Code == opt_endofopt | Option Length == 0 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 名稱 | Code | 長度 | 可多個? | 說明 |
|---|---|---|---|---|
| opt_endofopt | 0 | 0 | no | 選項表結束。 |
| opt_comment | 1 | 可變 | 可 | utf-8 編碼的註解,字串沒有結束的 0。換行用「\r\n」或「\n」。 |
| opt_custom 客訂選項 | 0x0BAC | 可變 | 可 | utf-8 編碼的字串,沒有結束的 0。複製到新檔案。 |
| 0x0BAD | 可變 | 可 | 二進位資料。複製到新檔案。 | |
| 0x4BAC | 可變 | 可 | utf-8 編碼的字串,沒有結束的 0。不複製到新檔案。 | |
| 0x4BAD | 可變 | 可 | 二進位資料。不複製到新檔案。 |
客訂選項有 4 種,選項值開頭放登記在 IANA 的 32-bit Private Enterprise Number (PEN) 來避免衝突。
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Custom Option Code | Option Length | +---------------------------------------------------------------+ | Private Enterprise Number (PEN) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ / Custom Data / / variable length, padded to 32 bits / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------------------------------------------------------+ 0 | Section Header Block Type = 0x0A0D0D0A | +---------------------------------------------------------------+ 4 | Block Total Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 8 | Byte-Order Magic = 0x1A2B3C4D | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 12 | Major Version = 1 | Minor Version = 0 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 16 | | | Section Length | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 24 / / / Options (variable) / / / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Block Total Length | +---------------------------------------------------------------+
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------------------------------------------------------+
0 | Block Type = 0x00000001 |
+---------------------------------------------------------------+
4 | Block Total Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
8 | LinkType | Reserved = 0 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
12 | SnapLen |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
16 / /
/ Options (variable) /
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Block Total Length |
+---------------------------------------------------------------+
| Name | Code | Length | 可多個? | 說明 |
|---|---|---|---|---|
| if_name | 2 | Variable | no | |
| if_description | 3 | Variable | no | |
| if_IPv4addr | 4 | 8 | yes | |
| if_IPv6addr | 5 | 17 | yes | |
| if_MACaddr | 6 | 6 | no | |
| if_EUIaddr | 7 | 8 | no | |
| if_speed | 8 | 8 | no | |
| if_tsresol | 9 | 1 | no | 時間精度。MSB 0:剩下是 10 的 negative power。MSB 1:剩下是 2 的 negative power。預設是 10-6,跟 pcap 預設的微秒一致。 |
| if_tzone | 10 | 4 | no | |
| if_filter | 11 | variable | no | |
| if_os | 12 | variable | no | |
| if_fcslen | 13 | 1 | no | |
| if_tsoffset | 14 | 8 | no |
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------------------------------------------------------+ 0 | Enhanced Packet Block Type = 0x00000006 | +---------------------------------------------------------------+ 4 | Block Total Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 8 | Interface ID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 12 | Timestamp (High) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 16 | Timestamp (Low) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 20 | Captured Packet Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 24 | Original Packet Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 28 / / / Packet Data / / variable length, padded to 32 bits / / / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ / / / Options (variable) / / / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Block Total Length | +---------------------------------------------------------------+
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------------------------------------------------------+
0 | Simple Block Type = 0x00000003 |
+---------------------------------------------------------------+
4 | Block Total Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
8 | Original Packet Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
12 / /
/ Packet Data /
/ variable length, padded to 32 bits /
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Block Total Length |
+---------------------------------------------------------------+
| 項目 | IPv4 | IPv6 | 說明 |
|---|---|---|---|
| EtherType | 0x0800 | 0x86DD | |
| header 版本 | 4 | 6 | |
| header 長度 | 20 | 40 | 不含 options |
| 位址 bit 數 | 32 | 128 | |
| 位址 byte 數 | 4 | 16 | |
| family | AF_INET | AF_INET6 | |
| data type | struct in_addr (unsigned long) | struct in6_addr | |
| 字串表示 | 逗點隔開的 4 個十進位數字 dotted-decimal 255.255.255.255 | 分號隔開的 8 組 4 位十六進位數字 colon-separated hexadecimal ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | IPv6 有簡寫規則 |
| 字串最長長度 | INET_ADDRSTRLEN 16 | INET6_ADDRSTRLEN 46 (40) | 含結尾 0。IPv6 位址 40-byte,但IPv4 tunneling 有 46-byte。 |
struct sockaddr_in {
sa_family_t sin_family; /* address family: AF_INET */
in_port_t sin_port; /* port in network byte order */
struct in_addr sin_addr; /* internet address */
};
struct sockaddr_in6 {
sa_family_t sin6_family; /* AF_INET6 */
in_port_t sin6_port; /* port number */
uint32_t sin6_flowinfo; /* IPv6 flow information */
struct in6_addr sin6_addr; /* IPv6 address */
uint32_t sin6_scope_id; /* Scope ID */
};
flowinfo 作用?sin6_scope_id 只用在 link-local。
Kamailio 使用的 IP 位址
typedef struct ip_addr {
unsigned int af; /* address family: AF_INET6 or AF_INET */
unsigned int len; /* address len, 16 or 4 */
/* 64 bits aligned address */
union {
unsigned long addrl[16/sizeof(long)]; /* long format*/
unsigned int addr32[4];
unsigned short addr16[8];
unsigned char addr[16];
}u;
} ip_addr_t;
所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...