Source-Changes-HG archive

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

[src/trunk]: src/sys/compat/common Don't reference ifp->if_data directly; use...



details:   https://anonhg.NetBSD.org/src/rev/8fb9306e7225
branches:  trunk
changeset: 1006842:8fb9306e7225
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Jan 29 05:47:12 2020 +0000

description:
Don't reference ifp->if_data directly; use if_export_if_data().

diffstat:

 sys/compat/common/rtsock_14.c        |  80 ++++++++++++++++++----------------
 sys/compat/common/rtsock_50.c        |  84 ++++++++++++++++++-----------------
 sys/compat/common/uipc_syscalls_50.c |  16 +++---
 3 files changed, 93 insertions(+), 87 deletions(-)

diffs (295 lines):

diff -r cb239e76d0ea -r 8fb9306e7225 sys/compat/common/rtsock_14.c
--- a/sys/compat/common/rtsock_14.c     Wed Jan 29 05:41:48 2020 +0000
+++ b/sys/compat/common/rtsock_14.c     Wed Jan 29 05:47:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsock_14.c,v 1.9 2019/12/12 02:15:42 pgoyette Exp $   */
+/*     $NetBSD: rtsock_14.c,v 1.10 2020/01/29 05:47:12 thorpej Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock_14.c,v 1.9 2019/12/12 02:15:42 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock_14.c,v 1.10 2020/01/29 05:47:12 thorpej Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -99,6 +99,7 @@
 compat_14_rt_oifmsg(struct ifnet *ifp)
 {
        struct if_msghdr14 oifm;
+       struct if_data ifi;
        struct mbuf *m;
        struct rt_addrinfo info;
        struct timeval tv;
@@ -107,26 +108,27 @@
                return;
        (void)memset(&info, 0, sizeof(info));
        (void)memset(&oifm, 0, sizeof(oifm));
+       if_export_if_data(ifp, &ifi, false);
        oifm.ifm_index = ifp->if_index;
        oifm.ifm_flags = ifp->if_flags;
-       oifm.ifm_data.ifi_type = ifp->if_data.ifi_type;
-       oifm.ifm_data.ifi_addrlen = ifp->if_data.ifi_addrlen;
-       oifm.ifm_data.ifi_hdrlen = ifp->if_data.ifi_hdrlen;
-       oifm.ifm_data.ifi_mtu = ifp->if_data.ifi_mtu;
-       oifm.ifm_data.ifi_metric = ifp->if_data.ifi_metric;
-       oifm.ifm_data.ifi_baudrate = ifp->if_data.ifi_baudrate;
-       oifm.ifm_data.ifi_ipackets = ifp->if_data.ifi_ipackets;
-       oifm.ifm_data.ifi_ierrors = ifp->if_data.ifi_ierrors;
-       oifm.ifm_data.ifi_opackets = ifp->if_data.ifi_opackets;
-       oifm.ifm_data.ifi_oerrors = ifp->if_data.ifi_oerrors;
-       oifm.ifm_data.ifi_collisions = ifp->if_data.ifi_collisions;
-       oifm.ifm_data.ifi_ibytes = ifp->if_data.ifi_ibytes;
-       oifm.ifm_data.ifi_obytes = ifp->if_data.ifi_obytes;
-       oifm.ifm_data.ifi_imcasts = ifp->if_data.ifi_imcasts;
-       oifm.ifm_data.ifi_omcasts = ifp->if_data.ifi_omcasts;
-       oifm.ifm_data.ifi_iqdrops = ifp->if_data.ifi_iqdrops;
-       oifm.ifm_data.ifi_noproto = ifp->if_data.ifi_noproto;
-       TIMESPEC_TO_TIMEVAL(&tv, &ifp->if_data.ifi_lastchange);
+       oifm.ifm_data.ifi_type = ifi.ifi_type;
+       oifm.ifm_data.ifi_addrlen = ifi.ifi_addrlen;
+       oifm.ifm_data.ifi_hdrlen = ifi.ifi_hdrlen;
+       oifm.ifm_data.ifi_mtu = ifi.ifi_mtu;
+       oifm.ifm_data.ifi_metric = ifi.ifi_metric;
+       oifm.ifm_data.ifi_baudrate = ifi.ifi_baudrate;
+       oifm.ifm_data.ifi_ipackets = ifi.ifi_ipackets;
+       oifm.ifm_data.ifi_ierrors = ifi.ifi_ierrors;
+       oifm.ifm_data.ifi_opackets = ifi.ifi_opackets;
+       oifm.ifm_data.ifi_oerrors = ifi.ifi_oerrors;
+       oifm.ifm_data.ifi_collisions = ifi.ifi_collisions;
+       oifm.ifm_data.ifi_ibytes = ifi.ifi_ibytes;
+       oifm.ifm_data.ifi_obytes = ifi.ifi_obytes;
+       oifm.ifm_data.ifi_imcasts = ifi.ifi_imcasts;
+       oifm.ifm_data.ifi_omcasts = ifi.ifi_omcasts;
+       oifm.ifm_data.ifi_iqdrops = ifi.ifi_iqdrops;
+       oifm.ifm_data.ifi_noproto = ifi.ifi_noproto;
+       TIMESPEC_TO_TIMEVAL(&tv, &ifi.ifi_lastchange);
        timeval_to_timeval50(&tv, &oifm.ifm_data.ifi_lastchange);
        oifm.ifm_addrs = 0;
        m = compat_50_rt_msg1(RTM_OOIFINFO, &info, (void *)&oifm, sizeof(oifm));
@@ -140,30 +142,32 @@
     struct rt_addrinfo *info, size_t len)
 {
        struct if_msghdr14 *ifm;
+       struct if_data ifi;
        struct timeval tv;
        int error;
 
        ifm = (struct if_msghdr14 *)w->w_tmem;
+       if_export_if_data(ifp, &ifi, false);
        ifm->ifm_index = ifp->if_index;
        ifm->ifm_flags = ifp->if_flags;
-       ifm->ifm_data.ifi_type = ifp->if_data.ifi_type;
-       ifm->ifm_data.ifi_addrlen = ifp->if_data.ifi_addrlen;
-       ifm->ifm_data.ifi_hdrlen = ifp->if_data.ifi_hdrlen;
-       ifm->ifm_data.ifi_mtu = ifp->if_data.ifi_mtu;
-       ifm->ifm_data.ifi_metric = ifp->if_data.ifi_metric;
-       ifm->ifm_data.ifi_baudrate = ifp->if_data.ifi_baudrate;
-       ifm->ifm_data.ifi_ipackets = ifp->if_data.ifi_ipackets;
-       ifm->ifm_data.ifi_ierrors = ifp->if_data.ifi_ierrors;
-       ifm->ifm_data.ifi_opackets = ifp->if_data.ifi_opackets;
-       ifm->ifm_data.ifi_oerrors = ifp->if_data.ifi_oerrors;
-       ifm->ifm_data.ifi_collisions = ifp->if_data.ifi_collisions;
-       ifm->ifm_data.ifi_ibytes = ifp->if_data.ifi_ibytes;
-       ifm->ifm_data.ifi_obytes = ifp->if_data.ifi_obytes;
-       ifm->ifm_data.ifi_imcasts = ifp->if_data.ifi_imcasts;
-       ifm->ifm_data.ifi_omcasts = ifp->if_data.ifi_omcasts;
-       ifm->ifm_data.ifi_iqdrops = ifp->if_data.ifi_iqdrops;
-       ifm->ifm_data.ifi_noproto = ifp->if_data.ifi_noproto;
-       TIMESPEC_TO_TIMEVAL(&tv, &ifp->if_data.ifi_lastchange);
+       ifm->ifm_data.ifi_type = ifi.ifi_type;
+       ifm->ifm_data.ifi_addrlen = ifi.ifi_addrlen;
+       ifm->ifm_data.ifi_hdrlen = ifi.ifi_hdrlen;
+       ifm->ifm_data.ifi_mtu = ifi.ifi_mtu;
+       ifm->ifm_data.ifi_metric = ifi.ifi_metric;
+       ifm->ifm_data.ifi_baudrate = ifi.ifi_baudrate;
+       ifm->ifm_data.ifi_ipackets = ifi.ifi_ipackets;
+       ifm->ifm_data.ifi_ierrors = ifi.ifi_ierrors;
+       ifm->ifm_data.ifi_opackets = ifi.ifi_opackets;
+       ifm->ifm_data.ifi_oerrors = ifi.ifi_oerrors;
+       ifm->ifm_data.ifi_collisions = ifi.ifi_collisions;
+       ifm->ifm_data.ifi_ibytes = ifi.ifi_ibytes;
+       ifm->ifm_data.ifi_obytes = ifi.ifi_obytes;
+       ifm->ifm_data.ifi_imcasts = ifi.ifi_imcasts;
+       ifm->ifm_data.ifi_omcasts = ifi.ifi_omcasts;
+       ifm->ifm_data.ifi_iqdrops = ifi.ifi_iqdrops;
+       ifm->ifm_data.ifi_noproto = ifi.ifi_noproto;
+       TIMESPEC_TO_TIMEVAL(&tv, &ifi.ifi_lastchange);
        timeval_to_timeval50(&tv, &ifm->ifm_data.ifi_lastchange);
        ifm->ifm_addrs = info->rti_addrs;
        error = copyout(ifm, w->w_where, len);
diff -r cb239e76d0ea -r 8fb9306e7225 sys/compat/common/rtsock_50.c
--- a/sys/compat/common/rtsock_50.c     Wed Jan 29 05:41:48 2020 +0000
+++ b/sys/compat/common/rtsock_50.c     Wed Jan 29 05:47:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsock_50.c,v 1.15 2019/12/12 02:15:42 pgoyette Exp $  */
+/*     $NetBSD: rtsock_50.c,v 1.16 2020/01/29 05:47:12 thorpej Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock_50.c,v 1.15 2019/12/12 02:15:42 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock_50.c,v 1.16 2020/01/29 05:47:12 thorpej Exp $");
 
 #define        COMPAT_RTSOCK   /* Use the COMPATNAME/COMPATCALL macros and the
                         * various other compat definitions - see
@@ -77,6 +77,7 @@
 compat_50_rt_oifmsg(struct ifnet *ifp)
 {
        struct if_msghdr50 oifm;
+       struct if_data ifi;
        struct mbuf *m;
        struct rt_addrinfo info;
 
@@ -84,28 +85,29 @@
                return;
        (void)memset(&info, 0, sizeof(info));
        (void)memset(&oifm, 0, sizeof(oifm));
+       if_export_if_data(ifp, &ifi, false);
        oifm.ifm_index = ifp->if_index;
        oifm.ifm_flags = ifp->if_flags;
-       oifm.ifm_data.ifi_type = ifp->if_data.ifi_type;
-       oifm.ifm_data.ifi_addrlen = ifp->if_data.ifi_addrlen;
-       oifm.ifm_data.ifi_hdrlen = ifp->if_data.ifi_hdrlen;
-       oifm.ifm_data.ifi_link_state = ifp->if_data.ifi_link_state;
-       oifm.ifm_data.ifi_mtu = ifp->if_data.ifi_mtu;
-       oifm.ifm_data.ifi_metric = ifp->if_data.ifi_metric;
-       oifm.ifm_data.ifi_baudrate = ifp->if_data.ifi_baudrate;
-       oifm.ifm_data.ifi_ipackets = ifp->if_data.ifi_ipackets;
-       oifm.ifm_data.ifi_ierrors = ifp->if_data.ifi_ierrors;
-       oifm.ifm_data.ifi_opackets = ifp->if_data.ifi_opackets;
-       oifm.ifm_data.ifi_oerrors = ifp->if_data.ifi_oerrors;
-       oifm.ifm_data.ifi_collisions = ifp->if_data.ifi_collisions;
-       oifm.ifm_data.ifi_ibytes = ifp->if_data.ifi_ibytes;
-       oifm.ifm_data.ifi_obytes = ifp->if_data.ifi_obytes;
-       oifm.ifm_data.ifi_imcasts = ifp->if_data.ifi_imcasts;
-       oifm.ifm_data.ifi_omcasts = ifp->if_data.ifi_omcasts;
-       oifm.ifm_data.ifi_iqdrops = ifp->if_data.ifi_iqdrops;
-       oifm.ifm_data.ifi_noproto = ifp->if_data.ifi_noproto;
+       oifm.ifm_data.ifi_type = ifi.ifi_type;
+       oifm.ifm_data.ifi_addrlen = ifi.ifi_addrlen;
+       oifm.ifm_data.ifi_hdrlen = ifi.ifi_hdrlen;
+       oifm.ifm_data.ifi_link_state = ifi.ifi_link_state;
+       oifm.ifm_data.ifi_mtu = ifi.ifi_mtu;
+       oifm.ifm_data.ifi_metric = ifi.ifi_metric;
+       oifm.ifm_data.ifi_baudrate = ifi.ifi_baudrate;
+       oifm.ifm_data.ifi_ipackets = ifi.ifi_ipackets;
+       oifm.ifm_data.ifi_ierrors = ifi.ifi_ierrors;
+       oifm.ifm_data.ifi_opackets = ifi.ifi_opackets;
+       oifm.ifm_data.ifi_oerrors = ifi.ifi_oerrors;
+       oifm.ifm_data.ifi_collisions = ifi.ifi_collisions;
+       oifm.ifm_data.ifi_ibytes = ifi.ifi_ibytes;
+       oifm.ifm_data.ifi_obytes = ifi.ifi_obytes;
+       oifm.ifm_data.ifi_imcasts = ifi.ifi_imcasts;
+       oifm.ifm_data.ifi_omcasts = ifi.ifi_omcasts;
+       oifm.ifm_data.ifi_iqdrops = ifi.ifi_iqdrops;
+       oifm.ifm_data.ifi_noproto = ifi.ifi_noproto;
        TIMESPEC_TO_TIMEVAL(&oifm.ifm_data.ifi_lastchange,
-           &ifp->if_data.ifi_lastchange);
+           &ifi.ifi_lastchange);
        oifm.ifm_addrs = 0;
        m = COMPATNAME(rt_msg1)(RTM_OIFINFO, &info, (void *)&oifm, sizeof(oifm));
        if (m == NULL)
@@ -118,31 +120,33 @@
     struct rt_addrinfo *info, size_t len)
 {
        struct if_msghdr50 *ifm;
+       struct if_data ifi;
        int error;
 
        ifm = (struct if_msghdr50 *)w->w_tmem;
+       if_export_if_data(ifp, &ifi, false);
        ifm->ifm_index = ifp->if_index;
        ifm->ifm_flags = ifp->if_flags;
-       ifm->ifm_data.ifi_type = ifp->if_data.ifi_type;
-       ifm->ifm_data.ifi_addrlen = ifp->if_data.ifi_addrlen;
-       ifm->ifm_data.ifi_hdrlen = ifp->if_data.ifi_hdrlen;
-       ifm->ifm_data.ifi_link_state = ifp->if_data.ifi_link_state;
-       ifm->ifm_data.ifi_mtu = ifp->if_data.ifi_mtu;
-       ifm->ifm_data.ifi_metric = ifp->if_data.ifi_metric;
-       ifm->ifm_data.ifi_baudrate = ifp->if_data.ifi_baudrate;
-       ifm->ifm_data.ifi_ipackets = ifp->if_data.ifi_ipackets;
-       ifm->ifm_data.ifi_ierrors = ifp->if_data.ifi_ierrors;
-       ifm->ifm_data.ifi_opackets = ifp->if_data.ifi_opackets;
-       ifm->ifm_data.ifi_oerrors = ifp->if_data.ifi_oerrors;
-       ifm->ifm_data.ifi_collisions = ifp->if_data.ifi_collisions;
-       ifm->ifm_data.ifi_ibytes = ifp->if_data.ifi_ibytes;
-       ifm->ifm_data.ifi_obytes = ifp->if_data.ifi_obytes;
-       ifm->ifm_data.ifi_imcasts = ifp->if_data.ifi_imcasts;
-       ifm->ifm_data.ifi_omcasts = ifp->if_data.ifi_omcasts;
-       ifm->ifm_data.ifi_iqdrops = ifp->if_data.ifi_iqdrops;
-       ifm->ifm_data.ifi_noproto = ifp->if_data.ifi_noproto;
+       ifm->ifm_data.ifi_type = ifi.ifi_type;
+       ifm->ifm_data.ifi_addrlen = ifi.ifi_addrlen;
+       ifm->ifm_data.ifi_hdrlen = ifi.ifi_hdrlen;
+       ifm->ifm_data.ifi_link_state = ifi.ifi_link_state;
+       ifm->ifm_data.ifi_mtu = ifi.ifi_mtu;
+       ifm->ifm_data.ifi_metric = ifi.ifi_metric;
+       ifm->ifm_data.ifi_baudrate = ifi.ifi_baudrate;
+       ifm->ifm_data.ifi_ipackets = ifi.ifi_ipackets;
+       ifm->ifm_data.ifi_ierrors = ifi.ifi_ierrors;
+       ifm->ifm_data.ifi_opackets = ifi.ifi_opackets;
+       ifm->ifm_data.ifi_oerrors = ifi.ifi_oerrors;
+       ifm->ifm_data.ifi_collisions = ifi.ifi_collisions;
+       ifm->ifm_data.ifi_ibytes = ifi.ifi_ibytes;
+       ifm->ifm_data.ifi_obytes = ifi.ifi_obytes;
+       ifm->ifm_data.ifi_imcasts = ifi.ifi_imcasts;
+       ifm->ifm_data.ifi_omcasts = ifi.ifi_omcasts;
+       ifm->ifm_data.ifi_iqdrops = ifi.ifi_iqdrops;
+       ifm->ifm_data.ifi_noproto = ifi.ifi_noproto;
        TIMESPEC_TO_TIMEVAL(&ifm->ifm_data.ifi_lastchange,
-           &ifp->if_data.ifi_lastchange);
+           &ifi.ifi_lastchange);
        ifm->ifm_addrs = info->rti_addrs;
        error = copyout(ifm, w->w_where, len);
        if (error)
diff -r cb239e76d0ea -r 8fb9306e7225 sys/compat/common/uipc_syscalls_50.c
--- a/sys/compat/common/uipc_syscalls_50.c      Wed Jan 29 05:41:48 2020 +0000
+++ b/sys/compat/common/uipc_syscalls_50.c      Wed Jan 29 05:47:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_syscalls_50.c,v 1.10 2019/12/15 16:48:26 tsutsui Exp $    */
+/*     $NetBSD: uipc_syscalls_50.c,v 1.11 2020/01/29 05:48:22 thorpej Exp $    */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,6 +58,7 @@
 static int
 compat_ifdatareq(struct lwp *l, u_long cmd, void *data)
 {
+       struct if_data ifi;
        struct oifdatareq *ifdr = data;
        struct ifnet *ifp;
        int error;
@@ -78,7 +79,8 @@
        /* Do work. */
        switch (cmd) {
        case OSIOCGIFDATA:
-               ifdatan2o(&ifdr->ifdr_data, &ifp->if_data);
+               if_export_if_data(ifp, &ifi, false);
+               ifdatan2o(&ifdr->ifdr_data, &ifi);
                return 0;
 
        case OSIOCZIFDATA:
@@ -90,13 +92,9 @@
                        if (error != 0)
                                return error;
                }
-               ifdatan2o(&ifdr->ifdr_data, &ifp->if_data);
-               /*
-                * Assumes that the volatile counters that can be
-                * zero'ed are at the end of if_data.
-                */
-               memset(&ifp->if_data.ifi_ipackets, 0, sizeof(ifp->if_data) -
-                   offsetof(struct if_data, ifi_ipackets));
+               if_export_if_data(ifp, &ifi, true);
+               ifdatan2o(&ifdr->ifdr_data, &ifi);
+               /* XXX if_lastchange? */
                return 0;
 
        default:



Home | Main Index | Thread Index | Old Index