Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问如何修复 "pcap init failed"? #10

Open
wilia opened this issue Jun 28, 2018 · 24 comments
Open

请问如何修复 "pcap init failed"? #10

wilia opened this issue Jun 28, 2018 · 24 comments
Labels
bug Something isn't working

Comments

@wilia
Copy link

wilia commented Jun 28, 2018

安装号rsock后我使用以下命令
/opt/rsock/./server_rsock_Linux --dev=venet0 --taddr=127.0.0.1:32227 --ports=12221-12225
dev: venet0, ipv4: 127.0.0.1
Run in background. pid: 8226
但是在ps aux看不到进程,查看日志如下
2018-06-28 22:38:08.633 ERROR [8226] [RCap::doInit@108] init failed: arptype 65535 not supported by libpcap - falling back to cooked socket
2018-06-28 22:38:08.633 ERROR [8226] [ISockApp::doInit@211] pcap init failed
2018-06-28 22:38:08.633 DEBUG [8226] [ISockApp::Close@275]

组件安装了 libuv libnet libpcap libdnet gcc gcc-c++

@iceonsun
Copy link
Owner

  1. root权限确认一下
  2. 你应该知道--dev的意思,是外网网卡(监听来自client的流量)。但我看这个dev是一loopback

你先照上面的错误排查一下。如果还有问题,请反馈。记得帖日志。

@wilia
Copy link
Author

wilia commented Jun 29, 2018

首先,谢谢大大百忙之中回复!
1、我查看的这台vps的网卡就是venet0,不知道对不对
[root@ss ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: venet0: <BROADCAST,POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/void
inet 127.0.0.1/32 scope host venet0
inet 155.94.181.XX/32 brd 155.94.181.XX scope global venet0:0
[root@ss ~]#
2、然后我用的是root账户,这个是确认的,因为我懒得创建普通用户再配置sudo,感觉多此一举
3、请问贴日志是贴的默认生成/var/log/rsock/rsock.log这个嘛?
如果是的话我只有这个,我运行的时候加了-v参数,可是日志还是输出这些,没有变化
2018-06-29 10:09:38.982 DEBUG [27511] [ISockApp::doInit@182] conf: {"daemon": true, "log": "/var/log/rsock/rsock.log", "param": {"cap_timeout": 10, "dev": "venet0", "duration": 600, "hash": "bt25^n1", "keepalive": 4, "lcapIp": "155.94.181.xx", "ludp": "", "ports": "12221-12225", "taddr": "127.0.0.1:32227", "type": "all", "unPath": ""}, "server": true, "verbose": true}
2018-06-29 10:09:38.983 DEBUG [27511] [RCap::doInit@65] filter : ((tcp[tcpflags] & tcp-syn != 0) and tcp and (ip src 155.94.181.xx) and ( src portrange 12221-12225 )) or (tcp and (ip dst 155.94.181.xx) and ( dst portrange 12221-12225 )and (tcp[tcpflags] & (tcp-syn) == 0))
2018-06-29 10:09:38.997 ERROR [27511] [RCap::doInit@108] init failed: arptype 65535 not supported by libpcap - falling back to cooked socket
2018-06-29 10:09:38.997 ERROR [27511] [ISockApp::doInit@211] pcap init failed
2018-06-29 10:09:38.997 DEBUG [27511] [ISockApp::Close@275]

@iceonsun
Copy link
Owner

iceonsun commented Jun 29, 2018 via email

@wilia
Copy link
Author

wilia commented Jun 29, 2018

嗯嗯,好的,麻烦大大了。

@iceonsun
Copy link
Owner

你运行下tcpdump,看一下输出是什么。

tcpdump "host your_ip"

@wilia
Copy link
Author

wilia commented Jun 30, 2018

测试过程如下:
[root@ss ~]# /opt/rsock/./server_rsock_Linux --lcapIp=155.94.181.X --type=all -t 127.0.0.1:32227 --ports=12221-12225 -v
Run in background. pid: 3786
[root@ss ~]# cat /var/log/rsock/rsock.log
2018-06-30 17:53:56.153 DEBUG [3786] [ISockApp::doInit@182] conf: {"daemon": true, "log": "/var/log/rsock/rsock.log", "param": {"cap_timeout": 10, "dev": "venet0", "duration": 600, "hash": "hello135", "keepalive": 4, "lcapIp": "155.94.181.X", "ludp": "", "ports": "12221-12225", "taddr": "127.0.0.1:32227", "type": "all", "unPath": ""}, "server": true, "verbose": true}
2018-06-30 17:53:56.153 DEBUG [3786] [RCap::doInit@65] filter : ((tcp[tcpflags] & tcp-syn != 0) and tcp and (ip src 155.94.181.X) and ( src portrange 12221-12225 )) or (tcp and (ip dst 155.94.181.X) and ( dst portrange 12221-12225 )and (tcp[tcpflags] & (tcp-syn) == 0))
2018-06-30 17:53:56.169 ERROR [3786] [RCap::doInit@108] init failed: arptype 65535 not supported by libpcap - falling back to cooked socket
2018-06-30 17:53:56.169 ERROR [3786] [ISockApp::doInit@211] pcap init failed
2018-06-30 17:53:56.169 DEBUG [3786] [ISockApp::Close@275]
[root@ss ~]#
[root@ss ~]#
[root@ss ~]#
[root@ss ~]# rm -rf /var/log/rsock/rsock.log
[root@ss ~]#
[root@ss ~]# /opt/rsock/./server_rsock_Linux --lcapIp=155.94.181.X --hash=bCt87^n2 --type=all -t 127.0.0.1:32227 --ports=12221-12225 -v
Run in background. pid: 4110
[root@ss ~]#
[root@ss ~]# cat /var/log/rsock/rsock.log
2018-06-30 17:55:34.623 DEBUG [4110] [ISockApp::doInit@182] conf: {"daemon": true, "log": "/var/log/rsock/rsock.log", "param": {"cap_timeout": 10, "dev": "venet0", "duration": 600, "hash": "bCt87^n2", "keepalive": 4, "lcapIp": "155.94.181.X", "ludp": "", "ports": "12221-12225", "taddr": "127.0.0.1:32227", "type": "all", "unPath": ""}, "server": true, "verbose": true}
2018-06-30 17:55:34.624 DEBUG [4110] [RCap::doInit@65] filter : ((tcp[tcpflags] & tcp-syn != 0) and tcp and (ip src 155.94.181.X) and ( src portrange 12221-12225 )) or (tcp and (ip dst 155.94.181.X) and ( dst portrange 12221-12225 )and (tcp[tcpflags] & (tcp-syn) == 0))
2018-06-30 17:55:34.642 ERROR [4110] [RCap::doInit@108] init failed: arptype 65535 not supported by libpcap - falling back to cooked socket
2018-06-30 17:55:34.642 ERROR [4110] [ISockApp::doInit@211] pcap init failed
2018-06-30 17:55:34.642 DEBUG [4110] [ISockApp::Close@275]
[root@ss ~]#
[root@ss ~]# tcpdump "host 158.94.181.x"
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on venet0, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes

^C
0 packets captured
0 packets received by filter
0 packets dropped by kernel
[root@ss ~]#
使用tcpdump "host your_ip"似乎没有出现什么问题

@iceonsun
Copy link
Owner

自己下源代码手动编译试试吧。tcpdump ok的话,按理说pcap就应该支持这个网卡设备。编译指南请看这里 https://github.com/iceonsun/rsock/wiki/%E7%BC%96%E8%AF%91%E6%8C%87%E5%8D%97

如果仍然不ok的话,我现阶段也木有办法,找这个bug估计得需要一番精力

@wilia
Copy link
Author

wilia commented Jun 30, 2018

使用Linux/macOS里面的步骤编译的话报这个错误
Scanning dependencies of target client_rsock_Linux
[ 0%] Building C object CMakeFiles/client_rsock_Linux.dir/src/rcommon.c.o
In file included from /opt/rsock/src/rcommon.c:6:0:
/opt/rsock/./include/rcommon.h:9:16: fatal error: uv.h: No such file or directory
#include <uv.h>
^
compilation terminated.
make[2]: *** [CMakeFiles/client_rsock_Linux.dir/src/rcommon.c.o] Error 1
make[1]: *** [CMakeFiles/client_rsock_Linux.dir/all] Error 2
make: *** [all] Error 2

@iceonsun
Copy link
Owner

安装libuv等依赖库没有

输入

  1. updatdb

  2. locate uv.h

第2步如果有输出,切输出的路径以/usr/开头。证明有安装。

@wilia
Copy link
Author

wilia commented Jun 30, 2018

第一个是updatedb命令嘛?updatedb可以,updatdb不行,
[root@ss ~]# updatedb
[root@ss ~]# locate uv.h
/opt/rsock/xbuild/include/libuv/uv.h
/root/cmake-3.11.4/Utilities/cm_uv.h
/root/cmake-3.11.4/Utilities/cmlibuv/include/uv.h
这样表示我没有安装依赖嘛?
请问我还需要安装什么依赖呢?CentOS 7
[root@ss ~]#
[root@ss ~]# yum -y install libuv libnet libdnet libpcap flex byacc gcc gcc-c++
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

  • base: repos-lax.psychz.net
  • epel: mirror.hmc.edu
  • extras: centos.mirror.ndchost.com
  • updates: repos-lax.psychz.net
    Package 1:libuv-1.19.2-1.el7.x86_64 already installed and latest version
    Package libnet-1.1.6-7.el7.x86_64 already installed and latest version
    Package libdnet-1.12-13.1.el7.x86_64 already installed and latest version
    Package 14:libpcap-1.5.3-11.el7.x86_64 already installed and latest version
    Package flex-2.5.37-3.el7.x86_64 already installed and latest version
    Package byacc-1.9.20130304-3.el7.x86_64 already installed and latest version
    Package gcc-4.8.5-28.el7_5.1.x86_64 already installed and latest version
    Package gcc-c++-4.8.5-28.el7_5.1.x86_64 already installed and latest version
    Nothing to do
    [root@ss ~]#

@iceonsun
Copy link
Owner

是updatedb,我打错了。

这输出不正常啊。安装了uv等库,会有uv.h等头文件啊。你ls -al /usr/include/uv*, /usr/local/include/uv*,/usr/x86-linux(大概是这样)/include/uv* 下面找一下。

@wilia
Copy link
Author

wilia commented Jun 30, 2018

确实不对呀,这些目录都找不到
[root@ss ~]# ls -al /usr/include/uv*
ls: cannot access /usr/include/uv*: No such file or directory
[root@ss ~]#
[root@ss ~]#
[root@ss ~]# ls -al /usr/local/include/uv*
ls: cannot access /usr/local/include/uv*: No such file or directory
[root@ss ~]#
[root@ss ~]#
[root@ss ~]# ls -al /usr/
bin/ etc/ games/ include/ lib/ lib64/ libexec/ local/ sbin/ share/ src/ tmp/
[root@ss ~]# ls -al /usr/
bin/ etc/ games/ include/ lib/ lib64/ libexec/ local/ sbin/ share/ src/ tmp/
[root@ss ~]# ls -al /usr/

@iceonsun
Copy link
Owner

这个 /usr/include/lib,以及类似的。有include的文件夹,都ls -al 输出一下

比如 ls -al /usr/include/lib/uv*

@wilia
Copy link
Author

wilia commented Jun 30, 2018

查了下,都没有,这么看来是安装失败了吧,
[root@ss ~]#
[root@ss ~]# ls -al /usr/libexec/nv*
ls: cannot access /usr/libexec/nv*: No such file or directory
[root@ss ~]#
[root@ss ~]# ls -al /usr/libexec/lib*
ls: cannot access /usr/libexec/lib*: No such file or directory
[root@ss ~]#
[root@ss ~]# ls -al /usr/lib64/u*
ls: cannot access /usr/lib64/u*: No such file or directory
[root@ss ~]#
[root@ss ~]#
[root@ss ~]#
[root@ss ~]# ls -al /usr/include/uv*
ls: cannot access /usr/include/uv*: No such file or directory
[root@ss ~]#
[root@ss ~]# ls -al /usr/include/lib*
-rw-r--r-- 1 root root 1398 Apr 10 15:56 /usr/include/libgen.h
-rw-r--r-- 1 root root 4597 Apr 10 15:56 /usr/include/libintl.h
-rw-r--r-- 1 root root 17276 Apr 10 15:56 /usr/include/libio.h
-rw-r--r-- 1 root root 3958 Jun 10 2014 /usr/include/libnet.h

/usr/include/libnet:
total 204
drwxr-xr-x 2 root root 4096 Jun 28 16:06 .
drwxr-xr-x 38 root root 4096 Jun 30 18:55 ..
-rw-r--r-- 1 root root 8031 Mar 6 2012 libnet-asn1.h
-rw-r--r-- 1 root root 96475 Mar 7 2012 libnet-functions.h
-rw-r--r-- 1 root root 62050 Mar 30 2012 libnet-headers.h
-rw-r--r-- 1 root root 6832 Mar 6 2012 libnet-macros.h
-rw-r--r-- 1 root root 12706 Mar 6 2012 libnet-structures.h
-rw-r--r-- 1 root root 1734 Feb 2 2011 libnet-types.h
[root@ss ~]#
[root@ss ~]# ls -al /usr/lib64/uv*
ls: cannot access /usr/lib64/uv*: No such file or directory
[root@ss ~]#
[root@ss ~]# ls -al /usr/lib64/lib*
-rwxr-xr-x 1 root root 8816 Apr 10 16:24 /usr/lib64/libBrokenLocale-2.17.so
lrwxrwxrwx 1 root root 32 Jun 15 12:53 /usr/lib64/libBrokenLocale.so -> ../../lib64/libBrokenLocale.so.1
lrwxrwxrwx 1 root root 23 Jun 15 12:53 /usr/lib64/libBrokenLocale.so.1 -> libBrokenLocale-2.17.so
lrwxrwxrwx 1 root root 15 Jun 15 12:53 /usr/lib64/libEGL.so.1 -> libEGL.so.1.0.0
............
-rwxr-xr-x 1 root root 53600 May 16 16:13 /usr/lib64/libxtables.so.10.0.0
lrwxrwxrwx 1 root root 13 Jun 15 13:07 /usr/lib64/libz.so.1 -> libz.so.1.2.7
-rwxr-xr-x 1 root root 90664 Nov 6 2016 /usr/lib64/libz.so.1.2.7

/usr/lib64/libuser:
total 192
drwxr-xr-x 2 root root 4096 Jun 15 13:08 .
dr-xr-xr-x 34 root root 36864 Jun 30 17:57 ..
-rwxr-xr-x 1 root root 45520 Apr 13 02:44 libuser_files.so
-rwxr-xr-x 1 root root 49400 Apr 13 02:44 libuser_ldap.so
-rwxr-xr-x 1 root root 45512 Apr 13 02:44 libuser_shadow.so

/usr/lib64/libxslt-plugins:
total 44
drwxr-xr-x 2 root root 4096 Jun 10 2014 .
dr-xr-xr-x 34 root root 36864 Jun 30 17:57 ..
[root@ss ~]#

@iceonsun
Copy link
Owner

这个不是有输出么/usr/include/libnet。 ls -al /usr/include/libuv 这样,换一下。

或者这样 locate uv.so locate uv.a

@wilia
Copy link
Author

wilia commented Jun 30, 2018

只有locate uv.so有/usr/输出
[root@ss ~]# /usr/include/libnet
-bash: /usr/include/libnet: Is a directory
[root@ss ~]#
[root@ss ~]# ls -al /usr/include/libnet/
total 204
drwxr-xr-x 2 root root 4096 Jun 28 16:06 .
drwxr-xr-x 38 root root 4096 Jun 30 18:55 ..
-rw-r--r-- 1 root root 8031 Mar 6 2012 libnet-asn1.h
-rw-r--r-- 1 root root 96475 Mar 7 2012 libnet-functions.h
-rw-r--r-- 1 root root 62050 Mar 30 2012 libnet-headers.h
-rw-r--r-- 1 root root 6832 Mar 6 2012 libnet-macros.h
-rw-r--r-- 1 root root 12706 Mar 6 2012 libnet-structures.h
-rw-r--r-- 1 root root 1734 Feb 2 2011 libnet-types.h
[root@ss ~]# ls -al /usr/include/libuv
ls: cannot access /usr/include/libuv: No such file or directory
[root@ss ~]#
[root@ss ~]# locate uv.so
/usr/lib64/libuv.so.1
/usr/lib64/libuv.so.1.0.0
[root@ss ~]#
[root@ss ~]# locate uv.a
/opt/rsock/xbuild/lib/Darwin_x86_64/libuv.a
/opt/rsock/xbuild/lib/Linux_x86_64/libuv.a
/root/cmake-3.11.4/Utilities/cmlibuv/libcmlibuv.a
[root@ss ~]#

@iceonsun
Copy link
Owner

uv没装上。

如果你会手动编译且自己愿意折腾的话,这样做做:修改CMakeLists.txt,像这行一样: https://github.com/iceonsun/rsock/blob/master/CMakeLists.txt#L8

加入 include_directories(/opt/rsock/xbuild/include/libuv/),一次加入libpcap, libnet, libdnet的。然后重新编译。如果还报错说没找文件,那就肯定是你的库没装好。

如果不愿意折腾,且客户端不是mac或者windows,就别折腾了。改用kcpraw或者udp2raw吧。不过我没试过

@wilia
Copy link
Author

wilia commented Jun 30, 2018

嗯,好的

@iceonsun iceonsun added the bug Something isn't working label Jun 30, 2018
@wangyu-
Copy link

wangyu- commented Jun 30, 2018

网卡叫venet0,应该是openvz的(跟我的搬瓦工一个样)。openvz上面不支持SOCK_RAW,所以pcap fallback到了SOCK_DGRAM(也就是所谓的cooked mode):

2018-06-28 22:38:08.633 ERROR [8226] [RCap::doInit@108] init failed: arptype 65535 not supported by libpcap - falling back to cooked socket

这时pcap_datalink()返回的datalink类型就不再是DLT_EN10MB了,而是DLT_LINUX_SLL,得在代码里单独处理一下。

@wilia
Copy link
Author

wilia commented Jul 2, 2018

@wangyu- 大佬,没错我是openvz,不过不是帮瓦工,请问该怎么处理呢?

@wilia
Copy link
Author

wilia commented Jul 2, 2018

编译的话,这次报错不是说没找到文件
[root@ss build]# make
Scanning dependencies of target client_rsock_Linux
[ 0%] Building C object CMakeFiles/client_rsock_Linux.dir/src/rcommon.c.o
[ 1%] Building CXX object CMakeFiles/client_rsock_Linux.dir/src/ISockApp.cpp.o
In file included from /opt/rsock/src/../net/TcpAckPool.h:17:0,
from /opt/rsock/src/ISockApp.cpp:19:
/opt/rsock/src/../net/../bean/TcpInfo.h:15:20: error: 'TH_ACK' was not declared in this scope
uint8_t flag = TH_ACK;
^
/opt/rsock/src/../net/../bean/TcpInfo.h: In member function 'bool TcpInfo::HasCloseFlag()':
/opt/rsock/src/../net/../bean/TcpInfo.h:32:42: error: 'TH_FIN' was not declared in this scope
return static_cast(flag & (TH_FIN | TH_RST));
^
/opt/rsock/src/../net/../bean/TcpInfo.h:32:51: error: 'TH_RST' was not declared in this scope
return static_cast(flag & (TH_FIN | TH_RST));
^
/opt/rsock/src/ISockApp.cpp: In member function 'virtual void ISockApp::initSingletons()':
/opt/rsock/src/ISockApp.cpp:129:10: warning: unused variable 'manager' [-Wunused-variable]
auto manager = ServiceManager::GetInstance();
^
/opt/rsock/src/ISockApp.cpp:130:10: warning: unused variable 'handlerUtil' [-Wunused-variable]
auto handlerUtil = HandlerUtil::GetInstance(mLoop);
^
make[2]: *** [CMakeFiles/client_rsock_Linux.dir/src/ISockApp.cpp.o] Error 1
make[1]: *** [CMakeFiles/client_rsock_Linux.dir/all] Error 2
make: *** [all] Error 2

@wangyu-
Copy link

wangyu- commented Jul 2, 2018

@wilia 你自己编译解决不了,得改代码。不过改起来不难,等作者更新吧。

@wilia
Copy link
Author

wilia commented Jul 2, 2018

@wangyu- 嗯嗯,好的,多谢大佬提醒,我试试 udp2raw 去

@xiebruce
Copy link

@wilia @wangyu- 请问这个bug现在解决了吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants