Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Jul 2005 12:22:06 +1200
From:      Matthew Luckie <mjl@luckie.org.nz>
To:        gnn@freebsd.org
Cc:        freebsd-net@freebsd.org
Subject:   Re: A bit of a route socket bug...
Message-ID:  <20050708002203.GB48639@lycra.luckie.org.nz>
In-Reply-To: <m2slysgfh3.wl%gnn@neville-neil.com>

next in thread | previous in thread | raw e-mail | index | archive | help
I'm not very familiar with the route code, but here is what i came up with.

[mjl@rayon mjl]$ sudo route change 10.3.2.1 127.0.0.1
route: writing to routing socket: No such process
change host 10.3.2.1: gateway 127.0.0.1: not in table

the code checks that if changing a host or network route, that the
route returned by a lookup matches this type.  for network routes, it
also ensures that the netmask matches.

--- rtsock.c.orig       Fri Jul  8 11:56:36 2005
+++ rtsock.c    Fri Jul  8 12:12:39 2005
@@ -489,6 +489,30 @@
 
                case RTM_CHANGE:
                        /*
+                        * Check that the route returned is exactly the one
+                        * that was looked up, so that some other route is not
+                        * changed in error.
+                        * Ensure the type of route (host/net) to be changed
+                        * matches, and ensure that the route matches if net
+                        * by checking that the netmask matches.
+                        */
+                       if (rt->rt_flags & RTF_HOST) {
+                               if((info.rti_flags & RTF_HOST) == 0) {
+                                       RT_UNLOCK(rt);
+                                       senderr(ESRCH);
+                               }
+                       } else {
+                               if((info.rti_flags & RTF_HOST) ||
+                                  info.rti_info[RTAX_NETMASK] == NULL ||
+                                  rt_mask(rt) == NULL ||
+                                  !sa_equal(info.rti_info[RTAX_NETMASK],
+                                            rt_mask(rt))) {
+                                       RT_UNLOCK(rt);
+                                       senderr(ESRCH);
+                               }
+                       }
+
+                       /*
                         * New gateway could require new ifaddr, ifp;
                         * flags may also be different; ifp may be specified
                         * by ll sockaddr when protocol address is ambiguous





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050708002203.GB48639>