]>
The Tcpdump Group git mirrors - tcpdump/blob - print-radius.c
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
[] =
47 "$Id: print-radius.c,v 1.11 2002-04-20 09:40:42 guy Exp $";
56 #include <sys/param.h>
58 #include <netinet/in.h>
62 #ifdef TIME_WITH_SYS_TIME
66 #include "interface.h"
67 #include "addrtoname.h"
70 #define TAM_SIZE(x) (sizeof(x)/sizeof(x[0]) )
72 #define PRINT_HEX(bytes_len, ptr_data) \
75 printf("%02X", *ptr_data ); \
81 /* Radius packet codes */
82 #define RADCMD_ACCESS_REQ 1 /* Access-Request */
83 #define RADCMD_ACCESS_ACC 2 /* Access-Accept */
84 #define RADCMD_ACCESS_REJ 3 /* Access-Reject */
85 #define RADCMD_ACCOUN_REQ 4 /* Accounting-Request */
86 #define RADCMD_ACCOUN_RES 5 /* Accounting-Response */
87 #define RADCMD_ACCESS_CHA 11 /* Access-Challenge */
88 #define RADCMD_STATUS_SER 12 /* Status-Server */
89 #define RADCMD_STATUS_CLI 13 /* Status-Client */
90 #define RADCMD_RESERVED 255 /* Reserved */
93 /********************************/
94 /* Begin Radius Attribute types */
95 /********************************/
99 #define LOG_SERVICE 15
101 #define SESSION_TIMEOUT 27
102 #define IDLE_TIMEOUT 28
103 #define FRM_ATALK_LINK 37
104 #define FRM_ATALK_NETWORK 38
106 #define ACCT_DELAY 41
107 #define ACCT_SESSION_TIME 46
109 #define TUNNEL_TYPE 64
110 #define TUNNEL_MEDIUM 65
111 #define TUNNEL_CLIENT_END 66
112 #define TUNNEL_SERVER_END 67
113 #define TUNNEL_PASS 69
116 #define ARAP_FEATURES 71
118 #define TUNNEL_PRIV_GROUP 81
119 #define TUNNEL_ASSIGN_ID 82
120 #define TUNNEL_PREFERENCE 83
122 #define ARAP_CHALLENGE_RESP 84
123 #define ACCT_INT_INTERVAL 85
125 #define TUNNEL_CLIENT_AUTH 90
126 #define TUNNEL_SERVER_AUTH 91
127 /********************************/
128 /* End Radius Attribute types */
129 /********************************/
132 static void print_attr_string(register u_char
*, u_int
, u_short
);
133 static void print_attr_num(register u_char
*, u_int
, u_short
);
134 static void print_attr_address(register u_char
*, u_int
, u_short
);
135 static void print_attr_time(register u_char
*, u_int
, u_short
);
136 static void print_attr_strange(register u_char
*, u_int
, u_short
);
139 struct radius_hdr
{ u_int8_t code
; /* Radius packet code */
140 u_int8_t id
; /* Radius packet id */
141 u_int16_t len
; /* Radius total length */
142 u_int8_t auth
[16]; /* Authenticator */
145 #define MIN_RADIUS_LEN 20
147 struct radius_attr
{ u_int8_t type
; /* Attribute type */
148 u_int8_t len
; /* Attribute length */
152 /* Service-Type Attribute standard values */
153 static const char *serv_type
[]={ NULL
,
162 "Callback NAS Prompt",
164 "Callback Administrative",
167 /* Framed-Protocol Attribute standard values */
168 static const char *frm_proto
[]={ NULL
,
172 "Gandalf proprietary",
177 /* Framed-Routing Attribute standard values */
178 static const char *frm_routing
[]={ "None",
184 /* Framed-Compression Attribute standard values */
185 static const char *frm_comp
[]={ "None",
191 /* Login-Service Attribute standard values */
192 static const char *login_serv
[]={ "Telnet",
195 "PortMaster(proprietary)",
204 /* Termination-Action Attribute standard values */
205 static const char *term_action
[]={ "Default",
209 /* NAS-Port-Type Attribute standard values */
210 static const char *nas_port_type
[]={ "Async",
217 "HDLC Clear Channel",
229 "Wireless - IEEE 802.11",
232 /* Acct-Status-Type Accounting Attribute standard values */
233 static const char *acct_status
[]={ NULL
,
247 "Tunnel-Link-Reject",
251 /* Acct-Authentic Accounting Attribute standard values */
252 static const char *acct_auth
[]={ NULL
,
258 /* Acct-Terminate-Cause Accounting Attribute standard values */
259 static const char *acct_term
[]={ NULL
,
274 "Service Unavailable",
280 /* Tunnel-Type Attribute standard values */
281 static const char *tunnel_type
[]={ NULL
,
293 "IP-in-IP Tunneling",
296 /* Tunnel-Medium-Type Attribute standard values */
297 static const char *tunnel_medium
[]={ NULL
,
312 "E.164 with NSAP subaddress",
315 /* ARAP-Zone-Access Attribute standard values */
316 static const char *arap_zone
[]={ NULL
,
317 "Only access to dfl zone",
318 "Use zone filter inc.",
320 "Use zone filter exc.",
323 static const char *prompt
[]={ "No Echo",
328 struct attrtype
{ char *name
; /* Attribute name */
329 const char **subtypes
; /* Standard Values (if any) */
330 u_char siz_subtypes
; /* Size of total standard values */
331 u_char first_subtype
; /* First standard value is 0 or 1 */
332 void (*print_func
)(register u_char
*, u_int
, u_short
);
335 { NULL
, NULL
, 0, 0, NULL
},
336 { "User", NULL
, 0, 0, print_attr_string
},
337 { "Pass", NULL
, 0, 0, NULL
},
338 { "CHAP-Pass", NULL
, 0, 0, NULL
},
339 { "NAS_ipaddr", NULL
, 0, 0, print_attr_address
},
340 { "NAS_port", NULL
, 0, 0, print_attr_num
},
341 { "Service_type", serv_type
, TAM_SIZE(serv_type
)-1, 1, print_attr_num
},
342 { "Framed_proto", frm_proto
, TAM_SIZE(frm_proto
)-1, 1, print_attr_num
},
343 { "Framed_ipaddr", NULL
, 0, 0, print_attr_address
},
344 { "Framed_ipnet", NULL
, 0, 0, print_attr_address
},
345 { "Framed_routing", frm_routing
, TAM_SIZE(frm_routing
), 0,
347 { "Filter_id", NULL
, 0, 0, print_attr_string
},
348 { "Framed_mtu", NULL
, 0, 0, print_attr_num
},
349 { "Framed_compress", frm_comp
, TAM_SIZE(frm_comp
), 0, print_attr_num
},
350 { "Login_iphost", NULL
, 0, 0, print_attr_address
},
351 { "Login_service", login_serv
, TAM_SIZE(login_serv
), 0, print_attr_num
},
352 { "Login_TCP_port", NULL
, 0, 0, print_attr_num
},
353 /*17*/ { "Unassigned", NULL
, 0, 0, NULL
},
354 { "Reply", NULL
, 0, 0, print_attr_string
},
355 { "Callback-number", NULL
, 0, 0, print_attr_string
},
356 { "Callback-id", NULL
, 0, 0, print_attr_string
},
357 /*21*/ { "Unassigned", NULL
, 0, 0, NULL
},
358 { "Framed_route", NULL
, 0, 0, print_attr_string
},
359 { "Framed_ipx_net", NULL
, 0, 0, print_attr_num
},
360 { "State", NULL
, 0, 0, print_attr_string
},
361 { "Class", NULL
, 0, 0, print_attr_string
},
362 { "Vendor_specific", NULL
, 0, 0, print_attr_string
},
363 { "Session_timeout", NULL
, 0, 0, print_attr_num
},
364 { "Idle_timeout", NULL
, 0, 0, print_attr_num
},
365 { "Term_action", term_action
, TAM_SIZE(term_action
), 0, print_attr_num
},
366 { "Called_station", NULL
, 0, 0, print_attr_string
},
367 { "Calling_station", NULL
, 0, 0, print_attr_string
},
368 { "NAS_id", NULL
, 0, 0, print_attr_string
},
369 { "Proxy_state", NULL
, 0, 0, print_attr_string
},
370 { "Login_LAT_service", NULL
, 0, 0, print_attr_string
},
371 { "Login_LAT_node", NULL
, 0, 0, print_attr_string
},
372 { "Login_LAT_group", NULL
, 0, 0, print_attr_string
},
373 { "Framed_atalk_link", NULL
, 0, 0, print_attr_num
},
374 { "Framed_atalk_net", NULL
, 0, 0, print_attr_num
},
375 { "Framed_atalk_zone", NULL
, 0, 0, print_attr_string
},
376 { "Acct_status", acct_status
, TAM_SIZE(acct_status
)-1, 1, print_attr_num
},
377 { "Acct_delay", NULL
, 0, 0, print_attr_num
},
378 { "Acct_in_octets", NULL
, 0, 0, print_attr_num
},
379 { "Acct_out_octets", NULL
, 0, 0, print_attr_num
},
380 { "Acct_session_id", NULL
, 0, 0, print_attr_string
},
381 { "Acct_authentic", acct_auth
, TAM_SIZE(acct_auth
)-1, 1, print_attr_num
},
382 { "Acct_session_time", NULL
, 0, 0, print_attr_num
},
383 { "Acct_in_packets", NULL
, 0, 0, print_attr_num
},
384 { "Acct_out_packets", NULL
, 0, 0, print_attr_num
},
385 { "Acct_term_cause", acct_term
, TAM_SIZE(acct_term
)-1, 1, print_attr_num
},
386 { "Acct_multi_session_id", NULL
, 0, 0, print_attr_string
},
387 { "Acct_link_count", NULL
, 0, 0, print_attr_num
},
388 { "Acct_in_giga", NULL
, 0, 0, print_attr_num
},
389 { "Acct_out_giga", NULL
, 0, 0, print_attr_num
},
390 /*54*/ { "Unassigned", NULL
, 0, 0, NULL
},
391 { "Event_timestamp", NULL
, 0, 0, print_attr_time
},
392 /*56*/ { "Unassigned", NULL
, 0, 0, NULL
},
393 /*57*/ { "Unassigned", NULL
, 0, 0, NULL
},
394 /*58*/ { "Unassigned", NULL
, 0, 0, NULL
},
395 /*59*/ { "Unassigned", NULL
, 0, 0, NULL
},
396 { "CHAP_challenge", NULL
, 0, 0, print_attr_string
},
397 { "NAS_port_type", nas_port_type
, TAM_SIZE(nas_port_type
), 0,
399 { "Port_limit", NULL
, 0, 0, print_attr_num
},
400 /*63*/ { "Login_LAT_port", NULL
, 0, 0, print_attr_string
},
401 { "Tunnel_type", tunnel_type
, TAM_SIZE(tunnel_type
)-1, 1, print_attr_num
},
402 { "Tunnel_medium", tunnel_medium
, TAM_SIZE(tunnel_medium
)-1, 1,
404 { "Tunnel_client_end", NULL
, 0, 0, print_attr_string
},
405 { "Tunnel_server_end", NULL
, 0, 0, print_attr_string
},
406 { "Acct_tunnel_connect", NULL
, 0, 0, print_attr_string
},
407 { "Tunnel_pass", NULL
, 0, 0, print_attr_string
},
408 { "ARAP_pass", NULL
, 0, 0, print_attr_strange
},
409 { "ARAP_feature", NULL
, 0, 0, print_attr_strange
},
410 /*72*/ { "ARAP_zone_acces", arap_zone
, TAM_SIZE(arap_zone
)-1, 1,
412 { "ARAP_security", NULL
, 0, 0, print_attr_string
},
413 { "ARAP_security_data", NULL
, 0, 0, print_attr_string
},
414 { "Password_retry", NULL
, 0, 0, print_attr_num
},
415 { "Prompt", prompt
, TAM_SIZE(prompt
), 0, print_attr_num
},
416 { "Connect_info", NULL
, 0, 0, print_attr_string
},
417 { "Config_token", NULL
, 0, 0, print_attr_string
},
418 { "EAP_msg", NULL
, 0, 0, print_attr_string
},
419 /*80*/ { "Message_auth", NULL
, 0, 0, print_attr_string
},
420 { "Tunnel_priv_group", NULL
, 0, 0, print_attr_string
},
421 { "Tunnel_assign_id", NULL
, 0, 0, print_attr_string
},
422 { "Tunnel_pref", NULL
, 0, 0, print_attr_num
},
423 { "ARAP_challenge_resp", NULL
, 0, 0, print_attr_strange
},
424 { "Acct_interim_interval", NULL
, 0, 0, print_attr_num
},
425 /*86*/ { "Acct_tunnel_pack_lost", NULL
, 0, 0, print_attr_num
},
426 { "NAS_port_id", NULL
, 0, 0, print_attr_string
},
427 { "Framed_pool", NULL
, 0, 0, print_attr_string
},
428 { "Unassigned", NULL
, 0, 0, NULL
},
429 { "Tunnel_client_auth_id", NULL
, 0, 0, print_attr_string
},
430 { "Tunnel_server_auth_id", NULL
, 0, 0, print_attr_string
},
431 /*92*/ { "Unassigned", NULL
, 0, 0, NULL
},
432 /*93*/ { "Unassigned", NULL
, 0, 0, NULL
}
436 /*****************************/
437 /* Print an attribute string */
438 /* value pointed by 'data' */
439 /* and 'length' size. */
440 /*****************************/
441 /* Returns nothing. */
442 /*****************************/
444 print_attr_string(register u_char
*data
, u_int length
, u_short attr_code
)
448 TCHECK2(data
[0],length
);
454 if (*data
&& (*data
<=0x1F) )
455 printf("Tag[%d] ",*data
);
457 printf("Salt[%d] ",EXTRACT_16BITS(data
) );
461 case TUNNEL_CLIENT_END
:
462 case TUNNEL_SERVER_END
:
463 case TUNNEL_PRIV_GROUP
:
464 case TUNNEL_ASSIGN_ID
:
465 case TUNNEL_CLIENT_AUTH
:
466 case TUNNEL_SERVER_AUTH
:
469 printf("Tag[%d] ",*data
);
476 for (i
=0; i
< length
; i
++, data
++)
477 printf("%c",(*data
< 32 || *data
> 128) ? '.' : *data
);
488 /******************************/
489 /* Print an attribute numeric */
490 /* value pointed by 'data' */
491 /* and 'length' size. */
492 /******************************/
493 /* Returns nothing. */
494 /******************************/
496 print_attr_num(register u_char
*data
, u_int length
, u_short attr_code
)
503 printf("{length %u != 4}", length
);
508 /* This attribute has standard values */
509 if (attr_type
[attr_code
].siz_subtypes
)
511 static const char **table
;
512 u_int32_t data_value
;
513 table
= attr_type
[attr_code
].subtypes
;
515 if ( (attr_code
== TUNNEL_TYPE
) || (attr_code
== TUNNEL_MEDIUM
) )
518 printf("{Tag[Unused]");
520 printf("{Tag[%d]", *data
);
522 data_value
= EXTRACT_24BITS(data
);
526 data_value
= EXTRACT_32BITS(data
);
528 if ( data_value
<= (attr_type
[attr_code
].siz_subtypes
- 1 +
529 attr_type
[attr_code
].first_subtype
) )
530 printf("{%s}",table
[data_value
]);
532 printf("{#%d}",data_value
);
536 switch(attr_code
) /* Be aware of special cases... */
539 if (EXTRACT_32BITS( data
) == 0xFFFFFFFE )
540 printf("{NAS_select}");
542 printf("{%d}",EXTRACT_32BITS( data
) );
545 case SESSION_TIMEOUT
:
548 case ACCT_SESSION_TIME
:
549 case ACCT_INT_INTERVAL
:
550 timeout
= EXTRACT_32BITS( data
);
552 printf( "{%02d secs}", timeout
);
555 if ( timeout
< 3600 )
556 printf( "{%02d:%02d min}",
557 timeout
/ 60, timeout
% 60);
559 printf( "{%02d:%02d:%02d hours}",
560 timeout
/ 3600, (timeout
% 3600) / 60,
566 if (EXTRACT_32BITS(data
) )
567 printf("{%d}",EXTRACT_32BITS(data
) );
569 printf("{Unnumbered}" );
572 case FRM_ATALK_NETWORK
:
573 if (EXTRACT_32BITS(data
) )
574 printf("{%d}",EXTRACT_32BITS(data
) );
576 printf("{NAS_assign}" );
579 case TUNNEL_PREFERENCE
:
583 printf("{Tag[Unused] %d}",EXTRACT_24BITS(data
) );
585 printf("{Tag[%d] %d}", tag
, EXTRACT_24BITS(data
) );
589 printf("{%d}",EXTRACT_32BITS( data
) );
603 /*****************************/
604 /* Print an attribute IPv4 */
605 /* address value pointed by */
606 /* 'data' and 'length' size. */
607 /*****************************/
608 /* Returns nothing. */
609 /*****************************/
611 print_attr_address(register u_char
*data
, u_int length
, u_short attr_code
)
615 printf("{length %u != 4}", length
);
625 if (EXTRACT_32BITS(data
) == 0xFFFFFFFF )
626 printf("{User_select}");
628 if (EXTRACT_32BITS(data
) == 0xFFFFFFFE )
629 printf("{NAS_select}");
631 printf("{%s}",ipaddr_string(data
));
635 printf("{%s}",ipaddr_string(data
) );
646 /*************************************/
647 /* Print an attribute of 'secs since */
648 /* January 1, 1970 00:00 UTC' value */
649 /* pointed by 'data' and 'length' */
651 /*************************************/
652 /* Returns nothing. */
653 /*************************************/
654 static void print_attr_time(register u_char
*data
, u_int length
, u_short attr_code
)
661 printf("{length %u != 4}", length
);
667 attr_time
= EXTRACT_32BITS(data
);
668 strlcpy(string
, ctime(&attr_time
), sizeof(string
));
669 /* Get rid of the newline */
671 printf("{%.24s}", string
);
679 /***********************************/
680 /* Print an attribute of 'strange' */
681 /* data format pointed by 'data' */
682 /* and 'length' size. */
683 /***********************************/
684 /* Returns nothing. */
685 /***********************************/
686 static void print_attr_strange(register u_char
*data
, u_int length
, u_short attr_code
)
695 printf("{length %u != 16}", length
);
698 printf("{User_challenge[");
701 PRINT_HEX(len_data
, data
);
702 printf("] User_resp[");
705 PRINT_HEX(len_data
, data
);
712 printf("{length %u != 14}", length
);
717 printf("{User_can_change_pass");
719 printf("{User_cant_change_pass");
722 printf(" Min_pass_len[%d]",*data
);
724 printf(" Pass_created_at[");
727 PRINT_HEX(len_data
, data
);
728 printf("] Pass_expired_in[");
731 PRINT_HEX(len_data
, data
);
732 printf("] Current_time[");
735 PRINT_HEX(len_data
, data
);
739 case ARAP_CHALLENGE_RESP
:
742 printf("{length %u != 8}", length
);
748 PRINT_HEX(len_data
, data
);
760 radius_attr_print(register const u_char
*attr
, u_int length
)
762 register const struct radius_attr
*rad_attr
= (struct radius_attr
*)attr
;
766 printf(" [|radius]");
773 if (rad_attr
->len
== 0)
775 printf("(zero-length attribute)");
778 if ( rad_attr
->len
<= length
)
780 if ( !rad_attr
->type
|| (rad_attr
->type
> (TAM_SIZE(attr_type
)-1)) )
781 printf("#%d",rad_attr
->type
);
784 printf(" %s",attr_type
[rad_attr
->type
].name
);
786 if (rad_attr
->len
> 2)
788 if ( attr_type
[rad_attr
->type
].print_func
)
789 (*attr_type
[rad_attr
->type
].print_func
)(
790 ((u_char
*)(rad_attr
+1)),
791 rad_attr
->len
- 2, rad_attr
->type
);
797 printf(" [|radius]");
800 length
-=(rad_attr
->len
);
801 rad_attr
= (struct radius_attr
*)( ((char *)(rad_attr
))+rad_attr
->len
);
809 radius_print(const u_char
*dat
, u_int length
)
811 register const struct radius_hdr
*rad
;
815 i
= min(length
, snapend
- dat
);
817 if (i
< MIN_RADIUS_LEN
)
819 printf(" [|radius]");
823 rad
= (struct radius_hdr
*)dat
;
824 len
= ntohs(rad
->len
);
826 if (len
< MIN_RADIUS_LEN
)
828 printf(" [|radius]");
839 case RADCMD_ACCESS_REQ
:
840 printf(" rad-access-req %d", length
);
843 case RADCMD_ACCESS_ACC
:
844 printf(" rad-access-accept %d", length
);
847 case RADCMD_ACCESS_REJ
:
848 printf(" rad-access-reject %d", length
);
851 case RADCMD_ACCOUN_REQ
:
852 printf(" rad-account-req %d", length
);
855 case RADCMD_ACCOUN_RES
:
856 printf(" rad-account-resp %d", length
);
859 case RADCMD_ACCESS_CHA
:
860 printf(" rad-access-cha %d", length
);
863 case RADCMD_STATUS_SER
:
864 printf(" rad-status-serv %d", length
);
867 case RADCMD_STATUS_CLI
:
868 printf(" rad-status-cli %d", length
);
871 case RADCMD_RESERVED
:
872 printf(" rad-reserved %d", length
);
876 printf(" rad-#%d %d", rad
->code
, length
);
879 printf(" [id %d]", rad
->id
);
882 radius_attr_print( dat
+ MIN_RADIUS_LEN
, i
);