1- /* ip_icmp.c 4.1 81/11/07 */
1+ /* ip_icmp.c 4.2 81/11/08 */
22
33#include "../h/param.h"
44#include "../h/mbuf.h"
5- #include "../inet/inet.h"
6- #include "../inet/inet_systm.h"
7- #include "../inet/ip.h"
5+ #include "../h/inaddr.h"
6+ #include "../net/inet.h"
7+ #include "../net/inet_systm.h"
8+ #include "../net/ip.h"
9+ #include "../net/ip_icmp.h"
810
911/*
1012 * ICMP routines: error generation, receive packet processing, and
@@ -20,7 +22,7 @@ icmp_error(oip, type, code)
2022 int type ;
2123{
2224 int oiplen = oip -> ip_hl << 2 ;
23- struct icmp * icp = (struct icp * )((int )oip + oiplen );
25+ struct icmp * icp = (struct icmp * )((int )oip + oiplen );
2426 struct mbuf * m ;
2527 struct ip * nip ;
2628
@@ -47,17 +49,17 @@ icmp_error(oip, type, code)
4749 icp -> icmp_pptr = code ;
4850 } else
4951 icp -> icmp_code = code ;
50- bcopy ((caddr_t )oip , (caddr_t )& icp -> icmp_ip . icmp_ip , oiplen + 8 );
52+ bcopy ((caddr_t )oip , (caddr_t )& icp -> icmp_ip , oiplen + 8 );
5153
5254 /*
5355 * Now prepend an IP header and reflect this packet back to
5456 * the source.
5557 */
5658 m -> m_off -= sizeof (struct ip );
5759 m -> m_len += sizeof (struct ip );
58- nip = (struct ip * )mtod (m );
59- * nip = * ip ;
60- icmp_reflect (ip );
60+ nip = (struct ip * )mtod (m , struct ip * );
61+ * nip = * oip ;
62+ icmp_reflect (nip );
6163
6264 /*
6365 * Discard mbufs of original datagram
@@ -67,15 +69,16 @@ icmp_error(oip, type, code)
6769}
6870
6971/*
70- * Processor a received ICMP message.
72+ * Process a received ICMP message.
7173 */
7274icmp_input (m )
7375 struct mbuf * m ;
7476{
75- int hlen = ip -> ip_hl << 2 ;
76- register struct ip * ip = (struct ip * )mtod (m );
7777 register struct icmp * icp ;
78+ register struct ip * ip = mtod (m , struct ip * );
79+ int hlen = ip -> ip_hl << 2 ;
7880 int icmplen = ip -> ip_len - hlen ;
81+ int i ;
7982
8083 /*
8184 * Locate icmp structure in mbuf, and check
@@ -84,16 +87,16 @@ icmp_input(m)
8487 m -> m_len -= hlen ;
8588 m -> m_off += hlen ;
8689 /* need routine to make sure header is in this mbuf here */
87- icp = (struct icmp * )mtod (m );
90+ icp = (struct icmp * )mtod (m , struct icmp * );
8891 i = icp -> icmp_cksum ;
8992 icp -> icmp_cksum = 0 ;
90- if (i != cksum (m , icmplen ) || icmplen < ICMP_MINLEN )
91- goto bad ;
93+ if (i != inet_cksum (m , icmplen ) || icmplen < ICMP_MINLEN )
94+ goto free ;
9295
9396 /*
9497 * Message type specific processing.
9598 */
96- switch (ipc -> icmp_type ) {
99+ switch (icp -> icmp_type ) {
97100
98101 case ICMP_UNREACH :
99102 case ICMP_TIMXCEED :
@@ -104,20 +107,20 @@ icmp_input(m)
104107 * Problem with previous datagram; advise
105108 * higher level routines.
106109 */
107- if (icmplen < ICMP_MINADVLEN || icmplen < ICMP_ADVLEN (ipc ))
108- goto drop ;
109- icmp_advise (ip , ipc );
110+ if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN (icp ))
111+ goto free ;
112+ icmp_advise (ip , icp );
110113 goto free ;
111114
112115 case ICMP_ECHO :
113116 icp -> icmp_type = ICMP_ECHOREPLY ;
114117 goto reflect ;
115118
116119 case ICMP_TSTAMP :
117- if (icmplen < ICMP_MINLEN + sizeof ( ) )
118- goto bad ;
120+ if (icmplen < ICMP_TSLEN )
121+ goto free ;
119122 icp -> icmp_type = ICMP_TSTAMPREPLY ;
120- millitime (& icp -> icmp_rtime );
123+ ip_time (& icp -> icmp_rtime );
121124 icp -> icmp_ttime = icp -> icmp_rtime ; /* bogus, do later! */
122125 goto reflect ;
123126
@@ -128,8 +131,8 @@ icmp_input(m)
128131 case ICMP_ECHOREPLY :
129132 case ICMP_TSTAMPREPLY :
130133 case ICMP_IREQREPLY :
131- if (icmplen < ICMP_MINADVLEN || icmplen < ICMP_ADVLEN (ipc ))
132- goto drop ;
134+ if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN (icp ))
135+ goto free ;
133136 icmp_gotreply (icp );
134137 goto free ;
135138
@@ -148,29 +151,27 @@ icmp_input(m)
148151icmp_reflect (ip )
149152 struct ip * ip ;
150153{
151- struct inet_addr t ;
154+ struct ip_addr t ;
152155
156+ t = ip -> ip_src ; ip -> ip_dst = ip -> ip_src ; ip -> ip_src = t ;
153157 /*
154158 * This is a little naive... do we have to munge the options
155159 * to reverse source routing?
156160 */
157- t = ip -> ip_src .s_addr ;
158- ip -> ip_dst .s_addr = ip -> ip_src .d_addr ;
159- ip -> ip_src .d_addr = t ;
160161 icmp_send (ip );
161162}
162163
163164/*
164165 * Send an icmp packet back to the ip level, after
165166 * supplying a checksum.
166167 */
167- icmp_send (ip , ipc )
168+ icmp_send (ip , icp )
168169 struct ip * ip ;
169- struct icmp * ipc ;
170+ struct icmp * icp ;
170171{
171172
172- ipc -> ipc_cksum = 0 ;
173- ipc -> ipc_cksum = cksum (m , impclen );
173+ icp -> icmp_cksum = 0 ;
174+ icp -> icmp_inet_cksum = cksum (dtom ( ip ), 0 ); /* ### */
174175 /* what about ttl? */
175176 ip_output (ip );
176177}
@@ -183,22 +184,9 @@ icmp_advise(ip, icp)
183184 struct ip * ip ;
184185 struct icmp * icp ;
185186{
186- int (* f )(), tcp_advise (), udp_advise (), raw_advise ();
187-
188- switch (ip -> ip_p ) {
189- case IPPROTO_TCP :
190- f = tcp_advise ;
191- break ;
192187
193- case IPPROTO_UDP :
194- f = udp_advise ;
195- break ;
196-
197- default :
198- f = raw_advise ;
199- break ;
200- }
201- (* f )(ip , icp );
188+ /* pass through protocol specific switch */
189+ /* (*f)(ip, icp); */
202190}
203191
204192/*
@@ -211,3 +199,13 @@ icmp_gotreply(icp)
211199{
212200
213201}
202+
203+ icmp_drain ()
204+ {
205+
206+ }
207+
208+ ip_time ()
209+ {
210+
211+ }
0 commit comments