github.com/MerlinKodo/sing-tun@v0.1.15/internal/clashtcpip/icmpv6.go (about) 1 package clashtcpip 2 3 import ( 4 "encoding/binary" 5 ) 6 7 type ICMPv6Packet []byte 8 9 const ( 10 ICMPv6HeaderSize = 4 11 12 ICMPv6MinimumSize = 8 13 14 ICMPv6PayloadOffset = 8 15 16 ICMPv6EchoMinimumSize = 8 17 18 ICMPv6ErrorHeaderSize = 8 19 20 ICMPv6DstUnreachableMinimumSize = ICMPv6MinimumSize 21 22 ICMPv6PacketTooBigMinimumSize = ICMPv6MinimumSize 23 24 ICMPv6ChecksumOffset = 2 25 26 icmpv6PointerOffset = 4 27 28 icmpv6MTUOffset = 4 29 30 icmpv6IdentOffset = 4 31 32 icmpv6SequenceOffset = 6 33 34 NDPHopLimit = 255 35 ) 36 37 type ICMPv6Type byte 38 39 const ( 40 ICMPv6DstUnreachable ICMPv6Type = 1 41 ICMPv6PacketTooBig ICMPv6Type = 2 42 ICMPv6TimeExceeded ICMPv6Type = 3 43 ICMPv6ParamProblem ICMPv6Type = 4 44 ICMPv6EchoRequest ICMPv6Type = 128 45 ICMPv6EchoReply ICMPv6Type = 129 46 47 ICMPv6RouterSolicit ICMPv6Type = 133 48 ICMPv6RouterAdvert ICMPv6Type = 134 49 ICMPv6NeighborSolicit ICMPv6Type = 135 50 ICMPv6NeighborAdvert ICMPv6Type = 136 51 ICMPv6RedirectMsg ICMPv6Type = 137 52 53 ICMPv6MulticastListenerQuery ICMPv6Type = 130 54 ICMPv6MulticastListenerReport ICMPv6Type = 131 55 ICMPv6MulticastListenerDone ICMPv6Type = 132 56 ) 57 58 func (typ ICMPv6Type) IsErrorType() bool { 59 return typ&0x80 == 0 60 } 61 62 type ICMPv6Code byte 63 64 const ( 65 ICMPv6NetworkUnreachable ICMPv6Code = 0 66 ICMPv6Prohibited ICMPv6Code = 1 67 ICMPv6BeyondScope ICMPv6Code = 2 68 ICMPv6AddressUnreachable ICMPv6Code = 3 69 ICMPv6PortUnreachable ICMPv6Code = 4 70 ICMPv6Policy ICMPv6Code = 5 71 ICMPv6RejectRoute ICMPv6Code = 6 72 ) 73 74 const ( 75 ICMPv6HopLimitExceeded ICMPv6Code = 0 76 ICMPv6ReassemblyTimeout ICMPv6Code = 1 77 ) 78 79 const ( 80 ICMPv6ErroneousHeader ICMPv6Code = 0 81 82 ICMPv6UnknownHeader ICMPv6Code = 1 83 84 ICMPv6UnknownOption ICMPv6Code = 2 85 ) 86 87 const ICMPv6UnusedCode ICMPv6Code = 0 88 89 func (b ICMPv6Packet) Type() ICMPv6Type { 90 return ICMPv6Type(b[0]) 91 } 92 93 func (b ICMPv6Packet) SetType(t ICMPv6Type) { 94 b[0] = byte(t) 95 } 96 97 func (b ICMPv6Packet) Code() ICMPv6Code { 98 return ICMPv6Code(b[1]) 99 } 100 101 func (b ICMPv6Packet) SetCode(c ICMPv6Code) { 102 b[1] = byte(c) 103 } 104 105 func (b ICMPv6Packet) TypeSpecific() uint32 { 106 return binary.BigEndian.Uint32(b[icmpv6PointerOffset:]) 107 } 108 109 func (b ICMPv6Packet) SetTypeSpecific(val uint32) { 110 binary.BigEndian.PutUint32(b[icmpv6PointerOffset:], val) 111 } 112 113 func (b ICMPv6Packet) Checksum() uint16 { 114 return binary.BigEndian.Uint16(b[ICMPv6ChecksumOffset:]) 115 } 116 117 func (b ICMPv6Packet) SetChecksum(sum [2]byte) { 118 _ = b[ICMPv6ChecksumOffset+1] 119 b[ICMPv6ChecksumOffset] = sum[0] 120 b[ICMPv6ChecksumOffset+1] = sum[1] 121 } 122 123 func (ICMPv6Packet) SourcePort() uint16 { 124 return 0 125 } 126 127 func (ICMPv6Packet) DestinationPort() uint16 { 128 return 0 129 } 130 131 func (ICMPv6Packet) SetSourcePort(uint16) { 132 } 133 134 func (ICMPv6Packet) SetDestinationPort(uint16) { 135 } 136 137 func (b ICMPv6Packet) MTU() uint32 { 138 return binary.BigEndian.Uint32(b[icmpv6MTUOffset:]) 139 } 140 141 func (b ICMPv6Packet) SetMTU(mtu uint32) { 142 binary.BigEndian.PutUint32(b[icmpv6MTUOffset:], mtu) 143 } 144 145 func (b ICMPv6Packet) Ident() uint16 { 146 return binary.BigEndian.Uint16(b[icmpv6IdentOffset:]) 147 } 148 149 func (b ICMPv6Packet) SetIdent(ident uint16) { 150 binary.BigEndian.PutUint16(b[icmpv6IdentOffset:], ident) 151 } 152 153 func (b ICMPv6Packet) Sequence() uint16 { 154 return binary.BigEndian.Uint16(b[icmpv6SequenceOffset:]) 155 } 156 157 func (b ICMPv6Packet) SetSequence(sequence uint16) { 158 binary.BigEndian.PutUint16(b[icmpv6SequenceOffset:], sequence) 159 } 160 161 func (b ICMPv6Packet) MessageBody() []byte { 162 return b[ICMPv6HeaderSize:] 163 } 164 165 func (b ICMPv6Packet) Payload() []byte { 166 return b[ICMPv6PayloadOffset:] 167 } 168 169 func (b ICMPv6Packet) ResetChecksum(psum uint32) { 170 b.SetChecksum(zeroChecksum) 171 b.SetChecksum(Checksum(psum, b)) 172 }