@@ -18,6 +18,7 @@ import (
18
18
"fmt"
19
19
"net"
20
20
"os"
21
+ "strconv"
21
22
"strings"
22
23
"time"
23
24
@@ -34,6 +35,7 @@ import (
34
35
agentconfig "antrea.io/antrea/pkg/config/agent"
35
36
"antrea.io/antrea/pkg/features"
36
37
"antrea.io/antrea/pkg/ovs/ovsconfig"
38
+ "antrea.io/antrea/pkg/util/checks"
37
39
"antrea.io/antrea/pkg/util/env"
38
40
"antrea.io/antrea/pkg/util/flowexport"
39
41
"antrea.io/antrea/pkg/util/ip"
@@ -193,7 +195,7 @@ func (o *Options) setDefaults() {
193
195
if o .config .OVSRunDir == "" {
194
196
o .config .OVSRunDir = ovsconfig .DefaultOVSRunDir
195
197
}
196
- if o .config .APIPort == 0 {
198
+ if ! checks . IsValidPort ( o .config .APIPort ) {
197
199
o .config .APIPort = apis .AntreaAgentAPIPort
198
200
}
199
201
if o .config .NodeType == "" {
@@ -430,13 +432,13 @@ func (o *Options) setK8sNodeDefaultOptions() {
430
432
if o .config .AntreaProxy .DefaultLoadBalancerMode == "" {
431
433
o .config .AntreaProxy .DefaultLoadBalancerMode = config .LoadBalancerModeNAT .String ()
432
434
}
433
- if o .config .ClusterMembershipPort == 0 {
435
+ if ! checks . IsValidPort ( o .config .ClusterMembershipPort ) {
434
436
o .config .ClusterMembershipPort = apis .AntreaAgentClusterMembershipPort
435
437
}
436
438
if o .config .EnablePrometheusMetrics == nil {
437
439
o .config .EnablePrometheusMetrics = ptr .To (true )
438
440
}
439
- if o .config .WireGuard .Port == 0 {
441
+ if ! checks . IsValidPort ( o .config .WireGuard .Port ) {
440
442
o .config .WireGuard .Port = apis .WireGuardListenPort
441
443
}
442
444
@@ -534,6 +536,9 @@ func (o *Options) validateK8sNodeOptions() error {
534
536
o .config .TunnelType != ovsconfig .GRETunnel && o .config .TunnelType != ovsconfig .STTTunnel {
535
537
return fmt .Errorf ("tunnel type %s is invalid" , o .config .TunnelType )
536
538
}
539
+ if ! checks .IsValidPort (int (o .config .TunnelPort )) {
540
+ return fmt .Errorf ("tunnel port %d is invalid" , o .config .TunnelPort )
541
+ }
537
542
ok , encryptionMode := config .GetTrafficEncryptionModeFromStr (o .config .TrafficEncryptionMode )
538
543
if ! ok {
539
544
return fmt .Errorf ("TrafficEncryptionMode %s is unknown" , o .config .TrafficEncryptionMode )
@@ -605,8 +610,9 @@ func (o *Options) validateK8sNodeOptions() error {
605
610
606
611
if o .config .DNSServerOverride != "" {
607
612
hostPort := ip .AppendPortIfMissing (o .config .DNSServerOverride , "53" )
608
- _ , _ , err := net .SplitHostPort (hostPort )
609
- if err != nil {
613
+ _ , port , err := net .SplitHostPort (hostPort )
614
+ portNum , parseErr := strconv .Atoi (port )
615
+ if err != nil || ! checks .IsValidPort (portNum ) || parseErr != nil {
610
616
return fmt .Errorf ("dnsServerOverride %s is invalid: %v" , o .config .DNSServerOverride , err )
611
617
}
612
618
o .dnsServerOverride = hostPort
@@ -706,7 +712,7 @@ func (o *Options) setExternalNodeDefaultOptions() {
706
712
func (o * Options ) setMulticlusterDefaultOptions () {
707
713
_ , trafficEncryptionModeType := config .GetTrafficEncryptionModeFromStr (o .config .Multicluster .TrafficEncryptionMode )
708
714
if trafficEncryptionModeType == config .TrafficEncryptionModeWireGuard {
709
- if o .config .Multicluster .WireGuard .Port == 0 {
715
+ if ! checks . IsValidPort ( o .config .Multicluster .WireGuard .Port ) {
710
716
o .config .Multicluster .WireGuard .Port = apis .MulticlusterWireGuardListenPort
711
717
}
712
718
}
0 commit comments