y805939188/simple-k8s-cni

问题

Opened this issue · 2 comments

请问veth_ingress代码中

bpf_memcpy(src_mac, ep->nodeMac, ETH_ALEN);
bpf_memcpy(dst_mac, ep->mac, ETH_ALEN);
bpf_skb_store_bytes(skb, offsetof(struct ethhdr, h_source), dst_mac, ETH_ALEN, 0);
bpf_skb_store_bytes(skb, offsetof(struct ethhdr, h_dest), src_mac, ETH_ALEN, 0);
return bpf_redirect_peer(ep->lxcIfIndex, 0);

h_source 为什么是dst_mac ,h_dest为什么是src_mac ,这里不是太理解
不应该是h_source设置为nodeMac(留在host空间的网卡mac地址),h_dest设置为mac(留在ns空间的mac地址)吗?为什么是反的喃?
请作者大大帮忙解答一下。

我发现,改成这样也没有什么问题

bpf_memcpy(src_mac, ep->nodeMac, ETH_ALEN);
bpf_memcpy(dst_mac, ep->mac, ETH_ALEN);
bpf_skb_store_bytes(skb, offsetof(struct ethhdr, h_source), src_mac, ETH_ALEN, 0);
bpf_skb_store_bytes(skb, offsetof(struct ethhdr, h_dest), dst_mac, ETH_ALEN, 0);
return bpf_redirect_peer(ep->lxcIfIndex, 0);

我发现,改成这样也没有什么问题

bpf_memcpy(src_mac, ep->nodeMac, ETH_ALEN);
bpf_memcpy(dst_mac, ep->mac, ETH_ALEN);
bpf_skb_store_bytes(skb, offsetof(struct ethhdr, h_source), src_mac, ETH_ALEN, 0);
bpf_skb_store_bytes(skb, offsetof(struct ethhdr, h_dest), dst_mac, ETH_ALEN, 0);
return bpf_redirect_peer(ep->lxcIfIndex, 0);

这个可能是我当时手误写错了。但是当前的现象是交换过来也能跑通的话,我猜有三个可能,一个是 bpf_redirect_peer 内部做了一些 magic,一个是 veth 的收发函数内部做了一些 magic。比如正常情况下一块儿网卡发现 dst mac 不是自己的,就把这个 skb 给丢了,但是可能是 bpf_redirect_peer 或者 veth 他俩之中的谁做了类似 “ dst mac 不是当前网卡,但是当前是一个 veth 网卡,所以就往另外一半的 veth pair 也试一试吧”之类的操作。第三个可能就是无意中给 veth 开启了类似 “混杂模式” 之类的配置项,导致 veth 能接受 dst mac 不是自己的包。
我个人估摸着可能大概率就是这仨原因之一。有时间的话你可以试下。如果试出来是哪种情况的话可以再告诉我,谢谢。