icmp.go 980 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 "sync"
  6. // An ICMPType represents a type of ICMP message.
  7. type ICMPType int
  8. func (typ ICMPType) String() string {
  9. s, ok := icmpTypes[typ]
  10. if !ok {
  11. return "<nil>"
  12. }
  13. return s
  14. }
  15. // An ICMPFilter represents an ICMP message filter for incoming
  16. // packets.
  17. type ICMPFilter struct {
  18. mu sync.RWMutex
  19. sysICMPFilter
  20. }
  21. // Set sets the ICMP type and filter action to the filter.
  22. func (f *ICMPFilter) Set(typ ICMPType, block bool) {
  23. f.mu.Lock()
  24. f.set(typ, block)
  25. f.mu.Unlock()
  26. }
  27. // SetAll sets the filter action to the filter.
  28. func (f *ICMPFilter) SetAll(block bool) {
  29. f.mu.Lock()
  30. f.setAll(block)
  31. f.mu.Unlock()
  32. }
  33. // WillBlock reports whether the ICMP type will be blocked.
  34. func (f *ICMPFilter) WillBlock(typ ICMPType) bool {
  35. f.mu.RLock()
  36. ok := f.willBlock(typ)
  37. f.mu.RUnlock()
  38. return ok
  39. }