Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp port forwarding to support UDP #2411

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/lima-guestagent/daemon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/lima-vm/lima/pkg/guestagent"
"github.com/lima-vm/lima/pkg/guestagent/api/server"
"github.com/lima-vm/lima/pkg/guestagent/serialport"
"github.com/lima-vm/lima/pkg/portfwdserver"
"github.com/mdlayher/vsock"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -91,5 +92,5 @@ func daemonAction(cmd *cobra.Command, _ []string) error {
l = socketL
logrus.Infof("serving the guest agent on %q", socket)
}
return server.StartServer(l, &server.GuestServer{Agent: agent})
return server.StartServer(l, &server.GuestServer{Agent: agent, TunnelS: portfwdserver.NewTunnelServer()})
}
13 changes: 13 additions & 0 deletions pkg/guestagent/api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"math"
"net"

"github.com/lima-vm/lima/pkg/guestagent/api"
Expand All @@ -16,6 +17,10 @@ type GuestAgentClient struct {

func NewGuestAgentClient(dialFn func(ctx context.Context) (net.Conn, error)) (*GuestAgentClient, error) {
opts := []grpc.DialOption{
grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(math.MaxInt64),
grpc.MaxCallSendMsgSize(math.MaxInt64),
),
grpc.WithContextDialer(func(ctx context.Context, _ string) (net.Conn, error) {
return dialFn(ctx)
}),
Expand Down Expand Up @@ -59,3 +64,11 @@ func (c *GuestAgentClient) Inotify(ctx context.Context) (api.GuestService_PostIn
}
return inotify, nil
}

func (c *GuestAgentClient) Tunnel(ctx context.Context) (api.GuestService_TunnelClient, error) {
stream, err := c.cli.Tunnel(ctx)
if err != nil {
return nil, err
}
return stream, nil
}
22 changes: 15 additions & 7 deletions pkg/guestagent/api/guestservice.pb.desc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

”
ô
guestservice.protogoogle/protobuf/empty.protogoogle/protobuf/timestamp.proto"0
Info(
local_ports ( 2.IPPortR
Expand All @@ -8,15 +8,23 @@ localPorts"
time ( 2.google.protobuf.TimestampRtime3
local_ports_added ( 2.IPPortRlocalPortsAdded7
local_ports_removed ( 2.IPPortRlocalPortsRemoved
errors ( Rerrors",
IPPort
ip ( Rip
port (Rport"X
errors ( Rerrors"H
IPPort
protocol ( Rprotocol
ip ( Rip
port (Rport"X
Inotify

mount_path ( R mountPath.
time ( 2.google.protobuf.TimestampRtime2š
time ( 2.google.protobuf.TimestampRtime"“
TunnelMessage
id ( Rid
protocol ( Rprotocol
data ( Rdata
guestAddr ( R guestAddr$
udpTargetAddr ( RudpTargetAddr2È
GuestService(
GetInfo.google.protobuf.Empty.Info-
GetEvents.google.protobuf.Empty.Event01
PostInotify.Inotify.google.protobuf.Empty(B!Zgithub.com/lima-vm/lima/pkg/apibproto3
PostInotify.Inotify.google.protobuf.Empty(,
Tunnel.TunnelMessage.TunnelMessage(0B!Zgithub.com/lima-vm/lima/pkg/apibproto3
Expand Down
186 changes: 151 additions & 35 deletions pkg/guestagent/api/guestservice.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions pkg/guestagent/api/guestservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ service GuestService {
rpc GetInfo(google.protobuf.Empty) returns (Info);
rpc GetEvents(google.protobuf.Empty) returns (stream Event);
rpc PostInotify(stream Inotify) returns (google.protobuf.Empty);

rpc Tunnel(stream TunnelMessage) returns (stream TunnelMessage);
}

message Info {
Expand All @@ -22,11 +24,20 @@ message Event {
}

message IPPort {
string ip = 1;
int32 port = 2;
string protocol = 1; //tcp, udp
string ip = 2;
int32 port = 3;
}

message Inotify {
string mount_path = 1;
google.protobuf.Timestamp time = 2;
}

message TunnelMessage {
string id = 1;
string protocol = 2; //tcp, udp
bytes data = 3;
string guestAddr = 4;
string udpTargetAddr = 5;
}
Loading
Loading