@@ -29,6 +29,80 @@ fn parse_ipv6(data: &[u8]) -> crate::wire::Result<Packet<'_>> {
29
29
}
30
30
}
31
31
32
+ #[ rstest]
33
+ #[ case:: ip( Medium :: Ip ) ]
34
+ #[ cfg( feature = "medium-ip" ) ]
35
+ #[ case:: ethernet( Medium :: Ethernet ) ]
36
+ #[ cfg( feature = "medium-ethernet" ) ]
37
+ #[ case:: ieee802154( Medium :: Ieee802154 ) ]
38
+ #[ cfg( feature = "medium-ieee802154" ) ]
39
+ fn any_ip ( #[ case] medium : Medium ) {
40
+ // An empty echo request with destination address fdbe::3, which is not part of the interface
41
+ // address list.
42
+ let data = [
43
+ 0x60 , 0x0 , 0x0 , 0x0 , 0x0 , 0x8 , 0x3a , 0x40 , 0xfd , 0xbe , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
44
+ 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x2 , 0xfd , 0xbe , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
45
+ 0x0 , 0x0 , 0x0 , 0x0 , 0x3 , 0x80 , 0x0 , 0x84 , 0x3a , 0x0 , 0x0 , 0x0 , 0x0 ,
46
+ ] ;
47
+
48
+ assert_eq ! (
49
+ parse_ipv6( & data) ,
50
+ Ok ( Packet :: new_ipv6(
51
+ Ipv6Repr {
52
+ src_addr: Ipv6Address :: from_parts( & [ 0xfdbe , 0 , 0 , 0 , 0 , 0 , 0 , 0x0002 ] ) ,
53
+ dst_addr: Ipv6Address :: from_parts( & [ 0xfdbe , 0 , 0 , 0 , 0 , 0 , 0 , 0x0003 ] ) ,
54
+ hop_limit: 64 ,
55
+ next_header: IpProtocol :: Icmpv6 ,
56
+ payload_len: 8 ,
57
+ } ,
58
+ IpPayload :: Icmpv6 ( Icmpv6Repr :: EchoRequest {
59
+ ident: 0 ,
60
+ seq_no: 0 ,
61
+ data: b"" ,
62
+ } )
63
+ ) )
64
+ ) ;
65
+
66
+ let ( mut iface, mut sockets, _device) = setup ( medium) ;
67
+
68
+ // Add a route to the interface, otherwise, we don't know if the packet is routed localy.
69
+ iface. routes_mut ( ) . update ( |routes| {
70
+ routes
71
+ . push ( crate :: iface:: Route {
72
+ cidr : IpCidr :: Ipv6 ( Ipv6Cidr :: new (
73
+ Ipv6Address :: new ( 0xfdbe , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ,
74
+ 64 ,
75
+ ) ) ,
76
+ via_router : IpAddress :: Ipv6 ( Ipv6Address :: from_parts ( & [
77
+ 0xfdbe , 0 , 0 , 0 , 0 , 0 , 0 , 0x0001 ,
78
+ ] ) ) ,
79
+ preferred_until : None ,
80
+ expires_at : None ,
81
+ } )
82
+ . unwrap ( ) ;
83
+ } ) ;
84
+
85
+ assert_eq ! (
86
+ iface. inner. process_ipv6(
87
+ & mut sockets,
88
+ PacketMeta :: default ( ) ,
89
+ & Ipv6Packet :: new_checked( & data[ ..] ) . unwrap( )
90
+ ) ,
91
+ None
92
+ ) ;
93
+
94
+ // Accept any IP:
95
+ iface. set_any_ip ( true ) ;
96
+ assert ! ( iface
97
+ . inner
98
+ . process_ipv6(
99
+ & mut sockets,
100
+ PacketMeta :: default ( ) ,
101
+ & Ipv6Packet :: new_checked( & data[ ..] ) . unwrap( )
102
+ )
103
+ . is_some( ) ) ;
104
+ }
105
+
32
106
#[ rstest]
33
107
#[ case:: ip( Medium :: Ip ) ]
34
108
#[ cfg( feature = "medium-ip" ) ]
0 commit comments