73
73
// Allocate a buffer large enough to hold the entire file
74
74
// File size should be small and this makes it easy to
75
75
// do two passes on the file
76
if ((file_buf = (char *) xmalloc((file_info.st_size + 1))) != NULL) {
77
// Null terminate the buffer so that string operations will work
78
file_buf[file_info.st_size] = '\0';
80
read_size = (file_info.st_size > 0) ? read(fd, file_buf, file_info.st_size) : 0;
82
// Check to make sure that we got the whole file
84
Error("%s Read of %s file failed : %s", module_name, file_path, strerror(errno));
87
} else if (read_size < file_info.st_size) {
88
// We don't want to signal this error on WIN32 because the sizes
89
// won't match if the file contains any CR/LF sequence.
90
Error("%s Only able to read %d bytes out %d for %s file",
91
module_name, read_size, (int) file_info.st_size, file_path);
92
file_buf[read_size] = '\0';
95
Error("%s Insufficient memory to read %s file", module_name, file_path);
76
file_buf = (char *)ats_malloc(file_info.st_size + 1);
77
// Null terminate the buffer so that string operations will work
78
file_buf[file_info.st_size] = '\0';
80
read_size = (file_info.st_size > 0) ? read(fd, file_buf, file_info.st_size) : 0;
82
// Check to make sure that we got the whole file
84
Error("%s Read of %s file failed : %s", module_name, file_path, strerror(errno));
87
} else if (read_size < file_info.st_size) {
88
// We don't want to signal this error on WIN32 because the sizes
89
// won't match if the file contains any CR/LF sequence.
90
Error("%s Only able to read %d bytes out %d for %s file",
91
module_name, read_size, (int) file_info.st_size, file_path);
92
file_buf[read_size] = '\0';
98
95
if (file_buf && read_size_ptr) {
139
136
return (write - buffer);
142
// char* ExtractIpRange(char* match_str, ip_addr_t* addr1,
140
ExtractIpRange(char* match_str, in_addr_t* min, in_addr_t* max) {
141
IpEndpoint ip_min, ip_max;
142
char const* zret = ExtractIpRange(match_str, &ip_min.sa, &ip_max.sa);
143
if (0 == zret) { // success
144
if (ats_is_ip4(&ip_min) && ats_is_ip4(&ip_max)) {
145
if (min) *min = ntohl(ats_ip4_addr_cast(&ip_min));
146
if (max) *max = ntohl(ats_ip4_addr_cast(&ip_max));
148
zret = "The addresses were not IPv4 addresses.";
154
// char* ExtractIpRange(char* match_str, sockaddr* addr1,
145
157
// Attempts to extract either an Ip Address or an IP Range
146
158
// from match_str. The range should be two addresses
154
166
// that describes the reason for the error.
157
ExtractIpRange(char *match_str, ip_addr_t *addr1, ip_addr_t *addr2)
169
ExtractIpRange(char *match_str, sockaddr* addr1, sockaddr* addr2)
159
171
Tokenizer rangeTok("-/");
172
bool mask = strchr(match_str, '/') != NULL;
164
ip_addr_t addr1_local;
165
ip_addr_t addr2_local;
167
if (strchr(match_str, '/') != NULL) {
170
178
// Extract the IP addresses from match data
171
179
numToks = rangeTok.Initialize(match_str, SHARE_TOKS);
176
184
return "malformed IP range";
179
addr1_local = htonl(inet_addr(rangeTok[0]));
187
if (0 != ats_ip_pton(rangeTok[0], &la1.sa)) {
188
return "malformed IP address";
181
if (addr1_local == (ip_addr_t) - 1 && strcmp(rangeTok[0], "255.255.255.255") != 0) {
182
return "malformed ip address";
184
191
// Handle a IP range
185
192
if (numToks == 2) {
195
if (!ats_is_ip4(&la1)) {
196
return "Masks supported only for IPv4";
188
198
// coverity[secure_coding]
189
199
if (sscanf(rangeTok[1], "%d", &mask_bits) != 1) {
190
200
return "bad mask specification";
197
207
if (mask_bits == 32) {
200
mask_val = 0xffffffff >> mask_bits;
210
mask_val = htonl(0xffffffff >> mask_bits);
203
addr2_local = addr1_local | mask_val;
204
addr1_local = addr1_local & (mask_val ^ 0xffffffff);
212
in_addr_t a = ats_ip4_addr_cast(&la1);
213
ats_ip4_set(&la2, a | mask_val);
214
ats_ip4_set(&la1, a & (mask_val ^ 0xffffffff));
207
addr2_local = htonl(inet_addr(rangeTok[1]));
208
if (addr2_local == (ip_addr_t) - 1 && strcmp(rangeTok[1], "255.255.255.255") != 0) {
217
if (0 != ats_ip_pton(rangeTok[1], &la2)) {
209
218
return "malformed ip address at range end";
213
if (addr1_local > addr2_local) {
222
if (1 == ats_ip_addr_cmp(&la1.sa, &la2.sa)) {
214
223
return "range start greater than range end";
226
ats_ip_copy(addr2, &la2);
217
addr2_local = addr1_local;
228
ats_ip_copy(addr2, &la1);
220
*addr1 = addr1_local;
221
*addr2 = addr2_local;
231
ats_ip_copy(addr1, &la1);
575
585
return "Malformed entry";
578
if (p_line->type == MATCH_NONE) {
588
if (!tags->empty() && p_line->type == MATCH_NONE) {
579
589
if (tags->dest_error_msg == false) {
580
590
return "No source specifier";