control.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2012 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. import (
  6. "fmt"
  7. "net"
  8. "sync"
  9. )
  10. type rawOpt struct {
  11. mu sync.Mutex
  12. cflags ControlFlags
  13. }
  14. func (o *rawOpt) lock() { o.mu.Lock() }
  15. func (o *rawOpt) unlock() { o.mu.Unlock() }
  16. func (o *rawOpt) set(f ControlFlags) { o.cflags |= f }
  17. func (o *rawOpt) clear(f ControlFlags) { o.cflags ^= f }
  18. func (o *rawOpt) isset(f ControlFlags) bool { return o.cflags&f != 0 }
  19. type ControlFlags uint
  20. const (
  21. FlagTTL ControlFlags = 1 << iota // pass the TTL on the received packet
  22. FlagSrc // pass the source address on the received packet
  23. FlagDst // pass the destination address on the received packet
  24. FlagInterface // pass the interface index on the received packet or outgoing packet
  25. )
  26. // A ControlMessage represents control information that contains per
  27. // packet IP-level option data.
  28. type ControlMessage struct {
  29. TTL int // time-to-live
  30. Src net.IP // source address
  31. Dst net.IP // destination address
  32. IfIndex int // interface index
  33. }
  34. func (cm *ControlMessage) String() string {
  35. if cm == nil {
  36. return "<nil>"
  37. }
  38. return fmt.Sprintf("ttl: %v, src: %v, dst: %v, ifindex: %v", cm.TTL, cm.Src, cm.Dst, cm.IfIndex)
  39. }