Пример #1
0
	def __init__(self):
		super(Stateful_thread, self).__init__()
		self.os_type = common.get_os_type()
		self.checks = checks.Checks()
		self.controlchannel = controlchannel.ControlChannel()

		# control message handlers
		self.cmh_struct  = {
			# num : [string to look for, function, server(1) or client(0), return on success, return on failure]
			# return value meanings: True  - module continues
			#						 False - module thread terminates
			# in case of Stateless modules, the whole module terminates if the return value is False
			0  : [common.CONTROL_CHECK, 		self.controlchannel.cmh_check_query, 1, True, False],
			1  : [common.CONTROL_CHECK_RESULT, 	self.controlchannel.cmh_check_check, 0, True, False],
			2  : [common.CONTROL_AUTH, 			self.controlchannel.cmh_auth, 1, True, False],
			3  : [common.CONTROL_AUTH_OK, 		self.controlchannel.cmh_auth_ok, 0, True, False],
			4  : [common.CONTROL_AUTH_NOTOK, 	self.controlchannel.cmh_auth_not_ok, 0, True, False],
			5  : [common.CONTROL_LOGOFF, 		self.controlchannel.cmh_logoff, 1, False, False]
		}

		self.packet_writer = self.packet_writer_default
		self.packet_reader = self.packet_reader_default
		self.communication = self.communication_unix

		if self.os_type == common.OS_WINDOWS:
			self.packet_writer = self.packet_writer_win
			self.communication = self.communication_win
			self.packet_reader = None

		if self.os_type == common.OS_MACOSX:
			self.packet_writer = self.packet_writer_mac
			self.packet_reader = self.packet_reader_mac

		return
Пример #2
0
    def __init__(self):
        super(Stateless_module, self).__init__()
        self.checks = checks.Checks()
        self.timeout = 1.0
        self.controlchannel = controlchannel.ControlChannel()

        # control message handlers
        self.cmh_struct = {
            # num : [string to look for, function, server(1) or client(0), return on success, return on failure]
            # return value meanings: True  - module continues
            #						 False - module thread terminates
            # in case of Stateless modules, the whole module terminates if the return value is False
            0: [
                common.CONTROL_CHECK, self.controlchannel.cmh_check_query, 1,
                True, True
            ],
            1: [
                common.CONTROL_CHECK_RESULT,
                self.controlchannel.cmh_check_check, 0, True, False
            ],
            2:
            [common.CONTROL_INIT, self.controlchannel.cmh_init, 1, True, True],
            3: [
                common.CONTROL_INIT_DONE, self.controlchannel.cmh_init_done, 0,
                True, False
            ],
            4: [
                common.CONTROL_LOGOFF, self.controlchannel.cmh_logoff, 1, True,
                False
            ],
            5: [
                common.CONTROL_DUMMY_PACKET,
                self.controlchannel.cmh_dummy_packet, 1, True, True
            ],
        }

        # reading/writing packets can be different based on the OS
        self.packet_writer = self.packet_writer_default
        self.packet_reader = self.packet_reader_default
        # different communication function for Unix and Windows
        self.communication = self.communication_unix

        # setting up for Windows
        if self.os_type == common.OS_WINDOWS:
            self.packet_writer = self.packet_writer_win
            self.communication = self.communication_win
            self.packet_reader = None

        # setting up for MacOS(X)
        if self.os_type == common.OS_MACOSX:
            self.packet_writer = self.packet_writer_mac
            self.packet_reader = self.packet_reader_mac

        return
Пример #3
0
    def __init__(self):
        super(Stateless_module, self).__init__()
        self.timeout = 3.0
        self.controlchannel = controlchannel.ControlChannel()

        # control message handlers
        self.cmh_struct = {
            # num : [string to look for, function, server(1) or client(0), return on success, return on failure]
            # return value meanings: True  - module continues
            #						 False - module thread terminates
            # in case of Stateless modules, the whole module terminates if the return value is False
            0: [
                common.CONTROL_CHECK, self.controlchannel.cmh_check_query, 1,
                True, True
            ],
            1: [
                common.CONTROL_CHECK_RESULT,
                self.controlchannel.cmh_check_check, 0, True, False
            ],
            2:
            [common.CONTROL_AUTH, self.controlchannel.cmh_auth, 1, True, True],
            3: [
                common.CONTROL_AUTH_OK, self.controlchannel.cmh_auth_ok, 0,
                True, False
            ],
            4: [
                common.CONTROL_AUTH_NOTOK, self.controlchannel.cmh_auth_not_ok,
                0, True, False
            ],
            5: [
                common.CONTROL_LOGOFF, self.controlchannel.cmh_logoff, 1, True,
                False
            ],
            6: [
                common.CONTROL_DUMMY_PACKET,
                self.controlchannel.cmh_dummy_packet, 1, True, True
            ]
        }

        return
Пример #4
0
    def per_interface(self, if_name):
        """
        Run per interface that sniffing will run on as separate process
        """
        #*** Instantiate Data Plane (DP) class:
        self.dp = dp.DP(self.config)

        #*** Instantiate Control Channel Class:
        self.controlchannel = controlchannel.ControlChannel(
            self, self.config, if_name, self.dp)

        finished = 0
        while not finished:
            #*** Start Phase 1 connection to the controller:
            phase1_connected = 0
            self.logger.info("Phase 1 initiated for interface=%s", if_name)
            while not phase1_connected:
                result = self.controlchannel.phase1(self.api_base, if_name)
                if not isinstance(result, dict):
                    self.logger.error(
                        "Phase 1 join to controller failed, "
                        "will retry, "
                        "interface=%s result=%s", if_name, result)
                    time.sleep(3)
                    phase1_connected = 0
                    continue

                if not 'dpae2ctrl_mac' in result:
                    self.logger.error(
                        "Phase 1 join to controller failed, "
                        "will retry, "
                        "interface=%s", if_name)
                    time.sleep(3)
                    phase1_connected = 0
                    continue
                else:
                    dpae2ctrl_mac = result['dpae2ctrl_mac']
                    ctrl2dpae_mac = result['ctrl2dpae_mac']
                    dpae_ethertype = result['dpae_ethertype']
                    location = result['location']
                    phase1_connected = 1
            self.logger.info("Phase 1 active for interface=%s", if_name)

            #*** Start Phase 2:
            phase2_connected = 0
            retries = 1
            while phase1_connected and not phase2_connected:
                self.logger.info("Phase 2 Negotiation interface=%s starting",
                                 if_name)
                phase2_connected = self.controlchannel.phase2(
                    location, if_name, dpae2ctrl_mac, ctrl2dpae_mac,
                    dpae_ethertype)
                if phase2_connected:
                    self.logger.info("Phase 2 Active interface=%s", if_name)
                else:
                    self.logger.info("Phase 2 retry number %s", retries)
                    time.sleep(3)
                    retries += 1
                    if retries > self.PHASE2_MAX_RETRIES:
                        self.logger.info("Phase 2 max retries exceeded, "
                                         "restarting at Phase 1")
                        phase1_connected = 0
            if not phase2_connected:
                continue

            #*** Start Phase 3:
            phase3_connected = 0
            retries = 1
            while phase1_connected and phase2_connected and not \
                                                    phase3_connected:
                self.logger.info(
                    "Phase 3 confirmation sniff starting"
                    "interface=%s", if_name)
                phase3_connected = self.controlchannel.phase3(
                    location, if_name, dpae2ctrl_mac, ctrl2dpae_mac,
                    dpae_ethertype)
                if phase3_connected:
                    self.logger.info("Phase 3 Active interface=%s", if_name)
                else:
                    self.logger.info("Phase 3 retry number %s", retries)
                    time.sleep(3)
                    retries += 1
                    if retries > self.PHASE3_MAX_RETRIES:
                        self.logger.info("Phase 3 max retries exceeded, "
                                         "restarting at Phase 1")
                        phase1_connected = 0
                        phase2_connected = 0
            if not phase3_connected:
                continue

            #*** Start Phase 4:
            phase4_services = 0
            while phase1_connected and phase2_connected and phase3_connected \
                                            and not phase4_services:
                self.logger.info(
                    "Phase 4 services negotiation starting, "
                    "interface=%s", if_name)
                phase4_services = self.controlchannel.phase4(location, if_name)

            #*** Start Services:
            if 'traffic_classification' in phase4_services:
                self.logger.info("Phase 4 Traffic Classification service "
                                 "starting")
                self.cp_run(if_name, self.controlchannel, location)