@@ -86,7 +86,9 @@ pub(crate) trait AddressExt {
86
86
/// Query whether the IPv6 address is an [unicast address].
87
87
///
88
88
/// [unicast address]: https://tools.ietf.org/html/rfc4291#section-2.5
89
- fn is_unicast ( & self ) -> bool ;
89
+ ///
90
+ /// `x_` prefix is to avoid a collision with the still-unstable method in `core::ip`.
91
+ fn x_is_unicast ( & self ) -> bool ;
90
92
91
93
/// Query whether the IPv6 address is a [global unicast address].
92
94
///
@@ -101,7 +103,9 @@ pub(crate) trait AddressExt {
101
103
/// Query whether the IPv6 address is a [Unique Local Address] (ULA).
102
104
///
103
105
/// [Unique Local Address]: https://tools.ietf.org/html/rfc4193
104
- fn is_unique_local ( & self ) -> bool ;
106
+ ///
107
+ /// `x_` prefix is to avoid a collision with the still-unstable method in `core::ip`.
108
+ fn x_is_unique_local ( & self ) -> bool ;
105
109
106
110
/// Helper function used to mask an address given a prefix.
107
111
///
@@ -117,7 +121,9 @@ pub(crate) trait AddressExt {
117
121
fn solicited_node ( & self ) -> Address ;
118
122
119
123
/// Return the scope of the address.
120
- fn multicast_scope ( & self ) -> MulticastScope ;
124
+ ///
125
+ /// `x_` prefix is to avoid a collision with the still-unstable method in `core::ip`.
126
+ fn x_multicast_scope ( & self ) -> MulticastScope ;
121
127
122
128
/// If `self` is a CIDR-compatible subnet mask, return `Some(prefix_len)`,
123
129
/// where `prefix_len` is the number of leading zeroes. Return `None` otherwise.
@@ -131,7 +137,7 @@ impl AddressExt for Address {
131
137
Address :: from ( bytes)
132
138
}
133
139
134
- fn is_unicast ( & self ) -> bool {
140
+ fn x_is_unicast ( & self ) -> bool {
135
141
!( self . is_multicast ( ) || self . is_unspecified ( ) )
136
142
}
137
143
@@ -143,7 +149,7 @@ impl AddressExt for Address {
143
149
self . octets ( ) [ 0 ..8 ] == [ 0xfe , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ]
144
150
}
145
151
146
- fn is_unique_local ( & self ) -> bool {
152
+ fn x_is_unique_local ( & self ) -> bool {
147
153
( self . octets ( ) [ 0 ] & 0b1111_1110 ) == 0xfc
148
154
}
149
155
@@ -163,22 +169,22 @@ impl AddressExt for Address {
163
169
}
164
170
165
171
fn solicited_node ( & self ) -> Address {
166
- assert ! ( self . is_unicast ( ) ) ;
172
+ assert ! ( self . x_is_unicast ( ) ) ;
167
173
let o = self . octets ( ) ;
168
174
Address :: from ( [
169
175
0xff , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0xFF , o[ 13 ] ,
170
176
o[ 14 ] , o[ 15 ] ,
171
177
] )
172
178
}
173
179
174
- fn multicast_scope ( & self ) -> MulticastScope {
180
+ fn x_multicast_scope ( & self ) -> MulticastScope {
175
181
if self . is_multicast ( ) {
176
182
return MulticastScope :: from ( self . octets ( ) [ 1 ] & 0b1111 ) ;
177
183
}
178
184
179
185
if self . is_link_local ( ) {
180
186
MulticastScope :: LinkLocal
181
- } else if self . is_unique_local ( ) || self . is_global_unicast ( ) {
187
+ } else if self . x_is_unique_local ( ) || self . is_global_unicast ( ) {
182
188
// ULA are considered global scope
183
189
// https://www.rfc-editor.org/rfc/rfc6724#section-3.1
184
190
MulticastScope :: Global
@@ -680,13 +686,13 @@ pub(crate) mod test {
680
686
assert ! ( LINK_LOCAL_ALL_ROUTERS . is_multicast( ) ) ;
681
687
assert ! ( !LINK_LOCAL_ALL_ROUTERS . is_link_local( ) ) ;
682
688
assert ! ( !LINK_LOCAL_ALL_ROUTERS . is_loopback( ) ) ;
683
- assert ! ( !LINK_LOCAL_ALL_ROUTERS . is_unique_local ( ) ) ;
689
+ assert ! ( !LINK_LOCAL_ALL_ROUTERS . x_is_unique_local ( ) ) ;
684
690
assert ! ( !LINK_LOCAL_ALL_ROUTERS . is_global_unicast( ) ) ;
685
691
assert ! ( !LINK_LOCAL_ALL_NODES . is_unspecified( ) ) ;
686
692
assert ! ( LINK_LOCAL_ALL_NODES . is_multicast( ) ) ;
687
693
assert ! ( !LINK_LOCAL_ALL_NODES . is_link_local( ) ) ;
688
694
assert ! ( !LINK_LOCAL_ALL_NODES . is_loopback( ) ) ;
689
- assert ! ( !LINK_LOCAL_ALL_NODES . is_unique_local ( ) ) ;
695
+ assert ! ( !LINK_LOCAL_ALL_NODES . x_is_unique_local ( ) ) ;
690
696
assert ! ( !LINK_LOCAL_ALL_NODES . is_global_unicast( ) ) ;
691
697
}
692
698
@@ -696,7 +702,7 @@ pub(crate) mod test {
696
702
assert ! ( !LINK_LOCAL_ADDR . is_multicast( ) ) ;
697
703
assert ! ( LINK_LOCAL_ADDR . is_link_local( ) ) ;
698
704
assert ! ( !LINK_LOCAL_ADDR . is_loopback( ) ) ;
699
- assert ! ( !LINK_LOCAL_ADDR . is_unique_local ( ) ) ;
705
+ assert ! ( !LINK_LOCAL_ADDR . x_is_unique_local ( ) ) ;
700
706
assert ! ( !LINK_LOCAL_ADDR . is_global_unicast( ) ) ;
701
707
}
702
708
@@ -706,7 +712,7 @@ pub(crate) mod test {
706
712
assert ! ( !Address :: LOCALHOST . is_multicast( ) ) ;
707
713
assert ! ( !Address :: LOCALHOST . is_link_local( ) ) ;
708
714
assert ! ( Address :: LOCALHOST . is_loopback( ) ) ;
709
- assert ! ( !Address :: LOCALHOST . is_unique_local ( ) ) ;
715
+ assert ! ( !Address :: LOCALHOST . x_is_unique_local ( ) ) ;
710
716
assert ! ( !Address :: LOCALHOST . is_global_unicast( ) ) ;
711
717
}
712
718
@@ -716,7 +722,7 @@ pub(crate) mod test {
716
722
assert ! ( !UNIQUE_LOCAL_ADDR . is_multicast( ) ) ;
717
723
assert ! ( !UNIQUE_LOCAL_ADDR . is_link_local( ) ) ;
718
724
assert ! ( !UNIQUE_LOCAL_ADDR . is_loopback( ) ) ;
719
- assert ! ( UNIQUE_LOCAL_ADDR . is_unique_local ( ) ) ;
725
+ assert ! ( UNIQUE_LOCAL_ADDR . x_is_unique_local ( ) ) ;
720
726
assert ! ( !UNIQUE_LOCAL_ADDR . is_global_unicast( ) ) ;
721
727
}
722
728
@@ -726,7 +732,7 @@ pub(crate) mod test {
726
732
assert ! ( !GLOBAL_UNICAST_ADDR . is_multicast( ) ) ;
727
733
assert ! ( !GLOBAL_UNICAST_ADDR . is_link_local( ) ) ;
728
734
assert ! ( !GLOBAL_UNICAST_ADDR . is_loopback( ) ) ;
729
- assert ! ( !GLOBAL_UNICAST_ADDR . is_unique_local ( ) ) ;
735
+ assert ! ( !GLOBAL_UNICAST_ADDR . x_is_unique_local ( ) ) ;
730
736
assert ! ( GLOBAL_UNICAST_ADDR . is_global_unicast( ) ) ;
731
737
}
732
738
@@ -903,46 +909,52 @@ pub(crate) mod test {
903
909
fn test_scope ( ) {
904
910
use super :: * ;
905
911
assert_eq ! (
906
- Address :: new( 0xff01 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . multicast_scope ( ) ,
912
+ Address :: new( 0xff01 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . x_multicast_scope ( ) ,
907
913
MulticastScope :: InterfaceLocal
908
914
) ;
909
915
assert_eq ! (
910
- Address :: new( 0xff02 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . multicast_scope ( ) ,
916
+ Address :: new( 0xff02 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . x_multicast_scope ( ) ,
911
917
MulticastScope :: LinkLocal
912
918
) ;
913
919
assert_eq ! (
914
- Address :: new( 0xff03 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . multicast_scope ( ) ,
920
+ Address :: new( 0xff03 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . x_multicast_scope ( ) ,
915
921
MulticastScope :: Unknown
916
922
) ;
917
923
assert_eq ! (
918
- Address :: new( 0xff04 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . multicast_scope ( ) ,
924
+ Address :: new( 0xff04 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . x_multicast_scope ( ) ,
919
925
MulticastScope :: AdminLocal
920
926
) ;
921
927
assert_eq ! (
922
- Address :: new( 0xff05 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . multicast_scope ( ) ,
928
+ Address :: new( 0xff05 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . x_multicast_scope ( ) ,
923
929
MulticastScope :: SiteLocal
924
930
) ;
925
931
assert_eq ! (
926
- Address :: new( 0xff08 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . multicast_scope ( ) ,
932
+ Address :: new( 0xff08 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . x_multicast_scope ( ) ,
927
933
MulticastScope :: OrganizationLocal
928
934
) ;
929
935
assert_eq ! (
930
- Address :: new( 0xff0e , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . multicast_scope ( ) ,
936
+ Address :: new( 0xff0e , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) . x_multicast_scope ( ) ,
931
937
MulticastScope :: Global
932
938
) ;
933
939
934
940
assert_eq ! (
935
- LINK_LOCAL_ALL_NODES . multicast_scope ( ) ,
941
+ LINK_LOCAL_ALL_NODES . x_multicast_scope ( ) ,
936
942
MulticastScope :: LinkLocal
937
943
) ;
938
944
939
945
// For source address selection, unicast addresses also have a scope:
940
- assert_eq ! ( LINK_LOCAL_ADDR . multicast_scope( ) , MulticastScope :: LinkLocal ) ;
941
946
assert_eq ! (
942
- GLOBAL_UNICAST_ADDR . multicast_scope( ) ,
947
+ LINK_LOCAL_ADDR . x_multicast_scope( ) ,
948
+ MulticastScope :: LinkLocal
949
+ ) ;
950
+ assert_eq ! (
951
+ GLOBAL_UNICAST_ADDR . x_multicast_scope( ) ,
952
+ MulticastScope :: Global
953
+ ) ;
954
+ assert_eq ! (
955
+ UNIQUE_LOCAL_ADDR . x_multicast_scope( ) ,
943
956
MulticastScope :: Global
944
957
) ;
945
- assert_eq ! ( UNIQUE_LOCAL_ADDR . multicast_scope( ) , MulticastScope :: Global ) ;
946
958
}
947
959
948
960
static REPR_PACKET_BYTES : [ u8 ; 52 ] = [
0 commit comments