X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/c9321fdee351d7c29f92d89036671fdcec83074d..HEAD:/print-radius.c diff --git a/print-radius.c b/print-radius.c index 6465d7b7..598db8e6 100644 --- a/print-radius.c +++ b/print-radius.c @@ -82,64 +82,65 @@ * TODO: Among other things to print ok MacIntosh and Vendor values */ -#ifdef HAVE_CONFIG_H #include -#endif #include "netdissect-stdinc.h" #include +#include "netdissect-ctype.h" + +#define ND_LONGJMP_FROM_TCHECK #include "netdissect.h" #include "addrtoname.h" #include "extract.h" #include "oui.h" - +#include "ntp.h" #define TAM_SIZE(x) (sizeof(x)/sizeof(x[0]) ) #define PRINT_HEX(bytes_len, ptr_data) \ while(bytes_len) \ { \ - ND_PRINT("%02X", *ptr_data ); \ + ND_PRINT("%02X", GET_U_1(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_DISCON_REQ 40 /* Disconnect-Request */ -#define RADCMD_DISCON_ACK 41 /* Disconnect-ACK */ -#define RADCMD_DISCON_NAK 42 /* Disconnect-NAK */ -#define RADCMD_COA_REQ 43 /* CoA-Request */ -#define RADCMD_COA_ACK 44 /* CoA-ACK */ -#define RADCMD_COA_NAK 45 /* CoA-NAK */ -#define RADCMD_RESERVED 255 /* Reserved */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-27 */ +#define RADCMD_ACCESS_REQ 1 /* Access-Request */ +#define RADCMD_ACCESS_ACC 2 /* Access-Accept */ +#define RADCMD_ACCESS_REJ 3 /* Access-Reject */ +#define RADCMD_ACCOUNT_REQ 4 /* Accounting-Request */ +#define RADCMD_ACCOUNT_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_DISCON_REQ 40 /* Disconnect-Request */ +#define RADCMD_DISCON_ACK 41 /* Disconnect-ACK */ +#define RADCMD_DISCON_NAK 42 /* Disconnect-NAK */ +#define RADCMD_COA_REQ 43 /* CoA-Request */ +#define RADCMD_COA_ACK 44 /* CoA-ACK */ +#define RADCMD_COA_NAK 45 /* CoA-NAK */ +#define RADCMD_RESERVED 255 /* Reserved */ static const struct tok radius_command_values[] = { - { RADCMD_ACCESS_REQ, "Access-Request" }, - { RADCMD_ACCESS_ACC, "Access-Accept" }, - { RADCMD_ACCESS_REJ, "Access-Reject" }, - { RADCMD_ACCOUN_REQ, "Accounting-Request" }, - { RADCMD_ACCOUN_RES, "Accounting-Response" }, - { RADCMD_ACCESS_CHA, "Access-Challenge" }, - { RADCMD_STATUS_SER, "Status-Server" }, - { RADCMD_STATUS_CLI, "Status-Client" }, - { RADCMD_DISCON_REQ, "Disconnect-Request" }, - { RADCMD_DISCON_ACK, "Disconnect-ACK" }, - { RADCMD_DISCON_NAK, "Disconnect-NAK" }, - { RADCMD_COA_REQ, "CoA-Request" }, - { RADCMD_COA_ACK, "CoA-ACK" }, - { RADCMD_COA_NAK, "CoA-NAK" }, - { RADCMD_RESERVED, "Reserved" }, + { RADCMD_ACCESS_REQ, "Access-Request" }, + { RADCMD_ACCESS_ACC, "Access-Accept" }, + { RADCMD_ACCESS_REJ, "Access-Reject" }, + { RADCMD_ACCOUNT_REQ, "Accounting-Request" }, + { RADCMD_ACCOUNT_RES, "Accounting-Response" }, + { RADCMD_ACCESS_CHA, "Access-Challenge" }, + { RADCMD_STATUS_SER, "Status-Server" }, + { RADCMD_STATUS_CLI, "Status-Client" }, + { RADCMD_DISCON_REQ, "Disconnect-Request" }, + { RADCMD_DISCON_ACK, "Disconnect-ACK" }, + { RADCMD_DISCON_NAK, "Disconnect-NAK" }, + { RADCMD_COA_REQ, "CoA-Request" }, + { RADCMD_COA_ACK, "CoA-ACK" }, + { RADCMD_COA_NAK, "CoA-NAK" }, + { RADCMD_RESERVED, "Reserved" }, { 0, NULL} }; @@ -171,6 +172,8 @@ static const struct tok radius_command_values[] = { #define ARAP_PASS 70 #define ARAP_FEATURES 71 +#define EAP_MESSAGE 79 + #define TUNNEL_PRIV_GROUP 81 #define TUNNEL_ASSIGN_ID 82 #define TUNNEL_PREFERENCE 83 @@ -195,7 +198,6 @@ static const struct tok rfc4675_tagged[] = { { 0, NULL} }; - static void print_attr_string(netdissect_options *, const u_char *, u_int, u_short ); static void print_attr_num(netdissect_options *, const u_char *, u_int, u_short ); static void print_vendor_attr(netdissect_options *, const u_char *, u_int, u_short ); @@ -203,11 +205,14 @@ static void print_attr_address(netdissect_options *, const u_char *, u_int, u_sh static void print_attr_address6(netdissect_options *, const u_char *, u_int, u_short); static void print_attr_netmask6(netdissect_options *, const u_char *, u_int, u_short); static void print_attr_mip6_home_link_prefix(netdissect_options *, const u_char *, u_int, u_short); +static void print_attr_operator_name(netdissect_options *, const u_char *, u_int, u_short); +static void print_attr_location_information(netdissect_options *, const u_char *, u_int, u_short); +static void print_attr_location_data(netdissect_options *, const u_char *, u_int, u_short); +static void print_basic_location_policy_rules(netdissect_options *, const u_char *, u_int, u_short); static void print_attr_time(netdissect_options *, const u_char *, u_int, u_short); -static void print_attr_vector64(netdissect_options *, register const u_char *, u_int, u_short); +static void print_attr_vector64(netdissect_options *, const u_char *, u_int, u_short); static void print_attr_strange(netdissect_options *, const u_char *, u_int, u_short); - struct radius_hdr { nd_uint8_t code; /* Radius packet code */ nd_uint8_t id; /* Radius packet id */ nd_uint16_t len; /* Radius total length */ @@ -220,8 +225,8 @@ struct radius_attr { nd_uint8_t type; /* Attribute type */ nd_uint8_t len; /* Attribute length */ }; - /* Service-Type Attribute standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-4 */ static const char *serv_type[]={ NULL, "Login", "Framed", @@ -232,11 +237,22 @@ static const char *serv_type[]={ NULL, "NAS Prompt", "Authenticate Only", "Callback NAS Prompt", + /* ^ [0, 9] ^ */ "Call Check", "Callback Administrative", + "Voice", + "Fax", + "Modem Relay", + "IAPP-Register", + "IAPP-AP-Check", + "Authorize Only", + "Framed-Management", + "Additional-Authorization", + /* ^ [10, 19] ^ */ }; /* Framed-Protocol Attribute standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-5 */ static const char *frm_proto[]={ NULL, "PPP", "SLIP", @@ -244,9 +260,11 @@ static const char *frm_proto[]={ NULL, "Gandalf proprietary", "Xylogics IPX/SLIP", "X.75 Synchronous", + "GPRS PDP Context", }; /* Framed-Routing Attribute standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-6 */ static const char *frm_routing[]={ "None", "Send", "Listen", @@ -254,6 +272,7 @@ static const char *frm_routing[]={ "None", }; /* Framed-Compression Attribute standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-7 */ static const char *frm_comp[]={ "None", "VJ TCP/IP", "IPX", @@ -261,6 +280,7 @@ static const char *frm_comp[]={ "None", }; /* Login-Service Attribute standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-8 */ static const char *login_serv[]={ "Telnet", "Rlogin", "TCP Clear", @@ -272,8 +292,8 @@ static const char *login_serv[]={ "Telnet", "TCP Clear Quiet", }; - /* Termination-Action Attribute standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-9 */ static const char *term_action[]={ "Default", "RADIUS-Request", }; @@ -285,6 +305,7 @@ static const char *ingress_filters[]={ NULL, }; /* NAS-Port-Type Attribute standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-13 */ static const char *nas_port_type[]={ "Async", "Sync", "ISDN Sync", @@ -295,6 +316,7 @@ static const char *nas_port_type[]={ "Async", "HDLC Clear Channel", "X.25", "X.75", + /* ^ [0, 9] ^ */ "G.3 Fax", "SDSL", "ADSL-CAP", @@ -305,9 +327,37 @@ static const char *nas_port_type[]={ "Async", "Cable", "Wireless - Other", "Wireless - IEEE 802.11", + /* ^ [10, 19] ^ */ + "Token-Ring", + "FDDI", + "Wireless - CDMA200", + "Wireless - UMTS", + "Wireless - 1X-EV", + "IAPP", + "FTTP", + "Wireless - IEEE 802.16", + "Wireless - IEEE 802.20", + "Wireless - IEEE 802.22", + /* ^ [20, 29] ^ */ + "PPPoA", + "PPPoEoA", + "PPPoEoE", + "PPPoEoVLAN", + "PPPoEoQinQ", + "xPON", + "Wireless - XGP", + "WiMAX Pre-Release 8 IWK Function", + "WIMAX-WIFI-IWK", + "WIMAX-SFF", + /* ^ [30, 39] ^ */ + "WIMAX-HA-LMA", + "WIMAX-DHCP", + "WIMAX-LBS", + "WIMAX-WVS", }; /* Acct-Status-Type Accounting Attribute standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-10 */ static const char *acct_status[]={ NULL, "Start", "Stop", @@ -318,6 +368,7 @@ static const char *acct_status[]={ NULL, "Accounting-On", "Accounting-Off", "Tunnel-Start", + /* ^ [0, 9] ^ */ "Tunnel-Stop", "Tunnel-Reject", "Tunnel-Link-Start", @@ -327,13 +378,16 @@ static const char *acct_status[]={ NULL, }; /* Acct-Authentic Accounting Attribute standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-11 */ static const char *acct_auth[]={ NULL, "RADIUS", "Local", "Remote", + "Diameter", }; /* Acct-Terminate-Cause Accounting Attribute standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-12 */ static const char *acct_term[]={ NULL, "User Request", "Lost Carrier", @@ -344,6 +398,7 @@ static const char *acct_term[]={ NULL, "Admin Reboot", "Port Error", "NAS Error", + /* ^ [0, 9] ^ */ "NAS Request", "NAS Reboot", "Port Unneeded", @@ -353,9 +408,16 @@ static const char *acct_term[]={ NULL, "Callback", "User Error", "Host Request", + "Supplicant Restart", + /* ^ [10, 19] ^ */ + "Reauthentication Failure", + "Port Reinitialized", + "Port Administratively Disabled", + "Lost Power", }; /* Tunnel-Type Attribute standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-14 */ static const char *tunnel_type[]={ NULL, "PPTP", "L2F", @@ -366,6 +428,7 @@ static const char *tunnel_type[]={ NULL, "IP-IP", "MIN-IP-IP", "ESP", + /* ^ [0, 9] ^ */ "GRE", "DVS", "IP-in-IP Tunneling", @@ -373,6 +436,7 @@ static const char *tunnel_type[]={ NULL, }; /* Tunnel-Medium-Type Attribute standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-15 */ static const char *tunnel_medium[]={ NULL, "IPv4", "IPv6", @@ -383,6 +447,7 @@ static const char *tunnel_medium[]={ NULL, "E.163", "E.164", "F.69", + /* ^ [0, 9] ^ */ "X.121", "IPX", "Appletalk", @@ -392,6 +457,7 @@ static const char *tunnel_medium[]={ NULL, }; /* ARAP-Zone-Access Attribute standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-16 */ static const char *arap_zone[]={ NULL, "Only access to dfl zone", "Use zone filter inc.", @@ -399,11 +465,13 @@ static const char *arap_zone[]={ NULL, "Use zone filter exc.", }; +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-17 */ static const char *prompt[]={ "No Echo", "Echo", }; /* Error-Cause standard values */ +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-18 */ #define ERROR_CAUSE_RESIDUAL_CONTEXT_REMOVED 201 #define ERROR_CAUSE_INVALID_EAP_PACKET 202 #define ERROR_CAUSE_UNSUPPORTED_ATTRIBUTE 401 @@ -476,7 +544,59 @@ static const struct mip6_feature_vector { { INTER_MAG_ROUTING_SUPPORTED, "INTER_MAG_ROUTING_SUPPORTED" }, }; +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-19 */ +#define OPERATOR_NAME_TADIG 0x30 +#define OPERATOR_NAME_REALM 0x31 +#define OPERATOR_NAME_E212 0x32 +#define OPERATOR_NAME_ICC 0x33 +static const struct tok operator_name_vector[] = { + { OPERATOR_NAME_TADIG, "TADIG" }, + { OPERATOR_NAME_REALM, "REALM" }, + { OPERATOR_NAME_E212, "E212" }, + { OPERATOR_NAME_ICC, "ICC" }, + { 0, NULL } + }; + +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-20 */ +#define LOCATION_INFORMATION_CODE_CIVIC 0 +#define LOCATION_INFORMATION_CODE_GEOSPATIAL 1 +static const struct tok location_information_code_vector[] = { + { LOCATION_INFORMATION_CODE_CIVIC , "Civic" }, + { LOCATION_INFORMATION_CODE_GEOSPATIAL, "Geospatial" }, + { 0, NULL } + }; + +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-21 */ +#define LOCATION_INFORMATION_ENTITY_USER 0 +#define LOCATION_INFORMATION_ENTITY_RADIUS 1 +static const struct tok location_information_entity_vector[] = { + { LOCATION_INFORMATION_ENTITY_USER, "User" }, + { LOCATION_INFORMATION_ENTITY_RADIUS, "RADIUS" }, + { 0, NULL } + }; + +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-22 */ +static const struct tok blpr_bm[] = { + { 0x0001, "MBZ-15" }, + { 0x0002, "MBZ-14" }, + { 0x0004, "MBZ-13" }, + { 0x0008, "MBZ-12" }, + { 0x0010, "MBZ-11" }, + { 0x0020, "MBZ-10" }, + { 0x0040, "MBZ-9" }, + { 0x0080, "MBZ-8" }, + { 0x0100, "MBZ-7" }, + { 0x0200, "MBZ-6" }, + { 0x0400, "MBZ-5" }, + { 0x0800, "MBZ-4" }, + { 0x1000, "MBZ-3" }, + { 0x2000, "MBZ-2" }, + { 0x4000, "MBZ-1" }, + { 0x8000, "Retransmission Allowed" }, + { 0, NULL } + }; +/* https://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-2 */ static const struct attrtype { const char *name; /* Attribute name */ const char **subtypes; /* Standard Values (if any) */ @@ -495,6 +615,7 @@ static const struct attrtype { { "Framed-Protocol", frm_proto, TAM_SIZE(frm_proto)-1, 1, print_attr_num }, { "Framed-IP-Address", NULL, 0, 0, print_attr_address }, { "Framed-IP-Netmask", NULL, 0, 0, print_attr_address }, + /* ^ [0, 9] ^ */ { "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 }, @@ -505,6 +626,7 @@ static const struct attrtype { { "Unassigned", NULL, 0, 0, NULL }, /*17*/ { "Reply-Message", NULL, 0, 0, print_attr_string }, { "Callback-Number", NULL, 0, 0, print_attr_string }, + /* ^ [10, 19] ^ */ { "Callback-Id", NULL, 0, 0, print_attr_string }, { "Unassigned", NULL, 0, 0, NULL }, /*21*/ { "Framed-Route", NULL, 0, 0, print_attr_string }, @@ -515,6 +637,7 @@ static const struct attrtype { { "Session-Timeout", NULL, 0, 0, print_attr_num }, { "Idle-Timeout", NULL, 0, 0, print_attr_num }, { "Termination-Action", term_action, TAM_SIZE(term_action), 0, print_attr_num }, + /* ^ [20, 29] ^ */ { "Called-Station-Id", NULL, 0, 0, print_attr_string }, { "Calling-Station-Id", NULL, 0, 0, print_attr_string }, { "NAS-Identifier", NULL, 0, 0, print_attr_string }, @@ -525,6 +648,7 @@ static const struct attrtype { { "Framed-AppleTalk-Link", NULL, 0, 0, print_attr_num }, { "Framed-AppleTalk-Network", NULL, 0, 0, print_attr_num }, { "Framed-AppleTalk-Zone", NULL, 0, 0, print_attr_string }, + /* ^ [30, 39] ^ */ { "Acct-Status-Type", acct_status, TAM_SIZE(acct_status)-1, 1, print_attr_num }, { "Acct-Delay-Time", NULL, 0, 0, print_attr_num }, { "Acct-Input-Octets", NULL, 0, 0, print_attr_num }, @@ -535,6 +659,7 @@ static const struct attrtype { { "Acct-Input-Packets", NULL, 0, 0, print_attr_num }, { "Acct-Output-Packets", NULL, 0, 0, print_attr_num }, { "Acct-Terminate-Cause", acct_term, TAM_SIZE(acct_term)-1, 1, print_attr_num }, + /* ^ [40, 49] ^ */ { "Acct-Multi-Session-Id", NULL, 0, 0, print_attr_string }, { "Acct-Link-Count", NULL, 0, 0, print_attr_num }, { "Acct-Input-Gigawords", NULL, 0, 0, print_attr_num }, @@ -545,6 +670,7 @@ static const struct attrtype { { "Ingress-Filters", ingress_filters, TAM_SIZE(ingress_filters)-1, 1, print_attr_num }, { "Egress-VLAN-Name", NULL, 0, 0, print_attr_string }, { "User-Priority-Table", NULL, 0, 0, NULL }, + /* ^ [50, 59] ^ */ { "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 }, @@ -555,6 +681,7 @@ static const struct attrtype { { "Tunnel-Server-Endpoint", NULL, 0, 0, print_attr_string }, { "Acct-Tunnel-Connection", NULL, 0, 0, print_attr_string }, { "Tunnel-Password", NULL, 0, 0, print_attr_string }, + /* ^ [60, 69] ^ */ { "ARAP-Password", NULL, 0, 0, print_attr_strange }, { "ARAP-Features", NULL, 0, 0, print_attr_strange }, { "ARAP-Zone-Access", arap_zone, TAM_SIZE(arap_zone)-1, 1, print_attr_num }, /*72*/ @@ -565,6 +692,7 @@ static const struct attrtype { { "Connect-Info", NULL, 0, 0, print_attr_string }, { "Configuration-Token", NULL, 0, 0, print_attr_string }, { "EAP-Message", NULL, 0, 0, print_attr_string }, + /* ^ [70, 79] ^ */ { "Message-Authenticator", NULL, 0, 0, print_attr_string }, /*80*/ { "Tunnel-Private-Group-ID", NULL, 0, 0, print_attr_string }, { "Tunnel-Assignment-ID", NULL, 0, 0, print_attr_string }, @@ -575,6 +703,7 @@ static const struct attrtype { { "NAS-Port-Id", NULL, 0, 0, print_attr_string }, { "Framed-Pool", NULL, 0, 0, print_attr_string }, { "CUI", NULL, 0, 0, print_attr_string }, + /* ^ [80, 89] ^ */ { "Tunnel-Client-Auth-ID", NULL, 0, 0, print_attr_string }, { "Tunnel-Server-Auth-ID", NULL, 0, 0, print_attr_string }, { "NAS-Filter-Rule", NULL, 0, 0, print_attr_string }, @@ -585,6 +714,7 @@ static const struct attrtype { { "Framed-IPv6-Prefix", NULL, 0, 0, print_attr_netmask6 }, { "Login-IPv6-Host", NULL, 0, 0, print_attr_address6 }, { "Framed-IPv6-Route", NULL, 0, 0, print_attr_string }, + /* ^ [90, 99] ^ */ { "Framed-IPv6-Pool", NULL, 0, 0, print_attr_string }, { "Error-Cause", NULL, 0, 0, print_attr_strange }, { "EAP-Key-Name", NULL, 0, 0, NULL }, @@ -595,6 +725,7 @@ static const struct attrtype { { "Digest-Nextnonce", NULL, 0, 0, print_attr_string }, { "Digest-Method", NULL, 0, 0, print_attr_string }, { "Digest-URI", NULL, 0, 0, print_attr_string }, + /* ^ [100, 109] ^ */ { "Digest-Qop", NULL, 0, 0, print_attr_string }, { "Digest-Algorithm", NULL, 0, 0, print_attr_string }, { "Digest-Entity-Body-Hash", NULL, 0, 0, print_attr_string }, @@ -605,15 +736,20 @@ static const struct attrtype { { "Digest-Auth-Param", NULL, 0, 0, print_attr_string }, { "Digest-AKA-Auts", NULL, 0, 0, print_attr_string }, { "Digest-Domain", NULL, 0, 0, print_attr_string }, + /* ^ [110, 119] ^ */ { "Digest-Stale", NULL, 0, 0, print_attr_string }, { "Digest-HA1", NULL, 0, 0, print_attr_string }, { "SIP-AOR", NULL, 0, 0, print_attr_string }, { "Delegated-IPv6-Prefix", NULL, 0, 0, print_attr_netmask6 }, { "MIP6-Feature-Vector", NULL, 0, 0, print_attr_vector64 }, { "MIP6-Home-Link-Prefix", NULL, 0, 0, print_attr_mip6_home_link_prefix }, + { "Operator-Name", NULL, 0, 0, print_attr_operator_name }, + { "Location-Information", NULL, 0, 0, print_attr_location_information }, + { "Location-Data", NULL, 0, 0, print_attr_location_data }, + { "Basic-Location-Policy-Rules", NULL, 0, 0, print_basic_location_policy_rules } + /* ^ [120, 129] ^ */ }; - /*****************************/ /* Print an attribute string */ /* value pointed by 'data' */ @@ -627,13 +763,9 @@ print_attr_string(netdissect_options *ndo, { u_int i; - ND_TCHECK_LEN(data, length); - - switch(attr_code) - { + switch(attr_code) { case TUNNEL_PASS: - if (length < 3) - goto trunc; + ND_ICHECK_U(length, <, 3); if (GET_U_1(data) && (GET_U_1(data) <= 0x1F)) ND_PRINT("Tag[%u] ", GET_U_1(data)); else @@ -650,10 +782,8 @@ print_attr_string(netdissect_options *ndo, case TUNNEL_ASSIGN_ID: case TUNNEL_CLIENT_AUTH: case TUNNEL_SERVER_AUTH: - if (GET_U_1(data) <= 0x1F) - { - if (length < 1) - goto trunc; + if (GET_U_1(data) <= 0x1F) { + ND_ICHECK_U(length, <, 1); if (GET_U_1(data)) ND_PRINT("Tag[%u] ", GET_U_1(data)); else @@ -663,23 +793,26 @@ print_attr_string(netdissect_options *ndo, } break; case EGRESS_VLAN_NAME: - if (length < 1) - goto trunc; + ND_ICHECK_U(length, <, 1); ND_PRINT("%s (0x%02x) ", tok2str(rfc4675_tagged,"Unknown tag",GET_U_1(data)), GET_U_1(data)); data++; length--; break; + case EAP_MESSAGE: + ND_ICHECK_U(length, <, 1); + eap_print(ndo, data, length); + return; } for (i=0; i < length && GET_U_1(data); i++, data++) - ND_PRINT("%c", ND_ISPRINT(GET_U_1(data)) ? GET_U_1(data) : '.'); + ND_PRINT("%c", ND_ASCII_ISPRINT(GET_U_1(data)) ? GET_U_1(data) : '.'); return; - trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); } /* @@ -694,9 +827,7 @@ print_vendor_attr(netdissect_options *ndo, u_int vendor_type; u_int vendor_length; - if (length < 4) - goto trunc; - ND_TCHECK_4(data); + ND_ICHECK_U(length, <, 4); vendor_id = GET_BE_U_4(data); data+=4; length-=4; @@ -706,41 +837,26 @@ print_vendor_attr(netdissect_options *ndo, vendor_id); while (length >= 2) { - ND_TCHECK_2(data); - vendor_type = GET_U_1(data); vendor_length = GET_U_1(data + 1); - if (vendor_length < 2) - { - ND_PRINT("\n\t Vendor Attribute: %u, Length: %u (bogus, must be >= 2)", - vendor_type, - vendor_length); - return; - } - if (vendor_length > length) - { - ND_PRINT("\n\t Vendor Attribute: %u, Length: %u (bogus, goes past end of vendor-specific attribute)", - vendor_type, - vendor_length); - return; - } + ND_PRINT("\n\t Vendor Attribute: %u, length: %u", + vendor_type, vendor_length); + ND_ICHECKMSG_U("length", vendor_length, <, 2); + ND_ICHECKMSG_U("length", vendor_length, >, length); data+=2; vendor_length-=2; length-=2; - ND_TCHECK_LEN(data, vendor_length); - ND_PRINT("\n\t Vendor Attribute: %u, Length: %u, Value: ", - vendor_type, - vendor_length); + ND_PRINT(", value: "); for (idx = 0; idx < vendor_length ; idx++, data++) - ND_PRINT("%c", ND_ISPRINT(GET_U_1(data)) ? GET_U_1(data) : '.'); + ND_PRINT("%c", ND_ASCII_ISPRINT(GET_U_1(data)) ? GET_U_1(data) : '.'); length-=vendor_length; } return; - trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); } /******************************/ @@ -756,31 +872,22 @@ print_attr_num(netdissect_options *ndo, { uint32_t timeout; - if (length != 4) - { - ND_PRINT("ERROR: length %u != 4", length); - return; - } + ND_ICHECK_U(length, !=, 4); - ND_TCHECK_4(data); /* This attribute has standard values */ - if (attr_type[attr_code].siz_subtypes) - { + if (attr_type[attr_code].siz_subtypes) { static const char **table; uint32_t data_value; table = attr_type[attr_code].subtypes; - if ( (attr_code == TUNNEL_TYPE) || (attr_code == TUNNEL_MEDIUM) ) - { + if ( (attr_code == TUNNEL_TYPE) || (attr_code == TUNNEL_MEDIUM) ) { if (!GET_U_1(data)) ND_PRINT("Tag[Unused] "); else ND_PRINT("Tag[%u] ", GET_U_1(data)); data++; data_value = GET_BE_U_3(data); - } - else - { + } else { data_value = GET_BE_U_4(data); } if ( data_value <= (uint32_t)(attr_type[attr_code].siz_subtypes - 1 + @@ -789,9 +896,7 @@ print_attr_num(netdissect_options *ndo, ND_PRINT("%s", table[data_value]); else ND_PRINT("#%u", data_value); - } - else - { + } else { switch(attr_code) /* Be aware of special cases... */ { case FRM_IPX: @@ -809,8 +914,7 @@ print_attr_num(netdissect_options *ndo, timeout = GET_BE_U_4(data); if ( timeout < 60 ) ND_PRINT("%02d secs", timeout); - else - { + else { if ( timeout < 3600 ) ND_PRINT("%02d:%02d min", timeout / 60, timeout % 60); @@ -859,11 +963,10 @@ print_attr_num(netdissect_options *ndo, } /* switch */ } /* if-else */ - return; - trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); } /*****************************/ @@ -877,16 +980,9 @@ static void print_attr_address(netdissect_options *ndo, const u_char *data, u_int length, u_short attr_code) { - if (length != 4) - { - ND_PRINT("ERROR: length %u != 4", length); - return; - } - - ND_TCHECK_4(data); + ND_ICHECK_U(length, !=, 4); - switch(attr_code) - { + switch(attr_code) { case FRM_IPADDR: case LOG_IPHOST: if (GET_BE_U_4(data) == 0xFFFFFFFF ) @@ -895,18 +991,17 @@ print_attr_address(netdissect_options *ndo, if (GET_BE_U_4(data) == 0xFFFFFFFE ) ND_PRINT("NAS Select"); else - ND_PRINT("%s",ipaddr_string(ndo, data)); + ND_PRINT("%s",GET_IPADDR_STRING(data)); break; default: - ND_PRINT("%s", ipaddr_string(ndo, data)); + ND_PRINT("%s", GET_IPADDR_STRING(data)); break; } - return; - trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); } /*****************************/ @@ -920,20 +1015,13 @@ static void print_attr_address6(netdissect_options *ndo, const u_char *data, u_int length, u_short attr_code _U_) { - if (length != 16) - { - ND_PRINT("ERROR: length %u != 16", length); - return; - } - - ND_TCHECK_16(data); - - ND_PRINT("%s", ip6addr_string(ndo, data)); + ND_ICHECK_U(length, !=, 16); + ND_PRINT("%s", GET_IP6ADDR_STRING(data)); return; - trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); } static void @@ -941,56 +1029,160 @@ print_attr_netmask6(netdissect_options *ndo, const u_char *data, u_int length, u_short attr_code _U_) { u_char data2[16]; - - if (length < 2 || length > 18) - { - ND_PRINT("ERROR: length %u not in range (2..18)", length); - return; - } - ND_TCHECK_LEN(data, length); - if (GET_U_1(data + 1) > 128) - { - ND_PRINT("ERROR: netmask %u not in range (0..128)", GET_U_1(data + 1)); - return; - } - + u_int reserved_mbz, prefix_length; + + ND_ICHECK_U(length, <, 2); + ND_ICHECK_U(length, >, 18); + reserved_mbz = GET_U_1(data); + if (reserved_mbz) + ND_PRINT("[reserved-MBZ %u] ", reserved_mbz); + prefix_length = GET_U_1(data + 1); + ND_ICHECKMSG_U("prefix length", prefix_length, >, 128); memset(data2, 0, sizeof(data2)); if (length > 2) - memcpy(data2, data+2, length-2); + GET_CPY_BYTES(data2, data+2, length-2); - ND_PRINT("%s/%u", ip6addr_string(ndo, data2), GET_U_1(data + 1)); + ND_PRINT("%s/%u", ip6addr_string(ndo, data2), prefix_length); /* local buffer, not packet data; don't use GET_IP6ADDR_STRING() */ - if (GET_U_1(data + 1) > 8 * (length - 2)) - ND_PRINT(" (inconsistent prefix length)"); + ND_ICHECKMSG_U("inconsistent prefix length", prefix_length, >, 8 * (length - 2)); return; - trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); } static void print_attr_mip6_home_link_prefix(netdissect_options *ndo, const u_char *data, u_int length, u_short attr_code _U_) { - if (length != 17) - { - ND_PRINT("ERROR: length %u != 17", length); - return; - } - ND_TCHECK_LEN(data, length); - if (GET_U_1(data) > 128) - { - ND_PRINT("ERROR: netmask %u not in range (0..128)", GET_U_1(data)); - return; - } + ND_ICHECK_U(length, !=, 17); + ND_ICHECKMSG_U("prefix length", GET_U_1(data), >, 128); + + ND_PRINT("%s/%u", GET_IP6ADDR_STRING(data + 1), GET_U_1(data)); + + return; + +invalid: + nd_print_invalid(ndo); +} + +static void +print_attr_operator_name(netdissect_options *ndo, + const u_char *data, u_int length, u_short attr_code _U_) +{ + u_int namespace_value; + + ND_ICHECK_U(length, <, 2); + namespace_value = GET_U_1(data); + data++; + ND_PRINT("[%s] ", tok2str(operator_name_vector, "unknown namespace %u", namespace_value)); + + nd_printjn(ndo, data, length - 1); + + return; - ND_PRINT("%s/%u", ip6addr_string(ndo, data + 1), GET_U_1(data)); +invalid: + nd_print_invalid(ndo); +} + +static void +print_attr_location_information(netdissect_options *ndo, + const u_char *data, u_int length, u_short attr_code _U_) +{ + uint16_t index; + uint8_t code, entity; + + ND_ICHECK_U(length, <, 21); + + index = GET_BE_U_2(data); + data += 2; + + code = GET_U_1(data); + data++; + + entity = GET_U_1(data); + data++; + + ND_PRINT("index %u, code %s, entity %s, ", + index, + tok2str(location_information_code_vector, "Unknown (%u)", code), + tok2str(location_information_entity_vector, "Unknown (%u)", entity) + ); + + ND_PRINT("sighting time "); + p_ntp_time(ndo, (const struct l_fixedpt *)data); + ND_PRINT(", "); + data += 8; + + ND_PRINT("time to live "); + p_ntp_time(ndo, (const struct l_fixedpt *)data); + ND_PRINT(", "); + data += 8; + + ND_PRINT("method \""); + nd_printjn(ndo, data, length - 20); + ND_PRINT("\""); + + return; + +invalid: + nd_print_invalid(ndo); +} + +static void +print_attr_location_data(netdissect_options *ndo, + const u_char *data, u_int length, u_short attr_code _U_) +{ + uint16_t index; + + ND_ICHECK_U(length, <, 3); + + index = GET_BE_U_2(data); + data += 2; + ND_PRINT("index %u, location", index); + + /* The Location field of the String field of the Location-Data attribute + * can have two completely different structures depending on the value of + * the Code field of a Location-Info attribute, which supposedly precedes + * the current attribute. Unfortunately, this choice of encoding makes it + * non-trivial to decode the Location field without preserving some state + * between the attributes. + */ + hex_and_ascii_print(ndo, "\n\t ", data, length - 2); return; - trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); +} + +static void +print_basic_location_policy_rules(netdissect_options *ndo, + const u_char *data, u_int length, u_short attr_code _U_) +{ + uint16_t flags; + + ND_ICHECK_U(length, <, 10); + + flags = GET_BE_U_2(data); + data += 2; + ND_PRINT("flags [%s], ", bittok2str(blpr_bm, "none", flags)); + + ND_PRINT("retention expires "); + p_ntp_time(ndo, (const struct l_fixedpt *)data); + data += 8; + + if (length > 10) { + ND_PRINT(", note well \""); + nd_printjn(ndo, data, length - 10); + ND_PRINT("\""); + } + + return; + +invalid: + nd_print_invalid(ndo); } /*************************************/ @@ -1008,13 +1200,7 @@ print_attr_time(netdissect_options *ndo, time_t attr_time; char string[26]; - if (length != 4) - { - ND_PRINT("ERROR: length %u != 4", length); - return; - } - - ND_TCHECK_4(data); + ND_ICHECK_U(length, !=, 4); attr_time = GET_BE_U_4(data); strlcpy(string, ctime(&attr_time), sizeof(string)); @@ -1023,22 +1209,18 @@ print_attr_time(netdissect_options *ndo, ND_PRINT("%.24s", string); return; - trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); } static void print_attr_vector64(netdissect_options *ndo, - register const u_char *data, u_int length, u_short attr_code _U_) + const u_char *data, u_int length, u_short attr_code _U_) { uint64_t data_value, i; const char *sep = ""; - if (length != 8) - { - ND_PRINT("ERROR: length %u != 8", length); - return; - } + ND_ICHECK_U(length, !=, 8); ND_PRINT("["); @@ -1055,11 +1237,10 @@ print_attr_vector64(netdissect_options *ndo, } ND_PRINT("]"); - return; - trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); } /***********************************/ @@ -1076,81 +1257,54 @@ print_attr_strange(netdissect_options *ndo, u_short len_data; u_int error_cause_value; - switch(attr_code) - { + switch(attr_code) { case ARAP_PASS: - if (length != 16) - { - ND_PRINT("ERROR: length %u != 16", length); - return; - } + ND_ICHECK_U(length, !=, 16); ND_PRINT("User_challenge ("); - ND_TCHECK_8(data); len_data = 8; PRINT_HEX(len_data, data); ND_PRINT(") User_resp("); - ND_TCHECK_8(data); len_data = 8; PRINT_HEX(len_data, data); ND_PRINT(")"); break; case ARAP_FEATURES: - if (length != 14) - { - ND_PRINT("ERROR: length %u != 14", length); - return; - } - ND_TCHECK_1(data); + ND_ICHECK_U(length, !=, 14); if (GET_U_1(data)) ND_PRINT("User can change password"); else ND_PRINT("User cannot change password"); data++; - ND_TCHECK_1(data); ND_PRINT(", Min password length: %u", GET_U_1(data)); data++; ND_PRINT(", created at: "); - ND_TCHECK_4(data); len_data = 4; PRINT_HEX(len_data, data); ND_PRINT(", expires in: "); - ND_TCHECK_4(data); len_data = 4; PRINT_HEX(len_data, data); ND_PRINT(", Current Time: "); - ND_TCHECK_4(data); len_data = 4; PRINT_HEX(len_data, data); break; case ARAP_CHALLENGE_RESP: - if (length < 8) - { - ND_PRINT("ERROR: length %u != 8", length); - return; - } - ND_TCHECK_8(data); + ND_ICHECK_U(length, !=, 8); len_data = 8; PRINT_HEX(len_data, data); break; case ERROR_CAUSE: - if (length != 4) - { - ND_PRINT("Error: length %u != 4", length); - return; - } - ND_TCHECK_4(data); - + ND_ICHECK_U(length, !=, 4); error_cause_value = GET_BE_U_4(data); ND_PRINT("Error cause %u: %s", error_cause_value, tok2str(errorcausetype, "Error-Cause %u not known", error_cause_value)); break; } return; - trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); } static void @@ -1161,11 +1315,8 @@ radius_attrs_print(netdissect_options *ndo, const char *attr_string; uint8_t type, len; - while (length > 0) - { - if (length < 2) - goto trunc; - ND_TCHECK_SIZE(rad_attr); + while (length != 0) { + ND_ICHECK_U(length, <, 2); type = GET_U_1(rad_attr->type); len = GET_U_1(rad_attr->len); @@ -1178,22 +1329,12 @@ radius_attrs_print(netdissect_options *ndo, attr_string, type, len); - if (len < 2) - { - ND_PRINT(" (bogus, must be >= 2)"); - return; - } - if (len > length) - { - ND_PRINT(" (bogus, goes past end of packet)"); - return; - } + ND_ICHECKMSG_U("length", len, <, 2); + ND_ICHECKMSG_U("length", len, >, length); ND_PRINT(", Value: "); - if (type < TAM_SIZE(attr_type)) - { - if (len > 2) - { + if (type < TAM_SIZE(attr_type)) { + if (len > 2) { if ( attr_type[type].print_func ) (*attr_type[type].print_func)( ndo, ((const u_char *)(rad_attr+1)), @@ -1209,54 +1350,50 @@ radius_attrs_print(netdissect_options *ndo, } return; -trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); } void radius_print(netdissect_options *ndo, - const u_char *dat, u_int length) + const u_char *dat, const u_int length) { const struct radius_hdr *rad; u_int len, auth_idx; ndo->ndo_protocol = "radius"; - ND_TCHECK_LEN(dat, MIN_RADIUS_LEN); + nd_print_protocol_caps(ndo); + ND_ICHECK_U(length, <, MIN_RADIUS_LEN); rad = (const struct radius_hdr *)dat; len = GET_BE_U_2(rad->len); - if (len < MIN_RADIUS_LEN) - { - nd_print_trunc(ndo); - return; - } - - if (len > length) - len = length; + ND_ICHECKMSG_U("length", len, <, MIN_RADIUS_LEN); + ND_ICHECKMSG_U("length", len, >, 4096); + ND_ICHECKMSG_U("length", len, >, length); if (ndo->ndo_vflag < 1) { - ND_PRINT("RADIUS, %s (%u), id: 0x%02x length: %u", + ND_PRINT(", %s (%u), id: 0x%02x, length: %u", tok2str(radius_command_values,"Unknown Command",GET_U_1(rad->code)), GET_U_1(rad->code), GET_U_1(rad->id), len); + ND_TCHECK_LEN(dat, MIN_RADIUS_LEN); return; - } - else { - ND_PRINT("RADIUS, length: %u\n\t%s (%u), id: 0x%02x, Authenticator: ", + } else { + ND_PRINT(", length: %u\n\t%s (%u), id: 0x%02x, Authenticator: ", len, tok2str(radius_command_values,"Unknown Command",GET_U_1(rad->code)), GET_U_1(rad->code), GET_U_1(rad->id)); for(auth_idx=0; auth_idx < 16; auth_idx++) - ND_PRINT("%02x", rad->auth[auth_idx]); + ND_PRINT("%02x", GET_U_1((rad->auth + auth_idx))); } if (len > MIN_RADIUS_LEN) radius_attrs_print(ndo, dat + MIN_RADIUS_LEN, len - MIN_RADIUS_LEN); return; -trunc: - nd_print_trunc(ndo); +invalid: + nd_print_invalid(ndo); }