简体   繁体   English

从 Go 打开 pfring: pfring NewRing error: no such device

[英]Opening a pfring from Go: pfring NewRing error: no such device

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).我想使用github.com/google/gopacket/pfring package 从 Go 代码调用 pf_ring,但无法在 Debian 11 上运行(我的代码在 Debian 10 上运行)。

This is my Go code:这是我的 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)
}

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:显然 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] 

The odd thing is that the same code written in C works:奇怪的是,在 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!

Any idea?任何的想法?

It turns out this is a bug in gopacket/pfring, see issue #147 and the fix .事实证明这是 gopacket/pfring 中的一个错误,请参见问题 #147修复 The call to pfring_open made by this library reported no error, but the library misinterpreted the return code.该库对pfring_open的调用未报告错误,但该库错误解释了返回码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM