checker: Use OnFinish to perform need tips about firewall
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2023-03-18 11:22:46 +01:00
parent 11bf5362a3
commit d61f28875e
2 changed files with 23 additions and 10 deletions

View File

@ -96,7 +96,7 @@ func studentChecker(std *adlin.Student, also_check_matrix bool, offline bool) {
if _, err := std.UnlockChallenge(CheckMap[tunnel_version][PingResolver], ""); err != nil {
log.Printf("Unable to register challenge for %s: %s\n", std.Login, err.Error())
}
})
}, nil)
}
// Firewalled
@ -368,17 +368,29 @@ func studentChecker(std *adlin.Student, also_check_matrix bool, offline bool) {
}
return
}, func(stats *ping.Statistics) {
if verbose2 {
log.Printf("%s: %s ping statistics: %d packets transmitted, %d packets received, %v%% packet loss", std.Login, stdIP, stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss)
}
if stats.PacketsRecv > 0 {
return
}
tunnel_version, err := minTunnelVersion(std, tun.SuffixIP)
if err != nil {
return
}
if !has_test(CheckMap[tunnel_version], Firewalled) {
return
}
if e, err := std.GetChallengeError(CheckMap[tunnel_version][Firewalled]); err == nil && len(e.Error) > 0 {
std.RegisterChallengeError(CheckMap[tunnel_version][Firewalled], fmt.Errorf("Your host is unreachable, no more tests are performed. Check that you are not filtering the tunnel (Wireguard uses UDP datagrams), nor ICMPv6 as your host needs to respond to PING."))
}
})
if err != nil && verbose {
log.Printf("%s: Unable to perform ping to %s: %s", std.Login, stdIP, err.Error())
if tunnel_version, err := minTunnelVersion(std, tun.SuffixIP); err == nil {
if has_test(CheckMap[tunnel_version], Firewalled) {
if e, err := std.GetChallengeError(CheckMap[tunnel_version][Firewalled]); err == nil && len(e.Error) > 0 {
std.RegisterChallengeError(CheckMap[tunnel_version][Firewalled], fmt.Errorf("Your host is unreachable, no more tests are performed. Check that you are not filtering the tunnel (Wireguard uses UDP datagrams), nor ICMPv6 as your host needs to respond to PING."))
}
}
}
}
}
}

View File

@ -98,7 +98,7 @@ func has_test(m map[AdlinTest]int, test AdlinTest) bool {
// ICMP
func check_ping(ip string, cb func(pkt *ping.Packet)) (err error) {
func check_ping(ip string, cb func(pkt *ping.Packet), cb_finished func(stats *ping.Statistics)) (err error) {
var pinger *ping.Pinger
pinger, err = ping.NewPinger(ip)
if err != nil {
@ -112,6 +112,7 @@ func check_ping(ip string, cb func(pkt *ping.Packet)) (err error) {
pinger.Timeout = time.Second * 5
pinger.Count = 1
pinger.OnRecv = cb
pinger.OnFinish = cb_finished
pinger.SetPrivileged(true)
err = pinger.Run()