icmp_bsd.go 689 B

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