icmp.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 "golang.org/x/net/internal/iana"
  6. // BUG(mikio): On Windows, methods related to ICMPFilter are not
  7. // implemented.
  8. // An ICMPType represents a type of ICMP message.
  9. type ICMPType int
  10. func (typ ICMPType) String() string {
  11. s, ok := icmpTypes[typ]
  12. if !ok {
  13. return "<nil>"
  14. }
  15. return s
  16. }
  17. // Protocol returns the ICMPv6 protocol number.
  18. func (typ ICMPType) Protocol() int {
  19. return iana.ProtocolIPv6ICMP
  20. }
  21. // An ICMPFilter represents an ICMP message filter for incoming
  22. // packets. The filter belongs to a packet delivery path on a host and
  23. // it cannot interact with forwarding packets or tunnel-outer packets.
  24. //
  25. // Note: RFC 8200 defines a reasonable role model. A node means a
  26. // device that implements IP. A router means a node that forwards IP
  27. // packets not explicitly addressed to itself, and a host means a node
  28. // that is not a router.
  29. type ICMPFilter struct {
  30. icmpv6Filter
  31. }
  32. // Accept accepts incoming ICMP packets including the type field value
  33. // typ.
  34. func (f *ICMPFilter) Accept(typ ICMPType) {
  35. f.accept(typ)
  36. }
  37. // Block blocks incoming ICMP packets including the type field value
  38. // typ.
  39. func (f *ICMPFilter) Block(typ ICMPType) {
  40. f.block(typ)
  41. }
  42. // SetAll sets the filter action to the filter.
  43. func (f *ICMPFilter) SetAll(block bool) {
  44. f.setAll(block)
  45. }
  46. // WillBlock reports whether the ICMP type will be blocked.
  47. func (f *ICMPFilter) WillBlock(typ ICMPType) bool {
  48. return f.willBlock(typ)
  49. }