Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement subtraction between IpNetworks #126

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Commits on Feb 14, 2020

  1. Create Ipv4NetworkSubSet helper iterator

    This is a helper type that is created with an initial IPv4 network,
    represented as a `u32` representation of its IP address and a `u8` with
    its prefix, and the prefix of a larger IPv4 network which contains the
    initial IPv4 network. Since one is contained in the other, the IP
    address shares most bits, so it only needs to keep track of it once.
    However, proper care must be taken so that the initial network prefix is
    larger than the larger network prefix.
    
    The iterator will produce `Ipv4Network` items representing increasing
    network ranges that are still inside the larger network but do not
    include the initial network.
    jvff committed Feb 14, 2020
    Configuration menu
    Copy the full SHA
    47f52e0 View commit details
    Browse the repository at this point in the history

Commits on Feb 15, 2020

  1. Create Ipv4NetworkSubResult helper type

    This is also an iterator, and it wraps around the `Ipv4NetworkSubSet`
    type. However, it also includes entries for when the minuend and the
    subtrahend don't overlap and for when the subtrahend completly ovelaps
    the minuend.
    
    In the former case, there is no overlap of the networks. Therefore,
    nothing is subtracted from the original network (the minuend), so the
    result is just the original network.
    
    In the latter case, since the subtrahend completly overlaps the minuend,
    it is in effect completely removing the original network. Therefore, the
    result is no networks at all, and the resulting iterator is empty.
    jvff committed Feb 15, 2020
    Configuration menu
    Copy the full SHA
    3bd9cb9 View commit details
    Browse the repository at this point in the history
  2. Implement Sub for Ipv4Network

    The resulting set is returned through a `Ipv4NetworkSubResult` helper
    iterator.
    jvff committed Feb 15, 2020
    Configuration menu
    Copy the full SHA
    bf081f6 View commit details
    Browse the repository at this point in the history
  3. Implement subtraction of multiple Ipv4Networks

    This allows one to subtract multiple `Ipv4Network`s from a single
    `Ipv4Network`. This works by having a subtraction chain, where the
    original minuend `Ipv4Network` is subtracted by the first `Ipv4Network`
    subtrahend, and the result is then subtracted by the second
    `Ipv4Network` subtrahend, and so on.
    
    The implementation uses dynamic dispatch because it is impossible to
    know how many subtrahends there will be. This is a simple initial
    implementation, and tere might be other solutions, such as creating a
    custom iterator and looping around all subtrahends to provide the
    results, but it quickly becomes more complicated. This might be doable
    as future work.
    
    Another possible future work is to remove the dynamic dispatch for known
    sizes of subtrahend arrays, but this would probably require const
    generics to be stabilized.
    jvff committed Feb 15, 2020
    Configuration menu
    Copy the full SHA
    d98ff92 View commit details
    Browse the repository at this point in the history
  4. Create Ipv6NetworkSubSet helper iterator

    This is the IPv6 equivalent of the `Ipv4NetworkSubSet`.
    
    It is a helper type that is created with an initial IPv6 network,
    represented as a `u128` representation of its IP address and a `u8` with
    its prefix, and the prefix of a larger IPv6 network which contains the
    initial IPv6 network. Since one is contained in the other, the IP
    address shares most bits, so it only needs to keep track of it once.
    However, proper care must be taken so that the initial network prefix is
    larger than the larger network prefix.
    
    The iterator will produce `Ipv6Network` items representing increasing
    network ranges that are still inside the larger network but do not
    include the initial network.
    jvff committed Feb 15, 2020
    Configuration menu
    Copy the full SHA
    9340cc5 View commit details
    Browse the repository at this point in the history
  5. Create Ipv6NetworkSubResult helper type

    This is the IPv6 equivalent to the `Ipv4NetworkSubResult` type.
    
    This is also an iterator, and it wraps around the `Ipv6NetworkSubSet`
    type. However, it also includes entries for when the minuend and the
    subtrahend don't overlap and for when the subtrahend completly ovelaps
    the minuend.
    
    In the former case, there is no overlap of the networks. Therefore,
    nothing is subtracted from the original network (the minuend), so the
    result is just the original network.
    
    In the latter case, since the subtrahend completly overlaps the minuend,
    it is in effect completely removing the original network. Therefore, the
    result is no networks at all, and the resulting iterator is empty.
    jvff committed Feb 15, 2020
    Configuration menu
    Copy the full SHA
    3f1955f View commit details
    Browse the repository at this point in the history
  6. Implement Sub for Ipv6Network

    The resulting set is returned through a `Ipv6NetworkSubResult` helper
    iterator.
    jvff committed Feb 15, 2020
    Configuration menu
    Copy the full SHA
    01b3bfb View commit details
    Browse the repository at this point in the history
  7. Implement subtraction of multiple Ipv6Networks

    This allows one to subtract multiple `Ipv6Network`s from a single
    `Ipv6Network`. This works by having a subtraction chain, where the
    original minuend `Ipv6Network` is subtracted by the first `Ipv6Network`
    subtrahend, and the result is then subtracted by the second
    `Ipv6Network` subtrahend, and so on.
    
    The implementation uses dynamic dispatch because it is impossible to
    know how many subtrahends there will be. This is a simple initial
    implementation, and tere might be other solutions, such as creating a
    custom iterator and looping around all subtrahends to provide the
    results, but it quickly becomes more complicated. This might be doable
    as future work.
    
    Another possible future work is to remove the dynamic dispatch for known
    sizes of subtrahend arrays, but this would probably require const
    generics to be stabilized.
    jvff committed Feb 15, 2020
    Configuration menu
    Copy the full SHA
    c0e4083 View commit details
    Browse the repository at this point in the history
  8. Create IpNetworkSubResult wrapper type

    This type represents the result of the subtraction of one `IpNetwork`
    from another. The implementation just wraps the resulting subtraction of
    the protocol specific (IPv4 or IPv6) subtraction result.
    
    Note that this means that it is not currently possible to subtract
    `IpNetwork`s of different protocols (i.e., either an IPv4 network from
    an IPv6 network or vice-versa).
    jvff committed Feb 15, 2020
    Configuration menu
    Copy the full SHA
    da67e84 View commit details
    Browse the repository at this point in the history
  9. Implement Sub for IpNetwork

    The resulting set is returned through a `IpNetworkSubResult` helper
    iterator.
    
    Note that it is not currently possible to subtract `IpNetwork`s of
    different protocols (i.e., either an IPv4 network from an IPv6 network
    or vice-versa).
    jvff committed Feb 15, 2020
    Configuration menu
    Copy the full SHA
    686c060 View commit details
    Browse the repository at this point in the history
  10. Implement subtraction of multiple IpNetworks

    This allows one to subtract multiple `IpNetwork`s from a single
    `IpNetwork`. This works by having a subtraction chain, where the
    original minuend `IpNetwork` is subtracted by the first `IpNetwork`
    subtrahend, and the result is then subtracted by the second
    `IpNetwork` subtrahend, and so on.
    
    Since it isn't currently possible to subtract `IpNetworks` of different
    protocols, all operands must be of the same protocol (either IPv4 or
    IPv6). Having one operand of a different protocol will cause the code to
    panic.
    
    The implementation uses dynamic dispatch because it is impossible to
    know how many subtrahends there will be. This is a simple initial
    implementation, and tere might be other solutions, such as creating a
    custom iterator and looping around all subtrahends to provide the
    results, but it quickly becomes more complicated. This might be doable
    as future work.
    
    Another possible future work is to remove the dynamic dispatch for known
    sizes of subtrahend arrays, but this would probably require const
    generics to be stabilized.
    jvff committed Feb 15, 2020
    Configuration menu
    Copy the full SHA
    1473c5d View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    9031d4d View commit details
    Browse the repository at this point in the history