CN102223289B - Method and device for storing IPv4 (the Fourth Internet Protocol Version) address and IPv6 (the Sixth Internet Protocol Version) address - Google Patents

Method and device for storing IPv4 (the Fourth Internet Protocol Version) address and IPv6 (the Sixth Internet Protocol Version) address Download PDF

Info

Publication number
CN102223289B
CN102223289B CN201010149629.4A CN201010149629A CN102223289B CN 102223289 B CN102223289 B CN 102223289B CN 201010149629 A CN201010149629 A CN 201010149629A CN 102223289 B CN102223289 B CN 102223289B
Authority
CN
China
Prior art keywords
address
prefix
field
inquire
ipv6
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.)
Expired - Fee Related
Application number
CN201010149629.4A
Other languages
Chinese (zh)
Other versions
CN102223289A (en
Inventor
钟果
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
New H3C Technologies Co Ltd
Original Assignee
Hangzhou H3C Technologies Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Hangzhou H3C Technologies Co Ltd filed Critical Hangzhou H3C Technologies Co Ltd
Priority to CN201010149629.4A priority Critical patent/CN102223289B/en
Publication of CN102223289A publication Critical patent/CN102223289A/en
Application granted granted Critical
Publication of CN102223289B publication Critical patent/CN102223289B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The invention provides a method and device for storing an IPv4 (the Fourth Internet Protocol Version) address and an IPv6 (the Sixth Internet Protocol Version) address. An IP (Internet Protocol) address is stored in a storage space including a prefix field and a postfix field. Specific IP address types in a storage instruction are distinguished, that is to say, for the IPv4 address, after being converted into integer data, the IPv4 address is stored in the postfix field, the prefix field is idle; for the IPv6 address, the IPv6 address is divided into a high-level storage address and a low-level storage address, information of the high-level storage address is stored in the prefix field; and, after being converted into integer data, the low-level storage address is stored in the postfix field. By means of the invention, the efficiency for storing and inquiring the addresses can be improved, and the system accuracy is improved.

Description

The method and apparatus of a kind of storing IP v4 address and IPv6 address
Technical field
The present invention relates to network communications technology field, particularly the method and apparatus of a kind of storing IP v4 address and IPv6 address.
Background technology
IPv6 is the IP next generation protocol for alternative existing IPv4 of Internet Engineering task groups (IETF) design, has solved the problem of IPv4 address exhaustion.Because the application of IPv6 is an asymptotic process in proper order, in for a long time, IPv4 network and IPv6 network can exist simultaneously, and under many circumstances, the network equipment need to be supported IPv4 and the two stacks of IPv6, in network, also can have IPv4 address and IPv6 address simultaneously.
The storage mode of IPv4 and IPv6 address, directly has influence on fusion and the search efficiency of IPv4 address and IPv6 address, especially to storing the search efficiency of the business of magnanimity IP address.IPv4 address is by 32 bit-identifies, and, by 128 bit-identifies, due to the difference of length, store IPv4 address and IPv6 address respectively in the prior art IPv6 address according to storage mode separately.IPv4 address is stored as to an integer, for IPv6 address, has following two kinds of storage modes: one, IPv6 address is stored as to character string; Two, IPv6 address is carried out after the processing of digest algorithm, calculate an integer and identify this IPv6 address, the integer that this is calculated is stored.
In above-mentioned two kinds of methods, IPv4 address and IPv6 address adopt respectively storage mode separately, cause IPv4 address and IPv6 address to inquire about respectively, while storing in magnanimity address, have a strong impact on efficiency, and have increased development amount.
Summary of the invention
In view of this, the invention provides the method and apparatus of a kind of storing IP v4 address and IPv6 address, so that improve the efficiency of address storage and inquiry, improve system accuracy.
A method for storing IP v4 address and IPv6 address, the method comprises:
A, while receiving the storage instruction that comprises IP address, in specified data storehouse, comprise the memory space of prefix field and suffix field, and judge the type of described IP address, if IPv4 address performs step B; If IPv6 address performs step C;
B, be stored in described suffix field after described IPv4 address transition is become to integer data, described prefix field is put to sky, finish current Stored Procedure;
C, described IPv6 address is divided into high address part and LAP Lower Address Part, the information of high address part is stored in described prefix field, after converting LAP Lower Address Part to integer data, be stored in described suffix field, finish current Stored Procedure.
A device for storing IP v4 address and IPv6 address, this device comprises: command reception unit, space determining unit, first kind judging unit, IPv4 address storaging unit and IPv6 address storaging unit;
Described command reception unit, for receiving the storage instruction that comprises IP address;
Described space determining unit, for receiving after the storage instruction that comprises IP address in described command reception unit, comprises the memory space of prefix field and suffix field in specified data storehouse;
Described first kind judging unit, for judging the type of described IP address, if IPv4 address sends to described IPv4 address storaging unit by this IPv4 address; If IPv6 address sends to described IPv6 address storaging unit by this IPv6 address;
Described IPv4 address storaging unit is stored in described suffix field after described IPv4 address transition is become to integer data, and described prefix field is put to sky;
Described IPv6 address storaging unit, for described IPv6 address is divided into high address part and LAP Lower Address Part, the information of high address part is stored in described prefix field, is stored in described suffix field after LAP Lower Address Part is converted to integer data.
As can be seen from the above technical solutions, IP address is stored in to the memory space that comprises prefix field and suffix field, and concrete IP address class type in storage instruction is distinguished, for IPv4 address, after being converted to integer data, be stored in suffix field, prefix field is put sky; For IPv6 address, IPv6 address is divided into higher memory address and lower memory address, the information of higher memory address is stored in prefix field, by lower memory address transition, be to be stored in suffix field after integer data.This storage mode has been realized the unified storage of IPv4 address and IPv6 address in database, for the unified query of IPv4 address and IPv6 address, provides convenience, and has improved storage and search efficiency.In addition, the IPv4 storage system that this storage mode can be compatible current, only need can not cause the IPv4 address of having stored to lose using original IPv4 address memory space as suffix field, realizes IPv4 storage system seamless transitions to IPv6 storage system.
Accompanying drawing explanation
Fig. 1 is main method flow chart provided by the invention;
The IP address Stored Procedure figure that Fig. 2 provides for embodiment mono-;
The single ip address querying flow figure that Fig. 3 provides for embodiment mono-;
The IP address range querying flow figure that Fig. 4 provides for embodiment mono-;
Fig. 5 is the query context schematic diagram of step 405 correspondence in embodiment mono-;
Fig. 6 is the query context schematic diagram of step 406 correspondence in embodiment mono-;
Fig. 7 and Fig. 8 are the query context schematic diagram that in embodiment mono-, step 407-1 is corresponding;
Fig. 9 and Figure 10 are the query context schematic diagram that in embodiment mono-, step 407-3 is corresponding;
The IP address Stored Procedure figure that Figure 11 provides for embodiment bis-;
The single ip address querying flow figure that Figure 12 provides for embodiment bis-;
The IP address range querying flow figure that Figure 13 provides for embodiment bis-;
Figure 14 is structure drawing of device provided by the invention;
Figure 15 is another kind of structure drawing of device provided by the invention.
Embodiment
In order to make the object, technical solutions and advantages of the present invention clearer, below in conjunction with the drawings and specific embodiments, describe the present invention.
Method provided by the invention as shown in Figure 1, can mainly comprise the following steps:
Step 101: while receiving the storage instruction that comprises IP address, comprise the memory space of prefix field and suffix field in specified data storehouse, and judge the type of this IP address; If IPv4 address performs step 102; If IPv6 address performs step 103.
Step 102: be to be stored in suffix field after integer data by this IPv4 address transition, prefix field is put to sky, finish current Stored Procedure.
Step 103: this IPv6 address is divided into high address part and LAP Lower Address Part, the information of high address part is stored in prefix field, be stored in suffix field after LAP Lower Address Part is converted to integer data, finish current Stored Procedure.
Wherein, the information of high address part can be that the high address part of IPv6 address is converted to after integer data, after soon the high address part of IPv6 is converted to integer data, is stored in prefix field.Or, the information of high address part can be also the side-play amount ID mating with the address prefix of IPv6 address in offset-lists, be about to after the data mode of IPv6 address transition for setting, search in offset-lists, the side-play amount ID that high address part is corresponding, is stored in this side-play amount ID in prefix field.By two specific embodiments, both of these case is described in detail respectively below.
Embodiment mono-:
In database, conventionally support the integer data of 64, existing IPv4 address is generally stored in the low 32 of 64 memory spaces in database.In the present embodiment, for the situation of storage is merged in IPv4 address and IPv6 address, can be on the basis of existing 64 memory spaces, 64 of extra increases, with existing 64 common memory spaces that form an IP address, this memory space comprises two fields: the prefix field of 64 and 64 s' suffix field.Prefix field adopts ip_prefix field to represent in the present embodiment, and suffix field adopts ip field to represent.
The IP address Stored Procedure figure that Fig. 2 provides for embodiment mono-, as shown in Figure 2, this flow process can comprise the following steps:
Step 201: while receiving the storage instruction that comprises IP address, determine a memory space that comprises ip_prefix field and ip field in database.
Step 202: the type that judges this IP address; If IPv4 address performs step 203; If IPv6 address performs step 204.
Step 203: be to be stored in the low 32 of ip field after integer data by this IPv4 address transition, ip_prefix field is put to sky, finish current Stored Procedure.
Step 204: this IPv6 address is divided into high 64 memory addresss and low 64 memory addresss, after being converted to integer data, high 64 memory addresss are stored in ip_prefix field, after converting low 64 memory addresss to integer data, be stored in ip field, finish current Stored Procedure.
For the IP address storage mode shown in Fig. 2, corresponding IP address lookup process can be divided into following two kinds of situations:
The first situation: inquiry single ip address, now corresponding querying flow can as shown in Figure 3, comprise the following steps:
Step 301: receive after the query statement that comprises single ip address, judge the type of this IP address, if IPv4 address performs step 302; If IPv6 address performs step 303.
Step 302: after IPv4 address transition is integer data, arranging the querying condition of database is that ip_prefix field is sky and the data of ip field for obtaining after changing, and obtains the Query Result that database returns, and finishes current querying flow.
For IPv4 address, because it has only taken low 32 in ip field, therefore, when to data lab setting querying condition, need to inquire about ip_prefix field is sky and the data of ip field for obtaining after changing, and after database root is inquired about according to this querying condition, can return to Query Result.For example, information such as user name, subscriber phone, station address corresponding to this IPv4 address in meeting return data storehouse.
Step 303: be converted to respectively integer data after this IPv6 address is divided into high 64 and low 64, obtain high 64 inquire addresses and low 64 inquire addresses, arranging the querying condition of database is that ip_prefx field is that these high 64 inquire addresses and ip field are low 64 inquire addresses, obtain the Query Result that database returns, finish current querying flow.
For IPv6 address, during due to storage, according to high 64 and low 64 divisions, therefore, when inquiry, also need to carry out respectively for high 64 and low 64.
The second situation: inquiry IP address range, now corresponding querying flow can as shown in Figure 4, comprise the following steps:
Step 401: receive after the query statement that comprises IP address range, judge the type of this IP address range, if IPv4 address realm performs step 402; If IPv6 address realm performs step 403.
Step 402: the initial end value of this IPv4 address realm and end end value are converted to after integer data, arranging the querying condition of database is that ip_prefix field is for empty, and ip field is greater than the initial end value after conversion and is less than the end end value after conversion, obtain the Query Result that database returns, finish current querying flow.
Suppose that the initial end value after this IPv4 address transition is ipv4_start, end end value after changing is ipv4_end, and the querying condition arranging can be expressed as: ip_prefix field=null and (ipv4_start <=ip field <=ipv4_end).
Step 403: the initial end value of IPv6 address realm and end end value are divided into respectively after high 64 and low 64, be converted to respectively again high 64 inquire addresses and low 64 inquire addresses that integer data obtain initial end value, and high 64 inquire addresses and low 64 inquire addresses that finish end value, continue execution step 404.
Step 404: judge that whether high 64 inquire addresses of initial end value are identical with high 64 inquire addresses of end end value, if identical, execution step 405; Otherwise, execution step 408.
Step 405: whether the sign bit that judges low 64 inquire addresses of initial end value and low 64 inquire addresses of end end value is identical, if identical, execution step 406; If not identical, execution step 407.
Because the highest order of memory space of every 64 in database is sign bit, for compatible with this characteristic of database, need to specifically distinguish this initial end value and this sign bit that finishes end value.
Step 406: arranging the querying condition of database is that ip_prefix field is high 64 inquire addresses of initial end value, and ip field is more than or equal to low 64 inquire addresses of initial end value after conversion and is less than or equal to low 64 inquire addresses of end end value after conversion, obtain the Query Result that database returns, finish current querying flow.
Because the highest order of 64 in database is sign bit, sign bit is within 0 o'clock, to be positive number, and sign bit is within 1 o'clock, to be negative.Wherein, sign bit is that 0 o'clock corresponding integer range is 0 to 7FFFFFFFFFFFFFFF, and sign bit is that 1 o'clock corresponding integer range is 8000000000000000 to FFFFFFFFFFFFFFFF.If query context is at a sign bit section, low 64 inquire addresses that are initial end value are identical with low 64 the inquire address sign bits that finish end value, at a sign bit section, as shown in Figure 5, to the querying condition of database at low 64 inquire addresses of this initial end value with finish between low 64 inquire addresses of end value.For example, when low 64 inquire address scopes are 2 to 5, the querying condition of setting is 2 <=ip field <=5, as shown in (a) in Fig. 5; When low 64 inquire address scopes are-2 to-5, the querying condition of setting is-5 <=ip field <=-2, as shown in (b) in Fig. 5.
In this step, high 64 startIP_prefix if of initial end value, low 64 is startIP_postfix, finish end value high 64 identical with initial end value, low 64 is endIP_postfix, the querying condition arranging is: ip_prefix field=startIP_prefix, and (startIP_postfix <=ip field <=endIP_postfix).
Step 407: arranging the querying condition of database is that ip_prefix field is high 64 inquire addresses of initial end value, and ip field is more than or equal to low 64 inquire addresses of initial end value after conversion or is less than or equal to low 64 inquire addresses of end end value after conversion, obtain the Query Result that database returns, finish current querying flow.
If query context is crossed over two sign bit sections, low 64 inquire addresses that are initial end value are different with low 64 the inquire address sign bits that finish end value, not at a sign bit section, as shown in Figure 6, to the querying condition of database, should comprise and be greater than low 64 inquire addresses of this initial end value and be less than the two kinds of situations of low 64 inquire addresses that finish end value.For example, when low 64 inquire address scopes are 2 to FFFFFFFFFFFFFFFE ,-2 to 2 o'clock, the querying condition of setting was ip field >=2or ip field <=-2.
Equally, in this step, if high 64 of initial end value is startIP_prefix, low 64 is startIP_postfix, finish end value high 64 identical with initial end value, low 64 is endIP_postfix, and startIP_postfix is different from the sign bit of endIP_postfix, the querying condition of this step setting is: ip_prefix field=startIP_prefix, and (ip field >=startIP_postfixor ip field <=endIP_postfx).
Step 408: perform step in any order or simultaneously 408-1,408-2 and 408-3.
If high 64 inquire addresses of high 64 inquire addresses of initial end value and end end value are not identical, query context can be divided into three sections: high 64 inquire addresses that situation, prefix field ip_prefx during high 64 inquire addresses that prefix field ip_prefix is initial end value is initial end value and finish situation between high 64 inquire addresses of end value, prefix field ip_prefix for finishing the situation of high 64 inquire addresses of end value, respectively corresponding step 408-1,408-2 and 408-3.
Step 408-1: if the sign bit of low 64 inquire addresses of initial end value is 0, the querying condition that database is set is: high 64 inquire addresses that ip_prefix is initial end value, and ip field is more than or equal to low 64 inquire addresses of initial end value or is less than or equal to-1; If the sign bit of low 64 inquire addresses of initial end value is 1, the querying condition that database is set is: high 64 inquire addresses that ip_prefix is initial end value, and ip field is more than or equal to low 64 inquire addresses of initial end value and is less than or equal to-1; Obtain the Query Result that database returns.
In this step, when the sign bit of low 64 inquire addresses of initial end value is 0, low 64 inquire addresses that this initial end value is described are positive numbers, situation during low 64 inquire addresses that are initial end value for ip_prefix as shown in Figure 7, comprise two parts: ip field is more than or equal to low 64 the inquire address startIP_postfix of initial end value, and the whole part that ip field is negative is that ip field is less than or equal to-1.The querying condition arranging is: ip_prefix field=startIP_prefix and (ip field >=startIP_postfix or ip field <=-1)
When the sign bit of low 64 inquire addresses of initial end value is 1, low 64 inquire addresses that this initial end value is described are negatives, situation during low 64 inquire addresses that are initial end value for ip_prefix as shown in Figure 8, should be set to: ip_prefix field=startIP_prefix and (ip field >=startIP_postfix and ip field <=-1).
Step 408-2: if high 64 inquire addresses of initial end value are identical with high 64 the inquire address sign bits that finish end value, the querying condition that database is set is: prefix field ip_prefix field is greater than high 64 inquire addresses of initial end value and is less than high 64 inquire addresses that finish end value; If high 64 inquire addresses of initial end value are not identical with high 64 the inquire address sign bits that finish end value, the querying condition that database is set is: prefix field ip_prefix field is greater than high 64 inquire addresses of initial end value or is less than high 64 inquire addresses that finish end value; Obtain the Query Result that database returns.
In this step, if high 64 inquire addresses of initial end value are identical with high 64 the inquire address sign bits that finish end value, explanation is all positive number or is all negative, and the querying condition arranging can be expressed as: ip_prefix field > startIP_prefix and ip_prefix field < endIP_prefix.If high 64 inquire addresses of initial end value are different from high 64 the inquire address sign bits that finish end value, high 64 inquire addresses that initial end value is described are that positive number and high 64 inquire addresses that finish end value are negative, the querying condition arranging can be expressed as: ip_prefix field > startIP_prefix or ip_prefix field < endIP_prefx, obtains the Query Result that database returns.
Step 408-3: be 0 if finish the sign bit of low 64 inquire addresses of end value, the querying condition that database is set is: ip_prefix is for finishing high 64 inquire addresses of end value, and ip field is more than or equal to 0 and be less than or equal to and finish low 64 inquire addresses of end value; If finishing the sign bit of low 64 inquire addresses of end value is 1, the querying condition that database is set is: ip_prefix is for finishing high 64 inquire addresses of end value, and ip field is more than or equal to 0 or be less than or equal to and finish low 64 inquire addresses of end value; Obtain the Query Result that database returns.
In this step, when finishing the sign bit of low 64 inquire addresses of end value and be 0, illustrate that these low 64 inquire addresses that finish end value are positive numbers, situation during low 64 inquire addresses that are end end value for ip_prefix as shown in Figure 9, should be set to: ip_prefix field=endIP_prefix and (ip field >=0and ip field <=ip_postfix).
When finishing the sign bit of low 64 inquire addresses of end value and be 1, illustrate that these low 64 inquire addresses that finish end value are negatives, situation during low 64 inquire addresses that are end end value for ip_prefx as shown in figure 10, comprise two parts: ip field is more than or equal to 0, and ip field is less than or equal to low 64 the inquire address startIP_postfix of end end value.The querying condition arranging is: ip_prefix field=endIP_prefix and (ip field >=0 or ip field <=endIP_postfix).
The Query Result that the database that step 409: integration step 408-1,408-2 and step 408-3 obtain returns, as Query Result corresponding to the query statement receiving, finishes current querying flow.
Embodiment bis-:
In this embodiment, can first configure an offset-lists, in this offset-lists, each list item comprises 3 field: side-play amount ID, address prefix and prefix length L.This offset-lists can be configured in the storage system of IPv6 address, also can be configured in the storage system of IPv4 address, or configure in other management system, at this, the setting position of offset-lists is not specifically limited.In the memory space of an address, can be on the basis of original ip field, extra increase a prefix field, for the address prefix of storing IP address, at side-play amount ID corresponding to offset-lists, this extra prefix field increasing can be designated ip_offset_id field.
The IP address Stored Procedure figure that Figure 11 provides for embodiment bis-, as shown in figure 11, this flow process can comprise the following steps:
Step 1101: while receiving the storage instruction that comprises IP address, determine a memory space that comprises ip_offset_id field and ip field in database.
Step 1102: the type that judges this IP address; If IPv4 address performs step 1103; If IPv6 address performs step 1104.
Step 1103: be to be stored in the low 32 of ip field after integer data by this IPv4 address transition, ip_offset_id field is set to sky, finishes current Stored Procedure.
Step 1104: after IPv6 address transition is character string, from a high position for character string, start to mate with the list item offset-lists, obtain deflected length L and side-play amount ID in the list item of coupling, this side-play amount ID is stored in ip_offset_id field, is stored in ip field after the low 128-L position of character string after conversion is converted to integer data.
The offset-lists relating in the present invention sets in advance, when mating, be actually the character string obtaining after IPv6 conversion is started to mate with the address prefix of each list item offset-lists from a high position, if match list item, the side-play amount ID of this list item is stored in ip_offset_id field.If coupling, less than list item, can create new list item, the prefix length of this list item adopts the L value of acquiescence, the high L position of this character string is stored in the address prefix field of this list item, and sequentially increases side-play amount ID according to the side-play amount ID setting.
Because the maximum integer form in database is 64 positive numbers, but comprise a bit sign position, therefore, in order to simplify the processing that residue 128-L position is stored in to the data in ip field, need to guarantee that residue 128-L position is at least in 63, that is to say, need to guarantee in offset-lists that prefix length L is at least more than 65.For example, the prefix length L that can configure in offset-lists is 80, and in this list item, in address prefix field, the length of address prefix is 80, is stored in ip field after 48 character strings of residue are converted to integer data.Now, the prefix length of acquiescence also can be 80.
It should be noted that, the address prefix configuring in offset-lists does not allow overlapping even repetition, for example, when being configured certain address prefix of 80 in offset-lists, front 72 contents as certain list item of this address prefix in offset-lists, have been configured again, in matching addresses process, can make mistakes, therefore this situation is unallowed.
In addition, it should be noted that, is that the form that to take IPv6 address transition be character string is example in this embodiment, the data mode that can be also other setting by IPv6 address transition.
For the IP address storage mode shown in Figure 11, corresponding IP address lookup process can be divided into following two kinds of situations equally:
The first situation: inquiry single ip address, now corresponding querying flow can as shown in figure 12, comprise the following steps:
Step 1201: receive after the query statement that comprises single ip address, judge the type of this IP address, if IPv4 address performs step 1202; If IPv6 address performs step 1203.
Step 1202: after this IPv4 address transition is integer data, arranges and to the querying condition of database be: ip_offset_id field is for empty, and the data that obtain after for conversion of ip field, obtain the Query Result that database returns, and finishes current querying flow.
Step 1203: after this IPv6 address transition is character string, search the list item with this string matching in offset-lists, if find the list item of coupling, perform step 1204; Otherwise finish current querying flow.
In this step, after IPv6 address transition is character string, from a high position for this character string, mate with the address prefix in each list item in offset-lists.
Step 1204: obtain side-play amount ID and prefix length L in the list item finding, after being converted to integer data, the low 128-L position of character string obtains ip_postfix, arrange and to the querying condition of database be: ip_offset_id field is that side-play amount ID and the ip field obtained are ip_postfix, obtain the Query Result that database returns, finish current querying flow.
The second situation: inquiry IP address range, now corresponding querying flow can as shown in figure 13, comprise the following steps:
Step 1301: receive after the query statement that comprises IP address range, judge the type of this IP address range, if IPv4 address realm performs step 1302; If IPv6 address realm performs step 1303.
Step 1302: the initial end value of this IPv4 address realm and end end value are converted to after integer data, arranging the querying condition of database is that ip_offset_id field is for empty, and ip field is greater than the initial end value after conversion and is less than the end end value after conversion, obtain the Query Result that database returns, finish current querying flow.
Suppose that the initial end value after this IPv4 address transition is ipv4_start, end end value after changing is ipv4_end, and the querying condition arranging can be expressed as: ip_offset_id field=null andipv4_start <=ip field <=ipv4_end.
Step 1303: the initial end value of this IPv6 address realm is converted to after the data type identical with address prefix in offset-lists with end end value, in offset-lists, mate respectively, if there is respectively the list item mating with initial end value and the list item mating with end end value, perform step 1304; Otherwise finish current querying flow.
Step 1304: obtain the list item mating with initial end value and side-play amount ID and prefix length in the list item mating with end end value, wherein, the side-play amount ID that initial end value and end end value match is respectively start_id and end_id, prefix length is respectively start_L and end_L, and obtains respectively startIp_postfix and endIp_postfix after respectively the 128-end_L position of the low 128-start_L position of initial end value and end end value being converted to integer data.
Step 1305: whether judge side-play amount ID that initial end value is corresponding and finish the side-play amount ID that end value is corresponding identical, whether start_id and end_id be identical, if identical, execution step 1306; If not identical, execution step 1307.
Step 1306: arranging the querying condition of database is that ip_offset_id field is start_id, and ip field is more than or equal to startIp_postfix and is less than or equal to endIp_postfix, be ip_offset_id field=start_id and (startIp_postfix <=ip field <=endIp_postfix), obtain the Query Result that database returns, finish current querying flow.
Step 1307: perform step in any order or simultaneously 1307-1,1307-2 and 1307-3.
If start_id and end_id are not identical, query context can be divided into three sections equally: the situation that the situation of the side-play amount ID of the part correspondence between the situation that side-play amount ID is start_id, startIP prefix and endIP prefix, side-play amount ID are end_id, respectively corresponding step 1307-1,1307-2 and 1307-3.
Step 1307-1: the querying condition that database is set is: ip_offset_id field is that start_id and ip field are more than or equal to startIp_postfix, be ip_offset_id field=start_id and ip field >=startIp_postfix, obtain the Query Result that database returns.
Step 1307-2: each data between the data in determining step 1303 after initial end value and the conversion of end end value, search in offset-lists and each side-play amount ID of each Data Matching of determining, if find side-play amount ID, the querying condition that database is set is: prefix field is the logic OR between each side-play amount ID finding, and obtains the Query Result that database returns; If search less than side-play amount ID, finish current querying flow.
Initial end value and finish end value and be converted to after character string in step 1303, determines the character string that initial end value is corresponding and finishes all character strings between character string that end value is corresponding, searches the side-play amount ID of these string matchings in offset-lists, is assumed to be ID k, ID k+1..., IDm, the querying condition that database is set is: prefix field is ID kor ID k+1or...or IDm.
If searched less than corresponding side-play amount ID, no record in database of descriptions, process ends.
Step 1307-3: the querying condition that database is set is: ip_offset_id field is that end_id and ip field are more than or equal to endIp_postfix, be ip_offset_id field=end_id and ip field <=endIp_postfix, obtain the Query Result that database returns.
The Query Result that step 1308: integration step 1307-1,1307-2 and 1307-3 obtain, as Query Result corresponding to the query statement receiving, finishes current querying flow.
Be more than the detailed description that method provided by the present invention is carried out, below device provided by the invention be described in detail.Figure 14 is structure drawing of device provided by the invention, and as shown in figure 14, this device can comprise: command reception unit 1400, space determining unit 1401, first kind judging unit 1402, IPv4 address storaging unit 1403 and IPv6 address storaging unit 1404.
Command reception unit 1400, for receiving the storage instruction that comprises IP address.
Space determining unit 1401, for receiving after the storage instruction that comprises IP address in command reception unit 1400, comprises the memory space of prefix field and suffix field in specified data storehouse.
First kind judging unit 1402, for judging the type of IP address, if IPv4 address sends to IPv4 address storaging unit 1403 by this IPv4 address; If IPv6 address sends to IPv6 address storaging unit 1404 by this IPv6 address.
IPv4 address storaging unit 1403 is stored in suffix field after IPv4 address transition is become to integer data, and prefix field is put to sky.
IPv6 address storaging unit 1404, for IPv6 address is divided into high address part and LAP Lower Address Part, is stored in the information of high address part in prefix field, is stored in suffix field after LAP Lower Address Part is converted to integer data.
Wherein, according to the difference of IPv6 address storaging unit 1404, realize, this device can adopt following two kinds of different structures:
The first, as shown in figure 14, IPv6 address storaging unit 1404 can specifically comprise: subelement 14041, the first address storing sub-units 14042 and the second address storing sub-units 14043 are divided in address;
Subelement 14041 is divided in address, high 64 and low 64 for IPv6 address is divided into, and sends to the first address storing sub-units 14042 by high 64, by low 64, sends to the second address storing sub-units 14043.
The first address storing sub-units 14042 is stored in prefix field after converting integer data to by high 64.
The second address storing sub-units 14043 is stored in suffix field after converting integer data to by low 64.
In this kind of situation, this device can also be realized the inquiry of single ip address, and now, this device can comprise: Second Type judging unit 1405, the first address lookup unit 1406 and the second address lookup unit 1407.
Command reception unit 1400, can also be for receiving the query statement that comprises single IP inquire address.
At this, 1400 pairs of the command reception unit query statement receiving possesses recognition function, can identify inquiry single ip address or inquiry IP address range, if only comprise single IP inquire address in this query statement, illustrate that this query statement is for inquiring about single ip address; If comprise IP inquire address scope (comprise initial inquiry end value and finish inquiry end value) in this query statement, illustrate that this query statement is for inquiring about IP address range.This partial content is prior art, and in this not go into detail.
Second Type judging unit 1405, for judging the type of IP inquire address, if IPv4 inquire address sends to the first address lookup unit 1406 by this IPv4 inquire address; If IPv6 inquire address sends to the second address lookup unit 1407 by this IPv6 inquire address.
The first address lookup unit 1406, for IPv4 inquire address is converted to after integer data, arrange and to the querying condition of database be: prefix field is that sky and suffix field are the data that obtain after the conversion of IPv4 inquire address, obtains the Query Result that database returns.
The second address lookup unit 1407, after IPv6 inquire address being divided into high 64 and low 64, be converted to respectively integer data, obtain high 64 inquire addresses and low 64 inquire addresses, arrange and to the querying condition of database be: prefix field is that high 64 inquire addresses and suffix field are low 64 inquire addresses, obtains the Query Result that database returns.
For the inquiry of IP address range, this device can also comprise: the 4th type judging unit 1408, the 5th address lookup unit 1409, the first address processing unit 1410, the first comparing unit 1411, the second comparing unit 1412, the 6th address lookup unit 1413, the 7th address lookup unit 1414 and the 8th address lookup unit 1415.
Command reception unit 1400, can also be for receiving the query statement that comprises IP inquire address scope.
The 4th type judging unit 1408, for judging the type of IP inquire address scope, if IPv4 inquire address scope sends to the 5th address lookup unit 1409 by this IPv4 inquire address scope; If IPv6 address lookup address realm sends to the first address processing unit 1410 by this IPv6 inquire address scope.
The 5th address lookup unit 1409, for the initial end value of IPv4 inquire address scope is obtained respectively to ipv4_start and ipv4_end with finishing after end value is converted to integer data, arrange and to the querying condition of database be: prefix field is for empty, and ipv4_start <=suffix field <=ipv4_end, obtains the Query Result that database returns.
The first address processing unit 1410, for by the initial end value ipv6_start of IPv6 inquire address scope with finish end value ipv6_end and be divided into respectively high 64 and low 64, be converted to again high 64 the inquire address startIP_prefix and low 64 the inquire address startIP_postfx that obtain respectively ipv6_start after integer data, and high 64 inquire address endIP_prefix of ipv6_end and low 64 inquire address endIP_postfix.
The first comparing unit 1411, for judging that whether startIP_prefix and endIP_prefix be identical.
The second comparing unit 1412, for when judgment result is that of the first comparing unit 1411 is, judges that whether the sign bit of startIP_postfix and endIP_postfix is identical.
The 6th address lookup unit 1413, for when judgment result is that of the second comparing unit 1412 is, arrange and to the querying condition of database be: prefix field is startIP_prefix and startIP_postfix <=suffix field <=endIP_postfix, obtains the Query Result that database returns.
The 7th address lookup unit 1414, for at the second comparing unit 1412 when the determination result is NO, arrange and to the querying condition of database be: prefix field is startIP_prefix and suffix field >=startIP_postfix or suffix field <=endIP_postfix, obtains the Query Result that database returns.
The 8th address lookup unit 1415, when the determination result is NO at the first comparing unit 1411, according to random order or executable operations Q11, operation Q12 and operation Q13 simultaneously, and integrates the Query Result obtaining by operation Q11, Q12 and Q13.
Wherein, operation Q11 is: if the sign bit of startIP_postfix is 0, the querying condition that database is set is: prefix field is startIP_prefix and (suffix field >=startIP_postfix or suffix field <=-1); If the sign bit of startIP_postfix is 1, the querying condition that database is set is: prefix field is startIP_prefix and startIP_postfix <=suffix field <=-1; Obtain the Query Result that database returns.
Operation Q12 is: if the sign bit of startIP_prefix and endIP_prefix is identical, the querying condition that database is set is: startIP_prefix < prefix field < endIP_prefix; If the sign bit of startIP_prefix and endIP_prefix is different, the querying condition that database is set is: prefix field > startIP_prefix or prefix field <=endIP_prefix; Obtain the Query Result that database returns.
Operation Q13 is: if the sign bit of endIP_postfix is 0, the querying condition that database is set is: prefix field is endIP_prefix and 0 <=suffix field <=endIP_postfix; If the sign bit of endIP_postfix is 1, the querying condition that database is set is: prefix field is endIP_prefix and (suffix field >=0or suffix field <=endIP_postfix); Obtain the Query Result that database returns.
Above-mentioned and is logical AND, and or is logic OR.
The second: as shown in figure 15, this device can also comprise: offset table memory cell 1430.IPv6 address storaging unit 1404 can specifically comprise: the first address transition subelement 14045, list item coupling subelement 14046, the 3rd address storing sub-units 14047, the skew newly-built subelement 14044 of list item and four-address storing sub-units 14048.
Offset table memory cell 1430, for storing offset-lists, each list item in this offset-lists comprises: side-play amount ID, address prefix and prefix length.
This offset table memory cell 1430 can be set to an independently unit, also can be arranged in IPv6 address storaging unit 1404, also can be arranged in IPv4 address storaging unit 1403.
L ' the value of above-mentioned acquiescence can be predefined, can be also that system generates automatically.This L ' value is at least more than 65, and the L ' value that for example can adopt acquiescence is 80.
The first address transition subelement 14045, by IPv6 address transition for sending to list item to mate subelement 14046 with after the data of address prefix same type in offset-lists.
List item coupling subelement 14046, starts to mate with the list item of offset-lists for the high position of the IPv6 address from conversion, if there is the list item of coupling, to the 3rd address storing sub-units 14047 transmission processings notices; Otherwise, the IPv6 address after conversion is sent to the newly-built subelement 14044 of skew list item.
The 3rd address storing sub-units 14047, for obtaining side-play amount ID and the prefix length L of list item of coupling, the side-play amount ID obtaining is stored in prefix field, after being converted to integer data, the low M position of the IPv6 address after conversion is stored in suffix field, wherein, M=128-L.
The newly-built subelement 14044 of skew list item, for when list item coupling subelement 14046 mates less than corresponding list item, during IPv6 address after receiving the conversion that list item coupling subelement 14046 sends, in offset-lists, create new list item, the prefix length of the list item that this is new adopts the L ' value of acquiescence, high L ' the position of the IPv6 address after conversion is stored as to the address prefix of new list item, and sequentially for new list item, side-play amount ID is set according to the side-play amount ID setting, this side-play amount ID and L ' value are sent to four-address storing sub-units 14048.
Four-address storing sub-units 14048, for the side-play amount ID receiving is stored in to prefix field, is stored in suffix field after the low N position of IPv6 address after conversion is converted to integer data, wherein, and N=128-L '.
For single ip address inquiry, this device can also comprise: the 3rd type judging unit 1416, the 3rd address lookup unit 1417 and four-address query unit 1418.
Command reception unit 1400, can also be for receiving the query statement that comprises single IP inquire address.
The 3rd type judging unit 1416, for judging the type of IP inquire address, if IPv4 inquire address sends to the 3rd address lookup unit 1417 by this IPv4 inquire address; If IPv6 inquire address sends to four-address query unit 1418 by this IPv6 inquire address.
The 3rd address lookup unit 1417, for IPv4 inquire address is converted to after integer data, arrange and to the querying condition of database be: prefix field is that sky and suffix field are the data that obtain after the conversion of IPv4 inquire address, obtains the Query Result that database returns.
Four-address query unit 1418, for IPv6 inquire address, be converted to after the data with offset-lists address prefix same type, in offset-lists, search the list item of the Data Matching after changing with IPv6 inquire address, if search the list item less than coupling, end operation; If find the list item of coupling, obtain side-play amount ID and prefix length L1 in the list item finding, after being converted to integer data, the low N1 position of data after the conversion of IPv6 inquire address obtains ip_postfix, arrange and to the querying condition of database be: prefix field is that side-play amount ID and the suffix field obtained are ip_postfix, obtain the Query Result that database returns, finish current querying flow; Wherein, N1=128-L1.
For the inquiry of IP address range, this device can also comprise: the 5th type judging unit 1419, the 9th address lookup unit 1420, the second address processing unit 1421, the 3rd address processing unit 1422, the 3rd comparing unit 1423, the tenth address lookup unit 1424 and the 11 address lookup unit 1425.
Command reception unit 1400, also for receiving the query statement that comprises IP inquire address scope.
With identical in the first structure, 1400 pairs of the command reception unit query statement receiving possesses recognition function, can identify inquiry single ip address or inquiry IP address range, if only comprise single IP inquire address in this query statement, illustrate that this query statement is for inquiring about single ip address; If comprise IP inquire address scope (comprise initial inquiry end value and finish inquiry end value) in this query statement, illustrate that this query statement is for inquiring about IP address range.
The 5th type judging unit 1419, for judging the type of this IP inquire address scope, if IPv4 inquire address scope sends to the 9th address lookup unit 1420 by this IPv4 address lookup scope; If IPv6 inquire address scope sends to the second address processing unit 1421 by this IPv6 inquire address scope.
The 9th address lookup unit 1420, for the initial end value of IPv4 inquire address scope is obtained respectively to ipv4_start and ipv4_end with finishing after end value is converted to integer data, arrange and to the querying condition of database be: prefix field is for empty, and ipv4_start <=suffix field <=ipv4_end, obtains the Query Result that database returns.
The second address processing unit 1421 for by the initial end value of IPv6 inquire address scope with finish end value and be converted to after the data with offset-lists address prefix same type, mates respectively in offset-lists.
The 3rd address processing unit 1422, for at the second address processing unit 1421, match with change after the list item that mate of initial end value and with change after while finishing list item that end value mates, obtain with change after initial end value and the side-play amount ID finishing in list item that end value mates be respectively start_id and end_id, prefix length is respectively start_L and end_L, and obtains respectively startIp_postfix and endIp_postfix after respectively the low N3 position of the end end value after the low N2 position of the initial end value after conversion and conversion being converted to integer data; Wherein, N2=128-start_L, N3=128-end_L.
The 3rd comparing unit 1423, for judging that whether start_id and end_id be identical.
The tenth address lookup unit 1424, for when judgment result is that of the 3rd comparing unit 1423 is, arrange and to the querying condition of database be: prefix field is start_id and startIp_postfix <=suffix field <=endIp_postfix, obtains the Query Result that database returns.
The 11 address lookup unit 1425, when at the 3rd comparing unit 1423, the determination result is NO, according to random order or executable operations Q21, operation Q22 and operation Q23 simultaneously, and the Query Result that obtains of integrated operation Q21, operation Q22 and operation Q23.
Wherein, operation Q21 is: the querying condition that database is set is: prefix field is start_id and suffix field >=startIp_postfix, obtains the Query Result that database returns.
Operation Q22 is: determine that initial end value is converted to and offset-lists in address prefix same type data and finish that end value is converted to and offset-lists in each data between the data of address prefix same type, search in offset-lists and each side-play amount ID of each Data Matching of determining, if find side-play amount ID, the querying condition that database is set is: prefix field is the logic OR between each side-play amount ID finding, and obtains the Query Result that database returns.
Operation Q23 is: the querying condition that database is set is: prefix field is end_id and suffix field <=endIp_postfix, obtains the Query Result that database returns.
By above description, can be found out, method and apparatus provided by the invention possesses following advantage:
1) IP address is stored in to the memory space that comprises prefix field and suffix field, and concrete IP address class type in storage instruction is distinguished, for IPv4 address, be stored in suffix field after being converted to integer data, prefix field is put sky; For IPv6 address, IPv6 address is divided into higher memory address and lower memory address, the information of higher memory address is stored in prefix field, by lower memory address transition, be to be stored in suffix field after integer data.This storage mode has been realized the unified storage of IPv4 address and IPv6 address in database, for the unified query of IPv4 address and IPv6 address, provides convenience, and has improved storage and search efficiency.
2) the IPv4 storage system that this storage mode can be compatible current, only need can not cause the IPv4 address of having stored to lose using original IPv4 address memory space as suffix field, realizes IPv4 storage system seamless transitions to IPv6 storage system.
3) in the present invention, inquiry velocity that the mode of character string brings shortcoming very slowly, all with the form storage of integer data, has been avoided being stored as in existing first kind of way in IPv4 address and IPv6 address.
4) mode provided by the invention is without the algorithm that carries out any complexity, and the second way of the prior art of comparing, realizes very simple.In addition, the second way for prior art, because IPv6 address is 128, and the result of digest algorithm is mostly 32, in the storage of magnanimity address, repetition rate is very large, affect system accuracy, and the result of digest algorithm is not linear, cannot carry out to IPv6 address the inquiry of address realm, have very large limitation.And mode provided by the invention reaches 128, in the storage of magnanimity address, can not produce repetition, system accuracy is improved.In addition, the IP address of storing in the present invention is all linear, can realize easily the inquiry of single ip address or IP address range.
The foregoing is only preferred embodiment of the present invention, in order to limit the present invention, within the spirit and principles in the present invention not all, any modification of making, be equal to replacement, improvement etc., within all should being included in the scope of protection of the invention.

Claims (10)

1. a method for storing IP v4 address and IPv6 address, is characterized in that, the method comprises:
A, while receiving the storage instruction that comprises IP address, in specified data storehouse, comprise the memory space of prefix field and suffix field, and judge the type of described IP address, if IPv4 address performs step B; If IPv6 address performs step C;
B, be stored in described suffix field after described IPv4 address transition is become to integer data, described prefix field is put to sky, finish current Stored Procedure;
C, described IPv6 address is divided into high address part and LAP Lower Address Part, the information of high address part is stored in described prefix field, after converting LAP Lower Address Part to integer data, be stored in described suffix field, finish current Stored Procedure;
Described step C specifically comprises: described IPv6 address is divided into high 64 and low 64, after converting integer data to by high 64, be stored in described prefix field, after converting integer data to by low 64, be stored in described suffix field, finish current Stored Procedure;
Or, default bias scale, each list item in this offset-lists comprises: side-play amount ID, address prefix and prefix length;
Described step C specifically comprises:
C1, by described IPv6 address transition be with described offset-lists in after the data of address prefix same type, a high position for the IPv6 address from conversion starts to mate with the list item in described offset-lists, if there is the list item of coupling, performs step C2; Otherwise, execution step C3;
C2, obtain side-play amount ID and prefix length L in the list item of coupling, the side-play amount ID obtaining is stored in described prefix field, is stored in described suffix field, wherein after the low M position of IPv6 address after conversion is converted to integer data, M=128-L, finishes current Stored Procedure;
C3, in offset-lists, create new list item, the prefix length of the list item that this is new adopts the L ' value of acquiescence, high L ' the position of the IPv6 address after conversion is stored as to the address prefix of described new list item, and sequentially for described new list item, side-play amount ID is set according to the side-play amount ID setting, this side-play amount ID arranging is stored in described prefix field, after being converted to integer data, the low N position of the IPv6 address after conversion is stored in described suffix field, wherein, N=128-L ', finishes current Stored Procedure.
2. method according to claim 1, is characterized in that, the method also comprises following querying flow:
D1, receive after the query statement that comprises single IP inquire address, judge the type of this single IP inquire address, if IPv4 inquire address performs step E1; If IPv6 inquire address performs step F1;
E1, described IPv4 inquire address is converted to after integer data, arrange and to the querying condition of database be: prefix field is that sky and suffix field are the data that obtain after described IPv4 inquire address conversion, obtain the Query Result that database returns, finish current querying flow;
F1, after being divided into high 64 and low 64, described IPv6 inquire address is converted to respectively integer data, obtain high 64 inquire addresses and low 64 inquire addresses, arrange and to the querying condition of database be: prefix field is that described high 64 inquire addresses and suffix field are described low 64 inquire addresses, obtains the Query Result that database returns.
3. method according to claim 1, is characterized in that, the method also comprises following querying flow:
D2, receive after the query statement that comprises single IP inquire address, judge the type of described IP inquire address, if IPv4 inquire address performs step E2; If IPv6 inquire address performs step F2;
E2, described IPv4 inquire address is converted to after integer data, arrange and to the querying condition of database be: prefix field is that sky and suffix field are the data that obtain after described IPv4 inquire address conversion, obtain the Query Result that database returns, finish current querying flow;
F2, by described IPv6 inquire address be converted to described offset-lists in after the data of address prefix same type, in described offset-lists, search the list item of the Data Matching after changing with described IPv6 inquire address, if find the list item of coupling, perform step G2, otherwise, finish current querying flow;
G2, obtain side-play amount ID and prefix length L1 in the list item finding, after being converted to integer data, the low N1 position of data after described IPv6 inquire address conversion obtains ip_postfix, arrange and to the querying condition of database be: prefix field is that side-play amount ID and the suffix field obtained are ip_postfix, obtain the Query Result that database returns, finish current querying flow; Wherein, N1=128-L1.
4. method according to claim 1, is characterized in that, the method also comprises following querying flow:
H1, receive after the query statement that comprises IP inquire address scope, judge the type of described IP inquire address scope, if IPv4 inquire address scope performs step I1; If IPv6 inquire address scope performs step J1;
I1, by the initial end value of described IPv4 inquire address scope with finish after end value is converted to integer data to obtain respectively ipv4_start and ipv4_end, arrange and to the querying condition of database be: prefix field is for empty, and ipv4_start<=suffix field <=ipv4_end, obtain the Query Result that database returns, finish current querying flow;
J1, by the initial end value ipv6_start of described IPv6 inquire address scope with finish end value ipv6_end and be divided into respectively high 64 and low 64, be converted to again high 64 the inquire address startIP_prefix and low 64 the inquire address startIP_postfix that obtain respectively ipv6_start after integer data, and high 64 inquire address endIP_prefix of ipv6_end and low 64 inquire address endIP_postfix; Judge that whether startIP_prefix and endIP_prefix be identical, if identical, execution step K1; Otherwise execution step Q1;
K1, judge that whether the sign bit of startIP_postfix and endIP_postfix is identical, if identical, execution step O1; Otherwise execution step P1;
O1, arrange and to the querying condition of database be: prefix field is startIP_prefix and startIP_postfix<=suffix field <=endIP_postfix, obtain the Query Result that database returns, finish current querying flow;
P1, arrange and to the querying condition of database be: prefix field is startIP_prefix and suffix field >=startIP_postfix or suffix field <=endIP_postfix, obtain the Query Result that database returns, finish current querying flow;
Q1, perform step Q11, Q12 and Q13 in any order or simultaneously;
If the sign bit of Q11 startIP_postfix is 0, the querying condition that database is set is: prefix field is startIP_prefix and(suffix field >=startIP_postfix or suffix field <=-1); If the sign bit of startIP_postfix is 1, the querying condition that database is set is: prefix field is startIP_prefix and startIP_postfix<=suffix field <=-1; Obtain the Query Result that database returns;
If the sign bit of Q12 startIP_prefix and endIP_prefix is identical, the querying condition that database is set is: startIP_prefix< prefix field <endIP_prefix; If the sign bit of startIP_prefix and endIP_prefix is different, the querying condition that database is set is: prefix field >startIP_prefix or prefix field <=endIP_prefix; Obtain the Query Result that database returns;
If the sign bit of Q13 endIP_postfix is 0, the querying condition that database is set is: prefix field is endIP_prefix and0<=suffix field <=endIP_postfix; If the sign bit of endIP_postfix is 1, the querying condition that database is set is: prefix field is endIP_prefix and(suffix field >=0or suffix field <=endIP_postfix); Obtain the Query Result that database returns;
The Query Result that R1, integration step Q11, Q12 and Q13 obtain;
Wherein, described and is logical AND, and described or is logic OR.
5. method according to claim 1, is characterized in that, the method also comprises following querying flow;
H2, receive after the query statement that comprises IP inquire address scope, judge the type of this IP inquire address scope, if IPv4 inquire address scope performs step I2; If IPv6 inquire address scope performs step J2;
I2, by the initial end value of described IPv4 inquire address scope with finish after end value is converted to integer data to obtain respectively ipv4_start and ipv4_end, arrange and to the querying condition of database be: prefix field is for empty, and ipv4_start<=suffix field <=ipv4_end, obtain the Query Result that database returns, finish current querying flow;
J2, by the initial end value of described IPv6 inquire address scope and finish end value be converted to described offset-lists in after the data of address prefix same type, in described offset-lists, mate respectively, if there is respectively the list item mating with initial end value after conversion and finish with after conversion the list item that end value mates, performing step K2; Otherwise, finish current querying flow;
K2, obtain with change after initial end value and the side-play amount ID finishing in list item that end value mates be respectively start_id and end_id, prefix length is respectively start_L and end_L, and obtains respectively startIp_postfix and endIp_postfix after respectively the low N3 position of the end end value after the low N2 position of the initial end value after conversion and conversion being converted to integer data; Wherein, N2=128-start_L, N3=128-end_L;
O2, judge that whether start_id is identical with end_id, if identical, execution step P2; Otherwise execution step Q2;
P2, arrange and to the querying condition of database be: prefix field is start_id and startIp_postfix<=suffix field <=endIp_postfix, obtain the Query Result that database returns, finish current querying flow;
Q2, according to random order or perform step Q21, Q22 and Q23 simultaneously;
Q21, the querying condition that database is set are: prefix field is start_id and suffix field >=startIp_postfix, obtains the Query Result that database returns;
Q22, determine that initial end value is converted to and described offset-lists in address prefix same type data and finish that end value is converted to and described offset-lists in each data between the data of address prefix same type, search in described offset-lists and each side-play amount ID of described each Data Matching of determining, if find side-play amount ID, the querying condition that database is set is: prefix field is the logic OR between each side-play amount ID finding, and obtains the Query Result that database returns;
Q23, the querying condition that database is set are: prefix field is end_id and suffix field <=endIp_postfix, obtains the Query Result that database returns;
The Query Result that R2, integration step Q21, Q22 and Q23 obtain;
Wherein, described and is logical AND, and described or is logic OR.
6. a device for storing IP v4 address and IPv6 address, is characterized in that, this device comprises: command reception unit, space determining unit, first kind judging unit, IPv4 address storaging unit and IPv6 address storaging unit;
Described command reception unit, for receiving the storage instruction that comprises IP address;
Described space determining unit, for receiving after the storage instruction that comprises IP address in described command reception unit, comprises the memory space of prefix field and suffix field in specified data storehouse;
Described first kind judging unit, for judging the type of described IP address, if IPv4 address sends to described IPv4 address storaging unit by this IPv4 address; If IPv6 address sends to described IPv6 address storaging unit by this IPv6 address;
Described IPv4 address storaging unit is stored in described suffix field after described IPv4 address transition is become to integer data, and described prefix field is put to sky;
Described IPv6 address storaging unit, for described IPv6 address is divided into high address part and LAP Lower Address Part, the information of high address part is stored in described prefix field, is stored in described suffix field after LAP Lower Address Part is converted to integer data;
Described IPv6 address storaging unit comprises: subelement and the first address storing sub-units and the second address storing sub-units are divided in address;
Subelement is divided in described address, high 64 and low 64 for described IPv6 address is divided into, and sends to the first address storing sub-units by high 64, by low 64, sends to the second address storing sub-units;
Described the first address storing sub-units, for being stored in described prefix field by described high 64 after converting integer data to;
Described the second address storing sub-units, for being stored in described suffix field by described low 64 after converting integer data to;
This device also comprises: offset table memory cell, and for storing offset-lists, each list item in this offset-lists comprises: side-play amount ID, address prefix and prefix length;
Described IPv6 address storaging unit comprises: the first address transition subelement, list item coupling subelement, the 3rd address storing sub-units, the skew newly-built subelement of list item and four-address storing sub-units;
Described the first address transition subelement, by described IPv6 address transition for sending to list item to mate subelement with after the data of address prefix same type in described offset-lists;
Described list item coupling subelement, starts to mate with the list item of described offset-lists for the high position of the IPv6 address from conversion, if there is the list item of coupling, to the 3rd address storing sub-units transmission processing notice; Otherwise, the IPv6 address after conversion is sent to the newly-built subelement of described skew list item;
Described the 3rd address storing sub-units, for obtaining side-play amount ID and the prefix length L of list item of coupling, the side-play amount ID obtaining is stored in described prefix field, after being converted to integer data, the low M position of the IPv6 address after conversion is stored in described suffix field, wherein, M=128-L;
The newly-built subelement of described skew list item, for receiving behind the IPv6 address after the conversion that described list item coupling subelement sends, in offset-lists, create new list item, the prefix length of the list item that this is new adopts the L ' value of acquiescence, high L ' the position of the IPv6 address after conversion is stored as to the address prefix of described new list item, and sequentially for described new list item, side-play amount ID is set according to the side-play amount ID setting, this side-play amount ID and L ' value are sent to four-address storing sub-units;
Described four-address storing sub-units, for the side-play amount ID receiving is stored in to described prefix field, is stored in described suffix field after the low N position of IPv6 address after conversion is converted to integer data, wherein, and N=128-L '.
7. device according to claim 6, is characterized in that, this device also comprises: Second Type judging unit, the first address lookup unit and the second address lookup unit;
Described command reception unit, also for receiving the query statement that comprises single IP inquire address;
Described Second Type judging unit, for judging the type of described IP inquire address, if IPv4 inquire address sends to the first address lookup unit by this IPv4 inquire address; If IPv6 inquire address sends to the second address lookup unit by this IPv6 inquire address;
Described the first address lookup unit, for described IPv4 inquire address is converted to after integer data, arrange and to the querying condition of database be: prefix field is that sky and suffix field are the data that obtain after described IPv4 inquire address conversion, obtains the Query Result that database returns;
Described the second address lookup unit, after described IPv6 inquire address being divided into high 64 and low 64, be converted to respectively integer data, obtain high 64 inquire addresses and low 64 inquire addresses, arrange and to the querying condition of database be: prefix field is that described high 64 inquire addresses and suffix field are described low 64 inquire addresses, obtains the Query Result that database returns.
8. device according to claim 6, is characterized in that, this device also comprises: the 3rd type judging unit, the 3rd address lookup unit and four-address query unit;
Described command reception unit, also for receiving the query statement that comprises single IP inquire address;
Described the 3rd type judging unit, for judging the type of described IP inquire address, if IPv4 inquire address sends to the 3rd address lookup unit by this IPv4 inquire address; If IPv6 inquire address sends to four-address query unit by this IPv6 inquire address;
Described the 3rd address lookup unit, for described IPv4 inquire address is converted to after integer data, arrange and to the querying condition of database be: prefix field is that sky and suffix field are the data that obtain after described IPv4 inquire address conversion, obtains the Query Result that database returns;
Described four-address query unit, for described IPv6 inquire address, be converted to after the data with described offset-lists address prefix same type, in described offset-lists, search the list item of the Data Matching after changing with described IPv6 inquire address, if search the list item less than coupling, end operation; If find the list item of coupling, obtain side-play amount ID and prefix length L1 in the list item finding, after being converted to integer data, the low N1 position of data after described IPv6 inquire address conversion obtains ip_postfix, arrange and to the querying condition of database be: prefix field is that side-play amount ID and the suffix field obtained are ip_postfix, obtain the Query Result that database returns, finish current querying flow; Wherein, N1=128-L1.
9. device according to claim 6, it is characterized in that, this device also comprises: the 4th type judging unit, the 5th address lookup unit, the first address processing unit, the first comparing unit, the second comparing unit, the 6th address lookup unit, the 7th address lookup unit and the 8th address lookup unit;
Described command reception unit, also for receiving the query statement that comprises IP inquire address scope;
Described the 4th type judging unit, for judging the type of described IP inquire address scope, if IPv4 inquire address scope sends to described the 5th address lookup unit by this IPv4 inquire address scope; If IPv6 address lookup address realm sends to described the first address processing unit by this IPv6 inquire address scope;
Described the 5th address lookup unit, for the initial end value of described IPv4 inquire address scope is obtained respectively to ipv4_start and ipv4_end with finishing after end value is converted to integer data, arrange and to the querying condition of database be: prefix field is for empty, and ipv4_start<=suffix field <=ipv4_end, obtains the Query Result that database returns;
Described the first address processing unit, for by the initial end value ipv6_start of described IPv6 inquire address scope with finish end value ipv6_end and be divided into respectively high 64 and low 64, be converted to again high 64 the inquire address startIP_prefix and low 64 the inquire address startIP_postfix that obtain respectively ipv6_start after integer data, and high 64 inquire address endIP_prefix of ipv6_end and low 64 inquire address endIP_postfix;
Described the first comparing unit, for judging that whether described startIP_prefix and endIP_prefix be identical;
Described the second comparing unit, for when judgment result is that of described the first comparing unit is, judges that whether the sign bit of startIP_postfix and endIP_postfix is identical;
Described the 6th address lookup unit, for when judgment result is that of described the second comparing unit is, arrange and to the querying condition of database be: prefix field is startIP_prefix and startIP_postfix<=suffix field <=endIP_postfix, obtains the Query Result that database returns;
Described the 7th address lookup unit, for at described the second comparing unit when the determination result is NO, arrange and to the querying condition of database be: prefix field is startIP_prefix and suffix field >=startIP_postfix or suffix field <=endIP_postfix, obtains the Query Result that database returns;
Described the 8th address lookup unit, when the determination result is NO at described the first comparing unit, according to random order or executable operations Q11, operation Q12 and operation Q13 simultaneously, and integrates the Query Result obtaining by operation Q11, Q12 and Q13;
Wherein, described operation Q11 is: if the sign bit of startIP_postfix is 0, the querying condition that database is set is: prefix field is startIP_prefix and(suffix field >=startIP_postfix or suffix field <=-1); If the sign bit of startIP_postfix is 1, the querying condition that database is set is: prefix field is startIP_prefix and startIP_postfix<=suffix field <=-1; Obtain the Query Result that database returns;
Described operation Q12 is: if the sign bit of startIP_prefix and endIP_prefix is identical, the querying condition that database is set is: startIP_prefix< prefix field <endIP_prefix; If the sign bit of startIP_prefix and endIP_prefix is different, the querying condition that database is set is: prefix field >startIP_prefix or prefix field <=endIP_prefix; Obtain the Query Result that database returns;
Described operation Q13 is: if the sign bit of endIP_postfix is 0, the querying condition that database is set is: prefix field is endIP_prefix and0<=suffix field <=endIP_postfix; If the sign bit of endIP_postfix is 1, the querying condition that database is set is: prefix field is endIP_prefix and(suffix field >=0or suffix field <=endIP_postfix); Obtain the Query Result that database returns;
Described and is logical AND, and described or is logic OR.
10. device according to claim 6, it is characterized in that, this device also comprises: the 5th type judging unit, the 9th address lookup unit, the second address processing unit, the 3rd address processing unit, the 3rd comparing unit, the tenth address lookup unit and the 11 address lookup unit;
Described command reception unit, also for receiving the query statement that comprises IP inquire address scope;
Described the 5th type judging unit, for judging the type of this IP inquire address scope, if IPv4 inquire address scope sends to the 9th address lookup unit by this IPv4 address lookup scope; If IPv6 inquire address scope sends to the second address processing unit by this IPv6 inquire address scope;
Described the 9th address lookup unit, for the initial end value of described IPv4 inquire address scope is obtained respectively to ipv4_start and ipv4_end with finishing after end value is converted to integer data, arrange and to the querying condition of database be: prefix field is for empty, and ipv4_start<=suffix field <=ipv4_end, obtains the Query Result that database returns;
Described the second address processing unit for by the initial end value of described IPv6 inquire address scope with finish end value and be converted to after the data with described offset-lists address prefix same type, mates respectively in described offset-lists;
Described the 3rd address processing unit, for at described the second address processing unit, match with change after the list item that mate of initial end value and with change after while finishing list item that end value mates, obtain with change after initial end value and the side-play amount ID finishing in list item that end value mates be respectively start_id and end_id, prefix length is respectively start_L and end_L, and obtains respectively startIp_postfix and endIp_postfix after respectively the low N3 position of the end end value after the low N2 position of the initial end value after conversion and conversion being converted to integer data; Wherein, N2=128-start_L, N3=128-end_L;
Described the 3rd comparing unit, for judging that whether described start_id and end_id be identical;
Described the tenth address lookup unit, for when judgment result is that of described the 3rd comparing unit is, arrange and to the querying condition of database be: prefix field is start_id and startIp_postfix<=suffix field <=endIp_postfix, obtains the Query Result that database returns;
Described the 11 address lookup unit, when at described the 3rd comparing unit, the determination result is NO, according to random order or executable operations Q21, operation Q22 and operation Q23 simultaneously, and the Query Result that obtains of integrated operation Q21, operation Q22 and operation Q23;
Wherein, described operation Q21 is: the querying condition that database is set is: prefix field is start_id and suffix field >=startIp_postfix, obtains the Query Result that database returns;
Described operation Q22 is: determine that initial end value is converted to and described offset-lists in address prefix same type data and finish that end value is converted to and described offset-lists in each data between the data of address prefix same type, search in described offset-lists and each side-play amount ID of described each Data Matching of determining, if find side-play amount ID, the querying condition that database is set is: prefix field is the logic OR between each side-play amount ID finding, and obtains the Query Result that database returns;
Described operation Q23 is: the querying condition that database is set is: prefix field is end_id and suffix field <=endIp_postfix, obtains the Query Result that database returns;
Described and is logical AND, and described or is logic OR.
CN201010149629.4A 2010-04-15 2010-04-15 Method and device for storing IPv4 (the Fourth Internet Protocol Version) address and IPv6 (the Sixth Internet Protocol Version) address Expired - Fee Related CN102223289B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201010149629.4A CN102223289B (en) 2010-04-15 2010-04-15 Method and device for storing IPv4 (the Fourth Internet Protocol Version) address and IPv6 (the Sixth Internet Protocol Version) address

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201010149629.4A CN102223289B (en) 2010-04-15 2010-04-15 Method and device for storing IPv4 (the Fourth Internet Protocol Version) address and IPv6 (the Sixth Internet Protocol Version) address

Publications (2)

Publication Number Publication Date
CN102223289A CN102223289A (en) 2011-10-19
CN102223289B true CN102223289B (en) 2014-04-16

Family

ID=44779722

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201010149629.4A Expired - Fee Related CN102223289B (en) 2010-04-15 2010-04-15 Method and device for storing IPv4 (the Fourth Internet Protocol Version) address and IPv6 (the Sixth Internet Protocol Version) address

Country Status (1)

Country Link
CN (1) CN102223289B (en)

Families Citing this family (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103297554B (en) * 2012-03-02 2016-09-28 深圳市中兴通讯技术服务有限责任公司 The method and device of IPv4 and IPv6 compatible processing
CN102682112B (en) * 2012-05-11 2014-11-19 华为技术有限公司 Storage method and device
CN103870492B (en) * 2012-12-14 2017-08-04 腾讯科技(深圳)有限公司 A kind of date storage method and device based on key row sequence
US9479475B1 (en) * 2014-03-17 2016-10-25 Michael E. Mazarick System and method for IPv4 to IPv6 transition rather than an outage
CN104539537B (en) * 2014-12-25 2018-04-20 北京华为数字技术有限公司 A kind of method for searching route and device
CN106789137A (en) * 2015-11-19 2017-05-31 北京国双科技有限公司 The comparative approach and device of IP scopes
CN107547407B (en) * 2017-09-15 2021-03-09 新华三技术有限公司 Message transmission method, device and implementation device
CN108011993B (en) * 2017-12-07 2021-07-16 北京百悟科技有限公司 Method and system for storing IP address information and inquiring IPv4 address
CN110837510B (en) * 2019-11-13 2020-08-07 北京深演智能科技股份有限公司 Data processing method, device, storage medium and processor
CN110995805B (en) * 2019-11-24 2022-02-18 浪潮电子信息产业股份有限公司 Method, device and equipment for determining cluster network card and readable storage medium
CN112383647A (en) * 2020-11-30 2021-02-19 安徽信息工程学院 Network system based on SPACE6 and dual-stack technology
CN114095472B (en) * 2021-11-22 2023-11-28 北京知道创宇信息技术股份有限公司 Address management method, terminal, electronic device and computer readable storage medium
CN114285797B (en) * 2021-12-30 2024-04-19 北京天融信网络安全技术有限公司 Processing method, device and storage medium of IP address

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101179508A (en) * 2007-11-29 2008-05-14 中兴通讯股份有限公司 IPV4 and IPV6 multiplexing routing table generating device and method for generating the multiplexing routing table

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005295217A (en) * 2004-03-31 2005-10-20 Toshiba Corp Communication apparatus, name resolution method and program

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101179508A (en) * 2007-11-29 2008-05-14 中兴通讯股份有限公司 IPV4 and IPV6 multiplexing routing table generating device and method for generating the multiplexing routing table

Also Published As

Publication number Publication date
CN102223289A (en) 2011-10-19

Similar Documents

Publication Publication Date Title
CN102223289B (en) Method and device for storing IPv4 (the Fourth Internet Protocol Version) address and IPv6 (the Sixth Internet Protocol Version) address
CN101141389B (en) Reinforcement multidigit Trie tree searching method and apparatus
CN101819580B (en) System for forwarding packets with identifiers using exact-match lookup engine
CN102571599B (en) Rapid storage method of routing table entry
CN101510855B (en) Method and apparatus for processing QinQ message
US20100284405A1 (en) Method and apparatus for searching ip address
CN102946356B (en) CB-PE (controlling bridge-port extender) network-based multicast message transmitting method and device
CN100385880C (en) Packet classification apparatus and method using field level tries
JP2010178342A (en) System for forwarding packet with hierarchically structured variable-length identifier
CN101009656A (en) Routing system and method for managing rule entry thereof
US20080133494A1 (en) Method and apparatus for searching forwarding table
CN102035735A (en) Device and method for providing forwarding and qos information
CN102970150A (en) Extensible multicast forwarding method and device for data center (DC)
CN100511229C (en) Domain name information storage and inquiring method and system
CN101651628A (en) Implementation method of three-state content addressable memory and device
CN101695054A (en) Method and device for route maintenance and method and device for route query
CN103107945A (en) System and method of quick searching Internet protocol version 6 (IPV6) route
US20120054198A1 (en) Table creating and lookup method used by network processor
CN101710864B (en) Collocation method and device for multi-gateway Linux server
CN112235436A (en) Network address translation rule matching method and equipment
CN101478488A (en) Packet forwarding method, forwarding engine chip and routing device
CN114884877A (en) IPv6 route searching method combining hash table and HOT
US20140052710A1 (en) Device and method of mass data storage based on tree structure
CN102164080B (en) Routing address inquiry method and device
US20070025346A1 (en) System and method for creating a routing table

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CP03 Change of name, title or address
CP03 Change of name, title or address

Address after: 310052 Binjiang District Changhe Road, Zhejiang, China, No. 466, No.

Patentee after: Xinhua three Technology Co., Ltd.

Address before: 310053 Hangzhou hi tech Industrial Development Zone, Zhejiang province science and Technology Industrial Park, No. 310 and No. six road, HUAWEI, Hangzhou production base

Patentee before: Huasan Communication Technology Co., Ltd.

CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20140416

Termination date: 20200415