ip_input.c (167886) | ip_input.c (169454) |
---|---|
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 --- 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 * @(#)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 --- 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 * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 |
30 * $FreeBSD: head/sys/netinet/ip_input.c 167886 2007-03-25 21:49:50Z rwatson $ | 30 * $FreeBSD: head/sys/netinet/ip_input.c 169454 2007-05-10 15:58:48Z rwatson $ |
31 */ 32 33#include "opt_bootp.h" 34#include "opt_ipfw.h" 35#include "opt_ipstealth.h" 36#include "opt_ipsec.h" 37#include "opt_mac.h" 38#include "opt_carp.h" --- 165 unchanged lines hidden (view full) --- 204 205static void ip_freef(struct ipqhead *, struct ipq *); 206 207/* 208 * IP initialization: fill in IP protocol switch table. 209 * All protocols not implemented in kernel go to raw IP protocol handler. 210 */ 211void | 31 */ 32 33#include "opt_bootp.h" 34#include "opt_ipfw.h" 35#include "opt_ipstealth.h" 36#include "opt_ipsec.h" 37#include "opt_mac.h" 38#include "opt_carp.h" --- 165 unchanged lines hidden (view full) --- 204 205static void ip_freef(struct ipqhead *, struct ipq *); 206 207/* 208 * IP initialization: fill in IP protocol switch table. 209 * All protocols not implemented in kernel go to raw IP protocol handler. 210 */ 211void |
212ip_init() | 212ip_init(void) |
213{ | 213{ |
214 register struct protosw *pr; 215 register int i; | 214 struct protosw *pr; 215 int i; |
216 217 TAILQ_INIT(&in_ifaddrhead); 218 in_ifaddrhashtbl = hashinit(INADDR_NHASH, M_IFADDR, &in_ifaddrhmask); 219 pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW); 220 if (pr == NULL) 221 panic("ip_init: PF_INET not found"); 222 223 /* Initialize the entire ip_protox[] array to IPPROTO_RAW. */ --- 39 unchanged lines hidden (view full) --- 263 264 /* Initialize various other remaining things. */ 265 ip_id = time_second & 0xffff; 266 ipintrq.ifq_maxlen = ipqmaxlen; 267 mtx_init(&ipintrq.ifq_mtx, "ip_inq", NULL, MTX_DEF); 268 netisr_register(NETISR_IP, ip_input, &ipintrq, NETISR_MPSAFE); 269} 270 | 216 217 TAILQ_INIT(&in_ifaddrhead); 218 in_ifaddrhashtbl = hashinit(INADDR_NHASH, M_IFADDR, &in_ifaddrhmask); 219 pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW); 220 if (pr == NULL) 221 panic("ip_init: PF_INET not found"); 222 223 /* Initialize the entire ip_protox[] array to IPPROTO_RAW. */ --- 39 unchanged lines hidden (view full) --- 263 264 /* Initialize various other remaining things. */ 265 ip_id = time_second & 0xffff; 266 ipintrq.ifq_maxlen = ipqmaxlen; 267 mtx_init(&ipintrq.ifq_mtx, "ip_inq", NULL, MTX_DEF); 268 netisr_register(NETISR_IP, ip_input, &ipintrq, NETISR_MPSAFE); 269} 270 |
271void ip_fini(xtp) 272 void *xtp; | 271void 272ip_fini(void *xtp) |
273{ | 273{ |
274 |
|
274 callout_stop(&ipport_tick_callout); 275} 276 277/* 278 * Ip input routine. Checksum and byte swap header. If fragmented 279 * try to reassemble. Process options. Pass to next level. 280 */ 281void --- 451 unchanged lines hidden (view full) --- 733 * whole datagram. If the argument is the first fragment or one 734 * in between the function will return NULL and store the mbuf 735 * in the fragment chain. If the argument is the last fragment 736 * the packet will be reassembled and the pointer to the new 737 * mbuf returned for further processing. Only m_tags attached 738 * to the first packet/fragment are preserved. 739 * The IP header is *NOT* adjusted out of iplen. 740 */ | 275 callout_stop(&ipport_tick_callout); 276} 277 278/* 279 * Ip input routine. Checksum and byte swap header. If fragmented 280 * try to reassemble. Process options. Pass to next level. 281 */ 282void --- 451 unchanged lines hidden (view full) --- 734 * whole datagram. If the argument is the first fragment or one 735 * in between the function will return NULL and store the mbuf 736 * in the fragment chain. If the argument is the last fragment 737 * the packet will be reassembled and the pointer to the new 738 * mbuf returned for further processing. Only m_tags attached 739 * to the first packet/fragment are preserved. 740 * The IP header is *NOT* adjusted out of iplen. 741 */ |
741 | |
742struct mbuf * 743ip_reass(struct mbuf *m) 744{ 745 struct ip *ip; 746 struct mbuf *p, *q, *nq, *t; 747 struct ipq *fp = NULL; 748 struct ipqhead *head; 749 int i, hlen, next; --- 299 unchanged lines hidden (view full) --- 1049#undef GETIP 1050} 1051 1052/* 1053 * Free a fragment reassembly header and all 1054 * associated datagrams. 1055 */ 1056static void | 742struct mbuf * 743ip_reass(struct mbuf *m) 744{ 745 struct ip *ip; 746 struct mbuf *p, *q, *nq, *t; 747 struct ipq *fp = NULL; 748 struct ipqhead *head; 749 int i, hlen, next; --- 299 unchanged lines hidden (view full) --- 1049#undef GETIP 1050} 1051 1052/* 1053 * Free a fragment reassembly header and all 1054 * associated datagrams. 1055 */ 1056static void |
1057ip_freef(fhp, fp) 1058 struct ipqhead *fhp; 1059 struct ipq *fp; | 1057ip_freef(struct ipqhead *fhp, struct ipq *fp) |
1060{ | 1058{ |
1061 register struct mbuf *q; | 1059 struct mbuf *q; |
1062 1063 IPQ_LOCK_ASSERT(); 1064 1065 while (fp->ipq_frags) { 1066 q = fp->ipq_frags; 1067 fp->ipq_frags = q->m_nextpkt; 1068 m_freem(q); 1069 } 1070 TAILQ_REMOVE(fhp, fp, ipq_list); 1071 uma_zfree(ipq_zone, fp); 1072 nipq--; 1073} 1074 1075/* 1076 * IP timer processing; 1077 * if a timer expires on a reassembly 1078 * queue, discard it. 1079 */ 1080void | 1060 1061 IPQ_LOCK_ASSERT(); 1062 1063 while (fp->ipq_frags) { 1064 q = fp->ipq_frags; 1065 fp->ipq_frags = q->m_nextpkt; 1066 m_freem(q); 1067 } 1068 TAILQ_REMOVE(fhp, fp, ipq_list); 1069 uma_zfree(ipq_zone, fp); 1070 nipq--; 1071} 1072 1073/* 1074 * IP timer processing; 1075 * if a timer expires on a reassembly 1076 * queue, discard it. 1077 */ 1078void |
1081ip_slowtimo() | 1079ip_slowtimo(void) |
1082{ | 1080{ |
1083 register struct ipq *fp; | 1081 struct ipq *fp; |
1084 int i; 1085 1086 IPQ_LOCK(); 1087 for (i = 0; i < IPREASS_NHASH; i++) { 1088 for(fp = TAILQ_FIRST(&ipq[i]); fp;) { 1089 struct ipq *fpp; 1090 1091 fpp = fp; --- 20 unchanged lines hidden (view full) --- 1112 } 1113 IPQ_UNLOCK(); 1114} 1115 1116/* 1117 * Drain off all datagram fragments. 1118 */ 1119void | 1082 int i; 1083 1084 IPQ_LOCK(); 1085 for (i = 0; i < IPREASS_NHASH; i++) { 1086 for(fp = TAILQ_FIRST(&ipq[i]); fp;) { 1087 struct ipq *fpp; 1088 1089 fpp = fp; --- 20 unchanged lines hidden (view full) --- 1110 } 1111 IPQ_UNLOCK(); 1112} 1113 1114/* 1115 * Drain off all datagram fragments. 1116 */ 1117void |
1120ip_drain() | 1118ip_drain(void) |
1121{ 1122 int i; 1123 1124 IPQ_LOCK(); 1125 for (i = 0; i < IPREASS_NHASH; i++) { 1126 while(!TAILQ_EMPTY(&ipq[i])) { 1127 ipstat.ips_fragdropped += 1128 TAILQ_FIRST(&ipq[i])->ipq_nfrags; --- 64 unchanged lines hidden (view full) --- 1193 return (0); 1194} 1195 1196/* 1197 * Given address of next destination (final or next hop), 1198 * return internet address info of interface to be used to get there. 1199 */ 1200struct in_ifaddr * | 1119{ 1120 int i; 1121 1122 IPQ_LOCK(); 1123 for (i = 0; i < IPREASS_NHASH; i++) { 1124 while(!TAILQ_EMPTY(&ipq[i])) { 1125 ipstat.ips_fragdropped += 1126 TAILQ_FIRST(&ipq[i])->ipq_nfrags; --- 64 unchanged lines hidden (view full) --- 1191 return (0); 1192} 1193 1194/* 1195 * Given address of next destination (final or next hop), 1196 * return internet address info of interface to be used to get there. 1197 */ 1198struct in_ifaddr * |
1201ip_rtaddr(dst) 1202 struct in_addr dst; | 1199ip_rtaddr(struct in_addr dst) |
1203{ 1204 struct route sro; 1205 struct sockaddr_in *sin; 1206 struct in_ifaddr *ifa; 1207 1208 bzero(&sro, sizeof(sro)); 1209 sin = (struct sockaddr_in *)&sro.ro_dst; 1210 sin->sin_family = AF_INET; --- 220 unchanged lines hidden (view full) --- 1431 case EACCES: /* ipfw denied packet */ 1432 m_freem(mcopy); 1433 return; 1434 } 1435 icmp_error(mcopy, type, code, dest.s_addr, mtu); 1436} 1437 1438void | 1200{ 1201 struct route sro; 1202 struct sockaddr_in *sin; 1203 struct in_ifaddr *ifa; 1204 1205 bzero(&sro, sizeof(sro)); 1206 sin = (struct sockaddr_in *)&sro.ro_dst; 1207 sin->sin_family = AF_INET; --- 220 unchanged lines hidden (view full) --- 1428 case EACCES: /* ipfw denied packet */ 1429 m_freem(mcopy); 1430 return; 1431 } 1432 icmp_error(mcopy, type, code, dest.s_addr, mtu); 1433} 1434 1435void |
1439ip_savecontrol(inp, mp, ip, m) 1440 register struct inpcb *inp; 1441 register struct mbuf **mp; 1442 register struct ip *ip; 1443 register struct mbuf *m; | 1436ip_savecontrol(struct inpcb *inp, struct mbuf **mp, struct ip *ip, 1437 struct mbuf *m) |
1444{ 1445 if (inp->inp_socket->so_options & (SO_BINTIME | SO_TIMESTAMP)) { 1446 struct bintime bt; 1447 1448 bintime(&bt); 1449 if (inp->inp_socket->so_options & SO_BINTIME) { 1450 *mp = sbcreatecontrol((caddr_t) &bt, sizeof(bt), 1451 SCM_BINTIME, SOL_SOCKET); --- 151 unchanged lines hidden --- | 1438{ 1439 if (inp->inp_socket->so_options & (SO_BINTIME | SO_TIMESTAMP)) { 1440 struct bintime bt; 1441 1442 bintime(&bt); 1443 if (inp->inp_socket->so_options & SO_BINTIME) { 1444 *mp = sbcreatecontrol((caddr_t) &bt, sizeof(bt), 1445 SCM_BINTIME, SOL_SOCKET); --- 151 unchanged lines hidden --- |