sys_linux.go 2.9 KB

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