gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/net/ipv6/control_unix.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 //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos 6 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris zos 7 8 package ipv6 9 10 import "gitee.com/ks-custle/core-gm/net/internal/socket" 11 12 func setControlMessage(c *socket.Conn, opt *rawOpt, cf ControlFlags, on bool) error { 13 opt.Lock() 14 defer opt.Unlock() 15 if so, ok := sockOpts[ssoReceiveTrafficClass]; ok && cf&FlagTrafficClass != 0 { 16 if err := so.SetInt(c, boolint(on)); err != nil { 17 return err 18 } 19 if on { 20 opt.set(FlagTrafficClass) 21 } else { 22 opt.clear(FlagTrafficClass) 23 } 24 } 25 if so, ok := sockOpts[ssoReceiveHopLimit]; ok && cf&FlagHopLimit != 0 { 26 if err := so.SetInt(c, boolint(on)); err != nil { 27 return err 28 } 29 if on { 30 opt.set(FlagHopLimit) 31 } else { 32 opt.clear(FlagHopLimit) 33 } 34 } 35 if so, ok := sockOpts[ssoReceivePacketInfo]; ok && cf&flagPacketInfo != 0 { 36 if err := so.SetInt(c, boolint(on)); err != nil { 37 return err 38 } 39 if on { 40 opt.set(cf & flagPacketInfo) 41 } else { 42 opt.clear(cf & flagPacketInfo) 43 } 44 } 45 if so, ok := sockOpts[ssoReceivePathMTU]; ok && cf&FlagPathMTU != 0 { 46 if err := so.SetInt(c, boolint(on)); err != nil { 47 return err 48 } 49 if on { 50 opt.set(FlagPathMTU) 51 } else { 52 opt.clear(FlagPathMTU) 53 } 54 } 55 return nil 56 }