On Mon, Jun 20, 2011 at 06:30:11PM +0200, Mike Belopuhov wrote:
> Now that we support SO_RTABLE on the socket level, it makes
> sense to cleanup the tree.  OK?
> 

The if (getsockopt() && errno != ENOPROTOOPT) constructs are in my opinion
evil but the sa_family == AF_INET check is not much better but I guess you
should have a closer look at tcpbench:
                if (ptb->Vflag) {
                        if (setsockopt(sock, SOL_SOCKET, SO_RTABLE,
                            &ptb->Vflag, sizeof(ptb->Vflag)) == -1 &&
                            errno != ENOPROTOOPT)
                                err(1, "setsockopt SO_RTABLE");
                } else if (ptb->Vflag)
                        warnx("rtable only supported on AF_INET");

That does not make sense.
The other changes are OK claudio@

> Index: sbin/ping/ping.c
> ===================================================================
> RCS file: /home/cvs/src/sbin/ping/ping.c,v
> retrieving revision 1.88
> diff -u -p -r1.88 ping.c
> --- sbin/ping/ping.c  3 Jul 2010 04:44:51 -0000       1.88
> +++ sbin/ping/ping.c  20 Jun 2011 15:31:59 -0000
> @@ -312,7 +312,7 @@ main(int argc, char *argv[])
>                               errx(1, "rtable value is %s: %s",
>                                   errstr, optarg);
>  
> -                     if (setsockopt(s, IPPROTO_IP, SO_RTABLE, &rtableid,
> +                     if (setsockopt(s, SOL_SOCKET, SO_RTABLE, &rtableid,
>                           sizeof(rtableid)) == -1)
>                               err(1, "setsockopt SO_RTABLE");
>                       break;
> Index: usr.bin/nc/netcat.c
> ===================================================================
> RCS file: /home/cvs/src/usr.bin/nc/netcat.c,v
> retrieving revision 1.100
> diff -u -p -r1.100 netcat.c
> --- usr.bin/nc/netcat.c       9 Jan 2011 22:16:46 -0000       1.100
> +++ usr.bin/nc/netcat.c       20 Jun 2011 15:50:35 -0000
> @@ -552,7 +552,7 @@ remote_connect(const char *host, const c
>                       continue;
>  
>               if (rtableid) {
> -                     if (setsockopt(s, IPPROTO_IP, SO_RTABLE, &rtableid,
> +                     if (setsockopt(s, SOL_SOCKET, SO_RTABLE, &rtableid,
>                           sizeof(rtableid)) == -1)
>                               err(1, "setsockopt SO_RTABLE");
>               }
> Index: usr.bin/tcpbench/tcpbench.c
> ===================================================================
> RCS file: /home/cvs/src/usr.bin/tcpbench/tcpbench.c,v
> retrieving revision 1.21
> diff -u -p -r1.21 tcpbench.c
> --- usr.bin/tcpbench/tcpbench.c       16 Mar 2011 08:06:10 -0000      1.21
> +++ usr.bin/tcpbench/tcpbench.c       20 Jun 2011 15:53:59 -0000
> @@ -719,9 +719,10 @@ server_init(struct addrinfo *aitop, stru
>                               warn("socket");
>                       continue;
>               }
> -             if (ptb->Vflag && ai->ai_family == AF_INET) {
> -                     if (setsockopt(sock, IPPROTO_IP, SO_RTABLE,
> -                         &ptb->Vflag, sizeof(ptb->Vflag)) == -1)
> +             if (ptb->Vflag) {
> +                     if (setsockopt(sock, SOL_SOCKET, SO_RTABLE,
> +                         &ptb->Vflag, sizeof(ptb->Vflag)) == -1 &&
> +                         errno != ENOPROTOOPT)
>                               err(1, "setsockopt SO_RTABLE");
>               } else if (ptb->Vflag)
>                       warnx("rtable only supported on AF_INET");
> @@ -817,9 +818,10 @@ client_init(struct addrinfo *aitop, int 
>                                       warn("socket");
>                               continue;
>                       }
> -                     if (ptb->Vflag && ai->ai_family == AF_INET) {
> -                             if (setsockopt(sock, IPPROTO_IP, SO_RTABLE,
> -                                 &ptb->Vflag, sizeof(ptb->Vflag)) == -1)
> +                     if (ptb->Vflag) {
> +                             if (setsockopt(sock, SOL_SOCKET, SO_RTABLE,
> +                                 &ptb->Vflag, sizeof(ptb->Vflag)) == -1 &&
> +                                 errno != ENOPROTOOPT)
>                                       err(1, "setsockopt SO_RTABLE");
>                       } else if (ptb->Vflag)
>                               warnx("rtable only supported on AF_INET");
> Index: usr.bin/telnet/commands.c
> ===================================================================
> RCS file: /home/cvs/src/usr.bin/telnet/commands.c,v
> retrieving revision 1.52
> diff -u -p -r1.52 commands.c
> --- usr.bin/telnet/commands.c 3 Jul 2010 04:44:51 -0000       1.52
> +++ usr.bin/telnet/commands.c 20 Jun 2011 16:00:02 -0000
> @@ -2397,7 +2397,7 @@ tn(argc, argv)
>           continue;
>  
>       if (rtableid) {
> -             if (setsockopt(net, IPPROTO_IP, SO_RTABLE, &rtableid,
> +             if (setsockopt(net, SOL_SOCKET, SO_RTABLE, &rtableid,
>                   sizeof(rtableid)) == -1)
>                       perror("setsockopt (SO_RTABLE)");
>       }
> Index: usr.sbin/dhcrelay/dhcrelay.c
> ===================================================================
> RCS file: /home/cvs/src/usr.sbin/dhcrelay/dhcrelay.c,v
> retrieving revision 1.34
> diff -u -p -r1.34 dhcrelay.c
> --- usr.sbin/dhcrelay/dhcrelay.c      3 Jul 2010 04:44:52 -0000       1.34
> +++ usr.sbin/dhcrelay/dhcrelay.c      20 Jun 2011 16:05:40 -0000
> @@ -176,7 +176,7 @@ main(int argc, char *argv[])
>               if (setsockopt(sp->fd, SOL_SOCKET, SO_REUSEPORT,
>                   &opt, sizeof(opt)) == -1)
>                       error("setsockopt: %m");
> -             if (setsockopt(sp->fd, IPPROTO_IP, SO_RTABLE, &rdomain,
> +             if (setsockopt(sp->fd, SOL_SOCKET, SO_RTABLE, &rdomain,
>                   sizeof(rdomain)) == -1)
>                       error("setsockopt: %m");
>               if (bind(sp->fd, (struct sockaddr *)&laddr, sizeof laddr) == -1)
> @@ -197,7 +197,7 @@ main(int argc, char *argv[])
>               if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEPORT,
>                   &opt, sizeof(opt)) == -1)
>                       error("setsockopt: %m");
> -             if (setsockopt(server_fd, IPPROTO_IP, SO_RTABLE, &rdomain,
> +             if (setsockopt(server_fd, SOL_SOCKET, SO_RTABLE, &rdomain,
>                   sizeof(rdomain)) == -1)
>                       error("setsockopt: %m");
>               if (bind(server_fd, (struct sockaddr *)&laddr,
> Index: usr.sbin/ftp-proxy/ftp-proxy.c
> ===================================================================
> RCS file: /home/cvs/src/usr.sbin/ftp-proxy/ftp-proxy.c,v
> retrieving revision 1.22
> diff -u -p -r1.22 ftp-proxy.c
> --- usr.sbin/ftp-proxy/ftp-proxy.c    28 Apr 2011 00:17:28 -0000      1.22
> +++ usr.sbin/ftp-proxy/ftp-proxy.c    4 May 2011 11:59:55 -0000
> @@ -428,9 +428,8 @@ handle_connection(const int listen_fd, s
>               goto fail;
>       }
>       len = sizeof(s->client_rd);
> -     if (client_sa->sa_family == AF_INET &&
> -         getsockopt(s->client_fd, IPPROTO_IP, SO_RTABLE, &s->client_rd,
> -         &len)) {
> +     if (getsockopt(s->client_fd, SOL_SOCKET, SO_RTABLE, &s->client_rd,
> +         &len) && errno != ENOPROTOOPT) {
>               logmsg(LOG_CRIT, "#%d getsockopt failed: %s", s->id,
>                   strerror(errno));
>               goto fail;
> Index: usr.sbin/ospfd/interface.c
> ===================================================================
> RCS file: /home/cvs/src/usr.sbin/ospfd/interface.c,v
> retrieving revision 1.72
> diff -u -p -r1.72 interface.c
> --- usr.sbin/ospfd/interface.c        9 May 2011 12:24:41 -0000       1.72
> +++ usr.sbin/ospfd/interface.c        20 Jun 2011 16:06:12 -0000
> @@ -257,7 +257,7 @@ if_init(struct ospfd_conf *xconf, struct
>               rdomain = 0;
>       else {
>               rdomain = ifr.ifr_rdomainid;
> -             if (setsockopt(iface->fd, IPPROTO_IP, SO_RTABLE,
> +             if (setsockopt(iface->fd, SOL_SOCKET, SO_RTABLE,
>                   &rdomain, sizeof(rdomain)) == -1)
>                       fatal("failed to set rdomain");
>       }
> Index: usr.sbin/ripd/interface.c
> ===================================================================
> RCS file: /home/cvs/src/usr.sbin/ripd/interface.c,v
> retrieving revision 1.9
> diff -u -p -r1.9 interface.c
> --- usr.sbin/ripd/interface.c 3 Jul 2010 04:44:52 -0000       1.9
> +++ usr.sbin/ripd/interface.c 20 Jun 2011 16:07:31 -0000
> @@ -83,7 +83,7 @@ if_init(struct ripd_conf *xconf, struct 
>               rdomain = 0;
>       else {
>               rdomain = ifr.ifr_rdomainid;
> -             if (setsockopt(iface->fd, IPPROTO_IP, SO_RTABLE, &rdomain,
> +             if (setsockopt(iface->fd, SOL_SOCKET, SO_RTABLE, &rdomain,
>                   sizeof(rdomain)) == -1)
>                       fatal("failed to set rdomain");
>       }
> Index: usr.sbin/traceroute/traceroute.c
> ===================================================================
> RCS file: /home/cvs/src/usr.sbin/traceroute/traceroute.c,v
> retrieving revision 1.76
> diff -u -p -r1.76 traceroute.c
> --- usr.sbin/traceroute/traceroute.c  23 Apr 2011 10:00:13 -0000      1.76
> +++ usr.sbin/traceroute/traceroute.c  20 Jun 2011 16:08:07 -0000
> @@ -442,10 +442,10 @@ main(int argc, char *argv[])
>                       if (errstr)
>                               errx(1, "rtable value is %s: %s",
>                                   errstr, optarg);
> -                     if (setsockopt(sndsock, IPPROTO_IP, SO_RTABLE,
> +                     if (setsockopt(sndsock, SOL_SOCKET, SO_RTABLE,
>                           &rtableid, sizeof(rtableid)) == -1)
>                               err(1, "setsockopt SO_RTABLE");
> -                     if (setsockopt(s, IPPROTO_IP, SO_RTABLE,
> +                     if (setsockopt(s, SOL_SOCKET, SO_RTABLE,
>                           &rtableid, sizeof(rtableid)) == -1)
>                               err(1, "setsockopt SO_RTABLE");
>                       break;
> 

-- 
:wq Claudio

Reply via email to