icmp_bsd.go 713 B

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