Ticket #1824 (closed feature: fixed)

Opened 4 years ago

Last modified 4 years ago

Configure step to determine if IPv6 is available on local machine

Reported by: dukeleto Owned by: jkeenan
Priority: normal Milestone:
Component: configure Version: 2.8.0
Severity: medium Keywords:
Cc: kurahaupo Language:
Patch status: applied Platform: all

Description

I would like to add tests that connect to the local machine via IPv6, but we need a way of knowing if these tests should be run.

Creating IPv6 sockets always works, but actually using them requires knowing if the local machine is running a IPv6 stack. Most modern Linux variants run both ipv4+ipv6, but I am not sure about other operating systems.

Attachments

ipv6probe.c Download (1.8 KB) - added by jkeenan 4 years ago.
kurahaupo's patch converted to a file (no c++ style comments)

Change History

in reply to: ↑ description   Changed 4 years ago by jkeenan

  • cc jkeenan added

Replying to dukeleto:

I would like to add tests that connect to the local machine via IPv6, but we need a way of knowing if these tests should be run.

I don't have the answer to that, but once you do, contact me and I will dress it up as a configuration step.

kid51

  Changed 4 years ago by kurahaupo

On Tue, 12 Oct 2010, Parrot wrote:
> #1824: Configure step to determine if IPv6 is available on local machine
> -----------------------+----------------------------------------------------
>  Reporter:  dukeleto   |       Owner:
>      Type:  feature    |      Status:  new
>  Priority:  normal     |   Milestone:
> Component:  configure  |     Version:  2.8.0
>  Severity:  medium     |    Keywords:
>      Lang:             |       Patch:
>  Platform:  all        |
> -----------------------+----------------------------------------------------

Two things need to be checked:

(1) are the compile-time constants "AF_INET6" & "PF_INET6" available?
(2) is address "::1" bound to the loopback interface?

Both can be checked by compiling and running a short C program something
like this:

    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <stdio.h>
    #include <errno.h>

    int main(int c,char**v) {
        int x = socket( PF_INET6, SOCK_DGRAM, 0 );
        if ( x < 0 ) {
            perror("Not OK - socket failed");
            return 2;
        }

        // By now we have (a) PF_INET6 defined, and (b) in-principle kernel
        // support for v6; however we don't yet know if we have any v6
        // interfaces.

        struct in6_addr A = IN6ADDR_LOOPBACK_INIT;  // IN6ADDR_ANY_INIT;
        struct sockaddr_in6 S = { AF_INET6 };  // family is always first field in sockaddr_*
        S.sin6_addr = A;
        S.sin6_port = 32760;  // a pseudorandom 15-bit number

        // By now we have struct in6_addr, struct sockaddr_in6 and AF_INET6 and
        // IN6ADDR_LOOPBACK_INIT. But we still don't know about interfaces.

        #ifdef linux  // might not be supported elsewhere
        S.sin6_flowinfo = 0;
        S.sin6_scope_id = 0;
        #endif

        // Set the SO_REUSEADDR option so as not to interfere with anyone else
        // using the port, including running this test again within the
        // re-use timeout period.
        int reuse_address = 1;
        if ( setsockopt(x, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0 ) {
            perror("Not OK - setsockopt failed");
            return 1;
        }

        if ( bind( x, (void*) &S, sizeof(S) ) < 0 && errno != EADDRINUSE ) {
            perror("Not OK - bind failed");
            return 1;
        }

        // By now we know we can bind to "::1", which means we truly do have
        // IPv6 support. Of course, we might not have any useful routes off
        // this host, but that wasn't the question.

        puts("OK");
        close(x);
        return 0;
    }

  Changed 4 years ago by jkeenan

  • patch set to new

I have created the tt1824_ipv6_configure branch in the Subversion repository to work on this ticket. Depending on time availability, I will try to work up kurahaupo++'s patch into a proper configuration step.

Thank you very much.

kid51

  Changed 4 years ago by jkeenan

  • status changed from new to assigned
  • owner set to jkeenan

  Changed 4 years ago by jkeenan

  • cc jkeenan removed

Changed 4 years ago by jkeenan

kurahaupo's patch converted to a file (no c++ style comments)

  Changed 4 years ago by jkeenan

  • cc kurahaupo added

I have converted kurahaupo's patch to a file, attached. (Since codingstd will ultimately complain about C++-style comments, I converted those to C comments.)

When I went to compile this file, I got:

$ gcc ipv6probe.c 
ipv6probe.c: In function 'main':
ipv6probe.c:46: error: 'reuse' undeclared (first use in this function)
ipv6probe.c:46: error: (Each undeclared identifier is reported only once
ipv6probe.c:46: error: for each function it appears in.)

Any suggestions as to what the reuse() function should be?

Thank you very much.

kid51

  Changed 4 years ago by bacek

Hello.

Looks like it should be C<reuse_address> not reuse.

Vasily

Parrot <parrot-tickets@lists.parrot.org> wrote:

>#1824: Configure step to determine if IPv6 is available on local machine
>-----------------------+----------------------------------------------------
> Reporter:  dukeleto   |       Owner:  jkeenan 
>     Type:  feature    |      Status:  assigned
> Priority:  normal     |   Milestone:          
>Component:  configure  |     Version:  2.8.0   
> Severity:  medium     |    Keywords:          
>     Lang:             |       Patch:  new     
> Platform:  all        |  
>-----------------------+----------------------------------------------------
>Changes (by jkeenan):
>
> * cc: kurahaupo (added)
>
>
>Comment:
>
> I have converted kurahaupo's patch to a file, attached.  (Since codingstd
> will ultimately complain about C++-style comments, I converted those to C
> comments.)
>
> When I went to compile this file, I got:
> {{{
> $ gcc ipv6probe.c
> ipv6probe.c: In function 'main':
> ipv6probe.c:46: error: 'reuse' undeclared (first use in this function)
> ipv6probe.c:46: error: (Each undeclared identifier is reported only once
> ipv6probe.c:46: error: for each function it appears in.)
> }}}
> Any suggestions as to what the reuse() function should be?
>
> Thank you very much.
>
> kid51
>
>-- 
>Ticket URL: <https://trac.parrot.org/parrot/ticket/1824#comment:6>
>Parrot <https://trac.parrot.org/parrot/>
>Parrot Development
>_______________________________________________
>parrot-tickets mailing list
>parrot-tickets@lists.parrot.org
>http://lists.parrot.org/mailman/listinfo/parrot-tickets

follow-up: ↓ 9   Changed 4 years ago by jkeenan

  • patch changed from new to applied

Thanks to bacek++ for the correction. With that, and a few revisions to kurahaupo++'s patch to conform to prior art for configuration probes, I have added, in this branch, in r49552, configuration step auto::ipv6.

dukeleto: Whether this probe tells you what you need to know is beyond my ken. You can take it from here.

Thanks.

kid51

in reply to: ↑ 8   Changed 4 years ago by jkeenan

Replying to jkeenan:

dukeleto:

Have you had a chance to evaluate this? Thanks.

kid51

  Changed 4 years ago by dukeleto

I think this branch can get merged. I am not sure if it does everything that we need yet, but I won't know that until I try to actually use it. Thanks for working on this Jim!

follow-up: ↓ 12   Changed 4 years ago by jkeenan

Merge performed in r49631. Will keep ticket open for no more than 3 days to receive any complaints.

Thank you very much.

kid51

in reply to: ↑ 11   Changed 4 years ago by jkeenan

  • status changed from assigned to closed
  • resolution set to fixed

Replying to jkeenan:

Merge performed in r49631. Will keep ticket open for no more than 3 days to receive any complaints.

No complaints received. Closing ticket.

Thank you very much.

kid51

Note: See TracTickets for help on using tickets.