icmp_linux.go 648 B

12345678910111213141516171819202122232425262728293031
  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. type sysICMPFilter struct {
  6. Data [8]uint32
  7. }
  8. func (f *sysICMPFilter) set(typ ICMPType, block bool) {
  9. if block {
  10. f.Data[typ>>5] |= 1 << (uint32(typ) & 31)
  11. } else {
  12. f.Data[typ>>5] &^= 1 << (uint32(typ) & 31)
  13. }
  14. }
  15. func (f *sysICMPFilter) setAll(block bool) {
  16. for i := range f.Data {
  17. if block {
  18. f.Data[i] = 1<<32 - 1
  19. } else {
  20. f.Data[i] = 0
  21. }
  22. }
  23. }
  24. func (f *sysICMPFilter) willBlock(typ ICMPType) bool {
  25. return f.Data[typ>>5]&(1<<(uint32(typ)&31)) != 0
  26. }