#endif
#include "ipproto.h"
+/* RFC4340: Datagram Congestion Control Protocol (DCCP) */
+
/**
* struct dccp_hdr - generic part of DCCP packet header, with a 24-bit
* sequence number
struct dccp_hdr {
uint16_t dccph_sport,
dccph_dport;
- uint8_t dccph_doff;
- uint8_t dccph_ccval_cscov;
+ uint8_t dccph_doff;
+ uint8_t dccph_ccval_cscov;
uint16_t dccph_checksum;
- uint8_t dccph_xtr;
- uint8_t dccph_seq[3];
+ uint8_t dccph_xtr;
+ uint8_t dccph_seq[3];
} UNALIGNED;
/**
struct dccp_hdr_ext {
uint16_t dccph_sport,
dccph_dport;
- uint8_t dccph_doff;
- uint8_t dccph_ccval_cscov;
+ uint8_t dccph_doff;
+ uint8_t dccph_ccval_cscov;
uint16_t dccph_checksum;
- uint8_t dccph_xtr;
- uint8_t reserved;
- uint8_t dccph_seq[6];
+ uint8_t dccph_xtr;
+ uint8_t reserved;
+ uint8_t dccph_seq[6];
} UNALIGNED;
#define DCCPH_CCVAL(dh) (((dh)->dccph_ccval_cscov >> 4) & 0xF)
* @dccph_resp_service - Echoes the Service Code on a received DCCP-Request
*/
struct dccp_hdr_response {
- uint8_t dccph_resp_ack[8]; /* always 8 bytes */
+ uint8_t dccph_resp_ack[8]; /* always 8 bytes */
uint32_t dccph_resp_service;
} UNALIGNED;
* @dccph_reset_service - Echoes the Service Code on a received DCCP-Request
*/
struct dccp_hdr_reset {
- uint8_t dccph_reset_ack[8]; /* always 8 bytes */
- uint8_t dccph_reset_code,
+ uint8_t dccph_reset_ack[8]; /* always 8 bytes */
+ uint8_t dccph_reset_code,
dccph_reset_data[3];
} UNALIGNED;
DCCP_PKT_CLOSE,
DCCP_PKT_RESET,
DCCP_PKT_SYNC,
- DCCP_PKT_SYNCACK,
- DCCP_PKT_INVALID
+ DCCP_PKT_SYNCACK
+};
+
+static const struct tok dccp_pkt_type_str[] = {
+ { DCCP_PKT_REQUEST, "DCCP-Request" },
+ { DCCP_PKT_RESPONSE, "DCCP-Response" },
+ { DCCP_PKT_DATA, "DCCP-Data" },
+ { DCCP_PKT_ACK, "DCCP-Ack" },
+ { DCCP_PKT_DATAACK, "DCCP-DataAck" },
+ { DCCP_PKT_CLOSEREQ, "DCCP-CloseReq" },
+ { DCCP_PKT_CLOSE, "DCCP-Close" },
+ { DCCP_PKT_RESET, "DCCP-Reset" },
+ { DCCP_PKT_SYNC, "DCCP-Sync" },
+ { DCCP_PKT_SYNCACK, "DCCP-SyncAck" },
+ { 0, NULL}
};
enum dccp_reset_codes {
* @len - lenght of ip packet
*/
void dccp_print(netdissect_options *ndo, const u_char *bp, const u_char *data2,
- u_int len)
+ u_int len)
{
const struct dccp_hdr *dh;
const struct ip *ip;
u_short sport, dport;
u_int hlen;
u_int fixed_hdrlen;
+ uint8_t dccph_type;
dh = (const struct dccp_hdr *)bp;
}
if (len < sizeof(struct dccp_hdr)) {
ND_PRINT((ndo, "truncated-dccp - %u bytes missing!",
- len - (u_int)sizeof(struct dccp_hdr)));
+ len - (u_int)sizeof(struct dccp_hdr)));
return;
}
fixed_hdrlen = dccp_basic_hdr_len(dh);
if (len < fixed_hdrlen) {
ND_PRINT((ndo, "truncated-dccp - %u bytes missing!",
- len - fixed_hdrlen));
+ len - fixed_hdrlen));
return;
}
ND_TCHECK2(*dh, fixed_hdrlen);
#ifdef INET6
if (ip6) {
ND_PRINT((ndo, "%s.%d > %s.%d: ",
- ip6addr_string(ndo, &ip6->ip6_src), sport,
- ip6addr_string(ndo, &ip6->ip6_dst), dport));
+ ip6addr_string(ndo, &ip6->ip6_src), sport,
+ ip6addr_string(ndo, &ip6->ip6_dst), dport));
} else
#endif /*INET6*/
{
ND_PRINT((ndo, "%s.%d > %s.%d: ",
- ipaddr_string(ndo, &ip->ip_src), sport,
- ipaddr_string(ndo, &ip->ip_dst), dport));
+ ipaddr_string(ndo, &ip->ip_src), sport,
+ ipaddr_string(ndo, &ip->ip_dst), dport));
}
+ ND_PRINT((ndo, "DCCP"));
+
if (ndo->ndo_qflag) {
ND_PRINT((ndo, " %d", len - hlen));
if (hlen > len) {
- ND_PRINT((ndo, "dccp [bad hdr length %u - too long, > %u]",
- hlen, len));
+ ND_PRINT((ndo, " [bad hdr length %u - too long, > %u]",
+ hlen, len));
}
return;
}
/* other variables in generic header */
if (ndo->ndo_vflag) {
- ND_PRINT((ndo, "CCVal %d, CsCov %d, ", DCCPH_CCVAL(dh), DCCPH_CSCOV(dh)));
+ ND_PRINT((ndo, " (CCVal %d, CsCov %d, ", DCCPH_CCVAL(dh), DCCPH_CSCOV(dh)));
}
/* checksum calculation */
sum = dccp6_cksum(ip6, dh, len);
#endif
if (sum != 0)
- ND_PRINT((ndo, "(incorrect -> 0x%04x), ",in_cksum_shouldbe(dccp_sum, sum)));
+ ND_PRINT((ndo, "(incorrect -> 0x%04x)",in_cksum_shouldbe(dccp_sum, sum)));
else
- ND_PRINT((ndo, "(correct), "));
+ ND_PRINT((ndo, "(correct)"));
}
- switch (DCCPH_TYPE(dh)) {
+ if (ndo->ndo_vflag)
+ ND_PRINT((ndo, ")"));
+ ND_PRINT((ndo, " "));
+
+ dccph_type = DCCPH_TYPE(dh);
+ switch (dccph_type) {
case DCCP_PKT_REQUEST: {
struct dccp_hdr_request *dhr =
(struct dccp_hdr_request *)(bp + fixed_hdrlen);
fixed_hdrlen += 4;
if (len < fixed_hdrlen) {
- ND_PRINT((ndo, "truncated-dccp request - %u bytes missing!",
- len - fixed_hdrlen));
+ ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
+ tok2str(dccp_pkt_type_str, "", dccph_type),
+ len - fixed_hdrlen));
return;
}
ND_TCHECK(*dhr);
- ND_PRINT((ndo, "request (service=%d) ",
- EXTRACT_32BITS(&dhr->dccph_req_service)));
+ ND_PRINT((ndo, "%s (service=%d) ",
+ tok2str(dccp_pkt_type_str, "", dccph_type),
+ EXTRACT_32BITS(&dhr->dccph_req_service)));
break;
}
case DCCP_PKT_RESPONSE: {
(struct dccp_hdr_response *)(bp + fixed_hdrlen);
fixed_hdrlen += 12;
if (len < fixed_hdrlen) {
- ND_PRINT((ndo, "truncated-dccp response - %u bytes missing!",
- len - fixed_hdrlen));
+ ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
+ tok2str(dccp_pkt_type_str, "", dccph_type),
+ len - fixed_hdrlen));
return;
}
ND_TCHECK(*dhr);
- ND_PRINT((ndo, "response (service=%d) ",
- EXTRACT_32BITS(&dhr->dccph_resp_service)));
+ ND_PRINT((ndo, "%s (service=%d) ",
+ tok2str(dccp_pkt_type_str, "", dccph_type),
+ EXTRACT_32BITS(&dhr->dccph_resp_service)));
break;
}
case DCCP_PKT_DATA:
- ND_PRINT((ndo, "data "));
+ ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
break;
case DCCP_PKT_ACK: {
fixed_hdrlen += 8;
if (len < fixed_hdrlen) {
- ND_PRINT((ndo, "truncated-dccp ack - %u bytes missing!",
- len - fixed_hdrlen));
+ ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
+ tok2str(dccp_pkt_type_str, "", dccph_type),
+ len - fixed_hdrlen));
return;
}
- ND_PRINT((ndo, "ack "));
+ ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
break;
}
case DCCP_PKT_DATAACK: {
fixed_hdrlen += 8;
if (len < fixed_hdrlen) {
- ND_PRINT((ndo, "truncated-dccp dataack - %u bytes missing!",
- len - fixed_hdrlen));
+ ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
+ tok2str(dccp_pkt_type_str, "", dccph_type),
+ len - fixed_hdrlen));
return;
}
- ND_PRINT((ndo, "dataack "));
+ ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
break;
}
case DCCP_PKT_CLOSEREQ:
fixed_hdrlen += 8;
if (len < fixed_hdrlen) {
- ND_PRINT((ndo, "truncated-dccp closereq - %u bytes missing!",
- len - fixed_hdrlen));
+ ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
+ tok2str(dccp_pkt_type_str, "", dccph_type),
+ len - fixed_hdrlen));
return;
}
- ND_PRINT((ndo, "closereq "));
+ ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
break;
case DCCP_PKT_CLOSE:
fixed_hdrlen += 8;
if (len < fixed_hdrlen) {
- ND_PRINT((ndo, "truncated-dccp close - %u bytes missing!",
- len - fixed_hdrlen));
+ ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
+ tok2str(dccp_pkt_type_str, "", dccph_type),
+ len - fixed_hdrlen));
return;
}
- ND_PRINT((ndo, "close "));
+ ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
break;
case DCCP_PKT_RESET: {
struct dccp_hdr_reset *dhr =
(struct dccp_hdr_reset *)(bp + fixed_hdrlen);
fixed_hdrlen += 12;
if (len < fixed_hdrlen) {
- ND_PRINT((ndo, "truncated-dccp reset - %u bytes missing!",
- len - fixed_hdrlen));
+ ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
+ tok2str(dccp_pkt_type_str, "", dccph_type),
+ len - fixed_hdrlen));
return;
}
ND_TCHECK(*dhr);
- ND_PRINT((ndo, "reset (code=%s) ",
- dccp_reset_code(dhr->dccph_reset_code)));
+ ND_PRINT((ndo, "%s (code=%s) ",
+ tok2str(dccp_pkt_type_str, "", dccph_type),
+ dccp_reset_code(dhr->dccph_reset_code)));
break;
}
case DCCP_PKT_SYNC:
fixed_hdrlen += 8;
if (len < fixed_hdrlen) {
- ND_PRINT((ndo, "truncated-dccp sync - %u bytes missing!",
- len - fixed_hdrlen));
+ ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
+ tok2str(dccp_pkt_type_str, "", dccph_type),
+ len - fixed_hdrlen));
return;
}
- ND_PRINT((ndo, "sync "));
+ ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
break;
case DCCP_PKT_SYNCACK:
fixed_hdrlen += 8;
if (len < fixed_hdrlen) {
- ND_PRINT((ndo, "truncated-dccp syncack - %u bytes missing!",
- len - fixed_hdrlen));
+ ND_PRINT((ndo, "truncated-%s - %u bytes missing!",
+ tok2str(dccp_pkt_type_str, "", dccph_type),
+ len - fixed_hdrlen));
return;
}
- ND_PRINT((ndo, "syncack "));
+ ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "", dccph_type)));
break;
default:
- ND_PRINT((ndo, "invalid "));
+ ND_PRINT((ndo, "%s ", tok2str(dccp_pkt_type_str, "unknown-type-%u", dccph_type)));
break;
}
{ 42, "timestamp_echo" },
{ 43, "elapsed_time" },
{ 44, "data_checksum" },
- { 0, NULL }
+ { 0, NULL }
};
static int dccp_print_option(netdissect_options *ndo, const u_char *option, u_int hlen)
ND_PRINT((ndo, "CCID option %u optlen too short", *option));
else
ND_PRINT((ndo, "%s optlen too short",
- tok2str(dccp_option_values, "Option %u", *option)));
+ tok2str(dccp_option_values, "Option %u", *option)));
return 0;
}
} else
if (hlen < optlen) {
if (*option >= 128)
ND_PRINT((ndo, "CCID option %u optlen goes past header length",
- *option));
+ *option));
else
ND_PRINT((ndo, "%s optlen goes past header length",
- tok2str(dccp_option_values, "Option %u", *option)));
+ tok2str(dccp_option_values, "Option %u", *option)));
return 0;
}
ND_TCHECK2(*option, optlen);