Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/rtadvd - remove extra \n from stderr logging



details:   https://anonhg.NetBSD.org/src/rev/51248a5205d5
branches:  trunk
changeset: 1019871:51248a5205d5
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Mar 22 18:41:11 2021 +0000

description:
- remove extra \n from stderr logging
- add string message types
- sprinkle const

diffstat:

 usr.sbin/rtadvd/config.c |    5 +-
 usr.sbin/rtadvd/config.h |    4 +-
 usr.sbin/rtadvd/if.c     |  103 ++++++++++++++++++++++++++--------------------
 usr.sbin/rtadvd/if.h     |   23 +++++-----
 usr.sbin/rtadvd/rtadvd.c |   12 ++--
 usr.sbin/rtadvd/rtadvd.h |    4 +-
 6 files changed, 82 insertions(+), 69 deletions(-)

diffs (truncated from 345 to 300 lines):

diff -r 27c21705dee0 -r 51248a5205d5 usr.sbin/rtadvd/config.c
--- a/usr.sbin/rtadvd/config.c  Mon Mar 22 18:40:18 2021 +0000
+++ b/usr.sbin/rtadvd/config.c  Mon Mar 22 18:41:11 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: config.c,v 1.44 2020/04/21 12:16:47 roy Exp $  */
+/*     $NetBSD: config.c,v 1.45 2021/03/22 18:41:11 christos Exp $     */
 /*     $KAME: config.c,v 1.93 2005/10/17 14:40:02 suz Exp $    */
 
 /*
@@ -965,7 +965,8 @@
  * able to be specified.
  */
 void
-add_prefix(struct rainfo *rai, int ifindex, struct in6_addr *addr, int plen)
+add_prefix(struct rainfo *rai, int ifindex, const struct in6_addr *addr,
+    int plen)
 {
        struct prefix *prefix;
        char ntopbuf[INET6_ADDRSTRLEN];
diff -r 27c21705dee0 -r 51248a5205d5 usr.sbin/rtadvd/config.h
--- a/usr.sbin/rtadvd/config.h  Mon Mar 22 18:40:18 2021 +0000
+++ b/usr.sbin/rtadvd/config.h  Mon Mar 22 18:41:11 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: config.h,v 1.11 2020/04/21 12:16:47 roy Exp $  */
+/*     $NetBSD: config.h,v 1.12 2021/03/22 18:41:11 christos Exp $     */
 /*     $KAME: config.h,v 1.9 2003/08/06 04:19:40 ono Exp $     */
 
 /*
@@ -35,7 +35,7 @@
 extern void delete_prefix(struct prefix *);
 extern void invalidate_prefix(struct prefix *);
 extern void update_prefix(struct prefix *);
-extern void add_prefix(struct rainfo *, int, struct in6_addr *, int);
+extern void add_prefix(struct rainfo *, int, const struct in6_addr *, int);
 extern void make_packet(struct rainfo *);
 extern void get_prefix(struct rainfo *);
 
diff -r 27c21705dee0 -r 51248a5205d5 usr.sbin/rtadvd/if.c
--- a/usr.sbin/rtadvd/if.c      Mon Mar 22 18:40:18 2021 +0000
+++ b/usr.sbin/rtadvd/if.c      Mon Mar 22 18:41:11 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.26 2018/04/20 10:39:37 roy Exp $      */
+/*     $NetBSD: if.c,v 1.27 2021/03/22 18:41:11 christos Exp $ */
 /*     $KAME: if.c,v 1.36 2004/11/30 22:32:01 suz Exp $        */
 
 /*
@@ -30,6 +30,7 @@
  * SUCH DAMAGE.
  */
 
+#define RTM_NAMES
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/socket.h>
@@ -65,7 +66,8 @@
 #endif
 
 static void
-get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
+get_rtaddrs(int addrs, const struct sockaddr *sa,
+    const struct sockaddr **rti_info)
 {
        int i;
 
@@ -189,14 +191,14 @@
 }
 
 #define FILTER_MATCH(type, filter) ((0x1 << type) & filter)
-#define SIN6(s) ((struct sockaddr_in6 *)(s))
-#define SDL(s) ((struct sockaddr_dl *)(s))
+#define SIN6(s) ((const struct sockaddr_in6 *)(s))
+#define SDL(s) ((const struct sockaddr_dl *)(s))
 char *
 get_next_msg(char *buf, char *lim, int ifindex, size_t *lenp, int filter)
 {
        struct rt_msghdr *rtm;
        struct ifa_msghdr *ifam;
-       struct sockaddr *sa, *dst, *gw, *ifa, *rti_info[RTAX_MAX];
+       const struct sockaddr *sa, *dst, *gw, *ifa, *rti_info[RTAX_MAX];
 
        *lenp = 0;
        for (rtm = (struct rt_msghdr *)buf;
@@ -280,85 +282,85 @@
 }
 #undef FILTER_MATCH
 
-struct in6_addr *
-get_addr(char *buf)
+const struct in6_addr *
+get_addr(const void *buf)
 {
-       struct rt_msghdr *rtm = (struct rt_msghdr *)buf;
-       struct sockaddr *sa, *rti_info[RTAX_MAX];
+       const struct rt_msghdr *rtm = buf;
+       const struct sockaddr *sa, *rti_info[RTAX_MAX];
 
-       sa = (struct sockaddr *)(rtm + 1);
+       sa = (const struct sockaddr *)(rtm + 1);
        get_rtaddrs(rtm->rtm_addrs, sa, rti_info);
 
-       return(&SIN6(rti_info[RTAX_DST])->sin6_addr);
+       return &SIN6(rti_info[RTAX_DST])->sin6_addr;
 }
 
 int
-get_rtm_ifindex(char *buf)
+get_rtm_ifindex(const void *buf)
 {
-       struct rt_msghdr *rtm = (struct rt_msghdr *)buf;
-       struct sockaddr *sa, *rti_info[RTAX_MAX];
+       const struct rt_msghdr *rtm = buf;
+       const struct sockaddr *sa, *rti_info[RTAX_MAX];
 
-       sa = (struct sockaddr *)(rtm + 1);
+       sa = (const struct sockaddr *)(rtm + 1);
        get_rtaddrs(rtm->rtm_addrs, sa, rti_info);
 
-       return(((struct sockaddr_dl *)rti_info[RTAX_GATEWAY])->sdl_index);
+       return SDL(rti_info[RTAX_GATEWAY])->sdl_index;
 }
 
 int
-get_ifm_ifindex(char *buf)
+get_ifm_ifindex(const void *buf)
 {
-       struct if_msghdr *ifm = (struct if_msghdr *)buf;
+       const struct if_msghdr *ifm = buf;
 
-       return ((int)ifm->ifm_index);
+       return (int)ifm->ifm_index;
 }
 
 int
-get_ifam_ifindex(char *buf)
+get_ifam_ifindex(const void *buf)
 {
-       struct ifa_msghdr *ifam = (struct ifa_msghdr *)buf;
+       const struct ifa_msghdr *ifam = buf;
 
-       return ((int)ifam->ifam_index);
+       return (int)ifam->ifam_index;
 }
 
 int
-get_ifm_flags(char *buf)
+get_ifm_flags(const void *buf)
 {
-       struct if_msghdr *ifm = (struct if_msghdr *)buf;
+       const struct if_msghdr *ifm = buf;
 
-       return (ifm->ifm_flags);
+       return ifm->ifm_flags;
 }
 
 #ifdef RTM_IFANNOUNCE
 int
-get_ifan_ifindex(char *buf)
+get_ifan_ifindex(const void *buf)
 {
-       struct if_announcemsghdr *ifan = (struct if_announcemsghdr *)buf;
+       const struct if_announcemsghdr *ifan = buf;
 
-       return ((int)ifan->ifan_index);
+       return (int)ifan->ifan_index;
 }
 
 int
-get_ifan_what(char *buf)
+get_ifan_what(const void *buf)
 {
-       struct if_announcemsghdr *ifan = (struct if_announcemsghdr *)buf;
+       const struct if_announcemsghdr *ifan = buf;
 
-       return ((int)ifan->ifan_what);
+       return (int)ifan->ifan_what;
 }
 #endif
 
 int
-get_prefixlen(char *buf)
+get_prefixlen(const void *buf)
 {
-       struct rt_msghdr *rtm = (struct rt_msghdr *)buf;
-       struct sockaddr *sa, *rti_info[RTAX_MAX];
-       unsigned char *p, *lim;
+       const struct rt_msghdr *rtm = buf;
+       const struct sockaddr *sa, *rti_info[RTAX_MAX];
+       const unsigned char *p, *lim;
 
-       sa = (struct sockaddr *)(rtm + 1);
+       sa = (const struct sockaddr *)(rtm + 1);
        get_rtaddrs(rtm->rtm_addrs, sa, rti_info);
        sa = rti_info[RTAX_NETMASK];
 
-       p = (unsigned char *)(&SIN6(sa)->sin6_addr);
-       lim = (unsigned char *)sa + sa->sa_len;
+       p = (const unsigned char *)(&SIN6(sa)->sin6_addr);
+       lim = (const unsigned char *)sa + sa->sa_len;
        return prefixlen(p, lim);
 }
 
@@ -396,25 +398,34 @@
                case 0x00:
                        break;
                default:
-                       return(-1);
+                       return -1;
                }
        }
 
-       return(masklen);
+       return masklen;
 }
 
 int
-rtmsg_type(char *buf)
+rtmsg_type(const void *buf)
 {
-       struct rt_msghdr *rtm = (struct rt_msghdr *)buf;
+       const struct rt_msghdr *rtm = buf;
+
+       return rtm->rtm_type;
+}
 
-       return(rtm->rtm_type);
+const char *
+rtmsg_typestr(const void *buf)
+{
+       const struct rt_msghdr *rtm = buf;
+
+       return rtm->rtm_type < __arraycount(rtm_names)
+           ? rtm_names[rtm->rtm_type] : "*unknown*";
 }
 
 int
-rtmsg_len(char *buf)
+rtmsg_len(const void *buf)
 {
-       struct rt_msghdr *rtm = (struct rt_msghdr *)buf;
+       const struct rt_msghdr *rtm = buf;
 
-       return(rtm->rtm_msglen);
+       return rtm->rtm_msglen;
 }
diff -r 27c21705dee0 -r 51248a5205d5 usr.sbin/rtadvd/if.h
--- a/usr.sbin/rtadvd/if.h      Mon Mar 22 18:40:18 2021 +0000
+++ b/usr.sbin/rtadvd/if.h      Mon Mar 22 18:41:11 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.h,v 1.11 2018/04/20 10:39:37 roy Exp $      */
+/*     $NetBSD: if.h,v 1.12 2021/03/22 18:41:11 christos Exp $ */
 /*     $KAME: if.h,v 1.12 2003/09/21 07:17:03 itojun Exp $     */
 
 /*
@@ -39,16 +39,17 @@
 int lladdropt_length(struct sockaddr_dl *);
 void lladdropt_fill(struct sockaddr_dl *, struct nd_opt_hdr *);
 char *get_next_msg(char *, char *, int, size_t *, int);
-struct in6_addr *get_addr(char *);
-int get_rtm_ifindex(char *);
-int get_ifm_ifindex(char *);
-int get_ifam_ifindex(char *);
-int get_ifm_flags(char *);
+const struct in6_addr *get_addr(const void *);
+int get_rtm_ifindex(const void *);
+int get_ifm_ifindex(const void *);
+int get_ifam_ifindex(const void *);
+int get_ifm_flags(const void *);
 #ifdef RTM_IFANNOUNCE
-int get_ifan_ifindex(char *);
-int get_ifan_what(char *);
+int get_ifan_ifindex(const void *);
+int get_ifan_what(const void *);
 #endif
-int get_prefixlen(char *);
+int get_prefixlen(const void *);
 int prefixlen(const unsigned char *, const unsigned char *);
-int rtmsg_type(char *);
-int rtmsg_len(char *);
+const char *rtmsg_typestr(const void *);
+int rtmsg_type(const void *);
+int rtmsg_len(const void *);
diff -r 27c21705dee0 -r 51248a5205d5 usr.sbin/rtadvd/rtadvd.c
--- a/usr.sbin/rtadvd/rtadvd.c  Mon Mar 22 18:40:18 2021 +0000
+++ b/usr.sbin/rtadvd/rtadvd.c  Mon Mar 22 18:41:11 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtadvd.c,v 1.79 2020/08/28 00:19:37 rjs Exp $  */
+/*     $NetBSD: rtadvd.c,v 1.80 2021/03/22 18:41:11 christos Exp $     */
 /*     $KAME: rtadvd.c,v 1.92 2005/10/17 14:40:02 suz Exp $    */
 
 /*
@@ -469,7 +469,7 @@
        char ifname[IF_NAMESIZE];
        struct prefix *prefix;
        struct rainfo *rai;
-       struct in6_addr *addr;
+       const struct in6_addr *addr;
        char addrbuf[INET6_ADDRSTRLEN];
        int prefixchange = 0, argc;
 
@@ -483,8 +483,8 @@



Home | Main Index | Thread Index | Old Index