diff --git a/checker/checker.go b/checker/checker.go index 056426c..f2465f7 100644 --- a/checker/checker.go +++ b/checker/checker.go @@ -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.")) - } - } - } } } } diff --git a/checker/checks.go b/checker/checks.go index 4b1d072..681cceb 100644 --- a/checker/checks.go +++ b/checker/checks.go @@ -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()