use bounds-checking lookup functions for string constants

This commit is contained in:
Brendan O'Dea 2005-01-05 13:37:56 +00:00
parent 5c3bc79ed4
commit 2a09904461
2 changed files with 194 additions and 151 deletions

View file

@ -1,140 +1,197 @@
// L2TPNS: constants // L2TPNS: constants
char const *cvs_id_constants = "$Id: constants.c,v 1.3 2004-06-28 02:43:13 fred_nerk Exp $"; char const *cvs_id_constants = "$Id: constants.c,v 1.4 2005-01-05 13:37:56 bodea Exp $";
#include <stdio.h>
#include "constants.h" #include "constants.h"
#include <memory.h>
const char *lcp_types[MAX_LCP_TYPE+1] = { #define CONSTANT(table, ...) \
"Reserved", static char const *table ## s[] = { \
"Maximum-Receive-Unit", __VA_ARGS__ \
"Async-Control-Map", }; \
"Authentication-Protocol", char const *table(int index) \
"Quality-Protocol", { \
"Magic-Number", static char n[16]; \
"Reserved 6", if (index >= 0 && index < sizeof(table ## s) / sizeof(table ## s[0]) \
"Protocol-Field-Compression", && table ## s[index]) \
"Address-and-Control-Field-Compression", return table ## s[index]; \
}; snprintf(n, sizeof(n), "%d", index); \
return n; \
}
const char *avpnames[MAX_AVPNAME+1] = { CONSTANT(lcp_type,
"Message Type", // 0 0, // 0
"Result Code", // 1 "Maximum-Receive-Unit", // 1
"Protocol Version", // 2 "Async-Control-Map", // 2
"Framing Capabilities", // 3 "Authentication-Protocol", // 3
"Bearer Capabilities", // 4 "Quality-Protocol", // 4
"Tie Breaker", // 5 "Magic-Number", // 5
"Firmware Revision", // 6 0, // 6
"Host Name", // 7 "Protocol-Field-Compression", // 7
"Vendor Name", // 8 "Address-and-Control-Field-Compression" // 8
"Assigned Tunnel ID", // 9 )
"Receive Window Size", // 10
"Challenge", // 11
"Q.931 Cause Code", // 12
"Challenge Response", // 13
"Assigned Session ID", // 14
"Call Serial Number", // 15
"Minimum BPS", // 16
"Maximum BPS", // 17
"Bearer Type", // 18 (2 = Analog, 1 = Digital)
"Framing Type", // 19 (2 = Async, 1 = Sync)
"Reserved 20", // 20
"Called Number", // 21
"Calling Number", // 22
"Sub Address", // 23
"Tx Connect Speed", // 24
"Physical Channel ID", // 25
"Initial Received LCP CONFREQ", // 26
"Last Sent LCP CONFREQ", // 27
"Last Received LCP CONFREQ", // 28
"Proxy Authen Type", // 29
"Proxy Authen Name", // 30
"Proxy Authen Challenge", // 31
"Proxy Authen ID", // 32
"Proxy Authen Response", // 33
"Call Errors", // 34
"ACCM", // 35
"Random Vector", // 36
"Private Group ID", // 37
"Rx Connect Speed", // 38
"Sequencing Required", // 39
};
const char *stopccn_result_codes[MAX_STOPCCN_RESULT_CODE+1] = { CONSTANT(avp_name,
"Reserved", "Message Type", // 0
"General request to clear control connection", "Result Code", // 1
"General error--Error Code indicates the problem", "Protocol Version", // 2
"Control channel already exists", "Framing Capabilities", // 3
"Requester is not authorized to establish a control channel", "Bearer Capabilities", // 4
"The protocol version of the requester is not supported", "Tie Breaker", // 5
"Requester is being shut down", "Firmware Revision", // 6
"Finite State Machine error", "Host Name", // 7
}; "Vendor Name", // 8
"Assigned Tunnel ID", // 9
"Receive Window Size", // 10
"Challenge", // 11
"Q.931 Cause Code", // 12
"Challenge Response", // 13
"Assigned Session ID", // 14
"Call Serial Number", // 15
"Minimum BPS", // 16
"Maximum BPS", // 17
"Bearer Type", // 18 (2 = Analog, 1 = Digital)
"Framing Type", // 19 (2 = Async, 1 = Sync)
0, // 20
"Called Number", // 21
"Calling Number", // 22
"Sub Address", // 23
"Tx Connect Speed", // 24
"Physical Channel ID", // 25
"Initial Received LCP CONFREQ", // 26
"Last Sent LCP CONFREQ", // 27
"Last Received LCP CONFREQ", // 28
"Proxy Authen Type", // 29
"Proxy Authen Name", // 30
"Proxy Authen Challenge", // 31
"Proxy Authen ID", // 32
"Proxy Authen Response", // 33
"Call Errors", // 34
"ACCM", // 35
"Random Vector", // 36
"Private Group ID", // 37
"Rx Connect Speed", // 38
"Sequencing Required" // 39
)
const char *cdn_result_codes[MAX_CDN_RESULT_CODE+1] = { CONSTANT(stopccn_result_code,
"Reserved", 0, // 0
"Call disconnected due to loss of carrier", "General request to clear control connection", // 1
"Call disconnected for the reason indicated in error code", "General error--Error Code indicates the problem", // 2
"Call disconnected for administrative reasons", "Control channel already exists", // 3
"Call failed due to lack of appropriate facilities being available (temporary condition)", "Requester is not authorized to establish a"
"Call failed due to lack of appropriate facilities being available (permanent condition)", " control channel", // 4
"Invalid destination", "The protocol version of the requester is not"
"Call failed due to no carrier detected", " supported", // 5
"Call failed due to detection of a busy signal", "Requester is being shut down", // 6
"Call failed due to lack of a dial tone", "Finite State Machine error" // 7
"Call was not established within time allotted by LAC", )
"Call was connected but no appropriate framing was detected",
};
const char *error_codes[MAX_ERROR_CODE+1] = { CONSTANT(cdn_result_code,
"No general error", 0, // 0
"No control connection exists yet for this LAC-LNS pair", "Call disconnected due to loss of carrier", // 1
"Length is wrong", "Call disconnected for the reason indicated in"
"One of the field values was out of range or reserved field was non-zero", " error code", // 2
"Insufficient resources to handle this operation now", "Call disconnected for administrative reasons", // 3
"The Session ID is invalid in this context", "Call failed due to lack of appropriate facilities"
"A generic vendor-specific error occurred in the LAC", " being available (temporary condition)", // 4
"Try another LNS", "Call failed due to lack of appropriate facilities"
"Session or tunnel was shutdown due to receipt of an unknown AVP with the M-bit set", " being available (permanent condition)", // 5
}; "Invalid destination", // 6
"Call failed due to no carrier detected", // 7
"Call failed due to detection of a busy signal", // 8
"Call failed due to lack of a dial tone", // 9
"Call was not established within time allotted by"
" LAC", // 10
"Call was connected but no appropriate framing was"
" detected" // 11
)
const char *authtypes[MAX_AUTHTYPE+1] = { CONSTANT(error_code,
"Reserved", "No general error", // 0
"Textual username/password exchange", "No control connection exists yet for this LAC-LNS"
"PPP CHAP", " pair", // 1
"PPP PAP", "Length is wrong", // 2
"No Authentication", "One of the field values was out of range or"
"Microsoft CHAP Version 1 (MSCHAPv1)", " reserved field was non-zero", // 3
}; "Insufficient resources to handle this operation"
" now", // 4
"The Session ID is invalid in this context", // 5
"A generic vendor-specific error occurred in the"
" LAC", // 6
"Try another LNS", // 7
"Session or tunnel was shutdown due to receipt of"
" an unknown AVP with the M-bit set" // 8
)
const char *radius_states[MAX_RADIUS_STATE+1] = { CONSTANT(auth_type,
"RADIUSNULL", 0, // 0
"RADIUSCHAP", "Textual username/password exchange", // 1
"RADIUSAUTH", "PPP CHAP", // 2
"RADIUSIPCP", "PPP PAP", // 3
"RADIUSSTART", "No Authentication", // 4
"RADIUSSTOP", "Microsoft CHAP Version 1 (MSCHAPv1)" // 5
"RADIUSWAIT", )
NULL
};
const char *l2tp_message_types[MAX_L2TP_MESSAGE_TYPE+1] = { CONSTANT(ppp_lcp_type,
"reserved", 0, // 0
"SCCRQ", "ConfigReq", // 1
"SCCRP", "ConfigAck", // 2
"SCCCN", "ConfigNak", // 3
"StopCCN", // 4 "ConfigRej", // 4
"reserved", "TerminateReq", // 5
"HELLO", "TerminateAck", // 6
"OCRQ", "CodeRej", // 7
"OCRP", "ProtocolRej", // 8
"OCCN", "EchoReq", // 9
"ICRQ", // 10 "EchoReply", // 10
"ICRP", "DiscardRequest", // 11
"ICCN", "IdentRequest" // 12
"reserved", )
"CDN",
"WEN", // 15
"SLI",
};
CONSTANT(radius_state,
"RADIUSNULL", // 0
"RADIUSCHAP", // 1
"RADIUSAUTH", // 2
"RADIUSIPCP", // 3
"RADIUSSTART", // 4
"RADIUSSTOP", // 5
"RADIUSWAIT" // 6
)
CONSTANT(radius_code,
0, // 0
"Access-Request", // 1
"Access-Accept", // 2
"Access-Reject", // 3
"Accounting-Request", // 4
"Accounting-Response", // 5
0, // 6
0, // 7
0, // 8
0, // 9
0, // 10
"Access-Challenge", // 11
"Status-Server (experimental)", // 12
"Status-Client (experimental)" // 13
)
CONSTANT(l2tp_message_type,
0, // 0
"SCCRQ", // 1
"SCCRP", // 2
"SCCCN", // 3
"StopCCN", // 4
0, // 5
"HELLO", // 6
"OCRQ", // 7
"OCRP", // 8
"OCCN", // 9
"ICRQ", // 10
"ICRP", // 11
"ICCN", // 12
0, // 13
"CDN", // 14
"WEN", // 15
"SLI" // 16
)

View file

@ -1,29 +1,15 @@
#ifndef __CONSTANTS_H__ #ifndef __CONSTANTS_H__
#define __CONSTANTS_H__ #define __CONSTANTS_H__
#define MAX_LCP_TYPE 8 char const *lcp_type(int type);
extern const char *lcp_types[MAX_LCP_TYPE+1]; char const *avp_name(int avp);
char const *stopccn_result_code(int code);
#define MAX_AVPNAME 40 char const *cdn_result_code(int code);
extern const char *avpnames[MAX_AVPNAME+1]; char const *error_code(int code);
char const *auth_type(int type);
#define MAX_STOPCCN_RESULT_CODE 7 char const *ppp_lcp_type(int type);
extern const char *stopccn_result_codes[MAX_STOPCCN_RESULT_CODE+1]; char const *radius_state(int state);
char const *radius_code(int code);
#define MAX_CDN_RESULT_CODE 11 char const *l2tp_message_type(int type);
extern const char *cdn_result_codes[MAX_CDN_RESULT_CODE+1];
#define MAX_ERROR_CODE 8
extern const char *error_codes[MAX_ERROR_CODE+1];
#define MAX_AUTHTYPE 5
extern const char *authtypes[MAX_AUTHTYPE+1];
// Can remove the NULL end now
#define MAX_RADIUS_STATE 8
extern const char *radius_states[MAX_RADIUS_STATE+1];
#define MAX_L2TP_MESSAGE_TYPE 16
extern const char *l2tp_message_types[MAX_L2TP_MESSAGE_TYPE+1];
#endif /* __CONSTANTS_H__ */ #endif /* __CONSTANTS_H__ */