ip_input.c (7090) | ip_input.c (7091) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1988, 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 --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 | 1/* 2 * Copyright (c) 1982, 1986, 1988, 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 --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 |
34 * $Id: ip_input.c,v 1.17 1995/02/14 23:04:52 wollman Exp $ | 34 * $Id: ip_input.c,v 1.18 1995/03/16 18:14:55 bde Exp $ |
35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/malloc.h> 40#include <sys/mbuf.h> 41#include <sys/domain.h> 42#include <sys/protosw.h> 43#include <sys/socket.h> 44#include <sys/errno.h> 45#include <sys/time.h> 46#include <sys/kernel.h> | 35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/malloc.h> 40#include <sys/mbuf.h> 41#include <sys/domain.h> 42#include <sys/protosw.h> 43#include <sys/socket.h> 44#include <sys/errno.h> 45#include <sys/time.h> 46#include <sys/kernel.h> |
47#include <sys/syslog.h> 48 |
|
47#include <vm/vm.h> 48#include <sys/sysctl.h> 49 50#include <net/if.h> 51#include <net/route.h> 52 53#include <netinet/in.h> 54#include <netinet/in_systm.h> --- 17 unchanged lines hidden (view full) --- 72#endif /* GATEWAY */ 73#endif /* IPFORWARDING */ 74#ifndef IPSENDREDIRECTS 75#define IPSENDREDIRECTS 1 76#endif 77int ipforwarding = IPFORWARDING; 78int ipsendredirects = IPSENDREDIRECTS; 79int ip_defttl = IPDEFTTL; | 49#include <vm/vm.h> 50#include <sys/sysctl.h> 51 52#include <net/if.h> 53#include <net/route.h> 54 55#include <netinet/in.h> 56#include <netinet/in_systm.h> --- 17 unchanged lines hidden (view full) --- 74#endif /* GATEWAY */ 75#endif /* IPFORWARDING */ 76#ifndef IPSENDREDIRECTS 77#define IPSENDREDIRECTS 1 78#endif 79int ipforwarding = IPFORWARDING; 80int ipsendredirects = IPSENDREDIRECTS; 81int ip_defttl = IPDEFTTL; |
82int ip_dosourceroute = 0; |
|
80#ifdef DIAGNOSTIC 81int ipprintfs = 0; 82#endif 83 84extern struct domain inetdomain; 85extern struct protosw inetsw[]; 86u_char ip_protox[IPPROTO_MAX]; 87int ipqmaxlen = IFQ_MAXLEN; --- 13 unchanged lines hidden (view full) --- 101int ip_nhops = 0; 102static struct ip_srcrt { 103 struct in_addr dst; /* final destination */ 104 char nop; /* one NOP to align */ 105 char srcopt[IPOPT_OFFSET + 1]; /* OPTVAL, OLEN and OFFSET */ 106 struct in_addr route[MAX_IPOPTLEN/sizeof(struct in_addr)]; 107} ip_srcrt; 108 | 83#ifdef DIAGNOSTIC 84int ipprintfs = 0; 85#endif 86 87extern struct domain inetdomain; 88extern struct protosw inetsw[]; 89u_char ip_protox[IPPROTO_MAX]; 90int ipqmaxlen = IFQ_MAXLEN; --- 13 unchanged lines hidden (view full) --- 104int ip_nhops = 0; 105static struct ip_srcrt { 106 struct in_addr dst; /* final destination */ 107 char nop; /* one NOP to align */ 108 char srcopt[IPOPT_OFFSET + 1]; /* OPTVAL, OLEN and OFFSET */ 109 struct in_addr route[MAX_IPOPTLEN/sizeof(struct in_addr)]; 110} ip_srcrt; 111 |
109#ifdef GATEWAY 110extern int if_index; 111u_long *ip_ifmatrix; 112#endif 113 | |
114static void save_rte __P((u_char *, struct in_addr)); 115/* 116 * IP initialization: fill in IP protocol switch table. 117 * All protocols not implemented in kernel go to raw IP protocol handler. 118 */ 119void 120ip_init() 121{ --- 8 unchanged lines hidden (view full) --- 130 for (pr = inetdomain.dom_protosw; 131 pr < inetdomain.dom_protoswNPROTOSW; pr++) 132 if (pr->pr_domain->dom_family == PF_INET && 133 pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) 134 ip_protox[pr->pr_protocol] = pr - inetsw; 135 ipq.next = ipq.prev = &ipq; 136 ip_id = time.tv_sec & 0xffff; 137 ipintrq.ifq_maxlen = ipqmaxlen; | 112static void save_rte __P((u_char *, struct in_addr)); 113/* 114 * IP initialization: fill in IP protocol switch table. 115 * All protocols not implemented in kernel go to raw IP protocol handler. 116 */ 117void 118ip_init() 119{ --- 8 unchanged lines hidden (view full) --- 128 for (pr = inetdomain.dom_protosw; 129 pr < inetdomain.dom_protoswNPROTOSW; pr++) 130 if (pr->pr_domain->dom_family == PF_INET && 131 pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) 132 ip_protox[pr->pr_protocol] = pr - inetsw; 133 ipq.next = ipq.prev = &ipq; 134 ip_id = time.tv_sec & 0xffff; 135 ipintrq.ifq_maxlen = ipqmaxlen; |
138#ifdef GATEWAY 139 i = (if_index + 1) * (if_index + 1) * sizeof (u_long); 140 ip_ifmatrix = (u_long *) malloc(i, M_RTABLE, M_WAITOK); 141 bzero((char *)ip_ifmatrix, i); 142#endif | |
143} 144 145struct sockaddr_in ipaddr = { sizeof(ipaddr), AF_INET }; 146struct route ipforward_rt; 147 148/* 149 * Ip input routine. Checksum and byte swap header. If fragmented 150 * try to reassemble. Process options. Pass to next level. --- 590 unchanged lines hidden (view full) --- 741 off--; /* 0 origin */ 742 if (off > optlen - sizeof(struct in_addr)) { 743 /* 744 * End of source route. Should be for us. 745 */ 746 save_rte(cp, ip->ip_src); 747 break; 748 } | 136} 137 138struct sockaddr_in ipaddr = { sizeof(ipaddr), AF_INET }; 139struct route ipforward_rt; 140 141/* 142 * Ip input routine. Checksum and byte swap header. If fragmented 143 * try to reassemble. Process options. Pass to next level. --- 590 unchanged lines hidden (view full) --- 734 off--; /* 0 origin */ 735 if (off > optlen - sizeof(struct in_addr)) { 736 /* 737 * End of source route. Should be for us. 738 */ 739 save_rte(cp, ip->ip_src); 740 break; 741 } |
742 743 if (!ip_dosourceroute) { 744 char buf[4*sizeof "123"]; 745 strcpy(buf, inet_ntoa(ip->ip_dst)); 746 747 log(LOG_WARNING, 748 "attempted source route from %s to %s\n", 749 inet_ntoa(ip->ip_src), buf); 750 type = ICMP_UNREACH; 751 code = ICMP_UNREACH_SRCFAIL; 752 goto bad; 753 } 754 |
|
749 /* 750 * locate outgoing interface 751 */ 752 bcopy((caddr_t)(cp + off), (caddr_t)&ipaddr.sin_addr, 753 sizeof(ipaddr.sin_addr)); | 755 /* 756 * locate outgoing interface 757 */ 758 bcopy((caddr_t)(cp + off), (caddr_t)&ipaddr.sin_addr, 759 sizeof(ipaddr.sin_addr)); |
760 |
|
754 if (opt == IPOPT_SSRR) { 755#define INA struct in_ifaddr * 756#define SA struct sockaddr * 757 if ((ia = (INA)ifa_ifwithdstaddr((SA)&ipaddr)) == 0) 758 ia = (INA)ifa_ifwithnet((SA)&ipaddr); 759 } else 760 ia = ip_rtaddr(ipaddr.sin_addr); 761 if (ia == 0) { --- 324 unchanged lines hidden (view full) --- 1086 } 1087 1088 /* 1089 * Save at most 64 bytes of the packet in case 1090 * we need to generate an ICMP message to the src. 1091 */ 1092 mcopy = m_copy(m, 0, imin((int)ip->ip_len, 64)); 1093 | 761 if (opt == IPOPT_SSRR) { 762#define INA struct in_ifaddr * 763#define SA struct sockaddr * 764 if ((ia = (INA)ifa_ifwithdstaddr((SA)&ipaddr)) == 0) 765 ia = (INA)ifa_ifwithnet((SA)&ipaddr); 766 } else 767 ia = ip_rtaddr(ipaddr.sin_addr); 768 if (ia == 0) { --- 324 unchanged lines hidden (view full) --- 1093 } 1094 1095 /* 1096 * Save at most 64 bytes of the packet in case 1097 * we need to generate an ICMP message to the src. 1098 */ 1099 mcopy = m_copy(m, 0, imin((int)ip->ip_len, 64)); 1100 |
1094#ifdef bogus 1095#ifdef GATEWAY 1096 ip_ifmatrix[rt->rt_ifp->if_index + 1097 if_index * m->m_pkthdr.rcvif->if_index]++; 1098#endif 1099#endif | |
1100 /* 1101 * If forwarding packet using same interface that it came in on, 1102 * perhaps should send a redirect to sender to shortcut a hop. 1103 * Only send redirect if source is sending directly to us, 1104 * and if packet was not source routed (or has any options). 1105 * Also, don't send redirect if forwarding using a default route 1106 * or a route modified by a redirect. 1107 */ --- 89 unchanged lines hidden (view full) --- 1197 switch (name[0]) { 1198 case IPCTL_FORWARDING: 1199 return (sysctl_int(oldp, oldlenp, newp, newlen, &ipforwarding)); 1200 case IPCTL_SENDREDIRECTS: 1201 return (sysctl_int(oldp, oldlenp, newp, newlen, 1202 &ipsendredirects)); 1203 case IPCTL_DEFTTL: 1204 return (sysctl_int(oldp, oldlenp, newp, newlen, &ip_defttl)); | 1101 /* 1102 * If forwarding packet using same interface that it came in on, 1103 * perhaps should send a redirect to sender to shortcut a hop. 1104 * Only send redirect if source is sending directly to us, 1105 * and if packet was not source routed (or has any options). 1106 * Also, don't send redirect if forwarding using a default route 1107 * or a route modified by a redirect. 1108 */ --- 89 unchanged lines hidden (view full) --- 1198 switch (name[0]) { 1199 case IPCTL_FORWARDING: 1200 return (sysctl_int(oldp, oldlenp, newp, newlen, &ipforwarding)); 1201 case IPCTL_SENDREDIRECTS: 1202 return (sysctl_int(oldp, oldlenp, newp, newlen, 1203 &ipsendredirects)); 1204 case IPCTL_DEFTTL: 1205 return (sysctl_int(oldp, oldlenp, newp, newlen, &ip_defttl)); |
1206 case IPCTL_SOURCEROUTE: 1207 return (sysctl_int(oldp, oldlenp, newp, newlen, 1208 &ip_dosourceroute)); |
|
1205#ifdef notyet 1206 case IPCTL_DEFMTU: 1207 return (sysctl_int(oldp, oldlenp, newp, newlen, &ip_mtu)); 1208#endif 1209 case IPCTL_RTEXPIRE: 1210 return (sysctl_int(oldp, oldlenp, newp, newlen, 1211 &rtq_reallyold)); 1212 case IPCTL_RTMINEXPIRE: --- 32 unchanged lines hidden --- | 1209#ifdef notyet 1210 case IPCTL_DEFMTU: 1211 return (sysctl_int(oldp, oldlenp, newp, newlen, &ip_mtu)); 1212#endif 1213 case IPCTL_RTEXPIRE: 1214 return (sysctl_int(oldp, oldlenp, newp, newlen, 1215 &rtq_reallyold)); 1216 case IPCTL_RTMINEXPIRE: --- 32 unchanged lines hidden --- |