Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/route6d Clean up.



details:   https://anonhg.NetBSD.org/src/rev/d4de5238ef57
branches:  trunk
changeset: 318901:d4de5238ef57
user:      maxv <maxv%NetBSD.org@localhost>
date:      Wed May 09 07:21:08 2018 +0000
description:
Clean up.

diffstat:

 usr.sbin/route6d/route6d.c |  255 ++++++++++++++++----------------------------
 usr.sbin/route6d/route6d.h |    8 +-
 2 files changed, 98 insertions(+), 165 deletions(-)

diffs (truncated from 887 to 300 lines):

diff -r 7b1e64d11e37 -r d4de5238ef57 usr.sbin/route6d/route6d.c
--- a/usr.sbin/route6d/route6d.c        Wed May 09 07:05:42 2018 +0000
+++ b/usr.sbin/route6d/route6d.c        Wed May 09 07:21:08 2018 +0000
@@ -1,10 +1,10 @@
-/*     $NetBSD: route6d.c,v 1.69 2018/05/09 07:05:42 maxv Exp $        */
+/*     $NetBSD: route6d.c,v 1.70 2018/05/09 07:21:08 maxv Exp $        */
 /*     $KAME: route6d.c,v 1.94 2002/10/26 20:08:55 itojun Exp $        */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  * All rights reserved.
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -16,7 +16,7 @@
  * 3. Neither the name of the project nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #ifndef        lint
-__RCSID("$NetBSD: route6d.c,v 1.69 2018/05/09 07:05:42 maxv Exp $");
+__RCSID("$NetBSD: route6d.c,v 1.70 2018/05/09 07:21:08 maxv Exp $");
 #endif
 
 #include <stdbool.h>
@@ -59,9 +59,6 @@
 #include <sys/sysctl.h>
 #include <sys/uio.h>
 #include <net/if.h>
-#if defined(__FreeBSD__) && __FreeBSD__ >= 3
-#include <net/if_var.h>
-#endif /* __FreeBSD__ >= 3 */
 #include <net/route.h>
 #include <netinet/in.h>
 #include <netinet/in_var.h>
@@ -74,22 +71,21 @@
 
 #include "route6d.h"
 
-#define        MAXFILTER       40
+#define MAXFILTER      40
 
-#ifdef DEBUG
-#define        INIT_INTERVAL6  6
+#ifdef DEBUG
+#define INIT_INTERVAL6 6
 #else
-#define        INIT_INTERVAL6  10      /* Wait to submit a initial riprequest */
+#define INIT_INTERVAL6 10      /* Wait to submit a initial riprequest */
 #endif
 
 /* alignment constraint for routing socket */
-#if defined(__NetBSD__) && defined(RT_ROUNDUP)
+#if defined(RT_ROUNDUP)
 #define ROUNDUP(a) RT_ROUNDUP(a)
 #else
 #define ROUNDUP(a) \
        ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
 #endif
-#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
 
 /*
  * Following two macros are highly depending on KAME Release
@@ -118,7 +114,7 @@
        int     ifc_joined;                     /* joined to ff02::9 */
 };
 
-struct ifac {                  /* Address associated to an interface */ 
+struct ifac {                  /* Address associated to an interface */
        struct  ifc *ifa_conf;          /* back pointer */
        struct  ifac *ifa_next;
        struct  in6_addr ifa_addr;      /* address */
@@ -194,17 +190,17 @@
 
 static int logopened = 0;
 
-static int     seq = 0;
+static int     seq = 0;
 
 static volatile sig_atomic_t seenalrm;
 static volatile sig_atomic_t seenquit;
 static volatile sig_atomic_t seenusr1;
 
-#define        RRTF_AGGREGATE          0x08000000
-#define        RRTF_NOADVERTISE        0x10000000
-#define        RRTF_NH_NOT_LLADDR      0x20000000
+#define RRTF_AGGREGATE         0x08000000
+#define RRTF_NOADVERTISE       0x10000000
+#define RRTF_NH_NOT_LLADDR     0x20000000
 #define RRTF_SENDANYWAY                0x40000000
-#define        RRTF_CHANGED            0x80000000
+#define RRTF_CHANGED           0x80000000
 
 static void    sighandler(int);
 static void    ripalarm(void);
@@ -267,14 +263,14 @@
        iff_find(struct ifc *, int);
 static void    setindex2ifc(int, struct ifc *);
 
-#define        MALLOC(type)    ((type *)malloc(sizeof(type)))
+#define        MALLOC(type)    (malloc(sizeof(type)))
 
 int
 main(int argc, char **argv)
 {
-       int     ch;
-       int     error = 0;
-       struct  ifc *ifcp;
+       int ch;
+       int error = 0;
+       struct ifc *ifcp;
        sigset_t mask, omask;
        char *progname;
        char *ep;
@@ -295,7 +291,6 @@
                case 'L':
                        if (nfilter >= MAXFILTER) {
                                fatal("Exceeds MAXFILTER");
-                               /*NOTREACHED*/
                        }
                        filtertype[nfilter] = ch;
                        filter[nfilter++] = allocopy(optarg);
@@ -305,13 +300,11 @@
                        routetag = strtoul(optarg, &ep, 0);
                        if (!ep || *ep != '\0' || (routetag & ~0xffff) != 0) {
                                fatal("invalid route tag");
-                               /*NOTREACHED*/
                        }
                        break;
                case 'R':
                        if ((rtlog = fopen(optarg, "w")) == NULL) {
                                fatal("Can not write to routelog");
-                               /*NOTREACHED*/
                        }
                        break;
 #define        FLAG(c, flag, n)        case c: do { flag = n; break; } while(0)
@@ -327,14 +320,12 @@
 #undef FLAG
                default:
                        fatal("Invalid option specified, terminating");
-                       /*NOTREACHED*/
                }
        }
        argc -= optind;
        argv += optind;
        if (argc > 0) {
                fatal("bogus extra arguments");
-               /*NOTREACHED*/
        }
 
        if (geteuid()) {
@@ -345,14 +336,13 @@
        if (dflag == 0) {
                if (daemon(0, 0) < 0) {
                        fatal("daemon");
-                       /*NOTREACHED*/
                }
        }
 
        openlog(progname, LOG_NDELAY|LOG_PID, LOG_DAEMON);
        logopened++;
 
-       if ((ripbuf = (struct rip6 *)malloc(RIP6_MAXMTU)) == NULL)
+       if ((ripbuf = malloc(RIP6_MAXMTU)) == NULL)
                fatal("malloc");
        memset(ripbuf, 0, RIP6_MAXMTU);
        ripbuf->rip6_cmd = RIP6_RESPONSE;
@@ -374,7 +364,6 @@
                exit(1);
        if (loopifcp == NULL) {
                fatal("No loopback found");
-               /*NOTREACHED*/
        }
        for (ifcp = ifc; ifcp; ifcp = ifcp->ifc_next)
                ifrt(ifcp, 0);
@@ -385,9 +374,8 @@
 
        pidfile(NULL);
 
-       if ((ripbuf = (struct rip6 *)malloc(RIP6_MAXMTU)) == NULL) {
+       if ((ripbuf = malloc(RIP6_MAXMTU)) == NULL) {
                fatal("malloc");
-               /*NOTREACHED*/
        }
        memset(ripbuf, 0, RIP6_MAXMTU);
        ripbuf->rip6_cmd = RIP6_RESPONSE;
@@ -402,7 +390,6 @@
            signal(SIGHUP, sighandler) == SIG_ERR ||
            signal(SIGINT, sighandler) == SIG_ERR) {
                fatal("signal");
-               /*NOTREACHED*/
        }
        /*
         * To avoid rip packet congestion (not on a cable but in this
@@ -443,7 +430,6 @@
                case -1:
                        if (errno != EINTR) {
                                fatal("poll");
-                               /*NOTREACHED*/
                        }
                        continue;
                case 0:
@@ -492,7 +478,7 @@
 static void
 rtdexit(void)
 {
-       struct  riprt *rrt;
+       struct riprt *rrt;
 
        alarm(0);
        for (rrt = riprt; rrt; rrt = rrt->rrt_next) {
@@ -519,9 +505,9 @@
 static void
 ripalarm(void)
 {
-       struct  ifc *ifcp;
-       struct  riprt *rrt, *rrt_prev, *rrt_next;
-       time_t  t_lifetime, t_holddown;
+       struct ifc *ifcp;
+       struct riprt *rrt, *rrt_prev, *rrt_next;
+       time_t t_lifetime, t_holddown;
 
        /* age the RIP routes */
        rrt_prev = 0;
@@ -559,10 +545,10 @@
 static void
 init(void)
 {
-       int     i, error;
+       int i, error;
        const int int0 = 0, int1 = 1, int255 = 255;
-       struct  addrinfo hints, *res;
-       char    port[NI_MAXSERV];
+       struct addrinfo hints, *res;
+       char port[NI_MAXSERV];
 
        ifc = NULL;
        nifc = 0;
@@ -577,43 +563,35 @@
        error = getaddrinfo(NULL, port, &hints, &res);
        if (error) {
                fatal("%s", gai_strerror(error));
-               /*NOTREACHED*/
        }
        if (res->ai_next) {
                fatal(":: resolved to multiple address");
-               /*NOTREACHED*/
        }
 
        ripsock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
        if (ripsock < 0) {
                fatal("rip socket");
-               /*NOTREACHED*/
        }
        if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_V6ONLY,
            &int1, sizeof(int1)) < 0) {
                fatal("rip IPV6_V6ONLY");
-               /*NOTREACHED*/
        }
        if (bind(ripsock, res->ai_addr, res->ai_addrlen) < 0) {
                fatal("rip bind");
-               /*NOTREACHED*/
        }
        if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
            &int255, sizeof(int255)) < 0) {
                fatal("rip IPV6_MULTICAST_HOPS");
-               /*NOTREACHED*/
        }
        if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
            &int0, sizeof(int0)) < 0) {
                fatal("rip IPV6_MULTICAST_LOOP");
-               /*NOTREACHED*/
        }
 
        i = 1;
        if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &i,
            sizeof(i)) < 0) {
                fatal("rip IPV6_RECVPKTINFO");
-               /*NOTREACHED*/
        }
 
        memset(&hints, 0, sizeof(hints));
@@ -622,11 +600,9 @@
        error = getaddrinfo(RIP6_DEST, port, &hints, &res);
        if (error) {
                fatal("%s", gai_strerror(error));
-               /*NOTREACHED*/
        }
        if (res->ai_next) {
                fatal("%s resolved to multiple address", RIP6_DEST);
-               /*NOTREACHED*/



Home | Main Index | Thread Index | Old Index