2 * Copyright (C) 2000 Alfredo Andres Omella. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
14 * 3. The names of the authors may not be used to endorse or promote
15 * products derived from this software without specific prior
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * Radius printer routines as specified on:
26 * "Remote Authentication Dial In User Service (RADIUS)"
32 * "RADIUS Accounting Modifications for Tunnel Protocol Support"
35 * "RADIUS Attributes for Tunnel Protocol Support"
40 * Alfredo Andres Omella (aandres@s21sec.com) v0.1 2000/09/15
42 * TODO: Among other things to print ok MacIntosh and Vendor values
46 static const char rcsid
[] _U_
=
47 "$Id: print-radius.c,v 1.19.2.4 2004-02-06 14:38:51 hannes Exp $";
54 #include <tcpdump-stdinc.h>
60 #include "interface.h"
61 #include "addrtoname.h"
65 #define TAM_SIZE(x) (sizeof(x)/sizeof(x[0]) )
67 #define PRINT_HEX(bytes_len, ptr_data) \
70 printf("%02X", *ptr_data ); \
76 /* Radius packet codes */
77 #define RADCMD_ACCESS_REQ 1 /* Access-Request */
78 #define RADCMD_ACCESS_ACC 2 /* Access-Accept */
79 #define RADCMD_ACCESS_REJ 3 /* Access-Reject */
80 #define RADCMD_ACCOUN_REQ 4 /* Accounting-Request */
81 #define RADCMD_ACCOUN_RES 5 /* Accounting-Response */
82 #define RADCMD_ACCESS_CHA 11 /* Access-Challenge */
83 #define RADCMD_STATUS_SER 12 /* Status-Server */
84 #define RADCMD_STATUS_CLI 13 /* Status-Client */
85 #define RADCMD_RESERVED 255 /* Reserved */
87 static struct tok radius_command_values
[] = {
88 { RADCMD_ACCESS_REQ
, "Access Request" },
89 { RADCMD_ACCESS_ACC
, "Access Accept" },
90 { RADCMD_ACCESS_REJ
, "Access Reject" },
91 { RADCMD_ACCOUN_REQ
, "Accounting Request" },
92 { RADCMD_ACCOUN_RES
, "Accounting Response" },
93 { RADCMD_ACCESS_CHA
, "Access Challenge" },
94 { RADCMD_STATUS_SER
, "Status Server" },
95 { RADCMD_STATUS_CLI
, "Status Client" },
96 { RADCMD_RESERVED
, "Reserved" },
100 /********************************/
101 /* Begin Radius Attribute types */
102 /********************************/
105 #define LOG_IPHOST 14
106 #define LOG_SERVICE 15
108 #define SESSION_TIMEOUT 27
109 #define IDLE_TIMEOUT 28
110 #define FRM_ATALK_LINK 37
111 #define FRM_ATALK_NETWORK 38
113 #define ACCT_DELAY 41
114 #define ACCT_SESSION_TIME 46
116 #define TUNNEL_TYPE 64
117 #define TUNNEL_MEDIUM 65
118 #define TUNNEL_CLIENT_END 66
119 #define TUNNEL_SERVER_END 67
120 #define TUNNEL_PASS 69
123 #define ARAP_FEATURES 71
125 #define TUNNEL_PRIV_GROUP 81
126 #define TUNNEL_ASSIGN_ID 82
127 #define TUNNEL_PREFERENCE 83
129 #define ARAP_CHALLENGE_RESP 84
130 #define ACCT_INT_INTERVAL 85
132 #define TUNNEL_CLIENT_AUTH 90
133 #define TUNNEL_SERVER_AUTH 91
134 /********************************/
135 /* End Radius Attribute types */
136 /********************************/
139 static void print_attr_string(register u_char
*, u_int
, u_short
);
140 static void print_attr_num(register u_char
*, u_int
, u_short
);
141 static void print_vendor_attr(register u_char
*, u_int
, u_short
);
142 static void print_attr_address(register u_char
*, u_int
, u_short
);
143 static void print_attr_time(register u_char
*, u_int
, u_short
);
144 static void print_attr_strange(register u_char
*, u_int
, u_short
);
147 struct radius_hdr
{ u_int8_t code
; /* Radius packet code */
148 u_int8_t id
; /* Radius packet id */
149 u_int16_t len
; /* Radius total length */
150 u_int8_t auth
[16]; /* Authenticator */
153 #define MIN_RADIUS_LEN 20
155 struct radius_attr
{ u_int8_t type
; /* Attribute type */
156 u_int8_t len
; /* Attribute length */
160 /* Service-Type Attribute standard values */
161 static const char *serv_type
[]={ NULL
,
170 "Callback NAS Prompt",
172 "Callback Administrative",
175 /* Framed-Protocol Attribute standard values */
176 static const char *frm_proto
[]={ NULL
,
180 "Gandalf proprietary",
185 /* Framed-Routing Attribute standard values */
186 static const char *frm_routing
[]={ "None",
192 /* Framed-Compression Attribute standard values */
193 static const char *frm_comp
[]={ "None",
199 /* Login-Service Attribute standard values */
200 static const char *login_serv
[]={ "Telnet",
203 "PortMaster(proprietary)",
212 /* Termination-Action Attribute standard values */
213 static const char *term_action
[]={ "Default",
217 /* NAS-Port-Type Attribute standard values */
218 static const char *nas_port_type
[]={ "Async",
225 "HDLC Clear Channel",
237 "Wireless - IEEE 802.11",
240 /* Acct-Status-Type Accounting Attribute standard values */
241 static const char *acct_status
[]={ NULL
,
255 "Tunnel-Link-Reject",
259 /* Acct-Authentic Accounting Attribute standard values */
260 static const char *acct_auth
[]={ NULL
,
266 /* Acct-Terminate-Cause Accounting Attribute standard values */
267 static const char *acct_term
[]={ NULL
,
282 "Service Unavailable",
288 /* Tunnel-Type Attribute standard values */
289 static const char *tunnel_type
[]={ NULL
,
301 "IP-in-IP Tunneling",
304 /* Tunnel-Medium-Type Attribute standard values */
305 static const char *tunnel_medium
[]={ NULL
,
320 "E.164 with NSAP subaddress",
323 /* ARAP-Zone-Access Attribute standard values */
324 static const char *arap_zone
[]={ NULL
,
325 "Only access to dfl zone",
326 "Use zone filter inc.",
328 "Use zone filter exc.",
331 static const char *prompt
[]={ "No Echo",
336 struct attrtype
{ const char *name
; /* Attribute name */
337 const char **subtypes
; /* Standard Values (if any) */
338 u_char siz_subtypes
; /* Size of total standard values */
339 u_char first_subtype
; /* First standard value is 0 or 1 */
340 void (*print_func
)(register u_char
*, u_int
, u_short
);
343 { NULL
, NULL
, 0, 0, NULL
},
344 { "Username", NULL
, 0, 0, print_attr_string
},
345 { "Password", NULL
, 0, 0, NULL
},
346 { "CHAP Password", NULL
, 0, 0, NULL
},
347 { "NAS IP Address", NULL
, 0, 0, print_attr_address
},
348 { "NAS Port", NULL
, 0, 0, print_attr_num
},
349 { "Service Type", serv_type
, TAM_SIZE(serv_type
)-1, 1, print_attr_num
},
350 { "Framed Protocol", frm_proto
, TAM_SIZE(frm_proto
)-1, 1, print_attr_num
},
351 { "Framed IP Address", NULL
, 0, 0, print_attr_address
},
352 { "Framed IP Network", NULL
, 0, 0, print_attr_address
},
353 { "Framed Routing", frm_routing
, TAM_SIZE(frm_routing
), 0, print_attr_num
},
354 { "Filter ID", NULL
, 0, 0, print_attr_string
},
355 { "Framed MTU", NULL
, 0, 0, print_attr_num
},
356 { "Framed Compression", frm_comp
, TAM_SIZE(frm_comp
), 0, print_attr_num
},
357 { "Login IP Host", NULL
, 0, 0, print_attr_address
},
358 { "Login Service", login_serv
, TAM_SIZE(login_serv
), 0, print_attr_num
},
359 { "Login TCP Port", NULL
, 0, 0, print_attr_num
},
360 { "Unassigned", NULL
, 0, 0, NULL
}, /*17*/
361 { "Reply", NULL
, 0, 0, print_attr_string
},
362 { "Callback-number", NULL
, 0, 0, print_attr_string
},
363 { "Callback-ID", NULL
, 0, 0, print_attr_string
},
364 { "Unassigned", NULL
, 0, 0, NULL
}, /*21*/
365 { "Framed Route", NULL
, 0, 0, print_attr_string
},
366 { "Framed IPX Network", NULL
, 0, 0, print_attr_num
},
367 { "State", NULL
, 0, 0, print_attr_string
},
368 { "Class", NULL
, 0, 0, print_attr_string
},
369 { "Vendor Specific", NULL
, 0, 0, print_vendor_attr
},
370 { "Session Timeout", NULL
, 0, 0, print_attr_num
},
371 { "Idle Timeout", NULL
, 0, 0, print_attr_num
},
372 { "Termination Action", term_action
, TAM_SIZE(term_action
), 0, print_attr_num
},
373 { "Called Station", NULL
, 0, 0, print_attr_string
},
374 { "Calling Station", NULL
, 0, 0, print_attr_string
},
375 { "NAS ID", NULL
, 0, 0, print_attr_string
},
376 { "Proxy State", NULL
, 0, 0, print_attr_string
},
377 { "Login LAT Service", NULL
, 0, 0, print_attr_string
},
378 { "Login LAT Node", NULL
, 0, 0, print_attr_string
},
379 { "Login LAT Group", NULL
, 0, 0, print_attr_string
},
380 { "Framed Appletalk Link", NULL
, 0, 0, print_attr_num
},
381 { "Framed Appltalk Net", NULL
, 0, 0, print_attr_num
},
382 { "Framed Appletalk Zone", NULL
, 0, 0, print_attr_string
},
383 { "Accounting Status", acct_status
, TAM_SIZE(acct_status
)-1, 1, print_attr_num
},
384 { "Accounting Delay", NULL
, 0, 0, print_attr_num
},
385 { "Accounting Input Octets", NULL
, 0, 0, print_attr_num
},
386 { "Accounting Output Octets", NULL
, 0, 0, print_attr_num
},
387 { "Accounting Session ID", NULL
, 0, 0, print_attr_string
},
388 { "Accounting Authentication", acct_auth
, TAM_SIZE(acct_auth
)-1, 1, print_attr_num
},
389 { "Accounting Session Time", NULL
, 0, 0, print_attr_num
},
390 { "Accounting Input Packets", NULL
, 0, 0, print_attr_num
},
391 { "Accounting Output Packets", NULL
, 0, 0, print_attr_num
},
392 { "Accounting Termination Cause", acct_term
, TAM_SIZE(acct_term
)-1, 1, print_attr_num
},
393 { "Accounting Multilink Session ID", NULL
, 0, 0, print_attr_string
},
394 { "Accounting Link Count", NULL
, 0, 0, print_attr_num
},
395 { "Accounting Input Giga", NULL
, 0, 0, print_attr_num
},
396 { "Accounting Output Giga", NULL
, 0, 0, print_attr_num
},
397 { "Unassigned", NULL
, 0, 0, NULL
}, /*54*/
398 { "Event Timestamp", NULL
, 0, 0, print_attr_time
},
399 { "Unassigned", NULL
, 0, 0, NULL
}, /*56*/
400 { "Unassigned", NULL
, 0, 0, NULL
}, /*57*/
401 { "Unassigned", NULL
, 0, 0, NULL
}, /*58*/
402 { "Unassigned", NULL
, 0, 0, NULL
}, /*59*/
403 { "CHAP challenge", NULL
, 0, 0, print_attr_string
},
404 { "NAS Port Type", nas_port_type
, TAM_SIZE(nas_port_type
), 0, print_attr_num
},
405 { "Port Limit", NULL
, 0, 0, print_attr_num
},
406 { "Login LAT Port", NULL
, 0, 0, print_attr_string
}, /*63*/
407 { "Tunnel Type", tunnel_type
, TAM_SIZE(tunnel_type
)-1, 1, print_attr_num
},
408 { "Tunnel Medium", tunnel_medium
, TAM_SIZE(tunnel_medium
)-1, 1, print_attr_num
},
409 { "Tunnel Client End", NULL
, 0, 0, print_attr_string
},
410 { "Tunnel Server End", NULL
, 0, 0, print_attr_string
},
411 { "Accounting Tunnel connect", NULL
, 0, 0, print_attr_string
},
412 { "Tunnel Password", NULL
, 0, 0, print_attr_string
},
413 { "ARAP Password", NULL
, 0, 0, print_attr_strange
},
414 { "ARAP Feature", NULL
, 0, 0, print_attr_strange
},
415 { "ARAP Zone Acces", arap_zone
, TAM_SIZE(arap_zone
)-1, 1, print_attr_num
}, /*72*/
416 { "ARAP Security", NULL
, 0, 0, print_attr_string
},
417 { "ARAP Security Data", NULL
, 0, 0, print_attr_string
},
418 { "Password Retry", NULL
, 0, 0, print_attr_num
},
419 { "Prompt", prompt
, TAM_SIZE(prompt
), 0, print_attr_num
},
420 { "Connect Info", NULL
, 0, 0, print_attr_string
},
421 { "Config Token", NULL
, 0, 0, print_attr_string
},
422 { "EAP Message", NULL
, 0, 0, print_attr_string
},
423 { "Message Authentication", NULL
, 0, 0, print_attr_string
}, /*80*/
424 { "Tunnel Private Group", NULL
, 0, 0, print_attr_string
},
425 { "Tunnel Assigned ID", NULL
, 0, 0, print_attr_string
},
426 { "Tunnel Preference", NULL
, 0, 0, print_attr_num
},
427 { "ARAP Challenge Response", NULL
, 0, 0, print_attr_strange
},
428 { "Accounting Interim Interval", NULL
, 0, 0, print_attr_num
},
429 { "Accounting Tunnel packets lost", NULL
, 0, 0, print_attr_num
}, /*86*/
430 { "NAS Port ID", NULL
, 0, 0, print_attr_string
},
431 { "Framed Pool", NULL
, 0, 0, print_attr_string
},
432 { "Unassigned", NULL
, 0, 0, NULL
},
433 { "Tunnel Client Authentication ID", NULL
, 0, 0, print_attr_string
},
434 { "Tunnel Server Authentication ID", NULL
, 0, 0, print_attr_string
},
435 { "Unassigned", NULL
, 0, 0, NULL
}, /*92*/
436 { "Unassigned", NULL
, 0, 0, NULL
} /*93*/
440 /*****************************/
441 /* Print an attribute string */
442 /* value pointed by 'data' */
443 /* and 'length' size. */
444 /*****************************/
445 /* Returns nothing. */
446 /*****************************/
448 print_attr_string(register u_char
*data
, u_int length
, u_short attr_code
)
452 TCHECK2(data
[0],length
);
457 if (*data
&& (*data
<=0x1F) )
458 printf("Tag %u, ",*data
);
460 printf("Salt %u ",EXTRACT_16BITS(data
) );
464 case TUNNEL_CLIENT_END
:
465 case TUNNEL_SERVER_END
:
466 case TUNNEL_PRIV_GROUP
:
467 case TUNNEL_ASSIGN_ID
:
468 case TUNNEL_CLIENT_AUTH
:
469 case TUNNEL_SERVER_AUTH
:
472 printf("Tag %u",*data
);
479 for (i
=0; *data
&& i
< length
; i
++, data
++)
480 printf("%c",(*data
< 32 || *data
> 128) ? '.' : *data
);
489 * print vendor specific attributes
493 print_vendor_attr(register u_char
*data
, u_int length
, u_short attr_code _U_
)
500 /* FIXME: all sort of boundary checks */
501 vendor_id
= EXTRACT_32BITS(data
);
505 printf("Vendor: %s (%u)",
506 tok2str(smi_values
,"Unknown",vendor_id
),
509 while (length
>= 2) {
510 if(!TTEST2(*data
, 2))
513 vendor_type
= *(data
);
514 vendor_length
= *(data
+1);
517 if(!TTEST2(*data
, vendor_length
))
520 printf("\n\t Vendor Attribute: %u, Length: %u, Value: ",
523 for (idx
= 0; idx
< vendor_length
; idx
++, data
++)
524 printf("%c",(*data
< 32 || *data
> 128) ? '.' : *data
);
525 length
-=vendor_length
;
531 /******************************/
532 /* Print an attribute numeric */
533 /* value pointed by 'data' */
534 /* and 'length' size. */
535 /******************************/
536 /* Returns nothing. */
537 /******************************/
539 print_attr_num(register u_char
*data
, u_int length
, u_short attr_code
)
546 printf("ERROR: length %u != 4", length
);
551 /* This attribute has standard values */
552 if (attr_type
[attr_code
].siz_subtypes
)
554 static const char **table
;
555 u_int32_t data_value
;
556 table
= attr_type
[attr_code
].subtypes
;
558 if ( (attr_code
== TUNNEL_TYPE
) || (attr_code
== TUNNEL_MEDIUM
) )
561 printf("Tag[Unused]");
563 printf("Tag[%d]", *data
);
565 data_value
= EXTRACT_24BITS(data
);
569 data_value
= EXTRACT_32BITS(data
);
571 if ( data_value
<= (u_int32_t
)(attr_type
[attr_code
].siz_subtypes
- 1 +
572 attr_type
[attr_code
].first_subtype
) &&
573 data_value
>= attr_type
[attr_code
].first_subtype
)
574 printf("%s",table
[data_value
]);
576 printf("#%u",data_value
);
580 switch(attr_code
) /* Be aware of special cases... */
583 if (EXTRACT_32BITS( data
) == 0xFFFFFFFE )
584 printf("NAS Select");
586 printf("%d",EXTRACT_32BITS( data
) );
589 case SESSION_TIMEOUT
:
592 case ACCT_SESSION_TIME
:
593 case ACCT_INT_INTERVAL
:
594 timeout
= EXTRACT_32BITS( data
);
596 printf( "%02d secs", timeout
);
599 if ( timeout
< 3600 )
600 printf( "%02d:%02d min",
601 timeout
/ 60, timeout
% 60);
603 printf( "%02d:%02d:%02d hours",
604 timeout
/ 3600, (timeout
% 3600) / 60,
610 if (EXTRACT_32BITS(data
) )
611 printf("%d",EXTRACT_32BITS(data
) );
613 printf("Unnumbered" );
616 case FRM_ATALK_NETWORK
:
617 if (EXTRACT_32BITS(data
) )
618 printf("%d",EXTRACT_32BITS(data
) );
620 printf("NAS assigned" );
623 case TUNNEL_PREFERENCE
:
627 printf("Tag (Unused) %d",EXTRACT_24BITS(data
) );
629 printf("Tag (%d) %d", tag
, EXTRACT_24BITS(data
) );
633 printf("%d",EXTRACT_32BITS( data
) );
647 /*****************************/
648 /* Print an attribute IPv4 */
649 /* address value pointed by */
650 /* 'data' and 'length' size. */
651 /*****************************/
652 /* Returns nothing. */
653 /*****************************/
655 print_attr_address(register u_char
*data
, u_int length
, u_short attr_code
)
659 printf("ERROR: length %u != 4", length
);
669 if (EXTRACT_32BITS(data
) == 0xFFFFFFFF )
670 printf("User Selected");
672 if (EXTRACT_32BITS(data
) == 0xFFFFFFFE )
673 printf("NAS Select");
675 printf("%s",ipaddr_string(data
));
679 printf("%s",ipaddr_string(data
) );
690 /*************************************/
691 /* Print an attribute of 'secs since */
692 /* January 1, 1970 00:00 UTC' value */
693 /* pointed by 'data' and 'length' */
695 /*************************************/
696 /* Returns nothing. */
697 /*************************************/
698 static void print_attr_time(register u_char
*data
, u_int length
, u_short attr_code _U_
)
705 printf("ERROR: length %u != 4", length
);
711 attr_time
= EXTRACT_32BITS(data
);
712 strlcpy(string
, ctime(&attr_time
), sizeof(string
));
713 /* Get rid of the newline */
715 printf("%.24s", string
);
723 /***********************************/
724 /* Print an attribute of 'strange' */
725 /* data format pointed by 'data' */
726 /* and 'length' size. */
727 /***********************************/
728 /* Returns nothing. */
729 /***********************************/
730 static void print_attr_strange(register u_char
*data
, u_int length
, u_short attr_code
)
739 printf("ERROR: length %u != 16", length
);
742 printf("User_challenge (");
745 PRINT_HEX(len_data
, data
);
746 printf(") User_resp(");
749 PRINT_HEX(len_data
, data
);
756 printf("ERROR: length %u != 14", length
);
761 printf("User can change password");
763 printf("User cannot change password");
766 printf(", Min password length: %d",*data
);
768 printf(", created at: ");
771 PRINT_HEX(len_data
, data
);
772 printf(", expires in: ");
775 PRINT_HEX(len_data
, data
);
776 printf(", Current Time: ");
779 PRINT_HEX(len_data
, data
);
782 case ARAP_CHALLENGE_RESP
:
785 printf("ERROR: length %u != 8", length
);
790 PRINT_HEX(len_data
, data
);
801 radius_attr_print(register const u_char
*attr
, u_int length
)
803 register const struct radius_attr
*rad_attr
= (struct radius_attr
*)attr
;
807 printf(" [|radius]");
813 if (rad_attr
->len
== 0 && rad_attr
->type
< (TAM_SIZE(attr_type
)-1))
815 printf("\n\t %s Attribute (%u), zero-length",
816 attr_type
[rad_attr
->type
].name
,
820 if ( rad_attr
->len
<= length
&& rad_attr
->type
< (TAM_SIZE(attr_type
)-1))
822 printf("\n\t %s Attribute (%u), length: %u, Value: ",
823 attr_type
[rad_attr
->type
].name
,
827 if ( !rad_attr
->type
|| (rad_attr
->type
> (TAM_SIZE(attr_type
)-1)) ) {
830 if (rad_attr
->len
> 2)
832 if ( attr_type
[rad_attr
->type
].print_func
)
833 (*attr_type
[rad_attr
->type
].print_func
)(
834 ((u_char
*)(rad_attr
+1)),
835 rad_attr
->len
- 2, rad_attr
->type
);
840 printf(" [|radius]");
843 /* do we want to see an additionally hexdump ? */
844 if (vflag
> 1 && rad_attr
->len
>= 2)
845 print_unknown_data((char *)rad_attr
+2,"\n\t ",(rad_attr
->len
)-2);
847 length
-=(rad_attr
->len
);
848 rad_attr
= (struct radius_attr
*)( ((char *)(rad_attr
))+rad_attr
->len
);
854 radius_print(const u_char
*dat
, u_int length
)
856 register const struct radius_hdr
*rad
;
862 printf(" [|radius]");
869 if (i
< MIN_RADIUS_LEN
)
871 printf(" [|radius]");
875 rad
= (struct radius_hdr
*)dat
;
876 len
= EXTRACT_16BITS(&rad
->len
);
878 if (len
< MIN_RADIUS_LEN
)
880 printf(" [|radius]");
890 printf("RADIUS, %s (%u), id: 0x%02x length: %u",
891 tok2str(radius_command_values
,"Unknown Command",rad
->code
),
898 printf("RADIUS, length: %u\n\t%s (%u), id: 0x%02x, Authenticator: ",
900 tok2str(radius_command_values
,"Unknown Command",rad
->code
),
904 for(auth_idx
=0; auth_idx
< 16; auth_idx
++)
905 printf("%02x", rad
->auth
[auth_idx
] );
909 radius_attr_print( dat
+ MIN_RADIUS_LEN
, i
);