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