all: fix install.sh, imp aghnet functions

This commit is contained in:
f.setrakov 2025-09-23 15:54:12 +03:00
parent 7c746cbf88
commit 06d172cc12
3 changed files with 6 additions and 47 deletions

View File

@ -124,7 +124,7 @@ func discover4(iface *net.Interface, dstAddr *net.UDPAddr, hostname string) (ok
for {
var next bool
ok, next, err = getDHCP4Response(req, c, iface)
ok, next, err = tryConn4(req, c, iface)
if next {
continue
}
@ -137,25 +137,6 @@ func discover4(iface *net.Interface, dstAddr *net.UDPAddr, hostname string) (ok
}
}
// getDHCP4Response reads and validates DHCP response from [net.PacketConn].
// req, c and iface must not be nil.
func getDHCP4Response(
req *dhcpv4.DHCPv4,
c net.PacketConn,
iface *net.Interface,
) (ok, next bool, err error) {
ok, next, err = tryConn4(req, c, iface)
if next {
return false, next, err
}
if err != nil {
return false, false, err
}
return ok, false, nil
}
// tryConn4 reads and validates DHCPv4 response packet if it matches
// the original request. req and c must not be nil.
//
@ -169,6 +150,7 @@ func tryConn4(
if err = c.SetDeadline(time.Now().Add(defaultDiscoverTime)); err != nil {
return false, false, fmt.Errorf("setting deadline: %w", err)
}
// TODO: replicate dhclient's behavior of retrying several times with
// progressively longer timeouts.
log.Tracef("dhcpv4: waiting %v for an answer", defaultDiscoverTime)
@ -267,7 +249,7 @@ func discover6(iface *net.Interface, udpAddr, dstAddr *net.UDPAddr) (ok bool, er
for {
var next bool
ok, next, err = getDHCP6Response(req, c)
ok, next, err = tryConn6(req, c)
if next {
continue
}
@ -280,25 +262,6 @@ func discover6(iface *net.Interface, udpAddr, dstAddr *net.UDPAddr) (ok bool, er
}
}
// getDHCP6Response reads and validates DHCP response from [net.PacketConn].
// req and c must not be nil.
func getDHCP6Response(req *dhcpv6.Message, c net.PacketConn) (ok, next bool, err error) {
ok, next, err = tryConn6(req, c)
if next {
if err != nil {
log.Debug("dhcpv6: trying a connection: %s", err)
}
return false, next, err
}
if err != nil {
return false, false, err
}
return ok, false, nil
}
// tryConn6 reads and validates DHCPv6 response packet if it matches
// the original request. req and c must not be nil.
//

View File

@ -160,7 +160,7 @@ func NetInterfaceFrom(iface *net.Interface) (niface *NetInterface, err error) {
return niface, nil
}
// populateAddrs fills *NetInterface IP addresses and subnets. niface
// populateAddrs fills *NetInterface IP addresses and subnets. addr and niface
// must not be nil.
func populateAddrs(addr net.Addr, niface *NetInterface) (err error) {
n, err := ipNetFromAddr(addr)
@ -198,11 +198,7 @@ func ipNetFromAddr(addr net.Addr) (ip *net.IPNet, err error) {
ipNet, ok := addr.(*net.IPNet)
if !ok {
// Should be *net.IPNet, this is weird.
return nil, fmt.Errorf("expected %[2]s to be %[1]T, got %[2]T", ipNet, addr)
}
if ip4 := ipNet.IP.To4(); ip4 != nil {
ipNet.IP = ip4
return nil, fmt.Errorf("bad type for interface net.Addr %T(%[1]v)", ipNet)
}
return ipNet, nil

View File

@ -301,7 +301,7 @@ fix_darwin() {
# Function fix_freebsd performs some fixes to make it work on FreeBSD.
fix_freebsd() {
if "$os" != 'freebsd'; then
if [ "$os" != 'freebsd' ]; then
return 0
fi