github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/net/ipv6/icmp.go (about)

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