]>
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.14 2002-08-01 08:53:25 risso Exp $";
54 #include <tcpdump-stdinc.h>
60 #ifdef TIME_WITH_SYS_TIME
64 #include "interface.h"
65 #include "addrtoname.h"
68 #define TAM_SIZE(x) (sizeof(x)/sizeof(x[0]) )
70 #define PRINT_HEX(bytes_len, ptr_data) \
73 printf("%02X", *ptr_data ); \
79 /* Radius packet codes */
80 #define RADCMD_ACCESS_REQ 1 /* Access-Request */
81 #define RADCMD_ACCESS_ACC 2 /* Access-Accept */
82 #define RADCMD_ACCESS_REJ 3 /* Access-Reject */
83 #define RADCMD_ACCOUN_REQ 4 /* Accounting-Request */
84 #define RADCMD_ACCOUN_RES 5 /* Accounting-Response */
85 #define RADCMD_ACCESS_CHA 11 /* Access-Challenge */
86 #define RADCMD_STATUS_SER 12 /* Status-Server */
87 #define RADCMD_STATUS_CLI 13 /* Status-Client */
88 #define RADCMD_RESERVED 255 /* Reserved */
91 /********************************/
92 /* Begin Radius Attribute types */
93 /********************************/
97 #define LOG_SERVICE 15
99 #define SESSION_TIMEOUT 27
100 #define IDLE_TIMEOUT 28
101 #define FRM_ATALK_LINK 37
102 #define FRM_ATALK_NETWORK 38
104 #define ACCT_DELAY 41
105 #define ACCT_SESSION_TIME 46
107 #define TUNNEL_TYPE 64
108 #define TUNNEL_MEDIUM 65
109 #define TUNNEL_CLIENT_END 66
110 #define TUNNEL_SERVER_END 67
111 #define TUNNEL_PASS 69
114 #define ARAP_FEATURES 71
116 #define TUNNEL_PRIV_GROUP 81
117 #define TUNNEL_ASSIGN_ID 82
118 #define TUNNEL_PREFERENCE 83
120 #define ARAP_CHALLENGE_RESP 84
121 #define ACCT_INT_INTERVAL 85
123 #define TUNNEL_CLIENT_AUTH 90
124 #define TUNNEL_SERVER_AUTH 91
125 /********************************/
126 /* End Radius Attribute types */
127 /********************************/
130 static void print_attr_string(register u_char
*, u_int
, u_short
);
131 static void print_attr_num(register u_char
*, u_int
, u_short
);
132 static void print_attr_address(register u_char
*, u_int
, u_short
);
133 static void print_attr_time(register u_char
*, u_int
, u_short
);
134 static void print_attr_strange(register u_char
*, u_int
, u_short
);
137 struct radius_hdr
{ u_int8_t code
; /* Radius packet code */
138 u_int8_t id
; /* Radius packet id */
139 u_int16_t len
; /* Radius total length */
140 u_int8_t auth
[16]; /* Authenticator */
143 #define MIN_RADIUS_LEN 20
145 struct radius_attr
{ u_int8_t type
; /* Attribute type */
146 u_int8_t len
; /* Attribute length */
150 /* Service-Type Attribute standard values */
151 static const char *serv_type
[]={ NULL
,
160 "Callback NAS Prompt",
162 "Callback Administrative",
165 /* Framed-Protocol Attribute standard values */
166 static const char *frm_proto
[]={ NULL
,
170 "Gandalf proprietary",
175 /* Framed-Routing Attribute standard values */
176 static const char *frm_routing
[]={ "None",
182 /* Framed-Compression Attribute standard values */
183 static const char *frm_comp
[]={ "None",
189 /* Login-Service Attribute standard values */
190 static const char *login_serv
[]={ "Telnet",
193 "PortMaster(proprietary)",
202 /* Termination-Action Attribute standard values */
203 static const char *term_action
[]={ "Default",
207 /* NAS-Port-Type Attribute standard values */
208 static const char *nas_port_type
[]={ "Async",
215 "HDLC Clear Channel",
227 "Wireless - IEEE 802.11",
230 /* Acct-Status-Type Accounting Attribute standard values */
231 static const char *acct_status
[]={ NULL
,
245 "Tunnel-Link-Reject",
249 /* Acct-Authentic Accounting Attribute standard values */
250 static const char *acct_auth
[]={ NULL
,
256 /* Acct-Terminate-Cause Accounting Attribute standard values */
257 static const char *acct_term
[]={ NULL
,
272 "Service Unavailable",
278 /* Tunnel-Type Attribute standard values */
279 static const char *tunnel_type
[]={ NULL
,
291 "IP-in-IP Tunneling",
294 /* Tunnel-Medium-Type Attribute standard values */
295 static const char *tunnel_medium
[]={ NULL
,
310 "E.164 with NSAP subaddress",
313 /* ARAP-Zone-Access Attribute standard values */
314 static const char *arap_zone
[]={ NULL
,
315 "Only access to dfl zone",
316 "Use zone filter inc.",
318 "Use zone filter exc.",
321 static const char *prompt
[]={ "No Echo",
326 struct attrtype
{ char *name
; /* Attribute name */
327 const char **subtypes
; /* Standard Values (if any) */
328 u_char siz_subtypes
; /* Size of total standard values */
329 u_char first_subtype
; /* First standard value is 0 or 1 */
330 void (*print_func
)(register u_char
*, u_int
, u_short
);
333 { NULL
, NULL
, 0, 0, NULL
},
334 { "User", NULL
, 0, 0, print_attr_string
},
335 { "Pass", NULL
, 0, 0, NULL
},
336 { "CHAP-Pass", NULL
, 0, 0, NULL
},
337 { "NAS_ipaddr", NULL
, 0, 0, print_attr_address
},
338 { "NAS_port", NULL
, 0, 0, print_attr_num
},
339 { "Service_type", serv_type
, TAM_SIZE(serv_type
)-1, 1, print_attr_num
},
340 { "Framed_proto", frm_proto
, TAM_SIZE(frm_proto
)-1, 1, print_attr_num
},
341 { "Framed_ipaddr", NULL
, 0, 0, print_attr_address
},
342 { "Framed_ipnet", NULL
, 0, 0, print_attr_address
},
343 { "Framed_routing", frm_routing
, TAM_SIZE(frm_routing
), 0,
345 { "Filter_id", NULL
, 0, 0, print_attr_string
},
346 { "Framed_mtu", NULL
, 0, 0, print_attr_num
},
347 { "Framed_compress", frm_comp
, TAM_SIZE(frm_comp
), 0, print_attr_num
},
348 { "Login_iphost", NULL
, 0, 0, print_attr_address
},
349 { "Login_service", login_serv
, TAM_SIZE(login_serv
), 0, print_attr_num
},
350 { "Login_TCP_port", NULL
, 0, 0, print_attr_num
},
351 /*17*/ { "Unassigned", NULL
, 0, 0, NULL
},
352 { "Reply", NULL
, 0, 0, print_attr_string
},
353 { "Callback-number", NULL
, 0, 0, print_attr_string
},
354 { "Callback-id", NULL
, 0, 0, print_attr_string
},
355 /*21*/ { "Unassigned", NULL
, 0, 0, NULL
},
356 { "Framed_route", NULL
, 0, 0, print_attr_string
},
357 { "Framed_ipx_net", NULL
, 0, 0, print_attr_num
},
358 { "State", NULL
, 0, 0, print_attr_string
},
359 { "Class", NULL
, 0, 0, print_attr_string
},
360 { "Vendor_specific", NULL
, 0, 0, print_attr_string
},
361 { "Session_timeout", NULL
, 0, 0, print_attr_num
},
362 { "Idle_timeout", NULL
, 0, 0, print_attr_num
},
363 { "Term_action", term_action
, TAM_SIZE(term_action
), 0, print_attr_num
},
364 { "Called_station", NULL
, 0, 0, print_attr_string
},
365 { "Calling_station", NULL
, 0, 0, print_attr_string
},
366 { "NAS_id", NULL
, 0, 0, print_attr_string
},
367 { "Proxy_state", NULL
, 0, 0, print_attr_string
},
368 { "Login_LAT_service", NULL
, 0, 0, print_attr_string
},
369 { "Login_LAT_node", NULL
, 0, 0, print_attr_string
},
370 { "Login_LAT_group", NULL
, 0, 0, print_attr_string
},
371 { "Framed_atalk_link", NULL
, 0, 0, print_attr_num
},
372 { "Framed_atalk_net", NULL
, 0, 0, print_attr_num
},
373 { "Framed_atalk_zone", NULL
, 0, 0, print_attr_string
},
374 { "Acct_status", acct_status
, TAM_SIZE(acct_status
)-1, 1, print_attr_num
},
375 { "Acct_delay", NULL
, 0, 0, print_attr_num
},
376 { "Acct_in_octets", NULL
, 0, 0, print_attr_num
},
377 { "Acct_out_octets", NULL
, 0, 0, print_attr_num
},
378 { "Acct_session_id", NULL
, 0, 0, print_attr_string
},
379 { "Acct_authentic", acct_auth
, TAM_SIZE(acct_auth
)-1, 1, print_attr_num
},
380 { "Acct_session_time", NULL
, 0, 0, print_attr_num
},
381 { "Acct_in_packets", NULL
, 0, 0, print_attr_num
},
382 { "Acct_out_packets", NULL
, 0, 0, print_attr_num
},
383 { "Acct_term_cause", acct_term
, TAM_SIZE(acct_term
)-1, 1, print_attr_num
},
384 { "Acct_multi_session_id", NULL
, 0, 0, print_attr_string
},
385 { "Acct_link_count", NULL
, 0, 0, print_attr_num
},
386 { "Acct_in_giga", NULL
, 0, 0, print_attr_num
},
387 { "Acct_out_giga", NULL
, 0, 0, print_attr_num
},
388 /*54*/ { "Unassigned", NULL
, 0, 0, NULL
},
389 { "Event_timestamp", NULL
, 0, 0, print_attr_time
},
390 /*56*/ { "Unassigned", NULL
, 0, 0, NULL
},
391 /*57*/ { "Unassigned", NULL
, 0, 0, NULL
},
392 /*58*/ { "Unassigned", NULL
, 0, 0, NULL
},
393 /*59*/ { "Unassigned", NULL
, 0, 0, NULL
},
394 { "CHAP_challenge", NULL
, 0, 0, print_attr_string
},
395 { "NAS_port_type", nas_port_type
, TAM_SIZE(nas_port_type
), 0,
397 { "Port_limit", NULL
, 0, 0, print_attr_num
},
398 /*63*/ { "Login_LAT_port", NULL
, 0, 0, print_attr_string
},
399 { "Tunnel_type", tunnel_type
, TAM_SIZE(tunnel_type
)-1, 1, print_attr_num
},
400 { "Tunnel_medium", tunnel_medium
, TAM_SIZE(tunnel_medium
)-1, 1,
402 { "Tunnel_client_end", NULL
, 0, 0, print_attr_string
},
403 { "Tunnel_server_end", NULL
, 0, 0, print_attr_string
},
404 { "Acct_tunnel_connect", NULL
, 0, 0, print_attr_string
},
405 { "Tunnel_pass", NULL
, 0, 0, print_attr_string
},
406 { "ARAP_pass", NULL
, 0, 0, print_attr_strange
},
407 { "ARAP_feature", NULL
, 0, 0, print_attr_strange
},
408 /*72*/ { "ARAP_zone_acces", arap_zone
, TAM_SIZE(arap_zone
)-1, 1,
410 { "ARAP_security", NULL
, 0, 0, print_attr_string
},
411 { "ARAP_security_data", NULL
, 0, 0, print_attr_string
},
412 { "Password_retry", NULL
, 0, 0, print_attr_num
},
413 { "Prompt", prompt
, TAM_SIZE(prompt
), 0, print_attr_num
},
414 { "Connect_info", NULL
, 0, 0, print_attr_string
},
415 { "Config_token", NULL
, 0, 0, print_attr_string
},
416 { "EAP_msg", NULL
, 0, 0, print_attr_string
},
417 /*80*/ { "Message_auth", NULL
, 0, 0, print_attr_string
},
418 { "Tunnel_priv_group", NULL
, 0, 0, print_attr_string
},
419 { "Tunnel_assign_id", NULL
, 0, 0, print_attr_string
},
420 { "Tunnel_pref", NULL
, 0, 0, print_attr_num
},
421 { "ARAP_challenge_resp", NULL
, 0, 0, print_attr_strange
},
422 { "Acct_interim_interval", NULL
, 0, 0, print_attr_num
},
423 /*86*/ { "Acct_tunnel_pack_lost", NULL
, 0, 0, print_attr_num
},
424 { "NAS_port_id", NULL
, 0, 0, print_attr_string
},
425 { "Framed_pool", NULL
, 0, 0, print_attr_string
},
426 { "Unassigned", NULL
, 0, 0, NULL
},
427 { "Tunnel_client_auth_id", NULL
, 0, 0, print_attr_string
},
428 { "Tunnel_server_auth_id", NULL
, 0, 0, print_attr_string
},
429 /*92*/ { "Unassigned", NULL
, 0, 0, NULL
},
430 /*93*/ { "Unassigned", NULL
, 0, 0, NULL
}
434 /*****************************/
435 /* Print an attribute string */
436 /* value pointed by 'data' */
437 /* and 'length' size. */
438 /*****************************/
439 /* Returns nothing. */
440 /*****************************/
442 print_attr_string(register u_char
*data
, u_int length
, u_short attr_code
)
446 TCHECK2(data
[0],length
);
452 if (*data
&& (*data
<=0x1F) )
453 printf("Tag[%d] ",*data
);
455 printf("Salt[%d] ",EXTRACT_16BITS(data
) );
459 case TUNNEL_CLIENT_END
:
460 case TUNNEL_SERVER_END
:
461 case TUNNEL_PRIV_GROUP
:
462 case TUNNEL_ASSIGN_ID
:
463 case TUNNEL_CLIENT_AUTH
:
464 case TUNNEL_SERVER_AUTH
:
467 printf("Tag[%d] ",*data
);
474 for (i
=0; i
< length
; i
++, data
++)
475 printf("%c",(*data
< 32 || *data
> 128) ? '.' : *data
);
486 /******************************/
487 /* Print an attribute numeric */
488 /* value pointed by 'data' */
489 /* and 'length' size. */
490 /******************************/
491 /* Returns nothing. */
492 /******************************/
494 print_attr_num(register u_char
*data
, u_int length
, u_short attr_code
)
501 printf("{length %u != 4}", length
);
506 /* This attribute has standard values */
507 if (attr_type
[attr_code
].siz_subtypes
)
509 static const char **table
;
510 u_int32_t data_value
;
511 table
= attr_type
[attr_code
].subtypes
;
513 if ( (attr_code
== TUNNEL_TYPE
) || (attr_code
== TUNNEL_MEDIUM
) )
516 printf("{Tag[Unused]");
518 printf("{Tag[%d]", *data
);
520 data_value
= EXTRACT_24BITS(data
);
524 data_value
= EXTRACT_32BITS(data
);
526 if ( data_value
<= (attr_type
[attr_code
].siz_subtypes
- 1 +
527 attr_type
[attr_code
].first_subtype
) &&
528 data_value
>= attr_type
[attr_code
].first_subtype
)
529 printf("{%s}",table
[data_value
]);
531 printf("{#%d}",data_value
);
535 switch(attr_code
) /* Be aware of special cases... */
538 if (EXTRACT_32BITS( data
) == 0xFFFFFFFE )
539 printf("{NAS_select}");
541 printf("{%d}",EXTRACT_32BITS( data
) );
544 case SESSION_TIMEOUT
:
547 case ACCT_SESSION_TIME
:
548 case ACCT_INT_INTERVAL
:
549 timeout
= EXTRACT_32BITS( data
);
551 printf( "{%02d secs}", timeout
);
554 if ( timeout
< 3600 )
555 printf( "{%02d:%02d min}",
556 timeout
/ 60, timeout
% 60);
558 printf( "{%02d:%02d:%02d hours}",
559 timeout
/ 3600, (timeout
% 3600) / 60,
565 if (EXTRACT_32BITS(data
) )
566 printf("{%d}",EXTRACT_32BITS(data
) );
568 printf("{Unnumbered}" );
571 case FRM_ATALK_NETWORK
:
572 if (EXTRACT_32BITS(data
) )
573 printf("{%d}",EXTRACT_32BITS(data
) );
575 printf("{NAS_assign}" );
578 case TUNNEL_PREFERENCE
:
582 printf("{Tag[Unused] %d}",EXTRACT_24BITS(data
) );
584 printf("{Tag[%d] %d}", tag
, EXTRACT_24BITS(data
) );
588 printf("{%d}",EXTRACT_32BITS( data
) );
602 /*****************************/
603 /* Print an attribute IPv4 */
604 /* address value pointed by */
605 /* 'data' and 'length' size. */
606 /*****************************/
607 /* Returns nothing. */
608 /*****************************/
610 print_attr_address(register u_char
*data
, u_int length
, u_short attr_code
)
614 printf("{length %u != 4}", length
);
624 if (EXTRACT_32BITS(data
) == 0xFFFFFFFF )
625 printf("{User_select}");
627 if (EXTRACT_32BITS(data
) == 0xFFFFFFFE )
628 printf("{NAS_select}");
630 printf("{%s}",ipaddr_string(data
));
634 printf("{%s}",ipaddr_string(data
) );
645 /*************************************/
646 /* Print an attribute of 'secs since */
647 /* January 1, 1970 00:00 UTC' value */
648 /* pointed by 'data' and 'length' */
650 /*************************************/
651 /* Returns nothing. */
652 /*************************************/
653 static void print_attr_time(register u_char
*data
, u_int length
, u_short attr_code
)
660 printf("{length %u != 4}", length
);
666 attr_time
= EXTRACT_32BITS(data
);
667 strlcpy(string
, ctime(&attr_time
), sizeof(string
));
668 /* Get rid of the newline */
670 printf("{%.24s}", string
);
678 /***********************************/
679 /* Print an attribute of 'strange' */
680 /* data format pointed by 'data' */
681 /* and 'length' size. */
682 /***********************************/
683 /* Returns nothing. */
684 /***********************************/
685 static void print_attr_strange(register u_char
*data
, u_int length
, u_short attr_code
)
694 printf("{length %u != 16}", length
);
697 printf("{User_challenge[");
700 PRINT_HEX(len_data
, data
);
701 printf("] User_resp[");
704 PRINT_HEX(len_data
, data
);
711 printf("{length %u != 14}", length
);
716 printf("{User_can_change_pass");
718 printf("{User_cant_change_pass");
721 printf(" Min_pass_len[%d]",*data
);
723 printf(" Pass_created_at[");
726 PRINT_HEX(len_data
, data
);
727 printf("] Pass_expired_in[");
730 PRINT_HEX(len_data
, data
);
731 printf("] Current_time[");
734 PRINT_HEX(len_data
, data
);
738 case ARAP_CHALLENGE_RESP
:
741 printf("{length %u != 8}", length
);
747 PRINT_HEX(len_data
, data
);
759 radius_attr_print(register const u_char
*attr
, u_int length
)
761 register const struct radius_attr
*rad_attr
= (struct radius_attr
*)attr
;
765 printf(" [|radius]");
772 if (rad_attr
->len
== 0)
774 printf("(zero-length attribute)");
777 if ( rad_attr
->len
<= length
)
779 if ( !rad_attr
->type
|| (rad_attr
->type
> (TAM_SIZE(attr_type
)-1)) )
780 printf("#%d",rad_attr
->type
);
783 printf(" %s",attr_type
[rad_attr
->type
].name
);
785 if (rad_attr
->len
> 2)
787 if ( attr_type
[rad_attr
->type
].print_func
)
788 (*attr_type
[rad_attr
->type
].print_func
)(
789 ((u_char
*)(rad_attr
+1)),
790 rad_attr
->len
- 2, rad_attr
->type
);
796 printf(" [|radius]");
799 length
-=(rad_attr
->len
);
800 rad_attr
= (struct radius_attr
*)( ((char *)(rad_attr
))+rad_attr
->len
);
808 radius_print(const u_char
*dat
, u_int length
)
810 register const struct radius_hdr
*rad
;
814 i
= min(length
, snapend
- dat
);
816 if (i
< MIN_RADIUS_LEN
)
818 printf(" [|radius]");
822 rad
= (struct radius_hdr
*)dat
;
823 len
= ntohs(rad
->len
);
825 if (len
< MIN_RADIUS_LEN
)
827 printf(" [|radius]");
838 case RADCMD_ACCESS_REQ
:
839 printf(" rad-access-req %d", length
);
842 case RADCMD_ACCESS_ACC
:
843 printf(" rad-access-accept %d", length
);
846 case RADCMD_ACCESS_REJ
:
847 printf(" rad-access-reject %d", length
);
850 case RADCMD_ACCOUN_REQ
:
851 printf(" rad-account-req %d", length
);
854 case RADCMD_ACCOUN_RES
:
855 printf(" rad-account-resp %d", length
);
858 case RADCMD_ACCESS_CHA
:
859 printf(" rad-access-cha %d", length
);
862 case RADCMD_STATUS_SER
:
863 printf(" rad-status-serv %d", length
);
866 case RADCMD_STATUS_CLI
:
867 printf(" rad-status-cli %d", length
);
870 case RADCMD_RESERVED
:
871 printf(" rad-reserved %d", length
);
875 printf(" rad-#%d %d", rad
->code
, length
);
878 printf(" [id %d]", rad
->id
);
881 radius_attr_print( dat
+ MIN_RADIUS_LEN
, i
);