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 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);
156 ip.
ip_p = IPPROTO_UDP;
158 ip.ip_src.s_addr = from;
165 memcpy (&buf [*bufix], &ip,
sizeof ip);
171 udp.
uh_ulen = htons(
sizeof(udp) + len);
182 2 *
sizeof ip.ip_src,
188 memcpy (&buf [*bufix], &udp,
sizeof udp);
189 *bufix +=
sizeof udp;
193 #ifdef PACKET_DECODING 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");
248 unsigned char *buf,
unsigned bufix,
249 struct sockaddr_in *from,
unsigned buflen,
250 unsigned *rbuflen,
int csum_ready)
256 u_int32_t ip_len, ulen, pkt_len;
257 static unsigned int ip_packets_seen = 0;
258 static unsigned int ip_packets_bad_checksum = 0;
259 static unsigned int udp_packets_seen = 0;
260 static unsigned int udp_packets_bad_checksum = 0;
261 static unsigned int udp_packets_length_checked = 0;
262 static unsigned int udp_packets_length_overflow = 0;
266 if (
sizeof(ip) > buflen)
274 memcpy(&ip, upp,
sizeof(ip));
275 ip_len = (*upp & 0x0f) << 2;
285 pkt_len = ntohs(ip.
ip_len);
286 if ((ip_len > buflen) ||
287 (pkt_len > buflen) ||
288 ((ip_len +
sizeof(udp)) > buflen))
292 memcpy(&udp, upp,
sizeof(udp));
294 #ifdef USERLAND_FILTER 296 if (ip.
ip_p != IPPROTO_UDP)
305 if (ulen <
sizeof(udp))
308 udp_packets_length_checked++;
310 if ((ip_len + ulen) > buflen) {
311 udp_packets_length_overflow++;
312 if (((udp_packets_length_checked > 4) &&
313 (udp_packets_length_overflow != 0)) &&
314 ((udp_packets_length_checked / udp_packets_length_overflow) < 2)) {
315 log_info(
"%u udp packets in %u too long - dropped",
316 udp_packets_length_overflow,
317 udp_packets_length_checked);
318 udp_packets_length_overflow = 0;
319 udp_packets_length_checked = 0;
325 if (udp_packets_length_checked > 4) {
326 udp_packets_length_overflow = 0;
327 udp_packets_length_checked = 0;
333 ++ip_packets_bad_checksum;
334 if (((ip_packets_seen > 4) && (ip_packets_bad_checksum != 0)) &&
335 ((ip_packets_seen / ip_packets_bad_checksum) < 2)) {
336 log_info (
"%u bad IP checksums seen in %u packets",
337 ip_packets_bad_checksum, ip_packets_seen);
338 ip_packets_seen = ip_packets_bad_checksum = 0;
344 if (ip_packets_seen > 4) {
345 ip_packets_bad_checksum = 0;
350 memcpy(&from->sin_addr, &ip.ip_src, 4);
352 data = upp +
sizeof(udp);
353 len = ulen -
sizeof(udp);
358 if (udp.
uh_sum && csum_ready) {
364 checksum((
unsigned char *)&ip.ip_src,
365 8, IPPROTO_UDP + ulen))))) {
366 udp_packets_bad_checksum++;
367 if (((udp_packets_seen > 4) && (udp_packets_bad_checksum != 0))
368 && ((udp_packets_seen / udp_packets_bad_checksum) < 2)) {
369 log_info (
"%u bad udp checksums in %u packets",
370 udp_packets_bad_checksum, udp_packets_seen);
371 udp_packets_seen = udp_packets_bad_checksum = 0;
379 if (udp_packets_seen > 4) {
380 udp_packets_bad_checksum = 0;
381 udp_packets_seen = 0;
392 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)