37 #if defined (PACKET_ASSEMBLY) || defined (PACKET_DECODING)
53 log_debug (
"checksum (%x %d %x)", buf, nbytes, sum);
57 for (i = 0; i < (nbytes & ~1U); i += 2) {
58 #ifdef DEBUG_CHECKSUM_VERBOSE
61 sum += (u_int16_t) ntohs(*((u_int16_t *)(buf + i)));
70 #ifdef DEBUG_CHECKSUM_VERBOSE
92 #ifdef DEBUG_CHECKSUM_VERBOSE
97 log_debug (
"wrapsum returns %x", htons (sum));
102 #ifdef PACKET_ASSEMBLY
109 switch (interface->hw_address.hbuf[0]) {
110 #if defined(HAVE_TR_SUPPORT)
115 #if defined (DEC_FDDI)
117 assemble_fddi_header(interface, buf, bufix, to);
121 log_error(
"Attempt to assemble hw header for infiniband");
133 from, to, port, data, len)
146 memset (&
ip, 0,
sizeof ip);
152 ip.
ip_len = htons(
sizeof(
ip) +
sizeof(udp) + len);
158 ip.ip_src.s_addr = from;
165 memcpy (&buf [*bufix], &
ip,
sizeof ip);
171 udp.uh_ulen = htons(
sizeof(udp) + len);
172 memset (&udp.uh_sum, 0,
sizeof udp.uh_sum);
182 2 *
sizeof ip.ip_src,
185 ntohs (udp.uh_ulen)))));
188 memcpy (&buf [*bufix], &udp,
sizeof udp);
189 *bufix +=
sizeof udp;
193 #ifdef PACKET_DECODING
205 switch(interface->hw_address.hbuf[0]) {
206 #if defined (HAVE_TR_SUPPORT)
210 #if defined (DEC_FDDI)
212 return (decode_fddi_header(interface, buf, bufix, from));
215 log_error(
"Attempt to decode hw header for infiniband");
227 unsigned char *buf,
unsigned bufix,
228 struct sockaddr_in *from,
unsigned buflen,
229 unsigned *rbuflen,
int csum_ready)
234 unsigned char *upp, *endbuf;
235 u_int32_t ip_len, ulen, pkt_len;
236 static unsigned int ip_packets_seen = 0;
237 static unsigned int ip_packets_bad_checksum = 0;
238 static unsigned int udp_packets_seen = 0;
239 static unsigned int udp_packets_bad_checksum = 0;
240 static unsigned int udp_packets_length_checked = 0;
241 static unsigned int udp_packets_length_overflow = 0;
245 endbuf = buf + bufix + buflen;
248 if ((buf + bufix +
sizeof(
ip)) > endbuf)
256 memcpy(&
ip, upp,
sizeof(
ip));
257 ip_len = (*upp & 0x0f) << 2;
262 if (pkt_len > buflen)
266 if ((upp +
sizeof(udp)) > endbuf)
270 memcpy(&udp, upp,
sizeof(udp));
272 #ifdef USERLAND_FILTER
274 if (
ip.
ip_p != IPPROTO_UDP)
282 ulen = ntohs(udp.uh_ulen);
283 if (ulen <
sizeof(udp))
286 udp_packets_length_checked++;
287 if ((upp + ulen) > endbuf) {
288 udp_packets_length_overflow++;
289 if (((udp_packets_length_checked > 4) &&
290 (udp_packets_length_overflow != 0)) &&
291 ((udp_packets_length_checked / udp_packets_length_overflow) < 2)) {
292 log_info(
"%u udp packets in %u too long - dropped",
293 udp_packets_length_overflow,
294 udp_packets_length_checked);
295 udp_packets_length_overflow = 0;
296 udp_packets_length_checked = 0;
302 if (udp_packets_length_checked > 4) {
303 udp_packets_length_overflow = 0;
304 udp_packets_length_checked = 0;
310 ++ip_packets_bad_checksum;
311 if (((ip_packets_seen > 4) && (ip_packets_bad_checksum != 0)) &&
312 ((ip_packets_seen / ip_packets_bad_checksum) < 2)) {
313 log_info (
"%u bad IP checksums seen in %u packets",
314 ip_packets_bad_checksum, ip_packets_seen);
315 ip_packets_seen = ip_packets_bad_checksum = 0;
321 if (ip_packets_seen > 4) {
322 ip_packets_bad_checksum = 0;
327 memcpy(&from->sin_addr, &
ip.ip_src, 4);
329 data = upp +
sizeof(udp);
330 len = ulen -
sizeof(udp);
335 if (udp.uh_sum && csum_ready) {
342 8, IPPROTO_UDP + ulen))))) {
343 udp_packets_bad_checksum++;
344 if (((udp_packets_seen > 4) && (udp_packets_bad_checksum != 0))
345 && ((udp_packets_seen / udp_packets_bad_checksum) < 2)) {
346 log_info (
"%u bad udp checksums in %u packets",
347 udp_packets_bad_checksum, udp_packets_seen);
348 udp_packets_seen = udp_packets_bad_checksum = 0;
356 if (udp_packets_seen > 4) {
357 udp_packets_bad_checksum = 0;
358 udp_packets_seen = 0;
362 memcpy (&from -> sin_port, &udp.uh_sport,
sizeof udp.uh_sport);
369 return ip_len +
sizeof udp;
void assemble_ethernet_header(struct interface_info *, unsigned char *, unsigned *, struct hardware *)
void assemble_udp_ip_header(struct interface_info *, unsigned char *, unsigned *, u_int32_t, u_int32_t, u_int32_t, unsigned char *, unsigned)
ssize_t decode_udp_ip_header(struct interface_info *, unsigned char *, unsigned, struct sockaddr_in *, unsigned, unsigned *, int)
ssize_t decode_tr_header(struct interface_info *, unsigned char *, unsigned, struct hardware *)
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
struct in_addr ip_src ip_dst
void assemble_tr_header(struct interface_info *, unsigned char *, unsigned *, struct hardware *)
int log_error(const char *,...) __attribute__((__format__(__printf__
u_int32_t wrapsum(u_int32_t sum)
void assemble_hw_header(struct interface_info *, unsigned char *, unsigned *, struct hardware *)
#define IP_HL_SET(iph, x)
int int log_info(const char *,...) __attribute__((__format__(__printf__
ssize_t decode_ethernet_header(struct interface_info *, unsigned char *, unsigned, struct hardware *)
ssize_t decode_hw_header(struct interface_info *, unsigned char *, unsigned, struct hardware *)
u_int32_t checksum(unsigned char *buf, unsigned nbytes, u_int32_t sum)