예제 #1
0
파일: ph.py 프로젝트: Saber-Bjeoui/PyTCP
    def send_icmp6_nd_dad_message(self, ip6_unicast_candidate):
        """ Send out ICMPv6 ND Duplicate Address Detection message """

        self.phtx_icmp6(
            ip6_src=IPv6Address("::"),
            ip6_dst=ip6_solicited_node_multicast(ip6_unicast_candidate),
            ip6_hop=255,
            icmp6_type=ps_icmp6.ICMP6_NEIGHBOR_SOLICITATION,
            icmp6_ns_target_address=ip6_unicast_candidate,
        )
        self.logger.debug(
            f"Sent out ICMPv6 ND DAD message for {ip6_unicast_candidate}")
예제 #2
0
파일: ph.py 프로젝트: Saber-Bjeoui/PyTCP
    def perform_ip6_nd_dad(self, ip6_unicast_candidate):
        """ Perform IPv6 ND Duplicate Address Detection, return True if passed """

        self.logger.debug(
            f"ICMPv6 ND DAD - Starting process for {ip6_unicast_candidate}")
        self.assign_ip6_multicast(
            ip6_solicited_node_multicast(ip6_unicast_candidate))
        self.ip6_unicast_candidate = ip6_unicast_candidate
        self.send_icmp6_nd_dad_message(ip6_unicast_candidate)
        if event := self.event_icmp6_nd_dad.acquire(timeout=1):
            self.logger.warning(
                f"ICMPv6 ND DAD - Duplicate IPv6 address detected, {ip6_unicast_candidate} advertised by {self.icmp6_nd_dad_tlla}"
            )
예제 #3
0
    def __send_icmp6_neighbor_solicitation(icmp6_ns_target_address):
        """ Enqueue ICMPv6 Neighbor Solicitation packet with TX ring """

        # Pick apropriate source address
        ip6_src = IPv6Address("::")
        for stack_ip6_address in stack.packet_handler.stack_ip6_address:
            if icmp6_ns_target_address in stack_ip6_address.network:
                ip6_src = stack_ip6_address.ip

        # Send out ND Solicitation message
        stack.packet_handler.phtx_icmp6(
            ip6_src=ip6_src,
            ip6_dst=ip6_solicited_node_multicast(icmp6_ns_target_address),
            ip6_hop=255,
            icmp6_type=ps_icmp6.ICMP6_NEIGHBOR_SOLICITATION,
            icmp6_ns_target_address=icmp6_ns_target_address,
            icmp6_nd_options=[
                ps_icmp6.Icmp6NdOptSLLA(
                    opt_slla=stack.packet_handler.stack_mac_unicast[0])
            ],
        )
예제 #4
0
파일: ph.py 프로젝트: Saber-Bjeoui/PyTCP
    def remove_ip6_unicast(self, ip6_unicast):
        """ Remove IPv6 unicast address from the list stack listens on """

        self.stack_ip6_unicast.remove(ip6_unicast)
        self.logger.debug(f"Removed IPv6 unicast {ip6_unicast}")
        self.remove_ip6_multicast(ip6_solicited_node_multicast(ip6_unicast))
예제 #5
0
파일: ph.py 프로젝트: Saber-Bjeoui/PyTCP
    def assign_ip6_unicast(self, ip6_unicast):
        """ Assign IPv6 unicast address to the list stack listens on """

        self.stack_ip6_unicast.append(ip6_unicast)
        self.logger.debug(f"Assigned IPv6 unicast {ip6_unicast}")
        self.assign_ip6_multicast(ip6_solicited_node_multicast(ip6_unicast))
예제 #6
0
파일: ph.py 프로젝트: Saber-Bjeoui/PyTCP
            f"ICMPv6 ND DAD - Starting process for {ip6_unicast_candidate}")
        self.assign_ip6_multicast(
            ip6_solicited_node_multicast(ip6_unicast_candidate))
        self.ip6_unicast_candidate = ip6_unicast_candidate
        self.send_icmp6_nd_dad_message(ip6_unicast_candidate)
        if event := self.event_icmp6_nd_dad.acquire(timeout=1):
            self.logger.warning(
                f"ICMPv6 ND DAD - Duplicate IPv6 address detected, {ip6_unicast_candidate} advertised by {self.icmp6_nd_dad_tlla}"
            )
        else:
            self.logger.debug(
                f"ICMPv6 ND DAD - No duplicate address detected for {ip6_unicast_candidate}"
            )
        self.ip6_unicast_candidate = None
        self.remove_ip6_multicast(
            ip6_solicited_node_multicast(ip6_unicast_candidate))
        return not event

    def parse_stack_ip6_address_candidate(self):
        """ Parse IPv6 candidate addresses configured in stack.py module """

        address_candidate = []

        for address, gateway in stack.ip6_address_candidate:
            self.logger.debug(f"Parsing ('{address}', '{gateway}') entry")
            try:
                address = IPv6Interface(address)
            except AddressValueError:
                self.logger.warning(
                    f"Invalid host address '{address}' format, skiping...")
                return None