@@ -85,18 +85,18 @@ static void setup_loopback(struct __test_metadata *const _metadata)
85
85
clear_ambient_cap (_metadata , CAP_NET_ADMIN );
86
86
}
87
87
88
+ static bool prot_is_tcp (const struct protocol_variant * const prot )
89
+ {
90
+ return (prot -> domain == AF_INET || prot -> domain == AF_INET6 ) &&
91
+ prot -> type == SOCK_STREAM &&
92
+ (prot -> protocol == IPPROTO_TCP || prot -> protocol == IPPROTO_IP );
93
+ }
94
+
88
95
static bool is_restricted (const struct protocol_variant * const prot ,
89
96
const enum sandbox_type sandbox )
90
97
{
91
- switch (prot -> domain ) {
92
- case AF_INET :
93
- case AF_INET6 :
94
- switch (prot -> type ) {
95
- case SOCK_STREAM :
96
- return sandbox == TCP_SANDBOX ;
97
- }
98
- break ;
99
- }
98
+ if (sandbox == TCP_SANDBOX )
99
+ return prot_is_tcp (prot );
100
100
return false;
101
101
}
102
102
@@ -105,7 +105,7 @@ static int socket_variant(const struct service_fixture *const srv)
105
105
int ret ;
106
106
107
107
ret = socket (srv -> protocol .domain , srv -> protocol .type | SOCK_CLOEXEC ,
108
- 0 );
108
+ srv -> protocol . protocol );
109
109
if (ret < 0 )
110
110
return - errno ;
111
111
return ret ;
@@ -290,22 +290,48 @@ FIXTURE_TEARDOWN(protocol)
290
290
}
291
291
292
292
/* clang-format off */
293
- FIXTURE_VARIANT_ADD (protocol , no_sandbox_with_ipv4_tcp ) {
293
+ FIXTURE_VARIANT_ADD (protocol , no_sandbox_with_ipv4_tcp1 ) {
294
294
/* clang-format on */
295
295
.sandbox = NO_SANDBOX ,
296
296
.prot = {
297
297
.domain = AF_INET ,
298
298
.type = SOCK_STREAM ,
299
+ /* IPPROTO_IP == 0 */
300
+ .protocol = IPPROTO_IP ,
299
301
},
300
302
};
301
303
302
304
/* clang-format off */
303
- FIXTURE_VARIANT_ADD (protocol , no_sandbox_with_ipv6_tcp ) {
305
+ FIXTURE_VARIANT_ADD (protocol , no_sandbox_with_ipv4_tcp2 ) {
306
+ /* clang-format on */
307
+ .sandbox = NO_SANDBOX ,
308
+ .prot = {
309
+ .domain = AF_INET ,
310
+ .type = SOCK_STREAM ,
311
+ .protocol = IPPROTO_TCP ,
312
+ },
313
+ };
314
+
315
+ /* clang-format off */
316
+ FIXTURE_VARIANT_ADD (protocol , no_sandbox_with_ipv6_tcp1 ) {
304
317
/* clang-format on */
305
318
.sandbox = NO_SANDBOX ,
306
319
.prot = {
307
320
.domain = AF_INET6 ,
308
321
.type = SOCK_STREAM ,
322
+ /* IPPROTO_IP == 0 */
323
+ .protocol = IPPROTO_IP ,
324
+ },
325
+ };
326
+
327
+ /* clang-format off */
328
+ FIXTURE_VARIANT_ADD (protocol , no_sandbox_with_ipv6_tcp2 ) {
329
+ /* clang-format on */
330
+ .sandbox = NO_SANDBOX ,
331
+ .prot = {
332
+ .domain = AF_INET6 ,
333
+ .type = SOCK_STREAM ,
334
+ .protocol = IPPROTO_TCP ,
309
335
},
310
336
};
311
337
@@ -372,22 +398,48 @@ FIXTURE_VARIANT_ADD(protocol, no_sandbox_with_unix_datagram) {
372
398
};
373
399
374
400
/* clang-format off */
375
- FIXTURE_VARIANT_ADD (protocol , tcp_sandbox_with_ipv4_tcp ) {
401
+ FIXTURE_VARIANT_ADD (protocol , tcp_sandbox_with_ipv4_tcp1 ) {
402
+ /* clang-format on */
403
+ .sandbox = TCP_SANDBOX ,
404
+ .prot = {
405
+ .domain = AF_INET ,
406
+ .type = SOCK_STREAM ,
407
+ /* IPPROTO_IP == 0 */
408
+ .protocol = IPPROTO_IP ,
409
+ },
410
+ };
411
+
412
+ /* clang-format off */
413
+ FIXTURE_VARIANT_ADD (protocol , tcp_sandbox_with_ipv4_tcp2 ) {
376
414
/* clang-format on */
377
415
.sandbox = TCP_SANDBOX ,
378
416
.prot = {
379
417
.domain = AF_INET ,
380
418
.type = SOCK_STREAM ,
419
+ .protocol = IPPROTO_TCP ,
420
+ },
421
+ };
422
+
423
+ /* clang-format off */
424
+ FIXTURE_VARIANT_ADD (protocol , tcp_sandbox_with_ipv6_tcp1 ) {
425
+ /* clang-format on */
426
+ .sandbox = TCP_SANDBOX ,
427
+ .prot = {
428
+ .domain = AF_INET6 ,
429
+ .type = SOCK_STREAM ,
430
+ /* IPPROTO_IP == 0 */
431
+ .protocol = IPPROTO_IP ,
381
432
},
382
433
};
383
434
384
435
/* clang-format off */
385
- FIXTURE_VARIANT_ADD (protocol , tcp_sandbox_with_ipv6_tcp ) {
436
+ FIXTURE_VARIANT_ADD (protocol , tcp_sandbox_with_ipv6_tcp2 ) {
386
437
/* clang-format on */
387
438
.sandbox = TCP_SANDBOX ,
388
439
.prot = {
389
440
.domain = AF_INET6 ,
390
441
.type = SOCK_STREAM ,
442
+ .protocol = IPPROTO_TCP ,
391
443
},
392
444
};
393
445
0 commit comments