Deleted Added
sdiff udiff text old ( 167886 ) new ( 169454 )
full compact
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 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
212ip_init(void)
213{
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
271void
272ip_fini(void *xtp)
273{
274
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 */
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(struct ipqhead *fhp, struct ipq *fp)
1058{
1059 struct mbuf *q;
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
1079ip_slowtimo(void)
1080{
1081 struct ipq *fp;
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
1118ip_drain(void)
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 *
1199ip_rtaddr(struct in_addr dst)
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
1436ip_savecontrol(struct inpcb *inp, struct mbuf **mp, struct ip *ip,
1437 struct mbuf *m)
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 ---