On Tue, Dec 01, 2015 at 05:53:47PM +0100, Martin Pieuchot wrote:
> The netmask argument is always NULL and the flags are always the same.
> RTF_GATEWAY|RTF_HOST routes *are* routes created by redirect.   
> 
> I need this simplification to move forward with my rt_mask() cleanup.
> 
> ok?

OK bluhm@

> 
> Index: net/route.c
> ===================================================================
> RCS file: /cvs/src/sys/net/route.c,v
> retrieving revision 1.277
> diff -u -p -r1.277 route.c
> --- net/route.c       27 Nov 2015 11:52:44 -0000      1.277
> +++ net/route.c       1 Dec 2015 16:52:10 -0000
> @@ -529,8 +529,7 @@ ifafree(struct ifaddr *ifa)
>   */
>  void
>  rtredirect(struct sockaddr *dst, struct sockaddr *gateway,
> -    struct sockaddr *netmask, int flags, struct sockaddr *src,
> -    struct rtentry **rtp, u_int rdomain)
> +    struct sockaddr *src, struct rtentry **rtp, unsigned int rdomain)
>  {
>       struct rtentry          *rt;
>       int                      error = 0;
> @@ -538,6 +537,7 @@ rtredirect(struct sockaddr *dst, struct 
>       struct rt_addrinfo       info;
>       struct ifaddr           *ifa;
>       unsigned int             ifidx = 0;
> +     int                      flags = RTF_GATEWAY|RTF_HOST;
>  
>       splsoftassert(IPL_SOFTNET);
>  
> @@ -557,8 +557,7 @@ rtredirect(struct sockaddr *dst, struct 
>  #define      equal(a1, a2) \
>       ((a1)->sa_len == (a2)->sa_len && \
>        bcmp((caddr_t)(a1), (caddr_t)(a2), (a1)->sa_len) == 0)
> -     if (!(flags & RTF_DONE) && rt &&
> -          (!equal(src, rt->rt_gateway) || rt->rt_ifa != ifa))
> +     if (rt != NULL && (!equal(src, rt->rt_gateway) || rt->rt_ifa != ifa))
>               error = EINVAL;
>       else if (ifa_ifwithaddr(gateway, rdomain) != NULL)
>               error = EHOSTUNREACH;
> @@ -574,21 +573,20 @@ rtredirect(struct sockaddr *dst, struct 
>               goto create;
>       /*
>        * Don't listen to the redirect if it's
> -      * for a route to an interface. 
> +      * for a route to an interface.
>        */
> -     if (rt->rt_flags & RTF_GATEWAY) {
> -             if (((rt->rt_flags & RTF_HOST) == 0) && (flags & RTF_HOST)) {
> +     if (ISSET(rt->rt_flags, RTF_GATEWAY)) {
> +             if (!ISSET(rt->rt_flags, RTF_HOST)) {
>                       /*
>                        * Changing from route to net => route to host.
>                        * Create new route, rather than smashing route to net.
>                        */
>  create:
>                       rtfree(rt);
> -                     flags |= RTF_GATEWAY | RTF_DYNAMIC;
> +                     flags |= RTF_DYNAMIC;
>                       bzero(&info, sizeof(info));
>                       info.rti_info[RTAX_DST] = dst;
>                       info.rti_info[RTAX_GATEWAY] = gateway;
> -                     info.rti_info[RTAX_NETMASK] = netmask;
>                       info.rti_ifa = ifa;
>                       info.rti_flags = flags;
>                       rt = NULL;
> @@ -624,7 +622,6 @@ out:
>       bzero((caddr_t)&info, sizeof(info));
>       info.rti_info[RTAX_DST] = dst;
>       info.rti_info[RTAX_GATEWAY] = gateway;
> -     info.rti_info[RTAX_NETMASK] = netmask;
>       info.rti_info[RTAX_AUTHOR] = src;
>       rt_missmsg(RTM_REDIRECT, &info, flags, ifidx, error, rdomain);
>  }
> Index: net/route.h
> ===================================================================
> RCS file: /cvs/src/sys/net/route.h,v
> retrieving revision 1.122
> diff -u -p -r1.122 route.h
> --- net/route.h       29 Nov 2015 16:02:18 -0000      1.122
> +++ net/route.h       1 Dec 2015 16:49:26 -0000
> @@ -392,9 +392,7 @@ int        rt_ifa_del(struct ifaddr *, int, st
>  int   rt_ifa_addlocal(struct ifaddr *);
>  int   rt_ifa_dellocal(struct ifaddr *);
>  int   rtioctl(u_long, caddr_t, struct proc *);
> -void  rtredirect(struct sockaddr *, struct sockaddr *,
> -                      struct sockaddr *, int, struct sockaddr *,
> -                      struct rtentry **, u_int);
> +void  rtredirect(struct sockaddr *, struct sockaddr *, struct sockaddr *, 
> struct rtentry **, unsigned int);
>  int   rtrequest(int, struct rt_addrinfo *, u_int8_t, struct rtentry **,
>            u_int);
>  void  rt_if_remove(struct ifnet *);
> Index: netinet/ip_icmp.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_icmp.c,v
> retrieving revision 1.146
> diff -u -p -r1.146 ip_icmp.c
> --- netinet/ip_icmp.c 21 Nov 2015 11:26:59 -0000      1.146
> +++ netinet/ip_icmp.c 1 Dec 2015 16:36:52 -0000
> @@ -652,9 +652,8 @@ reflect:
>                   &ip->ip_dst.s_addr))
>                       goto freeit;
>  #endif
> -             rtredirect(sintosa(&sdst), sintosa(&sgw), NULL,
> -                 RTF_GATEWAY | RTF_HOST, sintosa(&ssrc),
> -                 &newrt, m->m_pkthdr.ph_rtableid);
> +             rtredirect(sintosa(&sdst), sintosa(&sgw),
> +                 sintosa(&ssrc), &newrt, m->m_pkthdr.ph_rtableid);
>               if (newrt != NULL && icmp_redirtimeout != 0) {
>                       (void)rt_timer_add(newrt, icmp_redirect_timeout,
>                           icmp_redirect_timeout_q, m->m_pkthdr.ph_rtableid);
> Index: netinet6/icmp6.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/icmp6.c,v
> retrieving revision 1.178
> diff -u -p -r1.178 icmp6.c
> --- netinet6/icmp6.c  21 Nov 2015 11:23:07 -0000      1.178
> +++ netinet6/icmp6.c  1 Dec 2015 16:37:04 -0000
> @@ -1517,8 +1517,7 @@ icmp6_redirect_input(struct mbuf *m, int
>               bcopy(&redtgt6, &sgw.sin6_addr, sizeof(struct in6_addr));
>               bcopy(&reddst6, &sdst.sin6_addr, sizeof(struct in6_addr));
>               bcopy(&src6, &ssrc.sin6_addr, sizeof(struct in6_addr));
> -             rtredirect(sin6tosa(&sdst), sin6tosa(&sgw), NULL,
> -                 RTF_GATEWAY | RTF_HOST, sin6tosa(&ssrc),
> +             rtredirect(sin6tosa(&sdst), sin6tosa(&sgw), sin6tosa(&ssrc),
>                   &newrt, m->m_pkthdr.ph_rtableid);
>  
>               if (newrt) {

Reply via email to