打开一个来自Go的pfring:pfring NewRing错误:没有这样的设备

huangapple go评论78阅读模式
英文:

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 (
	&quot;github.com/google/gopacket/pfring&quot;
	&quot;log&quot;
)

func main() {
	_, err := pfring.NewRing(&quot;eno1@0&quot;, 1574, pfring.FlagPromisc|pfring.Flag(1&lt;&lt;14))
	if err == nil {
		log.Printf(&quot;Success!&quot;)
		return
	}
	log.Fatalf(&quot;Failure: %s&quot;, 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 &lt;errno.h&gt;
#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;pfring.h&gt;

int main() {
	pfring* ring = pfring_open(&quot;eno1@0&quot;, 1574, PF_RING_PROMISC | PF_RING_ZC_NOT_REPROGRAM_RSS);
	if (ring != NULL) {
		printf(&quot;Success!\n&quot;);
		exit(0);
	}
	int e = errno;
	char* msg = strerror(e);
	printf(&quot;Failure %d: %s\n&quot;, 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.

huangapple
  • 本文由 发表于 2023年1月24日 17:20:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75219485.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定