]>
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.19 2002-12-11 07:14:07 guy Exp $";
54 #include <tcpdump-stdinc.h>
60 #include "interface.h"
61 #include "addrtoname.h"
64 #define TAM_SIZE(x) (sizeof(x)/sizeof(x[0]) )
66 #define PRINT_HEX(bytes_len, ptr_data) \
69 printf("%02X", *ptr_data ); \
75 /* Radius packet codes */
76 #define RADCMD_ACCESS_REQ 1 /* Access-Request */
77 #define RADCMD_ACCESS_ACC 2 /* Access-Accept */
78 #define RADCMD_ACCESS_REJ 3 /* Access-Reject */
79 #define RADCMD_ACCOUN_REQ 4 /* Accounting-Request */
80 #define RADCMD_ACCOUN_RES 5 /* Accounting-Response */
81 #define RADCMD_ACCESS_CHA 11 /* Access-Challenge */
82 #define RADCMD_STATUS_SER 12 /* Status-Server */
83 #define RADCMD_STATUS_CLI 13 /* Status-Client */
84 #define RADCMD_RESERVED 255 /* Reserved */
87 /********************************/
88 /* Begin Radius Attribute types */
89 /********************************/
93 #define LOG_SERVICE 15
95 #define SESSION_TIMEOUT 27
96 #define IDLE_TIMEOUT 28
97 #define FRM_ATALK_LINK 37
98 #define FRM_ATALK_NETWORK 38
100 #define ACCT_DELAY 41
101 #define ACCT_SESSION_TIME 46
103 #define TUNNEL_TYPE 64
104 #define TUNNEL_MEDIUM 65
105 #define TUNNEL_CLIENT_END 66
106 #define TUNNEL_SERVER_END 67
107 #define TUNNEL_PASS 69
110 #define ARAP_FEATURES 71
112 #define TUNNEL_PRIV_GROUP 81
113 #define TUNNEL_ASSIGN_ID 82
114 #define TUNNEL_PREFERENCE 83
116 #define ARAP_CHALLENGE_RESP 84
117 #define ACCT_INT_INTERVAL 85
119 #define TUNNEL_CLIENT_AUTH 90
120 #define TUNNEL_SERVER_AUTH 91
121 /********************************/
122 /* End Radius Attribute types */
123 /********************************/
126 static void print_attr_string(register u_char
*, u_int
, u_short
);
127 static void print_attr_num(register u_char
*, u_int
, u_short
);
128 static void print_attr_address(register u_char
*, u_int
, u_short
);
129 static void print_attr_time(register u_char
*, u_int
, u_short
);
130 static void print_attr_strange(register u_char
*, u_int
, u_short
);
133 struct radius_hdr
{ u_int8_t code
; /* Radius packet code */
134 u_int8_t id
; /* Radius packet id */
135 u_int16_t len
; /* Radius total length */
136 u_int8_t auth
[16]; /* Authenticator */
139 #define MIN_RADIUS_LEN 20
141 struct radius_attr
{ u_int8_t type
; /* Attribute type */
142 u_int8_t len
; /* Attribute length */
146 /* Service-Type Attribute standard values */
147 static const char *serv_type
[]={ NULL
,
156 "Callback NAS Prompt",
158 "Callback Administrative",
161 /* Framed-Protocol Attribute standard values */
162 static const char *frm_proto
[]={ NULL
,
166 "Gandalf proprietary",
171 /* Framed-Routing Attribute standard values */
172 static const char *frm_routing
[]={ "None",
178 /* Framed-Compression Attribute standard values */
179 static const char *frm_comp
[]={ "None",
185 /* Login-Service Attribute standard values */
186 static const char *login_serv
[]={ "Telnet",
189 "PortMaster(proprietary)",
198 /* Termination-Action Attribute standard values */
199 static const char *term_action
[]={ "Default",
203 /* NAS-Port-Type Attribute standard values */
204 static const char *nas_port_type
[]={ "Async",
211 "HDLC Clear Channel",
223 "Wireless - IEEE 802.11",
226 /* Acct-Status-Type Accounting Attribute standard values */
227 static const char *acct_status
[]={ NULL
,
241 "Tunnel-Link-Reject",
245 /* Acct-Authentic Accounting Attribute standard values */
246 static const char *acct_auth
[]={ NULL
,
252 /* Acct-Terminate-Cause Accounting Attribute standard values */
253 static const char *acct_term
[]={ NULL
,
268 "Service Unavailable",
274 /* Tunnel-Type Attribute standard values */
275 static const char *tunnel_type
[]={ NULL
,
287 "IP-in-IP Tunneling",
290 /* Tunnel-Medium-Type Attribute standard values */
291 static const char *tunnel_medium
[]={ NULL
,
306 "E.164 with NSAP subaddress",
309 /* ARAP-Zone-Access Attribute standard values */
310 static const char *arap_zone
[]={ NULL
,
311 "Only access to dfl zone",
312 "Use zone filter inc.",
314 "Use zone filter exc.",
317 static const char *prompt
[]={ "No Echo",
322 struct attrtype
{ const char *name
; /* Attribute name */
323 const char **subtypes
; /* Standard Values (if any) */
324 u_char siz_subtypes
; /* Size of total standard values */
325 u_char first_subtype
; /* First standard value is 0 or 1 */
326 void (*print_func
)(register u_char
*, u_int
, u_short
);
329 { NULL
, NULL
, 0, 0, NULL
},
330 { "User", NULL
, 0, 0, print_attr_string
},
331 { "Pass", NULL
, 0, 0, NULL
},
332 { "CHAP-Pass", NULL
, 0, 0, NULL
},
333 { "NAS_ipaddr", NULL
, 0, 0, print_attr_address
},
334 { "NAS_port", NULL
, 0, 0, print_attr_num
},
335 { "Service_type", serv_type
, TAM_SIZE(serv_type
)-1, 1, print_attr_num
},
336 { "Framed_proto", frm_proto
, TAM_SIZE(frm_proto
)-1, 1, print_attr_num
},
337 { "Framed_ipaddr", NULL
, 0, 0, print_attr_address
},
338 { "Framed_ipnet", NULL
, 0, 0, print_attr_address
},
339 { "Framed_routing", frm_routing
, TAM_SIZE(frm_routing
), 0,
341 { "Filter_id", NULL
, 0, 0, print_attr_string
},
342 { "Framed_mtu", NULL
, 0, 0, print_attr_num
},
343 { "Framed_compress", frm_comp
, TAM_SIZE(frm_comp
), 0, print_attr_num
},
344 { "Login_iphost", NULL
, 0, 0, print_attr_address
},
345 { "Login_service", login_serv
, TAM_SIZE(login_serv
), 0, print_attr_num
},
346 { "Login_TCP_port", NULL
, 0, 0, print_attr_num
},
347 /*17*/ { "Unassigned", NULL
, 0, 0, NULL
},
348 { "Reply", NULL
, 0, 0, print_attr_string
},
349 { "Callback-number", NULL
, 0, 0, print_attr_string
},
350 { "Callback-id", NULL
, 0, 0, print_attr_string
},
351 /*21*/ { "Unassigned", NULL
, 0, 0, NULL
},
352 { "Framed_route", NULL
, 0, 0, print_attr_string
},
353 { "Framed_ipx_net", NULL
, 0, 0, print_attr_num
},
354 { "State", NULL
, 0, 0, print_attr_string
},
355 { "Class", NULL
, 0, 0, print_attr_string
},
356 { "Vendor_specific", NULL
, 0, 0, print_attr_string
},
357 { "Session_timeout", NULL
, 0, 0, print_attr_num
},
358 { "Idle_timeout", NULL
, 0, 0, print_attr_num
},
359 { "Term_action", term_action
, TAM_SIZE(term_action
), 0, print_attr_num
},
360 { "Called_station", NULL
, 0, 0, print_attr_string
},
361 { "Calling_station", NULL
, 0, 0, print_attr_string
},
362 { "NAS_id", NULL
, 0, 0, print_attr_string
},
363 { "Proxy_state", NULL
, 0, 0, print_attr_string
},
364 { "Login_LAT_service", NULL
, 0, 0, print_attr_string
},
365 { "Login_LAT_node", NULL
, 0, 0, print_attr_string
},
366 { "Login_LAT_group", NULL
, 0, 0, print_attr_string
},
367 { "Framed_atalk_link", NULL
, 0, 0, print_attr_num
},
368 { "Framed_atalk_net", NULL
, 0, 0, print_attr_num
},
369 { "Framed_atalk_zone", NULL
, 0, 0, print_attr_string
},
370 { "Acct_status", acct_status
, TAM_SIZE(acct_status
)-1, 1, print_attr_num
},
371 { "Acct_delay", NULL
, 0, 0, print_attr_num
},
372 { "Acct_in_octets", NULL
, 0, 0, print_attr_num
},
373 { "Acct_out_octets", NULL
, 0, 0, print_attr_num
},
374 { "Acct_session_id", NULL
, 0, 0, print_attr_string
},
375 { "Acct_authentic", acct_auth
, TAM_SIZE(acct_auth
)-1, 1, print_attr_num
},
376 { "Acct_session_time", NULL
, 0, 0, print_attr_num
},
377 { "Acct_in_packets", NULL
, 0, 0, print_attr_num
},
378 { "Acct_out_packets", NULL
, 0, 0, print_attr_num
},
379 { "Acct_term_cause", acct_term
, TAM_SIZE(acct_term
)-1, 1, print_attr_num
},
380 { "Acct_multi_session_id", NULL
, 0, 0, print_attr_string
},
381 { "Acct_link_count", NULL
, 0, 0, print_attr_num
},
382 { "Acct_in_giga", NULL
, 0, 0, print_attr_num
},
383 { "Acct_out_giga", NULL
, 0, 0, print_attr_num
},
384 /*54*/ { "Unassigned", NULL
, 0, 0, NULL
},
385 { "Event_timestamp", NULL
, 0, 0, print_attr_time
},
386 /*56*/ { "Unassigned", NULL
, 0, 0, NULL
},
387 /*57*/ { "Unassigned", NULL
, 0, 0, NULL
},
388 /*58*/ { "Unassigned", NULL
, 0, 0, NULL
},
389 /*59*/ { "Unassigned", NULL
, 0, 0, NULL
},
390 { "CHAP_challenge", NULL
, 0, 0, print_attr_string
},
391 { "NAS_port_type", nas_port_type
, TAM_SIZE(nas_port_type
), 0,
393 { "Port_limit", NULL
, 0, 0, print_attr_num
},
394 /*63*/ { "Login_LAT_port", NULL
, 0, 0, print_attr_string
},
395 { "Tunnel_type", tunnel_type
, TAM_SIZE(tunnel_type
)-1, 1, print_attr_num
},
396 { "Tunnel_medium", tunnel_medium
, TAM_SIZE(tunnel_medium
)-1, 1,
398 { "Tunnel_client_end", NULL
, 0, 0, print_attr_string
},
399 { "Tunnel_server_end", NULL
, 0, 0, print_attr_string
},
400 { "Acct_tunnel_connect", NULL
, 0, 0, print_attr_string
},
401 { "Tunnel_pass", NULL
, 0, 0, print_attr_string
},
402 { "ARAP_pass", NULL
, 0, 0, print_attr_strange
},
403 { "ARAP_feature", NULL
, 0, 0, print_attr_strange
},
404 /*72*/ { "ARAP_zone_acces", arap_zone
, TAM_SIZE(arap_zone
)-1, 1,
406 { "ARAP_security", NULL
, 0, 0, print_attr_string
},
407 { "ARAP_security_data", NULL
, 0, 0, print_attr_string
},
408 { "Password_retry", NULL
, 0, 0, print_attr_num
},
409 { "Prompt", prompt
, TAM_SIZE(prompt
), 0, print_attr_num
},
410 { "Connect_info", NULL
, 0, 0, print_attr_string
},
411 { "Config_token", NULL
, 0, 0, print_attr_string
},
412 { "EAP_msg", NULL
, 0, 0, print_attr_string
},
413 /*80*/ { "Message_auth", NULL
, 0, 0, print_attr_string
},
414 { "Tunnel_priv_group", NULL
, 0, 0, print_attr_string
},
415 { "Tunnel_assign_id", NULL
, 0, 0, print_attr_string
},
416 { "Tunnel_pref", NULL
, 0, 0, print_attr_num
},
417 { "ARAP_challenge_resp", NULL
, 0, 0, print_attr_strange
},
418 { "Acct_interim_interval", NULL
, 0, 0, print_attr_num
},
419 /*86*/ { "Acct_tunnel_pack_lost", NULL
, 0, 0, print_attr_num
},
420 { "NAS_port_id", NULL
, 0, 0, print_attr_string
},
421 { "Framed_pool", NULL
, 0, 0, print_attr_string
},
422 { "Unassigned", NULL
, 0, 0, NULL
},
423 { "Tunnel_client_auth_id", NULL
, 0, 0, print_attr_string
},
424 { "Tunnel_server_auth_id", NULL
, 0, 0, print_attr_string
},
425 /*92*/ { "Unassigned", NULL
, 0, 0, NULL
},
426 /*93*/ { "Unassigned", NULL
, 0, 0, NULL
}
430 /*****************************/
431 /* Print an attribute string */
432 /* value pointed by 'data' */
433 /* and 'length' size. */
434 /*****************************/
435 /* Returns nothing. */
436 /*****************************/
438 print_attr_string(register u_char
*data
, u_int length
, u_short attr_code
)
442 TCHECK2(data
[0],length
);
448 if (*data
&& (*data
<=0x1F) )
449 printf("Tag[%d] ",*data
);
451 printf("Salt[%d] ",EXTRACT_16BITS(data
) );
455 case TUNNEL_CLIENT_END
:
456 case TUNNEL_SERVER_END
:
457 case TUNNEL_PRIV_GROUP
:
458 case TUNNEL_ASSIGN_ID
:
459 case TUNNEL_CLIENT_AUTH
:
460 case TUNNEL_SERVER_AUTH
:
463 printf("Tag[%d] ",*data
);
470 for (i
=0; i
< length
; i
++, data
++)
471 printf("%c",(*data
< 32 || *data
> 128) ? '.' : *data
);
482 /******************************/
483 /* Print an attribute numeric */
484 /* value pointed by 'data' */
485 /* and 'length' size. */
486 /******************************/
487 /* Returns nothing. */
488 /******************************/
490 print_attr_num(register u_char
*data
, u_int length
, u_short attr_code
)
497 printf("{length %u != 4}", length
);
502 /* This attribute has standard values */
503 if (attr_type
[attr_code
].siz_subtypes
)
505 static const char **table
;
506 u_int32_t data_value
;
507 table
= attr_type
[attr_code
].subtypes
;
509 if ( (attr_code
== TUNNEL_TYPE
) || (attr_code
== TUNNEL_MEDIUM
) )
512 printf("{Tag[Unused]");
514 printf("{Tag[%d]", *data
);
516 data_value
= EXTRACT_24BITS(data
);
520 data_value
= EXTRACT_32BITS(data
);
522 if ( data_value
<= (u_int32_t
)(attr_type
[attr_code
].siz_subtypes
- 1 +
523 attr_type
[attr_code
].first_subtype
) &&
524 data_value
>= attr_type
[attr_code
].first_subtype
)
525 printf("{%s}",table
[data_value
]);
527 printf("{#%u}",data_value
);
531 switch(attr_code
) /* Be aware of special cases... */
534 if (EXTRACT_32BITS( data
) == 0xFFFFFFFE )
535 printf("{NAS_select}");
537 printf("{%d}",EXTRACT_32BITS( data
) );
540 case SESSION_TIMEOUT
:
543 case ACCT_SESSION_TIME
:
544 case ACCT_INT_INTERVAL
:
545 timeout
= EXTRACT_32BITS( data
);
547 printf( "{%02d secs}", timeout
);
550 if ( timeout
< 3600 )
551 printf( "{%02d:%02d min}",
552 timeout
/ 60, timeout
% 60);
554 printf( "{%02d:%02d:%02d hours}",
555 timeout
/ 3600, (timeout
% 3600) / 60,
561 if (EXTRACT_32BITS(data
) )
562 printf("{%d}",EXTRACT_32BITS(data
) );
564 printf("{Unnumbered}" );
567 case FRM_ATALK_NETWORK
:
568 if (EXTRACT_32BITS(data
) )
569 printf("{%d}",EXTRACT_32BITS(data
) );
571 printf("{NAS_assign}" );
574 case TUNNEL_PREFERENCE
:
578 printf("{Tag[Unused] %d}",EXTRACT_24BITS(data
) );
580 printf("{Tag[%d] %d}", tag
, EXTRACT_24BITS(data
) );
584 printf("{%d}",EXTRACT_32BITS( data
) );
598 /*****************************/
599 /* Print an attribute IPv4 */
600 /* address value pointed by */
601 /* 'data' and 'length' size. */
602 /*****************************/
603 /* Returns nothing. */
604 /*****************************/
606 print_attr_address(register u_char
*data
, u_int length
, u_short attr_code
)
610 printf("{length %u != 4}", length
);
620 if (EXTRACT_32BITS(data
) == 0xFFFFFFFF )
621 printf("{User_select}");
623 if (EXTRACT_32BITS(data
) == 0xFFFFFFFE )
624 printf("{NAS_select}");
626 printf("{%s}",ipaddr_string(data
));
630 printf("{%s}",ipaddr_string(data
) );
641 /*************************************/
642 /* Print an attribute of 'secs since */
643 /* January 1, 1970 00:00 UTC' value */
644 /* pointed by 'data' and 'length' */
646 /*************************************/
647 /* Returns nothing. */
648 /*************************************/
649 static void print_attr_time(register u_char
*data
, u_int length
, u_short attr_code _U_
)
656 printf("{length %u != 4}", length
);
662 attr_time
= EXTRACT_32BITS(data
);
663 strlcpy(string
, ctime(&attr_time
), sizeof(string
));
664 /* Get rid of the newline */
666 printf("{%.24s}", string
);
674 /***********************************/
675 /* Print an attribute of 'strange' */
676 /* data format pointed by 'data' */
677 /* and 'length' size. */
678 /***********************************/
679 /* Returns nothing. */
680 /***********************************/
681 static void print_attr_strange(register u_char
*data
, u_int length
, u_short attr_code
)
690 printf("{length %u != 16}", length
);
693 printf("{User_challenge[");
696 PRINT_HEX(len_data
, data
);
697 printf("] User_resp[");
700 PRINT_HEX(len_data
, data
);
707 printf("{length %u != 14}", length
);
712 printf("{User_can_change_pass");
714 printf("{User_cant_change_pass");
717 printf(" Min_pass_len[%d]",*data
);
719 printf(" Pass_created_at[");
722 PRINT_HEX(len_data
, data
);
723 printf("] Pass_expired_in[");
726 PRINT_HEX(len_data
, data
);
727 printf("] Current_time[");
730 PRINT_HEX(len_data
, data
);
734 case ARAP_CHALLENGE_RESP
:
737 printf("{length %u != 8}", length
);
743 PRINT_HEX(len_data
, data
);
755 radius_attr_print(register const u_char
*attr
, u_int length
)
757 register const struct radius_attr
*rad_attr
= (struct radius_attr
*)attr
;
761 printf(" [|radius]");
768 if (rad_attr
->len
== 0)
770 printf("(zero-length attribute)");
773 if ( rad_attr
->len
<= length
)
775 if ( !rad_attr
->type
|| (rad_attr
->type
> (TAM_SIZE(attr_type
)-1)) )
776 printf("#%d",rad_attr
->type
);
779 printf(" %s",attr_type
[rad_attr
->type
].name
);
781 if (rad_attr
->len
> 2)
783 if ( attr_type
[rad_attr
->type
].print_func
)
784 (*attr_type
[rad_attr
->type
].print_func
)(
785 ((u_char
*)(rad_attr
+1)),
786 rad_attr
->len
- 2, rad_attr
->type
);
792 printf(" [|radius]");
795 length
-=(rad_attr
->len
);
796 rad_attr
= (struct radius_attr
*)( ((char *)(rad_attr
))+rad_attr
->len
);
804 radius_print(const u_char
*dat
, u_int length
)
806 register const struct radius_hdr
*rad
;
812 printf(" [|radius]");
819 if (i
< MIN_RADIUS_LEN
)
821 printf(" [|radius]");
825 rad
= (struct radius_hdr
*)dat
;
826 len
= EXTRACT_16BITS(&rad
->len
);
828 if (len
< MIN_RADIUS_LEN
)
830 printf(" [|radius]");
841 case RADCMD_ACCESS_REQ
:
842 printf(" rad-access-req %u", length
);
845 case RADCMD_ACCESS_ACC
:
846 printf(" rad-access-accept %u", length
);
849 case RADCMD_ACCESS_REJ
:
850 printf(" rad-access-reject %u", length
);
853 case RADCMD_ACCOUN_REQ
:
854 printf(" rad-account-req %u", length
);
857 case RADCMD_ACCOUN_RES
:
858 printf(" rad-account-resp %u", length
);
861 case RADCMD_ACCESS_CHA
:
862 printf(" rad-access-cha %u", length
);
865 case RADCMD_STATUS_SER
:
866 printf(" rad-status-serv %u", length
);
869 case RADCMD_STATUS_CLI
:
870 printf(" rad-status-cli %u", length
);
873 case RADCMD_RESERVED
:
874 printf(" rad-reserved %u", length
);
878 printf(" rad-#%u %u", rad
->code
, length
);
881 printf(" [id %u]", rad
->id
);
884 radius_attr_print( dat
+ MIN_RADIUS_LEN
, i
);