SerializeTo writes the serialized form of this layer into the SerializationBuffer, implementing gopacket.SerializableLayer. See the docs for gopacket.SerializableLayer for more info.
(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions)
| 89 | // SerializeTo writes the serialized form of this layer into the SerializationBuffer, |
| 90 | // implementing gopacket.SerializableLayer. See the docs for gopacket.SerializableLayer for more info. |
| 91 | func (g *GRE) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
| 92 | size := 4 |
| 93 | if g.ChecksumPresent || g.RoutingPresent { |
| 94 | size += 4 |
| 95 | } |
| 96 | if g.KeyPresent { |
| 97 | size += 4 |
| 98 | } |
| 99 | if g.SeqPresent { |
| 100 | size += 4 |
| 101 | } |
| 102 | if g.RoutingPresent { |
| 103 | r := g.GRERouting |
| 104 | for r != nil { |
| 105 | size += 4 + int(r.SRELength) |
| 106 | r = r.Next |
| 107 | } |
| 108 | size += 4 |
| 109 | } |
| 110 | if g.AckPresent { |
| 111 | size += 4 |
| 112 | } |
| 113 | buf, err := b.PrependBytes(size) |
| 114 | if err != nil { |
| 115 | return err |
| 116 | } |
| 117 | // Reset any potentially dirty memory in the first 2 bytes, as these use OR to set flags. |
| 118 | buf[0] = 0 |
| 119 | buf[1] = 0 |
| 120 | if g.ChecksumPresent { |
| 121 | buf[0] |= 0x80 |
| 122 | } |
| 123 | if g.RoutingPresent { |
| 124 | buf[0] |= 0x40 |
| 125 | } |
| 126 | if g.KeyPresent { |
| 127 | buf[0] |= 0x20 |
| 128 | } |
| 129 | if g.SeqPresent { |
| 130 | buf[0] |= 0x10 |
| 131 | } |
| 132 | if g.StrictSourceRoute { |
| 133 | buf[0] |= 0x08 |
| 134 | } |
| 135 | if g.AckPresent { |
| 136 | buf[1] |= 0x80 |
| 137 | } |
| 138 | buf[0] |= g.RecursionControl |
| 139 | buf[1] |= g.Flags << 3 |
| 140 | buf[1] |= g.Version |
| 141 | binary.BigEndian.PutUint16(buf[2:4], uint16(g.Protocol)) |
| 142 | offset := 4 |
| 143 | if g.ChecksumPresent || g.RoutingPresent { |
| 144 | // Don't write the checksum value yet, as we may need to compute it, |
| 145 | // which requires the entire header be complete. |
| 146 | // Instead we zeroize the memory in case it is dirty. |
| 147 | buf[offset] = 0 |
| 148 | buf[offset+1] = 0 |
nothing calls this directly
no test coverage detected