Skip to content

Commit a54f51c

Browse files
committed
rewrite IpPacket
1 parent d63d409 commit a54f51c

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ defmt = [ "dep:defmt", "heapless/defmt", "heapless/defmt-impl" ]
5050
"proto-igmp" = ["proto-ipv4"]
5151
"proto-dhcpv4" = ["proto-ipv4"]
5252
"proto-ipv6" = []
53-
"proto-rpl" = []
53+
"proto-ipv6-hbh" = ["proto-ipv6"]
54+
"proto-ipv6-fragmentation" = ["proto-ipv6", "_proto-fragmentation"]
55+
"proto-ipv6-routing" = ["proto-ipv6"]
56+
"proto-rpl" = ["proto-ipv6-hbh", "proto-ipv6-routing"]
5457
"proto-sixlowpan" = ["proto-ipv6"]
5558
"proto-sixlowpan-fragmentation" = ["proto-sixlowpan", "_proto-fragmentation"]
5659
"proto-dns" = []

src/iface/interface/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,7 @@ impl InterfaceInner {
16741674

16751675
// Emit the IP header to the buffer.
16761676
emit_ip(&ip_repr, &mut frag.buffer);
1677+
16771678
let mut ipv4_packet = Ipv4PacketWire::new_unchecked(&mut frag.buffer[..]);
16781679
frag.ipv4.ident = ipv4_id;
16791680
ipv4_packet.set_ident(ipv4_id);

src/iface/ip_packet.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,9 @@ impl<'p> IpPacket<'p> {
2424
pub(crate) fn new(ip_repr: IpRepr, payload: IpPayload<'p>) -> Self {
2525
match ip_repr {
2626
#[cfg(feature = "proto-ipv4")]
27-
IpRepr::Ipv4(header) => Self::Ipv4(Ipv4Packet { header, payload }),
27+
IpRepr::Ipv4(header) => Self::new_ipv4(header, payload),
2828
#[cfg(feature = "proto-ipv6")]
29-
IpRepr::Ipv6(header) => Self::Ipv6(Ipv6Packet {
30-
header,
31-
hop_by_hop: None,
32-
fragment: None,
33-
routing: None,
34-
payload,
35-
}),
29+
IpRepr::Ipv6(header) => Self::new_ipv6(header, payload),
3630
}
3731
}
3832

@@ -48,8 +42,11 @@ impl<'p> IpPacket<'p> {
4842
pub(crate) fn new_ipv6(ip_repr: Ipv6Repr, payload: IpPayload<'p>) -> Self {
4943
Self::Ipv6(Ipv6Packet {
5044
header: ip_repr,
45+
#[cfg(feature = "proto-ipv6-hbh")]
5146
hop_by_hop: None,
47+
#[cfg(feature = "proto-ipv6-fragmentation")]
5248
fragment: None,
49+
#[cfg(feature = "proto-ipv6-routing")]
5350
routing: None,
5451
payload,
5552
})
@@ -157,8 +154,11 @@ pub(crate) struct Ipv4Packet<'p> {
157154
#[cfg(feature = "proto-ipv6")]
158155
pub(crate) struct Ipv6Packet<'p> {
159156
header: Ipv6Repr,
157+
#[cfg(feature = "proto-ipv6-hbh")]
160158
hop_by_hop: Option<Ipv6HopByHopRepr<'p>>,
159+
#[cfg(feature = "proto-ipv6-fragmentation")]
161160
fragment: Option<Ipv6FragmentRepr>,
161+
#[cfg(feature = "proto-ipv6-routing")]
162162
routing: Option<Ipv6RoutingRepr<'p>>,
163163
payload: IpPayload<'p>,
164164
}

0 commit comments

Comments
 (0)