David K. Bainbridge | 215e024 | 2017-09-05 23:18:24 -0700 | [diff] [blame] | 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 ipv4 |
| 6 | |
| 7 | import "golang.org/x/net/internal/iana" |
| 8 | |
| 9 | // An ICMPType represents a type of ICMP message. |
| 10 | type ICMPType int |
| 11 | |
| 12 | func (typ ICMPType) String() string { |
| 13 | s, ok := icmpTypes[typ] |
| 14 | if !ok { |
| 15 | return "<nil>" |
| 16 | } |
| 17 | return s |
| 18 | } |
| 19 | |
| 20 | // Protocol returns the ICMPv4 protocol number. |
| 21 | func (typ ICMPType) Protocol() int { |
| 22 | return iana.ProtocolICMP |
| 23 | } |
| 24 | |
| 25 | // An ICMPFilter represents an ICMP message filter for incoming |
| 26 | // packets. The filter belongs to a packet delivery path on a host and |
| 27 | // it cannot interact with forwarding packets or tunnel-outer packets. |
| 28 | // |
| 29 | // Note: RFC 8200 defines a reasonable role model and it works not |
| 30 | // only for IPv6 but IPv4. A node means a device that implements IP. |
| 31 | // A router means a node that forwards IP packets not explicitly |
| 32 | // addressed to itself, and a host means a node that is not a router. |
| 33 | type ICMPFilter struct { |
| 34 | icmpFilter |
| 35 | } |
| 36 | |
| 37 | // Accept accepts incoming ICMP packets including the type field value |
| 38 | // typ. |
| 39 | func (f *ICMPFilter) Accept(typ ICMPType) { |
| 40 | f.accept(typ) |
| 41 | } |
| 42 | |
| 43 | // Block blocks incoming ICMP packets including the type field value |
| 44 | // typ. |
| 45 | func (f *ICMPFilter) Block(typ ICMPType) { |
| 46 | f.block(typ) |
| 47 | } |
| 48 | |
| 49 | // SetAll sets the filter action to the filter. |
| 50 | func (f *ICMPFilter) SetAll(block bool) { |
| 51 | f.setAll(block) |
| 52 | } |
| 53 | |
| 54 | // WillBlock reports whether the ICMP type will be blocked. |
| 55 | func (f *ICMPFilter) WillBlock(typ ICMPType) bool { |
| 56 | return f.willBlock(typ) |
| 57 | } |