in.c (260217) | in.c (260508) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (C) 2001 WIDE Project. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 17 unchanged lines hidden (view full) --- 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * @(#)in.c 8.4 (Berkeley) 1/9/95 31 */ 32 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1982, 1986, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (C) 2001 WIDE Project. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 17 unchanged lines hidden (view full) --- 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * @(#)in.c 8.4 (Berkeley) 1/9/95 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/netinet/in.c 260217 2014-01-03 02:32:05Z ae $"); | 34__FBSDID("$FreeBSD: head/sys/netinet/in.c 260508 2014-01-10 12:13:55Z melifaro $"); |
35 36#include "opt_mpath.h" 37 38#include <sys/param.h> 39#include <sys/eventhandler.h> 40#include <sys/systm.h> 41#include <sys/sockio.h> 42#include <sys/malloc.h> --- 562 unchanged lines hidden (view full) --- 605 return (0); 606} 607 608#define rtinitflags(x) \ 609 ((((x)->ia_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) != 0) \ 610 ? RTF_HOST : 0) 611 612/* | 35 36#include "opt_mpath.h" 37 38#include <sys/param.h> 39#include <sys/eventhandler.h> 40#include <sys/systm.h> 41#include <sys/sockio.h> 42#include <sys/malloc.h> --- 562 unchanged lines hidden (view full) --- 605 return (0); 606} 607 608#define rtinitflags(x) \ 609 ((((x)->ia_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) != 0) \ 610 ? RTF_HOST : 0) 611 612/* |
613 * Generate a routing message when inserting or deleting 614 * an interface address alias. 615 */ 616static void in_addralias_rtmsg(int cmd, struct in_addr *prefix, 617 struct in_ifaddr *target) 618{ 619 struct route pfx_ro; 620 struct sockaddr_in *pfx_addr; 621 struct rtentry msg_rt; 622 623 /* QL: XXX 624 * This is a bit questionable because there is no 625 * additional route entry added/deleted for an address 626 * alias. Therefore this route report is inaccurate. 627 */ 628 bzero(&pfx_ro, sizeof(pfx_ro)); 629 pfx_addr = (struct sockaddr_in *)(&pfx_ro.ro_dst); 630 pfx_addr->sin_len = sizeof(*pfx_addr); 631 pfx_addr->sin_family = AF_INET; 632 pfx_addr->sin_addr = *prefix; 633 rtalloc_ign_fib(&pfx_ro, 0, 0); 634 if (pfx_ro.ro_rt != NULL) { 635 msg_rt = *pfx_ro.ro_rt; 636 637 /* QL: XXX 638 * Point the gateway to the new interface 639 * address as if a new prefix route entry has 640 * been added through the new address alias. 641 * All other parts of the rtentry is accurate, 642 * e.g., rt_key, rt_mask, rt_ifp etc. 643 */ 644 msg_rt.rt_gateway = (struct sockaddr *)&target->ia_addr; 645 rt_newaddrmsg(cmd, (struct ifaddr *)target, 0, &msg_rt); 646 RTFREE(pfx_ro.ro_rt); 647 } 648 return; 649} 650 651/* | |
652 * Check if we have a route for the given prefix already or add one accordingly. 653 */ 654int 655in_addprefix(struct in_ifaddr *target, int flags) 656{ 657 struct in_ifaddr *ia; 658 struct in_addr prefix, mask, p, m; | 613 * Check if we have a route for the given prefix already or add one accordingly. 614 */ 615int 616in_addprefix(struct in_ifaddr *target, int flags) 617{ 618 struct in_ifaddr *ia; 619 struct in_addr prefix, mask, p, m; |
659 int error; | 620 int error, fibnum; |
660 661 if ((flags & RTF_HOST) != 0) { 662 prefix = target->ia_dstaddr.sin_addr; 663 mask.s_addr = 0; 664 } else { 665 prefix = target->ia_addr.sin_addr; 666 mask = target->ia_sockmask.sin_addr; 667 prefix.s_addr &= mask.s_addr; 668 } 669 | 621 622 if ((flags & RTF_HOST) != 0) { 623 prefix = target->ia_dstaddr.sin_addr; 624 mask.s_addr = 0; 625 } else { 626 prefix = target->ia_addr.sin_addr; 627 mask = target->ia_sockmask.sin_addr; 628 prefix.s_addr &= mask.s_addr; 629 } 630 |
631 fibnum = rt_add_addr_allfibs ? RT_ALL_FIBS : target->ia_ifp->if_fib; 632 |
|
670 IN_IFADDR_RLOCK(); 671 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { 672 if (rtinitflags(ia)) { 673 p = ia->ia_dstaddr.sin_addr; 674 675 if (prefix.s_addr != p.s_addr) 676 continue; 677 } else { --- 18 unchanged lines hidden (view full) --- 696 return (EEXIST); 697 } else 698 break; 699#endif 700 if (V_nosameprefix) { 701 IN_IFADDR_RUNLOCK(); 702 return (EEXIST); 703 } else { | 633 IN_IFADDR_RLOCK(); 634 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { 635 if (rtinitflags(ia)) { 636 p = ia->ia_dstaddr.sin_addr; 637 638 if (prefix.s_addr != p.s_addr) 639 continue; 640 } else { --- 18 unchanged lines hidden (view full) --- 659 return (EEXIST); 660 } else 661 break; 662#endif 663 if (V_nosameprefix) { 664 IN_IFADDR_RUNLOCK(); 665 return (EEXIST); 666 } else { |
704 in_addralias_rtmsg(RTM_ADD, &prefix, target); | 667 rt_addrmsg(RTM_ADD, &target->ia_ifa, fibnum); |
705 IN_IFADDR_RUNLOCK(); 706 return (0); 707 } 708 } 709 } 710 IN_IFADDR_RUNLOCK(); 711 712 /* --- 10 unchanged lines hidden (view full) --- 723 * same prefix, remove the route. Hand over the route to the new address 724 * otherwise. 725 */ 726int 727in_scrubprefix(struct in_ifaddr *target, u_int flags) 728{ 729 struct in_ifaddr *ia; 730 struct in_addr prefix, mask, p, m; | 668 IN_IFADDR_RUNLOCK(); 669 return (0); 670 } 671 } 672 } 673 IN_IFADDR_RUNLOCK(); 674 675 /* --- 10 unchanged lines hidden (view full) --- 686 * same prefix, remove the route. Hand over the route to the new address 687 * otherwise. 688 */ 689int 690in_scrubprefix(struct in_ifaddr *target, u_int flags) 691{ 692 struct in_ifaddr *ia; 693 struct in_addr prefix, mask, p, m; |
731 int error = 0; | 694 int error = 0, fibnum; |
732 struct sockaddr_in prefix0, mask0; 733 | 695 struct sockaddr_in prefix0, mask0; 696 |
697 fibnum = rt_add_addr_allfibs ? RT_ALL_FIBS : target->ia_ifp->if_fib; 698 |
|
734 /* 735 * Remove the loopback route to the interface address. 736 */ 737 if ((target->ia_addr.sin_addr.s_addr != INADDR_ANY) && 738 !(target->ia_ifp->if_flags & IFF_LOOPBACK) && 739 (flags & LLE_STATIC)) { 740 struct in_ifaddr *eia; 741 --- 19 unchanged lines hidden (view full) --- 761 mask.s_addr = 0; 762 } else { 763 prefix = target->ia_addr.sin_addr; 764 mask = target->ia_sockmask.sin_addr; 765 prefix.s_addr &= mask.s_addr; 766 } 767 768 if ((target->ia_flags & IFA_ROUTE) == 0) { | 699 /* 700 * Remove the loopback route to the interface address. 701 */ 702 if ((target->ia_addr.sin_addr.s_addr != INADDR_ANY) && 703 !(target->ia_ifp->if_flags & IFF_LOOPBACK) && 704 (flags & LLE_STATIC)) { 705 struct in_ifaddr *eia; 706 --- 19 unchanged lines hidden (view full) --- 726 mask.s_addr = 0; 727 } else { 728 prefix = target->ia_addr.sin_addr; 729 mask = target->ia_sockmask.sin_addr; 730 prefix.s_addr &= mask.s_addr; 731 } 732 733 if ((target->ia_flags & IFA_ROUTE) == 0) { |
769 in_addralias_rtmsg(RTM_DELETE, &prefix, target); | 734 rt_addrmsg(RTM_DELETE, &target->ia_ifa, fibnum); |
770 return (0); 771 } 772 773 IN_IFADDR_RLOCK(); 774 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { 775 if (rtinitflags(ia)) { 776 p = ia->ia_dstaddr.sin_addr; 777 --- 509 unchanged lines hidden --- | 735 return (0); 736 } 737 738 IN_IFADDR_RLOCK(); 739 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { 740 if (rtinitflags(ia)) { 741 p = ia->ia_dstaddr.sin_addr; 742 --- 509 unchanged lines hidden --- |