@@ -138,6 +138,58 @@ func TestAdd2Int(t *testing.T) {
138
138
IntIP {4 , - math .MaxInt64 + 0x010203FF , 0 },
139
139
},
140
140
},
141
+ {
142
+ input : "::ffff:1.2.3.4" ,
143
+ want : Range {
144
+ IntIP {16 , - math .MaxInt64 + 0x000000000000ffff , - math .MaxInt64 + 0x01020304 },
145
+ IntIP {16 , - math .MaxInt64 + 0x000000000000ffff , - math .MaxInt64 + 0x01020304 },
146
+ },
147
+ },
148
+ {
149
+ input : "::ffff:1.2.3.0/120" ,
150
+ want : Range {
151
+ IntIP {16 , - math .MaxInt64 + 0x000000000000ffff , - math .MaxInt64 + 0x01020300 },
152
+ IntIP {16 , - math .MaxInt64 + 0x000000000000ffff , - math .MaxInt64 + 0x010203FF },
153
+ },
154
+ },
155
+ {
156
+ input : "1.2.3.4/32" ,
157
+ want : Range {
158
+ IntIP {4 , - math .MaxInt64 + 0x01020304 , 0 },
159
+ IntIP {4 , - math .MaxInt64 + 0x01020304 , 0 },
160
+ },
161
+ },
162
+ {
163
+ input : "2001:db8::/128" ,
164
+ want : Range {
165
+ IntIP {16 , - math .MaxInt64 + 0x20010DB800000000 , - math .MaxInt64 },
166
+ IntIP {16 , - math .MaxInt64 + 0x20010DB800000000 , - math .MaxInt64 },
167
+ },
168
+ },
169
+
170
+ {
171
+ input : "255.255.255.255" ,
172
+ want : Range {
173
+ IntIP {4 , - math .MaxInt64 + 0xFFFFFFFF , 0 },
174
+ IntIP {4 , - math .MaxInt64 + 0xFFFFFFFF , 0 },
175
+ },
176
+ },
177
+ {
178
+ input : "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" ,
179
+ want : Range {
180
+ IntIP {16 , math .MaxInt64 , math .MaxInt64 },
181
+ IntIP {16 , math .MaxInt64 , math .MaxInt64 },
182
+ },
183
+ },
184
+
185
+ {
186
+ input : "2001:db8:0::/64" ,
187
+ want : Range {
188
+ IntIP {16 , - math .MaxInt64 + 0x20010DB800000000 , - math .MaxInt64 },
189
+ IntIP {16 , - math .MaxInt64 + 0x20010DB800000000 , math .MaxInt64 },
190
+ },
191
+ },
192
+
141
193
{
142
194
input : "xxx/24" ,
143
195
wantErr : `netip.ParsePrefix("xxx/24"): ParseAddr("xxx"): unable to parse IP` ,
@@ -146,6 +198,10 @@ func TestAdd2Int(t *testing.T) {
146
198
input : "xxx2" ,
147
199
wantErr : `ParseAddr("xxx2"): unable to parse IP` ,
148
200
},
201
+ {
202
+ input : "::ffff:1.2.3.0/95" , // mask < 96
203
+ wantErr : "prefix with 4in6 address must have mask >= 96" ,
204
+ },
149
205
}
150
206
151
207
for _ , tc := range tests {
0 commit comments