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?
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.