sys_freebsd.go 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. "runtime"
  8. "strings"
  9. "syscall"
  10. "unsafe"
  11. "golang.org/x/net/internal/iana"
  12. )
  13. var (
  14. ctlOpts = [ctlMax]ctlOpt{
  15. ctlTrafficClass: {sysIPV6_TCLASS, 4, marshalTrafficClass, parseTrafficClass},
  16. ctlHopLimit: {sysIPV6_HOPLIMIT, 4, marshalHopLimit, parseHopLimit},
  17. ctlPacketInfo: {sysIPV6_PKTINFO, sizeofInet6Pktinfo, marshalPacketInfo, parsePacketInfo},
  18. ctlNextHop: {sysIPV6_NEXTHOP, sizeofSockaddrInet6, marshalNextHop, parseNextHop},
  19. ctlPathMTU: {sysIPV6_PATHMTU, sizeofIPv6Mtuinfo, marshalPathMTU, parsePathMTU},
  20. }
  21. sockOpts = [ssoMax]sockOpt{
  22. ssoTrafficClass: {iana.ProtocolIPv6, sysIPV6_TCLASS, ssoTypeInt},
  23. ssoHopLimit: {iana.ProtocolIPv6, sysIPV6_UNICAST_HOPS, ssoTypeInt},
  24. ssoMulticastInterface: {iana.ProtocolIPv6, sysIPV6_MULTICAST_IF, ssoTypeInterface},
  25. ssoMulticastHopLimit: {iana.ProtocolIPv6, sysIPV6_MULTICAST_HOPS, ssoTypeInt},
  26. ssoMulticastLoopback: {iana.ProtocolIPv6, sysIPV6_MULTICAST_LOOP, ssoTypeInt},
  27. ssoReceiveTrafficClass: {iana.ProtocolIPv6, sysIPV6_RECVTCLASS, ssoTypeInt},
  28. ssoReceiveHopLimit: {iana.ProtocolIPv6, sysIPV6_RECVHOPLIMIT, ssoTypeInt},
  29. ssoReceivePacketInfo: {iana.ProtocolIPv6, sysIPV6_RECVPKTINFO, ssoTypeInt},
  30. ssoReceivePathMTU: {iana.ProtocolIPv6, sysIPV6_RECVPATHMTU, ssoTypeInt},
  31. ssoPathMTU: {iana.ProtocolIPv6, sysIPV6_PATHMTU, ssoTypeMTUInfo},
  32. ssoChecksum: {iana.ProtocolIPv6, sysIPV6_CHECKSUM, ssoTypeInt},
  33. ssoICMPFilter: {iana.ProtocolIPv6ICMP, sysICMP6_FILTER, ssoTypeICMPFilter},
  34. ssoJoinGroup: {iana.ProtocolIPv6, sysMCAST_JOIN_GROUP, ssoTypeGroupReq},
  35. ssoLeaveGroup: {iana.ProtocolIPv6, sysMCAST_LEAVE_GROUP, ssoTypeGroupReq},
  36. ssoJoinSourceGroup: {iana.ProtocolIPv6, sysMCAST_JOIN_SOURCE_GROUP, ssoTypeGroupSourceReq},
  37. ssoLeaveSourceGroup: {iana.ProtocolIPv6, sysMCAST_LEAVE_SOURCE_GROUP, ssoTypeGroupSourceReq},
  38. ssoBlockSourceGroup: {iana.ProtocolIPv6, sysMCAST_BLOCK_SOURCE, ssoTypeGroupSourceReq},
  39. ssoUnblockSourceGroup: {iana.ProtocolIPv6, sysMCAST_UNBLOCK_SOURCE, ssoTypeGroupSourceReq},
  40. }
  41. )
  42. func init() {
  43. if runtime.GOOS == "freebsd" && runtime.GOARCH == "386" {
  44. archs, _ := syscall.Sysctl("kern.supported_archs")
  45. for _, s := range strings.Fields(archs) {
  46. if s == "amd64" {
  47. freebsd32o64 = true
  48. break
  49. }
  50. }
  51. }
  52. }
  53. func (sa *sockaddrInet6) setSockaddr(ip net.IP, i int) {
  54. sa.Len = sizeofSockaddrInet6
  55. sa.Family = syscall.AF_INET6
  56. copy(sa.Addr[:], ip)
  57. sa.Scope_id = uint32(i)
  58. }
  59. func (pi *inet6Pktinfo) setIfindex(i int) {
  60. pi.Ifindex = uint32(i)
  61. }
  62. func (mreq *ipv6Mreq) setIfindex(i int) {
  63. mreq.Interface = uint32(i)
  64. }
  65. func (gr *groupReq) setGroup(grp net.IP) {
  66. sa := (*sockaddrInet6)(unsafe.Pointer(&gr.Group))
  67. sa.Len = sizeofSockaddrInet6
  68. sa.Family = syscall.AF_INET6
  69. copy(sa.Addr[:], grp)
  70. }
  71. func (gsr *groupSourceReq) setSourceGroup(grp, src net.IP) {
  72. sa := (*sockaddrInet6)(unsafe.Pointer(&gsr.Group))
  73. sa.Len = sizeofSockaddrInet6
  74. sa.Family = syscall.AF_INET6
  75. copy(sa.Addr[:], grp)
  76. sa = (*sockaddrInet6)(unsafe.Pointer(&gsr.Source))
  77. sa.Len = sizeofSockaddrInet6
  78. sa.Family = syscall.AF_INET6
  79. copy(sa.Addr[:], src)
  80. }