Skip to content

Commit

Permalink
Revamp port forwarding to support UDP
Browse files Browse the repository at this point in the history
Signed-off-by: Balaji Vijayakumar <kuttibalaji.v6@gmail.com>
  • Loading branch information
balajiv113 committed Jul 1, 2024
1 parent f7108eb commit aade4fa
Show file tree
Hide file tree
Showing 23 changed files with 1,023 additions and 79 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ on:
- "**.md"
env:
LIMACTL_CREATE_ARGS: ""
LIMA_GRPC_PORT_FORWARDER: true

jobs:
lints:
Expand Down
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
184 changes: 150 additions & 34 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

0 comments on commit aade4fa

Please sign in to comment.