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