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§
- An address and that address’s subnet.
- Wrapper type that implements
GenericOverIp
withType<I: Ip>=Self
. - A wrapper structure to add an IP version marker to an IP-invariant type.
- A zero-sized type that carries IP version information.
- An IPv4 address.
- An IPv6 address.
- The maximum transmit unit, i.e., the maximum size of an entire IP packet one link can transmit.
- An IP address was provided which is not a valid subnet mask (the address has set bits after the first unset bit).
- An IP prefix length.
- A prefix was provided which is longer than the number of bits in the address (32 for IPv4/128 for IPv6).
- An IP subnet.
Enums§
- An address and that address’s subnet, either IPv4 or IPv6.
- The error returned from
AddrSubnet::new
andAddrSubnetEither::new
. - An IP address.
- An IP protocol version.
- IPv4.
- IPv6.
- The class of an IPv4 address.
- The list of IPv6 scopes which are reserved for future use by RFC 4291 Section 2.7.
- The list of IPv6 scopes.
- The source address from an IPv6 packet.
- The list of IPv6 scopes which are available for local definition by administrators.
- An IPv4 subnet or an IPv6 subnet.
- The error returned from
Subnet::new
andSubnetEither::new
. - An IPv6 address stored as a unicast or multicast witness type.
Traits§
- Marks types that are generic over IP version.
- A trait for IP protocol versions.
- A type which is a witness to some property about an
IpAddress
. - An IPv4 or IPv6 address.
- A type which is witness to some property about an
IpAddress
,A
.
Derive Macros§
- 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.