sys_linux.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 (
  6. "net"
  7. "syscall"
  8. "unsafe"
  9. "golang.org/x/net/internal/iana"
  10. )
  11. type sysSockoptLen int32
  12. var (
  13. ctlOpts = [ctlMax]ctlOpt{
  14. ctlTrafficClass: {sysIPV6_TCLASS, 4, marshalTrafficClass, parseTrafficClass},
  15. ctlHopLimit: {sysIPV6_HOPLIMIT, 4, marshalHopLimit, parseHopLimit},
  16. ctlPacketInfo: {sysIPV6_PKTINFO, sysSizeofInet6Pktinfo, marshalPacketInfo, parsePacketInfo},
  17. ctlPathMTU: {sysIPV6_PATHMTU, sysSizeofIPv6Mtuinfo, marshalPathMTU, parsePathMTU},
  18. }
  19. sockOpts = [ssoMax]sockOpt{
  20. ssoTrafficClass: {iana.ProtocolIPv6, sysIPV6_TCLASS, ssoTypeInt},
  21. ssoHopLimit: {iana.ProtocolIPv6, sysIPV6_UNICAST_HOPS, ssoTypeInt},
  22. ssoMulticastInterface: {iana.ProtocolIPv6, sysIPV6_MULTICAST_IF, ssoTypeInterface},
  23. ssoMulticastHopLimit: {iana.ProtocolIPv6, sysIPV6_MULTICAST_HOPS, ssoTypeInt},
  24. ssoMulticastLoopback: {iana.ProtocolIPv6, sysIPV6_MULTICAST_LOOP, ssoTypeInt},
  25. ssoReceiveTrafficClass: {iana.ProtocolIPv6, sysIPV6_RECVTCLASS, ssoTypeInt},
  26. ssoReceiveHopLimit: {iana.ProtocolIPv6, sysIPV6_RECVHOPLIMIT, ssoTypeInt},
  27. ssoReceivePacketInfo: {iana.ProtocolIPv6, sysIPV6_RECVPKTINFO, ssoTypeInt},
  28. ssoReceivePathMTU: {iana.ProtocolIPv6, sysIPV6_RECVPATHMTU, ssoTypeInt},
  29. ssoPathMTU: {iana.ProtocolIPv6, sysIPV6_PATHMTU, ssoTypeMTUInfo},
  30. ssoChecksum: {iana.ProtocolReserved, sysIPV6_CHECKSUM, ssoTypeInt},
  31. ssoICMPFilter: {iana.ProtocolIPv6ICMP, sysICMPV6_FILTER, ssoTypeICMPFilter},
  32. ssoJoinGroup: {iana.ProtocolIPv6, sysMCAST_JOIN_GROUP, ssoTypeGroupReq},
  33. ssoLeaveGroup: {iana.ProtocolIPv6, sysMCAST_LEAVE_GROUP, ssoTypeGroupReq},
  34. ssoJoinSourceGroup: {iana.ProtocolIPv6, sysMCAST_JOIN_SOURCE_GROUP, ssoTypeGroupSourceReq},
  35. ssoLeaveSourceGroup: {iana.ProtocolIPv6, sysMCAST_LEAVE_SOURCE_GROUP, ssoTypeGroupSourceReq},
  36. ssoBlockSourceGroup: {iana.ProtocolIPv6, sysMCAST_BLOCK_SOURCE, ssoTypeGroupSourceReq},
  37. ssoUnblockSourceGroup: {iana.ProtocolIPv6, sysMCAST_UNBLOCK_SOURCE, ssoTypeGroupSourceReq},
  38. }
  39. )
  40. func (sa *sysSockaddrInet6) setSockaddr(ip net.IP, i int) {
  41. sa.Family = syscall.AF_INET6
  42. copy(sa.Addr[:], ip)
  43. sa.Scope_id = uint32(i)
  44. }
  45. func (pi *sysInet6Pktinfo) setIfindex(i int) {
  46. pi.Ifindex = int32(i)
  47. }
  48. func (mreq *sysIPv6Mreq) setIfindex(i int) {
  49. mreq.Ifindex = int32(i)
  50. }
  51. func (gr *sysGroupReq) setGroup(grp net.IP) {
  52. sa := (*sysSockaddrInet6)(unsafe.Pointer(&gr.Group))
  53. sa.Family = syscall.AF_INET6
  54. copy(sa.Addr[:], grp)
  55. }
  56. func (gsr *sysGroupSourceReq) setSourceGroup(grp, src net.IP) {
  57. sa := (*sysSockaddrInet6)(unsafe.Pointer(&gsr.Group))
  58. sa.Family = syscall.AF_INET6
  59. copy(sa.Addr[:], grp)
  60. sa = (*sysSockaddrInet6)(unsafe.Pointer(&gsr.Source))
  61. sa.Family = syscall.AF_INET6
  62. copy(sa.Addr[:], src)
  63. }