Called to explicitly fixup the packet according to the IGMP RFC The rules are: - General: 1. the Max Response time is meaningful only in Membership Queries and should be zero - IP: 1. Send General Group Query to 224.0.0.1 (all systems) 2. Send Leave
(self)
| 77 | return IGMP |
| 78 | |
| 79 | def igmpize(self): |
| 80 | """Called to explicitly fixup the packet according to the IGMP RFC |
| 81 | |
| 82 | The rules are: |
| 83 | - General: |
| 84 | 1. the Max Response time is meaningful only in Membership Queries and should be zero |
| 85 | - IP: |
| 86 | 1. Send General Group Query to 224.0.0.1 (all systems) |
| 87 | 2. Send Leave Group to 224.0.0.2 (all routers) |
| 88 | 3a.Otherwise send the packet to the group address |
| 89 | 3b.Send reports/joins to the group address |
| 90 | 4. ttl = 1 (RFC 2236, section 2) |
| 91 | 5. send the packet with the router alert IP option (RFC 2236, section 2) |
| 92 | - Ether: |
| 93 | 1. Recalculate destination |
| 94 | |
| 95 | Returns: |
| 96 | True The tuple ether/ip/self passed all check and represents |
| 97 | a proper IGMP packet. |
| 98 | False One of more validation checks failed and no fields |
| 99 | were adjusted. |
| 100 | |
| 101 | The function will examine the IGMP message to assure proper format. |
| 102 | Corrections will be attempted if possible. The IP header is then properly |
| 103 | adjusted to ensure correct formatting and assignment. The Ethernet header |
| 104 | is then adjusted to the proper IGMP packet format. |
| 105 | """ |
| 106 | from scapy.contrib.igmpv3 import IGMPv3 |
| 107 | gaddr = self.gaddr if hasattr(self, "gaddr") and self.gaddr else "0.0.0.0" # noqa: E501 |
| 108 | underlayer = self.underlayer |
| 109 | if self.type not in [0x11, 0x30]: # General Rule 1 # noqa: E501 |
| 110 | self.mrcode = 0 |
| 111 | if isinstance(underlayer, IP): |
| 112 | if (self.type == 0x11): |
| 113 | if (gaddr == "0.0.0.0"): |
| 114 | underlayer.dst = "224.0.0.1" # IP rule 1 # noqa: E501 |
| 115 | elif isValidMCAddr(gaddr): |
| 116 | underlayer.dst = gaddr # IP rule 3a # noqa: E501 |
| 117 | else: |
| 118 | warning("Invalid IGMP Group Address detected !") |
| 119 | return False |
| 120 | elif ((self.type == 0x17) and isValidMCAddr(gaddr)): |
| 121 | underlayer.dst = "224.0.0.2" # IP rule 2 # noqa: E501 |
| 122 | elif ((self.type == 0x12) or (self.type == 0x16)) and (isValidMCAddr(gaddr)): # noqa: E501 |
| 123 | underlayer.dst = gaddr # IP rule 3b # noqa: E501 |
| 124 | elif (self.type in [0x11, 0x22, 0x30, 0x31, 0x32] and isinstance(self, IGMPv3)): |
| 125 | pass |
| 126 | else: |
| 127 | warning("Invalid IGMP Type detected !") |
| 128 | return False |
| 129 | if not any(isinstance(x, IPOption_Router_Alert) for x in underlayer.options): # noqa: E501 |
| 130 | underlayer.options.append(IPOption_Router_Alert()) |
| 131 | underlayer.ttl = 1 # IP rule 4 |
| 132 | _root = self.firstlayer() |
| 133 | if _root.haslayer(Ether): |
| 134 | # Force recalculate Ether dst |
| 135 | _root[Ether].dst = getmacbyip(underlayer.dst) # Ether rule 1 # noqa: E501 |
| 136 | if isinstance(self, IGMPv3): |
nothing calls this directly
no test coverage detected