Compile the BPF stored in the .bpf attribute
(self)
| 227 | |
| 228 | # TODO: Perhaps make bpf a property which auto-triggers this when the property value is set. |
| 229 | def recompile_bpf(self): |
| 230 | """ |
| 231 | Compile the BPF stored in the .bpf attribute |
| 232 | """ |
| 233 | # This function is normally only called by the decode.py script, |
| 234 | # but can also be called by plugins that need to dynamically update |
| 235 | # their filter. |
| 236 | if not self.bpf: |
| 237 | logger.debug("Cannot compile BPF: .bpf attribute not set for plugin {!r}.".format(self.name)) |
| 238 | self.compiled_bpf = None |
| 239 | return |
| 240 | |
| 241 | # Add VLAN wrapper, if necessary |
| 242 | if self.vlan_bpf: |
| 243 | bpf = "({0}) or (vlan and {0})".format(self.bpf) |
| 244 | else: |
| 245 | bpf = self.bpf |
| 246 | logger.debug("Compiling BPF as {!r}".format(bpf)) |
| 247 | |
| 248 | # Compile BPF and handle any expected errors |
| 249 | try: |
| 250 | self.compiled_bpf = pcapy.compile( |
| 251 | self.link_layer_type, 65536, bpf, True, 0xffffffff |
| 252 | ) |
| 253 | except pcapy.PcapError as e: |
| 254 | if str(e).startswith("no VLAN support for data link type"): |
| 255 | logger.error("Cannot use VLAN filters for {!r} plugin. Recommend running with --no-vlan argument.".format(self.name)) |
| 256 | elif str(e) == "syntax error": |
| 257 | raise ValueError("Fatal error when compiling BPF: {!r}".format(bpf)) |
| 258 | else: |
| 259 | raise e |
| 260 | |
| 261 | def ipdefrag(self, packet: 'Packet') -> 'Packet': |
| 262 | """ |
no test coverage detected