MCPcopy Create free account
hub / github.com/F-Stack/f-stack / IcmpAliasIn2

Function IcmpAliasIn2

freebsd/netinet/libalias/alias.c:333–432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331}
332
333static int
334IcmpAliasIn2(struct libalias *la, struct ip *pip)
335{
336
337 LIBALIAS_LOCK_ASSERT(la);
338/*
339 Alias incoming ICMP error messages containing
340 IP header and first 64 bits of datagram.
341*/
342 struct ip *ip;
343 struct icmp *ic, *ic2;
344 struct udphdr *ud;
345 struct tcphdr *tc;
346 struct alias_link *lnk;
347
348 ic = (struct icmp *)ip_next(pip);
349 ip = &ic->icmp_ip;
350
351 ud = (struct udphdr *)ip_next(ip);
352 tc = (struct tcphdr *)ip_next(ip);
353 ic2 = (struct icmp *)ip_next(ip);
354
355 if (ip->ip_p == IPPROTO_UDP)
356 lnk = FindUdpTcpIn(la, ip->ip_dst, ip->ip_src,
357 ud->uh_dport, ud->uh_sport,
358 IPPROTO_UDP, 0);
359 else if (ip->ip_p == IPPROTO_TCP)
360 lnk = FindUdpTcpIn(la, ip->ip_dst, ip->ip_src,
361 tc->th_dport, tc->th_sport,
362 IPPROTO_TCP, 0);
363 else if (ip->ip_p == IPPROTO_ICMP) {
364 if (ic2->icmp_type == ICMP_ECHO || ic2->icmp_type == ICMP_TSTAMP)
365 lnk = FindIcmpIn(la, ip->ip_dst, ip->ip_src, ic2->icmp_id, 0);
366 else
367 lnk = NULL;
368 } else
369 lnk = NULL;
370
371 if (lnk != NULL) {
372 if (ip->ip_p == IPPROTO_UDP || ip->ip_p == IPPROTO_TCP) {
373 int accumulate, accumulate2;
374 struct in_addr original_address;
375 u_short original_port;
376
377 original_address = GetOriginalAddress(lnk);
378 original_port = GetOriginalPort(lnk);
379
380/* Adjust ICMP checksum */
381 accumulate = twowords(&ip->ip_src);
382 accumulate -= twowords(&original_address);
383 accumulate += ud->uh_sport;
384 accumulate -= original_port;
385 accumulate2 = accumulate;
386 accumulate2 += ip->ip_sum;
387 ADJUST_CHECKSUM(accumulate, ip->ip_sum);
388 accumulate2 -= ip->ip_sum;
389 ADJUST_CHECKSUM(accumulate2, ic->icmp_cksum);
390

Callers 1

IcmpAliasInFunction · 0.85

Calls 7

ip_nextFunction · 0.85
FindUdpTcpInFunction · 0.85
FindIcmpInFunction · 0.85
GetOriginalAddressFunction · 0.85
GetOriginalPortFunction · 0.85
twowordsFunction · 0.85
DifferentialChecksumFunction · 0.85

Tested by

no test coverage detected