Skip to content

Commit

Permalink
fix: udp match port range
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaizenghui committed Dec 19, 2024
1 parent 9e2c67b commit c34034f
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions iptables/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -10314,23 +10314,28 @@ func (mUDP *MatchUDP) Short() string {
func (mUDP *MatchUDP) ShortArgs() []string {
args := make([]string, 0, 17)
args = append(args, "-m", mUDP.matchType.String())
if mUDP.SrcPortMin > -1 {
if mUDP.SrcPortMin > -1 && mUDP.SrcPortMax > -1 {
if mUDP.SrcPortInvert {
args = append(args, "!")
}
args = append(args, "--sport", strconv.Itoa(mUDP.SrcPortMin))
if mUDP.SrcPortMax > -1 {
args = append(args, ":"+strconv.Itoa(mUDP.SrcPortMax))
args = append(args, "--sport", strconv.Itoa(mUDP.SrcPortMin)+":"+strconv.Itoa(mUDP.SrcPortMax))
} else if mUDP.SrcPortMin > -1 {
if mUDP.SrcPortInvert {
args = append(args, "!")
}
args = append(args, "--sport", strconv.Itoa(mUDP.SrcPortMin))
}
if mUDP.DstPortMin > -1 {

if mUDP.DstPortMin > -1 && mUDP.DstPortMax > -1 {
if mUDP.DstPortInvert {
args = append(args, "!")
}
args = append(args, "--dport", strconv.Itoa(mUDP.DstPortMin))
if mUDP.DstPortMax > -1 {
args = append(args, ":"+strconv.Itoa(mUDP.DstPortMax))
args = append(args, "--dport", strconv.Itoa(mUDP.DstPortMin)+":"+strconv.Itoa(mUDP.DstPortMax))
} else if mUDP.DstPortMin > -1 {
if mUDP.DstPortInvert {
args = append(args, "!")
}
args = append(args, "--dport", strconv.Itoa(mUDP.DstPortMin))
}
return args
}
Expand All @@ -10342,23 +10347,28 @@ func (mUDP *MatchUDP) Long() string {
func (mUDP *MatchUDP) LongArgs() []string {
args := make([]string, 0, 17)
args = append(args, "-m", mUDP.matchType.String())
if mUDP.SrcPortMin > -1 {
if mUDP.SrcPortMin > -1 && mUDP.SrcPortMax > -1 {
if mUDP.SrcPortInvert {
args = append(args, "!")
}
args = append(args, "--source-port", strconv.Itoa(mUDP.SrcPortMin))
if mUDP.SrcPortMax > -1 {
args = append(args, ":"+strconv.Itoa(mUDP.SrcPortMax))
args = append(args, "--source-port", strconv.Itoa(mUDP.SrcPortMin)+":"+strconv.Itoa(mUDP.SrcPortMax))
} else if mUDP.SrcPortMin > -1 {
if mUDP.SrcPortInvert {
args = append(args, "!")
}
args = append(args, "--source-port", strconv.Itoa(mUDP.SrcPortMin))
}
if mUDP.DstPortMin > -1 {

if mUDP.DstPortMin > -1 && mUDP.DstPortMax > -1 {
if mUDP.DstPortInvert {
args = append(args, "!")
}
args = append(args, "--destination-port", strconv.Itoa(mUDP.DstPortMin))
if mUDP.DstPortMax > -1 {
args = append(args, ":"+strconv.Itoa(mUDP.DstPortMax))
args = append(args, "--destination-port", strconv.Itoa(mUDP.DstPortMin)+":"+strconv.Itoa(mUDP.DstPortMax))
} else if mUDP.DstPortMin > -1 {
if mUDP.DstPortInvert {
args = append(args, "!")
}
args = append(args, "--destination-port", strconv.Itoa(mUDP.DstPortMin))
}
return args
}
Expand Down

0 comments on commit c34034f

Please sign in to comment.