On Fri, May 12, 2023 at 11:43:42AM +0000, Klemens Nanni wrote:
> > Access rt_llinfo and check for NULL without checking RTF_LLINFO
> > flag before.  They are changed togehter with the arp or nd6 mutex.
> 
> It is the same change, but I'd commit ARP separately (you don't change
> any locking semantics there).

I had prepared a smaller diff already.  Here is the part that does
not touch the locking.  Just some cleanup to get ARP and ND6 in
sync.

Let's start with that and discuss locking separately.

ok?

bluhm

Index: netinet/if_ether.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/if_ether.c,v
retrieving revision 1.264
diff -u -p -r1.264 if_ether.c
--- netinet/if_ether.c  7 May 2023 16:23:23 -0000       1.264
+++ netinet/if_ether.c  12 May 2023 11:15:07 -0000
@@ -388,10 +388,8 @@ arpresolve(struct ifnet *ifp, struct rte
                    rt->rt_expire - arpt_keep / 8 < uptime) {
 
                        mtx_enter(&arp_mtx);
-                       if (ISSET(rt->rt_flags, RTF_LLINFO)) {
-                               la = (struct llinfo_arp *)rt->rt_llinfo;
-                               KASSERT(la != NULL);
-
+                       la = (struct llinfo_arp *)rt->rt_llinfo;
+                       if (la != NULL) {
                                if (la->la_refreshed + 30 < uptime) {
                                        la->la_refreshed = uptime;
                                        refresh = 1;
@@ -412,12 +410,11 @@ arpresolve(struct ifnet *ifp, struct rte
                goto bad;
 
        mtx_enter(&arp_mtx);
-       if (!ISSET(rt->rt_flags, RTF_LLINFO)) {
+       la = (struct llinfo_arp *)rt->rt_llinfo;
+       if (la == NULL) {
                mtx_leave(&arp_mtx);
                goto bad;
        }
-       la = (struct llinfo_arp *)rt->rt_llinfo;
-       KASSERT(la != NULL);
 
        /*
         * There is an arptab entry, but no ethernet address
Index: netinet6/nd6.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet6/nd6.c,v
retrieving revision 1.278
diff -u -p -r1.278 nd6.c
--- netinet6/nd6.c      8 May 2023 13:14:21 -0000       1.278
+++ netinet6/nd6.c      12 May 2023 11:58:54 -0000
@@ -527,6 +527,7 @@ nd6_lookup(const struct in6_addr *addr6,
        if (rt == NULL) {
                if (create && ifp) {
                        struct rt_addrinfo info;
+                       struct llinfo_nd6 *ln;
                        struct ifaddr *ifa;
                        int error;
 
@@ -556,11 +557,9 @@ nd6_lookup(const struct in6_addr *addr6,
                            rtableid);
                        if (error)
                                return (NULL);
-                       if (rt->rt_llinfo != NULL) {
-                               struct llinfo_nd6 *ln =
-                                   (struct llinfo_nd6 *)rt->rt_llinfo;
+                       ln = (struct llinfo_nd6 *)rt->rt_llinfo;
+                       if (ln != NULL)
                                ln->ln_state = ND6_LLINFO_NOSTATE;
-                       }
                } else
                        return (NULL);
        }
@@ -741,7 +740,7 @@ void
 nd6_rtrequest(struct ifnet *ifp, int req, struct rtentry *rt)
 {
        struct sockaddr *gate = rt->rt_gateway;
-       struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo;
+       struct llinfo_nd6 *ln;
        struct ifaddr *ifa;
        struct in6_ifaddr *ifa6;
 
@@ -1027,10 +1026,10 @@ void
 nd6_cache_lladdr(struct ifnet *ifp, const struct in6_addr *from, char *lladdr,
     int lladdrlen, int type, int code)
 {
-       struct rtentry *rt = NULL;
-       struct llinfo_nd6 *ln = NULL;
+       struct rtentry *rt;
+       struct llinfo_nd6 *ln;
        int is_newentry;
-       struct sockaddr_dl *sdl = NULL;
+       struct sockaddr_dl *sdl;
        int do_update;
        int olladdr;
        int llchange;
@@ -1257,7 +1256,7 @@ nd6_resolve(struct ifnet *ifp, struct rt
 {
        struct sockaddr_dl *sdl;
        struct rtentry *rt;
-       struct llinfo_nd6 *ln = NULL;
+       struct llinfo_nd6 *ln;
        struct in6_addr saddr6;
        time_t uptime;
        int solicit = 0;

Reply via email to