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 nocsum)
234 unsigned char *upp, *endbuf;
235 u_int32_t ip_len, ulen, pkt_len;
237 static int ip_packets_seen;
238 static int ip_packets_bad_checksum;
239 static int udp_packets_seen;
240 static int udp_packets_bad_checksum;
241 static int udp_packets_length_checked;
242 static int udp_packets_length_overflow;
246 endbuf = buf + bufix + buflen;
249 if ((buf + bufix +
sizeof(
ip)) > endbuf)
257 memcpy(&
ip, upp,
sizeof(
ip));
258 ip_len = (*upp & 0x0f) << 2;
263 if (pkt_len > buflen)
267 if ((upp +
sizeof(udp)) > endbuf)
271 memcpy(&udp, upp,
sizeof(udp));
273 #ifdef USERLAND_FILTER
275 if (
ip.
ip_p != IPPROTO_UDP)
283 ulen = ntohs(udp.uh_ulen);
284 if (ulen <
sizeof(udp))
287 udp_packets_length_checked++;
288 if ((upp + ulen) > endbuf) {
289 udp_packets_length_overflow++;
290 if ((udp_packets_length_checked > 4) &&
291 ((udp_packets_length_checked /
292 udp_packets_length_overflow) < 2)) {
293 log_info(
"%d udp packets in %d too long - dropped",
294 udp_packets_length_overflow,
295 udp_packets_length_checked);
296 udp_packets_length_overflow = 0;
297 udp_packets_length_checked = 0;
302 if ((ulen <
sizeof(udp)) || ((upp + ulen) > endbuf))
308 ++ip_packets_bad_checksum;
309 if (ip_packets_seen > 4 &&
310 (ip_packets_seen / ip_packets_bad_checksum) < 2) {
311 log_info (
"%d bad IP checksums seen in %d packets",
312 ip_packets_bad_checksum, ip_packets_seen);
313 ip_packets_seen = ip_packets_bad_checksum = 0;
319 memcpy(&from->sin_addr, &
ip.ip_src, 4);
325 data = upp +
sizeof(udp);
326 len = ulen -
sizeof(udp);
329 if (usum == 0xffff) usum = 0;
338 8, IPPROTO_UDP + ulen))));
341 if (!nocsum && usum && usum != sum) {
342 udp_packets_bad_checksum++;
343 if (udp_packets_seen > 4 &&
344 (udp_packets_seen / udp_packets_bad_checksum) < 2) {
345 log_info (
"%d bad udp checksums in %d packets",
346 udp_packets_bad_checksum, udp_packets_seen);
347 udp_packets_seen = udp_packets_bad_checksum = 0;
353 memcpy (&from -> sin_port, &udp.uh_sport,
sizeof udp.uh_sport);
360 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)