Author: markj
Date: Sat Nov 17 20:54:24 2018
New Revision: 340521
URL: https://svnweb.freebsd.org/changeset/base/340521

Log:
  MFC r339453, r339455, r339456, r339460, r339687, r339745, r339747:
  Miscellaneous cleanups of rtsol(d).

Modified:
  stable/12/usr.sbin/rtsold/if.c
  stable/12/usr.sbin/rtsold/rtsock.c
  stable/12/usr.sbin/rtsold/rtsol.c
  stable/12/usr.sbin/rtsold/rtsold.8
  stable/12/usr.sbin/rtsold/rtsold.c
  stable/12/usr.sbin/rtsold/rtsold.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.sbin/rtsold/if.c
==============================================================================
--- stable/12/usr.sbin/rtsold/if.c      Sat Nov 17 20:47:41 2018        
(r340520)
+++ stable/12/usr.sbin/rtsold/if.c      Sat Nov 17 20:54:24 2018        
(r340521)
@@ -332,37 +332,6 @@ if_nametosdl(char *name)
        return (ret_sdl);
 }
 
-int
-getinet6sysctl(int code)
-{
-       int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, 0 };
-       int value;
-       size_t size;
-
-       mib[3] = code;
-       size = sizeof(value);
-       if (sysctl(mib, nitems(mib), &value, &size, NULL, 0) < 0)
-               return (-1);
-       else
-               return (value);
-}
-
-int
-setinet6sysctl(int code, int newval)
-{
-       int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, 0 };
-       int value;
-       size_t size;
-
-       mib[3] = code;
-       size = sizeof(value);
-       if (sysctl(mib, nitems(mib), &value, &size,
-           &newval, sizeof(newval)) < 0)
-               return (-1);
-       else
-               return (value);
-}
-
 /*------------------------------------------------------------*/
 
 /* get ia6_flags for link-local addr on if.  returns -1 on error. */

Modified: stable/12/usr.sbin/rtsold/rtsock.c
==============================================================================
--- stable/12/usr.sbin/rtsold/rtsock.c  Sat Nov 17 20:47:41 2018        
(r340520)
+++ stable/12/usr.sbin/rtsold/rtsock.c  Sat Nov 17 20:54:24 2018        
(r340521)
@@ -57,27 +57,15 @@
 #include <syslog.h>
 #include "rtsold.h"
 
-#define ROUNDUP(a, size) \
-       (((a) & ((size)-1)) ? (1 + ((a) | ((size)-1))) : (a))
-
-#define NEXT_SA(ap) (ap) = (struct sockaddr *) \
-       ((caddr_t)(ap) + \
-        ((ap)->sa_len ? ROUNDUP((ap)->sa_len, sizeof(u_long)) \
-                      : sizeof(u_long)))
-
-#ifdef RTM_IFANNOUNCE  /*NetBSD 1.5 or later*/
 static int rtsock_input_ifannounce(int, struct rt_msghdr *, char *);
-#endif
 
 static struct {
        u_char type;
        size_t minlen;
        int (*func)(int, struct rt_msghdr *, char *);
 } rtsock_dispatch[] = {
-#ifdef RTM_IFANNOUNCE  /*NetBSD 1.5 or later*/
        { RTM_IFANNOUNCE, sizeof(struct if_announcemsghdr),
          rtsock_input_ifannounce },
-#endif
        { 0, 0, NULL },
 };
 
@@ -135,7 +123,6 @@ rtsock_input(int s)
        return (ret);
 }
 
-#ifdef RTM_IFANNOUNCE  /*NetBSD 1.5 or later*/
 static int
 rtsock_input_ifannounce(int s __unused, struct rt_msghdr *rtm, char *lim)
 {
@@ -174,4 +161,3 @@ rtsock_input_ifannounce(int s __unused, struct rt_msgh
 
        return (0);
 }
-#endif

Modified: stable/12/usr.sbin/rtsold/rtsol.c
==============================================================================
--- stable/12/usr.sbin/rtsold/rtsol.c   Sat Nov 17 20:47:41 2018        
(r340520)
+++ stable/12/usr.sbin/rtsold/rtsol.c   Sat Nov 17 20:54:24 2018        
(r340521)
@@ -98,22 +98,20 @@ static char *make_rsid(const char *, const char *, str
 #define        _ARGS_RESADD    resolvconf_script, "-a", rsid
 #define        _ARGS_RESDEL    resolvconf_script, "-d", rsid
 
-#define        CALL_SCRIPT(name, sm_head)                                      
\
-       do {                                                            \
-               const char *const sarg[] = { _ARGS_##name, NULL };      \
-               call_script(sizeof(sarg), sarg, sm_head);               \
-       } while(0)
+#define        CALL_SCRIPT(name, sm_head) do {                         \
+       const char *const sarg[] = { _ARGS_##name, NULL };      \
+       call_script(sizeof(sarg), sarg, sm_head);               \
+} while (0)
 
-#define        ELM_MALLOC(p,error_action)                                      
\
-       do {                                                            \
-               p = malloc(sizeof(*p));                                 \
-               if (p == NULL) {                                        \
-                       warnmsg(LOG_ERR, __func__, "malloc failed: %s", \
-                               strerror(errno));                       \
-                       error_action;                                   \
-               }                                                       \
-               memset(p, 0, sizeof(*p));                               \
-       } while(0)
+#define        ELM_MALLOC(p, error_action) do {                        \
+       p = malloc(sizeof(*p));                                 \
+       if (p == NULL) {                                        \
+               warnmsg(LOG_ERR, __func__, "malloc failed: %s", \
+                   strerror(errno));                           \
+               error_action;                                   \
+       }                                                       \
+       memset(p, 0, sizeof(*p));                               \
+} while (0)
 
 int
 sockopen(void)
@@ -616,7 +614,6 @@ ra_opt_handler(struct ifinfo *ifi)
                                TAILQ_INSERT_TAIL(&sm_rdnss_head, smp3,
                                    sm_next);
                                ifi->ifi_rdnss = IFI_DNSOPT_STATE_RECEIVED;
-
                                break;
                        case ND_OPT_DNSSL:
                                if (TS_CMP(&now, &rao->rao_expire, >)) {
@@ -656,10 +653,7 @@ ra_opt_handler(struct ifinfo *ifi)
                                    sm_next);
                                dlen += strlen(rao->rao_msg) +
                                    strlen(resstr_sp);
-                               break;
-
                                ifi->ifi_dnssl = IFI_DNSOPT_STATE_RECEIVED;
-                       default:
                                break;
                        }
                        continue;
@@ -701,13 +695,12 @@ make_rsid(const char *ifname, const char *origin, stru
 }
 
 int
-ra_opt_rdnss_dispatch(struct ifinfo *ifi,
-    struct rainfo *rai,
+ra_opt_rdnss_dispatch(struct ifinfo *ifi, struct rainfo *rai,
     struct script_msg_head_t *sm_rdnss_head,
     struct script_msg_head_t *sm_dnssl_head)
 {
-       const char *r;
        struct script_msg *smp1;
+       const char *r;
        int error;
 
        error = 0;
@@ -719,10 +712,7 @@ ra_opt_rdnss_dispatch(struct ifinfo *ifi,
        }
        TAILQ_CONCAT(sm_rdnss_head, sm_dnssl_head, sm_next);
 
-       if (rai != NULL && uflag)
-               r = make_rsid(ifi->ifname, DNSINFO_ORIGIN_LABEL, rai);
-       else
-               r = make_rsid(ifi->ifname, DNSINFO_ORIGIN_LABEL, NULL);
+       r = make_rsid(ifi->ifname, DNSINFO_ORIGIN_LABEL, uflag ? rai : NULL);
        if (r == NULL) {
                warnmsg(LOG_ERR, __func__, "make_rsid() failed.  "
                    "Script was not invoked.");

Modified: stable/12/usr.sbin/rtsold/rtsold.8
==============================================================================
--- stable/12/usr.sbin/rtsold/rtsold.8  Sat Nov 17 20:47:41 2018        
(r340520)
+++ stable/12/usr.sbin/rtsold/rtsold.8  Sat Nov 17 20:54:24 2018        
(r340521)
@@ -241,16 +241,16 @@ The
 .Xr resolvconf 8
 script is used by default.
 .It Fl u
-Specifies whether adding the source address of Router Advertisement
-messages to the interface name in an argument of the RDNSS and DNSSL
-script.
+Specifies whether to add the source address of Router Advertisement
+messages to the interface name in the parameters of the RDNSS and DNSSL
+scripts.
 .Pp
 If
 .Fl u
-is specified, the interface name in the script argument will be
+is specified, the interface name in the script parameters will be
 .Ql ifname:slaac:[RA-source-address] .
 .Pp
-If not, it will be
+Otherwise it will be
 .Ql ifname:slaac .
 .El
 .Sh FILES

Modified: stable/12/usr.sbin/rtsold/rtsold.c
==============================================================================
--- stable/12/usr.sbin/rtsold/rtsold.c  Sat Nov 17 20:47:41 2018        
(r340520)
+++ stable/12/usr.sbin/rtsold/rtsold.c  Sat Nov 17 20:54:24 2018        
(r340521)
@@ -33,10 +33,9 @@
  * $FreeBSD$
  */
 
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <sys/param.h>
 
 #include <net/if.h>
 #include <net/if_dl.h>
@@ -98,10 +97,8 @@ static int do_dump;
 static const char *dumpfilename = RTSOL_DUMPFILE;
 #endif
 
-#if 0
-static int ifreconfig(char *);
-#endif
-
+static char **autoifprobe(void);
+static int ifconfig(char *ifname);
 static int make_packet(struct ifinfo *);
 static struct timespec *rtsol_check_timer(void);
 
@@ -217,16 +214,6 @@ main(int argc, char **argv)
                    pidfilename);
        }
 
-#if (__FreeBSD_version < 900000)
-       if (Fflag) {
-               setinet6sysctl(IPV6CTL_FORWARDING, 0);
-       } else {
-               /* warn if forwarding is up */
-               if (getinet6sysctl(IPV6CTL_FORWARDING))
-                       warnx("kernel is configured as a router, not a host");
-       }
-#endif
-
 #ifndef SMALL
        /* initialization to dump internal status to a file */
        signal(SIGUSR1, rtsold_set_dump_file);
@@ -340,23 +327,23 @@ main(int argc, char **argv)
        return (0);
 }
 
-int
+static int
 ifconfig(char *ifname)
 {
        struct ifinfo *ifi;
        struct sockaddr_dl *sdl;
        int flags;
 
+       ifi = NULL;
        if ((sdl = if_nametosdl(ifname)) == NULL) {
                warnmsg(LOG_ERR, __func__,
                    "failed to get link layer information for %s", ifname);
-               return (-1);
+               goto bad;
        }
        if (find_ifinfo(sdl->sdl_index)) {
                warnmsg(LOG_ERR, __func__,
                    "interface %s was already configured", ifname);
-               free(sdl);
-               return (-1);
+               goto bad;
        }
 
        if (Fflag) {
@@ -365,30 +352,29 @@ ifconfig(char *ifname)
 
                if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
                        warnmsg(LOG_ERR, __func__, "socket() failed.");
-                       return (-1);
+                       goto bad;
                }
                memset(&nd, 0, sizeof(nd));
                strlcpy(nd.ifname, ifname, sizeof(nd.ifname));
                if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) {
                        warnmsg(LOG_ERR, __func__,
                            "cannot get accept_rtadv flag");
-                       close(s);
-                       return (-1);
+                       (void)close(s);
+                       goto bad;
                }
                nd.ndi.flags |= ND6_IFF_ACCEPT_RTADV;
                if (ioctl(s, SIOCSIFINFO_IN6, (caddr_t)&nd) < 0) {
                        warnmsg(LOG_ERR, __func__,
                            "cannot set accept_rtadv flag");
-                       close(s);
-                       return (-1);
+                       (void)close(s);
+                       goto bad;
                }
-               close(s);
+               (void)close(s);
        }
 
        if ((ifi = malloc(sizeof(*ifi))) == NULL) {
                warnmsg(LOG_ERR, __func__, "memory allocation failed");
-               free(sdl);
-               return (-1);
+               goto bad;
        }
        memset(ifi, 0, sizeof(*ifi));
        ifi->sdl = sdl;
@@ -439,53 +425,11 @@ ifconfig(char *ifname)
        return (0);
 
 bad:
-       free(ifi->sdl);
+       free(sdl);
        free(ifi);
        return (-1);
 }
 
-void
-iflist_init(void)
-{
-       struct ifinfo *ifi;
-
-       while ((ifi = TAILQ_FIRST(&ifinfo_head)) != NULL) {
-               TAILQ_REMOVE(&ifinfo_head, ifi, ifi_next);
-               if (ifi->sdl != NULL)
-                       free(ifi->sdl);
-               if (ifi->rs_data != NULL)
-                       free(ifi->rs_data);
-               free(ifi);
-       }
-}
-
-#if 0
-static int
-ifreconfig(char *ifname)
-{
-       struct ifinfo *ifi, *prev;
-       int rv;
-
-       prev = NULL;
-       TAILQ_FOREACH(ifi, &ifinfo_head, ifi_next) {
-               if (strncmp(ifi->ifname, ifname, sizeof(ifi->ifname)) == 0)
-                       break;
-               prev = ifi;
-       }
-       prev->next = ifi->next;
-
-       rv = ifconfig(ifname);
-
-       /* reclaim it after ifconfig() in case ifname is pointer inside ifi */
-       if (ifi->rs_data)
-               free(ifi->rs_data);
-       free(ifi->sdl);
-       free(ifi);
-
-       return (rv);
-}
-#endif
-
 struct rainfo *
 find_rainfo(struct ifinfo *ifi, struct sockaddr_in6 *sin6)
 {
@@ -767,9 +711,6 @@ rtsol_timer_update(struct ifinfo *ifi)
 #undef MILLION
 }
 
-/* timer related utility functions */
-#define MILLION 1000000
-
 #ifndef SMALL
 static void
 rtsold_set_dump_file(int sig __unused)
@@ -817,7 +758,7 @@ warnmsg(int priority, const char *func, const char *ms
 /*
  * return a list of interfaces which is suitable to sending an RS.
  */
-char **
+static char **
 autoifprobe(void)
 {
        static char **argv = NULL;

Modified: stable/12/usr.sbin/rtsold/rtsold.h
==============================================================================
--- stable/12/usr.sbin/rtsold/rtsold.h  Sat Nov 17 20:47:41 2018        
(r340520)
+++ stable/12/usr.sbin/rtsold/rtsold.h  Sat Nov 17 20:54:24 2018        
(r340521)
@@ -157,14 +157,11 @@ extern int Fflag;
 extern int uflag;
 extern const char *otherconf_script;
 extern const char *resolvconf_script;
-extern int ifconfig(char *);
-extern void iflist_init(void);
 struct ifinfo *find_ifinfo(int);
 struct rainfo *find_rainfo(struct ifinfo *, struct sockaddr_in6 *);
 void rtsol_timer_update(struct ifinfo *);
 extern void warnmsg(int, const char *, const char *, ...)
      __attribute__((__format__(__printf__, 3, 4)));
-extern char **autoifprobe(void);
 extern int ra_opt_handler(struct ifinfo *);
 
 /* if.c */
@@ -174,8 +171,6 @@ extern int interface_status(struct ifinfo *);
 extern int lladdropt_length(struct sockaddr_dl *);
 extern void lladdropt_fill(struct sockaddr_dl *, struct nd_opt_hdr *);
 extern struct sockaddr_dl *if_nametosdl(char *);
-extern int getinet6sysctl(int);
-extern int setinet6sysctl(int, int);
 
 /* rtsol.c */
 extern int rssock;
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to