@@ -18,13 +18,16 @@ import (
18
18
19
19
"k8s.io/apimachinery/pkg/util/sets"
20
20
kapi "k8s.io/kubernetes/pkg/api"
21
+
22
+ "github.com/vishvananda/netlink"
21
23
)
22
24
23
25
type ovsController struct {
24
26
ovs ovs.Interface
25
27
pluginId int
26
28
useConnTrack bool
27
29
localIP string
30
+ tunMAC string
28
31
}
29
32
30
33
const (
@@ -83,6 +86,13 @@ func (oc *ovsController) SetupOVS(clusterNetworkCIDR []string, serviceNetworkCID
83
86
if err != nil {
84
87
return err
85
88
}
89
+ if oc .tunMAC == "" {
90
+ link , err := netlink .LinkByName (Tun0 )
91
+ if err != nil {
92
+ return err
93
+ }
94
+ oc .tunMAC = link .Attrs ().HardwareAddr .String ()
95
+ }
86
96
87
97
otx := oc .ovs .NewTransaction ()
88
98
@@ -94,6 +104,7 @@ func (oc *ovsController) SetupOVS(clusterNetworkCIDR []string, serviceNetworkCID
94
104
for _ , clusterCIDR := range clusterNetworkCIDR {
95
105
otx .AddFlow ("table=0, priority=200, in_port=1, arp, nw_src=%s, nw_dst=%s, actions=move:NXM_NX_TUN_ID[0..31]->NXM_NX_REG0[],goto_table:10" , clusterCIDR , localSubnetCIDR )
96
106
otx .AddFlow ("table=0, priority=200, in_port=1, ip, nw_src=%s, actions=move:NXM_NX_TUN_ID[0..31]->NXM_NX_REG0[],goto_table:10" , clusterCIDR )
107
+ otx .AddFlow ("table=0, priority=200, in_port=1, ip, nw_dst=%s, actions=move:NXM_NX_TUN_ID[0..31]->NXM_NX_REG0[],goto_table:10" , clusterCIDR )
97
108
}
98
109
otx .AddFlow ("table=0, priority=150, in_port=1, actions=drop" )
99
110
// tun0
@@ -693,7 +704,7 @@ func (oc *ovsController) UpdateNamespaceEgressRules(vnid uint32, nodeIP, egressH
693
704
otx .AddFlow ("table=100, priority=100, reg0=%d, actions=drop" , vnid )
694
705
} else if nodeIP == oc .localIP {
695
706
// Local Egress IP
696
- otx .AddFlow ("table=100, priority=100, reg0=%d, ip, actions=set_field:%s->pkt_mark,output:2" , vnid , egressHex )
707
+ otx .AddFlow ("table=100, priority=100, reg0=%d, ip, actions=set_field:%s->eth_dst,set_field:%s-> pkt_mark,output:2" , vnid , oc . tunMAC , egressHex )
697
708
} else {
698
709
// Remote Egress IP; send via VXLAN
699
710
otx .AddFlow ("table=100, priority=100, reg0=%d, ip, actions=move:NXM_NX_REG0[]->NXM_NX_TUN_ID[0..31],set_field:%s->tun_dst,output:1" , vnid , nodeIP )
0 commit comments