2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1982, 1986, 1988, 1993
24 * The Regents of the University of California. All rights reserved.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. All advertising materials mentioning features or use of this software
35 * must display the following acknowledgement:
36 * This product includes software developed by the University of
37 * California, Berkeley and its contributors.
38 * 4. Neither the name of the University nor the names of its contributors
39 * may be used to endorse or promote products derived from this software
40 * without specific prior written permission.
42 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * @(#)ip_icmp.c 8.2 (Berkeley) 1/4/94
57 #include <sys/param.h>
58 #include <sys/systm.h>
60 #include <sys/protosw.h>
61 #include <sys/socket.h>
63 #include <sys/kernel.h>
64 #include <sys/sysctl.h>
67 #include <net/route.h>
70 #include <netinet/in.h>
71 #include <netinet/in_systm.h>
72 #include <netinet/in_var.h>
73 #include <netinet/ip.h>
74 #include <netinet/ip_icmp.h>
75 #include <netinet/ip_var.h>
76 #include <netinet/icmp_var.h>
79 #include <netinet6/ipsec.h>
80 #include <netkey/key.h>
83 #if defined(NFAITH) && NFAITH > 0
85 #include <net/if_types.h>
89 * ICMP routines: error generation, receive packet processing, and
90 * routines to turnaround packets back to the originator, and
91 * host table maintenance routines.
94 static struct icmpstat icmpstat
;
95 SYSCTL_STRUCT(_net_inet_icmp
, ICMPCTL_STATS
, stats
, CTLFLAG_RD
,
96 &icmpstat
, icmpstat
, "");
98 static int icmpmaskrepl
= 0;
99 SYSCTL_INT(_net_inet_icmp
, ICMPCTL_MASKREPL
, maskrepl
, CTLFLAG_RW
,
100 &icmpmaskrepl
, 0, "");
105 * ICMP error-response bandwidth limiting sysctl. If not enabled, sysctl
106 * variable content is -1 and read-only.
109 static int icmplim
= 100;
110 SYSCTL_INT(_net_inet_icmp
, ICMPCTL_ICMPLIM
, icmplim
, CTLFLAG_RW
,
114 static int icmplim
= -1;
115 SYSCTL_INT(_net_inet_icmp
, ICMPCTL_ICMPLIM
, icmplim
, CTLFLAG_RD
,
121 * ICMP broadcast echo sysctl
124 static int icmpbmcastecho
= 0;
125 SYSCTL_INT(_net_inet_icmp
, OID_AUTO
, bmcastecho
, CTLFLAG_RW
, &icmpbmcastecho
,
133 static void icmp_reflect
__P((struct mbuf
*));
134 static void icmp_send
__P((struct mbuf
*, struct mbuf
*));
135 int ip_next_mtu
__P((int, int));
137 extern struct protosw inetsw
[];
140 * Generate an error packet of type error
141 * in response to bad packet ip.
144 icmp_error(n
, type
, code
, dest
, destifp
)
148 struct ifnet
*destifp
;
150 register struct ip
*oip
= mtod(n
, struct ip
*), *nip
;
151 register unsigned oiplen
= IP_VHL_HL(oip
->ip_vhl
) << 2;
152 register struct icmp
*icp
;
153 register struct mbuf
*m
;
158 printf("icmp_error(%p, %x, %d)\n", oip
, type
, code
);
160 if (type
!= ICMP_REDIRECT
)
161 icmpstat
.icps_error
++;
163 * Don't send error if the original packet was encrypted.
164 * Don't send error if not the first fragment of message.
165 * Don't error if the old packet protocol was ICMP
166 * error message, only known informational types.
168 if (n
->m_flags
& M_DECRYPTED
)
170 if (oip
->ip_off
&~ (IP_MF
|IP_DF
))
172 if (oip
->ip_p
== IPPROTO_ICMP
&& type
!= ICMP_REDIRECT
&&
173 n
->m_len
>= oiplen
+ ICMP_MINLEN
&&
174 !ICMP_INFOTYPE(((struct icmp
*)((caddr_t
)oip
+ oiplen
))->icmp_type
)) {
175 icmpstat
.icps_oldicmp
++;
178 /* Don't send error in response to a multicast or broadcast packet */
179 if (n
->m_flags
& (M_BCAST
|M_MCAST
))
182 * First, formulate icmp message
184 m
= m_gethdr(M_DONTWAIT
, MT_HEADER
);
187 icmplen
= oiplen
+ min(8, oip
->ip_len
);
188 m
->m_len
= icmplen
+ ICMP_MINLEN
;
189 MH_ALIGN(m
, m
->m_len
);
190 icp
= mtod(m
, struct icmp
*);
191 if ((u_int
)type
> ICMP_MAXTYPE
)
193 icmpstat
.icps_outhist
[type
]++;
194 icp
->icmp_type
= type
;
195 if (type
== ICMP_REDIRECT
)
196 icp
->icmp_gwaddr
.s_addr
= dest
;
200 * The following assignments assume an overlay with the
201 * zeroed icmp_void field.
203 if (type
== ICMP_PARAMPROB
) {
204 icp
->icmp_pptr
= code
;
206 } else if (type
== ICMP_UNREACH
&&
207 code
== ICMP_UNREACH_NEEDFRAG
&& destifp
) {
208 icp
->icmp_nextmtu
= htons(destifp
->if_mtu
);
212 icp
->icmp_code
= code
;
213 bcopy((caddr_t
)oip
, (caddr_t
)&icp
->icmp_ip
, icmplen
);
215 nip
->ip_len
= htons((u_short
)(nip
->ip_len
+ oiplen
));
218 * Now, copy old ip header (without options)
219 * in front of icmp message.
221 if (m
->m_data
- sizeof(struct ip
) < m
->m_pktdat
)
223 m
->m_data
-= sizeof(struct ip
);
224 m
->m_len
+= sizeof(struct ip
);
225 m
->m_pkthdr
.len
= m
->m_len
;
226 m
->m_pkthdr
.rcvif
= n
->m_pkthdr
.rcvif
;
227 m
->m_pkthdr
.aux
= NULL
; /* for IPsec */
228 nip
= mtod(m
, struct ip
*);
229 bcopy((caddr_t
)oip
, (caddr_t
)nip
, sizeof(struct ip
));
230 nip
->ip_len
= m
->m_len
;
231 nip
->ip_vhl
= IP_VHL_BORING
;
232 nip
->ip_p
= IPPROTO_ICMP
;
240 static struct sockaddr_in icmpsrc
= { sizeof (struct sockaddr_in
), AF_INET
};
241 static struct sockaddr_in icmpdst
= { sizeof (struct sockaddr_in
), AF_INET
};
242 static struct sockaddr_in icmpgw
= { sizeof (struct sockaddr_in
), AF_INET
};
245 * Process a received ICMP message.
249 register struct mbuf
*m
;
252 register struct icmp
*icp
;
253 register struct ip
*ip
= mtod(m
, struct ip
*);
254 int icmplen
= ip
->ip_len
;
256 struct in_ifaddr
*ia
;
257 void (*ctlfunc
) __P((int, struct sockaddr
*, void *));
261 * Locate icmp structure in mbuf, and check
262 * that not corrupted and of at least minimum length.
266 char buf
[4 * sizeof "123"];
267 strcpy(buf
, inet_ntoa(ip
->ip_src
));
268 printf("icmp_input from %s to %s, len %d\n",
269 buf
, inet_ntoa(ip
->ip_dst
), icmplen
);
272 if (icmplen
< ICMP_MINLEN
) {
273 icmpstat
.icps_tooshort
++;
276 i
= hlen
+ min(icmplen
, ICMP_ADVLENMIN
);
277 if (m
->m_len
< i
&& (m
= m_pullup(m
, i
)) == 0) {
278 icmpstat
.icps_tooshort
++;
281 ip
= mtod(m
, struct ip
*);
284 icp
= mtod(m
, struct icmp
*);
285 if (in_cksum(m
, icmplen
)) {
286 icmpstat
.icps_checksum
++;
292 #if defined(NFAITH) && 0 < NFAITH
293 if (m
->m_pkthdr
.rcvif
&& m
->m_pkthdr
.rcvif
->if_type
== IFT_FAITH
) {
295 * Deliver very specific ICMP type only.
297 switch (icp
->icmp_type
) {
309 printf("icmp_input, type %d code %d\n", icp
->icmp_type
,
314 /* drop it if it does not match the policy */
315 /* XXX Is there meaning of check in here ? */
316 if (ipsec4_in_reject(m
, NULL
)) {
317 ipsecstat
.in_polvio
++;
323 * Message type specific processing.
325 if (icp
->icmp_type
> ICMP_MAXTYPE
)
327 icmpstat
.icps_inhist
[icp
->icmp_type
]++;
328 code
= icp
->icmp_code
;
329 switch (icp
->icmp_type
) {
333 case ICMP_UNREACH_NET
:
334 case ICMP_UNREACH_HOST
:
335 case ICMP_UNREACH_PROTOCOL
:
336 case ICMP_UNREACH_PORT
:
337 case ICMP_UNREACH_SRCFAIL
:
338 code
+= PRC_UNREACH_NET
;
341 case ICMP_UNREACH_NEEDFRAG
:
345 case ICMP_UNREACH_NET_UNKNOWN
:
346 case ICMP_UNREACH_NET_PROHIB
:
347 case ICMP_UNREACH_TOSNET
:
348 code
= PRC_UNREACH_NET
;
351 case ICMP_UNREACH_HOST_UNKNOWN
:
352 case ICMP_UNREACH_ISOLATED
:
353 case ICMP_UNREACH_HOST_PROHIB
:
354 case ICMP_UNREACH_TOSHOST
:
355 code
= PRC_UNREACH_HOST
;
358 case ICMP_UNREACH_FILTER_PROHIB
:
359 case ICMP_UNREACH_HOST_PRECEDENCE
:
360 case ICMP_UNREACH_PRECEDENCE_CUTOFF
:
361 code
= PRC_UNREACH_PORT
;
372 code
+= PRC_TIMXCEED_INTRANS
;
378 code
= PRC_PARAMPROB
;
381 case ICMP_SOURCEQUENCH
:
387 * Problem with datagram; advise higher level routines.
389 if (icmplen
< ICMP_ADVLENMIN
|| icmplen
< ICMP_ADVLEN(icp
) ||
390 IP_VHL_HL(icp
->icmp_ip
.ip_vhl
) < (sizeof(struct ip
) >> 2)) {
391 icmpstat
.icps_badlen
++;
394 NTOHS(icp
->icmp_ip
.ip_len
);
395 /* Discard ICMP's in response to multicast packets */
396 if (IN_MULTICAST(ntohl(icp
->icmp_ip
.ip_dst
.s_addr
)))
400 printf("deliver to protocol %d\n", icp
->icmp_ip
.ip_p
);
402 icmpsrc
.sin_addr
= icp
->icmp_ip
.ip_dst
;
406 * If we got a needfrag and there is a host route to the
407 * original destination, and the MTU is not locked, then
408 * set the MTU in the route to the suggested new value
409 * (if given) and then notify as usual. The ULPs will
410 * notice that the MTU has changed and adapt accordingly.
411 * If no new MTU was suggested, then we guess a new one
412 * less than the current value. If the new MTU is
413 * unreasonably small (arbitrarily set at 296), then
414 * we reset the MTU to the interface value and enable the
415 * lock bit, indicating that we are no longer doing MTU
418 if (code
== PRC_MSGSIZE
) {
422 rt
= rtalloc1((struct sockaddr
*)&icmpsrc
, 0,
423 RTF_CLONING
| RTF_PRCLONING
);
424 if (rt
&& (rt
->rt_flags
& RTF_HOST
)
425 && !(rt
->rt_rmx
.rmx_locks
& RTV_MTU
)) {
426 mtu
= ntohs(icp
->icmp_nextmtu
);
428 mtu
= ip_next_mtu(rt
->rt_rmx
.rmx_mtu
,
431 printf("MTU for %s reduced to %d\n",
432 inet_ntoa(icmpsrc
.sin_addr
), mtu
);
435 /* rt->rt_rmx.rmx_mtu =
436 rt->rt_ifp->if_mtu; */
437 rt
->rt_rmx
.rmx_locks
|= RTV_MTU
;
438 } else if (rt
->rt_rmx
.rmx_mtu
> mtu
) {
439 rt
->rt_rmx
.rmx_mtu
= mtu
;
448 * XXX if the packet contains [IPv4 AH TCP], we can't make a
449 * notification to TCP layer.
451 ctlfunc
= ip_protox
[icp
->icmp_ip
.ip_p
]->pr_ctlinput
;
453 (*ctlfunc
)(code
, (struct sockaddr
*)&icmpsrc
,
454 (void *)&icp
->icmp_ip
);
458 icmpstat
.icps_badcode
++;
463 && (m
->m_flags
& (M_MCAST
| M_BCAST
)) != 0) {
464 icmpstat
.icps_bmcastecho
++;
467 icp
->icmp_type
= ICMP_ECHOREPLY
;
472 && (m
->m_flags
& (M_MCAST
| M_BCAST
)) != 0) {
473 icmpstat
.icps_bmcasttstamp
++;
476 if (icmplen
< ICMP_TSLEN
) {
477 icmpstat
.icps_badlen
++;
480 icp
->icmp_type
= ICMP_TSTAMPREPLY
;
481 icp
->icmp_rtime
= iptime();
482 icp
->icmp_ttime
= icp
->icmp_rtime
; /* bogus, do later! */
486 #define satosin(sa) ((struct sockaddr_in *)(sa))
487 if (icmpmaskrepl
== 0)
490 * We are not able to respond with all ones broadcast
491 * unless we receive it over a point-to-point interface.
493 if (icmplen
< ICMP_MASKLEN
)
495 switch (ip
->ip_dst
.s_addr
) {
497 case INADDR_BROADCAST
:
499 icmpdst
.sin_addr
= ip
->ip_src
;
503 icmpdst
.sin_addr
= ip
->ip_dst
;
505 ia
= (struct in_ifaddr
*)ifaof_ifpforaddr(
506 (struct sockaddr
*)&icmpdst
, m
->m_pkthdr
.rcvif
);
511 icp
->icmp_type
= ICMP_MASKREPLY
;
512 icp
->icmp_mask
= ia
->ia_sockmask
.sin_addr
.s_addr
;
513 if (ip
->ip_src
.s_addr
== 0) {
514 if (ia
->ia_ifp
->if_flags
& IFF_BROADCAST
)
515 ip
->ip_src
= satosin(&ia
->ia_broadaddr
)->sin_addr
;
516 else if (ia
->ia_ifp
->if_flags
& IFF_POINTOPOINT
)
517 ip
->ip_src
= satosin(&ia
->ia_dstaddr
)->sin_addr
;
520 ip
->ip_len
+= hlen
; /* since ip_input deducts this */
521 icmpstat
.icps_reflect
++;
522 icmpstat
.icps_outhist
[icp
->icmp_type
]++;
529 if (icmplen
< ICMP_ADVLENMIN
|| icmplen
< ICMP_ADVLEN(icp
) ||
530 IP_VHL_HL(icp
->icmp_ip
.ip_vhl
) < (sizeof(struct ip
) >> 2)) {
531 icmpstat
.icps_badlen
++;
535 * Short circuit routing redirects to force
536 * immediate change in the kernel's routing
537 * tables. The message is also handed to anyone
538 * listening on a raw socket (e.g. the routing
539 * daemon for use in updating its tables).
541 icmpgw
.sin_addr
= ip
->ip_src
;
542 icmpdst
.sin_addr
= icp
->icmp_gwaddr
;
545 char buf
[4 * sizeof "123"];
546 strcpy(buf
, inet_ntoa(icp
->icmp_ip
.ip_dst
));
548 printf("redirect dst %s to %s\n",
549 buf
, inet_ntoa(icp
->icmp_gwaddr
));
552 icmpsrc
.sin_addr
= icp
->icmp_ip
.ip_dst
;
553 rtredirect((struct sockaddr
*)&icmpsrc
,
554 (struct sockaddr
*)&icmpdst
,
555 (struct sockaddr
*)0, RTF_GATEWAY
| RTF_HOST
,
556 (struct sockaddr
*)&icmpgw
, (struct rtentry
**)0);
557 pfctlinput(PRC_REDIRECT_HOST
, (struct sockaddr
*)&icmpsrc
);
559 key_sa_routechange((struct sockaddr
*)&icmpsrc
);
564 * No kernel processing for the following;
565 * just fall through to send to raw listener.
568 case ICMP_ROUTERADVERT
:
569 case ICMP_ROUTERSOLICIT
:
570 case ICMP_TSTAMPREPLY
:
586 * Reflect the ip packet back to the source
592 register struct ip
*ip
= mtod(m
, struct ip
*);
593 register struct in_ifaddr
*ia
;
595 struct mbuf
*opts
= 0;
596 int optlen
= (IP_VHL_HL(ip
->ip_vhl
) << 2) - sizeof(struct ip
);
598 if (!in_canforward(ip
->ip_src
) &&
599 ((ntohl(ip
->ip_src
.s_addr
) & IN_CLASSA_NET
) !=
600 (IN_LOOPBACKNET
<< IN_CLASSA_NSHIFT
))) {
601 m_freem(m
); /* Bad return address */
602 goto done
; /* Ip_output() will check for broadcast */
605 ip
->ip_dst
= ip
->ip_src
;
607 * If the incoming packet was addressed directly to us,
608 * use dst as the src for the reply. Otherwise (broadcast
609 * or anonymous), use the address which corresponds
610 * to the incoming interface.
612 for (ia
= in_ifaddrhead
.tqh_first
; ia
; ia
= ia
->ia_link
.tqe_next
) {
613 if (t
.s_addr
== IA_SIN(ia
)->sin_addr
.s_addr
)
615 if (ia
->ia_ifp
&& (ia
->ia_ifp
->if_flags
& IFF_BROADCAST
) &&
616 t
.s_addr
== satosin(&ia
->ia_broadaddr
)->sin_addr
.s_addr
)
619 icmpdst
.sin_addr
= t
;
620 if ((ia
== (struct in_ifaddr
*)0) && m
->m_pkthdr
.rcvif
)
621 ia
= (struct in_ifaddr
*)ifaof_ifpforaddr(
622 (struct sockaddr
*)&icmpdst
, m
->m_pkthdr
.rcvif
);
624 * The following happens if the packet was not addressed to us,
625 * and was received on an interface with no IP address.
627 if (ia
== (struct in_ifaddr
*)0)
628 ia
= in_ifaddrhead
.tqh_first
;
629 t
= IA_SIN(ia
)->sin_addr
;
639 * Retrieve any source routing from the incoming packet;
640 * add on any record-route or timestamp options.
642 cp
= (u_char
*) (ip
+ 1);
643 if ((opts
= ip_srcroute()) == 0 &&
644 (opts
= m_gethdr(M_DONTWAIT
, MT_HEADER
))) {
645 opts
->m_len
= sizeof(struct in_addr
);
646 mtod(opts
, struct in_addr
*)->s_addr
= 0;
651 printf("icmp_reflect optlen %d rt %d => ",
652 optlen
, opts
->m_len
);
654 for (cnt
= optlen
; cnt
> 0; cnt
-= len
, cp
+= len
) {
655 opt
= cp
[IPOPT_OPTVAL
];
656 if (opt
== IPOPT_EOL
)
658 if (opt
== IPOPT_NOP
)
661 if (cnt
< IPOPT_OLEN
+ sizeof(*cp
))
663 len
= cp
[IPOPT_OLEN
];
664 if (len
< IPOPT_OLEN
+ sizeof(*cp
) ||
669 * Should check for overflow, but it "can't happen"
671 if (opt
== IPOPT_RR
|| opt
== IPOPT_TS
||
672 opt
== IPOPT_SECURITY
) {
674 mtod(opts
, caddr_t
) + opts
->m_len
, len
);
678 /* Terminate & pad, if necessary */
679 cnt
= opts
->m_len
% 4;
681 for (; cnt
< 4; cnt
++) {
682 *(mtod(opts
, caddr_t
) + opts
->m_len
) =
689 printf("%d\n", opts
->m_len
);
693 * Now strip out original options by copying rest of first
694 * mbuf's data back, and adjust the IP length.
696 ip
->ip_len
-= optlen
;
697 ip
->ip_vhl
= IP_VHL_BORING
;
699 if (m
->m_flags
& M_PKTHDR
)
700 m
->m_pkthdr
.len
-= optlen
;
701 optlen
+= sizeof(struct ip
);
702 bcopy((caddr_t
)ip
+ optlen
, (caddr_t
)(ip
+ 1),
703 (unsigned)(m
->m_len
- sizeof(struct ip
)));
705 m
->m_flags
&= ~(M_BCAST
|M_MCAST
);
713 * Send an icmp packet back to the ip level,
714 * after supplying a checksum.
718 register struct mbuf
*m
;
721 register struct ip
*ip
= mtod(m
, struct ip
*);
723 register struct icmp
*icp
;
726 hlen
= IP_VHL_HL(ip
->ip_vhl
) << 2;
729 icp
= mtod(m
, struct icmp
*);
731 icp
->icmp_cksum
= in_cksum(m
, ip
->ip_len
- hlen
);
734 m
->m_pkthdr
.rcvif
= (struct ifnet
*)0;
735 m
->m_pkthdr
.aux
= NULL
;
736 m
->m_pkthdr
.csum_data
= 0;
737 m
->m_pkthdr
.csum_flags
= 0;
740 char buf
[4 * sizeof "123"];
741 strcpy(buf
, inet_ntoa(ip
->ip_dst
));
742 printf("icmp_send dst %s src %s\n",
743 buf
, inet_ntoa(ip
->ip_src
));
746 bzero(&ro
, sizeof ro
);
749 ipsec_setsocket(m
, NULL
);
751 (void) ip_output(m
, opts
, &ro
, 0, NULL
);
763 t
= (atv
.tv_sec
% (24*60*60)) * 1000 + atv
.tv_usec
/ 1000;
769 * Return the next larger or smaller MTU plateau (table from RFC 1191)
770 * given current value MTU. If DIR is less than zero, a larger plateau
771 * is returned; otherwise, a smaller value is returned.
774 ip_next_mtu(mtu
, dir
)
778 static int mtutab
[] = {
779 65535, 32000, 17914, 8166, 4352, 2002, 1492, 1006, 508, 296,
784 for (i
= 0; i
< (sizeof mtutab
) / (sizeof mtutab
[0]); i
++) {
785 if (mtu
>= mtutab
[i
])
793 return mtutab
[i
- 1];
796 if (mtutab
[i
] == 0) {
798 } else if(mtu
> mtutab
[i
]) {
801 return mtutab
[i
+ 1];
810 * badport_bandlim() - check for ICMP bandwidth limit
812 * Return 0 if it is ok to send an ICMP error response, -1 if we have
813 * hit our bandwidth limit and it is not ok.
815 * If icmplim is <= 0, the feature is disabled and 0 is returned.
817 * For now we separate the TCP and UDP subsystems w/ different 'which'
818 * values. We may eventually remove this separation (and simplify the
821 * Note that the printing of the error message is delayed so we can
822 * properly print the icmp error rate that the system was trying to do
823 * (i.e. 22000/100 pps, etc...). This can cause long delays in printing
824 * the 'final' error, but it doesn't make sense to solve the printing
825 * delay with more complex code.
829 badport_bandlim(int which
)
831 static int lticks
[2];
832 static int lpackets
[2];
836 * Return ok status if feature disabled or argument out of
840 if (icmplim
<= 0 || which
>= 2 || which
< 0)
842 dticks
= ticks
- lticks
[which
];
845 * reset stats when cumulative dt exceeds one second.
848 if ((unsigned int)dticks
> hz
) {
849 if (lpackets
[which
] > icmplim
) {
850 printf("icmp-response bandwidth limit %d/%d pps\n",
855 lticks
[which
] = ticks
;
863 if (++lpackets
[which
] > icmplim
) {