Deleted Added
full compact
route.c (287476) route.c (287798)
1/*-
2 * Copyright (c) 1980, 1986, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)route.c 8.3.1.1 (Berkeley) 2/23/95
1/*-
2 * Copyright (c) 1980, 1986, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)route.c 8.3.1.1 (Berkeley) 2/23/95
30 * $FreeBSD: head/sys/net/route.c 287476 2015-09-05 05:33:20Z melifaro $
30 * $FreeBSD: head/sys/net/route.c 287798 2015-09-14 19:17:25Z vangyzen $
31 */
32/************************************************************************
33 * Note: In this file a 'fib' is a "forwarding information base" *
34 * Which is the new name for an in kernel routing (next hop) table. *
35 ***********************************************************************/
36
37#include "opt_inet.h"
38#include "opt_inet6.h"

--- 540 unchanged lines hidden (view full) ---

579 }
580 rt = rtalloc1_fib(dst, 0, 0UL, fibnum); /* NB: rt is locked */
581 /*
582 * If the redirect isn't from our current router for this dst,
583 * it's either old or wrong. If it redirects us to ourselves,
584 * we have a routing loop, perhaps as a result of an interface
585 * going down recently.
586 */
31 */
32/************************************************************************
33 * Note: In this file a 'fib' is a "forwarding information base" *
34 * Which is the new name for an in kernel routing (next hop) table. *
35 ***********************************************************************/
36
37#include "opt_inet.h"
38#include "opt_inet6.h"

--- 540 unchanged lines hidden (view full) ---

579 }
580 rt = rtalloc1_fib(dst, 0, 0UL, fibnum); /* NB: rt is locked */
581 /*
582 * If the redirect isn't from our current router for this dst,
583 * it's either old or wrong. If it redirects us to ourselves,
584 * we have a routing loop, perhaps as a result of an interface
585 * going down recently.
586 */
587 if (!(flags & RTF_DONE) && rt &&
588 (!sa_equal(src, rt->rt_gateway) || rt->rt_ifa != ifa))
589 error = EINVAL;
590 else if (ifa_ifwithaddr_check(gateway))
587 if (!(flags & RTF_DONE) && rt) {
588 if (!sa_equal(src, rt->rt_gateway)) {
589 error = EINVAL;
590 goto done;
591 }
592 if (rt->rt_ifa != ifa && ifa->ifa_addr->sa_family != AF_LINK) {
593 error = EINVAL;
594 goto done;
595 }
596 }
597 if ((flags & RTF_GATEWAY) && ifa_ifwithaddr_check(gateway)) {
591 error = EHOSTUNREACH;
598 error = EHOSTUNREACH;
592 if (error)
593 goto done;
599 goto done;
600 }
594 /*
595 * Create a new entry if we just got back a wildcard entry
596 * or the lookup failed. This is necessary for hosts
597 * which use routing redirects generated by smart gateways
598 * to dynamically build the routing tables.
599 */
600 if (rt == NULL || (rt_mask(rt) && rt_mask(rt)->sa_len < 2))
601 goto create;

--- 6 unchanged lines hidden (view full) ---

608 /*
609 * Changing from route to net => route to host.
610 * Create new route, rather than smashing route to net.
611 */
612 create:
613 rt0 = rt;
614 rt = NULL;
615
601 /*
602 * Create a new entry if we just got back a wildcard entry
603 * or the lookup failed. This is necessary for hosts
604 * which use routing redirects generated by smart gateways
605 * to dynamically build the routing tables.
606 */
607 if (rt == NULL || (rt_mask(rt) && rt_mask(rt)->sa_len < 2))
608 goto create;

--- 6 unchanged lines hidden (view full) ---

615 /*
616 * Changing from route to net => route to host.
617 * Create new route, rather than smashing route to net.
618 */
619 create:
620 rt0 = rt;
621 rt = NULL;
622
616 flags |= RTF_GATEWAY | RTF_DYNAMIC;
623 flags |= RTF_DYNAMIC;
617 bzero((caddr_t)&info, sizeof(info));
618 info.rti_info[RTAX_DST] = dst;
619 info.rti_info[RTAX_GATEWAY] = gateway;
620 info.rti_info[RTAX_NETMASK] = netmask;
621 info.rti_ifa = ifa;
622 info.rti_flags = flags;
623 if (rt0 != NULL)
624 RT_UNLOCK(rt0); /* drop lock to avoid LOR with RNH */

--- 10 unchanged lines hidden (view full) ---

635 stat = &V_rtstat.rts_dynamic;
636 } else {
637 struct rtentry *gwrt;
638
639 /*
640 * Smash the current notion of the gateway to
641 * this destination. Should check about netmask!!!
642 */
624 bzero((caddr_t)&info, sizeof(info));
625 info.rti_info[RTAX_DST] = dst;
626 info.rti_info[RTAX_GATEWAY] = gateway;
627 info.rti_info[RTAX_NETMASK] = netmask;
628 info.rti_ifa = ifa;
629 info.rti_flags = flags;
630 if (rt0 != NULL)
631 RT_UNLOCK(rt0); /* drop lock to avoid LOR with RNH */

--- 10 unchanged lines hidden (view full) ---

642 stat = &V_rtstat.rts_dynamic;
643 } else {
644 struct rtentry *gwrt;
645
646 /*
647 * Smash the current notion of the gateway to
648 * this destination. Should check about netmask!!!
649 */
650 if ((flags & RTF_GATEWAY) == 0)
651 rt->rt_flags &= ~RTF_GATEWAY;
643 rt->rt_flags |= RTF_MODIFIED;
644 flags |= RTF_MODIFIED;
645 stat = &V_rtstat.rts_newgateway;
646 /*
647 * add the key and gateway (in one malloc'd chunk).
648 */
649 RT_UNLOCK(rt);
650 RADIX_NODE_HEAD_LOCK(rnh);
651 RT_LOCK(rt);
652 rt_setgate(rt, rt_key(rt), gateway);
653 gwrt = rtalloc1(gateway, 1, RTF_RNH_LOCKED);
654 RADIX_NODE_HEAD_UNLOCK(rnh);
655 EVENTHANDLER_INVOKE(route_redirect_event, rt, gwrt, dst);
652 rt->rt_flags |= RTF_MODIFIED;
653 flags |= RTF_MODIFIED;
654 stat = &V_rtstat.rts_newgateway;
655 /*
656 * add the key and gateway (in one malloc'd chunk).
657 */
658 RT_UNLOCK(rt);
659 RADIX_NODE_HEAD_LOCK(rnh);
660 RT_LOCK(rt);
661 rt_setgate(rt, rt_key(rt), gateway);
662 gwrt = rtalloc1(gateway, 1, RTF_RNH_LOCKED);
663 RADIX_NODE_HEAD_UNLOCK(rnh);
664 EVENTHANDLER_INVOKE(route_redirect_event, rt, gwrt, dst);
656 RTFREE_LOCKED(gwrt);
665 if (gwrt)
666 RTFREE_LOCKED(gwrt);
657 }
658 } else
659 error = EHOSTUNREACH;
660done:
661 if (rt)
662 RTFREE_LOCKED(rt);
663out:
664 if (error)

--- 1458 unchanged lines hidden ---
667 }
668 } else
669 error = EHOSTUNREACH;
670done:
671 if (rt)
672 RTFREE_LOCKED(rt);
673out:
674 if (error)

--- 1458 unchanged lines hidden ---