Skip to content

Commit

Permalink
Not always listen on TCP
Browse files Browse the repository at this point in the history
This change provides the protocol when calling expose or unexpose API requests.
This is vital to ensure we listen on the correct protocol instead of always defaulting to TCP.

Signed-off-by: Nino Kodabande <[email protected]>
  • Loading branch information
Nino-K committed Oct 10, 2024
1 parent 9c4941f commit 36d2b6e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/go/guestagent/pkg/tracker/apitracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (a *APITracker) Add(containerID string, portMap nat.PortMap) error {
for portProto, portBindings := range portMap {
var tmpPortBinding []nat.PortBinding

log.Debugf("called add with portProto: %+v, portBindings: %+v\n", portProto, portBindings)

for _, portBinding := range portBindings {
// The expose API only supports IPv4
ipv4, err := isIPv4(portBinding.HostIP)
Expand All @@ -100,8 +102,9 @@ func (a *APITracker) Add(containerID string, portMap nat.PortMap) error {

err = a.apiForwarder.Expose(
&types.ExposeRequest{
Local: ipPortBuilder(a.determineHostIP(portBinding.HostIP), portBinding.HostPort),
Remote: ipPortBuilder(a.tapInterfaceIP, portBinding.HostPort),
Local: ipPortBuilder(a.determineHostIP(portBinding.HostIP), portBinding.HostPort),
Remote: ipPortBuilder(a.tapInterfaceIP, portBinding.HostPort),
Protocol: types.TransportProtocol(portProto.Proto()),
})
if err != nil {
errs = append(errs, fmt.Errorf("exposing %+v failed: %w", portBinding, err))
Expand Down Expand Up @@ -147,7 +150,7 @@ func (a *APITracker) Remove(containerID string) error {

var errs []error

for _, portBindings := range portMap {
for portProto, portBindings := range portMap {
for _, portBinding := range portBindings {
// The unexpose API only supports IPv4
ipv4, err := isIPv4(portBinding.HostIP)
Expand All @@ -160,7 +163,8 @@ func (a *APITracker) Remove(containerID string) error {

err = a.apiForwarder.Unexpose(
&types.UnexposeRequest{
Local: ipPortBuilder(a.determineHostIP(portBinding.HostIP), portBinding.HostPort),
Local: ipPortBuilder(a.determineHostIP(portBinding.HostIP), portBinding.HostPort),
Protocol: types.TransportProtocol(portProto.Proto()),
})
if err != nil {
errs = append(errs,
Expand Down

0 comments on commit 36d2b6e

Please sign in to comment.