print-mptcp.c (313537) | print-mptcp.c (327234) |
---|---|
1/** 2 * Copyright (c) 2012 3 * 4 * Gregory Detal <gregory.detal@uclouvain.be> 5 * Christoph Paasch <christoph.paasch@uclouvain.be> 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 164 unchanged lines hidden (view full) --- 173} 174 175static int 176mp_capable_print(netdissect_options *ndo, 177 const u_char *opt, u_int opt_len, u_char flags) 178{ 179 const struct mp_capable *mpc = (const struct mp_capable *) opt; 180 | 1/** 2 * Copyright (c) 2012 3 * 4 * Gregory Detal <gregory.detal@uclouvain.be> 5 * Christoph Paasch <christoph.paasch@uclouvain.be> 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 164 unchanged lines hidden (view full) --- 173} 174 175static int 176mp_capable_print(netdissect_options *ndo, 177 const u_char *opt, u_int opt_len, u_char flags) 178{ 179 const struct mp_capable *mpc = (const struct mp_capable *) opt; 180 |
181 if (!(opt_len == 12 && flags & TH_SYN) && | 181 if (!(opt_len == 12 && (flags & TH_SYN)) && |
182 !(opt_len == 20 && (flags & (TH_SYN | TH_ACK)) == TH_ACK)) 183 return 0; 184 185 if (MP_CAPABLE_OPT_VERSION(mpc->sub_ver) != 0) { 186 ND_PRINT((ndo, " Unknown Version (%d)", MP_CAPABLE_OPT_VERSION(mpc->sub_ver))); 187 return 1; 188 } 189 --- 7 unchanged lines hidden (view full) --- 197} 198 199static int 200mp_join_print(netdissect_options *ndo, 201 const u_char *opt, u_int opt_len, u_char flags) 202{ 203 const struct mp_join *mpj = (const struct mp_join *) opt; 204 | 182 !(opt_len == 20 && (flags & (TH_SYN | TH_ACK)) == TH_ACK)) 183 return 0; 184 185 if (MP_CAPABLE_OPT_VERSION(mpc->sub_ver) != 0) { 186 ND_PRINT((ndo, " Unknown Version (%d)", MP_CAPABLE_OPT_VERSION(mpc->sub_ver))); 187 return 1; 188 } 189 --- 7 unchanged lines hidden (view full) --- 197} 198 199static int 200mp_join_print(netdissect_options *ndo, 201 const u_char *opt, u_int opt_len, u_char flags) 202{ 203 const struct mp_join *mpj = (const struct mp_join *) opt; 204 |
205 if (!(opt_len == 12 && flags & TH_SYN) && | 205 if (!(opt_len == 12 && (flags & TH_SYN)) && |
206 !(opt_len == 16 && (flags & (TH_SYN | TH_ACK)) == (TH_SYN | TH_ACK)) && | 206 !(opt_len == 16 && (flags & (TH_SYN | TH_ACK)) == (TH_SYN | TH_ACK)) && |
207 !(opt_len == 24 && flags & TH_ACK)) | 207 !(opt_len == 24 && (flags & TH_ACK))) |
208 return 0; 209 210 if (opt_len != 24) { 211 if (mpj->sub_b & MP_JOIN_B) 212 ND_PRINT((ndo, " backup")); 213 ND_PRINT((ndo, " id %u", mpj->addr_id)); 214 } 215 --- 15 unchanged lines hidden (view full) --- 231 ND_PRINT((ndo, "%02x", mpj->u.ack.mac[i])); 232 } 233 default: 234 break; 235 } 236 return 1; 237} 238 | 208 return 0; 209 210 if (opt_len != 24) { 211 if (mpj->sub_b & MP_JOIN_B) 212 ND_PRINT((ndo, " backup")); 213 ND_PRINT((ndo, " id %u", mpj->addr_id)); 214 } 215 --- 15 unchanged lines hidden (view full) --- 231 ND_PRINT((ndo, "%02x", mpj->u.ack.mac[i])); 232 } 233 default: 234 break; 235 } 236 return 1; 237} 238 |
239static u_int mp_dss_len(const struct mp_dss *m, int csum) 240{ 241 u_int len; 242 243 len = 4; 244 if (m->flags & MP_DSS_A) { 245 /* Ack present - 4 or 8 octets */ 246 len += (m->flags & MP_DSS_a) ? 8 : 4; 247 } 248 if (m->flags & MP_DSS_M) { 249 /* 250 * Data Sequence Number (DSN), Subflow Sequence Number (SSN), 251 * Data-Level Length present, and Checksum possibly present. 252 * All but the Checksum are 10 bytes if the m flag is 253 * clear (4-byte DSN) and 14 bytes if the m flag is set 254 * (8-byte DSN). 255 */ 256 len += (m->flags & MP_DSS_m) ? 14 : 10; 257 258 /* 259 * The Checksum is present only if negotiated. 260 */ 261 if (csum) 262 len += 2; 263 } 264 return len; 265} 266 | |
267static int 268mp_dss_print(netdissect_options *ndo, 269 const u_char *opt, u_int opt_len, u_char flags) 270{ 271 const struct mp_dss *mdss = (const struct mp_dss *) opt; 272 | 239static int 240mp_dss_print(netdissect_options *ndo, 241 const u_char *opt, u_int opt_len, u_char flags) 242{ 243 const struct mp_dss *mdss = (const struct mp_dss *) opt; 244 |
273 if ((opt_len != mp_dss_len(mdss, 1) && 274 opt_len != mp_dss_len(mdss, 0)) || flags & TH_SYN) | 245 /* We need the flags, at a minimum. */ 246 if (opt_len < 4) |
275 return 0; 276 | 247 return 0; 248 |
249 if (flags & TH_SYN) 250 return 0; 251 |
|
277 if (mdss->flags & MP_DSS_F) 278 ND_PRINT((ndo, " fin")); 279 280 opt += 4; | 252 if (mdss->flags & MP_DSS_F) 253 ND_PRINT((ndo, " fin")); 254 255 opt += 4; |
256 opt_len -= 4; |
|
281 if (mdss->flags & MP_DSS_A) { | 257 if (mdss->flags & MP_DSS_A) { |
258 /* Ack present */ |
|
282 ND_PRINT((ndo, " ack ")); | 259 ND_PRINT((ndo, " ack ")); |
260 /* 261 * If the a flag is set, we have an 8-byte ack; if it's 262 * clear, we have a 4-byte ack. 263 */ |
|
283 if (mdss->flags & MP_DSS_a) { | 264 if (mdss->flags & MP_DSS_a) { |
265 if (opt_len < 8) 266 return 0; |
|
284 ND_PRINT((ndo, "%" PRIu64, EXTRACT_64BITS(opt))); 285 opt += 8; | 267 ND_PRINT((ndo, "%" PRIu64, EXTRACT_64BITS(opt))); 268 opt += 8; |
269 opt_len -= 8; |
|
286 } else { | 270 } else { |
271 if (opt_len < 4) 272 return 0; |
|
287 ND_PRINT((ndo, "%u", EXTRACT_32BITS(opt))); 288 opt += 4; | 273 ND_PRINT((ndo, "%u", EXTRACT_32BITS(opt))); 274 opt += 4; |
275 opt_len -= 4; |
|
289 } 290 } 291 292 if (mdss->flags & MP_DSS_M) { | 276 } 277 } 278 279 if (mdss->flags & MP_DSS_M) { |
280 /* 281 * Data Sequence Number (DSN), Subflow Sequence Number (SSN), 282 * Data-Level Length present, and Checksum possibly present. 283 */ |
|
293 ND_PRINT((ndo, " seq ")); | 284 ND_PRINT((ndo, " seq ")); |
285 /* 286 * If the m flag is set, we have an 8-byte NDS; if it's clear, 287 * we have a 4-byte DSN. 288 */ |
|
294 if (mdss->flags & MP_DSS_m) { | 289 if (mdss->flags & MP_DSS_m) { |
290 if (opt_len < 8) 291 return 0; |
|
295 ND_PRINT((ndo, "%" PRIu64, EXTRACT_64BITS(opt))); 296 opt += 8; | 292 ND_PRINT((ndo, "%" PRIu64, EXTRACT_64BITS(opt))); 293 opt += 8; |
294 opt_len -= 8; |
|
297 } else { | 295 } else { |
296 if (opt_len < 4) 297 return 0; |
|
298 ND_PRINT((ndo, "%u", EXTRACT_32BITS(opt))); 299 opt += 4; | 298 ND_PRINT((ndo, "%u", EXTRACT_32BITS(opt))); 299 opt += 4; |
300 opt_len -= 4; |
|
300 } | 301 } |
302 if (opt_len < 4) 303 return 0; |
|
301 ND_PRINT((ndo, " subseq %u", EXTRACT_32BITS(opt))); 302 opt += 4; | 304 ND_PRINT((ndo, " subseq %u", EXTRACT_32BITS(opt))); 305 opt += 4; |
306 opt_len -= 4; 307 if (opt_len < 2) 308 return 0; |
|
303 ND_PRINT((ndo, " len %u", EXTRACT_16BITS(opt))); 304 opt += 2; | 309 ND_PRINT((ndo, " len %u", EXTRACT_16BITS(opt))); 310 opt += 2; |
311 opt_len -= 2; |
|
305 | 312 |
306 if (opt_len == mp_dss_len(mdss, 1)) | 313 /* 314 * The Checksum is present only if negotiated. 315 * If there are at least 2 bytes left, process the next 2 316 * bytes as the Checksum. 317 */ 318 if (opt_len >= 2) { |
307 ND_PRINT((ndo, " csum 0x%x", EXTRACT_16BITS(opt))); | 319 ND_PRINT((ndo, " csum 0x%x", EXTRACT_16BITS(opt))); |
320 opt_len -= 2; 321 } |
|
308 } | 322 } |
323 if (opt_len != 0) 324 return 0; |
|
309 return 1; 310} 311 312static int 313add_addr_print(netdissect_options *ndo, 314 const u_char *opt, u_int opt_len, u_char flags _U_) 315{ 316 const struct mp_add_addr *add_addr = (const struct mp_add_addr *) opt; --- 114 unchanged lines hidden --- | 325 return 1; 326} 327 328static int 329add_addr_print(netdissect_options *ndo, 330 const u_char *opt, u_int opt_len, u_char flags _U_) 331{ 332 const struct mp_add_addr *add_addr = (const struct mp_add_addr *) opt; --- 114 unchanged lines hidden --- |