-
Notifications
You must be signed in to change notification settings - Fork 388
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
Add port validator to ensure configurable ports are valid #7037
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these all the port numbers we want to validate? what about tunnelPort
(we mentioned it in the issue)?
also you are not referencing issue #7035
cmd/antrea-agent/util.go
Outdated
@@ -79,3 +79,11 @@ func parsePortRange(portRangeStr string) (start, end int, err error) { | |||
|
|||
return start, end, nil | |||
} | |||
|
|||
// isValidPort checks if the given port number is within the valid range of 1 to 65535. | |||
func isValidPort(port int) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't need to be "exported"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not required at the moment, but I will go through and double check if I missed any port beside tunnelPort. I have updated the changes for tunnelPort.
699efa6
to
069be9b
Compare
Signed-off-by: Lan Luo <lan.luo@broadcom.com>
069be9b
to
f310d4f
Compare
@@ -193,7 +195,7 @@ func (o *Options) setDefaults() { | |||
if o.config.OVSRunDir == "" { | |||
o.config.OVSRunDir = ovsconfig.DefaultOVSRunDir | |||
} | |||
if o.config.APIPort == 0 { | |||
if !checks.IsValidPort(o.config.APIPort) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be better to give an error if the port is not valid (and non-zero), like you do for tunnelPort
below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe pkg/util/config/validate.go
would be a better location for this function?
if !checks.IsValidPort(portNum) || err != nil { | ||
port = "443" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here also it seems like silently dropping an error may not be the right thing to do?
maybe the function could return an error?
Resolves #7035