mirror of
https://github.com/decke/smtprelay.git
synced 2025-12-25 18:22:28 -07:00
Simplify peerIP determination in connectionChecker()
peerIP = net.ParseIP(addr.IP.String())
can be simplified to just:
peerIP = addr.IP
but we can also skip the safe cast since we know the net.Addr will always
be net.TCPAddr because we only have TCP listeners.
This commit is contained in:
10
main.go
10
main.go
@@ -17,14 +17,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func connectionChecker(peer smtpd.Peer) error {
|
func connectionChecker(peer smtpd.Peer) error {
|
||||||
var peerIP net.IP
|
// This can't panic because we only have TCP listeners
|
||||||
if addr, ok := peer.Addr.(*net.TCPAddr); ok {
|
peerIP := peer.Addr.(*net.TCPAddr).IP
|
||||||
peerIP = net.ParseIP(addr.IP.String())
|
|
||||||
} else {
|
|
||||||
log.WithField("ip", addr.IP).
|
|
||||||
Warn("failed to parse IP")
|
|
||||||
return smtpd.Error{Code: 421, Message: "Denied"}
|
|
||||||
}
|
|
||||||
|
|
||||||
nets := strings.Split(*allowedNets, " ")
|
nets := strings.Split(*allowedNets, " ")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user