英文:
Opening a pfring from Go: pfring NewRing error: no such device
问题
我想在Debian 11上使用github.com/google/gopacket/pfring
包从Go代码中调用pf_ring,但无法在Debian 11上使其正常工作(我的代码在Debian 10上可以工作)。
这是我的Go代码:
package main
import (
"github.com/google/gopacket/pfring"
"log"
)
func main() {
_, err := pfring.NewRing("eno1@0", 1574, pfring.FlagPromisc|pfring.Flag(1<<14))
if err == nil {
log.Printf("Success!")
return
}
log.Fatalf("Failure: %s", err)
}
当我运行它时:
# ./test-go
2023/01/24 10:12:25 Failure: pfring NewRing error: no such device
显然,eno1接口是存在的:
# pf_ringcfg --list-interfaces
Name: eno1 Driver: i40e RSS: 12 [Supported by ZC]
Name: enp3s0f1 Driver: i40e RSS: 12 [Supported by ZC]
Name: enx0a229512eeb9 Driver: cdc_ether RSS: 1 [Linux Driver]
奇怪的是,相同的C代码可以工作:
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <pfring.h>
int main() {
pfring* ring = pfring_open("eno1@0", 1574, PF_RING_PROMISC | PF_RING_ZC_NOT_REPROGRAM_RSS);
if (ring != NULL) {
printf("Success!\n");
exit(0);
}
int e = errno;
char* msg = strerror(e);
printf("Failure %d: %s\n", e, msg);
exit(1);
}
# ./test-c
Success!
有什么想法吗?
英文:
I want to call pf_ring from Go code using the github.com/google/gopacket/pfring
package and cannot get it working on a Debian 11 (my code is working on Debian 10).
This is my Go code:
package main
import (
"github.com/google/gopacket/pfring"
"log"
)
func main() {
_, err := pfring.NewRing("eno1@0", 1574, pfring.FlagPromisc|pfring.Flag(1<<14))
if err == nil {
log.Printf("Success!")
return
}
log.Fatalf("Failure: %s", err)
}
And when I run it:
# ./test-go
2023/01/24 10:12:25 Failure: pfring NewRing error: no such device
Obviously the eno1 interface exists:
# pf_ringcfg --list-interfaces
Name: eno1 Driver: i40e RSS: 12 [Supported by ZC]
Name: enp3s0f1 Driver: i40e RSS: 12 [Supported by ZC]
Name: enx0a229512eeb9 Driver: cdc_ether RSS: 1 [Linux Driver]
The odd thing is that the same code written in C works:
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <pfring.h>
int main() {
pfring* ring = pfring_open("eno1@0", 1574, PF_RING_PROMISC | PF_RING_ZC_NOT_REPROGRAM_RSS);
if (ring != NULL) {
printf("Success!\n");
exit(0);
}
int e = errno;
char* msg = strerror(e);
printf("Failure %d: %s\n", e, msg);
exit(1);
}
# ./test-c
Success!
Any idea?
答案1
得分: 0
这是gopacket/pfring中的一个错误,详见问题 #147和修复。该库调用pfring_open
时没有报告错误,但是库错误地解释了返回代码。
英文:
It turns out this is a bug in gopacket/pfring, see issue #147 and the fix. The call to pfring_open
made by this library reported no error, but the library misinterpreted the return code.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论