1/* $FreeBSD: head/sys/netinet6/ip6_mroute.c 165118 2006-12-12 12:17:58Z bz $ */ |
2/* $KAME: ip6_mroute.c,v 1.58 2001/12/18 02:36:31 itojun Exp $ */ 3 4/*- 5 * Copyright (C) 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 710 unchanged lines hidden (view full) --- 720add_m6fc(mfccp) 721 struct mf6cctl *mfccp; 722{ 723 struct mf6c *rt; 724 u_long hash; 725 struct rtdetq *rte; 726 u_short nstl; 727 int s; |
728 char ip6bufo[INET6_ADDRSTRLEN], ip6bufg[INET6_ADDRSTRLEN]; |
729 730 MF6CFIND(mfccp->mf6cc_origin.sin6_addr, 731 mfccp->mf6cc_mcastgrp.sin6_addr, rt); 732 733 /* If an entry already exists, just update the fields */ 734 if (rt) { 735#ifdef MRT6DEBUG |
736 if (mrt6debug & DEBUG_MFC) { 737 log(LOG_DEBUG, 738 "add_m6fc no upcall h %d o %s g %s p %x\n", 739 ip6_sprintf(ip6bufo, &mfccp->mf6cc_origin.sin6_addr), 740 ip6_sprintf(ip6bufg, &mfccp->mf6cc_mcastgrp.sin6_addr), 741 mfccp->mf6cc_parent); 742 } |
743#endif 744 745 s = splnet(); 746 rt->mf6c_parent = mfccp->mf6cc_parent; 747 rt->mf6c_ifset = mfccp->mf6cc_ifset; 748 splx(s); 749 return (0); 750 } --- 10 unchanged lines hidden (view full) --- 761 IN6_ARE_ADDR_EQUAL(&rt->mf6c_mcastgrp.sin6_addr, 762 &mfccp->mf6cc_mcastgrp.sin6_addr) && 763 (rt->mf6c_stall != NULL)) { 764 765 if (nstl++) 766 log(LOG_ERR, 767 "add_m6fc: %s o %s g %s p %x dbx %p\n", 768 "multiple kernel entries", |
769 ip6_sprintf(ip6bufo, 770 &mfccp->mf6cc_origin.sin6_addr), 771 ip6_sprintf(ip6bufg, 772 &mfccp->mf6cc_mcastgrp.sin6_addr), |
773 mfccp->mf6cc_parent, rt->mf6c_stall); 774 775#ifdef MRT6DEBUG 776 if (mrt6debug & DEBUG_MFC) 777 log(LOG_DEBUG, 778 "add_m6fc o %s g %s p %x dbg %x\n", |
779 ip6_sprintf(ip6bufo, 780 &mfccp->mf6cc_origin.sin6_addr), 781 ip6_sprintf(ip6bufg, 782 &mfccp->mf6cc_mcastgrp.sin6_addr), |
783 mfccp->mf6cc_parent, rt->mf6c_stall); 784#endif 785 786 rt->mf6c_origin = mfccp->mf6cc_origin; 787 rt->mf6c_mcastgrp = mfccp->mf6cc_mcastgrp; 788 rt->mf6c_parent = mfccp->mf6cc_parent; 789 rt->mf6c_ifset = mfccp->mf6cc_ifset; 790 /* initialize pkt counters per src-grp */ --- 20 unchanged lines hidden (view full) --- 811 } 812 813 /* 814 * It is possible that an entry is being inserted without an upcall 815 */ 816 if (nstl == 0) { 817#ifdef MRT6DEBUG 818 if (mrt6debug & DEBUG_MFC) |
819 log(LOG_DEBUG, 820 "add_mfc no upcall h %d o %s g %s p %x\n", 821 hash, 822 ip6_sprintf(ip6bufo, &mfccp->mf6cc_origin.sin6_addr), 823 ip6_sprintf(ip6bufg, &mfccp->mf6cc_mcastgrp.sin6_addr), 824 mfccp->mf6cc_parent); |
825#endif 826 827 for (rt = mf6ctable[hash]; rt; rt = rt->mf6c_next) { 828 829 if (IN6_ARE_ADDR_EQUAL(&rt->mf6c_origin.sin6_addr, 830 &mfccp->mf6cc_origin.sin6_addr)&& 831 IN6_ARE_ADDR_EQUAL(&rt->mf6c_mcastgrp.sin6_addr, 832 &mfccp->mf6cc_mcastgrp.sin6_addr)) { --- 83 unchanged lines hidden (view full) --- 916 u_long hash; 917 int s; 918 919 origin = mfccp->mf6cc_origin; 920 mcastgrp = mfccp->mf6cc_mcastgrp; 921 hash = MF6CHASH(origin.sin6_addr, mcastgrp.sin6_addr); 922 923#ifdef MRT6DEBUG |
924 if (mrt6debug & DEBUG_MFC) { 925 char ip6bufo[INET6_ADDRSTRLEN], ip6bufg[INET6_ADDRSTRLEN]; |
926 log(LOG_DEBUG,"del_m6fc orig %s mcastgrp %s\n", |
927 ip6_sprintf(ip6bufo, &origin.sin6_addr), 928 ip6_sprintf(ip6bufg, &mcastgrp.sin6_addr)); 929 } |
930#endif 931 932 s = splnet(); 933 934 nptr = &mf6ctable[hash]; 935 while ((rt = *nptr) != NULL) { 936 if (IN6_ARE_ADDR_EQUAL(&origin.sin6_addr, 937 &rt->mf6c_origin.sin6_addr) && --- 60 unchanged lines hidden (view full) --- 998 struct ifnet *ifp; 999 struct mbuf *m; 1000{ 1001 struct mf6c *rt; 1002 struct mif6 *mifp; 1003 struct mbuf *mm; 1004 int s; 1005 mifi_t mifi; |
1006 char ip6bufs[INET6_ADDRSTRLEN], ip6bufd[INET6_ADDRSTRLEN]; |
1007 1008#ifdef MRT6DEBUG 1009 if (mrt6debug & DEBUG_FORWARD) 1010 log(LOG_DEBUG, "ip6_mforward: src %s, dst %s, ifindex %d\n", |
1011 ip6_sprintf(ip6bufs, &ip6->ip6_src), 1012 ip6_sprintf(ip6bufd, &ip6->ip6_dst), |
1013 ifp->if_index); 1014#endif 1015 1016 /* 1017 * Don't forward a packet with Hop limit of zero or one, 1018 * or a packet destined to a local-only group. 1019 */ 1020 if (ip6->ip6_hlim <= 1 || IN6_IS_ADDR_MC_INTFACELOCAL(&ip6->ip6_dst) || --- 10 unchanged lines hidden (view full) --- 1031 */ 1032 if (IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) { 1033 ip6stat.ip6s_cantforward++; 1034 if (ip6_log_time + ip6_log_interval < time_second) { 1035 ip6_log_time = time_second; 1036 log(LOG_DEBUG, 1037 "cannot forward " 1038 "from %s to %s nxt %d received on %s\n", |
1039 ip6_sprintf(ip6bufs, &ip6->ip6_src), 1040 ip6_sprintf(ip6bufd, &ip6->ip6_dst), |
1041 ip6->ip6_nxt, 1042 if_name(m->m_pkthdr.rcvif)); 1043 } 1044 return (0); 1045 } 1046 1047 /* 1048 * Determine forwarding mifs from the forwarding cache table --- 21 unchanged lines hidden (view full) --- 1070 1071 GET_TIME(tp); 1072#endif /* UPCALL_TIMING */ 1073 1074 mrt6stat.mrt6s_no_route++; 1075#ifdef MRT6DEBUG 1076 if (mrt6debug & (DEBUG_FORWARD | DEBUG_MFC)) 1077 log(LOG_DEBUG, "ip6_mforward: no rte s %s g %s\n", |
1078 ip6_sprintf(ip6bufs, &ip6->ip6_src), 1079 ip6_sprintf(ip6bufd, &ip6->ip6_dst)); |
1080#endif 1081 1082 /* 1083 * Allocate mbufs early so that we don't do extra work if we 1084 * are just going to fail anyway. 1085 */ 1086 rte = (struct rtdetq *)malloc(sizeof(*rte), M_MRTABLE6, 1087 M_NOWAIT); --- 192 unchanged lines hidden (view full) --- 1280 * Skip real cache entries 1281 * Make sure it wasn't marked to not expire (shouldn't happen) 1282 * If it expires now 1283 */ 1284 if (rte != NULL && 1285 mfc->mf6c_expire != 0 && 1286 --mfc->mf6c_expire == 0) { 1287#ifdef MRT6DEBUG |
1288 if (mrt6debug & DEBUG_EXPIRE) { 1289 char ip6bufo[INET6_ADDRSTRLEN]; 1290 char ip6bufg[INET6_ADDRSTRLEN]; |
1291 log(LOG_DEBUG, "expire_upcalls: expiring (%s %s)\n", |
1292 ip6_sprintf(ip6bufo, &mfc->mf6c_origin.sin6_addr), 1293 ip6_sprintf(ip6bufg, &mfc->mf6c_mcastgrp.sin6_addr)); 1294 } |
1295#endif 1296 /* 1297 * drop all the packets 1298 * free the mbuf with the pkt, if, timing info 1299 */ 1300 do { 1301 struct rtdetq *n = rte->next; 1302 m_freem(rte->m); --- 293 unchanged lines hidden (view full) --- 1596 * pMTU discovery is intentionally disabled by default, since 1597 * various router may notify pMTU in multicast, which can be 1598 * a DDoS to a router 1599 */ 1600 if (ip6_mcast_pmtu) 1601 icmp6_error(mb_copy, ICMP6_PACKET_TOO_BIG, 0, linkmtu); 1602 else { 1603#ifdef MRT6DEBUG |
1604 if (mrt6debug & DEBUG_XMIT) { 1605 char ip6bufs[INET6_ADDRSTRLEN]; 1606 char ip6bufd[INET6_ADDRSTRLEN]; |
1607 log(LOG_DEBUG, 1608 "phyint_send: packet too big on %s o %s " 1609 "g %s size %d(discarded)\n", 1610 if_name(ifp), |
1611 ip6_sprintf(ip6bufs, &ip6->ip6_src), 1612 ip6_sprintf(ip6bufd, &ip6->ip6_dst), |
1613 mb_copy->m_pkthdr.len); |
1614 } |
1615#endif /* MRT6DEBUG */ 1616 m_freem(mb_copy); /* simply discard the packet */ 1617 } 1618 } 1619 1620 splx(s); 1621} 1622 --- 4 unchanged lines hidden (view full) --- 1627 struct mbuf *m; 1628{ 1629 struct mbuf *mm; 1630 int i, len = m->m_pkthdr.len; 1631 static struct sockaddr_in6 sin6 = { sizeof(sin6), AF_INET6 }; 1632 struct mrt6msg *im6; 1633 1634#ifdef MRT6DEBUG |
1635 if (mrt6debug) { 1636 char ip6bufs[INET6_ADDRSTRLEN], ip6bufd[INET6_ADDRSTRLEN]; |
1637 log(LOG_DEBUG, "** IPv6 register_send **\n src %s dst %s\n", |
1638 ip6_sprintf(ip6bufs, &ip6->ip6_src), 1639 ip6_sprintf(ip6bufd, &ip6->ip6_dst)); 1640 } |
1641#endif 1642 ++pim6stat.pim6s_snd_registers; 1643 1644 /* Make a copy of the packet to send to the user level process */ 1645 MGETHDR(mm, M_DONTWAIT, MT_HEADER); 1646 if (mm == NULL) 1647 return (ENOBUFS); 1648 mm->m_pkthdr.rcvif = NULL; --- 151 unchanged lines hidden (view full) --- 1800 * routing daemon. 1801 */ 1802 static struct sockaddr_in6 dst = { sizeof(dst), AF_INET6 }; 1803 1804 struct mbuf *mcp; 1805 struct ip6_hdr *eip6; 1806 u_int32_t *reghdr; 1807 int rc; |
1808#ifdef MRT6DEBUG 1809 char ip6bufs[INET6_ADDRSTRLEN], ip6bufd[INET6_ADDRSTRLEN]; 1810#endif |
1811 1812 ++pim6stat.pim6s_rcv_registers; 1813 1814 if ((reg_mif_num >= nummifs) || (reg_mif_num == (mifi_t) -1)) { 1815#ifdef MRT6DEBUG 1816 if (mrt6debug & DEBUG_PIM) 1817 log(LOG_DEBUG, 1818 "pim6_input: register mif not set: %d\n", --- 13 unchanged lines hidden (view full) --- 1832 */ 1833 if (pimlen < PIM6_REG_MINLEN) { 1834 ++pim6stat.pim6s_rcv_tooshort; 1835 ++pim6stat.pim6s_rcv_badregisters; 1836#ifdef MRT6DEBUG 1837 log(LOG_ERR, 1838 "pim6_input: register packet size too " 1839 "small %d from %s\n", |
1840 pimlen, ip6_sprintf(ip6bufs, &ip6->ip6_src)); |
1841#endif 1842 m_freem(m); 1843 return (IPPROTO_DONE); 1844 } 1845 1846 eip6 = (struct ip6_hdr *) (reghdr + 1); 1847#ifdef MRT6DEBUG 1848 if (mrt6debug & DEBUG_PIM) 1849 log(LOG_DEBUG, 1850 "pim6_input[register], eip6: %s -> %s, " 1851 "eip6 plen %d\n", |
1852 ip6_sprintf(ip6bufs, &eip6->ip6_src), 1853 ip6_sprintf(ip6bufd, &eip6->ip6_dst), |
1854 ntohs(eip6->ip6_plen)); 1855#endif 1856 1857 /* verify the version number of the inner packet */ 1858 if ((eip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) { 1859 ++pim6stat.pim6s_rcv_badregisters; 1860#ifdef MRT6DEBUG 1861 log(LOG_DEBUG, "pim6_input: invalid IP version (%d) " --- 7 unchanged lines hidden (view full) --- 1869 /* verify the inner packet is destined to a mcast group */ 1870 if (!IN6_IS_ADDR_MULTICAST(&eip6->ip6_dst)) { 1871 ++pim6stat.pim6s_rcv_badregisters; 1872#ifdef MRT6DEBUG 1873 if (mrt6debug & DEBUG_PIM) 1874 log(LOG_DEBUG, 1875 "pim6_input: inner packet of register " 1876 "is not multicast %s\n", |
1877 ip6_sprintf(ip6bufd, &eip6->ip6_dst)); |
1878#endif 1879 m_freem(m); 1880 return (IPPROTO_DONE); 1881 } 1882 1883 /* 1884 * make a copy of the whole header to pass to the daemon later. 1885 */ --- 12 unchanged lines hidden (view full) --- 1898 * forward the inner ip6 packet; point m_data at the inner ip6. 1899 */ 1900 m_adj(m, off + PIM_MINLEN); 1901#ifdef MRT6DEBUG 1902 if (mrt6debug & DEBUG_PIM) { 1903 log(LOG_DEBUG, 1904 "pim6_input: forwarding decapsulated register: " 1905 "src %s, dst %s, mif %d\n", |
1906 ip6_sprintf(ip6bufs, &eip6->ip6_src), 1907 ip6_sprintf(ip6bufd, &eip6->ip6_dst), |
1908 reg_mif_num); 1909 } 1910#endif 1911 1912 rc = if_simloop(mif6table[reg_mif_num].m6_ifp, m, 1913 dst.sin6_family, 0); 1914 1915 /* prepare the register head to send to the mrouting daemon */ --- 13 unchanged lines hidden --- |