Deleted Added
full compact
26c26
< * $FreeBSD: head/tools/regression/netinet/ipsockopt/ipsockopt.c 136384 2004-10-11 16:09:45Z rwatson $
---
> * $FreeBSD: head/tools/regression/netinet/ipsockopt/ipsockopt.c 136390 2004-10-11 19:03:53Z rwatson $
51a52,98
> * get_socket() is a wrapper function that returns a socket of the specified
> * type, and created with or without restored root privilege (if running
> * with a real uid of root and an effective uid of some other user). This
> * us to test whether the same rights are granted using a socket with a
> * privileged cached credential vs. a socket with a regular credential.
> */
> #define PRIV_ASIS 0
> #define PRIV_GETROOT 1
> static int
> get_socket_unpriv(int type)
> {
>
> return (socket(PF_INET, type, 0));
> }
>
> static int
> get_socket_priv(int type)
> {
> uid_t olduid;
> int sock;
>
> if (getuid() != 0)
> errx(-1, "get_sock_priv: running without real uid 0");
>
> olduid = geteuid();
> if (seteuid(0) < 0)
> err(-1, "get_sock_priv: seteuid(0)");
>
> sock = socket(PF_INET, type, 0);
>
> if (seteuid(olduid) < 0)
> err(-1, "get_sock_priv: seteuid(%d)", olduid);
>
> return (sock);
> }
>
> static int
> get_socket(int type, int priv)
> {
>
> if (priv)
> return (get_socket_priv(type));
> else
> return (get_socket_unpriv(type));
> }
>
> /*
61c108
< test_ip_options(void)
---
> test_ip_options(int sock, const char *socktypename)
65d111
< int sock;
67,70d112
< sock = socket(PF_INET, SOCK_DGRAM, 0);
< if (sock == -1)
< err(-1, "test_ip_options: socket(SOCK_DGRAM)");
<
77c119,120
< err(-1, "test_ip_options: initial getsockopt()");
---
> err(-1, "test_ip_options(%s): initial getsockopt()",
> socktypename);
80,81c123,124
< errx(-1, "test_ip_options: initial getsockopt() returned "
< "%d bytes", len);
---
> errx(-1, "test_ip_options(%s): initial getsockopt() returned "
> "%d bytes", socktypename, len);
93c136,137
< err(-1, "test_ip_options: setsockopt(NOP|NOP|NOP|EOL)");
---
> err(-1, "test_ip_options(%s): setsockopt(NOP|NOP|NOP|EOL)",
> socktypename);
105c149,150
< err(-1, "test_ip_options: getsockopt() after set");
---
> err(-1, "test_ip_options(%s): getsockopt() after set",
> socktypename);
111,112c156,157
< errx(-1, "test_ip_options: getsockopt() after set returned "
< "%d bytes of data", len);
---
> errx(-1, "test_ip_options(%s): getsockopt() after set "
> "returned %d bytes of data", socktypename, len);
119,120c164,165
< errx(-1, "test_ip_options: getsockopt() after set didn't "
< "return data");
---
> errx(-1, "test_ip_options(%s): getsockopt() after set didn't "
> "return data", socktypename);
126,128c171,173
< errx(-1, "test_ip_options: getsockopt() after set returned "
< "wrong options (%08x, %08x)", new_options,
< test_options[0]);
---
> errx(-1, "test_ip_options(%s): getsockopt() after set "
> "returned wrong options (%08x, %08x)", socktypename,
> new_options, test_options[0]);
134c179,180
< err(-1, "test_ip_options: setsockopt() to reset");
---
> err(-1, "test_ip_options(%s): setsockopt() to reset",
> socktypename);
143c189,190
< err(-1, "test_ip_options: getsockopt() after reset");
---
> err(-1, "test_ip_options(%s): getsockopt() after reset",
> socktypename);
146,149c193,194
< errx(-1, "test_ip_options: getsockopt() after reset returned "
< "%d bytes", len);
<
< close(sock);
---
> errx(-1, "test_ip_options(%s): getsockopt() after reset "
> "returned %d bytes", socktypename, len);
158a204,206
> *
> * Unlike other tests, doesn't use caller-provided socket. Probably should
> * be fixed.
170,173c218,219
< if (sock == -1) {
< perror("socket");
< exit(-1);
< }
---
> if (sock == -1)
> err(-1, "test_ip_hdrincl(): socket(SOCK_STREAM)");
177,180c223,224
< if (getsockopt(sock, IPPROTO_IP, IP_HDRINCL, flag, &len) == 0) {
< fprintf(stderr, "getsockopt(IP_HDRINCL) on TCP succeeded\n");
< exit(-1);
< }
---
> if (getsockopt(sock, IPPROTO_IP, IP_HDRINCL, flag, &len) == 0)
> err(-1, "test_ip_hdrincl(): initial getsockopt(IP_HDRINCL)");
182,186c226,229
< if (errno != ENOPROTOOPT) {
< fprintf(stderr, "getsockopt(IP_HDRINCL) on TCP returned %d "
< "(%s) not ENOPROTOOPT\n", errno, strerror(errno));
< exit(-1);
< }
---
> if (errno != ENOPROTOOPT)
> errx(-1, "test_ip_hdrincl(): initial getsockopt(IP_HDRINC) "
> "returned %d (%s) not ENOPROTOOPT", errno,
> strerror(errno));
190,193c233,235
< == 0) {
< fprintf(stderr, "setsockopt(IP_HDRINCL) on TCP succeeded\n");
< exit(-1);
< }
---
> == 0)
> err(-1,"test_ip_hdrincl(): setsockopt(IP_HDRINCL) on TCP "
> "succeeded\n");
195,199c237,240
< if (errno != ENOPROTOOPT) {
< fprintf(stderr, "setsockopt(IP_HDRINCL) on TCP returned %d "
< "(%s) not ENOPROTOOPT\n", errno, strerror(errno));
< exit(-1);
< }
---
> if (errno != ENOPROTOOPT)
> errx(-1, "test_ip_hdrincl(): setsockopt(IP_HDRINCL) on TCP "
> "returned %d (%s) not ENOPROTOOPT\n", errno,
> strerror(errno));
207,210c248,249
< if (sock == -1) {
< perror("socket");
< exit(-1);
< }
---
> if (sock == -1)
> err(-1, "test_ip_hdrincl(): socket(SOCK_DGRAM");
214,217c253,255
< if (getsockopt(sock, IPPROTO_IP, IP_HDRINCL, flag, &len) == 0) {
< fprintf(stderr, "getsockopt(IP_HDRINCL) on UDP succeeded\n");
< exit(-1);
< }
---
> if (getsockopt(sock, IPPROTO_IP, IP_HDRINCL, flag, &len) == 0)
> err(-1, "test_ip_hdrincl(): getsockopt(IP_HDRINCL) on UDP "
> "succeeded\n");
219,223c257,260
< if (errno != ENOPROTOOPT) {
< fprintf(stderr, "getsockopt(IP_HDRINCL) on UDP returned %d "
< "(%s) not ENOPROTOOPT\n", errno, strerror(errno));
< exit(-1);
< }
---
> if (errno != ENOPROTOOPT)
> errx(-1, "test_ip_hdrincl(): getsockopt(IP_HDRINCL) on UDP "
> "returned %d (%s) not ENOPROTOOPT\n", errno,
> strerror(errno));
226,229c263,265
< == 0) {
< fprintf(stderr, "setsockopt(IP_HDRINCL) on UDPsucceeded\n");
< exit(-1);
< }
---
> == 0)
> err(-1, "test_ip_hdrincl(): setsockopt(IP_HDRINCL) on UDP "
> "succeeded\n");
231,235c267,270
< if (errno != ENOPROTOOPT) {
< fprintf(stderr, "setsockopt(IP_HDRINCL) on UDP returned %d "
< "(%s) not ENOPROTOOPT\n", errno, strerror(errno));
< exit(-1);
< }
---
> if (errno != ENOPROTOOPT)
> errx(-1, "test_ip_hdrincl(): setsockopt(IP_HDRINCL) on UDP "
> "returned %d (%s) not ENOPROTOOPT\n", errno,
> strerror(errno));
253,256c288,289
< if (sock == -1) {
< perror("test_ip_hdrincl: socket(PF_INET, SOCK_RAW)");
< exit(-1);
< }
---
> if (sock == -1)
> err(-1, "test_ip_hdrincl(): socket(PF_INET, SOCK_RAW)");
264,267c297,299
< if (getsockopt(sock, IPPROTO_IP, IP_HDRINCL, flag, &len) < 0) {
< perror("test_ip_hdrincl: getsockopt(IP_HDRINCL) on raw");
< exit(-1);
< }
---
> if (getsockopt(sock, IPPROTO_IP, IP_HDRINCL, flag, &len) < 0)
> err(-1, "test_ip_hdrincl(): getsockopt(IP_HDRINCL) on raw "
> "socket");
269,270c301,302
< if (len != sizeof(flag[0])) {
< fprintf(stderr, "test_ip_hdrincl: %d bytes returned on "
---
> if (len != sizeof(flag[0]))
> errx(-1, "test_ip_hdrincl(): %d bytes returned on "
272,273d303
< exit(-1);
< }
275,276c305,306
< if (flag[0] != 0) {
< fprintf(stderr, "test_ip_hdrincl: initial flag value of %d\n",
---
> if (flag[0] != 0)
> errx(-1, "test_ip_hdrincl(): initial flag value of %d\n",
278,279d307
< exit(-1);
< }
286,289c314,315
< < 0) {
< perror("test_ip_hdrincl: setsockopt(IP_HDRINCL, 1)");
< exit(-1);
< }
---
> < 0)
> err(-1, "test_ip_hdrincl(): setsockopt(IP_HDRINCL, 1)");
297,300c323,325
< if (getsockopt(sock, IPPROTO_IP, IP_HDRINCL, flag, &len) < 0) {
< perror("test_ip_hdrincl: getsockopt(IP_HDRINCL) after set");
< exit(-1);
< }
---
> if (getsockopt(sock, IPPROTO_IP, IP_HDRINCL, flag, &len) < 0)
> err(-1, "test_ip_hdrincl(): getsockopt(IP_HDRINCL) after "
> "set");
302,303c327,328
< if (flag[0] == 0) {
< fprintf(stderr, "test_ip_hdrincl: getsockopt(IP_HDRINCL) "
---
> if (flag[0] == 0)
> errx(-1, "test_ip_hdrincl(): getsockopt(IP_HDRINCL) "
305,306d329
< exit(-1);
< }
309,310c332,333
< if (flag[0] != HISTORICAL_INP_HDRINCL) {
< fprintf(stderr, "test_ip_hdrincl: WARNING: getsockopt(IP_H"
---
> if (flag[0] != HISTORICAL_INP_HDRINCL)
> warnx("test_ip_hdrincl(): WARNING: getsockopt(IP_H"
313d335
< }
320,323c342,343
< < 0) {
< perror("test_ip_hdrincl: setsockopt(IP_HDRINCL, 0)");
< exit(-1);
< }
---
> < 0)
> err(-1, "test_ip_hdrincl(): setsockopt(IP_HDRINCL, 0)");
331,334c351,353
< if (getsockopt(sock, IPPROTO_IP, IP_HDRINCL, flag, &len) < 0) {
< perror("test_ip_hdrincl: getsockopt(IP_HDRINCL) after reset");
< exit(-1);
< }
---
> if (getsockopt(sock, IPPROTO_IP, IP_HDRINCL, flag, &len) < 0)
> err(-1, "test_ip_hdrincl(): getsockopt(IP_HDRINCL) after "
> "reset");
336,337c355,356
< if (flag[0] != 0) {
< fprintf(stderr, "test_ip_hdrincl: getsockopt(IP_HDRINCL) "
---
> if (flag[0] != 0)
> errx(-1, "test_ip_hdrincl(): getsockopt(IP_HDRINCL) "
339,340d357
< exit(-1);
< }
368c385,386
< test_ip_uchar(int option, char *optionname, int initial)
---
> test_ip_uchar(int sock, const char *socktypename, int option,
> const char *optionname, int initial)
370c388
< int sock, val[2];
---
> int val[2];
373,376d390
< sock = socket(PF_INET, SOCK_DGRAM, 0);
< if (sock == -1)
< err(-1, "test_ip_tosttl(%s): socket", optionname);
<
385,386c399,400
< err(-1, "test_ip_tosttl: initial getsockopt(%s)",
< optionname);
---
> err(-1, "test_ip_uchar(%s, %s): initial getsockopt()",
> socktypename, optionname);
389,390c403,404
< errx(-1, "test_ip_tosttl(%s): initial getsockopt() returned "
< "%d bytes", optionname, len);
---
> errx(-1, "test_ip_uchar(%s, %s): initial getsockopt() "
> "returned %d bytes", socktypename, optionname, len);
393,394c407,408
< errx(-1, "test_ip_tosttl(%s): initial getsockopt() didn't "
< "return data", optionname);
---
> errx(-1, "test_ip_uchar(%s, %s): initial getsockopt() didn't "
> "return data", socktypename, optionname);
397,398c411,413
< errx(-1, "test_ip_tosttl(%s): initial getsockopt() returned "
< "value of %d, not %d", optionname, val[0], initial);
---
> errx(-1, "test_ip_uchar(%s, %s): initial getsockopt() "
> "returned value of %d, not %d", socktypename, optionname,
> val[0], initial);
406c421,422
< err(-1, "test_ip_tosttl(%s): setsockopt(128)", optionname);
---
> err(-1, "test_ip_uchar(%s, %s): setsockopt(128)",
> socktypename, optionname);
415,416c431,432
< err(-1, "test_ip_tosttl(%s): getsockopt() after set to 128",
< optionname);
---
> err(-1, "test_ip_uchar(%s, %s): getsockopt() after set to "
> "128", socktypename, optionname);
419,420c435,436
< errx(-1, "test_ip_tosttl(%s): getsockopt() after set to 128 "
< "returned %d bytes", optionname, len);
---
> errx(-1, "test_ip_uchar(%s, %s): getsockopt() after set to "
> "128 returned %d bytes", socktypename, optionname, len);
423,424c439,440
< errx(-1, "test_ip_tosttl(%s): getsockopt() after set to 128 "
< "didn't return data", optionname);
---
> errx(-1, "test_ip_uchar(%s, %s): getsockopt() after set to "
> "128 didn't return data", socktypename, optionname);
427,428c443,444
< errx(-1, "test_ip_tosttl(%s): getsockopt() after set to 128 "
< "returned %d", optionname, val[0]);
---
> errx(-1, "test_ip_uchar(%s, %s): getsockopt() after set to "
> "128 returned %d", socktypename, optionname, val[0]);
436,437c452,453
< err(-1, "test_ip_tosttl(%s): setsockopt() to reset from 128",
< optionname);
---
> err(-1, "test_ip_uchar(%s, %s): setsockopt() to reset from "
> "128", socktypename, optionname);
440,441c456,458
< errx(-1, "test_ip_tosttl(%s): getsockopt() after reset from "
< "128 returned %d bytes", optionname, len);
---
> errx(-1, "test_ip_uchar(%s, %s): getsockopt() after reset "
> "from 128 returned %d bytes", socktypename, optionname,
> len);
444,445c461,462
< errx(-1, "test_ip_tosttl(%s): getsockopt() after reset from "
< "128 didn't return data", optionname);
---
> errx(-1, "test_ip_uchar(%s, %s): getsockopt() after reset "
> "from 128 didn't return data", socktypename, optionname);
448,449c465,467
< errx(-1, "test_ip_tosttl(%s): getsockopt() after reset from "
< "128 returned %d", optionname, val[0]);
---
> errx(-1, "test_ip_uchar(%s, %s): getsockopt() after reset "
> "from 128 returned %d", socktypename, optionname,
> val[0]);
464,465c482
< if (errno == EINVAL) {
< close(sock);
---
> if (errno == EINVAL)
467,468c484,485
< }
< err(-1, "test_ip_tosttl(%s): getsockopt(32000)", optionname);
---
> err(-1, "test_ip_uchar(%s, %s): getsockopt(32000)",
> socktypename, optionname);
475,476c492,493
< err(-1, "test_ip_tosttl(%s): getsockopt() after set to 32000",
< optionname);
---
> err(-1, "test_ip_uchar(%s, %s): getsockopt() after set to "
> "32000", socktypename, optionname);
479,480c496,498
< errx(-1, "test_ip_tosttl(%s): getsockopt() after set to 32000"
< "returned %d bytes", optionname, len);
---
> errx(-1, "test_ip_uchar(%s, %s): getsockopt() after set to "
> "32000 returned %d bytes", socktypename, optionname,
> len);
483,484c501,502
< errx(-1, "test_ip_tosttl(%s): getsockopt() after set to 32000"
< "didn't return data", optionname);
---
> errx(-1, "test_ip_uchar(%s, %s): getsockopt() after set to "
> "32000 didn't return data", socktypename, optionname);
487,490c505,507
< errx(-1, "test_ip_tosttl(%s): getsockopt() after set to 32000"
< "returned 32000: failed to truncate", optionname);
<
< close(sock);
---
> errx(-1, "test_ip_uchar(%s, %s): getsockopt() after set to "
> "32000 returned 32000: failed to truncate", socktypename,
> optionname);
504,505d520
< *
< * Test using a UDP socket.
510c525,526
< test_ip_boolean(int option, char *optionname, int initial, int rootonly)
---
> test_ip_boolean(int sock, const char *socktypename, int option,
> char *optionname, int initial, int rootonly)
512c528
< int newvalue, sock, val[2];
---
> int newvalue, val[2];
515,518d530
< sock = socket(PF_INET, SOCK_DGRAM, 0);
< if (sock == -1)
< err(-1, "test_ip_boolean(%s): socket", optionname);
<
536,537c548,549
< errx(-1, "test_ip_boolean(%s): initial getsockopt() returned "
< "%d bytes", optionname, len);
---
> errx(-1, "test_ip_boolean(%s, %s): initial getsockopt() "
> "returned %d bytes", socktypename, optionname, len);
540,541c552,553
< errx(-1, "test_ip_boolean(%s): initial getsockopt() didn't "
< "return data", optionname);
---
> errx(-1, "test_ip_boolean(%s, %s): initial getsockopt() "
> "didn't return data", socktypename, optionname);
544,545c556,558
< errx(-1, "test_ip_boolean(%s): initial getsockopt() returned "
< "%d (expected %d)", optionname, val[0], initial);
---
> errx(-1, "test_ip_boolean(%s, %s): initial getsockopt() "
> "returned %d (expected %d)", socktypename, optionname,
> val[0], initial);
552,553c565,566
< err(-1, "test_ip_boolean(%s): setsockopt() to %d", optionname,
< newvalue);
---
> err(-1, "test_ip_boolean(%s, %s): setsockopt() to %d",
> socktypename, optionname, newvalue);
563,564c576,577
< err(-1, "test_ip_boolean(%s): getsockopt() after set to %d",
< optionname, newvalue);
---
> err(-1, "test_ip_boolean(%s, %s): getsockopt() after set to "
> "%d", socktypename, optionname, newvalue);
567,568c580,582
< errx(-1, "test_ip_boolean(%s): getsockopt() after set to %d "
< "returned %d bytes", optionname, newvalue, len);
---
> errx(-1, "test_ip_boolean(%s, %s): getsockopt() after set "
> "to %d returned %d bytes", socktypename, optionname,
> newvalue, len);
571,572c585,587
< errx(-1, "test_ip_boolean(%s): getsockopt() after set to %d "
< "didn't return data", optionname, newvalue);
---
> errx(-1, "test_ip_boolean(%s, %s): getsockopt() after set "
> "to %d didn't return data", socktypename, optionname,
> newvalue);
578,579c593,595
< errx(-1, "test_ip_boolean(%s): getsockopt() after set to %d "
< "returned %d", optionname, newvalue, val[0]);
---
> errx(-1, "test_ip_boolean(%s, %s): getsockopt() after set "
> "to %d returned %d", socktypename, optionname, newvalue,
> val[0]);
587,588c603,604
< err(-1, "test_ip_boolean(%s): setsockopt() to reset",
< optionname);
---
> err(-1, "test_ip_boolean(%s, %s): setsockopt() to reset",
> socktypename, optionname);
597,598c613,614
< err(-1, "test_ip_boolean(%s): getsockopt() after reset",
< optionname);
---
> err(-1, "test_ip_boolean(%s, %s): getsockopt() after reset",
> socktypename, optionname);
601,602c617,618
< errx(-1, "test_ip_boolean(%s): getsockopt() after reset "
< "returned %d bytes", optionname, len);
---
> errx(-1, "test_ip_boolean(%s, %s): getsockopt() after reset "
> "returned %d bytes", socktypename, optionname, len);
605,606c621,622
< errx(-1, "test_ip_boolean(%s): getsockopt() after reset "
< "didn't return data", optionname);
---
> errx(-1, "test_ip_boolean(%s, %s): getsockopt() after reset "
> "didn't return data", socktypename, optionname);
609,612c625,626
< errx(-1, "test_ip_boolean(%s): getsockopt() after reset "
< "returned %d", optionname, newvalue);
<
< close(sock);
---
> errx(-1, "test_ip_boolean(%s, %s): getsockopt() after reset "
> "returned %d", socktypename, optionname, newvalue);
619c633
< test_ip_multicast_if(void)
---
> test_ip_multicast_if(int sock, const char *socktypename)
632c646
< test_ip_multicast_vif(void)
---
> test_ip_multicast_vif(int sock, const char *socktypename)
645c659
< test_ip_multicast_membership(void)
---
> test_ip_multicast_membership(int sock, const char *socktypename)
651c665
< test_ip_multicast(void)
---
> testsuite(int priv)
652a667,671
> const char *socktypenameset[] = {"SOCK_DGRAM", "SOCK_STREAM",
> "SOCK_RAW"};
> int socktypeset[] = {SOCK_DGRAM, SOCK_STREAM, SOCK_RAW};
> const char *socktypename;
> int i, sock, socktype;
654,655c673
< test_ip_multicast_if();
< test_ip_multicast_vif();
---
> test_ip_hdrincl();
657,661c675,677
< /*
< * Test the multicast TTL exactly as we would the regular TTL, only
< * expect a different default.
< */
< test_ip_uchar(IP_MULTICAST_TTL, "IP_MULTICAST_TTL", 1);
---
> for (i = 0; i < sizeof(socktypeset)/sizeof(int); i++) {
> socktype = socktypeset[i];
> socktypename = socktypenameset[i];
663,670c679,684
< /*
< * The multicast loopback flag can be tested using our boolean
< * tester, but only because the FreeBSD API is a bit more flexible
< * than earlir APIs and will accept an int as well as a u_char.
< * Loopback is enabled by default.
< */
< test_ip_boolean(IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP", 1,
< BOOLEAN_ANYONE);
---
> /*
> * If we can't acquire root privilege, we can't open raw
> * sockets, so don't actually try.
> */
> if (getuid() != 0 && socktype == SOCK_RAW)
> continue;
672,673c686,694
< test_ip_multicast_membership();
< }
---
> /*
> * XXXRW: On 5.3, this seems not to work for SOCK_RAW.
> */
> sock = get_socket(socktype, priv);
> if (sock == -1)
> err(-1, "get_socket(%s, %d) for test_ip_uchar(IP_TOS)",
> socktypename, priv);
> test_ip_uchar(sock, socktypename, IP_TOS, "IP_TOS", 0);
> close(sock);
675,677c696,701
< static void
< testsuite(void)
< {
---
> sock = get_socket(socktype, priv);
> if (sock == -1)
> err(-1, "get_socket(%s %d) for test_ip_uchar(IP_TTL)",
> socktypename, priv);
> test_ip_uchar(sock, socktypename, IP_TTL, "IP_TTL", 64);
> close(sock);
679c703,709
< test_ip_hdrincl();
---
> sock = get_socket(socktype, priv);
> if (sock == -1)
> err(-1, "get_socket(%s, %d) for test_ip_boolean"
> "(IP_RECVOPTS)", socktypename, priv);
> test_ip_boolean(sock, socktypename, IP_RECVOPTS,
> "IP_RECVOPTS", 0, BOOLEAN_ANYONE);
> close(sock);
681,682c711,717
< test_ip_uchar(IP_TOS, "IP_TOS", 0);
< test_ip_uchar(IP_TTL, "IP_TTL", 64);
---
> sock = get_socket(socktype, priv);
> if (sock == -1)
> err(-1, "get_socket(%s, %d) for test_ip_boolean"
> "(IP_RECVRETOPTS)", socktypename, priv);
> test_ip_boolean(sock, socktypename, IP_RECVRETOPTS,
> "IP_RECVRETOPTS", 0, BOOLEAN_ANYONE);
> close(sock);
684,690c719,725
< test_ip_boolean(IP_RECVOPTS, "IP_RECVOPTS", 0, BOOLEAN_ANYONE);
< test_ip_boolean(IP_RECVRETOPTS, "IP_RECVRETOPTS", 0, BOOLEAN_ANYONE);
< test_ip_boolean(IP_RECVDSTADDR, "IP_RECVDSTADDR", 0, BOOLEAN_ANYONE);
< test_ip_boolean(IP_RECVTTL, "IP_RECVTTL", 0, BOOLEAN_ANYONE);
< test_ip_boolean(IP_RECVIF, "IP_RECVIF", 0, BOOLEAN_ANYONE);
< test_ip_boolean(IP_FAITH, "IP_FAITH", 0, BOOLEAN_ANYONE);
< test_ip_boolean(IP_ONESBCAST, "IP_ONESBCAST", 0, BOOLEAN_ANYONE);
---
> sock = get_socket(socktype, priv);
> if (sock == -1)
> err(-1, "get_socket(%s, %d) for test_ip_boolean"
> "(IP_RECVDSTADDR)", socktypename, priv);
> test_ip_boolean(sock, socktypename, IP_RECVDSTADDR,
> "IP_RECVDSTADDR", 0, BOOLEAN_ANYONE);
> close(sock);
692,696c727,733
< /*
< * XXX: Still need to test:
< * IP_PORTRANGE
< * IP_IPSEC_POLICY?
< */
---
> sock = get_socket(socktype, priv);
> if (sock == -1)
> err(-1, "get_socket(%s, %d) for test_ip_boolean"
> "(IP_RECVTTL)", socktypename, priv);
> test_ip_boolean(sock, socktypename, IP_RECVTTL, "IP_RECVTTL",
> 0, BOOLEAN_ANYONE);
> close(sock);
698c735,741
< test_ip_multicast();
---
> sock = get_socket(socktype, priv);
> if (sock == -1)
> err(-1, "get_socket(%s, %d) for test_ip_boolean"
> "(IP_RECVIF)", socktypename, priv);
> test_ip_boolean(sock, socktypename, IP_RECVIF, "IP_RECVIF",
> 0, BOOLEAN_ANYONE);
> close(sock);
700c743,800
< test_ip_options();
---
> sock = get_socket(socktype, priv);
> if (sock == -1)
> err(-1, "get_socket(%s, %d) for test_ip_boolean"
> "(IP_FAITH)", socktypename, priv);
> test_ip_boolean(sock, socktypename, IP_FAITH, "IP_FAITH", 0,
> BOOLEAN_ANYONE);
> close(sock);
>
> sock = get_socket(socktype, priv);
> if (sock == -1)
> err(-1, "get_socket(%s, %d) for test_ip_boolean"
> "(IP_ONESBCAST)", socktypename, priv);
> test_ip_boolean(sock, socktypename, IP_ONESBCAST,
> "IP_ONESBCAST", 0, BOOLEAN_ANYONE);
> close(sock);
>
> /*
> * Test the multicast TTL exactly as we would the regular
> * TTL, only expect a different default.
> */
> sock = get_socket(socktype, priv);
> if (sock == -1)
> err(-1, "get_socket(%s, %d) for IP_MULTICAST_TTL",
> socktypename, priv);
> test_ip_uchar(sock, socktypename, IP_MULTICAST_TTL,
> "IP_MULTICAST_TTL", 1);
> close(sock);
>
> /*
> * The multicast loopback flag can be tested using our
> * boolean tester, but only because the FreeBSD API is a bit
> * more flexible than earlir APIs and will accept an int as
> * well as a u_char. Loopback is enabled by default.
> */
> sock = get_socket(socktype, priv);
> if (sock == -1)
> err(-1, "get_socket(%s, %d) for IP_MULTICAST_LOOP",
> socktypename, priv);
> test_ip_boolean(sock, socktypename, IP_MULTICAST_LOOP,
> "IP_MULTICAST_LOOP", 1, BOOLEAN_ANYONE);
> close(sock);
>
> sock = get_socket(socktype, priv);
> if (sock == -1)
> err(-1, "get_socket(%s, %d) for test_ip_options",
> socktypename, priv);
> //test_ip_options(sock, socktypename);
> close(sock);
>
> test_ip_multicast_if(0, NULL);
> test_ip_multicast_vif(0, NULL);
> test_ip_multicast_membership(0, NULL);
> /*
> * XXX: Still need to test:
> * IP_PORTRANGE
> * IP_IPSEC_POLICY?
> */
> }
712c812
< warnx("Not running as root, can't run as-root tests");
---
> warnx("Not running as root, can't run tests as root");
714,716c814,817
< fprintf(stderr, "Running tests with uid %d\n", geteuid());
< testsuite();
< fprintf(stderr, "PASS\n");
---
> fprintf(stderr,
> "Running tests with uid %d sock uid %d\n", geteuid(),
> geteuid());
> testsuite(PRIV_ASIS);
718,724c819,832
< fprintf(stderr, "Running tests with uid 0\n");
< testsuite();
< if (setuid(65534) != 0)
< err(-1, "setuid(65534)");
< fprintf(stderr, "Running tests with uid 65535\n");
< testsuite();
< fprintf(stderr, "PASS\n");
---
> fprintf(stderr,
> "Running tests with ruid %d euid %d sock uid 0\n",
> getuid(), geteuid());
> testsuite(PRIV_ASIS);
> if (seteuid(65534) != 0)
> err(-1, "seteuid(65534)");
> fprintf(stderr,
> "Running tests with ruid %d euid %d sock uid 0\n",
> getuid(), geteuid());
> testsuite(PRIV_GETROOT);
> fprintf(stderr,
> "Running tests with ruid %d euid %d sock uid 65534\n",
> getuid(), geteuid());
> testsuite(PRIV_ASIS);
725a834
> fprintf(stderr, "PASS\n");