summaryrefslogtreecommitdiffstats
path: root/contrib/tcpdump/print-radius.c
blob: 32c8575817a69f049b1aff9b66b3ada3adcabdb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
/*
 * Radius printer routines as specified on:
 *
 * RFC 2865:
 *      "Remote Authentication Dial In User Service (RADIUS)"
 *
 * RFC 2866:
 *      "RADIUS Accounting"
 *
 * RFC 2867:
 *      "RADIUS Accounting Modifications for Tunnel Protocol Support"
 *
 * RFC 2868:
 *      "RADIUS Attributes for Tunnel Protocol Support"
 *
 * RFC 2869:
 *      "RADIUS Extensions"
 *
 * Alfredo Andres Omella (aandres@s21sec.com) v0.1 2000/09/15
 *
 * TODO: Among other things to print ok MacIntosh and Vendor values 
 */

#ifndef lint
static const char rcsid[] =
    "$Id: print-radius.c,v 1.5 2000/12/18 08:16:58 guy Exp $";
#endif

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <sys/param.h>

#include <netinet/in.h>

#include <stdio.h>

#include "interface.h"
#include "addrtoname.h"
#include "extract.h"

#define TAM_SIZE(x) (sizeof(x)/sizeof(x[0]) )

#define PRINT_HEX(bytes_len, ptr_data)                               \
           while(bytes_len)                                          \
           {                                                         \
              printf("%02X", *ptr_data );                            \
              ptr_data++;                                            \
              bytes_len--;                                           \
           }


/* Radius packet codes */
#define RADCMD_ACCESS_REQ   1 /* Access-Request      */
#define RADCMD_ACCESS_ACC   2 /* Access-Accept       */
#define RADCMD_ACCESS_REJ   3 /* Access-Reject       */
#define RADCMD_ACCOUN_REQ   4 /* Accounting-Request  */
#define RADCMD_ACCOUN_RES   5 /* Accounting-Response */
#define RADCMD_ACCESS_CHA  11 /* Access-Challenge    */
#define RADCMD_STATUS_SER  12 /* Status-Server       */
#define RADCMD_STATUS_CLI  13 /* Status-Client       */
#define RADCMD_RESERVED   255 /* Reserved            */


/********************************/
/* Begin Radius Attribute types */
/********************************/
#define SERV_TYPE    6
#define FRM_IPADDR   8
#define LOG_IPHOST  14
#define LOG_SERVICE 15
#define FRM_IPX     23
#define SESSION_TIMEOUT   27
#define IDLE_TIMEOUT      28
#define FRM_ATALK_LINK    37
#define FRM_ATALK_NETWORK 38

#define ACCT_DELAY        41
#define ACCT_SESSION_TIME 46

#define TUNNEL_TYPE        64
#define TUNNEL_MEDIUM      65
#define TUNNEL_CLIENT_END  66
#define TUNNEL_SERVER_END  67
#define TUNNEL_PASS        69

#define ARAP_PASS          70
#define ARAP_FEATURES      71

#define TUNNEL_PRIV_GROUP  81
#define TUNNEL_ASSIGN_ID   82
#define TUNNEL_PREFERENCE  83

#define ARAP_CHALLENGE_RESP 84
#define ACCT_INT_INTERVAL   85

#define TUNNEL_CLIENT_AUTH 90
#define TUNNEL_SERVER_AUTH 91
/********************************/
/* End Radius Attribute types */
/********************************/


static void print_attr_string(register u_char *, u_int, u_short );
static void print_attr_num(register u_char *, u_int, u_short );
static void print_attr_address(register u_char *, u_int, u_short);
static void print_attr_time(register u_char *, u_int, u_short);
static void print_attr_strange(register u_char *, u_int, u_short);


struct radius_hdr { u_int8_t  code; /* Radius packet code  */
                    u_int8_t  id;   /* Radius packet id    */
                    u_int16_t len;  /* Radius total length */
                    u_int8_t  auth[16]; /* Authenticator   */
                  };


struct radius_attr { u_int8_t type; /* Attribute type   */
                     u_int8_t len;  /* Attribute length */
                   };


/* Service-Type Attribute standard values */                 
static const char *serv_type[]={ NULL,
                                "Login",
                                "Framed",  
                                "Callback Login",
                                "Callback Framed",
                                "Outbound",
                                "Administrative",
                                "NAS Prompt",                            
                                "Authenticate Only",
                                "Callback NAS Prompt",
                                "Call Check",
                                "Callback Administrative",
                               };                               

/* Framed-Protocol Attribute standard values */
static const char *frm_proto[]={ NULL,
                                 "PPP",
                                 "SLIP",
                                 "ARAP",
                                 "Gandalf proprietary",
                                 "Xylogics IPX/SLIP",
                                 "X.75 Synchronous",
                               };                               

/* Framed-Routing Attribute standard values */
static const char *frm_routing[]={ "None",
                                   "Send",
                                   "Listen",
                                   "Send&Listen",
                                 };                               

/* Framed-Compression Attribute standard values */
static const char *frm_comp[]={ "None",
                                "VJ TCP/IP",
                                "IPX",
                                "Stac-LZS",
                              };

/* Login-Service Attribute standard values */
static const char *login_serv[]={ "Telnet",
                                  "Rlogin",
                                  "TCP Clear",
                                  "PortMaster(proprietary)",
                                  "LAT",
                                  "X.25-PAD",
                                  "X.25-T3POS",
                                  "Unassigned",
                                  "TCP Clear Quiet",
                                };


/* Termination-Action Attribute standard values */
static const char *term_action[]={ "Default",
                                   "RADIUS-Request",
                                 };

/* NAS-Port-Type Attribute standard values */
static const char *nas_port_type[]={ "Async",
                                     "Sync",
                                     "ISDN Sync",
                                     "ISDN Async V.120",
                                     "ISDN Async V.110",
                                     "Virtual",
                                     "PIAFS",
                                     "HDLC Clear Channel",
                                     "X.25",
                                     "X.75",
                                     "G.3 Fax",
                                     "SDSL",
                                     "ADSL-CAP",
                                     "ADSL-DMT",
                                     "ISDN-DSL",
                                     "Ethernet",
                                     "xDSL",
                                     "Cable",
                                     "Wireless - Other",
                                     "Wireless - IEEE 802.11",
                                   };         

/* Acct-Status-Type Accounting Attribute standard values */
static const char *acct_status[]={ NULL,
                                   "Start",
                                   "Stop",
                                   "Interim-Update",
                                   "Unassigned",
                                   "Unassigned",
                                   "Unassigned",
                                   "Accounting-On",
                                   "Accounting-Off",
                                   "Tunnel-Start",
                                   "Tunnel-Stop",
                                   "Tunnel-Reject",
                                   "Tunnel-Link-Start",
                                   "Tunnel-Link-Stop",
                                   "Tunnel-Link-Reject",
                                   "Failed",
                                 };

/* Acct-Authentic Accounting Attribute standard values */
static const char *acct_auth[]={ NULL,
                                 "RADIUS",
                                 "Local",
                                 "Remote",
                               };

/* Acct-Terminate-Cause Accounting Attribute standard values */
static const char *acct_term[]={ NULL,
                                 "User Request",
                                 "Lost Carrier",
                                 "Lost Service",
                                 "Idle Timeout",
                                 "Session Timeout",
                                 "Admin Reset",
                                 "Admin Reboot",
                                 "Port Error",
                                 "NAS Error",
                                 "NAS Request",
                                 "NAS Reboot",
                                 "Port Unneeded",
                                 "Port Preempted",
                                 "Port Suspended",
                                 "Service Unavailable",
                                 "Callback",
                                 "User Error",
                                 "Host Request",
                               };

/* Tunnel-Type Attribute standard values */
static const char *tunnel_type[]={ NULL,
                                   "PPTP",
                                   "L2F",
                                   "L2TP",
                                   "ATMP",
                                   "VTP",
                                   "AH",
                                   "IP-IP",
                                   "MIN-IP-IP",
                                   "ESP",
                                   "GRE",
                                   "DVS",
                                   "IP-in-IP Tunneling",
                                 };
                                   
/* Tunnel-Medium-Type Attribute standard values */
static const char *tunnel_medium[]={ NULL,
                                     "IPv4",
                                     "IPv6",
                                     "NSAP",
                                     "HDLC",
                                     "BBN 1822",
                                     "802",
                                     "E.163",
                                     "E.164",
                                     "F.69",
                                     "X.121",
                                     "IPX",
                                     "Appletalk",
                                     "Decnet IV",
                                     "Banyan Vines",
                                     "E.164 with NSAP subaddress",
                                   };

/* ARAP-Zone-Access Attribute standard values */
static const char *arap_zone[]={ NULL,
                                 "Only access to dfl zone",
                                 "Use zone filter inc.",
                                 "Not used",
                                 "Use zone filter exc.",
                               };

static const char *prompt[]={ "No Echo",
                              "Echo",
                            };
                            
                                                               
struct attrtype { char *name;            /* Attribute name                 */
                  const char **subtypes; /* Standard Values (if any)       */
                  u_char siz_subtypes;   /* Size of total standard values  */
                  u_char first_subtype;  /* First standard value is 0 or 1 */
                  void (*print_func)(register u_char *, u_int, u_short );
                } attr_type[]=
  {
     { NULL,             NULL, 0, 0, NULL               },
     { "User",           NULL, 0, 0, print_attr_string  },
     { "Pass",           NULL, 0, 0, NULL               },
     { "CHAP-Pass",      NULL, 0, 0, NULL               },
     { "NAS_ipaddr",     NULL, 0, 0, print_attr_address },
     { "NAS_port",       NULL, 0, 0, print_attr_num     },
     { "Service_type",   serv_type, TAM_SIZE(serv_type)-1, 1, print_attr_num },                 
     { "Framed_proto",   frm_proto, TAM_SIZE(frm_proto)-1, 1, print_attr_num },
     { "Framed_ipaddr",  NULL, 0, 0, print_attr_address },
     { "Framed_ipnet",   NULL, 0, 0, print_attr_address },
     { "Framed_routing", frm_routing, TAM_SIZE(frm_routing), 0, 
                                                              print_attr_num }, 
     { "Filter_id",      NULL, 0, 0, print_attr_string  },
     { "Framed_mtu",     NULL, 0, 0, print_attr_num     },
     { "Framed_compress",  frm_comp, TAM_SIZE(frm_comp),   0, print_attr_num },
     { "Login_iphost",   NULL, 0, 0, print_attr_address },
     { "Login_service",  login_serv, TAM_SIZE(login_serv), 0, print_attr_num },
     { "Login_TCP_port", NULL, 0, 0, print_attr_num     },                 
/*17*/ { "Unassigned", NULL, 0, 0, NULL },                 
     { "Reply",           NULL, 0, 0, print_attr_string },
     { "Callback-number", NULL, 0, 0, print_attr_string },
     { "Callback-id",     NULL, 0, 0, print_attr_string },
/*21*/ { "Unassigned", NULL, 0, 0, NULL },   
     { "Framed_route",      NULL, 0, 0, print_attr_string },
     { "Framed_ipx_net",    NULL, 0, 0, print_attr_num    },
     { "State",             NULL, 0, 0, print_attr_string },
     { "Class",             NULL, 0, 0, print_attr_string },
     { "Vendor_specific",   NULL, 0, 0, print_attr_string },
     { "Session_timeout",   NULL, 0, 0, print_attr_num    },
     { "Idle_timeout",      NULL, 0, 0, print_attr_num    },
     { "Term_action", term_action, TAM_SIZE(term_action), 0, print_attr_num },
     { "Called_station",    NULL, 0, 0, print_attr_string },
     { "Calling_station",   NULL, 0, 0, print_attr_string },   
     { "NAS_id",            NULL, 0, 0, print_attr_string },
     { "Proxy_state",       NULL, 0, 0, print_attr_string },
     { "Login_LAT_service", NULL, 0, 0, print_attr_string },
     { "Login_LAT_node",    NULL, 0, 0, print_attr_string },
     { "Login_LAT_group",   NULL, 0, 0, print_attr_string },
     { "Framed_atalk_link", NULL, 0, 0, print_attr_num    },
     { "Framed_atalk_net",  NULL, 0, 0, print_attr_num    },
     { "Framed_atalk_zone", NULL, 0, 0, print_attr_string },
     { "Acct_status", acct_status, TAM_SIZE(acct_status)-1, 1, print_attr_num },
     { "Acct_delay",        NULL, 0, 0, print_attr_num    },
     { "Acct_in_octets",    NULL, 0, 0, print_attr_num    },
     { "Acct_out_octets",   NULL, 0, 0, print_attr_num    },
     { "Acct_session_id",   NULL, 0, 0, print_attr_string },
     { "Acct_authentic",  acct_auth, TAM_SIZE(acct_auth)-1, 1, print_attr_num },
     { "Acct_session_time", NULL, 0, 0, print_attr_num },
     { "Acct_in_packets",   NULL, 0, 0, print_attr_num },
     { "Acct_out_packets",  NULL, 0, 0, print_attr_num },
     { "Acct_term_cause", acct_term, TAM_SIZE(acct_term)-1, 1, print_attr_num },
     { "Acct_multi_session_id", NULL, 0, 0, print_attr_string },
     { "Acct_link_count", NULL, 0, 0, print_attr_num },
     { "Acct_in_giga",    NULL, 0, 0, print_attr_num },
     { "Acct_out_giga",   NULL, 0, 0, print_attr_num },
/*54*/ { "Unassigned", NULL, 0, 0, NULL },
     { "Event_timestamp", NULL, 0, 0, print_attr_time },
/*56*/ { "Unassigned", NULL, 0, 0, NULL },
/*57*/ { "Unassigned", NULL, 0, 0, NULL },
/*58*/ { "Unassigned", NULL, 0, 0, NULL },
/*59*/ { "Unassigned", NULL, 0, 0, NULL },
     { "CHAP_challenge", NULL, 0, 0, print_attr_string },  
     { "NAS_port_type",  nas_port_type, TAM_SIZE(nas_port_type), 0, 
                                                              print_attr_num },
     { "Port_limit",     NULL, 0, 0, print_attr_num },
/*63*/ { "Login_LAT_port", NULL, 0, 0, print_attr_string },
     { "Tunnel_type", tunnel_type, TAM_SIZE(tunnel_type)-1, 1, print_attr_num },
     { "Tunnel_medium", tunnel_medium, TAM_SIZE(tunnel_medium)-1, 1, 
                                                             print_attr_num },
     { "Tunnel_client_end",   NULL, 0, 0, print_attr_string },
     { "Tunnel_server_end",   NULL, 0, 0, print_attr_string },
     { "Acct_tunnel_connect", NULL, 0, 0, print_attr_string },
     { "Tunnel_pass",  NULL, 0, 0, print_attr_string  },
     { "ARAP_pass",    NULL, 0, 0, print_attr_strange },
     { "ARAP_feature", NULL, 0, 0, print_attr_strange },
/*72*/ { "ARAP_zone_acces", arap_zone, TAM_SIZE(arap_zone)-1, 1, 
                                                             print_attr_num },
     { "ARAP_security",      NULL, 0, 0, print_attr_string },
     { "ARAP_security_data", NULL, 0, 0, print_attr_string },
     { "Password_retry",     NULL, 0, 0, print_attr_num    },
     { "Prompt", prompt, TAM_SIZE(prompt), 0, print_attr_num },
     { "Connect_info",       NULL, 0, 0, print_attr_string   },
     { "Config_token",       NULL, 0, 0, print_attr_string   },
     { "EAP_msg",            NULL, 0, 0, print_attr_string   },
/*80*/ { "Message_auth",    NULL, 0, 0, print_attr_string },
     { "Tunnel_priv_group", NULL, 0, 0, print_attr_string },
     { "Tunnel_assign_id",  NULL, 0, 0, print_attr_string },
     { "Tunnel_pref",       NULL, 0, 0, print_attr_num    },
     { "ARAP_challenge_resp",    NULL, 0, 0, print_attr_strange },
     { "Acct_interim_interval",  NULL, 0, 0, print_attr_num     },
/*86*/ { "Acct_tunnel_pack_lost",  NULL, 0, 0, print_attr_num },
     { "NAS_port_id", NULL, 0, 0, print_attr_string },
     { "Framed_pool", NULL, 0, 0, print_attr_string },
     { "Unassigned",  NULL, 0, 0, NULL },
     { "Tunnel_client_auth_id", NULL, 0, 0, print_attr_string },
     { "Tunnel_server_auth_id", NULL, 0, 0, print_attr_string },
/*92*/ { "Unassigned",  NULL, 0, 0, NULL },
/*93*/ { "Unassigned",  NULL, 0, 0, NULL }
  };                    


/*****************************/
/* Print an attribute string */
/* value pointed by 'data'   */
/* and 'length' size.        */
/*****************************/
/* Returns nothing.          */
/*****************************/
static void
print_attr_string(register u_char *data, u_int length, u_short attr_code )
{
   register u_int i;
   
   TCHECK2(data[0],length);
   
   printf("{");
   switch(attr_code)
   {
      case TUNNEL_PASS:
           if (*data && (*data <=0x1F) )
              printf("Tag[%d] ",*data);
           data++;
           printf("Salt[%d] ",EXTRACT_16BITS(data) );
           data+=2;
           length-=2;
        break;
      case TUNNEL_CLIENT_END:
      case TUNNEL_SERVER_END:
      case TUNNEL_PRIV_GROUP:
      case TUNNEL_ASSIGN_ID:
      case TUNNEL_CLIENT_AUTH:
      case TUNNEL_SERVER_AUTH:
           if (*data <= 0x1F)
           {
              printf("Tag[%d] ",*data);
              data++;
              length--;
           }
        break;
   }

   for (i=0; i < length ; i++, data++)
       printf("%c",(*data < 32 || *data > 128) ? '.' : *data );

   printf("}");
   
   return;
   
   trunc:
      printf("|radius");
}  


/******************************/
/* Print an attribute numeric */
/* value pointed by 'data'    */
/* and 'length' size.         */
/******************************/
/* Returns nothing.           */
/******************************/
static void
print_attr_num(register u_char *data, u_int length, u_short attr_code )
{
   u_int8_t tag;
   u_int32_t timeout;
   
   if (length != 4)
   {
       printf("{length %u != 4}", length);
       return;
   }

   TCHECK2(data[0],4);
                          /* This attribute has standard values */
   if (attr_type[attr_code].siz_subtypes) 
   {
      static const char **table;
      u_int32_t data_value;
      table = attr_type[attr_code].subtypes;
      
      if ( (attr_code == TUNNEL_TYPE) || (attr_code == TUNNEL_MEDIUM) )
      {
         if (!*data)
            printf("{Tag[Unused]");
         else
            printf("{Tag[%d]", *data);
         data++;
         data_value = EXTRACT_24BITS(data);
      }
      else
      {
      	 data++;
         data_value = EXTRACT_32BITS(data);
      }
      if ( data_value <= (attr_type[attr_code].siz_subtypes - 1 +
            attr_type[attr_code].first_subtype) )
         printf("{%s}",table[data_value]);
      else
         printf("{#%d}",data_value);          
   }
   else
   {
      switch(attr_code) /* Be aware of special cases... */
      {
        case FRM_IPX:
             if (EXTRACT_32BITS( data) == 0xFFFFFFFE )
                printf("{NAS_select}");
             else
                printf("{%d}",EXTRACT_32BITS( data) );          
          break;

        case SESSION_TIMEOUT:
        case IDLE_TIMEOUT:
        case ACCT_DELAY:
        case ACCT_SESSION_TIME:
        case ACCT_INT_INTERVAL:
             timeout = EXTRACT_32BITS( data);
             if ( timeout < 60 )
                printf( "{%02d secs}", timeout);
             else
             {
                if ( timeout < 3600 )
                   printf( "{%02d:%02d min}", 
                          timeout / 60, timeout % 60);
                else
                   printf( "{%02d:%02d:%02d hours}",
                          timeout / 3600, (timeout % 3600) / 60, 
                          timeout % 60);
             }
          break;

        case FRM_ATALK_LINK:
             if (EXTRACT_32BITS(data) )          
                printf("{%d}",EXTRACT_32BITS(data) );
             else
                printf("{Unnumbered}" );
          break;
             
        case FRM_ATALK_NETWORK:
             if (EXTRACT_32BITS(data) )          
                printf("{%d}",EXTRACT_32BITS(data) );
             else
                printf("{NAS_assign}" );          
          break;

        case TUNNEL_PREFERENCE:
            tag = *data;
            data++;
            if (tag == 0)
               printf("{Tag[Unused] %d}",EXTRACT_24BITS(data) );
            else
               printf("{Tag[%d] %d}", tag, EXTRACT_24BITS(data) );
          break;

        default:
             printf("{%d}",EXTRACT_32BITS( data) );
          break;
      
      } /* switch */
   
   } /* if-else */

   return;
   
   trunc:
     printf("|radius}");
}


/*****************************/
/* Print an attribute IPv4   */
/* address value pointed by  */
/* 'data' and 'length' size. */
/*****************************/
/* Returns nothing.          */
/*****************************/
static void
print_attr_address(register u_char *data, u_int length, u_short attr_code )
{
   if (length != 4)
   {
       printf("{length %u != 4}", length);
       return;
   }

   TCHECK2(data[0],4);
   
   switch(attr_code)
   {
      case FRM_IPADDR:
      case LOG_IPHOST:
           if (EXTRACT_32BITS(data) == 0xFFFFFFFF )
              printf("{User_select}");
           else
              if (EXTRACT_32BITS(data) == 0xFFFFFFFE )
                 printf("{NAS_select}");
              else
                 printf("{%s}",ipaddr_string(data));
      break;
      
      default:
          printf("{%s}",ipaddr_string(data) );
      break;
   }
   
   return;
   
   trunc:
     printf("{|radius}");
}


/*************************************/
/* Print an attribute of 'secs since */
/* January 1, 1970 00:00 UTC' value  */
/* pointed by 'data' and 'length'    */
/* size.                             */
/*************************************/
/* Returns nothing.                  */
/*************************************/
static void print_attr_time(register u_char *data, u_int length, u_short attr_code)
{
   time_t attr_time;
   char string[26];

   if (length != 4)
   {
       printf("{length %u != 4}", length);
       return;
   }

   TCHECK2(data[0],4);
   
   attr_time = EXTRACT_32BITS(data);
   strcpy(string, ctime(&attr_time));
   /* Get rid of the newline */
   string[24] = '\0';
   printf("{%.24s}", string);
   return;
   
   trunc:
     printf("{|radius}");
}

           
/***********************************/
/* Print an attribute of 'strange' */
/* data format pointed by 'data'   */
/* and 'length' size.              */
/***********************************/
/* Returns nothing.                */
/***********************************/
static void print_attr_strange(register u_char *data, u_int length, u_short attr_code)
{
   u_short len_data;
   
   switch(attr_code)
   {
      case ARAP_PASS:
           if (length != 16)
           {
               printf("{length %u != 16}", length);
               return;
           }
           printf("{User_challenge[");
           TCHECK2(data[0],8);
           len_data = 8;
           PRINT_HEX(len_data, data);
           printf("] User_resp[");
           TCHECK2(data[0],8);
           len_data = 8;
           PRINT_HEX(len_data, data);
           printf("]}");
        break;
        
      case ARAP_FEATURES:
           if (length != 14)
           {
               printf("{length %u != 14}", length);
               return;
           }
           TCHECK2(data[0],1);
           if (*data)
              printf("{User_can_change_pass");
           else
              printf("{User_cant_change_pass");
           data++;
           TCHECK2(data[0],1);
           printf(" Min_pass_len[%d]",*data);
           data++;
           printf(" Pass_created_at[");
           TCHECK2(data[0],4);
           len_data = 4;
           PRINT_HEX(len_data, data);
           printf("] Pass_expired_in[");
           TCHECK2(data[0],4);
           len_data = 4;
           PRINT_HEX(len_data, data);
           printf("] Current_time[");
           len_data = 4;
           TCHECK2(data[0],4);
           PRINT_HEX(len_data, data);
           printf("]}");
        break;

      case ARAP_CHALLENGE_RESP:
           if (length < 8)
           {
               printf("{length %u != 8}", length);
               return;
           }
           printf("{");
           TCHECK2(data[0],8);
           len_data = 8;
           PRINT_HEX(len_data, data);
           printf("}");
        break;
   }
   
   trunc:
     printf("|radius}");
}



static void
radius_attr_print(register u_char *attr, u_int length)
{
   register const struct radius_attr *rad_attr = (struct radius_attr *)attr;
   
   if (length < 3)
   {
      printf(" [|radius]");
      return;
   }
 
   printf(" Attr[ ");
   while (length > 0)
   {
     if ( rad_attr->len <= length )
     {
        if ( !rad_attr->type || (rad_attr->type > (TAM_SIZE(attr_type)-1))  )
           printf("#%d",rad_attr->type);
        else
        {
           printf(" %s",attr_type[rad_attr->type].name);

           if (rad_attr->len > 2)
           {
               if ( attr_type[rad_attr->type].print_func )
                  (*attr_type[rad_attr->type].print_func)( 
		                           ((u_char *)(rad_attr+1)),
                                           rad_attr->len - 2, rad_attr->type);
           }
        }
     }
     else
     {
        printf(" [|radius]");
        return;
     }
     length-=(rad_attr->len);
     rad_attr = (struct radius_attr *)( ((char *)(rad_attr))+rad_attr->len);
   }
   
   printf(" ]");
}


void
radius_print(const u_char *dat, u_int length)
{
   register const struct radius_hdr *rad;
   register int i;
   
   i = min(length, snapend - dat) - sizeof(*rad);

   if (i < 0) 
   {
	  printf(" [|radius]");
	  return;
   }

   rad = (struct radius_hdr *)dat;
 
   switch (rad->code) 
   {
     case RADCMD_ACCESS_REQ:
         printf(" rad-access-req %d", length);
         break;

     case RADCMD_ACCESS_ACC:
         printf(" rad-access-accept %d", length);
         break;

     case RADCMD_ACCESS_REJ:
         printf(" rad-access-reject %d", length);
         break;

     case RADCMD_ACCOUN_REQ:
         printf(" rad-account-req %d", length);
         break;

     case RADCMD_ACCOUN_RES:
         printf(" rad-account-resp %d", length);
         break;

     case RADCMD_ACCESS_CHA:
         printf(" rad-access-cha %d", length);
         break;

     case RADCMD_STATUS_SER:
         printf(" rad-status-serv %d", length);
         break;

     case RADCMD_STATUS_CLI:
         printf(" rad-status-cli %d", length);
         break;

     case RADCMD_RESERVED:
         printf(" rad-reserved %d", length);
         break;

     default:
         printf(" rad-#%d %d", rad->code, length);
         break;
   }
   printf(" [id %d]", rad->id);
 
   if (i)
      radius_attr_print( ((u_char *)(rad+1)), i);  
}
OpenPOWER on IntegriCloud