40 #ifndef included_ip_input_h
41 #define included_ip_input_h
63 if ((
ip->ip_version_and_header_length & 0xf) != 5)
65 *
error = IP4_ERROR_OPTIONS;
67 *
error = IP4_ERROR_BAD_CHECKSUM;
70 *
error = IP4_ERROR_VERSION;
75 *
error = IP4_ERROR_BAD_CHECKSUM;
82 u16 *
next,
int verify_checksum)
84 u8 error0, error1, error2, error3;
85 u32 ip_len0, cur_len0;
86 u32 ip_len1, cur_len1;
87 u32 ip_len2, cur_len2;
88 u32 ip_len3, cur_len3;
89 i32 len_diff0, len_diff1, len_diff2, len_diff3;
91 error0 = error1 = error2 = error3 = IP4_ERROR_NONE;
99 error0 = IP4_ERROR_TIME_EXPIRED;
101 error1 = IP4_ERROR_TIME_EXPIRED;
103 error2 = IP4_ERROR_TIME_EXPIRED;
105 error3 = IP4_ERROR_TIME_EXPIRED;
109 IP4_ERROR_FRAGMENT_OFFSET_ONE : error0;
111 IP4_ERROR_FRAGMENT_OFFSET_ONE : error1;
113 IP4_ERROR_FRAGMENT_OFFSET_ONE : error2;
115 IP4_ERROR_FRAGMENT_OFFSET_ONE : error3;
118 ip_len0 = clib_net_to_host_u16 (
ip[0]->
length);
119 ip_len1 = clib_net_to_host_u16 (
ip[1]->
length);
120 ip_len2 = clib_net_to_host_u16 (
ip[2]->
length);
121 ip_len3 = clib_net_to_host_u16 (
ip[3]->
length);
124 error0 = ip_len0 <
sizeof (
ip[0][0]) ? IP4_ERROR_TOO_SHORT : error0;
125 error1 = ip_len1 <
sizeof (
ip[1][0]) ? IP4_ERROR_TOO_SHORT : error1;
126 error2 = ip_len2 <
sizeof (
ip[2][0]) ? IP4_ERROR_TOO_SHORT : error2;
127 error3 = ip_len3 <
sizeof (
ip[3][0]) ? IP4_ERROR_TOO_SHORT : error3;
134 len_diff0 = cur_len0 - ip_len0;
135 len_diff1 = cur_len1 - ip_len1;
136 len_diff2 = cur_len2 - ip_len2;
137 len_diff3 = cur_len3 - ip_len3;
139 error0 = len_diff0 < 0 ? IP4_ERROR_BAD_LENGTH : error0;
140 error1 = len_diff1 < 0 ? IP4_ERROR_BAD_LENGTH : error1;
141 error2 = len_diff2 < 0 ? IP4_ERROR_BAD_LENGTH : error2;
142 error3 = len_diff3 < 0 ? IP4_ERROR_BAD_LENGTH : error3;
146 if (error0 == IP4_ERROR_TIME_EXPIRED)
149 ICMP4_time_exceeded_ttl_exceeded_in_transit,
154 next[0] = error0 != IP4_ERROR_OPTIONS ?
160 if (error1 == IP4_ERROR_TIME_EXPIRED)
163 ICMP4_time_exceeded_ttl_exceeded_in_transit,
168 next[1] = error1 != IP4_ERROR_OPTIONS ?
174 if (error2 == IP4_ERROR_TIME_EXPIRED)
177 ICMP4_time_exceeded_ttl_exceeded_in_transit,
182 next[2] = error2 != IP4_ERROR_OPTIONS ?
188 if (error3 == IP4_ERROR_TIME_EXPIRED)
191 ICMP4_time_exceeded_ttl_exceeded_in_transit,
196 next[3] = error3 != IP4_ERROR_OPTIONS ?
207 u32 * next0,
u32 * next1,
int verify_checksum)
210 u32 ip_len0, cur_len0;
211 u32 ip_len1, cur_len1;
212 i32 len_diff0, len_diff1;
214 error0 = error1 = IP4_ERROR_NONE;
220 error0 = IP4_ERROR_TIME_EXPIRED;
222 error1 = IP4_ERROR_TIME_EXPIRED;
226 IP4_ERROR_FRAGMENT_OFFSET_ONE : error0;
228 IP4_ERROR_FRAGMENT_OFFSET_ONE : error1;
231 ip_len0 = clib_net_to_host_u16 (ip0->
length);
232 ip_len1 = clib_net_to_host_u16 (ip1->
length);
235 error0 = ip_len0 <
sizeof (ip0[0]) ? IP4_ERROR_TOO_SHORT : error0;
236 error1 = ip_len1 <
sizeof (ip1[0]) ? IP4_ERROR_TOO_SHORT : error1;
241 len_diff0 = cur_len0 - ip_len0;
242 len_diff1 = cur_len1 - ip_len1;
244 error0 = len_diff0 < 0 ? IP4_ERROR_BAD_LENGTH : error0;
245 error1 = len_diff1 < 0 ? IP4_ERROR_BAD_LENGTH : error1;
249 if (error0 == IP4_ERROR_TIME_EXPIRED)
252 ICMP4_time_exceeded_ttl_exceeded_in_transit,
257 *next0 = error0 != IP4_ERROR_OPTIONS ?
263 if (error1 == IP4_ERROR_TIME_EXPIRED)
266 ICMP4_time_exceeded_ttl_exceeded_in_transit,
271 *next1 = error1 != IP4_ERROR_OPTIONS ?
283 u32 ip_len0, cur_len0;
287 error0 = IP4_ERROR_NONE;
292 error0 = IP4_ERROR_TIME_EXPIRED;
296 IP4_ERROR_FRAGMENT_OFFSET_ONE : error0;
299 ip_len0 = clib_net_to_host_u16 (ip0->
length);
302 error0 = ip_len0 <
sizeof (ip0[0]) ? IP4_ERROR_TOO_SHORT : error0;
306 len_diff0 = cur_len0 - ip_len0;
308 error0 = len_diff0 < 0 ? IP4_ERROR_BAD_LENGTH : error0;
312 if (error0 == IP4_ERROR_TIME_EXPIRED)
315 ICMP4_time_exceeded_ttl_exceeded_in_transit,
320 *next0 = error0 != IP4_ERROR_OPTIONS ?