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#if defined(RELAY_PORT)
176 udp.uh_ulen = htons(
sizeof(udp) + len);
177 memset (&udp.uh_sum, 0,
sizeof udp.uh_sum);
187 2 *
sizeof ip.ip_src,
190 ntohs (udp.uh_ulen)))));
193 memcpy (&buf [*bufix], &udp,
sizeof udp);
194 *bufix +=
sizeof udp;
198#ifdef PACKET_DECODING
211#if defined (HAVE_TR_SUPPORT)
215#if defined (DEC_FDDI)
217 return (decode_fddi_header(interface, buf, bufix, from));
220 log_error(
"Attempt to decode hw header for infiniband");
253 unsigned char *buf,
unsigned bufix,
254 struct sockaddr_in *from,
unsigned buflen,
255 unsigned *rbuflen,
int csum_ready)
261 u_int32_t ip_len, ulen, pkt_len;
262 static unsigned int ip_packets_seen = 0;
263 static unsigned int ip_packets_bad_checksum = 0;
264 static unsigned int udp_packets_seen = 0;
265 static unsigned int udp_packets_bad_checksum = 0;
266 static unsigned int udp_packets_length_checked = 0;
267 static unsigned int udp_packets_length_overflow = 0;
271 if (
sizeof(
ip) > buflen)
279 memcpy(&
ip, upp,
sizeof(
ip));
280 ip_len = (*upp & 0x0f) << 2;
291 if ((ip_len > buflen) ||
292 (pkt_len > buflen) ||
293 ((ip_len +
sizeof(udp)) > buflen))
297 memcpy(&udp, upp,
sizeof(udp));
299#ifdef USERLAND_FILTER
301 if (
ip.
ip_p != IPPROTO_UDP)
305#if defined(RELAY_PORT)
314 ulen = ntohs(udp.uh_ulen);
315 if (ulen <
sizeof(udp))
318 udp_packets_length_checked++;
320 if ((ip_len + ulen) > buflen) {
321 udp_packets_length_overflow++;
322 if (((udp_packets_length_checked > 4) &&
323 (udp_packets_length_overflow != 0)) &&
324 ((udp_packets_length_checked / udp_packets_length_overflow) < 2)) {
325 log_info(
"%u udp packets in %u too long - dropped",
326 udp_packets_length_overflow,
327 udp_packets_length_checked);
328 udp_packets_length_overflow = 0;
329 udp_packets_length_checked = 0;
335 if (udp_packets_length_checked > 4) {
336 udp_packets_length_overflow = 0;
337 udp_packets_length_checked = 0;
343 ++ip_packets_bad_checksum;
344 if (((ip_packets_seen > 4) && (ip_packets_bad_checksum != 0)) &&
345 ((ip_packets_seen / ip_packets_bad_checksum) < 2)) {
346 log_info (
"%u bad IP checksums seen in %u packets",
347 ip_packets_bad_checksum, ip_packets_seen);
348 ip_packets_seen = ip_packets_bad_checksum = 0;
354 if (ip_packets_seen > 4) {
355 ip_packets_bad_checksum = 0;
360 memcpy(&from->sin_addr, &
ip.ip_src, 4);
362 data = upp +
sizeof(udp);
363 len = ulen -
sizeof(udp);
368 if (udp.uh_sum && csum_ready) {
375 8, IPPROTO_UDP + ulen))))) {
376 udp_packets_bad_checksum++;
377 if (((udp_packets_seen > 4) && (udp_packets_bad_checksum != 0))
378 && ((udp_packets_seen / udp_packets_bad_checksum) < 2)) {
379 log_debug (
"%u bad udp checksums in %u packets",
380 udp_packets_bad_checksum, udp_packets_seen);
381 udp_packets_seen = udp_packets_bad_checksum = 0;
389 if (udp_packets_seen > 4) {
390 udp_packets_bad_checksum = 0;
391 udp_packets_seen = 0;
395 memcpy (&from -> sin_port, &udp.uh_sport,
sizeof udp.uh_sport);
402 return ip_len +
sizeof udp;
ssize_t decode_ethernet_header(struct interface_info *, unsigned char *, unsigned, struct hardware *)
void assemble_hw_header(struct interface_info *, unsigned char *, unsigned *, struct hardware *)
ssize_t decode_udp_ip_header(struct interface_info *, unsigned char *, unsigned, struct sockaddr_in *, unsigned, unsigned *, int)
void assemble_udp_ip_header(struct interface_info *, unsigned char *, unsigned *, u_int32_t, u_int32_t, u_int32_t, unsigned char *, unsigned)
void assemble_tr_header(struct interface_info *, unsigned char *, unsigned *, struct hardware *)
void assemble_ethernet_header(struct interface_info *, unsigned char *, unsigned *, struct hardware *)
ssize_t decode_tr_header(struct interface_info *, unsigned char *, unsigned, struct hardware *)
ssize_t decode_hw_header(struct interface_info *, unsigned char *, unsigned, struct hardware *)
#define IP_HL_SET(iph, x)
int log_error(const char *,...) __attribute__((__format__(__printf__
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
int int log_info(const char *,...) __attribute__((__format__(__printf__
u_int32_t checksum(unsigned char *buf, unsigned nbytes, u_int32_t sum)
u_int32_t wrapsum(u_int32_t sum)
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
struct hardware hw_address
struct in_addr ip_src ip_dst