Example #1
0
    def __init__(self, connection: Connection,
                 shared_memory_manager_dict: Dict) -> NoReturn:
        self.connection = connection
        self.shared_memory_manager_dict = shared_memory_manager_dict

        # EXCHANGES
        self.hijack_notification_exchange = create_exchange(
            "hijack-notification", connection, declare=True)
        self.command_exchange = create_exchange("command",
                                                connection,
                                                declare=True)

        # QUEUES
        self.hij_log_queue = create_queue(
            SERVICE_NAME,
            exchange=self.hijack_notification_exchange,
            routing_key="hij-log",
            priority=1,
        )
        self.mail_log_queue = create_queue(
            SERVICE_NAME,
            exchange=self.hijack_notification_exchange,
            routing_key="mail-log",
            priority=1,
        )
        self.stop_queue = create_queue(
            "{}-{}".format(SERVICE_NAME, uuid()),
            exchange=self.command_exchange,
            routing_key="stop-{}".format(SERVICE_NAME),
            priority=1,
        )

        log.info("data worker initiated")
Example #2
0
    def __init__(self, connection, shared_memory_manager_dict):
        self.connection = connection
        self.shared_memory_manager_dict = shared_memory_manager_dict

        # wait for other needed data workers to start
        wait_data_worker_dependencies(DATA_WORKER_DEPENDENCIES)

        # EXCHANGES
        self.mitigation_exchange = create_exchange(
            "mitigation", connection, declare=True
        )
        self.command_exchange = create_exchange("command", connection, declare=True)

        # QUEUES
        self.mitigate_queue = create_queue(
            SERVICE_NAME,
            exchange=self.mitigation_exchange,
            routing_key="mitigate-with-action",
            priority=2,
        )
        self.unmitigate_queue = create_queue(
            SERVICE_NAME,
            exchange=self.mitigation_exchange,
            routing_key="unmitigate-with-action",
            priority=2,
        )
        self.stop_queue = create_queue(
            "{}-{}".format(SERVICE_NAME, uuid()),
            exchange=self.command_exchange,
            routing_key="stop-{}".format(SERVICE_NAME),
            priority=1,
        )

        log.info("data worker initiated")
Example #3
0
    def __init__(self, connection: Connection,
                 shared_memory_manager_dict: Dict) -> NoReturn:
        self.connection = connection
        self.rule_timer_thread = None
        self.shared_memory_manager_dict = shared_memory_manager_dict

        # wait for other needed data workers to start
        wait_data_worker_dependencies(DATA_WORKER_DEPENDENCIES)

        # EXCHANGES
        self.autoignore_exchange = create_exchange("autoignore",
                                                   connection,
                                                   declare=True)
        self.hijack_exchange = create_exchange("hijack-update",
                                               connection,
                                               declare=True)
        self.command_exchange = create_exchange("command",
                                                connection,
                                                declare=True)

        # QUEUES
        self.autoignore_hijacks_rules_queue = create_queue(
            SERVICE_NAME,
            exchange=self.autoignore_exchange,
            routing_key="hijacks-matching-rule",
            priority=1,
        )
        self.stop_queue = create_queue(
            "{}-{}".format(SERVICE_NAME, uuid()),
            exchange=self.command_exchange,
            routing_key="stop-{}".format(SERVICE_NAME),
            priority=1,
        )

        # DB variables
        self.ro_db = DB(
            application_name="autoignore-data-worker-readonly",
            user=DB_USER,
            password=DB_PASS,
            host=DB_HOST,
            port=DB_PORT,
            database=DB_NAME,
            reconnect=True,
            autocommit=True,
            readonly=True,
        )

        log.info("setting up autoignore checker process...")
        self.autoignore_checker = AutoignoreChecker(
            self.connection, self.shared_memory_manager_dict)
        mp.Process(target=self.autoignore_checker.run).start()
        log.info("autoignore checker set up")

        log.info("data worker initiated")
Example #4
0
        def __init__(self, connection):
            self.module_name = "monitor"
            self.connection = connection
            self.timestamp = -1
            self.prefix_tree = None
            self.process_ids = []
            self.rules = None
            self.prefixes = set()
            self.prefix_file = "/root/monitor_prefixes.json"
            self.monitors = None
            self.flag = True
            self.redis = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)
            ping_redis(self.redis)
            self.correlation_id = None

            # EXCHANGES
            self.config_exchange = create_exchange("config", connection)

            # QUEUES
            self.config_queue = create_queue(
                self.module_name,
                exchange=self.config_exchange,
                routing_key="notify",
                priority=2,
            )

            self.config_request_rpc()

            # setup Redis monitor listeners
            self.setup_redis_mon_listeners()

            log.info("started")
Example #5
0
    def __init__(self, connection: Connection,
                 shared_memory_manager_dict: Dict) -> NoReturn:
        self.connection = connection
        self.redis = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)
        ping_redis(self.redis)
        self.shared_memory_manager_dict = shared_memory_manager_dict

        self.prefix_tree = {
            "v4": pytricia.PyTricia(32),
            "v6": pytricia.PyTricia(128)
        }
        shared_memory_locks["prefix_tree"].acquire()
        if self.shared_memory_manager_dict["prefix_tree_recalculate"]:
            for ip_version in ["v4", "v6"]:
                if ip_version == "v4":
                    size = 32
                else:
                    size = 128
                self.prefix_tree[ip_version] = dict_to_pytricia(
                    self.shared_memory_manager_dict["prefix_tree"][ip_version],
                    size)
                log.info("{} pytricia tree parsed from configuration".format(
                    ip_version))
                self.shared_memory_manager_dict[
                    "prefix_tree_recalculate"] = False
        shared_memory_locks["prefix_tree"].release()

        self.autoignore_prefix_tree = {
            "v4": pytricia.PyTricia(32),
            "v6": pytricia.PyTricia(128),
        }
        shared_memory_locks["autoignore"].acquire()
        if self.shared_memory_manager_dict["autoignore_recalculate"]:
            for ip_version in ["v4", "v6"]:
                if ip_version == "v4":
                    size = 32
                else:
                    size = 128
                self.autoignore_prefix_tree[ip_version] = dict_to_pytricia(
                    self.shared_memory_manager_dict["autoignore_prefix_tree"]
                    [ip_version],
                    size,
                )
                log.info("{} pytricia tree parsed from configuration".format(
                    ip_version))
                self.shared_memory_manager_dict[
                    "autoignore_recalculate"] = False
        shared_memory_locks["autoignore"].release()

        # EXCHANGES
        self.update_exchange = create_exchange("bgp-update",
                                               connection,
                                               declare=True)
        self.hijack_exchange = create_exchange("hijack-update",
                                               connection,
                                               declare=True)
        self.autoconf_exchange = create_exchange("autoconf",
                                                 connection,
                                                 declare=True)
        self.pg_amq_bridge = create_exchange("amq.direct", connection)
        self.mitigation_exchange = create_exchange("mitigation",
                                                   connection,
                                                   declare=True)
        self.autoignore_exchange = create_exchange("autoignore",
                                                   connection,
                                                   declare=True)
        self.command_exchange = create_exchange("command",
                                                connection,
                                                declare=True)

        # QUEUES
        self.update_queue = create_queue(
            SERVICE_NAME,
            exchange=self.update_exchange,
            routing_key="update",
            priority=1,
        )
        self.hijack_ongoing_queue = create_queue(
            SERVICE_NAME,
            exchange=self.hijack_exchange,
            routing_key="ongoing",
            priority=1,
        )
        self.pg_amq_update_queue = create_queue(
            SERVICE_NAME,
            exchange=self.pg_amq_bridge,
            routing_key="update-insert",
            priority=1,
        )
        self.mitigation_request_queue = create_queue(
            SERVICE_NAME,
            exchange=self.mitigation_exchange,
            routing_key="mitigate",
            priority=2,
        )
        self.unmitigation_request_queue = create_queue(
            SERVICE_NAME,
            exchange=self.mitigation_exchange,
            routing_key="unmitigate",
            priority=2,
        )
        self.stop_queue = create_queue(
            "{}-{}".format(SERVICE_NAME, uuid()),
            exchange=self.command_exchange,
            routing_key="stop-{}".format(SERVICE_NAME),
            priority=1,
        )
        self.autoconf_update_queue = create_queue(
            SERVICE_NAME,
            exchange=self.autoconf_exchange,
            routing_key="update",
            priority=4,
            random=True,
        )
        self.ongoing_hijack_prefixes_queue = create_queue(
            SERVICE_NAME,
            exchange=self.autoignore_exchange,
            routing_key="ongoing-hijack-prefixes",
            priority=1,
            random=True,
        )

        log.info("data worker initiated")
Example #6
0
    def __init__(self, connection: Connection,
                 shared_memory_manager_dict: Dict) -> NoReturn:
        self.connection = connection
        self.shared_memory_manager_dict = shared_memory_manager_dict
        self.rtrmanager = None

        # wait for other needed data workers to start
        wait_data_worker_dependencies(DATA_WORKER_DEPENDENCIES)

        # EXCHANGES
        self.update_exchange = create_exchange("bgp-update",
                                               connection,
                                               declare=True)
        self.hijack_exchange = create_exchange("hijack-update",
                                               connection,
                                               declare=True)
        self.hijack_hashing = create_exchange("hijack-hashing",
                                              connection,
                                              "x-consistent-hash",
                                              declare=True)
        self.handled_exchange = create_exchange("handled-update",
                                                connection,
                                                declare=True)
        self.hijack_notification_exchange = create_exchange(
            "hijack-notification", connection, declare=True)
        self.command_exchange = create_exchange("command",
                                                connection,
                                                declare=True)

        # QUEUES
        self.update_queue = create_queue(
            SERVICE_NAME,
            exchange=self.update_exchange,
            routing_key="stored-update-with-prefix-node",
            priority=1,
        )
        self.hijack_ongoing_queue = create_queue(
            SERVICE_NAME,
            exchange=self.hijack_exchange,
            routing_key="ongoing-with-prefix-node",
            priority=1,
        )
        self.stop_queue = create_queue(
            "{}-{}".format(SERVICE_NAME, uuid()),
            exchange=self.command_exchange,
            routing_key="stop-{}".format(SERVICE_NAME),
            priority=1,
        )

        setattr(self, "publish_hijack_fun",
                self.publish_hijack_result_production)
        if TEST_ENV == "true":
            setattr(self, "publish_hijack_fun",
                    self.publish_hijack_result_test)

        self.redis = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)
        ping_redis(self.redis)

        if RPKI_VALIDATOR_ENABLED == "true":
            from rtrlib import RTRManager

            while True:
                try:
                    self.rtrmanager = RTRManager(RPKI_VALIDATOR_HOST,
                                                 RPKI_VALIDATOR_PORT)
                    self.rtrmanager.start()
                    log.info("Connected to RPKI VALIDATOR '{}:{}'".format(
                        RPKI_VALIDATOR_HOST, RPKI_VALIDATOR_PORT))
                    break
                except Exception:
                    log.info(
                        "Could not connect to RPKI VALIDATOR '{}:{}'".format(
                            RPKI_VALIDATOR_HOST, RPKI_VALIDATOR_PORT))
                    log.info("Retrying RTR connection in 30 seconds...")
                    time.sleep(30)

        log.info("data worker initiated")