mirror of
https://github.com/smoltcp-rs/smoltcp.git
synced 2025-10-02 15:15:05 +00:00
Fix a naming mishap. NFCI.
This commit is contained in:
parent
581e7b3f6f
commit
2602a151e4
110
src/wire/ip.rs
110
src/wire/ip.rs
@ -261,7 +261,7 @@ impl<T: Into<Address>> From<(T, u16)> for Endpoint {
|
|||||||
/// high-level representation for some IP protocol version, or an unspecified representation,
|
/// high-level representation for some IP protocol version, or an unspecified representation,
|
||||||
/// which permits the `IpAddress::Unspecified` addresses.
|
/// which permits the `IpAddress::Unspecified` addresses.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum IpRepr {
|
pub enum Repr {
|
||||||
Unspecified {
|
Unspecified {
|
||||||
src_addr: Address,
|
src_addr: Address,
|
||||||
dst_addr: Address,
|
dst_addr: Address,
|
||||||
@ -274,75 +274,75 @@ pub enum IpRepr {
|
|||||||
__Nonexhaustive
|
__Nonexhaustive
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Ipv4Repr> for IpRepr {
|
impl From<Ipv4Repr> for Repr {
|
||||||
fn from(repr: Ipv4Repr) -> IpRepr {
|
fn from(repr: Ipv4Repr) -> Repr {
|
||||||
IpRepr::Ipv4(repr)
|
Repr::Ipv4(repr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IpRepr {
|
impl Repr {
|
||||||
/// Return the protocol version.
|
/// Return the protocol version.
|
||||||
pub fn version(&self) -> Version {
|
pub fn version(&self) -> Version {
|
||||||
match self {
|
match self {
|
||||||
&IpRepr::Unspecified { .. } => Version::Unspecified,
|
&Repr::Unspecified { .. } => Version::Unspecified,
|
||||||
&IpRepr::Ipv4(_) => Version::Ipv4,
|
&Repr::Ipv4(_) => Version::Ipv4,
|
||||||
&IpRepr::__Nonexhaustive => unreachable!()
|
&Repr::__Nonexhaustive => unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the source address.
|
/// Return the source address.
|
||||||
pub fn src_addr(&self) -> Address {
|
pub fn src_addr(&self) -> Address {
|
||||||
match self {
|
match self {
|
||||||
&IpRepr::Unspecified { src_addr, .. } => src_addr,
|
&Repr::Unspecified { src_addr, .. } => src_addr,
|
||||||
&IpRepr::Ipv4(repr) => Address::Ipv4(repr.src_addr),
|
&Repr::Ipv4(repr) => Address::Ipv4(repr.src_addr),
|
||||||
&IpRepr::__Nonexhaustive => unreachable!()
|
&Repr::__Nonexhaustive => unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the destination address.
|
/// Return the destination address.
|
||||||
pub fn dst_addr(&self) -> Address {
|
pub fn dst_addr(&self) -> Address {
|
||||||
match self {
|
match self {
|
||||||
&IpRepr::Unspecified { dst_addr, .. } => dst_addr,
|
&Repr::Unspecified { dst_addr, .. } => dst_addr,
|
||||||
&IpRepr::Ipv4(repr) => Address::Ipv4(repr.dst_addr),
|
&Repr::Ipv4(repr) => Address::Ipv4(repr.dst_addr),
|
||||||
&IpRepr::__Nonexhaustive => unreachable!()
|
&Repr::__Nonexhaustive => unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the protocol.
|
/// Return the protocol.
|
||||||
pub fn protocol(&self) -> Protocol {
|
pub fn protocol(&self) -> Protocol {
|
||||||
match self {
|
match self {
|
||||||
&IpRepr::Unspecified { protocol, .. } => protocol,
|
&Repr::Unspecified { protocol, .. } => protocol,
|
||||||
&IpRepr::Ipv4(repr) => repr.protocol,
|
&Repr::Ipv4(repr) => repr.protocol,
|
||||||
&IpRepr::__Nonexhaustive => unreachable!()
|
&Repr::__Nonexhaustive => unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the payload length.
|
/// Return the payload length.
|
||||||
pub fn payload_len(&self) -> usize {
|
pub fn payload_len(&self) -> usize {
|
||||||
match self {
|
match self {
|
||||||
&IpRepr::Unspecified { payload_len, .. } => payload_len,
|
&Repr::Unspecified { payload_len, .. } => payload_len,
|
||||||
&IpRepr::Ipv4(repr) => repr.payload_len,
|
&Repr::Ipv4(repr) => repr.payload_len,
|
||||||
&IpRepr::__Nonexhaustive => unreachable!()
|
&Repr::__Nonexhaustive => unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the payload length.
|
/// Set the payload length.
|
||||||
pub fn set_payload_len(&mut self, length: usize) {
|
pub fn set_payload_len(&mut self, length: usize) {
|
||||||
match self {
|
match self {
|
||||||
&mut IpRepr::Unspecified { ref mut payload_len, .. } =>
|
&mut Repr::Unspecified { ref mut payload_len, .. } =>
|
||||||
*payload_len = length,
|
*payload_len = length,
|
||||||
&mut IpRepr::Ipv4(Ipv4Repr { ref mut payload_len, .. }) =>
|
&mut Repr::Ipv4(Ipv4Repr { ref mut payload_len, .. }) =>
|
||||||
*payload_len = length,
|
*payload_len = length,
|
||||||
&mut IpRepr::__Nonexhaustive => unreachable!()
|
&mut Repr::__Nonexhaustive => unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the TTL value.
|
/// Return the TTL value.
|
||||||
pub fn ttl(&self) -> u8 {
|
pub fn ttl(&self) -> u8 {
|
||||||
match self {
|
match self {
|
||||||
&IpRepr::Unspecified { ttl, .. } => ttl,
|
&Repr::Unspecified { ttl, .. } => ttl,
|
||||||
&IpRepr::Ipv4(Ipv4Repr { ttl, .. }) => ttl,
|
&Repr::Ipv4(Ipv4Repr { ttl, .. }) => ttl,
|
||||||
&IpRepr::__Nonexhaustive => unreachable!()
|
&Repr::__Nonexhaustive => unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,14 +352,14 @@ impl IpRepr {
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
/// This function panics if source and destination addresses belong to different families,
|
/// This function panics if source and destination addresses belong to different families,
|
||||||
/// or the destination address is unspecified, since this indicates a logic error.
|
/// or the destination address is unspecified, since this indicates a logic error.
|
||||||
pub fn lower(&self, fallback_src_addrs: &[Cidr]) -> Result<IpRepr> {
|
pub fn lower(&self, fallback_src_addrs: &[Cidr]) -> Result<Repr> {
|
||||||
match self {
|
match self {
|
||||||
&IpRepr::Unspecified {
|
&Repr::Unspecified {
|
||||||
src_addr: Address::Ipv4(src_addr),
|
src_addr: Address::Ipv4(src_addr),
|
||||||
dst_addr: Address::Ipv4(dst_addr),
|
dst_addr: Address::Ipv4(dst_addr),
|
||||||
protocol, payload_len, ttl
|
protocol, payload_len, ttl
|
||||||
} => {
|
} => {
|
||||||
Ok(IpRepr::Ipv4(Ipv4Repr {
|
Ok(Repr::Ipv4(Ipv4Repr {
|
||||||
src_addr: src_addr,
|
src_addr: src_addr,
|
||||||
dst_addr: dst_addr,
|
dst_addr: dst_addr,
|
||||||
protocol: protocol,
|
protocol: protocol,
|
||||||
@ -367,7 +367,7 @@ impl IpRepr {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
&IpRepr::Unspecified {
|
&Repr::Unspecified {
|
||||||
src_addr: Address::Unspecified,
|
src_addr: Address::Unspecified,
|
||||||
dst_addr: Address::Ipv4(dst_addr),
|
dst_addr: Address::Ipv4(dst_addr),
|
||||||
protocol, payload_len, ttl
|
protocol, payload_len, ttl
|
||||||
@ -382,38 +382,38 @@ impl IpRepr {
|
|||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(IpRepr::Ipv4(Ipv4Repr {
|
Ok(Repr::Ipv4(Ipv4Repr {
|
||||||
src_addr: src_addr.ok_or(Error::Unaddressable)?,
|
src_addr: src_addr.ok_or(Error::Unaddressable)?,
|
||||||
dst_addr, protocol, payload_len, ttl
|
dst_addr, protocol, payload_len, ttl
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
&IpRepr::Unspecified { dst_addr: Address::Unspecified, .. } =>
|
&Repr::Unspecified { dst_addr: Address::Unspecified, .. } =>
|
||||||
panic!("unspecified destination IP address"),
|
panic!("unspecified destination IP address"),
|
||||||
|
|
||||||
// &IpRepr::Unspecified { .. } =>
|
// &Repr::Unspecified { .. } =>
|
||||||
// panic!("source and destination IP address families do not match"),
|
// panic!("source and destination IP address families do not match"),
|
||||||
|
|
||||||
&IpRepr::Ipv4(mut repr) => {
|
&Repr::Ipv4(mut repr) => {
|
||||||
if repr.src_addr.is_unspecified() {
|
if repr.src_addr.is_unspecified() {
|
||||||
for cidr in fallback_src_addrs {
|
for cidr in fallback_src_addrs {
|
||||||
match cidr.address() {
|
match cidr.address() {
|
||||||
Address::Ipv4(addr) => {
|
Address::Ipv4(addr) => {
|
||||||
repr.src_addr = addr;
|
repr.src_addr = addr;
|
||||||
return Ok(IpRepr::Ipv4(repr));
|
return Ok(Repr::Ipv4(repr));
|
||||||
}
|
}
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Error::Unaddressable)
|
Err(Error::Unaddressable)
|
||||||
} else {
|
} else {
|
||||||
Ok(IpRepr::Ipv4(repr))
|
Ok(Repr::Ipv4(repr))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
&IpRepr::__Nonexhaustive |
|
&Repr::__Nonexhaustive |
|
||||||
&IpRepr::Unspecified { src_addr: Address::__Nonexhaustive, .. } |
|
&Repr::Unspecified { src_addr: Address::__Nonexhaustive, .. } |
|
||||||
&IpRepr::Unspecified { dst_addr: Address::__Nonexhaustive, .. } =>
|
&Repr::Unspecified { dst_addr: Address::__Nonexhaustive, .. } =>
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -424,11 +424,11 @@ impl IpRepr {
|
|||||||
/// This function panics if invoked on an unspecified representation.
|
/// This function panics if invoked on an unspecified representation.
|
||||||
pub fn buffer_len(&self) -> usize {
|
pub fn buffer_len(&self) -> usize {
|
||||||
match self {
|
match self {
|
||||||
&IpRepr::Unspecified { .. } =>
|
&Repr::Unspecified { .. } =>
|
||||||
panic!("unspecified IP representation"),
|
panic!("unspecified IP representation"),
|
||||||
&IpRepr::Ipv4(repr) =>
|
&Repr::Ipv4(repr) =>
|
||||||
repr.buffer_len(),
|
repr.buffer_len(),
|
||||||
&IpRepr::__Nonexhaustive =>
|
&Repr::__Nonexhaustive =>
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -439,11 +439,11 @@ impl IpRepr {
|
|||||||
/// This function panics if invoked on an unspecified representation.
|
/// This function panics if invoked on an unspecified representation.
|
||||||
pub fn emit<T: AsRef<[u8]> + AsMut<[u8]>>(&self, buffer: T, checksum_caps: &ChecksumCapabilities) {
|
pub fn emit<T: AsRef<[u8]> + AsMut<[u8]>>(&self, buffer: T, checksum_caps: &ChecksumCapabilities) {
|
||||||
match self {
|
match self {
|
||||||
&IpRepr::Unspecified { .. } =>
|
&Repr::Unspecified { .. } =>
|
||||||
panic!("unspecified IP representation"),
|
panic!("unspecified IP representation"),
|
||||||
&IpRepr::Ipv4(repr) =>
|
&Repr::Ipv4(repr) =>
|
||||||
repr.emit(&mut Ipv4Packet::new(buffer), &checksum_caps),
|
repr.emit(&mut Ipv4Packet::new(buffer), &checksum_caps),
|
||||||
&IpRepr::__Nonexhaustive =>
|
&Repr::__Nonexhaustive =>
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -538,14 +538,14 @@ mod test {
|
|||||||
let payload_len = 10;
|
let payload_len = 10;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
IpRepr::Unspecified{
|
Repr::Unspecified{
|
||||||
src_addr: IpAddress::Ipv4(ip_addr_a),
|
src_addr: IpAddress::Ipv4(ip_addr_a),
|
||||||
dst_addr: IpAddress::Ipv4(ip_addr_b),
|
dst_addr: IpAddress::Ipv4(ip_addr_b),
|
||||||
protocol: proto,
|
protocol: proto,
|
||||||
ttl: 0x2a,
|
ttl: 0x2a,
|
||||||
payload_len,
|
payload_len,
|
||||||
}.lower(&[]),
|
}.lower(&[]),
|
||||||
Ok(IpRepr::Ipv4(Ipv4Repr{
|
Ok(Repr::Ipv4(Ipv4Repr{
|
||||||
src_addr: ip_addr_a,
|
src_addr: ip_addr_a,
|
||||||
dst_addr: ip_addr_b,
|
dst_addr: ip_addr_b,
|
||||||
protocol: proto,
|
protocol: proto,
|
||||||
@ -555,7 +555,7 @@ mod test {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
IpRepr::Unspecified{
|
Repr::Unspecified{
|
||||||
src_addr: IpAddress::Unspecified,
|
src_addr: IpAddress::Unspecified,
|
||||||
dst_addr: IpAddress::Ipv4(ip_addr_b),
|
dst_addr: IpAddress::Ipv4(ip_addr_b),
|
||||||
protocol: proto,
|
protocol: proto,
|
||||||
@ -566,14 +566,14 @@ mod test {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
IpRepr::Unspecified{
|
Repr::Unspecified{
|
||||||
src_addr: IpAddress::Unspecified,
|
src_addr: IpAddress::Unspecified,
|
||||||
dst_addr: IpAddress::Ipv4(ip_addr_b),
|
dst_addr: IpAddress::Ipv4(ip_addr_b),
|
||||||
protocol: proto,
|
protocol: proto,
|
||||||
ttl: 64,
|
ttl: 64,
|
||||||
payload_len
|
payload_len
|
||||||
}.lower(&[IpCidr::new(IpAddress::Ipv4(ip_addr_a), 24)]),
|
}.lower(&[IpCidr::new(IpAddress::Ipv4(ip_addr_a), 24)]),
|
||||||
Ok(IpRepr::Ipv4(Ipv4Repr{
|
Ok(Repr::Ipv4(Ipv4Repr{
|
||||||
src_addr: ip_addr_a,
|
src_addr: ip_addr_a,
|
||||||
dst_addr: ip_addr_b,
|
dst_addr: ip_addr_b,
|
||||||
protocol: proto,
|
protocol: proto,
|
||||||
@ -583,14 +583,14 @@ mod test {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
IpRepr::Ipv4(Ipv4Repr{
|
Repr::Ipv4(Ipv4Repr{
|
||||||
src_addr: ip_addr_a,
|
src_addr: ip_addr_a,
|
||||||
dst_addr: ip_addr_b,
|
dst_addr: ip_addr_b,
|
||||||
protocol: proto,
|
protocol: proto,
|
||||||
ttl: 255,
|
ttl: 255,
|
||||||
payload_len
|
payload_len
|
||||||
}).lower(&[]),
|
}).lower(&[]),
|
||||||
Ok(IpRepr::Ipv4(Ipv4Repr{
|
Ok(Repr::Ipv4(Ipv4Repr{
|
||||||
src_addr: ip_addr_a,
|
src_addr: ip_addr_a,
|
||||||
dst_addr: ip_addr_b,
|
dst_addr: ip_addr_b,
|
||||||
protocol: proto,
|
protocol: proto,
|
||||||
@ -600,7 +600,7 @@ mod test {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
IpRepr::Ipv4(Ipv4Repr{
|
Repr::Ipv4(Ipv4Repr{
|
||||||
src_addr: Ipv4Address::UNSPECIFIED,
|
src_addr: Ipv4Address::UNSPECIFIED,
|
||||||
dst_addr: ip_addr_b,
|
dst_addr: ip_addr_b,
|
||||||
protocol: proto,
|
protocol: proto,
|
||||||
@ -611,14 +611,14 @@ mod test {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
IpRepr::Ipv4(Ipv4Repr{
|
Repr::Ipv4(Ipv4Repr{
|
||||||
src_addr: Ipv4Address::UNSPECIFIED,
|
src_addr: Ipv4Address::UNSPECIFIED,
|
||||||
dst_addr: ip_addr_b,
|
dst_addr: ip_addr_b,
|
||||||
protocol: proto,
|
protocol: proto,
|
||||||
ttl: 64,
|
ttl: 64,
|
||||||
payload_len
|
payload_len
|
||||||
}).lower(&[IpCidr::new(IpAddress::Ipv4(ip_addr_a), 24)]),
|
}).lower(&[IpCidr::new(IpAddress::Ipv4(ip_addr_a), 24)]),
|
||||||
Ok(IpRepr::Ipv4(Ipv4Repr{
|
Ok(Repr::Ipv4(Ipv4Repr{
|
||||||
src_addr: ip_addr_a,
|
src_addr: ip_addr_a,
|
||||||
dst_addr: ip_addr_b,
|
dst_addr: ip_addr_b,
|
||||||
protocol: proto,
|
protocol: proto,
|
||||||
|
@ -100,7 +100,7 @@ pub use self::ip::Version as IpVersion;
|
|||||||
pub use self::ip::Protocol as IpProtocol;
|
pub use self::ip::Protocol as IpProtocol;
|
||||||
pub use self::ip::Address as IpAddress;
|
pub use self::ip::Address as IpAddress;
|
||||||
pub use self::ip::Endpoint as IpEndpoint;
|
pub use self::ip::Endpoint as IpEndpoint;
|
||||||
pub use self::ip::IpRepr as IpRepr;
|
pub use self::ip::Repr as IpRepr;
|
||||||
pub use self::ip::Cidr as IpCidr;
|
pub use self::ip::Cidr as IpCidr;
|
||||||
|
|
||||||
pub use self::ipv4::Address as Ipv4Address;
|
pub use self::ipv4::Address as Ipv4Address;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user