Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit beb2bbb

Browse files
sar772004srinivsr
andauthored
Add support for HOST_INTF env, so vxlan source interface can be chosen physical interface , fixes #71 (#72)
* Add support for HOST_INTF env, so vxlan source interface can be chosen statically * Add comment to getVxlanSource explaining HOST_INTF * add the missing option to getVxlanSource when calling it * Revert "add the missing option to getVxlanSource when calling it" This reverts commit 514b3cc. * add the missing option to getVxlanSource when calling it , removing the spaces added by vscode * add the vxlan srcintf to remotepod definition as well, otherwise it uses default gw intf * fix formatting for the comment * fix the protobuf remotePod def index * fix the protobuf in Pod def index * fix the go bindings * generate the grpc go files for v1beta/meshnet protoc --go-grpc_opt=paths=source_relative --go-grpc_out=. daemon/proto/meshnet/v1beta1/meshnet.proto protoc --go_opt=paths=source_relative --go_out=. daemon/proto/meshnet/v1beta1/meshnet.proto --------- Co-authored-by: srinivsr <srinivasan.sridharan@nokia.com>
1 parent bd8f2e1 commit beb2bbb

File tree

8 files changed

+330
-279
lines changed

8 files changed

+330
-279
lines changed

daemon/meshnet/handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (m *Meshnet) Get(ctx context.Context, pod *mpb.PodQuery) (*mpb.Pod, error)
6464
srcIP, _, _ := unstructured.NestedString(result.Object, "status", "src_ip")
6565
netNs, _, _ := unstructured.NestedString(result.Object, "status", "net_ns")
6666
nodeIP := os.Getenv("HOST_IP")
67+
nodeIntf := os.Getenv("HOST_INTF")
6768

6869
return &mpb.Pod{
6970
Name: pod.Name,
@@ -72,6 +73,7 @@ func (m *Meshnet) Get(ctx context.Context, pod *mpb.PodQuery) (*mpb.Pod, error)
7273
KubeNs: pod.KubeNs,
7374
Links: links,
7475
NodeIp: nodeIP,
76+
NodeIntf: nodeIntf,
7577
}, nil
7678
}
7779

daemon/proto/meshnet/v1beta1/meshnet.pb.go

Lines changed: 265 additions & 242 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

daemon/proto/meshnet/v1beta1/meshnet.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ message Pod {
1212
string kube_ns = 4;
1313
repeated Link links = 5;
1414
string node_ip = 6;
15+
string node_intf = 7;
1516
}
1617

1718
message Link {
@@ -45,6 +46,7 @@ message RemotePod {
4546
string peer_vtep = 4;
4647
string kube_ns = 5;
4748
int64 vni = 6;
49+
string node_intf = 7;
4850
}
4951

5052
// The proto describes both end of a grpc-wire, the local end and the remote
@@ -141,4 +143,4 @@ service Remote {
141143
service WireProtocol {
142144
rpc SendToOnce (Packet) returns (BoolResponse);
143145
rpc SendToStream (stream Packet) returns (BoolResponse);
144-
}
146+
}

daemon/proto/meshnet/v1beta1/meshnet_grpc.pb.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

daemon/vxlan/vxlan.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ func InitLogger() {
2222

2323
// CreateOrUpdate creates or updates the vxlan on the node.
2424
func CreateOrUpdate(v *mpb.RemotePod) error {
25-
/// Looking up default interface
26-
_, srcIntf, err := getSource()
27-
if err != nil {
28-
return err
25+
var srcIntf string
26+
var err error
27+
srcIntf = v.NodeIntf
28+
if srcIntf == "" {
29+
/// Looking up default interface
30+
_, srcIntf, err = getSource()
31+
if err != nil {
32+
return err
33+
}
2934
}
3035

3136
// Creating koko Veth struct

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/sirupsen/logrus v1.8.1
1717
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852
1818
google.golang.org/grpc v1.47.0
19-
google.golang.org/protobuf v1.28.1
19+
google.golang.org/protobuf v1.30.0
2020
k8s.io/apimachinery v0.26.1
2121
k8s.io/client-go v0.26.1
2222
sigs.k8s.io/controller-runtime v0.14.5
@@ -30,12 +30,13 @@ require (
3030
github.com/docker/go-units v0.4.0 // indirect
3131
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
3232
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
33+
github.com/go-errors/errors v1.4.2
3334
github.com/go-logr/logr v1.2.3 // indirect
3435
github.com/go-openapi/jsonpointer v0.19.5 // indirect
3536
github.com/go-openapi/jsonreference v0.20.0 // indirect
3637
github.com/go-openapi/swag v0.19.14 // indirect
3738
github.com/gogo/protobuf v1.3.2 // indirect
38-
github.com/golang/protobuf v1.5.2 // indirect
39+
github.com/golang/protobuf v1.5.3 // indirect
3940
github.com/google/gnostic v0.5.7-v3refs // indirect
4041
github.com/google/gofuzz v1.1.0 // indirect
4142
github.com/imdario/mergo v0.3.6 // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
106106
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
107107
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
108108
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
109+
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
110+
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
109111
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
110112
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
111113
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@@ -163,6 +165,8 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
163165
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
164166
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
165167
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
168+
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
169+
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
166170
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
167171
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
168172
github.com/google/gnostic v0.5.7-v3refs h1:FhTMOKj2VhjpouxvWJAV1TL304uMlb9zcDqkl6cEI54=
@@ -612,6 +616,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
612616
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
613617
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
614618
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
619+
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
620+
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
615621
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
616622
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
617623
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

plugin/meshnet.go

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -84,32 +84,43 @@ func loadConf(bytes []byte) (*netConf, *current.Result, error) {
8484
}
8585

8686
// getVxlanSource uses netlink to get the iface reliably given an IP address.
87-
func getVxlanSource(nodeIP string) (string, string, error) {
88-
if nodeIP == "" {
89-
return "", "", fmt.Errorf("meshnetd provided no HOST_IP address: %s", nodeIP)
90-
}
91-
nIP := net.ParseIP(nodeIP)
92-
if nIP == nil {
93-
return "", "", fmt.Errorf("parsing failed for meshnetd provided no HOST_IP address: %s", nodeIP)
94-
}
95-
ifaces, _ := net.Interfaces()
96-
for _, i := range ifaces {
97-
addrs, _ := i.Addrs()
98-
for _, a := range addrs {
99-
var ip net.IP
100-
switch v := a.(type) {
101-
case *net.IPNet:
102-
ip = v.IP
103-
case *net.IPAddr:
104-
ip = v.IP
105-
}
106-
if nIP.Equal(ip) {
107-
log.Infof("Found iface %s for address %s", i.Name, nodeIP)
108-
return nodeIP, i.Name, nil
109-
}
110-
}
111-
}
112-
return "", "", fmt.Errorf("no iface found for address %s", nodeIP)
87+
// when IP and Interface both are present then Interface is going to take preference
88+
// nodeIntf is specified by the user and it's not auto discovered. The user has to be careful that the peer is reachable though this interface otherwise, VxLAN may not work.
89+
// daemonset.yaml meshnet container env required for host_intf override
90+
// env:
91+
// - name: HOST_INTF
92+
// value: breth2
93+
func getVxlanSource(nodeIP string, nodeIntf string) (string, string, error) {
94+
if nodeIntf == "" && nodeIP == "" {
95+
return "", "", fmt.Errorf("meshnetd provided no HOST_IP address: %s or HOST_INTF: %s", nodeIP, nodeIntf)
96+
}
97+
nIP := net.ParseIP(nodeIP)
98+
if nIP == nil && nodeIntf == "" {
99+
return "", "", fmt.Errorf("parsing failed for meshnetd provided no HOST_IP address: %s and node HOST_INTF: %s", nodeIP, nodeIntf)
100+
}
101+
ifaces, _ := net.Interfaces()
102+
for _, i := range ifaces {
103+
addrs, _ := i.Addrs()
104+
for _, a := range addrs {
105+
var ip net.IP
106+
switch v := a.(type) {
107+
case *net.IPNet:
108+
ip = v.IP
109+
case *net.IPAddr:
110+
ip = v.IP
111+
}
112+
if nodeIntf != "" {
113+
if i.Name == nodeIntf {
114+
return ip.String(), nodeIntf, nil
115+
}
116+
}
117+
if nIP != nil && nIP.Equal(ip) {
118+
log.Infof("Found iface %s for address %s", i.Name, nodeIP)
119+
return nodeIP, i.Name, nil
120+
}
121+
}
122+
}
123+
return "", "", fmt.Errorf("no iface found for address %s", nodeIP)
113124
}
114125

115126
// -------------------------------------------------------------------------------------------------
@@ -182,7 +193,7 @@ func cmdAdd(args *skel.CmdArgs) error {
182193
}
183194

184195
// Finding the source IP and interface for VXLAN VTEP
185-
srcIP, srcIntf, err := getVxlanSource(localPod.NodeIp)
196+
srcIP, srcIntf, err := getVxlanSource(localPod.NodeIp, localPod.NodeIntf)
186197
if err != nil {
187198
return err
188199
}
@@ -349,6 +360,7 @@ func cmdAdd(args *skel.CmdArgs) error {
349360
PeerVtep: localPod.SrcIp,
350361
Vni: link.Uid + vxlanBase,
351362
KubeNs: string(cniArgs.K8S_POD_NAMESPACE),
363+
NodeIntf: srcIntf,
352364
}
353365

354366
url := fmt.Sprintf("%s:%s", peerPod.SrcIp, defaultPort)

0 commit comments

Comments
 (0)