~ubuntu-branches/ubuntu/wily/tcpdump/wily

« back to all changes in this revision

Viewing changes to print-ldp.c

  • Committer: Package Import Robot
  • Author(s): Logan Rosen
  • Date: 2012-08-08 20:06:38 UTC
  • mfrom: (7.1.12 sid)
  • Revision ID: package-import@ubuntu.com-20120808200638-fzv1zks6p7a1qb2f
Tags: 4.3.0-1ubuntu1
* Merge from Debian unstable. Remaining changes:
  - Add enforcing AppArmor profile.
  - debian/control: Build-Depends on dh-apparmor.

Show diffs side-by-side

added added

removed removed

Lines of Context:
180
180
#define LDP_FEC_WILDCARD        0x01
181
181
#define LDP_FEC_PREFIX          0x02
182
182
#define LDP_FEC_HOSTADDRESS     0x03
183
 
/* From draft-martini-l2circuit-trans-mpls-13.txt */
 
183
/* From RFC 4906; should probably be updated to RFC 4447 (e.g., VC -> PW) */
184
184
#define LDP_FEC_MARTINI_VC      0x80
185
185
 
186
186
static const struct tok ldp_fec_values[] = {
238
238
 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
239
239
 */
240
240
 
 
241
#define TLV_TCHECK(minlen) \
 
242
    TCHECK2(*tptr, minlen); if (tlv_tlen < minlen) goto badtlv;
 
243
 
241
244
int
242
245
ldp_tlv_print(register const u_char *tptr) {
243
246
 
273
276
    switch(tlv_type) {
274
277
 
275
278
    case LDP_TLV_COMMON_HELLO:
 
279
        TLV_TCHECK(4);
276
280
        printf("\n\t      Hold Time: %us, Flags: [%s Hello%s]",
277
281
               EXTRACT_16BITS(tptr),
278
282
               (EXTRACT_16BITS(tptr+2)&0x8000) ? "Targeted" : "Link",
280
284
        break;
281
285
 
282
286
    case LDP_TLV_IPV4_TRANSPORT_ADDR:
 
287
        TLV_TCHECK(4);
283
288
        printf("\n\t      IPv4 Transport Address: %s", ipaddr_string(tptr));
284
289
        break;
285
290
#ifdef INET6
286
291
    case LDP_TLV_IPV6_TRANSPORT_ADDR:
 
292
        TLV_TCHECK(16);
287
293
        printf("\n\t      IPv6 Transport Address: %s", ip6addr_string(tptr));
288
294
        break;
289
295
#endif
290
296
    case LDP_TLV_CONFIG_SEQ_NUMBER:
 
297
        TLV_TCHECK(4);
291
298
        printf("\n\t      Sequence Number: %u", EXTRACT_32BITS(tptr));
292
299
        break;
293
300
 
294
301
    case LDP_TLV_ADDRESS_LIST:
 
302
        TLV_TCHECK(LDP_TLV_ADDRESS_LIST_AFNUM_LEN);
295
303
        af = EXTRACT_16BITS(tptr);
296
304
        tptr+=LDP_TLV_ADDRESS_LIST_AFNUM_LEN;
297
305
        tlv_tlen -= LDP_TLV_ADDRESS_LIST_AFNUM_LEN;
300
308
        switch (af) {
301
309
        case AFNUM_INET:
302
310
            while(tlv_tlen >= sizeof(struct in_addr)) {
 
311
                TCHECK2(*tptr, sizeof(struct in_addr));
303
312
                printf(" %s",ipaddr_string(tptr));
304
313
                tlv_tlen-=sizeof(struct in_addr);
305
314
                tptr+=sizeof(struct in_addr);                
308
317
#ifdef INET6
309
318
        case AFNUM_INET6:
310
319
            while(tlv_tlen >= sizeof(struct in6_addr)) {
 
320
                TCHECK2(*tptr, sizeof(struct in6_addr));
311
321
                printf(" %s",ip6addr_string(tptr));
312
322
                tlv_tlen-=sizeof(struct in6_addr);
313
323
                tptr+=sizeof(struct in6_addr);                
321
331
        break;
322
332
 
323
333
    case LDP_TLV_COMMON_SESSION:
 
334
        TLV_TCHECK(8);
324
335
        printf("\n\t      Version: %u, Keepalive: %us, Flags: [Downstream %s, Loop Detection %s]",
325
336
               EXTRACT_16BITS(tptr), EXTRACT_16BITS(tptr+2),
326
337
               (EXTRACT_16BITS(tptr+6)&0x8000) ? "On Demand" : "Unsolicited",
329
340
        break;
330
341
 
331
342
    case LDP_TLV_FEC:
 
343
        TLV_TCHECK(1);
332
344
        fec_type = *tptr;
333
345
        printf("\n\t      %s FEC (0x%02x)",
334
346
               tok2str(ldp_fec_values, "Unknown", fec_type),
335
347
               fec_type);
336
348
 
337
349
        tptr+=1;
 
350
        tlv_tlen-=1;
338
351
        switch(fec_type) {
339
352
 
340
353
        case LDP_FEC_WILDCARD:
341
354
            break;
342
355
        case LDP_FEC_PREFIX:
 
356
            TLV_TCHECK(2);
343
357
            af = EXTRACT_16BITS(tptr);
344
 
            tptr+=2;
 
358
            tptr+=LDP_TLV_ADDRESS_LIST_AFNUM_LEN;
 
359
            tlv_tlen-=LDP_TLV_ADDRESS_LIST_AFNUM_LEN;
345
360
            if (af == AFNUM_INET) {
346
 
                i=decode_prefix4(tptr,buf,sizeof(buf));
347
 
                printf(": IPv4 prefix %s",buf);
 
361
                i=decode_prefix4(tptr,tlv_tlen,buf,sizeof(buf));
 
362
                if (i == -2)
 
363
                    goto trunc;
 
364
                if (i == -3)
 
365
                    printf(": IPv4 prefix (goes past end of TLV)");
 
366
                else if (i == -1)
 
367
                    printf(": IPv4 prefix (invalid length)");
 
368
                else
 
369
                    printf(": IPv4 prefix %s",buf);
348
370
            }
349
371
#ifdef INET6
350
372
            else if (af == AFNUM_INET6) {
351
 
                i=decode_prefix6(tptr,buf,sizeof(buf));
352
 
                printf(": IPv6 prefix %s",buf);
 
373
                i=decode_prefix6(tptr,tlv_tlen,buf,sizeof(buf));
 
374
                if (i == -2)
 
375
                    goto trunc;
 
376
                if (i == -3)
 
377
                    printf(": IPv4 prefix (goes past end of TLV)");
 
378
                else if (i == -1)
 
379
                    printf(": IPv6 prefix (invalid length)");
 
380
                else
 
381
                    printf(": IPv6 prefix %s",buf);
353
382
            }
354
383
#endif
 
384
            else
 
385
                printf(": Address family %u prefix", af);
355
386
            break;
356
387
        case LDP_FEC_HOSTADDRESS:
357
388
            break;
358
389
        case LDP_FEC_MARTINI_VC:
359
 
            if (!TTEST2(*tptr, 11))
360
 
                goto trunc;
 
390
            /*
 
391
             * According to RFC 4908, the VC info Length field can be zero,
 
392
             * in which case not only are there no interface parameters,
 
393
             * there's no VC ID.
 
394
             */
 
395
            TLV_TCHECK(7);
361
396
            vc_info_len = *(tptr+2);
362
397
 
 
398
            if (vc_info_len == 0) {
 
399
                printf(": %s, %scontrol word, group-ID %u, VC-info-length: %u",
 
400
                       tok2str(l2vpn_encaps_values, "Unknown", EXTRACT_16BITS(tptr)&0x7fff),
 
401
                       EXTRACT_16BITS(tptr)&0x8000 ? "" : "no ",
 
402
                       EXTRACT_32BITS(tptr+3),
 
403
                       vc_info_len);
 
404
                break;
 
405
            }
 
406
 
 
407
            /* Make sure we have the VC ID as well */
 
408
            TLV_TCHECK(11);
363
409
            printf(": %s, %scontrol word, group-ID %u, VC-ID %u, VC-info-length: %u",
364
410
                   tok2str(l2vpn_encaps_values, "Unknown", EXTRACT_16BITS(tptr)&0x7fff),
365
411
                   EXTRACT_16BITS(tptr)&0x8000 ? "" : "no ",
366
412
                   EXTRACT_32BITS(tptr+3),
367
413
                   EXTRACT_32BITS(tptr+7),
368
414
                   vc_info_len);
369
 
 
370
 
            if (vc_info_len == 0) /* infinite loop protection */
371
 
                break;
372
 
 
 
415
            if (vc_info_len < 4)
 
416
                goto trunc; /* minimum 4, for the VC ID */
 
417
            vc_info_len -= 4; /* subtract out the VC ID, giving the length of the interface parameters */
 
418
 
 
419
            /* Skip past the fixed information and the VC ID */
373
420
            tptr+=11;
374
 
            if (!TTEST2(*tptr, vc_info_len))
375
 
                goto trunc;
 
421
            tlv_tlen-=11;
 
422
            TLV_TCHECK(vc_info_len);
376
423
 
377
424
            while (vc_info_len > 2) {
378
425
                vc_info_tlv_type = *tptr;
421
468
        break;
422
469
 
423
470
    case LDP_TLV_GENERIC_LABEL:
 
471
        TLV_TCHECK(4);
424
472
        printf("\n\t      Label: %u", EXTRACT_32BITS(tptr) & 0xfffff);
425
473
        break;
426
474
 
427
475
    case LDP_TLV_STATUS:
 
476
        TLV_TCHECK(8);
428
477
        ui = EXTRACT_32BITS(tptr);
429
478
        tptr+=4;
430
479
        printf("\n\t      Status: 0x%02x, Flags: [%s and %s forward]",
438
487
        break;
439
488
 
440
489
    case LDP_TLV_FT_SESSION:
 
490
        TLV_TCHECK(8);
441
491
        ft_flags = EXTRACT_16BITS(tptr);
442
492
        printf("\n\t      Flags: [%sReconnect, %sSave State, %sAll-Label Protection, %s Checkpoint, %sRe-Learn State]",
443
493
               ft_flags&0x8000 ? "" : "No ",
456
506
        break;
457
507
 
458
508
    case LDP_TLV_MTU:
 
509
        TLV_TCHECK(2);
459
510
        printf("\n\t      MTU: %u", EXTRACT_16BITS(tptr));
460
511
        break;
461
512
 
486
537
trunc:
487
538
    printf("\n\t\t packet exceeded snapshot");
488
539
    return 0;
 
540
 
 
541
badtlv:
 
542
    printf("\n\t\t TLV contents go past end of TLV");
 
543
    return(tlv_len+4); /* Type & Length fields not included */
489
544
}
490
545
 
491
546
void
546
601
 
547
602
    while(tlen>0) {
548
603
        /* did we capture enough for fully decoding the msg header ? */
549
 
        if (!TTEST2(*tptr, sizeof(struct ldp_msg_header)))
550
 
            goto trunc;
 
604
        TCHECK2(*tptr, sizeof(struct ldp_msg_header));
551
605
 
552
606
        ldp_msg_header = (const struct ldp_msg_header *)tptr;
553
607
        msg_len=EXTRACT_16BITS(ldp_msg_header->length);
570
624
        msg_tlen=msg_len-sizeof(struct ldp_msg_header)+4; /* Type & Length fields not included */
571
625
 
572
626
        /* did we capture enough for fully decoding the message ? */
573
 
        if (!TTEST2(*tptr, msg_len))
574
 
            goto trunc;
 
627
        TCHECK2(*tptr, msg_len);
575
628
        hexdump=FALSE;
576
629
 
577
630
        switch(msg_type) {