ifconfig(8) tunnel and address families

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ifconfig(8) tunnel and address families

Stuart Henderson
Re http://permalink.gmane.org/gmane.os.openbsd.misc/185629
To set IPv6 tunnel endpoints for gif/gre, you have to use
syntax like "ifconfig gif0 inet6 tunnel 1::1 2::2" rather
than just "ifconfig gif0 tunnel 1::1 2::2".

This is because settunnel provides an af hint to getaddrinfo,
so it only considers addresses of a specified family.

The code already checks that the families match, so the hint
seems to be pointless. How about this diff? Works as expected
in my tests with v4 and v6.


Index: ifconfig.c
===================================================================
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.246
diff -u -p -u -7 -r1.246 ifconfig.c
--- ifconfig.c 23 Mar 2011 18:36:41 -0000 1.246
+++ ifconfig.c 16 May 2011 10:53:39 -0000
@@ -3151,27 +3151,23 @@ in6_status(int force)
 }
 #endif /*INET6*/
 
 #ifndef SMALL
 void
 settunnel(const char *src, const char *dst)
 {
- struct addrinfo hints, *srcres, *dstres;
+ struct addrinfo *srcres, *dstres;
  int ecode;
  struct if_laddrreq req;
 
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = afp->af_af;
- hints.ai_socktype = SOCK_DGRAM; /*dummy*/
-
- if ((ecode = getaddrinfo(src, NULL, &hints, &srcres)) != 0)
+ if ((ecode = getaddrinfo(src, NULL, NULL, &srcres)) != 0)
  errx(1, "error in parsing address string: %s",
     gai_strerror(ecode));
 
- if ((ecode = getaddrinfo(dst, NULL, &hints, &dstres)) != 0)
+ if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0)
  errx(1, "error in parsing address string: %s",
     gai_strerror(ecode));
 
  if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)
  errx(1,
     "source and destination address families do not match");

Reply | Threaded
Open this post in threaded view
|

Re: ifconfig(8) tunnel and address families

Andreas Bartelt-2
Hello Stuart,

On 05/16/11 12:59, Stuart Henderson wrote:

> Re http://permalink.gmane.org/gmane.os.openbsd.misc/185629
> To set IPv6 tunnel endpoints for gif/gre, you have to use
> syntax like "ifconfig gif0 inet6 tunnel 1::1 2::2" rather
> than just "ifconfig gif0 tunnel 1::1 2::2".
>
> This is because settunnel provides an af hint to getaddrinfo,
> so it only considers addresses of a specified family.
>
> The code already checks that the families match, so the hint
> seems to be pointless. How about this diff? Works as expected
> in my tests with v4 and v6.
>

the patch works and makes the tunnel configuration for v4/v6 addresses
more consistent.

Thanks,
Andreas

>
> Index: ifconfig.c
> ===================================================================
> RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
> retrieving revision 1.246
> diff -u -p -u -7 -r1.246 ifconfig.c
> --- ifconfig.c 23 Mar 2011 18:36:41 -0000 1.246
> +++ ifconfig.c 16 May 2011 10:53:39 -0000
> @@ -3151,27 +3151,23 @@ in6_status(int force)
>   }
>   #endif /*INET6*/
>
>   #ifndef SMALL
>   void
>   settunnel(const char *src, const char *dst)
>   {
> - struct addrinfo hints, *srcres, *dstres;
> + struct addrinfo *srcres, *dstres;
>   int ecode;
>   struct if_laddrreq req;
>
> - memset(&hints, 0, sizeof(hints));
> - hints.ai_family = afp->af_af;
> - hints.ai_socktype = SOCK_DGRAM; /*dummy*/
> -
> - if ((ecode = getaddrinfo(src, NULL,&hints,&srcres)) != 0)
> + if ((ecode = getaddrinfo(src, NULL, NULL,&srcres)) != 0)
>   errx(1, "error in parsing address string: %s",
>      gai_strerror(ecode));
>
> - if ((ecode = getaddrinfo(dst, NULL,&hints,&dstres)) != 0)
> + if ((ecode = getaddrinfo(dst, NULL, NULL,&dstres)) != 0)
>   errx(1, "error in parsing address string: %s",
>      gai_strerror(ecode));
>
>   if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)
>   errx(1,
>      "source and destination address families do not match");

Reply | Threaded
Open this post in threaded view
|

Re: ifconfig(8) tunnel and address families

David Coppa
In reply to this post by Stuart Henderson
On Mon, May 16, 2011 at 12:59 PM, Stuart Henderson <[hidden email]>
wrote:

> Re http://permalink.gmane.org/gmane.os.openbsd.misc/185629
> To set IPv6 tunnel endpoints for gif/gre, you have to use
> syntax like "ifconfig gif0 inet6 tunnel 1::1 2::2" rather
> than just "ifconfig gif0 tunnel 1::1 2::2".
>
> This is because settunnel provides an af hint to getaddrinfo,
> so it only considers addresses of a specified family.
>
> The code already checks that the families match, so the hint
> seems to be pointless. How about this diff? Works as expected
> in my tests with v4 and v6.
>
>
> Index: ifconfig.c
> ===================================================================
> RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
> retrieving revision 1.246
> diff -u -p -u -7 -r1.246 ifconfig.c
> --- ifconfig.c  23 Mar 2011 18:36:41 -0000      1.246
> +++ ifconfig.c  16 May 2011 10:53:39 -0000
> @@ -3151,27 +3151,23 @@ in6_status(int force)
>  }
>  #endif /*INET6*/
>
>  #ifndef SMALL
>  void
>  settunnel(const char *src, const char *dst)
>  {
> -       struct addrinfo hints, *srcres, *dstres;
> +       struct addrinfo *srcres, *dstres;
>        int ecode;
>        struct if_laddrreq req;
>
> -       memset(&hints, 0, sizeof(hints));
> -       hints.ai_family = afp->af_af;
> -       hints.ai_socktype = SOCK_DGRAM; /*dummy*/
> -
> -       if ((ecode = getaddrinfo(src, NULL, &hints, &srcres)) != 0)
> +       if ((ecode = getaddrinfo(src, NULL, NULL, &srcres)) != 0)
>                errx(1, "error in parsing address string: %s",
>                    gai_strerror(ecode));
>
> -       if ((ecode = getaddrinfo(dst, NULL, &hints, &dstres)) != 0)
> +       if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0)
>                errx(1, "error in parsing address string: %s",
>                    gai_strerror(ecode));
>
>        if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)
>                errx(1,
>                    "source and destination address families do not match");
>
>

Seems sane. Ok for me.

Ciao,
David

Reply | Threaded
Open this post in threaded view
|

Re: ifconfig(8) tunnel and address families

Todd T. Fries-2
In reply to this post by Stuart Henderson
Penned by Stuart Henderson on 20110516  5:59.19, we have:
| Re http://permalink.gmane.org/gmane.os.openbsd.misc/185629
| To set IPv6 tunnel endpoints for gif/gre, you have to use
| syntax like "ifconfig gif0 inet6 tunnel 1::1 2::2" rather
| than just "ifconfig gif0 tunnel 1::1 2::2".
|
| This is because settunnel provides an af hint to getaddrinfo,
| so it only considers addresses of a specified family.
|
| The code already checks that the families match, so the hint
| seems to be pointless. How about this diff? Works as expected
| in my tests with v4 and v6.
|
|
| Index: ifconfig.c
| ===================================================================
| RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
| retrieving revision 1.246
| diff -u -p -u -7 -r1.246 ifconfig.c
| --- ifconfig.c 23 Mar 2011 18:36:41 -0000 1.246
| +++ ifconfig.c 16 May 2011 10:53:39 -0000
| @@ -3151,27 +3151,23 @@ in6_status(int force)
|  }
|  #endif /*INET6*/
|  
|  #ifndef SMALL
|  void
|  settunnel(const char *src, const char *dst)
|  {
| - struct addrinfo hints, *srcres, *dstres;
| + struct addrinfo *srcres, *dstres;
|   int ecode;
|   struct if_laddrreq req;
|  
| - memset(&hints, 0, sizeof(hints));
| - hints.ai_family = afp->af_af;
| - hints.ai_socktype = SOCK_DGRAM; /*dummy*/
| -
| - if ((ecode = getaddrinfo(src, NULL, &hints, &srcres)) != 0)
| + if ((ecode = getaddrinfo(src, NULL, NULL, &srcres)) != 0)
|   errx(1, "error in parsing address string: %s",
|      gai_strerror(ecode));
|  
| - if ((ecode = getaddrinfo(dst, NULL, &hints, &dstres)) != 0)
| + if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0)
|   errx(1, "error in parsing address string: %s",
|      gai_strerror(ecode));
|  
|   if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)
|   errx(1,
|      "source and destination address families do not match");

This solution is much better than what I've been doing in hostname.if(5) files:

 !ifconfig \$if inet6 tunnel ...

This looks ok to me, I really like this solution.
--
Todd Fries .. [hidden email]

 _____________________________________________
|                                             \  1.636.410.0632 (voice)
| Free Daemon Consulting, LLC                 \  1.405.227.9094 (voice)
| http://FreeDaemonConsulting.com             \  1.866.792.3418 (FAX)
| 2525 NW Expy #525, Oklahoma City, OK 73112  \  sip:[hidden email]
| "..in support of free software solutions."  \  sip:[hidden email]
 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
                                                 
              37E7 D3EB 74D0 8D66 A68D  B866 0326 204E 3F42 004A
                        http://todd.fries.net/pgp.txt