icmp_linux.go 538 B

12345678910111213141516171819202122232425
  1. // Copyright 2014 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 ipv4
  5. func (f *icmpFilter) accept(typ ICMPType) {
  6. f.Data &^= 1 << (uint32(typ) & 31)
  7. }
  8. func (f *icmpFilter) block(typ ICMPType) {
  9. f.Data |= 1 << (uint32(typ) & 31)
  10. }
  11. func (f *icmpFilter) setAll(block bool) {
  12. if block {
  13. f.Data = 1<<32 - 1
  14. } else {
  15. f.Data = 0
  16. }
  17. }
  18. func (f *icmpFilter) willBlock(typ ICMPType) bool {
  19. return f.Data&(1<<(uint32(typ)&31)) != 0
  20. }