|
14 | 14 | from scapy.fields import ByteEnumField, ByteField, XByteField, \ |
15 | 15 | ShortField, XShortField, XLongField, BitField, XBitField, FCSField |
16 | 16 | from scapy.layers.inet import IP, UDP |
| 17 | +from scapy.layers.inet6 import IPv6 |
17 | 18 | from scapy.layers.l2 import Ether |
18 | 19 | from scapy.compat import raw |
19 | 20 | from scapy.error import warning |
@@ -179,8 +180,25 @@ def compute_icrc(self, p): |
179 | 180 | pshdr[UDP].payload = Raw(bth + payload + icrc_placeholder) |
180 | 181 | icrc = crc32(raw(pshdr)[:-4]) & 0xffffffff |
181 | 182 | return self.pack_icrc(icrc) |
| 183 | + elif isinstance(ip, IPv6): |
| 184 | + # pseudo-LRH / IPv6 / UDP / BTH / payload |
| 185 | + pshdr = Raw(b'\xff' * 8) / ip.copy() |
| 186 | + pshdr.hlim = 0xff |
| 187 | + pshdr.fl = 0xfffff |
| 188 | + pshdr.tc = 0xff |
| 189 | + pshdr[UDP].chksum = 0xffff |
| 190 | + pshdr[BTH].fecn = 1 |
| 191 | + pshdr[BTH].becn = 1 |
| 192 | + pshdr[BTH].resv6 = 0xff |
| 193 | + bth = pshdr[BTH].self_build() |
| 194 | + payload = raw(pshdr[BTH].payload) |
| 195 | + # add ICRC placeholder just to get the right IPv6.plen and |
| 196 | + # UDP.length |
| 197 | + icrc_placeholder = b'\xff\xff\xff\xff' |
| 198 | + pshdr[UDP].payload = Raw(bth + payload + icrc_placeholder) |
| 199 | + icrc = crc32(raw(pshdr)[:-4]) & 0xffffffff |
| 200 | + return self.pack_icrc(icrc) |
182 | 201 | else: |
183 | | - # TODO support IPv6 |
184 | 202 | warning("The underlayer protocol %s is not supported.", |
185 | 203 | ip and ip.name) |
186 | 204 | return self.pack_icrc(0) |
|
0 commit comments