36 #if defined (PACKET_ASSEMBLY) || defined (PACKET_DECODING) 52 log_debug (
"checksum (%x %d %x)", (
unsigned)buf, nbytes, sum);
56 for (i = 0; i < (nbytes & ~1U); i += 2) {
57 #ifdef DEBUG_CHECKSUM_VERBOSE 60 sum += (u_int16_t) ntohs(*((u_int16_t *)(buf + i)));
69 #ifdef DEBUG_CHECKSUM_VERBOSE 91 #ifdef DEBUG_CHECKSUM_VERBOSE 96 log_debug (
"wrapsum returns %x", htons (sum));
101 #ifdef PACKET_ASSEMBLY 109 #if defined(HAVE_TR_SUPPORT) 114 #if defined (DEC_FDDI) 116 assemble_fddi_header(interface, buf, bufix, to);
120 log_error(
"Attempt to assemble hw header for infiniband");
132 from, to, port, data, len)
145 memset (&
ip, 0,
sizeof ip);
151 ip.
ip_len = htons(
sizeof(
ip) +
sizeof(udp) + len);
157 ip.ip_src.s_addr = from;
164 memcpy (&buf [*bufix], &
ip,
sizeof ip);
170 udp.uh_ulen = htons(
sizeof(udp) + len);
171 memset (&udp.uh_sum, 0,
sizeof udp.uh_sum);
181 2 *
sizeof ip.ip_src,
184 ntohs (udp.uh_ulen)))));
187 memcpy (&buf [*bufix], &udp,
sizeof udp);
188 *bufix +=
sizeof udp;
192 #ifdef PACKET_DECODING 205 #if defined (HAVE_TR_SUPPORT) 209 #if defined (DEC_FDDI) 211 return (decode_fddi_header(interface, buf, bufix, from));
214 log_error(
"Attempt to decode hw header for infiniband");
247 unsigned char *buf,
unsigned bufix,
248 struct sockaddr_in *from,
unsigned buflen,
249 unsigned *rbuflen,
int csum_ready)
255 u_int32_t ip_len, ulen, pkt_len;
256 static unsigned int ip_packets_seen = 0;
257 static unsigned int ip_packets_bad_checksum = 0;
258 static unsigned int udp_packets_seen = 0;
259 static unsigned int udp_packets_bad_checksum = 0;
260 static unsigned int udp_packets_length_checked = 0;
261 static unsigned int udp_packets_length_overflow = 0;
265 if (
sizeof(
ip) > buflen)
273 memcpy(&
ip, upp,
sizeof(
ip));
274 ip_len = (*upp & 0x0f) << 2;
285 if ((ip_len > buflen) ||
286 (pkt_len > buflen) ||
287 ((ip_len +
sizeof(udp)) > buflen))
291 memcpy(&udp, upp,
sizeof(udp));
293 #ifdef USERLAND_FILTER 295 if (
ip.
ip_p != IPPROTO_UDP)
303 ulen = ntohs(udp.uh_ulen);
304 if (ulen <
sizeof(udp))
307 udp_packets_length_checked++;
309 if ((ip_len + ulen) > buflen) {
310 udp_packets_length_overflow++;
311 if (((udp_packets_length_checked > 4) &&
312 (udp_packets_length_overflow != 0)) &&
313 ((udp_packets_length_checked / udp_packets_length_overflow) < 2)) {
314 log_info(
"%u udp packets in %u too long - dropped",
315 udp_packets_length_overflow,
316 udp_packets_length_checked);
317 udp_packets_length_overflow = 0;
318 udp_packets_length_checked = 0;
324 if (udp_packets_length_checked > 4) {
325 udp_packets_length_overflow = 0;
326 udp_packets_length_checked = 0;
332 ++ip_packets_bad_checksum;
333 if (((ip_packets_seen > 4) && (ip_packets_bad_checksum != 0)) &&
334 ((ip_packets_seen / ip_packets_bad_checksum) < 2)) {
335 log_info (
"%u bad IP checksums seen in %u packets",
336 ip_packets_bad_checksum, ip_packets_seen);
337 ip_packets_seen = ip_packets_bad_checksum = 0;
343 if (ip_packets_seen > 4) {
344 ip_packets_bad_checksum = 0;
349 memcpy(&from->sin_addr, &
ip.ip_src, 4);
351 data = upp +
sizeof(udp);
352 len = ulen -
sizeof(udp);
357 if (udp.uh_sum && csum_ready) {
364 8, IPPROTO_UDP + ulen))))) {
365 udp_packets_bad_checksum++;
366 if (((udp_packets_seen > 4) && (udp_packets_bad_checksum != 0))
367 && ((udp_packets_seen / udp_packets_bad_checksum) < 2)) {
368 log_debug (
"%u bad udp checksums in %u packets",
369 udp_packets_bad_checksum, udp_packets_seen);
370 udp_packets_seen = udp_packets_bad_checksum = 0;
378 if (udp_packets_seen > 4) {
379 udp_packets_bad_checksum = 0;
380 udp_packets_seen = 0;
384 memcpy (&from -> sin_port, &udp.uh_sport,
sizeof udp.uh_sport);
391 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)
struct hardware hw_address
int int log_info(const char *,...) __attribute__((__format__(__printf__
ssize_t decode_ethernet_header(struct interface_info *, unsigned char *, unsigned, struct hardware *)
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
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)