Example #1
0
	def ProcessPacket(self, data, addr, sock, socktype):
		"""
			The purpose of this function is to create a RADIUS packet
			structure, quickly dispatch an accounting-ok packet back
			to the sender (in case we recieved an acct packet) and
			possibly start logging (instead of dispatching for further
			processing) new accounting packets under heavy server load
			when the packet queue becomes overpopulated with accounting
			packets.
		"""
		if socktype == SOCKTYPE_AUTH:
			# create auth packet
			pkt = packet.AuthPacket(dict = self.server.dict, packet = data)
			pkt.timestamp = time.time()
			pkt.source = addr
			pkt.fd = sock
			pkt.addClientIpAddress()
			pkt.addRequestAuthenticator()
			
			if not pkt.source[0] in self.server.hosts:
				warning ("dropped packet: received packet from unknown host")
				return

			pkt.secret = self.server.hosts[pkt.source[0]].secret

			if pkt.code != packet.AccessRequest:
				error ("dropped packet: received non-authentication packet on authentication port")
				return

			self.server.packets.add_auth_packet(pkt)
			return

		if socktype == SOCKTYPE_ACCT:
			# create acct packet
			pkt = packet.AcctPacket(dict = self.server.dict, packet = data)
			pkt.timestamp = time.time()
			pkt.source = addr
			pkt.fd = sock			
			pkt.addClientIpAddress()

			if not pkt.source[0] in self.server.hosts:
				error ("dropped packet: received packet from unknown host")
				return
			
			pkt.secret = self.server.hosts[pkt.source[0]].secret
			
			if not pkt.code in [packet.AccountingRequest, packet.AccountingResponse]:
				error ("dropped packet: received non-accounting packet on accounting port")
				return
				
			# send acct response to client even before processing the packet
			if main_config['SERVER']['fast_accounting']:
				self.sendAcctResponse(pkt)
			
			# put the whole packet into packet queue for later processing
			if self.server.packets.add_acct_packet(pkt) == False:
				info ("WARNING: Accounting packet queue full, must start logging")
				dumpPacket.dumpUnhandledAcctPacket(pkt)
			return
Example #2
0
    def ProcessPacket(self, data, addr, sock, socktype):
        """
			The purpose of this function is to create a RADIUS packet
			structure, quickly dispatch an accounting-ok packet back
			to the sender (in case we recieved an acct packet) and
			possibly start logging (instead of dispatching for further
			processing) new accounting packets under heavy server load
			when the packet queue becomes overpopulated with accounting
			packets.
		"""
        if socktype == SOCKTYPE_AUTH:
            # create auth packet
            pkt = packet.AuthPacket(dict=self.server.dict, packet=data)
            pkt.timestamp = time.time()
            pkt.source = addr
            pkt.fd = sock
            pkt.addClientIpAddress()
            pkt.addRequestAuthenticator()

            if not pkt.source[0] in self.server.hosts:
                error("dropped packet: received packet from unknown host")
                return

            pkt.secret = self.server.hosts[pkt.source[0]].secret

            if pkt.code != packet.AccessRequest:
                error(
                    "dropped packet: received non-authentication packet on authentication port"
                )
                return

            self.server.packets.add_auth_packet(pkt)
            return

        if socktype == SOCKTYPE_ACCT:
            # create acct packet
            pkt = packet.AcctPacket(dict=self.server.dict, packet=data)
            pkt.timestamp = time.time()
            pkt.source = addr
            pkt.fd = sock
            pkt.addClientIpAddress()

            if not pkt.source[0] in self.server.hosts:
                error("dropped packet: received packet from unknown host")
                return

            pkt.secret = self.server.hosts[pkt.source[0]].secret

            if not pkt.code in [
                    packet.AccountingRequest, packet.AccountingResponse
            ]:
                error(
                    "dropped packet: received non-accounting packet on accounting port"
                )
                return

            # create and send a reply packet
            client = self.server.hosts[pkt.source[0]]
            address = pkt.source[0]
            debug("Sending Accounting ACCEPT to %s (%s)" %
                  (client.name, address))
            reply = pkt.CreateReply()
            reply.source = pkt.source
            sock.sendto(reply.ReplyPacket(), reply.source)

            # put the whole packet into packet queue for later processing
            if self.server.packets.add_acct_packet(pkt) == False:
                info("acct packet queue full, must start logging")
                dumpPacket.dumpUnhandledAcctPacket(pkt)
            return