1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright Amazon.com Inc. or its affiliates. */
4 #include <sys/socket.h>
5 #include <netinet/in.h>
7 #include "../kselftest_harness.h"
9 static const __u32 in4addr_any
= INADDR_ANY
;
10 static const __u32 in4addr_loopback
= INADDR_LOOPBACK
;
11 static const struct in6_addr in6addr_v4mapped_any
= {
19 static const struct in6_addr in6addr_v4mapped_loopback
= {
30 FIXTURE(bind_wildcard
)
33 socklen_t addrlen
[NR_SOCKETS
];
36 struct sockaddr_in addr4
;
37 struct sockaddr_in6 addr6
;
41 FIXTURE_VARIANT(bind_wildcard
)
43 sa_family_t family
[2];
47 /* 6 bind() calls below follow two bind() for the defined 2 addresses:
56 int expected_errno
[NR_SOCKETS
];
57 int expected_reuse_errno
[NR_SOCKETS
];
61 FIXTURE_VARIANT_ADD(bind_wildcard
, v4_any_v4_local
)
63 .family
= {AF_INET
, AF_INET
},
64 .addr
= {&in4addr_any
, &in4addr_loopback
},
65 .expected_errno
= {0, EADDRINUSE
,
66 EADDRINUSE
, EADDRINUSE
,
68 EADDRINUSE
, EADDRINUSE
},
69 .expected_reuse_errno
= {0, 0,
70 EADDRINUSE
, EADDRINUSE
,
72 EADDRINUSE
, EADDRINUSE
},
75 FIXTURE_VARIANT_ADD(bind_wildcard
, v4_local_v4_any
)
77 .family
= {AF_INET
, AF_INET
},
78 .addr
= {&in4addr_loopback
, &in4addr_any
},
79 .expected_errno
= {0, EADDRINUSE
,
80 EADDRINUSE
, EADDRINUSE
,
82 EADDRINUSE
, EADDRINUSE
},
83 .expected_reuse_errno
= {0, 0,
84 EADDRINUSE
, EADDRINUSE
,
86 EADDRINUSE
, EADDRINUSE
},
90 FIXTURE_VARIANT_ADD(bind_wildcard
, v4_any_v6_any
)
92 .family
= {AF_INET
, AF_INET6
},
93 .addr
= {&in4addr_any
, &in6addr_any
},
94 .expected_errno
= {0, EADDRINUSE
,
95 EADDRINUSE
, EADDRINUSE
,
97 EADDRINUSE
, EADDRINUSE
},
98 .expected_reuse_errno
= {0, 0,
99 EADDRINUSE
, EADDRINUSE
,
100 EADDRINUSE
, EADDRINUSE
,
101 EADDRINUSE
, EADDRINUSE
},
104 FIXTURE_VARIANT_ADD(bind_wildcard
, v4_any_v6_any_only
)
106 .family
= {AF_INET
, AF_INET6
},
107 .addr
= {&in4addr_any
, &in6addr_any
},
108 .ipv6_only
= {false, true},
109 .expected_errno
= {0, 0,
110 EADDRINUSE
, EADDRINUSE
,
111 EADDRINUSE
, EADDRINUSE
,
112 EADDRINUSE
, EADDRINUSE
},
113 .expected_reuse_errno
= {0, 0,
114 EADDRINUSE
, EADDRINUSE
,
115 EADDRINUSE
, EADDRINUSE
,
116 EADDRINUSE
, EADDRINUSE
},
119 FIXTURE_VARIANT_ADD(bind_wildcard
, v4_any_v6_local
)
121 .family
= {AF_INET
, AF_INET6
},
122 .addr
= {&in4addr_any
, &in6addr_loopback
},
123 .expected_errno
= {0, 0,
124 EADDRINUSE
, EADDRINUSE
,
125 EADDRINUSE
, EADDRINUSE
,
126 EADDRINUSE
, EADDRINUSE
},
127 .expected_reuse_errno
= {0, 0,
128 EADDRINUSE
, EADDRINUSE
,
129 EADDRINUSE
, EADDRINUSE
,
130 EADDRINUSE
, EADDRINUSE
},
133 FIXTURE_VARIANT_ADD(bind_wildcard
, v4_any_v6_v4mapped_any
)
135 .family
= {AF_INET
, AF_INET6
},
136 .addr
= {&in4addr_any
, &in6addr_v4mapped_any
},
137 .expected_errno
= {0, EADDRINUSE
,
138 EADDRINUSE
, EADDRINUSE
,
140 EADDRINUSE
, EADDRINUSE
},
141 .expected_reuse_errno
= {0, 0,
142 EADDRINUSE
, EADDRINUSE
,
144 EADDRINUSE
, EADDRINUSE
},
147 FIXTURE_VARIANT_ADD(bind_wildcard
, v4_any_v6_v4mapped_local
)
149 .family
= {AF_INET
, AF_INET6
},
150 .addr
= {&in4addr_any
, &in6addr_v4mapped_loopback
},
151 .expected_errno
= {0, EADDRINUSE
,
152 EADDRINUSE
, EADDRINUSE
,
154 EADDRINUSE
, EADDRINUSE
},
155 .expected_reuse_errno
= {0, 0,
156 EADDRINUSE
, EADDRINUSE
,
158 EADDRINUSE
, EADDRINUSE
},
161 FIXTURE_VARIANT_ADD(bind_wildcard
, v4_local_v6_any
)
163 .family
= {AF_INET
, AF_INET6
},
164 .addr
= {&in4addr_loopback
, &in6addr_any
},
165 .expected_errno
= {0, EADDRINUSE
,
166 EADDRINUSE
, EADDRINUSE
,
168 EADDRINUSE
, EADDRINUSE
},
169 .expected_reuse_errno
= {0, 0,
170 EADDRINUSE
, EADDRINUSE
,
171 EADDRINUSE
, EADDRINUSE
,
172 EADDRINUSE
, EADDRINUSE
},
175 FIXTURE_VARIANT_ADD(bind_wildcard
, v4_local_v6_any_only
)
177 .family
= {AF_INET
, AF_INET6
},
178 .addr
= {&in4addr_loopback
, &in6addr_any
},
179 .ipv6_only
= {false, true},
180 .expected_errno
= {0, 0,
181 EADDRINUSE
, EADDRINUSE
,
182 EADDRINUSE
, EADDRINUSE
,
183 EADDRINUSE
, EADDRINUSE
},
184 .expected_reuse_errno
= {0, 0,
185 EADDRINUSE
, EADDRINUSE
,
186 EADDRINUSE
, EADDRINUSE
,
187 EADDRINUSE
, EADDRINUSE
},
190 FIXTURE_VARIANT_ADD(bind_wildcard
, v4_local_v6_local
)
192 .family
= {AF_INET
, AF_INET6
},
193 .addr
= {&in4addr_loopback
, &in6addr_loopback
},
194 .expected_errno
= {0, 0,
195 EADDRINUSE
, EADDRINUSE
,
196 EADDRINUSE
, EADDRINUSE
,
197 EADDRINUSE
, EADDRINUSE
},
198 .expected_reuse_errno
= {0, 0,
199 EADDRINUSE
, EADDRINUSE
,
200 EADDRINUSE
, EADDRINUSE
,
201 EADDRINUSE
, EADDRINUSE
},
204 FIXTURE_VARIANT_ADD(bind_wildcard
, v4_local_v6_v4mapped_any
)
206 .family
= {AF_INET
, AF_INET6
},
207 .addr
= {&in4addr_loopback
, &in6addr_v4mapped_any
},
208 .expected_errno
= {0, EADDRINUSE
,
209 EADDRINUSE
, EADDRINUSE
,
211 EADDRINUSE
, EADDRINUSE
},
212 .expected_reuse_errno
= {0, 0,
213 EADDRINUSE
, EADDRINUSE
,
215 EADDRINUSE
, EADDRINUSE
},
218 FIXTURE_VARIANT_ADD(bind_wildcard
, v4_local_v6_v4mapped_local
)
220 .family
= {AF_INET
, AF_INET6
},
221 .addr
= {&in4addr_loopback
, &in6addr_v4mapped_loopback
},
222 .expected_errno
= {0, EADDRINUSE
,
223 EADDRINUSE
, EADDRINUSE
,
225 EADDRINUSE
, EADDRINUSE
},
226 .expected_reuse_errno
= {0, 0,
227 EADDRINUSE
, EADDRINUSE
,
229 EADDRINUSE
, EADDRINUSE
},
233 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_v4_any
)
235 .family
= {AF_INET6
, AF_INET
},
236 .addr
= {&in6addr_any
, &in4addr_any
},
237 .expected_errno
= {0, EADDRINUSE
,
238 EADDRINUSE
, EADDRINUSE
,
239 EADDRINUSE
, EADDRINUSE
,
240 EADDRINUSE
, EADDRINUSE
},
241 .expected_reuse_errno
= {0, 0,
242 EADDRINUSE
, EADDRINUSE
,
243 EADDRINUSE
, EADDRINUSE
,
244 EADDRINUSE
, EADDRINUSE
},
247 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_only_v4_any
)
249 .family
= {AF_INET6
, AF_INET
},
250 .addr
= {&in6addr_any
, &in4addr_any
},
251 .ipv6_only
= {true, false},
252 .expected_errno
= {0, 0,
253 EADDRINUSE
, EADDRINUSE
,
254 EADDRINUSE
, EADDRINUSE
,
255 EADDRINUSE
, EADDRINUSE
},
256 .expected_reuse_errno
= {0, 0,
257 EADDRINUSE
, EADDRINUSE
,
258 EADDRINUSE
, EADDRINUSE
,
259 EADDRINUSE
, EADDRINUSE
},
262 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_v4_local
)
264 .family
= {AF_INET6
, AF_INET
},
265 .addr
= {&in6addr_any
, &in4addr_loopback
},
266 .expected_errno
= {0, EADDRINUSE
,
267 EADDRINUSE
, EADDRINUSE
,
268 EADDRINUSE
, EADDRINUSE
,
269 EADDRINUSE
, EADDRINUSE
},
270 .expected_reuse_errno
= {0, 0,
271 EADDRINUSE
, EADDRINUSE
,
272 EADDRINUSE
, EADDRINUSE
,
273 EADDRINUSE
, EADDRINUSE
},
276 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_only_v4_local
)
278 .family
= {AF_INET6
, AF_INET
},
279 .addr
= {&in6addr_any
, &in4addr_loopback
},
280 .ipv6_only
= {true, false},
281 .expected_errno
= {0, 0,
282 EADDRINUSE
, EADDRINUSE
,
283 EADDRINUSE
, EADDRINUSE
,
284 EADDRINUSE
, EADDRINUSE
},
285 .expected_reuse_errno
= {0, 0,
286 EADDRINUSE
, EADDRINUSE
,
287 EADDRINUSE
, EADDRINUSE
,
288 EADDRINUSE
, EADDRINUSE
},
291 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_local_v4_any
)
293 .family
= {AF_INET6
, AF_INET
},
294 .addr
= {&in6addr_loopback
, &in4addr_any
},
295 .expected_errno
= {0, 0,
296 EADDRINUSE
, EADDRINUSE
,
297 EADDRINUSE
, EADDRINUSE
,
298 EADDRINUSE
, EADDRINUSE
},
299 .expected_reuse_errno
= {0, 0,
300 EADDRINUSE
, EADDRINUSE
,
301 EADDRINUSE
, EADDRINUSE
,
302 EADDRINUSE
, EADDRINUSE
},
305 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_local_v4_local
)
307 .family
= {AF_INET6
, AF_INET
},
308 .addr
= {&in6addr_loopback
, &in4addr_loopback
},
309 .expected_errno
= {0, 0,
310 EADDRINUSE
, EADDRINUSE
,
311 EADDRINUSE
, EADDRINUSE
,
312 EADDRINUSE
, EADDRINUSE
},
313 .expected_reuse_errno
= {0, 0,
314 EADDRINUSE
, EADDRINUSE
,
315 EADDRINUSE
, EADDRINUSE
,
316 EADDRINUSE
, EADDRINUSE
},
319 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_v4mapped_any_v4_any
)
321 .family
= {AF_INET6
, AF_INET
},
322 .addr
= {&in6addr_v4mapped_any
, &in4addr_any
},
323 .expected_errno
= {0, EADDRINUSE
,
324 EADDRINUSE
, EADDRINUSE
,
326 EADDRINUSE
, EADDRINUSE
},
327 .expected_reuse_errno
= {0, 0,
328 EADDRINUSE
, EADDRINUSE
,
330 EADDRINUSE
, EADDRINUSE
},
333 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_v4mapped_any_v4_local
)
335 .family
= {AF_INET6
, AF_INET
},
336 .addr
= {&in6addr_v4mapped_any
, &in4addr_loopback
},
337 .expected_errno
= {0, EADDRINUSE
,
338 EADDRINUSE
, EADDRINUSE
,
340 EADDRINUSE
, EADDRINUSE
},
341 .expected_reuse_errno
= {0, 0,
342 EADDRINUSE
, EADDRINUSE
,
344 EADDRINUSE
, EADDRINUSE
},
347 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_v4mapped_local_v4_any
)
349 .family
= {AF_INET6
, AF_INET
},
350 .addr
= {&in6addr_v4mapped_loopback
, &in4addr_any
},
351 .expected_errno
= {0, EADDRINUSE
,
352 EADDRINUSE
, EADDRINUSE
,
354 EADDRINUSE
, EADDRINUSE
},
355 .expected_reuse_errno
= {0, 0,
356 EADDRINUSE
, EADDRINUSE
,
358 EADDRINUSE
, EADDRINUSE
},
361 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_v4mapped_local_v4_local
)
363 .family
= {AF_INET6
, AF_INET
},
364 .addr
= {&in6addr_v4mapped_loopback
, &in4addr_loopback
},
365 .expected_errno
= {0, EADDRINUSE
,
366 EADDRINUSE
, EADDRINUSE
,
368 EADDRINUSE
, EADDRINUSE
},
369 .expected_reuse_errno
= {0, 0,
370 EADDRINUSE
, EADDRINUSE
,
372 EADDRINUSE
, EADDRINUSE
},
376 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_v6_any
)
378 .family
= {AF_INET6
, AF_INET6
},
379 .addr
= {&in6addr_any
, &in6addr_any
},
380 .expected_errno
= {0, EADDRINUSE
,
381 EADDRINUSE
, EADDRINUSE
,
382 EADDRINUSE
, EADDRINUSE
,
383 EADDRINUSE
, EADDRINUSE
},
384 .expected_reuse_errno
= {0, 0,
385 EADDRINUSE
, EADDRINUSE
,
386 EADDRINUSE
, EADDRINUSE
,
387 EADDRINUSE
, EADDRINUSE
},
390 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_only_v6_any
)
392 .family
= {AF_INET6
, AF_INET6
},
393 .addr
= {&in6addr_any
, &in6addr_any
},
394 .ipv6_only
= {true, false},
395 .expected_errno
= {0, EADDRINUSE
,
397 EADDRINUSE
, EADDRINUSE
,
398 EADDRINUSE
, EADDRINUSE
},
399 .expected_reuse_errno
= {0, 0,
400 EADDRINUSE
, EADDRINUSE
,
401 EADDRINUSE
, EADDRINUSE
,
402 EADDRINUSE
, EADDRINUSE
},
405 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_v6_any_only
)
407 .family
= {AF_INET6
, AF_INET6
},
408 .addr
= {&in6addr_any
, &in6addr_any
},
409 .ipv6_only
= {false, true},
410 .expected_errno
= {0, EADDRINUSE
,
411 EADDRINUSE
, EADDRINUSE
,
412 EADDRINUSE
, EADDRINUSE
,
413 EADDRINUSE
, EADDRINUSE
},
414 .expected_reuse_errno
= {0, 0,
415 EADDRINUSE
, EADDRINUSE
,
416 EADDRINUSE
, EADDRINUSE
,
417 EADDRINUSE
, EADDRINUSE
},
420 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_only_v6_any_only
)
422 .family
= {AF_INET6
, AF_INET6
},
423 .addr
= {&in6addr_any
, &in6addr_any
},
424 .ipv6_only
= {true, true},
425 .expected_errno
= {0, EADDRINUSE
,
427 EADDRINUSE
, EADDRINUSE
,
428 EADDRINUSE
, EADDRINUSE
},
429 .expected_reuse_errno
= {0, 0,
431 EADDRINUSE
, EADDRINUSE
,
432 EADDRINUSE
, EADDRINUSE
},
435 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_v6_local
)
437 .family
= {AF_INET6
, AF_INET6
},
438 .addr
= {&in6addr_any
, &in6addr_loopback
},
439 .expected_errno
= {0, EADDRINUSE
,
440 EADDRINUSE
, EADDRINUSE
,
441 EADDRINUSE
, EADDRINUSE
,
442 EADDRINUSE
, EADDRINUSE
},
443 .expected_reuse_errno
= {0, 0,
444 EADDRINUSE
, EADDRINUSE
,
445 EADDRINUSE
, EADDRINUSE
,
446 EADDRINUSE
, EADDRINUSE
},
449 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_only_v6_local
)
451 .family
= {AF_INET6
, AF_INET6
},
452 .addr
= {&in6addr_any
, &in6addr_loopback
},
453 .ipv6_only
= {true, false},
454 .expected_errno
= {0, EADDRINUSE
,
456 EADDRINUSE
, EADDRINUSE
,
457 EADDRINUSE
, EADDRINUSE
},
458 .expected_reuse_errno
= {0, 0,
460 EADDRINUSE
, EADDRINUSE
,
461 EADDRINUSE
, EADDRINUSE
},
464 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_v6_v4mapped_any
)
466 .family
= {AF_INET6
, AF_INET6
},
467 .addr
= {&in6addr_any
, &in6addr_v4mapped_any
},
468 .expected_errno
= {0, EADDRINUSE
,
469 EADDRINUSE
, EADDRINUSE
,
470 EADDRINUSE
, EADDRINUSE
,
471 EADDRINUSE
, EADDRINUSE
},
472 .expected_reuse_errno
= {0, 0,
473 EADDRINUSE
, EADDRINUSE
,
474 EADDRINUSE
, EADDRINUSE
,
475 EADDRINUSE
, EADDRINUSE
},
478 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_only_v6_v4mapped_any
)
480 .family
= {AF_INET6
, AF_INET6
},
481 .addr
= {&in6addr_any
, &in6addr_v4mapped_any
},
482 .ipv6_only
= {true, false},
483 .expected_errno
= {0, 0,
484 EADDRINUSE
, EADDRINUSE
,
485 EADDRINUSE
, EADDRINUSE
,
486 EADDRINUSE
, EADDRINUSE
},
487 .expected_reuse_errno
= {0, 0,
488 EADDRINUSE
, EADDRINUSE
,
489 EADDRINUSE
, EADDRINUSE
,
490 EADDRINUSE
, EADDRINUSE
},
493 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_v6_v4mapped_local
)
495 .family
= {AF_INET6
, AF_INET6
},
496 .addr
= {&in6addr_any
, &in6addr_v4mapped_loopback
},
497 .expected_errno
= {0, EADDRINUSE
,
498 EADDRINUSE
, EADDRINUSE
,
499 EADDRINUSE
, EADDRINUSE
,
500 EADDRINUSE
, EADDRINUSE
},
501 .expected_reuse_errno
= {0, 0,
502 EADDRINUSE
, EADDRINUSE
,
503 EADDRINUSE
, EADDRINUSE
,
504 EADDRINUSE
, EADDRINUSE
},
507 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_any_only_v6_v4mapped_local
)
509 .family
= {AF_INET6
, AF_INET6
},
510 .addr
= {&in6addr_any
, &in6addr_v4mapped_loopback
},
511 .ipv6_only
= {true, false},
512 .expected_errno
= {0, 0,
513 EADDRINUSE
, EADDRINUSE
,
514 EADDRINUSE
, EADDRINUSE
,
515 EADDRINUSE
, EADDRINUSE
},
516 .expected_reuse_errno
= {0, 0,
517 EADDRINUSE
, EADDRINUSE
,
518 EADDRINUSE
, EADDRINUSE
,
519 EADDRINUSE
, EADDRINUSE
},
522 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_local_v6_any
)
524 .family
= {AF_INET6
, AF_INET6
},
525 .addr
= {&in6addr_loopback
, &in6addr_any
},
526 .expected_errno
= {0, EADDRINUSE
,
528 EADDRINUSE
, EADDRINUSE
,
529 EADDRINUSE
, EADDRINUSE
},
530 .expected_reuse_errno
= {0, 0,
531 EADDRINUSE
, EADDRINUSE
,
532 EADDRINUSE
, EADDRINUSE
,
533 EADDRINUSE
, EADDRINUSE
},
536 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_local_v6_any_only
)
538 .family
= {AF_INET6
, AF_INET6
},
539 .addr
= {&in6addr_loopback
, &in6addr_any
},
540 .ipv6_only
= {false, true},
541 .expected_errno
= {0, EADDRINUSE
,
543 EADDRINUSE
, EADDRINUSE
,
544 EADDRINUSE
, EADDRINUSE
},
545 .expected_reuse_errno
= {0, 0,
547 EADDRINUSE
, EADDRINUSE
,
548 EADDRINUSE
, EADDRINUSE
},
551 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_local_v6_v4mapped_any
)
553 .family
= {AF_INET6
, AF_INET6
},
554 .addr
= {&in6addr_loopback
, &in6addr_v4mapped_any
},
555 .expected_errno
= {0, 0,
556 EADDRINUSE
, EADDRINUSE
,
557 EADDRINUSE
, EADDRINUSE
,
558 EADDRINUSE
, EADDRINUSE
},
559 .expected_reuse_errno
= {0, 0,
560 EADDRINUSE
, EADDRINUSE
,
561 EADDRINUSE
, EADDRINUSE
,
562 EADDRINUSE
, EADDRINUSE
},
565 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_local_v6_v4mapped_local
)
567 .family
= {AF_INET6
, AF_INET6
},
568 .addr
= {&in6addr_loopback
, &in6addr_v4mapped_loopback
},
569 .expected_errno
= {0, 0,
570 EADDRINUSE
, EADDRINUSE
,
571 EADDRINUSE
, EADDRINUSE
,
572 EADDRINUSE
, EADDRINUSE
},
573 .expected_reuse_errno
= {0, 0,
574 EADDRINUSE
, EADDRINUSE
,
575 EADDRINUSE
, EADDRINUSE
,
576 EADDRINUSE
, EADDRINUSE
},
579 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_v4mapped_any_v6_any
)
581 .family
= {AF_INET6
, AF_INET6
},
582 .addr
= {&in6addr_v4mapped_any
, &in6addr_any
},
583 .expected_errno
= {0, EADDRINUSE
,
584 EADDRINUSE
, EADDRINUSE
,
586 EADDRINUSE
, EADDRINUSE
},
587 .expected_reuse_errno
= {0, 0,
588 EADDRINUSE
, EADDRINUSE
,
589 EADDRINUSE
, EADDRINUSE
,
590 EADDRINUSE
, EADDRINUSE
},
593 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_v4mapped_any_v6_any_only
)
595 .family
= {AF_INET6
, AF_INET6
},
596 .addr
= {&in6addr_v4mapped_any
, &in6addr_any
},
597 .ipv6_only
= {false, true},
598 .expected_errno
= {0, 0,
599 EADDRINUSE
, EADDRINUSE
,
600 EADDRINUSE
, EADDRINUSE
,
601 EADDRINUSE
, EADDRINUSE
},
602 .expected_reuse_errno
= {0, 0,
603 EADDRINUSE
, EADDRINUSE
,
604 EADDRINUSE
, EADDRINUSE
,
605 EADDRINUSE
, EADDRINUSE
},
608 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_v4mapped_any_v6_local
)
610 .family
= {AF_INET6
, AF_INET6
},
611 .addr
= {&in6addr_v4mapped_any
, &in6addr_loopback
},
612 .expected_errno
= {0, 0,
613 EADDRINUSE
, EADDRINUSE
,
614 EADDRINUSE
, EADDRINUSE
,
615 EADDRINUSE
, EADDRINUSE
},
616 .expected_reuse_errno
= {0, 0,
617 EADDRINUSE
, EADDRINUSE
,
618 EADDRINUSE
, EADDRINUSE
,
619 EADDRINUSE
, EADDRINUSE
},
622 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_v4mapped_any_v6_v4mapped_local
)
624 .family
= {AF_INET6
, AF_INET6
},
625 .addr
= {&in6addr_v4mapped_any
, &in6addr_v4mapped_loopback
},
626 .expected_errno
= {0, EADDRINUSE
,
627 EADDRINUSE
, EADDRINUSE
,
629 EADDRINUSE
, EADDRINUSE
},
630 .expected_reuse_errno
= {0, 0,
631 EADDRINUSE
, EADDRINUSE
,
633 EADDRINUSE
, EADDRINUSE
},
636 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_v4mapped_loopback_v6_any
)
638 .family
= {AF_INET6
, AF_INET6
},
639 .addr
= {&in6addr_v4mapped_loopback
, &in6addr_any
},
640 .expected_errno
= {0, EADDRINUSE
,
641 EADDRINUSE
, EADDRINUSE
,
643 EADDRINUSE
, EADDRINUSE
},
644 .expected_reuse_errno
= {0, 0,
645 EADDRINUSE
, EADDRINUSE
,
646 EADDRINUSE
, EADDRINUSE
,
647 EADDRINUSE
, EADDRINUSE
},
650 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_v4mapped_loopback_v6_any_only
)
652 .family
= {AF_INET6
, AF_INET6
},
653 .addr
= {&in6addr_v4mapped_loopback
, &in6addr_any
},
654 .ipv6_only
= {false, true},
655 .expected_errno
= {0, 0,
656 EADDRINUSE
, EADDRINUSE
,
657 EADDRINUSE
, EADDRINUSE
,
658 EADDRINUSE
, EADDRINUSE
},
659 .expected_reuse_errno
= {0, 0,
660 EADDRINUSE
, EADDRINUSE
,
661 EADDRINUSE
, EADDRINUSE
,
662 EADDRINUSE
, EADDRINUSE
},
665 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_v4mapped_loopback_v6_local
)
667 .family
= {AF_INET6
, AF_INET6
},
668 .addr
= {&in6addr_v4mapped_loopback
, &in6addr_loopback
},
669 .expected_errno
= {0, 0,
670 EADDRINUSE
, EADDRINUSE
,
671 EADDRINUSE
, EADDRINUSE
,
672 EADDRINUSE
, EADDRINUSE
},
673 .expected_reuse_errno
= {0, 0,
674 EADDRINUSE
, EADDRINUSE
,
675 EADDRINUSE
, EADDRINUSE
,
676 EADDRINUSE
, EADDRINUSE
},
679 FIXTURE_VARIANT_ADD(bind_wildcard
, v6_v4mapped_loopback_v6_v4mapped_any
)
681 .family
= {AF_INET6
, AF_INET6
},
682 .addr
= {&in6addr_v4mapped_loopback
, &in6addr_v4mapped_any
},
683 .expected_errno
= {0, EADDRINUSE
,
684 EADDRINUSE
, EADDRINUSE
,
686 EADDRINUSE
, EADDRINUSE
},
687 .expected_reuse_errno
= {0, 0,
688 EADDRINUSE
, EADDRINUSE
,
690 EADDRINUSE
, EADDRINUSE
},
693 static void setup_addr(FIXTURE_DATA(bind_wildcard
) *self
, int i
,
694 int family
, const void *addr_const
)
696 if (family
== AF_INET
) {
697 struct sockaddr_in
*addr4
= &self
->addr
[i
].addr4
;
698 const __u32
*addr4_const
= addr_const
;
700 addr4
->sin_family
= AF_INET
;
701 addr4
->sin_port
= htons(0);
702 addr4
->sin_addr
.s_addr
= htonl(*addr4_const
);
704 self
->addrlen
[i
] = sizeof(struct sockaddr_in
);
706 struct sockaddr_in6
*addr6
= &self
->addr
[i
].addr6
;
707 const struct in6_addr
*addr6_const
= addr_const
;
709 addr6
->sin6_family
= AF_INET6
;
710 addr6
->sin6_port
= htons(0);
711 addr6
->sin6_addr
= *addr6_const
;
713 self
->addrlen
[i
] = sizeof(struct sockaddr_in6
);
717 FIXTURE_SETUP(bind_wildcard
)
719 setup_addr(self
, 0, variant
->family
[0], variant
->addr
[0]);
720 setup_addr(self
, 1, variant
->family
[1], variant
->addr
[1]);
722 setup_addr(self
, 2, AF_INET
, &in4addr_any
);
723 setup_addr(self
, 3, AF_INET
, &in4addr_loopback
);
725 setup_addr(self
, 4, AF_INET6
, &in6addr_any
);
726 setup_addr(self
, 5, AF_INET6
, &in6addr_loopback
);
727 setup_addr(self
, 6, AF_INET6
, &in6addr_v4mapped_any
);
728 setup_addr(self
, 7, AF_INET6
, &in6addr_v4mapped_loopback
);
731 FIXTURE_TEARDOWN(bind_wildcard
)
735 for (i
= 0; i
< NR_SOCKETS
; i
++)
739 void bind_socket(struct __test_metadata
*_metadata
,
740 FIXTURE_DATA(bind_wildcard
) *self
,
741 const FIXTURE_VARIANT(bind_wildcard
) *variant
,
746 self
->fd
[i
] = socket(self
->addr
[i
].addr
.sa_family
, SOCK_STREAM
, 0);
747 ASSERT_GT(self
->fd
[i
], 0);
749 if (i
< 2 && variant
->ipv6_only
[i
]) {
750 ret
= setsockopt(self
->fd
[i
], SOL_IPV6
, IPV6_V6ONLY
, &(int){1}, sizeof(int));
754 if (i
< 2 && reuse
) {
755 ret
= setsockopt(self
->fd
[i
], SOL_SOCKET
, reuse
, &(int){1}, sizeof(int));
759 self
->addr
[i
].addr4
.sin_port
= self
->addr
[0].addr4
.sin_port
;
761 ret
= bind(self
->fd
[i
], &self
->addr
[i
].addr
, self
->addrlen
[i
]);
764 if (variant
->expected_reuse_errno
[i
]) {
766 ASSERT_EQ(errno
, variant
->expected_reuse_errno
[i
]);
771 if (variant
->expected_errno
[i
]) {
773 ASSERT_EQ(errno
, variant
->expected_errno
[i
]);
780 ret
= getsockname(self
->fd
[0], &self
->addr
[0].addr
, &self
->addrlen
[0]);
785 TEST_F(bind_wildcard
, plain
)
789 for (i
= 0; i
< NR_SOCKETS
; i
++)
790 bind_socket(_metadata
, self
, variant
, i
, 0);
793 TEST_F(bind_wildcard
, reuseaddr
)
797 for (i
= 0; i
< NR_SOCKETS
; i
++)
798 bind_socket(_metadata
, self
, variant
, i
, SO_REUSEADDR
);
801 TEST_F(bind_wildcard
, reuseport
)
805 for (i
= 0; i
< NR_SOCKETS
; i
++)
806 bind_socket(_metadata
, self
, variant
, i
, SO_REUSEPORT
);