Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

DNAT rule support for both OriginalPort and TranslatedPort #37

Open
pasikarkkainen opened this issue Nov 26, 2016 · 4 comments
Open

DNAT rule support for both OriginalPort and TranslatedPort #37

pasikarkkainen opened this issue Nov 26, 2016 · 4 comments

Comments

@pasikarkkainen
Copy link

It seems edgegateway.go func AddNATMapping(nattype, externalIP, internalIP, port string) lack support for being able to specify separate OriginalPort and TranslatedPort. Currently "port" parameter is used for both:

//add rule
natRule := &types.NatRule{
        RuleType:  nattype,
        IsEnabled: true,
        GatewayNatRule: &types.GatewayNatRule{
                Interface: &types.Reference{
                        HREF: uplink.HREF,
                },
                OriginalIP:     externalIP,
                OriginalPort:   port,
                TranslatedIP:   internalIP,
                TranslatedPort: port,
                Protocol:       "tcp",
        },
}

It'd be great to be able to add more flexible DNAT port mappings.. thoughts?

@pasikarkkainen
Copy link
Author

What's the correct way of fixing this?

Should I perhaps rename the existing AddNATMapping() to something else, say AddNATMappingPorts(), then make it accept separate "originalPort" and "translatedPort" parameters, and then add AddNATMapping() again for backwards "compatibility", making it call the new AddNATMappingPorts() function giving the same "port" parameter as both "originalPort" and "translatedPort" ?

@robcoward
Copy link
Contributor

robcoward commented Mar 2, 2017

Hi @pasikarkkainen, my suggested approach would be to try and keep backwards compatibility for other non-terraform users of the govcloudair library by renaming the current AddNATMapping() function to AddNATPortMapping() and extending the parameters to take src/dest ports, then creating a new wrapper function to replace AddNATMapping() than passed the port through to the new AddNATPortMapping() function as both the src & dst ports:

func (e *EdgeGateway) AddNATMapping(nattype, externalIP, internalIP, port string) (Task, error) {
    return e.AddNATPortMapping(nattype,externalIP,port,internalIP,port)
}

func (e *EdgeGateway) AddNATPortMapping(nattype, externalIP, externalPort string, internalIP, internalPort string) (Task, error) {
...
// Update to the original AddNATMapping() function
	natRule := &types.NatRule{
		RuleType:  nattype,
		IsEnabled: true,
		GatewayNatRule: &types.GatewayNatRule{
			Interface: &types.Reference{
				HREF: uplink.HREF,
			},
			OriginalIP:     externalIP,
			OriginalPort:   externalPort,
			TranslatedIP:   internalIP,
			TranslatedPort: internalPort,
			Protocol:       "tcp",
		},
	}

Please can you submit any PRs against the https://github.com/UKCloud/govcloudair fork of this vmware repo as we are in the process of enhancing the vcloud provider and have updated terraform to pull in our fork. We'll be more than happy to merge your changes. Any work done in our fork will be pushed back upstream to vmware's repo in due course.

@pasikarkkainen
Copy link
Author

PR submitted here:
UKCloud#3

@pasikarkkainen
Copy link
Author

@robcoward: I kept the backwards compatibility as you suggested, so existing AddNATMapping() and RemoveNATMapping() functions call the newly introduced AddNATPortMapping() and RemoveNATPortMapping().

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants