Ejemplo n.º 1
0
func NewIngressChain(chain [4]int) (*IngressChain, error) {
	cflags := []string{
		fmt.Sprintf("-DCHAIN_VALUE0=%#x", chain[0]),
		fmt.Sprintf("-DCHAIN_VALUE1=%#x", chain[1]),
		fmt.Sprintf("-DCHAIN_VALUE2=%#x", chain[2]),
		fmt.Sprintf("-DCHAIN_VALUE3=%#x", chain[3]),
	}
	//Debug.Printf("netdev: %v\n", cflags)
	bpf := bpf.NewBpfModule(bpf.NetdevRxC, cflags)
	if bpf == nil {
		return nil, fmt.Errorf("NewIngressChain bpf compile failed")
	}
	defer bpf.Close()
	fd, err := bpf.LoadNet("ingress")
	if err != nil {
		return nil, err
	}
	fd2, err := syscall.Dup(fd)
	if err != nil {
		return nil, err
	}
	return &IngressChain{fd: fd2}, nil
}
Ejemplo n.º 2
0
func (ifc *ExtInterface) FD() int {
	if ifc.NodeBase.FD() >= 0 {
		return ifc.NodeBase.FD()
	}
	cflags := []string{
		fmt.Sprintf("-DINTERFACE_ID=%d", ifc.link.Attrs().Index),
	}
	bpf := bpf.NewBpfModule(bpf.NetdevTxC, cflags)
	if bpf == nil {
		panic(fmt.Errorf("Failed to compile bpf module for %s egress", ifc.Path()))
	}
	// free the llvm memory, just keep the fd
	defer bpf.Close()
	fd, err := bpf.LoadNet("egress")
	if err != nil {
		panic(err)
	}
	fd2, err := syscall.Dup(fd)
	if err != nil {
		panic(err)
	}
	ifc.NodeBase.SetFD(fd2)
	return ifc.NodeBase.FD()
}