icmp.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2013 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package ipv6
  5. import (
  6. "sync"
  7. "golang.org/x/net/internal/iana"
  8. )
  9. // An ICMPType represents a type of ICMP message.
  10. type ICMPType int
  11. func (typ ICMPType) String() string {
  12. s, ok := icmpTypes[typ]
  13. if !ok {
  14. return "<nil>"
  15. }
  16. return s
  17. }
  18. // Protocol returns the ICMPv6 protocol number.
  19. func (typ ICMPType) Protocol() int {
  20. return iana.ProtocolIPv6ICMP
  21. }
  22. // An ICMPFilter represents an ICMP message filter for incoming
  23. // packets.
  24. type ICMPFilter struct {
  25. mu sync.RWMutex
  26. sysICMPv6Filter
  27. }
  28. // Set sets the ICMP type and filter action to the filter.
  29. func (f *ICMPFilter) Set(typ ICMPType, block bool) {
  30. f.mu.Lock()
  31. f.set(typ, block)
  32. f.mu.Unlock()
  33. }
  34. // SetAll sets the filter action to the filter.
  35. func (f *ICMPFilter) SetAll(block bool) {
  36. f.mu.Lock()
  37. f.setAll(block)
  38. f.mu.Unlock()
  39. }
  40. // WillBlock reports whether the ICMP type will be blocked.
  41. func (f *ICMPFilter) WillBlock(typ ICMPType) bool {
  42. f.mu.RLock()
  43. ok := f.willBlock(typ)
  44. f.mu.RUnlock()
  45. return ok
  46. }