Module ip

Source
Expand description

Internet Protocol (IP) types.

This module provides support for various types and traits relating to IPv4 and IPv6, including a number of mechanisms for abstracting over details which are shared between IPv4 and IPv6.

§Ip and IpAddress

The most important traits are Ip and IpAddress.

Ip represents a version of the IP protocol - either IPv4 or IPv6 - and is implemented by Ipv4 and Ipv6. These types exist only at the type level - they cannot be constructed at runtime. They provide a place to put constants and functionality which are not associated with a particular type, and they allow code to be written which is generic over the version of the IP protocol. For example:

struct Entry<A: IpAddress> {
    subnet: Subnet<A>,
    dest: Destination<A>,
}

enum Destination<A: IpAddress> {
    Local { device_id: usize },
    Remote { dst: A },
}

struct ForwardingTable<I: Ip> {
    entries: Vec<Entry<I::Addr>>,
}

See also IpVersionMarker.

The IpAddress trait is implemented by the concrete Ipv4Addr and Ipv6Addr types.

§Runtime types

Sometimes, it is not known at compile time which version of a given type - IPv4 or IPv6 - is present. For these cases, enums are provided with variants for both IPv4 and IPv6. These are IpAddr, SubnetEither, and AddrSubnetEither.

§Composite types

This modules also provides composite types such as Subnet and AddrSubnet.

Structs§

AddrSubnet
An address and that address’s subnet.
IpInvariant
Wrapper type that implements GenericOverIp with Type<I: Ip>=Self.
IpMarked
A wrapper structure to add an IP version marker to an IP-invariant type.
IpVersionMarker
A zero-sized type that carries IP version information.
Ipv4Addr
An IPv4 address.
Ipv6Addr
An IPv6 address.
Mtu
The maximum transmit unit, i.e., the maximum size of an entire IP packet one link can transmit.
NotSubnetMaskError
An IP address was provided which is not a valid subnet mask (the address has set bits after the first unset bit).
PrefixLength
An IP prefix length.
PrefixTooLongError
A prefix was provided which is longer than the number of bits in the address (32 for IPv4/128 for IPv6).
Subnet
An IP subnet.

Enums§

AddrSubnetEither
An address and that address’s subnet, either IPv4 or IPv6.
AddrSubnetError
The error returned from AddrSubnet::new and AddrSubnetEither::new.
IpAddr
An IP address.
IpVersion
An IP protocol version.
Ipv4
IPv4.
Ipv6
IPv6.
Ipv4AddressClass
The class of an IPv4 address.
Ipv6ReservedScope
The list of IPv6 scopes which are reserved for future use by RFC 4291 Section 2.7.
Ipv6Scope
The list of IPv6 scopes.
Ipv6SourceAddr
The source address from an IPv6 packet.
Ipv6UnassignedScope
The list of IPv6 scopes which are available for local definition by administrators.
SubnetEither
An IPv4 subnet or an IPv6 subnet.
SubnetError
The error returned from Subnet::new and SubnetEither::new.
UnicastOrMulticastIpv6Addr
An IPv6 address stored as a unicast or multicast witness type.

Traits§

GenericOverIp
Marks types that are generic over IP version.
Ip
A trait for IP protocol versions.
IpAddrWitness
A type which is a witness to some property about an IpAddress.
IpAddress
An IPv4 or IPv6 address.
IpAddressWitness
A type which is witness to some property about an IpAddress, A.

Derive Macros§

GenericOverIp
Implements a derive macro for [net_types::ip::GenericOverIp]. Requires that #[derive(GenericOverIp)] invocations explicitly specify which type parameter is the generic-over-ip one with the #[generic_over_ip] attribute, rather than inferring it from the bounds on the struct generics.