hpimdm/Run.py
def run(self):
        """
        Daemon process will run this method until the daemon process explicitly is stopped
        """
        Main.main()
        server_address = hpim_globals.DAEMON_SOCKET.format(hpim_globals.MULTICAST_TABLE_ID)

        # Make sure the socket does not already exist
        try:
            os.unlink(server_address)
        except OSError:
            if os.path.exists(server_address):
                raise

        # Create a UDS socket
        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

        # Bind the socket to the port
        sock.bind(server_address)

        # Listen for incoming connections
        sock.listen(1)
        while True:
            try:
                connection, client_address = sock.accept()
                data = connection.recv(256 * 1024)
                print(sys.stderr, 'sending data back to the client')
                print(pickle.loads(data))
                args = pickle.loads(data)
                if 'ipv4' not in args or 'ipv6' not in args or not (args.ipv4 or args.ipv6):
                    args.ipv4 = True
                    args.ipv6 = False

                if 'list_interfaces' in args and args.list_interfaces:
                    connection.sendall(pickle.dumps(Main.list_enabled_interfaces(ipv4=args.ipv4, ipv6=args.ipv6)))
                elif 'list_neighbors' in args and args.list_neighbors:
                    connection.sendall(pickle.dumps(Main.list_neighbors(ipv4=args.ipv4, ipv6=args.ipv6)))
                elif 'list_state' in args and args.list_state:
                    connection.sendall(pickle.dumps(Main.list_state(ipv4=args.ipv4, ipv6=args.ipv6)))
                elif 'list_neighbors_state' in args and args.list_neighbors_state:
                    connection.sendall(pickle.dumps(Main.list_neighbors_state(ipv4=args.ipv4, ipv6=args.ipv6)))
                elif 'list_sequence_numbers' in args and args.list_sequence_numbers:
                    connection.sendall(pickle.dumps(Main.list_sequence_numbers(ipv4=args.ipv4, ipv6=args.ipv6)))
                elif 'list_instances' in args and args.list_instances:
                    connection.sendall(pickle.dumps(Main.list_instances()))
                elif 'add_interface' in args and args.add_interface:
                    Main.add_hpim_interface(args.add_interface[0], ipv4=args.ipv4, ipv6=args.ipv6)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'flood_initial_data' in args and args.flood_initial_data:
                    connection.sendall(pickle.dumps(Main.change_initial_flood_setting()))
                elif 'hold_forwarding_state' in args and args.hold_forwarding_state:
                    connection.sendall(pickle.dumps(Main.hold_forwarding_state()))
                elif 'add_interface_igmp' in args and args.add_interface_igmp:
                    Main.add_membership_interface(interface_name=args.add_interface_igmp[0], ipv4=True, ipv6=False)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'add_interface_mld' in args and args.add_interface_mld:
                    Main.add_membership_interface(interface_name=args.add_interface_mld[0], ipv4=False, ipv6=True)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'remove_interface' in args and args.remove_interface:
                    Main.remove_interface(args.remove_interface[0], hpim=True, ipv4=args.ipv4, ipv6=args.ipv6)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'remove_interface_igmp' in args and args.remove_interface_igmp:
                    Main.remove_interface(args.remove_interface_igmp[0], membership=True, ipv4=True, ipv6=False)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'remove_interface_mld' in args and args.remove_interface_mld:
                    Main.remove_interface(args.remove_interface_mld[0], membership=True, ipv4=False, ipv6=True)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'list_hmac_algorithms' in args and args.list_hmac_algorithms:
                    connection.sendall(pickle.dumps(Main.list_hash_algorithms()))
                elif 'add_interface_security' in args and args.add_interface_security:
                    Main.add_security_key(args.add_interface_security[0], int(args.add_interface_security[1]),
                                          args.add_interface_security[2], args.add_interface_security[3],
                                          ipv4=args.ipv4, ipv6=args.ipv6)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'remove_interface_security' in args and args.remove_interface_security:
                    Main.remove_security_key(args.remove_interface_security[0], int(args.remove_interface_security[1]),
                                             ipv4=args.ipv4, ipv6=args.ipv6)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'stop' in args and args.stop:
                    Main.stop()
                    connection.shutdown(socket.SHUT_RDWR)
                    break
                elif 'test' in args and args.test:
                    Main.test(args.test[0], args.test[1])
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'traceback' in args and args.traceback:
                    faulthandler.dump_traceback(file=sys.stderr, all_threads=True)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'config' in args and args.config:
                    Main.set_config(args.config[0])
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'get_config' in args and args.get_config:
                    connection.sendall(pickle.dumps(Main.get_config()))
                elif 'drop' in args and args.drop:
                    Main.drop(args.drop[0], int(args.drop[1]))
            except Exception:
                connection.shutdown(socket.SHUT_RDWR)
                traceback.print_exc()
            finally:
                # Clean up the connection
                connection.close()
        sock.close()

        Daemon process will run this method until the daemon process explicitly is stopped
        
Daemon process will run this method until the daemon process explicitly is stopped
Daemon process will run this method until the daemon process explicitly is stopped
def run(self):
        Main.main()
        server_address = hpim_globals.DAEMON_SOCKET.format(hpim_globals.MULTICAST_TABLE_ID)
        try:
            os.unlink(server_address)
        except OSError:
            if os.path.exists(server_address):
                raise
        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        sock.bind(server_address)
        sock.listen(1)
        while True:
            try:
                connection, client_address = sock.accept()
                data = connection.recv(256 * 1024)
                print(sys.stderr, 'sending data back to the client')
                print(pickle.loads(data))
                args = pickle.loads(data)
                if 'ipv4' not in args or 'ipv6' not in args or not (args.ipv4 or args.ipv6):
                    args.ipv4 = True
                    args.ipv6 = False
                if 'list_interfaces' in args and args.list_interfaces:
                    connection.sendall(pickle.dumps(Main.list_enabled_interfaces(ipv4=args.ipv4, ipv6=args.ipv6)))
                elif 'list_neighbors' in args and args.list_neighbors:
                    connection.sendall(pickle.dumps(Main.list_neighbors(ipv4=args.ipv4, ipv6=args.ipv6)))
                elif 'list_state' in args and args.list_state:
                    connection.sendall(pickle.dumps(Main.list_state(ipv4=args.ipv4, ipv6=args.ipv6)))
                elif 'list_neighbors_state' in args and args.list_neighbors_state:
                    connection.sendall(pickle.dumps(Main.list_neighbors_state(ipv4=args.ipv4, ipv6=args.ipv6)))
                elif 'list_sequence_numbers' in args and args.list_sequence_numbers:
                    connection.sendall(pickle.dumps(Main.list_sequence_numbers(ipv4=args.ipv4, ipv6=args.ipv6)))
                elif 'list_instances' in args and args.list_instances:
                    connection.sendall(pickle.dumps(Main.list_instances()))
                elif 'add_interface' in args and args.add_interface:
                    Main.add_hpim_interface(args.add_interface[0], ipv4=args.ipv4, ipv6=args.ipv6)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'flood_initial_data' in args and args.flood_initial_data:
                    connection.sendall(pickle.dumps(Main.change_initial_flood_setting()))
                elif 'hold_forwarding_state' in args and args.hold_forwarding_state:
                    connection.sendall(pickle.dumps(Main.hold_forwarding_state()))
                elif 'add_interface_igmp' in args and args.add_interface_igmp:
                    Main.add_membership_interface(interface_name=args.add_interface_igmp[0], ipv4=True, ipv6=False)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'add_interface_mld' in args and args.add_interface_mld:
                    Main.add_membership_interface(interface_name=args.add_interface_mld[0], ipv4=False, ipv6=True)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'remove_interface' in args and args.remove_interface:
                    Main.remove_interface(args.remove_interface[0], hpim=True, ipv4=args.ipv4, ipv6=args.ipv6)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'remove_interface_igmp' in args and args.remove_interface_igmp:
                    Main.remove_interface(args.remove_interface_igmp[0], membership=True, ipv4=True, ipv6=False)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'remove_interface_mld' in args and args.remove_interface_mld:
                    Main.remove_interface(args.remove_interface_mld[0], membership=True, ipv4=False, ipv6=True)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'list_hmac_algorithms' in args and args.list_hmac_algorithms:
                    connection.sendall(pickle.dumps(Main.list_hash_algorithms()))
                elif 'add_interface_security' in args and args.add_interface_security:
                    Main.add_security_key(args.add_interface_security[0], int(args.add_interface_security[1]),
                                          args.add_interface_security[2], args.add_interface_security[3],
                                          ipv4=args.ipv4, ipv6=args.ipv6)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'remove_interface_security' in args and args.remove_interface_security:
                    Main.remove_security_key(args.remove_interface_security[0], int(args.remove_interface_security[1]),
                                             ipv4=args.ipv4, ipv6=args.ipv6)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'stop' in args and args.stop:
                    Main.stop()
                    connection.shutdown(socket.SHUT_RDWR)
                    break
                elif 'test' in args and args.test:
                    Main.test(args.test[0], args.test[1])
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'traceback' in args and args.traceback:
                    faulthandler.dump_traceback(file=sys.stderr, all_threads=True)
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'config' in args and args.config:
                    Main.set_config(args.config[0])
                    connection.shutdown(socket.SHUT_RDWR)
                elif 'get_config' in args and args.get_config:
                    connection.sendall(pickle.dumps(Main.get_config()))
                elif 'drop' in args and args.drop:
                    Main.drop(args.drop[0], int(args.drop[1]))
            except Exception:
                connection.shutdown(socket.SHUT_RDWR)
                traceback.print_exc()
            finally:
                connection.close()
        sock.close()
def run ( self ) : Main . main ( ) server_address = hpim_globals . DAEMON_SOCKET . format ( hpim_globals . MULTICAST_TABLE_ID ) try : os . unlink ( server_address ) except OSError : if os . path . exists ( server_address ) : raise sock = socket . socket ( socket . AF_UNIX , socket . SOCK_STREAM ) sock . bind ( server_address ) sock . listen ( 1 ) while True : try : connection , client_address = sock . accept ( ) data = connection . recv ( 256 * 1024 ) print ( sys . stderr , 'sending data back to the client' ) print ( pickle . loads ( data ) ) args = pickle . loads ( data ) if 'ipv4' not in args or 'ipv6' not in args or not ( args . ipv4 or args . ipv6 ) : args . ipv4 = True args . ipv6 = False if 'list_interfaces' in args and args . list_interfaces : connection . sendall ( pickle . dumps ( Main . list_enabled_interfaces ( ipv4 = args . ipv4 , ipv6 = args . ipv6 ) ) ) elif 'list_neighbors' in args and args . list_neighbors : connection . sendall ( pickle . dumps ( Main . list_neighbors ( ipv4 = args . ipv4 , ipv6 = args . ipv6 ) ) ) elif 'list_state' in args and args . list_state : connection . sendall ( pickle . dumps ( Main . list_state ( ipv4 = args . ipv4 , ipv6 = args . ipv6 ) ) ) elif 'list_neighbors_state' in args and args . list_neighbors_state : connection . sendall ( pickle . dumps ( Main . list_neighbors_state ( ipv4 = args . ipv4 , ipv6 = args . ipv6 ) ) ) elif 'list_sequence_numbers' in args and args . list_sequence_numbers : connection . sendall ( pickle . dumps ( Main . list_sequence_numbers ( ipv4 = args . ipv4 , ipv6 = args . ipv6 ) ) ) elif 'list_instances' in args and args . list_instances : connection . sendall ( pickle . dumps ( Main . list_instances ( ) ) ) elif 'add_interface' in args and args . add_interface : Main . add_hpim_interface ( args . add_interface [ 0 ] , ipv4 = args . ipv4 , ipv6 = args . ipv6 ) connection . shutdown ( socket . SHUT_RDWR ) elif 'flood_initial_data' in args and args . flood_initial_data : connection . sendall ( pickle . dumps ( Main . change_initial_flood_setting ( ) ) ) elif 'hold_forwarding_state' in args and args . hold_forwarding_state : connection . sendall ( pickle . dumps ( Main . hold_forwarding_state ( ) ) ) elif 'add_interface_igmp' in args and args . add_interface_igmp : Main . add_membership_interface ( interface_name = args . add_interface_igmp [ 0 ] , ipv4 = True , ipv6 = False ) connection . shutdown ( socket . SHUT_RDWR ) elif 'add_interface_mld' in args and args . add_interface_mld : Main . add_membership_interface ( interface_name = args . add_interface_mld [ 0 ] , ipv4 = False , ipv6 = True ) connection . shutdown ( socket . SHUT_RDWR ) elif 'remove_interface' in args and args . remove_interface : Main . remove_interface ( args . remove_interface [ 0 ] , hpim = True , ipv4 = args . ipv4 , ipv6 = args . ipv6 ) connection . shutdown ( socket . SHUT_RDWR ) elif 'remove_interface_igmp' in args and args . remove_interface_igmp : Main . remove_interface ( args . remove_interface_igmp [ 0 ] , membership = True , ipv4 = True , ipv6 = False ) connection . shutdown ( socket . SHUT_RDWR ) elif 'remove_interface_mld' in args and args . remove_interface_mld : Main . remove_interface ( args . remove_interface_mld [ 0 ] , membership = True , ipv4 = False , ipv6 = True ) connection . shutdown ( socket . SHUT_RDWR ) elif 'list_hmac_algorithms' in args and args . list_hmac_algorithms : connection . sendall ( pickle . dumps ( Main . list_hash_algorithms ( ) ) ) elif 'add_interface_security' in args and args . add_interface_security : Main . add_security_key ( args . add_interface_security [ 0 ] , int ( args . add_interface_security [ 1 ] ) , args . add_interface_security [ 2 ] , args . add_interface_security [ 3 ] , ipv4 = args . ipv4 , ipv6 = args . ipv6 ) connection . shutdown ( socket . SHUT_RDWR ) elif 'remove_interface_security' in args and args . remove_interface_security : Main . remove_security_key ( args . remove_interface_security [ 0 ] , int ( args . remove_interface_security [ 1 ] ) , ipv4 = args . ipv4 , ipv6 = args . ipv6 ) connection . shutdown ( socket . SHUT_RDWR ) elif 'stop' in args and args . stop : Main . stop ( ) connection . shutdown ( socket . SHUT_RDWR ) break elif 'test' in args and args . test : Main . test ( args . test [ 0 ] , args . test [ 1 ] ) connection . shutdown ( socket . SHUT_RDWR ) elif 'traceback' in args and args . traceback : faulthandler . dump_traceback ( file = sys . stderr , all_threads = True ) connection . shutdown ( socket . SHUT_RDWR ) elif 'config' in args and args . config : Main . set_config ( args . config [ 0 ] ) connection . shutdown ( socket . SHUT_RDWR ) elif 'get_config' in args and args . get_config : connection . sendall ( pickle . dumps ( Main . get_config ( ) ) ) elif 'drop' in args and args . drop : Main . drop ( args . drop [ 0 ] , int ( args . drop [ 1 ] ) ) except Exception : connection . shutdown ( socket . SHUT_RDWR ) traceback . print_exc ( ) finally : connection . close ( ) sock . close ( )
Daemon process will run this method until the daemon process explicitly is stopped
Daemon process will run this method until the daemon process explicitly is stopped
"""
        Daemon process will run this method until the daemon process explicitly is stopped
        """ # Make sure the socket does not already exist # Create a UDS socket # Bind the socket to the port # Listen for incoming connections # Clean up the connection
self