1 /* $NetBSD: print-tcp.c,v 1.9 2007/07/26 18:15:12 plunky Exp $ */
4 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
5 * The Regents of the University of California. All rights reserved.
7 * Copyright (c) 1999-2004 The tcpdump.org project
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that: (1) source code distributions
11 * retain the above copyright notice and this paragraph in its entirety, (2)
12 * distributions including binary code include the above copyright notice and
13 * this paragraph in its entirety in the documentation or other materials
14 * provided with the distribution, and (3) all advertising materials mentioning
15 * features or use of this software display the following acknowledgement:
16 * ``This product includes software developed by the University of California,
17 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
18 * the University nor the names of its contributors may be used to endorse
19 * or promote products derived from this software without specific prior
21 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
28 __RCSID("$NetBSD: print-tcp.c,v 1.8 2007/07/24 11:53:48 drochner Exp $");
35 #include <tcpdump-stdinc.h>
40 #include "interface.h"
41 #include "addrtoname.h"
57 #include <openssl/md5.h>
58 #include <signature.h>
60 static int tcp_verify_signature(netdissect_options
*ndo
,
61 const struct ip
*ip
, const struct tcphdr
*tp
,
62 const u_char
*data
, int length
, const u_char
*rcvsig
);
65 static void print_tcp_rst_data(netdissect_options
*, register const u_char
*sp
, u_int length
);
67 #define MAX_RST_DATA_LEN 30
77 struct tcp_seq_hash
*nxt
;
90 struct tcp_seq_hash6
{
91 struct tcp_seq_hash6
*nxt
;
98 #define TSEQ_HASHSIZE 919
100 /* These tcp optinos do not have the size octet */
101 #define ZEROLENOPT(o) ((o) == TCPOPT_EOL || (o) == TCPOPT_NOP)
103 static struct tcp_seq_hash tcp_seq_hash4
[TSEQ_HASHSIZE
];
105 static struct tcp_seq_hash6 tcp_seq_hash6
[TSEQ_HASHSIZE
];
108 static const struct tok tcp_flag_values
[] = {
120 static const struct tok tcp_option_values
[] = {
121 { TCPOPT_EOL
, "eol" },
122 { TCPOPT_NOP
, "nop" },
123 { TCPOPT_MAXSEG
, "mss" },
124 { TCPOPT_WSCALE
, "wscale" },
125 { TCPOPT_SACKOK
, "sackOK" },
126 { TCPOPT_SACK
, "sack" },
127 { TCPOPT_ECHO
, "echo" },
128 { TCPOPT_ECHOREPLY
, "echoreply" },
129 { TCPOPT_TIMESTAMP
, "TS" },
131 { TCPOPT_CCNEW
, "ccnew" },
132 { TCPOPT_CCECHO
, "" },
133 { TCPOPT_SIGNATURE
, "md5" },
134 { TCPOPT_AUTH
, "enhanced auth" },
135 { TCPOPT_UTO
, "uto" },
136 { TCPOPT_MPTCP
, "mptcp" },
137 { TCPOPT_EXPERIMENT2
, "exp" },
142 tcp_cksum(netdissect_options
*ndo
,
143 register const struct ip
*ip
,
144 register const struct tcphdr
*tp
,
147 return nextproto4_cksum(ndo
, ip
, (const uint8_t *)tp
, len
, len
,
152 tcp_print(netdissect_options
*ndo
,
153 register const u_char
*bp
, register u_int length
,
154 register const u_char
*bp2
, int fragmented
)
156 register const struct tcphdr
*tp
;
157 register const struct ip
*ip
;
158 register u_char flags
;
161 uint16_t sport
, dport
, win
, urp
;
162 uint32_t seq
, ack
, thseq
, thack
;
167 register const struct ip6_hdr
*ip6
;
170 tp
= (struct tcphdr
*)bp
;
171 ip
= (struct ip
*)bp2
;
174 ip6
= (struct ip6_hdr
*)bp2
;
179 if (!ND_TTEST(tp
->th_dport
)) {
180 ND_PRINT((ndo
, "%s > %s: [|tcp]",
181 ipaddr_string(ndo
, &ip
->ip_src
),
182 ipaddr_string(ndo
, &ip
->ip_dst
)));
186 sport
= EXTRACT_16BITS(&tp
->th_sport
);
187 dport
= EXTRACT_16BITS(&tp
->th_dport
);
189 hlen
= TH_OFF(tp
) * 4;
193 if (ip6
->ip6_nxt
== IPPROTO_TCP
) {
194 ND_PRINT((ndo
, "%s.%s > %s.%s: ",
195 ip6addr_string(ndo
, &ip6
->ip6_src
),
196 tcpport_string(sport
),
197 ip6addr_string(ndo
, &ip6
->ip6_dst
),
198 tcpport_string(dport
)));
200 ND_PRINT((ndo
, "%s > %s: ",
201 tcpport_string(sport
), tcpport_string(dport
)));
206 if (ip
->ip_p
== IPPROTO_TCP
) {
207 ND_PRINT((ndo
, "%s.%s > %s.%s: ",
208 ipaddr_string(ndo
, &ip
->ip_src
),
209 tcpport_string(sport
),
210 ipaddr_string(ndo
, &ip
->ip_dst
),
211 tcpport_string(dport
)));
213 ND_PRINT((ndo
, "%s > %s: ",
214 tcpport_string(sport
), tcpport_string(dport
)));
218 if (hlen
< sizeof(*tp
)) {
219 ND_PRINT((ndo
, " tcp %d [bad hdr length %u - too short, < %lu]",
220 length
- hlen
, hlen
, (unsigned long)sizeof(*tp
)));
226 seq
= EXTRACT_32BITS(&tp
->th_seq
);
227 ack
= EXTRACT_32BITS(&tp
->th_ack
);
228 win
= EXTRACT_16BITS(&tp
->th_win
);
229 urp
= EXTRACT_16BITS(&tp
->th_urp
);
231 if (ndo
->ndo_qflag
) {
232 ND_PRINT((ndo
, "tcp %d", length
- hlen
));
234 ND_PRINT((ndo
, " [bad hdr length %u - too long, > %u]",
240 flags
= tp
->th_flags
;
241 ND_PRINT((ndo
, "Flags [%s]", bittok2str_nosep(tcp_flag_values
, "none", flags
)));
243 if (!ndo
->ndo_Sflag
&& (flags
& TH_ACK
)) {
245 * Find (or record) the initial sequence numbers for
246 * this conversation. (we pick an arbitrary
247 * collating order so there's only one entry for
253 register struct tcp_seq_hash6
*th
;
254 struct tcp_seq_hash6
*tcp_seq_hash
;
255 const struct in6_addr
*src
, *dst
;
258 tcp_seq_hash
= tcp_seq_hash6
;
263 else if (sport
== dport
) {
264 if (UNALIGNED_MEMCMP(src
, dst
, sizeof ip6
->ip6_dst
) > 0)
268 UNALIGNED_MEMCPY(&tha
.src
, dst
, sizeof ip6
->ip6_dst
);
269 UNALIGNED_MEMCPY(&tha
.dst
, src
, sizeof ip6
->ip6_src
);
270 tha
.port
= dport
<< 16 | sport
;
272 UNALIGNED_MEMCPY(&tha
.dst
, dst
, sizeof ip6
->ip6_dst
);
273 UNALIGNED_MEMCPY(&tha
.src
, src
, sizeof ip6
->ip6_src
);
274 tha
.port
= sport
<< 16 | dport
;
277 for (th
= &tcp_seq_hash
[tha
.port
% TSEQ_HASHSIZE
];
278 th
->nxt
; th
= th
->nxt
)
279 if (memcmp((char *)&tha
, (char *)&th
->addr
,
280 sizeof(th
->addr
)) == 0)
283 if (!th
->nxt
|| (flags
& TH_SYN
)) {
284 /* didn't find it or new conversation */
285 if (th
->nxt
== NULL
) {
286 th
->nxt
= (struct tcp_seq_hash6
*)
287 calloc(1, sizeof(*th
));
289 error("tcp_print: calloc");
293 th
->ack
= seq
, th
->seq
= ack
- 1;
295 th
->seq
= seq
, th
->ack
= ack
- 1;
298 seq
-= th
->ack
, ack
-= th
->seq
;
300 seq
-= th
->seq
, ack
-= th
->ack
;
309 register struct tcp_seq_hash
*th
;
310 struct tcp_seq_hash
*tcp_seq_hash
;
311 const struct in_addr
*src
, *dst
;
314 tcp_seq_hash
= tcp_seq_hash4
;
319 else if (sport
== dport
) {
320 if (UNALIGNED_MEMCMP(src
, dst
, sizeof ip
->ip_dst
) > 0)
324 UNALIGNED_MEMCPY(&tha
.src
, dst
, sizeof ip
->ip_dst
);
325 UNALIGNED_MEMCPY(&tha
.dst
, src
, sizeof ip
->ip_src
);
326 tha
.port
= dport
<< 16 | sport
;
328 UNALIGNED_MEMCPY(&tha
.dst
, dst
, sizeof ip
->ip_dst
);
329 UNALIGNED_MEMCPY(&tha
.src
, src
, sizeof ip
->ip_src
);
330 tha
.port
= sport
<< 16 | dport
;
333 for (th
= &tcp_seq_hash
[tha
.port
% TSEQ_HASHSIZE
];
334 th
->nxt
; th
= th
->nxt
)
335 if (memcmp((char *)&tha
, (char *)&th
->addr
,
336 sizeof(th
->addr
)) == 0)
339 if (!th
->nxt
|| (flags
& TH_SYN
)) {
340 /* didn't find it or new conversation */
341 if (th
->nxt
== NULL
) {
342 th
->nxt
= (struct tcp_seq_hash
*)
343 calloc(1, sizeof(*th
));
345 error("tcp_print: calloc");
349 th
->ack
= seq
, th
->seq
= ack
- 1;
351 th
->seq
= seq
, th
->ack
= ack
- 1;
354 seq
-= th
->ack
, ack
-= th
->seq
;
356 seq
-= th
->seq
, ack
-= th
->ack
;
364 thseq
= thack
= rev
= 0;
367 ND_PRINT((ndo
, " [bad hdr length %u - too long, > %u]",
372 if (ndo
->ndo_vflag
&& !ndo
->ndo_Kflag
&& !fragmented
) {
373 /* Check the checksum, if possible. */
374 uint16_t sum
, tcp_sum
;
377 if (ND_TTEST2(tp
->th_sport
, length
)) {
378 sum
= tcp_cksum(ndo
, ip
, tp
, length
);
379 tcp_sum
= EXTRACT_16BITS(&tp
->th_sum
);
381 ND_PRINT((ndo
, ", cksum 0x%04x", tcp_sum
));
383 ND_PRINT((ndo
, " (incorrect -> 0x%04x)",
384 in_cksum_shouldbe(tcp_sum
, sum
)));
386 ND_PRINT((ndo
, " (correct)"));
390 else if (IP_V(ip
) == 6 && ip6
->ip6_plen
) {
391 if (ND_TTEST2(tp
->th_sport
, length
)) {
392 sum
= nextproto6_cksum(ip6
, (const uint8_t *)tp
,
393 length
, length
, IPPROTO_TCP
);
394 tcp_sum
= EXTRACT_16BITS(&tp
->th_sum
);
396 ND_PRINT((ndo
, ", cksum 0x%04x", tcp_sum
));
398 ND_PRINT((ndo
, " (incorrect -> 0x%04x)",
399 in_cksum_shouldbe(tcp_sum
, sum
)));
401 ND_PRINT((ndo
, " (correct)"));
409 if (ndo
->ndo_vflag
> 1 || length
> 0 || flags
& (TH_SYN
| TH_FIN
| TH_RST
)) {
410 ND_PRINT((ndo
, ", seq %u", seq
));
413 ND_PRINT((ndo
, ":%u", seq
+ length
));
417 if (flags
& TH_ACK
) {
418 ND_PRINT((ndo
, ", ack %u", ack
));
421 ND_PRINT((ndo
, ", win %d", win
));
424 ND_PRINT((ndo
, ", urg %d", urp
));
426 * Handle any options.
428 if (hlen
> sizeof(*tp
)) {
429 register const u_char
*cp
;
430 register u_int i
, opt
, datalen
;
434 cp
= (const u_char
*)tp
+ sizeof(*tp
);
435 ND_PRINT((ndo
, ", options ["));
438 ND_PRINT((ndo
, "%c", ch
));
445 len
= *cp
++; /* total including type, len */
446 if (len
< 2 || len
> hlen
)
448 --hlen
; /* account for length byte */
450 --hlen
; /* account for type byte */
453 /* Bail if "l" bytes of data are not left or were not captured */
454 #define LENCHECK(l) { if ((l) > hlen) goto bad; ND_TCHECK2(*cp, l); }
457 ND_PRINT((ndo
, "%s", tok2str(tcp_option_values
, "unknown-%u", opt
)));
464 ND_PRINT((ndo
, " %u", EXTRACT_16BITS(cp
)));
470 ND_PRINT((ndo
, " %u", *cp
));
475 if (datalen
% 8 != 0) {
476 ND_PRINT((ndo
, "malformed sack"));
480 ND_PRINT((ndo
, " %d ", datalen
/ 8));
481 for (i
= 0; i
< datalen
; i
+= 8) {
483 s
= EXTRACT_32BITS(cp
+ i
);
485 e
= EXTRACT_32BITS(cp
+ i
+ 4);
493 ND_PRINT((ndo
, "{%u:%u}", s
, e
));
502 case TCPOPT_ECHOREPLY
:
505 * those options share their semantics.
510 ND_PRINT((ndo
, " %u", EXTRACT_32BITS(cp
)));
513 case TCPOPT_TIMESTAMP
:
516 ND_PRINT((ndo
, " val %u ecr %u",
518 EXTRACT_32BITS(cp
+ 4)));
521 case TCPOPT_SIGNATURE
:
522 datalen
= TCP_SIGLEN
;
524 #ifdef HAVE_LIBCRYPTO
525 switch (tcp_verify_signature(ndo
, ip
, tp
,
526 bp
+ TH_OFF(tp
) * 4, length
, cp
)) {
528 case SIGNATURE_VALID
:
529 ND_PRINT((ndo
, "valid"));
532 case SIGNATURE_INVALID
:
533 ND_PRINT((ndo
, "invalid"));
536 case CANT_CHECK_SIGNATURE
:
537 ND_PRINT((ndo
, "can't check - "));
538 for (i
= 0; i
< TCP_SIGLEN
; ++i
)
539 ND_PRINT((ndo
, "%02x", cp
[i
]));
543 for (i
= 0; i
< TCP_SIGLEN
; ++i
)
544 ND_PRINT((ndo
, "%02x", cp
[i
]));
549 ND_PRINT((ndo
, "keyid %d", *cp
++));
551 for (i
= 0; i
< datalen
; ++i
) {
553 ND_PRINT((ndo
, "%02x", cp
[i
]));
562 * Nothing interesting.
570 utoval
= EXTRACT_16BITS(cp
);
571 ND_PRINT((ndo
, "0x%x", utoval
));
573 utoval
= (utoval
>> 1) * 60;
576 ND_PRINT((ndo
, " %u", utoval
));
582 if (!mptcp_print(ndo
, cp
-2, len
, flags
))
586 case TCPOPT_EXPERIMENT2
:
592 magic
= EXTRACT_16BITS(cp
);
593 ND_PRINT((ndo
, "-"));
598 /* TCP Fast Open: RFC 7413 */
600 /* Fast Open Cookie Request */
601 ND_PRINT((ndo
, "tfo cookiereq"));
603 /* Fast Open Cookie */
604 if (datalen
% 2 != 0 || datalen
< 6 || datalen
> 18) {
605 ND_PRINT((ndo
, "tfo malformed"));
607 ND_PRINT((ndo
, "tfo cookie "));
608 for (i
= 2; i
< datalen
; ++i
)
609 ND_PRINT((ndo
, "%02x", cp
[i
]));
615 /* Unknown magic number */
616 ND_PRINT((ndo
, "%04x", magic
));
624 ND_PRINT((ndo
, " 0x"));
625 for (i
= 0; i
< datalen
; ++i
) {
627 ND_PRINT((ndo
, "%02x", cp
[i
]));
632 /* Account for data printed */
636 /* Check specification against observed length */
637 ++datalen
; /* option octet */
638 if (!ZEROLENOPT(opt
))
639 ++datalen
; /* size octet */
641 ND_PRINT((ndo
, "[len %d]", len
));
643 if (opt
== TCPOPT_EOL
)
646 ND_PRINT((ndo
, "]"));
650 * Print length field before crawling down the stack.
652 ND_PRINT((ndo
, ", length %u", length
));
658 * Decode payload if necessary.
660 bp
+= TH_OFF(tp
) * 4;
661 if ((flags
& TH_RST
) && ndo
->ndo_vflag
) {
662 print_tcp_rst_data(ndo
, bp
, length
);
666 if (ndo
->ndo_packettype
) {
667 switch (ndo
->ndo_packettype
) {
669 zmtp1_print(ndo
, bp
, length
);
675 if (sport
== TELNET_PORT
|| dport
== TELNET_PORT
) {
676 telnet_print(ndo
, bp
, length
);
677 } else if (sport
== SMTP_PORT
|| dport
== SMTP_PORT
) {
678 ND_PRINT((ndo
, ": "));
679 smtp_print(ndo
, bp
, length
);
680 } else if (sport
== BGP_PORT
|| dport
== BGP_PORT
)
681 bgp_print(ndo
, bp
, length
);
682 else if (sport
== PPTP_PORT
|| dport
== PPTP_PORT
)
684 #ifdef TCPDUMP_DO_SMB
685 else if (sport
== NETBIOS_SSN_PORT
|| dport
== NETBIOS_SSN_PORT
)
686 nbt_tcp_print(ndo
, bp
, length
);
687 else if (sport
== SMB_PORT
|| dport
== SMB_PORT
)
688 smb_tcp_print(ndo
, bp
, length
);
690 else if (sport
== BEEP_PORT
|| dport
== BEEP_PORT
)
691 beep_print(ndo
, bp
, length
);
692 else if (sport
== OPENFLOW_PORT_OLD
|| dport
== OPENFLOW_PORT_OLD
||
693 sport
== OPENFLOW_PORT_IANA
|| dport
== OPENFLOW_PORT_IANA
)
694 openflow_print(ndo
, bp
, length
);
695 else if (sport
== FTP_PORT
|| dport
== FTP_PORT
) {
696 ND_PRINT((ndo
, ": "));
697 ftp_print(ndo
, bp
, length
);
698 } else if (sport
== HTTP_PORT
|| dport
== HTTP_PORT
||
699 sport
== HTTP_PORT_ALT
|| dport
== HTTP_PORT_ALT
) {
700 ND_PRINT((ndo
, ": "));
701 http_print(ndo
, bp
, length
);
702 } else if (sport
== RTSP_PORT
|| dport
== RTSP_PORT
||
703 sport
== RTSP_PORT_ALT
|| dport
== RTSP_PORT_ALT
) {
704 ND_PRINT((ndo
, ": "));
705 rtsp_print(ndo
, bp
, length
);
706 } else if (length
> 2 &&
707 (sport
== NAMESERVER_PORT
|| dport
== NAMESERVER_PORT
||
708 sport
== MULTICASTDNS_PORT
|| dport
== MULTICASTDNS_PORT
)) {
710 * TCP DNS query has 2byte length at the head.
711 * XXX packet could be unaligned, it can go strange
713 ns_print(ndo
, bp
+ 2, length
- 2, 0);
714 } else if (sport
== MSDP_PORT
|| dport
== MSDP_PORT
) {
715 msdp_print(ndo
, bp
, length
);
716 } else if (sport
== RPKI_RTR_PORT
|| dport
== RPKI_RTR_PORT
) {
717 rpki_rtr_print(ndo
, bp
, length
);
719 else if (length
> 0 && (sport
== LDP_PORT
|| dport
== LDP_PORT
)) {
720 ldp_print(ndo
, bp
, length
);
722 else if ((sport
== NFS_PORT
|| dport
== NFS_PORT
) &&
723 length
>= 4 && ND_TTEST2(*bp
, 4)) {
725 * If data present, header length valid, and NFS port used,
727 * Pass offset of data plus 4 bytes for RPC TCP msg length
728 * to NFS print routines.
731 register struct sunrpc_msg
*rp
;
732 enum sunrpc_msg_type direction
;
734 fraglen
= EXTRACT_32BITS(bp
) & 0x7FFFFFFF;
735 if (fraglen
> (length
) - 4)
736 fraglen
= (length
) - 4;
737 rp
= (struct sunrpc_msg
*)(bp
+ 4);
738 if (ND_TTEST(rp
->rm_direction
)) {
739 direction
= (enum sunrpc_msg_type
)EXTRACT_32BITS(&rp
->rm_direction
);
740 if (dport
== NFS_PORT
&& direction
== SUNRPC_CALL
) {
741 ND_PRINT((ndo
, ": NFS request xid %u ", EXTRACT_32BITS(&rp
->rm_xid
)));
742 nfsreq_print_noaddr(ndo
, (u_char
*)rp
, fraglen
, (u_char
*)ip
);
745 if (sport
== NFS_PORT
&& direction
== SUNRPC_REPLY
) {
746 ND_PRINT((ndo
, ": NFS reply xid %u ", EXTRACT_32BITS(&rp
->rm_xid
)));
747 nfsreply_print_noaddr(ndo
, (u_char
*)rp
, fraglen
, (u_char
*)ip
);
755 ND_PRINT((ndo
, "[bad opt]"));
757 ND_PRINT((ndo
, ">"));
760 ND_PRINT((ndo
, "[|tcp]"));
762 ND_PRINT((ndo
, ">"));
766 * RFC1122 says the following on data in RST segments:
768 * 4.2.2.12 RST Segment: RFC-793 Section 3.4
770 * A TCP SHOULD allow a received RST segment to include data.
773 * It has been suggested that a RST segment could contain
774 * ASCII text that encoded and explained the cause of the
775 * RST. No standard has yet been established for such
781 print_tcp_rst_data(netdissect_options
*ndo
,
782 register const u_char
*sp
, u_int length
)
786 ND_PRINT((ndo
, ND_TTEST2(*sp
, length
) ? " [RST" : " [!RST"));
787 if (length
> MAX_RST_DATA_LEN
) {
788 length
= MAX_RST_DATA_LEN
; /* can use -X for longer */
789 ND_PRINT((ndo
, "+")); /* indicate we truncate */
791 ND_PRINT((ndo
, " "));
792 while (length
-- && sp
<= ndo
->ndo_snapend
) {
796 ND_PRINT((ndo
, "]"));
799 #ifdef HAVE_LIBCRYPTO
800 USES_APPLE_DEPRECATED_API
802 tcp_verify_signature(netdissect_options
*ndo
,
803 const struct ip
*ip
, const struct tcphdr
*tp
,
804 const u_char
*data
, int length
, const u_char
*rcvsig
)
807 u_char sig
[TCP_SIGLEN
];
810 uint16_t savecsum
, tlen
;
817 if (data
+ length
> ndo
->ndo_snapend
) {
818 ND_PRINT((ndo
, "snaplen too short, "));
819 return (CANT_CHECK_SIGNATURE
);
824 if (ndo
->ndo_sigsecret
== NULL
) {
825 ND_PRINT((ndo
, "shared secret not supplied with -M, "));
826 return (CANT_CHECK_SIGNATURE
);
831 * Step 1: Update MD5 hash with IP pseudo-header.
834 MD5_Update(&ctx
, (char *)&ip
->ip_src
, sizeof(ip
->ip_src
));
835 MD5_Update(&ctx
, (char *)&ip
->ip_dst
, sizeof(ip
->ip_dst
));
836 MD5_Update(&ctx
, (char *)&zero_proto
, sizeof(zero_proto
));
837 MD5_Update(&ctx
, (char *)&ip
->ip_p
, sizeof(ip
->ip_p
));
838 tlen
= EXTRACT_16BITS(&ip
->ip_len
) - IP_HL(ip
) * 4;
840 MD5_Update(&ctx
, (char *)&tlen
, sizeof(tlen
));
842 } else if (IP_V(ip
) == 6) {
843 ip6
= (struct ip6_hdr
*)ip
;
844 MD5_Update(&ctx
, (char *)&ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
845 MD5_Update(&ctx
, (char *)&ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
846 len32
= htonl(EXTRACT_16BITS(&ip6
->ip6_plen
));
847 MD5_Update(&ctx
, (char *)&len32
, sizeof(len32
));
849 MD5_Update(&ctx
, (char *)&nxt
, sizeof(nxt
));
850 MD5_Update(&ctx
, (char *)&nxt
, sizeof(nxt
));
851 MD5_Update(&ctx
, (char *)&nxt
, sizeof(nxt
));
853 MD5_Update(&ctx
, (char *)&nxt
, sizeof(nxt
));
857 ND_PRINT((ndo
, "IP version not 4 or 6, "));
859 ND_PRINT((ndo
, "IP version not 4, "));
861 return (CANT_CHECK_SIGNATURE
);
865 * Step 2: Update MD5 hash with TCP header, excluding options.
866 * The TCP checksum must be set to zero.
868 savecsum
= tp1
.th_sum
;
870 MD5_Update(&ctx
, (char *)&tp1
, sizeof(struct tcphdr
));
871 tp1
.th_sum
= savecsum
;
873 * Step 3: Update MD5 hash with TCP segment data, if present.
876 MD5_Update(&ctx
, data
, length
);
878 * Step 4: Update MD5 hash with shared secret.
880 MD5_Update(&ctx
, ndo
->ndo_sigsecret
, strlen(ndo
->ndo_sigsecret
));
881 MD5_Final(sig
, &ctx
);
883 if (memcmp(rcvsig
, sig
, TCP_SIGLEN
) == 0)
884 return (SIGNATURE_VALID
);
886 return (SIGNATURE_INVALID
);
889 #endif /* HAVE_LIBCRYPTO */
893 * c-style: whitesmith