CN107172009B - Method for uploading VLAN information to application module through socket - Google Patents
Method for uploading VLAN information to application module through socket Download PDFInfo
- Publication number
- CN107172009B CN107172009B CN201710221456.4A CN201710221456A CN107172009B CN 107172009 B CN107172009 B CN 107172009B CN 201710221456 A CN201710221456 A CN 201710221456A CN 107172009 B CN107172009 B CN 107172009B
- Authority
- CN
- China
- Prior art keywords
- socket
- vlan
- information
- data
- application module
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L63/00—Network architectures or network communication protocols for network security
- H04L63/02—Network architectures or network communication protocols for network security for separating internal from external traffic, e.g. firewalls
- H04L63/0272—Virtual private networks
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/56—Provisioning of proxy services
- H04L67/565—Conversion or adaptation of application format or content
- H04L67/5651—Reducing the amount or size of exchanged application data
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/16—Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
- H04L69/161—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
- H04L69/162—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/22—Parsing or analysis of headers
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer Security & Cryptography (AREA)
- Computer Hardware Design (AREA)
- Computing Systems (AREA)
- General Engineering & Computer Science (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
- Small-Scale Networks (AREA)
Abstract
The invention discloses a method for sending VLAN information to an application module through a socket, which comprises the following steps: the application module creates a socket packet, binds the socket packet to a physical interface, and receives and transmits data with an IP protocol stack; the application module sets socket options, sets the type and protocol level of control information of each socket and is used for controlling and receiving the auxiliary data information; the IP protocol stack stores VLAN information and stores the data message in a socket cache region; the application module calls a packet receiving interface function recvmsg to read data from the socket cache region; and the application module analyzes the data message information and the VLAN auxiliary information copied from the socket cache region to acquire a VLAN value. The invention enables the application module to sense the VLAN information, distinguishes and isolates the services, improves the network security, saves the network resources and enhances the user experience.
Description
Technical Field
The invention relates to a network communication technology, in particular to a method for sending VLAN information to an application module through a socket.
Background
VLAN (virtual Local Area network), a virtual Local Area network, is a communication technology that logically divides one physical LAN into a plurality of broadcast domains (a plurality of VLANs). The hosts in the VLANs can directly communicate with each other, and the VLANs cannot directly communicate with each other, so that the broadcast messages are limited in one VLAN, and the VLANs cannot directly access each other, so that the network security is improved.
The VLAN technology is utilized to package different VLAN tags for different service types, and the different VLAN tags are accessed into a carrier network of an operator through an access network, so that the operator can conveniently distribute network resources in the carrier network according to the service types, thereby helping the operator to effectively utilize the network resources and providing different service qualities for different types of services.
In a communication network, in order to enable a network device to distinguish messages of different VLANs, a field for identifying the VLAN needs to be added to the message, and the IEEE (institute of Electrical and Electronics Engineers) 802.1Q Protocol specifies that 4 bytes encapsulated after a destination MAC address and a source MAC address constitute a VLAN Tag (VLAN Tag) including 2 bytes of TPID (Tag Protocol Identifier), 3 bits of Priority, 1 bit of CFI (standard Format Indicator) and 12 bits of VLAN id. The VLAN to which the message belongs is identified by using the VLAN ID in the Ethernet protocol network equipment, and the message is processed according to whether the message carries the VLANTag and the carried VLAN ID value; particularly when the VLAN is divided on a port basis, since VLAN members are defined by device ports, one port may own a plurality of VLAN members.
In a network protocol scene enabled under a two-layer interface, an upper layer protocol module receives a signaling message of a certain service type for response, and the protocol module does not sense VLAN information, so that the response message does not contain VLAN Tag; when a two-layer signaling message is sent, an upper layer protocol module binds an interface through a socket and then directly sends the interface to a protocol stack, if a plurality of VLAN members exist in a two-layer physical interface, the IP protocol stack and a forwarding plane do not know which VLAN Tag is packaged for the signaling message at the moment, and therefore services cannot be distinguished. And the communication between the IP protocol stack and the application module adopts standard socket I/O (In/Out, input/output) interface functions recvmsg and sendmsg, most parameters are packaged into the structure struct msghdr to be transmitted and received on a socket In the form of datagram, the application module can only analyze the size of a buffer area occupied by data and the initial address of the data when analyzing the message, and the VLAN information can not be acquired from the IP protocol stack through the I/O interface recvmsg.
Disclosure of Invention
The invention aims to solve the technical problem that when an IP protocol stack and an application module carry out data communication through a standard socket I/O interface, most parameters are packaged into a structure struct msghdr, data are transmitted and received on a socket in a datagram mode, and the application module can only analyze the size of a cache region occupied by data and the initial address of the cache region when analyzing a data report, and can not acquire VLAN information from the data cache region.
In order to solve the technical problem, the technical scheme adopted by the invention is to provide a method for sending VLAN information to an application module through a socket, which comprises the following steps:
the application module creates a socket to receive and transmit data with an IP protocol stack;
the application module sets socket options, sets the type and protocol level of control information of each socket and is used for controlling and receiving the auxiliary data information;
the IP protocol stack stores VLAN information and stores the data message in a socket cache region;
the application module calls a packet receiving interface function recvmsg to read data from the socket cache region;
and the application module analyzes the data message information copied from the socket cache region, and sends an auxiliary data acquisition message to the IP protocol stack through the socket to acquire the VLAN value.
In the method, a socket option IP _ PKTINFO is set through a standard application programming interface function setsockopt, a data structure struct In _ PKTINFO is expanded to increase a VLAN _ id attribute, and VLAN information is received through a VLAN _ id field of the structure.
In the above method, the IP protocol stack stores VLAN information, and specifically includes the following steps:
step S31, the main control signaling driver receives the two-layer signaling message with VLAN mark from the forwarding plane, analyzes the physical interface of the receiving packet according to the MAC-IN-MAC head of the message, then strips the MAC-IN-MAC head, and sends the MAC-IN-MAC head to the corresponding interface IN the IP protocol stack;
step S32, after the IP protocol stack interface receives the message, stripping the VLAN information carried In the message, and storing the VLAN ID value In the message according to the VLAN _ ID member expanded In the structure struct In _ pktinfo;
step S33, the IP protocol stack searches for a socket for monitoring the data message according to the message protocol number and the socket address family, hangs the message data on a socket receiving linked list, and informs the application module that the socket has a readable event.
In the method, an application module reads data information from a socket cache region, allocates a section of memory for storing the data message information read from the socket cache region, and independently allocates a section of memory for storing VLAN (virtual local area network) accessory information;
and the member msg _ iov of the standard interface struct msghdr points to the memory head address used for storing the data message part, and the member msg _ control of the struct msghdr points to the memory head address used for storing the auxiliary information parts such as VLAN and the like.
In the method, when the application module copies data from the socket buffer area, if the memory pointed by msg _ control is not empty, a message is sent to the IP stack through a pipeline, the VLAN ID value of the data packet is copied to the memory pointed by msg _ control, and the data information in the socket linked list is copied to the memory pointed by msg _ iov.
The invention can realize the management of the VLAN information corresponding to the physical interface in the application module, the message VLAN identification is filled by the application module, at the moment, the IP protocol stack and the data forwarding plane can not add VLAN fields to the message any more, other network equipment can distinguish the VLAN which the message belongs to according to the VLAN fields carried by the sent message for processing, the application module can sense the VLAN information, distinguish and isolate the service, improve the network security, save the network resources and enhance the user experience.
Drawings
Fig. 1 is a frame diagram of a method for uploading VLAN information to an application module via a socket according to the present invention;
fig. 2 is a flowchart of a method for uploading VLAN information to an application module via a socket according to the present invention;
fig. 3 is a flowchart illustrating step S30 in the present invention.
Detailed Description
The invention is described in detail below with reference to the figures and specific examples.
The invention defines a global data structure for all application modules which need to receive the auxiliary data by using an IP protocol stack, the application modules set socket options, and the auxiliary data is acquired through the socket to receive VLAN information. As shown in fig. 1, the modules involved in the method for sending VLAN information to an application module via a socket according to the present invention are an application module and an IP protocol stack; the IP protocol stack comprises an IP protocol stack socket (L2socket), a VLAN information storage module and a master control signaling driver; the hierarchical relationship of the involved modules is as follows:
the application module is responsible for processing a protocol layer of a data packet sent by the IP protocol stack;
the IP protocol stack socket provides a uniform packet receiving and sending interface for the upper application module, is a uniform packet receiving and sending platform and carries out data communication through the socket;
the VLAN information storage module is used for setting VLAN attribute information for the data message;
the main control signaling driver is responsible for MAC-IN-MAC processing on the control plane, an MAC-IN-MAC head is packaged when the main control sends a message, and the MAC-IN-MAC head is stripped when the message is received.
As shown in fig. 2, the method for sending VLAN information to an application module via a socket according to the present invention includes the following steps:
step S10, the application module creates a socket through the function socket (the function parameter af is set as PF _ PACKET), the socket type is a PACKET type after the creation is successful, and data receiving and sending are carried out through the socket and the IP protocol stack.
Step S20, the application module sets socket options, sets the type and protocol level of each socket control information, and is used for controlling and receiving the auxiliary data information; the method specifically comprises the following steps:
the application module sets a socket option IP _ PKTINFO through a standard application programming interface function setsockopt, expands a data structure struct In _ PKTINFO to increase a VLAN _ id attribute, and receives VLAN information through a VLAN _ id field of the structure.
And step S30, the IP protocol stack stores the VLAN information and stores the data message in a socket cache region.
In the present invention, as shown in fig. 3, step S30 specifically includes the following steps:
step S31, the main control signaling driver receives the two-layer signaling message with VLAN mark from the forwarding plane, analyzes the physical interface of the receiving packet according to the MAC-IN-MAC head of the message, then strips the MAC-IN-MAC head, and sends the MAC-IN-MAC head to the corresponding interface IN the IP protocol stack;
step S32, after the IP protocol stack interface receives the message, stripping the VLAN information carried In the message, and storing the VLAN ID value In the message according to the VLAN _ ID member expanded In the structure struct In _ pktinfo;
step S33, the IP protocol stack searches for a socket for monitoring the data message according to the message protocol number and the socket address family, hangs the message data on a socket receiving chain table, and informs the application module that the socket has a readable event, although one socket characteristic value comprises the AF address family, the type and the protocol number, for the socket with the AF being the PF _ PACKET, only one socket needs to be matched according to the AF and the protocol number.
Therefore, when the application module receives the IP protocol stack to inform that the socket has the event readable, the application module can read the data on the socket receiving chain table through the socket I/O interface recvmsg, fill the data in the msg message data buffer area, and then request the attached data by sending the sig message to the IP protocol stack to obtain the VLAN information.
And step S40, the application module calls a packet receiving interface function recvmsg to read data from the socket cache region.
After step S33, the IP protocol stack has placed the data packet in the corresponding socket buffer, that is, hung on the socket linked list, and has notified the application module that there is a readable event. And after the running thread is called, the application module reads data information from the socket cache region. Usually, the application module allocates a segment of memory for storing data message information read from the socket buffer, and if it wants to obtain the auxiliary information such as VLAN, it will allocate a segment of memory independently. And the member msg _ iov of the standard interface struct msghdr points to the memory head address used for storing the data message part, and the member msg _ control of the struct msghdr points to the memory head address used for storing the auxiliary information parts such as VLAN and the like. And the IP protocol stack and the application module perform data analysis through a common structure struct msghdr.
When the application module copies data from the socket buffer area, if the memory pointed by msg _ control is not empty, a message is sent to the IP stack through a pipeline, the VLAN attribute information (the VLAN ID value stored in step S32) of the data packet is copied to the memory area pointed by msg _ control, and the data information on the socket linked list is copied to the memory area pointed by msg _ iov.
Step S50, the application module parses the data packet information copied from the socket buffer, and sends an accessory data acquiring message to the IP protocol stack through the socket to acquire a VLAN value, where the accessory information generally refers to information other than the data packet required by the application module in standard programming, such as information of an upper interface, a VLAN, and the like.
The application module analyzes the data information of the memory area pointed by the msg _ control according to the data structure struct In _ pktinfo, and then the stored VLAN information can be obtained. And storing the VLAN information and the corresponding interface in the application module in a mapping mode, so that the application module has the interface sent by the data packet and the corresponding VLAN information.
Therefore, when the application module needs to respond to the signaling message in a certain VLAN, the corresponding VLAN information can be searched according to the interface, and the VLAN Tag is packaged for the message.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.
Claims (5)
1. The method for uploading the VLAN information to the application module through the socket is characterized by comprising the following steps:
the application module creates a socket to receive and transmit data with an IP protocol stack;
the application module sets socket options, sets the type and protocol level of control information of each socket and is used for controlling and receiving the auxiliary data information;
the IP protocol stack stores VLAN information and stores the data message in a socket cache region;
the application module calls a packet receiving interface function recvmsg to read data from the socket cache region;
and the application module analyzes the data message information copied from the socket cache region, and sends an auxiliary data acquisition message to the IP protocol stack through the socket to acquire the VLAN value.
2. The method of claim 1, wherein the socket option IP _ PKTINFO is set through a standard application programming interface function setsockopt, and the VLAN _ id attribute is added by extending a data structure struct In _ PKTINFO, and the VLAN information is received through a VLAN _ id field In the data structure struct In _ PKTINFO.
3. The method of claim 2, wherein the IP protocol stack stores VLAN information, comprising the steps of:
step S31, the main control signaling driver receives the two-layer signaling message with VLAN mark from the forwarding plane, analyzes the physical interface of the receiving packet according to the MAC-IN-MAC head of the message, then strips the MAC-IN-MAC head, and sends the MAC-IN-MAC head to the corresponding interface IN the IP protocol stack;
step S32, after the IP protocol stack interface receives the message, stripping the VLAN information carried In the message, and storing the VLAN ID value In the message according to the VLAN _ ID member expanded In the structure struct In _ pktinfo;
step S33, the IP protocol stack searches for a socket for monitoring the data message according to the message protocol number and the socket address family, hangs the message data on a socket receiving linked list, and informs the application module that the socket has a readable event.
4. The method of claim 3, wherein the application module reads data information from the socket buffer, allocates a segment of memory for storing the data information read from the socket buffer, and independently allocates a segment of memory for storing VLAN attachment information;
and the member msg _ iov of the standard interface struct msghdr points to the memory head address used for storing the data message part, and the member msg _ control of the struct msghdr points to the memory head address used for storing the VLAN auxiliary information part.
5. The method as claimed in claim 4, wherein when the application module copies data from the socket buffer, if the memory pointed to by msg _ control is not empty, then sending a message to the IP stack through a pipe, copying the VLAN ID value of the packet in the socket buffer to the memory pointed to by msg _ control, and copying the data information in the socket linked list to the memory pointed to by msg _ iov.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710221456.4A CN107172009B (en) | 2017-04-06 | 2017-04-06 | Method for uploading VLAN information to application module through socket |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710221456.4A CN107172009B (en) | 2017-04-06 | 2017-04-06 | Method for uploading VLAN information to application module through socket |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107172009A CN107172009A (en) | 2017-09-15 |
CN107172009B true CN107172009B (en) | 2020-01-07 |
Family
ID=59848933
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710221456.4A Active CN107172009B (en) | 2017-04-06 | 2017-04-06 | Method for uploading VLAN information to application module through socket |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107172009B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108712459B (en) * | 2018-03-30 | 2021-06-15 | 深圳市风云实业有限公司 | Protocol message cross-layer communication method and device and electronic equipment |
CN108650295A (en) * | 2018-03-30 | 2018-10-12 | 深圳市风云实业有限公司 | Protocol massages cross-layer communication method device and electronic equipment |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1512718A (en) * | 2002-12-26 | 2004-07-14 | 成都卫士通信息产业股份有限公司 | Realizing VLAN technology on Ethernet via network card drive |
CN101184038A (en) * | 2007-11-05 | 2008-05-21 | 中国网络通信集团公司 | Subscriber terminal and information receiving and transmitting method |
CN105282034A (en) * | 2015-09-11 | 2016-01-27 | 烽火通信科技股份有限公司 | ARP/NDP learning system and learning method |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7636323B2 (en) * | 2005-06-14 | 2009-12-22 | Broadcom Corporation | Method and system for handling connection setup in a network |
-
2017
- 2017-04-06 CN CN201710221456.4A patent/CN107172009B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1512718A (en) * | 2002-12-26 | 2004-07-14 | 成都卫士通信息产业股份有限公司 | Realizing VLAN technology on Ethernet via network card drive |
CN101184038A (en) * | 2007-11-05 | 2008-05-21 | 中国网络通信集团公司 | Subscriber terminal and information receiving and transmitting method |
CN105282034A (en) * | 2015-09-11 | 2016-01-27 | 烽火通信科技股份有限公司 | ARP/NDP learning system and learning method |
Also Published As
Publication number | Publication date |
---|---|
CN107172009A (en) | 2017-09-15 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112422393B (en) | Method for transmitting message of extensible virtual local area network, computer equipment and readable medium | |
US10063470B2 (en) | Data center network system based on software-defined network and packet forwarding method, address resolution method, routing controller thereof | |
KR102429560B1 (en) | Network slice control method and apparatus and computer-readable storage medium | |
CN107733670B (en) | Forwarding strategy configuration method and device | |
CN105871721B (en) | Segment routing processing method, processing device and sending device | |
CN107733799B (en) | Message transmission method and device | |
US20160261496A1 (en) | Packet forwarding in data center network | |
US8094567B2 (en) | Method for transferring test messages and network element device | |
US10193707B2 (en) | Packet transmission method and apparatus | |
CN101160850B (en) | Method and device for forwarding packet | |
CN105591971B (en) | A kind of implementation method and device of QoS | |
US20120307828A1 (en) | Method and System of Frame Forwarding with Link Aggregation in Distributed Ethernet Bridges | |
EP2086178A1 (en) | Link aggregation method, device, mac frame receiving/sending method and system | |
WO2021004536A1 (en) | Method and apparatus for parsing messages | |
CN103763121A (en) | Method and device for quickly issuing network configuration information | |
US20210392084A1 (en) | Transmission Of Packets Over A TSN Aware Network | |
CN110062060B (en) | System and method for IP address allocation | |
US11777830B2 (en) | Virtual machine status probe method, and device | |
CN105207909B (en) | A kind of method and network equipment sending information | |
CN107172009B (en) | Method for uploading VLAN information to application module through socket | |
CN113746658A (en) | Method, device and system for determining network slice topology | |
CN102857400B (en) | The method for building up of broadcast domain and device in a kind of Layer 2 virtual private network | |
CN113543234A (en) | Port resource reservation method, electronic device and storage medium | |
CN106850268B (en) | device and method for realizing linear protection switching | |
CN111404797B (en) | Control method, SDN controller, SDN access point, SDN gateway and CE |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |