Skip to content

Commit ff41cd2

Browse files
author
eddie murphy
committed
update
1 parent 8b48142 commit ff41cd2

File tree

7 files changed

+107
-9
lines changed

7 files changed

+107
-9
lines changed

content/posts/2022/05/02-hugo-add-mermaid.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ categories:
1111

1212
# step1
1313

14-
在themes/YourTheme/layouts/partials/footer.html 的最后追加如下内容
14+
在themes/YourTheme/layouts/partials/extend_footer.html 的最后追加如下内容
1515

1616
```html
1717
{{if .Store.Get "hasMermaid" }}

content/posts/2025/hep-protocol/a1.excalidraw.svg

Whitespace-only changes.
85.4 KB
Loading
142 KB
Loading
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: "HEP 协议学习笔记"
3+
date: "2025-02-02 15:12:40"
4+
draft: false
5+
type: posts
6+
tags:
7+
- all
8+
categories:
9+
- all
10+
---
11+
12+
# HEP简介
13+
14+
HEP协议目前叫做EEP(Extensible Encapsulation Protocol), 那之前的缩写HEP的H,我只能推测为homer。
15+
16+
这个协议的主要功能是对VoIP连路上的数据包,例如SIP进行封装,方便后续分析SIP信令图。
17+
18+
目前这个协议已经升级到V3版本,在这个pdf[HEP3_Network_Protocol_Specification_REV_36](https://github.com/sipcapture/HEP/blob/master/docs/HEP3_Network_Protocol_Specification_REV_36.pdf)中有详细的介绍。
19+
20+
今天我们主要看这个协议的V3版本的协议是如何实现的。
21+
22+
23+
# 包头
24+
25+
```mermaid
26+
packet-beta
27+
title HEP Packet
28+
0-3: "版本号"
29+
4-5: "总长度"
30+
6-15: "数据段(变长)"
31+
```
32+
33+
HEPv3的包头是6个字节,主要分为三个部分
34+
- 版本号:固定4个字节长度,是HEP3
35+
- 总长度:固定2个字节长度,是包的总长度,这个总长度包括了包头的六个字节。所以HEP包的大小范围一般是6-65535之间。
36+
- 数据段:数据段的长度不固定
37+
38+
> 注意事项:假如从传输层读到1000个字节的数据,在解析前6个字节是,发现总长度(total length)的子段是1200,那就说明本次读到的数据还不是一个完整的
39+
40+
# 数据段解析
41+
42+
数据段由固定6字节长度的头部和变长的payload部分。
43+
44+
```mermaid
45+
packet-beta
46+
title HEP Packet
47+
0-1: "vendor ID"
48+
2-3: "type ID"
49+
4-5: "length"
50+
6-15: "payload"
51+
```
52+
- vendor ID: 固定2字节长度, 其实意义不大,
53+
- type ID: 固定2字节长度,这个子段很重要,决定了payload的类型。可以理解为是一个对象的key, 然后把payload理解为value
54+
- length: 固定2字节长度,范围是0-65535,这个字段是也是整个数据段的长度,也就是包括了6个字节的段头
55+
- payload: 长度是length的长度-6,表示数据长度
56+
57+
hep协议有个type ID的映射表
58+
59+
| chunk type ID | 类型 | 描述 |
60+
| --- | --- | --- |
61+
| 0x0001 | uint8 | IP类型,0x02=IPv4, 0x0a=IPv6
62+
| 0x0002 | uint8 | 协议类型 0x06=TCP, 0x11=UDP, 可以参考[IP协议号列表](https://zh.wikipedia.org/wiki/IP%E5%8D%8F%E8%AE%AE%E5%8F%B7%E5%88%97%E8%A1%A8)
63+
64+
其他的字段还有很多,可以参考[HEP3_Network_Protocol_Specification_REV_36](https://github.com/sipcapture/HEP/blob/master/docs/HEP3_Network_Protocol_Specification_REV_36.pdf)
65+
66+
67+
# HEP3例子分析
68+
69+
![](atta/2025-02-02-18-02-31.png)
70+
71+
```
72+
48 45 50 33 00 71
73+
H E P 3 len=113
74+
00 00 00 01 00 07 02
75+
不重要 IP类型 长度为7, 减去6字节的头,payload长度为1字节, 也就是0x02, 值为2,表示IP用的是IPv4
76+
00 00 00 02 00 07 11
77+
procotol ID = 17 (UDP)
78+
```
79+
80+
> 关于 00 00 00 01 00 07 02, 02为什么代表IPv4, 关于这个问题,刚开始我也不清楚,而且还有个人提出issue https://github.com/sipcapture/HEP/issues/6
81+
> 按照 Address Family Numbers, IPv4对应的号码其实是1,但是hep协议的作者为什么定义为1,我觉得这个可能和INNA并没有什么关系。
82+
> IPv4是2,那么IPv6是多少,规范里也没有说明,只能从一些代码里看出IPv6的号码是0x0a, 也就是10.
83+
84+
```go
85+
// HEP chuncks
86+
const (
87+
Version = 1 // Chunk 0x0001 IP protocol family (0x02=IPv4, 0x0a=IPv6)
88+
```
89+
90+
91+
# 参考文档
92+
- https://github.com/sipcapture/homer/wiki
93+
- https://github.com/sipcapture/HEP/issues/6
94+
- https://github.com/sipcapture/HEP
95+
- https://github.com/sipcapture/HEP/blob/master/docs/HEP3_Network_Protocol_Specification_REV_36.pdf
96+
- https://github.com/sipcapture/heplify/blob/master/decoder/decoder.go
97+
- https://zh.wikipedia.org/wiki/IP%E5%8D%8F%E8%AE%AE%E5%8F%B7%E5%88%97%E8%A1%A8
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
{{- /* Footer custom content area start */ -}}
22
{{- /* Insert any custom code web-analytics, resources, etc. here */ -}}
33
{{- /* Footer custom content area end */ -}}
4+
5+
6+
{{if .Store.Get "hasMermaid" }}
7+
<script type="module">
8+
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
9+
mermaid.initialize({ startOnLoad: true });
10+
</script>
11+
{{end }}

themes/PaperMod/layouts/partials/footer.html

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,4 @@
132132
}
133133
});
134134
</script>
135-
{{- end }}
136-
137-
{{if .Store.Get "hasMermaid" }}
138-
<script type="module">
139-
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
140-
mermaid.initialize({ startOnLoad: true });
141-
</script>
142-
{{end }}
135+
{{- end }}

0 commit comments

Comments
 (0)