Wired ad hoc network method, device and equipment based on FTTR and medium

By using the original socket and target filtering rules of the data link layer in the FTTR network, identifying the LAN and WAN interfaces of the network device, determining the host and slave identities, solving the problem of wrong role selection in the network, and improving the accuracy and user experience of the network.

CN120238782APending Publication Date: 2025-07-01SHENZHEN SKYWORTH DIGITAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510278316.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-10
Publication Date
2025-07-01

AI Technical Summary

Technical Problem

In the existing FTTR networking technology, users are prone to errors in device role selection when forming networking, resulting in inaccurate networking and affecting user experience.

Method used

By creating a raw socket based on the data link layer, binding it to the LAN interface and WAN interface of the network device, starting a preset thread to monitor the network data packets, filtering out the target data packets using the target filtering rules, performing port detection, identifying the LAN interface and WAN interface of the network device, and determining the host and slave identity based on the interface connection status and message data reception status.

Benefits of technology

It realizes fast and accurate wired networking, improves user networking experience, avoids role selection errors, and ensures stable connection and communication of network devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120238782A_ABST
    Figure CN120238782A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of fiber to the room (FTTR) networking, is applied to fiber to the room (FTTR), enterprise-level fiber to the room (Fiber To the Room-Bus) and broadband fusion terminal products, and particularly relates to a wired ad hoc network method, device and equipment based on the FTTR and a medium. Visibly, the original socket based on the data link layer is created and bound to the network interface in the network equipment, the preset thread is started to monitor each network data packet passing through the original socket, the target data packet is filtered out from each network data packet by using the preset target filtering rule, and the target data packet is filtered out by using the target filtering rule. According to the embodiment of the invention, port detection is carried out on the target data packet, and then the host and slave identities of each network device are determined according to the connection condition of the LAN interface and the WAN interface of the network device and the receiving condition of the LAN interface and the WAN interface about a plurality of target types of message data, so that role selection errors during networking are avoided; therefore, wired networking can be completed quickly and accurately, and the user networking experience is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of FTTR networking technology, and is applied to fiber to the room (FTTR), enterprise-level fiber to the room (Fiber to the Room-Business) and broadband converged terminal products, and in particular to a wired self-organizing network method, device, equipment and medium based on FTTR. Background Art

[0002] In the fiber to the room (FTTR), enterprise-level fiber to the room (Fiber to TheRoom-Business) or broadband converged terminal environment, the sub-device and the main device together form an efficient and stable home network architecture. FTTR technology achieves gigabit network coverage throughout the house by laying optical fiber directly to every room in the home.

[0003] Wired self-organizing network is a common networking method, and its key is to let each device select the correct role according to the corresponding judgment conditions. However, the current wired self-organizing network solutions basically have restrictions. When the user does not meet some conditions during the networking operation, it is easy to make mistakes in device role selection, which will lead to the inability to accurately complete the networking and affect the user's networking experience. Therefore, how to avoid role selection errors during networking, which will lead to the inability to accurately complete the networking and affect the user's networking experience, is a technical problem that needs to be solved urgently. Summary of the invention

[0004] Based on this, it is necessary to address the above technical problems. The embodiments of the present invention provide a wired self-organizing network method, device, equipment and medium based on FTTR to solve the problem that the existing technology cannot avoid role selection errors during networking, resulting in the inability to accurately complete the networking and affecting the user's networking experience.

[0005] A first aspect of an embodiment of the present application provides a wired self-organizing network method based on FTTR, and the wired self-organizing network method based on FTTR includes: Creating a raw socket based on a data link layer, and binding the raw socket to a network interface in a network device, wherein the network interface includes a LAN interface and a WAN interface; Starting a preset thread to monitor each network data packet passing through the original socket, and filtering out a target data packet from each network data packet using a preset target filtering rule; Performing port detection on the target data packet to identify the LAN interface and WAN interface of the network device; Determine the host and slave identities of each network device according to the connection status of the LAN interface and the WAN interface, and the reception status of the LAN interface and the WAN interface for several types of target packet data, so as to perform wired networking of the network devices.

[0006] The second aspect of the embodiments of the present application provides a wired self-organizing network device based on FTTR. The wired self-organizing network device based on FTTR includes: A creation module, configured to create a raw socket based on the data link layer and bind the raw socket to a network interface in a network device, where the network interface includes a LAN interface and a WAN interface; A listening module, configured to start a preset thread to listen for each network data packet passing through the raw socket, and filter out target data packets from each network data packet by using a preset target filtering rule; A detection module, configured to perform port detection on the target data packet to identify the LAN interface and the WAN interface of the network device; A determination module, configured to determine the host and slave identities of each network device according to the connection status of the LAN interface and the WAN interface, and the reception status of the LAN interface and the WAN interface for several types of target packet data, so as to perform wired networking of the network devices.

[0007] In a third aspect, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the wired self-organizing network method based on FTTR as described in the first aspect is implemented.

[0008] In a fourth aspect, a computer-readable storage medium is provided. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the wired self-organizing network method based on FTTR as described in the first aspect is implemented.

[0009] In summary, the present invention provides a wired ad-hoc network method, device, equipment and medium based on FTTR. By creating a raw socket based on the data link layer and binding the raw socket to a network interface in the network device, where the network interface includes a LAN interface and a WAN interface, starting a preset thread to listen for each network data packet passing through the raw socket, filtering out target data packets from each network data packet using a preset target filtering rule, performing port detection on the target data packets, identifying the LAN interface and the WAN interface of the network device, and determining the host and slave identities of each network device according to the connection status of the LAN interface and the WAN interface and the reception status of the message data of several target types by the LAN interface and the WAN interface, so as to perform wired networking of the network devices. It can be seen that in this application, by determining the host and slave identities of each network device according to the connection status of the LAN interface and the WAN interface and the reception status of the message data of several target types by the LAN interface and the WAN interface, the error in role selection during networking is avoided, so that wired networking can be completed quickly and accurately, improving the user's networking experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention, and those of ordinary skill in the art can also obtain other drawings without creative efforts based on these drawings.

[0011] Figure 1 is an application environment diagram of a wired ad-hoc network method based on FTTR provided by an embodiment of the present invention; Figure 2 is a flowchart of a wired ad-hoc network method based on FTTR provided by an embodiment of the present invention; Figure 3 is a structural diagram of a wired ad-hoc network device based on FTTR provided by an embodiment of the present invention; Figure 4 is a structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0012] The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art without creative efforts based on the embodiments of the present invention belong to the scope of protection of the present invention.

[0013] It should be understood that, as used in the specification of the present invention and the appended claims, the term "comprising" indicates the presence of the described features, integers, steps, operations, elements and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or their groups.

[0014] It should also be understood that the term "and / or" used in the specification of the present invention and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0015] As used in the specification of the present invention and the appended claims, the term "if" may be interpreted, depending on the context, as "when" or "once" or "in response to determining". Similarly, the phrase "if it is determined" or "if [the described condition or event] is matched" may be interpreted, depending on the context, as meaning "once it is determined" or "in response to determining" or "once [the described condition or event] is matched" or "in response to [the described condition or event] being matched".

[0016] In addition, in the description of the specification of the present invention and the appended claims, the terms "first", "second", "third", etc. are only used for distinguishing descriptions and cannot be understood as indicating or implying relative importance.

[0017] The reference to "one embodiment" or "some embodiments" etc. described in the specification of the present invention means that a specific feature, structure or characteristic described in connection with that embodiment is included in one or more embodiments of the present invention. Thus, statements such as "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments" etc. that appear in different places in this specification do not necessarily all refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in another way. The terms "comprising", "including", "having" and their variants all mean "including but not limited to", unless otherwise specifically emphasized in another way.

[0018] It should be understood that the magnitudes of the sequence numbers of the steps in the following embodiments do not mean the order of execution is prior or subsequent. The order of execution of each process should be determined according to its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.

[0019] In order to illustrate the technical solution of the present invention, the following specific embodiments are used for illustration.

[0020] See Figure 1 , which is an application environment diagram of a wired ad-hoc network method based on FTTR provided by an embodiment of the present invention. A wired ad-hoc network method based on FTTR provided by an embodiment of the present invention can be applied in, for example,Figure 1 In the application environment, the client communicates with the server. The client includes, but is not limited to, electronic devices such as a personal digital assistant, a desktop computer, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc. Here, the client is replaced by a business system. The server can be implemented by an independent server or a server cluster composed of multiple servers. Through the server, a wired self-organizing network based on FTTR is carried out to improve the user's network experience.

[0021] See Figure 2 , which is a schematic flow chart of a wired self-organizing network method based on FTTR provided by an embodiment of the present invention. As Figure 2 shown, the wired self-organizing network method based on FTTR can be implemented through the following steps.

[0022] S201: Create a raw socket based on the data link layer and bind the raw socket to a network interface in the network device, where the network interface includes a LAN interface and a WAN interface.

[0023] In step S201, a raw socket is a type of socket used in network programming, which mainly provides direct access to the underlying network protocol. Through the raw socket, an application can customize the content and format of data packets, including the IP header, TCP header, UDP header, etc., thereby being able to support the implementation of special network functions, such as custom protocols, network monitoring, packet filtering, etc. The raw socket allows an application to read and write unprocessed network data packets, including protocol headers and payloads. The network interface can be determined by querying the network topology and the corresponding interface identifier, and a deployed network configuration tool or management interface can also be used to view the settings and status of the network interface to determine information such as the interface name, IP address, MAC address, etc. corresponding to each network interface, so as to determine the network interface. Of course, the network interface can also be obtained by other means. The specific method for obtaining the network interface is not limited here, and those skilled in the art can determine it according to actual needs. The LAN interface (local area network interface) is used for data exchange and resource sharing between devices within the local area network, and the WAN interface (wide area network interface) is used to connect the local area network to an external network to achieve communication with the Internet or other remote networks.

[0024] In this embodiment, a raw socket is created by using the socket() function, specifying the protocol family type as PF_PACKET (for Linux systems, it may be different for other systems), and the socket type as SOCK_RAW or SOCK_DGRAM. Among them, the SOCK_RAW type allows receiving and sending data starting from the MAC header, and the packet data needs to be manually constructed and encapsulated; the data packets received by the SOCK_DGRAM type will have the MAC header removed, and there is no need to manually construct the MAC header when sending, and the filling of the MAC header is implemented by the kernel. The raw socket is bound to the specified network interface by using the setsockopt() function and the SO_BINDTODEVICE option. It is necessary to construct an ifreq structure and set its ifr_name field to the name of the network interface (such as "eth0" represents the LAN interface, "wan0" or a similar name represents the WAN interface, and the specific name depends on the system configuration). The address and size of the ifreq structure are passed as parameters to the setsockopt() function to complete the binding operation (in fact, an interface that can directly interact with the network hardware is created. Through this raw socket, all types of data frames passing through the bound interface can be captured and sent). The bind() function can also be used to bind the raw socket to the specified network interface, such as binding the raw socket to the specified source port 53, where 53 is the interface identifier of the source port, and the source port is the specified network interface. After completing the binding of the raw socket and the network interface, the raw socket is used to receive and send network packets. The kernel hook point socket_filter is used for the raw socket of the AF_PACKET type, so that the raw socket can capture all network packets passing through the specified network interface, including the Ethernet frame header, IP header, and data of higher-layer protocols, etc.

[0025] In an embodiment of the invention, creating a raw socket based on the data link layer includes: Obtaining the created network access node information; According to the created network access node information, obtaining the parameter information of the configured PF_PACKET protocol; According to the parameter information of the configured PF_PACKET protocol, creating a raw socket for the 2-layer working mode of the network device.

[0026] Specifically, first, it is necessary to determine and obtain the relevant information of the network access node, which may include the physical location of the node, IP address, MAC address, network interface type, etc. This can usually be obtained through network management protocols (such as SNMP), configuration files, or manual input. Specific APIs or library functions can be called to query network interface information or parse relevant entries in the configuration file. Based on the obtained network access node information, the parameter information required by the PF_PACKET protocol is determined. These parameters may include socket type (such as SOCK_RAW), protocol family (AF_PACKET), network interface index, packet capture mode (such as promiscuous mode), etc. Then, using the obtained PF_PACKET protocol parameter information, the socket() function is called to create a raw socket. This socket will work in the 2-layer (data link layer) mode, allowing direct capture and processing of Ethernet frames. When creating the raw socket, the correct address family (AF_PACKET), socket type (SOCK_RAW), and protocol (usually 0, indicating capturing packets of all protocols) need to be specified so that the raw socket can be bound to a specific network interface using the bind() function later, that is, binding all LAN interfaces and WAN interfaces. Through the above steps, an efficient packet capture mechanism is provided, reducing the processing overhead at the operating system level, and by configuring different parameter information, the behavior of the raw socket can be easily adjusted to adapt to different network environments and requirements.

[0027] In the embodiment of this application, by creating a raw socket based on the data link layer and binding the raw socket to the network interface in the network device, the sending and receiving paths of data can be precisely controlled so that the wired networking of the network device can be carried out more quickly subsequently.

[0028] S202: Start a preset thread to listen for each network packet passing through the raw socket, and filter out target packets from each of the network packets using a preset target filtering rule.

[0029] In step S202, after creating the raw socket, one or more threads can be created using multi-threaded programming techniques to listen for packets on the raw socket. For example, threads can be created in C / C++ using the POSIX thread (pthread) library. Define preset target filtering rules, that is, set BPF filtering rules on the raw socket so that it does not listen for response messages sent by itself; listen for response messages whose destination mac is itself; listen for request broadcast packets. BPF filters define filtering rules based on a register-based virtual machine instruction set to check specific fields of packets, such as source address, destination address, protocol type, port number, etc. In the listening thread, a loop structure is used to continuously receive packets from the raw socket. For each received packet, the content of the packet is parsed according to its header information (such as Ethernet frame header, IP header, TCP / UDP header, etc.). By checking whether the packet meets the filtering conditions. If the conditions are met, the packet is regarded as a target packet and subsequent processing is performed (such as storage, analysis, forwarding, etc.). If the conditions are not met, the packet is discarded. It can be seen that by introducing the BPF technology, it is ensured that the network device operates efficiently and securely, supports real-time monitoring information, can customize packet filtering rules, and can be loaded into the raw socket through the BPF filtering rules to run, thus enabling efficient and accurate determination of the target packets to be captured.

[0030] In an embodiment of the invention, the filtering out of the target packets from each of the network packets by using the preset filtering rules includes: Obtain the target filtering rules corresponding to the raw socket; Perform preprocessing on each of the network packets to obtain preprocessed network packets; If the preprocessed network packet meets the target filtering rules corresponding to the raw socket, determine the preprocessed network packet as the target packet.

[0031] Specifically, according to business requirements or user configurations, define the packet filtering rules that the raw socket needs to apply. These rules can be based on various attributes of the packets, such as source / destination IP addresses, source / destination port numbers, protocol types (TCP, UDP, ICMP, etc.), packet lengths, values of specific fields, etc. The filtering rules are usually stored in a certain form (such as strings, regular expressions, structured configuration objects, etc.) and can be dynamically loaded during program runtime. Parse the captured raw packets (usually link-layer frames) to extract relevant information at the IP layer, transport layer (TCP / UDP, etc.), and application layer (if needed). Perform preprocessing on each network packet to obtain the preprocessed network packet. The preprocessing may include steps such as packet decoding, checksum verification, fragmentation reassembly (for IP fragmentation), protocol identification, etc. Then, for each preprocessed packet, check whether it meets the target filtering rules corresponding to the raw socket. If the preprocessed network packet meets the filtering rules, mark it as a target packet for subsequent processing; otherwise, the packet can be discarded or ignored. Through the above steps, the efficiency and accuracy of packet processing are improved, thereby reducing the possibility of false positives and false negatives, which is beneficial to enhancing the stability and security of network device operation.

[0032] In an optional embodiment, in response to an update operation for the target filtering rules, update the target filtering rules to obtain the updated target filtering rules. Among them, different target filtering rules are used to filter network packets of different protocols. The update operation is an operation for technicians to adjust the filtering rules according to packet capture requirements. Since different target filtering rules are adapted to network packets of different protocols, during subsequent monitoring, monitor and capture network packets of different protocols according to the target filtering rules generated by the update. By supporting the custom update of the target filtering rules, it is convenient to flexibly adjust the filtering rules according to packet capture requirements, thereby enabling the monitoring of packets of different protocols and enhancing the flexibility and scalability of packet monitoring.

[0033] In this embodiment, by starting a preset thread to monitor each network packet passing through the raw socket and using the preset target filtering rules to filter out the target packets from each network packet, a large number of irrelevant packets can be prevented from being passed to the upper-layer protocol stack for processing, which helps to reduce the burden on the system and improve the efficiency of network processing.

[0034] S203: Perform port detection on the target packet to identify the LAN interface and WAN interface of the network device.

[0035] In step S203, use a preset listening thread and the original socket to capture data packets on the network. Apply preset target filtering rules to screen out target data packets from the captured data packets, and then parse the screened-out target data packets to extract their header information, including source address, destination address, source port, destination port, etc. According to the protocol type of the data packet (such as TCP, UDP, etc.), detect the source port and destination port of the data packet to identify whether they belong to the port ranges used by known LAN interfaces or WAN interfaces. This can be achieved by matching with a preset port list or rules. For example, certain port numbers may be predefined for use by LAN interfaces, while other port numbers may be predefined for use by WAN interfaces. According to the results of the port detection, identify through which network interface (LAN interface or WAN interface) the data packet is transmitted. If the port of the data packet matches the preset port list of the LAN interface, it is identified as a data packet of the LAN interface; if it matches the preset port list of the WAN interface, it is identified as a data packet of the WAN interface. Then record the identified data packets of the LAN interface and WAN interface, and generate corresponding reports or logs, which helps subsequent network analysis, monitoring, and troubleshooting.

[0036] In an embodiment of the invention, performing port detection on the target data packet to identify the LAN interface and WAN interface of the network device includes: Obtain the data type of the target data packet; According to the data type and the connection end information of the network interface, identify the LAN interface and WAN interface of the network device.

[0037] Specifically, parse the target data packet to identify its protocol type (such as IP, ARP, IPv6, etc.) and possible higher-layer protocols (such as TCP, UDP, HTTP, etc.). The data type can be determined by checking the header information of the data packet. Query the interface configuration or status information of the network device to obtain the connection end information of each network interface. This may involve querying the configuration file of the network device, using a network management protocol (such as SNMP), or calling a system API to obtain interface information. Analyze the flow direction and source of the target data packet based on the data type and connection end information. Generally, the LAN interface is connected to devices within the local area network, while the WAN interface is connected to an external network (such as the Internet, the network provided by the ISP, etc.). It can be determined whether the data packet is transmitted through the LAN interface or the WAN interface by checking whether the source IP address and target IP address of the data packet belong to the internal network address range (such as the private IP address space). Additionally, the physical connection information of the interface (such as the port connected to the switch, the type of physical cable connected, etc.) or configuration information (such as the interface IP address, gateway settings, etc.) can be used to assist in identification. Record the identified LAN interface and WAN interface information for subsequent analysis or monitoring. Based on the identification results, different network policies can be implemented, such as traffic control, limited networking, access control list (ACL) rules, etc. Through the above steps, the LAN interface and WAN interface can be accurately determined, and the flow direction and source of network traffic can be better understood, so that subsequent wired networking of network devices can be carried out more quickly, thereby improving the security and reliability of network operation.

[0038] In an embodiment of the invention, identifying the LAN interface and WAN interface of the network device according to the data type and the connection end information of the network interface includes: If the data type is for external network data exchange, detect whether there is a gateway at the connection end of the network interface; If there is a gateway at the connection end of the network interface, use the network interface as the WAN interface, otherwise, use the network interface as the LAN interface; If the data type is for internal network data exchange, according to a preset network protocol, detect whether there is a server at the connection end of the network interface and whether the network interface has established a session with the server; If there is a server at the connection end of the network interface and the network interface has established a session with the server, use the network interface as the WAN interface, otherwise, use the network interface as the LAN interface.

[0039] Specifically, by checking information such as the IP address, port number, and protocol type of the data packet, it is determined whether the data type is internal network exchange data or external network exchange data. If the data type is external network exchange data, it is detected whether there is a gateway at the connection end of the network interface. The gateway is usually a node connecting the internal network and the external network, and it is responsible for routing data packets. If the network interface is configured with a gateway and this gateway is the entry point of the external network (for example, the gateway provided by the ISP), then this network interface is identified as a WAN interface. Conversely, this network interface is identified as a LAN interface. If the data type is internal network exchange data, according to the preset network protocols (such as DHCP, DNS, HTTP, etc.), it is detected whether there is a server at the connection end of the network interface and whether the network interface has established a session with the server. The server can be a key device in the internal network, such as a DHCP server, a DNS server, a Web server, etc. The session status can be determined by checking the TCP connection, UDP session, or other protocol-specific session information. If the network interface is connected to a server and has established an effective session with the server, this may mean that this interface is used for interaction with the external network (such as the Internet), so it can be identified as a WAN interface (especially in some special configurations, such as NAT reflection, VPN tunnel, etc.). Conversely, if the network interface is not connected to a server or has not established a session with the server, this network interface is identified as a LAN interface because it is mainly used for internal network communication. Furthermore, the identified WAN interface and LAN interface information are recorded for subsequent analysis or monitoring. Through the above steps, it is possible to accurately determine the WAN interface and LAN interface in the network interface, reduce the possibility of misjudgment and missed judgment, so as to be able to connect the network cable at will for network formation later.

[0040] In this embodiment, by performing port detection on the target data packet, the LAN interface and WAN interface of the network device are identified, and then it can be accurately identified through which network interface the data packet is transmitted. This helps to avoid misjudgment and missed judgment and improve the accuracy of network monitoring.

[0041] S204: Determine the host and slave identities of each network device according to the connection conditions of the LAN interface and the WAN interface, and the reception conditions of the LAN interface and the WAN interface for several types of target message data, so as to perform wired networking of the network device.

[0042] In step S204, first, the connection status of the LAN interface and the WAN interface of each network device is detected by checking the physical connection of the interface, the link layer status (such as the on / off state of the Ethernet link), and the network layer configuration (such as the allocation of IP addresses). The packet data received by each network device through the LAN interface and the WAN interface is monitored. In particular, attention is paid to those packets related to the target type, such as ARP requests / responses, DHCP discovery / offers / requests / acks, ICMP echo requests / responses, etc. By analyzing the source address, destination address, packet type, and content of these packets, the roles and behaviors of the network devices can be inferred. Furthermore, based on the interface connection situation and the packet data reception situation, a set of determination rules is formulated to determine the host and slave identities of the network devices. For example, if a device is connected to the Internet through the WAN interface and provides DHCP services to other devices or forwards packets as a gateway through the LAN interface, it is very likely to be determined as the host. On the contrary, if a device is only connected to the host through the LAN interface and obtains the IP address and other network configurations from the host, it is very likely to be determined as the slave. Once the host and slave identities of the network devices are determined, the wired networking process can begin. This includes configuring network parameters such as the IP address, subnet mask, gateway, DNS, etc. of the network devices, as well as establishing and maintaining the connection and communication between the network devices. During the networking process, it is necessary to ensure that the connection between the host and the slave is stable and reliable and can meet the requirements of network applications in order to complete the wired networking quickly and accurately.

[0043] It should be noted that these determination rules can be customized and adjusted according to the specific network environment and requirements, and the present application does not make any limitations in this regard.

[0044] In an embodiment of the invention, according to the connection situation of the LAN interface and the WAN interface, and the reception situation of the packet data of several target types of the LAN interface and the WAN interface, determining the host and slave identities of each network device includes: In response to the connection situation including the connection time of the LAN interface and the WAN interface, obtaining the time difference between the current time and the connection time; Based on the time difference and the reception time of the first packet data of various target types, determining the host and slave identities of each network device.

[0045] Specifically, the connection situation may include the connection time, or it may not include any connection time. In the case where the connection situation includes the connection time (i.e., when there is a valid connection time T4), it can be considered that the LAN interface and the WAN interface maintain a valid communication connection. On this basis, the time difference between the current time T5 and the connection time T4 can be further obtained, and based on the time difference and the reception times of the first packet data of various target types (i.e., the aforementioned T1, T2, T3), the host and slave identities of each network device can be determined. Through the above method, the situation where the connection situation does not include the connection time can be excluded, and the host and slave identities of each network device can be further determined by combining the time difference between the current time and the connection time, which is beneficial to improving the efficiency and accuracy of wired networking.

[0046] In an embodiment of the invention, determining the host and slave identities of each of the network devices based on the time difference and the reception times of the first packet data of various target types includes: Determine whether the time difference is less than a preset time threshold; If the time difference is less than the preset time threshold, then sort the reception times of the first packet data of various target types according to the priority to obtain a time sorting result; According to the time sorting result, use the network device with the earliest reception time as the host identity.

[0047] Specifically, for the first packet data of each target type, record its reception time, calculate the difference between its reception time and a certain reference time (such as the earliest reception time or the current time), compare each time difference with the preset time threshold. If the time difference is less than the preset time threshold, it is considered that these packets are received within a similar time and need further processing. For all packets with time differences less than the preset threshold, sort the reception times of the first packet data of various target types according to the priority of their network devices or packets to obtain a time sorting result, where the priority can be determined based on factors such as device type, historical behavior, processing ability, etc. According to the time sorting result, select the network device with the earliest reception time (or according to specific rules, such as the highest priority) as the host identity, that is, the network interfaces of all devices will receive response messages. At this time, judge according to the timestamps of each device carried in the replied response messages, and the device with the earliest time is used as the host identity. Through the above steps, the host and slave identities of each of the network devices can be determined more quickly without manual operation and configuration, which is beneficial to improving the flexibility of wired networking and the network deployment efficiency.

[0048] In this embodiment, by according to the connection status of the LAN interface and the WAN interface, as well as the reception status of the LAN interface and the WAN interface for message data of several target types, the host and slave identities of the network device can be determined quickly and accurately without manual intervention or additional configuration work, thereby establishing a stable and reliable connection and communication, improving the efficiency and accuracy of wired networking, and ensuring the stability and reliability of network applications.

[0049] In an alternative embodiment, when multiple devices with undetermined roles are networking, they all continuously request and collect the replied messages within a time node, and finally determine their own roles according to the response messages, ensuring that all the devices networking simultaneously within this time node can send requests and receive response messages. If there is a fixed host in the network device, it will directly reply that the role of auto changes to a slave. If there is no fixed host, it will determine whether its WAN interface has received a response message within this time node. Through the above steps, it is possible to support multiple devices to first connect the network cables and then power on for simultaneous networking.

[0050] In summary, the present invention provides a wired self - networking method, device, equipment and medium based on FTTR. By creating a raw socket based on the data link layer and binding the raw socket to the network interfaces in the network device, where the network interfaces include the LAN interface and the WAN interface, starting a preset thread to listen for each network packet passing through the raw socket, filtering out target packets from each network packet using a preset target filtering rule, performing port detection on the target packets, identifying the LAN interface and the WAN interface of the network device, and determining the host and slave identities of each network device according to the connection status of the LAN interface and the WAN interface, as well as the reception status of the LAN interface and the WAN interface for message data of several target types, so as to perform wired networking of the network devices. It can be seen that the present application determines the host and slave identities of each network device according to the connection status of the LAN interface and the WAN interface, as well as the reception status of the LAN interface and the WAN interface for message data of several target types, avoiding incorrect role selection during networking, and thus can complete wired networking quickly and accurately, improving the user's networking experience.

[0051] Please refer to Figure 3 , Figure 3 which is a schematic structural diagram of the wired self - networking device based on FTTR provided by the embodiment of the present invention. The wired self - networking device based on FTTR corresponds one - to - one with the wired self - networking method based on FTTR in the above - mentioned embodiment. Specifically, please refer to Figure 2 and Figure 2 the relevant descriptions in the corresponding embodiments. For the sake of convenience of description, only the parts related to this embodiment are shown. See Figure 3, the wired ad-hoc network device 30 based on FTTR includes: a creation module 31, a listening module 32, a detection module 33, and a determination module 34.

[0052] The creation module 31 is used to create a raw socket based on the data link layer and bind the raw socket to a network interface in the network device, where the network interface includes a LAN interface and a WAN interface; The listening module 32 is used to start a preset thread to listen for each network data packet passing through the raw socket, and filter out target data packets from each of the network data packets using a preset target filtering rule; The detection module 33 is used to perform port detection on the target data packet to identify the LAN interface and the WAN interface of the network device; The determination module 34 is used to determine the host and slave identities of each network device according to the connection status of the LAN interface and the WAN interface, and the reception status of the message data of the LAN interface and the WAN interface regarding several target types, so as to perform wired networking of the network device.

[0053] Optionally, the above-mentioned creation module 31 is specifically used for: Obtain the created network access node information; According to the created network access node information, obtain the parameter information of the configured PF_PACKET protocol; According to the parameter information of the configured PF_PACKET protocol, create a raw socket for the 2-layer working mode of the network device.

[0054] Optionally, the above-mentioned listening module 32 is specifically used for: Obtain the target filtering rule corresponding to the raw socket; Perform preprocessing on each of the network data packets to obtain preprocessed network data packets; If the preprocessed network data packet meets the target filtering rule corresponding to the raw socket, determine the preprocessed network data packet as the target data packet.

[0055] Optionally, the above-mentioned detection module 33 is specifically used for: Obtain the data type of the target data packet; According to the data type and the connection end information of the network interface, identify the LAN interface and the WAN interface of the network device.

[0056] Optionally, the above-mentioned detection module 33 is further used for: If the data type is external network exchange data, detect whether there is a gateway at the connection end of the network interface; If there is a gateway at the connection end of the network interface, the network interface is used as the WAN interface; otherwise, the network interface is used as the LAN interface. If the data type is internal network exchange data, according to the preset network protocol, it is detected whether there is a server at the connection end of the network interface and whether the network interface establishes a session with the server. If there is a server at the connection end of the network interface and the network interface establishes a session with the server, the network interface is used as the WAN interface; otherwise, the network interface is used as the LAN interface.

[0057] Optionally, the determination module 34 is specifically configured to: In response to the connection situation including the connection times of the LAN interface and the WAN interface, obtain the time difference between the current time and the connection times. Based on the time difference and the reception times of the first packet data of various target types, determine the host and slave identities of each network device.

[0058] Optionally, the determination module 34 is further configured to: Judge whether the time difference is less than a preset time threshold. If the time difference is less than the preset time threshold, sort the reception times of the first packet data of various target types according to the priority to obtain a time sorting result. According to the time sorting result, use the network device with the earliest reception time as the host identity.

[0059] It should be noted that for the information interaction, execution process, etc. between the above units, since they are based on the same concept as the method embodiment of the present invention, the specific functions and the technical effects brought by them can be specifically referred to the method embodiment part, and will not be elaborated here.

[0060] Figure 4 It is a schematic structural diagram of an electronic device provided by an embodiment of the present invention. As Figure 4 shown, the electronic device of this embodiment includes: at least one processor ( Figure 4 only one is shown in the figure), a memory, and a computer program stored in the memory and executable on at least one processor. When the processor executes the computer program, it implements the steps in any of the above method embodiments of the wired ad hoc network method based on FTTR.

[0061] The electronic device may include, but is not limited to, a processor and a memory. Those skilled in the art can understand, Figure 4The examples of electronic devices are merely illustrative and do not constitute a limitation on the electronic devices. The electronic devices may include more or fewer components than those shown in the figures, or combine certain components, or different components. For example, they may also include a network interface, a display screen, an input system, etc.

[0062] In one embodiment, a computer-readable storage medium is provided. When the instructions in the computer-readable storage medium are executed by a processor in an electronic device, the electronic device is enabled to execute each step of any embodiment of a wired ad-hoc network method based on FTTR as disclosed in the present invention, which will not be repeated here. The computer-readable storage medium may be non-volatile or volatile.

[0063] The so-called processor may be a CPU, and this processor may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc.

[0064] The memory includes a readable storage medium, an internal memory, etc. Among them, the internal memory may be the memory of the electronic device, and the internal memory provides an environment for the operation of the operating system and computer-readable instructions in the readable storage medium. The readable storage medium may be the hard disk of the electronic device, and in some other embodiments, it may also be an external storage device of the electronic device. For example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device. Further, the memory may also include both the internal storage unit and the external storage device of the electronic device. The memory is used to store an operating system, cooperative applications, a boot loader, data, and other programs, such as the program code of a computer program. The memory may also be used to temporarily store data that has been output or will be output.

[0065] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. This computer program can be stored in a non-volatile computer-readable storage medium. When this computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, storage, database, or other medium used in the embodiments provided in this application can include non-volatile and / or volatile memories. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and Rambus dynamic RAM (RDRAM), etc.

[0066] Those skilled in the art can clearly understand that for the convenience and brevity of description, only the above division of each functional unit and module is used as an example. In actual applications, the above functions can be allocated to different functional units and modules as needed, that is, the internal structure of the system is divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiments can be integrated into a processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of each functional unit and module are only for the convenience of mutual distinction and do not limit the protection scope of the present invention. The specific working processes of the units and modules in the above system can refer to the corresponding processes in the foregoing method embodiments and will not be repeated here. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium.

[0067] The above-described embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention, and should all be included within the protection scope of the present invention.

Claims

1. A wired self-organizing network method based on FTTR, characterized in that: include: Creating a raw socket based on a data link layer, and binding the raw socket to a network interface in a network device, wherein the network interface includes a LAN interface and a WAN interface; Starting a preset thread to monitor each network data packet passing through the original socket, and filtering out a target data packet from each network data packet using a preset target filtering rule; Performing port detection on the target data packet to identify the LAN interface and WAN interface of the network device; According to the connection status of the LAN interface and the WAN interface, and the reception status of message data of several target types by the LAN interface and the WAN interface, the host and slave identities of each of the network devices are determined to perform wired networking of the network devices.

2. The FTTR-based wired ad hoc network method according to claim 1, characterized in that: The created raw socket based on the data link layer includes: Get the created network access node information; According to the created network access node information, obtain parameter information of the configured PF_PACKET protocol; According to the parameter information of the configured PF_PACKET protocol, a raw socket in a layer 2 working mode for the network device is created.

3. The FTTR-based wired ad hoc network method according to claim 1, characterized in that: The method of filtering out a target data packet from each of the network data packets by using a preset filtering rule includes: Obtaining the target filtering rule corresponding to the original socket; Preprocessing each of the network data packets to obtain preprocessed network data packets; If the preprocessed network data packet meets the target filtering rule corresponding to the original socket, the preprocessed network data packet is determined as the target data packet.

4. The FTTR-based wired ad hoc network method according to claim 1, characterized in that: The performing port detection on the target data packet to identify the LAN interface and the WAN interface of the network device includes: Acquire the data type of the target data packet; The LAN interface and the WAN interface of the network device are identified according to the data type and the connection end information of the network interface.

5. The FTTR-based wired ad hoc network method according to claim 4, characterized in that: The step of identifying the LAN interface and the WAN interface of the network device according to the data type and the connection end information of the network interface includes: If the data type is external network exchange data, detecting whether a gateway exists at the connection end of the network interface; If a gateway exists at the connection end of the network interface, the network interface is used as a WAN interface, otherwise, the network interface is used as a LAN interface; If the data type is internal network exchange data, then according to a preset network protocol, detecting whether there is a server at the connection end of the network interface and whether the network interface has established a session with the server; If there is a server at the connection end of the network interface and the network interface establishes a session with the server, the network interface is used as a WAN interface; otherwise, the network interface is used as a LAN interface.

6. The FTTR-based wired ad hoc network method according to claim 1, characterized in that: Determining the master and slave identities of each of the network devices according to the connection status of the LAN interface and the WAN interface, and the reception status of the message data of several target types by the LAN interface and the WAN interface, comprises: In response to the connection status including connection time of the LAN interface and the WAN interface, obtaining a time difference between a current time and the connection time; Based on the time difference and the reception time of the first message data of each target type, the master and slave identities of each network device are determined.

7. The FTTR-based wired ad hoc network method according to claim 6, characterized in that: The determining the master and slave identities of each of the network devices based on the time difference and the reception time of the first message data of various target types includes: Determining whether the time difference is less than a preset time threshold; If the time difference is less than a preset time threshold, sorting the receiving time of the first message data of various target types according to the priority to obtain a time sorting result; According to the time sorting result, the network device with the earliest receiving time is used as the host identity.

8. A wired ad hoc network device based on FTTR, characterized in that: include: A creation module, used for creating a raw socket based on a data link layer, and binding the raw socket to a network interface in a network device, wherein the network interface includes a LAN interface and a WAN interface; A monitoring module, used for starting a preset thread to monitor each network data packet passing through the original socket, and filtering out a target data packet from each network data packet using a preset target filtering rule; A detection module, used for performing port detection on the target data packet to identify the LAN interface and WAN interface of the network device; A determination module is used to determine the host and slave identities of each of the network devices based on the connection status of the LAN interface and the WAN interface, and the reception status of message data of several target types by the LAN interface and the WAN interface, so as to perform wired networking of the network devices.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the FTTR-based wired ad hoc network method according to any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the FTTR-based wired ad hoc network method according to any one of claims 1 to 7 is implemented.