vsomeip是BMW实现的开源someip库,目前主要实现了someip的通信和服务发现功能,并在此基础上增加了少许的安全机制。
本文主要从vsomeip的环境搭建,编译,以及对应helloworld程序分析开始,目的在于分析整套vsomeip库的运行机制。
由于目前基于vsomeip的安全相关分析文章相对较少,笔者也会对vsomeip库整体的安全机制进行分析,去深入的了解vsomeip库在不修改协议栈的情况下,如何做到相应的访问控制能力。
vsomeip相关代码可以直接从github上获取。
https://github.com/GENIVI/vsomeip.git
由于我的ubuntu版本是20.04,官方文档上的对应boost包的版本过低,因此这里不需要指定对应的boost包版本号
sudo apt-get install libboost-system-dev libboost-thread-dev libboost-log-dev
sudo apt-get install asciidoc source-highlight doxygen graphviz
由于我的ubuntu是20.04版本全新安装的,因此再编译的过程中,遇到了如下的问题:
遇到对应图中的问题,主要是对应的编译工具未安装导致的。
CMAKE_C_COMPILER是对应的gcc没有安装
CMAKE_CXX_COMPILER是对应的G++没有安装
CMAKE_MAKE_CONPILER是对应的make命令没有安装
因此执行如下命令安装对应的编译工具
sudo apt-get install gcc g++ make
其实缺少gtest应该也不影响大局,但是这里以防万一,加上对应的gtest目录。
根据官方的依赖文档
mkdir build
cd build
cmake ..
make
根据官方的文档,可以直接运行上述命令进行编译vsomeip库
分析从也是从自带的helloworld程序开始,因此我们先编译对应的helloworld程序。
Helloworld程序的编译方法可以查看
examples/hello_world/readme
相关的编译命令如下:
cmake --build . --target hello_world
cd ./examples/hello_world/
make
编译完成之后,会在对应的编译目录下生成对应helloworld的二进制程序:hello_world_client和hello_world_service。
这里有个坑需要注意,官方给出的运行命令并不能直接运行。
HOST1运行service:
env VSOMEIP_CONFIGURATION=../helloworld-local.json \
VSOMEIP_APPLICATION_NAME=hello_world_service \
./hello_world_service
HOST1运行client:
env VSOMEIP_CONFIGURATION=../helloworld-local.json \
VSOMEIP_APPLICATION_NAME=hello_world_client \
./hello_world_client
这里官方文档中,指定的VSOMEIP_CONFIGURATION的配置文件路径在../下面。但是默认编译完成后,根本没有这个命令。因此,我们需要手动copy一下对应的命令,否则就会出现加载策略文件失败的问题。
将代码目录下的helloworld-local.json 复制到我们的运行目录,因此对应的内容如下。
drwxrwxr-x 3 seven seven 4096 Aug 23 23:16 .
drwxrwxr-x 5 seven seven 4096 Aug 23 02:46 ..
drwxrwxr-x 4 seven seven 4096 Aug 20 00:29 CMakeFiles
-rw-rw-r-- 1 seven seven 1288 Aug 19 23:26 cmake_install.cmake
-rwxrwxr-x 1 seven seven 349512 Aug 22 23:27 hello_world_client
-rw-rw-r-- 1 seven seven 1526 Aug 23 23:16 helloworld-local.json
-rwxrwxr-x 1 seven seven 372872 Aug 23 02:43 hello_world_service
-rw-rw-r-- 1 seven seven 11414 Aug 19 23:27 Makefile
完成之后,修改上述官方指定配置文件的路径,启动程序。
对应修改后的文件如下:
HOST1运行service:
env VSOMEIP_CONFIGURATION=./helloworld-local.json \
VSOMEIP_APPLICATION_NAME=hello_world_service \
./hello_world_service
HOST1运行client:
env VSOMEIP_CONFIGURATION=./helloworld-local.json \
VSOMEIP_APPLICATION_NAME=hello_world_client \
./hello_world_client
运行成功后service端的运行日志:
2021-07-24 00:39:22.968673 [info] Parsed vsomeip configuration in 0ms
2021-07-24 00:39:22.969368 [info] Using configuration file: "./helloworld-local.json".
2021-07-24 00:39:22.969505 [info] Configuration module loaded.
2021-07-24 00:39:22.969585 [info] Initializing vsomeip application "hello_world_service".
2021-07-24 00:39:22.970287 [info] Instantiating routing manager [Host].
2021-07-24 00:39:22.970967 [info] create_local_server Routing endpoint at /tmp/vsomeip-0
2021-07-24 00:39:22.971693 [info] Application(hello_world_service, 4444) is initialized (11, 100).
2021-07-24 00:39:22.972006 [info] Starting vsomeip application "hello_world_service" (4444) using 2 threads I/O nice 255
2021-07-24 00:39:22.973797 [info] main dispatch thread id from application: 4444 (hello_world_service) is: 7fe67327a700 TID: 30757
2021-07-24 00:39:22.974427 [info] shutdown thread id from application: 4444 (hello_world_service) is: 7fe672a79700 TID: 30758
2021-07-24 00:39:22.975582 [info] Watchdog is disabled!
2021-07-24 00:39:22.976711 [info] OFFER(4444): [1111.2222:0.0] (true)
2021-07-24 00:39:22.976949 [info] io thread id from application: 4444 (hello_world_service) is: 7fe671a77700 TID: 30760
2021-07-24 00:39:22.976941 [info] io thread id from application: 4444 (hello_world_service) is: 7fe673b06740 TID: 30755
2021-07-24 00:39:22.978376 [info] Listening at /tmp/vsomeip-4444
2021-07-24 00:39:22.978504 [info] vSomeIP 3.1.20.3 | (default)
2021-07-24 00:40:30.882696 [info] Application/Client 5555 is registering.
2021-07-24 00:40:30.885026 [info] Client [4444] is connecting to [5555] at /tmp/vsomeip-5555
2021-07-24 00:40:30.888982 [info] REGISTERED_ACK(5555)
2021-07-24 00:40:30.002024 [info] REQUEST(5555): [1111.2222:255.4294967295]
2021-07-24 00:40:30.021586 [info] RELEASE(5555): [1111.2222]
2021-07-24 00:40:30.022233 [info] Application/Client 5555 is deregistering.
2021-07-24 00:40:30.132041 [info] Client [4444] is closing connection to [5555]
2021-07-24 00:40:33.039677 [info] vSomeIP 3.1.20.3 | (default)
2021-07-24 00:40:35.016774 [info] STOP OFFER(4444): [1111.2222:0.0] (true)
2021-07-24 00:40:35.018794 [info] Stopping vsomeip application "hello_world_service" (4444).
运行成功后client端的日志:
2021-07-24 00:40:30.863438 [info] Parsed vsomeip configuration in 0ms
2021-07-24 00:40:30.864396 [info] Using configuration file: "./helloworld-local.json".
2021-07-24 00:40:30.864794 [info] Configuration module loaded.
2021-07-24 00:40:30.865133 [info] Initializing vsomeip application "hello_world_client".
2021-07-24 00:40:30.865472 [info] Instantiating routing manager [Proxy].
2021-07-24 00:40:30.865988 [info] Client [5555] is connecting to [0] at /tmp/vsomeip-0
2021-07-24 00:40:30.866444 [info] Application(hello_world_client, 5555) is initialized (11, 100).
2021-07-24 00:40:30.866878 [info] Starting vsomeip application "hello_world_client" (5555) using 2 threads I/O nice 255
2021-07-24 00:40:30.869134 [info] main dispatch thread id from application: 5555 (hello_world_client) is: 7fd99f664700 TID: 30773
2021-07-24 00:40:30.869406 [info] shutdown thread id from application: 5555 (hello_world_client) is: 7fd99ee63700 TID: 30774
2021-07-24 00:40:30.872267 [info] io thread id from application: 5555 (hello_world_client) is: 7fd99f6ef740 TID: 30772
2021-07-24 00:40:30.873138 [info] io thread id from application: 5555 (hello_world_client) is: 7fd99e662700 TID: 30775
2021-07-24 00:40:30.876012 [info] Listening at /tmp/vsomeip-5555
2021-07-24 00:40:30.876564 [info] Client 5555 (hello_world_client) successfully connected to routing ~> registering..
2021-07-24 00:40:30.887494 [info] Application/Client 5555 (hello_world_client) is registered.
2021-07-24 00:40:30.005002 [info] ON_AVAILABLE(5555): [1111.2222:0.0]
Sending: World
2021-07-24 00:40:30.007028 [info] Client [5555] is connecting to [4444] at /tmp/vsomeip-4444
Received: Hello World
2021-07-24 00:40:30.019968 [info] Stopping vsomeip application "hello_world_client" (5555).
2021-07-24 00:40:30.023966 [info] Application/Client 5555 (hello_world_client) is deregistered.
2021-07-24 00:40:30.025815 [info] Client [5555] is closing connection to [4444]