|
NAMErwsettool - Operate on IPset files to produce a new IPsetSYNOPSISrwsettool { --union | --intersect | --difference | --symmetric-difference | --sample {--size=SIZE | --ratio=RATIO} [--seed=SEED] | --mask=NET_BLOCK_SIZE | --fill-blocks=NET_BLOCK_SIZE } [--output-path=PATH] [--record-version=VERSION] [--invocation-strip] [--note-strip] [--note-add=TEXT] [--note-file-add=FILE] [--compression-method=COMP_METHOD] [INPUT_SET ...] rwsettool --help rwsettool --version DESCRIPTIONrwsettool performs a single operation on one or more IPset file(s) to produce a new IPset file.The operations that rwsettool provides are
More details are provided in the "OPTIONS" section. rwsettool reads the IPsets specified on the command line; when no IPsets are listed, rwsettool attempts to read an IPset from the standard input. The strings "stdin" or "-" can be used as the name of an input file to force rwsettool to read from the standard input. The resulting IPset is written to the location specified by the --output-path switch or to the standard output if that switch is not provided. Using the strings "stdout" or "-" as the argument to --output-path causes rwsettool to write the IPset to the standard output. rwsettool exits with an error if an attempt is made to read an IPset from the terminal or write an IPset to the terminal. To create an IPset file from SiLK Flow records, use rwset(1), and to create one from text, use rwsetbuild(1). rwsetcat(1) prints an IPset file as text. To determine whether an IPset file contains an IP address, use rwsetmember(1). OPTIONSOption names may be abbreviated if the abbreviation is unique or is an exact match for an option. A parameter to an option may be specified as --arg=param or --arg param, though the first form is required for options that take optional parameters.Operation SwitchesExactly one of the following operation switches must be provided:
Output SwitchesThese switches control the output:
Additional Switchesrwsettool supports these additional switches:
EXAMPLESIn the following examples, the dollar sign ("$") represents the shell prompt. The text after the dollar sign represents the command line. Lines have been wrapped for improved readability, and the back slash ("\") is used to indicate a wrapped line.Assume the following IPsets: A.set = { 1, 2, 4, 6 } B.set = { 1, 3, 5, 7 } C.set = { 1, 3, 6, 8 } D.set = { } (empty set) Set Union ExamplesThe union of two IPsets contains the IP addresses that are members of either IPset. The union of multiple IPsets contains the IP addresses that are members of any of the sets. The resulting IPset does not depend on the order of the input IPsets. The union of a single IPset, of an IPset with itself, and of an IPset with an empty IPset is the original IPset.+---------------------------------+----------------------------+ | OPTIONS | RESULT | +---------------------------------+----------------------------+ | --union A.set B.set | { 1, 2, 3, 4, 5, 6, 7 } | | --union A.set C.set | { 1, 2, 3, 4, 6, 8 } | | --union A.set B.set C.set | { 1, 2, 3, 4, 5, 6, 7, 8 } | | --union C.set D.set | { 1, 3, 6, 8 } | | --union A.set | { 1, 2, 4, 6 } | | --union A.set A.set | { 1, 2, 4, 6 } | +---------------------------------+----------------------------+ Set Intersection ExamplesThe intersection of two IPsets contains the IP addresses that are members of both IPsets (that is, the IP addresses they have in common). The intersection of multiple IPsets contains the IP addresses that are members of all of the sets. The resulting IPset does not depend on the order of the input IPsets. The intersection of a single IPset is the original IPset. The intersection of an IPset with itself is the original IPset. The intersection of an IPset with an empty IPset is an empty IPset.+---------------------------------+----------------------------+ | OPTIONS | RESULT | +---------------------------------+----------------------------+ | --intersect A.set B.set | { 1 } | | --intersect A.set C.set | { 1, 6 } | | --intersect B.set C.set | { 1, 3 } | | --intersect A.set B.set C.set | { 1 } | | --intersect A.set D.set | { } | | --intersect A.set | { 1, 2, 4, 6 } | | --intersect A.set A.set | { 1, 2, 4, 6 } | +---------------------------------+----------------------------+ Set Difference ExamplesThe difference of two IPsets contains the IP addresses that are members of the first set but not members of the second. The difference of multiple IPsets contains the IP addresses in the first set that are not members of any other IPset. The resulting IPset is dependent on the order of the input IPsets. Using the difference operation on a single IPset gives that IPset. The difference of an IPset with an empty IPset is the first IPset. The difference of an IPset with itself is the empty IPset.+---------------------------------+----------------------------+ | OPTIONS | RESULT | +---------------------------------+----------------------------+ | --difference A.set B.set | { 2, 4, 6 } | | --difference B.set A.set | { 3, 5, 7 } | | --difference A.set B.set C.set | { 2, 4 } | | --difference C.set B.set A.set | { 8 } | | --difference C.set D.set | { 1, 3, 6, 8 } | | --difference D.set C.set | { } | | --difference A.set | { 1, 2, 4, 6 } | | --difference A.set A.set | { } | +---------------------------------+----------------------------+ Set Symmetric Difference ExamplesThe symmetric difference (or relative complement) of two IPsets contains the IP addresses that are members of either set but not members of both sets. For each additional input IPset, rwsettool computes the symmetric difference of the current result with the that IPset. The resulting IPset contains the IP addresses that are members of an odd number of the input sets. The resulting IPset does not depend on the order of the input IPsets. Using the symmetric difference operation on a single IPset gives that IPset. The symmetric difference of an IPset with an empty IPset is the first IPset. The symmetric difference of an IPset with itself is the empty IPset.+---------------------------------+----------------------------+ | OPTIONS | RESULT | +---------------------------------+----------------------------+ | --symmetric A.set B.set | { 2, 3, 4, 5, 6, 7 } | | --symmetric A.set C.set | { 2, 3, 4, 8 } | | --symmetric A.set D.set | { 1, 2, 4, 6 } | | --symmetric C.set B.set | { 5, 6, 7, 8 } | | --symmetric A.set B.set C.set | { 1, 2, 4, 5, 7, 8 } | | --symmetric A.set | { 1, 2, 4, 6 } | | --symmetric A.set A.set | { } | +---------------------------------+----------------------------+ Finding IP Addresses Unique to an Input SetUsing the symmetric difference on three or more IPsets does not result in an IPset containing the IP addresses that are members of a single input set. To compute that, use the Bag tools as follows.
A different approach may be used which does not require temporary files. Use rwsetcat(1) to convert the IPset files to text and feed that data to rwbagbuild. (When rwsetcat is invoked on multiple IPset files, it prints the contents of each individual IPset file, and as rwbagbuild processes the text, it increments an IP address's counter each time the IP appears in the input.) Use rwbagtool to create the IPset as shown in Step 3 above. $ rwsetcat --cidr-blocks=1 *.set \ | rwbagbuild --bag-input=- \ | rwbagtool --maxcounter=1 --coverset --output=unique.set Set Sampling ExamplesThe --sample switch creates a subset that contains IP addresses that have been randomly selected from the input IPset(s).The --size switch selects exactly SIZE IP addresses from each input set, but the number of IP addresses in the result may be less than the product of SIZE and the number of inputs when the input sets have IPs in common or when an IPset has fewer than SIZE members. When using the --size switch, the probability of selecting an individual IP address varies with the number of IPs to be selected and the number of IPs remaining in the set. If N is the number of IPs in a set, the probability of selecting the first IP is SIZE/N. If that IP is selected, the probability of selecting the second is (SIZE-1)/(N-1), but if the first IP is not selected, the probability of selecting the second is SIZE/(N-1). +----------------------------------+----------------------------+ | COMMAND | RESULT | +----------------------------------+----------------------------+ | --sample --size 2 A.set | { 1, 4 } | | --sample --size 2 A.set | { 1, 6 } | | --sample --size 3 A.set | { 2, 4, 6 } | | --sample --size 2 A.set B.set | { 1, 2, 5, 7 } | | --sample --size 2 A.set B.set | { 3, 4, 5, 6 } | | --sample --size 2 A.set B.set | { 1, 4, 5 } | +----------------------------------+----------------------------+ The argument to the --ratio switch is the probability of choosing an individual IP address. For each IP address in the input, the IP is added to the output when a pseudo-random number between 0 and 1 is less then the argument to --ratio. The number of IP addresses in the result varies with each invocation. +----------------------------------+----------------------------+ | COMMAND | RESULT | +----------------------------------+----------------------------+ | --sample --ratio 0.5 A.set | { 2, 6 } | | --sample --ratio 0.5 A.set | { 4 } | | --sample --ratio 0.5 A.set B.set | { 1, 3 } | | --sample --ratio 0.5 A.set B.set | { 2, 3, 5, 6, 7 } | +----------------------------------+----------------------------+ Set Masking and Block-Filling ExamplesThe goal of the --mask and --fill-blocks switches is to produce an IPset whose members are on user-defined CIDR-block (or net-block) boundaries. (In some ways, these switches produce output that is similar to the --network-structure switch on rwsetcat(1).)The --mask and --fill-blocks switches require a decimal argument that is a CIDR-block network mask size. For example, the argument 24 represents 256 IPv4 addresses. rwsettool visits each block of that size in the input IPset. If no IP addresses appear in that block, the result also has no IPs in the block. If one or more IP addresses appear in that block, the output IPset has either the lowest address in that block as a member (for --mask) or all IP addresses in that block as members (for --fill-blocks. For example, consider the IPset s.set containing the three IP addresses. $ rwsetcat --cidr-blocks=1 s.set 10.1.1.1 10.1.1.2 10.1.3.1 Specifying --mask=24 produces an IPset containing two IP addresses. $ rwsettool --mask=24 s.set | rwsetcat --cidr-blocks=1 10.1.1.0 10.1.3.0 Specifying --fill-blocks=24 produces an IPset containing 512 IP addresses. $ rwsettool --fill-block=24 s.set | rwsetcat --cidr-blocks=1 10.1.1.0/24 10.1.3.0/24 Consider t.set that contains four IP addresses. $ rwsetcat --cidr-blocks=1 t.set 10.1.1.1 10.1.1.2 10.1.2.5 10.1.3.1 Running --mask=24 and --fill-blocks=24 on that file produces the following. $ rwsettool --mask=24 t.set | rwsetcat --cidr-blocks=1 10.1.1.0 10.1.2.0 10.1.3.0 $ rwsettool --fill-block=24 t.set | rwsetcat --cidr-blocks=1 10.1.1.0/24 10.1.2.0/23 rwsetcat merges 10.1.2.0/24 and 10.1.3.0.24 into a single /23. When multiple IPsets are specified on the command line, the union of the IPsets is computed prior to performing the mask or fill-blocks operation. The result is not dependent on the order of the IPsets. Mixed IPv4 and IPv6 ExamplesSuppose the IPset file mixed.set contains IPv4 and IPv6 addresses. To create an IPset file that contains only the IPv4 addresses, intersect mixed.set with the IPset all-v4.set, which is an IPset that contains all of IPv4 space (::ffff:0:0/96).$ echo '::ffff:0:0/96' | rwsetbuild - all-v4.set $ rwsettool --intersect mixed.set all-v4.set > subset-v4.set To create an IPset file that contains only the IPv6 addresses, subtract all-v4.set from mixed.set: $ rwsettool --difference mixed.set all-v4.set > subset-v6.set The previous two commands may also be performed without having to write create the all-v4.set IPset file. $ echo '::ffff:0:0/96' \ | rwsettool --intersect mixed.set - > subset-v4.set $ echo '::ffff:0:0/96' \ | rwsettool --difference mixed.set - > subset-v6.set Comparing Two IPsets ExampleTo determine if two IPset files contain the same set of IP addresses, use the --symmetric-difference switch and then count the number of IP addresses of the result with rwsetcat. If the count is 0, the files contain the same IP addresses.$ cp A.set A2.set $ rwsettool --symmetric-difference A.set A2.set \ | rwsetcat --count 0 Changing a File's FormatTo share an IPset file with a user who has an older version of SiLK that includes different compression libraries, it may be necessary to change the the record-version or the compression-method of an IPset file.It is not possible to change those aspects of the file directly. A new file must be created first, and then you may then replace the old file with the new file. To create a new file that uses a different record-version or compression-method of the IPset file A.set, use rwsettool with the --union switch and specify the desired arguments: $ rwsettool --union --record-version=5 --output-path=A2.set A.set $ rwsettool --union --compression=none --output-path=A3.set A.set $ rwsettool --union --record-version=2 --compression=best \ --output-path=A4.set A.set ENVIRONMENT
SEE ALSOrwset(1), rwsetbuild(1), rwsetcat(1), rwsetmember(1), rwbagbuild(1), rwbagtool(1), rwfileinfo(1), silk(7), zlib(3)NOTESPrior to SiLK 3.0, an IPset file could not contain IPv6 addresses and the record version was 2. The --record-version switch was added in SiLK 3.0 and its default was 3. In SiLK 3.6, an argument of 0 was allowed and made the default. Version 4 was added in SiLK 3.7 as was support for the SILK_IPSET_RECORD_VERSION environment variable. Version 5 was added in SiLK 3.14.
Visit the GSP FreeBSD Man Page Interface. |