2 * Routines for Van Jacobson header decompression. (See RFC 1144.)
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
9 * This file created by Irfan Khan <ikhan@qualcomm.com>
10 * Copyright (c) 2001 by QUALCOMM, Incorporated.
11 * All Rights reserved.
13 * Routines to compress and uncompress TCP packets (for transmission
14 * over low speed serial lines).
16 * Copyright (c) 1989 Regents of the University of California.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that the above copyright notice and this paragraph are
21 * duplicated in all such forms and that any documentation,
22 * advertising materials, and other materials related to such
23 * distribution and use acknowledge that the software was developed
24 * by the University of California, Berkeley. The name of the
25 * University may not be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
28 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
29 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
31 * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
32 * - Initial distribution.
35 * modified for KA9Q Internet Software Package by
36 * Katie Stevens (dkstevens@ucdavis.edu)
37 * University of California, Davis
39 * - 01-31-90 initial adaptation (from 1.19)
40 * PPP.05 02-15-90 [ks]
41 * PPP.08 05-02-90 [ks] use PPP protocol field to signal compression
42 * PPP.15 09-90 [ks] improve mbuf handling
43 * PPP.16 11-02 [karn] substantially rewritten to use NOS facilities
45 * - Feb 1991 Bill_Simpson@um.cc.umich.edu
46 * variable number of conversation slots
47 * allow zero or one slots
50 * - Jul 1994 Dmitry Gorodchanin
51 * Fixes for memory leaks.
52 * - Oct 1994 Dmitry Gorodchanin
54 * - Jan 1995 Bjorn Ekwall
55 * Use ip_fast_csum from ip.h
56 * - July 1995 Christos A. Polyzols
57 * Spotted bug in tcp option checking
58 * - Sep 2001 Irfan Khan
59 * Rewrite to make the code work for wireshark.
68 #include <epan/packet.h>
69 #include <epan/prefs.h>
70 #include "packet-ppp.h"
71 #include <epan/ppptypes.h>
72 #include <epan/ipproto.h>
73 #include <epan/in_cksum.h>
74 #include <epan/emem.h>
76 /* Define relevant IP/TCP parameters */
77 #define IP_FIELD_TOT_LEN 2 /* Total length field in IP hdr */
78 #define IP_FIELD_PROTOCOL 9 /* Protocol field byte in IP hdr */
79 #define IP_ADDR_SIZE 4 /* Size in bytes of IPv4 address */
80 #define IP_FIELD_SRC 12 /* Byte 12 in IP hdr - src address */
81 #define IP_FIELD_DST 16 /* Byte 16 in IP hdr - dst address */
82 #define IP_HDR_LEN 20 /* Minimum IP header length */
83 #define IP_HDR_LEN_MASK 0x0f /* Mask for header length field */
84 #define IP_MAX_OPT_LEN 44 /* Max length of IP options */
85 #define TCP_FIELD_HDR_LEN 12 /* Data offset field in TCP hdr */
86 #define TCP_HDR_LEN 20 /* Minimum TCP header length */
87 #define TCP_MAX_OPT_LEN 44 /* Max length of TCP options */
88 #define TCP_SIMUL_CONV_MAX 256 /* Max number of simul. TCP conversations */
89 #define TCP_PUSH_BIT 0x08 /* TCP push bit */
90 #define TCP_URG_BIT 0x20 /* TCP urgent bit */
92 /* Bits in first octet of compressed packet */
93 /* flag bits for what changed in a packet */
94 #define NEW_C 0x40 /* Connection number changed */
95 #define NEW_I 0x20 /* IP sequence number change by value != 1 */
96 #define CHANGE_PUSH_BIT 0x10 /* TCP push bit set */
97 #define NEW_S 0x08 /* Sequence number changed */
98 #define NEW_A 0x04 /* Ack sequence number changed */
99 #define NEW_W 0x02 /* Window changed */
100 #define NEW_U 0x01 /* Urgent pointer present */
102 /* reserved, special-case values of above */
103 #define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */
104 #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)/* unidirectional data */
105 #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
107 /* Function return values */
114 /* VJ Mem Chunk defines */
115 #define VJ_DATA_SIZE 128 /* Max IP hdr(64)+Max TCP hdr(64) */
117 /* IP and TCP header types */
143 #define TCP_OFFSET(th) (((th)->off_x2 & 0xf0) >> 4)
145 /* State per active tcp conversation */
146 typedef struct cstate {
149 guint8 cs_ipopt[IP_MAX_OPT_LEN];
150 guint8 cs_tcpopt[TCP_MAX_OPT_LEN];
152 #define SLF_TOSS 0x00000001 /* tossing rcvd frames until id received */
155 /* All the state data for one serial line */
157 cstate rstate[TCP_SIMUL_CONV_MAX]; /* receive connection states (array) */
158 guint8 recv_current; /* most recent rcvd id */
161 /* Initialize the protocol and registered fields */
162 static int proto_vj = -1;
164 static int hf_vj_change_mask = -1;
165 static int hf_vj_change_mask_c = -1;
166 static int hf_vj_change_mask_i = -1;
167 static int hf_vj_change_mask_p = -1;
168 static int hf_vj_change_mask_s = -1;
169 static int hf_vj_change_mask_a = -1;
170 static int hf_vj_change_mask_w = -1;
171 static int hf_vj_change_mask_u = -1;
172 static int hf_vj_connection_number = -1;
173 static int hf_vj_tcp_cksum = -1;
174 static int hf_vj_urp = -1;
175 static int hf_vj_win_delta = -1;
176 static int hf_vj_ack_delta = -1;
177 static int hf_vj_seq_delta = -1;
178 static int hf_vj_ip_id_delta = -1;
180 static gint ett_vj = -1;
181 static gint ett_vj_changes = -1;
183 /* Protocol handles */
184 static dissector_handle_t ip_handle;
185 static dissector_handle_t data_handle;
187 /* State repository (Full Duplex) */
188 #define RX_TX_STATE_COUNT 2
189 static slcompress *rx_tx_state[RX_TX_STATE_COUNT] = {NULL, NULL};
191 /* Mem Chunks for storing decompressed headers */
193 int offset; /* uppermost bit is "can't dissect" flag */
194 guint8 data[VJ_DATA_SIZE];
197 /* Function prototypes */
198 static int get_unsigned_delta(tvbuff_t *tvb, int *offsetp, int hf,
200 static int get_signed_delta(tvbuff_t *tvb, int *offsetp, int hf,
202 static guint16 ip_csum(const guint8 *ptr, guint32 len);
203 static slcompress *slhc_init(void);
204 static gint vjc_process(tvbuff_t *src_tvb, packet_info *pinfo, proto_tree *tree,
206 static gint vjc_tvb_setup(tvbuff_t *src_tvb, tvbuff_t **dst_tvb,
209 /* Dissector for VJ Uncompressed packets */
211 dissect_vjuc(tvbuff_t *tvb, packet_info *pinfo, proto_tree * tree)
214 proto_tree *vj_tree = NULL;
223 gint isize = tvb_length(tvb);
226 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PPP VJ");
229 ti = proto_tree_add_protocol_format(tree, proto_vj, tvb, 0, -1,
230 "PPP VJ Compression: Uncompressed data");
231 vj_tree = proto_item_add_subtree(ti, ett_vj);
234 if(pinfo->p2p_dir == P2P_DIR_UNKNOWN) {
235 /* Direction of the traffic unknown - can't update state */
238 /* Get state for that direction */
239 comp = rx_tx_state[pinfo->p2p_dir];
243 * Check to make sure we can fetch the connection index.
245 if(!tvb_bytes_exist(tvb, IP_FIELD_PROTOCOL, 1)) {
247 * We don't. We can't even mark a connection as non-decompressable,
248 * as we don't know which connection this is. Mark them all as
249 * non-decompressable.
251 col_set_str(pinfo->cinfo, COL_INFO, "VJ uncompressed TCP (not enough data available)");
253 call_dissector(data_handle, tvb, pinfo, tree);
255 for(i = 0; i < TCP_SIMUL_CONV_MAX; i++)
256 comp->rstate[i].flags |= SLF_TOSS;
261 /* Get connection index */
262 conn_index = tvb_get_guint8(tvb, IP_FIELD_PROTOCOL);
264 proto_tree_add_uint(vj_tree, hf_vj_connection_number, tvb,
265 IP_FIELD_PROTOCOL, 1, conn_index);
268 * Update the current connection, and get a pointer to its state.
271 comp->recv_current = conn_index;
272 cs = &comp->rstate[conn_index];
275 /* Get the IP header length */
276 ihl = tvb_get_guint8(tvb, 0) & IP_HDR_LEN_MASK;
279 /* Check IP header length */
280 if(ihl < IP_HDR_LEN) {
281 if(check_col(pinfo->cinfo, COL_INFO)) {
282 col_add_fstr(pinfo->cinfo, COL_INFO, "VJ uncompressed TCP (IP header length (%u) < %u)",
286 cs->flags |= SLF_TOSS;
290 /* Make sure we have the full IP header */
292 col_set_str(pinfo->cinfo, COL_INFO, "VJ uncompressed TCP (not enough data available)");
294 call_dissector(data_handle, tvb, pinfo, tree);
296 cs->flags |= SLF_TOSS;
300 col_set_str(pinfo->cinfo, COL_INFO, "VJ uncompressed TCP");
303 * Copy packet data to a buffer, and replace the connection index with
304 * the protocol type (which is always TCP), to give the actual IP header.
306 buffer = tvb_memdup(tvb, 0, isize);
307 buffer[IP_FIELD_PROTOCOL] = IP_PROTO_TCP;
309 /* Check IP checksum */
310 if(ip_csum(buffer, ihl) != ZERO) {
312 * Checksum invalid - don't update state, and don't decompress
313 * any subsequent compressed packets in this direction.
316 cs->flags |= SLF_TOSS;
317 cs = NULL; /* disable state updates */
319 /* Do we have the TCP header length in the tvbuff? */
320 if(!tvb_bytes_exist(tvb, ihl + TCP_FIELD_HDR_LEN, 1)) {
321 /* We don't, so we can't provide enough data for decompression */
322 col_set_str(pinfo->cinfo, COL_INFO, "VJ uncompressed TCP (not enough data available)");
324 cs->flags |= SLF_TOSS;
325 cs = NULL; /* disable state updates */
327 /* Get the TCP header length */
328 thl = tvb_get_guint8(tvb, ihl + TCP_FIELD_HDR_LEN);
329 thl = ((thl & 0xf0) >> 4) * 4;
331 /* Check TCP header length */
332 if(thl < TCP_HDR_LEN) {
333 if(check_col(pinfo->cinfo, COL_INFO)) {
334 col_add_fstr(pinfo->cinfo, COL_INFO, "VJ uncompressed TCP (TCP header length (%u) < %u)",
338 cs->flags |= SLF_TOSS;
339 cs = NULL; /* disable state updates */
341 /* Make sure we have the full TCP header */
343 col_set_str(pinfo->cinfo, COL_INFO, "VJ uncompressed TCP (not enough data available)");
345 cs->flags |= SLF_TOSS;
346 cs = NULL; /* disable state updates */
353 * If packet seen for first time, update state if we have state and can
356 if(!pinfo->fd->flags.visited) {
358 cs->flags &= ~SLF_TOSS;
359 memcpy(&cs->cs_ip, &buffer[0], IP_HDR_LEN);
360 memcpy(&cs->cs_tcp, &buffer[ihl], TCP_HDR_LEN);
362 memcpy(cs->cs_ipopt, &buffer[sizeof(iphdr_type)], ihl - IP_HDR_LEN);
363 if(TCP_OFFSET(&(cs->cs_tcp)) > 5)
364 memcpy(cs->cs_tcpopt, &buffer[ihl + sizeof(tcphdr_type)],
365 (TCP_OFFSET(&(cs->cs_tcp)) - 5) * 4);
370 * Set up tvbuff containing packet with protocol type.
371 * Neither header checksum is recalculated.
373 * Use the length field from the IP header as the reported length;
374 * use the minimum of that and the number of bytes we got from
375 * the tvbuff as the actual length, just in case the tvbuff we were
376 * handed includes part or all of the FCS (because the FCS preference
377 * for the PPP dissector doesn't match the FCS size in this session).
379 ipsize = pntohs(&buffer[IP_FIELD_TOT_LEN]);
382 next_tvb = tvb_new_child_real_data(tvb, buffer, isize, ipsize);
383 tvb_set_free_cb(next_tvb, g_free);
384 add_new_data_source(pinfo, next_tvb, "VJ Uncompressed");
389 call_dissector(ip_handle, next_tvb, pinfo, tree);
392 /* Dissector for VJ Compressed packets */
394 dissect_vjc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
397 proto_tree *vj_tree = NULL;
398 tvbuff_t *next_tvb = NULL;
399 slcompress *comp = NULL;
402 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PPP VJ");
405 ti = proto_tree_add_protocol_format(tree, proto_vj, tvb, 0, -1,
406 "PPP VJ Compression: Compressed data");
407 vj_tree = proto_item_add_subtree(ti, ett_vj);
410 if(!ppp_vj_decomp || pinfo->p2p_dir == P2P_DIR_UNKNOWN) {
412 * VJ decompression turned off, so we shouldn't decompress, or
413 * direction of the traffic unknown, so we can't decompress.
417 /* Get state for that direction */
418 comp = rx_tx_state[pinfo->p2p_dir];
421 /* Process the compressed data header */
422 if(vjc_process(tvb, pinfo, vj_tree, comp) == VJ_ERROR)
425 /* Decompression possible - set up tvb containing decompressed packet */
426 err = vjc_tvb_setup(tvb, &next_tvb, pinfo);
427 if(err == VJ_ERROR) {
429 call_dissector(data_handle, tvb, pinfo, vj_tree);
433 /* No errors, so call IP dissector */
434 call_dissector(ip_handle, next_tvb, pinfo, tree);
437 /* Initialization function */
443 for(i = 0; i < RX_TX_STATE_COUNT; i++) {
444 rx_tx_state[i] = slhc_init();
449 /* Initialization routine for VJ decompression */
453 slcompress *comp = se_alloc0(sizeof(slcompress));
457 * Initialize the state; there is no current connection, and
458 * we have no header data for any of the connections, as we
459 * haven't yet seen an uncompressed frame.
461 comp->recv_current = TCP_SIMUL_CONV_MAX - 1;
462 for (i = 0; i < TCP_SIMUL_CONV_MAX; i++)
463 comp->rstate[i].flags |= SLF_TOSS;
467 /* Setup the decompressed packet tvb for VJ compressed packets */
469 vjc_tvb_setup(tvbuff_t *src_tvb,
473 vj_header_t *hdr_buf;
481 DISSECTOR_ASSERT(src_tvb);
483 /* Get decompressed header stored in fd protocol area */
484 hdr_buf = p_get_proto_data(pinfo->fd, proto_vj);
485 if(hdr_buf == NULL) {
486 col_set_str(pinfo->cinfo, COL_INFO, "VJ compressed TCP (previous data bad or missing)");
490 col_set_str(pinfo->cinfo, COL_INFO, "VJ compressed TCP");
492 /* Get the data offset in the tvbuff */
493 offset = hdr_buf->offset;
495 /* Copy header and form tvb */
496 data_ptr = hdr_buf->data;
497 hdr_len = lo_nibble(data_ptr[0]) * 4;
498 hdr_len += hi_nibble(data_ptr[hdr_len + 12]) * 4;
499 buf_len = tvb_length(src_tvb) + hdr_len - offset;
500 pbuf = g_malloc(buf_len);
501 memcpy(pbuf, data_ptr, hdr_len);
502 tvb_memcpy(src_tvb, pbuf + hdr_len, offset, buf_len - hdr_len);
503 memcpy(&tot_len, data_ptr + 2, 2);
504 *dst_tvb = tvb_new_child_real_data(src_tvb, pbuf, buf_len, g_ntohs(tot_len));
505 tvb_set_free_cb(*dst_tvb, g_free);
506 add_new_data_source(pinfo, *dst_tvb, "VJ Decompressed");
511 * For VJ compressed packet:
513 * check if it is malformed;
514 * dissect the relevant fields;
515 * update the decompressor state on the first pass.
518 vjc_process(tvbuff_t *src_tvb, packet_info *pinfo, proto_tree *tree,
525 proto_tree *changes_tree;
528 iphdr_type *ip = NULL;
529 tcphdr_type *thp = NULL;
535 vj_header_t *buf_hdr;
538 if(tvb_length(src_tvb) < 3){
540 * We don't even have enough data for the change byte, so we can't
541 * determine which connection this is; mark all connections as
542 * non-decompressible.
544 col_set_str(pinfo->cinfo, COL_INFO, "VJ compressed TCP (not enough data available)");
546 call_dissector(data_handle, src_tvb, pinfo, tree);
548 for(i = 0; i < TCP_SIMUL_CONV_MAX; i++)
549 comp->rstate[i].flags |= SLF_TOSS;
554 /* Read the change byte */
555 changes = tvb_get_guint8(src_tvb, offset);
557 switch (changes & SPECIALS_MASK) {
560 ti = proto_tree_add_uint_format(tree, hf_vj_change_mask, src_tvb,
562 "Change mask: 0x%02x (echoed interactive traffic)",
567 ti = proto_tree_add_uint_format(tree, hf_vj_change_mask, src_tvb,
569 "Change mask: 0x%02x (unidirectional data)",
575 * XXX - summarize bits?
577 ti = proto_tree_add_uint_format(tree, hf_vj_change_mask, src_tvb,
579 "Change mask: 0x%02x", changes);
582 changes_tree = proto_item_add_subtree(ti, ett_vj_changes);
583 proto_tree_add_boolean(changes_tree, hf_vj_change_mask_c, src_tvb,
585 proto_tree_add_boolean(changes_tree, hf_vj_change_mask_i, src_tvb,
587 proto_tree_add_boolean(changes_tree, hf_vj_change_mask_p, src_tvb,
589 proto_tree_add_boolean(changes_tree, hf_vj_change_mask_s, src_tvb,
591 proto_tree_add_boolean(changes_tree, hf_vj_change_mask_a, src_tvb,
593 proto_tree_add_boolean(changes_tree, hf_vj_change_mask_w, src_tvb,
595 proto_tree_add_boolean(changes_tree, hf_vj_change_mask_u, src_tvb,
600 if(changes & NEW_C){ /* Read conn index */
601 conn_index = tvb_get_guint8(src_tvb, offset);
603 proto_tree_add_uint(tree, hf_vj_connection_number, src_tvb, offset, 1,
607 comp->recv_current = conn_index;
610 if(!pinfo->fd->flags.visited) {
612 * This is the first time this frame has been seen, so we need
613 * state information to decompress it. If that information isn't
614 * available, don't use the state information, and don't update it,
617 if(comp != NULL && !(comp->rstate[comp->recv_current].flags & SLF_TOSS)) {
618 cs = &comp->rstate[comp->recv_current];
624 /* Build TCP and IP headers */
625 tcp_cksum = tvb_get_ntohs(src_tvb, offset);
627 proto_tree_add_uint(tree, hf_vj_tcp_cksum, src_tvb, offset, 2, tcp_cksum);
629 hdrlen = lo_nibble(ip->ihl_version) * 4 + TCP_OFFSET(thp) * 4;
630 thp->cksum = g_htons(tcp_cksum);
634 if(changes & CHANGE_PUSH_BIT)
635 thp->flags |= TCP_PUSH_BIT;
637 thp->flags &= ~TCP_PUSH_BIT;
640 /* Deal with special cases and normal deltas */
641 switch(changes & SPECIALS_MASK){
643 case SPECIAL_I: /* Echoed terminal traffic */
645 word = g_ntohs(ip->tot_len) - hdrlen;
646 tmp = g_ntohl(thp->ack_seq) + word;
647 thp->ack_seq = g_htonl(tmp);
648 tmp = g_ntohl(thp->seq) + word;
649 thp->seq = g_htonl(tmp);
652 case SPECIAL_D: /* Unidirectional data */
654 tmp = g_ntohl(thp->seq) + g_ntohs(ip->tot_len) - hdrlen;
655 thp->seq = g_htonl(tmp);
660 delta = get_unsigned_delta(src_tvb, &offset, hf_vj_urp, tree);
662 thp->urg_ptr = delta;
663 thp->flags |= TCP_URG_BIT;
667 thp->flags &= ~TCP_URG_BIT;
669 if(changes & NEW_W) {
670 delta = get_signed_delta(src_tvb, &offset, hf_vj_win_delta, tree);
672 tmp = g_ntohs(thp->window) + delta;
673 thp->window = g_htons(tmp);
676 if(changes & NEW_A) {
677 delta = get_unsigned_delta(src_tvb, &offset, hf_vj_ack_delta, tree);
679 tmp = g_ntohl(thp->ack_seq) + delta;
680 thp->ack_seq = g_htonl(tmp);
683 if(changes & NEW_S) {
684 delta = get_unsigned_delta(src_tvb, &offset, hf_vj_seq_delta, tree);
686 tmp = g_ntohl(thp->seq) + delta;
687 thp->seq = g_htonl(tmp);
693 delta = get_unsigned_delta(src_tvb, &offset, hf_vj_ip_id_delta, tree);
698 tmp = g_ntohs(ip->id) + delta;
699 ip->id = g_htons(tmp);
702 /* Compute IP packet length and the buffer length needed */
703 len = tvb_reported_length_remaining(src_tvb, offset);
706 * This shouldn't happen, as we *were* able to fetch stuff right before
709 col_set_str(pinfo->cinfo, COL_INFO, "VJ compressed TCP (not enough data available)");
711 cs->flags |= SLF_TOSS;
715 /* Show the TCP payload */
716 if(tree != NULL && tvb_offset_exists(src_tvb, offset))
717 proto_tree_add_text(tree, src_tvb, offset, -1, "TCP payload");
719 /* Nothing more to do if we don't have any compression state */
721 /* Direction of the traffic unknown - can't decompress */
722 col_set_str(pinfo->cinfo, COL_INFO, "VJ compressed TCP (direction unknown)");
726 if((cs != NULL) && (!pinfo->fd->flags.visited)) {
728 ip->tot_len = g_htons(len);
729 /* Compute IP check sum */
731 ip->cksum = ip_csum((guint8 *)ip, lo_nibble(ip->ihl_version) * 4);
733 /* Store the reconstructed header in frame data area */
734 buf_hdr = se_alloc(sizeof (vj_header_t));
735 buf_hdr->offset = offset; /* Offset in tvbuff is also stored */
736 data_ptr = buf_hdr->data;
737 memcpy(data_ptr, ip, IP_HDR_LEN);
738 data_ptr += IP_HDR_LEN;
739 if(lo_nibble(ip->ihl_version) > 5) {
740 memcpy(data_ptr, cs->cs_ipopt, (lo_nibble(ip->ihl_version) - 5) * 4);
741 data_ptr += (lo_nibble(ip->ihl_version) - 5) * 4;
743 memcpy(data_ptr, thp, TCP_HDR_LEN);
744 data_ptr += TCP_HDR_LEN;
745 if(TCP_OFFSET(thp) > 5)
746 memcpy(data_ptr, cs->cs_tcpopt, (TCP_OFFSET(thp) - 5) * 4);
747 p_add_proto_data(pinfo->fd, proto_vj, buf_hdr);
754 * Get an unsigned delta for a field, and put it into the protocol tree if
755 * we're building a protocol tree.
758 get_unsigned_delta(tvbuff_t *tvb, int *offsetp, int hf, proto_tree *tree)
760 int offset = *offsetp;
765 del = tvb_get_guint8(tvb, offset++);
767 del = tvb_get_ntohs(tvb, offset);
772 proto_tree_add_uint(tree, hf, tvb, *offsetp, len, del);
778 * Get a signed delta for a field, and put it into the protocol tree if
779 * we're building a protocol tree.
782 get_signed_delta(tvbuff_t *tvb, int *offsetp, int hf, proto_tree *tree)
784 int offset = *offsetp;
789 del = tvb_get_guint8(tvb, offset++);
791 del = tvb_get_ntohs(tvb, offset);
796 proto_tree_add_int(tree, hf, tvb, *offsetp, len, del);
801 /* Wrapper for in_cksum function */
803 ip_csum(const guint8 * ptr, guint32 len)
807 cksum_vec[0].ptr = ptr;
808 cksum_vec[0].len = len;
809 return in_cksum(&cksum_vec[0], 1);
812 /* Registration functions for dissectors */
814 proto_register_vj(void)
816 static hf_register_info hf[] = {
817 { &hf_vj_change_mask,
818 { "Change mask", "vj.change_mask", FT_UINT8, BASE_HEX,
819 NULL, 0x0, NULL, HFILL }},
820 { &hf_vj_change_mask_c,
821 { "Connection changed", "vj.change_mask_c", FT_BOOLEAN, 8,
822 NULL, NEW_C, "Connection number changed", HFILL }},
823 { &hf_vj_change_mask_i,
824 { "IP ID change != 1", "vj.change_mask_i", FT_BOOLEAN, 8,
825 NULL, NEW_I, "IP ID changed by a value other than 1", HFILL }},
826 { &hf_vj_change_mask_p,
827 { "Push bit set", "vj.change_mask_p", FT_BOOLEAN, 8,
828 NULL, CHANGE_PUSH_BIT, "TCP PSH flag set", HFILL }},
829 { &hf_vj_change_mask_s,
830 { "Sequence number changed", "vj.change_mask_s", FT_BOOLEAN, 8,
831 NULL, NEW_S, NULL, HFILL }},
832 { &hf_vj_change_mask_a,
833 { "Ack number changed", "vj.change_mask_a", FT_BOOLEAN, 8,
834 NULL, NEW_A, "Acknowledgement sequence number changed", HFILL }},
835 { &hf_vj_change_mask_w,
836 { "Window changed", "vj.change_mask_w", FT_BOOLEAN, 8,
837 NULL, NEW_W, "TCP window changed", HFILL }},
838 { &hf_vj_change_mask_u,
839 { "Urgent pointer set", "vj.change_mask_u", FT_BOOLEAN, 8,
840 NULL, NEW_U, NULL, HFILL }},
841 { &hf_vj_connection_number,
842 { "Connection number", "vj.connection_number", FT_UINT8, BASE_DEC,
843 NULL, 0x0, NULL, HFILL }},
845 { "TCP checksum", "vj.tcp_cksum", FT_UINT16, BASE_HEX,
846 NULL, 0x0, NULL, HFILL }},
848 { "Urgent pointer", "vj.urp", FT_UINT16, BASE_DEC,
849 NULL, 0x0, NULL, HFILL }},
851 { "Window delta", "vj.win_delta", FT_INT16, BASE_DEC,
852 NULL, 0x0, "Delta for window", HFILL }},
854 { "Ack delta", "vj.ack_delta", FT_UINT16, BASE_DEC,
855 NULL, 0x0, "Delta for acknowledgment sequence number", HFILL }},
857 { "Sequence delta", "vj.seq_delta", FT_UINT16, BASE_DEC,
858 NULL, 0x0, "Delta for sequence number", HFILL }},
859 { &hf_vj_ip_id_delta,
860 { "IP ID delta", "vj.ip_id_delta", FT_UINT16, BASE_DEC,
861 NULL, 0x0, "Delta for IP ID", HFILL }},
863 static gint *ett[] = {
868 proto_vj = proto_register_protocol("PPP VJ Compression", "PPP VJ", "vj");
869 proto_register_field_array(proto_vj, hf, array_length(hf));
870 proto_register_subtree_array(ett, array_length(ett));
871 register_init_routine(&vj_init);
875 proto_reg_handoff_vj(void)
877 dissector_handle_t vjc_handle;
878 dissector_handle_t vjuc_handle;
880 vjc_handle = create_dissector_handle(dissect_vjc, proto_vj);
881 dissector_add("ppp.protocol", PPP_VJC_COMP, vjc_handle);
883 vjuc_handle = create_dissector_handle(dissect_vjuc, proto_vj);
884 dissector_add("ppp.protocol", PPP_VJC_UNCOMP, vjuc_handle);
886 ip_handle = find_dissector("ip");
887 data_handle = find_dissector("data");