def send_answer(received_message, referral):
    map_request = received_message.inner_message

    # Put it in a reply packet
    reply = MapReferralMessage(nonce=map_request.nonce,
                               records=[referral])

    # Send the reply over UDP
    send_message(message=reply,
                 my_sockets=[received_message.socket],
                 destinations=[received_message.source[0]],
                 port=received_message.source[1])
示例#2
0
    def send(self):
        if not self.nat_info:
            # Plain Map_Register
            logger.debug(u"Sending Map-Register for {0} to Map-Server {1}".format(self.prefix, self.etrr.map_server))
            self.sent_from, self.sent_to = send_message(message=self.map_register,
                                                        my_sockets=self.control_plane_sockets,
                                                        destinations=[self.etrr.map_server],
                                                        port=4342)
        else:
            logger.debug(u"Sending NATT Map-Register for {0} to Map-Server {1}".format(self.prefix, self.etrr.map_server))

            # Create an IP packet
            if self.etrr.map_server.version != self.nat_info.private_etr_rloc.version:
                logger.error("Address family mismatch between local RLOC and Map-Server")
                return

            if self.etrr.map_server.version == 4:
                ip_packet = IPv4Packet()
            else:
                ip_packet = IPv6Packet()

            # Fill the packet
            ip_packet.ttl = 63
            ip_packet.source = self.nat_info.private_etr_rloc
            ip_packet.destination = self.etrr.map_server

            # UDP payload
            inner_udp = UDPMessage(source_port=4342,
                                   destination_port=4342,
                                   payload=self.map_register)
            inner_udp.checksum = inner_udp.calculate_checksum(source=ip_packet.source,
                                                              destination=ip_packet.destination)

            # Put UDP in the packet
            ip_packet.next_header = inner_udp.header_type
            ip_packet.payload = inner_udp

            # Encapsulate it in an ECM
            ecm = EncapsulatedControlMessage(payload=ip_packet)

            send_message(message=ecm,
                         my_sockets=self.data_plane_sockets,
                         destinations=self.nat_info.rtr_rlocs,
                         port=4342)
示例#3
0
    def handle_map_request(self, received_message, eid_prefix, control_plane_sockets, data_plane_sockets):
        map_request = received_message.message
        assert isinstance(map_request, MapRequestMessage)

        # Return our locators
        locators = self.get_etr_locators(control_plane_sockets)

        # Do we have locators?
        if locators:
            # Get the address the Map-Request was sent to
            etr_address = ip_address(unicode(received_message.destination[0]))

            # Pretend that all locators are reachable
            # TODO: implement something better
            for locator in locators:
                locator.reachable = True
                locator.probed_locator = map_request.probe and etr_address == locator.address

            reply_record = MapReplyRecord(ttl=1440,
                                          authoritative=True,
                                          eid_prefix=self.prefix,
                                          locator_records=locators)
        else:
            reply_record = MapReplyRecord(ttl=1440,
                                          action=MapReplyRecord.ACT_NATIVELY_FORWARD,
                                          authoritative=True,
                                          eid_prefix=self.prefix)

        if map_request.probe:
            logger.info(u"Replying to probe for {0} from {1}".format(eid_prefix, received_message.source[0]))

        # Send the reply to the RLOCs in the MapRequest
        reply = MapReplyMessage(probe=map_request.probe,
                                nonce=map_request.nonce,
                                records=[reply_record])

        send_message(message=reply,
                     my_sockets=control_plane_sockets,
                     destinations=map_request.itr_rlocs,
                     port=received_message.source[1])
示例#4
0
            )

    if map_register.want_map_notify and processed_records:
        # Notify the sender using the saved key from the MapServerNode
        notify = MapNotifyMessage(
            nonce=map_register.nonce,
            key_id=map_register.key_id,
            records=processed_records,
            xtr_id=map_register.xtr_id,
            site_id=map_register.site_id,
        )
        notify.insert_authentication_data(saved_key)

        # Send the reply over UDP
        send_message(
            message=notify, my_sockets=[received_message.socket], destinations=[received_message.source[0]], port=4342
        )


def handle_map_referral(received_message, control_plane_sockets, data_plane_sockets):
    pass


def handle_map_notify(received_message, control_plane_sockets, data_plane_sockets):
    map_notify = received_message.message
    assert isinstance(map_notify, MapNotifyMessage)

    for record in map_notify.records:
        assert isinstance(record, MapRegisterRecord)

        # Look up the address in the tree
示例#5
0
 def send(self):
     self.sent_from, self.sent_to = send_message(message=self.info_request,
                                                 my_sockets=self.control_plane_sockets,
                                                 destinations=[self.etrr.map_server],
                                                 port=4342)